1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | * |
7 | * |
… | |
… | |
145 | coroapi::cede_to_tick_every (10); |
145 | coroapi::cede_to_tick_every (10); |
146 | |
146 | |
147 | switch (f.kw) |
147 | switch (f.kw) |
148 | { |
148 | { |
149 | case KW_arch: |
149 | case KW_arch: |
150 | if (!(t->item = archetype::find (f.get_str ()))) |
150 | t->item = archetype::get (f.get_str ()); |
151 | LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ()); |
|
|
152 | break; |
151 | break; |
153 | |
152 | |
154 | case KW_list: f.get (t->name); break; |
153 | case KW_list: f.get (t->name); break; |
155 | case KW_change_name: f.get (t->change_arch.name); break; |
154 | case KW_change_name: f.get (t->change_arch.name); break; |
156 | case KW_change_title: f.get (t->change_arch.title); break; |
155 | case KW_change_title: f.get (t->change_arch.title); break; |
… | |
… | |
198 | |
197 | |
199 | /* This is a one of the many items on the list should be generated. |
198 | /* This is a one of the many items on the list should be generated. |
200 | * Add up the chance total, and check to make sure the yes & no |
199 | * Add up the chance total, and check to make sure the yes & no |
201 | * fields of the treasures are not being used. |
200 | * fields of the treasures are not being used. |
202 | */ |
201 | */ |
203 | tl->total_chance = 0; |
|
|
204 | |
|
|
205 | if (one) |
202 | if (one) |
206 | { |
203 | { |
207 | for (treasure *t = tl->items; t; t = t->next) |
204 | for (treasure *t = tl->items; t; t = t->next) |
208 | { |
205 | { |
209 | if (t->next_yes || t->next_no) |
206 | if (t->next_yes || t->next_no) |
… | |
… | |
231 | * start with equipment, but only their abilities). |
228 | * start with equipment, but only their abilities). |
232 | */ |
229 | */ |
233 | static void |
230 | static void |
234 | put_treasure (object *op, object *creator, int flags) |
231 | put_treasure (object *op, object *creator, int flags) |
235 | { |
232 | { |
236 | object *tmp; |
233 | if (flags & GT_ENVIRONMENT) |
237 | |
234 | { |
238 | /* Bit of a hack - spells should never be put onto the map. The entire |
235 | /* Bit of a hack - spells should never be put onto the map. The entire |
239 | * treasure stuff is a problem - there is no clear idea of knowing |
236 | * treasure stuff is a problem - there is no clear idea of knowing |
240 | * this is the original object, or if this is an object that should be created |
237 | * this is the original object, or if this is an object that should be created |
241 | * by another object. |
238 | * by another object. |
242 | */ |
239 | */ |
243 | if (flags & GT_ENVIRONMENT && op->type != SPELL) |
240 | //TODO: flag such as objects... as such (no drop, anybody?) |
244 | { |
241 | if (op->type == SPELL) |
|
|
242 | { |
|
|
243 | op->destroy (); |
|
|
244 | return; |
|
|
245 | } |
|
|
246 | |
|
|
247 | op->expand_tail (); |
|
|
248 | |
|
|
249 | if (ob_blocked (op, creator->map, creator->x, creator->y)) |
|
|
250 | op->destroy (); |
|
|
251 | else |
|
|
252 | { |
245 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
253 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
246 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
254 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
255 | } |
247 | } |
256 | } |
248 | else |
257 | else |
249 | { |
258 | { |
250 | op = creator->insert (op); |
259 | op = creator->insert (op); |
251 | |
260 | |
252 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
261 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
253 | monster_check_apply (creator, op); |
262 | monster_check_apply (creator, op); |
254 | |
263 | |
255 | if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) |
264 | if (flags & GT_UPDATE_INV) |
|
|
265 | if (object *tmp = creator->in_player ()) |
256 | esrv_send_item (tmp, op); |
266 | esrv_send_item (tmp, op); |
257 | } |
267 | } |
258 | } |
268 | } |
259 | |
269 | |
260 | /* if there are change_xxx commands in the treasure, we include the changes |
270 | /* if there are change_xxx commands in the treasure, we include the changes |
261 | * in the generated object |
271 | * in the generated object |
… | |
… | |
359 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
369 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
360 | change_treasure (t, tmp); |
370 | change_treasure (t, tmp); |
361 | put_treasure (tmp, op, flag); |
371 | put_treasure (tmp, op, flag); |
362 | } |
372 | } |
363 | } |
373 | } |
|
|
374 | } |
|
|
375 | |
|
|
376 | void |
|
|
377 | object::create_treasure (treasurelist *tl, int flags) |
|
|
378 | { |
|
|
379 | ::create_treasure (tl, this, flags, map ? map->difficulty : 0); |
364 | } |
380 | } |
365 | |
381 | |
366 | /* This calls the appropriate treasure creation function. tries is passed |
382 | /* This calls the appropriate treasure creation function. tries is passed |
367 | * to determine how many list transitions or attempts to create treasure |
383 | * to determine how many list transitions or attempts to create treasure |
368 | * have been made. It is really in place to prevent infinite loops with |
384 | * have been made. It is really in place to prevent infinite loops with |
… | |
… | |
381 | { |
397 | { |
382 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
398 | LOG (llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n"); |
383 | return; |
399 | return; |
384 | } |
400 | } |
385 | |
401 | |
|
|
402 | if (op->flag [FLAG_TREASURE_ENV]) |
|
|
403 | flag |= GT_ENVIRONMENT; |
|
|
404 | |
386 | if (tl->total_chance) |
405 | if (tl->total_chance) |
387 | create_one_treasure (tl, op, flag, difficulty, tries); |
406 | create_one_treasure (tl, op, flag, difficulty, tries); |
388 | else |
407 | else |
389 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
408 | create_all_treasures (tl->items, op, flag, difficulty, tries); |
390 | } |
409 | } |
… | |
… | |
397 | object * |
416 | object * |
398 | generate_treasure (treasurelist *tl, int difficulty) |
417 | generate_treasure (treasurelist *tl, int difficulty) |
399 | { |
418 | { |
400 | difficulty = clamp (difficulty, 1, settings.max_level); |
419 | difficulty = clamp (difficulty, 1, settings.max_level); |
401 | |
420 | |
402 | object *ob = object::create (), *tmp; |
421 | object *ob = object::create (); |
403 | |
422 | |
404 | create_treasure (tl, ob, 0, difficulty, 0); |
423 | create_treasure (tl, ob, 0, difficulty, 0); |
405 | |
424 | |
406 | /* Don't want to free the object we are about to return */ |
425 | /* Don't want to free the object we are about to return */ |
407 | tmp = ob->inv; |
426 | object *tmp = ob->inv; |
408 | if (tmp != NULL) |
427 | if (tmp) |
409 | tmp->remove (); |
428 | tmp->remove (); |
410 | |
429 | |
411 | if (ob->inv) |
430 | if (ob->inv) |
412 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
431 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
413 | |
432 | |
… | |
… | |
421 | * The array has two arguments, the difficulty of the level, and the |
440 | * The array has two arguments, the difficulty of the level, and the |
422 | * magical bonus "wanted". |
441 | * magical bonus "wanted". |
423 | */ |
442 | */ |
424 | |
443 | |
425 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
444 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
426 | |
|
|
427 | // chance of magic difficulty |
445 | // chance of magic difficulty |
428 | // +0 +1 +2 +3 +4 |
446 | // +0 +1 +2 +3 +4 |
429 | {95, 2, 2, 1, 0}, // 1 |
447 | {95, 2, 2, 1, 0}, // 1 |
430 | {92, 5, 2, 1, 0}, // 2 |
448 | {92, 5, 2, 1, 0}, // 2 |
431 | {85, 10, 4, 1, 0}, // 3 |
449 | {85, 10, 4, 1, 0}, // 3 |
… | |
… | |
457 | { 0, 0, 0, 3, 97}, // 29 |
475 | { 0, 0, 0, 3, 97}, // 29 |
458 | { 0, 0, 0, 0, 100}, // 30 |
476 | { 0, 0, 0, 0, 100}, // 30 |
459 | { 0, 0, 0, 0, 100}, // 31 |
477 | { 0, 0, 0, 0, 100}, // 31 |
460 | }; |
478 | }; |
461 | |
479 | |
462 | |
|
|
463 | /* calculate the appropriate level for wands staves and scrolls. |
480 | /* calculate the appropriate level for wands staves and scrolls. |
464 | * This code presumes that op has had its spell object created (in op->inv) |
481 | * This code presumes that op has had its spell object created (in op->inv) |
465 | * |
482 | * |
466 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
483 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
467 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
484 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
468 | */ |
485 | */ |
469 | |
|
|
470 | int |
486 | int |
471 | level_for_item (const object *op, int difficulty) |
487 | level_for_item (const object *op, int difficulty) |
472 | { |
488 | { |
473 | int olevel = 0; |
489 | int olevel = 0; |
474 | |
490 | |
… | |
… | |
784 | save_item_power = op->item_power; |
800 | save_item_power = op->item_power; |
785 | op->item_power = 0; |
801 | op->item_power = 0; |
786 | |
802 | |
787 | if (op->randomitems && op->type != SPELL) |
803 | if (op->randomitems && op->type != SPELL) |
788 | { |
804 | { |
789 | create_treasure (op->randomitems, op, flags, difficulty, 0); |
805 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
790 | if (!op->inv) |
|
|
791 | LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ()); |
|
|
792 | |
|
|
793 | /* So the treasure doesn't get created again */ |
806 | /* So the treasure doesn't get created again */ |
794 | op->randomitems = 0; |
807 | op->randomitems = 0; |
795 | } |
808 | } |
796 | |
809 | |
797 | if (difficulty < 1) |
810 | if (difficulty < 1) |
… | |
… | |
1573 | if (change->msg) |
1586 | if (change->msg) |
1574 | op->msg = change->msg; |
1587 | op->msg = change->msg; |
1575 | } |
1588 | } |
1576 | |
1589 | |
1577 | static int |
1590 | static int |
1578 | legal_artifact_combination (object *op, artifact * art) |
1591 | legal_artifact_combination (object *op, artifact *art) |
1579 | { |
1592 | { |
1580 | int neg, success = 0; |
1593 | int neg, success = 0; |
1581 | linked_char *tmp; |
1594 | linked_char *tmp; |
1582 | const char *name; |
1595 | const char *name; |
1583 | |
1596 | |
1584 | if (art->allowed == (linked_char *) NULL) |
1597 | if (!art->allowed) |
1585 | return 1; /* Ie, "all" */ |
1598 | return 1; /* Ie, "all" */ |
|
|
1599 | |
1586 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1600 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1587 | { |
1601 | { |
1588 | #ifdef TREASURE_VERBOSE |
1602 | #ifdef TREASURE_VERBOSE |
1589 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1603 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1590 | #endif |
1604 | #endif |
… | |
… | |
1601 | * everything is allowed except what we match |
1615 | * everything is allowed except what we match |
1602 | */ |
1616 | */ |
1603 | else if (neg) |
1617 | else if (neg) |
1604 | success = 1; |
1618 | success = 1; |
1605 | } |
1619 | } |
|
|
1620 | |
1606 | return success; |
1621 | return success; |
1607 | } |
1622 | } |
1608 | |
1623 | |
1609 | /* |
1624 | /* |
1610 | * Fixes the given object, giving it the abilities and titles |
1625 | * Fixes the given object, giving it the abilities and titles |