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 | * |
… | |
… | |
54 | > tl_map_t; |
54 | > tl_map_t; |
55 | |
55 | |
56 | static tl_map_t tl_map; |
56 | static tl_map_t tl_map; |
57 | |
57 | |
58 | /* |
58 | /* |
59 | * Initialize global archtype pointers: |
|
|
60 | */ |
|
|
61 | void |
|
|
62 | init_archetype_pointers () |
|
|
63 | { |
|
|
64 | int prev_warn = warn_archetypes; |
|
|
65 | |
|
|
66 | warn_archetypes = 1; |
|
|
67 | |
|
|
68 | if (ring_arch == NULL) |
|
|
69 | ring_arch = archetype::find ("ring"); |
|
|
70 | if (amulet_arch == NULL) |
|
|
71 | amulet_arch = archetype::find ("amulet"); |
|
|
72 | if (staff_arch == NULL) |
|
|
73 | staff_arch = archetype::find ("staff"); |
|
|
74 | if (crown_arch == NULL) |
|
|
75 | crown_arch = archetype::find ("crown"); |
|
|
76 | |
|
|
77 | warn_archetypes = prev_warn; |
|
|
78 | } |
|
|
79 | |
|
|
80 | /* |
|
|
81 | * Searches for the given treasurelist |
59 | * Searches for the given treasurelist |
82 | */ |
60 | */ |
83 | treasurelist * |
61 | treasurelist * |
84 | treasurelist::find (const char *name) |
62 | treasurelist::find (const char *name) |
85 | { |
63 | { |
… | |
… | |
167 | coroapi::cede_to_tick_every (10); |
145 | coroapi::cede_to_tick_every (10); |
168 | |
146 | |
169 | switch (f.kw) |
147 | switch (f.kw) |
170 | { |
148 | { |
171 | case KW_arch: |
149 | case KW_arch: |
172 | if (!(t->item = archetype::find (f.get_str ()))) |
150 | t->item = archetype::get (f.get_str ()); |
173 | LOG (llevError, "%s:%d treasure references unknown archetype '%s', skipping.\n", f.name, f.linenum, f.get_str ()); |
|
|
174 | break; |
151 | break; |
175 | |
152 | |
176 | case KW_list: f.get (t->name); break; |
153 | case KW_list: f.get (t->name); break; |
177 | case KW_change_name: f.get (t->change_arch.name); break; |
154 | case KW_change_name: f.get (t->change_arch.name); break; |
178 | case KW_change_title: f.get (t->change_arch.title); break; |
155 | case KW_change_title: f.get (t->change_arch.title); break; |
… | |
… | |
253 | * start with equipment, but only their abilities). |
230 | * start with equipment, but only their abilities). |
254 | */ |
231 | */ |
255 | static void |
232 | static void |
256 | put_treasure (object *op, object *creator, int flags) |
233 | put_treasure (object *op, object *creator, int flags) |
257 | { |
234 | { |
258 | object *tmp; |
235 | if (flags & GT_ENVIRONMENT) |
259 | |
236 | { |
260 | /* 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 |
261 | * 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 |
262 | * 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 |
263 | * by another object. |
240 | * by another object. |
264 | */ |
241 | */ |
265 | if (flags & GT_ENVIRONMENT && op->type != SPELL) |
242 | //TODO: flag such as objects... as such (no drop, anybody?) |
266 | { |
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 | { |
267 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
255 | SET_FLAG (op, FLAG_OBJ_ORIGINAL); |
268 | 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 | } |
269 | } |
258 | } |
270 | else |
259 | else |
271 | { |
260 | { |
272 | op = creator->insert (op); |
261 | op = creator->insert (op); |
273 | |
262 | |
274 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
263 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
275 | monster_check_apply (creator, op); |
264 | monster_check_apply (creator, op); |
276 | |
265 | |
277 | if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) |
266 | if (flags & GT_UPDATE_INV) |
|
|
267 | if (object *tmp = creator->in_player ()) |
278 | esrv_send_item (tmp, op); |
268 | esrv_send_item (tmp, op); |
279 | } |
269 | } |
280 | } |
270 | } |
281 | |
271 | |
282 | /* 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 |
283 | * in the generated object |
273 | * in the generated object |
… | |
… | |
381 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
371 | fix_generated_item (tmp, op, difficulty, t->magic, flag); |
382 | change_treasure (t, tmp); |
372 | change_treasure (t, tmp); |
383 | put_treasure (tmp, op, flag); |
373 | put_treasure (tmp, op, flag); |
384 | } |
374 | } |
385 | } |
375 | } |
|
|
376 | } |
|
|
377 | |
|
|
378 | void |
|
|
379 | object::create_treasure (treasurelist *tl, int flags) |
|
|
380 | { |
|
|
381 | ::create_treasure (tl, this, flags, map ? map->difficulty : 0); |
386 | } |
382 | } |
387 | |
383 | |
388 | /* This calls the appropriate treasure creation function. tries is passed |
384 | /* This calls the appropriate treasure creation function. tries is passed |
389 | * to determine how many list transitions or attempts to create treasure |
385 | * to determine how many list transitions or attempts to create treasure |
390 | * have been made. It is really in place to prevent infinite loops with |
386 | * have been made. It is really in place to prevent infinite loops with |
… | |
… | |
419 | object * |
415 | object * |
420 | generate_treasure (treasurelist *tl, int difficulty) |
416 | generate_treasure (treasurelist *tl, int difficulty) |
421 | { |
417 | { |
422 | difficulty = clamp (difficulty, 1, settings.max_level); |
418 | difficulty = clamp (difficulty, 1, settings.max_level); |
423 | |
419 | |
424 | object *ob = object::create (), *tmp; |
420 | object *ob = object::create (); |
425 | |
421 | |
426 | create_treasure (tl, ob, 0, difficulty, 0); |
422 | create_treasure (tl, ob, 0, difficulty, 0); |
427 | |
423 | |
428 | /* Don't want to free the object we are about to return */ |
424 | /* Don't want to free the object we are about to return */ |
429 | tmp = ob->inv; |
425 | object *tmp = ob->inv; |
430 | if (tmp != NULL) |
426 | if (tmp) |
431 | tmp->remove (); |
427 | tmp->remove (); |
432 | |
428 | |
433 | if (ob->inv) |
429 | if (ob->inv) |
434 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
430 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
435 | |
431 | |
… | |
… | |
443 | * The array has two arguments, the difficulty of the level, and the |
439 | * The array has two arguments, the difficulty of the level, and the |
444 | * magical bonus "wanted". |
440 | * magical bonus "wanted". |
445 | */ |
441 | */ |
446 | |
442 | |
447 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
443 | static int difftomagic_list[DIFFLEVELS][MAXMAGIC + 1] = { |
448 | |
|
|
449 | // chance of magic difficulty |
444 | // chance of magic difficulty |
450 | // +0 +1 +2 +3 +4 |
445 | // +0 +1 +2 +3 +4 |
451 | {95, 2, 2, 1, 0}, // 1 |
446 | {95, 2, 2, 1, 0}, // 1 |
452 | {92, 5, 2, 1, 0}, // 2 |
447 | {92, 5, 2, 1, 0}, // 2 |
453 | {85, 10, 4, 1, 0}, // 3 |
448 | {85, 10, 4, 1, 0}, // 3 |
… | |
… | |
479 | { 0, 0, 0, 3, 97}, // 29 |
474 | { 0, 0, 0, 3, 97}, // 29 |
480 | { 0, 0, 0, 0, 100}, // 30 |
475 | { 0, 0, 0, 0, 100}, // 30 |
481 | { 0, 0, 0, 0, 100}, // 31 |
476 | { 0, 0, 0, 0, 100}, // 31 |
482 | }; |
477 | }; |
483 | |
478 | |
484 | |
|
|
485 | /* calculate the appropriate level for wands staves and scrolls. |
479 | /* calculate the appropriate level for wands staves and scrolls. |
486 | * This code presumes that op has had its spell object created (in op->inv) |
480 | * This code presumes that op has had its spell object created (in op->inv) |
487 | * |
481 | * |
488 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
482 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
489 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
483 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
490 | */ |
484 | */ |
491 | |
|
|
492 | int |
485 | int |
493 | level_for_item (const object *op, int difficulty) |
486 | level_for_item (const object *op, int difficulty) |
494 | { |
487 | { |
495 | int olevel = 0; |
488 | int olevel = 0; |
496 | |
489 | |
… | |
… | |
806 | save_item_power = op->item_power; |
799 | save_item_power = op->item_power; |
807 | op->item_power = 0; |
800 | op->item_power = 0; |
808 | |
801 | |
809 | if (op->randomitems && op->type != SPELL) |
802 | if (op->randomitems && op->type != SPELL) |
810 | { |
803 | { |
811 | create_treasure (op->randomitems, op, flags, difficulty, 0); |
804 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
812 | if (!op->inv) |
|
|
813 | LOG (llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->debug_desc ()); |
|
|
814 | |
|
|
815 | /* So the treasure doesn't get created again */ |
805 | /* So the treasure doesn't get created again */ |
816 | op->randomitems = 0; |
806 | op->randomitems = 0; |
817 | } |
807 | } |
818 | |
808 | |
819 | if (difficulty < 1) |
809 | if (difficulty < 1) |
… | |
… | |
1349 | break; |
1339 | break; |
1350 | |
1340 | |
1351 | case KW_object: |
1341 | case KW_object: |
1352 | { |
1342 | { |
1353 | art->item = object::create (); |
1343 | art->item = object::create (); |
|
|
1344 | f.get (art->item->name); |
|
|
1345 | f.next (); |
1354 | |
1346 | |
1355 | if (!art->item->parse_kv (f)) |
1347 | if (!art->item->parse_kv (f)) |
1356 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1348 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1357 | |
1349 | |
1358 | al = find_artifactlist (art->item->type); |
1350 | al = find_artifactlist (art->item->type); |
… | |
… | |
1593 | if (change->msg) |
1585 | if (change->msg) |
1594 | op->msg = change->msg; |
1586 | op->msg = change->msg; |
1595 | } |
1587 | } |
1596 | |
1588 | |
1597 | static int |
1589 | static int |
1598 | legal_artifact_combination (object *op, artifact * art) |
1590 | legal_artifact_combination (object *op, artifact *art) |
1599 | { |
1591 | { |
1600 | int neg, success = 0; |
1592 | int neg, success = 0; |
1601 | linked_char *tmp; |
1593 | linked_char *tmp; |
1602 | const char *name; |
1594 | const char *name; |
1603 | |
1595 | |
1604 | if (art->allowed == (linked_char *) NULL) |
1596 | if (!art->allowed) |
1605 | return 1; /* Ie, "all" */ |
1597 | return 1; /* Ie, "all" */ |
|
|
1598 | |
1606 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1599 | for (tmp = art->allowed; tmp; tmp = tmp->next) |
1607 | { |
1600 | { |
1608 | #ifdef TREASURE_VERBOSE |
1601 | #ifdef TREASURE_VERBOSE |
1609 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1602 | LOG (llevDebug, "legal_art: %s\n", &tmp->name); |
1610 | #endif |
1603 | #endif |
… | |
… | |
1621 | * everything is allowed except what we match |
1614 | * everything is allowed except what we match |
1622 | */ |
1615 | */ |
1623 | else if (neg) |
1616 | else if (neg) |
1624 | success = 1; |
1617 | success = 1; |
1625 | } |
1618 | } |
|
|
1619 | |
1626 | return success; |
1620 | return success; |
1627 | } |
1621 | } |
1628 | |
1622 | |
1629 | /* |
1623 | /* |
1630 | * Fixes the given object, giving it the abilities and titles |
1624 | * Fixes the given object, giving it the abilities and titles |