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.141 by root, Fri May 18 15:05:09 2007 UTC vs.
Revision 1.202 by root, Fri Aug 29 02:07:09 2008 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * This program 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 2 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,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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, write to the Free Software 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * 20 *
22 * The author can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 22 */
24 23
25#include <global.h> 24#include <global.h>
26#include <sproto.h> 25#include <sproto.h>
27#include <sounds.h> 26#include <sounds.h>
123 continue; 122 continue;
124 123
125 if (*buf == '%') 124 if (*buf == '%')
126 { /* send one news */ 125 { /* send one news */
127 if (size > 0) 126 if (size > 0)
128 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", (char *)"%s\n%s", subject, news); /*send previously read news */ 127 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
128 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
129 "INFORMATION: %s\n%s", (char *)"%s\n%s",
130 subject, news); /*send previously read news */
129 131
130 strcpy (subject, buf + 1); 132 strcpy (subject, buf + 1);
131 strip_endline (subject); 133 strip_endline (subject);
132 size = 0; 134 size = 0;
133 news[0] = '\0'; 135 news[0] = '\0';
157 op->x = -1; 159 op->x = -1;
158 op->y = -1; 160 op->y = -1;
159} 161}
160 162
161void 163void
162player::enter_map ()
163{
164 object *tmp = object::create ();
165
166 EXIT_PATH (tmp) = maplevel;
167 EXIT_X (tmp) = ob->x;
168 EXIT_Y (tmp) = ob->y;
169 ob->enter_exit (tmp);
170
171 tmp->destroy ();
172}
173
174void
175player::activate () 164player::activate ()
176{ 165{
177 if (active) 166 if (active)
178 return; 167 return;
179 168
181 ob->remove (); 170 ob->remove ();
182 ob->map = 0; 171 ob->map = 0;
183 ob->activate_recursive (); 172 ob->activate_recursive ();
184 CLEAR_FLAG (ob, FLAG_FRIENDLY); 173 CLEAR_FLAG (ob, FLAG_FRIENDLY);
185 add_friendly_object (ob); 174 add_friendly_object (ob);
186 enter_map ();
187} 175}
188 176
189void 177void
190player::deactivate () 178player::deactivate ()
191{ 179{
198 186
199 if (ob->map) 187 if (ob->map)
200 maplevel = ob->map->path; 188 maplevel = ob->map->path;
201 189
202 ob->remove (); 190 ob->remove ();
191 ob->enemy = 0; // sometimes keeps an extra refcount on itself
203 ob->map = 0; 192 ob->map = 0;
204 party = 0; 193 party = 0;
205 194
206 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
207 196
221 ob->close_container (); //TODO: client-specific 210 ob->close_container (); //TODO: client-specific
222 211
223 ns->update_look = 0; 212 ns->update_look = 0;
224 ns->look_position = 0; 213 ns->look_position = 0;
225 214
226 clear_los (ob); 215 clear_los (this);
227 216
228 ns->reset_stats (); 217 ns->reset_stats ();
229 218
230 /* make sure he's a player -- needed because of class change. */ 219 /* make sure he's a player -- needed because of class change. */
231 ob->type = PLAYER; // we are paranoid 220 ob->type = PLAYER; // we are paranoid
232 ob->race = ob->arch->clone.race; 221 ob->race = ob->arch->race;
233 222
234 ob->carrying = sum_weight (ob); 223 ob->update_weight ();
235 link_player_skills (ob); 224 link_player_skills (ob);
236 225
237 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 226 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
238 227
239 assign (title, ob->arch->clone.name); 228 assign (title, ob->arch->object::name);
240 229
241 /* if it's a dragon player, set the correct title here */ 230 /* if it's a dragon player, set the correct title here */
242 if (is_dragon_pl (ob)) 231 if (is_dragon_pl (ob))
243 { 232 {
244 object *tmp, *abil = 0, *skin = 0; 233 object *tmp, *abil = 0, *skin = 0;
245 234
246 shstr_cmp dragon_ability_force ("dragon_ability_force");
247 shstr_cmp dragon_skin_force ("dragon_skin_force");
248
249 for (tmp = ob->inv; tmp; tmp = tmp->below) 235 for (tmp = ob->inv; tmp; tmp = tmp->below)
250 if (tmp->type == FORCE) 236 if (tmp->type == FORCE)
251 if (tmp->arch->name == dragon_ability_force) 237 if (tmp->arch->archname == shstr_dragon_ability_force)
252 abil = tmp; 238 abil = tmp;
253 else if (tmp->arch->name == dragon_skin_force) 239 else if (tmp->arch->archname == shstr_dragon_skin_force)
254 skin = tmp; 240 skin = tmp;
255 241
256 set_dragon_name (ob, abil, skin); 242 set_dragon_name (ob, abil, skin);
257 } 243 }
258 244
259 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
260 246
261 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 */
262 303
263 ob->flag [FLAG_READY_WEAPON] = false; 304 ob->flag [FLAG_READY_WEAPON] = false;
264 ob->flag [FLAG_READY_SKILL] = false; 305 ob->flag [FLAG_READY_SKILL] = false;
265 ob->flag [FLAG_READY_BOW] = false; 306 ob->flag [FLAG_READY_BOW] = false;
266 307
283 combat_ob = op; 324 combat_ob = op;
284 break; 325 break;
285 } 326 }
286 327
287 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
288 ob->update_stats (); 329 ob->deactivate (); // change_weapon activates, fix this better
289
290 ns->floorbox_update ();
291 esrv_send_inventory (ob, ob);
292 esrv_add_spells (this, 0);
293
294 activate ();
295
296 send_rules (ob);
297 send_news (ob);
298 display_motd (ob);
299
300 INVOKE_PLAYER (CONNECT, this);
301 INVOKE_PLAYER (LOGIN, this);
302} 330}
303 331
304void 332void
305player::disconnect ()
306{
307 if (ns)
308 {
309 if (active)
310 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
311
312 INVOKE_PLAYER (DISCONNECT, this);
313
314 ns->reset_stats ();
315 ns->pl = 0;
316 ns = 0;
317 }
318
319 if (ob)
320 ob->close_container (); //TODO: client-specific
321
322 deactivate ();
323}
324
325// the need for this function can be explained
326// by load_object not returning the object
327void
328player::set_object (object *op) 333player::set_observe (object *op)
329{ 334{
330 ob = op; 335 observe = op ? op : ob;
331 ob->contr = this; /* this aren't yet in archetype */ 336 do_los = 1;
332
333 ob->speed_left = 0.5f;
334 ob->speed = 1.0f;
335 ob->direction = 5; /* So player faces south */
336} 337}
337 338
338player::player () 339player::player ()
339{ 340{
340 /* There are some elements we want initialised to non zero value - 341 /* There are some elements we want initialised to non zero value -
347 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
348 349
349 gen_sp_armour = 10; 350 gen_sp_armour = 10;
350 bowtype = bow_normal; 351 bowtype = bow_normal;
351 petmode = pet_normal; 352 petmode = pet_normal;
352 listening = 10;
353 usekeys = containers; 353 usekeys = containers;
354 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
355 do_los = 1; 355 do_los = 1;
356
357 weapon_sp = 1.0f;
358 weapon_sp_left = 0.5f;
356} 359}
357 360
358void 361void
359player::do_destroy () 362player::do_destroy ()
360{ 363{
365 if (ob) 368 if (ob)
366 { 369 {
367 ob->destroy_inv (false); 370 ob->destroy_inv (false);
368 ob->destroy (); 371 ob->destroy ();
369 } 372 }
373
374 ob = observe = 0;
370} 375}
371 376
372player::~player () 377player::~player ()
373{ 378{
374 /* Clear item stack */ 379 /* Clear item stack */
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{
406 archetype *start = at; 411 // archetypes could have been reloaded
412 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
413
414 if (!nat)
415 return at;
416
417 archvec::iterator i = archetypes.find (nat);
407 418
408 for (;;) 419 for (;;)
409 { 420 {
410 if (at == NULL || at->next == NULL) 421 if (++i == archetypes.end ())
411 at = first_archetype; 422 i = archetypes.begin ();
412 else 423 else if (*i == at)
413 at = at->next; 424 cleanup ("not a single player archetype found");
414 425
415 if (at->clone.type == PLAYER) 426 if ((*i)->type == PLAYER)
416 return at; 427 return *i;
417
418 if (at == start)
419 {
420 LOG (llevError, "No Player archetypes\n");
421 exit (-1);
422 }
423 } 428 }
424} 429}
425 430
426object * 431object *
427get_nearest_player (object *mon) 432get_nearest_player (object *mon)
431 unsigned lastdist; 436 unsigned lastdist;
432 rv_vector rv; 437 rv_vector rv;
433 438
434 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) 439 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next)
435 { 440 {
436 /* We should not find free objects on this friendly list, but it
437 * does periodically happen. Given that, lets deal with it.
438 * While unlikely, it is possible the next object on the friendly
439 * list is also free, so encapsulate this in a while loop.
440 */
441 while (QUERY_FLAG (ol->ob, FLAG_FREED) || !QUERY_FLAG (ol->ob, FLAG_FRIENDLY))
442 {
443 object *tmp = ol->ob;
444
445 /* Can't do much more other than log the fact, because the object
446 * itself will have been cleared.
447 */
448 LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n",
449 tmp->debug_desc ());
450 ol = ol->next;
451 remove_friendly_object (tmp);
452 if (!ol)
453 return op;
454 }
455
456 /* Remove special check for player from this. First, it looks to cause
457 * some crashes (ol->ob->contr not set properly?), but secondly, a more
458 * complicated method of state checking would be needed in any case -
459 * as it was, a clever player could type quit, and the function would
460 * skip them over while waiting for confirmation. Remove
461 * on_same_map check, as can_detect_enemy also does this
462 */
463 if (!can_detect_enemy (mon, ol->ob, &rv)) 441 if (!can_detect_enemy (mon, ol->ob, &rv))
464 continue; 442 continue;
465 443
466 if (lastdist > rv.distance) 444 if (lastdist > rv.distance)
467 { 445 {
662 640
663 return firstdir; 641 return firstdir;
664} 642}
665 643
666void 644void
667give_initial_items (object *pl, treasurelist * items) 645give_initial_items (object *pl, treasurelist *items)
668{ 646{
669 object *op, *next = NULL;
670
671 if (pl->randomitems != NULL) 647 if (pl->randomitems)
672 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 648 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
673 649
674 for (op = pl->inv; op; op = next) 650 for (object *next, *op = pl->inv; op; op = next)
675 { 651 {
676 next = op->below; 652 next = op->below;
677 653
678 /* Forces get applied per default, unless they have the 654 /* Forces get applied per default, unless they have the
679 * 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
684 /* we never give weapons/armour if these cannot be used 660 /* we never give weapons/armour if these cannot be used
685 * by this player due to race restrictions 661 * by this player due to race restrictions
686 */ 662 */
687 if (pl->type == PLAYER) 663 if (pl->type == PLAYER)
688 { 664 {
689 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 665 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
666 &&
690 (op->type == ARMOUR || op->type == BOOTS || 667 (op->type == ARMOUR || op->type == BOOTS
691 op->type == CLOAK || op->type == HELMET || 668 || op->type == CLOAK || op->type == HELMET
692 op->type == SHIELD || op->type == GLOVES || 669 || op->type == SHIELD || op->type == GLOVES
670 || op->type == BRACERS || op->type == GIRDLE))
693 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))
694 { 672 {
695 op->destroy (); 673 op->destroy ();
696 continue; 674 continue;
697 } 675 }
698 } 676 }
721 if (op->nrof > 1) 699 if (op->nrof > 1)
722 op->nrof = 1; 700 op->nrof = 1;
723 } 701 }
724 702
725 if (op->type == SPELLBOOK && op->inv) 703 if (op->type == SPELLBOOK && op->inv)
726 {
727 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 704 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
728 }
729 705
730 /* Give starting characters identified, uncursed, and undamned 706 /* Give starting characters identified, uncursed, and undamned
731 * 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
732 * merged properly. 708 * merged properly.
733 */ 709 */
734 if (need_identify (op)) 710 if (need_identify (op))
735 { 711 {
736 SET_FLAG (op, FLAG_IDENTIFIED); 712 SET_FLAG (op, FLAG_IDENTIFIED);
737 CLEAR_FLAG (op, FLAG_CURSED); 713 CLEAR_FLAG (op, FLAG_CURSED);
738 CLEAR_FLAG (op, FLAG_DAMNED); 714 CLEAR_FLAG (op, FLAG_DAMNED);
739 } 715 }
716
740 if (op->type == SPELL) 717 if (op->type == SPELL)
741 { 718 {
742 op->destroy (); 719 op->destroy ();
743 continue; 720 continue;
744 } 721 }
746 { 723 {
747 SET_FLAG (op, FLAG_CAN_USE_SKILL); 724 SET_FLAG (op, FLAG_CAN_USE_SKILL);
748 op->stats.exp = 0; 725 op->stats.exp = 0;
749 op->level = 1; 726 op->level = 1;
750 } 727 }
751 /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
752 else
753 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
754 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
755 731
756 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
757 link_player_skills (pl); 733 link_player_skills (pl);
863static void 839static void
864start_info (object *op) 840start_info (object *op)
865{ 841{
866 char buf[MAX_BUF]; 842 char buf[MAX_BUF];
867 843
868 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 844 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
869 new_draw_info (NDI_UNIQUE, 0, op, buf); 845 new_draw_info (NDI_UNIQUE, 0, op, buf);
870 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
871 //new_draw_info (NDI_UNIQUE, 0, op, " ");
872} 846}
873 847
874/* This function takes the key that is passed, and does the 848/* This function takes the key that is passed, and does the
875 * appropriate action with it (change race, or other things). 849 * appropriate action with it (change race, or other things).
876 * The function name is for historical reasons - now we have 850 * The function name is for historical reasons - now we have
879 */ 853 */
880void 854void
881player::chargen_race_done () 855player::chargen_race_done ()
882{ 856{
883 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
884 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
885 859
886 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
887 if (tl) 861 if (tl)
888 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
889 863
892 866
893 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
894 868
895 if (ob->msg) 869 if (ob->msg)
896 ob->msg = 0; 870 ob->msg = 0;
897
898 /* We create this now because some of the unique maps will need it
899 * to save here.
900 */
901 {
902 char buf[MAX_BUF];
903 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
904 make_path_to_file (buf);
905 }
906 871
907 start_info (ob); 872 start_info (ob);
908 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
909 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
910 link_player_skills (ob); 875 link_player_skills (ob);
913 878
914 /* This moves the player to a different start map, if there 879 /* This moves the player to a different start map, if there
915 * is one for this race 880 * is one for this race
916 */ 881 */
917 if (*first_map_ext_path) 882 if (*first_map_ext_path)
918 { 883 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
919 object *tmp;
920 char mapname[MAX_BUF];
921
922 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name);
923 tmp = object::create ();
924 EXIT_PATH (tmp) = mapname;
925 EXIT_X (tmp) = ob->x;
926 EXIT_Y (tmp) = ob->y;
927 ob->enter_exit (tmp); /* we don't really care if it succeeded;
928 * if the map isn't there, then stay on the
929 * default initial map */
930 tmp->destroy ();
931 }
932 else 884 else
933 LOG (llevDebug, "first_map_ext_path not set\n"); 885 LOG (llevDebug, "first_map_ext_path not set\n");
934} 886}
935 887
936void 888void
946 int x = ob->x, y = ob->y; 898 int x = ob->x, y = ob->y;
947 899
948 ob->remove_statbonus (); 900 ob->remove_statbonus ();
949 ob->remove (); 901 ob->remove ();
950 ob->arch = get_player_archetype (ob->arch); 902 ob->arch = get_player_archetype (ob->arch);
951 ob->arch->clone.copy_to (ob); 903 ob->arch->copy_to (ob);
952 ob->instantiate (); 904 ob->instantiate ();
953 ob->stats = ob->contr->orig_stats; 905 ob->stats = ob->contr->orig_stats;
954 ob->name = ob->name_pl = name; 906 ob->name = ob->name_pl = name;
955 ob->x = x; 907 ob->x = x;
956 ob->y = y; 908 ob->y = y;
957 SET_ANIMATION (ob, 2); /* So player faces south */ 909 SET_ANIMATION (ob, 2); /* So player faces south */
958 insert_ob_in_map (ob, ob->map, ob, 0); 910 insert_ob_in_map (ob, ob->map, ob, 0);
959 assign (ob->contr->title, ob->arch->clone.name); 911 assign (ob->contr->title, ob->arch->object::name);
960 ob->add_statbonus (); 912 ob->add_statbonus ();
961 } 913 }
962 while (!allowed_class (ob)); 914 while (!allowed_class (ob));
963 915
964 update_object (ob, UP_OBJ_FACE); 916 update_object (ob, UP_OBJ_FACE);
1039 if (op->move_type & MOVE_FLYING) 991 if (op->move_type & MOVE_FLYING)
1040 return 1; 992 return 1;
1041 993
1042 next = op->below; 994 next = op->below;
1043 995
996 int cnt = MAX_ITEM_PER_DROP;
997#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
998
1044 /* 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
1045 * destroyed */ 1000 * destroyed */
1046 while (next && !next->destroyed ()) 1001 while (next && !next->destroyed ())
1047 { 1002 {
1048 tmp = next; 1003 tmp = next;
1049 next = tmp->below; 1004 next = tmp->below;
1050 1005
1006 if (cnt <= 0)
1007 {
1008 op->failmsg ("Couldn't pickup all items at once.");
1009 return 0;
1010 }
1011
1051 if (op->destroyed ()) 1012 if (op->destroyed ())
1052 return 0; 1013 return 0;
1053 1014
1054 if (!can_pick (op, tmp)) 1015 if (!can_pick (op, tmp))
1055 continue; 1016 continue;
1056 1017
1057 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1018 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1058 { 1019 {
1059 if (item_matched_string (op, tmp, op->contr->search_str)) 1020 if (item_matched_string (op, tmp, op->contr->search_str))
1060 pick_up (op, tmp); 1021 CHK_PICK_PICKUP;
1061 continue; 1022 continue;
1062 } 1023 }
1063 1024
1064 /* high not bit set? We're using the old autopickup model */ 1025 /* high not bit set? We're using the old autopickup model */
1065 if (!(op->contr->mode & PU_NEWMODE)) 1026 if (!(op->contr->mode & PU_NEWMODE))
1067 switch (op->contr->mode) 1028 switch (op->contr->mode)
1068 { 1029 {
1069 case 0: 1030 case 0:
1070 return 1; /* don't pick up */ 1031 return 1; /* don't pick up */
1071 case 1: 1032 case 1:
1072 pick_up (op, tmp); 1033 CHK_PICK_PICKUP;
1073 return 1; 1034 return 1;
1074 case 2: 1035 case 2:
1075 pick_up (op, tmp); 1036 CHK_PICK_PICKUP;
1076 return 0; 1037 return 0;
1077 case 3: 1038 case 3:
1078 return 0; /* stop before pickup */ 1039 return 0; /* stop before pickup */
1079 case 4: 1040 case 4:
1080 pick_up (op, tmp); 1041 CHK_PICK_PICKUP;
1081 break; 1042 break;
1082 case 5: 1043 case 5:
1083 pick_up (op, tmp); 1044 CHK_PICK_PICKUP;
1084 stop = 1; 1045 stop = 1;
1085 break; 1046 break;
1086 case 6: 1047 case 6:
1087 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1048 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1088 pick_up (op, tmp); 1049 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1050 CHK_PICK_PICKUP;
1089 break; 1051 break;
1090 1052
1091 case 7: 1053 case 7:
1092 if (tmp->type == MONEY || tmp->type == GEM) 1054 if (tmp->type == MONEY || tmp->type == GEM)
1093 pick_up (op, tmp); 1055 CHK_PICK_PICKUP;
1094 break; 1056 break;
1095 1057
1096 default: 1058 default:
1097 /* use value density */ 1059 /* use value density */
1098 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1060 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1099 && (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)
1100 pick_up (op, tmp); 1062 CHK_PICK_PICKUP;
1101 } 1063 }
1102 } 1064 }
1103 else 1065 else
1104 { /* old model */ 1066 { /* old model */
1105 /* NEW pickup handling */ 1067 /* NEW pickup handling */
1109 if (tmp->name != NULL) 1071 if (tmp->name != NULL)
1110 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1072 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1111 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1073 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1112 else 1074 else
1113 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1075 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1114 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1076 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1115 1077
1116 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1078 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1117 } 1079 }
1118 1080
1119 /* philosophy: 1081 /* philosophy:
1160 /* all food and drink if desired */ 1122 /* all food and drink if desired */
1161 /* question: don't pick up known-poisonous stuff? */ 1123 /* question: don't pick up known-poisonous stuff? */
1162 if (op->contr->mode & PU_FOOD) 1124 if (op->contr->mode & PU_FOOD)
1163 if (tmp->type == FOOD) 1125 if (tmp->type == FOOD)
1164 { 1126 {
1165 pick_up (op, tmp); 1127 CHK_PICK_PICKUP;
1166 continue; 1128 continue;
1167 } 1129 }
1168 1130
1169 if (op->contr->mode & PU_DRINK) 1131 if (op->contr->mode & PU_DRINK)
1170 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)))
1171 { 1133 {
1172 pick_up (op, tmp); 1134 CHK_PICK_PICKUP;
1173 continue; 1135 continue;
1174 } 1136 }
1175 1137
1176 if (op->contr->mode & PU_POTION) 1138 if (op->contr->mode & PU_POTION)
1177 if (tmp->type == POTION) 1139 if (tmp->type == POTION)
1178 { 1140 {
1179 pick_up (op, tmp); 1141 CHK_PICK_PICKUP;
1180 continue; 1142 continue;
1181 } 1143 }
1182 1144
1183 /* spellbooks, skillscrolls and normal books/scrolls */ 1145 /* spellbooks, skillscrolls and normal books/scrolls */
1184 if (op->contr->mode & PU_SPELLBOOK) 1146 if (op->contr->mode & PU_SPELLBOOK)
1185 if (tmp->type == SPELLBOOK) 1147 if (tmp->type == SPELLBOOK)
1186 { 1148 {
1187 pick_up (op, tmp); 1149 CHK_PICK_PICKUP;
1188 continue; 1150 continue;
1189 } 1151 }
1190 1152
1191 if (op->contr->mode & PU_SKILLSCROLL) 1153 if (op->contr->mode & PU_SKILLSCROLL)
1192 if (tmp->type == SKILLSCROLL) 1154 if (tmp->type == SKILLSCROLL)
1193 { 1155 {
1194 pick_up (op, tmp); 1156 CHK_PICK_PICKUP;
1195 continue; 1157 continue;
1196 } 1158 }
1197 1159
1198 if (op->contr->mode & PU_READABLES) 1160 if (op->contr->mode & PU_READABLES)
1199 if (tmp->type == BOOK || tmp->type == SCROLL) 1161 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1200 { 1162 {
1201 pick_up (op, tmp); 1163 CHK_PICK_PICKUP;
1202 continue; 1164 continue;
1203 } 1165 }
1204 1166
1205 /* wands/staves/rods/horns */ 1167 /* wands/staves/rods/horns */
1206 if (op->contr->mode & PU_MAGIC_DEVICE) 1168 if (op->contr->mode & PU_MAGIC_DEVICE)
1207 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1169 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1208 { 1170 {
1209 pick_up (op, tmp); 1171 CHK_PICK_PICKUP;
1210 continue; 1172 continue;
1211 } 1173 }
1212 1174
1213 /* pick up all magical items */ 1175 /* pick up all magical items */
1214 if (op->contr->mode & PU_MAGICAL) 1176 if (op->contr->mode & PU_MAGICAL)
1215 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))
1216 { 1178 {
1217 pick_up (op, tmp); 1179 CHK_PICK_PICKUP;
1218 continue; 1180 continue;
1219 } 1181 }
1220 1182
1221 if (op->contr->mode & PU_VALUABLES) 1183 if (op->contr->mode & PU_VALUABLES)
1222 { 1184 {
1223 if (tmp->type == MONEY || tmp->type == GEM) 1185 if (tmp->type == MONEY || tmp->type == GEM)
1224 { 1186 {
1225 pick_up (op, tmp); 1187 CHK_PICK_PICKUP;
1226 continue; 1188 continue;
1227 } 1189 }
1228 } 1190 }
1229 1191
1230 /* rings & amulets - talismans seems to be typed AMULET */ 1192 /* rings & amulets - talismans seems to be typed AMULET */
1231 if (op->contr->mode & PU_JEWELS) 1193 if (op->contr->mode & PU_JEWELS)
1232 if (tmp->type == RING || tmp->type == AMULET) 1194 if (tmp->type == RING || tmp->type == AMULET)
1233 { 1195 {
1234 pick_up (op, tmp); 1196 CHK_PICK_PICKUP;
1235 continue; 1197 continue;
1236 } 1198 }
1237 1199
1238 /* we don't forget dragon food */ 1200 /* we don't forget dragon food */
1239 if (op->contr->mode & PU_FLESH) 1201 if (op->contr->mode & PU_FLESH)
1240 if (tmp->type == FLESH) 1202 if (tmp->type == FLESH)
1241 { 1203 {
1242 pick_up (op, tmp); 1204 CHK_PICK_PICKUP;
1243 continue; 1205 continue;
1244 } 1206 }
1245 1207
1246 /* bows and arrows. Bows are good for selling! */ 1208 /* bows and arrows. Bows are good for selling! */
1247 if (op->contr->mode & PU_BOW) 1209 if (op->contr->mode & PU_BOW)
1248 if (tmp->type == BOW) 1210 if (tmp->type == BOW)
1249 { 1211 {
1250 pick_up (op, tmp); 1212 CHK_PICK_PICKUP;
1251 continue; 1213 continue;
1252 } 1214 }
1253 1215
1254 if (op->contr->mode & PU_ARROW) 1216 if (op->contr->mode & PU_ARROW)
1255 if (tmp->type == ARROW) 1217 if (tmp->type == ARROW)
1256 { 1218 {
1257 pick_up (op, tmp); 1219 CHK_PICK_PICKUP;
1258 continue; 1220 continue;
1259 } 1221 }
1260 1222
1261 /* all kinds of armor etc. */ 1223 /* all kinds of armor etc. */
1262 if (op->contr->mode & PU_ARMOUR) 1224 if (op->contr->mode & PU_ARMOUR)
1263 if (tmp->type == ARMOUR) 1225 if (tmp->type == ARMOUR)
1264 { 1226 {
1265 pick_up (op, tmp); 1227 CHK_PICK_PICKUP;
1266 continue; 1228 continue;
1267 } 1229 }
1268 1230
1269 if (op->contr->mode & PU_HELMET) 1231 if (op->contr->mode & PU_HELMET)
1270 if (tmp->type == HELMET) 1232 if (tmp->type == HELMET)
1271 { 1233 {
1272 pick_up (op, tmp); 1234 CHK_PICK_PICKUP;
1273 continue; 1235 continue;
1274 } 1236 }
1275 1237
1276 if (op->contr->mode & PU_SHIELD) 1238 if (op->contr->mode & PU_SHIELD)
1277 if (tmp->type == SHIELD) 1239 if (tmp->type == SHIELD)
1278 { 1240 {
1279 pick_up (op, tmp); 1241 CHK_PICK_PICKUP;
1280 continue; 1242 continue;
1281 } 1243 }
1282 1244
1283 if (op->contr->mode & PU_BOOTS) 1245 if (op->contr->mode & PU_BOOTS)
1284 if (tmp->type == BOOTS) 1246 if (tmp->type == BOOTS)
1285 { 1247 {
1286 pick_up (op, tmp); 1248 CHK_PICK_PICKUP;
1287 continue; 1249 continue;
1288 } 1250 }
1289 1251
1290 if (op->contr->mode & PU_GLOVES) 1252 if (op->contr->mode & PU_GLOVES)
1291 if (tmp->type == GLOVES) 1253 if (tmp->type == GLOVES)
1292 { 1254 {
1293 pick_up (op, tmp); 1255 CHK_PICK_PICKUP;
1294 continue; 1256 continue;
1295 } 1257 }
1296 1258
1297 if (op->contr->mode & PU_CLOAK) 1259 if (op->contr->mode & PU_CLOAK)
1298 if (tmp->type == CLOAK) 1260 if (tmp->type == CLOAK)
1299 { 1261 {
1300 pick_up (op, tmp); 1262 CHK_PICK_PICKUP;
1301 continue; 1263 continue;
1302 } 1264 }
1303 1265
1304 /* hoping to catch throwing daggers here */ 1266 /* hoping to catch throwing daggers here */
1305 if (op->contr->mode & PU_MISSILEWEAPON) 1267 if (op->contr->mode & PU_MISSILEWEAPON)
1306 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1268 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1307 { 1269 {
1308 pick_up (op, tmp); 1270 CHK_PICK_PICKUP;
1309 continue; 1271 continue;
1310 } 1272 }
1311 1273
1312 /* careful: chairs and tables are weapons! */ 1274 /* careful: chairs and tables are weapons! */
1313 if (op->contr->mode & PU_ALLWEAPON) 1275 if (op->contr->mode & PU_ALLWEAPON)
1314 { 1276 {
1315 if (tmp->type == WEAPON && tmp->name != NULL) 1277 if (tmp->type == WEAPON && tmp->name != NULL)
1316 { 1278 {
1317 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1279 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1318 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1280 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1319 { 1281 {
1320 pick_up (op, tmp); 1282 CHK_PICK_PICKUP;
1321 continue; 1283 continue;
1322 } 1284 }
1323 } 1285 }
1324 1286
1325 if (tmp->type == WEAPON && tmp->name == NULL) 1287 if (tmp->type == WEAPON && tmp->name == NULL)
1326 { 1288 {
1327 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1289 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1328 { 1290 {
1329 pick_up (op, tmp); 1291 CHK_PICK_PICKUP;
1330 continue; 1292 continue;
1331 } 1293 }
1332 } 1294 }
1333 } 1295 }
1334 1296
1335 /* misc stuff that's useful */ 1297 /* misc stuff that's useful */
1336 if (op->contr->mode & PU_KEY) 1298 if (op->contr->mode & PU_KEY)
1337 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1299 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1338 { 1300 {
1339 pick_up (op, tmp); 1301 CHK_PICK_PICKUP;
1340 continue; 1302 continue;
1341 } 1303 }
1342 1304
1343 /* 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
1344 * pickups */ 1306 * pickups */
1345 if (op->contr->mode & PU_RATIO) 1307 if (op->contr->mode & PU_RATIO)
1346 { 1308 {
1347 /* use value density to decide what else to grab */ 1309 /* use value density to decide what else to grab */
1348 /* >=7 was >= op->contr->mode */ 1310 /* >=7 was >= op->contr->mode */
1349 /* >=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
1350 * and multiply them by 5, giving 0..15*5== 5..75 */ 1312 */
1351 wvratio = (op->contr->mode & PU_RATIO) * 5; 1313 wvratio = op->contr->mode & PU_RATIO;
1352 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)
1353 { 1315 {
1354 pick_up (op, tmp); 1316 CHK_PICK_PICKUP;
1355#if 0 1317#if 0
1356 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1318 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1357 if (tmp->name != NULL) 1319 if (tmp->name != NULL)
1358 { 1320 {
1359 fprintf (stderr, "%s", tmp->name); 1321 fprintf (stderr, "%s", tmp->name);
1360 } 1322 }
1361 else 1323 else
1362 fprintf (stderr, "%s", tmp->arch->name); 1324 fprintf (stderr, "%s", tmp->arch->archname);
1363 fprintf (stderr, ",%d] = ", tmp->type); 1325 fprintf (stderr, ",%d] = ", tmp->type);
1364 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1326 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1365#endif 1327#endif
1366 continue; 1328 continue;
1367 } 1329 }
1378 * found object is returned. 1340 * found object is returned.
1379 */ 1341 */
1380object * 1342object *
1381find_arrow (object *op, const char *type) 1343find_arrow (object *op, const char *type)
1382{ 1344{
1383 object *tmp = 0;
1384
1385 for (op = op->inv; op; op = op->below) 1345 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1386 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1387 tmp = find_arrow (op, type);
1388 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);
1389 return op; 1354 return arrow;
1355 }
1390 1356
1391 return tmp; 1357 return 0;
1392} 1358}
1393 1359
1394/* 1360/*
1395 * 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
1396 * 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
1419 } 1385 }
1420 } 1386 }
1421 else if (arrow->type == ARROW && arrow->race == type) 1387 else if (arrow->type == ARROW && arrow->race == type)
1422 { 1388 {
1423 /* allways prefer assasination/slaying */ 1389 /* allways prefer assasination/slaying */
1424 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1390 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1425 { 1391 {
1426 if (arrow->attacktype & AT_DEATH) 1392 if (arrow->attacktype & AT_DEATH)
1427 { 1393 {
1428 *better = 100; 1394 *better = 100;
1429 return arrow; 1395 return arrow;
1437 else 1403 else
1438 { 1404 {
1439 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) 1405 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++)
1440 { 1406 {
1441 attacktype = 1 << attacknum; 1407 attacktype = 1 << attacknum;
1442 if ((arrow->attacktype & attacktype) && (target->arch->clone.resist[attacknum]) < 0) 1408 if ((arrow->attacktype & attacktype) && (target->arch->resist[attacknum]) < 0)
1443 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100) > betterby) 1409 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100) > betterby)
1444 { 1410 {
1445 tmp = arrow; 1411 tmp = arrow;
1446 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100; 1412 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1447 } 1413 }
1448 } 1414 }
1449 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1415 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1450 { 1416 {
1451 tmp = arrow; 1417 tmp = arrow;
1457 betterby = 1 + arrow->magic + arrow->stats.dam; 1423 betterby = 1 + arrow->magic + arrow->stats.dam;
1458 } 1424 }
1459 } 1425 }
1460 } 1426 }
1461 } 1427 }
1428
1462 if (tmp == NULL && arrow == NULL) 1429 if (tmp == NULL && arrow == NULL)
1463 return find_arrow (op, type); 1430 return find_arrow (op, type);
1464 1431
1465 *better = betterby; 1432 *better = betterby;
1466 return tmp; 1433 return tmp;
1617 arrow->destroy (); 1584 arrow->destroy ();
1618 return 0; 1585 return 0;
1619 } 1586 }
1620 1587
1621 left = arrow; /* these are arrows left to the player */ 1588 left = arrow; /* these are arrows left to the player */
1622 arrow = get_split_ob (arrow, 1); 1589 arrow = arrow->split ();
1623 if (!arrow) 1590 if (!arrow)
1624 { 1591 {
1625 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);
1626 return 0; 1593 return 0;
1627 } 1594 }
1635 arrow->stats.grace = arrow->attacktype; 1602 arrow->stats.grace = arrow->attacktype;
1636 1603
1637 if (arrow->slaying) 1604 if (arrow->slaying)
1638 arrow->spellarg = strdup (arrow->slaying); 1605 arrow->spellarg = strdup (arrow->slaying);
1639 1606
1607#if 0
1640 if (player *pl = op->contr) 1608 if (player *pl = op->contr)
1641 { 1609 {
1642 if (!pl->has_hit)
1643 {
1644 pl->has_hit = 1;
1645 pl->ob->speed_left += pl->weapon_sp - pl->ob->speed;
1646 }
1647#if 0
1648 float speed = pl->weapon_sp; 1610 float speed = pl->weapon_sp;
1649 1611
1650 /* penalize ROF for bestarrow */ 1612 /* penalize ROF for bestarrow */
1651 if (pl->bowtype == bow_bestarrow) 1613 if (pl->bowtype == bow_bestarrow)
1652 speed *= .9f; 1614 speed *= .9f;
1653 else 1615 else
1654 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f; 1616 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f;
1655 1617
1656 op->speed_left += speed - op->speed; 1618 op->speed_left += speed - op->speed;
1619 }
1657#endif 1620#endif
1658 }
1659 1621
1660 SET_ANIMATION (arrow, arrow->direction); 1622 SET_ANIMATION (arrow, arrow->direction);
1661 1623
1662 /* update the speed */ 1624 /* update the speed */
1663 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 1625 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1664 + bow->stats.dam / 7.0; 1626 + bow->stats.dam / 7.f;
1665 1627
1666 arrow->set_speed (max (arrow->speed, 2.0)); 1628 arrow->set_speed (max (arrow->speed, 2.f));
1667 arrow->speed_left = 0; 1629 arrow->speed_left = 0;
1668 1630
1669 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1631 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1670 1632
1671 if (op->type == PLAYER) 1633 if (op->type == PLAYER)
1694 1656
1695 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); 1657 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1696 arrow->move_type = MOVE_FLY_LOW; 1658 arrow->move_type = MOVE_FLY_LOW;
1697 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1659 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1698 1660
1699 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1661 op->play_sound (sound_find ("fire_arrow"));
1700 m->insert (arrow, sx, sy, op); 1662 m->insert (arrow, sx, sy, op);
1701 1663
1702 if (!arrow->destroyed ()) 1664 if (!arrow->destroyed ())
1703 move_arrow (arrow); 1665 move_arrow (arrow);
1704
1705 if (op->type == PLAYER)
1706 {
1707 if (left->destroyed ())
1708 esrv_del_item (op->contr, left->count);
1709 else
1710 esrv_send_item (op, left);
1711 }
1712 1666
1713 return 1; 1667 return 1;
1714} 1668}
1715 1669
1716/* Special fire code for players - this takes into 1670/* Special fire code for players - this takes into
1782 1736
1783 if (item->type == WAND) 1737 if (item->type == WAND)
1784 { 1738 {
1785 if (item->stats.food <= 0) 1739 if (item->stats.food <= 0)
1786 { 1740 {
1787 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1741 op->contr->play_sound (sound_find ("wand_poof"));
1788 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0)); 1742 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0));
1789 1743
1790 return; 1744 return;
1791 } 1745 }
1792 } 1746 }
1793 else if (item->type == ROD || item->type == HORN) 1747 else if (item->type == ROD || item->type == HORN)
1794 { 1748 {
1795 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))
1796 { 1754 {
1797 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1755 op->contr->play_sound (sound_find ("wand_poof"));
1798 1756
1799 if (item->type == ROD) 1757 if (item->type == ROD)
1800 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));
1801 else 1759 else
1802 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0)); 1760 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0));
1815 object *tmp; 1773 object *tmp;
1816 1774
1817 if (item->arch) 1775 if (item->arch)
1818 { 1776 {
1819 CLEAR_FLAG (item, FLAG_ANIMATE); 1777 CLEAR_FLAG (item, FLAG_ANIMATE);
1820 item->face = item->arch->clone.face; 1778 item->face = item->arch->face;
1821 item->set_speed (0); 1779 item->set_speed (0);
1822 } 1780 }
1823 1781
1824 if ((tmp = item->in_player ())) 1782 if (object *pl = item->visible_to ())
1825 esrv_update_item (UPD_ANIM, tmp, item); 1783 esrv_update_item (UPD_ANIM, pl, item);
1826 } 1784 }
1827 } 1785 }
1828 else if (item->type == ROD || item->type == HORN) 1786 else if (item->type == ROD || item->type == HORN)
1829 drain_rod_charge (item); 1787 drain_rod_charge (item);
1830 } 1788 }
1831} 1789}
1832 1790
1833/* Received a fire command for the player - go and do it. 1791/* Received a fire command for the player - go and do it.
1834 */ 1792 */
1835void 1793bool
1836fire (object *op, int dir) 1794fire (object *op, int dir)
1837{ 1795{
1838 int spellcost = 0; 1796 int spellcost = 0;
1839 1797
1840 /* check for loss of invisiblity/hide */ 1798 /* check for loss of invisiblity/hide */
1844 player *pl = op->contr; 1802 player *pl = op->contr;
1845 1803
1846 if (pl->golem) 1804 if (pl->golem)
1847 { 1805 {
1848 control_golem (op->contr->golem, dir); 1806 control_golem (op->contr->golem, dir);
1849 return; 1807 return false;
1850 } 1808 }
1851 1809
1852 object *ob = pl->ranged_ob; 1810 object *ob = pl->ranged_ob;
1853 1811
1854 if (!ob) 1812 if (!ob)
1855 return; 1813 return false;
1856 1814
1857 if (!op->change_weapon (ob)) 1815 if (!op->change_weapon (ob))
1858 return; 1816 return false;
1817
1818 if (op->speed_left > 0.f)
1819 --op->speed_left;
1820 else
1821 return false;
1859 1822
1860 switch (ob->type) 1823 switch (ob->type)
1861 { 1824 {
1862 case BOW: 1825 case BOW:
1863 player_fire_bow (op, dir); 1826 player_fire_bow (op, dir);
1877 1840
1878 default: 1841 default:
1879 fire_misc_object (op, dir); 1842 fire_misc_object (op, dir);
1880 break; 1843 break;
1881 } 1844 }
1845
1846 return true;
1882} 1847}
1883 1848
1884/* find_key 1849/* find_key
1885 * We try to find a key for the door as passed. If we find a key 1850 * We try to find a key for the door as passed. If we find a key
1886 * and successfully use it, we return the key, otherwise NULL 1851 * and successfully use it, we return the key, otherwise NULL
1973 * 0 otherwise 1938 * 0 otherwise
1974 */ 1939 */
1975static int 1940static int
1976player_attack_door (object *op, object *door) 1941player_attack_door (object *op, object *door)
1977{ 1942{
1978 /* If its a door, try to find a use a key. If we do destroy the door, 1943 /* If its a door, try to find a key. If we do destroy the door,
1979 * might as well return immediately as there is nothing more to do - 1944 * might as well return immediately as there is nothing more to do -
1980 * otherwise, we fall through to the rest of the code. 1945 * otherwise, we fall through to the rest of the code.
1981 */ 1946 */
1982 object *key = find_key (op, op, door); 1947 object *key = find_key (op, op, door);
1983 1948
1984 /* IF we found a key, do some extra work */ 1949 /* If we found a key, do some extra work */
1985 if (key) 1950 if (key)
1986 { 1951 {
1987 object *container = key->env; 1952 object *container = key->env;
1988
1989 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR);
1990 1953
1991 if (action_makes_visible (op)) 1954 if (action_makes_visible (op))
1992 make_visible (op); 1955 make_visible (op);
1993 1956
1994 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1957 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
1996 1959
1997 if (door->type == DOOR) 1960 if (door->type == DOOR)
1998 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 */
1999 else if (door->type == LOCKED_DOOR) 1962 else if (door->type == LOCKED_DOOR)
2000 { 1963 {
2001 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);
2002 remove_door2 (door); /* remove door without violence ;-) */ 1965 remove_door2 (door); /* remove door without violence ;-) */
2003 } 1966 }
2004 1967
2005 /* Do this after we print the message */ 1968 /* Do this after we print the message */
2006 decrease_ob (key); /* Use up one of the keys */ 1969 key->decrease (); /* Use up one of the keys */
2007 /* Need to update the weight the container the key was in */
2008 if (container != op)
2009 esrv_update_item (UPD_WEIGHT, op, container);
2010 1970
2011 return 1; /* Nothing more to do below */ 1971 return 1; /* Nothing more to do below */
2012 } 1972 }
2013 else if (door->type == LOCKED_DOOR) 1973 else if (door->type == LOCKED_DOOR)
2014 { 1974 {
2015 /* Might as well return now - no other way to open this */ 1975 /* Might as well return now - no other way to open this */
2016 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...");
2017 return 1; 1977 return 1;
2018 } 1978 }
2019 1979
2020 return 0; 1980 return 0;
2021} 1981}
2024 * It should keep the code cleaner. 1984 * It should keep the code cleaner.
2025 * When this is called, the players direction has been updated 1985 * When this is called, the players direction has been updated
2026 * (taking into account confusion.) The player is also actually 1986 * (taking into account confusion.) The player is also actually
2027 * going to try and move (not fire weapons). 1987 * going to try and move (not fire weapons).
2028 */ 1988 */
2029void 1989bool
2030move_player_attack (object *op, int dir) 1990move_player_attack (object *op, int dir)
2031{ 1991{
2032 object *tmp, *mon;
2033 int on_battleground; 1992 int on_battleground;
2034 maptile *m;
2035 1993
2036 sint16 nx = freearr_x[dir] + op->x; 1994 sint16 nx = freearr_x[dir] + op->x;
2037 sint16 ny = freearr_y[dir] + op->y; 1995 sint16 ny = freearr_y[dir] + op->y;
2038 1996
2039 on_battleground = op_on_battleground (op, 0, 0); 1997 on_battleground = op_on_battleground (op, 0, 0);
1998
1999 if (out_of_map (op->map, nx, ny))
2000 return false;
2001
2002 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op))
2003 {
2004 --op->speed_left;
2005 return true;
2006 }
2040 2007
2041 /* If braced, or can't move to the square, and it is not out of the 2008 /* If braced, or can't move to the square, and it is not out of the
2042 * map, attack it. Note order of if statement is important - don't 2009 * map, attack it. Note order of if statement is important - don't
2043 * want to be calling move_ob if braced, because move_ob will move the 2010 * want to be calling move_ob if braced, because move_ob will move the
2044 * player. This is a pretty nasty hack, because if we could 2011 * player. This is a pretty nasty hack, because if we could
2045 * move to some space, it then means that if we are braced, we should 2012 * move to some space, it then means that if we are braced, we should
2046 * do nothing at all. As it is, if we are braced, we go through 2013 * do nothing at all. As it is, if we are braced, we go through
2047 * quite a bit of processing. However, it probably is less than what 2014 * quite a bit of processing. However, it probably is less than what
2048 * move_ob uses. 2015 * move_ob uses.
2049 */ 2016 */
2050 if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny))
2051 {
2052 if (OUT_OF_REAL_MAP (op->map, nx, ny))
2053 {
2054 m = op->map->xy_find (nx, ny); 2017 maptile *m = op->map->xy_find (nx, ny);
2055 if (!m)
2056 return; /* Don't think this should happen */
2057 }
2058 else
2059 m = op->map;
2060 2018
2061 if (!(tmp = m->at (nx, ny).bot))
2062 return;
2063
2064 mon = 0;
2065 /* Go through all the objects, and find ones of interest. Only stop if 2019 /* Go through all the objects, and find ones of interest. Only stop if
2066 * we find a monster - that is something we know we want to attack. 2020 * we find a monster - that is something we know we want to attack.
2067 * if its a door or barrel (can roll) see if there may be monsters 2021 * if its a door or barrel (can roll) see if there may be monsters
2068 * on the space 2022 * on the space
2069 */ 2023 */
2070 while (tmp) 2024 object *mon;
2071 { 2025 for (mon = m->at (nx, ny).bot; mon; mon = mon->above)
2072 if (tmp == op) 2026 {
2073 { 2027 if ((mon->flag [FLAG_ALIVE]
2074 tmp = tmp->above; 2028 || mon->type == LOCKED_DOOR
2075 continue; 2029 || mon->flag [FLAG_CAN_ROLL])
2076 }
2077
2078 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2079 {
2080 mon = tmp; 2030 && mon != op)
2081 break; 2031 break;
2082 } 2032 }
2083 2033
2084 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2085 mon = tmp;
2086
2087 tmp = tmp->above;
2088 }
2089
2090 if (!mon) /* This happens anytime the player tries to move */ 2034 if (!mon) /* This happens anytime the player tries to move */
2091 return; /* into a wall */ 2035 return false; /* into a wall */
2092 2036
2093 if (mon->head)
2094 mon = mon->head; 2037 mon = mon->head_ ();
2095 2038
2096 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 2039 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2040 if (op->contr->weapon_sp_left > 0.f)
2097 if (player_attack_door (op, mon)) 2041 if (player_attack_door (op, mon))
2042 {
2043 --op->contr->weapon_sp_left;
2098 return; 2044 return true;
2045 }
2099 2046
2100 /* The following deals with possibly attacking peaceful 2047 /* The following deals with possibly attacking peaceful
2101 * or frienddly creatures. Basically, all players are considered 2048 * or friendly creatures. Basically, all players are considered
2102 * unaggressive. If the moving player has peaceful set, then the 2049 * unaggressive. If the moving player has peaceful set, then the
2103 * object should be pushed instead of attacked. It is assumed that 2050 * object should be pushed instead of attacked. It is assumed that
2104 * if you are braced, you will not attack friends accidently, 2051 * if you are braced, you will not attack friends accidently,
2105 * and thus will not push them. 2052 * and thus will not push them.
2106 */ 2053 */
2107 2054
2108 /* If the creature is a pet, push it even if the player is not 2055 /* If the creature is a pet, push it even if the player is not
2109 * peaceful. Our assumption is the creature is a pet if the 2056 * peaceful. Our assumption is the creature is a pet if the
2110 * player owns it and it is either friendly or unagressive. 2057 * player owns it and it is either friendly or unagressive.
2111 */ 2058 */
2112 if (op->type == PLAYER 2059 if (op->type == PLAYER
2113 && ((mon->owner && mon->owner->contr 2060 && ((mon->owner && mon->owner->contr
2114 && same_party (mon->owner->contr->party, op->contr->party)) 2061 && same_party (mon->owner->contr->party, op->contr->party))
2115 || mon->owner == op) 2062 || mon->owner == op)
2116 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2063 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2117 { 2064 {
2118 /* If we're braced, we don't want to switch places with it */ 2065 /* If we're braced, we don't want to switch places with it */
2119 if (op->contr->braced) 2066 if (op->contr->braced)
2120 return; 2067 return false;
2121 2068
2122 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2069 if (op->speed_left > 0.f)
2070 {
2071 --op->speed_left;
2072
2073 op->play_sound (sound_find ("push_player"));
2123 push_ob (mon, dir, op); 2074 push_ob (mon, dir, op);
2075
2124 if (op->contr->tmp_invis || op->hide) 2076 if (op->contr->tmp_invis || op->hide)
2125 make_visible (op); 2077 make_visible (op);
2126 2078
2127 return; 2079 return true;
2128 } 2080 }
2081 else
2082 return false;
2083 }
2129 2084
2130 /* in certain circumstances, you shouldn't attack friendly 2085 /* in certain circumstances, you shouldn't attack friendly
2131 * creatures. Note that if you are braced, you can't push 2086 * creatures. Note that if you are braced, you can't push
2132 * someone, but put it inside this loop so that you won't 2087 * someone, but put it inside this loop so that you won't
2133 * attack them either. 2088 * attack them either.
2134 */ 2089 */
2135 if ((mon->type == PLAYER || mon->enemy != op) 2090 if ((mon->type == PLAYER || mon->enemy != op)
2136 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 2091 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))
2137 && ((op->contr->peaceful 2092 && ((op->contr->peaceful
2138 || (mon->type == PLAYER && mon->contr->peaceful)) 2093 || (mon->type == PLAYER && mon->contr->peaceful))
2139 && !on_battleground)) 2094 && !on_battleground))
2095 {
2096 if (op->speed_left > 0.f)
2140 { 2097 {
2098 --op->speed_left;
2099
2141 if (!op->contr->braced) 2100 if (!op->contr->braced)
2142 { 2101 {
2143 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2102 op->play_sound (sound_find ("push_player"));
2144 push_ob (mon, dir, op); 2103 push_ob (mon, dir, op);
2145 } 2104 }
2146 else 2105 else
2147 new_draw_info (0, 0, op, "You withhold your attack"); 2106 op->statusmsg ("You withhold your attack");
2148 2107
2149 if (op->contr->tmp_invis || op->hide) 2108 if (op->contr->tmp_invis || op->hide)
2150 make_visible (op); 2109 make_visible (op);
2151 }
2152 2110
2111 return true;
2112 }
2113 }
2153 /* If the object is a boulder or other rollable object, then 2114 /* If the object is a boulder or other rollable object, then
2154 * roll it if not braced. You can't roll it if you are braced. 2115 * roll it if not braced. You can't roll it if you are braced.
2155 */ 2116 */
2156 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 2117 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced))
2118 {
2119 if (op->speed_left > 0.f)
2157 { 2120 {
2121 --op->speed_left;
2122
2158 recursive_roll (mon, dir, op); 2123 recursive_roll (mon, dir, op);
2159 if (action_makes_visible (op)) 2124 if (action_makes_visible (op))
2160 make_visible (op); 2125 make_visible (op);
2161 }
2162 2126
2127 return true;
2128 }
2129 }
2163 /* Any generic living creature. Including things like doors. 2130 /* Any generic living creature. Including things like doors.
2164 * Way it works is like this: First, it must have some hit points 2131 * Way it works is like this: First, it must have some hit points
2165 * and be living. Then, it must be one of the following: 2132 * and be living. Then, it must be one of the following:
2166 * 1) Not a player, 2) A player, but of a different party. Note 2133 * 1) Not a player, 2) A player, but of a different party. Note
2167 * that party_number -1 is no party, so attacks can still happen. 2134 * that party_number -1 is no party, so attacks can still happen.
2168 */ 2135 */
2169 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2136 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2170 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2137 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2171 { 2138 {
2172 if (!op->contr->has_hit) 2139 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2173 { 2140 {
2174 op->contr->has_hit = 1; 2141 --op->contr->weapon_sp_left;
2175 op->speed_left += op->contr->weapon_sp - op->speed;
2176 }
2177 2142
2178 skill_attack (mon, op, 0, 0, 0); 2143 skill_attack (mon, op, 0, 0, 0);
2179
2180 /* If attacking another player, that player gets automatic
2181 * hitback, and doesn't loose luck either.
2182 * Disable hitback on the battleground or if the target is
2183 * the wiz.
2184 */
2185 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2186 {
2187 short luck = mon->stats.luck;
2188
2189 mon->contr->has_hit = 1;
2190 skill_attack (op, mon, 0, 0, 0);
2191 mon->stats.luck = luck;
2192 }
2193 2144
2194 if (action_makes_visible (op)) 2145 if (action_makes_visible (op))
2195 make_visible (op); 2146 make_visible (op);
2196 }
2197 } /* if player should attack something */
2198}
2199 2147
2200int 2148 return true;
2149 }
2150 }
2151
2152 return false;
2153}
2154
2155bool
2201move_player (object *op, int dir) 2156move_player (object *op, int dir)
2202{ 2157{
2203 int pick; 2158 int pick;
2204 2159
2205 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2160 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2206 return 0; 2161 return 0;
2207 2162
2208 /* Sanity check: make sure dir is valid */ 2163 /* Sanity check: make sure dir is valid */
2209 if ((dir < 0) || (dir >= 9)) 2164 if ((dir < 0) || (dir >= 9))
2210 { 2165 {
2219 op->facing = dir; 2174 op->facing = dir;
2220 2175
2221 if (op->hide) 2176 if (op->hide)
2222 do_hidden_move (op); 2177 do_hidden_move (op);
2223 2178
2179 bool retval;
2180
2224 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2181 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2225 /*nop */ ; 2182 retval = RESULT_INT (0);
2226 else if (op->contr->fire_on) 2183 else if (op->contr->fire_on)
2227 fire (op, dir); 2184 retval = fire (op, dir);
2228 else 2185 else
2229 { 2186 {
2230 move_player_attack (op, dir); 2187 retval = move_player_attack (op, dir);
2231 pick = check_pick (op); 2188 pick = check_pick (op);
2232 } 2189 }
2233 2190
2234 /* Add special check for newcs players and fire on - this way, the 2191 /* Add special check for newcs players and fire on - this way, the
2235 * server can handle repeat firing. 2192 * server can handle repeat firing.
2242 /* Update how the player looks. Use the facing, so direction may 2199 /* Update how the player looks. Use the facing, so direction may
2243 * get reset to zero. This allows for full animation capabilities 2200 * get reset to zero. This allows for full animation capabilities
2244 * for players. 2201 * for players.
2245 */ 2202 */
2246 animate_object (op, op->facing); 2203 animate_object (op, op->facing);
2247 return 0; 2204
2205 return retval;
2248} 2206}
2249 2207
2250/* This is similar to handle_player, below, but is only used by the 2208/* This is similar to handle_player, below, but is only used by the
2251 * new client/server stuff. 2209 * new client/server stuff.
2252 * This is sort of special, in that the new client/server actually uses 2210 * This is sort of special, in that the new client/server actually uses
2253 * the new speed values for commands. 2211 * the new speed values for commands.
2254 * 2212 *
2255 * Returns true if there are more actions we can do. 2213 * Returns true if there are more actions we can do. Should not do
2214 * many actions in a row, as that would be too unfair to other
2215 * players.
2256 */ 2216 */
2257int 2217bool
2258handle_newcs_player (object *op) 2218handle_newcs_player (object *op)
2259{ 2219{
2260 if (QUERY_FLAG (op, FLAG_SCARED)) 2220 if (QUERY_FLAG (op, FLAG_SCARED))
2261 { 2221 {
2262 flee_player (op); 2222 if (op->speed_left > 0.f)
2263
2264 /* If player is still scared, that is his action for this tick */
2265 if (op->flag [FLAG_SCARED])
2266 { 2223 {
2267 --op->speed_left; 2224 --op->speed_left;
2225 flee_player (op);
2226
2268 return 0; 2227 return true;
2269 } 2228 }
2229 else
2230 return false;
2270 } 2231 }
2271 2232
2272 /* call this here - we also will call this in do_ericserver, but 2233 /* call this here - we also will call this in do_ericserver, but
2273 * the players time has been increased when doericserver has been 2234 * the players time has been increased when doericserver has been
2274 * called, so we recheck it here. 2235 * called, so we recheck it here.
2275 */ 2236 */
2276 if (op->contr->ns->handle_command ()) 2237 if (op->contr->ns->handle_command ())
2277 return 1; 2238 return true;
2278 2239
2279 if (op->speed_left > 0.f)
2280 {
2281 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2240 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2282 {
2283 /* All move commands take 1 tick, at least for now */
2284 --op->speed_left;
2285
2286 /* Instead of all the stuff below, let move_player take care
2287 * of it. Also, some of the skill stuff is only put in
2288 * there, as well as the confusion stuff.
2289 */
2290 move_player (op, op->direction); 2241 return move_player (op, op->direction);
2291 2242
2292 return op->speed_left > 0.f;
2293 }
2294 }
2295
2296 return 0; 2243 return false;
2297} 2244}
2298 2245
2299int 2246int
2300save_life (object *op) 2247save_life (object *op)
2301{ 2248{
2303 return 0; 2250 return 0;
2304 2251
2305 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2252 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2306 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2253 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2307 { 2254 {
2308 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2255 op->play_sound (sound_find ("ob_evaporate"));
2309 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));
2310
2311 if (op->contr)
2312 esrv_del_item (op->contr, tmp->count);
2313 2257
2314 tmp->destroy (); 2258 tmp->destroy ();
2315 CLEAR_FLAG (op, FLAG_LIFESAVE); 2259 CLEAR_FLAG (op, FLAG_LIFESAVE);
2316 2260
2317 if (op->stats.hp < 0) 2261 if (op->stats.hp < 0)
2330 return 0; 2274 return 0;
2331} 2275}
2332 2276
2333/* 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
2334 * 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
2335 * 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
2336 * from. 2280 * from.
2337 */ 2281 */
2282static void
2283drop_unpaid_items (object *op, object *env)
2284{
2285 while (op)
2286 {
2287 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2288
2289 if (QUERY_FLAG (op, FLAG_UNPAID))
2290 op->insert_at (env);
2291 else if (op->inv)
2292 drop_unpaid_items (op->inv, env);
2293
2294 op = next;
2295 }
2296}
2297
2338void 2298void
2339remove_unpaid_objects (object *op, object *env) 2299object::drop_unpaid_items ()
2340{ 2300{
2341 while (op) 2301 if (!flag [FLAG_REMOVED])
2342 { 2302 ::drop_unpaid_items (inv, this);
2343 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2344
2345 if (QUERY_FLAG (op, FLAG_UNPAID))
2346 {
2347 if (env->type == PLAYER)
2348 esrv_del_item (env->contr, op->count);
2349
2350 op->insert_at (env);
2351 }
2352 else if (op->inv)
2353 remove_unpaid_objects (op->inv, env);
2354
2355 op = next;
2356 }
2357} 2303}
2358 2304
2359/* 2305/*
2360 * Returns pointer a static string containing gravestone text 2306 * Returns pointer a static string containing gravestone text
2361 * Moved from apply.c to player.c - player.c is what 2307 * Moved from apply.c to player.c - player.c is what
2362 * actually uses this function. player.c may not be quite the 2308 * actually uses this function. player.c may not be quite the
2363 * best, a misc file for object actions is probably better, 2309 * best, a misc file for object actions is probably better,
2364 * but there isn't one in the server directory. 2310 * but there isn't one in the server directory.
2365 */ 2311 */
2366char * 2312const char *
2367gravestone_text (object *op) 2313gravestone_text (object *op)
2368{ 2314{
2369 static char buf2[MAX_BUF]; 2315 static dynbuf_text buf;
2370 char buf[MAX_BUF];
2371 time_t now = time (NULL);
2372 2316
2373 strcpy (buf2, " R.I.P.\n\n"); 2317 buf << "---- R.I.P. ----\n\n";
2318 op->name;
2319
2374 if (op->type == PLAYER) 2320 if (op->type == PLAYER)
2375 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2321 buf << " the " << op->contr->title;
2376 else
2377 sprintf (buf, "%s\n", &op->name);
2378 2322
2379 strncat (buf2, " ", 20 - strlen (buf) / 2); 2323 buf << "\n\n";
2380 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
2381 if (op->type == PLAYER) 2329 if (op->type == PLAYER)
2382 sprintf (buf, "who was in level %d when killed\n", op->level); 2330 buf << "by " << op->contr->killer_name () << ".\n\n";
2383 else
2384 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2385 2331
2386 strncat (buf2, " ", 20 - strlen (buf) / 2);
2387 strcat (buf2, buf);
2388 if (op->type == PLAYER)
2389 { 2332 {
2390 sprintf (buf, "by %s.\n\n", op->contr->killer); 2333 static char buf2[128];
2391 strncat (buf2, " ", 21 - strlen (buf) / 2); 2334 time_t now = time (NULL);
2392 strcat (buf2, buf);
2393 }
2394
2395 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2335 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2396 strncat (buf2, " ", 20 - strlen (buf) / 2); 2336 buf << buf2;
2397 strcat (buf2, buf); 2337 }
2398 2338
2399 return buf2; 2339 return buf;
2400} 2340}
2401 2341
2402void 2342void
2403do_some_living (object *op) 2343do_some_living (object *op)
2404{ 2344{
2456 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace; 2396 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace;
2457 else 2397 else
2458 { 2398 {
2459 gen_grace = op->stats.maxgrace; 2399 gen_grace = op->stats.maxgrace;
2460 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2400 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2461 }
2462
2463 /* Regenerate Spell Points */
2464 if (!op->contr->golem && --op->last_sp < 0)
2465 {
2466 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2467 if (op->stats.sp < op->stats.maxsp)
2468 {
2469 op->stats.sp++;
2470 /* dms do not consume food */
2471 if (!QUERY_FLAG (op, FLAG_WIZ))
2472 {
2473 op->stats.food--;
2474 if (op->contr->digestion < 0)
2475 op->stats.food += op->contr->digestion;
2476 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2477 op->stats.food = last_food;
2478 }
2479 }
2480
2481 if (max_sp > 1)
2482 {
2483 over_sp = (gen_sp + 10) / rate_sp;
2484 if (over_sp > 0)
2485 {
2486 if (op->stats.sp < op->stats.maxsp)
2487 {
2488 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2489
2490 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2491 op->stats.sp--;
2492
2493 if (op->stats.sp > op->stats.maxsp)
2494 op->stats.sp = op->stats.maxsp;
2495 }
2496 op->last_sp = 0;
2497 }
2498 else
2499 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2500 }
2501 else
2502 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2503 } 2401 }
2504 2402
2505 /* Regenerate Grace */ 2403 /* Regenerate Grace */
2506 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ 2404 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */
2507 if (--op->last_grace < 0) 2405 if (--op->last_grace < 0)
2528 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); 2426 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10);
2529 } 2427 }
2530 /* wearing stuff doesn't detract from grace generation. */ 2428 /* wearing stuff doesn't detract from grace generation. */
2531 } 2429 }
2532 2430
2431 if (op->stats.food > 0)
2432 {
2533 /* Regenerate Hit Points */ 2433 /* Regenerate Spell Points */
2534 if (--op->last_heal < 0) 2434 if (!op->contr->golem && --op->last_sp < 0)
2535 {
2536 if (op->stats.hp < op->stats.maxhp)
2537 { 2435 {
2538 op->stats.hp++; 2436 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2539 /* dms do not consume food */ 2437
2540 if (!QUERY_FLAG (op, FLAG_WIZ)) 2438 if (op->stats.sp < op->stats.maxsp)
2541 { 2439 {
2440 op->stats.sp++;
2441
2442 /* dms do not consume food */
2443 if (!QUERY_FLAG (op, FLAG_WIZ))
2444 {
2542 op->stats.food--; 2445 op->stats.food--;
2446
2543 if (op->contr->digestion < 0) 2447 if (op->contr->digestion < 0)
2544 op->stats.food += op->contr->digestion; 2448 op->stats.food += op->contr->digestion;
2545 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2449 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2546 op->stats.food = last_food; 2450 op->stats.food = last_food;
2451 }
2547 } 2452 }
2548 }
2549 2453
2550 if (max_hp > 1) 2454 if (max_sp > 1)
2551 {
2552 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2553 if (over_hp > 0)
2554 { 2455 {
2555 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2456 over_sp = (gen_sp + 10) / rate_sp;
2457 if (over_sp > 0)
2458 {
2459 if (op->stats.sp < op->stats.maxsp)
2460 {
2461 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2462
2463 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2464 op->stats.sp--;
2465
2466 if (op->stats.sp > op->stats.maxsp)
2467 op->stats.sp = op->stats.maxsp;
2468 }
2469
2556 op->last_heal = 0; 2470 op->last_sp = 0;
2471 }
2472 else
2473 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2557 } 2474 }
2558 else 2475 else
2476 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2477 }
2478
2479 /* Regenerate Hit Points */
2480 if (--op->last_heal < 0)
2481 {
2482 if (op->stats.hp < op->stats.maxhp)
2559 { 2483 {
2560 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2484 op->stats.hp++;
2485
2486 /* dms do not consume food */
2487 if (!QUERY_FLAG (op, FLAG_WIZ))
2488 {
2489 op->stats.food--;
2490
2491 if (op->contr->digestion < 0)
2492 op->stats.food += op->contr->digestion;
2493 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2494 op->stats.food = last_food;
2495 }
2561 } 2496 }
2497
2498 if (max_hp > 1)
2499 {
2500 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2501
2502 if (over_hp > 0)
2503 {
2504 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2505 op->last_heal = 0;
2506 }
2507 else
2508 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2562 } 2509 }
2563 else 2510 else
2564 {
2565 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2511 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2566 } 2512 }
2567 } 2513 }
2568 2514
2569 /* Digestion */ 2515 /* Digestion */
2570 if (--op->last_eat < 0) 2516 if (--op->last_eat < 0)
2571 { 2517 {
2572 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; 2518 int bonus = max (0, op->contr->digestion),
2519 penalty = max (0, -op->contr->digestion);
2573 2520
2574 if (op->contr->gen_hp > 0)
2575 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); 2521 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2576 else
2577 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2578 2522
2579 /* dms do not consume food */ 2523 /* dms do not consume food */
2580 if (!QUERY_FLAG (op, FLAG_WIZ)) 2524 if (!QUERY_FLAG (op, FLAG_WIZ))
2581 op->stats.food--; 2525 op->stats.food--;
2582 } 2526 }
2583 2527
2584 if (op->stats.food < 0 && op->stats.hp >= 0) 2528 if (op->stats.food < 0 && op->stats.hp >= 0)
2585 { 2529 {
2586 object *tmp, *flesh = 0; 2530 object *flesh = 0;
2587 2531
2588 for (tmp = op->inv; tmp; tmp = tmp->below) 2532 for_inv_removable (op, tmp)
2589 { 2533 {
2590 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)
2591 { 2538 {
2592 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2539 op->statusmsg ("You blindly grab for a bite of food. "
2593 { 2540 "H<To prevent you from starving, you ate some random item from your backpack.>");
2594 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2595 manual_apply (op, tmp, 0); 2541 manual_apply (op, tmp, 0);
2542
2596 if (op->stats.food >= 0 || op->stats.hp < 0) 2543 if (op->stats.food >= 0 || op->stats.hp < 0)
2597 break; 2544 break;
2598 } 2545 }
2599 else if (tmp->type == FLESH) 2546 else if (tmp->type == FLESH)
2600 flesh = tmp; 2547 flesh = tmp;
2601 } /* End if paid for object */ 2548 }
2602 } /* end of for loop */
2603 2549
2604 /* 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
2605 * eat flesh instead. 2551 * eat flesh instead.
2606 */ 2552 */
2607 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2553 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2608 { 2554 {
2609 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.>");
2610 manual_apply (op, flesh, 0); 2557 manual_apply (op, flesh, 0);
2611 } 2558 }
2559
2560 // If player is still starving, alert him!
2561 if (op->stats.food < 0)
2562 op->failmsg ("You are starving! "
2563 "H<Eat some food to increase your food and prevent you from an untimely death.>");
2564 }
2565
2566 if (op->stats.food < 0)
2612 } 2567 {
2568 op->stats.hp += op->stats.food;
2569 op->stats.food = 0;
2613 2570
2614 while (op->stats.food < 0 && op->stats.hp >= 0) 2571 if (op->stats.hp < 0)
2615 op->stats.food++, op->stats.hp--; 2572 {
2573 op->contr->killer = archetype::get ("killer_starvation");
2574 op->contr->killer->destroy ();
2575 }
2576 }
2616 2577
2578 /* killer should be set here already */
2617 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2579 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2618 kill_player (op); 2580 kill_player (op);
2619 } 2581 }
2620} 2582}
2621 2583
2625 * file. 2587 * file.
2626 */ 2588 */
2627void 2589void
2628kill_player (object *op) 2590kill_player (object *op)
2629{ 2591{
2592 int x, y;
2630 char buf[MAX_BUF]; 2593 char buf[MAX_BUF];
2631 int x, y;
2632
2633 //int i;
2634 maptile *map; /* this is for resurrection */ 2594 maptile *map; /* this is for resurrection */
2635
2636 /* int z;
2637 int num_stats_lose;
2638 int lost_a_stat;
2639 int lose_this_stat;
2640 int this_stat; */
2641 int will_kill_again; 2595 int will_kill_again;
2642 archetype *at; 2596 archetype *at;
2643 object *tmp; 2597 object *tmp;
2644 2598
2645 if (save_life (op)) 2599 if (save_life (op))
2646 return; 2600 return;
2647
2648 2601
2649 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2602 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
2650 * in cities ONLY!!! It is very important that this doesn't get abused. 2603 * in cities ONLY!!! It is very important that this doesn't get abused.
2651 * Look at op_on_battleground() for more info --AndreasV 2604 * Look at op_on_battleground() for more info --AndreasV
2652 */ 2605 */
2668 { 2621 {
2669 tmp->destroy (); 2622 tmp->destroy ();
2670 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2623 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2671 } 2624 }
2672 2625
2673 cure_disease (op, 0); /* remove any disease */ 2626 cure_disease (op, 0, 0); /* remove any disease */
2674 op->stats.hp = op->stats.maxhp; 2627 op->stats.hp = op->stats.maxhp;
2675 if (op->stats.food <= 0) 2628 if (op->stats.food <= 0)
2676 op->stats.food = 999; 2629 op->stats.food = 999;
2677 2630
2678 /* create a bodypart-trophy to make the winner happy */ 2631 /* create a bodypart-trophy to make the winner happy */
2679 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2632 if (object *tmp = arch_to_object (archetype::find ("finger")))
2680 { 2633 {
2681 sprintf (buf, "%s's finger", &op->name); 2634 tmp->name = format ("%s's finger" , &op->name);
2682 tmp->name = buf; 2635 tmp->name_pl = format ("%s's fingers", &op->name);
2683 sprintf (buf, " This finger has been cut off %s\n"
2684 " the %s, when he was defeated at\n level %d by %s.\n",
2685 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2686 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 );
2687 tmp->value = 0, tmp->type = 0; 2642 tmp->value = 0, tmp->type = 0;
2688 tmp->materialname = "organics"; 2643 tmp->materialname = "organics";
2689 tmp->insert_at (op, tmp); 2644 tmp->insert_at (op, tmp);
2690 } 2645 }
2691 2646
2697 2652
2698 INVOKE_PLAYER (DEATH, op->contr); 2653 INVOKE_PLAYER (DEATH, op->contr);
2699 2654
2700 command_kill_pets (op, 0); 2655 command_kill_pets (op, 0);
2701 2656
2702 if (op->stats.food < 0) 2657 op->contr->play_sound (sound_find ("player_dies"));
2703 {
2704 sprintf (buf, "%s starved to death.", &op->name);
2705 strcpy (op->contr->killer, "starvation");
2706 }
2707 else
2708 sprintf (buf, "%s died.", &op->name);
2709
2710 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2711 2658
2712 /* save the map location for corpse, gravestone */ 2659 /* save the map location for corpse, gravestone */
2713 x = op->x; 2660 x = op->x;
2714 y = op->y; 2661 y = op->y;
2715 map = op->map; 2662 map = op->map;
2822 lost_a_stat = 1; 2769 lost_a_stat = 1;
2823 } 2770 }
2824 } 2771 }
2825 } 2772 }
2826 } 2773 }
2774
2827 /* If no stat lost, tell the player. */ 2775 /* If no stat lost, tell the player. */
2828 if (!lost_a_stat) 2776 if (!lost_a_stat)
2829 { 2777 {
2830 /* determine_god() seems to not work sometimes... why is this? 2778 /* determine_god() seems to not work sometimes... why is this?
2831 Should I be using something else? GD */ 2779 Should I be using something else? GD */
2835 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);
2836 else 2784 else
2837 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.");
2838 } 2786 }
2839#else 2787#else
2840 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.");
2841#endif 2789#endif
2842 2790
2843 /* Put a gravestone up where the character 'almost' died. List the 2791 /* Put a gravestone up where the character 'almost' died. List the
2844 * exp loss on the stone. 2792 * exp loss on the stone.
2845 */ 2793 */
2846 tmp = arch_to_object (archetype::find ("gravestone")); 2794 tmp = arch_to_object (archetype::find ("gravestone"));
2847 sprintf (buf, "%s's gravestone", &op->name); 2795 tmp->name = format ("%s's gravestone", &op->name);
2848 tmp->name = buf; 2796 tmp->name_pl = format ("%s's gravestones", &op->name);
2849 sprintf (buf, "%s's gravestones", &op->name);
2850 tmp->name_pl = buf;
2851 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 ());
2852 tmp->msg = buf;
2853 tmp->x = op->x, tmp->y = op->y; 2798 tmp->x = op->x, tmp->y = op->y;
2854 insert_ob_in_map (tmp, op->map, NULL, 0); 2799 insert_ob_in_map (tmp, op->map, NULL, 0);
2855 2800
2856 /**************************************/ 2801 /**************************************/
2857 /* */ 2802 /* */
2878 { 2823 {
2879 tmp->destroy (); 2824 tmp->destroy ();
2880 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2825 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2881 } 2826 }
2882 2827
2883 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 }
2884 2841
2885 /*add_exp(op, (op->stats.exp * -0.20)); */ 2842 /*add_exp(op, (op->stats.exp * -0.20)); */
2886 apply_death_exp_penalty (op); 2843 apply_death_exp_penalty (op);
2844
2887 if (op->stats.food < 100) 2845 if (op->stats.food < 100)
2888 op->stats.food = 900; 2846 op->stats.food = 900;
2847
2889 op->stats.hp = op->stats.maxhp; 2848 op->stats.hp = op->stats.maxhp;
2890 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2849 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2891 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2850 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2892 2851
2893 /* 2852 /*
2894 * Check to see if the player has any unpaid items. If so, remove them 2853 * Check to see if the player has any unpaid items. If so, remove them
2895 * and put them back in the map. 2854 * and put them back in the map.
2896 */ 2855 */
2897 remove_unpaid_objects (op->inv, op); 2856 op->drop_unpaid_items ();
2898 2857
2899 /****************************************/ 2858 /****************************************/
2900 /* */ 2859 /* */
2901 /* Move player to his current respawn- */ 2860 /* Move player to his current respawn- */
2902 /* position (usually last savebed) */ 2861 /* position (usually last savebed) */
2961 2920
2962 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))))
2963 { 2922 {
2964 if (tmp->nrof > 1) 2923 if (tmp->nrof > 1)
2965 { 2924 {
2966 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2925 tmp->decrease (rndm (1, tmp->nrof - 1));
2967 tmp2->destroy ();
2968 insert_ob_in_map (tmp, op->map, NULL, 0); 2926 insert_ob_in_map (tmp, op->map, NULL, 0);
2969 } 2927 }
2970 else 2928 else
2971 tmp->destroy (); 2929 tmp->destroy ();
2972 } 2930 }
2983void 2941void
2984fix_weight (void) 2942fix_weight (void)
2985{ 2943{
2986 for_all_players (pl) 2944 for_all_players (pl)
2987 { 2945 {
2988 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2946 sint32 old = pl->ob->carrying;
2989 2947
2990 if (old == sum) 2948 pl->ob->update_weight ();
2991 continue; 2949
2950 if (old != pl->ob->carrying)
2951 {
2992 pl->ob->update_stats (); 2952 pl->ob->update_stats ();
2993 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 }
2994 } 2955 }
2995} 2956}
2996 2957
2997void 2958void
2998fix_luck (void) 2959fix_luck (void)
3042void 3003void
3043make_visible (object *op) 3004make_visible (object *op)
3044{ 3005{
3045 op->hide = 0; 3006 op->hide = 0;
3046 op->invisible = 0; 3007 op->invisible = 0;
3008
3047 if (op->type == PLAYER) 3009 if (op->type == PLAYER)
3048 { 3010 {
3049 op->contr->tmp_invis = 0; 3011 op->contr->tmp_invis = 0;
3050 op->contr->invis_race = 0; 3012 op->contr->invis_race = 0;
3051 } 3013 }
3054} 3016}
3055 3017
3056int 3018int
3057is_true_undead (object *op) 3019is_true_undead (object *op)
3058{ 3020{
3059 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3021 if (QUERY_FLAG (op->arch, FLAG_UNDEAD))
3060 return 1; 3022 return 1;
3061 3023
3062 return 0; 3024 return 0;
3063} 3025}
3064 3026
3065/* look at the surrounding terrain to determine 3027/* look at the surrounding terrain to determine
3066 * the hideability of this object. Positive levels 3028 * the hideability of this object. Positive levels
3067 * indicate greater hideability. 3029 * indicate greater hideability.
3068 */ 3030 */
3069
3070int 3031int
3071hideability (object *ob) 3032hideability (object *ob)
3072{ 3033{
3073 int i, level = 0, mflag; 3034 int i, level = 0, mflag;
3074 sint16 x, y; 3035 sint16 x, y;
3084 * as bad as carrying a light on a pitch dark map */ 3045 * as bad as carrying a light on a pitch dark map */
3085 if (has_carried_lights (ob)) 3046 if (has_carried_lights (ob))
3086 level = -(10 + (2 * ob->map->darkness)); 3047 level = -(10 + (2 * ob->map->darkness));
3087 3048
3088 /* scan through all nearby squares for terrain to hide in */ 3049 /* scan through all nearby squares for terrain to hide in */
3089 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])
3090 { 3053 {
3091 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3054 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3092 if (mflag & P_OUT_OF_MAP) 3055 if (mflag & P_OUT_OF_MAP)
3093 {
3094 continue; 3056 continue;
3095 } 3057
3096 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3058 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3097 level += 2; 3059 level += 2;
3098 else /* open terrain! */ 3060 else /* open terrain! */
3099 level -= 1; 3061 level -= 1;
3100 } 3062 }
3108/* For Hidden creatures - a chance of becoming 'unhidden' 3070/* For Hidden creatures - a chance of becoming 'unhidden'
3109 * every time they move - as we subtract off 'invisibility' 3071 * every time they move - as we subtract off 'invisibility'
3110 * AND, for players, if they move into a ridiculously unhideable 3072 * AND, for players, if they move into a ridiculously unhideable
3111 * spot (surrounded by clear terrain in broad daylight). -b.t. 3073 * spot (surrounded by clear terrain in broad daylight). -b.t.
3112 */ 3074 */
3113
3114void 3075void
3115do_hidden_move (object *op) 3076do_hidden_move (object *op)
3116{ 3077{
3117 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3078 int hide = 0;
3118 object *skop;
3119 3079
3120 if (!op || !op->map) 3080 if (!op || !op->map)
3121 return; 3081 return;
3122 3082
3123 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);
3124 3085
3125 /* 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! */
3126 if (op->type == PLAYER && op->contr->run_on) 3087 if (op->type == PLAYER && op->contr->run_on)
3127 if (!skop || num >= skop->level) 3088 if (!skop || num >= skop->level)
3128 { 3089 {
3138 num -= hide; 3099 num -= hide;
3139 3100
3140 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3101 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3141 { 3102 {
3142 make_visible (op); 3103 make_visible (op);
3104
3143 if (op->type == PLAYER) 3105 if (op->type == PLAYER)
3144 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!");
3145 } 3107 }
3146 else if (op->type == PLAYER && skop) 3108 else if (op->type == PLAYER && skop)
3147 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);
3200 * object op. This function works fine for monsters, 3162 * object op. This function works fine for monsters,
3201 * but we dont worry if the object isnt the top one in 3163 * but we dont worry if the object isnt the top one in
3202 * a pile (say a coin under a table would return "viewable" 3164 * a pile (say a coin under a table would return "viewable"
3203 * by this routine). Another question, should we be 3165 * by this routine). Another question, should we be
3204 * concerned with the direction the player is looking 3166 * concerned with the direction the player is looking
3205 * in? Realistically, most of use cant see stuff behind 3167 * in? Realistically, most of us can't see stuff behind
3206 * our backs...on the other hand, does the "facing" direction 3168 * our backs...on the other hand, does the "facing" direction
3207 * imply the way your head, or body is facing? Its possible 3169 * imply the way your head, or body is facing? It's possible
3208 * for them to differ. Sigh, this fctn could get a bit more complex. 3170 * for them to differ. Sigh, this fctn could get a bit more complex.
3209 * -b.t. 3171 * -b.t.
3210 * This function is now map tiling safe. 3172 * This function is now map tiling safe.
3211 */ 3173 */
3212
3213int 3174int
3214player_can_view (object *pl, object *op) 3175player_can_view (object *pl, object *op)
3215{ 3176{
3216 rv_vector rv; 3177 rv_vector rv;
3217 int dx, dy; 3178 int dx, dy;
3229 3190
3230 get_rangevector (pl, op, &rv, 0x1); 3191 get_rangevector (pl, op, &rv, 0x1);
3231 3192
3232 /* starting with the 'head' part, lets loop 3193 /* starting with the 'head' part, lets loop
3233 * through the object and find if it has any 3194 * through the object and find if it has any
3234 * part that is in the los array but isnt on 3195 * part that is in the los array but isn't on
3235 * a blocked los square. 3196 * a blocked los square.
3236 * we use the archetype to figure out offsets. 3197 * we use the archetype to figure out offsets.
3237 */ 3198 */
3238 while (op) 3199 while (op)
3239 { 3200 {
3240 dx = rv.distance_x + op->arch->clone.x; 3201 dx = rv.distance_x + op->arch->x;
3241 dy = rv.distance_y + op->arch->clone.y; 3202 dy = rv.distance_y + op->arch->y;
3242 3203
3243 /* only the viewable area the player sees is updated by LOS 3204 /* only the viewable area the player sees is updated by LOS
3244 * code, so we need to restrict ourselves to that range of values 3205 * code, so we need to restrict ourselves to that range of values
3245 * for any meaningful values. 3206 * for any meaningful values.
3246 */ 3207 */
3247 if (FABS (dx) <= (pl->contr->ns->mapx / 2) && 3208 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3248 FABS (dy) <= (pl->contr->ns->mapy / 2) && 3209 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3249 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)]) 3210 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3250 return 1; 3211 return 1;
3212
3251 op = op->more; 3213 op = op->more;
3252 } 3214 }
3215
3253 return 0; 3216 return 0;
3254} 3217}
3255 3218
3256/* routine for both players and monsters. We call this when 3219/* routine for both players and monsters. We call this when
3257 * there is a possibility for our action distrubing our hiding 3220 * there is a possibility for our action distrubing our hiding
3260 * return 0. 3223 * return 0.
3261 */ 3224 */
3262int 3225int
3263action_makes_visible (object *op) 3226action_makes_visible (object *op)
3264{ 3227{
3265
3266 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3228 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3267 { 3229 {
3268 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3230 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3269 return 0; 3231 return 0;
3270 3232
3276 { 3238 {
3277 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3239 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible");
3278 return 1; 3240 return 1;
3279 } 3241 }
3280 } 3242 }
3243
3281 return 0; 3244 return 0;
3282} 3245}
3283 3246
3284/* op_on_battleground - checks if the given object op (usually 3247/* op_on_battleground - checks if the given object op (usually
3285 * a player) is standing on a valid battleground-tile, 3248 * a player) is standing on a valid battleground-tile,
3290 * Default is to do the same as before, so only people wanting to have different points need worry about this 3253 * Default is to do the same as before, so only people wanting to have different points need worry about this
3291 */ 3254 */
3292int 3255int
3293op_on_battleground (object *op, int *x, int *y) 3256op_on_battleground (object *op, int *x, int *y)
3294{ 3257{
3295 object *tmp;
3296
3297 /* A battleground-tile needs the following attributes to be valid: 3258 /* A battleground-tile needs the following attributes to be valid:
3298 * is_floor 1 (has to be the FIRST floor beneath the player's feet), 3259 * is_floor 1 (has to be the FIRST floor beneath the player's feet),
3299 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND) 3260 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND)
3300 * and the exit-coordinates sp/hp must both be > 0. 3261 * and the exit-coordinates sp/hp must both be > 0.
3301 * => The intention here is to prevent abuse of the battleground- 3262 * => The intention here is to prevent abuse of the battleground-
3302 * feature (like pickable or hidden battleground tiles). */ 3263 * feature (like pickable or hidden battleground tiles). */
3303 for (tmp = op->below; tmp != NULL; tmp = tmp->below) 3264 for (object *tmp = op->below; tmp; tmp = tmp->below)
3304 { 3265 {
3305 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3266 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
3306 { 3267 {
3307 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && 3268 if (QUERY_FLAG (tmp, FLAG_NO_PICK)
3308 strcmp (tmp->name, "battleground") == 0 && tmp->type == BATTLEGROUND && EXIT_X (tmp) && EXIT_Y (tmp)) 3269 && tmp->type == BATTLEGROUND
3270 && tmp->name == shstr_battleground
3271 && EXIT_X (tmp) && EXIT_Y (tmp))
3309 { 3272 {
3310 /*before we assign the exit, check if this is a teambattle */ 3273 /* before we assign the exit, check if this is a teambattle */
3311 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3274 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3312 { 3275 {
3313 object *invtmp;
3314
3315 for (invtmp = op->inv; invtmp != NULL; invtmp = invtmp->below) 3276 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3316 { 3277 {
3317 if (invtmp->type == FORCE && invtmp->slaying && !strcmp (EXIT_PATH (tmp), invtmp->slaying)) 3278 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3318 { 3279 {
3319 if (x != NULL && y != NULL) 3280 if (x && y)
3320 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3281 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3282
3321 return 1; 3283 return 1;
3322 } 3284 }
3323 } 3285 }
3324 } 3286 }
3287
3325 if (x != NULL && y != NULL) 3288 if (x && y)
3326 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3289 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3290
3327 return 1; 3291 return 1;
3328 } 3292 }
3329 } 3293 }
3330 } 3294 }
3295
3331 /* If we got here, did not find a battleground */ 3296 /* If we got here, did not find a battleground */
3332 return 0; 3297 return 0;
3333} 3298}
3334 3299
3335/* 3300/*
3351 char buf[MAX_BUF]; /* tmp. string buffer */ 3316 char buf[MAX_BUF]; /* tmp. string buffer */
3352 int i = 0, j = 0; 3317 int i = 0, j = 0;
3353 3318
3354 /* get the appropriate treasurelist */ 3319 /* get the appropriate treasurelist */
3355 if (atnr == ATNR_FIRE) 3320 if (atnr == ATNR_FIRE)
3356 trlist = treasurelist::find ("dragon_ability_fire"); 3321 trlist = treasurelist::find (shstr_dragon_ability_fire);
3357 else if (atnr == ATNR_COLD) 3322 else if (atnr == ATNR_COLD)
3358 trlist = treasurelist::find ("dragon_ability_cold"); 3323 trlist = treasurelist::find (shstr_dragon_ability_cold);
3359 else if (atnr == ATNR_ELECTRICITY) 3324 else if (atnr == ATNR_ELECTRICITY)
3360 trlist = treasurelist::find ("dragon_ability_elec"); 3325 trlist = treasurelist::find (shstr_dragon_ability_elec);
3361 else if (atnr == ATNR_POISON) 3326 else if (atnr == ATNR_POISON)
3362 trlist = treasurelist::find ("dragon_ability_poison"); 3327 trlist = treasurelist::find (shstr_dragon_ability_poison);
3363 3328
3364 if (trlist == NULL || who->type != PLAYER) 3329 if (trlist == NULL || who->type != PLAYER)
3365 return; 3330 return;
3366 3331
3367 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); 3332 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++);
3371 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ 3336 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
3372 return; 3337 return;
3373 } 3338 }
3374 3339
3375 /* everything seems okay - now bring on the gift: */ 3340 /* everything seems okay - now bring on the gift: */
3376 item = &(tr->item->clone); 3341 item = tr->item;
3377 3342
3378 if (item->type == SPELL) 3343 if (item->type == SPELL)
3379 { 3344 {
3380 if (check_spell_known (who, item->name)) 3345 if (check_spell_known (who, item->name))
3381 return; 3346 return;
3440 { 3405 {
3441 /* forces in the treasurelist can alter the player's stats */ 3406 /* forces in the treasurelist can alter the player's stats */
3442 object *skin; 3407 object *skin;
3443 3408
3444 /* first get the dragon skin force */ 3409 /* first get the dragon skin force */
3445 shstr_cmp dragon_skin_force ("dragon_skin_force");
3446 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below) 3410 for (skin = who->inv; skin && !(skin->arch->archname == shstr_dragon_skin_force); skin = skin->below)
3447 ; 3411 ;
3448 3412
3449 if (!skin) 3413 if (!skin)
3450 return; 3414 return;
3451 3415
3486 else 3450 else
3487 { 3451 {
3488 /* generate misc. treasure */ 3452 /* generate misc. treasure */
3489 tmp = arch_to_object (tr->item); 3453 tmp = arch_to_object (tr->item);
3490 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));
3491 tmp = insert_ob_in_ob (tmp, who); 3455 who->insert (tmp);
3492 if (who->type == PLAYER)
3493 esrv_send_item (who, tmp);
3494 } 3456 }
3495} 3457}
3496 3458
3497/** 3459/**
3498 * 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
3527 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))
3528 return 0; 3490 return 0;
3529 3491
3530 return 100 - blocked_los [x][y]; 3492 return 100 - blocked_los [x][y];
3531} 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