… | |
… | |
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 (); |
463 | |
473 | |
464 | if (ob->inv) |
474 | if (ob->inv) |
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; |
… | |
… | |
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 */ |