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.163 by root, Thu Aug 23 17:16:17 2007 UTC vs.
Revision 1.202 by root, Fri Aug 29 02:07:09 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 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
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) 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, 13 * This program is distributed in the hope that it will be useful,
16 * GNU General Public License 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 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * 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>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <sproto.h> 25#include <sproto.h>
26#include <sounds.h> 26#include <sounds.h>
122 continue; 122 continue;
123 123
124 if (*buf == '%') 124 if (*buf == '%')
125 { /* send one news */ 125 { /* send one news */
126 if (size > 0) 126 if (size > 0)
127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", (char *)"%s\n%s", subject, news); /*send previously read news */ 127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
128 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
129 "INFORMATION: %s\n%s", (char *)"%s\n%s",
130 subject, news); /*send previously read news */
128 131
129 strcpy (subject, buf + 1); 132 strcpy (subject, buf + 1);
130 strip_endline (subject); 133 strip_endline (subject);
131 size = 0; 134 size = 0;
132 news[0] = '\0'; 135 news[0] = '\0';
183 186
184 if (ob->map) 187 if (ob->map)
185 maplevel = ob->map->path; 188 maplevel = ob->map->path;
186 189
187 ob->remove (); 190 ob->remove ();
191 ob->enemy = 0; // sometimes keeps an extra refcount on itself
188 ob->map = 0; 192 ob->map = 0;
189 party = 0; 193 party = 0;
190 194
191 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this 195 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this
192 196
214 218
215 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
216 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
217 ob->race = ob->arch->race; 221 ob->race = ob->arch->race;
218 222
219 ob->carrying = sum_weight (ob); 223 ob->update_weight ();
220 link_player_skills (ob); 224 link_player_skills (ob);
221 225
222 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 226 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
223 227
224 assign (title, ob->arch->object::name); 228 assign (title, ob->arch->object::name);
238 set_dragon_name (ob, abil, skin); 242 set_dragon_name (ob, abil, skin);
239 } 243 }
240 244
241 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
242 246
243 esrv_new_player (this, ob->weight + ob->carrying); 247 esrv_new_player (this);
248
249 ob->update_stats ();
250
251 ns->floorbox_update ();
252 esrv_send_inventory (ob, ob);
253 esrv_add_spells (this, 0);
254
255 activate ();
256
257 send_rules (ob);
258 send_news (ob);
259 display_motd (ob);
260
261 INVOKE_PLAYER (CONNECT, this);
262 INVOKE_PLAYER (LOGIN, this);
263}
264
265void
266player::disconnect ()
267{
268 if (ob)
269 {
270 ob->close_container (); //TODO: client-specific
271 ob->drop_unpaid_items ();
272 }
273
274 if (ns)
275 {
276 if (active)
277 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
278
279 INVOKE_PLAYER (DISCONNECT, this);
280
281 ns->reset_stats ();
282 ns->pl = 0;
283 ns = 0;
284 }
285
286 observe = ob;
287
288 deactivate ();
289}
290
291// the need for this function can be explained
292// by load_object not returning the object
293void
294player::set_object (object *op)
295{
296 ob = observe = op;
297 ob->contr = this; /* this aren't yet in archetype */
298
299 ob->speed = 1.0f;
300 ob->speed_left = 0.5f;
301
302 ob->direction = 5; /* So player faces south */
244 303
245 ob->flag [FLAG_READY_WEAPON] = false; 304 ob->flag [FLAG_READY_WEAPON] = false;
246 ob->flag [FLAG_READY_SKILL] = false; 305 ob->flag [FLAG_READY_SKILL] = false;
247 ob->flag [FLAG_READY_BOW] = false; 306 ob->flag [FLAG_READY_BOW] = false;
248 307
265 combat_ob = op; 324 combat_ob = op;
266 break; 325 break;
267 } 326 }
268 327
269 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
270 ob->update_stats (); 329 ob->deactivate (); // change_weapon activates, fix this better
271
272 ns->floorbox_update ();
273 esrv_send_inventory (ob, ob);
274 esrv_add_spells (this, 0);
275
276 activate ();
277
278 send_rules (ob);
279 send_news (ob);
280 display_motd (ob);
281
282 INVOKE_PLAYER (CONNECT, this);
283 INVOKE_PLAYER (LOGIN, this);
284}
285
286void
287player::disconnect ()
288{
289 if (ob)
290 {
291 ob->close_container (); //TODO: client-specific
292 ob->drop_unpaid_items ();
293 }
294
295 if (ns)
296 {
297 if (active)
298 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
299
300 INVOKE_PLAYER (DISCONNECT, this);
301
302 ns->reset_stats ();
303 ns->pl = 0;
304 ns = 0;
305 }
306
307 observe = ob;
308
309 deactivate ();
310}
311
312// the need for this function can be explained
313// by load_object not returning the object
314void
315player::set_object (object *op)
316{
317 ob = observe = op;
318 ob->contr = this; /* this aren't yet in archetype */
319
320 ob->speed = 1.0f;
321 ob->speed_left = 0.5f;
322
323 ob->direction = 5; /* So player faces south */
324} 330}
325 331
326void 332void
327player::set_observe (object *op) 333player::set_observe (object *op)
328{ 334{
342 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
343 349
344 gen_sp_armour = 10; 350 gen_sp_armour = 10;
345 bowtype = bow_normal; 351 bowtype = bow_normal;
346 petmode = pet_normal; 352 petmode = pet_normal;
347 listening = 10;
348 usekeys = containers; 353 usekeys = containers;
349 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
350 do_los = 1; 355 do_los = 1;
351 356
352 weapon_sp = 1.0f; 357 weapon_sp = 1.0f;
401 * Note: there MUST be at least one player archetype! 406 * Note: there MUST be at least one player archetype!
402 */ 407 */
403archetype * 408archetype *
404get_player_archetype (archetype *at) 409get_player_archetype (archetype *at)
405{ 410{
411 // archetypes could have been reloaded
412 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
413
414 if (!nat)
415 return at;
416
406 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 417 archvec::iterator i = archetypes.find (nat);
407 418
408 for (;;) 419 for (;;)
409 { 420 {
410 if (++i == archetypes.end ()) 421 if (++i == archetypes.end ())
411 i = archetypes.begin (); 422 i = archetypes.begin ();
629 640
630 return firstdir; 641 return firstdir;
631} 642}
632 643
633void 644void
634give_initial_items (object *pl, treasurelist * items) 645give_initial_items (object *pl, treasurelist *items)
635{ 646{
636 object *op, *next = NULL;
637
638 if (pl->randomitems != NULL) 647 if (pl->randomitems)
639 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 648 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
640 649
641 for (op = pl->inv; op; op = next) 650 for (object *next, *op = pl->inv; op; op = next)
642 { 651 {
643 next = op->below; 652 next = op->below;
644 653
645 /* Forces get applied per default, unless they have the 654 /* Forces get applied per default, unless they have the
646 * flag "neutral" set. Sorry but I can't think of a better way 655 * flag "neutral" set. Sorry but I can't think of a better way
651 /* we never give weapons/armour if these cannot be used 660 /* we never give weapons/armour if these cannot be used
652 * by this player due to race restrictions 661 * by this player due to race restrictions
653 */ 662 */
654 if (pl->type == PLAYER) 663 if (pl->type == PLAYER)
655 { 664 {
656 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 665 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
666 &&
657 (op->type == ARMOUR || op->type == BOOTS || 667 (op->type == ARMOUR || op->type == BOOTS
658 op->type == CLOAK || op->type == HELMET || 668 || op->type == CLOAK || op->type == HELMET
659 op->type == SHIELD || op->type == GLOVES || 669 || op->type == SHIELD || op->type == GLOVES
670 || op->type == BRACERS || op->type == GIRDLE))
660 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 671 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
661 { 672 {
662 op->destroy (); 673 op->destroy ();
663 continue; 674 continue;
664 } 675 }
665 } 676 }
688 if (op->nrof > 1) 699 if (op->nrof > 1)
689 op->nrof = 1; 700 op->nrof = 1;
690 } 701 }
691 702
692 if (op->type == SPELLBOOK && op->inv) 703 if (op->type == SPELLBOOK && op->inv)
693 {
694 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 704 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
695 }
696 705
697 /* Give starting characters identified, uncursed, and undamned 706 /* Give starting characters identified, uncursed, and undamned
698 * items. Just don't identify gold or silver, or it won't be 707 * items. Just don't identify gold or silver, or it won't be
699 * merged properly. 708 * merged properly.
700 */ 709 */
701 if (need_identify (op)) 710 if (need_identify (op))
702 { 711 {
703 SET_FLAG (op, FLAG_IDENTIFIED); 712 SET_FLAG (op, FLAG_IDENTIFIED);
704 CLEAR_FLAG (op, FLAG_CURSED); 713 CLEAR_FLAG (op, FLAG_CURSED);
705 CLEAR_FLAG (op, FLAG_DAMNED); 714 CLEAR_FLAG (op, FLAG_DAMNED);
706 } 715 }
716
707 if (op->type == SPELL) 717 if (op->type == SPELL)
708 { 718 {
709 op->destroy (); 719 op->destroy ();
710 continue; 720 continue;
711 } 721 }
713 { 723 {
714 SET_FLAG (op, FLAG_CAN_USE_SKILL); 724 SET_FLAG (op, FLAG_CAN_USE_SKILL);
715 op->stats.exp = 0; 725 op->stats.exp = 0;
716 op->level = 1; 726 op->level = 1;
717 } 727 }
718 /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
719 else
720 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
721 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
722 731
723 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
724 link_player_skills (pl); 733 link_player_skills (pl);
830static void 839static void
831start_info (object *op) 840start_info (object *op)
832{ 841{
833 char buf[MAX_BUF]; 842 char buf[MAX_BUF];
834 843
835 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 844 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
836 new_draw_info (NDI_UNIQUE, 0, op, buf); 845 new_draw_info (NDI_UNIQUE, 0, op, buf);
837 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
838 //new_draw_info (NDI_UNIQUE, 0, op, " ");
839} 846}
840 847
841/* This function takes the key that is passed, and does the 848/* This function takes the key that is passed, and does the
842 * appropriate action with it (change race, or other things). 849 * appropriate action with it (change race, or other things).
843 * The function name is for historical reasons - now we have 850 * The function name is for historical reasons - now we have
846 */ 853 */
847void 854void
848player::chargen_race_done () 855player::chargen_race_done ()
849{ 856{
850 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
851 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
852 859
853 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
854 if (tl) 861 if (tl)
855 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
856 863
859 866
860 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
861 868
862 if (ob->msg) 869 if (ob->msg)
863 ob->msg = 0; 870 ob->msg = 0;
864
865 /* We create this now because some of the unique maps will need it
866 * to save here.
867 */
868 {
869 char buf[MAX_BUF];
870 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
871 make_path_to_file (buf);
872 }
873 871
874 start_info (ob); 872 start_info (ob);
875 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
876 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
877 link_player_skills (ob); 875 link_player_skills (ob);
880 878
881 /* This moves the player to a different start map, if there 879 /* This moves the player to a different start map, if there
882 * is one for this race 880 * is one for this race
883 */ 881 */
884 if (*first_map_ext_path) 882 if (*first_map_ext_path)
885 { 883 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
886 object *tmp;
887 char mapname[MAX_BUF];
888
889 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
890 tmp = object::create ();
891 EXIT_PATH (tmp) = mapname;
892 EXIT_X (tmp) = ob->x;
893 EXIT_Y (tmp) = ob->y;
894 ob->enter_exit (tmp); /* we don't really care if it succeeded;
895 * if the map isn't there, then stay on the
896 * default initial map */
897 tmp->destroy ();
898 }
899 else 884 else
900 LOG (llevDebug, "first_map_ext_path not set\n"); 885 LOG (llevDebug, "first_map_ext_path not set\n");
901} 886}
902 887
903void 888void
1006 if (op->move_type & MOVE_FLYING) 991 if (op->move_type & MOVE_FLYING)
1007 return 1; 992 return 1;
1008 993
1009 next = op->below; 994 next = op->below;
1010 995
996 int cnt = MAX_ITEM_PER_DROP;
997#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
998
1011 /* loop while there are items on the floor that are not marked as 999 /* loop while there are items on the floor that are not marked as
1012 * destroyed */ 1000 * destroyed */
1013 while (next && !next->destroyed ()) 1001 while (next && !next->destroyed ())
1014 { 1002 {
1015 tmp = next; 1003 tmp = next;
1016 next = tmp->below; 1004 next = tmp->below;
1017 1005
1006 if (cnt <= 0)
1007 {
1008 op->failmsg ("Couldn't pickup all items at once.");
1009 return 0;
1010 }
1011
1018 if (op->destroyed ()) 1012 if (op->destroyed ())
1019 return 0; 1013 return 0;
1020 1014
1021 if (!can_pick (op, tmp)) 1015 if (!can_pick (op, tmp))
1022 continue; 1016 continue;
1023 1017
1024 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1018 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1025 { 1019 {
1026 if (item_matched_string (op, tmp, op->contr->search_str)) 1020 if (item_matched_string (op, tmp, op->contr->search_str))
1027 pick_up (op, tmp); 1021 CHK_PICK_PICKUP;
1028 continue; 1022 continue;
1029 } 1023 }
1030 1024
1031 /* high not bit set? We're using the old autopickup model */ 1025 /* high not bit set? We're using the old autopickup model */
1032 if (!(op->contr->mode & PU_NEWMODE)) 1026 if (!(op->contr->mode & PU_NEWMODE))
1034 switch (op->contr->mode) 1028 switch (op->contr->mode)
1035 { 1029 {
1036 case 0: 1030 case 0:
1037 return 1; /* don't pick up */ 1031 return 1; /* don't pick up */
1038 case 1: 1032 case 1:
1039 pick_up (op, tmp); 1033 CHK_PICK_PICKUP;
1040 return 1; 1034 return 1;
1041 case 2: 1035 case 2:
1042 pick_up (op, tmp); 1036 CHK_PICK_PICKUP;
1043 return 0; 1037 return 0;
1044 case 3: 1038 case 3:
1045 return 0; /* stop before pickup */ 1039 return 0; /* stop before pickup */
1046 case 4: 1040 case 4:
1047 pick_up (op, tmp); 1041 CHK_PICK_PICKUP;
1048 break; 1042 break;
1049 case 5: 1043 case 5:
1050 pick_up (op, tmp); 1044 CHK_PICK_PICKUP;
1051 stop = 1; 1045 stop = 1;
1052 break; 1046 break;
1053 case 6: 1047 case 6:
1054 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1048 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1055 pick_up (op, tmp); 1049 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1050 CHK_PICK_PICKUP;
1056 break; 1051 break;
1057 1052
1058 case 7: 1053 case 7:
1059 if (tmp->type == MONEY || tmp->type == GEM) 1054 if (tmp->type == MONEY || tmp->type == GEM)
1060 pick_up (op, tmp); 1055 CHK_PICK_PICKUP;
1061 break; 1056 break;
1062 1057
1063 default: 1058 default:
1064 /* use value density */ 1059 /* use value density */
1065 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1060 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1066 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1061 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1067 pick_up (op, tmp); 1062 CHK_PICK_PICKUP;
1068 } 1063 }
1069 } 1064 }
1070 else 1065 else
1071 { /* old model */ 1066 { /* old model */
1072 /* NEW pickup handling */ 1067 /* NEW pickup handling */
1127 /* all food and drink if desired */ 1122 /* all food and drink if desired */
1128 /* question: don't pick up known-poisonous stuff? */ 1123 /* question: don't pick up known-poisonous stuff? */
1129 if (op->contr->mode & PU_FOOD) 1124 if (op->contr->mode & PU_FOOD)
1130 if (tmp->type == FOOD) 1125 if (tmp->type == FOOD)
1131 { 1126 {
1132 pick_up (op, tmp); 1127 CHK_PICK_PICKUP;
1133 continue; 1128 continue;
1134 } 1129 }
1135 1130
1136 if (op->contr->mode & PU_DRINK) 1131 if (op->contr->mode & PU_DRINK)
1137 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1132 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1138 { 1133 {
1139 pick_up (op, tmp); 1134 CHK_PICK_PICKUP;
1140 continue; 1135 continue;
1141 } 1136 }
1142 1137
1143 if (op->contr->mode & PU_POTION) 1138 if (op->contr->mode & PU_POTION)
1144 if (tmp->type == POTION) 1139 if (tmp->type == POTION)
1145 { 1140 {
1146 pick_up (op, tmp); 1141 CHK_PICK_PICKUP;
1147 continue; 1142 continue;
1148 } 1143 }
1149 1144
1150 /* spellbooks, skillscrolls and normal books/scrolls */ 1145 /* spellbooks, skillscrolls and normal books/scrolls */
1151 if (op->contr->mode & PU_SPELLBOOK) 1146 if (op->contr->mode & PU_SPELLBOOK)
1152 if (tmp->type == SPELLBOOK) 1147 if (tmp->type == SPELLBOOK)
1153 { 1148 {
1154 pick_up (op, tmp); 1149 CHK_PICK_PICKUP;
1155 continue; 1150 continue;
1156 } 1151 }
1157 1152
1158 if (op->contr->mode & PU_SKILLSCROLL) 1153 if (op->contr->mode & PU_SKILLSCROLL)
1159 if (tmp->type == SKILLSCROLL) 1154 if (tmp->type == SKILLSCROLL)
1160 { 1155 {
1161 pick_up (op, tmp); 1156 CHK_PICK_PICKUP;
1162 continue; 1157 continue;
1163 } 1158 }
1164 1159
1165 if (op->contr->mode & PU_READABLES) 1160 if (op->contr->mode & PU_READABLES)
1166 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) 1161 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1167 { 1162 {
1168 pick_up (op, tmp); 1163 CHK_PICK_PICKUP;
1169 continue; 1164 continue;
1170 } 1165 }
1171 1166
1172 /* wands/staves/rods/horns */ 1167 /* wands/staves/rods/horns */
1173 if (op->contr->mode & PU_MAGIC_DEVICE) 1168 if (op->contr->mode & PU_MAGIC_DEVICE)
1174 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1169 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1175 { 1170 {
1176 pick_up (op, tmp); 1171 CHK_PICK_PICKUP;
1177 continue; 1172 continue;
1178 } 1173 }
1179 1174
1180 /* pick up all magical items */ 1175 /* pick up all magical items */
1181 if (op->contr->mode & PU_MAGICAL) 1176 if (op->contr->mode & PU_MAGICAL)
1182 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1177 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1183 { 1178 {
1184 pick_up (op, tmp); 1179 CHK_PICK_PICKUP;
1185 continue; 1180 continue;
1186 } 1181 }
1187 1182
1188 if (op->contr->mode & PU_VALUABLES) 1183 if (op->contr->mode & PU_VALUABLES)
1189 { 1184 {
1190 if (tmp->type == MONEY || tmp->type == GEM) 1185 if (tmp->type == MONEY || tmp->type == GEM)
1191 { 1186 {
1192 pick_up (op, tmp); 1187 CHK_PICK_PICKUP;
1193 continue; 1188 continue;
1194 } 1189 }
1195 } 1190 }
1196 1191
1197 /* rings & amulets - talismans seems to be typed AMULET */ 1192 /* rings & amulets - talismans seems to be typed AMULET */
1198 if (op->contr->mode & PU_JEWELS) 1193 if (op->contr->mode & PU_JEWELS)
1199 if (tmp->type == RING || tmp->type == AMULET) 1194 if (tmp->type == RING || tmp->type == AMULET)
1200 { 1195 {
1201 pick_up (op, tmp); 1196 CHK_PICK_PICKUP;
1202 continue; 1197 continue;
1203 } 1198 }
1204 1199
1205 /* we don't forget dragon food */ 1200 /* we don't forget dragon food */
1206 if (op->contr->mode & PU_FLESH) 1201 if (op->contr->mode & PU_FLESH)
1207 if (tmp->type == FLESH) 1202 if (tmp->type == FLESH)
1208 { 1203 {
1209 pick_up (op, tmp); 1204 CHK_PICK_PICKUP;
1210 continue; 1205 continue;
1211 } 1206 }
1212 1207
1213 /* bows and arrows. Bows are good for selling! */ 1208 /* bows and arrows. Bows are good for selling! */
1214 if (op->contr->mode & PU_BOW) 1209 if (op->contr->mode & PU_BOW)
1215 if (tmp->type == BOW) 1210 if (tmp->type == BOW)
1216 { 1211 {
1217 pick_up (op, tmp); 1212 CHK_PICK_PICKUP;
1218 continue; 1213 continue;
1219 } 1214 }
1220 1215
1221 if (op->contr->mode & PU_ARROW) 1216 if (op->contr->mode & PU_ARROW)
1222 if (tmp->type == ARROW) 1217 if (tmp->type == ARROW)
1223 { 1218 {
1224 pick_up (op, tmp); 1219 CHK_PICK_PICKUP;
1225 continue; 1220 continue;
1226 } 1221 }
1227 1222
1228 /* all kinds of armor etc. */ 1223 /* all kinds of armor etc. */
1229 if (op->contr->mode & PU_ARMOUR) 1224 if (op->contr->mode & PU_ARMOUR)
1230 if (tmp->type == ARMOUR) 1225 if (tmp->type == ARMOUR)
1231 { 1226 {
1232 pick_up (op, tmp); 1227 CHK_PICK_PICKUP;
1233 continue; 1228 continue;
1234 } 1229 }
1235 1230
1236 if (op->contr->mode & PU_HELMET) 1231 if (op->contr->mode & PU_HELMET)
1237 if (tmp->type == HELMET) 1232 if (tmp->type == HELMET)
1238 { 1233 {
1239 pick_up (op, tmp); 1234 CHK_PICK_PICKUP;
1240 continue; 1235 continue;
1241 } 1236 }
1242 1237
1243 if (op->contr->mode & PU_SHIELD) 1238 if (op->contr->mode & PU_SHIELD)
1244 if (tmp->type == SHIELD) 1239 if (tmp->type == SHIELD)
1245 { 1240 {
1246 pick_up (op, tmp); 1241 CHK_PICK_PICKUP;
1247 continue; 1242 continue;
1248 } 1243 }
1249 1244
1250 if (op->contr->mode & PU_BOOTS) 1245 if (op->contr->mode & PU_BOOTS)
1251 if (tmp->type == BOOTS) 1246 if (tmp->type == BOOTS)
1252 { 1247 {
1253 pick_up (op, tmp); 1248 CHK_PICK_PICKUP;
1254 continue; 1249 continue;
1255 } 1250 }
1256 1251
1257 if (op->contr->mode & PU_GLOVES) 1252 if (op->contr->mode & PU_GLOVES)
1258 if (tmp->type == GLOVES) 1253 if (tmp->type == GLOVES)
1259 { 1254 {
1260 pick_up (op, tmp); 1255 CHK_PICK_PICKUP;
1261 continue; 1256 continue;
1262 } 1257 }
1263 1258
1264 if (op->contr->mode & PU_CLOAK) 1259 if (op->contr->mode & PU_CLOAK)
1265 if (tmp->type == CLOAK) 1260 if (tmp->type == CLOAK)
1266 { 1261 {
1267 pick_up (op, tmp); 1262 CHK_PICK_PICKUP;
1268 continue; 1263 continue;
1269 } 1264 }
1270 1265
1271 /* hoping to catch throwing daggers here */ 1266 /* hoping to catch throwing daggers here */
1272 if (op->contr->mode & PU_MISSILEWEAPON) 1267 if (op->contr->mode & PU_MISSILEWEAPON)
1273 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1268 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1274 { 1269 {
1275 pick_up (op, tmp); 1270 CHK_PICK_PICKUP;
1276 continue; 1271 continue;
1277 } 1272 }
1278 1273
1279 /* careful: chairs and tables are weapons! */ 1274 /* careful: chairs and tables are weapons! */
1280 if (op->contr->mode & PU_ALLWEAPON) 1275 if (op->contr->mode & PU_ALLWEAPON)
1282 if (tmp->type == WEAPON && tmp->name != NULL) 1277 if (tmp->type == WEAPON && tmp->name != NULL)
1283 { 1278 {
1284 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && 1279 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1285 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1280 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1286 { 1281 {
1287 pick_up (op, tmp); 1282 CHK_PICK_PICKUP;
1288 continue; 1283 continue;
1289 } 1284 }
1290 } 1285 }
1291 1286
1292 if (tmp->type == WEAPON && tmp->name == NULL) 1287 if (tmp->type == WEAPON && tmp->name == NULL)
1293 { 1288 {
1294 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) 1289 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1295 { 1290 {
1296 pick_up (op, tmp); 1291 CHK_PICK_PICKUP;
1297 continue; 1292 continue;
1298 } 1293 }
1299 } 1294 }
1300 } 1295 }
1301 1296
1302 /* misc stuff that's useful */ 1297 /* misc stuff that's useful */
1303 if (op->contr->mode & PU_KEY) 1298 if (op->contr->mode & PU_KEY)
1304 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1299 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1305 { 1300 {
1306 pick_up (op, tmp); 1301 CHK_PICK_PICKUP;
1307 continue; 1302 continue;
1308 } 1303 }
1309 1304
1310 /* any of the last 4 bits set means we use the ratio for value 1305 /* any of the last 4 bits set means we use the ratio for value
1311 * pickups */ 1306 * pickups */
1312 if (op->contr->mode & PU_RATIO) 1307 if (op->contr->mode & PU_RATIO)
1313 { 1308 {
1314 /* use value density to decide what else to grab */ 1309 /* use value density to decide what else to grab */
1315 /* >=7 was >= op->contr->mode */ 1310 /* >=7 was >= op->contr->mode */
1316 /* >=7 is the old standard setting. Now we take the last 4 bits 1311 /* >=7 is the old standard setting. Now we take the last 4 bits
1317 * and multiply them by 5, giving 0..15*5== 5..75 */ 1312 */
1318 wvratio = (op->contr->mode & PU_RATIO) * 5; 1313 wvratio = op->contr->mode & PU_RATIO;
1319 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1314 if (1000 * query_cost (tmp, op, F_TRUE) / tmp->total_weight () >= wvratio * 100)
1320 { 1315 {
1321 pick_up (op, tmp); 1316 CHK_PICK_PICKUP;
1322#if 0 1317#if 0
1323 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1318 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1324 if (tmp->name != NULL) 1319 if (tmp->name != NULL)
1325 { 1320 {
1326 fprintf (stderr, "%s", tmp->name); 1321 fprintf (stderr, "%s", tmp->name);
1345 * found object is returned. 1340 * found object is returned.
1346 */ 1341 */
1347object * 1342object *
1348find_arrow (object *op, const char *type) 1343find_arrow (object *op, const char *type)
1349{ 1344{
1350 object *tmp = 0;
1351
1352 for (op = op->inv; op; op = op->below) 1345 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1353 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1354 tmp = find_arrow (op, type);
1355 else if (op->type == ARROW && op->race == type) 1346 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1347 return splay (tmp);
1348
1349 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1350 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1351 if (object *arrow = find_arrow (tmp, type))
1352 {
1353 splay (tmp);
1356 return op; 1354 return arrow;
1355 }
1357 1356
1358 return tmp; 1357 return 0;
1359} 1358}
1360 1359
1361/* 1360/*
1362 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1361 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1363 * against the target. A full test is not performed, simply a basic test 1362 * against the target. A full test is not performed, simply a basic test
1386 } 1385 }
1387 } 1386 }
1388 else if (arrow->type == ARROW && arrow->race == type) 1387 else if (arrow->type == ARROW && arrow->race == type)
1389 { 1388 {
1390 /* allways prefer assasination/slaying */ 1389 /* allways prefer assasination/slaying */
1391 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1390 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1392 { 1391 {
1393 if (arrow->attacktype & AT_DEATH) 1392 if (arrow->attacktype & AT_DEATH)
1394 { 1393 {
1395 *better = 100; 1394 *better = 100;
1396 return arrow; 1395 return arrow;
1424 betterby = 1 + arrow->magic + arrow->stats.dam; 1423 betterby = 1 + arrow->magic + arrow->stats.dam;
1425 } 1424 }
1426 } 1425 }
1427 } 1426 }
1428 } 1427 }
1428
1429 if (tmp == NULL && arrow == NULL) 1429 if (tmp == NULL && arrow == NULL)
1430 return find_arrow (op, type); 1430 return find_arrow (op, type);
1431 1431
1432 *better = betterby; 1432 *better = betterby;
1433 return tmp; 1433 return tmp;
1584 arrow->destroy (); 1584 arrow->destroy ();
1585 return 0; 1585 return 0;
1586 } 1586 }
1587 1587
1588 left = arrow; /* these are arrows left to the player */ 1588 left = arrow; /* these are arrows left to the player */
1589 arrow = get_split_ob (arrow, 1); 1589 arrow = arrow->split ();
1590 if (!arrow) 1590 if (!arrow)
1591 { 1591 {
1592 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1592 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1593 return 0; 1593 return 0;
1594 } 1594 }
1661 op->play_sound (sound_find ("fire_arrow")); 1661 op->play_sound (sound_find ("fire_arrow"));
1662 m->insert (arrow, sx, sy, op); 1662 m->insert (arrow, sx, sy, op);
1663 1663
1664 if (!arrow->destroyed ()) 1664 if (!arrow->destroyed ())
1665 move_arrow (arrow); 1665 move_arrow (arrow);
1666
1667 if (op->type == PLAYER)
1668 {
1669 if (left->destroyed ())
1670 esrv_del_item (op->contr, left->count);
1671 else
1672 esrv_send_item (op, left);
1673 }
1674 1666
1675 return 1; 1667 return 1;
1676} 1668}
1677 1669
1678/* Special fire code for players - this takes into 1670/* Special fire code for players - this takes into
1752 return; 1744 return;
1753 } 1745 }
1754 } 1746 }
1755 else if (item->type == ROD || item->type == HORN) 1747 else if (item->type == ROD || item->type == HORN)
1756 { 1748 {
1757 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1749 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace);
1750
1751 // using the maximum of the rods charge allows at least one spell cast
1752 // for a rod or horn, this fixes some broken rods.
1753 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp))
1758 { 1754 {
1759 op->contr->play_sound (sound_find ("wand_poof")); 1755 op->contr->play_sound (sound_find ("wand_poof"));
1760 1756
1761 if (item->type == ROD) 1757 if (item->type == ROD)
1762 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1758 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1781 CLEAR_FLAG (item, FLAG_ANIMATE); 1777 CLEAR_FLAG (item, FLAG_ANIMATE);
1782 item->face = item->arch->face; 1778 item->face = item->arch->face;
1783 item->set_speed (0); 1779 item->set_speed (0);
1784 } 1780 }
1785 1781
1786 if ((tmp = item->in_player ())) 1782 if (object *pl = item->visible_to ())
1787 esrv_update_item (UPD_ANIM, tmp, item); 1783 esrv_update_item (UPD_ANIM, pl, item);
1788 } 1784 }
1789 } 1785 }
1790 else if (item->type == ROD || item->type == HORN) 1786 else if (item->type == ROD || item->type == HORN)
1791 drain_rod_charge (item); 1787 drain_rod_charge (item);
1792 } 1788 }
1963 1959
1964 if (door->type == DOOR) 1960 if (door->type == DOOR)
1965 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ 1961 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */
1966 else if (door->type == LOCKED_DOOR) 1962 else if (door->type == LOCKED_DOOR)
1967 { 1963 {
1968 new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key)); 1964 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
1969 remove_door2 (door); /* remove door without violence ;-) */ 1965 remove_door2 (door); /* remove door without violence ;-) */
1970 } 1966 }
1971 1967
1972 /* Do this after we print the message */ 1968 /* Do this after we print the message */
1973 decrease_ob (key); /* Use up one of the keys */ 1969 key->decrease (); /* Use up one of the keys */
1974 /* Need to update the weight the container the key was in */
1975 if (container != op)
1976 esrv_update_item (UPD_WEIGHT, op, container);
1977 1970
1978 return 1; /* Nothing more to do below */ 1971 return 1; /* Nothing more to do below */
1979 } 1972 }
1980 else if (door->type == LOCKED_DOOR) 1973 else if (door->type == LOCKED_DOOR)
1981 { 1974 {
1982 /* Might as well return now - no other way to open this */ 1975 /* Might as well return now - no other way to open this */
1983 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); 1976 op->failmsg (door->msg ? &door->msg : "Hmm, you miss the certain something to open this door...");
1984 return 1; 1977 return 1;
1985 } 1978 }
1986 1979
1987 return 0; 1980 return 0;
1988} 1981}
2108 { 2101 {
2109 op->play_sound (sound_find ("push_player")); 2102 op->play_sound (sound_find ("push_player"));
2110 push_ob (mon, dir, op); 2103 push_ob (mon, dir, op);
2111 } 2104 }
2112 else 2105 else
2113 new_draw_info (0, 0, op, "You withhold your attack"); 2106 op->statusmsg ("You withhold your attack");
2114 2107
2115 if (op->contr->tmp_invis || op->hide) 2108 if (op->contr->tmp_invis || op->hide)
2116 make_visible (op); 2109 make_visible (op);
2117 2110
2118 return true; 2111 return true;
2162bool 2155bool
2163move_player (object *op, int dir) 2156move_player (object *op, int dir)
2164{ 2157{
2165 int pick; 2158 int pick;
2166 2159
2167 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2160 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2168 return 0; 2161 return 0;
2169 2162
2170 /* Sanity check: make sure dir is valid */ 2163 /* Sanity check: make sure dir is valid */
2171 if ((dir < 0) || (dir >= 9)) 2164 if ((dir < 0) || (dir >= 9))
2172 { 2165 {
2260 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2253 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2261 { 2254 {
2262 op->play_sound (sound_find ("ob_evaporate")); 2255 op->play_sound (sound_find ("ob_evaporate"));
2263 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2256 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2264 2257
2265 if (op->contr)
2266 esrv_del_item (op->contr, tmp->count);
2267
2268 tmp->destroy (); 2258 tmp->destroy ();
2269 CLEAR_FLAG (op, FLAG_LIFESAVE); 2259 CLEAR_FLAG (op, FLAG_LIFESAVE);
2270 2260
2271 if (op->stats.hp < 0) 2261 if (op->stats.hp < 0)
2272 op->stats.hp = op->stats.maxhp; 2262 op->stats.hp = op->stats.maxhp;
2284 return 0; 2274 return 0;
2285} 2275}
2286 2276
2287/* This goes throws the inventory and removes unpaid objects, and puts them 2277/* This goes throws the inventory and removes unpaid objects, and puts them
2288 * back in the map (location and map determined by values of env). This 2278 * back in the map (location and map determined by values of env). This
2289 * function will descend into containers. op is the object to start the search 2279 * function will descend into containers. op is the object to start the search
2290 * from. 2280 * from.
2291 */ 2281 */
2292static void 2282static void
2293drop_unpaid_items (object *op, object *env) 2283drop_unpaid_items (object *op, object *env)
2294{ 2284{
2295 while (op) 2285 while (op)
2296 { 2286 {
2297 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2287 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2298 2288
2299 if (QUERY_FLAG (op, FLAG_UNPAID)) 2289 if (QUERY_FLAG (op, FLAG_UNPAID))
2300 {
2301 if (env->type == PLAYER)
2302 esrv_del_item (env->contr, op->count);
2303
2304 op->insert_at (env); 2290 op->insert_at (env);
2305 }
2306 else if (op->inv) 2291 else if (op->inv)
2307 drop_unpaid_items (op->inv, env); 2292 drop_unpaid_items (op->inv, env);
2308 2293
2309 op = next; 2294 op = next;
2310 } 2295 }
2322 * Moved from apply.c to player.c - player.c is what 2307 * Moved from apply.c to player.c - player.c is what
2323 * actually uses this function. player.c may not be quite the 2308 * actually uses this function. player.c may not be quite the
2324 * best, a misc file for object actions is probably better, 2309 * best, a misc file for object actions is probably better,
2325 * but there isn't one in the server directory. 2310 * but there isn't one in the server directory.
2326 */ 2311 */
2327char * 2312const char *
2328gravestone_text (object *op) 2313gravestone_text (object *op)
2329{ 2314{
2330 static char buf2[MAX_BUF]; 2315 static dynbuf_text buf;
2331 char buf[MAX_BUF];
2332 time_t now = time (NULL);
2333 2316
2334 strcpy (buf2, " R.I.P.\n\n"); 2317 buf << "---- R.I.P. ----\n\n";
2318 op->name;
2319
2335 if (op->type == PLAYER) 2320 if (op->type == PLAYER)
2336 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2321 buf << " the " << op->contr->title;
2337 else
2338 sprintf (buf, "%s\n", &op->name);
2339 2322
2340 strncat (buf2, " ", 20 - strlen (buf) / 2); 2323 buf << "\n\n";
2341 strcat (buf2, buf); 2324
2325 buf << "who was level ";
2326 buf << (sint32)op->level << "\n\n" // OO breakdown
2327 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2328
2342 if (op->type == PLAYER) 2329 if (op->type == PLAYER)
2343 sprintf (buf, "who was in level %d when killed\n", op->level); 2330 buf << "by " << op->contr->killer_name () << ".\n\n";
2344 else
2345 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2346 2331
2347 strncat (buf2, " ", 20 - strlen (buf) / 2);
2348 strcat (buf2, buf);
2349 if (op->type == PLAYER)
2350 { 2332 {
2351 sprintf (buf, "by %s.\n\n", op->contr->killer); 2333 static char buf2[128];
2352 strncat (buf2, " ", 21 - strlen (buf) / 2); 2334 time_t now = time (NULL);
2353 strcat (buf2, buf);
2354 }
2355
2356 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2335 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2357 strncat (buf2, " ", 20 - strlen (buf) / 2); 2336 buf << buf2;
2358 strcat (buf2, buf); 2337 }
2359 2338
2360 return buf2; 2339 return buf;
2361} 2340}
2362 2341
2363void 2342void
2364do_some_living (object *op) 2343do_some_living (object *op)
2365{ 2344{
2546 op->stats.food--; 2525 op->stats.food--;
2547 } 2526 }
2548 2527
2549 if (op->stats.food < 0 && op->stats.hp >= 0) 2528 if (op->stats.food < 0 && op->stats.hp >= 0)
2550 { 2529 {
2551 object *tmp, *flesh = 0; 2530 object *flesh = 0;
2552 2531
2553 for (tmp = op->inv; tmp; tmp = tmp->below) 2532 for_inv_removable (op, tmp)
2554 { 2533 {
2555 if (!QUERY_FLAG (tmp, FLAG_UNPAID)) 2534 if (QUERY_FLAG (tmp, FLAG_UNPAID))
2535 continue;
2536
2537 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2556 { 2538 {
2557 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2539 op->statusmsg ("You blindly grab for a bite of food. "
2558 { 2540 "H<To prevent you from starving, you ate some random item from your backpack.>");
2559 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2560 manual_apply (op, tmp, 0); 2541 manual_apply (op, tmp, 0);
2542
2561 if (op->stats.food >= 0 || op->stats.hp < 0) 2543 if (op->stats.food >= 0 || op->stats.hp < 0)
2562 break; 2544 break;
2563 } 2545 }
2564 else if (tmp->type == FLESH) 2546 else if (tmp->type == FLESH)
2565 flesh = tmp; 2547 flesh = tmp;
2566 } /* End if paid for object */ 2548 }
2567 } /* end of for loop */
2568 2549
2569 /* If player is still starving, it means they don't have any food, so 2550 /* If player is still starving, it means they don't have any food, so
2570 * eat flesh instead. 2551 * eat flesh instead.
2571 */ 2552 */
2572 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2553 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2573 { 2554 {
2574 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2555 op->statusmsg ("You blindly grab for a bite of food. "
2556 "H<To prevent you from starving, you ate some random item from your backpack.>");
2575 manual_apply (op, flesh, 0); 2557 manual_apply (op, flesh, 0);
2576 } 2558 }
2559
2560 // If player is still starving, alert him!
2561 if (op->stats.food < 0)
2562 op->failmsg ("You are starving! "
2563 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2577 } 2564 }
2578 2565
2579 if (op->stats.food < 0) 2566 if (op->stats.food < 0)
2580 { 2567 {
2581 op->stats.hp += op->stats.food; 2568 op->stats.hp += op->stats.food;
2582 op->stats.food = 0; 2569 op->stats.food = 0;
2570
2571 if (op->stats.hp < 0)
2572 {
2573 op->contr->killer = archetype::get ("killer_starvation");
2574 op->contr->killer->destroy ();
2583 } 2575 }
2576 }
2584 2577
2578 /* killer should be set here already */
2585 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2579 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2586 kill_player (op); 2580 kill_player (op);
2587 } 2581 }
2588} 2582}
2589 2583
2593 * file. 2587 * file.
2594 */ 2588 */
2595void 2589void
2596kill_player (object *op) 2590kill_player (object *op)
2597{ 2591{
2592 int x, y;
2598 char buf[MAX_BUF]; 2593 char buf[MAX_BUF];
2599 int x, y;
2600
2601 //int i;
2602 maptile *map; /* this is for resurrection */ 2594 maptile *map; /* this is for resurrection */
2603
2604 /* int z;
2605 int num_stats_lose;
2606 int lost_a_stat;
2607 int lose_this_stat;
2608 int this_stat; */
2609 int will_kill_again; 2595 int will_kill_again;
2610 archetype *at; 2596 archetype *at;
2611 object *tmp; 2597 object *tmp;
2612 2598
2613 if (save_life (op)) 2599 if (save_life (op))
2635 { 2621 {
2636 tmp->destroy (); 2622 tmp->destroy ();
2637 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2623 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2638 } 2624 }
2639 2625
2640 cure_disease (op, 0); /* remove any disease */ 2626 cure_disease (op, 0, 0); /* remove any disease */
2641 op->stats.hp = op->stats.maxhp; 2627 op->stats.hp = op->stats.maxhp;
2642 if (op->stats.food <= 0) 2628 if (op->stats.food <= 0)
2643 op->stats.food = 999; 2629 op->stats.food = 999;
2644 2630
2645 /* create a bodypart-trophy to make the winner happy */ 2631 /* create a bodypart-trophy to make the winner happy */
2646 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2632 if (object *tmp = arch_to_object (archetype::find ("finger")))
2647 { 2633 {
2648 sprintf (buf, "%s's finger", &op->name); 2634 tmp->name = format ("%s's finger" , &op->name);
2649 tmp->name = buf; 2635 tmp->name_pl = format ("%s's fingers", &op->name);
2650 sprintf (buf, " This finger has been cut off %s\n"
2651 " the %s, when he was defeated at\n level %d by %s.\n",
2652 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2653 tmp->msg = buf; 2636 tmp->msg = format (
2637 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2638 &op->name, op->contr->title,
2639 (int)op->level,
2640 op->contr->killer_name ()
2641 );
2654 tmp->value = 0, tmp->type = 0; 2642 tmp->value = 0, tmp->type = 0;
2655 tmp->materialname = "organics"; 2643 tmp->materialname = "organics";
2656 tmp->insert_at (op, tmp); 2644 tmp->insert_at (op, tmp);
2657 } 2645 }
2658 2646
2663 } 2651 }
2664 2652
2665 INVOKE_PLAYER (DEATH, op->contr); 2653 INVOKE_PLAYER (DEATH, op->contr);
2666 2654
2667 command_kill_pets (op, 0); 2655 command_kill_pets (op, 0);
2668
2669 if (op->stats.food < 0)
2670 {
2671 sprintf (buf, "%s starved to death.", &op->name);
2672 strcpy (op->contr->killer, "starvation");
2673 }
2674 else
2675 sprintf (buf, "%s died.", &op->name);
2676 2656
2677 op->contr->play_sound (sound_find ("player_dies")); 2657 op->contr->play_sound (sound_find ("player_dies"));
2678 2658
2679 /* save the map location for corpse, gravestone */ 2659 /* save the map location for corpse, gravestone */
2680 x = op->x; 2660 x = op->x;
2789 lost_a_stat = 1; 2769 lost_a_stat = 1;
2790 } 2770 }
2791 } 2771 }
2792 } 2772 }
2793 } 2773 }
2774
2794 /* If no stat lost, tell the player. */ 2775 /* If no stat lost, tell the player. */
2795 if (!lost_a_stat) 2776 if (!lost_a_stat)
2796 { 2777 {
2797 /* determine_god() seems to not work sometimes... why is this? 2778 /* determine_god() seems to not work sometimes... why is this?
2798 Should I be using something else? GD */ 2779 Should I be using something else? GD */
2802 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god); 2783 new_draw_info_format (NDI_UNIQUE, 0, op, "For a brief moment you feel the holy presence of %s protecting" " you.", god);
2803 else 2784 else
2804 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you."); 2785 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you.");
2805 } 2786 }
2806#else 2787#else
2807 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you" " feel a holy presence protecting you from losing yourself completely."); 2788 new_draw_info (NDI_UNIQUE, 0, op, "For a brief moment you feel a holy presence protecting you from losing yourself completely.");
2808#endif 2789#endif
2809 2790
2810 /* Put a gravestone up where the character 'almost' died. List the 2791 /* Put a gravestone up where the character 'almost' died. List the
2811 * exp loss on the stone. 2792 * exp loss on the stone.
2812 */ 2793 */
2813 tmp = arch_to_object (archetype::find ("gravestone")); 2794 tmp = arch_to_object (archetype::find ("gravestone"));
2814 sprintf (buf, "%s's gravestone", &op->name); 2795 tmp->name = format ("%s's gravestone", &op->name);
2815 tmp->name = buf; 2796 tmp->name_pl = format ("%s's gravestones", &op->name);
2816 sprintf (buf, "%s's gravestones", &op->name);
2817 tmp->name_pl = buf;
2818 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); 2797 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 ());
2819 tmp->msg = buf;
2820 tmp->x = op->x, tmp->y = op->y; 2798 tmp->x = op->x, tmp->y = op->y;
2821 insert_ob_in_map (tmp, op->map, NULL, 0); 2799 insert_ob_in_map (tmp, op->map, NULL, 0);
2822 2800
2823 /**************************************/ 2801 /**************************************/
2824 /* */ 2802 /* */
2845 { 2823 {
2846 tmp->destroy (); 2824 tmp->destroy ();
2847 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2825 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2848 } 2826 }
2849 2827
2850 cure_disease (op, 0); /* remove any disease */ 2828 cure_disease (op, 0, 0); /* remove any disease */
2829
2830 // remove all spell effects that are active
2831 // to avoid long-term effects such as word-of-recall
2832 for (object *item = op->inv; item; )
2833 {
2834 object *next = item->below;
2835
2836 if (item->type == SPELL_EFFECT && item->active)
2837 item->destroy ();
2838
2839 item = next;
2840 }
2851 2841
2852 /*add_exp(op, (op->stats.exp * -0.20)); */ 2842 /*add_exp(op, (op->stats.exp * -0.20)); */
2853 apply_death_exp_penalty (op); 2843 apply_death_exp_penalty (op);
2844
2854 if (op->stats.food < 100) 2845 if (op->stats.food < 100)
2855 op->stats.food = 900; 2846 op->stats.food = 900;
2847
2856 op->stats.hp = op->stats.maxhp; 2848 op->stats.hp = op->stats.maxhp;
2857 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2849 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2858 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2850 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2859 2851
2860 /* 2852 /*
2928 2920
2929 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2921 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2930 { 2922 {
2931 if (tmp->nrof > 1) 2923 if (tmp->nrof > 1)
2932 { 2924 {
2933 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2925 tmp->decrease (rndm (1, tmp->nrof - 1));
2934 tmp2->destroy ();
2935 insert_ob_in_map (tmp, op->map, NULL, 0); 2926 insert_ob_in_map (tmp, op->map, NULL, 0);
2936 } 2927 }
2937 else 2928 else
2938 tmp->destroy (); 2929 tmp->destroy ();
2939 } 2930 }
2950void 2941void
2951fix_weight (void) 2942fix_weight (void)
2952{ 2943{
2953 for_all_players (pl) 2944 for_all_players (pl)
2954 { 2945 {
2955 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2946 sint32 old = pl->ob->carrying;
2956 2947
2957 if (old == sum) 2948 pl->ob->update_weight ();
2958 continue; 2949
2950 if (old != pl->ob->carrying)
2951 {
2959 pl->ob->update_stats (); 2952 pl->ob->update_stats ();
2960 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 2953 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying);
2954 }
2961 } 2955 }
2962} 2956}
2963 2957
2964void 2958void
2965fix_luck (void) 2959fix_luck (void)
3009void 3003void
3010make_visible (object *op) 3004make_visible (object *op)
3011{ 3005{
3012 op->hide = 0; 3006 op->hide = 0;
3013 op->invisible = 0; 3007 op->invisible = 0;
3008
3014 if (op->type == PLAYER) 3009 if (op->type == PLAYER)
3015 { 3010 {
3016 op->contr->tmp_invis = 0; 3011 op->contr->tmp_invis = 0;
3017 op->contr->invis_race = 0; 3012 op->contr->invis_race = 0;
3018 } 3013 }
3031 3026
3032/* look at the surrounding terrain to determine 3027/* look at the surrounding terrain to determine
3033 * the hideability of this object. Positive levels 3028 * the hideability of this object. Positive levels
3034 * indicate greater hideability. 3029 * indicate greater hideability.
3035 */ 3030 */
3036
3037int 3031int
3038hideability (object *ob) 3032hideability (object *ob)
3039{ 3033{
3040 int i, level = 0, mflag; 3034 int i, level = 0, mflag;
3041 sint16 x, y; 3035 sint16 x, y;
3051 * as bad as carrying a light on a pitch dark map */ 3045 * as bad as carrying a light on a pitch dark map */
3052 if (has_carried_lights (ob)) 3046 if (has_carried_lights (ob))
3053 level = -(10 + (2 * ob->map->darkness)); 3047 level = -(10 + (2 * ob->map->darkness));
3054 3048
3055 /* scan through all nearby squares for terrain to hide in */ 3049 /* scan through all nearby squares for terrain to hide in */
3056 for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3050 for (i = 0, x = ob->x, y = ob->y;
3051 i <= SIZEOFFREE1;
3052 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3057 { 3053 {
3058 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3054 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3059 if (mflag & P_OUT_OF_MAP) 3055 if (mflag & P_OUT_OF_MAP)
3060 {
3061 continue; 3056 continue;
3062 } 3057
3063 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3058 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3064 level += 2; 3059 level += 2;
3065 else /* open terrain! */ 3060 else /* open terrain! */
3066 level -= 1; 3061 level -= 1;
3067 } 3062 }
3078 * spot (surrounded by clear terrain in broad daylight). -b.t. 3073 * spot (surrounded by clear terrain in broad daylight). -b.t.
3079 */ 3074 */
3080void 3075void
3081do_hidden_move (object *op) 3076do_hidden_move (object *op)
3082{ 3077{
3083 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3078 int hide = 0;
3084 object *skop;
3085 3079
3086 if (!op || !op->map) 3080 if (!op || !op->map)
3087 return; 3081 return;
3088 3082
3089 skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); 3083 object *skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING);
3084 int num = random_roll (0, 19, op, PREFER_LOW);
3090 3085
3091 /* its *extremely* hard to run and sneak/hide at the same time! */ 3086 /* its *extremely* hard to run and sneak/hide at the same time! */
3092 if (op->type == PLAYER && op->contr->run_on) 3087 if (op->type == PLAYER && op->contr->run_on)
3093 if (!skop || num >= skop->level) 3088 if (!skop || num >= skop->level)
3094 { 3089 {
3104 num -= hide; 3099 num -= hide;
3105 3100
3106 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3101 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3107 { 3102 {
3108 make_visible (op); 3103 make_visible (op);
3104
3109 if (op->type == PLAYER) 3105 if (op->type == PLAYER)
3110 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); 3106 new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!");
3111 } 3107 }
3112 else if (op->type == PLAYER && skop) 3108 else if (op->type == PLAYER && skop)
3113 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); 3109 change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0);
3454 else 3450 else
3455 { 3451 {
3456 /* generate misc. treasure */ 3452 /* generate misc. treasure */
3457 tmp = arch_to_object (tr->item); 3453 tmp = arch_to_object (tr->item);
3458 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3454 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3459 tmp = insert_ob_in_ob (tmp, who); 3455 who->insert (tmp);
3460 if (who->type == PLAYER)
3461 esrv_send_item (who, tmp);
3462 } 3456 }
3463} 3457}
3464 3458
3465/** 3459/**
3466 * Unready an object for a player. This function does nothing if the object was 3460 * Unready an object for a player. This function does nothing if the object was
3495 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) 3489 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3496 return 0; 3490 return 0;
3497 3491
3498 return 100 - blocked_los [x][y]; 3492 return 100 - blocked_los [x][y];
3499} 3493}
3494
3495void
3496player::infobox (const char *title, const char *msg, int color)
3497{
3498 send_msg (color | NDI_DEF | NDI_REPLY | NDI_CLEAR, title, msg);
3499}
3500
3501void
3502player::statusmsg (const char *msg, int color)
3503{
3504 send_msg (color | NDI_REPLY, INFO_CHANNEL, msg);
3505}
3506
3507void
3508player::failmsg (const char *msg, int color)
3509{
3510 play_sound (sound_find ("generic_failure"));
3511 statusmsg (msg, color);
3512}
3513

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines