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.140 by root, Fri May 18 13:15:29 2007 UTC vs.
Revision 1.187 by root, Mon Apr 21 07:07:36 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 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>
147 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, 146 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
148 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news); 147 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news);
149 close_and_delete (fp, comp); 148 close_and_delete (fp, comp);
150} 149}
151 150
152float
153player::weapon_speed () const
154{
155 return ob->speed / weapon_sp * .5f;//TODO, the .5 is arbitrary
156}
157
158/* This loads the first map an puts the player on it. */ 151/* This loads the first map an puts the player on it. */
159static void 152static void
160set_first_map (object *op) 153set_first_map (object *op)
161{ 154{
162 op->contr->maplevel = first_map_path; 155 op->contr->maplevel = first_map_path;
163 op->x = -1; 156 op->x = -1;
164 op->y = -1; 157 op->y = -1;
165}
166
167void
168player::enter_map ()
169{
170 object *tmp = object::create ();
171
172 EXIT_PATH (tmp) = maplevel;
173 EXIT_X (tmp) = ob->x;
174 EXIT_Y (tmp) = ob->y;
175 ob->enter_exit (tmp);
176
177 tmp->destroy ();
178} 158}
179 159
180void 160void
181player::activate () 161player::activate ()
182{ 162{
187 ob->remove (); 167 ob->remove ();
188 ob->map = 0; 168 ob->map = 0;
189 ob->activate_recursive (); 169 ob->activate_recursive ();
190 CLEAR_FLAG (ob, FLAG_FRIENDLY); 170 CLEAR_FLAG (ob, FLAG_FRIENDLY);
191 add_friendly_object (ob); 171 add_friendly_object (ob);
192 enter_map ();
193} 172}
194 173
195void 174void
196player::deactivate () 175player::deactivate ()
197{ 176{
204 183
205 if (ob->map) 184 if (ob->map)
206 maplevel = ob->map->path; 185 maplevel = ob->map->path;
207 186
208 ob->remove (); 187 ob->remove ();
188 ob->enemy = 0; // sometimes keeps an extra refcount on itself
209 ob->map = 0; 189 ob->map = 0;
210 party = 0; 190 party = 0;
211 191
212 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this 192 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this
213 193
227 ob->close_container (); //TODO: client-specific 207 ob->close_container (); //TODO: client-specific
228 208
229 ns->update_look = 0; 209 ns->update_look = 0;
230 ns->look_position = 0; 210 ns->look_position = 0;
231 211
232 clear_los (ob); 212 clear_los (this);
233 213
234 ns->reset_stats (); 214 ns->reset_stats ();
235 215
236 /* make sure he's a player -- needed because of class change. */ 216 /* make sure he's a player -- needed because of class change. */
237 ob->type = PLAYER; // we are paranoid 217 ob->type = PLAYER; // we are paranoid
238 ob->race = ob->arch->clone.race; 218 ob->race = ob->arch->race;
239 219
240 ob->carrying = sum_weight (ob); 220 ob->update_weight ();
241 link_player_skills (ob); 221 link_player_skills (ob);
242 222
243 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
244 224
245 assign (title, ob->arch->clone.name); 225 assign (title, ob->arch->object::name);
246 226
247 /* if it's a dragon player, set the correct title here */ 227 /* if it's a dragon player, set the correct title here */
248 if (is_dragon_pl (ob)) 228 if (is_dragon_pl (ob))
249 { 229 {
250 object *tmp, *abil = 0, *skin = 0; 230 object *tmp, *abil = 0, *skin = 0;
251 231
252 shstr_cmp dragon_ability_force ("dragon_ability_force");
253 shstr_cmp dragon_skin_force ("dragon_skin_force");
254
255 for (tmp = ob->inv; tmp; tmp = tmp->below) 232 for (tmp = ob->inv; tmp; tmp = tmp->below)
256 if (tmp->type == FORCE) 233 if (tmp->type == FORCE)
257 if (tmp->arch->name == dragon_ability_force) 234 if (tmp->arch->archname == shstr_dragon_ability_force)
258 abil = tmp; 235 abil = tmp;
259 else if (tmp->arch->name == dragon_skin_force) 236 else if (tmp->arch->archname == shstr_dragon_skin_force)
260 skin = tmp; 237 skin = tmp;
261 238
262 set_dragon_name (ob, abil, skin); 239 set_dragon_name (ob, abil, skin);
263 } 240 }
264 241
265 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
266 243
267 esrv_new_player (this, ob->weight + ob->carrying); 244 esrv_new_player (this, ob->weight + ob->carrying);
245
246 ob->update_stats ();
247
248 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob);
250 esrv_add_spells (this, 0);
251
252 activate ();
253
254 send_rules (ob);
255 send_news (ob);
256 display_motd (ob);
257
258 INVOKE_PLAYER (CONNECT, this);
259 INVOKE_PLAYER (LOGIN, this);
260}
261
262void
263player::disconnect ()
264{
265 if (ob)
266 {
267 ob->close_container (); //TODO: client-specific
268 ob->drop_unpaid_items ();
269 }
270
271 if (ns)
272 {
273 if (active)
274 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
275
276 INVOKE_PLAYER (DISCONNECT, this);
277
278 ns->reset_stats ();
279 ns->pl = 0;
280 ns = 0;
281 }
282
283 observe = ob;
284
285 deactivate ();
286}
287
288// the need for this function can be explained
289// by load_object not returning the object
290void
291player::set_object (object *op)
292{
293 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */
295
296 ob->speed = 1.0f;
297 ob->speed_left = 0.5f;
298
299 ob->direction = 5; /* So player faces south */
268 300
269 ob->flag [FLAG_READY_WEAPON] = false; 301 ob->flag [FLAG_READY_WEAPON] = false;
270 ob->flag [FLAG_READY_SKILL] = false; 302 ob->flag [FLAG_READY_SKILL] = false;
271 ob->flag [FLAG_READY_BOW] = false; 303 ob->flag [FLAG_READY_BOW] = false;
272 304
289 combat_ob = op; 321 combat_ob = op;
290 break; 322 break;
291 } 323 }
292 324
293 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
294 ob->update_stats (); 326 ob->deactivate (); // change_Weapon activates, fix this better
295
296 ns->floorbox_update ();
297 esrv_send_inventory (ob, ob);
298 esrv_add_spells (this, 0);
299
300 activate ();
301
302 send_rules (ob);
303 send_news (ob);
304 display_motd (ob);
305
306 INVOKE_PLAYER (CONNECT, this);
307 INVOKE_PLAYER (LOGIN, this);
308} 327}
309 328
310void 329void
311player::disconnect ()
312{
313 if (ns)
314 {
315 if (active)
316 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
317
318 INVOKE_PLAYER (DISCONNECT, this);
319
320 ns->reset_stats ();
321 ns->pl = 0;
322 ns = 0;
323 }
324
325 if (ob)
326 ob->close_container (); //TODO: client-specific
327
328 deactivate ();
329}
330
331// the need for this function can be explained
332// by load_object not returning the object
333void
334player::set_object (object *op) 330player::set_observe (object *op)
335{ 331{
336 ob = op; 332 observe = op ? op : ob;
337 ob->contr = this; /* this aren't yet in archetype */ 333 do_los = 1;
338
339 ob->speed_left = 0.5f;
340 ob->speed = 1.0f;
341 ob->direction = 5; /* So player faces south */
342} 334}
343 335
344player::player () 336player::player ()
345{ 337{
346 /* There are some elements we want initialised to non zero value - 338 /* There are some elements we want initialised to non zero value -
357 petmode = pet_normal; 349 petmode = pet_normal;
358 listening = 10; 350 listening = 10;
359 usekeys = containers; 351 usekeys = containers;
360 peaceful = 1; /* default peaceful */ 352 peaceful = 1; /* default peaceful */
361 do_los = 1; 353 do_los = 1;
354
355 weapon_sp = 1.0f;
356 weapon_sp_left = 0.5f;
362} 357}
363 358
364void 359void
365player::do_destroy () 360player::do_destroy ()
366{ 361{
371 if (ob) 366 if (ob)
372 { 367 {
373 ob->destroy_inv (false); 368 ob->destroy_inv (false);
374 ob->destroy (); 369 ob->destroy ();
375 } 370 }
371
372 ob = observe = 0;
376} 373}
377 374
378player::~player () 375player::~player ()
379{ 376{
380 /* Clear item stack */ 377 /* Clear item stack */
407 * Note: there MUST be at least one player archetype! 404 * Note: there MUST be at least one player archetype!
408 */ 405 */
409archetype * 406archetype *
410get_player_archetype (archetype *at) 407get_player_archetype (archetype *at)
411{ 408{
412 archetype *start = at; 409 // archetypes could have been reloaded
410 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
411
412 if (!nat)
413 return at;
414
415 archvec::iterator i = archetypes.find (nat);
413 416
414 for (;;) 417 for (;;)
415 { 418 {
416 if (at == NULL || at->next == NULL) 419 if (++i == archetypes.end ())
417 at = first_archetype; 420 i = archetypes.begin ();
418 else 421 else if (*i == at)
419 at = at->next; 422 cleanup ("not a single player archetype found");
420 423
421 if (at->clone.type == PLAYER) 424 if ((*i)->type == PLAYER)
422 return at; 425 return *i;
423
424 if (at == start)
425 {
426 LOG (llevError, "No Player archetypes\n");
427 exit (-1);
428 }
429 } 426 }
430} 427}
431 428
432object * 429object *
433get_nearest_player (object *mon) 430get_nearest_player (object *mon)
437 unsigned lastdist; 434 unsigned lastdist;
438 rv_vector rv; 435 rv_vector rv;
439 436
440 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) 437 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next)
441 { 438 {
442 /* We should not find free objects on this friendly list, but it
443 * does periodically happen. Given that, lets deal with it.
444 * While unlikely, it is possible the next object on the friendly
445 * list is also free, so encapsulate this in a while loop.
446 */
447 while (QUERY_FLAG (ol->ob, FLAG_FREED) || !QUERY_FLAG (ol->ob, FLAG_FRIENDLY))
448 {
449 object *tmp = ol->ob;
450
451 /* Can't do much more other than log the fact, because the object
452 * itself will have been cleared.
453 */
454 LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n",
455 tmp->debug_desc ());
456 ol = ol->next;
457 remove_friendly_object (tmp);
458 if (!ol)
459 return op;
460 }
461
462 /* Remove special check for player from this. First, it looks to cause
463 * some crashes (ol->ob->contr not set properly?), but secondly, a more
464 * complicated method of state checking would be needed in any case -
465 * as it was, a clever player could type quit, and the function would
466 * skip them over while waiting for confirmation. Remove
467 * on_same_map check, as can_detect_enemy also does this
468 */
469 if (!can_detect_enemy (mon, ol->ob, &rv)) 439 if (!can_detect_enemy (mon, ol->ob, &rv))
470 continue; 440 continue;
471 441
472 if (lastdist > rv.distance) 442 if (lastdist > rv.distance)
473 { 443 {
668 638
669 return firstdir; 639 return firstdir;
670} 640}
671 641
672void 642void
673give_initial_items (object *pl, treasurelist * items) 643give_initial_items (object *pl, treasurelist *items)
674{ 644{
675 object *op, *next = NULL;
676
677 if (pl->randomitems != NULL) 645 if (pl->randomitems)
678 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
679 647
680 for (op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
681 { 649 {
682 next = op->below; 650 next = op->below;
683 651
684 /* Forces get applied per default, unless they have the 652 /* Forces get applied per default, unless they have the
685 * flag "neutral" set. Sorry but I can't think of a better way 653 * flag "neutral" set. Sorry but I can't think of a better way
690 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
691 * by this player due to race restrictions 659 * by this player due to race restrictions
692 */ 660 */
693 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
694 { 662 {
695 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
696 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
697 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
698 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
699 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 669 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
700 { 670 {
701 op->destroy (); 671 op->destroy ();
702 continue; 672 continue;
703 } 673 }
704 } 674 }
727 if (op->nrof > 1) 697 if (op->nrof > 1)
728 op->nrof = 1; 698 op->nrof = 1;
729 } 699 }
730 700
731 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
732 {
733 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
734 }
735 703
736 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
737 * items. Just don't identify gold or silver, or it won't be 705 * items. Just don't identify gold or silver, or it won't be
738 * merged properly. 706 * merged properly.
739 */ 707 */
740 if (need_identify (op)) 708 if (need_identify (op))
741 { 709 {
742 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
743 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
744 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
745 } 713 }
714
746 if (op->type == SPELL) 715 if (op->type == SPELL)
747 { 716 {
748 op->destroy (); 717 op->destroy ();
749 continue; 718 continue;
750 } 719 }
752 { 721 {
753 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
754 op->stats.exp = 0; 723 op->stats.exp = 0;
755 op->level = 1; 724 op->level = 1;
756 } 725 }
757 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
758 else
759 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
760 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
761 729
762 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
763 link_player_skills (pl); 731 link_player_skills (pl);
869static void 837static void
870start_info (object *op) 838start_info (object *op)
871{ 839{
872 char buf[MAX_BUF]; 840 char buf[MAX_BUF];
873 841
874 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 842 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
875 new_draw_info (NDI_UNIQUE, 0, op, buf); 843 new_draw_info (NDI_UNIQUE, 0, op, buf);
876 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
877 //new_draw_info (NDI_UNIQUE, 0, op, " ");
878} 844}
879 845
880/* This function takes the key that is passed, and does the 846/* This function takes the key that is passed, and does the
881 * appropriate action with it (change race, or other things). 847 * appropriate action with it (change race, or other things).
882 * The function name is for historical reasons - now we have 848 * The function name is for historical reasons - now we have
923 if (*first_map_ext_path) 889 if (*first_map_ext_path)
924 { 890 {
925 object *tmp; 891 object *tmp;
926 char mapname[MAX_BUF]; 892 char mapname[MAX_BUF];
927 893
928 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name); 894 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->archname);
929 tmp = object::create (); 895 tmp = object::create ();
930 EXIT_PATH (tmp) = mapname; 896 EXIT_PATH (tmp) = mapname;
931 EXIT_X (tmp) = ob->x; 897 EXIT_X (tmp) = ob->x;
932 EXIT_Y (tmp) = ob->y; 898 EXIT_Y (tmp) = ob->y;
933 ob->enter_exit (tmp); /* we don't really care if it succeeded; 899 ob->enter_exit (tmp); /* we don't really care if it succeeded;
952 int x = ob->x, y = ob->y; 918 int x = ob->x, y = ob->y;
953 919
954 ob->remove_statbonus (); 920 ob->remove_statbonus ();
955 ob->remove (); 921 ob->remove ();
956 ob->arch = get_player_archetype (ob->arch); 922 ob->arch = get_player_archetype (ob->arch);
957 ob->arch->clone.copy_to (ob); 923 ob->arch->copy_to (ob);
958 ob->instantiate (); 924 ob->instantiate ();
959 ob->stats = ob->contr->orig_stats; 925 ob->stats = ob->contr->orig_stats;
960 ob->name = ob->name_pl = name; 926 ob->name = ob->name_pl = name;
961 ob->x = x; 927 ob->x = x;
962 ob->y = y; 928 ob->y = y;
963 SET_ANIMATION (ob, 2); /* So player faces south */ 929 SET_ANIMATION (ob, 2); /* So player faces south */
964 insert_ob_in_map (ob, ob->map, ob, 0); 930 insert_ob_in_map (ob, ob->map, ob, 0);
965 assign (ob->contr->title, ob->arch->clone.name); 931 assign (ob->contr->title, ob->arch->object::name);
966 ob->add_statbonus (); 932 ob->add_statbonus ();
967 } 933 }
968 while (!allowed_class (ob)); 934 while (!allowed_class (ob));
969 935
970 update_object (ob, UP_OBJ_FACE); 936 update_object (ob, UP_OBJ_FACE);
1045 if (op->move_type & MOVE_FLYING) 1011 if (op->move_type & MOVE_FLYING)
1046 return 1; 1012 return 1;
1047 1013
1048 next = op->below; 1014 next = op->below;
1049 1015
1016 int cnt = MAX_ITEM_PER_DROP;
1017#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
1018
1050 /* loop while there are items on the floor that are not marked as 1019 /* loop while there are items on the floor that are not marked as
1051 * destroyed */ 1020 * destroyed */
1052 while (next && !next->destroyed ()) 1021 while (next && !next->destroyed ())
1053 { 1022 {
1054 tmp = next; 1023 tmp = next;
1055 next = tmp->below; 1024 next = tmp->below;
1056 1025
1026 if (cnt <= 0)
1027 {
1028 op->failmsg ("Couldn't pickup all items at once.");
1029 return 0;
1030 }
1031
1057 if (op->destroyed ()) 1032 if (op->destroyed ())
1058 return 0; 1033 return 0;
1059 1034
1060 if (!can_pick (op, tmp)) 1035 if (!can_pick (op, tmp))
1061 continue; 1036 continue;
1062 1037
1063 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1064 { 1039 {
1065 if (item_matched_string (op, tmp, op->contr->search_str)) 1040 if (item_matched_string (op, tmp, op->contr->search_str))
1066 pick_up (op, tmp); 1041 CHK_PICK_PICKUP;
1067 continue; 1042 continue;
1068 } 1043 }
1069 1044
1070 /* high not bit set? We're using the old autopickup model */ 1045 /* high not bit set? We're using the old autopickup model */
1071 if (!(op->contr->mode & PU_NEWMODE)) 1046 if (!(op->contr->mode & PU_NEWMODE))
1073 switch (op->contr->mode) 1048 switch (op->contr->mode)
1074 { 1049 {
1075 case 0: 1050 case 0:
1076 return 1; /* don't pick up */ 1051 return 1; /* don't pick up */
1077 case 1: 1052 case 1:
1078 pick_up (op, tmp); 1053 CHK_PICK_PICKUP;
1079 return 1; 1054 return 1;
1080 case 2: 1055 case 2:
1081 pick_up (op, tmp); 1056 CHK_PICK_PICKUP;
1082 return 0; 1057 return 0;
1083 case 3: 1058 case 3:
1084 return 0; /* stop before pickup */ 1059 return 0; /* stop before pickup */
1085 case 4: 1060 case 4:
1086 pick_up (op, tmp); 1061 CHK_PICK_PICKUP;
1087 break; 1062 break;
1088 case 5: 1063 case 5:
1089 pick_up (op, tmp); 1064 CHK_PICK_PICKUP;
1090 stop = 1; 1065 stop = 1;
1091 break; 1066 break;
1092 case 6: 1067 case 6:
1093 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1068 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1094 pick_up (op, tmp); 1069 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1070 CHK_PICK_PICKUP;
1095 break; 1071 break;
1096 1072
1097 case 7: 1073 case 7:
1098 if (tmp->type == MONEY || tmp->type == GEM) 1074 if (tmp->type == MONEY || tmp->type == GEM)
1099 pick_up (op, tmp); 1075 CHK_PICK_PICKUP;
1100 break; 1076 break;
1101 1077
1102 default: 1078 default:
1103 /* use value density */ 1079 /* use value density */
1104 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1080 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1105 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1081 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1106 pick_up (op, tmp); 1082 CHK_PICK_PICKUP;
1107 } 1083 }
1108 } 1084 }
1109 else 1085 else
1110 { /* old model */ 1086 { /* old model */
1111 /* NEW pickup handling */ 1087 /* NEW pickup handling */
1115 if (tmp->name != NULL) 1091 if (tmp->name != NULL)
1116 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1092 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1117 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1093 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1118 else 1094 else
1119 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1095 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1120 &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1096 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1121 1097
1122 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1098 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1123 } 1099 }
1124 1100
1125 /* philosophy: 1101 /* philosophy:
1166 /* all food and drink if desired */ 1142 /* all food and drink if desired */
1167 /* question: don't pick up known-poisonous stuff? */ 1143 /* question: don't pick up known-poisonous stuff? */
1168 if (op->contr->mode & PU_FOOD) 1144 if (op->contr->mode & PU_FOOD)
1169 if (tmp->type == FOOD) 1145 if (tmp->type == FOOD)
1170 { 1146 {
1171 pick_up (op, tmp); 1147 CHK_PICK_PICKUP;
1172 continue; 1148 continue;
1173 } 1149 }
1174 1150
1175 if (op->contr->mode & PU_DRINK) 1151 if (op->contr->mode & PU_DRINK)
1176 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1152 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1177 { 1153 {
1178 pick_up (op, tmp); 1154 CHK_PICK_PICKUP;
1179 continue; 1155 continue;
1180 } 1156 }
1181 1157
1182 if (op->contr->mode & PU_POTION) 1158 if (op->contr->mode & PU_POTION)
1183 if (tmp->type == POTION) 1159 if (tmp->type == POTION)
1184 { 1160 {
1185 pick_up (op, tmp); 1161 CHK_PICK_PICKUP;
1186 continue; 1162 continue;
1187 } 1163 }
1188 1164
1189 /* spellbooks, skillscrolls and normal books/scrolls */ 1165 /* spellbooks, skillscrolls and normal books/scrolls */
1190 if (op->contr->mode & PU_SPELLBOOK) 1166 if (op->contr->mode & PU_SPELLBOOK)
1191 if (tmp->type == SPELLBOOK) 1167 if (tmp->type == SPELLBOOK)
1192 { 1168 {
1193 pick_up (op, tmp); 1169 CHK_PICK_PICKUP;
1194 continue; 1170 continue;
1195 } 1171 }
1196 1172
1197 if (op->contr->mode & PU_SKILLSCROLL) 1173 if (op->contr->mode & PU_SKILLSCROLL)
1198 if (tmp->type == SKILLSCROLL) 1174 if (tmp->type == SKILLSCROLL)
1199 { 1175 {
1200 pick_up (op, tmp); 1176 CHK_PICK_PICKUP;
1201 continue; 1177 continue;
1202 } 1178 }
1203 1179
1204 if (op->contr->mode & PU_READABLES) 1180 if (op->contr->mode & PU_READABLES)
1205 if (tmp->type == BOOK || tmp->type == SCROLL) 1181 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1206 { 1182 {
1207 pick_up (op, tmp); 1183 CHK_PICK_PICKUP;
1208 continue; 1184 continue;
1209 } 1185 }
1210 1186
1211 /* wands/staves/rods/horns */ 1187 /* wands/staves/rods/horns */
1212 if (op->contr->mode & PU_MAGIC_DEVICE) 1188 if (op->contr->mode & PU_MAGIC_DEVICE)
1213 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1189 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1214 { 1190 {
1215 pick_up (op, tmp); 1191 CHK_PICK_PICKUP;
1216 continue; 1192 continue;
1217 } 1193 }
1218 1194
1219 /* pick up all magical items */ 1195 /* pick up all magical items */
1220 if (op->contr->mode & PU_MAGICAL) 1196 if (op->contr->mode & PU_MAGICAL)
1221 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1197 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1222 { 1198 {
1223 pick_up (op, tmp); 1199 CHK_PICK_PICKUP;
1224 continue; 1200 continue;
1225 } 1201 }
1226 1202
1227 if (op->contr->mode & PU_VALUABLES) 1203 if (op->contr->mode & PU_VALUABLES)
1228 { 1204 {
1229 if (tmp->type == MONEY || tmp->type == GEM) 1205 if (tmp->type == MONEY || tmp->type == GEM)
1230 { 1206 {
1231 pick_up (op, tmp); 1207 CHK_PICK_PICKUP;
1232 continue; 1208 continue;
1233 } 1209 }
1234 } 1210 }
1235 1211
1236 /* rings & amulets - talismans seems to be typed AMULET */ 1212 /* rings & amulets - talismans seems to be typed AMULET */
1237 if (op->contr->mode & PU_JEWELS) 1213 if (op->contr->mode & PU_JEWELS)
1238 if (tmp->type == RING || tmp->type == AMULET) 1214 if (tmp->type == RING || tmp->type == AMULET)
1239 { 1215 {
1240 pick_up (op, tmp); 1216 CHK_PICK_PICKUP;
1241 continue; 1217 continue;
1242 } 1218 }
1243 1219
1244 /* we don't forget dragon food */ 1220 /* we don't forget dragon food */
1245 if (op->contr->mode & PU_FLESH) 1221 if (op->contr->mode & PU_FLESH)
1246 if (tmp->type == FLESH) 1222 if (tmp->type == FLESH)
1247 { 1223 {
1248 pick_up (op, tmp); 1224 CHK_PICK_PICKUP;
1249 continue; 1225 continue;
1250 } 1226 }
1251 1227
1252 /* bows and arrows. Bows are good for selling! */ 1228 /* bows and arrows. Bows are good for selling! */
1253 if (op->contr->mode & PU_BOW) 1229 if (op->contr->mode & PU_BOW)
1254 if (tmp->type == BOW) 1230 if (tmp->type == BOW)
1255 { 1231 {
1256 pick_up (op, tmp); 1232 CHK_PICK_PICKUP;
1257 continue; 1233 continue;
1258 } 1234 }
1259 1235
1260 if (op->contr->mode & PU_ARROW) 1236 if (op->contr->mode & PU_ARROW)
1261 if (tmp->type == ARROW) 1237 if (tmp->type == ARROW)
1262 { 1238 {
1263 pick_up (op, tmp); 1239 CHK_PICK_PICKUP;
1264 continue; 1240 continue;
1265 } 1241 }
1266 1242
1267 /* all kinds of armor etc. */ 1243 /* all kinds of armor etc. */
1268 if (op->contr->mode & PU_ARMOUR) 1244 if (op->contr->mode & PU_ARMOUR)
1269 if (tmp->type == ARMOUR) 1245 if (tmp->type == ARMOUR)
1270 { 1246 {
1271 pick_up (op, tmp); 1247 CHK_PICK_PICKUP;
1272 continue; 1248 continue;
1273 } 1249 }
1274 1250
1275 if (op->contr->mode & PU_HELMET) 1251 if (op->contr->mode & PU_HELMET)
1276 if (tmp->type == HELMET) 1252 if (tmp->type == HELMET)
1277 { 1253 {
1278 pick_up (op, tmp); 1254 CHK_PICK_PICKUP;
1279 continue; 1255 continue;
1280 } 1256 }
1281 1257
1282 if (op->contr->mode & PU_SHIELD) 1258 if (op->contr->mode & PU_SHIELD)
1283 if (tmp->type == SHIELD) 1259 if (tmp->type == SHIELD)
1284 { 1260 {
1285 pick_up (op, tmp); 1261 CHK_PICK_PICKUP;
1286 continue; 1262 continue;
1287 } 1263 }
1288 1264
1289 if (op->contr->mode & PU_BOOTS) 1265 if (op->contr->mode & PU_BOOTS)
1290 if (tmp->type == BOOTS) 1266 if (tmp->type == BOOTS)
1291 { 1267 {
1292 pick_up (op, tmp); 1268 CHK_PICK_PICKUP;
1293 continue; 1269 continue;
1294 } 1270 }
1295 1271
1296 if (op->contr->mode & PU_GLOVES) 1272 if (op->contr->mode & PU_GLOVES)
1297 if (tmp->type == GLOVES) 1273 if (tmp->type == GLOVES)
1298 { 1274 {
1299 pick_up (op, tmp); 1275 CHK_PICK_PICKUP;
1300 continue; 1276 continue;
1301 } 1277 }
1302 1278
1303 if (op->contr->mode & PU_CLOAK) 1279 if (op->contr->mode & PU_CLOAK)
1304 if (tmp->type == CLOAK) 1280 if (tmp->type == CLOAK)
1305 { 1281 {
1306 pick_up (op, tmp); 1282 CHK_PICK_PICKUP;
1307 continue; 1283 continue;
1308 } 1284 }
1309 1285
1310 /* hoping to catch throwing daggers here */ 1286 /* hoping to catch throwing daggers here */
1311 if (op->contr->mode & PU_MISSILEWEAPON) 1287 if (op->contr->mode & PU_MISSILEWEAPON)
1312 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1288 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1313 { 1289 {
1314 pick_up (op, tmp); 1290 CHK_PICK_PICKUP;
1315 continue; 1291 continue;
1316 } 1292 }
1317 1293
1318 /* careful: chairs and tables are weapons! */ 1294 /* careful: chairs and tables are weapons! */
1319 if (op->contr->mode & PU_ALLWEAPON) 1295 if (op->contr->mode & PU_ALLWEAPON)
1320 { 1296 {
1321 if (tmp->type == WEAPON && tmp->name != NULL) 1297 if (tmp->type == WEAPON && tmp->name != NULL)
1322 { 1298 {
1323 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->name, "table") == NULL && 1299 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1324 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1300 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1325 { 1301 {
1326 pick_up (op, tmp); 1302 CHK_PICK_PICKUP;
1327 continue; 1303 continue;
1328 } 1304 }
1329 } 1305 }
1330 1306
1331 if (tmp->type == WEAPON && tmp->name == NULL) 1307 if (tmp->type == WEAPON && tmp->name == NULL)
1332 { 1308 {
1333 if (strstr (tmp->arch->name, "table") == NULL && strstr (tmp->arch->name, "chair") == NULL) 1309 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1334 { 1310 {
1335 pick_up (op, tmp); 1311 CHK_PICK_PICKUP;
1336 continue; 1312 continue;
1337 } 1313 }
1338 } 1314 }
1339 } 1315 }
1340 1316
1341 /* misc stuff that's useful */ 1317 /* misc stuff that's useful */
1342 if (op->contr->mode & PU_KEY) 1318 if (op->contr->mode & PU_KEY)
1343 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1319 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1344 { 1320 {
1345 pick_up (op, tmp); 1321 CHK_PICK_PICKUP;
1346 continue; 1322 continue;
1347 } 1323 }
1348 1324
1349 /* any of the last 4 bits set means we use the ratio for value 1325 /* any of the last 4 bits set means we use the ratio for value
1350 * pickups */ 1326 * pickups */
1355 /* >=7 is the old standard setting. Now we take the last 4 bits 1331 /* >=7 is the old standard setting. Now we take the last 4 bits
1356 * and multiply them by 5, giving 0..15*5== 5..75 */ 1332 * and multiply them by 5, giving 0..15*5== 5..75 */
1357 wvratio = (op->contr->mode & PU_RATIO) * 5; 1333 wvratio = (op->contr->mode & PU_RATIO) * 5;
1358 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1334 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1359 { 1335 {
1360 pick_up (op, tmp); 1336 CHK_PICK_PICKUP;
1361#if 0 1337#if 0
1362 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1338 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1363 if (tmp->name != NULL) 1339 if (tmp->name != NULL)
1364 { 1340 {
1365 fprintf (stderr, "%s", tmp->name); 1341 fprintf (stderr, "%s", tmp->name);
1366 } 1342 }
1367 else 1343 else
1368 fprintf (stderr, "%s", tmp->arch->name); 1344 fprintf (stderr, "%s", tmp->arch->archname);
1369 fprintf (stderr, ",%d] = ", tmp->type); 1345 fprintf (stderr, ",%d] = ", tmp->type);
1370 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1346 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))));
1371#endif 1347#endif
1372 continue; 1348 continue;
1373 } 1349 }
1384 * found object is returned. 1360 * found object is returned.
1385 */ 1361 */
1386object * 1362object *
1387find_arrow (object *op, const char *type) 1363find_arrow (object *op, const char *type)
1388{ 1364{
1389 object *tmp = 0;
1390
1391 for (op = op->inv; op; op = op->below) 1365 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1392 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1393 tmp = find_arrow (op, type);
1394 else if (op->type == ARROW && op->race == type) 1366 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1367 return splay (tmp);
1368
1369 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1370 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1371 if (object *arrow = find_arrow (tmp, type))
1372 {
1373 splay (tmp);
1395 return op; 1374 return arrow;
1375 }
1396 1376
1397 return tmp; 1377 return 0;
1398} 1378}
1399 1379
1400/* 1380/*
1401 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1381 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1402 * against the target. A full test is not performed, simply a basic test 1382 * against the target. A full test is not performed, simply a basic test
1443 else 1423 else
1444 { 1424 {
1445 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) 1425 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++)
1446 { 1426 {
1447 attacktype = 1 << attacknum; 1427 attacktype = 1 << attacknum;
1448 if ((arrow->attacktype & attacktype) && (target->arch->clone.resist[attacknum]) < 0) 1428 if ((arrow->attacktype & attacktype) && (target->arch->resist[attacknum]) < 0)
1449 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100) > betterby) 1429 if (((arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100) > betterby)
1450 { 1430 {
1451 tmp = arrow; 1431 tmp = arrow;
1452 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->clone.resist[attacknum]) / 100; 1432 betterby = (arrow->magic + arrow->stats.dam) * (100 - target->arch->resist[attacknum]) / 100;
1453 } 1433 }
1454 } 1434 }
1455 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1435 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1456 { 1436 {
1457 tmp = arrow; 1437 tmp = arrow;
1623 arrow->destroy (); 1603 arrow->destroy ();
1624 return 0; 1604 return 0;
1625 } 1605 }
1626 1606
1627 left = arrow; /* these are arrows left to the player */ 1607 left = arrow; /* these are arrows left to the player */
1628 arrow = get_split_ob (arrow, 1); 1608 arrow = arrow->split ();
1629 if (!arrow) 1609 if (!arrow)
1630 { 1610 {
1631 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1611 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1632 return 0; 1612 return 0;
1633 } 1613 }
1641 arrow->stats.grace = arrow->attacktype; 1621 arrow->stats.grace = arrow->attacktype;
1642 1622
1643 if (arrow->slaying) 1623 if (arrow->slaying)
1644 arrow->spellarg = strdup (arrow->slaying); 1624 arrow->spellarg = strdup (arrow->slaying);
1645 1625
1626#if 0
1646 if (player *pl = op->contr) 1627 if (player *pl = op->contr)
1647 { 1628 {
1648 if (!pl->has_hit)
1649 {
1650 pl->has_hit = 1;
1651 pl->ob->speed_left += pl->weapon_speed () - pl->ob->speed;
1652 }
1653#if 0
1654 float speed = pl->weapon_sp; 1629 float speed = pl->weapon_sp;
1655 1630
1656 /* penalize ROF for bestarrow */ 1631 /* penalize ROF for bestarrow */
1657 if (pl->bowtype == bow_bestarrow) 1632 if (pl->bowtype == bow_bestarrow)
1658 speed *= .9f; 1633 speed *= .9f;
1659 else 1634 else
1660 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f; 1635 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f;
1661 1636
1662 op->speed_left += speed - op->speed; 1637 op->speed_left += speed - op->speed;
1638 }
1663#endif 1639#endif
1664 }
1665 1640
1666 SET_ANIMATION (arrow, arrow->direction); 1641 SET_ANIMATION (arrow, arrow->direction);
1667 1642
1668 /* update the speed */ 1643 /* update the speed */
1669 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 1644 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1670 + bow->stats.dam / 7.0; 1645 + bow->stats.dam / 7.f;
1671 1646
1672 arrow->set_speed (max (arrow->speed, 2.0)); 1647 arrow->set_speed (max (arrow->speed, 2.f));
1673 arrow->speed_left = 0; 1648 arrow->speed_left = 0;
1674 1649
1675 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1650 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1676 1651
1677 if (op->type == PLAYER) 1652 if (op->type == PLAYER)
1700 1675
1701 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); 1676 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1702 arrow->move_type = MOVE_FLY_LOW; 1677 arrow->move_type = MOVE_FLY_LOW;
1703 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1678 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1704 1679
1705 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1680 op->play_sound (sound_find ("fire_arrow"));
1706 m->insert (arrow, sx, sy, op); 1681 m->insert (arrow, sx, sy, op);
1707 1682
1708 if (!arrow->destroyed ()) 1683 if (!arrow->destroyed ())
1709 move_arrow (arrow); 1684 move_arrow (arrow);
1710
1711 if (op->type == PLAYER)
1712 {
1713 if (left->destroyed ())
1714 esrv_del_item (op->contr, left->count);
1715 else
1716 esrv_send_item (op, left);
1717 }
1718 1685
1719 return 1; 1686 return 1;
1720} 1687}
1721 1688
1722/* Special fire code for players - this takes into 1689/* Special fire code for players - this takes into
1788 1755
1789 if (item->type == WAND) 1756 if (item->type == WAND)
1790 { 1757 {
1791 if (item->stats.food <= 0) 1758 if (item->stats.food <= 0)
1792 { 1759 {
1793 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1760 op->contr->play_sound (sound_find ("wand_poof"));
1794 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0)); 1761 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s goes poof.", query_base_name (item, 0));
1795 1762
1796 return; 1763 return;
1797 } 1764 }
1798 } 1765 }
1799 else if (item->type == ROD || item->type == HORN) 1766 else if (item->type == ROD || item->type == HORN)
1800 { 1767 {
1801 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace)) 1768 if (item->stats.hp < MAX (item->inv->stats.sp, item->inv->stats.grace))
1802 { 1769 {
1803 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1770 op->contr->play_sound (sound_find ("wand_poof"));
1804 1771
1805 if (item->type == ROD) 1772 if (item->type == ROD)
1806 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1773 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1807 else 1774 else
1808 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0)); 1775 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s needs more time to charge.", query_base_name (item, 0));
1821 object *tmp; 1788 object *tmp;
1822 1789
1823 if (item->arch) 1790 if (item->arch)
1824 { 1791 {
1825 CLEAR_FLAG (item, FLAG_ANIMATE); 1792 CLEAR_FLAG (item, FLAG_ANIMATE);
1826 item->face = item->arch->clone.face; 1793 item->face = item->arch->face;
1827 item->set_speed (0); 1794 item->set_speed (0);
1828 } 1795 }
1829 1796
1830 if ((tmp = item->in_player ())) 1797 if ((tmp = item->in_player ()))
1831 esrv_update_item (UPD_ANIM, tmp, item); 1798 esrv_update_item (UPD_ANIM, tmp, item);
1836 } 1803 }
1837} 1804}
1838 1805
1839/* Received a fire command for the player - go and do it. 1806/* Received a fire command for the player - go and do it.
1840 */ 1807 */
1841void 1808bool
1842fire (object *op, int dir) 1809fire (object *op, int dir)
1843{ 1810{
1844 int spellcost = 0; 1811 int spellcost = 0;
1845 1812
1846 /* check for loss of invisiblity/hide */ 1813 /* check for loss of invisiblity/hide */
1850 player *pl = op->contr; 1817 player *pl = op->contr;
1851 1818
1852 if (pl->golem) 1819 if (pl->golem)
1853 { 1820 {
1854 control_golem (op->contr->golem, dir); 1821 control_golem (op->contr->golem, dir);
1855 return; 1822 return false;
1856 } 1823 }
1857 1824
1858 object *ob = pl->ranged_ob; 1825 object *ob = pl->ranged_ob;
1859 1826
1860 if (!ob) 1827 if (!ob)
1861 return; 1828 return false;
1862 1829
1863 if (!op->change_weapon (ob)) 1830 if (!op->change_weapon (ob))
1864 return; 1831 return false;
1832
1833 if (op->speed_left > 0.f)
1834 --op->speed_left;
1835 else
1836 return false;
1865 1837
1866 switch (ob->type) 1838 switch (ob->type)
1867 { 1839 {
1868 case BOW: 1840 case BOW:
1869 player_fire_bow (op, dir); 1841 player_fire_bow (op, dir);
1883 1855
1884 default: 1856 default:
1885 fire_misc_object (op, dir); 1857 fire_misc_object (op, dir);
1886 break; 1858 break;
1887 } 1859 }
1860
1861 return true;
1888} 1862}
1889 1863
1890/* find_key 1864/* find_key
1891 * We try to find a key for the door as passed. If we find a key 1865 * We try to find a key for the door as passed. If we find a key
1892 * and successfully use it, we return the key, otherwise NULL 1866 * and successfully use it, we return the key, otherwise NULL
1979 * 0 otherwise 1953 * 0 otherwise
1980 */ 1954 */
1981static int 1955static int
1982player_attack_door (object *op, object *door) 1956player_attack_door (object *op, object *door)
1983{ 1957{
1984 /* If its a door, try to find a use a key. If we do destroy the door, 1958 /* If its a door, try to find a key. If we do destroy the door,
1985 * might as well return immediately as there is nothing more to do - 1959 * might as well return immediately as there is nothing more to do -
1986 * otherwise, we fall through to the rest of the code. 1960 * otherwise, we fall through to the rest of the code.
1987 */ 1961 */
1988 object *key = find_key (op, op, door); 1962 object *key = find_key (op, op, door);
1989 1963
1990 /* IF we found a key, do some extra work */ 1964 /* If we found a key, do some extra work */
1991 if (key) 1965 if (key)
1992 { 1966 {
1993 object *container = key->env; 1967 object *container = key->env;
1994
1995 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR);
1996 1968
1997 if (action_makes_visible (op)) 1969 if (action_makes_visible (op))
1998 make_visible (op); 1970 make_visible (op);
1999 1971
2000 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1972 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
2002 1974
2003 if (door->type == DOOR) 1975 if (door->type == DOOR)
2004 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */ 1976 hit_player (door, 9998, op, AT_PHYSICAL, 1); /* Break through the door */
2005 else if (door->type == LOCKED_DOOR) 1977 else if (door->type == LOCKED_DOOR)
2006 { 1978 {
2007 new_draw_info_format (NDI_UNIQUE, NDI_BROWN, op, "You open the door with the %s", query_short_name (key)); 1979 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
2008 remove_door2 (door); /* remove door without violence ;-) */ 1980 remove_door2 (door); /* remove door without violence ;-) */
2009 } 1981 }
2010 1982
2011 /* Do this after we print the message */ 1983 /* Do this after we print the message */
2012 decrease_ob (key); /* Use up one of the keys */ 1984 key->decrease (); /* Use up one of the keys */
2013 /* Need to update the weight the container the key was in */ 1985 /* Need to update the weight the container the key was in */
2014 if (container != op) 1986 if (container != op)
2015 esrv_update_item (UPD_WEIGHT, op, container); 1987 esrv_update_item (UPD_WEIGHT, op, container);
2016 1988
2017 return 1; /* Nothing more to do below */ 1989 return 1; /* Nothing more to do below */
2018 } 1990 }
2019 else if (door->type == LOCKED_DOOR) 1991 else if (door->type == LOCKED_DOOR)
2020 { 1992 {
2021 /* Might as well return now - no other way to open this */ 1993 /* Might as well return now - no other way to open this */
2022 new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, door->msg); 1994 op->failmsg (door->msg ? &door->msg : "Hmm, you miss the certain something to open this door...");
2023 return 1; 1995 return 1;
2024 } 1996 }
2025 1997
2026 return 0; 1998 return 0;
2027} 1999}
2030 * It should keep the code cleaner. 2002 * It should keep the code cleaner.
2031 * When this is called, the players direction has been updated 2003 * When this is called, the players direction has been updated
2032 * (taking into account confusion.) The player is also actually 2004 * (taking into account confusion.) The player is also actually
2033 * going to try and move (not fire weapons). 2005 * going to try and move (not fire weapons).
2034 */ 2006 */
2035void 2007bool
2036move_player_attack (object *op, int dir) 2008move_player_attack (object *op, int dir)
2037{ 2009{
2038 object *tmp, *mon;
2039 int on_battleground; 2010 int on_battleground;
2040 maptile *m;
2041 2011
2042 sint16 nx = freearr_x[dir] + op->x; 2012 sint16 nx = freearr_x[dir] + op->x;
2043 sint16 ny = freearr_y[dir] + op->y; 2013 sint16 ny = freearr_y[dir] + op->y;
2044 2014
2045 on_battleground = op_on_battleground (op, 0, 0); 2015 on_battleground = op_on_battleground (op, 0, 0);
2016
2017 if (out_of_map (op->map, nx, ny))
2018 return false;
2019
2020 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op))
2021 {
2022 --op->speed_left;
2023 return true;
2024 }
2046 2025
2047 /* If braced, or can't move to the square, and it is not out of the 2026 /* If braced, or can't move to the square, and it is not out of the
2048 * map, attack it. Note order of if statement is important - don't 2027 * map, attack it. Note order of if statement is important - don't
2049 * want to be calling move_ob if braced, because move_ob will move the 2028 * want to be calling move_ob if braced, because move_ob will move the
2050 * player. This is a pretty nasty hack, because if we could 2029 * player. This is a pretty nasty hack, because if we could
2051 * move to some space, it then means that if we are braced, we should 2030 * move to some space, it then means that if we are braced, we should
2052 * do nothing at all. As it is, if we are braced, we go through 2031 * do nothing at all. As it is, if we are braced, we go through
2053 * quite a bit of processing. However, it probably is less than what 2032 * quite a bit of processing. However, it probably is less than what
2054 * move_ob uses. 2033 * move_ob uses.
2055 */ 2034 */
2056 if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny))
2057 {
2058 if (OUT_OF_REAL_MAP (op->map, nx, ny))
2059 {
2060 m = op->map->xy_find (nx, ny); 2035 maptile *m = op->map->xy_find (nx, ny);
2061 if (!m)
2062 return; /* Don't think this should happen */
2063 }
2064 else
2065 m = op->map;
2066 2036
2067 if (!(tmp = m->at (nx, ny).bot))
2068 return;
2069
2070 mon = 0;
2071 /* Go through all the objects, and find ones of interest. Only stop if 2037 /* Go through all the objects, and find ones of interest. Only stop if
2072 * we find a monster - that is something we know we want to attack. 2038 * we find a monster - that is something we know we want to attack.
2073 * if its a door or barrel (can roll) see if there may be monsters 2039 * if its a door or barrel (can roll) see if there may be monsters
2074 * on the space 2040 * on the space
2075 */ 2041 */
2076 while (tmp) 2042 object *mon;
2077 { 2043 for (mon = m->at (nx, ny).bot; mon; mon = mon->above)
2078 if (tmp == op) 2044 {
2079 { 2045 if ((mon->flag [FLAG_ALIVE]
2080 tmp = tmp->above; 2046 || mon->type == LOCKED_DOOR
2081 continue; 2047 || mon->flag [FLAG_CAN_ROLL])
2082 }
2083
2084 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2085 {
2086 mon = tmp; 2048 && mon != op)
2087 break; 2049 break;
2088 } 2050 }
2089 2051
2090 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2091 mon = tmp;
2092
2093 tmp = tmp->above;
2094 }
2095
2096 if (!mon) /* This happens anytime the player tries to move */ 2052 if (!mon) /* This happens anytime the player tries to move */
2097 return; /* into a wall */ 2053 return false; /* into a wall */
2098 2054
2099 if (mon->head)
2100 mon = mon->head; 2055 mon = mon->head_ ();
2101 2056
2102 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 2057 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2058 if (op->contr->weapon_sp_left > 0.f)
2103 if (player_attack_door (op, mon)) 2059 if (player_attack_door (op, mon))
2060 {
2061 --op->contr->weapon_sp_left;
2104 return; 2062 return true;
2063 }
2105 2064
2106 /* The following deals with possibly attacking peaceful 2065 /* The following deals with possibly attacking peaceful
2107 * or frienddly creatures. Basically, all players are considered 2066 * or friendly creatures. Basically, all players are considered
2108 * unaggressive. If the moving player has peaceful set, then the 2067 * unaggressive. If the moving player has peaceful set, then the
2109 * object should be pushed instead of attacked. It is assumed that 2068 * object should be pushed instead of attacked. It is assumed that
2110 * if you are braced, you will not attack friends accidently, 2069 * if you are braced, you will not attack friends accidently,
2111 * and thus will not push them. 2070 * and thus will not push them.
2112 */ 2071 */
2113 2072
2114 /* If the creature is a pet, push it even if the player is not 2073 /* If the creature is a pet, push it even if the player is not
2115 * peaceful. Our assumption is the creature is a pet if the 2074 * peaceful. Our assumption is the creature is a pet if the
2116 * player owns it and it is either friendly or unagressive. 2075 * player owns it and it is either friendly or unagressive.
2117 */ 2076 */
2118 if (op->type == PLAYER 2077 if (op->type == PLAYER
2119 && ((mon->owner && mon->owner->contr 2078 && ((mon->owner && mon->owner->contr
2120 && same_party (mon->owner->contr->party, op->contr->party)) 2079 && same_party (mon->owner->contr->party, op->contr->party))
2121 || mon->owner == op) 2080 || mon->owner == op)
2122 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2081 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2123 { 2082 {
2124 /* If we're braced, we don't want to switch places with it */ 2083 /* If we're braced, we don't want to switch places with it */
2125 if (op->contr->braced) 2084 if (op->contr->braced)
2126 return; 2085 return false;
2127 2086
2128 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2087 if (op->speed_left > 0.f)
2088 {
2089 --op->speed_left;
2090
2091 op->play_sound (sound_find ("push_player"));
2129 push_ob (mon, dir, op); 2092 push_ob (mon, dir, op);
2093
2130 if (op->contr->tmp_invis || op->hide) 2094 if (op->contr->tmp_invis || op->hide)
2131 make_visible (op); 2095 make_visible (op);
2132 2096
2133 return; 2097 return true;
2134 } 2098 }
2099 else
2100 return false;
2101 }
2135 2102
2136 /* in certain circumstances, you shouldn't attack friendly 2103 /* in certain circumstances, you shouldn't attack friendly
2137 * creatures. Note that if you are braced, you can't push 2104 * creatures. Note that if you are braced, you can't push
2138 * someone, but put it inside this loop so that you won't 2105 * someone, but put it inside this loop so that you won't
2139 * attack them either. 2106 * attack them either.
2140 */ 2107 */
2141 if ((mon->type == PLAYER || mon->enemy != op) 2108 if ((mon->type == PLAYER || mon->enemy != op)
2142 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 2109 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))
2143 && ((op->contr->peaceful 2110 && ((op->contr->peaceful
2144 || (mon->type == PLAYER && mon->contr->peaceful)) 2111 || (mon->type == PLAYER && mon->contr->peaceful))
2145 && !on_battleground)) 2112 && !on_battleground))
2113 {
2114 if (op->speed_left > 0.f)
2146 { 2115 {
2116 --op->speed_left;
2117
2147 if (!op->contr->braced) 2118 if (!op->contr->braced)
2148 { 2119 {
2149 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2120 op->play_sound (sound_find ("push_player"));
2150 push_ob (mon, dir, op); 2121 push_ob (mon, dir, op);
2151 } 2122 }
2152 else 2123 else
2153 new_draw_info (0, 0, op, "You withhold your attack"); 2124 op->statusmsg ("You withhold your attack");
2154 2125
2155 if (op->contr->tmp_invis || op->hide) 2126 if (op->contr->tmp_invis || op->hide)
2156 make_visible (op); 2127 make_visible (op);
2157 }
2158 2128
2129 return true;
2130 }
2131 }
2159 /* If the object is a boulder or other rollable object, then 2132 /* If the object is a boulder or other rollable object, then
2160 * roll it if not braced. You can't roll it if you are braced. 2133 * roll it if not braced. You can't roll it if you are braced.
2161 */ 2134 */
2162 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 2135 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced))
2136 {
2137 if (op->speed_left > 0.f)
2163 { 2138 {
2139 --op->speed_left;
2140
2164 recursive_roll (mon, dir, op); 2141 recursive_roll (mon, dir, op);
2165 if (action_makes_visible (op)) 2142 if (action_makes_visible (op))
2166 make_visible (op); 2143 make_visible (op);
2167 }
2168 2144
2145 return true;
2146 }
2147 }
2169 /* Any generic living creature. Including things like doors. 2148 /* Any generic living creature. Including things like doors.
2170 * Way it works is like this: First, it must have some hit points 2149 * Way it works is like this: First, it must have some hit points
2171 * and be living. Then, it must be one of the following: 2150 * and be living. Then, it must be one of the following:
2172 * 1) Not a player, 2) A player, but of a different party. Note 2151 * 1) Not a player, 2) A player, but of a different party. Note
2173 * that party_number -1 is no party, so attacks can still happen. 2152 * that party_number -1 is no party, so attacks can still happen.
2174 */ 2153 */
2175 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2154 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2176 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2155 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2177 { 2156 {
2178 if (!op->contr->has_hit) 2157 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2179 { 2158 {
2180 op->contr->has_hit = 1; 2159 --op->contr->weapon_sp_left;
2181 op->speed_left += op->contr->weapon_speed () - op->speed;
2182 }
2183 2160
2184 skill_attack (mon, op, 0, 0, 0); 2161 skill_attack (mon, op, 0, 0, 0);
2185
2186 /* If attacking another player, that player gets automatic
2187 * hitback, and doesn't loose luck either.
2188 * Disable hitback on the battleground or if the target is
2189 * the wiz.
2190 */
2191 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2192 {
2193 short luck = mon->stats.luck;
2194
2195 mon->contr->has_hit = 1;
2196 skill_attack (op, mon, 0, 0, 0);
2197 mon->stats.luck = luck;
2198 }
2199 2162
2200 if (action_makes_visible (op)) 2163 if (action_makes_visible (op))
2201 make_visible (op); 2164 make_visible (op);
2202 }
2203 } /* if player should attack something */
2204}
2205 2165
2206int 2166 return true;
2167 }
2168 }
2169
2170 return false;
2171}
2172
2173bool
2207move_player (object *op, int dir) 2174move_player (object *op, int dir)
2208{ 2175{
2209 int pick; 2176 int pick;
2210 2177
2211 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2178 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2212 return 0; 2179 return 0;
2213 2180
2214 /* Sanity check: make sure dir is valid */ 2181 /* Sanity check: make sure dir is valid */
2215 if ((dir < 0) || (dir >= 9)) 2182 if ((dir < 0) || (dir >= 9))
2216 { 2183 {
2225 op->facing = dir; 2192 op->facing = dir;
2226 2193
2227 if (op->hide) 2194 if (op->hide)
2228 do_hidden_move (op); 2195 do_hidden_move (op);
2229 2196
2197 bool retval;
2198
2230 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2199 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2231 /*nop */ ; 2200 retval = RESULT_INT (0);
2232 else if (op->contr->fire_on) 2201 else if (op->contr->fire_on)
2233 fire (op, dir); 2202 retval = fire (op, dir);
2234 else 2203 else
2235 { 2204 {
2236 move_player_attack (op, dir); 2205 retval = move_player_attack (op, dir);
2237 pick = check_pick (op); 2206 pick = check_pick (op);
2238 } 2207 }
2239 2208
2240 /* Add special check for newcs players and fire on - this way, the 2209 /* Add special check for newcs players and fire on - this way, the
2241 * server can handle repeat firing. 2210 * server can handle repeat firing.
2248 /* Update how the player looks. Use the facing, so direction may 2217 /* Update how the player looks. Use the facing, so direction may
2249 * get reset to zero. This allows for full animation capabilities 2218 * get reset to zero. This allows for full animation capabilities
2250 * for players. 2219 * for players.
2251 */ 2220 */
2252 animate_object (op, op->facing); 2221 animate_object (op, op->facing);
2253 return 0; 2222
2223 return retval;
2254} 2224}
2255 2225
2256/* This is similar to handle_player, below, but is only used by the 2226/* This is similar to handle_player, below, but is only used by the
2257 * new client/server stuff. 2227 * new client/server stuff.
2258 * This is sort of special, in that the new client/server actually uses 2228 * This is sort of special, in that the new client/server actually uses
2259 * the new speed values for commands. 2229 * the new speed values for commands.
2260 * 2230 *
2261 * Returns true if there are more actions we can do. 2231 * Returns true if there are more actions we can do. Should not do
2232 * many actions in a row, as that would be too unfair to other
2233 * players.
2262 */ 2234 */
2263int 2235bool
2264handle_newcs_player (object *op) 2236handle_newcs_player (object *op)
2265{ 2237{
2266 if (QUERY_FLAG (op, FLAG_SCARED)) 2238 if (QUERY_FLAG (op, FLAG_SCARED))
2267 { 2239 {
2268 flee_player (op); 2240 if (op->speed_left > 0.f)
2269
2270 /* If player is still scared, that is his action for this tick */
2271 if (op->flag [FLAG_SCARED])
2272 { 2241 {
2273 --op->speed_left; 2242 --op->speed_left;
2243 flee_player (op);
2244
2274 return 0; 2245 return true;
2275 } 2246 }
2247 else
2248 return false;
2276 } 2249 }
2277 2250
2278 /* call this here - we also will call this in do_ericserver, but 2251 /* call this here - we also will call this in do_ericserver, but
2279 * the players time has been increased when doericserver has been 2252 * the players time has been increased when doericserver has been
2280 * called, so we recheck it here. 2253 * called, so we recheck it here.
2281 */ 2254 */
2282 if (op->contr->ns->handle_command ()) 2255 if (op->contr->ns->handle_command ())
2283 return 1; 2256 return true;
2284 2257
2285 if (op->speed_left > 0.f)
2286 {
2287 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2258 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2288 {
2289 /* All move commands take 1 tick, at least for now */
2290 --op->speed_left;
2291
2292 /* Instead of all the stuff below, let move_player take care
2293 * of it. Also, some of the skill stuff is only put in
2294 * there, as well as the confusion stuff.
2295 */
2296 move_player (op, op->direction); 2259 return move_player (op, op->direction);
2297 2260
2298 return op->speed_left > 0.f;
2299 }
2300 }
2301
2302 return 0; 2261 return false;
2303} 2262}
2304 2263
2305int 2264int
2306save_life (object *op) 2265save_life (object *op)
2307{ 2266{
2309 return 0; 2268 return 0;
2310 2269
2311 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2270 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2312 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2271 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2313 { 2272 {
2314 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2273 op->play_sound (sound_find ("ob_evaporate"));
2315 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2274 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2316 2275
2317 if (op->contr) 2276 if (op->contr)
2318 esrv_del_item (op->contr, tmp->count); 2277 esrv_del_item (op->contr, tmp->count);
2319 2278
2339/* This goes throws the inventory and removes unpaid objects, and puts them 2298/* This goes throws the inventory and removes unpaid objects, and puts them
2340 * back in the map (location and map determined by values of env). This 2299 * back in the map (location and map determined by values of env). This
2341 * function will descend into containers. op is the object to start the search 2300 * function will descend into containers. op is the object to start the search
2342 * from. 2301 * from.
2343 */ 2302 */
2344void 2303static void
2345remove_unpaid_objects (object *op, object *env) 2304drop_unpaid_items (object *op, object *env)
2346{ 2305{
2347 while (op) 2306 while (op)
2348 { 2307 {
2349 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2308 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2350 2309
2354 esrv_del_item (env->contr, op->count); 2313 esrv_del_item (env->contr, op->count);
2355 2314
2356 op->insert_at (env); 2315 op->insert_at (env);
2357 } 2316 }
2358 else if (op->inv) 2317 else if (op->inv)
2359 remove_unpaid_objects (op->inv, env); 2318 drop_unpaid_items (op->inv, env);
2360 2319
2361 op = next; 2320 op = next;
2362 } 2321 }
2322}
2323
2324void
2325object::drop_unpaid_items ()
2326{
2327 if (!flag [FLAG_REMOVED])
2328 ::drop_unpaid_items (inv, this);
2363} 2329}
2364 2330
2365/* 2331/*
2366 * Returns pointer a static string containing gravestone text 2332 * Returns pointer a static string containing gravestone text
2367 * Moved from apply.c to player.c - player.c is what 2333 * Moved from apply.c to player.c - player.c is what
2462 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace; 2428 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace;
2463 else 2429 else
2464 { 2430 {
2465 gen_grace = op->stats.maxgrace; 2431 gen_grace = op->stats.maxgrace;
2466 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2432 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2467 }
2468
2469 /* Regenerate Spell Points */
2470 if (!op->contr->golem && --op->last_sp < 0)
2471 {
2472 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2473 if (op->stats.sp < op->stats.maxsp)
2474 {
2475 op->stats.sp++;
2476 /* dms do not consume food */
2477 if (!QUERY_FLAG (op, FLAG_WIZ))
2478 {
2479 op->stats.food--;
2480 if (op->contr->digestion < 0)
2481 op->stats.food += op->contr->digestion;
2482 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2483 op->stats.food = last_food;
2484 }
2485 }
2486
2487 if (max_sp > 1)
2488 {
2489 over_sp = (gen_sp + 10) / rate_sp;
2490 if (over_sp > 0)
2491 {
2492 if (op->stats.sp < op->stats.maxsp)
2493 {
2494 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2495
2496 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2497 op->stats.sp--;
2498
2499 if (op->stats.sp > op->stats.maxsp)
2500 op->stats.sp = op->stats.maxsp;
2501 }
2502 op->last_sp = 0;
2503 }
2504 else
2505 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2506 }
2507 else
2508 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2509 } 2433 }
2510 2434
2511 /* Regenerate Grace */ 2435 /* Regenerate Grace */
2512 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */ 2436 /* I altered this a little - maximum grace is ony achieved through prayer -b.t. */
2513 if (--op->last_grace < 0) 2437 if (--op->last_grace < 0)
2534 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); 2458 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10);
2535 } 2459 }
2536 /* wearing stuff doesn't detract from grace generation. */ 2460 /* wearing stuff doesn't detract from grace generation. */
2537 } 2461 }
2538 2462
2463 if (op->stats.food > 0)
2464 {
2539 /* Regenerate Hit Points */ 2465 /* Regenerate Spell Points */
2540 if (--op->last_heal < 0) 2466 if (!op->contr->golem && --op->last_sp < 0)
2541 {
2542 if (op->stats.hp < op->stats.maxhp)
2543 { 2467 {
2544 op->stats.hp++; 2468 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2545 /* dms do not consume food */ 2469
2546 if (!QUERY_FLAG (op, FLAG_WIZ)) 2470 if (op->stats.sp < op->stats.maxsp)
2547 { 2471 {
2472 op->stats.sp++;
2473
2474 /* dms do not consume food */
2475 if (!QUERY_FLAG (op, FLAG_WIZ))
2476 {
2548 op->stats.food--; 2477 op->stats.food--;
2478
2549 if (op->contr->digestion < 0) 2479 if (op->contr->digestion < 0)
2550 op->stats.food += op->contr->digestion; 2480 op->stats.food += op->contr->digestion;
2551 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2481 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2552 op->stats.food = last_food; 2482 op->stats.food = last_food;
2483 }
2553 } 2484 }
2554 }
2555 2485
2556 if (max_hp > 1) 2486 if (max_sp > 1)
2557 {
2558 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2559 if (over_hp > 0)
2560 { 2487 {
2561 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2488 over_sp = (gen_sp + 10) / rate_sp;
2489 if (over_sp > 0)
2490 {
2491 if (op->stats.sp < op->stats.maxsp)
2492 {
2493 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2494
2495 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2496 op->stats.sp--;
2497
2498 if (op->stats.sp > op->stats.maxsp)
2499 op->stats.sp = op->stats.maxsp;
2500 }
2501
2562 op->last_heal = 0; 2502 op->last_sp = 0;
2503 }
2504 else
2505 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2563 } 2506 }
2564 else 2507 else
2508 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2509 }
2510
2511 /* Regenerate Hit Points */
2512 if (--op->last_heal < 0)
2513 {
2514 if (op->stats.hp < op->stats.maxhp)
2565 { 2515 {
2566 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2516 op->stats.hp++;
2517
2518 /* dms do not consume food */
2519 if (!QUERY_FLAG (op, FLAG_WIZ))
2520 {
2521 op->stats.food--;
2522
2523 if (op->contr->digestion < 0)
2524 op->stats.food += op->contr->digestion;
2525 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2526 op->stats.food = last_food;
2527 }
2567 } 2528 }
2529
2530 if (max_hp > 1)
2531 {
2532 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2533
2534 if (over_hp > 0)
2535 {
2536 op->stats.sp += over_hp + (RANDOM () % rate_hp > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0;
2537 op->last_heal = 0;
2538 }
2539 else
2540 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2568 } 2541 }
2569 else 2542 else
2570 {
2571 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2543 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10);
2572 } 2544 }
2573 } 2545 }
2574 2546
2575 /* Digestion */ 2547 /* Digestion */
2576 if (--op->last_eat < 0) 2548 if (--op->last_eat < 0)
2577 { 2549 {
2578 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0; 2550 int bonus = max (0, op->contr->digestion),
2551 penalty = max (0, -op->contr->digestion);
2579 2552
2580 if (op->contr->gen_hp > 0)
2581 op->last_eat = 25 * (1 + bonus) / (op->contr->gen_hp + penalty + 1); 2553 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2582 else
2583 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2584 2554
2585 /* dms do not consume food */ 2555 /* dms do not consume food */
2586 if (!QUERY_FLAG (op, FLAG_WIZ)) 2556 if (!QUERY_FLAG (op, FLAG_WIZ))
2587 op->stats.food--; 2557 op->stats.food--;
2588 } 2558 }
2615 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food."); 2585 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2616 manual_apply (op, flesh, 0); 2586 manual_apply (op, flesh, 0);
2617 } 2587 }
2618 } 2588 }
2619 2589
2620 while (op->stats.food < 0 && op->stats.hp >= 0) 2590 if (op->stats.food < 0)
2621 op->stats.food++, op->stats.hp--; 2591 {
2592 op->stats.hp += op->stats.food;
2593 op->stats.food = 0;
2594 }
2622 2595
2623 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2596 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2624 kill_player (op); 2597 kill_player (op);
2625 } 2598 }
2626} 2599}
2631 * file. 2604 * file.
2632 */ 2605 */
2633void 2606void
2634kill_player (object *op) 2607kill_player (object *op)
2635{ 2608{
2609 int x, y;
2636 char buf[MAX_BUF]; 2610 char buf[MAX_BUF];
2637 int x, y;
2638
2639 //int i;
2640 maptile *map; /* this is for resurrection */ 2611 maptile *map; /* this is for resurrection */
2641
2642 /* int z;
2643 int num_stats_lose;
2644 int lost_a_stat;
2645 int lose_this_stat;
2646 int this_stat; */
2647 int will_kill_again; 2612 int will_kill_again;
2648 archetype *at; 2613 archetype *at;
2649 object *tmp; 2614 object *tmp;
2650 2615
2651 if (save_life (op)) 2616 if (save_life (op))
2652 return; 2617 return;
2653
2654 2618
2655 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas 2619 /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
2656 * in cities ONLY!!! It is very important that this doesn't get abused. 2620 * in cities ONLY!!! It is very important that this doesn't get abused.
2657 * Look at op_on_battleground() for more info --AndreasV 2621 * Look at op_on_battleground() for more info --AndreasV
2658 */ 2622 */
2674 { 2638 {
2675 tmp->destroy (); 2639 tmp->destroy ();
2676 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2640 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2677 } 2641 }
2678 2642
2679 cure_disease (op, 0); /* remove any disease */ 2643 cure_disease (op, 0, 0); /* remove any disease */
2680 op->stats.hp = op->stats.maxhp; 2644 op->stats.hp = op->stats.maxhp;
2681 if (op->stats.food <= 0) 2645 if (op->stats.food <= 0)
2682 op->stats.food = 999; 2646 op->stats.food = 999;
2683 2647
2684 /* create a bodypart-trophy to make the winner happy */ 2648 /* create a bodypart-trophy to make the winner happy */
2685 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2649 if (object *tmp = arch_to_object (archetype::find ("finger")))
2686 { 2650 {
2687 sprintf (buf, "%s's finger", &op->name); 2651 tmp->name = format ("%s's finger" , &op->name);
2688 tmp->name = buf; 2652 tmp->name_pl = format ("%s's fingers", &op->name);
2689 sprintf (buf, " This finger has been cut off %s\n" 2653 tmp->msg = format (
2690 " the %s, when he was defeated at\n level %d by %s.\n", 2654 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2691 &op->name, op->contr->title, (int) (op->level), op->contr->killer); 2655 &op->name, op->contr->title, (int) (op->level), op->contr->killer
2692 tmp->msg = buf; 2656 );
2693 tmp->value = 0, tmp->type = 0; 2657 tmp->value = 0, tmp->type = 0;
2694 tmp->materialname = "organics"; 2658 tmp->materialname = "organics";
2695 tmp->insert_at (op, tmp); 2659 tmp->insert_at (op, tmp);
2696 } 2660 }
2697 2661
2704 INVOKE_PLAYER (DEATH, op->contr); 2668 INVOKE_PLAYER (DEATH, op->contr);
2705 2669
2706 command_kill_pets (op, 0); 2670 command_kill_pets (op, 0);
2707 2671
2708 if (op->stats.food < 0) 2672 if (op->stats.food < 0)
2709 {
2710 sprintf (buf, "%s starved to death.", &op->name);
2711 strcpy (op->contr->killer, "starvation"); 2673 strcpy (op->contr->killer, "starvation");
2712 }
2713 else
2714 sprintf (buf, "%s died.", &op->name);
2715 2674
2716 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); 2675 op->contr->play_sound (sound_find ("player_dies"));
2717 2676
2718 /* save the map location for corpse, gravestone */ 2677 /* save the map location for corpse, gravestone */
2719 x = op->x; 2678 x = op->x;
2720 y = op->y; 2679 y = op->y;
2721 map = op->map; 2680 map = op->map;
2884 { 2843 {
2885 tmp->destroy (); 2844 tmp->destroy ();
2886 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2845 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2887 } 2846 }
2888 2847
2889 cure_disease (op, 0); /* remove any disease */ 2848 cure_disease (op, 0, 0); /* remove any disease */
2890 2849
2891 /*add_exp(op, (op->stats.exp * -0.20)); */ 2850 /*add_exp(op, (op->stats.exp * -0.20)); */
2892 apply_death_exp_penalty (op); 2851 apply_death_exp_penalty (op);
2893 if (op->stats.food < 100) 2852 if (op->stats.food < 100)
2894 op->stats.food = 900; 2853 op->stats.food = 900;
2898 2857
2899 /* 2858 /*
2900 * Check to see if the player has any unpaid items. If so, remove them 2859 * Check to see if the player has any unpaid items. If so, remove them
2901 * and put them back in the map. 2860 * and put them back in the map.
2902 */ 2861 */
2903 remove_unpaid_objects (op->inv, op); 2862 op->drop_unpaid_items ();
2904 2863
2905 /****************************************/ 2864 /****************************************/
2906 /* */ 2865 /* */
2907 /* Move player to his current respawn- */ 2866 /* Move player to his current respawn- */
2908 /* position (usually last savebed) */ 2867 /* position (usually last savebed) */
2967 2926
2968 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2927 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2969 { 2928 {
2970 if (tmp->nrof > 1) 2929 if (tmp->nrof > 1)
2971 { 2930 {
2972 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2931 tmp->decrease (rndm (1, tmp->nrof - 1));
2973 tmp2->destroy ();
2974 insert_ob_in_map (tmp, op->map, NULL, 0); 2932 insert_ob_in_map (tmp, op->map, NULL, 0);
2975 } 2933 }
2976 else 2934 else
2977 tmp->destroy (); 2935 tmp->destroy ();
2978 } 2936 }
2989void 2947void
2990fix_weight (void) 2948fix_weight (void)
2991{ 2949{
2992 for_all_players (pl) 2950 for_all_players (pl)
2993 { 2951 {
2994 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2952 sint32 old = pl->ob->carrying;
2995 2953
2996 if (old == sum) 2954 pl->ob->update_weight ();
2997 continue; 2955
2956 if (old != pl->ob->carrying)
2957 {
2998 pl->ob->update_stats (); 2958 pl->ob->update_stats ();
2999 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 2959 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying);
2960 }
3000 } 2961 }
3001} 2962}
3002 2963
3003void 2964void
3004fix_luck (void) 2965fix_luck (void)
3048void 3009void
3049make_visible (object *op) 3010make_visible (object *op)
3050{ 3011{
3051 op->hide = 0; 3012 op->hide = 0;
3052 op->invisible = 0; 3013 op->invisible = 0;
3014
3053 if (op->type == PLAYER) 3015 if (op->type == PLAYER)
3054 { 3016 {
3055 op->contr->tmp_invis = 0; 3017 op->contr->tmp_invis = 0;
3056 op->contr->invis_race = 0; 3018 op->contr->invis_race = 0;
3057 } 3019 }
3060} 3022}
3061 3023
3062int 3024int
3063is_true_undead (object *op) 3025is_true_undead (object *op)
3064{ 3026{
3065 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3027 if (QUERY_FLAG (op->arch, FLAG_UNDEAD))
3066 return 1; 3028 return 1;
3067 3029
3068 return 0; 3030 return 0;
3069} 3031}
3070 3032
3071/* look at the surrounding terrain to determine 3033/* look at the surrounding terrain to determine
3072 * the hideability of this object. Positive levels 3034 * the hideability of this object. Positive levels
3073 * indicate greater hideability. 3035 * indicate greater hideability.
3074 */ 3036 */
3075
3076int 3037int
3077hideability (object *ob) 3038hideability (object *ob)
3078{ 3039{
3079 int i, level = 0, mflag; 3040 int i, level = 0, mflag;
3080 sint16 x, y; 3041 sint16 x, y;
3090 * as bad as carrying a light on a pitch dark map */ 3051 * as bad as carrying a light on a pitch dark map */
3091 if (has_carried_lights (ob)) 3052 if (has_carried_lights (ob))
3092 level = -(10 + (2 * ob->map->darkness)); 3053 level = -(10 + (2 * ob->map->darkness));
3093 3054
3094 /* scan through all nearby squares for terrain to hide in */ 3055 /* scan through all nearby squares for terrain to hide in */
3095 for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3056 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1;
3058 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3096 { 3059 {
3097 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3060 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3098 if (mflag & P_OUT_OF_MAP) 3061 if (mflag & P_OUT_OF_MAP)
3099 {
3100 continue; 3062 continue;
3101 } 3063
3102 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3064 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3103 level += 2; 3065 level += 2;
3104 else /* open terrain! */ 3066 else /* open terrain! */
3105 level -= 1; 3067 level -= 1;
3106 } 3068 }
3114/* For Hidden creatures - a chance of becoming 'unhidden' 3076/* For Hidden creatures - a chance of becoming 'unhidden'
3115 * every time they move - as we subtract off 'invisibility' 3077 * every time they move - as we subtract off 'invisibility'
3116 * AND, for players, if they move into a ridiculously unhideable 3078 * AND, for players, if they move into a ridiculously unhideable
3117 * spot (surrounded by clear terrain in broad daylight). -b.t. 3079 * spot (surrounded by clear terrain in broad daylight). -b.t.
3118 */ 3080 */
3119
3120void 3081void
3121do_hidden_move (object *op) 3082do_hidden_move (object *op)
3122{ 3083{
3123 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3084 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW);
3124 object *skop; 3085 object *skop;
3206 * object op. This function works fine for monsters, 3167 * object op. This function works fine for monsters,
3207 * but we dont worry if the object isnt the top one in 3168 * but we dont worry if the object isnt the top one in
3208 * a pile (say a coin under a table would return "viewable" 3169 * a pile (say a coin under a table would return "viewable"
3209 * by this routine). Another question, should we be 3170 * by this routine). Another question, should we be
3210 * concerned with the direction the player is looking 3171 * concerned with the direction the player is looking
3211 * in? Realistically, most of use cant see stuff behind 3172 * in? Realistically, most of us can't see stuff behind
3212 * our backs...on the other hand, does the "facing" direction 3173 * our backs...on the other hand, does the "facing" direction
3213 * imply the way your head, or body is facing? Its possible 3174 * imply the way your head, or body is facing? It's possible
3214 * for them to differ. Sigh, this fctn could get a bit more complex. 3175 * for them to differ. Sigh, this fctn could get a bit more complex.
3215 * -b.t. 3176 * -b.t.
3216 * This function is now map tiling safe. 3177 * This function is now map tiling safe.
3217 */ 3178 */
3218
3219int 3179int
3220player_can_view (object *pl, object *op) 3180player_can_view (object *pl, object *op)
3221{ 3181{
3222 rv_vector rv; 3182 rv_vector rv;
3223 int dx, dy; 3183 int dx, dy;
3235 3195
3236 get_rangevector (pl, op, &rv, 0x1); 3196 get_rangevector (pl, op, &rv, 0x1);
3237 3197
3238 /* starting with the 'head' part, lets loop 3198 /* starting with the 'head' part, lets loop
3239 * through the object and find if it has any 3199 * through the object and find if it has any
3240 * part that is in the los array but isnt on 3200 * part that is in the los array but isn't on
3241 * a blocked los square. 3201 * a blocked los square.
3242 * we use the archetype to figure out offsets. 3202 * we use the archetype to figure out offsets.
3243 */ 3203 */
3244 while (op) 3204 while (op)
3245 { 3205 {
3246 dx = rv.distance_x + op->arch->clone.x; 3206 dx = rv.distance_x + op->arch->x;
3247 dy = rv.distance_y + op->arch->clone.y; 3207 dy = rv.distance_y + op->arch->y;
3248 3208
3249 /* only the viewable area the player sees is updated by LOS 3209 /* only the viewable area the player sees is updated by LOS
3250 * code, so we need to restrict ourselves to that range of values 3210 * code, so we need to restrict ourselves to that range of values
3251 * for any meaningful values. 3211 * for any meaningful values.
3252 */ 3212 */
3253 if (FABS (dx) <= (pl->contr->ns->mapx / 2) && 3213 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3254 FABS (dy) <= (pl->contr->ns->mapy / 2) && 3214 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3255 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)]) 3215 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3256 return 1; 3216 return 1;
3217
3257 op = op->more; 3218 op = op->more;
3258 } 3219 }
3220
3259 return 0; 3221 return 0;
3260} 3222}
3261 3223
3262/* routine for both players and monsters. We call this when 3224/* routine for both players and monsters. We call this when
3263 * there is a possibility for our action distrubing our hiding 3225 * there is a possibility for our action distrubing our hiding
3266 * return 0. 3228 * return 0.
3267 */ 3229 */
3268int 3230int
3269action_makes_visible (object *op) 3231action_makes_visible (object *op)
3270{ 3232{
3271
3272 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3233 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3273 { 3234 {
3274 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3235 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3275 return 0; 3236 return 0;
3276 3237
3282 { 3243 {
3283 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible"); 3244 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->hide ? "unhidden" : "visible");
3284 return 1; 3245 return 1;
3285 } 3246 }
3286 } 3247 }
3248
3287 return 0; 3249 return 0;
3288} 3250}
3289 3251
3290/* op_on_battleground - checks if the given object op (usually 3252/* op_on_battleground - checks if the given object op (usually
3291 * a player) is standing on a valid battleground-tile, 3253 * a player) is standing on a valid battleground-tile,
3296 * Default is to do the same as before, so only people wanting to have different points need worry about this 3258 * Default is to do the same as before, so only people wanting to have different points need worry about this
3297 */ 3259 */
3298int 3260int
3299op_on_battleground (object *op, int *x, int *y) 3261op_on_battleground (object *op, int *x, int *y)
3300{ 3262{
3301 object *tmp;
3302
3303 /* A battleground-tile needs the following attributes to be valid: 3263 /* A battleground-tile needs the following attributes to be valid:
3304 * is_floor 1 (has to be the FIRST floor beneath the player's feet), 3264 * is_floor 1 (has to be the FIRST floor beneath the player's feet),
3305 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND) 3265 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND)
3306 * and the exit-coordinates sp/hp must both be > 0. 3266 * and the exit-coordinates sp/hp must both be > 0.
3307 * => The intention here is to prevent abuse of the battleground- 3267 * => The intention here is to prevent abuse of the battleground-
3308 * feature (like pickable or hidden battleground tiles). */ 3268 * feature (like pickable or hidden battleground tiles). */
3309 for (tmp = op->below; tmp != NULL; tmp = tmp->below) 3269 for (object *tmp = op->below; tmp; tmp = tmp->below)
3310 { 3270 {
3311 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3271 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
3312 { 3272 {
3313 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && 3273 if (QUERY_FLAG (tmp, FLAG_NO_PICK)
3314 strcmp (tmp->name, "battleground") == 0 && tmp->type == BATTLEGROUND && EXIT_X (tmp) && EXIT_Y (tmp)) 3274 && tmp->type == BATTLEGROUND
3275 && tmp->name == shstr_battleground
3276 && EXIT_X (tmp) && EXIT_Y (tmp))
3315 { 3277 {
3316 /*before we assign the exit, check if this is a teambattle */ 3278 /* before we assign the exit, check if this is a teambattle */
3317 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3279 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3318 { 3280 {
3319 object *invtmp;
3320
3321 for (invtmp = op->inv; invtmp != NULL; invtmp = invtmp->below) 3281 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3322 { 3282 {
3323 if (invtmp->type == FORCE && invtmp->slaying && !strcmp (EXIT_PATH (tmp), invtmp->slaying)) 3283 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3324 { 3284 {
3325 if (x != NULL && y != NULL) 3285 if (x && y)
3326 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3286 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3287
3327 return 1; 3288 return 1;
3328 } 3289 }
3329 } 3290 }
3330 } 3291 }
3292
3331 if (x != NULL && y != NULL) 3293 if (x && y)
3332 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3294 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3295
3333 return 1; 3296 return 1;
3334 } 3297 }
3335 } 3298 }
3336 } 3299 }
3300
3337 /* If we got here, did not find a battleground */ 3301 /* If we got here, did not find a battleground */
3338 return 0; 3302 return 0;
3339} 3303}
3340 3304
3341/* 3305/*
3357 char buf[MAX_BUF]; /* tmp. string buffer */ 3321 char buf[MAX_BUF]; /* tmp. string buffer */
3358 int i = 0, j = 0; 3322 int i = 0, j = 0;
3359 3323
3360 /* get the appropriate treasurelist */ 3324 /* get the appropriate treasurelist */
3361 if (atnr == ATNR_FIRE) 3325 if (atnr == ATNR_FIRE)
3362 trlist = treasurelist::find ("dragon_ability_fire"); 3326 trlist = treasurelist::find (shstr_dragon_ability_fire);
3363 else if (atnr == ATNR_COLD) 3327 else if (atnr == ATNR_COLD)
3364 trlist = treasurelist::find ("dragon_ability_cold"); 3328 trlist = treasurelist::find (shstr_dragon_ability_cold);
3365 else if (atnr == ATNR_ELECTRICITY) 3329 else if (atnr == ATNR_ELECTRICITY)
3366 trlist = treasurelist::find ("dragon_ability_elec"); 3330 trlist = treasurelist::find (shstr_dragon_ability_elec);
3367 else if (atnr == ATNR_POISON) 3331 else if (atnr == ATNR_POISON)
3368 trlist = treasurelist::find ("dragon_ability_poison"); 3332 trlist = treasurelist::find (shstr_dragon_ability_poison);
3369 3333
3370 if (trlist == NULL || who->type != PLAYER) 3334 if (trlist == NULL || who->type != PLAYER)
3371 return; 3335 return;
3372 3336
3373 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); 3337 for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++);
3377 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ 3341 /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
3378 return; 3342 return;
3379 } 3343 }
3380 3344
3381 /* everything seems okay - now bring on the gift: */ 3345 /* everything seems okay - now bring on the gift: */
3382 item = &(tr->item->clone); 3346 item = tr->item;
3383 3347
3384 if (item->type == SPELL) 3348 if (item->type == SPELL)
3385 { 3349 {
3386 if (check_spell_known (who, item->name)) 3350 if (check_spell_known (who, item->name))
3387 return; 3351 return;
3446 { 3410 {
3447 /* forces in the treasurelist can alter the player's stats */ 3411 /* forces in the treasurelist can alter the player's stats */
3448 object *skin; 3412 object *skin;
3449 3413
3450 /* first get the dragon skin force */ 3414 /* first get the dragon skin force */
3451 shstr_cmp dragon_skin_force ("dragon_skin_force");
3452 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below) 3415 for (skin = who->inv; skin && !(skin->arch->archname == shstr_dragon_skin_force); skin = skin->below)
3453 ; 3416 ;
3454 3417
3455 if (!skin) 3418 if (!skin)
3456 return; 3419 return;
3457 3420
3533 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy)) 3496 if (!IN_RANGE_EXC (x, 0, ns->mapx) || !IN_RANGE_EXC (y, 0, ns->mapy))
3534 return 0; 3497 return 0;
3535 3498
3536 return 100 - blocked_los [x][y]; 3499 return 100 - blocked_los [x][y];
3537} 3500}
3501
3502void
3503player::infobox (const char *title, const char *msg, int color)
3504{
3505 send_msg (color | NDI_DEF | NDI_REPLY | NDI_CLEAR, title, msg);
3506}
3507
3508void
3509player::statusmsg (const char *msg, int color)
3510{
3511 send_msg (color | NDI_REPLY, INFO_CHANNEL, msg);
3512}
3513
3514void
3515player::failmsg (const char *msg, int color)
3516{
3517 play_sound (sound_find ("generic_failure"));
3518 statusmsg (msg, color);
3519}
3520

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines