… | |
… | |
258 | shstr_cmp name_ (name); |
258 | shstr_cmp name_ (name); |
259 | |
259 | |
260 | if (!name_) |
260 | if (!name_) |
261 | return 0; |
261 | return 0; |
262 | |
262 | |
263 | for (treasurelist * tl = first_treasurelist; tl != 0; tl = tl->next) |
263 | for (treasurelist *tl = first_treasurelist; tl != 0; tl = tl->next) |
264 | if (name_ == tl->name) |
264 | if (name_ == tl->name) |
265 | return tl; |
265 | return tl; |
266 | |
266 | |
267 | if (first_treasurelist) |
267 | if (first_treasurelist) |
268 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
268 | LOG (llevError, "Couldn't find treasurelist %s\n", name); |
… | |
… | |
280 | * being generated. |
280 | * being generated. |
281 | * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only |
281 | * If flag is GT_INVISIBLE, only invisible objects are generated (ie, only |
282 | * abilities. This is used by summon spells, thus no summoned monsters |
282 | * abilities. This is used by summon spells, thus no summoned monsters |
283 | * start with equipment, but only their abilities). |
283 | * start with equipment, but only their abilities). |
284 | */ |
284 | */ |
285 | |
|
|
286 | |
|
|
287 | static void |
285 | static void |
288 | put_treasure (object *op, object *creator, int flags) |
286 | put_treasure (object *op, object *creator, int flags) |
289 | { |
287 | { |
290 | object *tmp; |
288 | object *tmp; |
291 | |
289 | |
… | |
… | |
302 | insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
300 | insert_ob_in_map (op, creator->map, op, INS_NO_MERGE | INS_NO_WALK_ON); |
303 | } |
301 | } |
304 | else |
302 | else |
305 | { |
303 | { |
306 | op = insert_ob_in_ob (op, creator); |
304 | op = insert_ob_in_ob (op, creator); |
|
|
305 | |
307 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
306 | if ((flags & GT_APPLY) && QUERY_FLAG (creator, FLAG_MONSTER)) |
308 | monster_check_apply (creator, op); |
307 | monster_check_apply (creator, op); |
|
|
308 | |
309 | if ((flags & GT_UPDATE_INV) && (tmp = is_player_inv (creator)) != NULL) |
309 | if ((flags & GT_UPDATE_INV) && (tmp = creator->in_player ())) |
310 | esrv_send_item (tmp, op); |
310 | esrv_send_item (tmp, op); |
311 | } |
311 | } |
312 | } |
312 | } |
313 | |
313 | |
314 | /* if there are change_xxx commands in the treasure, we include the changes |
314 | /* if there are change_xxx commands in the treasure, we include the changes |
… | |
… | |
339 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
339 | if ((int) t->chance >= 100 || (RANDOM () % 100 + 1) < (int) t->chance) |
340 | { |
340 | { |
341 | if (t->name) |
341 | if (t->name) |
342 | { |
342 | { |
343 | 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) |
344 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
347 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
348 | } |
345 | } |
349 | } |
346 | else |
350 | else |
347 | { |
351 | { |
348 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
352 | if (t->item->clone.invisible != 0 || !(flag & GT_INVISIBLE)) |
349 | { |
353 | { |
… | |
… | |
397 | { |
401 | { |
398 | if (!strcmp (t->name, "NONE")) |
402 | if (!strcmp (t->name, "NONE")) |
399 | return; |
403 | return; |
400 | |
404 | |
401 | if (difficulty >= t->magic) |
405 | if (difficulty >= t->magic) |
|
|
406 | { |
|
|
407 | treasurelist *tl = find_treasurelist (t->name); |
|
|
408 | if (tl) |
402 | create_treasure (find_treasurelist (t->name), op, flag, difficulty, tries); |
409 | create_treasure (tl, op, flag, difficulty, tries); |
|
|
410 | } |
403 | else if (t->nrof) |
411 | else if (t->nrof) |
404 | create_one_treasure (tl, op, flag, difficulty, tries); |
412 | create_one_treasure (tl, op, flag, difficulty, tries); |
405 | |
413 | |
406 | return; |
414 | return; |
407 | } |
415 | } |
… | |
… | |
448 | * 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 |
449 | * create_treasure. We create a dummy object that the treasure gets |
457 | * create_treasure. We create a dummy object that the treasure gets |
450 | * inserted into, and then return that treausre |
458 | * inserted into, and then return that treausre |
451 | */ |
459 | */ |
452 | object * |
460 | object * |
453 | generate_treasure (treasurelist * t, int difficulty) |
461 | generate_treasure (treasurelist *t, int difficulty) |
454 | { |
462 | { |
|
|
463 | difficulty = clamp (difficulty, 1, settings.max_level); |
|
|
464 | |
455 | object *ob = get_object (), *tmp; |
465 | object *ob = object::create (), *tmp; |
456 | |
466 | |
457 | create_treasure (t, ob, 0, difficulty, 0); |
467 | create_treasure (t, ob, 0, difficulty, 0); |
458 | |
468 | |
459 | /* 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 */ |
460 | tmp = ob->inv; |
470 | tmp = ob->inv; |
461 | if (tmp != NULL) |
471 | if (tmp != NULL) |
462 | remove_ob (tmp); |
472 | tmp->remove (); |
|
|
473 | |
463 | if (ob->inv) |
474 | if (ob->inv) |
464 | { |
|
|
465 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
475 | LOG (llevError, "In generate treasure, created multiple objects.\n"); |
466 | } |
476 | |
467 | free_object (ob); |
477 | ob->destroy (); |
468 | return tmp; |
478 | return tmp; |
469 | } |
479 | } |
470 | |
480 | |
471 | /* |
481 | /* |
472 | * 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 |
… | |
… | |
849 | } |
859 | } |
850 | |
860 | |
851 | if (difficulty < 1) |
861 | if (difficulty < 1) |
852 | difficulty = 1; |
862 | difficulty = 1; |
853 | |
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 | |
854 | if (!(flags & GT_MINIMAL)) |
870 | if (!(flags & GT_MINIMAL)) |
855 | { |
871 | { |
856 | if (op->arch == crown_arch) |
872 | if (op->arch == crown_arch) |
857 | { |
873 | { |
858 | set_magic (difficulty, op, max_magic, flags); |
874 | set_magic (difficulty, op, max_magic, flags); |
… | |
… | |
993 | op->value *= 5; /* Since it's not just decoration */ |
1009 | op->value *= 5; /* Since it's not just decoration */ |
994 | |
1010 | |
995 | case RING: |
1011 | case RING: |
996 | if (op->arch == NULL) |
1012 | if (op->arch == NULL) |
997 | { |
1013 | { |
998 | remove_ob (op); |
1014 | op->destroy (); |
999 | free_object (op); |
|
|
1000 | op = NULL; |
1015 | op = 0; |
1001 | break; |
1016 | break; |
1002 | } |
1017 | } |
1003 | |
1018 | |
1004 | 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! */ |
1005 | break; |
1020 | break; |
… | |
… | |
1257 | { |
1272 | { |
1258 | for (i = 0; i < depth; i++) |
1273 | for (i = 0; i < depth; i++) |
1259 | fprintf (logfile, " "); |
1274 | fprintf (logfile, " "); |
1260 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1275 | fprintf (logfile, "{ (list: %s)\n", &t->name); |
1261 | tl = find_treasurelist (t->name); |
1276 | tl = find_treasurelist (t->name); |
|
|
1277 | if (tl) |
1262 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1278 | dump_monster_treasure_rec (name, tl->items, depth + 2); |
1263 | for (i = 0; i < depth; i++) |
1279 | for (i = 0; i < depth; i++) |
1264 | fprintf (logfile, " "); |
1280 | fprintf (logfile, " "); |
1265 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1281 | fprintf (logfile, "} (end of list: %s)\n", &t->name); |
1266 | } |
1282 | } |
1267 | else |
1283 | else |
… | |
… | |
1384 | art->chance = (uint16) value; |
1400 | art->chance = (uint16) value; |
1385 | else if (sscanf (cp, "difficulty %d", &value)) |
1401 | else if (sscanf (cp, "difficulty %d", &value)) |
1386 | art->difficulty = (uint8) value; |
1402 | art->difficulty = (uint8) value; |
1387 | else if (!strncmp (cp, "Object", 6)) |
1403 | else if (!strncmp (cp, "Object", 6)) |
1388 | { |
1404 | { |
1389 | art->item = get_object (); |
1405 | art->item = object::create (); |
1390 | |
1406 | |
1391 | if (!load_object (thawer, art->item, 0)) |
1407 | if (!load_object (thawer, art->item, 0)) |
1392 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1408 | LOG (llevError, "Init_Artifacts: Could not load object.\n"); |
1393 | |
1409 | |
1394 | art->item->name = strchr (cp, ' ') + 1; |
1410 | art->item->name = strchr (cp, ' ') + 1; |
… | |
… | |
1483 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1499 | CLEAR_FLAG (op, FLAG_ANIMATE); |
1484 | /* so artifacts will join */ |
1500 | /* so artifacts will join */ |
1485 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1501 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
1486 | op->speed = 0.0; |
1502 | op->speed = 0.0; |
1487 | |
1503 | |
1488 | update_ob_speed (op); |
1504 | op->set_speed (op->speed); |
1489 | } |
1505 | } |
1490 | |
1506 | |
1491 | if (change->nrof) |
1507 | if (change->nrof) |
1492 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
1508 | op->nrof = RANDOM () % ((int) change->nrof) + 1; |
1493 | |
1509 | |
… | |
… | |
1505 | { |
1521 | { |
1506 | object *tmp_obj; |
1522 | object *tmp_obj; |
1507 | |
1523 | |
1508 | /* Remove any spells this object currently has in it */ |
1524 | /* Remove any spells this object currently has in it */ |
1509 | while (op->inv) |
1525 | while (op->inv) |
1510 | { |
1526 | op->inv->destroy (); |
1511 | tmp_obj = op->inv; |
|
|
1512 | remove_ob (tmp_obj); |
|
|
1513 | free_object (tmp_obj); |
|
|
1514 | } |
|
|
1515 | |
1527 | |
1516 | tmp_obj = arch_to_object (change->other_arch); |
1528 | tmp_obj = arch_to_object (change->other_arch); |
1517 | insert_ob_in_ob (tmp_obj, op); |
1529 | insert_ob_in_ob (tmp_obj, op); |
1518 | } |
1530 | } |
1519 | /* No harm setting this for potions/horns */ |
1531 | /* No harm setting this for potions/horns */ |
… | |
… | |
1556 | 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; |
1557 | |
1569 | |
1558 | op->item_power = change->item_power; |
1570 | op->item_power = change->item_power; |
1559 | |
1571 | |
1560 | for (i = 0; i < NROFATTACKS; i++) |
1572 | for (i = 0; i < NROFATTACKS; i++) |
1561 | { |
|
|
1562 | if (change->resist[i]) |
1573 | if (change->resist[i]) |
1563 | { |
|
|
1564 | op->resist[i] += change->resist[i]; |
1574 | op->resist[i] += change->resist[i]; |
1565 | } |
|
|
1566 | } |
|
|
1567 | |
1575 | |
1568 | if (change->stats.dam) |
1576 | if (change->stats.dam) |
1569 | { |
1577 | { |
1570 | if (change->stats.dam < 0) |
1578 | if (change->stats.dam < 0) |
1571 | op->stats.dam = (-change->stats.dam); |
1579 | op->stats.dam = (-change->stats.dam); |
… | |
… | |
1849 | free_artifact (at->next); |
1857 | free_artifact (at->next); |
1850 | |
1858 | |
1851 | if (at->allowed) |
1859 | if (at->allowed) |
1852 | free_charlinks (at->allowed); |
1860 | free_charlinks (at->allowed); |
1853 | |
1861 | |
1854 | at->item->free (1); |
1862 | at->item->destroy (1); |
1855 | |
1863 | |
1856 | delete at; |
1864 | delete at; |
1857 | } |
1865 | } |
1858 | |
1866 | |
1859 | void |
1867 | void |
1860 | free_artifactlist (artifactlist * al) |
1868 | free_artifactlist (artifactlist * al) |
1861 | { |
1869 | { |
1862 | artifactlist *nextal; |
1870 | artifactlist *nextal; |
1863 | |
1871 | |
1864 | for (al = first_artifactlist; al != NULL; al = nextal) |
1872 | for (al = first_artifactlist; al; al = nextal) |
1865 | { |
1873 | { |
1866 | nextal = al->next; |
1874 | nextal = al->next; |
1867 | |
1875 | |
1868 | if (al->items) |
1876 | if (al->items) |
1869 | free_artifact (al->items); |
1877 | free_artifact (al->items); |