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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines