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

Comparing deliantra/server/server/player.C (file contents):
Revision 1.151 by root, Sat Jun 16 00:12:20 2007 UTC vs.
Revision 1.206 by root, Mon Sep 29 10:20:49 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <sproto.h> 25#include <sproto.h>
27#include <sounds.h> 26#include <sounds.h>
123 continue; 122 continue;
124 123
125 if (*buf == '%') 124 if (*buf == '%')
126 { /* send one news */ 125 { /* send one news */
127 if (size > 0) 126 if (size > 0)
128 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", (char *)"%s\n%s", subject, news); /*send previously read news */ 127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
128 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
129 "INFORMATION: %s\n%s", (char *)"%s\n%s",
130 subject, news); /*send previously read news */
129 131
130 strcpy (subject, buf + 1); 132 strcpy (subject, buf + 1);
131 strip_endline (subject); 133 strip_endline (subject);
132 size = 0; 134 size = 0;
133 news[0] = '\0'; 135 news[0] = '\0';
184 186
185 if (ob->map) 187 if (ob->map)
186 maplevel = ob->map->path; 188 maplevel = ob->map->path;
187 189
188 ob->remove (); 190 ob->remove ();
191 ob->enemy = 0; // sometimes keeps an extra refcount on itself
189 ob->map = 0; 192 ob->map = 0;
190 party = 0; 193 party = 0;
191 194
192 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this 195 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this
193 196
215 218
216 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 221 ob->race = ob->arch->race;
219 222
220 ob->carrying = sum_weight (ob); 223 ob->update_weight ();
221 link_player_skills (ob); 224 link_skills ();
222 225
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 226 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 227
225 assign (title, ob->arch->object::name); 228 assign (title, ob->arch->object::name);
226 229
227 /* if it's a dragon player, set the correct title here */ 230 /* if it's a dragon player, set the correct title here */
228 if (is_dragon_pl (ob)) 231 if (is_dragon_pl (ob))
229 { 232 {
230 object *tmp, *abil = 0, *skin = 0; 233 object *tmp, *abil = 0, *skin = 0;
231 234
232 shstr_cmp dragon_ability_force ("dragon_ability_force");
233 shstr_cmp dragon_skin_force ("dragon_skin_force");
234
235 for (tmp = ob->inv; tmp; tmp = tmp->below) 235 for (tmp = ob->inv; tmp; tmp = tmp->below)
236 if (tmp->type == FORCE) 236 if (tmp->type == FORCE)
237 if (tmp->arch->archname == dragon_ability_force) 237 if (tmp->arch->archname == shstr_dragon_ability_force)
238 abil = tmp; 238 abil = tmp;
239 else if (tmp->arch->archname == dragon_skin_force) 239 else if (tmp->arch->archname == shstr_dragon_skin_force)
240 skin = tmp; 240 skin = tmp;
241 241
242 set_dragon_name (ob, abil, skin); 242 set_dragon_name (ob, abil, skin);
243 } 243 }
244 244
245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
246 246
247 esrv_new_player (this, ob->weight + ob->carrying); 247 esrv_new_player (this);
248
249 ob->update_stats ();
250
251 ns->floorbox_update ();
252 esrv_send_inventory (ob, ob);
253 esrv_add_spells (this, 0);
254
255 activate ();
256
257 send_rules (ob);
258 send_news (ob);
259 display_motd (ob);
260
261 INVOKE_PLAYER (CONNECT, this);
262 INVOKE_PLAYER (LOGIN, this);
263}
264
265void
266player::disconnect ()
267{
268 if (ob)
269 {
270 ob->close_container (); //TODO: client-specific
271 ob->drop_unpaid_items ();
272 }
273
274 if (ns)
275 {
276 if (active)
277 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
278
279 INVOKE_PLAYER (DISCONNECT, this);
280
281 ns->reset_stats ();
282 ns->pl = 0;
283 ns = 0;
284 }
285
286 observe = ob;
287
288 deactivate ();
289}
290
291// the need for this function can be explained
292// by load_object not returning the object
293void
294player::set_object (object *op)
295{
296 ob = observe = op;
297 ob->contr = this; /* this aren't yet in archetype */
298
299 ob->speed = 1.0f;
300 ob->speed_left = 0.5f;
301
302 ob->direction = 5; /* So player faces south */
248 303
249 ob->flag [FLAG_READY_WEAPON] = false; 304 ob->flag [FLAG_READY_WEAPON] = false;
250 ob->flag [FLAG_READY_SKILL] = false; 305 ob->flag [FLAG_READY_SKILL] = false;
251 ob->flag [FLAG_READY_BOW] = false; 306 ob->flag [FLAG_READY_BOW] = false;
252 307
269 combat_ob = op; 324 combat_ob = op;
270 break; 325 break;
271 } 326 }
272 327
273 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
274 ob->update_stats (); 329 ob->deactivate (); // change_weapon activates, fix this better
275
276 ns->floorbox_update ();
277 esrv_send_inventory (ob, ob);
278 esrv_add_spells (this, 0);
279
280 activate ();
281
282 send_rules (ob);
283 send_news (ob);
284 display_motd (ob);
285
286 INVOKE_PLAYER (CONNECT, this);
287 INVOKE_PLAYER (LOGIN, this);
288}
289
290void
291player::disconnect ()
292{
293 if (ns)
294 {
295 if (active)
296 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
297
298 INVOKE_PLAYER (DISCONNECT, this);
299
300 ns->reset_stats ();
301 ns->pl = 0;
302 ns = 0;
303 }
304
305 if (ob)
306 ob->close_container (); //TODO: client-specific
307
308 observe = ob;
309
310 deactivate ();
311}
312
313// the need for this function can be explained
314// by load_object not returning the object
315void
316player::set_object (object *op)
317{
318 ob = observe = op;
319 ob->contr = this; /* this aren't yet in archetype */
320
321 ob->speed = 1.0f;
322 ob->speed_left = 0.5f;
323
324 ob->direction = 5; /* So player faces south */
325} 330}
326 331
327void 332void
328player::set_observe (object *op) 333player::set_observe (object *op)
329{ 334{
343 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
344 349
345 gen_sp_armour = 10; 350 gen_sp_armour = 10;
346 bowtype = bow_normal; 351 bowtype = bow_normal;
347 petmode = pet_normal; 352 petmode = pet_normal;
348 listening = 10;
349 usekeys = containers; 353 usekeys = containers;
350 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
351 do_los = 1; 355 do_los = 1;
352 356
353 weapon_sp = 1.0f; 357 weapon_sp = 1.0f;
362 attachable::do_destroy (); 366 attachable::do_destroy ();
363 367
364 if (ob) 368 if (ob)
365 { 369 {
366 ob->destroy_inv (false); 370 ob->destroy_inv (false);
367 ob->destroy (); 371 ob->destroy (true);
368 } 372 }
369 373
370 ob = observe = 0; 374 ob = observe = 0;
371} 375}
372 376
402 * Note: there MUST be at least one player archetype! 406 * Note: there MUST be at least one player archetype!
403 */ 407 */
404archetype * 408archetype *
405get_player_archetype (archetype *at) 409get_player_archetype (archetype *at)
406{ 410{
411 // archetypes could have been reloaded
412 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
413
414 if (!nat)
415 return at;
416
407 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 417 archvec::iterator i = archetypes.find (nat);
408 418
409 for (;;) 419 for (;;)
410 { 420 {
411 if (++i == archetypes.end ()) 421 if (++i == archetypes.end ())
412 i = archetypes.begin (); 422 i = archetypes.begin ();
426 unsigned lastdist; 436 unsigned lastdist;
427 rv_vector rv; 437 rv_vector rv;
428 438
429 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) 439 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next)
430 { 440 {
431 /* We should not find free objects on this friendly list, but it
432 * does periodically happen. Given that, lets deal with it.
433 * While unlikely, it is possible the next object on the friendly
434 * list is also free, so encapsulate this in a while loop.
435 */
436 while (QUERY_FLAG (ol->ob, FLAG_FREED) || !QUERY_FLAG (ol->ob, FLAG_FRIENDLY))
437 {
438 object *tmp = ol->ob;
439
440 /* Can't do much more other than log the fact, because the object
441 * itself will have been cleared.
442 */
443 LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n",
444 tmp->debug_desc ());
445 ol = ol->next;
446 remove_friendly_object (tmp);
447 if (!ol)
448 return op;
449 }
450
451 /* Remove special check for player from this. First, it looks to cause
452 * some crashes (ol->ob->contr not set properly?), but secondly, a more
453 * complicated method of state checking would be needed in any case -
454 * as it was, a clever player could type quit, and the function would
455 * skip them over while waiting for confirmation. Remove
456 * on_same_map check, as can_detect_enemy also does this
457 */
458 if (!can_detect_enemy (mon, ol->ob, &rv)) 441 if (!can_detect_enemy (mon, ol->ob, &rv))
459 continue; 442 continue;
460 443
461 if (lastdist > rv.distance) 444 if (lastdist > rv.distance)
462 { 445 {
657 640
658 return firstdir; 641 return firstdir;
659} 642}
660 643
661void 644void
662give_initial_items (object *pl, treasurelist * items) 645give_initial_items (object *pl, treasurelist *items)
663{ 646{
664 object *op, *next = NULL;
665
666 if (pl->randomitems != NULL) 647 if (pl->randomitems)
667 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 648 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
668 649
669 for (op = pl->inv; op; op = next) 650 for (object *next, *op = pl->inv; op; op = next)
670 { 651 {
671 next = op->below; 652 next = op->below;
672 653
673 /* Forces get applied per default, unless they have the 654 /* Forces get applied per default, unless they have the
674 * flag "neutral" set. Sorry but I can't think of a better way 655 * flag "neutral" set. Sorry but I can't think of a better way
679 /* we never give weapons/armour if these cannot be used 660 /* we never give weapons/armour if these cannot be used
680 * by this player due to race restrictions 661 * by this player due to race restrictions
681 */ 662 */
682 if (pl->type == PLAYER) 663 if (pl->type == PLAYER)
683 { 664 {
684 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 665 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
666 &&
685 (op->type == ARMOUR || op->type == BOOTS || 667 (op->type == ARMOUR || op->type == BOOTS
686 op->type == CLOAK || op->type == HELMET || 668 || op->type == CLOAK || op->type == HELMET
687 op->type == SHIELD || op->type == GLOVES || 669 || op->type == SHIELD || op->type == GLOVES
670 || op->type == BRACERS || op->type == GIRDLE))
688 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 671 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
689 { 672 {
690 op->destroy (); 673 op->destroy (true);
691 continue; 674 continue;
692 } 675 }
693 } 676 }
694 677
695 /* This really needs to be better - we should really give 678 /* This really needs to be better - we should really give
706 if (tmp->type == op->type && tmp->name == op->name) 689 if (tmp->type == op->type && tmp->name == op->name)
707 break; 690 break;
708 691
709 if (tmp) 692 if (tmp)
710 { 693 {
711 op->destroy (); 694 op->destroy (true);
712 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); 695 LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name);
713 continue; 696 continue;
714 } 697 }
715 698
716 if (op->nrof > 1) 699 if (op->nrof > 1)
717 op->nrof = 1; 700 op->nrof = 1;
718 } 701 }
719 702
720 if (op->type == SPELLBOOK && op->inv) 703 if (op->type == SPELLBOOK && op->inv)
721 {
722 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 704 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
723 }
724 705
725 /* Give starting characters identified, uncursed, and undamned 706 /* Give starting characters identified, uncursed, and undamned
726 * items. Just don't identify gold or silver, or it won't be 707 * items. Just don't identify gold or silver, or it won't be
727 * merged properly. 708 * merged properly.
728 */ 709 */
729 if (need_identify (op)) 710 if (need_identify (op))
730 { 711 {
731 SET_FLAG (op, FLAG_IDENTIFIED); 712 SET_FLAG (op, FLAG_IDENTIFIED);
732 CLEAR_FLAG (op, FLAG_CURSED); 713 CLEAR_FLAG (op, FLAG_CURSED);
733 CLEAR_FLAG (op, FLAG_DAMNED); 714 CLEAR_FLAG (op, FLAG_DAMNED);
734 } 715 }
716
735 if (op->type == SPELL) 717 if (op->type == SPELL)
736 { 718 {
737 op->destroy (); 719 op->destroy (true);
738 continue; 720 continue;
739 } 721 }
740 else if (op->type == SKILL) 722 else if (op->type == SKILL)
741 { 723 {
742 SET_FLAG (op, FLAG_CAN_USE_SKILL); 724 SET_FLAG (op, FLAG_CAN_USE_SKILL);
743 op->stats.exp = 0; 725 op->stats.exp = 0;
744 op->level = 1; 726 op->level = 1;
745 } 727 }
746 /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
747 else
748 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
749 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
750 731
751 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
752 link_player_skills (pl); 733 pl->contr->link_skills ();
753} 734}
754 735
755void 736void
756get_party_password (object *op, partylist *party) 737get_party_password (object *op, partylist *party)
757{ 738{
858static void 839static void
859start_info (object *op) 840start_info (object *op)
860{ 841{
861 char buf[MAX_BUF]; 842 char buf[MAX_BUF];
862 843
863 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 844 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
864 new_draw_info (NDI_UNIQUE, 0, op, buf); 845 new_draw_info (NDI_UNIQUE, 0, op, buf);
865 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
866 //new_draw_info (NDI_UNIQUE, 0, op, " ");
867} 846}
868 847
869/* This function takes the key that is passed, and does the 848/* This function takes the key that is passed, and does the
870 * appropriate action with it (change race, or other things). 849 * appropriate action with it (change race, or other things).
871 * The function name is for historical reasons - now we have 850 * The function name is for historical reasons - now we have
874 */ 853 */
875void 854void
876player::chargen_race_done () 855player::chargen_race_done ()
877{ 856{
878 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
879 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
880 859
881 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
882 if (tl) 861 if (tl)
883 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
884 863
888 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
889 868
890 if (ob->msg) 869 if (ob->msg)
891 ob->msg = 0; 870 ob->msg = 0;
892 871
893 /* We create this now because some of the unique maps will need it
894 * to save here.
895 */
896 {
897 char buf[MAX_BUF];
898 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
899 make_path_to_file (buf);
900 }
901
902 start_info (ob); 872 start_info (ob);
903 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
904 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
905 link_player_skills (ob);
906 esrv_send_inventory (ob, ob); 875 esrv_send_inventory (ob, ob);
907 ob->update_stats (); 876 ob->update_stats ();
908 877
909 /* This moves the player to a different start map, if there 878 /* This moves the player to a different start map, if there
910 * is one for this race 879 * is one for this race
911 */ 880 */
912 if (*first_map_ext_path) 881 if (*first_map_ext_path)
913 { 882 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
914 object *tmp;
915 char mapname[MAX_BUF];
916
917 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
918 tmp = object::create ();
919 EXIT_PATH (tmp) = mapname;
920 EXIT_X (tmp) = ob->x;
921 EXIT_Y (tmp) = ob->y;
922 ob->enter_exit (tmp); /* we don't really care if it succeeded;
923 * if the map isn't there, then stay on the
924 * default initial map */
925 tmp->destroy ();
926 }
927 else 883 else
928 LOG (llevDebug, "first_map_ext_path not set\n"); 884 LOG (llevDebug, "first_map_ext_path not set\n");
929} 885}
930 886
931void 887void
1034 if (op->move_type & MOVE_FLYING) 990 if (op->move_type & MOVE_FLYING)
1035 return 1; 991 return 1;
1036 992
1037 next = op->below; 993 next = op->below;
1038 994
995 int cnt = MAX_ITEM_PER_DROP;
996#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
997
1039 /* loop while there are items on the floor that are not marked as 998 /* loop while there are items on the floor that are not marked as
1040 * destroyed */ 999 * destroyed */
1041 while (next && !next->destroyed ()) 1000 while (next && !next->destroyed ())
1042 { 1001 {
1043 tmp = next; 1002 tmp = next;
1044 next = tmp->below; 1003 next = tmp->below;
1045 1004
1005 if (cnt <= 0)
1006 {
1007 op->failmsg ("Couldn't pickup all items at once.");
1008 return 0;
1009 }
1010
1046 if (op->destroyed ()) 1011 if (op->destroyed ())
1047 return 0; 1012 return 0;
1048 1013
1049 if (!can_pick (op, tmp)) 1014 if (!can_pick (op, tmp))
1050 continue; 1015 continue;
1051 1016
1052 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1017 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1053 { 1018 {
1054 if (item_matched_string (op, tmp, op->contr->search_str)) 1019 if (item_matched_string (op, tmp, op->contr->search_str))
1055 pick_up (op, tmp); 1020 CHK_PICK_PICKUP;
1056 continue; 1021 continue;
1057 } 1022 }
1058 1023
1059 /* high not bit set? We're using the old autopickup model */ 1024 /* high not bit set? We're using the old autopickup model */
1060 if (!(op->contr->mode & PU_NEWMODE)) 1025 if (!(op->contr->mode & PU_NEWMODE))
1062 switch (op->contr->mode) 1027 switch (op->contr->mode)
1063 { 1028 {
1064 case 0: 1029 case 0:
1065 return 1; /* don't pick up */ 1030 return 1; /* don't pick up */
1066 case 1: 1031 case 1:
1067 pick_up (op, tmp); 1032 CHK_PICK_PICKUP;
1068 return 1; 1033 return 1;
1069 case 2: 1034 case 2:
1070 pick_up (op, tmp); 1035 CHK_PICK_PICKUP;
1071 return 0; 1036 return 0;
1072 case 3: 1037 case 3:
1073 return 0; /* stop before pickup */ 1038 return 0; /* stop before pickup */
1074 case 4: 1039 case 4:
1075 pick_up (op, tmp); 1040 CHK_PICK_PICKUP;
1076 break; 1041 break;
1077 case 5: 1042 case 5:
1078 pick_up (op, tmp); 1043 CHK_PICK_PICKUP;
1079 stop = 1; 1044 stop = 1;
1080 break; 1045 break;
1081 case 6: 1046 case 6:
1082 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1047 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1083 pick_up (op, tmp); 1048 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1049 CHK_PICK_PICKUP;
1084 break; 1050 break;
1085 1051
1086 case 7: 1052 case 7:
1087 if (tmp->type == MONEY || tmp->type == GEM) 1053 if (tmp->type == MONEY || tmp->type == GEM)
1088 pick_up (op, tmp); 1054 CHK_PICK_PICKUP;
1089 break; 1055 break;
1090 1056
1091 default: 1057 default:
1092 /* use value density */ 1058 /* use value density */
1093 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1059 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1094 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1060 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1095 pick_up (op, tmp); 1061 CHK_PICK_PICKUP;
1096 } 1062 }
1097 } 1063 }
1098 else 1064 else
1099 { /* old model */ 1065 { /* old model */
1100 /* NEW pickup handling */ 1066 /* NEW pickup handling */
1155 /* all food and drink if desired */ 1121 /* all food and drink if desired */
1156 /* question: don't pick up known-poisonous stuff? */ 1122 /* question: don't pick up known-poisonous stuff? */
1157 if (op->contr->mode & PU_FOOD) 1123 if (op->contr->mode & PU_FOOD)
1158 if (tmp->type == FOOD) 1124 if (tmp->type == FOOD)
1159 { 1125 {
1160 pick_up (op, tmp); 1126 CHK_PICK_PICKUP;
1161 continue; 1127 continue;
1162 } 1128 }
1163 1129
1164 if (op->contr->mode & PU_DRINK) 1130 if (op->contr->mode & PU_DRINK)
1165 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1131 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1166 { 1132 {
1167 pick_up (op, tmp); 1133 CHK_PICK_PICKUP;
1168 continue; 1134 continue;
1169 } 1135 }
1170 1136
1171 if (op->contr->mode & PU_POTION) 1137 if (op->contr->mode & PU_POTION)
1172 if (tmp->type == POTION) 1138 if (tmp->type == POTION)
1173 { 1139 {
1174 pick_up (op, tmp); 1140 CHK_PICK_PICKUP;
1175 continue; 1141 continue;
1176 } 1142 }
1177 1143
1178 /* spellbooks, skillscrolls and normal books/scrolls */ 1144 /* spellbooks, skillscrolls and normal books/scrolls */
1179 if (op->contr->mode & PU_SPELLBOOK) 1145 if (op->contr->mode & PU_SPELLBOOK)
1180 if (tmp->type == SPELLBOOK) 1146 if (tmp->type == SPELLBOOK)
1181 { 1147 {
1182 pick_up (op, tmp); 1148 CHK_PICK_PICKUP;
1183 continue; 1149 continue;
1184 } 1150 }
1185 1151
1186 if (op->contr->mode & PU_SKILLSCROLL) 1152 if (op->contr->mode & PU_SKILLSCROLL)
1187 if (tmp->type == SKILLSCROLL) 1153 if (tmp->type == SKILLSCROLL)
1188 { 1154 {
1189 pick_up (op, tmp); 1155 CHK_PICK_PICKUP;
1190 continue; 1156 continue;
1191 } 1157 }
1192 1158
1193 if (op->contr->mode & PU_READABLES) 1159 if (op->contr->mode & PU_READABLES)
1194 if (tmp->type == BOOK || tmp->type == SCROLL) 1160 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1195 { 1161 {
1196 pick_up (op, tmp); 1162 CHK_PICK_PICKUP;
1197 continue; 1163 continue;
1198 } 1164 }
1199 1165
1200 /* wands/staves/rods/horns */ 1166 /* wands/staves/rods/horns */
1201 if (op->contr->mode & PU_MAGIC_DEVICE) 1167 if (op->contr->mode & PU_MAGIC_DEVICE)
1202 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1168 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1203 { 1169 {
1204 pick_up (op, tmp); 1170 CHK_PICK_PICKUP;
1205 continue; 1171 continue;
1206 } 1172 }
1207 1173
1208 /* pick up all magical items */ 1174 /* pick up all magical items */
1209 if (op->contr->mode & PU_MAGICAL) 1175 if (op->contr->mode & PU_MAGICAL)
1210 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1176 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1211 { 1177 {
1212 pick_up (op, tmp); 1178 CHK_PICK_PICKUP;
1213 continue; 1179 continue;
1214 } 1180 }
1215 1181
1216 if (op->contr->mode & PU_VALUABLES) 1182 if (op->contr->mode & PU_VALUABLES)
1217 { 1183 {
1218 if (tmp->type == MONEY || tmp->type == GEM) 1184 if (tmp->type == MONEY || tmp->type == GEM)
1219 { 1185 {
1220 pick_up (op, tmp); 1186 CHK_PICK_PICKUP;
1221 continue; 1187 continue;
1222 } 1188 }
1223 } 1189 }
1224 1190
1225 /* rings & amulets - talismans seems to be typed AMULET */ 1191 /* rings & amulets - talismans seems to be typed AMULET */
1226 if (op->contr->mode & PU_JEWELS) 1192 if (op->contr->mode & PU_JEWELS)
1227 if (tmp->type == RING || tmp->type == AMULET) 1193 if (tmp->type == RING || tmp->type == AMULET)
1228 { 1194 {
1229 pick_up (op, tmp); 1195 CHK_PICK_PICKUP;
1230 continue; 1196 continue;
1231 } 1197 }
1232 1198
1233 /* we don't forget dragon food */ 1199 /* we don't forget dragon food */
1234 if (op->contr->mode & PU_FLESH) 1200 if (op->contr->mode & PU_FLESH)
1235 if (tmp->type == FLESH) 1201 if (tmp->type == FLESH)
1236 { 1202 {
1237 pick_up (op, tmp); 1203 CHK_PICK_PICKUP;
1238 continue; 1204 continue;
1239 } 1205 }
1240 1206
1241 /* bows and arrows. Bows are good for selling! */ 1207 /* bows and arrows. Bows are good for selling! */
1242 if (op->contr->mode & PU_BOW) 1208 if (op->contr->mode & PU_BOW)
1243 if (tmp->type == BOW) 1209 if (tmp->type == BOW)
1244 { 1210 {
1245 pick_up (op, tmp); 1211 CHK_PICK_PICKUP;
1246 continue; 1212 continue;
1247 } 1213 }
1248 1214
1249 if (op->contr->mode & PU_ARROW) 1215 if (op->contr->mode & PU_ARROW)
1250 if (tmp->type == ARROW) 1216 if (tmp->type == ARROW)
1251 { 1217 {
1252 pick_up (op, tmp); 1218 CHK_PICK_PICKUP;
1253 continue; 1219 continue;
1254 } 1220 }
1255 1221
1256 /* all kinds of armor etc. */ 1222 /* all kinds of armor etc. */
1257 if (op->contr->mode & PU_ARMOUR) 1223 if (op->contr->mode & PU_ARMOUR)
1258 if (tmp->type == ARMOUR) 1224 if (tmp->type == ARMOUR)
1259 { 1225 {
1260 pick_up (op, tmp); 1226 CHK_PICK_PICKUP;
1261 continue; 1227 continue;
1262 } 1228 }
1263 1229
1264 if (op->contr->mode & PU_HELMET) 1230 if (op->contr->mode & PU_HELMET)
1265 if (tmp->type == HELMET) 1231 if (tmp->type == HELMET)
1266 { 1232 {
1267 pick_up (op, tmp); 1233 CHK_PICK_PICKUP;
1268 continue; 1234 continue;
1269 } 1235 }
1270 1236
1271 if (op->contr->mode & PU_SHIELD) 1237 if (op->contr->mode & PU_SHIELD)
1272 if (tmp->type == SHIELD) 1238 if (tmp->type == SHIELD)
1273 { 1239 {
1274 pick_up (op, tmp); 1240 CHK_PICK_PICKUP;
1275 continue; 1241 continue;
1276 } 1242 }
1277 1243
1278 if (op->contr->mode & PU_BOOTS) 1244 if (op->contr->mode & PU_BOOTS)
1279 if (tmp->type == BOOTS) 1245 if (tmp->type == BOOTS)
1280 { 1246 {
1281 pick_up (op, tmp); 1247 CHK_PICK_PICKUP;
1282 continue; 1248 continue;
1283 } 1249 }
1284 1250
1285 if (op->contr->mode & PU_GLOVES) 1251 if (op->contr->mode & PU_GLOVES)
1286 if (tmp->type == GLOVES) 1252 if (tmp->type == GLOVES)
1287 { 1253 {
1288 pick_up (op, tmp); 1254 CHK_PICK_PICKUP;
1289 continue; 1255 continue;
1290 } 1256 }
1291 1257
1292 if (op->contr->mode & PU_CLOAK) 1258 if (op->contr->mode & PU_CLOAK)
1293 if (tmp->type == CLOAK) 1259 if (tmp->type == CLOAK)
1294 { 1260 {
1295 pick_up (op, tmp); 1261 CHK_PICK_PICKUP;
1296 continue; 1262 continue;
1297 } 1263 }
1298 1264
1299 /* hoping to catch throwing daggers here */ 1265 /* hoping to catch throwing daggers here */
1300 if (op->contr->mode & PU_MISSILEWEAPON) 1266 if (op->contr->mode & PU_MISSILEWEAPON)
1301 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1267 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1302 { 1268 {
1303 pick_up (op, tmp); 1269 CHK_PICK_PICKUP;
1304 continue; 1270 continue;
1305 } 1271 }
1306 1272
1307 /* careful: chairs and tables are weapons! */ 1273 /* careful: chairs and tables are weapons! */
1308 if (op->contr->mode & PU_ALLWEAPON) 1274 if (op->contr->mode & PU_ALLWEAPON)
1310 if (tmp->type == WEAPON && tmp->name != NULL) 1276 if (tmp->type == WEAPON && tmp->name != NULL)
1311 { 1277 {
1312 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && 1278 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1313 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1279 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1314 { 1280 {
1315 pick_up (op, tmp); 1281 CHK_PICK_PICKUP;
1316 continue; 1282 continue;
1317 } 1283 }
1318 } 1284 }
1319 1285
1320 if (tmp->type == WEAPON && tmp->name == NULL) 1286 if (tmp->type == WEAPON && tmp->name == NULL)
1321 { 1287 {
1322 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) 1288 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1323 { 1289 {
1324 pick_up (op, tmp); 1290 CHK_PICK_PICKUP;
1325 continue; 1291 continue;
1326 } 1292 }
1327 } 1293 }
1328 } 1294 }
1329 1295
1330 /* misc stuff that's useful */ 1296 /* misc stuff that's useful */
1331 if (op->contr->mode & PU_KEY) 1297 if (op->contr->mode & PU_KEY)
1332 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1298 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1333 { 1299 {
1334 pick_up (op, tmp); 1300 CHK_PICK_PICKUP;
1335 continue; 1301 continue;
1336 } 1302 }
1337 1303
1338 /* any of the last 4 bits set means we use the ratio for value 1304 /* any of the last 4 bits set means we use the ratio for value
1339 * pickups */ 1305 * pickups */
1340 if (op->contr->mode & PU_RATIO) 1306 if (op->contr->mode & PU_RATIO)
1341 { 1307 {
1342 /* use value density to decide what else to grab */ 1308 /* use value density to decide what else to grab */
1343 /* >=7 was >= op->contr->mode */ 1309 /* >=7 was >= op->contr->mode */
1344 /* >=7 is the old standard setting. Now we take the last 4 bits 1310 /* >=7 is the old standard setting. Now we take the last 4 bits
1345 * and multiply them by 5, giving 0..15*5== 5..75 */ 1311 */
1346 wvratio = (op->contr->mode & PU_RATIO) * 5; 1312 wvratio = op->contr->mode & PU_RATIO;
1347 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1313 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1348 { 1314 {
1349 pick_up (op, tmp); 1315 CHK_PICK_PICKUP;
1350#if 0 1316#if 0
1351 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1317 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1352 if (tmp->name != NULL) 1318 if (tmp->name != NULL)
1353 { 1319 {
1354 fprintf (stderr, "%s", tmp->name); 1320 fprintf (stderr, "%s", tmp->name);
1373 * found object is returned. 1339 * found object is returned.
1374 */ 1340 */
1375object * 1341object *
1376find_arrow (object *op, const char *type) 1342find_arrow (object *op, const char *type)
1377{ 1343{
1378 object *tmp = 0;
1379
1380 for (op = op->inv; op; op = op->below) 1344 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1381 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1382 tmp = find_arrow (op, type);
1383 else if (op->type == ARROW && op->race == type) 1345 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1346 return splay (tmp);
1347
1348 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1349 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1350 if (object *arrow = find_arrow (tmp, type))
1351 {
1352 splay (tmp);
1384 return op; 1353 return arrow;
1354 }
1385 1355
1386 return tmp; 1356 return 0;
1387} 1357}
1388 1358
1389/* 1359/*
1390 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1360 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1391 * against the target. A full test is not performed, simply a basic test 1361 * against the target. A full test is not performed, simply a basic test
1414 } 1384 }
1415 } 1385 }
1416 else if (arrow->type == ARROW && arrow->race == type) 1386 else if (arrow->type == ARROW && arrow->race == type)
1417 { 1387 {
1418 /* allways prefer assasination/slaying */ 1388 /* allways prefer assasination/slaying */
1419 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1389 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1420 { 1390 {
1421 if (arrow->attacktype & AT_DEATH) 1391 if (arrow->attacktype & AT_DEATH)
1422 { 1392 {
1423 *better = 100; 1393 *better = 100;
1424 return arrow; 1394 return arrow;
1452 betterby = 1 + arrow->magic + arrow->stats.dam; 1422 betterby = 1 + arrow->magic + arrow->stats.dam;
1453 } 1423 }
1454 } 1424 }
1455 } 1425 }
1456 } 1426 }
1427
1457 if (tmp == NULL && arrow == NULL) 1428 if (tmp == NULL && arrow == NULL)
1458 return find_arrow (op, type); 1429 return find_arrow (op, type);
1459 1430
1460 *better = betterby; 1431 *better = betterby;
1461 return tmp; 1432 return tmp;
1607 } 1578 }
1608 1579
1609 /* this should not happen, but sometimes does */ 1580 /* this should not happen, but sometimes does */
1610 if (arrow->nrof == 0) 1581 if (arrow->nrof == 0)
1611 { 1582 {
1583 LOG (llevError | logBacktrace, "arrow (%s) has nrof 0\n", arrow->debug_desc ());
1612 arrow->destroy (); 1584 arrow->destroy (true);
1613 return 0; 1585 return 0;
1614 } 1586 }
1615 1587
1616 left = arrow; /* these are arrows left to the player */ 1588 left = arrow; /* these are arrows left to the player */
1617 arrow = get_split_ob (arrow, 1); 1589 arrow = arrow->split ();
1618 if (!arrow) 1590 if (!arrow)
1619 { 1591 {
1620 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1592 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1621 return 0; 1593 return 0;
1622 } 1594 }
1684 1656
1685 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); 1657 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1686 arrow->move_type = MOVE_FLY_LOW; 1658 arrow->move_type = MOVE_FLY_LOW;
1687 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1659 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1688 1660
1689 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1661 op->play_sound (sound_find ("fire_arrow"));
1690 m->insert (arrow, sx, sy, op); 1662 m->insert (arrow, sx, sy, op);
1691 1663
1692 if (!arrow->destroyed ()) 1664 if (!arrow->destroyed ())
1693 move_arrow (arrow); 1665 move_arrow (arrow);
1694
1695 if (op->type == PLAYER)
1696 {
1697 if (left->destroyed ())
1698 esrv_del_item (op->contr, left->count);
1699 else
1700 esrv_send_item (op, left);
1701 }
1702 1666
1703 return 1; 1667 return 1;
1704} 1668}
1705 1669
1706/* Special fire code for players - this takes into 1670/* Special fire code for players - this takes into
1772 1736
1773 if (item->type == WAND) 1737 if (item->type == WAND)
1774 { 1738 {
1775 if (item->stats.food <= 0) 1739 if (item->stats.food <= 0)
1776 { 1740 {
1777 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1741 op->contr->play_sound (sound_find ("wand_poof"));
1778 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0)); 1742 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0));
1779 1743
1780 return; 1744 return;
1781 } 1745 }
1782 } 1746 }
1783 else if (item->type == ROD || item->type == HORN) 1747 else if (item->type == ROD || item->type == HORN)
1784 { 1748 {
1785 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1749 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1750
1751 // using the maximum of the rods charge allows at least one spell cast
1752 // for a rod or horn, this fixes some broken rods.
1753 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1786 { 1754 {
1787 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1755 op->contr->play_sound (sound_find ("wand_poof"));
1788 1756
1789 if (item->type == ROD) 1757 if (item->type == ROD)
1790 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1758 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1791 else 1759 else
1792 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0)); 1760 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0));
1809 CLEAR_FLAG (item, FLAG_ANIMATE); 1777 CLEAR_FLAG (item, FLAG_ANIMATE);
1810 item->face = item->arch->face; 1778 item->face = item->arch->face;
1811 item->set_speed (0); 1779 item->set_speed (0);
1812 } 1780 }
1813 1781
1814 if ((tmp = item->in_player ())) 1782 if (object *pl = item->visible_to ())
1815 esrv_update_item (UPD_ANIM, tmp, item); 1783 esrv_update_item (UPD_ANIM, pl, item);
1816 } 1784 }
1817 } 1785 }
1818 else if (item->type == ROD || item->type == HORN) 1786 else if (item->type == ROD || item->type == HORN)
1819 drain_rod_charge (item); 1787 drain_rod_charge (item);
1820 } 1788 }
1981 /* If we found a key, do some extra work */ 1949 /* If we found a key, do some extra work */
1982 if (key) 1950 if (key)
1983 { 1951 {
1984 object *container = key->env; 1952 object *container = key->env;
1985 1953
1986 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR);
1987
1988 if (action_makes_visible (op)) 1954 if (action_makes_visible (op))
1989 make_visible (op); 1955 make_visible (op);
1990 1956
1991 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1957 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
1992 spring_trap (door->inv, op); 1958 spring_trap (door->inv, op);
1993 1959
1994 if (door->type == DOOR) 1960 if (door->type == DOOR)
1995 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ 1961 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */
1996 else if (door->type == LOCKED_DOOR) 1962 else if (door->type == LOCKED_DOOR)
1997 { 1963 {
1998 new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key)); 1964 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
1999 remove_door2 (door); /* remove door without violence ;-) */ 1965 remove_door2 (door); /* remove door without violence ;-) */
2000 } 1966 }
2001 1967
2002 /* Do this after we print the message */ 1968 /* Do this after we print the message */
2003 decrease_ob (key); /* Use up one of the keys */ 1969 key->decrease (); /* Use up one of the keys */
2004 /* Need to update the weight the container the key was in */
2005 if (container != op)
2006 esrv_update_item (UPD_WEIGHT, op, container);
2007 1970
2008 return 1; /* Nothing more to do below */ 1971 return 1; /* Nothing more to do below */
2009 } 1972 }
2010 else if (door->type == LOCKED_DOOR) 1973 else if (door->type == LOCKED_DOOR)
2011 { 1974 {
2012 /* Might as well return now - no other way to open this */ 1975 /* Might as well return now - no other way to open this */
2013 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); 1976 op->failmsg (door->msg ? &door->msg : "Hmm, you miss the certain something to open this door...");
2014 return 1; 1977 return 1;
2015 } 1978 }
2016 1979
2017 return 0; 1980 return 0;
2018} 1981}
2105 2068
2106 if (op->speed_left > 0.f) 2069 if (op->speed_left > 0.f)
2107 { 2070 {
2108 --op->speed_left; 2071 --op->speed_left;
2109 2072
2110 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2073 op->play_sound (sound_find ("push_player"));
2111 push_ob (mon, dir, op); 2074 push_ob (mon, dir, op);
2112 2075
2113 if (op->contr->tmp_invis || op->hide) 2076 if (op->contr->tmp_invis || op->hide)
2114 make_visible (op); 2077 make_visible (op);
2115 2078
2134 { 2097 {
2135 --op->speed_left; 2098 --op->speed_left;
2136 2099
2137 if (!op->contr->braced) 2100 if (!op->contr->braced)
2138 { 2101 {
2139 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2102 op->play_sound (sound_find ("push_player"));
2140 push_ob (mon, dir, op); 2103 push_ob (mon, dir, op);
2141 } 2104 }
2142 else 2105 else
2143 new_draw_info (0, 0, op, "You withhold your attack"); 2106 op->statusmsg ("You withhold your attack");
2144 2107
2145 if (op->contr->tmp_invis || op->hide) 2108 if (op->contr->tmp_invis || op->hide)
2146 make_visible (op); 2109 make_visible (op);
2147 2110
2148 return true; 2111 return true;
2192bool 2155bool
2193move_player (object *op, int dir) 2156move_player (object *op, int dir)
2194{ 2157{
2195 int pick; 2158 int pick;
2196 2159
2197 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2160 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2198 return 0; 2161 return 0;
2199 2162
2200 /* Sanity check: make sure dir is valid */ 2163 /* Sanity check: make sure dir is valid */
2201 if ((dir < 0) || (dir >= 9)) 2164 if ((dir < 0) || (dir >= 9))
2202 { 2165 {
2287 return 0; 2250 return 0;
2288 2251
2289 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2252 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2290 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2253 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2291 { 2254 {
2292 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2255 op->play_sound (sound_find ("ob_evaporate"));
2293 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2256 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2294 2257
2295 if (op->contr)
2296 esrv_del_item (op->contr, tmp->count);
2297
2298 tmp->destroy (); 2258 tmp->destroy (true);
2299 CLEAR_FLAG (op, FLAG_LIFESAVE); 2259 CLEAR_FLAG (op, FLAG_LIFESAVE);
2300 2260
2301 if (op->stats.hp < 0) 2261 if (op->stats.hp < 0)
2302 op->stats.hp = op->stats.maxhp; 2262 op->stats.hp = op->stats.maxhp;
2303 2263
2314 return 0; 2274 return 0;
2315} 2275}
2316 2276
2317/* This goes throws the inventory and removes unpaid objects, and puts them 2277/* This goes throws the inventory and removes unpaid objects, and puts them
2318 * back in the map (location and map determined by values of env). This 2278 * back in the map (location and map determined by values of env). This
2319 * function will descend into containers. op is the object to start the search 2279 * function will descend into containers. op is the object to start the search
2320 * from. 2280 * from.
2321 */ 2281 */
2282static void
2283drop_unpaid_items (object *op, object *env)
2284{
2285 while (op)
2286 {
2287 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2288
2289 if (QUERY_FLAG (op, FLAG_UNPAID))
2290 op->insert_at (env);
2291 else if (op->inv)
2292 drop_unpaid_items (op->inv, env);
2293
2294 op = next;
2295 }
2296}
2297
2322void 2298void
2323remove_unpaid_objects (object *op, object *env) 2299object::drop_unpaid_items ()
2324{ 2300{
2325 while (op) 2301 if (!flag [FLAG_REMOVED])
2326 { 2302 ::drop_unpaid_items (inv, this);
2327 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2328
2329 if (QUERY_FLAG (op, FLAG_UNPAID))
2330 {
2331 if (env->type == PLAYER)
2332 esrv_del_item (env->contr, op->count);
2333
2334 op->insert_at (env);
2335 }
2336 else if (op->inv)
2337 remove_unpaid_objects (op->inv, env);
2338
2339 op = next;
2340 }
2341} 2303}
2342 2304
2343/* 2305/*
2344 * Returns pointer a static string containing gravestone text 2306 * Returns pointer a static string containing gravestone text
2345 * Moved from apply.c to player.c - player.c is what 2307 * Moved from apply.c to player.c - player.c is what
2346 * actually uses this function. player.c may not be quite the 2308 * actually uses this function. player.c may not be quite the
2347 * best, a misc file for object actions is probably better, 2309 * best, a misc file for object actions is probably better,
2348 * but there isn't one in the server directory. 2310 * but there isn't one in the server directory.
2349 */ 2311 */
2350char * 2312const char *
2351gravestone_text (object *op) 2313gravestone_text (object *op)
2352{ 2314{
2353 static char buf2[MAX_BUF]; 2315 static dynbuf_text buf;
2354 char buf[MAX_BUF];
2355 time_t now = time (NULL);
2356 2316
2357 strcpy (buf2, " R.I.P.\n\n"); 2317 buf << "---- R.I.P. ----\n\n"
2318 << op->name;
2319
2358 if (op->type == PLAYER) 2320 if (op->type == PLAYER)
2359 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2321 buf << " the " << op->contr->title;
2360 else
2361 sprintf (buf, "%s\n", &op->name);
2362 2322
2363 strncat (buf2, " ", 20 - strlen (buf) / 2); 2323 buf << "\n\n";
2364 strcat (buf2, buf); 2324
2325 buf << "who was level ";
2326 buf << (sint32)op->level << "\n\n" // OO breakdown
2327 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2328
2365 if (op->type == PLAYER) 2329 if (op->type == PLAYER)
2366 sprintf (buf, "who was in level %d when killed\n", op->level); 2330 buf << "by " << op->contr->killer_name () << ".\n\n";
2367 else
2368 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2369 2331
2370 strncat (buf2, " ", 20 - strlen (buf) / 2);
2371 strcat (buf2, buf);
2372 if (op->type == PLAYER)
2373 { 2332 {
2374 sprintf (buf, "by %s.\n\n", op->contr->killer); 2333 static char buf2[128];
2375 strncat (buf2, " ", 21 - strlen (buf) / 2); 2334 time_t now = time (NULL);
2376 strcat (buf2, buf);
2377 }
2378
2379 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2335 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2380 strncat (buf2, " ", 20 - strlen (buf) / 2); 2336 buf << buf2;
2381 strcat (buf2, buf); 2337 }
2382 2338
2383 return buf2; 2339 return buf;
2384} 2340}
2385 2341
2386void 2342void
2387do_some_living (object *op) 2343do_some_living (object *op)
2388{ 2344{
2440 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace; 2396 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace;
2441 else 2397 else
2442 { 2398 {
2443 gen_grace = op->stats.maxgrace; 2399 gen_grace = op->stats.maxgrace;
2444 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2400 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2445 }
2446
2447 /* Regenerate Spell Points */
2448 if (!op->contr->golem && --op->last_sp < 0)
2449 {
2450 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2451 if (op->stats.sp < op->stats.maxsp)
2452 {
2453 op->stats.sp++;
2454 /* dms do not consume food */
2455 if (!QUERY_FLAG (op, FLAG_WIZ))
2456 {
2457 op->stats.food--;
2458 if (op->contr->digestion < 0)
2459 op->stats.food += op->contr->digestion;
2460 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2461 op->stats.food = last_food;
2462 }
2463 }
2464
2465 if (max_sp > 1)
2466 {
2467 over_sp = (gen_sp + 10) / rate_sp;
2468 if (over_sp > 0)
2469 {
2470 if (op->stats.sp < op->stats.maxsp)
2471 {
2472 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2473
2474 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2475 op->stats.sp--;
2476
2477 if (op->stats.sp > op->stats.maxsp)
2478 op->stats.sp = op->stats.maxsp;
2479 }
2480 op->last_sp = 0;
2481 }
2482 else
2483 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2484 }
2485 else
2486 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2487 } 2401 }
2488 2402
2489 /* Regenerate Grace */ 2403 /* Regenerate Grace */
2490 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ 2404 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */
2491 if (--op->last_grace < 0) 2405 if (--op->last_grace < 0)
2512 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); 2426 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10);
2513 } 2427 }
2514 /* wearing stuff doesn't detract from grace generation. */ 2428 /* wearing stuff doesn't detract from grace generation. */
2515 } 2429 }
2516 2430
2431 if (op->stats.food > 0)
2432 {
2517 /* Regenerate Hit Points */ 2433 /* Regenerate Spell Points */
2518 if (--op->last_heal < 0) 2434 if (!op->contr->golem && --op->last_sp < 0)
2519 {
2520 if (op->stats.hp < op->stats.maxhp)
2521 { 2435 {
2522 op->stats.hp++; 2436 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2523 /* dms do not consume food */ 2437
2524 if (!QUERY_FLAG (op, FLAG_WIZ)) 2438 if (op->stats.sp < op->stats.maxsp)
2525 { 2439 {
2440 op->stats.sp++;
2441
2442 /* dms do not consume food */
2443 if (!QUERY_FLAG (op, FLAG_WIZ))
2444 {
2526 op->stats.food--; 2445 op->stats.food--;
2446
2527 if (op->contr->digestion < 0) 2447 if (op->contr->digestion < 0)
2528 op->stats.food += op->contr->digestion; 2448 op->stats.food += op->contr->digestion;
2529 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2449 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2530 op->stats.food = last_food; 2450 op->stats.food = last_food;
2451 }
2531 } 2452 }
2532 }
2533 2453
2534 if (max_hp > 1) 2454 if (max_sp > 1)
2535 {
2536 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2537 if (over_hp > 0)
2538 { 2455 {
2539 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2456 over_sp = (gen_sp + 10) / rate_sp;
2457 if (over_sp > 0)
2458 {
2459 if (op->stats.sp < op->stats.maxsp)
2460 {
2461 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2462
2463 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2464 op->stats.sp--;
2465
2466 if (op->stats.sp > op->stats.maxsp)
2467 op->stats.sp = op->stats.maxsp;
2468 }
2469
2540 op->last_heal = 0; 2470 op->last_sp = 0;
2471 }
2472 else
2473 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2541 } 2474 }
2542 else 2475 else
2476 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2477 }
2478
2479 /* Regenerate Hit Points */
2480 if (--op->last_heal < 0)
2481 {
2482 if (op->stats.hp < op->stats.maxhp)
2543 { 2483 {
2544 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2484 op->stats.hp++;
2485
2486 /* dms do not consume food */
2487 if (!QUERY_FLAG (op, FLAG_WIZ))
2488 {
2489 op->stats.food--;
2490
2491 if (op->contr->digestion < 0)
2492 op->stats.food += op->contr->digestion;
2493 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2494 op->stats.food = last_food;
2495 }
2545 } 2496 }
2497
2498 if (max_hp > 1)
2499 {
2500 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2501
2502 if (over_hp > 0)
2503 {
2504 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2505 op->last_heal = 0;
2506 }
2507 else
2508 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2546 } 2509 }
2547 else 2510 else
2548 {
2549 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2511 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2550 } 2512 }
2551 } 2513 }
2552 2514
2553 /* Digestion */ 2515 /* Digestion */
2554 if (--op->last_eat < 0) 2516 if (--op->last_eat < 0)
2555 { 2517 {
2556 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; 2518 int bonus = max (0, op->contr->digestion),
2519 penalty = max (0, -op->contr->digestion);
2557 2520
2558 if (op->contr->gen_hp > 0)
2559 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); 2521 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2560 else
2561 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2562 2522
2563 /* dms do not consume food */ 2523 /* dms do not consume food */
2564 if (!QUERY_FLAG (op, FLAG_WIZ)) 2524 if (!QUERY_FLAG (op, FLAG_WIZ))
2565 op->stats.food--; 2525 op->stats.food--;
2566 } 2526 }
2567 2527
2568 if (op->stats.food < 0 && op->stats.hp >= 0) 2528 if (op->stats.food < 0 && op->stats.hp >= 0)
2569 { 2529 {
2570 object *tmp, *flesh = 0; 2530 object *flesh = 0;
2571 2531
2572 for (tmp = op->inv; tmp; tmp = tmp->below) 2532 for_inv_removable (op, tmp)
2573 { 2533 {
2574 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2534 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2535 continue;
2536
2537 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2575 { 2538 {
2576 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2539 op->statusmsg ("You blindly grab for a bite of food. "
2577 { 2540 "H<To prevent you from starving, you ate some random item from your backpack.>");
2578 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2579 manual_apply (op, tmp, 0); 2541 manual_apply (op, tmp, 0);
2542
2580 if (op->stats.food >= 0 || op->stats.hp < 0) 2543 if (op->stats.food >= 0 || op->stats.hp < 0)
2581 break; 2544 break;
2582 } 2545 }
2583 else if (tmp->type == FLESH) 2546 else if (tmp->type == FLESH)
2584 flesh = tmp; 2547 flesh = tmp;
2585 } /* End if paid for object */ 2548 }
2586 } /* end of for loop */
2587 2549
2588 /* If player is still starving, it means they don't have any food, so 2550 /* If player is still starving, it means they don't have any food, so
2589 * eat flesh instead. 2551 * eat flesh instead.
2590 */ 2552 */
2591 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2553 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2592 { 2554 {
2593 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2555 op->statusmsg ("You blindly grab for a bite of food. "
2556 "H<To prevent you from starving, you ate some random item from your backpack.>");
2594 manual_apply (op, flesh, 0); 2557 manual_apply (op, flesh, 0);
2595 } 2558 }
2559
2560 // If player is still starving, alert him!
2561 if (op->stats.food < 0)
2562 op->failmsg ("You are starving! "
2563 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2564 }
2565
2566 if (op->stats.food < 0)
2596 } 2567 {
2568 op->stats.hp += op->stats.food;
2569 op->stats.food = 0;
2597 2570
2598 while (op->stats.food < 0 && op->stats.hp >= 0) 2571 if (op->stats.hp < 0)
2599 op->stats.food++, op->stats.hp--; 2572 {
2573 op->contr->killer = archetype::get ("killer_starvation");
2574 op->contr->killer->destroy (true);
2575 }
2576 }
2600 2577
2578 /* killer should be set here already */
2601 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2579 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2602 kill_player (op); 2580 kill_player (op);
2603 } 2581 }
2604} 2582}
2605 2583
2609 * file. 2587 * file.
2610 */ 2588 */
2611void 2589void
2612kill_player (object *op) 2590kill_player (object *op)
2613{ 2591{
2592 int x, y;
2614 char buf[MAX_BUF]; 2593 char buf[MAX_BUF];
2615 int x, y;
2616
2617 //int i;
2618 maptile *map; /* this is for resurrection */ 2594 maptile *map; /* this is for resurrection */
2619
2620 /* int z;
2621 int num_stats_lose;
2622 int lost_a_stat;
2623 int lose_this_stat;
2624 int this_stat; */
2625 int will_kill_again; 2595 int will_kill_again;
2626 archetype *at; 2596 archetype *at;
2627 object *tmp; 2597 object *tmp;
2628 2598
2629 if (save_life (op)) 2599 if (save_life (op))
2630 return; 2600 return;
2631
2632 2601
2633 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2602 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
2634 * in cities ONLY!!! It is very important that this doesn't get abused. 2603 * in cities ONLY!!! It is very important that this doesn't get abused.
2635 * Look at op_on_battleground() for more info --AndreasV 2604 * Look at op_on_battleground() for more info --AndreasV
2636 */ 2605 */
2641 2610
2642 /* restore player */ 2611 /* restore player */
2643 at = archetype::find ("poisoning"); 2612 at = archetype::find ("poisoning");
2644 if (object *tmp = present_arch_in_ob (at, op)) 2613 if (object *tmp = present_arch_in_ob (at, op))
2645 { 2614 {
2646 tmp->destroy (); 2615 tmp->destroy (true);
2647 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2616 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2648 } 2617 }
2649 2618
2650 at = archetype::find ("confusion"); 2619 at = archetype::find ("confusion");
2651 if (object *tmp = present_arch_in_ob (at, op)) 2620 if (object *tmp = present_arch_in_ob (at, op))
2652 { 2621 {
2653 tmp->destroy (); 2622 tmp->destroy (true);
2654 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2623 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2655 } 2624 }
2656 2625
2657 cure_disease (op, 0); /* remove any disease */ 2626 cure_disease (op, 0, 0); /* remove any disease */
2658 op->stats.hp = op->stats.maxhp; 2627 op->stats.hp = op->stats.maxhp;
2659 if (op->stats.food <= 0) 2628 if (op->stats.food <= 0)
2660 op->stats.food = 999; 2629 op->stats.food = 999;
2661 2630
2662 /* create a bodypart-trophy to make the winner happy */ 2631 /* create a bodypart-trophy to make the winner happy */
2663 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2632 if (object *tmp = arch_to_object (archetype::find ("finger")))
2664 { 2633 {
2665 sprintf (buf, "%s's finger", &op->name); 2634 tmp->name = format ("%s's finger" , &op->name);
2666 tmp->name = buf; 2635 tmp->name_pl = format ("%s's fingers", &op->name);
2667 sprintf (buf, " This finger has been cut off %s\n"
2668 " the %s, when he was defeated at\n level %d by %s.\n",
2669 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2670 tmp->msg = buf; 2636 tmp->msg = format (
2637 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2638 &op->name, op->contr->title,
2639 (int)op->level,
2640 op->contr->killer_name ()
2641 );
2671 tmp->value = 0, tmp->type = 0; 2642 tmp->value = 0, tmp->type = 0;
2672 tmp->materialname = "organics"; 2643 tmp->materialname = "organics";
2673 tmp->insert_at (op, tmp); 2644 tmp->insert_at (op, tmp);
2674 } 2645 }
2675 2646
2681 2652
2682 INVOKE_PLAYER (DEATH, op->contr); 2653 INVOKE_PLAYER (DEATH, op->contr);
2683 2654
2684 command_kill_pets (op, 0); 2655 command_kill_pets (op, 0);
2685 2656
2686 if (op->stats.food < 0) 2657 op->contr->play_sound (sound_find ("player_dies"));
2687 {
2688 sprintf (buf, "%s starved to death.", &op->name);
2689 strcpy (op->contr->killer, "starvation");
2690 }
2691 else
2692 sprintf (buf, "%s died.", &op->name);
2693
2694 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2695 2658
2696 /* save the map location for corpse, gravestone */ 2659 /* save the map location for corpse, gravestone */
2697 x = op->x; 2660 x = op->x;
2698 y = op->y; 2661 y = op->y;
2699 map = op->map; 2662 map = op->map;
2806 lost_a_stat = 1; 2769 lost_a_stat = 1;
2807 } 2770 }
2808 } 2771 }
2809 } 2772 }
2810 } 2773 }
2774
2811 /* If no stat lost, tell the player. */ 2775 /* If no stat lost, tell the player. */
2812 if (!lost_a_stat) 2776 if (!lost_a_stat)
2813 { 2777 {
2814 /* determine_god() seems to not work sometimes... why is this? 2778 /* determine_god() seems to not work sometimes... why is this?
2815 Should I be using something else? GD */ 2779 Should I be using something else? GD */
2819 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2783 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
2820 else 2784 else
2821 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2822 } 2786 }
2823#else 2787#else
2824 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2788 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2825#endif 2789#endif
2826 2790
2827 /* Put a gravestone up where the character 'almost' died. List the 2791 /* Put a gravestone up where the character 'almost' died. List the
2828 * exp loss on the stone. 2792 * exp loss on the stone.
2829 */ 2793 */
2830 tmp = arch_to_object (archetype::find ("gravestone")); 2794 tmp = arch_to_object (archetype::find ("gravestone"));
2831 sprintf (buf, "%s's gravestone", &op->name); 2795 tmp->name = format ("%s's gravestone", &op->name);
2832 tmp->name = buf; 2796 tmp->name_pl = format ("%s's gravestones", &op->name);
2833 sprintf (buf, "%s's gravestones", &op->name); 2797 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2834 tmp->name_pl = buf; 2798 &op->name, op->contr->title, op->contr->killer_name ());
2835 sprintf (buf, "RIP\nHere rests the hero %s the %s,\n" "who was killed\n" "by %s.\n", &op->name, op->contr->title, op->contr->killer);
2836 tmp->msg = buf;
2837 tmp->x = op->x, tmp->y = op->y; 2799 tmp->x = op->x, tmp->y = op->y;
2838 insert_ob_in_map (tmp, op->map, NULL, 0); 2800 insert_ob_in_map (tmp, op->map, NULL, 0);
2839 2801
2840 /**************************************/ 2802 /**************************************/
2841 /* */ 2803 /* */
2850 at = archetype::find ("poisoning"); 2812 at = archetype::find ("poisoning");
2851 tmp = present_arch_in_ob (at, op); 2813 tmp = present_arch_in_ob (at, op);
2852 2814
2853 if (tmp) 2815 if (tmp)
2854 { 2816 {
2855 tmp->destroy (); 2817 tmp->destroy (true);
2856 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); 2818 new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed");
2857 } 2819 }
2858 2820
2859 at = archetype::find ("confusion"); 2821 at = archetype::find ("confusion");
2860 tmp = present_arch_in_ob (at, op); 2822 tmp = present_arch_in_ob (at, op);
2861 if (tmp) 2823 if (tmp)
2862 { 2824 {
2863 tmp->destroy (); 2825 tmp->destroy (true);
2864 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2826 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2865 } 2827 }
2866 2828
2867 cure_disease (op, 0); /* remove any disease */ 2829 cure_disease (op, 0, 0); /* remove any disease */
2830
2831 // remove all spell effects that are active
2832 // to avoid long-term effects such as word-of-recall
2833 for (object *item = op->inv; item; )
2834 {
2835 object *next = item->below;
2836
2837 if (item->type == SPELL_EFFECT && item->active)
2838 item->destroy (true);
2839
2840 item = next;
2841 }
2868 2842
2869 /*add_exp(op, (op->stats.exp * -0.20)); */ 2843 /*add_exp(op, (op->stats.exp * -0.20)); */
2870 apply_death_exp_penalty (op); 2844 apply_death_exp_penalty (op);
2845
2871 if (op->stats.food < 100) 2846 if (op->stats.food < 100)
2872 op->stats.food = 900; 2847 op->stats.food = 900;
2848
2873 op->stats.hp = op->stats.maxhp; 2849 op->stats.hp = op->stats.maxhp;
2874 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2850 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2875 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2851 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2876 2852
2877 /* 2853 /*
2878 * Check to see if the player has any unpaid items. If so, remove them 2854 * Check to see if the player has any unpaid items. If so, remove them
2879 * and put them back in the map. 2855 * and put them back in the map.
2880 */ 2856 */
2881 remove_unpaid_objects (op->inv, op); 2857 op->drop_unpaid_items ();
2882 2858
2883 /****************************************/ 2859 /****************************************/
2884 /* */ 2860 /* */
2885 /* Move player to his current respawn- */ 2861 /* Move player to his current respawn- */
2886 /* position (usually last savebed) */ 2862 /* position (usually last savebed) */
2915 if (will_kill_again & (1 << at)) 2891 if (will_kill_again & (1 << at))
2916 force->resist[at] = 100; 2892 force->resist[at] = 100;
2917 2893
2918 insert_ob_in_ob (force, op); 2894 insert_ob_in_ob (force, op);
2919 op->update_stats (); 2895 op->update_stats ();
2920
2921 } 2896 }
2922 2897
2923 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED."); 2898 new_draw_info (NDI_UNIQUE, 0, op, "YOU HAVE DIED.");
2924} 2899}
2925 2900
2945 2920
2946 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2921 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2947 { 2922 {
2948 if (tmp->nrof > 1) 2923 if (tmp->nrof > 1)
2949 { 2924 {
2950 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2925 tmp->decrease (rndm (1, tmp->nrof - 1));
2951 tmp2->destroy ();
2952 insert_ob_in_map (tmp, op->map, NULL, 0); 2926 insert_ob_in_map (tmp, op->map, NULL, 0);
2953 } 2927 }
2954 else 2928 else
2955 tmp->destroy (); 2929 tmp->destroy (true);
2956 } 2930 }
2957 else 2931 else
2958 insert_ob_in_map (tmp, op->map, NULL, 0); 2932 insert_ob_in_map (tmp, op->map, NULL, 0);
2959 } 2933 }
2960} 2934}
2967void 2941void
2968fix_weight (void) 2942fix_weight (void)
2969{ 2943{
2970 for_all_players (pl) 2944 for_all_players (pl)
2971 { 2945 {
2972 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2946 sint32 old = pl->ob->carrying;
2973 2947
2974 if (old == sum) 2948 pl->ob->update_weight ();
2975 continue; 2949
2950 if (old != pl->ob->carrying)
2951 {
2976 pl->ob->update_stats (); 2952 pl->ob->update_stats ();
2977 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 2953 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying);
2954 }
2978 } 2955 }
2979} 2956}
2980 2957
2981void 2958void
2982fix_luck (void) 2959fix_luck (void)
3018 if (op->type == PLAYER) 2995 if (op->type == PLAYER)
3019 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); 2996 new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name);
3020 2997
3021 cast_spell (op, throw_ob, dir, spob, NULL); 2998 cast_spell (op, throw_ob, dir, spob, NULL);
3022 2999
3023 throw_ob->destroy (); 3000 throw_ob->destroy (true);
3024} 3001}
3025 3002
3026void 3003void
3027make_visible (object *op) 3004make_visible (object *op)
3028{ 3005{
3029 op->hide = 0; 3006 op->hide = 0;
3030 op->invisible = 0; 3007 op->invisible = 0;
3008
3031 if (op->type == PLAYER) 3009 if (op->type == PLAYER)
3032 { 3010 {
3033 op->contr->tmp_invis = 0; 3011 op->contr->tmp_invis = 0;
3034 op->contr->invis_race = 0; 3012 op->contr->invis_race = 0;
3035 } 3013 }
3048 3026
3049/* look at the surrounding terrain to determine 3027/* look at the surrounding terrain to determine
3050 * the hideability of this object. Positive levels 3028 * the hideability of this object. Positive levels
3051 * indicate greater hideability. 3029 * indicate greater hideability.
3052 */ 3030 */
3053
3054int 3031int
3055hideability (object *ob) 3032hideability (object *ob)
3056{ 3033{
3057 int i, level = 0, mflag; 3034 int i, level = 0, mflag;
3058 sint16 x, y; 3035 sint16 x, y;
3068 * as bad as carrying a light on a pitch dark map */ 3045 * as bad as carrying a light on a pitch dark map */
3069 if (has_carried_lights (ob)) 3046 if (has_carried_lights (ob))
3070 level = -(10 + (2 * ob->map->darkness)); 3047 level = -(10 + (2 * ob->map->darkness));
3071 3048
3072 /* scan through all nearby squares for terrain to hide in */ 3049 /* scan through all nearby squares for terrain to hide in */
3073 for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3050 for (i = 0, x = ob->x, y = ob->y;
3051 i <= SIZEOFFREE1;
3052 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3074 { 3053 {
3075 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3054 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3076 if (mflag & P_OUT_OF_MAP) 3055 if (mflag & P_OUT_OF_MAP)
3077 {
3078 continue; 3056 continue;
3079 } 3057
3080 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3058 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3081 level += 2; 3059 level += 2;
3082 else /* open terrain! */ 3060 else /* open terrain! */
3083 level -= 1; 3061 level -= 1;
3084 } 3062 }
3095 * spot (surrounded by clear terrain in broad daylight). -b.t. 3073 * spot (surrounded by clear terrain in broad daylight). -b.t.
3096 */ 3074 */
3097void 3075void
3098do_hidden_move (object *op) 3076do_hidden_move (object *op)
3099{ 3077{
3100 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3078 int hide = 0;
3101 object *skop;
3102 3079
3103 if (!op || !op->map) 3080 if (!op || !op->map)
3104 return; 3081 return;
3105 3082
3106 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3083 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3084 int num = random_roll (0, 19, op, PREFER_LOW);
3107 3085
3108 /* its *extremely* hard to run and sneak/hide at the same time! */ 3086 /* its *extremely* hard to run and sneak/hide at the same time! */
3109 if (op->type == PLAYER && op->contr->run_on) 3087 if (op->type == PLAYER && op->contr->run_on)
3110 if (!skop || num >= skop->level) 3088 if (!skop || num >= skop->level)
3111 { 3089 {
3121 num -= hide; 3099 num -= hide;
3122 3100
3123 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3101 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3124 { 3102 {
3125 make_visible (op); 3103 make_visible (op);
3104
3126 if (op->type == PLAYER) 3105 if (op->type == PLAYER)
3127 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3106 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3128 } 3107 }
3129 else if (op->type == PLAYER && skop) 3108 else if (op->type == PLAYER && skop)
3130 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3109 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3183 * object op. This function works fine for monsters, 3162 * object op. This function works fine for monsters,
3184 * but we dont worry if the object isnt the top one in 3163 * but we dont worry if the object isnt the top one in
3185 * a pile (say a coin under a table would return "viewable" 3164 * a pile (say a coin under a table would return "viewable"
3186 * by this routine). Another question, should we be 3165 * by this routine). Another question, should we be
3187 * concerned with the direction the player is looking 3166 * concerned with the direction the player is looking
3188 * in? Realistically, most of use cant see stuff behind 3167 * in? Realistically, most of us can't see stuff behind
3189 * our backs...on the other hand, does the "facing" direction 3168 * our backs...on the other hand, does the "facing" direction
3190 * imply the way your head, or body is facing? Its possible 3169 * imply the way your head, or body is facing? It's possible
3191 * for them to differ. Sigh, this fctn could get a bit more complex. 3170 * for them to differ. Sigh, this fctn could get a bit more complex.
3192 * -b.t. 3171 * -b.t.
3193 * This function is now map tiling safe. 3172 * This function is now map tiling safe.
3194 */ 3173 */
3195
3196int 3174int
3197player_can_view (object *pl, object *op) 3175player_can_view (object *pl, object *op)
3198{ 3176{
3199 rv_vector rv; 3177 rv_vector rv;
3200 int dx, dy; 3178 int dx, dy;
3212 3190
3213 get_rangevector (pl, op, &rv, 0x1); 3191 get_rangevector (pl, op, &rv, 0x1);
3214 3192
3215 /* starting with the 'head' part, lets loop 3193 /* starting with the 'head' part, lets loop
3216 * through the object and find if it has any 3194 * through the object and find if it has any
3217 * part that is in the los array but isnt on 3195 * part that is in the los array but isn't on
3218 * a blocked los square. 3196 * a blocked los square.
3219 * we use the archetype to figure out offsets. 3197 * we use the archetype to figure out offsets.
3220 */ 3198 */
3221 while (op) 3199 while (op)
3222 { 3200 {
3225 3203
3226 /* only the viewable area the player sees is updated by LOS 3204 /* only the viewable area the player sees is updated by LOS
3227 * code, so we need to restrict ourselves to that range of values 3205 * code, so we need to restrict ourselves to that range of values
3228 * for any meaningful values. 3206 * for any meaningful values.
3229 */ 3207 */
3230 if (FABS (dx) <= (pl->contr->ns->mapx / 2) && 3208 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3231 FABS (dy) <= (pl->contr->ns->mapy / 2) && 3209 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3232 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)]) 3210 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3233 return 1; 3211 return 1;
3212
3234 op = op->more; 3213 op = op->more;
3235 } 3214 }
3215
3236 return 0; 3216 return 0;
3237} 3217}
3238 3218
3239/* routine for both players and monsters. We call this when 3219/* routine for both players and monsters. We call this when
3240 * there is a possibility for our action distrubing our hiding 3220 * there is a possibility for our action distrubing our hiding
3243 * return 0. 3223 * return 0.
3244 */ 3224 */
3245int 3225int
3246action_makes_visible (object *op) 3226action_makes_visible (object *op)
3247{ 3227{
3248
3249 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3228 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3250 { 3229 {
3251 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3230 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3252 return 0; 3231 return 0;
3253 3232
3259 { 3238 {
3260 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3239 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible");
3261 return 1; 3240 return 1;
3262 } 3241 }
3263 } 3242 }
3243
3264 return 0; 3244 return 0;
3265} 3245}
3266 3246
3267/* op_on_battleground - checks if the given object op (usually 3247/* op_on_battleground - checks if the given object op (usually
3268 * a player) is standing on a valid battleground-tile, 3248 * a player) is standing on a valid battleground-tile,
3273 * Default is to do the same as before, so only people wanting to have different points need worry about this 3253 * Default is to do the same as before, so only people wanting to have different points need worry about this
3274 */ 3254 */
3275int 3255int
3276op_on_battleground (object *op, int *x, int *y) 3256op_on_battleground (object *op, int *x, int *y)
3277{ 3257{
3278 object *tmp;
3279
3280 /* A battleground-tile needs the following attributes to be valid: 3258 /* A battleground-tile needs the following attributes to be valid:
3281 * is_floor 1 (has to be the FIRST floor beneath the player's feet), 3259 * is_floor 1 (has to be the FIRST floor beneath the player's feet),
3282 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND) 3260 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND)
3283 * and the exit-coordinates sp/hp must both be > 0. 3261 * and the exit-coordinates sp/hp must both be > 0.
3284 * => The intention here is to prevent abuse of the battleground- 3262 * => The intention here is to prevent abuse of the battleground-
3285 * feature (like pickable or hidden battleground tiles). */ 3263 * feature (like pickable or hidden battleground tiles). */
3286 for (tmp = op->below; tmp != NULL; tmp = tmp->below) 3264 for (object *tmp = op->below; tmp; tmp = tmp->below)
3287 { 3265 {
3288 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3266 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
3289 { 3267 {
3290 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && 3268 if (QUERY_FLAG (tmp, FLAG_NO_PICK)
3291 strcmp (tmp->name, "battleground") == 0 && tmp->type == BATTLEGROUND && EXIT_X (tmp) && EXIT_Y (tmp)) 3269 && tmp->type == BATTLEGROUND
3270 && tmp->name == shstr_battleground
3271 && EXIT_X (tmp) && EXIT_Y (tmp))
3292 { 3272 {
3293 /*before we assign the exit, check if this is a teambattle */ 3273 /* before we assign the exit, check if this is a teambattle */
3294 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3274 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3295 { 3275 {
3296 object *invtmp;
3297
3298 for (invtmp = op->inv; invtmp != NULL; invtmp = invtmp->below) 3276 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3299 { 3277 {
3300 if (invtmp->type == FORCE && invtmp->slaying && !strcmp (EXIT_PATH (tmp), invtmp->slaying)) 3278 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3301 { 3279 {
3302 if (x != NULL && y != NULL) 3280 if (x && y)
3303 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3281 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3282
3304 return 1; 3283 return 1;
3305 } 3284 }
3306 } 3285 }
3307 } 3286 }
3287
3308 if (x != NULL && y != NULL) 3288 if (x && y)
3309 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3289 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3290
3310 return 1; 3291 return 1;
3311 } 3292 }
3312 } 3293 }
3313 } 3294 }
3295
3314 /* If we got here, did not find a battleground */ 3296 /* If we got here, did not find a battleground */
3315 return 0; 3297 return 0;
3316} 3298}
3317 3299
3318/* 3300/*
3334 char buf[MAX_BUF]; /* tmp. string buffer */ 3316 char buf[MAX_BUF]; /* tmp. string buffer */
3335 int i = 0, j = 0; 3317 int i = 0, j = 0;
3336 3318
3337 /* get the appropriate treasurelist */ 3319 /* get the appropriate treasurelist */
3338 if (atnr == ATNR_FIRE) 3320 if (atnr == ATNR_FIRE)
3339 trlist = treasurelist::find ("dragon_ability_fire"); 3321 trlist = treasurelist::find (shstr_dragon_ability_fire);
3340 else if (atnr == ATNR_COLD) 3322 else if (atnr == ATNR_COLD)
3341 trlist = treasurelist::find ("dragon_ability_cold"); 3323 trlist = treasurelist::find (shstr_dragon_ability_cold);
3342 else if (atnr == ATNR_ELECTRICITY) 3324 else if (atnr == ATNR_ELECTRICITY)
3343 trlist = treasurelist::find ("dragon_ability_elec"); 3325 trlist = treasurelist::find (shstr_dragon_ability_elec);
3344 else if (atnr == ATNR_POISON) 3326 else if (atnr == ATNR_POISON)
3345 trlist = treasurelist::find ("dragon_ability_poison"); 3327 trlist = treasurelist::find (shstr_dragon_ability_poison);
3346 3328
3347 if (trlist == NULL || who->type != PLAYER) 3329 if (trlist == NULL || who->type != PLAYER)
3348 return; 3330 return;
3349 3331
3350 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); 3332 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++);
3423 { 3405 {
3424 /* forces in the treasurelist can alter the player's stats */ 3406 /* forces in the treasurelist can alter the player's stats */
3425 object *skin; 3407 object *skin;
3426 3408
3427 /* first get the dragon skin force */ 3409 /* first get the dragon skin force */
3428 shstr_cmp dragon_skin_force ("dragon_skin_force");
3429 for (skin = who->inv; skin && !(skin->arch->archname == dragon_skin_force); skin = skin->below) 3410 for (skin = who->inv; skin && !(skin->arch->archname == shstr_dragon_skin_force); skin = skin->below)
3430 ; 3411 ;
3431 3412
3432 if (!skin) 3413 if (!skin)
3433 return; 3414 return;
3434 3415
3469 else 3450 else
3470 { 3451 {
3471 /* generate misc. treasure */ 3452 /* generate misc. treasure */
3472 tmp = arch_to_object (tr->item); 3453 tmp = arch_to_object (tr->item);
3473 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3454 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3474 tmp = insert_ob_in_ob (tmp, who); 3455 who->insert (tmp);
3475 if (who->type == PLAYER)
3476 esrv_send_item (who, tmp);
3477 } 3456 }
3478} 3457}
3479 3458
3480/** 3459/**
3481 * Unready an object for a player. This function does nothing if the object was 3460 * Unready an object for a player. This function does nothing if the object was
3510 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) 3489 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3511 return 0; 3490 return 0;
3512 3491
3513 return 100 - blocked_los [x][y]; 3492 return 100 - blocked_los [x][y];
3514} 3493}
3494
3495void
3496player::infobox (const char *title, const char *msg, int color)
3497{
3498 send_msg (color | NDI_DEF | NDI_REPLY | NDI_CLEAR, title, msg);
3499}
3500
3501void
3502player::statusmsg (const char *msg, int color)
3503{
3504 send_msg (color | NDI_REPLY, INFO_CHANNEL, msg);
3505}
3506
3507void
3508player::failmsg (const char *msg, int color)
3509{
3510 play_sound (sound_find ("generic_failure"));
3511 statusmsg (msg, color);
3512}
3513

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines