1 | |
|
|
2 | /* |
|
|
3 | * static char *rcs_treasure_c = |
|
|
4 | * "$Id: treasure.C,v 1.16 2006/09/10 16:00:23 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #define ALLOWED_COMBINATION |
24 | #define ALLOWED_COMBINATION |
31 | |
25 | |
32 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
26 | /* TREASURE_DEBUG does some checking on the treasurelists after loading. |
… | |
… | |
58 | { |
52 | { |
59 | int prev_warn = warn_archetypes; |
53 | int prev_warn = warn_archetypes; |
60 | |
54 | |
61 | warn_archetypes = 1; |
55 | warn_archetypes = 1; |
62 | if (ring_arch == NULL) |
56 | if (ring_arch == NULL) |
63 | ring_arch = find_archetype ("ring"); |
57 | ring_arch = archetype::find ("ring"); |
64 | if (amulet_arch == NULL) |
58 | if (amulet_arch == NULL) |
65 | amulet_arch = find_archetype ("amulet"); |
59 | amulet_arch = archetype::find ("amulet"); |
66 | if (staff_arch == NULL) |
60 | if (staff_arch == NULL) |
67 | staff_arch = find_archetype ("staff"); |
61 | staff_arch = archetype::find ("staff"); |
68 | if (crown_arch == NULL) |
62 | if (crown_arch == NULL) |
69 | crown_arch = find_archetype ("crown"); |
63 | crown_arch = archetype::find ("crown"); |
70 | warn_archetypes = prev_warn; |
64 | warn_archetypes = prev_warn; |
71 | } |
65 | } |
72 | |
66 | |
73 | /* |
67 | /* |
74 | * Allocate and return the pointer to an empty treasurelist structure. |
68 | * Allocate and return the pointer to an empty treasurelist structure. |
… | |
… | |
119 | while (isspace (*cp)) /* Skip blanks */ |
113 | while (isspace (*cp)) /* Skip blanks */ |
120 | cp++; |
114 | cp++; |
121 | |
115 | |
122 | if (sscanf (cp, "arch %s", variable)) |
116 | if (sscanf (cp, "arch %s", variable)) |
123 | { |
117 | { |
124 | if ((t->item = find_archetype (variable)) == NULL) |
118 | if ((t->item = archetype::find (variable)) == NULL) |
125 | LOG (llevError, "Treasure lacks archetype: %s\n", variable); |
119 | LOG (llevError, "Treasure lacks archetype: %s\n", variable); |
126 | } |
120 | } |
127 | else if (sscanf (cp, "list %s", variable)) |
121 | else if (sscanf (cp, "list %s", variable)) |
128 | t->name = variable; |
122 | t->name = variable; |
129 | else if (sscanf (cp, "change_name %s", variable)) |
123 | else if (sscanf (cp, "change_name %s", variable)) |
… | |
… | |
259 | */ |
253 | */ |
260 | |
254 | |
261 | treasurelist * |
255 | treasurelist * |
262 | find_treasurelist (const char *name) |
256 | find_treasurelist (const char *name) |
263 | { |
257 | { |
264 | /* Special cases - randomitems of NULL is to override default. If |
258 | shstr_cmp name_ (name); |
265 | * first_treasurelist is null, it means we are on the first pass of |
259 | |
266 | * of loading archetypes, so for now, just return - second pass will |
|
|
267 | * init these values. |
|
|
268 | */ |
|
|
269 | if (!name) |
260 | if (!name_) |
270 | return 0; |
261 | return 0; |
271 | |
262 | |
272 | if (const char *tmp = shstr::find (name)) |
|
|
273 | for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) |
263 | for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) |
274 | if (tmp == tl->name) |
264 | if (name_ == tl->name) |
275 | return tl; |
265 | return tl; |
276 | |
266 | |
277 | if (first_treasurelist) |
267 | if (first_treasurelist) |
278 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
268 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
279 | |
269 | |
280 | return 0; |
270 | return 0; |
… | |
… | |
349 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
339 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
350 | { |
340 | { |
351 | if (t->name) |
341 | if (t->name) |
352 | { |
342 | { |
353 | if (strcmp (t->name, "NONE") && difficulty >= t->magic) |
343 | if (strcmp (t->name, "NONE") && difficulty >= t->magic) |
|
|
344 | { |
|
|
345 | treasurelist *tl = find_treasurelist (t->name); |
|
|
346 | if (tl) |
354 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
347 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
348 | } |
355 | } |
349 | } |
356 | else |
350 | else |
357 | { |
351 | { |
358 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
352 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
359 | { |
353 | { |
… | |
… | |
407 | { |
401 | { |
408 | if (!strcmp (t->name, "NONE")) |
402 | if (!strcmp (t->name, "NONE")) |
409 | return; |
403 | return; |
410 | |
404 | |
411 | if (difficulty >= t->magic) |
405 | if (difficulty >= t->magic) |
|
|
406 | { |
|
|
407 | treasurelist *tl = find_treasurelist (t->name); |
|
|
408 | if (tl) |
412 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
409 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
410 | } |
413 | else if (t->nrof) |
411 | else if (t->nrof) |
414 | create_one_treasure (tl, op, flag, difficulty, tries); |
412 | create_one_treasure (tl, op, flag, difficulty, tries); |
415 | |
413 | |
416 | return; |
414 | return; |
417 | } |
415 | } |
… | |
… | |
458 | * it instead takes a treasurelist. It is really just a wrapper around |
456 | * it instead takes a treasurelist. It is really just a wrapper around |
459 | * create_treasure. We create a dummy object that the treasure gets |
457 | * create_treasure. We create a dummy object that the treasure gets |
460 | * inserted into, and then return that treausre |
458 | * inserted into, and then return that treausre |
461 | */ |
459 | */ |
462 | object * |
460 | object * |
463 | generate_treasure (treasurelist * t, int difficulty) |
461 | generate_treasure (treasurelist *t, int difficulty) |
464 | { |
462 | { |
|
|
463 | difficulty = clamp (difficulty, 1, settings.max_level); |
|
|
464 | |
465 | object *ob = get_object (), *tmp; |
465 | object *ob = object::create (), *tmp; |
466 | |
466 | |
467 | create_treasure (t, ob, 0, difficulty, 0); |
467 | create_treasure (t, ob, 0, difficulty, 0); |
468 | |
468 | |
469 | /* Don't want to free the object we are about to return */ |
469 | /* Don't want to free the object we are about to return */ |
470 | tmp = ob->inv; |
470 | tmp = ob->inv; |
471 | if (tmp != NULL) |
471 | if (tmp != NULL) |
472 | remove_ob (tmp); |
472 | tmp->remove (); |
|
|
473 | |
473 | if (ob->inv) |
474 | if (ob->inv) |
474 | { |
|
|
475 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
475 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
476 | } |
476 | |
477 | free_object (ob); |
477 | ob->destroy (); |
478 | return tmp; |
478 | return tmp; |
479 | } |
479 | } |
480 | |
480 | |
481 | /* |
481 | /* |
482 | * This is a new way of calculating the chance for an item to have |
482 | * This is a new way of calculating the chance for an item to have |
… | |
… | |
859 | } |
859 | } |
860 | |
860 | |
861 | if (difficulty < 1) |
861 | if (difficulty < 1) |
862 | difficulty = 1; |
862 | difficulty = 1; |
863 | |
863 | |
|
|
864 | if (INVOKE_OBJECT (ADD_BONUS, op, |
|
|
865 | ARG_OBJECT (creator != op ? creator : 0), |
|
|
866 | ARG_INT (difficulty), ARG_INT (max_magic), |
|
|
867 | ARG_INT (flags))) |
|
|
868 | return; |
|
|
869 | |
864 | if (!(flags & GT_MINIMAL)) |
870 | if (!(flags & GT_MINIMAL)) |
865 | { |
871 | { |
866 | if (op->arch == crown_arch) |
872 | if (op->arch == crown_arch) |
867 | { |
873 | { |
868 | set_magic (difficulty, op, max_magic, flags); |
874 | set_magic (difficulty, op, max_magic, flags); |
… | |
… | |
1003 | op->value *= 5; /* Since it's not just decoration */ |
1009 | op->value *= 5; /* Since it's not just decoration */ |
1004 | |
1010 | |
1005 | case RING: |
1011 | case RING: |
1006 | if (op->arch == NULL) |
1012 | if (op->arch == NULL) |
1007 | { |
1013 | { |
1008 | remove_ob (op); |
1014 | op->destroy (); |
1009 | free_object (op); |
|
|
1010 | op = NULL; |
1015 | op = 0; |
1011 | break; |
1016 | break; |
1012 | } |
1017 | } |
1013 | |
1018 | |
1014 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1019 | if (op->arch != ring_arch && op->arch != amulet_arch) /* It's a special artifact! */ |
1015 | break; |
1020 | break; |
… | |
… | |
1267 | { |
1272 | { |
1268 | for (i = 0; i < depth; i++) |
1273 | for (i = 0; i < depth; i++) |
1269 | fprintf (logfile, " "); |
1274 | fprintf (logfile, " "); |
1270 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1275 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1271 | tl = find_treasurelist (t->name); |
1276 | tl = find_treasurelist (t->name); |
|
|
1277 | if (tl) |
1272 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1278 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1273 | for (i = 0; i < depth; i++) |
1279 | for (i = 0; i < depth; i++) |
1274 | fprintf (logfile, " "); |
1280 | fprintf (logfile, " "); |
1275 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1281 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1276 | } |
1282 | } |
1277 | else |
1283 | else |
… | |
… | |
1394 | art->chance = (uint16) value; |
1400 | art->chance = (uint16) value; |
1395 | else if (sscanf (cp, "difficulty %d", &value)) |
1401 | else if (sscanf (cp, "difficulty %d", &value)) |
1396 | art->difficulty = (uint8) value; |
1402 | art->difficulty = (uint8) value; |
1397 | else if (!strncmp (cp, "Object", 6)) |
1403 | else if (!strncmp (cp, "Object", 6)) |
1398 | { |
1404 | { |
1399 | art->item = get_object (); |
1405 | art->item = object::create (); |
1400 | |
1406 | |
1401 | if (!load_object (thawer, art->item, 0)) |
1407 | if (!load_object (thawer, art->item, 0)) |
1402 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1408 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1403 | |
1409 | |
1404 | art->item->name = strchr (cp, ' ') + 1; |
1410 | art->item->name = strchr (cp, ' ') + 1; |
… | |
… | |
1515 | { |
1521 | { |
1516 | object *tmp_obj; |
1522 | object *tmp_obj; |
1517 | |
1523 | |
1518 | /* Remove any spells this object currently has in it */ |
1524 | /* Remove any spells this object currently has in it */ |
1519 | while (op->inv) |
1525 | while (op->inv) |
1520 | { |
1526 | op->inv->destroy (); |
1521 | tmp_obj = op->inv; |
|
|
1522 | remove_ob (tmp_obj); |
|
|
1523 | free_object (tmp_obj); |
|
|
1524 | } |
|
|
1525 | |
1527 | |
1526 | tmp_obj = arch_to_object (change->other_arch); |
1528 | tmp_obj = arch_to_object (change->other_arch); |
1527 | insert_ob_in_ob (tmp_obj, op); |
1529 | insert_ob_in_ob (tmp_obj, op); |
1528 | } |
1530 | } |
1529 | /* No harm setting this for potions/horns */ |
1531 | /* No harm setting this for potions/horns */ |
… | |
… | |
1566 | op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; |
1568 | op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; |
1567 | |
1569 | |
1568 | op->item_power = change->item_power; |
1570 | op->item_power = change->item_power; |
1569 | |
1571 | |
1570 | for (i = 0; i < NROFATTACKS; i++) |
1572 | for (i = 0; i < NROFATTACKS; i++) |
1571 | { |
|
|
1572 | if (change->resist[i]) |
1573 | if (change->resist[i]) |
1573 | { |
|
|
1574 | op->resist[i] += change->resist[i]; |
1574 | op->resist[i] += change->resist[i]; |
1575 | } |
|
|
1576 | } |
|
|
1577 | |
1575 | |
1578 | if (change->stats.dam) |
1576 | if (change->stats.dam) |
1579 | { |
1577 | { |
1580 | if (change->stats.dam < 0) |
1578 | if (change->stats.dam < 0) |
1581 | op->stats.dam = (-change->stats.dam); |
1579 | op->stats.dam = (-change->stats.dam); |
… | |
… | |
1859 | free_artifact (at->next); |
1857 | free_artifact (at->next); |
1860 | |
1858 | |
1861 | if (at->allowed) |
1859 | if (at->allowed) |
1862 | free_charlinks (at->allowed); |
1860 | free_charlinks (at->allowed); |
1863 | |
1861 | |
1864 | at->item->free (1); |
1862 | at->item->destroy (1); |
1865 | |
1863 | |
1866 | delete at; |
1864 | delete at; |
1867 | } |
1865 | } |
1868 | |
1866 | |
1869 | void |
1867 | void |
1870 | free_artifactlist (artifactlist * al) |
1868 | free_artifactlist (artifactlist * al) |
1871 | { |
1869 | { |
1872 | artifactlist *nextal; |
1870 | artifactlist *nextal; |
1873 | |
1871 | |
1874 | for (al = first_artifactlist; al != NULL; al = nextal) |
1872 | for (al = first_artifactlist; al; al = nextal) |
1875 | { |
1873 | { |
1876 | nextal = al->next; |
1874 | nextal = al->next; |
1877 | |
1875 | |
1878 | if (al->items) |
1876 | if (al->items) |
1879 | free_artifact (al->items); |
1877 | free_artifact (al->items); |