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.127 by root, Sat May 12 18:14:48 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 */
303
304 ob->flag [FLAG_READY_WEAPON] = false;
305 ob->flag [FLAG_READY_SKILL] = false;
306 ob->flag [FLAG_READY_BOW] = false;
262 307
263 for (object *op = ob->inv; op; op = op->below) 308 for (object *op = ob->inv; op; op = op->below)
264 if (op->flag [FLAG_APPLIED]) 309 if (op->flag [FLAG_APPLIED])
265 switch (op->type) 310 switch (op->type)
266 { 311 {
312 case SKILL:
313 ob->flag [FLAG_APPLIED] = false;
314 break;
315
267 case WAND: 316 case WAND:
268 case ROD: 317 case ROD:
269 case HORN: 318 case HORN:
270 case BOW: 319 case BOW:
271 case SKILL: 320 ranged_ob = op;
272 case SKILL_TOOL: 321 break;
322
273 case WEAPON: 323 case WEAPON:
274 apply_special (ob, op, AP_UNAPPLY); 324 combat_ob = op;
275 apply_special (ob, op, AP_APPLY);
276 break; 325 break;
277 } 326 }
278 327
279 ob->update_stats (); 328 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
280 ns->floorbox_update (); 329 ob->deactivate (); // change_weapon activates, fix this better
281
282 esrv_send_inventory (ob, ob);
283 esrv_add_spells (this, 0);
284
285 activate ();
286
287 send_rules (ob);
288 send_news (ob);
289 display_motd (ob);
290
291 INVOKE_PLAYER (CONNECT, this);
292 INVOKE_PLAYER (LOGIN, this);
293} 330}
294 331
295void 332void
296player::disconnect ()
297{
298 if (ns)
299 {
300 if (active)
301 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
302
303 INVOKE_PLAYER (DISCONNECT, this);
304
305 ns->reset_stats ();
306 ns->pl = 0;
307 ns = 0;
308 }
309
310 if (ob)
311 ob->close_container (); //TODO: client-specific
312
313 deactivate ();
314}
315
316// the need for this function can be explained
317// by load_object not returning the object
318void
319player::set_object (object *op) 333player::set_observe (object *op)
320{ 334{
321 ob = op; 335 observe = op ? op : ob;
322 ob->contr = this; /* this aren't yet in archetype */ 336 do_los = 1;
323
324 ob->speed_left = 0.5;
325 ob->speed = 1.0;
326 ob->direction = 5; /* So player faces south */
327} 337}
328 338
329player::player () 339player::player ()
330{ 340{
331 /* There are some elements we want initialised to non zero value - 341 /* There are some elements we want initialised to non zero value -
338 savebed_map = first_map_path; /* Init. respawn position */ 348 savebed_map = first_map_path; /* Init. respawn position */
339 349
340 gen_sp_armour = 10; 350 gen_sp_armour = 10;
341 bowtype = bow_normal; 351 bowtype = bow_normal;
342 petmode = pet_normal; 352 petmode = pet_normal;
343 listening = 10;
344 usekeys = containers; 353 usekeys = containers;
345 peaceful = 1; /* default peaceful */ 354 peaceful = 1; /* default peaceful */
346 do_los = 1; 355 do_los = 1;
356
357 weapon_sp = 1.0f;
358 weapon_sp_left = 0.5f;
347} 359}
348 360
349void 361void
350player::do_destroy () 362player::do_destroy ()
351{ 363{
356 if (ob) 368 if (ob)
357 { 369 {
358 ob->destroy_inv (false); 370 ob->destroy_inv (false);
359 ob->destroy (); 371 ob->destroy ();
360 } 372 }
373
374 ob = observe = 0;
361} 375}
362 376
363player::~player () 377player::~player ()
364{ 378{
365 /* Clear item stack */ 379 /* Clear item stack */
392 * Note: there MUST be at least one player archetype! 406 * Note: there MUST be at least one player archetype!
393 */ 407 */
394archetype * 408archetype *
395get_player_archetype (archetype *at) 409get_player_archetype (archetype *at)
396{ 410{
397 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);
398 418
399 for (;;) 419 for (;;)
400 { 420 {
401 if (at == NULL || at->next == NULL) 421 if (++i == archetypes.end ())
402 at = first_archetype; 422 i = archetypes.begin ();
403 else 423 else if (*i == at)
404 at = at->next; 424 cleanup ("not a single player archetype found");
405 425
406 if (at->clone.type == PLAYER) 426 if ((*i)->type == PLAYER)
407 return at; 427 return *i;
408
409 if (at == start)
410 {
411 LOG (llevError, "No Player archetypes\n");
412 exit (-1);
413 }
414 } 428 }
415} 429}
416 430
417object * 431object *
418get_nearest_player (object *mon) 432get_nearest_player (object *mon)
422 unsigned lastdist; 436 unsigned lastdist;
423 rv_vector rv; 437 rv_vector rv;
424 438
425 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next) 439 for (ol = first_friendly_object, lastdist = 1000; ol; ol = ol->next)
426 { 440 {
427 /* We should not find free objects on this friendly list, but it
428 * does periodically happen. Given that, lets deal with it.
429 * While unlikely, it is possible the next object on the friendly
430 * list is also free, so encapsulate this in a while loop.
431 */
432 while (QUERY_FLAG (ol->ob, FLAG_FREED) || !QUERY_FLAG (ol->ob, FLAG_FRIENDLY))
433 {
434 object *tmp = ol->ob;
435
436 /* Can't do much more other than log the fact, because the object
437 * itself will have been cleared.
438 */
439 LOG (llevDebug, "get_nearest_player: Found free/non friendly object '%s' on friendly list\n",
440 tmp->debug_desc ());
441 ol = ol->next;
442 remove_friendly_object (tmp);
443 if (!ol)
444 return op;
445 }
446
447 /* Remove special check for player from this. First, it looks to cause
448 * some crashes (ol->ob->contr not set properly?), but secondly, a more
449 * complicated method of state checking would be needed in any case -
450 * as it was, a clever player could type quit, and the function would
451 * skip them over while waiting for confirmation. Remove
452 * on_same_map check, as can_detect_enemy also does this
453 */
454 if (!can_detect_enemy (mon, ol->ob, &rv)) 441 if (!can_detect_enemy (mon, ol->ob, &rv))
455 continue; 442 continue;
456 443
457 if (lastdist > rv.distance) 444 if (lastdist > rv.distance)
458 { 445 {
653 640
654 return firstdir; 641 return firstdir;
655} 642}
656 643
657void 644void
658give_initial_items (object *pl, treasurelist * items) 645give_initial_items (object *pl, treasurelist *items)
659{ 646{
660 object *op, *next = NULL;
661
662 if (pl->randomitems != NULL) 647 if (pl->randomitems)
663 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 648 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
664 649
665 for (op = pl->inv; op; op = next) 650 for (object *next, *op = pl->inv; op; op = next)
666 { 651 {
667 next = op->below; 652 next = op->below;
668 653
669 /* Forces get applied per default, unless they have the 654 /* Forces get applied per default, unless they have the
670 * 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
675 /* we never give weapons/armour if these cannot be used 660 /* we never give weapons/armour if these cannot be used
676 * by this player due to race restrictions 661 * by this player due to race restrictions
677 */ 662 */
678 if (pl->type == PLAYER) 663 if (pl->type == PLAYER)
679 { 664 {
680 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 665 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
666 &&
681 (op->type == ARMOUR || op->type == BOOTS || 667 (op->type == ARMOUR || op->type == BOOTS
682 op->type == CLOAK || op->type == HELMET || 668 || op->type == CLOAK || op->type == HELMET
683 op->type == SHIELD || op->type == GLOVES || 669 || op->type == SHIELD || op->type == GLOVES
670 || op->type == BRACERS || op->type == GIRDLE))
684 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))
685 { 672 {
686 op->destroy (); 673 op->destroy ();
687 continue; 674 continue;
688 } 675 }
689 } 676 }
712 if (op->nrof > 1) 699 if (op->nrof > 1)
713 op->nrof = 1; 700 op->nrof = 1;
714 } 701 }
715 702
716 if (op->type == SPELLBOOK && op->inv) 703 if (op->type == SPELLBOOK && op->inv)
717 {
718 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 704 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
719 }
720 705
721 /* Give starting characters identified, uncursed, and undamned 706 /* Give starting characters identified, uncursed, and undamned
722 * 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
723 * merged properly. 708 * merged properly.
724 */ 709 */
725 if (need_identify (op)) 710 if (need_identify (op))
726 { 711 {
727 SET_FLAG (op, FLAG_IDENTIFIED); 712 SET_FLAG (op, FLAG_IDENTIFIED);
728 CLEAR_FLAG (op, FLAG_CURSED); 713 CLEAR_FLAG (op, FLAG_CURSED);
729 CLEAR_FLAG (op, FLAG_DAMNED); 714 CLEAR_FLAG (op, FLAG_DAMNED);
730 } 715 }
716
731 if (op->type == SPELL) 717 if (op->type == SPELL)
732 { 718 {
733 op->destroy (); 719 op->destroy ();
734 continue; 720 continue;
735 } 721 }
737 { 723 {
738 SET_FLAG (op, FLAG_CAN_USE_SKILL); 724 SET_FLAG (op, FLAG_CAN_USE_SKILL);
739 op->stats.exp = 0; 725 op->stats.exp = 0;
740 op->level = 1; 726 op->level = 1;
741 } 727 }
742 /* lock all 'normal items by default */ 728 else /* lock all 'normal items by default */
743 else
744 SET_FLAG (op, FLAG_INV_LOCKED); 729 SET_FLAG (op, FLAG_INV_LOCKED);
745 } /* for loop of objects in player inv */ 730 } /* for loop of objects in player inv */
746 731
747 /* Need to set up the skill pointers */ 732 /* Need to set up the skill pointers */
748 link_player_skills (pl); 733 link_player_skills (pl);
784} 769}
785 770
786void 771void
787object::roll_stats () 772object::roll_stats ()
788{ 773{
789 int statsort [7]; 774 int statsort [NUM_STATS];
790 775
791 for (;;) 776 for (;;)
792 { 777 {
793 int sum = 0; 778 int sum = 0;
794 for (int i = 7; i--; ) 779 for (int i = NUM_STATS; i--; )
795 sum += statsort [i] = roll_stat (); 780 sum += statsort [i] = roll_stat ();
796 781
797 if (sum >= 82 && sum <= 116) 782 if (sum >= 82 && sum <= 116)
798 break; 783 break;
799 } 784 }
800 785
801 // Sort the stats so that rerolling is easier... 786 // Sort the stats so that rerolling is easier...
802 std::sort (statsort, statsort + 7, std::greater<int>()); 787 std::sort (statsort, statsort + NUM_STATS, std::greater<int>());
803 788
789 for (int i = 0; i < NUM_STATS; ++i)
804 stats.Str = statsort[0]; 790 stats.stat (i) = statsort [i];
805 stats.Dex = statsort[1];
806 stats.Con = statsort[2];
807 stats.Int = statsort[3];
808 stats.Wis = statsort[4];
809 stats.Pow = statsort[5];
810 stats.Cha = statsort[6];
811 791
812 stats.exp = 0; 792 stats.exp = 0;
813 stats.ac = 0; 793 stats.ac = 0;
814 794
815 stats.hp = stats.maxhp; 795 stats.hp = stats.maxhp;
859static void 839static void
860start_info (object *op) 840start_info (object *op)
861{ 841{
862 char buf[MAX_BUF]; 842 char buf[MAX_BUF];
863 843
864 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 844 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
865 new_draw_info (NDI_UNIQUE, 0, op, buf); 845 new_draw_info (NDI_UNIQUE, 0, op, buf);
866 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
867 //new_draw_info (NDI_UNIQUE, 0, op, " ");
868} 846}
869 847
870/* This function takes the key that is passed, and does the 848/* This function takes the key that is passed, and does the
871 * appropriate action with it (change race, or other things). 849 * appropriate action with it (change race, or other things).
872 * The function name is for historical reasons - now we have 850 * The function name is for historical reasons - now we have
875 */ 853 */
876void 854void
877player::chargen_race_done () 855player::chargen_race_done ()
878{ 856{
879 /* this must before then initial items are given */ 857 /* this must before then initial items are given */
880 esrv_new_player (ob->contr, ob->weight + ob->carrying); 858 esrv_new_player (ob->contr);
881 859
882 treasurelist *tl = treasurelist::find ("starting_wealth"); 860 treasurelist *tl = treasurelist::find ("starting_wealth");
883 if (tl) 861 if (tl)
884 create_treasure (tl, ob, 0, 0, 0); 862 create_treasure (tl, ob, 0, 0, 0);
885 863
888 866
889 ob->contr->ns->state = ST_PLAYING; 867 ob->contr->ns->state = ST_PLAYING;
890 868
891 if (ob->msg) 869 if (ob->msg)
892 ob->msg = 0; 870 ob->msg = 0;
893
894 /* We create this now because some of the unique maps will need it
895 * to save here.
896 */
897 {
898 char buf[MAX_BUF];
899 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, &ob->name);
900 make_path_to_file (buf);
901 }
902 871
903 start_info (ob); 872 start_info (ob);
904 CLEAR_FLAG (ob, FLAG_WIZ); 873 CLEAR_FLAG (ob, FLAG_WIZ);
905 give_initial_items (ob, ob->randomitems); 874 give_initial_items (ob, ob->randomitems);
906 link_player_skills (ob); 875 link_player_skills (ob);
909 878
910 /* This moves the player to a different start map, if there 879 /* This moves the player to a different start map, if there
911 * is one for this race 880 * is one for this race
912 */ 881 */
913 if (*first_map_ext_path) 882 if (*first_map_ext_path)
914 { 883 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
915 object *tmp;
916 char mapname[MAX_BUF];
917
918 snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &ob->arch->name);
919 tmp = object::create ();
920 EXIT_PATH (tmp) = mapname;
921 EXIT_X (tmp) = ob->x;
922 EXIT_Y (tmp) = ob->y;
923 ob->enter_exit (tmp); /* we don't really care if it succeeded;
924 * if the map isn't there, then stay on the
925 * default initial map */
926 tmp->destroy ();
927 }
928 else 884 else
929 LOG (llevDebug, "first_map_ext_path not set\n"); 885 LOG (llevDebug, "first_map_ext_path not set\n");
930} 886}
931 887
932void 888void
942 int x = ob->x, y = ob->y; 898 int x = ob->x, y = ob->y;
943 899
944 ob->remove_statbonus (); 900 ob->remove_statbonus ();
945 ob->remove (); 901 ob->remove ();
946 ob->arch = get_player_archetype (ob->arch); 902 ob->arch = get_player_archetype (ob->arch);
947 ob->arch->clone.copy_to (ob); 903 ob->arch->copy_to (ob);
948 ob->instantiate (); 904 ob->instantiate ();
949 ob->stats = ob->contr->orig_stats; 905 ob->stats = ob->contr->orig_stats;
950 ob->name = ob->name_pl = name; 906 ob->name = ob->name_pl = name;
951 ob->x = x; 907 ob->x = x;
952 ob->y = y; 908 ob->y = y;
953 SET_ANIMATION (ob, 2); /* So player faces south */ 909 SET_ANIMATION (ob, 2); /* So player faces south */
954 insert_ob_in_map (ob, ob->map, ob, 0); 910 insert_ob_in_map (ob, ob->map, ob, 0);
955 assign (ob->contr->title, ob->arch->clone.name); 911 assign (ob->contr->title, ob->arch->object::name);
956 ob->add_statbonus (); 912 ob->add_statbonus ();
957 } 913 }
958 while (!allowed_class (ob)); 914 while (!allowed_class (ob));
959 915
960 update_object (ob, UP_OBJ_FACE); 916 update_object (ob, UP_OBJ_FACE);
1035 if (op->move_type & MOVE_FLYING) 991 if (op->move_type & MOVE_FLYING)
1036 return 1; 992 return 1;
1037 993
1038 next = op->below; 994 next = op->below;
1039 995
996 int cnt = MAX_ITEM_PER_DROP;
997#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
998
1040 /* 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
1041 * destroyed */ 1000 * destroyed */
1042 while (next && !next->destroyed ()) 1001 while (next && !next->destroyed ())
1043 { 1002 {
1044 tmp = next; 1003 tmp = next;
1045 next = tmp->below; 1004 next = tmp->below;
1046 1005
1006 if (cnt <= 0)
1007 {
1008 op->failmsg ("Couldn't pickup all items at once.");
1009 return 0;
1010 }
1011
1047 if (op->destroyed ()) 1012 if (op->destroyed ())
1048 return 0; 1013 return 0;
1049 1014
1050 if (!can_pick (op, tmp)) 1015 if (!can_pick (op, tmp))
1051 continue; 1016 continue;
1052 1017
1053 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1018 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1054 { 1019 {
1055 if (item_matched_string (op, tmp, op->contr->search_str)) 1020 if (item_matched_string (op, tmp, op->contr->search_str))
1056 pick_up (op, tmp); 1021 CHK_PICK_PICKUP;
1057 continue; 1022 continue;
1058 } 1023 }
1059 1024
1060 /* high not bit set? We're using the old autopickup model */ 1025 /* high not bit set? We're using the old autopickup model */
1061 if (!(op->contr->mode & PU_NEWMODE)) 1026 if (!(op->contr->mode & PU_NEWMODE))
1063 switch (op->contr->mode) 1028 switch (op->contr->mode)
1064 { 1029 {
1065 case 0: 1030 case 0:
1066 return 1; /* don't pick up */ 1031 return 1; /* don't pick up */
1067 case 1: 1032 case 1:
1068 pick_up (op, tmp); 1033 CHK_PICK_PICKUP;
1069 return 1; 1034 return 1;
1070 case 2: 1035 case 2:
1071 pick_up (op, tmp); 1036 CHK_PICK_PICKUP;
1072 return 0; 1037 return 0;
1073 case 3: 1038 case 3:
1074 return 0; /* stop before pickup */ 1039 return 0; /* stop before pickup */
1075 case 4: 1040 case 4:
1076 pick_up (op, tmp); 1041 CHK_PICK_PICKUP;
1077 break; 1042 break;
1078 case 5: 1043 case 5:
1079 pick_up (op, tmp); 1044 CHK_PICK_PICKUP;
1080 stop = 1; 1045 stop = 1;
1081 break; 1046 break;
1082 case 6: 1047 case 6:
1083 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1048 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1084 pick_up (op, tmp); 1049 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1050 CHK_PICK_PICKUP;
1085 break; 1051 break;
1086 1052
1087 case 7: 1053 case 7:
1088 if (tmp->type == MONEY || tmp->type == GEM) 1054 if (tmp->type == MONEY || tmp->type == GEM)
1089 pick_up (op, tmp); 1055 CHK_PICK_PICKUP;
1090 break; 1056 break;
1091 1057
1092 default: 1058 default:
1093 /* use value density */ 1059 /* use value density */
1094 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1060 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1095 && (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)
1096 pick_up (op, tmp); 1062 CHK_PICK_PICKUP;
1097 } 1063 }
1098 } 1064 }
1099 else 1065 else
1100 { /* old model */ 1066 { /* old model */
1101 /* NEW pickup handling */ 1067 /* NEW pickup handling */
1105 if (tmp->name != NULL) 1071 if (tmp->name != NULL)
1106 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1072 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1107 &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))));
1108 else 1074 else
1109 sprintf (putstring, "item name: %s item type: %d weight/value: %d", 1075 sprintf (putstring, "item name: %s item type: %d weight/value: %d",
1110 &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))));
1111 1077
1112 new_draw_info (NDI_UNIQUE, 0, op, putstring); 1078 new_draw_info (NDI_UNIQUE, 0, op, putstring);
1113 } 1079 }
1114 1080
1115 /* philosophy: 1081 /* philosophy:
1156 /* all food and drink if desired */ 1122 /* all food and drink if desired */
1157 /* question: don't pick up known-poisonous stuff? */ 1123 /* question: don't pick up known-poisonous stuff? */
1158 if (op->contr->mode & PU_FOOD) 1124 if (op->contr->mode & PU_FOOD)
1159 if (tmp->type == FOOD) 1125 if (tmp->type == FOOD)
1160 { 1126 {
1161 pick_up (op, tmp); 1127 CHK_PICK_PICKUP;
1162 continue; 1128 continue;
1163 } 1129 }
1164 1130
1165 if (op->contr->mode & PU_DRINK) 1131 if (op->contr->mode & PU_DRINK)
1166 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)))
1167 { 1133 {
1168 pick_up (op, tmp); 1134 CHK_PICK_PICKUP;
1169 continue; 1135 continue;
1170 } 1136 }
1171 1137
1172 if (op->contr->mode & PU_POTION) 1138 if (op->contr->mode & PU_POTION)
1173 if (tmp->type == POTION) 1139 if (tmp->type == POTION)
1174 { 1140 {
1175 pick_up (op, tmp); 1141 CHK_PICK_PICKUP;
1176 continue; 1142 continue;
1177 } 1143 }
1178 1144
1179 /* spellbooks, skillscrolls and normal books/scrolls */ 1145 /* spellbooks, skillscrolls and normal books/scrolls */
1180 if (op->contr->mode & PU_SPELLBOOK) 1146 if (op->contr->mode & PU_SPELLBOOK)
1181 if (tmp->type == SPELLBOOK) 1147 if (tmp->type == SPELLBOOK)
1182 { 1148 {
1183 pick_up (op, tmp); 1149 CHK_PICK_PICKUP;
1184 continue; 1150 continue;
1185 } 1151 }
1186 1152
1187 if (op->contr->mode & PU_SKILLSCROLL) 1153 if (op->contr->mode & PU_SKILLSCROLL)
1188 if (tmp->type == SKILLSCROLL) 1154 if (tmp->type == SKILLSCROLL)
1189 { 1155 {
1190 pick_up (op, tmp); 1156 CHK_PICK_PICKUP;
1191 continue; 1157 continue;
1192 } 1158 }
1193 1159
1194 if (op->contr->mode & PU_READABLES) 1160 if (op->contr->mode & PU_READABLES)
1195 if (tmp->type == BOOK || tmp->type == SCROLL) 1161 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1196 { 1162 {
1197 pick_up (op, tmp); 1163 CHK_PICK_PICKUP;
1198 continue; 1164 continue;
1199 } 1165 }
1200 1166
1201 /* wands/staves/rods/horns */ 1167 /* wands/staves/rods/horns */
1202 if (op->contr->mode & PU_MAGIC_DEVICE) 1168 if (op->contr->mode & PU_MAGIC_DEVICE)
1203 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1169 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1204 { 1170 {
1205 pick_up (op, tmp); 1171 CHK_PICK_PICKUP;
1206 continue; 1172 continue;
1207 } 1173 }
1208 1174
1209 /* pick up all magical items */ 1175 /* pick up all magical items */
1210 if (op->contr->mode & PU_MAGICAL) 1176 if (op->contr->mode & PU_MAGICAL)
1211 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))
1212 { 1178 {
1213 pick_up (op, tmp); 1179 CHK_PICK_PICKUP;
1214 continue; 1180 continue;
1215 } 1181 }
1216 1182
1217 if (op->contr->mode & PU_VALUABLES) 1183 if (op->contr->mode & PU_VALUABLES)
1218 { 1184 {
1219 if (tmp->type == MONEY || tmp->type == GEM) 1185 if (tmp->type == MONEY || tmp->type == GEM)
1220 { 1186 {
1221 pick_up (op, tmp); 1187 CHK_PICK_PICKUP;
1222 continue; 1188 continue;
1223 } 1189 }
1224 } 1190 }
1225 1191
1226 /* rings & amulets - talismans seems to be typed AMULET */ 1192 /* rings & amulets - talismans seems to be typed AMULET */
1227 if (op->contr->mode & PU_JEWELS) 1193 if (op->contr->mode & PU_JEWELS)
1228 if (tmp->type == RING || tmp->type == AMULET) 1194 if (tmp->type == RING || tmp->type == AMULET)
1229 { 1195 {
1230 pick_up (op, tmp); 1196 CHK_PICK_PICKUP;
1231 continue; 1197 continue;
1232 } 1198 }
1233 1199
1234 /* we don't forget dragon food */ 1200 /* we don't forget dragon food */
1235 if (op->contr->mode & PU_FLESH) 1201 if (op->contr->mode & PU_FLESH)
1236 if (tmp->type == FLESH) 1202 if (tmp->type == FLESH)
1237 { 1203 {
1238 pick_up (op, tmp); 1204 CHK_PICK_PICKUP;
1239 continue; 1205 continue;
1240 } 1206 }
1241 1207
1242 /* bows and arrows. Bows are good for selling! */ 1208 /* bows and arrows. Bows are good for selling! */
1243 if (op->contr->mode & PU_BOW) 1209 if (op->contr->mode & PU_BOW)
1244 if (tmp->type == BOW) 1210 if (tmp->type == BOW)
1245 { 1211 {
1246 pick_up (op, tmp); 1212 CHK_PICK_PICKUP;
1247 continue; 1213 continue;
1248 } 1214 }
1249 1215
1250 if (op->contr->mode & PU_ARROW) 1216 if (op->contr->mode & PU_ARROW)
1251 if (tmp->type == ARROW) 1217 if (tmp->type == ARROW)
1252 { 1218 {
1253 pick_up (op, tmp); 1219 CHK_PICK_PICKUP;
1254 continue; 1220 continue;
1255 } 1221 }
1256 1222
1257 /* all kinds of armor etc. */ 1223 /* all kinds of armor etc. */
1258 if (op->contr->mode & PU_ARMOUR) 1224 if (op->contr->mode & PU_ARMOUR)
1259 if (tmp->type == ARMOUR) 1225 if (tmp->type == ARMOUR)
1260 { 1226 {
1261 pick_up (op, tmp); 1227 CHK_PICK_PICKUP;
1262 continue; 1228 continue;
1263 } 1229 }
1264 1230
1265 if (op->contr->mode & PU_HELMET) 1231 if (op->contr->mode & PU_HELMET)
1266 if (tmp->type == HELMET) 1232 if (tmp->type == HELMET)
1267 { 1233 {
1268 pick_up (op, tmp); 1234 CHK_PICK_PICKUP;
1269 continue; 1235 continue;
1270 } 1236 }
1271 1237
1272 if (op->contr->mode & PU_SHIELD) 1238 if (op->contr->mode & PU_SHIELD)
1273 if (tmp->type == SHIELD) 1239 if (tmp->type == SHIELD)
1274 { 1240 {
1275 pick_up (op, tmp); 1241 CHK_PICK_PICKUP;
1276 continue; 1242 continue;
1277 } 1243 }
1278 1244
1279 if (op->contr->mode & PU_BOOTS) 1245 if (op->contr->mode & PU_BOOTS)
1280 if (tmp->type == BOOTS) 1246 if (tmp->type == BOOTS)
1281 { 1247 {
1282 pick_up (op, tmp); 1248 CHK_PICK_PICKUP;
1283 continue; 1249 continue;
1284 } 1250 }
1285 1251
1286 if (op->contr->mode & PU_GLOVES) 1252 if (op->contr->mode & PU_GLOVES)
1287 if (tmp->type == GLOVES) 1253 if (tmp->type == GLOVES)
1288 { 1254 {
1289 pick_up (op, tmp); 1255 CHK_PICK_PICKUP;
1290 continue; 1256 continue;
1291 } 1257 }
1292 1258
1293 if (op->contr->mode & PU_CLOAK) 1259 if (op->contr->mode & PU_CLOAK)
1294 if (tmp->type == CLOAK) 1260 if (tmp->type == CLOAK)
1295 { 1261 {
1296 pick_up (op, tmp); 1262 CHK_PICK_PICKUP;
1297 continue; 1263 continue;
1298 } 1264 }
1299 1265
1300 /* hoping to catch throwing daggers here */ 1266 /* hoping to catch throwing daggers here */
1301 if (op->contr->mode & PU_MISSILEWEAPON) 1267 if (op->contr->mode & PU_MISSILEWEAPON)
1302 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1268 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1303 { 1269 {
1304 pick_up (op, tmp); 1270 CHK_PICK_PICKUP;
1305 continue; 1271 continue;
1306 } 1272 }
1307 1273
1308 /* careful: chairs and tables are weapons! */ 1274 /* careful: chairs and tables are weapons! */
1309 if (op->contr->mode & PU_ALLWEAPON) 1275 if (op->contr->mode & PU_ALLWEAPON)
1310 { 1276 {
1311 if (tmp->type == WEAPON && tmp->name != NULL) 1277 if (tmp->type == WEAPON && tmp->name != NULL)
1312 { 1278 {
1313 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 &&
1314 strstr (tmp->name, "chair") && strstr (tmp->arch->name, "chair") == NULL) 1280 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1315 { 1281 {
1316 pick_up (op, tmp); 1282 CHK_PICK_PICKUP;
1317 continue; 1283 continue;
1318 } 1284 }
1319 } 1285 }
1320 1286
1321 if (tmp->type == WEAPON && tmp->name == NULL) 1287 if (tmp->type == WEAPON && tmp->name == NULL)
1322 { 1288 {
1323 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)
1324 { 1290 {
1325 pick_up (op, tmp); 1291 CHK_PICK_PICKUP;
1326 continue; 1292 continue;
1327 } 1293 }
1328 } 1294 }
1329 } 1295 }
1330 1296
1331 /* misc stuff that's useful */ 1297 /* misc stuff that's useful */
1332 if (op->contr->mode & PU_KEY) 1298 if (op->contr->mode & PU_KEY)
1333 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1299 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1334 { 1300 {
1335 pick_up (op, tmp); 1301 CHK_PICK_PICKUP;
1336 continue; 1302 continue;
1337 } 1303 }
1338 1304
1339 /* 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
1340 * pickups */ 1306 * pickups */
1341 if (op->contr->mode & PU_RATIO) 1307 if (op->contr->mode & PU_RATIO)
1342 { 1308 {
1343 /* use value density to decide what else to grab */ 1309 /* use value density to decide what else to grab */
1344 /* >=7 was >= op->contr->mode */ 1310 /* >=7 was >= op->contr->mode */
1345 /* >=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
1346 * and multiply them by 5, giving 0..15*5== 5..75 */ 1312 */
1347 wvratio = (op->contr->mode & PU_RATIO) * 5; 1313 wvratio = op->contr->mode & PU_RATIO;
1348 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)
1349 { 1315 {
1350 pick_up (op, tmp); 1316 CHK_PICK_PICKUP;
1351#if 0 1317#if 0
1352 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1318 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1353 if (tmp->name != NULL) 1319 if (tmp->name != NULL)
1354 { 1320 {
1355 fprintf (stderr, "%s", tmp->name); 1321 fprintf (stderr, "%s", tmp->name);
1356 } 1322 }
1357 else 1323 else
1358 fprintf (stderr, "%s", tmp->arch->name); 1324 fprintf (stderr, "%s", tmp->arch->archname);
1359 fprintf (stderr, ",%d] = ", tmp->type); 1325 fprintf (stderr, ",%d] = ", tmp->type);
1360 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))));
1361#endif 1327#endif
1362 continue; 1328 continue;
1363 } 1329 }
1374 * found object is returned. 1340 * found object is returned.
1375 */ 1341 */
1376object * 1342object *
1377find_arrow (object *op, const char *type) 1343find_arrow (object *op, const char *type)
1378{ 1344{
1379 object *tmp = 0;
1380
1381 for (op = op->inv; op; op = op->below) 1345 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1382 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1383 tmp = find_arrow (op, type);
1384 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);
1385 return op; 1354 return arrow;
1355 }
1386 1356
1387 return tmp; 1357 return 0;
1388} 1358}
1389 1359
1390/* 1360/*
1391 * 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
1392 * 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
1415 } 1385 }
1416 } 1386 }
1417 else if (arrow->type == ARROW && arrow->race == type) 1387 else if (arrow->type == ARROW && arrow->race == type)
1418 { 1388 {
1419 /* allways prefer assasination/slaying */ 1389 /* allways prefer assasination/slaying */
1420 if (target->race != NULL && arrow->slaying != NULL && strstr (arrow->slaying, target->race)) 1390 if (target->race && arrow->slaying && strstr (arrow->slaying, target->race))
1421 { 1391 {
1422 if (arrow->attacktype & AT_DEATH) 1392 if (arrow->attacktype & AT_DEATH)
1423 { 1393 {
1424 *better = 100; 1394 *better = 100;
1425 return arrow; 1395 return arrow;
1433 else 1403 else
1434 { 1404 {
1435 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) 1405 for (attacknum = 0; attacknum < NROFATTACKS; attacknum++)
1436 { 1406 {
1437 attacktype = 1 << attacknum; 1407 attacktype = 1 << attacknum;
1438 if ((arrow->attacktype & attacktype) && (target->arch->clone.resist[attacknum]) < 0) 1408 if ((arrow->attacktype & attacktype) && (target->arch->resist[attacknum]) < 0)
1439 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)
1440 { 1410 {
1441 tmp = arrow; 1411 tmp = arrow;
1442 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;
1443 } 1413 }
1444 } 1414 }
1445 if ((2 + arrow->magic + arrow->stats.dam) > betterby) 1415 if ((2 + arrow->magic + arrow->stats.dam) > betterby)
1446 { 1416 {
1447 tmp = arrow; 1417 tmp = arrow;
1453 betterby = 1 + arrow->magic + arrow->stats.dam; 1423 betterby = 1 + arrow->magic + arrow->stats.dam;
1454 } 1424 }
1455 } 1425 }
1456 } 1426 }
1457 } 1427 }
1428
1458 if (tmp == NULL && arrow == NULL) 1429 if (tmp == NULL && arrow == NULL)
1459 return find_arrow (op, type); 1430 return find_arrow (op, type);
1460 1431
1461 *better = betterby; 1432 *better = betterby;
1462 return tmp; 1433 return tmp;
1540 */ 1511 */
1541int 1512int
1542fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy) 1513fire_bow (object *op, object *part, object *arrow, int dir, int wc_mod, sint16 sx, sint16 sy)
1543{ 1514{
1544 object *left, *bow; 1515 object *left, *bow;
1545 int bowspeed, mflags; 1516 int mflags;
1546 maptile *m; 1517 maptile *m;
1547 1518
1548 if (!dir) 1519 if (!dir)
1549 { 1520 {
1550 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); 1521 new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!");
1551 return 0; 1522 return 0;
1552 } 1523 }
1553 1524
1554 if (player *pl = op->contr) 1525 if (op->contr)
1555 { 1526 bow = op->current_weapon;
1556 bow = pl->ranged_ob;
1557 if (!op->change_weapon (bow))
1558 return 0;
1559 }
1560 else 1527 else
1561 { 1528 {
1562 for (bow = op->inv; bow; bow = bow->below) 1529 for (bow = op->inv; bow; bow = bow->below)
1563 /* Don't check for applied - monsters don't apply bows - in that way, they 1530 /* Don't check for applied - monsters don't apply bows - in that way, they
1564 * don't need to switch back and forth between bows and weapons. 1531 * don't need to switch back and forth between bows and weapons.
1585 { 1552 {
1586 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); 1553 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name);
1587 return 0; 1554 return 0;
1588 } 1555 }
1589 1556
1590 bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex];
1591
1592 /* penalize ROF for bestarrow */
1593 if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
1594 bowspeed -= dex_bonus[op->stats.Dex] + 5;
1595
1596 if (bowspeed < 1)
1597 bowspeed = 1;
1598
1599 if (arrow == NULL) 1557 if (arrow == NULL)
1600 { 1558 {
1601 if ((arrow = find_arrow (op, bow->race)) == NULL) 1559 if ((arrow = find_arrow (op, bow->race)) == NULL)
1602 { 1560 {
1603 if (op->type == PLAYER) 1561 if (op->type == PLAYER)
1626 arrow->destroy (); 1584 arrow->destroy ();
1627 return 0; 1585 return 0;
1628 } 1586 }
1629 1587
1630 left = arrow; /* these are arrows left to the player */ 1588 left = arrow; /* these are arrows left to the player */
1631 arrow = get_split_ob (arrow, 1); 1589 arrow = arrow->split ();
1632 if (!arrow) 1590 if (!arrow)
1633 { 1591 {
1634 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);
1635 return 0; 1593 return 0;
1636 } 1594 }
1644 arrow->stats.grace = arrow->attacktype; 1602 arrow->stats.grace = arrow->attacktype;
1645 1603
1646 if (arrow->slaying) 1604 if (arrow->slaying)
1647 arrow->spellarg = strdup (arrow->slaying); 1605 arrow->spellarg = strdup (arrow->slaying);
1648 1606
1607#if 0
1608 if (player *pl = op->contr)
1609 {
1610 float speed = pl->weapon_sp;
1611
1612 /* penalize ROF for bestarrow */
1613 if (pl->bowtype == bow_bestarrow)
1614 speed *= .9f;
1615 else
1616 speed *= 1.f + dex_bonus[op->stats.Dex] * .2f;
1617
1618 op->speed_left += speed - op->speed;
1619 }
1620#endif
1621
1622 SET_ANIMATION (arrow, arrow->direction);
1623
1624 /* update the speed */
1625 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1626 + bow->stats.dam / 7.f;
1627
1628 arrow->set_speed (max (arrow->speed, 2.f));
1629 arrow->speed_left = 0;
1630
1631 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1632
1649 if (op->type == PLAYER) 1633 if (op->type == PLAYER)
1650 { 1634 {
1651 op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed;
1652 op->update_stats ();
1653 }
1654
1655 SET_ANIMATION (arrow, arrow->direction);
1656
1657 arrow->stats.dam += op->stats.dam + arrow->magic;
1658
1659 /* update the speed */
1660 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0
1661 + bow->stats.dam / 7.0;
1662
1663 arrow->set_speed (max (arrow->speed, 2.0));
1664 arrow->speed_left = 0;
1665
1666 arrow->stats.wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1667
1668 if (op->type == PLAYER)
1669 {
1670 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level; 1635 arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
1671 arrow->stats.wc -= dex_bonus[op->stats.Dex]; 1636 wc -= dex_bonus[op->stats.Dex];
1672 1637
1673 if (!arrow->slaying) 1638 if (!arrow->slaying)
1674 arrow->slaying = op->slaying; 1639 arrow->slaying = op->slaying;
1675 1640
1676 arrow->attacktype |= op->attacktype; 1641 arrow->attacktype |= op->attacktype;
1684 arrow->slaying = bow->slaying; 1649 arrow->slaying = bow->slaying;
1685 1650
1686 arrow->attacktype |= bow->attacktype; 1651 arrow->attacktype |= bow->attacktype;
1687 } 1652 }
1688 1653
1689 arrow->stats.wc -= arrow->level; 1654 wc -= arrow->level;
1655 arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM);
1690 1656
1657 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1691 arrow->move_type = MOVE_FLY_LOW; 1658 arrow->move_type = MOVE_FLY_LOW;
1692 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1659 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1693 1660
1694 play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); 1661 op->play_sound (sound_find ("fire_arrow"));
1695 m->insert (arrow, sx, sy, op); 1662 m->insert (arrow, sx, sy, op);
1696 1663
1697 if (!arrow->destroyed ()) 1664 if (!arrow->destroyed ())
1698 move_arrow (arrow); 1665 move_arrow (arrow);
1699
1700 if (op->type == PLAYER)
1701 {
1702 if (left->destroyed ())
1703 esrv_del_item (op->contr, left->count);
1704 else
1705 esrv_send_item (op, left);
1706 }
1707 1666
1708 return 1; 1667 return 1;
1709} 1668}
1710 1669
1711/* Special fire code for players - this takes into 1670/* Special fire code for players - this takes into
1750 } 1709 }
1751 1710
1752 return ret; 1711 return ret;
1753} 1712}
1754 1713
1755
1756/* Fires a misc (wand/rod/horn) object in 'dir'. 1714/* Fires a misc (wand/rod/horn) object in 'dir'.
1757 * Broken apart from 'fire' to keep it more readable. 1715 * Broken apart from 'fire' to keep it more readable.
1758 */ 1716 */
1759void 1717void
1760fire_misc_object (object *op, int dir) 1718fire_misc_object (object *op, int dir)
1778 1736
1779 if (item->type == WAND) 1737 if (item->type == WAND)
1780 { 1738 {
1781 if (item->stats.food <= 0) 1739 if (item->stats.food <= 0)
1782 { 1740 {
1783 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1741 op->contr->play_sound (sound_find ("wand_poof"));
1784 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));
1785 1743
1786 return; 1744 return;
1787 } 1745 }
1788 } 1746 }
1789 else if (item->type == ROD || item->type == HORN) 1747 else if (item->type == ROD || item->type == HORN)
1790 { 1748 {
1791 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))
1792 { 1754 {
1793 play_sound_player_only (op->contr, SOUND_WAND_POOF, 0, 0); 1755 op->contr->play_sound (sound_find ("wand_poof"));
1794 1756
1795 if (item->type == ROD) 1757 if (item->type == ROD)
1796 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));
1797 else 1759 else
1798 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));
1811 object *tmp; 1773 object *tmp;
1812 1774
1813 if (item->arch) 1775 if (item->arch)
1814 { 1776 {
1815 CLEAR_FLAG (item, FLAG_ANIMATE); 1777 CLEAR_FLAG (item, FLAG_ANIMATE);
1816 item->face = item->arch->clone.face; 1778 item->face = item->arch->face;
1817 item->set_speed (0); 1779 item->set_speed (0);
1818 } 1780 }
1819 1781
1820 if ((tmp = item->in_player ())) 1782 if (object *pl = item->visible_to ())
1821 esrv_update_item (UPD_ANIM, tmp, item); 1783 esrv_update_item (UPD_ANIM, pl, item);
1822 } 1784 }
1823 } 1785 }
1824 else if (item->type == ROD || item->type == HORN) 1786 else if (item->type == ROD || item->type == HORN)
1825 drain_rod_charge (item); 1787 drain_rod_charge (item);
1826 } 1788 }
1827} 1789}
1828 1790
1829/* Received a fire command for the player - go and do it. 1791/* Received a fire command for the player - go and do it.
1830 */ 1792 */
1831void 1793bool
1832fire (object *op, int dir) 1794fire (object *op, int dir)
1833{ 1795{
1834 int spellcost = 0; 1796 int spellcost = 0;
1835 1797
1836 /* check for loss of invisiblity/hide */ 1798 /* check for loss of invisiblity/hide */
1840 player *pl = op->contr; 1802 player *pl = op->contr;
1841 1803
1842 if (pl->golem) 1804 if (pl->golem)
1843 { 1805 {
1844 control_golem (op->contr->golem, dir); 1806 control_golem (op->contr->golem, dir);
1845 return; 1807 return false;
1846 } 1808 }
1847 1809
1848 object *ob = pl->ranged_ob; 1810 object *ob = pl->ranged_ob;
1849 1811
1850 if (!ob) 1812 if (!ob)
1851 return; 1813 return false;
1814
1815 if (!op->change_weapon (ob))
1816 return false;
1817
1818 if (op->speed_left > 0.f)
1819 --op->speed_left;
1820 else
1821 return false;
1852 1822
1853 switch (ob->type) 1823 switch (ob->type)
1854 { 1824 {
1855 case BOW: 1825 case BOW:
1856 player_fire_bow (op, dir); 1826 player_fire_bow (op, dir);
1863 case BUILDER: 1833 case BUILDER:
1864 apply_map_builder (op, dir); 1834 apply_map_builder (op, dir);
1865 break; 1835 break;
1866 1836
1867 case SKILL: 1837 case SKILL:
1868 case SKILL_TOOL:
1869 do_skill (op, op, ob, dir, 0); 1838 do_skill (op, op, ob, dir, 0);
1870 break; 1839 break;
1871 1840
1872 default: 1841 default:
1873 fire_misc_object (op, dir); 1842 fire_misc_object (op, dir);
1874 break; 1843 break;
1875 } 1844 }
1845
1846 return true;
1876} 1847}
1877 1848
1878/* find_key 1849/* find_key
1879 * 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
1880 * and successfully use it, we return the key, otherwise NULL 1851 * and successfully use it, we return the key, otherwise NULL
1967 * 0 otherwise 1938 * 0 otherwise
1968 */ 1939 */
1969static int 1940static int
1970player_attack_door (object *op, object *door) 1941player_attack_door (object *op, object *door)
1971{ 1942{
1972 /* 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,
1973 * 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 -
1974 * otherwise, we fall through to the rest of the code. 1945 * otherwise, we fall through to the rest of the code.
1975 */ 1946 */
1976 object *key = find_key (op, op, door); 1947 object *key = find_key (op, op, door);
1977 1948
1978 /* IF we found a key, do some extra work */ 1949 /* If we found a key, do some extra work */
1979 if (key) 1950 if (key)
1980 { 1951 {
1981 object *container = key->env; 1952 object *container = key->env;
1982
1983 play_sound_map (op->map, op->x, op->y, SOUND_OPEN_DOOR);
1984 1953
1985 if (action_makes_visible (op)) 1954 if (action_makes_visible (op))
1986 make_visible (op); 1955 make_visible (op);
1987 1956
1988 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) 1957 if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
1990 1959
1991 if (door->type == DOOR) 1960 if (door->type == DOOR)
1992 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 */
1993 else if (door->type == LOCKED_DOOR) 1962 else if (door->type == LOCKED_DOOR)
1994 { 1963 {
1995 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);
1996 remove_door2 (door); /* remove door without violence ;-) */ 1965 remove_door2 (door); /* remove door without violence ;-) */
1997 } 1966 }
1998 1967
1999 /* Do this after we print the message */ 1968 /* Do this after we print the message */
2000 decrease_ob (key); /* Use up one of the keys */ 1969 key->decrease (); /* Use up one of the keys */
2001 /* Need to update the weight the container the key was in */
2002 if (container != op)
2003 esrv_update_item (UPD_WEIGHT, op, container);
2004 1970
2005 return 1; /* Nothing more to do below */ 1971 return 1; /* Nothing more to do below */
2006 } 1972 }
2007 else if (door->type == LOCKED_DOOR) 1973 else if (door->type == LOCKED_DOOR)
2008 { 1974 {
2009 /* Might as well return now - no other way to open this */ 1975 /* Might as well return now - no other way to open this */
2010 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...");
2011 return 1; 1977 return 1;
2012 } 1978 }
2013 1979
2014 return 0; 1980 return 0;
2015} 1981}
2018 * It should keep the code cleaner. 1984 * It should keep the code cleaner.
2019 * When this is called, the players direction has been updated 1985 * When this is called, the players direction has been updated
2020 * (taking into account confusion.) The player is also actually 1986 * (taking into account confusion.) The player is also actually
2021 * going to try and move (not fire weapons). 1987 * going to try and move (not fire weapons).
2022 */ 1988 */
2023void 1989bool
2024move_player_attack (object *op, int dir) 1990move_player_attack (object *op, int dir)
2025{ 1991{
2026 object *tmp, *mon;
2027 int on_battleground; 1992 int on_battleground;
2028 maptile *m;
2029 1993
2030 sint16 nx = freearr_x[dir] + op->x; 1994 sint16 nx = freearr_x[dir] + op->x;
2031 sint16 ny = freearr_y[dir] + op->y; 1995 sint16 ny = freearr_y[dir] + op->y;
2032 1996
2033 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 }
2034 2007
2035 /* 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
2036 * 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
2037 * 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
2038 * player. This is a pretty nasty hack, because if we could 2011 * player. This is a pretty nasty hack, because if we could
2039 * 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
2040 * 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
2041 * 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
2042 * move_ob uses. 2015 * move_ob uses.
2043 */ 2016 */
2044 if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny))
2045 {
2046 if (OUT_OF_REAL_MAP (op->map, nx, ny))
2047 {
2048 m = op->map->xy_find (nx, ny); 2017 maptile *m = op->map->xy_find (nx, ny);
2049 if (!m)
2050 return; /* Don't think this should happen */
2051 }
2052 else
2053 m = op->map;
2054 2018
2055 if (!(tmp = m->at (nx, ny).bot))
2056 return;
2057
2058 mon = 0;
2059 /* 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
2060 * 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.
2061 * 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
2062 * on the space 2022 * on the space
2063 */ 2023 */
2064 while (tmp) 2024 object *mon;
2065 { 2025 for (mon = m->at (nx, ny).bot; mon; mon = mon->above)
2066 if (tmp == op) 2026 {
2067 { 2027 if ((mon->flag [FLAG_ALIVE]
2068 tmp = tmp->above; 2028 || mon->type == LOCKED_DOOR
2069 continue; 2029 || mon->flag [FLAG_CAN_ROLL])
2070 }
2071
2072 if (QUERY_FLAG (tmp, FLAG_ALIVE))
2073 {
2074 mon = tmp; 2030 && mon != op)
2075 break; 2031 break;
2076 } 2032 }
2077 2033
2078 if (tmp->type == LOCKED_DOOR || QUERY_FLAG (tmp, FLAG_CAN_ROLL))
2079 mon = tmp;
2080
2081 tmp = tmp->above;
2082 }
2083
2084 if (!mon) /* This happens anytime the player tries to move */ 2034 if (!mon) /* This happens anytime the player tries to move */
2085 return; /* into a wall */ 2035 return false; /* into a wall */
2086 2036
2087 if (mon->head)
2088 mon = mon->head; 2037 mon = mon->head_ ();
2089 2038
2090 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)
2091 if (player_attack_door (op, mon)) 2041 if (player_attack_door (op, mon))
2042 {
2043 --op->contr->weapon_sp_left;
2092 return; 2044 return true;
2045 }
2093 2046
2094 /* The following deals with possibly attacking peaceful 2047 /* The following deals with possibly attacking peaceful
2095 * or frienddly creatures. Basically, all players are considered 2048 * or friendly creatures. Basically, all players are considered
2096 * unaggressive. If the moving player has peaceful set, then the 2049 * unaggressive. If the moving player has peaceful set, then the
2097 * object should be pushed instead of attacked. It is assumed that 2050 * object should be pushed instead of attacked. It is assumed that
2098 * if you are braced, you will not attack friends accidently, 2051 * if you are braced, you will not attack friends accidently,
2099 * and thus will not push them. 2052 * and thus will not push them.
2100 */ 2053 */
2101 2054
2102 /* 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
2103 * peaceful. Our assumption is the creature is a pet if the 2056 * peaceful. Our assumption is the creature is a pet if the
2104 * player owns it and it is either friendly or unagressive. 2057 * player owns it and it is either friendly or unagressive.
2105 */ 2058 */
2106 if ((op->type == PLAYER) 2059 if (op->type == PLAYER
2107#if COZY_SERVER
2108 &&
2109 ((mon->owner && mon->owner->contr 2060 && ((mon->owner && mon->owner->contr
2110 && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op) 2061 && same_party (mon->owner->contr->party, op->contr->party))
2111#else
2112 && mon->owner == op 2062 || mon->owner == op)
2113#endif
2114 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 2063 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)))
2115 { 2064 {
2116 /* 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 */
2117 if (op->contr->braced) 2066 if (op->contr->braced)
2118 return; 2067 return false;
2119 2068
2120 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"));
2121 push_ob (mon, dir, op); 2074 push_ob (mon, dir, op);
2075
2122 if (op->contr->tmp_invis || op->hide) 2076 if (op->contr->tmp_invis || op->hide)
2123 make_visible (op); 2077 make_visible (op);
2124 2078
2125 return; 2079 return true;
2126 } 2080 }
2081 else
2082 return false;
2083 }
2127 2084
2128 /* in certain circumstances, you shouldn't attack friendly 2085 /* in certain circumstances, you shouldn't attack friendly
2129 * creatures. Note that if you are braced, you can't push 2086 * creatures. Note that if you are braced, you can't push
2130 * 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
2131 * attack them either. 2088 * attack them either.
2132 */ 2089 */
2133 if ((mon->type == PLAYER || mon->enemy != op) && 2090 if ((mon->type == PLAYER || mon->enemy != op)
2134 (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))
2135#ifdef PROHIBIT_PLAYERKILL
2136 (op->contr->peaceful 2092 && ((op->contr->peaceful
2137 || (mon->type == PLAYER 2093 || (mon->type == PLAYER && mon->contr->peaceful))
2138 && mon->contr->
2139 peaceful)) &&
2140#else
2141 op->contr->peaceful &&
2142#endif
2143 !on_battleground)) 2094 && !on_battleground))
2095 {
2096 if (op->speed_left > 0.f)
2144 { 2097 {
2098 --op->speed_left;
2099
2145 if (!op->contr->braced) 2100 if (!op->contr->braced)
2146 { 2101 {
2147 play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); 2102 op->play_sound (sound_find ("push_player"));
2148 push_ob (mon, dir, op); 2103 push_ob (mon, dir, op);
2149 } 2104 }
2150 else 2105 else
2151 new_draw_info (0, 0, op, "You withhold your attack"); 2106 op->statusmsg ("You withhold your attack");
2152 2107
2153 if (op->contr->tmp_invis || op->hide) 2108 if (op->contr->tmp_invis || op->hide)
2154 make_visible (op); 2109 make_visible (op);
2155 }
2156 2110
2111 return true;
2112 }
2113 }
2157 /* If the object is a boulder or other rollable object, then 2114 /* If the object is a boulder or other rollable object, then
2158 * 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.
2159 */ 2116 */
2160 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)
2161 { 2120 {
2121 --op->speed_left;
2122
2162 recursive_roll (mon, dir, op); 2123 recursive_roll (mon, dir, op);
2163 if (action_makes_visible (op)) 2124 if (action_makes_visible (op))
2164 make_visible (op); 2125 make_visible (op);
2165 }
2166 2126
2127 return true;
2128 }
2129 }
2167 /* Any generic living creature. Including things like doors. 2130 /* Any generic living creature. Including things like doors.
2168 * 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
2169 * and be living. Then, it must be one of the following: 2132 * and be living. Then, it must be one of the following:
2170 * 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
2171 * 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.
2172 */ 2135 */
2173 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2136 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) &&
2174 ((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)))
2175 { 2138 {
2176 2139 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2177 /* If the player hasn't hit something this tick, and does
2178 * so, give them speed boost based on weapon speed. Doing
2179 * it here is better than process_players2, which basically
2180 * incurred a 1 tick offset.
2181 */
2182 if (!op->contr->has_hit)
2183 { 2140 {
2184 op->speed_left += op->speed / op->contr->weapon_sp; 2141 --op->contr->weapon_sp_left;
2185
2186 op->contr->has_hit = 1; /* The last action was to hit, so use weapon_sp */
2187 }
2188 2142
2189 skill_attack (mon, op, 0, 0, 0); 2143 skill_attack (mon, op, 0, 0, 0);
2190
2191 /* If attacking another player, that player gets automatic
2192 * hitback, and doesn't loose luck either.
2193 * Disable hitback on the battleground or if the target is
2194 * the wiz.
2195 */
2196 if (mon->type == PLAYER && mon->stats.hp >= 0 && !mon->contr->has_hit && !on_battleground && !QUERY_FLAG (mon, FLAG_WIZ))
2197 {
2198 short luck = mon->stats.luck;
2199
2200 mon->contr->has_hit = 1;
2201 skill_attack (op, mon, 0, 0, 0);
2202 mon->stats.luck = luck;
2203 }
2204 2144
2205 if (action_makes_visible (op)) 2145 if (action_makes_visible (op))
2206 make_visible (op); 2146 make_visible (op);
2207 }
2208 } /* if player should attack something */
2209}
2210 2147
2211int 2148 return true;
2149 }
2150 }
2151
2152 return false;
2153}
2154
2155bool
2212move_player (object *op, int dir) 2156move_player (object *op, int dir)
2213{ 2157{
2214 int pick; 2158 int pick;
2215 2159
2216 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2160 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2217 return 0; 2161 return 0;
2218 2162
2219 /* Sanity check: make sure dir is valid */ 2163 /* Sanity check: make sure dir is valid */
2220 if ((dir < 0) || (dir >= 9)) 2164 if ((dir < 0) || (dir >= 9))
2221 { 2165 {
2230 op->facing = dir; 2174 op->facing = dir;
2231 2175
2232 if (op->hide) 2176 if (op->hide)
2233 do_hidden_move (op); 2177 do_hidden_move (op);
2234 2178
2179 bool retval;
2180
2235 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2181 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2236 /*nop */ ; 2182 retval = RESULT_INT (0);
2237 else if (op->contr->fire_on) 2183 else if (op->contr->fire_on)
2238 fire (op, dir); 2184 retval = fire (op, dir);
2239 else 2185 else
2240 { 2186 {
2241 move_player_attack (op, dir); 2187 retval = move_player_attack (op, dir);
2242 pick = check_pick (op); 2188 pick = check_pick (op);
2243 } 2189 }
2244 2190
2245 /* 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
2246 * server can handle repeat firing. 2192 * server can handle repeat firing.
2253 /* Update how the player looks. Use the facing, so direction may 2199 /* Update how the player looks. Use the facing, so direction may
2254 * get reset to zero. This allows for full animation capabilities 2200 * get reset to zero. This allows for full animation capabilities
2255 * for players. 2201 * for players.
2256 */ 2202 */
2257 animate_object (op, op->facing); 2203 animate_object (op, op->facing);
2258 return 0; 2204
2205 return retval;
2259} 2206}
2260 2207
2261/* 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
2262 * new client/server stuff. 2209 * new client/server stuff.
2263 * 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
2264 * the new speed values for commands. 2211 * the new speed values for commands.
2265 * 2212 *
2266 * 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.
2267 */ 2216 */
2268int 2217bool
2269handle_newcs_player (object *op) 2218handle_newcs_player (object *op)
2270{ 2219{
2271 if (QUERY_FLAG (op, FLAG_SCARED)) 2220 if (QUERY_FLAG (op, FLAG_SCARED))
2272 { 2221 {
2273 flee_player (op); 2222 if (op->speed_left > 0.f)
2274 /* If player is still scared, that is his action for this tick */
2275 if (QUERY_FLAG (op, FLAG_SCARED))
2276 { 2223 {
2277 op->speed_left--; 2224 --op->speed_left;
2225 flee_player (op);
2226
2278 return 0; 2227 return true;
2279 } 2228 }
2229 else
2230 return false;
2280 } 2231 }
2281 2232
2282 /* 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
2283 * the players time has been increased when doericserver has been 2234 * the players time has been increased when doericserver has been
2284 * called, so we recheck it here. 2235 * called, so we recheck it here.
2285 */ 2236 */
2286 if (op->contr->ns->handle_command ()) 2237 if (op->contr->ns->handle_command ())
2287 return 1; 2238 return true;
2288 2239
2289 if (op->speed_left > 0)
2290 {
2291 if (op->direction && (op->contr->run_on || op->contr->fire_on)) 2240 if (op->direction && (op->contr->run_on || op->contr->fire_on))
2292 {
2293 /* All move commands take 1 tick, at least for now */
2294 op->speed_left--;
2295
2296 /* Instead of all the stuff below, let move_player take care
2297 * of it. Also, some of the skill stuff is only put in
2298 * there, as well as the confusion stuff.
2299 */
2300 move_player (op, op->direction); 2241 return move_player (op, op->direction);
2301 2242
2302 return op->speed_left > 0;
2303 }
2304 }
2305
2306 return 0; 2243 return false;
2307} 2244}
2308 2245
2309int 2246int
2310save_life (object *op) 2247save_life (object *op)
2311{ 2248{
2313 return 0; 2250 return 0;
2314 2251
2315 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2252 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2316 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2253 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE))
2317 { 2254 {
2318 play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); 2255 op->play_sound (sound_find ("ob_evaporate"));
2319 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));
2320
2321 if (op->contr)
2322 esrv_del_item (op->contr, tmp->count);
2323 2257
2324 tmp->destroy (); 2258 tmp->destroy ();
2325 CLEAR_FLAG (op, FLAG_LIFESAVE); 2259 CLEAR_FLAG (op, FLAG_LIFESAVE);
2326 2260
2327 if (op->stats.hp < 0) 2261 if (op->stats.hp < 0)
2340 return 0; 2274 return 0;
2341} 2275}
2342 2276
2343/* 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
2344 * 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
2345 * 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
2346 * from. 2280 * from.
2347 */ 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
2348void 2298void
2349remove_unpaid_objects (object *op, object *env) 2299object::drop_unpaid_items ()
2350{ 2300{
2351 while (op) 2301 if (!flag [FLAG_REMOVED])
2352 { 2302 ::drop_unpaid_items (inv, this);
2353 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2354
2355 if (QUERY_FLAG (op, FLAG_UNPAID))
2356 {
2357 if (env->type == PLAYER)
2358 esrv_del_item (env->contr, op->count);
2359
2360 op->insert_at (env);
2361 }
2362 else if (op->inv)
2363 remove_unpaid_objects (op->inv, env);
2364
2365 op = next;
2366 }
2367} 2303}
2368 2304
2369/* 2305/*
2370 * Returns pointer a static string containing gravestone text 2306 * Returns pointer a static string containing gravestone text
2371 * Moved from apply.c to player.c - player.c is what 2307 * Moved from apply.c to player.c - player.c is what
2372 * actually uses this function. player.c may not be quite the 2308 * actually uses this function. player.c may not be quite the
2373 * best, a misc file for object actions is probably better, 2309 * best, a misc file for object actions is probably better,
2374 * but there isn't one in the server directory. 2310 * but there isn't one in the server directory.
2375 */ 2311 */
2376char * 2312const char *
2377gravestone_text (object *op) 2313gravestone_text (object *op)
2378{ 2314{
2379 static char buf2[MAX_BUF]; 2315 static dynbuf_text buf;
2380 char buf[MAX_BUF];
2381 time_t now = time (NULL);
2382 2316
2383 strcpy (buf2, " R.I.P.\n\n"); 2317 buf << "---- R.I.P. ----\n\n";
2318 op->name;
2319
2384 if (op->type == PLAYER) 2320 if (op->type == PLAYER)
2385 sprintf (buf, "%s the %s\n", &op->name, op->contr->title); 2321 buf << " the " << op->contr->title;
2386 else
2387 sprintf (buf, "%s\n", &op->name);
2388 2322
2389 strncat (buf2, " ", 20 - strlen (buf) / 2); 2323 buf << "\n\n";
2390 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
2391 if (op->type == PLAYER) 2329 if (op->type == PLAYER)
2392 sprintf (buf, "who was in level %d when killed\n", op->level); 2330 buf << "by " << op->contr->killer_name () << ".\n\n";
2393 else
2394 sprintf (buf, "who was in level %d when died.\n\n", op->level);
2395 2331
2396 strncat (buf2, " ", 20 - strlen (buf) / 2);
2397 strcat (buf2, buf);
2398 if (op->type == PLAYER)
2399 { 2332 {
2400 sprintf (buf, "by %s.\n\n", op->contr->killer); 2333 static char buf2[128];
2401 strncat (buf2, " ", 21 - strlen (buf) / 2); 2334 time_t now = time (NULL);
2402 strcat (buf2, buf);
2403 }
2404
2405 strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); 2335 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2406 strncat (buf2, " ", 20 - strlen (buf) / 2); 2336 buf << buf2;
2407 strcat (buf2, buf); 2337 }
2408 2338
2409 return buf2; 2339 return buf;
2410} 2340}
2411 2341
2412void 2342void
2413do_some_living (object *op) 2343do_some_living (object *op)
2414{ 2344{
2466 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace; 2396 gen_grace = (op->contr->gen_grace + 1) * op->stats.maxgrace;
2467 else 2397 else
2468 { 2398 {
2469 gen_grace = op->stats.maxgrace; 2399 gen_grace = op->stats.maxgrace;
2470 rate_grace -= rate_grace / 2 * op->contr->gen_grace; 2400 rate_grace -= rate_grace / 2 * op->contr->gen_grace;
2471 }
2472
2473 /* Regenerate Spell Points */
2474 if (!op->contr->golem && --op->last_sp < 0)
2475 {
2476 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2477 if (op->stats.sp < op->stats.maxsp)
2478 {
2479 op->stats.sp++;
2480 /* dms do not consume food */
2481 if (!QUERY_FLAG (op, FLAG_WIZ))
2482 {
2483 op->stats.food--;
2484 if (op->contr->digestion < 0)
2485 op->stats.food += op->contr->digestion;
2486 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2487 op->stats.food = last_food;
2488 }
2489 }
2490
2491 if (max_sp > 1)
2492 {
2493 over_sp = (gen_sp + 10) / rate_sp;
2494 if (over_sp > 0)
2495 {
2496 if (op->stats.sp < op->stats.maxsp)
2497 {
2498 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2499
2500 if (random_roll (0, rate_sp - 1, op, PREFER_LOW) > ((gen_sp + 10) % rate_sp))
2501 op->stats.sp--;
2502
2503 if (op->stats.sp > op->stats.maxsp)
2504 op->stats.sp = op->stats.maxsp;
2505 }
2506 op->last_sp = 0;
2507 }
2508 else
2509 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2510 }
2511 else
2512 op->last_sp = rate_sp / (gen_sp < 20 ? 30 : gen_sp + 10);
2513 } 2401 }
2514 2402
2515 /* Regenerate Grace */ 2403 /* Regenerate Grace */
2516 /* 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. */
2517 if (--op->last_grace < 0) 2405 if (--op->last_grace < 0)
2538 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);
2539 } 2427 }
2540 /* wearing stuff doesn't detract from grace generation. */ 2428 /* wearing stuff doesn't detract from grace generation. */
2541 } 2429 }
2542 2430
2431 if (op->stats.food > 0)
2432 {
2543 /* Regenerate Hit Points */ 2433 /* Regenerate Spell Points */
2544 if (--op->last_heal < 0) 2434 if (!op->contr->golem && --op->last_sp < 0)
2545 {
2546 if (op->stats.hp < op->stats.maxhp)
2547 { 2435 {
2548 op->stats.hp++; 2436 gen_sp = gen_sp * 10 / (op->contr->gen_sp_armour < 10 ? 10 : op->contr->gen_sp_armour);
2549 /* dms do not consume food */ 2437
2550 if (!QUERY_FLAG (op, FLAG_WIZ)) 2438 if (op->stats.sp < op->stats.maxsp)
2551 { 2439 {
2440 op->stats.sp++;
2441
2442 /* dms do not consume food */
2443 if (!QUERY_FLAG (op, FLAG_WIZ))
2444 {
2552 op->stats.food--; 2445 op->stats.food--;
2446
2553 if (op->contr->digestion < 0) 2447 if (op->contr->digestion < 0)
2554 op->stats.food += op->contr->digestion; 2448 op->stats.food += op->contr->digestion;
2555 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))
2556 op->stats.food = last_food; 2450 op->stats.food = last_food;
2451 }
2557 } 2452 }
2558 }
2559 2453
2560 if (max_hp > 1) 2454 if (max_sp > 1)
2561 {
2562 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp;
2563 if (over_hp > 0)
2564 { 2455 {
2565 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
2566 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);
2567 } 2474 }
2568 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)
2569 { 2483 {
2570 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 }
2571 } 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);
2572 } 2509 }
2573 else 2510 else
2574 {
2575 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);
2576 } 2512 }
2577 } 2513 }
2578 2514
2579 /* Digestion */ 2515 /* Digestion */
2580 if (--op->last_eat < 0) 2516 if (--op->last_eat < 0)
2581 { 2517 {
2582#ifdef COZY_SERVER 2518 int bonus = max (0, op->contr->digestion),
2583 int dg = op->contr->digestion >= 0 && op->contr->digestion < 2 ? 2 : op->contr->digestion; 2519 penalty = max (0, -op->contr->digestion);
2584 int bonus = dg > 0 ? dg : 0, penalty = dg < 0 ? -dg : 0;
2585#else
2586 int bonus = op->contr->digestion > 0 ? op->contr->digestion : 0, penalty = op->contr->digestion < 0 ? -op->contr->digestion : 0;
2587#endif
2588 2520
2589 if (op->contr->gen_hp > 0)
2590 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);
2591 else
2592 op->last_eat = 25 * (1 + bonus) / (penalty + 1);
2593 2522
2594 /* dms do not consume food */ 2523 /* dms do not consume food */
2595 if (!QUERY_FLAG (op, FLAG_WIZ)) 2524 if (!QUERY_FLAG (op, FLAG_WIZ))
2596 op->stats.food--; 2525 op->stats.food--;
2597 } 2526 }
2598 2527
2599 if (op->stats.food < 0 && op->stats.hp >= 0) 2528 if (op->stats.food < 0 && op->stats.hp >= 0)
2600 { 2529 {
2601 object *tmp, *flesh = 0; 2530 object *flesh = 0;
2602 2531
2603 for (tmp = op->inv; tmp; tmp = tmp->below) 2532 for_inv_removable (op, tmp)
2604 { 2533 {
2605 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)
2606 { 2538 {
2607 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2539 op->statusmsg ("You blindly grab for a bite of food. "
2608 { 2540 "H<To prevent you from starving, you ate some random item from your backpack.>");
2609 new_draw_info (NDI_UNIQUE, 0, op, "You blindly grab for a bite of food.");
2610 manual_apply (op, tmp, 0); 2541 manual_apply (op, tmp, 0);
2542
2611 if (op->stats.food >= 0 || op->stats.hp < 0) 2543 if (op->stats.food >= 0 || op->stats.hp < 0)
2612 break; 2544 break;
2613 } 2545 }
2614 else if (tmp->type == FLESH) 2546 else if (tmp->type == FLESH)
2615 flesh = tmp; 2547 flesh = tmp;
2616 } /* End if paid for object */ 2548 }
2617 } /* end of for loop */
2618 2549
2619 /* 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
2620 * eat flesh instead. 2551 * eat flesh instead.
2621 */ 2552 */
2622 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2553 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2623 { 2554 {
2624 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.>");
2625 manual_apply (op, flesh, 0); 2557 manual_apply (op, flesh, 0);
2626 } 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)
2627 } 2567 {
2568 op->stats.hp += op->stats.food;
2569 op->stats.food = 0;
2628 2570
2629 while (op->stats.food < 0 && op->stats.hp >= 0) 2571 if (op->stats.hp < 0)
2630 op->stats.food++, op->stats.hp--; 2572 {
2573 op->contr->killer = archetype::get ("killer_starvation");
2574 op->contr->killer->destroy ();
2575 }
2576 }
2631 2577
2578 /* killer should be set here already */
2632 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2579 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ))
2633 kill_player (op); 2580 kill_player (op);
2634 } 2581 }
2635} 2582}
2636 2583
2640 * file. 2587 * file.
2641 */ 2588 */
2642void 2589void
2643kill_player (object *op) 2590kill_player (object *op)
2644{ 2591{
2592 int x, y;
2645 char buf[MAX_BUF]; 2593 char buf[MAX_BUF];
2646 int x, y;
2647
2648 //int i;
2649 maptile *map; /* this is for resurrection */ 2594 maptile *map; /* this is for resurrection */
2650
2651 /* int z;
2652 int num_stats_lose;
2653 int lost_a_stat;
2654 int lose_this_stat;
2655 int this_stat; */
2656 int will_kill_again; 2595 int will_kill_again;
2657 archetype *at; 2596 archetype *at;
2658 object *tmp; 2597 object *tmp;
2659 2598
2660 if (save_life (op)) 2599 if (save_life (op))
2661 return; 2600 return;
2662
2663 2601
2664 /* 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
2665 * 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.
2666 * Look at op_on_battleground() for more info --AndreasV 2604 * Look at op_on_battleground() for more info --AndreasV
2667 */ 2605 */
2683 { 2621 {
2684 tmp->destroy (); 2622 tmp->destroy ();
2685 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2623 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2686 } 2624 }
2687 2625
2688 cure_disease (op, 0); /* remove any disease */ 2626 cure_disease (op, 0, 0); /* remove any disease */
2689 op->stats.hp = op->stats.maxhp; 2627 op->stats.hp = op->stats.maxhp;
2690 if (op->stats.food <= 0) 2628 if (op->stats.food <= 0)
2691 op->stats.food = 999; 2629 op->stats.food = 999;
2692 2630
2693 /* create a bodypart-trophy to make the winner happy */ 2631 /* create a bodypart-trophy to make the winner happy */
2694 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2632 if (object *tmp = arch_to_object (archetype::find ("finger")))
2695 { 2633 {
2696 sprintf (buf, "%s's finger", &op->name); 2634 tmp->name = format ("%s's finger" , &op->name);
2697 tmp->name = buf; 2635 tmp->name_pl = format ("%s's fingers", &op->name);
2698 sprintf (buf, " This finger has been cut off %s\n"
2699 " the %s, when he was defeated at\n level %d by %s.\n",
2700 &op->name, op->contr->title, (int) (op->level), op->contr->killer);
2701 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 );
2702 tmp->value = 0, tmp->type = 0; 2642 tmp->value = 0, tmp->type = 0;
2703 tmp->materialname = "organics"; 2643 tmp->materialname = "organics";
2704 tmp->insert_at (op, tmp); 2644 tmp->insert_at (op, tmp);
2705 } 2645 }
2706 2646
2712 2652
2713 INVOKE_PLAYER (DEATH, op->contr); 2653 INVOKE_PLAYER (DEATH, op->contr);
2714 2654
2715 command_kill_pets (op, 0); 2655 command_kill_pets (op, 0);
2716 2656
2717 if (op->stats.food < 0) 2657 op->contr->play_sound (sound_find ("player_dies"));
2718 {
2719 sprintf (buf, "%s starved to death.", &op->name);
2720 strcpy (op->contr->killer, "starvation");
2721 }
2722 else
2723 sprintf (buf, "%s died.", &op->name);
2724
2725 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2726 2658
2727 /* save the map location for corpse, gravestone */ 2659 /* save the map location for corpse, gravestone */
2728 x = op->x; 2660 x = op->x;
2729 y = op->y; 2661 y = op->y;
2730 map = op->map; 2662 map = op->map;
2837 lost_a_stat = 1; 2769 lost_a_stat = 1;
2838 } 2770 }
2839 } 2771 }
2840 } 2772 }
2841 } 2773 }
2774
2842 /* If no stat lost, tell the player. */ 2775 /* If no stat lost, tell the player. */
2843 if (!lost_a_stat) 2776 if (!lost_a_stat)
2844 { 2777 {
2845 /* determine_god() seems to not work sometimes... why is this? 2778 /* determine_god() seems to not work sometimes... why is this?
2846 Should I be using something else? GD */ 2779 Should I be using something else? GD */
2850 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);
2851 else 2784 else
2852 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.");
2853 } 2786 }
2854#else 2787#else
2855 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.");
2856#endif 2789#endif
2857 2790
2858 /* Put a gravestone up where the character 'almost' died. List the 2791 /* Put a gravestone up where the character 'almost' died. List the
2859 * exp loss on the stone. 2792 * exp loss on the stone.
2860 */ 2793 */
2861 tmp = arch_to_object (archetype::find ("gravestone")); 2794 tmp = arch_to_object (archetype::find ("gravestone"));
2862 sprintf (buf, "%s's gravestone", &op->name); 2795 tmp->name = format ("%s's gravestone", &op->name);
2863 tmp->name = buf; 2796 tmp->name_pl = format ("%s's gravestones", &op->name);
2864 sprintf (buf, "%s's gravestones", &op->name);
2865 tmp->name_pl = buf;
2866 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 ());
2867 tmp->msg = buf;
2868 tmp->x = op->x, tmp->y = op->y; 2798 tmp->x = op->x, tmp->y = op->y;
2869 insert_ob_in_map (tmp, op->map, NULL, 0); 2799 insert_ob_in_map (tmp, op->map, NULL, 0);
2870 2800
2871 /**************************************/ 2801 /**************************************/
2872 /* */ 2802 /* */
2893 { 2823 {
2894 tmp->destroy (); 2824 tmp->destroy ();
2895 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); 2825 new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer");
2896 } 2826 }
2897 2827
2898 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 }
2899 2841
2900 /*add_exp(op, (op->stats.exp * -0.20)); */ 2842 /*add_exp(op, (op->stats.exp * -0.20)); */
2901 apply_death_exp_penalty (op); 2843 apply_death_exp_penalty (op);
2844
2902 if (op->stats.food < 100) 2845 if (op->stats.food < 100)
2903 op->stats.food = 900; 2846 op->stats.food = 900;
2847
2904 op->stats.hp = op->stats.maxhp; 2848 op->stats.hp = op->stats.maxhp;
2905 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp); 2849 op->stats.sp = MAX (op->stats.sp, op->stats.maxsp);
2906 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace); 2850 op->stats.grace = MAX (op->stats.grace, op->stats.maxgrace);
2907 2851
2908 /* 2852 /*
2909 * 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
2910 * and put them back in the map. 2854 * and put them back in the map.
2911 */ 2855 */
2912 remove_unpaid_objects (op->inv, op); 2856 op->drop_unpaid_items ();
2913 2857
2914 /****************************************/ 2858 /****************************************/
2915 /* */ 2859 /* */
2916 /* Move player to his current respawn- */ 2860 /* Move player to his current respawn- */
2917 /* position (usually last savebed) */ 2861 /* position (usually last savebed) */
2937 object *force; 2881 object *force;
2938 int at; 2882 int at;
2939 2883
2940 force = get_archetype (FORCE_NAME); 2884 force = get_archetype (FORCE_NAME);
2941 /* 50 ticks should be enough time for the spell to abate */ 2885 /* 50 ticks should be enough time for the spell to abate */
2942 force->speed = 0.1; 2886 force->speed = 0.1f;
2943 force->speed_left = -5.0; 2887 force->speed_left = -5.f;
2944 SET_FLAG (force, FLAG_APPLIED); 2888 SET_FLAG (force, FLAG_APPLIED);
2945 for (at = 0; at < NROFATTACKS; at++) 2889 for (at = 0; at < NROFATTACKS; at++)
2946 if (will_kill_again & (1 << at)) 2890 if (will_kill_again & (1 << at))
2947 force->resist[at] = 100; 2891 force->resist[at] = 100;
2948 2892
2976 2920
2977 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))))
2978 { 2922 {
2979 if (tmp->nrof > 1) 2923 if (tmp->nrof > 1)
2980 { 2924 {
2981 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2925 tmp->decrease (rndm (1, tmp->nrof - 1));
2982 tmp2->destroy ();
2983 insert_ob_in_map (tmp, op->map, NULL, 0); 2926 insert_ob_in_map (tmp, op->map, NULL, 0);
2984 } 2927 }
2985 else 2928 else
2986 tmp->destroy (); 2929 tmp->destroy ();
2987 } 2930 }
2998void 2941void
2999fix_weight (void) 2942fix_weight (void)
3000{ 2943{
3001 for_all_players (pl) 2944 for_all_players (pl)
3002 { 2945 {
3003 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2946 sint32 old = pl->ob->carrying;
3004 2947
3005 if (old == sum) 2948 pl->ob->update_weight ();
3006 continue; 2949
2950 if (old != pl->ob->carrying)
2951 {
3007 pl->ob->update_stats (); 2952 pl->ob->update_stats ();
3008 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 }
3009 } 2955 }
3010} 2956}
3011 2957
3012void 2958void
3013fix_luck (void) 2959fix_luck (void)
3057void 3003void
3058make_visible (object *op) 3004make_visible (object *op)
3059{ 3005{
3060 op->hide = 0; 3006 op->hide = 0;
3061 op->invisible = 0; 3007 op->invisible = 0;
3008
3062 if (op->type == PLAYER) 3009 if (op->type == PLAYER)
3063 { 3010 {
3064 op->contr->tmp_invis = 0; 3011 op->contr->tmp_invis = 0;
3065 op->contr->invis_race = 0; 3012 op->contr->invis_race = 0;
3066 } 3013 }
3069} 3016}
3070 3017
3071int 3018int
3072is_true_undead (object *op) 3019is_true_undead (object *op)
3073{ 3020{
3074 if (QUERY_FLAG (&op->arch->clone, FLAG_UNDEAD)) 3021 if (QUERY_FLAG (op->arch, FLAG_UNDEAD))
3075 return 1; 3022 return 1;
3076 3023
3077 return 0; 3024 return 0;
3078} 3025}
3079 3026
3080/* look at the surrounding terrain to determine 3027/* look at the surrounding terrain to determine
3081 * the hideability of this object. Positive levels 3028 * the hideability of this object. Positive levels
3082 * indicate greater hideability. 3029 * indicate greater hideability.
3083 */ 3030 */
3084
3085int 3031int
3086hideability (object *ob) 3032hideability (object *ob)
3087{ 3033{
3088 int i, level = 0, mflag; 3034 int i, level = 0, mflag;
3089 sint16 x, y; 3035 sint16 x, y;
3099 * as bad as carrying a light on a pitch dark map */ 3045 * as bad as carrying a light on a pitch dark map */
3100 if (has_carried_lights (ob)) 3046 if (has_carried_lights (ob))
3101 level = -(10 + (2 * ob->map->darkness)); 3047 level = -(10 + (2 * ob->map->darkness));
3102 3048
3103 /* scan through all nearby squares for terrain to hide in */ 3049 /* scan through all nearby squares for terrain to hide in */
3104 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])
3105 { 3053 {
3106 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3054 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3107 if (mflag & P_OUT_OF_MAP) 3055 if (mflag & P_OUT_OF_MAP)
3108 {
3109 continue; 3056 continue;
3110 } 3057
3111 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3058 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3112 level += 2; 3059 level += 2;
3113 else /* open terrain! */ 3060 else /* open terrain! */
3114 level -= 1; 3061 level -= 1;
3115 } 3062 }
3123/* For Hidden creatures - a chance of becoming 'unhidden' 3070/* For Hidden creatures - a chance of becoming 'unhidden'
3124 * every time they move - as we subtract off 'invisibility' 3071 * every time they move - as we subtract off 'invisibility'
3125 * AND, for players, if they move into a ridiculously unhideable 3072 * AND, for players, if they move into a ridiculously unhideable
3126 * spot (surrounded by clear terrain in broad daylight). -b.t. 3073 * spot (surrounded by clear terrain in broad daylight). -b.t.
3127 */ 3074 */
3128
3129void 3075void
3130do_hidden_move (object *op) 3076do_hidden_move (object *op)
3131{ 3077{
3132 int hide = 0, num = random_roll (0, 19, op, PREFER_LOW); 3078 int hide = 0;
3133 object *skop;
3134 3079
3135 if (!op || !op->map) 3080 if (!op || !op->map)
3136 return; 3081 return;
3137 3082
3138 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);
3139 3085
3140 /* 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! */
3141 if (op->type == PLAYER && op->contr->run_on) 3087 if (op->type == PLAYER && op->contr->run_on)
3142 if (!skop || num >= skop->level) 3088 if (!skop || num >= skop->level)
3143 { 3089 {
3153 num -= hide; 3099 num -= hide;
3154 3100
3155 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) 3101 if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0))
3156 { 3102 {
3157 make_visible (op); 3103 make_visible (op);
3104
3158 if (op->type == PLAYER) 3105 if (op->type == PLAYER)
3159 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!");
3160 } 3107 }
3161 else if (op->type == PLAYER && skop) 3108 else if (op->type == PLAYER && skop)
3162 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);
3215 * object op. This function works fine for monsters, 3162 * object op. This function works fine for monsters,
3216 * 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
3217 * a pile (say a coin under a table would return "viewable" 3164 * a pile (say a coin under a table would return "viewable"
3218 * by this routine). Another question, should we be 3165 * by this routine). Another question, should we be
3219 * concerned with the direction the player is looking 3166 * concerned with the direction the player is looking
3220 * in? Realistically, most of use cant see stuff behind 3167 * in? Realistically, most of us can't see stuff behind
3221 * our backs...on the other hand, does the "facing" direction 3168 * our backs...on the other hand, does the "facing" direction
3222 * imply the way your head, or body is facing? Its possible 3169 * imply the way your head, or body is facing? It's possible
3223 * 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.
3224 * -b.t. 3171 * -b.t.
3225 * This function is now map tiling safe. 3172 * This function is now map tiling safe.
3226 */ 3173 */
3227
3228int 3174int
3229player_can_view (object *pl, object *op) 3175player_can_view (object *pl, object *op)
3230{ 3176{
3231 rv_vector rv; 3177 rv_vector rv;
3232 int dx, dy; 3178 int dx, dy;
3244 3190
3245 get_rangevector (pl, op, &rv, 0x1); 3191 get_rangevector (pl, op, &rv, 0x1);
3246 3192
3247 /* starting with the 'head' part, lets loop 3193 /* starting with the 'head' part, lets loop
3248 * through the object and find if it has any 3194 * through the object and find if it has any
3249 * part that is in the los array but isnt on 3195 * part that is in the los array but isn't on
3250 * a blocked los square. 3196 * a blocked los square.
3251 * we use the archetype to figure out offsets. 3197 * we use the archetype to figure out offsets.
3252 */ 3198 */
3253 while (op) 3199 while (op)
3254 { 3200 {
3255 dx = rv.distance_x + op->arch->clone.x; 3201 dx = rv.distance_x + op->arch->x;
3256 dy = rv.distance_y + op->arch->clone.y; 3202 dy = rv.distance_y + op->arch->y;
3257 3203
3258 /* only the viewable area the player sees is updated by LOS 3204 /* only the viewable area the player sees is updated by LOS
3259 * 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
3260 * for any meaningful values. 3206 * for any meaningful values.
3261 */ 3207 */
3262 if (FABS (dx) <= (pl->contr->ns->mapx / 2) && 3208 if (abs (dx) <= (pl->contr->ns->mapx / 2) &&
3263 FABS (dy) <= (pl->contr->ns->mapy / 2) && 3209 abs (dy) <= (pl->contr->ns->mapy / 2) &&
3264 !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)])
3265 return 1; 3211 return 1;
3212
3266 op = op->more; 3213 op = op->more;
3267 } 3214 }
3215
3268 return 0; 3216 return 0;
3269} 3217}
3270 3218
3271/* routine for both players and monsters. We call this when 3219/* routine for both players and monsters. We call this when
3272 * there is a possibility for our action distrubing our hiding 3220 * there is a possibility for our action distrubing our hiding
3275 * return 0. 3223 * return 0.
3276 */ 3224 */
3277int 3225int
3278action_makes_visible (object *op) 3226action_makes_visible (object *op)
3279{ 3227{
3280
3281 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 3228 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3282 { 3229 {
3283 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 3230 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3284 return 0; 3231 return 0;
3285 3232
3291 { 3238 {
3292 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");
3293 return 1; 3240 return 1;
3294 } 3241 }
3295 } 3242 }
3243
3296 return 0; 3244 return 0;
3297} 3245}
3298 3246
3299/* op_on_battleground - checks if the given object op (usually 3247/* op_on_battleground - checks if the given object op (usually
3300 * a player) is standing on a valid battleground-tile, 3248 * a player) is standing on a valid battleground-tile,
3305 * 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
3306 */ 3254 */
3307int 3255int
3308op_on_battleground (object *op, int *x, int *y) 3256op_on_battleground (object *op, int *x, int *y)
3309{ 3257{
3310 object *tmp;
3311
3312 /* A battleground-tile needs the following attributes to be valid: 3258 /* A battleground-tile needs the following attributes to be valid:
3313 * 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),
3314 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND) 3260 * name="battleground", no_pick 1, type=58 (type BATTLEGROUND)
3315 * and the exit-coordinates sp/hp must both be > 0. 3261 * and the exit-coordinates sp/hp must both be > 0.
3316 * => The intention here is to prevent abuse of the battleground- 3262 * => The intention here is to prevent abuse of the battleground-
3317 * feature (like pickable or hidden battleground tiles). */ 3263 * feature (like pickable or hidden battleground tiles). */
3318 for (tmp = op->below; tmp != NULL; tmp = tmp->below) 3264 for (object *tmp = op->below; tmp; tmp = tmp->below)
3319 { 3265 {
3320 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3266 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
3321 { 3267 {
3322 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && 3268 if (QUERY_FLAG (tmp, FLAG_NO_PICK)
3323 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))
3324 { 3272 {
3325 /*before we assign the exit, check if this is a teambattle */ 3273 /* before we assign the exit, check if this is a teambattle */
3326 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))
3327 { 3275 {
3328 object *invtmp;
3329
3330 for (invtmp = op->inv; invtmp != NULL; invtmp = invtmp->below) 3276 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3331 { 3277 {
3332 if (invtmp->type == FORCE && invtmp->slaying && !strcmp (EXIT_PATH (tmp), invtmp->slaying)) 3278 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3333 { 3279 {
3334 if (x != NULL && y != NULL) 3280 if (x && y)
3335 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3281 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3282
3336 return 1; 3283 return 1;
3337 } 3284 }
3338 } 3285 }
3339 } 3286 }
3287
3340 if (x != NULL && y != NULL) 3288 if (x && y)
3341 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3289 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3290
3342 return 1; 3291 return 1;
3343 } 3292 }
3344 } 3293 }
3345 } 3294 }
3295
3346 /* If we got here, did not find a battleground */ 3296 /* If we got here, did not find a battleground */
3347 return 0; 3297 return 0;
3348} 3298}
3349 3299
3350/* 3300/*
3366 char buf[MAX_BUF]; /* tmp. string buffer */ 3316 char buf[MAX_BUF]; /* tmp. string buffer */
3367 int i = 0, j = 0; 3317 int i = 0, j = 0;
3368 3318
3369 /* get the appropriate treasurelist */ 3319 /* get the appropriate treasurelist */
3370 if (atnr == ATNR_FIRE) 3320 if (atnr == ATNR_FIRE)
3371 trlist = treasurelist::find ("dragon_ability_fire"); 3321 trlist = treasurelist::find (shstr_dragon_ability_fire);
3372 else if (atnr == ATNR_COLD) 3322 else if (atnr == ATNR_COLD)
3373 trlist = treasurelist::find ("dragon_ability_cold"); 3323 trlist = treasurelist::find (shstr_dragon_ability_cold);
3374 else if (atnr == ATNR_ELECTRICITY) 3324 else if (atnr == ATNR_ELECTRICITY)
3375 trlist = treasurelist::find ("dragon_ability_elec"); 3325 trlist = treasurelist::find (shstr_dragon_ability_elec);
3376 else if (atnr == ATNR_POISON) 3326 else if (atnr == ATNR_POISON)
3377 trlist = treasurelist::find ("dragon_ability_poison"); 3327 trlist = treasurelist::find (shstr_dragon_ability_poison);
3378 3328
3379 if (trlist == NULL || who->type != PLAYER) 3329 if (trlist == NULL || who->type != PLAYER)
3380 return; 3330 return;
3381 3331
3382 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++);
3386 /* 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]); */
3387 return; 3337 return;
3388 } 3338 }
3389 3339
3390 /* everything seems okay - now bring on the gift: */ 3340 /* everything seems okay - now bring on the gift: */
3391 item = &(tr->item->clone); 3341 item = tr->item;
3392 3342
3393 if (item->type == SPELL) 3343 if (item->type == SPELL)
3394 { 3344 {
3395 if (check_spell_known (who, item->name)) 3345 if (check_spell_known (who, item->name))
3396 return; 3346 return;
3455 { 3405 {
3456 /* forces in the treasurelist can alter the player's stats */ 3406 /* forces in the treasurelist can alter the player's stats */
3457 object *skin; 3407 object *skin;
3458 3408
3459 /* first get the dragon skin force */ 3409 /* first get the dragon skin force */
3460 shstr_cmp dragon_skin_force ("dragon_skin_force");
3461 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)
3462 ; 3411 ;
3463 3412
3464 if (!skin) 3413 if (!skin)
3465 return; 3414 return;
3466 3415
3501 else 3450 else
3502 { 3451 {
3503 /* generate misc. treasure */ 3452 /* generate misc. treasure */
3504 tmp = arch_to_object (tr->item); 3453 tmp = arch_to_object (tr->item);
3505 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));
3506 tmp = insert_ob_in_ob (tmp, who); 3455 who->insert (tmp);
3507 if (who->type == PLAYER)
3508 esrv_send_item (who, tmp);
3509 } 3456 }
3510} 3457}
3511 3458
3512/** 3459/**
3513 * 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
3542 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))
3543 return 0; 3490 return 0;
3544 3491
3545 return 100 - blocked_los [x][y]; 3492 return 100 - blocked_los [x][y];
3546} 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