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; |
… | |
… | |
231 | * start with equipment, but only their abilities). |
230 | * start with equipment, but only their abilities). |
232 | */ |
231 | */ |
233 | static void |
232 | static void |
234 | put_treasure (object *op, object *creator, int flags) |
233 | put_treasure (object *op, object *creator, int flags) |
235 | { |
234 | { |
236 | object *tmp; |
235 | if (flags & GT_ENVIRONMENT) |
237 | |
236 | { |
238 | /* Bit of a hack - spells should never be put onto the map. The entire |
237 | /* 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 |
238 | * 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 |
239 | * this is the original object, or if this is an object that should be created |
241 | * by another object. |
240 | * by another object. |
242 | */ |
241 | */ |
243 | if (flags & GT_ENVIRONMENT && op->type != SPELL) |
242 | //TODO: flag such as objects... as such (no drop, anybody?) |
244 | { |
243 | if (op->type == SPELL) |
|
|
244 | { |
|
|
245 | op->destroy (); |
|
|
246 | return; |
|
|
247 | } |
|
|
248 | |
|
|
249 | op->expand_tail (); |
|
|
250 | |
|
|
251 | if (ob_blocked (op, creator->map, creator->x, creator->y)) |
|
|
252 | op->destroy (); |
|
|
253 | else |
|
|
254 | { |
245 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
255 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
246 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
256 | op->insert_at (creator, creator, INS_NO_MERGE | INS_NO_WALK_ON); |
|
|
257 | } |
247 | } |
258 | } |
248 | else |
259 | else |
249 | { |
260 | { |
250 | op = creator->insert (op); |
261 | op = creator->insert (op); |
251 | |
262 | |
252 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
263 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
253 | monster_check_apply (creator, op); |
264 | monster_check_apply (creator, op); |
254 | |
265 | |
255 | if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) |
266 | if (flags & GT_UPDATE_INV) |
|
|
267 | if (object *tmp = creator->in_player ()) |
256 | esrv_send_item (tmp, op); |
268 | esrv_send_item (tmp, op); |
257 | } |
269 | } |
258 | } |
270 | } |
259 | |
271 | |
260 | /* if there are change_xxx commands in the treasure, we include the changes |
272 | /* if there are change_xxx commands in the treasure, we include the changes |
261 | * in the generated object |
273 | * in the generated object |
… | |
… | |
397 | object * |
409 | object * |
398 | generate_treasure (treasurelist *tl, int difficulty) |
410 | generate_treasure (treasurelist *tl, int difficulty) |
399 | { |
411 | { |
400 | difficulty = clamp (difficulty, 1, settings.max_level); |
412 | difficulty = clamp (difficulty, 1, settings.max_level); |
401 | |
413 | |
402 | object *ob = object::create (), *tmp; |
414 | object *ob = object::create (); |
403 | |
415 | |
404 | create_treasure (tl, ob, 0, difficulty, 0); |
416 | create_treasure (tl, ob, 0, difficulty, 0); |
405 | |
417 | |
406 | /* Don't want to free the object we are about to return */ |
418 | /* Don't want to free the object we are about to return */ |
407 | tmp = ob->inv; |
419 | object *tmp = ob->inv; |
408 | if (tmp != NULL) |
420 | if (tmp) |
409 | tmp->remove (); |
421 | tmp->remove (); |
410 | |
422 | |
411 | if (ob->inv) |
423 | if (ob->inv) |
412 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
424 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
413 | |
425 | |
… | |
… | |
421 | * The array has two arguments, the difficulty of the level, and the |
433 | * The array has two arguments, the difficulty of the level, and the |
422 | * magical bonus "wanted". |
434 | * magical bonus "wanted". |
423 | */ |
435 | */ |
424 | |
436 | |
425 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
437 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
426 | |
|
|
427 | // chance of magic difficulty |
438 | // chance of magic difficulty |
428 | // +0 +1 +2 +3 +4 |
439 | // +0 +1 +2 +3 +4 |
429 | {95, 2, 2, 1, 0}, // 1 |
440 | {95, 2, 2, 1, 0}, // 1 |
430 | {92, 5, 2, 1, 0}, // 2 |
441 | {92, 5, 2, 1, 0}, // 2 |
431 | {85, 10, 4, 1, 0}, // 3 |
442 | {85, 10, 4, 1, 0}, // 3 |
… | |
… | |
457 | { 0, 0, 0, 3, 97}, // 29 |
468 | { 0, 0, 0, 3, 97}, // 29 |
458 | { 0, 0, 0, 0, 100}, // 30 |
469 | { 0, 0, 0, 0, 100}, // 30 |
459 | { 0, 0, 0, 0, 100}, // 31 |
470 | { 0, 0, 0, 0, 100}, // 31 |
460 | }; |
471 | }; |
461 | |
472 | |
462 | |
|
|
463 | /* calculate the appropriate level for wands staves and scrolls. |
473 | /* calculate the appropriate level for wands staves and scrolls. |
464 | * This code presumes that op has had its spell object created (in op->inv) |
474 | * This code presumes that op has had its spell object created (in op->inv) |
465 | * |
475 | * |
466 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
476 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
467 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
477 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
468 | */ |
478 | */ |
469 | |
|
|
470 | int |
479 | int |
471 | level_for_item (const object *op, int difficulty) |
480 | level_for_item (const object *op, int difficulty) |
472 | { |
481 | { |
473 | int olevel = 0; |
482 | int olevel = 0; |
474 | |
483 | |
… | |
… | |
784 | save_item_power = op->item_power; |
793 | save_item_power = op->item_power; |
785 | op->item_power = 0; |
794 | op->item_power = 0; |
786 | |
795 | |
787 | if (op->randomitems && op->type != SPELL) |
796 | if (op->randomitems && op->type != SPELL) |
788 | { |
797 | { |
789 | create_treasure (op->randomitems, op, flags, difficulty, 0); |
798 | 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 */ |
799 | /* So the treasure doesn't get created again */ |
794 | op->randomitems = 0; |
800 | op->randomitems = 0; |
795 | } |
801 | } |
796 | |
802 | |
797 | if (difficulty < 1) |
803 | if (difficulty < 1) |
… | |
… | |
1573 | if (change->msg) |
1579 | if (change->msg) |
1574 | op->msg = change->msg; |
1580 | op->msg = change->msg; |
1575 | } |
1581 | } |
1576 | |
1582 | |
1577 | static int |
1583 | static int |
1578 | legal_artifact_combination (object *op, artifact * art) |
1584 | legal_artifact_combination (object *op, artifact *art) |
1579 | { |
1585 | { |
1580 | int neg, success = 0; |
1586 | int neg, success = 0; |
1581 | linked_char *tmp; |
1587 | linked_char *tmp; |
1582 | const char *name; |
1588 | const char *name; |
1583 | |
1589 | |
1584 | if (art->allowed == (linked_char *) NULL) |
1590 | if (!art->allowed) |
1585 | return 1; /* Ie, "all" */ |
1591 | return 1; /* Ie, "all" */ |
|
|
1592 | |
1586 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1593 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1587 | { |
1594 | { |
1588 | #ifdef TREASURE_VERBOSE |
1595 | #ifdef TREASURE_VERBOSE |
1589 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1596 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1590 | #endif |
1597 | #endif |
… | |
… | |
1601 | * everything is allowed except what we match |
1608 | * everything is allowed except what we match |
1602 | */ |
1609 | */ |
1603 | else if (neg) |
1610 | else if (neg) |
1604 | success = 1; |
1611 | success = 1; |
1605 | } |
1612 | } |
|
|
1613 | |
1606 | return success; |
1614 | return success; |
1607 | } |
1615 | } |
1608 | |
1616 | |
1609 | /* |
1617 | /* |
1610 | * Fixes the given object, giving it the abilities and titles |
1618 | * Fixes the given object, giving it the abilities and titles |