ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/apply.C
(Generate patch)

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.142 by root, Sun Apr 13 20:21:50 2008 UTC vs.
Revision 1.167 by root, Tue Aug 26 02:35:05 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
53 * subtype 5: arch or race 53 * subtype 5: arch or race
54 * subtype 7: all three 54 * subtype 7: all three
55 */ 55 */
56 if (op->subtype) 56 if (op->subtype)
57 { 57 {
58 arch_flag = (op->subtype & 1); 58 arch_flag = op->subtype & 1;
59 name_flag = (op->subtype & 2); 59 name_flag = op->subtype & 2;
60 race_flag = (op->subtype & 4); 60 race_flag = op->subtype & 4;
61 } 61 }
62 else 62 else
63 { 63 {
64 arch_flag = 1; 64 arch_flag = 1;
65 name_flag = 1; 65 name_flag = 1;
160 * matching item. 160 * matching item.
161 **/ 161 **/
162void 162void
163handle_apply_yield (object *tmp) 163handle_apply_yield (object *tmp)
164{ 164{
165 const char *yield; 165 if (shstr yield = tmp->kv (shstr_on_use_yield))
166 166 archetype::get (yield)->insert_at (tmp, tmp, INS_BELOW_ORIGINATOR);
167 yield = get_ob_key_value (tmp, "on_use_yield");
168 if (yield != NULL)
169 {
170 object *drop = get_archetype (yield);
171
172 if (tmp->env)
173 {
174 drop = insert_ob_in_ob (drop, tmp->env);
175 if (tmp->env->type == PLAYER)
176 esrv_send_item (tmp->env, drop);
177 }
178 else
179 {
180 drop->x = tmp->x;
181 drop->y = tmp->y;
182 insert_ob_in_map (drop, tmp->map, tmp, INS_BELOW_ORIGINATOR);
183 }
184 }
185} 167}
186 168
187/** 169/**
188 * Handles applying a potion. 170 * Handles applying a potion.
189 */ 171 */
217 199
218 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 200 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
219 { 201 {
220 op->drain_stat (); 202 op->drain_stat ();
221 op->update_stats (); 203 op->update_stats ();
222 decrease_ob (tmp); 204 tmp->decrease ();
223 return 1; 205 return 1;
224 } 206 }
225 207
226 if (!(at = archetype::find (ARCH_DEPLETION))) 208 if (!(at = archetype::find (ARCH_DEPLETION)))
227 { 209 {
228 LOG (llevError, "Could not find archetype depletion\n"); 210 LOG (llevError, "Could not find archetype depletion\n");
229 return 0; 211 return 0;
230 } 212 }
213
231 depl = present_arch_in_ob (at, op); 214 depl = present_arch_in_ob (at, op);
232 215
233 if (depl) 216 if (depl)
234 { 217 {
235 for (i = 0; i < NUM_STATS; i++) 218 for (i = 0; i < NUM_STATS; i++)
240 op->update_stats (); 223 op->update_stats ();
241 } 224 }
242 else 225 else
243 op->statusmsg ("Your potion had no effect."); 226 op->statusmsg ("Your potion had no effect.");
244 227
245 decrease_ob (tmp); 228 tmp->decrease ();
246 return 1; 229 return 1;
247 } 230 }
248 231
249 /* improvement potion - only for players */ 232 /* improvement potion - only for players */
250 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER)) 233 if (op->type == PLAYER && (tmp->attacktype & AT_GODPOWER))
318 } 301 }
319 else 302 else
320 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE); 303 op->statusmsg ("You are fortunate that you are so pathetic.", NDI_DK_ORANGE);
321 } 304 }
322 305
323 decrease_ob (tmp); 306 tmp->decrease ();
324 return 1; 307 return 1;
325 } 308 }
326 309
327 310
328 /* A potion that casts a spell. Healing, restore spellpoint (power potion) 311 /* A potion that casts a spell. Healing, restore spellpoint (power potion)
347 insert_ob_in_map (fball, op->map, NULL, 0); 330 insert_ob_in_map (fball, op->map, NULL, 0);
348 } 331 }
349 else 332 else
350 cast_spell (op, tmp, op->facing, tmp->inv, NULL); 333 cast_spell (op, tmp, op->facing, tmp->inv, NULL);
351 334
352 decrease_ob (tmp); 335 tmp->decrease ();
353 336
354 /* if youre dead, no point in doing this... */ 337 /* if youre dead, no point in doing this... */
355 if (!QUERY_FLAG (op, FLAG_REMOVED)) 338 if (!QUERY_FLAG (op, FLAG_REMOVED))
356 op->update_stats (); 339 op->update_stats ();
357 340
388 force->speed_left = -1; 371 force->speed_left = -1;
389 force = insert_ob_in_ob (force, op); 372 force = insert_ob_in_ob (force, op);
390 CLEAR_FLAG (tmp, FLAG_APPLIED); 373 CLEAR_FLAG (tmp, FLAG_APPLIED);
391 SET_FLAG (force, FLAG_APPLIED); 374 SET_FLAG (force, FLAG_APPLIED);
392 change_abil (op, force); 375 change_abil (op, force);
393 decrease_ob (tmp); 376 tmp->decrease ();
394 return 1; 377 return 1;
395 } 378 }
396 379
397 /* Only thing left are the stat potions */ 380 /* Only thing left are the stat potions */
398 if (op->type == PLAYER) 381 if (op->type == PLAYER)
411 * stat will not be raised by them. fix_player just clears 394 * stat will not be raised by them. fix_player just clears
412 * up all the stats. 395 * up all the stats.
413 */ 396 */
414 CLEAR_FLAG (tmp, FLAG_APPLIED); 397 CLEAR_FLAG (tmp, FLAG_APPLIED);
415 op->update_stats (); 398 op->update_stats ();
416 decrease_ob (tmp); 399 tmp->decrease ();
417 return 1; 400 return 1;
418} 401}
419 402
420/**************************************************************************** 403/****************************************************************************
421 * Weapon improvement code follows 404 * Weapon improvement code follows
468 { 451 {
469 if (strcmp (op->arch->archname, item) == 0) 452 if (strcmp (op->arch->archname, item) == 0)
470 { 453 {
471 if (op->nrof >= nrof) 454 if (op->nrof >= nrof)
472 { 455 {
473 decrease_ob_nr (op, nrof); 456 op->decrease (nrof);
474 return; 457 return;
475 } 458 }
476 else 459 else
477 { 460 {
478 decrease_ob_nr (op, op->nrof); 461 op->decrease (nrof);
479 nrof -= op->nrof; 462 nrof -= op->nrof;
480 } 463 }
481 464
482 op = prev; 465 op = prev;
483 } 466 }
568static int 551static int
569improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname) 552improve_weapon_stat (object *op, object *improver, object *weapon, sint8 &stat, int sacrifice_count, const char *statname)
570{ 553{
571 stat += sacrifice_count; 554 stat += sacrifice_count;
572 weapon->last_eat++; 555 weapon->last_eat++;
573 decrease_ob (improver); 556 improver->decrease ();
574 557
575 /* So it updates the players stats and the window */ 558 /* So it updates the players stats and the window */
576 op->update_stats (); 559 op->update_stats ();
577 560
578 op->statusmsg (format ( 561 op->statusmsg (format (
625 weapon->stats.exp || /* speed */ 608 weapon->stats.exp || /* speed */
626 weapon->stats.ac) /* AC - only taifu's I think */ 609 weapon->stats.ac) /* AC - only taifu's I think */
627 { 610 {
628 op->failmsg ("You cannot prepare magic weapons. " 611 op->failmsg ("You cannot prepare magic weapons. "
629 "H<A weapon is considered magical if it changes regeneration, " 612 "H<A weapon is considered magical if it changes regeneration, "
630 "speed or ac.>"); 613 "speed or ac, or has other protections.>");
631 return 0; 614 return 0;
632 } 615 }
633 616
634 sacrifice_count = check_sacrifice (op, improver); 617 sacrifice_count = check_sacrifice (op, improver);
635 if (sacrifice_count <= 0) 618 if (sacrifice_count <= 0)
646 629
647 sprintf (buf, "%s's %s", &op->name, &weapon->name); 630 sprintf (buf, "%s's %s", &op->name, &weapon->name);
648 weapon->name = weapon->name_pl = buf; 631 weapon->name = weapon->name_pl = buf;
649 weapon->nrof = 0; /* prevents preparing n weapons in the same 632 weapon->nrof = 0; /* prevents preparing n weapons in the same
650 slot at once! */ 633 slot at once! */
651 decrease_ob (improver); 634 improver->decrease ();
652 weapon->last_eat = 0; 635 weapon->last_eat = 0;
653 return 1; 636 return 1;
654} 637}
655
656 638
657/** 639/**
658 * Does the dirty job for 'improve weapon' scroll, prepare or add something. 640 * Does the dirty job for 'improve weapon' scroll, prepare or add something.
659 * This is the new improve weapon code. 641 * This is the new improve weapon code.
660 * Returns 0 if it was not able to work for some reason. 642 * Returns 0 if it was not able to work for some reason.
704 weapon->weight += 5000; /* 5 KG's */ 686 weapon->weight += 5000; /* 5 KG's */
705 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam)); 687 op->statusmsg (format ("Damage has been increased by 5 to %d.", weapon->stats.dam));
706 weapon->last_eat++; 688 weapon->last_eat++;
707 689
708 weapon->item_power++; 690 weapon->item_power++;
709 decrease_ob (improver); 691 improver->decrease ();
710 return 1; 692 return 1;
711 } 693 }
712 694
713 if (improver->stats.sp == IMPROVE_WEIGHT) 695 if (improver->stats.sp == IMPROVE_WEIGHT)
714 { 696 {
718 weapon->weight = 1; 700 weapon->weight = 1;
719 701
720 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0)); 702 op->statusmsg (format ("Weapon weight reduced to %6.1fkg.", (float) weapon->weight / 1000.0));
721 weapon->last_eat++; 703 weapon->last_eat++;
722 weapon->item_power++; 704 weapon->item_power++;
723 decrease_ob (improver); 705 improver->decrease ();
724 return 1; 706 return 1;
725 } 707 }
708
726 if (improver->stats.sp == IMPROVE_ENCHANT) 709 if (improver->stats.sp == IMPROVE_ENCHANT)
727 { 710 {
728 weapon->magic++; 711 weapon->magic++;
729 weapon->last_eat++; 712 weapon->last_eat++;
730 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic)); 713 op->statusmsg (format ("Weapon magic increased to %d.", weapon->magic));
731 decrease_ob (improver); 714 improver->decrease ();
732 weapon->item_power++; 715 weapon->item_power++;
733 return 1; 716 return 1;
734 } 717 }
735 718
736 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex + 719 sacrifice_needed = weapon->stats.Str + weapon->stats.Int + weapon->stats.Dex +
785 op->failmsg ("Something blocks the magic of the scroll!"); 768 op->failmsg ("Something blocks the magic of the scroll!");
786 return 0; 769 return 0;
787 } 770 }
788 771
789 otmp = find_marked_object (op); 772 otmp = find_marked_object (op);
773
790 if (!otmp) 774 if (!otmp)
791 { 775 {
792 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>"); 776 op->failmsg ("You need to mark a weapon object. H<Use the mark command or the mark option from the item popup menu.>");
793 return 0; 777 return 0;
794 } 778 }
851 } 835 }
852 836
853 /* Split objects if needed. Can't insert tmp until the 837 /* Split objects if needed. Can't insert tmp until the
854 * end of this function - otherwise it will just re-merge. 838 * end of this function - otherwise it will just re-merge.
855 */ 839 */
856 if (armour->nrof > 1) 840 tmp = armour->nrof > 1 ? armour->split (armour->nrof - 1) : 0;
857 tmp = get_split_ob (armour, armour->nrof - 1);
858 else
859 tmp = NULL;
860 841
861 armour->magic++; 842 armour->magic++;
862 843
863 if (!settings.armor_speed_linear) 844 if (!settings.armor_speed_linear)
864 { 845 {
901 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic); 882 armour->item_power = get_power_from_ench (armour->arch->item_power + armour->magic);
902 883
903 if (op->type == PLAYER) 884 if (op->type == PLAYER)
904 { 885 {
905 esrv_send_item (op, armour); 886 esrv_send_item (op, armour);
887
906 if (QUERY_FLAG (armour, FLAG_APPLIED)) 888 if (QUERY_FLAG (armour, FLAG_APPLIED))
907 op->update_stats (); 889 op->update_stats ();
908 } 890 }
909 891
910 decrease_ob (improver); 892 improver->decrease ();
911 893
912 if (tmp) 894 if (tmp)
913 { 895 op->insert (tmp);
914 insert_ob_in_ob (tmp, op);
915 esrv_send_item (op, tmp);
916 }
917 896
918 return 1; 897 return 1;
919} 898}
920 899
921/* 900/*
955 934
956 converter->play_sound (sound_find ("shop_buy")); 935 converter->play_sound (sound_find ("shop_buy"));
957 936
958 sint64 cost = (nr * need + item->value - 1) / item->value; 937 sint64 cost = (nr * need + item->value - 1) / item->value;
959 938
960 decrease_ob_nr (item, cost); 939 item->decrease (cost);
961 940
962 price_in = cost * item->value; 941 price_in = cost * item->value;
963 } 942 }
964 else 943 else
965 { 944 {
971 converter->play_sound (sound_find ("convert_item")); 950 converter->play_sound (sound_find ("convert_item"));
972 951
973 if (need) 952 if (need)
974 { 953 {
975 nr = sint64 (item->nrof) / need; 954 nr = sint64 (item->nrof) / need;
976 decrease_ob_nr (item, nr * need); 955 item->decrease (nr * need);
977 price_in = nr * need * item->value; 956 price_in = nr * need * item->value;
978 } 957 }
979 else 958 else
980 { 959 {
981 price_in = item->value; 960 price_in = item->value;
993 ob_to_copy = converter->inv; 972 ob_to_copy = converter->inv;
994 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++) 973 for (ob = converter->inv->below, i = 1; ob; ob = ob->below, i++)
995 if (rndm (0, i) == 0) 974 if (rndm (0, i) == 0)
996 ob_to_copy = ob; 975 ob_to_copy = ob;
997 976
998 item = object_create_clone (ob_to_copy); 977 item = ob_to_copy->deep_clone ();
999 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE); 978 CLEAR_FLAG (item, FLAG_IS_A_TEMPLATE);
1000 unflag_inv (item, FLAG_IS_A_TEMPLATE); 979 unflag_inv (item, FLAG_IS_A_TEMPLATE);
1001 } 980 }
1002 else 981 else
1003 { 982 {
1028 * elmex: we are going to let the game continue, as the mapcreator 1007 * elmex: we are going to let the game continue, as the mapcreator
1029 * hopefully had something in mind when doing this. 1008 * hopefully had something in mind when doing this.
1030 */ 1009 */
1031 } 1010 }
1032 1011
1033 SET_FLAG (item, FLAG_IDENTIFIED); 1012 // elmex: only identify if we need to, for example so that generated money doesn't
1013 // get an 'identified' flag so easily.
1014 if (need_identify (item))
1015 identify (item);
1016
1034 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y); 1017 insert_ob_in_map_at (item, converter->map, converter, 0, converter->x, converter->y);
1035 return 1; 1018 return 1;
1036} 1019}
1037 1020
1038/** 1021/**
1277 * Handles applying a sign. 1260 * Handles applying a sign.
1278 */ 1261 */
1279static void 1262static void
1280apply_sign (object *op, object *sign, int autoapply) 1263apply_sign (object *op, object *sign, int autoapply)
1281{ 1264{
1282 readable_message_type *msgType; 1265 if (sign->has_dialogue ())
1266 {
1267 op->statusmsg (form ("Maybe you should I<talk> to the %s instead?", &sign->name));
1268 return;
1269 }
1283 1270
1284 if (!sign->msg) 1271 if (!sign->msg)
1285 { 1272 {
1286 op->statusmsg ("Nothing is written on it."); 1273 op->statusmsg ("Nothing is written on it.");
1287 return; 1274 return;
1322 1309
1323 if (ns->can_msg) 1310 if (ns->can_msg)
1324 op->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n\n\n%s", &sign->name, &sign->msg)); 1311 op->contr->infobox (MSG_CHANNEL ("examine"), format ("T<%s>\n\n\n\n%s", &sign->name, &sign->msg));
1325 else 1312 else
1326 { 1313 {
1327 msgType = get_readable_message_type (sign); 1314 readable_message_type *msgType = get_readable_message_type (sign);
1328 const char *somemsg = format ("%u %s", autoapply ? 1 : 0, &sign->msg); 1315 const char *somemsg = format ("%u %s", autoapply ? 1 : 0, &sign->msg);
1329 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, somemsg, &sign->msg); 1316 draw_ext_info (NDI_UNIQUE | NDI_NAVY, 0, op, msgType->message_type, msgType->message_subtype, somemsg, &sign->msg);
1330 } 1317 }
1331 } 1318 }
1319}
1320
1321static void
1322move_apply_hole (object *trap, object *victim)
1323{
1324 /* Hole not open? */
1325 if (trap->stats.wc > 0)
1326 return;
1327
1328 /* Is this a multipart monster and not the head? If so, return.
1329 * Processing will happen if the head runs into the pit
1330 */
1331 if (victim->head)
1332 return;
1333
1334 fprintf (stderr, "range %d\n", trap->range);//D
1335 // now find all possible locations and randomly pick one
1336 int dir = find_free_spot (victim, trap->map, EXIT_X (trap), EXIT_Y (trap), 0,
1337 trap->range >= 3 ? SIZEOFFREE3
1338 : trap->range >= 2 ? SIZEOFFREE2
1339 : trap->range >= 1 ? SIZEOFFREE1
1340 : 0);
1341
1342 if (dir < 0)
1343 return;
1344
1345 victim->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1346 victim->statusmsg ("You fall through the hole!", NDI_RED);
1347
1348 transfer_ob (victim,
1349 EXIT_X (trap) + freearr_x[dir],
1350 EXIT_Y (trap) + freearr_y[dir],
1351 0, victim);
1332} 1352}
1333 1353
1334/** 1354/**
1335 * 'victim' moves onto 'trap' 1355 * 'victim' moves onto 'trap'
1336 * 'victim' leaves 'trap' 1356 * 'victim' leaves 'trap'
1448 1468
1449 if (!trap->value) 1469 if (!trap->value)
1450 { 1470 {
1451 int tot; 1471 int tot;
1452 1472
1453 for (ab = trap->above, tot = 0; ab != NULL; ab = ab->above) 1473 for (ab = trap->above, tot = 0; ab; ab = ab->above)
1454 if ((ab->move_type && trap->move_on) || ab->move_type == 0) 1474 if ((ab->move_type && trap->move_on) || ab->move_type == 0)
1455 tot += (ab->nrof ? ab->nrof : 1) * ab->weight + ab->carrying; 1475 tot += ab->head_ ()->total_weight ();
1456 1476
1457 if (!(trap->value = (tot > trap->weight) ? 1 : 0)) 1477 if (!(trap->value = (tot > trap->weight) ? 1 : 0))
1458 goto leave; 1478 goto leave;
1459 1479
1460 SET_ANIMATION (trap, trap->value); 1480 SET_ANIMATION (trap, trap->value);
1485 1505
1486 case CONVERTER: 1506 case CONVERTER:
1487 if (convert_item (victim, trap) < 0) 1507 if (convert_item (victim, trap) < 0)
1488 { 1508 {
1489 originator->failmsg (format ("The %s seems to be broken!", query_name (trap))); 1509 originator->failmsg (format ("The %s seems to be broken!", query_name (trap)));
1490 get_archetype ("burnout")->insert_at (trap, trap); 1510 archetype::get (shstr_burnout)->insert_at (trap, trap);
1491 } 1511 }
1492 1512
1493 goto leave; 1513 goto leave;
1494 1514
1495 case TRIGGER_BUTTON: 1515 case TRIGGER_BUTTON:
1505 case CHECK_INV: 1525 case CHECK_INV:
1506 check_inv (victim, trap); 1526 check_inv (victim, trap);
1507 goto leave; 1527 goto leave;
1508 1528
1509 case HOLE: 1529 case HOLE:
1510 /* Hole not open? */ 1530 move_apply_hole (trap, victim);
1511 if (trap->stats.wc > 0)
1512 goto leave;
1513
1514 /* Is this a multipart monster and not the head? If so, return.
1515 * Processing will happen if the head runs into the pit
1516 */
1517 if (victim->head)
1518 goto leave;
1519
1520 victim->play_sound (trap->sound ? trap->sound : sound_find ("fall_hole"));
1521 victim->statusmsg ("You fall through the hole!", NDI_RED);
1522 transfer_ob (victim, EXIT_X (trap), EXIT_Y (trap), 1, victim);
1523 goto leave; 1531 goto leave;
1524 1532
1525 case EXIT: 1533 case EXIT:
1526 if (victim->type == PLAYER && EXIT_PATH (trap)) 1534 if (victim->type == PLAYER && EXIT_PATH (trap))
1527 { 1535 {
1637 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1645 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1638 { 1646 {
1639 /*exp_gain *= 2; because they just identified it too */ 1647 /*exp_gain *= 2; because they just identified it too */
1640 SET_FLAG (tmp, FLAG_IDENTIFIED); 1648 SET_FLAG (tmp, FLAG_IDENTIFIED);
1641 1649
1642 /* If in a container, update how it looks */ 1650 if (object *pl = tmp->visible_to ())
1643 if (tmp->env)
1644 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp); 1651 esrv_update_item (UPD_FLAGS | UPD_NAME, pl, tmp);
1645 else
1646 op->contr->ns->floorbox_update ();
1647 } 1652 }
1648 1653
1649 change_exp (op, exp_gain, skill_ob->skill, 0); 1654 change_exp (op, exp_gain, skill_ob->skill, 0);
1650 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */ 1655 SET_FLAG (tmp, FLAG_NO_SKILL_IDENT); /* so no more xp gained from this book */
1651 } 1656 }
1664 op->play_sound (sound_find ("generic_fail")); 1669 op->play_sound (sound_find ("generic_fail"));
1665 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp))); 1670 op->failmsg (format ("You already possess the knowledge held within the %s.", query_name (tmp)));
1666 break; 1671 break;
1667 1672
1668 case 1: 1673 case 1:
1669 decrease_ob (tmp); 1674 tmp->decrease ();
1670 op->play_sound (sound_find ("skill_learn")); 1675 op->play_sound (sound_find ("skill_learn"));
1671 op->statusmsg (format ("You succeed in learning %s", &tmp->skill)); 1676 op->statusmsg (format ("You succeed in learning %s", &tmp->skill));
1672 break; 1677 break;
1673 1678
1674 default: 1679 default:
1675 decrease_ob (tmp); 1680 tmp->decrease ();
1676 op->play_sound (sound_find ("generic_fail")); 1681 op->play_sound (sound_find ("generic_fail"));
1677 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp))); 1682 op->failmsg (format ("You fail to learn the knowledge of the %s.\n", query_name (tmp)));
1678 break; 1683 break;
1679 } 1684 }
1680} 1685}
1801 } 1806 }
1802 1807
1803 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name)); 1808 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name));
1804 1809
1805 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED)) 1810 if (!QUERY_FLAG (tmp, FLAG_IDENTIFIED))
1806 {
1807 identify (tmp); 1811 identify (tmp);
1808
1809 if (tmp->env)
1810 esrv_update_item (UPD_FLAGS | UPD_NAME, op, tmp);
1811 else
1812 op->contr->ns->floorbox_update ();
1813 }
1814 1812
1815 /* I removed the check for special_prayer_mark here - it didn't make 1813 /* I removed the check for special_prayer_mark here - it didn't make
1816 * a lot of sense - special prayers are not found in spellbooks, and 1814 * a lot of sense - special prayers are not found in spellbooks, and
1817 * if the player doesn't know the spell, doesn't make a lot of sense that 1815 * if the player doesn't know the spell, doesn't make a lot of sense that
1818 * they would have a special prayer mark. 1816 * they would have a special prayer mark.
1871 { 1869 {
1872 op->contr->play_sound (sound_find ("fumble_spell")); 1870 op->contr->play_sound (sound_find ("fumble_spell"));
1873 op->failmsg ("You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n"); 1871 op->failmsg ("You fail to learn the spell. H<Wis (priests) or Int (wizards) governs the chance of learning a prayer or spell.>\n");
1874 } 1872 }
1875 1873
1876 decrease_ob (tmp); 1874 tmp->decrease ();
1877} 1875}
1878 1876
1879/** 1877/**
1880 * Handles applying a spell scroll. 1878 * Handles applying a spell scroll.
1881 */ 1879 */
1920 identify (tmp); 1918 identify (tmp);
1921 1919
1922 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name)); 1920 op->statusmsg (format ("The scroll of %s turns to dust.", &tmp->inv->name));
1923 1921
1924 cast_spell (op, tmp, dir, tmp->inv, NULL); 1922 cast_spell (op, tmp, dir, tmp->inv, NULL);
1925 decrease_ob (tmp); 1923 tmp->decrease ();
1926} 1924}
1927 1925
1928/** 1926/**
1929 * Applies a treasure object - by default, chest. op 1927 * Applies a treasure object - by default, chest. op
1930 * is the person doing the applying, tmp is the treasure 1928 * is the person doing the applying, tmp is the treasure
1942 object *treas = tmp->inv; 1940 object *treas = tmp->inv;
1943 1941
1944 if (!treas) 1942 if (!treas)
1945 { 1943 {
1946 op->statusmsg ("The chest was empty."); 1944 op->statusmsg ("The chest was empty.");
1947 decrease_ob (tmp); 1945 tmp->decrease ();
1948 return; 1946 return;
1949 } 1947 }
1950 1948
1951 while (tmp->inv) 1949 while (tmp->inv)
1952 { 1950 {
1968 if (op->destroyed () || tmp->destroyed ()) 1966 if (op->destroyed () || tmp->destroyed ())
1969 break; 1967 break;
1970 } 1968 }
1971 1969
1972 if (!tmp->destroyed () && !tmp->inv) 1970 if (!tmp->destroyed () && !tmp->inv)
1973 decrease_ob (tmp); 1971 tmp->decrease ();
1974} 1972}
1975 1973
1976/** 1974/**
1977 * op eats food. 1975 * op eats food.
1978 * If player, takes care of messages and dragon special food. 1976 * If player, takes care of messages and dragon special food.
2044 eat_special_food (op, tmp); 2042 eat_special_food (op, tmp);
2045 } 2043 }
2046 } 2044 }
2047 2045
2048 handle_apply_yield (tmp); 2046 handle_apply_yield (tmp);
2049 decrease_ob (tmp); 2047 tmp->decrease ();
2050} 2048}
2051 2049
2052/** 2050/**
2053 * A dragon is eating some flesh. If the flesh contains resistances, 2051 * A dragon is eating some flesh. If the flesh contains resistances,
2054 * there is a chance for the dragon's skin to get improved. 2052 * there is a chance for the dragon's skin to get improved.
2242 2240
2243 op->statusmsg ("Applying armour enchantment."); 2241 op->statusmsg ("Applying armour enchantment.");
2244 improve_armour (op, tmp, armor); 2242 improve_armour (op, tmp, armor);
2245} 2243}
2246 2244
2247extern void 2245void
2248apply_poison (object *op, object *tmp) 2246apply_poison (object *op, object *tmp)
2249{ 2247{
2248 // need to do it now when it is still on the map
2249 handle_apply_yield (tmp);
2250
2251 object *poison = tmp->split (1);
2252
2250 if (op->type == PLAYER) 2253 if (op->type == PLAYER)
2251 { 2254 {
2252 op->contr->play_sound (sound_find ("drink_poison")); 2255 op->contr->play_sound (sound_find ("drink_poison"));
2253 op->failmsg ("Yech! That tasted poisonous!"); 2256 op->failmsg ("Yech! That tasted poisonous!");
2254 strcpy (op->contr->killer, "poisonous booze"); 2257 op->contr->killer = poison;
2255 } 2258 }
2256 2259
2257 if (tmp->stats.hp > 0) 2260 if (poison->stats.hp > 0)
2258 { 2261 {
2259 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", tmp->stats.hp); 2262 LOG (llevDebug, "Trying to poison player/monster for %d hp\n", poison->stats.hp);
2260 hit_player (op, tmp->stats.hp, tmp, AT_POISON, 1); 2263 hit_player (op, poison->stats.hp, tmp, AT_POISON, 1);
2261 } 2264 }
2262 2265
2263 op->stats.food -= op->stats.food / 4; 2266 op->stats.food -= op->stats.food / 4;
2264 handle_apply_yield (tmp); 2267 poison->destroy ();
2265 decrease_ob (tmp);
2266} 2268}
2267 2269
2268/** 2270/**
2269 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit. 2271 * This function return true if the exit is not a 2 ways one or it is 2 ways, valid exit.
2270 * A valid 2 way exit means: 2272 * A valid 2 way exit means:
2372 * them in this function - they are passed to apply_special 2374 * them in this function - they are passed to apply_special
2373 */ 2375 */
2374int 2376int
2375manual_apply (object *op, object *tmp, int aflag) 2377manual_apply (object *op, object *tmp, int aflag)
2376{ 2378{
2377 if (tmp->head)
2378 tmp = tmp->head; 2379 tmp = tmp->head_ ();
2379 2380
2380 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED)) 2381 if (QUERY_FLAG (tmp, FLAG_UNPAID) && !QUERY_FLAG (tmp, FLAG_APPLIED))
2381 { 2382 {
2382 if (op->type == PLAYER) 2383 if (op->type == PLAYER)
2383 { 2384 {
2591 default: 2592 default:
2592 return 0; 2593 return 0;
2593 } 2594 }
2594} 2595}
2595 2596
2596
2597/* quiet suppresses the "don't know how to apply" and "you must get it first" 2597/* quiet suppresses the "don't know how to apply" and "you must get it first"
2598 * messages as needed by player_apply_below(). But there can still be 2598 * messages as needed by player_apply_below(). But there can still be
2599 * "but you are floating high above the ground" messages. 2599 * "but you are floating high above the ground" messages.
2600 * 2600 *
2601 * Same return value as apply() function. 2601 * Same return value as apply() function.
2602 */ 2602 */
2603int 2603int
2604player_apply (object *pl, object *op, int aflag, int quiet) 2604player_apply (object *pl, object *op, int aflag, int quiet)
2605{ 2605{
2606 int tmp;
2607
2608 if (op->env && (pl->move_type & MOVE_FLYING)) 2606 if (!op->env && (pl->move_type & MOVE_FLYING))
2609 { 2607 {
2610 /* player is flying and applying object not in inventory */ 2608 /* player is flying and applying object not in inventory */
2611 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING)) 2609 if (!QUERY_FLAG (pl, FLAG_WIZ) && !(op->move_type & MOVE_FLYING))
2612 { 2610 {
2613 pl->failmsg ("But you are floating high above the ground! H<You have to stop levitating first, if you can.>"); 2611 pl->failmsg ("But you are floating high above the ground! "
2612 "H<You have to stop levitating first, if you can, either by using your levitation skill, "
2613 "or waiting till the levitation effect wears off.>");
2614 return 0; 2614 return 0;
2615 } 2615 }
2616 } 2616 }
2617 2617
2618 pl->contr->last_used = op; 2618 pl->contr->last_used = op;
2619 2619
2620 tmp = manual_apply (pl, op, aflag); 2620 int tmp = manual_apply (pl, op, aflag);
2621
2621 if (!quiet) 2622 if (!quiet)
2622 { 2623 {
2623 if (tmp == 0) 2624 if (tmp == 0)
2624 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op))); 2625 pl->statusmsg (format ("I don't know how to apply the %s.", query_name (op)));
2625 else if (tmp == 2) 2626 else if (tmp == 2)
2717 break; 2718 break;
2718 2719
2719 case SKILL: 2720 case SKILL:
2720 if (who->contr) 2721 if (who->contr)
2721 { 2722 {
2723 if (IS_COMBAT_SKILL (op->subtype))
2724 who->change_weapon (who->contr->combat_ob = 0);
2725 else if (IS_RANGED_SKILL (op->subtype))
2726 who->change_weapon (who->contr->ranged_ob = 0);
2727
2722 if (!op->invisible) 2728 if (op->invisible)
2729 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2730 else
2723 who->statusmsg (format ("You stop using the %s.", query_name (op))); 2731 who->statusmsg (format ("You stop using the %s.", query_name (op)));
2724 else
2725 who->statusmsg (format ("You can no longer use the skill: %s.", &op->skill));
2726 } 2732 }
2727 2733
2728 change_abil (who, op); 2734 change_abil (who, op);
2729 CLEAR_FLAG (who, FLAG_READY_SKILL); 2735 CLEAR_FLAG (who, FLAG_READY_SKILL);
2730 break; 2736 break;
2757 CLEAR_FLAG (tmp2, FLAG_APPLIED); 2763 CLEAR_FLAG (tmp2, FLAG_APPLIED);
2758 2764
2759 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 2765 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
2760 SET_FLAG (tmp2, FLAG_INV_LOCKED); 2766 SET_FLAG (tmp2, FLAG_INV_LOCKED);
2761 2767
2768 op->destroy ();
2769 who->insert (tmp2);
2770 who->update_stats ();
2771
2762 if (who->contr) 2772 if (who->contr)
2763 esrv_del_item (who->contr, op->count);
2764
2765 op->destroy ();
2766 insert_ob_in_ob (tmp2, who);
2767 who->update_stats ();
2768
2769 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2770 { 2773 {
2771 if (who->contr) 2774 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
2772 { 2775 {
2773 who->failmsg ("Oops, it feels deadly cold!"); 2776 who->failmsg ("Oops, it feels deadly cold!");
2774 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 2777 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
2775 } 2778 }
2776 } 2779 }
2777
2778 if (who->contr)
2779 esrv_send_item (who, tmp2);
2780 } 2780 }
2781 2781
2782 return 1; /* otherwise, an attempt to drop causes problems */ 2782 return 1; /* otherwise, an attempt to drop causes problems */
2783 2783
2784 case BOW: 2784 case BOW:
2815 default: 2815 default:
2816 who->statusmsg (format ("You unapply %s.", query_name (op))); 2816 who->statusmsg (format ("You unapply %s.", query_name (op)));
2817 break; 2817 break;
2818 } 2818 }
2819 2819
2820 if (aflags & AP_NO_MERGE || !merge_ob (op, 0))
2821 if (object *pl = op->visible_to ())
2822 esrv_send_item (pl, op);
2823
2820 who->update_stats (); 2824 who->update_stats ();
2821
2822 if (!(aflags & AP_NO_MERGE))
2823 {
2824 object *tmp = merge_ob (op, 0);
2825
2826 if (who->contr)
2827 {
2828 if (tmp)
2829 { /* it was merged */
2830 esrv_del_item (who->contr, op->count);
2831 op = tmp;
2832 }
2833
2834 esrv_send_item (who, op);
2835 }
2836 }
2837 2825
2838 return 0; 2826 return 0;
2839} 2827}
2840 2828
2841/** 2829/**
3139 return 1; 3127 return 1;
3140 } 3128 }
3141 3129
3142 return unapply_special (who, op, aflags); 3130 return unapply_special (who, op, aflags);
3143 } 3131 }
3144
3145 if (basic_flag == AP_UNAPPLY) 3132 else if (basic_flag == AP_UNAPPLY)
3146 return 0; 3133 return 0;
3147 3134
3148 // if the item is combat/ranged, wield the relevant slot first 3135 // if the item is combat/ranged, wield the relevant slot first
3149 // to resolve conflicts. 3136 // to resolve conflicts.
3150 if (player *pl = who->contr) 3137 if (player *pl = who->contr)
3220 3207
3221 /* Ok. We are now at the state where we can apply the new object. 3208 /* Ok. We are now at the state where we can apply the new object.
3222 * Note that we don't have the checks for can_use_... 3209 * Note that we don't have the checks for can_use_...
3223 * below - that is already taken care of by can_apply_object. 3210 * below - that is already taken care of by can_apply_object.
3224 */ 3211 */
3225 if (op->nrof > 1) 3212 tmp = op->nrof > 1 ? op->split (op->nrof - 1) : 0;
3226 tmp = get_split_ob (op, op->nrof - 1);
3227 else
3228 tmp = 0;
3229 3213
3230 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op))) 3214 if (INVOKE_OBJECT (BE_READY, op, ARG_OBJECT (who)) || INVOKE_OBJECT (READY, who, ARG_OBJECT (op)))
3231 return RESULT_INT (0); 3215 return RESULT_INT (0);
3232 3216
3233 switch (op->type) 3217 switch (op->type)
3234 { 3218 {
3235 case WEAPON: 3219 case WEAPON:
3236 if (!check_weapon_power (who, op->last_eat)) 3220 if (!check_weapon_power (who, op->last_eat))
3237 { 3221 {
3238 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!." LACK_ITEM_POWER); 3222 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3239 3223
3240 if (tmp) 3224 if (tmp)
3241 insert_ob_in_ob (tmp, who); 3225 insert_ob_in_ob (tmp, who);
3242 3226
3243 return 1; 3227 return 1;
3308 SET_FLAG (tmp2, FLAG_APPLIED); 3292 SET_FLAG (tmp2, FLAG_APPLIED);
3309 3293
3310 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 3294 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
3311 SET_FLAG (tmp2, FLAG_INV_LOCKED); 3295 SET_FLAG (tmp2, FLAG_INV_LOCKED);
3312 3296
3313 insert_ob_in_ob (tmp2, who); 3297 who->insert (tmp2);
3314 3298
3315 /* Remove the old lantern */ 3299 /* Remove the old lantern */
3316 if (who->type == PLAYER)
3317 esrv_del_item (who->contr, op->count);
3318
3319 op->destroy (); 3300 op->destroy ();
3320 3301
3321 /* insert the portion that was split off */ 3302 /* insert the portion that was split off */
3322 if (tmp) 3303 if (tmp)
3323 { 3304 who->insert (tmp);
3324 insert_ob_in_ob (tmp, who);
3325 if (who->type == PLAYER)
3326 esrv_send_item (who, tmp);
3327 }
3328 3305
3329 who->update_stats (); 3306 who->update_stats ();
3330 3307
3331 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED)) 3308 if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
3332 if (who->type == PLAYER) 3309 if (who->type == PLAYER)
3333 { 3310 {
3334 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"); 3311 who->failmsg ("Oops, it feels deadly cold! H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>");
3335 SET_FLAG (tmp2, FLAG_KNOWN_CURSED); 3312 SET_FLAG (tmp2, FLAG_KNOWN_CURSED);
3336 } 3313 }
3337
3338 if (who->type == PLAYER)
3339 esrv_send_item (who, tmp2);
3340 3314
3341 return 0; 3315 return 0;
3342 3316
3343 case SKILL_TOOL: 3317 case SKILL_TOOL:
3344 // applying a skill tool also readies the skill 3318 // applying a skill tool also readies the skill
3504 } 3478 }
3505 3479
3506 SET_FLAG (op, FLAG_APPLIED); 3480 SET_FLAG (op, FLAG_APPLIED);
3507 3481
3508 if (tmp) 3482 if (tmp)
3509 tmp = insert_ob_in_ob (tmp, who); 3483 who->insert (tmp);
3510 3484
3511 who->update_stats (); 3485 who->update_stats ();
3512 3486
3513 /* We exclude spell casting objects. The fire code will set the 3487 /* We exclude spell casting objects. The fire code will set the
3514 * been applied flag when they are used - until that point, 3488 * been applied flag when they are used - until that point,
3525 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>" 3499 "H<Maybe it wasn't such a bright idea to apply this cursed/damned item.>"
3526 ); 3500 );
3527 SET_FLAG (op, FLAG_KNOWN_CURSED); 3501 SET_FLAG (op, FLAG_KNOWN_CURSED);
3528 } 3502 }
3529 3503
3530 if (who->type == PLAYER) 3504 if (object *pl = op->visible_to ())
3531 {
3532 /* if multiple objects were applied, update both slots */
3533 if (tmp)
3534 esrv_send_item (who, tmp);
3535
3536 esrv_send_item (who, op); 3505 esrv_send_item (pl, op);
3537 }
3538 3506
3539 return 0; 3507 return 0;
3540} 3508}
3541 3509
3542int 3510int
3556int 3524int
3557auto_apply (object *op) 3525auto_apply (object *op)
3558{ 3526{
3559 object *tmp = NULL, *tmp2; 3527 object *tmp = NULL, *tmp2;
3560 int i; 3528 int i;
3529
3530 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3561 3531
3562 switch (op->type) 3532 switch (op->type)
3563 { 3533 {
3564 case SHOP_FLOOR: 3534 case SHOP_FLOOR:
3565 if (!op->has_random_items ()) 3535 if (!op->has_random_items ())
3567 3537
3568 do 3538 do
3569 { 3539 {
3570 i = 10; /* let's give it 10 tries */ 3540 i = 10; /* let's give it 10 tries */
3571 while ((tmp = generate_treasure (op->randomitems, 3541 while ((tmp = generate_treasure (op->randomitems,
3572 op->stats.exp ? (int) op->stats.exp : MAX (op->map->difficulty, 5))) == NULL && --i); 3542 op->stats.exp
3543 ? (int) op->stats.exp
3544 : max (op->map->difficulty, 5)))
3545 == NULL && --i);
3546
3573 if (tmp == NULL) 3547 if (tmp == NULL)
3574 return 0; 3548 return 0;
3549
3575 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED)) 3550 if (QUERY_FLAG (tmp, FLAG_CURSED) || QUERY_FLAG (tmp, FLAG_DAMNED))
3576 { 3551 {
3577 tmp->destroy (); 3552 tmp->destroy ();
3578 tmp = NULL; 3553 tmp = NULL;
3579 } 3554 }
3582 3557
3583 tmp->x = op->x; 3558 tmp->x = op->x;
3584 tmp->y = op->y; 3559 tmp->y = op->y;
3585 SET_FLAG (tmp, FLAG_UNPAID); 3560 SET_FLAG (tmp, FLAG_UNPAID);
3586 insert_ob_in_map (tmp, op->map, NULL, 0); 3561 insert_ob_in_map (tmp, op->map, NULL, 0);
3587 CLEAR_FLAG (op, FLAG_AUTO_APPLY);
3588 identify (tmp); 3562 identify (tmp);
3589 break; 3563 break;
3590 3564
3591 case TREASURE: 3565 case TREASURE:
3592 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE)) 3566 if (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))
3613 } 3587 }
3614 3588
3615 op->destroy (); 3589 op->destroy ();
3616 break; 3590 break;
3617 } 3591 }
3618 return tmp ? 1 : 0; 3592
3593 return !!tmp;
3619} 3594}
3620 3595
3621/** 3596/**
3622 * fix_auto_apply goes through the entire map every time a map 3597 * fix_auto_apply goes through the entire map every time a map
3623 * is loaded or swapped in and performs special actions for 3598 * is loaded or swapped in and performs special actions for
3637 3612
3638 if (tmp->inv) 3613 if (tmp->inv)
3639 { 3614 {
3640 object *invtmp, *invnext; 3615 object *invtmp, *invnext;
3641 3616
3642 for (invtmp = tmp->inv; invtmp != NULL; invtmp = invnext) 3617 for (invtmp = tmp->inv; invtmp; invtmp = invnext)
3643 { 3618 {
3644 invnext = invtmp->below; 3619 invnext = invtmp->below;
3645 3620
3646 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY)) 3621 if (QUERY_FLAG (invtmp, FLAG_AUTO_APPLY))
3647 auto_apply (invtmp); 3622 auto_apply (invtmp);
3648 else if (invtmp->type == TREASURE && invtmp->has_random_items ()) 3623 else if (invtmp->type == TREASURE && invtmp->has_random_items ())
3649 { 3624 {
3650 while ((invtmp->stats.hp--) > 0) 3625 while (invtmp->stats.hp-- > 0)
3651 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0); 3626 create_treasure (invtmp->randomitems, invtmp, 0, difficulty, 0);
3652 3627
3653 invtmp->randomitems = NULL; 3628 invtmp->randomitems = NULL;
3654 } 3629 }
3655 else if (invtmp && invtmp->arch 3630 else if (invtmp && invtmp->arch
3767 /* check for hp, sp change */ 3742 /* check for hp, sp change */
3768 if (food->stats.hp != 0) 3743 if (food->stats.hp != 0)
3769 { 3744 {
3770 if (QUERY_FLAG (food, FLAG_CURSED)) 3745 if (QUERY_FLAG (food, FLAG_CURSED))
3771 { 3746 {
3772 assign (who->contr->killer, food->name); 3747 who->contr->killer = food;
3773 hit_player (who, food->stats.hp, food, AT_POISON, 1); 3748 hit_player (who, food->stats.hp, food, AT_POISON, 1);
3774 who->failmsg ("Eck!...that was poisonous!"); 3749 who->failmsg ("Eck!...that was poisonous!");
3775 } 3750 }
3776 else 3751 else
3777 { 3752 {
3781 who->failmsg ("Eck!...that was poisonous!"); 3756 who->failmsg ("Eck!...that was poisonous!");
3782 3757
3783 who->stats.hp += food->stats.hp; 3758 who->stats.hp += food->stats.hp;
3784 } 3759 }
3785 } 3760 }
3761
3786 if (food->stats.sp != 0) 3762 if (food->stats.sp != 0)
3787 { 3763 {
3788 if (QUERY_FLAG (food, FLAG_CURSED)) 3764 if (QUERY_FLAG (food, FLAG_CURSED))
3789 { 3765 {
3790 who->failmsg ("You are drained of mana!"); 3766 who->failmsg ("You are drained of mana!");
3817 item = find_marked_object (who); 3793 item = find_marked_object (who);
3818 if (item) 3794 if (item)
3819 { 3795 {
3820 if (lighter->last_eat && lighter->stats.food) 3796 if (lighter->last_eat && lighter->stats.food)
3821 { /* lighter gets used up */ 3797 { /* lighter gets used up */
3822 /* Split multiple lighters if they're being used up. Otherwise *
3823 * one charge from each would be used up. --DAMN */
3824 if (lighter->nrof > 1)
3825 {
3826 object *oneLighter = lighter->clone (); 3798 object *oneLighter = lighter->split ();
3827
3828 lighter->nrof -= 1;
3829 oneLighter->nrof = 1;
3830 oneLighter->stats.food--; 3799 oneLighter->stats.food--;
3831 esrv_send_item (who, lighter); 3800 who->insert (oneLighter);
3832 oneLighter = insert_ob_in_ob (oneLighter, who);
3833 esrv_send_item (who, oneLighter);
3834 }
3835 else
3836 lighter->stats.food--;
3837 } 3801 }
3838 else if (lighter->last_eat) 3802 else if (lighter->last_eat)
3839 { 3803 {
3840 /* no charges left in lighter */ 3804 /* no charges left in lighter */
3841 who->failmsg (format ("You attempt to light the %s with a used up %s.", &item->name, &lighter->name)); 3805 who->failmsg (format ("You attempt to light the %s with a used up %s.", &item->name, &lighter->name));
3988 if (!strcmp (walk->name, "NOCLASSFACECHANGE")) 3952 if (!strcmp (walk->name, "NOCLASSFACECHANGE"))
3989 flag_change_face = 0; 3953 flag_change_face = 0;
3990 3954
3991 if (flag_change_face) 3955 if (flag_change_face)
3992 { 3956 {
3993 pl->animation_id = GET_ANIM_ID (change);
3994 pl->face = change->face; 3957 pl->face = change->face;
3995 3958 pl->animation_id = change->animation_id;
3996 if (QUERY_FLAG (change, FLAG_ANIMATE)) 3959 pl->flag [FLAG_ANIMATE] = change->flag [FLAG_ANIMATE];
3997 SET_FLAG (pl, FLAG_ANIMATE);
3998 else
3999 CLEAR_FLAG (pl, FLAG_ANIMATE);
4000 } 3960 }
4001 3961
4002 /* check the special case of can't use weapons */ 3962 /* check the special case of can't use weapons */
4003 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */ 3963 /*if(QUERY_FLAG(change,FLAG_USE_WEAPON)) CLEAR_FLAG(pl,FLAG_USE_WEAPON); */
4004 if (!strcmp (change->name, "monk")) 3964 if (!strcmp (change->name, "monk"))
4098 4058
4099 new_item->nrof = yield; 4059 new_item->nrof = yield;
4100 4060
4101 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0))); 4061 pl->statusmsg (format ("You %s the %s.", &transformer->slaying, query_base_name (marked, 0)));
4102 4062
4103 insert_ob_in_ob (new_item, pl); 4063 pl->insert (new_item);
4104 esrv_send_inventory (pl, pl);
4105 /* Eat up one item */ 4064 /* Eat up one item */
4106 decrease_ob_nr (marked, 1); 4065 marked->decrease ();
4107 4066
4108 /* Eat one transformer if needed */ 4067 /* Eat one transformer if needed */
4109 if (transformer->stats.food) 4068 if (transformer->stats.food)
4110 if (--transformer->stats.food == 0) 4069 if (--transformer->stats.food == 0)
4111 decrease_ob_nr (transformer, 1); 4070 transformer->decrease ();
4112} 4071}
4113 4072

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines