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.174 by root, Thu Nov 8 19:43:27 2007 UTC vs.
Revision 1.198 by root, Sat May 17 00:17:02 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 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 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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);
239 set_dragon_name (ob, abil, skin); 239 set_dragon_name (ob, abil, skin);
240 } 240 }
241 241
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 243
244 esrv_new_player (this, ob->weight + ob->carrying); 244 esrv_new_player (this);
245 245
246 ob->update_stats (); 246 ob->update_stats ();
247 247
248 ns->floorbox_update (); 248 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob); 249 esrv_send_inventory (ob, ob);
291player::set_object (object *op) 291player::set_object (object *op)
292{ 292{
293 ob = observe = op; 293 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */ 294 ob->contr = this; /* this aren't yet in archetype */
295 295
296 ob->speed = 1.0f; 296 ob->speed = 1.0f;
297 ob->speed_left = 0.5f; 297 ob->speed_left = 0.5f;
298 298
299 ob->direction = 5; /* So player faces south */ 299 ob->direction = 5; /* So player faces south */
300 300
301 ob->flag [FLAG_READY_WEAPON] = false; 301 ob->flag [FLAG_READY_WEAPON] = false;
302 ob->flag [FLAG_READY_SKILL] = false; 302 ob->flag [FLAG_READY_SKILL] = false;
303 ob->flag [FLAG_READY_BOW] = false; 303 ob->flag [FLAG_READY_BOW] = false;
304 304
321 combat_ob = op; 321 combat_ob = op;
322 break; 322 break;
323 } 323 }
324 324
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_weapon activates, fix this better
326} 327}
327 328
328void 329void
329player::set_observe (object *op) 330player::set_observe (object *op)
330{ 331{
403 * Note: there MUST be at least one player archetype! 404 * Note: there MUST be at least one player archetype!
404 */ 405 */
405archetype * 406archetype *
406get_player_archetype (archetype *at) 407get_player_archetype (archetype *at)
407{ 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
408 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 415 archvec::iterator i = archetypes.find (nat);
409 416
410 for (;;) 417 for (;;)
411 { 418 {
412 if (++i == archetypes.end ()) 419 if (++i == archetypes.end ())
413 i = archetypes.begin (); 420 i = archetypes.begin ();
631 638
632 return firstdir; 639 return firstdir;
633} 640}
634 641
635void 642void
636give_initial_items (object *pl, treasurelist * items) 643give_initial_items (object *pl, treasurelist *items)
637{ 644{
638 object *op, *next = NULL;
639
640 if (pl->randomitems != NULL) 645 if (pl->randomitems)
641 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
642 647
643 for (op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
644 { 649 {
645 next = op->below; 650 next = op->below;
646 651
647 /* Forces get applied per default, unless they have the 652 /* Forces get applied per default, unless they have the
648 * 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
653 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
654 * by this player due to race restrictions 659 * by this player due to race restrictions
655 */ 660 */
656 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
657 { 662 {
658 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
659 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
660 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
661 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
662 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))
663 { 670 {
664 op->destroy (); 671 op->destroy ();
665 continue; 672 continue;
666 } 673 }
667 } 674 }
690 if (op->nrof > 1) 697 if (op->nrof > 1)
691 op->nrof = 1; 698 op->nrof = 1;
692 } 699 }
693 700
694 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
695 {
696 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
697 }
698 703
699 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
700 * 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
701 * merged properly. 706 * merged properly.
702 */ 707 */
703 if (need_identify (op)) 708 if (need_identify (op))
704 { 709 {
705 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
706 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
707 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
708 } 713 }
714
709 if (op->type == SPELL) 715 if (op->type == SPELL)
710 { 716 {
711 op->destroy (); 717 op->destroy ();
712 continue; 718 continue;
713 } 719 }
715 { 721 {
716 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
717 op->stats.exp = 0; 723 op->stats.exp = 0;
718 op->level = 1; 724 op->level = 1;
719 } 725 }
720 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
721 else
722 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
723 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
724 729
725 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
726 link_player_skills (pl); 731 link_player_skills (pl);
832static void 837static void
833start_info (object *op) 838start_info (object *op)
834{ 839{
835 char buf[MAX_BUF]; 840 char buf[MAX_BUF];
836 841
837 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 842 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
838 new_draw_info (NDI_UNIQUE, 0, op, buf); 843 new_draw_info (NDI_UNIQUE, 0, op, buf);
839 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
840 //new_draw_info (NDI_UNIQUE, 0, op, " ");
841} 844}
842 845
843/* This function takes the key that is passed, and does the 846/* This function takes the key that is passed, and does the
844 * appropriate action with it (change race, or other things). 847 * appropriate action with it (change race, or other things).
845 * The function name is for historical reasons - now we have 848 * The function name is for historical reasons - now we have
848 */ 851 */
849void 852void
850player::chargen_race_done () 853player::chargen_race_done ()
851{ 854{
852 /* this must before then initial items are given */ 855 /* this must before then initial items are given */
853 esrv_new_player (ob->contr, ob->weight + ob->carrying); 856 esrv_new_player (ob->contr);
854 857
855 treasurelist *tl = treasurelist::find ("starting_wealth"); 858 treasurelist *tl = treasurelist::find ("starting_wealth");
856 if (tl) 859 if (tl)
857 create_treasure (tl, ob, 0, 0, 0); 860 create_treasure (tl, ob, 0, 0, 0);
858 861
861 864
862 ob->contr->ns->state = ST_PLAYING; 865 ob->contr->ns->state = ST_PLAYING;
863 866
864 if (ob->msg) 867 if (ob->msg)
865 ob->msg = 0; 868 ob->msg = 0;
866
867 /* We create this now because some of the unique maps will need it
868 * to save here.
869 */
870 {
871 char buf[MAX_BUF];
872 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
873 make_path_to_file (buf);
874 }
875 869
876 start_info (ob); 870 start_info (ob);
877 CLEAR_FLAG (ob, FLAG_WIZ); 871 CLEAR_FLAG (ob, FLAG_WIZ);
878 give_initial_items (ob, ob->randomitems); 872 give_initial_items (ob, ob->randomitems);
879 link_player_skills (ob); 873 link_player_skills (ob);
882 876
883 /* This moves the player to a different start map, if there 877 /* This moves the player to a different start map, if there
884 * is one for this race 878 * is one for this race
885 */ 879 */
886 if (*first_map_ext_path) 880 if (*first_map_ext_path)
887 { 881 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
888 object *tmp;
889 char mapname[MAX_BUF];
890
891 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
892 tmp = object::create ();
893 EXIT_PATH (tmp) = mapname;
894 EXIT_X (tmp) = ob->x;
895 EXIT_Y (tmp) = ob->y;
896 ob->enter_exit (tmp); /* we don't really care if it succeeded;
897 * if the map isn't there, then stay on the
898 * default initial map */
899 tmp->destroy ();
900 }
901 else 882 else
902 LOG (llevDebug, "first_map_ext_path not set\n"); 883 LOG (llevDebug, "first_map_ext_path not set\n");
903} 884}
904 885
905void 886void
1008 if (op->move_type & MOVE_FLYING) 989 if (op->move_type & MOVE_FLYING)
1009 return 1; 990 return 1;
1010 991
1011 next = op->below; 992 next = op->below;
1012 993
994 int cnt = MAX_ITEM_PER_DROP;
995#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
996
1013 /* 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
1014 * destroyed */ 998 * destroyed */
1015 while (next && !next->destroyed ()) 999 while (next && !next->destroyed ())
1016 { 1000 {
1017 tmp = next; 1001 tmp = next;
1018 next = tmp->below; 1002 next = tmp->below;
1019 1003
1004 if (cnt <= 0)
1005 {
1006 op->failmsg ("Couldn't pickup all items at once.");
1007 return 0;
1008 }
1009
1020 if (op->destroyed ()) 1010 if (op->destroyed ())
1021 return 0; 1011 return 0;
1022 1012
1023 if (!can_pick (op, tmp)) 1013 if (!can_pick (op, tmp))
1024 continue; 1014 continue;
1025 1015
1026 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1016 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1027 { 1017 {
1028 if (item_matched_string (op, tmp, op->contr->search_str)) 1018 if (item_matched_string (op, tmp, op->contr->search_str))
1029 pick_up (op, tmp); 1019 CHK_PICK_PICKUP;
1030 continue; 1020 continue;
1031 } 1021 }
1032 1022
1033 /* high not bit set? We're using the old autopickup model */ 1023 /* high not bit set? We're using the old autopickup model */
1034 if (!(op->contr->mode & PU_NEWMODE)) 1024 if (!(op->contr->mode & PU_NEWMODE))
1036 switch (op->contr->mode) 1026 switch (op->contr->mode)
1037 { 1027 {
1038 case 0: 1028 case 0:
1039 return 1; /* don't pick up */ 1029 return 1; /* don't pick up */
1040 case 1: 1030 case 1:
1041 pick_up (op, tmp); 1031 CHK_PICK_PICKUP;
1042 return 1; 1032 return 1;
1043 case 2: 1033 case 2:
1044 pick_up (op, tmp); 1034 CHK_PICK_PICKUP;
1045 return 0; 1035 return 0;
1046 case 3: 1036 case 3:
1047 return 0; /* stop before pickup */ 1037 return 0; /* stop before pickup */
1048 case 4: 1038 case 4:
1049 pick_up (op, tmp); 1039 CHK_PICK_PICKUP;
1050 break; 1040 break;
1051 case 5: 1041 case 5:
1052 pick_up (op, tmp); 1042 CHK_PICK_PICKUP;
1053 stop = 1; 1043 stop = 1;
1054 break; 1044 break;
1055 case 6: 1045 case 6:
1056 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1046 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1057 pick_up (op, tmp); 1047 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1048 CHK_PICK_PICKUP;
1058 break; 1049 break;
1059 1050
1060 case 7: 1051 case 7:
1061 if (tmp->type == MONEY || tmp->type == GEM) 1052 if (tmp->type == MONEY || tmp->type == GEM)
1062 pick_up (op, tmp); 1053 CHK_PICK_PICKUP;
1063 break; 1054 break;
1064 1055
1065 default: 1056 default:
1066 /* use value density */ 1057 /* use value density */
1067 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1058 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1068 && (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)
1069 pick_up (op, tmp); 1060 CHK_PICK_PICKUP;
1070 } 1061 }
1071 } 1062 }
1072 else 1063 else
1073 { /* old model */ 1064 { /* old model */
1074 /* NEW pickup handling */ 1065 /* NEW pickup handling */
1129 /* all food and drink if desired */ 1120 /* all food and drink if desired */
1130 /* question: don't pick up known-poisonous stuff? */ 1121 /* question: don't pick up known-poisonous stuff? */
1131 if (op->contr->mode & PU_FOOD) 1122 if (op->contr->mode & PU_FOOD)
1132 if (tmp->type == FOOD) 1123 if (tmp->type == FOOD)
1133 { 1124 {
1134 pick_up (op, tmp); 1125 CHK_PICK_PICKUP;
1135 continue; 1126 continue;
1136 } 1127 }
1137 1128
1138 if (op->contr->mode & PU_DRINK) 1129 if (op->contr->mode & PU_DRINK)
1139 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)))
1140 { 1131 {
1141 pick_up (op, tmp); 1132 CHK_PICK_PICKUP;
1142 continue; 1133 continue;
1143 } 1134 }
1144 1135
1145 if (op->contr->mode & PU_POTION) 1136 if (op->contr->mode & PU_POTION)
1146 if (tmp->type == POTION) 1137 if (tmp->type == POTION)
1147 { 1138 {
1148 pick_up (op, tmp); 1139 CHK_PICK_PICKUP;
1149 continue; 1140 continue;
1150 } 1141 }
1151 1142
1152 /* spellbooks, skillscrolls and normal books/scrolls */ 1143 /* spellbooks, skillscrolls and normal books/scrolls */
1153 if (op->contr->mode & PU_SPELLBOOK) 1144 if (op->contr->mode & PU_SPELLBOOK)
1154 if (tmp->type == SPELLBOOK) 1145 if (tmp->type == SPELLBOOK)
1155 { 1146 {
1156 pick_up (op, tmp); 1147 CHK_PICK_PICKUP;
1157 continue; 1148 continue;
1158 } 1149 }
1159 1150
1160 if (op->contr->mode & PU_SKILLSCROLL) 1151 if (op->contr->mode & PU_SKILLSCROLL)
1161 if (tmp->type == SKILLSCROLL) 1152 if (tmp->type == SKILLSCROLL)
1162 { 1153 {
1163 pick_up (op, tmp); 1154 CHK_PICK_PICKUP;
1164 continue; 1155 continue;
1165 } 1156 }
1166 1157
1167 if (op->contr->mode & PU_READABLES) 1158 if (op->contr->mode & PU_READABLES)
1168 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) 1159 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1169 { 1160 {
1170 pick_up (op, tmp); 1161 CHK_PICK_PICKUP;
1171 continue; 1162 continue;
1172 } 1163 }
1173 1164
1174 /* wands/staves/rods/horns */ 1165 /* wands/staves/rods/horns */
1175 if (op->contr->mode & PU_MAGIC_DEVICE) 1166 if (op->contr->mode & PU_MAGIC_DEVICE)
1176 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1167 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1177 { 1168 {
1178 pick_up (op, tmp); 1169 CHK_PICK_PICKUP;
1179 continue; 1170 continue;
1180 } 1171 }
1181 1172
1182 /* pick up all magical items */ 1173 /* pick up all magical items */
1183 if (op->contr->mode & PU_MAGICAL) 1174 if (op->contr->mode & PU_MAGICAL)
1184 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))
1185 { 1176 {
1186 pick_up (op, tmp); 1177 CHK_PICK_PICKUP;
1187 continue; 1178 continue;
1188 } 1179 }
1189 1180
1190 if (op->contr->mode & PU_VALUABLES) 1181 if (op->contr->mode & PU_VALUABLES)
1191 { 1182 {
1192 if (tmp->type == MONEY || tmp->type == GEM) 1183 if (tmp->type == MONEY || tmp->type == GEM)
1193 { 1184 {
1194 pick_up (op, tmp); 1185 CHK_PICK_PICKUP;
1195 continue; 1186 continue;
1196 } 1187 }
1197 } 1188 }
1198 1189
1199 /* rings & amulets - talismans seems to be typed AMULET */ 1190 /* rings & amulets - talismans seems to be typed AMULET */
1200 if (op->contr->mode & PU_JEWELS) 1191 if (op->contr->mode & PU_JEWELS)
1201 if (tmp->type == RING || tmp->type == AMULET) 1192 if (tmp->type == RING || tmp->type == AMULET)
1202 { 1193 {
1203 pick_up (op, tmp); 1194 CHK_PICK_PICKUP;
1204 continue; 1195 continue;
1205 } 1196 }
1206 1197
1207 /* we don't forget dragon food */ 1198 /* we don't forget dragon food */
1208 if (op->contr->mode & PU_FLESH) 1199 if (op->contr->mode & PU_FLESH)
1209 if (tmp->type == FLESH) 1200 if (tmp->type == FLESH)
1210 { 1201 {
1211 pick_up (op, tmp); 1202 CHK_PICK_PICKUP;
1212 continue; 1203 continue;
1213 } 1204 }
1214 1205
1215 /* bows and arrows. Bows are good for selling! */ 1206 /* bows and arrows. Bows are good for selling! */
1216 if (op->contr->mode & PU_BOW) 1207 if (op->contr->mode & PU_BOW)
1217 if (tmp->type == BOW) 1208 if (tmp->type == BOW)
1218 { 1209 {
1219 pick_up (op, tmp); 1210 CHK_PICK_PICKUP;
1220 continue; 1211 continue;
1221 } 1212 }
1222 1213
1223 if (op->contr->mode & PU_ARROW) 1214 if (op->contr->mode & PU_ARROW)
1224 if (tmp->type == ARROW) 1215 if (tmp->type == ARROW)
1225 { 1216 {
1226 pick_up (op, tmp); 1217 CHK_PICK_PICKUP;
1227 continue; 1218 continue;
1228 } 1219 }
1229 1220
1230 /* all kinds of armor etc. */ 1221 /* all kinds of armor etc. */
1231 if (op->contr->mode & PU_ARMOUR) 1222 if (op->contr->mode & PU_ARMOUR)
1232 if (tmp->type == ARMOUR) 1223 if (tmp->type == ARMOUR)
1233 { 1224 {
1234 pick_up (op, tmp); 1225 CHK_PICK_PICKUP;
1235 continue; 1226 continue;
1236 } 1227 }
1237 1228
1238 if (op->contr->mode & PU_HELMET) 1229 if (op->contr->mode & PU_HELMET)
1239 if (tmp->type == HELMET) 1230 if (tmp->type == HELMET)
1240 { 1231 {
1241 pick_up (op, tmp); 1232 CHK_PICK_PICKUP;
1242 continue; 1233 continue;
1243 } 1234 }
1244 1235
1245 if (op->contr->mode & PU_SHIELD) 1236 if (op->contr->mode & PU_SHIELD)
1246 if (tmp->type == SHIELD) 1237 if (tmp->type == SHIELD)
1247 { 1238 {
1248 pick_up (op, tmp); 1239 CHK_PICK_PICKUP;
1249 continue; 1240 continue;
1250 } 1241 }
1251 1242
1252 if (op->contr->mode & PU_BOOTS) 1243 if (op->contr->mode & PU_BOOTS)
1253 if (tmp->type == BOOTS) 1244 if (tmp->type == BOOTS)
1254 { 1245 {
1255 pick_up (op, tmp); 1246 CHK_PICK_PICKUP;
1256 continue; 1247 continue;
1257 } 1248 }
1258 1249
1259 if (op->contr->mode & PU_GLOVES) 1250 if (op->contr->mode & PU_GLOVES)
1260 if (tmp->type == GLOVES) 1251 if (tmp->type == GLOVES)
1261 { 1252 {
1262 pick_up (op, tmp); 1253 CHK_PICK_PICKUP;
1263 continue; 1254 continue;
1264 } 1255 }
1265 1256
1266 if (op->contr->mode & PU_CLOAK) 1257 if (op->contr->mode & PU_CLOAK)
1267 if (tmp->type == CLOAK) 1258 if (tmp->type == CLOAK)
1268 { 1259 {
1269 pick_up (op, tmp); 1260 CHK_PICK_PICKUP;
1270 continue; 1261 continue;
1271 } 1262 }
1272 1263
1273 /* hoping to catch throwing daggers here */ 1264 /* hoping to catch throwing daggers here */
1274 if (op->contr->mode & PU_MISSILEWEAPON) 1265 if (op->contr->mode & PU_MISSILEWEAPON)
1275 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1266 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1276 { 1267 {
1277 pick_up (op, tmp); 1268 CHK_PICK_PICKUP;
1278 continue; 1269 continue;
1279 } 1270 }
1280 1271
1281 /* careful: chairs and tables are weapons! */ 1272 /* careful: chairs and tables are weapons! */
1282 if (op->contr->mode & PU_ALLWEAPON) 1273 if (op->contr->mode & PU_ALLWEAPON)
1284 if (tmp->type == WEAPON && tmp->name != NULL) 1275 if (tmp->type == WEAPON && tmp->name != NULL)
1285 { 1276 {
1286 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 &&
1287 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1278 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1288 { 1279 {
1289 pick_up (op, tmp); 1280 CHK_PICK_PICKUP;
1290 continue; 1281 continue;
1291 } 1282 }
1292 } 1283 }
1293 1284
1294 if (tmp->type == WEAPON && tmp->name == NULL) 1285 if (tmp->type == WEAPON && tmp->name == NULL)
1295 { 1286 {
1296 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)
1297 { 1288 {
1298 pick_up (op, tmp); 1289 CHK_PICK_PICKUP;
1299 continue; 1290 continue;
1300 } 1291 }
1301 } 1292 }
1302 } 1293 }
1303 1294
1304 /* misc stuff that's useful */ 1295 /* misc stuff that's useful */
1305 if (op->contr->mode & PU_KEY) 1296 if (op->contr->mode & PU_KEY)
1306 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1297 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1307 { 1298 {
1308 pick_up (op, tmp); 1299 CHK_PICK_PICKUP;
1309 continue; 1300 continue;
1310 } 1301 }
1311 1302
1312 /* 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
1313 * pickups */ 1304 * pickups */
1318 /* >=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
1319 * and multiply them by 5, giving 0..15*5== 5..75 */ 1310 * and multiply them by 5, giving 0..15*5== 5..75 */
1320 wvratio = (op->contr->mode & PU_RATIO) * 5; 1311 wvratio = (op->contr->mode & PU_RATIO) * 5;
1321 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)
1322 { 1313 {
1323 pick_up (op, tmp); 1314 CHK_PICK_PICKUP;
1324#if 0 1315#if 0
1325 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1316 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1326 if (tmp->name != NULL) 1317 if (tmp->name != NULL)
1327 { 1318 {
1328 fprintf (stderr, "%s", tmp->name); 1319 fprintf (stderr, "%s", tmp->name);
1347 * found object is returned. 1338 * found object is returned.
1348 */ 1339 */
1349object * 1340object *
1350find_arrow (object *op, const char *type) 1341find_arrow (object *op, const char *type)
1351{ 1342{
1352 object *tmp = 0;
1353
1354 for (op = op->inv; op; op = op->below) 1343 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1355 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1356 tmp = find_arrow (splay (op), type);
1357 else if (op->type == ARROW && op->race == type) 1344 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1358 return splay (op); 1345 return splay (tmp);
1359 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);
1352 return arrow;
1353 }
1354
1360 return tmp; 1355 return 0;
1361} 1356}
1362 1357
1363/* 1358/*
1364 * 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
1365 * 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
1388 } 1383 }
1389 } 1384 }
1390 else if (arrow->type == ARROW && arrow->race == type) 1385 else if (arrow->type == ARROW && arrow->race == type)
1391 { 1386 {
1392 /* allways prefer assasination/slaying */ 1387 /* allways prefer assasination/slaying */
1393 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1388 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1394 { 1389 {
1395 if (arrow->attacktype & AT_DEATH) 1390 if (arrow->attacktype & AT_DEATH)
1396 { 1391 {
1397 *better = 100; 1392 *better = 100;
1398 return arrow; 1393 return arrow;
1426 betterby = 1 + arrow->magic + arrow->stats.dam; 1421 betterby = 1 + arrow->magic + arrow->stats.dam;
1427 } 1422 }
1428 } 1423 }
1429 } 1424 }
1430 } 1425 }
1426
1431 if (tmp == NULL && arrow == NULL) 1427 if (tmp == NULL && arrow == NULL)
1432 return find_arrow (op, type); 1428 return find_arrow (op, type);
1433 1429
1434 *better = betterby; 1430 *better = betterby;
1435 return tmp; 1431 return tmp;
1586 arrow->destroy (); 1582 arrow->destroy ();
1587 return 0; 1583 return 0;
1588 } 1584 }
1589 1585
1590 left = arrow; /* these are arrows left to the player */ 1586 left = arrow; /* these are arrows left to the player */
1591 arrow = get_split_ob (arrow, 1); 1587 arrow = arrow->split ();
1592 if (!arrow) 1588 if (!arrow)
1593 { 1589 {
1594 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);
1595 return 0; 1591 return 0;
1596 } 1592 }
1663 op->play_sound (sound_find ("fire_arrow")); 1659 op->play_sound (sound_find ("fire_arrow"));
1664 m->insert (arrow, sx, sy, op); 1660 m->insert (arrow, sx, sy, op);
1665 1661
1666 if (!arrow->destroyed ()) 1662 if (!arrow->destroyed ())
1667 move_arrow (arrow); 1663 move_arrow (arrow);
1668
1669 if (op->type == PLAYER)
1670 {
1671 if (left->destroyed ())
1672 esrv_del_item (op->contr, left->count);
1673 else
1674 esrv_send_item (op, left);
1675 }
1676 1664
1677 return 1; 1665 return 1;
1678} 1666}
1679 1667
1680/* Special fire code for players - this takes into 1668/* Special fire code for players - this takes into
1754 return; 1742 return;
1755 } 1743 }
1756 } 1744 }
1757 else if (item->type == ROD || item->type == HORN) 1745 else if (item->type == ROD || item->type == HORN)
1758 { 1746 {
1759 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))
1760 { 1752 {
1761 op->contr->play_sound (sound_find ("wand_poof")); 1753 op->contr->play_sound (sound_find ("wand_poof"));
1762 1754
1763 if (item->type == ROD) 1755 if (item->type == ROD)
1764 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));
1783 CLEAR_FLAG (item, FLAG_ANIMATE); 1775 CLEAR_FLAG (item, FLAG_ANIMATE);
1784 item->face = item->arch->face; 1776 item->face = item->arch->face;
1785 item->set_speed (0); 1777 item->set_speed (0);
1786 } 1778 }
1787 1779
1788 if ((tmp = item->in_player ())) 1780 if (object *pl = item->visible_to ())
1789 esrv_update_item (UPD_ANIM, tmp, item); 1781 esrv_update_item (UPD_ANIM, pl, item);
1790 } 1782 }
1791 } 1783 }
1792 else if (item->type == ROD || item->type == HORN) 1784 else if (item->type == ROD || item->type == HORN)
1793 drain_rod_charge (item); 1785 drain_rod_charge (item);
1794 } 1786 }
1970 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); 1962 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
1971 remove_door2 (door); /* remove door without violence ;-) */ 1963 remove_door2 (door); /* remove door without violence ;-) */
1972 } 1964 }
1973 1965
1974 /* Do this after we print the message */ 1966 /* Do this after we print the message */
1975 decrease_ob (key); /* Use up one of the keys */ 1967 key->decrease (); /* Use up one of the keys */
1976 /* Need to update the weight the container the key was in */
1977 if (container != op)
1978 esrv_update_item (UPD_WEIGHT, op, container);
1979 1968
1980 return 1; /* Nothing more to do below */ 1969 return 1; /* Nothing more to do below */
1981 } 1970 }
1982 else if (door->type == LOCKED_DOOR) 1971 else if (door->type == LOCKED_DOOR)
1983 { 1972 {
2164bool 2153bool
2165move_player (object *op, int dir) 2154move_player (object *op, int dir)
2166{ 2155{
2167 int pick; 2156 int pick;
2168 2157
2169 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2158 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2170 return 0; 2159 return 0;
2171 2160
2172 /* Sanity check: make sure dir is valid */ 2161 /* Sanity check: make sure dir is valid */
2173 if ((dir < 0) || (dir >= 9)) 2162 if ((dir < 0) || (dir >= 9))
2174 { 2163 {
2262 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2251 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2263 { 2252 {
2264 op->play_sound (sound_find ("ob_evaporate")); 2253 op->play_sound (sound_find ("ob_evaporate"));
2265 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));
2266 2255
2267 if (op->contr)
2268 esrv_del_item (op->contr, tmp->count);
2269
2270 tmp->destroy (); 2256 tmp->destroy ();
2271 CLEAR_FLAG (op, FLAG_LIFESAVE); 2257 CLEAR_FLAG (op, FLAG_LIFESAVE);
2272 2258
2273 if (op->stats.hp < 0) 2259 if (op->stats.hp < 0)
2274 op->stats.hp = op->stats.maxhp; 2260 op->stats.hp = op->stats.maxhp;
2286 return 0; 2272 return 0;
2287} 2273}
2288 2274
2289/* 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
2290 * 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
2291 * 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
2292 * from. 2278 * from.
2293 */ 2279 */
2294static void 2280static void
2295drop_unpaid_items (object *op, object *env) 2281drop_unpaid_items (object *op, object *env)
2296{ 2282{
2297 while (op) 2283 while (op)
2298 { 2284 {
2299 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2285 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2300 2286
2301 if (QUERY_FLAG (op, FLAG_UNPAID)) 2287 if (QUERY_FLAG (op, FLAG_UNPAID))
2302 {
2303 if (env->type == PLAYER)
2304 esrv_del_item (env->contr, op->count);
2305
2306 op->insert_at (env); 2288 op->insert_at (env);
2307 }
2308 else if (op->inv) 2289 else if (op->inv)
2309 drop_unpaid_items (op->inv, env); 2290 drop_unpaid_items (op->inv, env);
2310 2291
2311 op = next; 2292 op = next;
2312 } 2293 }
2324 * Moved from apply.c to player.c - player.c is what 2305 * Moved from apply.c to player.c - player.c is what
2325 * actually uses this function. player.c may not be quite the 2306 * actually uses this function. player.c may not be quite the
2326 * best, a misc file for object actions is probably better, 2307 * best, a misc file for object actions is probably better,
2327 * but there isn't one in the server directory. 2308 * but there isn't one in the server directory.
2328 */ 2309 */
2329char * 2310const char *
2330gravestone_text (object *op) 2311gravestone_text (object *op)
2331{ 2312{
2332 static char buf2[MAX_BUF]; 2313 static dynbuf_text buf;
2333 char buf[MAX_BUF];
2334 time_t now = time (NULL);
2335 2314
2336 strcpy (buf2, " R.I.P.\n\n"); 2315 buf << "---- R.I.P. ----\n\n";
2316 op->name;
2317
2337 if (op->type == PLAYER) 2318 if (op->type == PLAYER)
2338 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2319 buf << " the " << op->contr->title;
2339 else
2340 sprintf (buf, "%s\n", &op->name);
2341 2320
2342 strncat (buf2, " ", 20 - strlen (buf) / 2); 2321 buf << "\n\n";
2343 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
2344 if (op->type == PLAYER) 2327 if (op->type == PLAYER)
2345 sprintf (buf, "who was in level %d when killed\n", op->level); 2328 buf << "by " << op->contr->killer_name () << ".\n\n";
2346 else
2347 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2348 2329
2349 strncat (buf2, " ", 20 - strlen (buf) / 2);
2350 strcat (buf2, buf);
2351 if (op->type == PLAYER)
2352 { 2330 {
2353 sprintf (buf, "by %s.\n\n", op->contr->killer); 2331 static char buf2[128];
2354 strncat (buf2, " ", 21 - strlen (buf) / 2); 2332 time_t now = time (NULL);
2355 strcat (buf2, buf);
2356 }
2357
2358 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2333 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2359 strncat (buf2, " ", 20 - strlen (buf) / 2); 2334 buf << buf2;
2360 strcat (buf2, buf); 2335 }
2361 2336
2362 return buf2; 2337 return buf;
2363} 2338}
2364 2339
2365void 2340void
2366do_some_living (object *op) 2341do_some_living (object *op)
2367{ 2342{
2548 op->stats.food--; 2523 op->stats.food--;
2549 } 2524 }
2550 2525
2551 if (op->stats.food < 0 && op->stats.hp >= 0) 2526 if (op->stats.food < 0 && op->stats.hp >= 0)
2552 { 2527 {
2553 object *tmp, *flesh = 0; 2528 object *flesh = 0;
2554 2529
2555 for (tmp = op->inv; tmp; tmp = tmp->below) 2530 for_inv_removable (op, tmp)
2556 { 2531 {
2557 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)
2558 { 2536 {
2559 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2537 op->statusmsg ("You blindly grab for a bite of food. "
2560 { 2538 "H<To prevent you from starving, you ate some random item from your backpack.>");
2561 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2562 manual_apply (op, tmp, 0); 2539 manual_apply (op, tmp, 0);
2540
2563 if (op->stats.food >= 0 || op->stats.hp < 0) 2541 if (op->stats.food >= 0 || op->stats.hp < 0)
2564 break; 2542 break;
2565 } 2543 }
2566 else if (tmp->type == FLESH) 2544 else if (tmp->type == FLESH)
2567 flesh = tmp; 2545 flesh = tmp;
2568 } /* End if paid for object */ 2546 }
2569 } /* end of for loop */
2570 2547
2571 /* 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
2572 * eat flesh instead. 2549 * eat flesh instead.
2573 */ 2550 */
2574 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2551 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2575 { 2552 {
2576 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.>");
2577 manual_apply (op, flesh, 0); 2555 manual_apply (op, flesh, 0);
2578 } 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.>");
2579 } 2562 }
2580 2563
2581 if (op->stats.food < 0) 2564 if (op->stats.food < 0)
2582 { 2565 {
2583 op->stats.hp += op->stats.food; 2566 op->stats.hp += op->stats.food;
2584 op->stats.food = 0; 2567 op->stats.food = 0;
2585 } 2568 }
2586 2569
2587 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2570 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2588 kill_player (op); 2571 kill_player (op);
2641 { 2624 {
2642 tmp->name = format ("%s's finger" , &op->name); 2625 tmp->name = format ("%s's finger" , &op->name);
2643 tmp->name_pl = format ("%s's fingers", &op->name); 2626 tmp->name_pl = format ("%s's fingers", &op->name);
2644 tmp->msg = format ( 2627 tmp->msg = format (
2645 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2628 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2646 &op->name, op->contr->title, (int) (op->level), op->contr->killer 2629 &op->name, op->contr->title,
2630 (int)op->level,
2631 op->contr->killer_name ()
2647 ); 2632 );
2648 tmp->value = 0, tmp->type = 0; 2633 tmp->value = 0, tmp->type = 0;
2649 tmp->materialname = "organics"; 2634 tmp->materialname = "organics";
2650 tmp->insert_at (op, tmp); 2635 tmp->insert_at (op, tmp);
2651 } 2636 }
2659 INVOKE_PLAYER (DEATH, op->contr); 2644 INVOKE_PLAYER (DEATH, op->contr);
2660 2645
2661 command_kill_pets (op, 0); 2646 command_kill_pets (op, 0);
2662 2647
2663 if (op->stats.food < 0) 2648 if (op->stats.food < 0)
2664 strcpy (op->contr->killer, "starvation"); 2649 {
2650 op->contr->killer = archetype::get ("killer_starvation");
2651 op->contr->killer->destroy ();
2652 }
2665 2653
2666 op->contr->play_sound (sound_find ("player_dies")); 2654 op->contr->play_sound (sound_find ("player_dies"));
2667 2655
2668 /* save the map location for corpse, gravestone */ 2656 /* save the map location for corpse, gravestone */
2669 x = op->x; 2657 x = op->x;
2778 lost_a_stat = 1; 2766 lost_a_stat = 1;
2779 } 2767 }
2780 } 2768 }
2781 } 2769 }
2782 } 2770 }
2771
2783 /* If no stat lost, tell the player. */ 2772 /* If no stat lost, tell the player. */
2784 if (!lost_a_stat) 2773 if (!lost_a_stat)
2785 { 2774 {
2786 /* determine_god() seems to not work sometimes... why is this? 2775 /* determine_god() seems to not work sometimes... why is this?
2787 Should I be using something else? GD */ 2776 Should I be using something else? GD */
2791 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);
2792 else 2781 else
2793 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.");
2794 } 2783 }
2795#else 2784#else
2796 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.");
2797#endif 2786#endif
2798 2787
2799 /* Put a gravestone up where the character 'almost' died. List the 2788 /* Put a gravestone up where the character 'almost' died. List the
2800 * exp loss on the stone. 2789 * exp loss on the stone.
2801 */ 2790 */
2802 tmp = arch_to_object (archetype::find ("gravestone")); 2791 tmp = arch_to_object (archetype::find ("gravestone"));
2803 sprintf (buf, "%s's gravestone", &op->name); 2792 tmp->name = format ("%s's gravestone", &op->name);
2804 tmp->name = buf; 2793 tmp->name_pl = format ("%s's gravestones", &op->name);
2805 sprintf (buf, "%s's gravestones", &op->name);
2806 tmp->name_pl = buf;
2807 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 ());
2808 tmp->msg = buf;
2809 tmp->x = op->x, tmp->y = op->y; 2795 tmp->x = op->x, tmp->y = op->y;
2810 insert_ob_in_map (tmp, op->map, NULL, 0); 2796 insert_ob_in_map (tmp, op->map, NULL, 0);
2811 2797
2812 /**************************************/ 2798 /**************************************/
2813 /* */ 2799 /* */
2836 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2822 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2837 } 2823 }
2838 2824
2839 cure_disease (op, 0, 0); /* remove any disease */ 2825 cure_disease (op, 0, 0); /* remove any disease */
2840 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 }
2838
2841 /*add_exp(op, (op->stats.exp * -0.20)); */ 2839 /*add_exp(op, (op->stats.exp * -0.20)); */
2842 apply_death_exp_penalty (op); 2840 apply_death_exp_penalty (op);
2841
2843 if (op->stats.food < 100) 2842 if (op->stats.food < 100)
2844 op->stats.food = 900; 2843 op->stats.food = 900;
2844
2845 op->stats.hp = op->stats.maxhp; 2845 op->stats.hp = op->stats.maxhp;
2846 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2846 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2847 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2847 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2848 2848
2849 /* 2849 /*
2917 2917
2918 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))))
2919 { 2919 {
2920 if (tmp->nrof > 1) 2920 if (tmp->nrof > 1)
2921 { 2921 {
2922 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2922 tmp->decrease (rndm (1, tmp->nrof - 1));
2923 tmp2->destroy ();
2924 insert_ob_in_map (tmp, op->map, NULL, 0); 2923 insert_ob_in_map (tmp, op->map, NULL, 0);
2925 } 2924 }
2926 else 2925 else
2927 tmp->destroy (); 2926 tmp->destroy ();
2928 } 2927 }
2939void 2938void
2940fix_weight (void) 2939fix_weight (void)
2941{ 2940{
2942 for_all_players (pl) 2941 for_all_players (pl)
2943 { 2942 {
2944 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2943 sint32 old = pl->ob->carrying;
2945 2944
2946 if (old == sum) 2945 pl->ob->update_weight ();
2947 continue; 2946
2947 if (old != pl->ob->carrying)
2948 {
2948 pl->ob->update_stats (); 2949 pl->ob->update_stats ();
2949 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 }
2950 } 2952 }
2951} 2953}
2952 2954
2953void 2955void
2954fix_luck (void) 2956fix_luck (void)
3040 * as bad as carrying a light on a pitch dark map */ 3042 * as bad as carrying a light on a pitch dark map */
3041 if (has_carried_lights (ob)) 3043 if (has_carried_lights (ob))
3042 level = -(10 + (2 * ob->map->darkness)); 3044 level = -(10 + (2 * ob->map->darkness));
3043 3045
3044 /* scan through all nearby squares for terrain to hide in */ 3046 /* scan through all nearby squares for terrain to hide in */
3045 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])
3046 { 3050 {
3047 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3051 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3048 if (mflag & P_OUT_OF_MAP) 3052 if (mflag & P_OUT_OF_MAP)
3049 {
3050 continue; 3053 continue;
3051 } 3054
3052 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3055 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3053 level += 2; 3056 level += 2;
3054 else /* open terrain! */ 3057 else /* open terrain! */
3055 level -= 1; 3058 level -= 1;
3056 } 3059 }
3067 * spot (surrounded by clear terrain in broad daylight). -b.t. 3070 * spot (surrounded by clear terrain in broad daylight). -b.t.
3068 */ 3071 */
3069void 3072void
3070do_hidden_move (object *op) 3073do_hidden_move (object *op)
3071{ 3074{
3072 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3075 int hide = 0;
3073 object *skop;
3074 3076
3075 if (!op || !op->map) 3077 if (!op || !op->map)
3076 return; 3078 return;
3077 3079
3078 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);
3079 3082
3080 /* 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! */
3081 if (op->type == PLAYER && op->contr->run_on) 3084 if (op->type == PLAYER && op->contr->run_on)
3082 if (!skop || num >= skop->level) 3085 if (!skop || num >= skop->level)
3083 { 3086 {
3093 num -= hide; 3096 num -= hide;
3094 3097
3095 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3098 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3096 { 3099 {
3097 make_visible (op); 3100 make_visible (op);
3101
3098 if (op->type == PLAYER) 3102 if (op->type == PLAYER)
3099 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!");
3100 } 3104 }
3101 else if (op->type == PLAYER && skop) 3105 else if (op->type == PLAYER && skop)
3102 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);
3443 else 3447 else
3444 { 3448 {
3445 /* generate misc. treasure */ 3449 /* generate misc. treasure */
3446 tmp = arch_to_object (tr->item); 3450 tmp = arch_to_object (tr->item);
3447 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));
3448 tmp = insert_ob_in_ob (tmp, who); 3452 who->insert (tmp);
3449 if (who->type == PLAYER)
3450 esrv_send_item (who, tmp);
3451 } 3453 }
3452} 3454}
3453 3455
3454/** 3456/**
3455 * 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines