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.268 by root, Wed Apr 7 19:54:45 2010 UTC vs.
Revision 1.299 by root, Sat Sep 16 21:55:51 2017 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * 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 Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25//+GPL 25//+GPL
26
27#include <algorithm>
28#include <functional>
26 29
27#include <global.h> 30#include <global.h>
28#include <sproto.h> 31#include <sproto.h>
29#include <sounds.h> 32#include <sounds.h>
30#include <living.h> 33#include <living.h>
31#include <object.h> 34#include <object.h>
32#include <spells.h> 35#include <spells.h>
33#include <skills.h> 36#include <skills.h>
34 37
35#include <algorithm>
36#include <functional>
37
38playervec players; 38playervec players;
39 39
40/* This loads the first map an puts the player on it. */ 40/* This loads the first map an puts the player on it. */
41static void 41static void
42set_first_map (object *op) 42set_first_map (object *op)
54 54
55 players.insert (this); 55 players.insert (this);
56 ob->remove (); 56 ob->remove ();
57 ob->map = 0; 57 ob->map = 0;
58 ob->activate_recursive (); 58 ob->activate_recursive ();
59 CLEAR_FLAG (ob, FLAG_FRIENDLY); 59 ob->clr_flag (FLAG_FRIENDLY);
60 add_friendly_object (ob); 60 add_friendly_object (ob);
61} 61}
62 62
63void 63void
64player::deactivate () 64player::deactivate ()
126 126
127 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 127 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
128 128
129 esrv_new_player (this); 129 esrv_new_player (this);
130 130
131 ob->update_stats ();
132
133 ns->floorbox_update ();
134 esrv_send_inventory (ob, ob);
135 esrv_add_spells (this, 0);
136
137 ob->flag [FLAG_READY_WEAPON] = false; 131 ob->flag [FLAG_READY_WEAPON] = false;
138 ob->flag [FLAG_READY_SKILL] = false; 132 ob->flag [FLAG_READY_SKILL] = false;
139 ob->flag [FLAG_READY_RANGE] = false; 133 ob->flag [FLAG_READY_RANGE] = false;
140 ob->flag [FLAG_READY_BOW] = false; 134 ob->flag [FLAG_READY_BOW] = false;
141 135
142 ob->update_stats (); // we unapplied stuff above 136 ob->update_stats ();
137
138 ns->floorbox_update ();
139 esrv_send_inventory (ob, ob);
140 esrv_add_spells (this, 0);
141
143 activate (); 142 activate ();
144 143
145 INVOKE_PLAYER (CONNECT, this); 144 INVOKE_PLAYER (CONNECT, this);
146 INVOKE_PLAYER (LOGIN, this); 145 INVOKE_PLAYER (LOGIN, this);
147} 146}
182player::set_object (object *op) 181player::set_object (object *op)
183{ 182{
184 ob = observe = viewpoint = op; 183 ob = observe = viewpoint = op;
185 ob->contr = this; /* this aren't yet in archetype */ 184 ob->contr = this; /* this aren't yet in archetype */
186 185
187 ob->speed = 1.0f; 186 ob->speed = 1.0f; // object still inactive, keep it that way
188 ob->speed_left = 0.5f; 187 ob->speed_left = 0.5f;
189 188
190 ob->direction = 5; /* So player faces south */ 189 ob->direction = 5; /* So player faces south */
191} 190}
192 191
234 disconnect (); 233 disconnect ();
235 234
236 attachable::do_destroy (); 235 attachable::do_destroy ();
237 236
238 if (ob) 237 if (ob)
238 {
239 // potentially fix a bug where ob->contr is non-null while ob->contr->ob is null, causing a segfault.
240 // temporarily backed out patchset 4025 to see if THIS change causes crashes
241 //ob->contr = 0;
239 ob->destroy (); 242 ob->destroy ();
243 }
240 244
241 ob = observe = viewpoint = 0; 245 ob = observe = viewpoint = 0;
242} 246}
243 247
244player::~player () 248player::~player ()
328#endif 332#endif
329 return op; 333 return op;
330} 334}
331 335
332/* I believe this can safely go to 2, 3 is questionable, 4 will likely 336/* I believe this can safely go to 2, 3 is questionable, 4 will likely
333 * result in a monster paths backtracking. It basically determines how large a 337 * result in a monster paths backtracking. It basically determines how large a
334 * detour a monster will take from the direction path when looking 338 * detour a monster will take from the direction path when looking
335 * for a path to the player. The values are in the amount of direction 339 * for a path to the player. The values are in the amount of direction
336 * the deviation is 340 * the deviation is
337 */ 341 */
338#define DETOUR_AMOUNT 2 342#define DETOUR_AMOUNT 2
374 */ 378 */
375int 379int
376path_to_player (object *mon, object *pl, unsigned mindiff) 380path_to_player (object *mon, object *pl, unsigned mindiff)
377{ 381{
378 rv_vector rv; 382 rv_vector rv;
379 sint16 x, y;
380 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 383 int dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES;
381 maptile *m, *lastmap;
382 384
383 get_rangevector (mon, pl, &rv, 0); 385 get_rangevector (mon, pl, &rv, 0);
384 386
385 if (rv.distance < mindiff) 387 if (rv.distance < mindiff)
386 return 0; 388 return 0;
387 389
388 x = mon->x; 390 mapxy pos (mon);
389 y = mon->y;
390 m = mon->map;
391 dir = rv.direction; 391 dir = rv.direction;
392 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ 392 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
393 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 393 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
394 394
395 /* If we can't solve it within the search distance, return now. */ 395 /* If we can't solve it within the search distance, return now. */
396 if (diff > max) 396 if (diff > max)
397 return 0; 397 return 0;
398 398
399 while (diff > 1 && max > 0) 399 while (diff > 1 && max > 0)
400 { 400 {
401 lastx = x; 401 mapxy lastpos = pos;
402 lasty = y;
403 lastmap = m;
404 x = lastx + freearr_x[dir];
405 y = lasty + freearr_y[dir];
406 402
407 mflags = get_map_flags (m, &m, x, y, &x, &y); 403 pos.move (dir);
408 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK (m, x, y);
409 404
410 /* Space is blocked - try changing direction a little */ 405 /* Space is blocked - try changing direction a little */
411 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK (mon, blocked) || (mflags & P_BLOCKSVIEW)) 406 if (!pos.normalise ()
412 && (m == mon->map && blocked_link (mon, m, x, y)))) 407 || (((pos->flags () & P_BLOCKSVIEW) || OB_TYPE_MOVE_BLOCK (mon, pos->move_block))
408 && blocked_link (mon, pos.m, pos.x, pos.y)))
413 { 409 {
414 /* recalculate direction from last good location. Possible 410 /* recalculate direction from last good location. Possible
415 * we were not traversing ideal location before. 411 * we were not traversing ideal location before.
416 */ 412 */
417 get_rangevector_from_mapcoord (lastmap, lastx, lasty, pl, &rv, 0); 413 get_rangevector_from_mapcoord (lastpos.m, lastpos.x, lastpos.y, pl, &rv, 0);
418 if (rv.direction != dir) 414 if (rv.direction != dir)
419 { 415 {
420 /* OK - says direction should be different - lets reset the 416 /* OK - says direction should be different - lets reset the
421 * the values so it will try again. 417 * the values so it will try again.
422 */ 418 */
423 x = lastx;
424 y = lasty;
425 m = lastmap; 419 pos = lastpos;
426 dir = firstdir = rv.direction; 420 dir = firstdir = rv.direction;
427 } 421 }
428 else 422 else
429 { 423 {
430 /* direct path is blocked - try taking a side step to 424 /* direct path is blocked - try taking a side step to
431 * either the left or right. 425 * either the left or right.
432 * Note increase the values in the loop below to be 426 * Note increase the values in the loop below to be
433 * more than -1/1 respectively will mean the monster takes 427 * more than -1/1 respectively will mean the monster takes
434 * bigger detour. Have to be careful about these values getting 428 * bigger detour. Have to be careful about these values getting
435 * too big (3 or maybe 4 or higher) as the monster may just try 429 * too big (3 or maybe 4 or higher) as the monster may just try
436 * stepping back and forth 430 * stepping back and forth
437 */ 431 */
438 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) 432 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++)
439 { 433 {
440 if (i == 0) 434 if (i == 0)
441 continue; /* already did this, so skip it */ 435 continue; /* already did this, so skip it */
436
442 /* Use lastdir here - otherwise, 437 /* Use lastdir here - otherwise,
443 * since the direction that the creature should move in 438 * since the direction that the creature should move in
444 * may change, you could get infinite loops. 439 * may change, you could get infinite loops.
445 * ie, player is northwest, but monster can only 440 * ie, player is northwest, but monster can only
446 * move west, so it does that. It goes some distance, 441 * move west, so it does that. It goes some distance,
448 * can't do that, but now finds it can move east, and 443 * can't do that, but now finds it can move east, and
449 * gets back to its original point. lastdir contains 444 * gets back to its original point. lastdir contains
450 * the last direction the creature has successfully 445 * the last direction the creature has successfully
451 * moved. 446 * moved.
452 */ 447 */
453
454 x = lastx + freearr_x[absdir (lastdir + i)];
455 y = lasty + freearr_y[absdir (lastdir + i)];
456 m = lastmap; 448 pos = lastpos;
457 mflags = get_map_flags (m, &m, x, y, &x, &y); 449 pos.move (absdir (lastdir + i));
458 if (mflags & P_OUT_OF_MAP) 450
451 if (!pos.normalise ())
459 continue; 452 continue;
460 blocked = GET_MAP_MOVE_BLOCK (m, x, y); 453
461 if (OB_TYPE_MOVE_BLOCK (mon, blocked)) 454 mapspace &ms = *pos;
455
456 if (ms.flags () & P_BLOCKSVIEW)
462 continue; 457 continue;
463 if (mflags & P_BLOCKSVIEW) 458
459 if (OB_TYPE_MOVE_BLOCK (mon, ms.move_block))
464 continue; 460 continue;
465 461
466 if (m == mon->map && blocked_link (mon, m, x, y)) 462 if (blocked_link (mon, pos.m, pos.x, pos.y))
467 break; 463 break;
468 } 464 }
465
469 /* go through entire loop without finding a valid 466 /* go through entire loop without finding a valid
470 * sidestep to take - thus, no valid path. 467 * sidestep to take - thus, no valid path.
471 */ 468 */
472 if (i == (DETOUR_AMOUNT + 1)) 469 if (i == DETOUR_AMOUNT + 1)
473 return 0; 470 return 0;
471
474 diff--; 472 diff--;
475 lastdir = dir; 473 lastdir = dir;
476 max--; 474 max--;
477 if (!firstdir) 475 if (!firstdir)
478 firstdir = dir + i; 476 firstdir = dir + i;
482 { 480 {
483 /* we moved towards creature, so diff is less */ 481 /* we moved towards creature, so diff is less */
484 diff--; 482 diff--;
485 max--; 483 max--;
486 lastdir = dir; 484 lastdir = dir;
485
487 if (!firstdir) 486 if (!firstdir)
488 firstdir = dir; 487 firstdir = dir;
489 } 488 }
490 489
491 if (diff <= 1) 490 if (diff <= 1)
492 { 491 {
493 /* Recalculate diff (distance) because we may not have actually 492 /* Recalculate diff (distance) because we may not have actually
494 * headed toward player for entire distance. 493 * headed toward player for entire distance.
495 */ 494 */
496 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); 495 get_rangevector_from_mapcoord (pos.m, pos.x, pos.y, pl, &rv, 0);
497 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 496 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
498 } 497 }
499 498
500 if (diff > max) 499 if (diff > max)
501 return 0; 500 return 0;
517 for (object *next, *op = pl->inv; op; op = next) 516 for (object *next, *op = pl->inv; op; op = next)
518 { 517 {
519 next = op->below; 518 next = op->below;
520 519
521 /* Forces get applied per default, unless they have the 520 /* Forces get applied per default, unless they have the
522 * flag "neutral" set. Sorry but I can't think of a better way 521 * flag "neutral" set. Sorry but I can't think of a better way
523 */ 522 */
524 if (op->type == FORCE && !QUERY_FLAG (op, FLAG_NEUTRAL)) 523 if (op->type == FORCE && !op->flag [FLAG_NEUTRAL])
525 SET_FLAG (op, FLAG_APPLIED); 524 op->set_flag (FLAG_APPLIED);
526 525
527 /* we never give weapons/armour if these cannot be used 526 /* we never give weapons/armour if these cannot be used
528 * by this player due to race restrictions 527 * by this player due to race restrictions
529 */ 528 */
530 if (pl->type == PLAYER) 529 if (pl->type == PLAYER)
531 { 530 {
532 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) 531 if ((!pl->flag [FLAG_USE_ARMOUR]
533 && 532 &&
534 (op->type == ARMOUR || op->type == BOOTS 533 (op->type == ARMOUR || op->type == BOOTS
535 || op->type == CLOAK || op->type == HELMET 534 || op->type == CLOAK || op->type == HELMET
536 || op->type == SHIELD || op->type == GLOVES 535 || op->type == SHIELD || op->type == GLOVES
537 || op->type == BRACERS || op->type == GIRDLE)) 536 || op->type == BRACERS || op->type == GIRDLE))
538 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 537 || (!pl->flag [FLAG_USE_WEAPON] && op->type == WEAPON))
539 { 538 {
540 op->destroy (); 539 op->destroy ();
541 continue; 540 continue;
542 } 541 }
543 } 542 }
544 543
545 /* Here we remove duplicated skills (as duplicated spell objects have 544 /* Here we remove duplicated skills (as duplicated spell objects have
546 * _very_ confusing effects for players), which could for instance be 545 * _very_ confusing effects for players), which could for instance be
547 * generated by bad treasurelists. - elmex 546 * generated by multiple treasurelists specifying the same skills.
548 */ 547 */
549 if (op->type == SKILL) 548 if (op->type == SKILL)
550 { 549 {
551 for (object *tmp = op->below; tmp; tmp = tmp->below) 550 for (object *tmp = op->below; tmp; tmp = tmp->below)
552 if (tmp->type == op->type && tmp->name == op->name) 551 if (tmp->type == op->type && tmp->name == op->name)
553 { 552 {
554 op->destroy (); 553 op->destroy ();
555 LOG (llevError,
556 "give_initial_items: Removing duplicate skill %s\n", &tmp->name);
557 break; 554 break;
558 } 555 }
559 556
560 if (op->nrof > 1) 557 if (op->nrof > 1)
561 op->nrof = 1; 558 op->nrof = 1;
562 } 559 }
563 560
564 if (op->type == SPELLBOOK && op->inv) 561 if (op->type == SPELLBOOK && op->inv)
565 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 562 op->inv->clr_flag (FLAG_STARTEQUIP);
566 563
567 /* Give starting characters identified, uncursed, and undamned 564 /* Give starting characters identified, uncursed, and undamned
568 * items. Just don't identify gold or silver, or it won't be 565 * items. Just don't identify gold or silver, or it won't be
569 * merged properly. 566 * merged properly.
570 */ 567 */
571 if (need_identify (op)) 568 if (op->need_identify ())
572 { 569 {
573 SET_FLAG (op, FLAG_IDENTIFIED); 570 op->set_flag (FLAG_IDENTIFIED);
574 CLEAR_FLAG (op, FLAG_CURSED); 571 op->clr_flag (FLAG_CURSED);
575 CLEAR_FLAG (op, FLAG_DAMNED); 572 op->clr_flag (FLAG_DAMNED);
576 } 573 }
577 574
578 if (op->type == SPELL) 575 if (op->type == SPELL)
579 { 576 {
580 op->destroy (); 577 op->destroy ();
581 continue; 578 continue;
582 } 579 }
583 else if (op->type == SKILL) 580 else if (op->type == SKILL)
584 { 581 {
585 SET_FLAG (op, FLAG_CAN_USE_SKILL); 582 op->set_flag (FLAG_CAN_USE_SKILL);
586 op->stats.exp = 0; 583 op->stats.exp = 0;
587 op->level = 1; 584 op->level = 1;
588 } 585 }
589 else /* lock all 'normal items by default */ 586 else /* lock all 'normal items by default */
590 SET_FLAG (op, FLAG_INV_LOCKED); 587 op->set_flag (FLAG_INV_LOCKED);
591 } /* for loop of objects in player inv */ 588 } /* for loop of objects in player inv */
592 589
593 /* Need to set up the skill pointers */ 590 /* Need to set up the skill pointers */
594 pl->contr->link_skills (); 591 pl->contr->link_skills ();
595} 592}
614roll_stat () 611roll_stat ()
615{ 612{
616 int a[4], i, j, k; 613 int a[4], i, j, k;
617 614
618 for (i = 0; i < 4; i++) 615 for (i = 0; i < 4; i++)
619 a[i] = (int) rndm (6) + 1; 616 a[i] = rndm (1, 6);
620 617
621 for (i = 0, j = 0, k = 7; i < 4; i++) 618 for (i = 0, j = 0, k = 7; i < 4; i++)
622 if (a[i] < k) 619 if (a[i] < k)
623 k = a[i], j = i; 620 k = a[i], j = i;
624 621
721 treasurelist *tl = treasurelist::find (shstr_starting_wealth); 718 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
722 if (tl) 719 if (tl)
723 create_treasure (tl, ob, 0, 0, 0); 720 create_treasure (tl, ob, 0, 0, 0);
724 721
725 INVOKE_PLAYER (BIRTH, ob->contr); 722 INVOKE_PLAYER (BIRTH, ob->contr);
726 INVOKE_PLAYER (LOGIN, ob->contr);
727 723
728 ob->contr->ns->state = ST_PLAYING; 724 ob->contr->ns->state = ST_PLAYING;
729 725
730 if (ob->msg) 726 if (ob->msg)
731 ob->msg = 0; 727 ob->msg = 0;
732 728
733 start_info (ob); 729 start_info (ob);
734 CLEAR_FLAG (ob, FLAG_WIZ); 730 ob->clr_flag (FLAG_WIZ);
735 give_initial_items (ob, ob->randomitems); 731 give_initial_items (ob, ob->randomitems);
736 esrv_send_inventory (ob, ob); 732 esrv_send_inventory (ob, ob);
737 ob->update_stats (); 733 ob->update_stats ();
738 734
739 /* This moves the player to a different start map, if there 735 /* This moves the player to a different start map, if there
741 */ 737 */
742 if (*first_map_ext_path) 738 if (*first_map_ext_path)
743 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y); 739 ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y);
744 else 740 else
745 LOG (llevDebug, "first_map_ext_path not set\n"); 741 LOG (llevDebug, "first_map_ext_path not set\n");
742}
743
744/*
745 * Returns true if the given player is a legal class.
746 * The function to add and remove class-bonuses to the stats doesn't
747 * check if the stat becomes negative, thus this function
748 * merely checks that all stats are 1 or more, and returns
749 * false otherwise.
750 */
751static int
752allowed_class (const object *op)
753{
754 return op->stats.Dex > 0
755 && op->stats.Str > 0
756 && op->stats.Con > 0
757 && op->stats.Int > 0
758 && op->stats.Wis > 0
759 && op->stats.Pow > 0
760 && op->stats.Cha > 0;
746} 761}
747 762
748void 763void
749player::chargen_race_next () 764player::chargen_race_next ()
750{ 765{
788 rv_vector rv; 803 rv_vector rv;
789 804
790 if (op->stats.hp < 0) 805 if (op->stats.hp < 0)
791 { 806 {
792 LOG (llevDebug, "Fleeing player is dead.\n"); 807 LOG (llevDebug, "Fleeing player is dead.\n");
793 CLEAR_FLAG (op, FLAG_SCARED); 808 op->clr_flag (FLAG_SCARED);
794 return; 809 return;
795 } 810 }
796 811
797 if (!op->enemy) 812 if (!op->enemy)
798 { 813 {
799 LOG (llevDebug, "Fleeing player had no enemy.\n"); 814 LOG (llevDebug, "Fleeing player had no enemy.\n");
800 CLEAR_FLAG (op, FLAG_SCARED); 815 op->clr_flag (FLAG_SCARED);
801 return; 816 return;
802 } 817 }
803 818
804 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 819 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
805 { 820 {
806 op->enemy = NULL; 821 op->enemy = NULL;
807 CLEAR_FLAG (op, FLAG_SCARED); 822 op->clr_flag (FLAG_SCARED);
808 return; 823 return;
809 } 824 }
810 825
811 get_rangevector (op, op->enemy, &rv, 0); 826 get_rangevector (op, op->enemy, &rv, 0);
812 827
818 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) 833 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
819 return; 834 return;
820 } 835 }
821 836
822 /* Cornered, get rid of scared */ 837 /* Cornered, get rid of scared */
823 CLEAR_FLAG (op, FLAG_SCARED); 838 op->clr_flag (FLAG_SCARED);
824 op->enemy = NULL; 839 op->enemy = NULL;
825} 840}
826 841
827/* check_pick sees if there is stuff to be picked up/picks up stuff. 842/* check_pick sees if there is stuff to be picked up/picks up stuff.
828 * It returns 1 if the player should keep on moving, 0 if he should 843 * It returns 1 if the player should keep on moving, 0 if he should
920 * fighting */ 935 * fighting */
921 if (op->contr->mode & PU_INHIBIT) 936 if (op->contr->mode & PU_INHIBIT)
922 return 1; 937 return 1;
923 938
924 /* prevent us from turning into auto-thieves :) */ 939 /* prevent us from turning into auto-thieves :) */
925 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 940 if (tmp->flag [FLAG_UNPAID])
926 continue; 941 continue;
927 942
928 /* ignore known cursed objects */ 943 /* ignore known cursed objects */
929 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 944 if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED)
930 continue; 945 continue;
931 946
932 /* all food and drink if desired */ 947 /* all food and drink if desired */
933 /* question: don't pick up known-poisonous stuff? */ 948 /* question: don't pick up known-poisonous stuff? */
934 if (op->contr->mode & PU_FOOD) 949 if (op->contr->mode & PU_FOOD)
937 CHK_PICK_PICKUP; 952 CHK_PICK_PICKUP;
938 continue; 953 continue;
939 } 954 }
940 955
941 if (op->contr->mode & PU_DRINK) 956 if (op->contr->mode & PU_DRINK)
942 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 957 if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED]))
943 { 958 {
944 CHK_PICK_PICKUP; 959 CHK_PICK_PICKUP;
945 continue; 960 continue;
946 } 961 }
947 962
985 continue; 1000 continue;
986 } 1001 }
987 1002
988 /* pick up all magical items */ 1003 /* pick up all magical items */
989 if (op->contr->mode & PU_MAGICAL) 1004 if (op->contr->mode & PU_MAGICAL)
990 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) 1005 if (tmp->flag [FLAG_KNOWN_MAGICAL]
991 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1006 && !tmp->flag [FLAG_KNOWN_CURSED])
992 { 1007 {
993 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
994 continue; 1009 continue;
995 } 1010 }
996 1011
1080 continue; 1095 continue;
1081 } 1096 }
1082 1097
1083 /* hoping to catch throwing daggers here */ 1098 /* hoping to catch throwing daggers here */
1084 if (op->contr->mode & PU_MISSILEWEAPON) 1099 if (op->contr->mode & PU_MISSILEWEAPON)
1085 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1100 if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN])
1086 { 1101 {
1087 CHK_PICK_PICKUP; 1102 CHK_PICK_PICKUP;
1088 continue; 1103 continue;
1089 } 1104 }
1090 1105
1139} 1154}
1140 1155
1141/* routine for both players and monsters. We call this when 1156/* routine for both players and monsters. We call this when
1142 * there is a possibility for our action distrubing our hiding 1157 * there is a possibility for our action distrubing our hiding
1143 * place or invisiblity spell. Artefact invisiblity causes 1158 * place or invisiblity spell. Artefact invisiblity causes
1144 * "noise" instead. If we arent invisible to begin with, we 1159 * "noise" instead. If we arent invisible to begin with, we
1145 * return 0. 1160 * return 0.
1146 */ 1161 */
1147static int 1162static int
1148action_makes_visible (object *op) 1163action_makes_visible (object *op)
1149{ 1164{
1150 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) 1165 if (op->invisible && op->flag [FLAG_ALIVE])
1151 { 1166 {
1152 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 1167 if (op->flag [FLAG_MAKE_INVIS])
1153 { 1168 {
1154 // artefact invisibility is permanent, but we still make noise 1169 // artefact invisibility is permanent, but we still make noise
1155 // this is important for game-balance. 1170 // this is important for game-balance.
1156 if (op->contr) 1171 if (op->contr)
1157 op->make_noise (); 1172 op->make_noise ();
1173 return 0; 1188 return 0;
1174} 1189}
1175 1190
1176/* 1191/*
1177 * Find an arrow in the inventory and after that 1192 * Find an arrow in the inventory and after that
1178 * in the right type container (quiver). Pointer to the 1193 * in the right type container (quiver). Pointer to the
1179 * found object is returned. 1194 * found object is returned.
1180 */ 1195 */
1181static object * 1196static object *
1182find_arrow (object *op, const char *type) 1197find_arrow (object *op, const char *type)
1183{ 1198{
1184 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1199 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1185 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1200 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1186 return splay (tmp); 1201 return splay (tmp);
1187 1202
1188 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1203 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1189 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) 1204 if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type))
1190 if (object *arrow = find_arrow (tmp, type)) 1205 if (object *arrow = find_arrow (tmp, type))
1191 { 1206 {
1192 splay (tmp); 1207 splay (tmp);
1193 return arrow; 1208 return arrow;
1194 } 1209 }
1211 if (!type) 1226 if (!type)
1212 return NULL; 1227 return NULL;
1213 1228
1214 for (arrow = op->inv; arrow; arrow = arrow->below) 1229 for (arrow = op->inv; arrow; arrow = arrow->below)
1215 { 1230 {
1216 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1231 if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED])
1217 { 1232 {
1218 i = 0; 1233 i = 0;
1219 ntmp = find_better_arrow (arrow, target, type, &i); 1234 ntmp = find_better_arrow (arrow, target, type, &i);
1220 1235
1221 if (i > betterby) 1236 if (i > betterby)
1322 break; 1337 break;
1323 } 1338 }
1324 1339
1325 if (mflags & P_IS_ALIVE) 1340 if (mflags & P_IS_ALIVE)
1326 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1341 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1327 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1342 if (tmp->flag [FLAG_ALIVE])
1328 break; 1343 break;
1329 } 1344 }
1330 1345
1331 if (!tmp) 1346 if (!tmp)
1332 return find_arrow (op, type); 1347 return find_arrow (op, type);
1336 1351
1337 return find_better_arrow (op, tmp, type, &i); 1352 return find_better_arrow (op, tmp, type, &i);
1338} 1353}
1339 1354
1340/* 1355/*
1341 * Creature fires a bow - op can be monster or player. Returns 1356 * Creature fires a bow - op can be monster or player. Returns
1342 * 1 if bow was actually fired, 0 otherwise. 1357 * 1 if bow was actually fired, 0 otherwise.
1343 * op is the object firing the bow. 1358 * op is the object firing the bow.
1344 * part is for multipart creatures - the part firing the bow. 1359 * part is for multipart creatures - the part firing the bow.
1345 * dir is the direction of fire. 1360 * dir is the direction of fire.
1346 * wc_mod is any special modifier to give (used in special player fire modes) 1361 * wc_mod is any special modifier to give (used in special player fire modes)
1393 { 1408 {
1394 if (op->type == PLAYER) 1409 if (op->type == PLAYER)
1395 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1410 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1396 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ 1411 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1397 else 1412 else
1398 CLEAR_FLAG (op, FLAG_READY_BOW); 1413 op->clr_flag (FLAG_READY_BOW);
1399 1414
1400 return 0; 1415 return 0;
1401 } 1416 }
1402 } 1417 }
1403 1418
1452#endif 1467#endif
1453 1468
1454 SET_ANIMATION (arrow, arrow->direction); 1469 SET_ANIMATION (arrow, arrow->direction);
1455 1470
1456 /* update the speed */ 1471 /* update the speed */
1457 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1458 + bow->stats.dam / 7.f;
1459 1472
1460 arrow->set_speed (max (arrow->speed, 2.f));
1461 arrow->speed_left = 0; 1473 arrow->speed_left = 0;
1474 arrow->set_speed (max (2.f,
1475 ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1476 + bow->stats.dam / 7.f
1477 ));
1462 1478
1463 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1479 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1464 1480
1465 if (op->type == PLAYER) 1481 if (op->type == PLAYER)
1466 { 1482 {
1487 arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM); 1503 arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM);
1488 1504
1489 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); 1505 arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC);
1490 arrow->move_type = MOVE_FLY_LOW; 1506 arrow->move_type = MOVE_FLY_LOW;
1491 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; 1507 arrow->move_on = MOVE_FLY_LOW | MOVE_WALK;
1508 arrow->set_flag (FLAG_NO_PICK);
1492 1509
1493 op->play_sound (sound_find ("fire_arrow")); 1510 op->play_sound (sound_find ("fire_arrow"));
1494 m->insert (arrow, sx, sy, op); 1511 m->insert (arrow, sx, sy, op);
1495 1512
1496 if (!arrow->destroyed ()) 1513 if (!arrow->destroyed ())
1599 1616
1600 if (item->type == WAND) 1617 if (item->type == WAND)
1601 { 1618 {
1602 if (!(--item->stats.food)) 1619 if (!(--item->stats.food))
1603 { 1620 {
1604 object *tmp;
1605
1606 if (item->arch) 1621 if (item->arch)
1607 { 1622 {
1608 CLEAR_FLAG (item, FLAG_ANIMATE); 1623 item->clr_flag (FLAG_ANIMATE);
1609 item->face = item->arch->face; 1624 item->face = item->arch->face;
1610 item->set_speed (0); 1625 item->set_speed (0);
1611 } 1626 }
1612 1627
1613 if (object *pl = item->visible_to ()) 1628 if (object *pl = item->visible_to ())
1694 for (tmp = container->inv; tmp; tmp = tmp->below) 1709 for (tmp = container->inv; tmp; tmp = tmp->below)
1695 { 1710 {
1696 if (door->type == DOOR && tmp->type == KEY) 1711 if (door->type == DOOR && tmp->type == KEY)
1697 break; 1712 break;
1698 1713
1699 /* For sanity, we should really check door type, but other stuff 1714 /* For sanity, we should really check door type, but other stuff
1700 * (like containers) can be locked with special keys 1715 * (like containers) can be locked with special keys
1701 */ 1716 */
1702 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) 1717 if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying)
1703 break; 1718 break;
1704 } 1719 }
1741 * 1756 *
1742 * Change the color so that the message doesn't disappear with 1757 * Change the color so that the message doesn't disappear with
1743 * all the others. 1758 * all the others.
1744 */ 1759 */
1745 if (pl->contr->usekeys == key_inventory 1760 if (pl->contr->usekeys == key_inventory
1746 || !QUERY_FLAG (container, FLAG_APPLIED) 1761 || !container->flag [FLAG_APPLIED]
1747 || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1762 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1748 { 1763 {
1749 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1764 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1750 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1765 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1751 return NULL; 1766 return NULL;
1758/* find_key 1773/* find_key
1759 * We try to find a key for the door as passed. If we find a key 1774 * We try to find a key for the door as passed. If we find a key
1760 * and successfully use it, we return the key, otherwise NULL 1775 * and successfully use it, we return the key, otherwise NULL
1761 * This function merges both normal and locked door, since the logic 1776 * This function merges both normal and locked door, since the logic
1762 * for both is the same - just the specific key is different. 1777 * for both is the same - just the specific key is different.
1763 * pl is the player, 1778 * pl is the player,
1764 * inv is the objects inventory to searched 1779 * inv is the objects inventory to searched
1765 * door is the door we are trying to match against. 1780 * door is the door we are trying to match against.
1766 * This function can be called recursively to search containers. 1781 * This function can be called recursively to search containers.
1767 */ 1782 */
1768object * 1783object *
1769find_key (object *pl, object *container, object *door) 1784find_key (object *pl, object *container, object *door)
1873 || mon->flag [FLAG_CAN_ROLL]) 1888 || mon->flag [FLAG_CAN_ROLL])
1874 && mon != op) 1889 && mon != op)
1875 break; 1890 break;
1876 } 1891 }
1877 1892
1878 if (!mon) /* This happens anytime the player tries to move */ 1893 /* no monster == player tries to move into a wall or so */
1879 return false; /* into a wall */ 1894 if (!mon)
1895 {
1896 for (object *ob = m->at (nx, ny).top; ob; ob = ob->below)
1897 if (op->move_type & ob->move_block)
1898 {
1899 if (ob->move_block == MOVE_ALL)
1900 move_into_wall (op, ob);
1901 else
1902 {
1903 if (op->contr->ns->bumpmsg)
1904 {
1905 op->play_sound (sound_find ("blocked_move"));
1906
1907 op->statusmsg (ob->invisible
1908 ? "Something blocks you."
1909 : format ("Something blocks you from entering the %s.", query_name (ob))
1910 );
1911 }
1912 }
1913
1914 break;
1915 }
1916
1917 return false;
1918 }
1880 1919
1881 mon = mon->head_ (); 1920 mon = mon->head_ ();
1882 1921
1883 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 1922 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
1884 if (op->contr->weapon_sp_left > 0.f) 1923 if (op->contr->weapon_sp_left > 0.f)
1902 */ 1941 */
1903 if (op->type == PLAYER 1942 if (op->type == PLAYER
1904 && ((mon->owner && mon->owner->contr 1943 && ((mon->owner && mon->owner->contr
1905 && same_party (mon->owner->contr->party, op->contr->party)) 1944 && same_party (mon->owner->contr->party, op->contr->party))
1906 || mon->owner == op) 1945 || mon->owner == op)
1907 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 1946 && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]))
1908 { 1947 {
1909 /* If we're braced, we don't want to switch places with it */ 1948 /* If we're braced, we don't want to switch places with it */
1910 if (op->contr->braced) 1949 if (op->contr->braced)
1911 return false; 1950 return false;
1912 1951
1932 * creatures. Note that if you are braced, you can't push 1971 * creatures. Note that if you are braced, you can't push
1933 * someone, but put it inside this loop so that you won't 1972 * someone, but put it inside this loop so that you won't
1934 * attack them either. 1973 * attack them either.
1935 */ 1974 */
1936 if ((mon->type == PLAYER || mon->enemy != op) 1975 if ((mon->type == PLAYER || mon->enemy != op)
1937 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 1976 && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])
1938 && ((op->contr->peaceful 1977 && ((op->contr->peaceful
1939 || (mon->type == PLAYER && mon->contr->peaceful)) 1978 || (mon->type == PLAYER && mon->contr->peaceful))
1940 && !on_battleground)) 1979 && !on_battleground))
1941 { 1980 {
1942 if (op->speed_left > 0.f) 1981 if (op->speed_left > 0.f)
1958 } 1997 }
1959 } 1998 }
1960 /* If the object is a boulder or other rollable object, then 1999 /* If the object is a boulder or other rollable object, then
1961 * roll it if not braced. You can't roll it if you are braced. 2000 * roll it if not braced. You can't roll it if you are braced.
1962 */ 2001 */
1963 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 2002 else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced))
1964 { 2003 {
1965 if (op->speed_left > 0.f) 2004 if (op->speed_left > 0.f)
1966 { 2005 {
1967 --op->speed_left; 2006 --op->speed_left;
1968 2007
1977 * Way it works is like this: First, it must have some hit points 2016 * Way it works is like this: First, it must have some hit points
1978 * and be living. Then, it must be one of the following: 2017 * and be living. Then, it must be one of the following:
1979 * 1) Not a player, 2) A player, but of a different party. Note 2018 * 1) Not a player, 2) A player, but of a different party. Note
1980 * that party_number -1 is no party, so attacks can still happen. 2019 * that party_number -1 is no party, so attacks can still happen.
1981 */ 2020 */
1982 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2021 else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] &&
1983 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2022 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
1984 { 2023 {
1985 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) 2024 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
1986 { 2025 {
1987 --op->contr->weapon_sp_left; 2026 --op->contr->weapon_sp_left;
1999} 2038}
2000 2039
2001bool 2040bool
2002move_player (object *op, int dir) 2041move_player (object *op, int dir)
2003{ 2042{
2004 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2043 if (!op->map || op->map->state != MAP_ACTIVE)
2005 return 0; 2044 return 0;
2006 2045
2007 /* Sanity check: make sure dir is valid */ 2046 /* Sanity check: make sure dir is valid */
2008 if (dir < 0 || dir >= 9) 2047 if (dir < 0 || dir > 8)
2009 { 2048 {
2010 LOG (llevError, "move_player: invalid direction %d\n", dir); 2049 LOG (llevError, "move_player: invalid direction %d\n", dir);
2011 return 0; 2050 return 0;
2012 } 2051 }
2013 2052
2014 /* peterm: added following line */ 2053 /* peterm: added following line */
2015 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2054 if (op->flag [FLAG_CONFUSED] && dir)
2016 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2055 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2017 2056
2018 op->facing = dir; 2057 op->facing = dir;
2019 2058
2020 if (op->flag [FLAG_HIDDEN]) 2059 if (op->flag [FLAG_HIDDEN])
2060 * players. 2099 * players.
2061 */ 2100 */
2062bool 2101bool
2063handle_newcs_player (object *op) 2102handle_newcs_player (object *op)
2064{ 2103{
2065 if (QUERY_FLAG (op, FLAG_SCARED)) 2104 if (op->flag [FLAG_SCARED])
2066 { 2105 {
2067 if (op->speed_left > 0.f) 2106 if (op->speed_left > 0.f)
2068 { 2107 {
2069 --op->speed_left; 2108 --op->speed_left;
2070 flee_player (op); 2109 flee_player (op);
2089} 2128}
2090 2129
2091static int 2130static int
2092save_life (object *op) 2131save_life (object *op)
2093{ 2132{
2094 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2133 if (!op->flag [FLAG_LIFESAVE])
2095 return 0; 2134 return 0;
2096 2135
2097 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2136 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2098 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2137 if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE])
2099 { 2138 {
2100 op->play_sound (sound_find ("ob_evaporate")); 2139 op->play_sound (sound_find ("ob_evaporate"));
2101 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2140 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2102 2141
2103 tmp->destroy (); 2142 tmp->destroy ();
2104 CLEAR_FLAG (op, FLAG_LIFESAVE); 2143 op->clr_flag (FLAG_LIFESAVE);
2105 2144
2106 if (op->stats.hp < 0) 2145 if (op->stats.hp < 0)
2107 op->stats.hp = op->stats.maxhp; 2146 op->stats.hp = op->stats.maxhp;
2108 2147
2109 if (op->stats.food < 0) 2148 if (op->stats.food < 0)
2112 op->update_stats (); 2151 op->update_stats ();
2113 return 1; 2152 return 1;
2114 } 2153 }
2115 2154
2116 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2155 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2117 CLEAR_FLAG (op, FLAG_LIFESAVE); 2156 op->clr_flag (FLAG_LIFESAVE);
2118 enter_player_savebed (op); /* bring him home. */ 2157 enter_player_savebed (op); /* bring him home. */
2119 return 0; 2158 return 0;
2120} 2159}
2121 2160
2122/* This goes throws the inventory and removes unpaid objects, and puts them 2161/* This goes throws the inventory and removes unpaid objects, and puts them
2129{ 2168{
2130 while (op) 2169 while (op)
2131 { 2170 {
2132 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2171 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2133 2172
2134 if (QUERY_FLAG (op, FLAG_UNPAID)) 2173 if (op->flag [FLAG_UNPAID])
2135 op->insert_at (env); 2174 op->insert_at (env);
2136 else if (op->inv) 2175 else if (op->inv)
2137 drop_unpaid_items (op->inv, env); 2176 drop_unpaid_items (op->inv, env);
2138 2177
2139 op = next; 2178 op = next;
2150void 2189void
2151do_some_living (object *op) 2190do_some_living (object *op)
2152{ 2191{
2153 int last_food = op->stats.food; 2192 int last_food = op->stats.food;
2154 int gen_hp, gen_sp, gen_grace; 2193 int gen_hp, gen_sp, gen_grace;
2155 int over_hp, over_sp, over_grace;
2156 int i;
2157 int rate_hp = 1200; 2194 int rate_hp = 1200;
2158 int rate_sp = 2500; 2195 int rate_sp = 2500;
2159 int rate_grace = 2000; 2196 int rate_grace = 2000;
2160 const int max_hp = 1; 2197 const int max_hp = 1;
2161 const int max_sp = 1; 2198 const int max_sp = 1;
2162 const int max_grace = 1; 2199 const int max_grace = 1;
2163 2200
2201#if 0
2164 if (op->contr->hidden) 2202 if (op->contr->hidden)
2165 { 2203 {
2166 op->invisible = 1000; 2204 op->invisible = 1000;
2167 /* the socket code flashes the player visible/invisible 2205 /* the socket code flashes the player visible/invisible
2168 * depending on the value of invisible, so we need to 2206 * depending on the value of invisible, so we need to
2169 * alternate it here for it to work correctly. 2207 * alternate it here for it to work correctly.
2170 */ 2208 */
2171 if (pticks & 2) 2209 if (server_tick & 2)
2172 op->invisible--; 2210 op->invisible--;
2173 } 2211 }
2212 else
2213#endif
2174 else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) 2214 if (op->invisible && !(op->flag [FLAG_MAKE_INVIS]))
2175 { 2215 {
2176 if (!op->invisible--) 2216 if (!op->invisible--)
2177 { 2217 {
2178 make_visible (op); 2218 make_visible (op);
2179 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2219 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2213 if (--op->last_grace < 0) 2253 if (--op->last_grace < 0)
2214 { 2254 {
2215 if (op->stats.grace < op->stats.maxgrace / 2) 2255 if (op->stats.grace < op->stats.maxgrace / 2)
2216 op->stats.grace++; /* no penalty in food for regaining grace */ 2256 op->stats.grace++; /* no penalty in food for regaining grace */
2217 2257
2258 int temp = gen_grace < 20 ? 30 : gen_grace + 10;
2259
2218 if (max_grace > 1) 2260 if (max_grace > 1)
2219 { 2261 {
2220 over_grace = (gen_grace < 20 ? 30 : gen_grace + 10) / rate_grace; 2262 int over_grace = temp / rate_grace;
2263
2221 if (over_grace > 0) 2264 if (over_grace > 0)
2222 { 2265 {
2223 op->stats.sp += over_grace 2266 op->stats.sp += over_grace + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > (temp % rate_grace)) ? -1 : 0;
2224 + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > ((gen_grace < 20 ? 30 : gen_grace + 10) % rate_grace)) ? -1 : 0;
2225 op->last_grace = 0; 2267 op->last_grace = 0;
2226 } 2268 }
2227 else 2269 else
2228 { 2270 op->last_grace = rate_grace / temp;
2229 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10);
2230 }
2231 } 2271 }
2232 else 2272 else
2233 { 2273 op->last_grace = rate_grace / temp;
2234 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); 2274
2235 }
2236 /* wearing stuff doesn't detract from grace generation. */ 2275 /* wearing stuff doesn't detract from grace generation. */
2237 } 2276 }
2238 2277
2239 if (op->stats.food > 0) 2278 if (op->stats.food > 0)
2240 { 2279 {
2246 if (op->stats.sp < op->stats.maxsp) 2285 if (op->stats.sp < op->stats.maxsp)
2247 { 2286 {
2248 op->stats.sp++; 2287 op->stats.sp++;
2249 2288
2250 /* dms do not consume food */ 2289 /* dms do not consume food */
2251 if (!QUERY_FLAG (op, FLAG_WIZ)) 2290 if (!op->flag [FLAG_WIZ])
2252 { 2291 {
2253 op->stats.food--; 2292 op->stats.food--;
2254 2293
2255 if (op->contr->digestion < 0) 2294 if (op->contr->digestion < 0)
2256 op->stats.food += op->contr->digestion; 2295 op->stats.food += op->contr->digestion;
2259 } 2298 }
2260 } 2299 }
2261 2300
2262 if (max_sp > 1) 2301 if (max_sp > 1)
2263 { 2302 {
2264 over_sp = (gen_sp + 10) / rate_sp; 2303 int over_sp = (gen_sp + 10) / rate_sp;
2265 if (over_sp > 0) 2304 if (over_sp > 0)
2266 { 2305 {
2267 if (op->stats.sp < op->stats.maxsp) 2306 if (op->stats.sp < op->stats.maxsp)
2268 { 2307 {
2269 op->stats.sp += over_sp > max_sp ? max_sp : over_sp; 2308 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2290 if (op->stats.hp < op->stats.maxhp) 2329 if (op->stats.hp < op->stats.maxhp)
2291 { 2330 {
2292 op->stats.hp++; 2331 op->stats.hp++;
2293 2332
2294 /* dms do not consume food */ 2333 /* dms do not consume food */
2295 if (!QUERY_FLAG (op, FLAG_WIZ)) 2334 if (!op->flag [FLAG_WIZ])
2296 { 2335 {
2297 op->stats.food--; 2336 op->stats.food--;
2298 2337
2299 if (op->contr->digestion < 0) 2338 if (op->contr->digestion < 0)
2300 op->stats.food += op->contr->digestion; 2339 op->stats.food += op->contr->digestion;
2301 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2340 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2302 op->stats.food = last_food; 2341 op->stats.food = last_food;
2303 } 2342 }
2304 } 2343 }
2305 2344
2345 int temp = gen_hp < 20 ? 30 : gen_hp + 10;
2346
2306 if (max_hp > 1) 2347 if (max_hp > 1)
2307 { 2348 {
2308 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2349 int over_hp = temp / rate_hp;
2309 2350
2310 if (over_hp > 0) 2351 if (over_hp > 0)
2311 { 2352 {
2312 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2353 op->stats.sp += over_hp + (random_roll (0, rate_hp - 1, op, PREFER_HIGH) > (temp % rate_hp)) ? -1 : 0;
2313 op->last_heal = 0; 2354 op->last_heal = 0;
2314 } 2355 }
2315 else 2356 else
2316 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2357 op->last_heal = rate_hp / temp;
2317 } 2358 }
2318 else 2359 else
2319 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2360 op->last_heal = rate_hp / temp;
2320 } 2361 }
2321 } 2362 }
2322 2363
2323 /* Digestion */ 2364 /* Digestion */
2324 if (--op->last_eat < 0) 2365 if (--op->last_eat < 0)
2327 penalty = max (0, -op->contr->digestion); 2368 penalty = max (0, -op->contr->digestion);
2328 2369
2329 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); 2370 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2330 2371
2331 /* dms do not consume food */ 2372 /* dms do not consume food */
2332 if (!QUERY_FLAG (op, FLAG_WIZ)) 2373 if (!op->flag [FLAG_WIZ])
2333 op->stats.food--; 2374 op->stats.food--;
2334 } 2375 }
2335 2376
2336 if (op->stats.food < 0 && op->stats.hp >= 0) 2377 if (op->stats.food < 0 && op->stats.hp >= 0)
2337 { 2378 {
2338 object *flesh = 0; 2379 object *flesh = 0;
2339 2380
2340 for_inv_removable (op, tmp) 2381 for_inv_removable (op, tmp)
2341 { 2382 {
2342 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 2383 if (tmp->flag [FLAG_UNPAID])
2343 continue; 2384 continue;
2344 2385
2345 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2386 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2346 { 2387 {
2347 op->statusmsg ("You blindly grab for a bite of food. " 2388 op->statusmsg ("You blindly grab for a bite of food. "
2382 op->contr->killer->destroy (); 2423 op->contr->killer->destroy ();
2383 } 2424 }
2384 } 2425 }
2385 2426
2386 /* killer should be set here already */ 2427 /* killer should be set here already */
2387 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2428 if (op->stats.hp < 0 && !op->flag [FLAG_WIZ])
2388 kill_player (op); 2429 kill_player (op);
2389 } 2430 }
2390} 2431}
2391 2432
2392/* If the player should die (lack of hp, food, etc), we call this. 2433/* If the player should die (lack of hp, food, etc), we call this.
2561 2602
2562 /* There is a maximum depletion total per level. */ 2603 /* There is a maximum depletion total per level. */
2563 if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO) 2604 if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO)
2564 { 2605 {
2565 lose_this_stat = 0; 2606 lose_this_stat = 0;
2566 /* Take loss chance vs keep chance to see if we 2607 /* Take loss chance vs keep chance to see if we
2567 retain the stat. */ 2608 retain the stat. */
2568 } 2609 }
2569 else 2610 else
2570 { 2611 {
2571 if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance) 2612 if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance)
2587 * difference. 2628 * difference.
2588 */ 2629 */
2589 if (this_stat >= -50) 2630 if (this_stat >= -50)
2590 { 2631 {
2591 change_attr_value (&(dep->stats), i, -1); 2632 change_attr_value (&(dep->stats), i, -1);
2592 SET_FLAG (dep, FLAG_APPLIED); 2633 dep->set_flag (FLAG_APPLIED);
2593 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2634 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2594 op->update_stats (); 2635 op->update_stats ();
2595 lost_a_stat = 1; 2636 lost_a_stat = 1;
2596 } 2637 }
2597 } 2638 }
2664 if (will_kill_again) 2705 if (will_kill_again)
2665 { 2706 {
2666 object *force; 2707 object *force;
2667 int at; 2708 int at;
2668 2709
2669 force = get_archetype (FORCE_NAME); 2710 force = archetype::get (FORCE_NAME);
2670 /* 50 ticks should be enough time for the spell to abate */ 2711 /* 50 ticks should be enough time for the spell to abate */
2671 force->speed = 0.1f;
2672 force->speed_left = -5.f; 2712 force->speed_left = -5.f;
2673 SET_FLAG (force, FLAG_APPLIED); 2713 force->set_speed (0.1f);
2714 force->set_flag (FLAG_APPLIED);
2715
2674 for (at = 0; at < NROFATTACKS; at++) 2716 for (at = 0; at < NROFATTACKS; at++)
2675 if (will_kill_again & (1 << at)) 2717 if (will_kill_again & (1 << at))
2676 force->resist[at] = 100; 2718 force->resist[at] = 100;
2677 2719
2678 insert_ob_in_ob (force, op); 2720 insert_ob_in_ob (force, op);
2683} 2725}
2684 2726
2685static void 2727static void
2686loot_object (object *op) 2728loot_object (object *op)
2687{ /* Grab and destroy some treasure */ 2729{ /* Grab and destroy some treasure */
2688 object *tmp, *tmp2, *next; 2730 object *tmp, *next;
2689 2731
2690 op->close_container (); /* close open sack first */ 2732 op->close_container (); /* close open sack first */
2691 2733
2692 for (tmp = op->inv; tmp; tmp = next) 2734 for (tmp = op->inv; tmp; tmp = next)
2693 { 2735 {
2700 tmp->x = op->x, tmp->y = op->y; 2742 tmp->x = op->x, tmp->y = op->y;
2701 2743
2702 if (tmp->type == CONTAINER) 2744 if (tmp->type == CONTAINER)
2703 loot_object (tmp); /* empty container to ground */ 2745 loot_object (tmp); /* empty container to ground */
2704 2746
2705 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2747 if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3))))
2706 { 2748 {
2707 if (tmp->nrof > 1) 2749 if (tmp->nrof > 1)
2708 { 2750 {
2709 tmp->decrease (rndm (1, tmp->nrof - 1)); 2751 tmp->decrease (rndm (1, tmp->nrof - 1));
2710 insert_ob_in_map (tmp, op->map, NULL, 0); 2752 insert_ob_in_map (tmp, op->map, NULL, 0);
2725void 2767void
2726fix_weight () 2768fix_weight ()
2727{ 2769{
2728 for_all_players (pl) 2770 for_all_players (pl)
2729 { 2771 {
2730 sint32 old = pl->ob->carrying; 2772 weight_t old = pl->ob->carrying;
2731 2773
2732 pl->ob->update_weight (); 2774 pl->ob->update_weight ();
2733 2775
2734 if (old != pl->ob->carrying) 2776 if (old != pl->ob->carrying)
2735 { 2777 {
2800} 2842}
2801 2843
2802int 2844int
2803is_true_undead (object *op) 2845is_true_undead (object *op)
2804{ 2846{
2805 if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) 2847 if (op->arch->flag [FLAG_UNDEAD])
2806 return 1; 2848 return 1;
2807 2849
2808 return 0; 2850 return 0;
2809} 2851}
2810 2852
2908 2950
2909 if (who->type == PLAYER) 2951 if (who->type == PLAYER)
2910 player = 1; 2952 player = 1;
2911 2953
2912 else 2954 else
2913 friendly = QUERY_FLAG (who, FLAG_FRIENDLY); 2955 friendly = who->flag [FLAG_FRIENDLY];
2914 2956
2915 /* search adjacent squares */ 2957 /* search adjacent squares */
2916 for (i = 1; i < 9; i++) 2958 for (i = 1; i < 9; i++)
2917 { 2959 {
2918 x = who->x + freearr_x[i]; 2960 x = who->x + freearr_x[i];
2927 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 2969 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
2928 continue; 2970 continue;
2929 2971
2930 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 2972 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
2931 { 2973 {
2932 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 2974 if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE])
2933 return 1; 2975 return 1;
2934 else if (tmp->type == PLAYER) 2976 else if (tmp->type == PLAYER)
2935 {
2936 /*don't let a hidden DM prevent you from hiding */
2937 if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0)
2938 return 1; 2977 return 1;
2939 }
2940 } 2978 }
2941 } 2979 }
2942 return 0; 2980 return 0;
2943} 2981}
2944 2982
2945/* check the player los field for viewability of the 2983/* check the player los field for viewability of the
2946 * object op. This function works fine for monsters, 2984 * object op. This function works fine for monsters,
2947 * but we dont worry if the object isnt the top one in 2985 * but we dont worry if the object isnt the top one in
2948 * a pile (say a coin under a table would return "viewable" 2986 * a pile (say a coin under a table would return "viewable"
2949 * by this routine). Another question, should we be 2987 * by this routine). Another question, should we be
2950 * concerned with the direction the player is looking 2988 * concerned with the direction the player is looking
2951 * in? Realistically, most of us can't see stuff behind 2989 * in? Realistically, most of us can't see stuff behind
2952 * our backs...on the other hand, does the "facing" direction 2990 * our backs...on the other hand, does the "facing" direction
2953 * imply the way your head, or body is facing? It's possible 2991 * imply the way your head, or body is facing? It's possible
2954 * for them to differ. Sigh, this fctn could get a bit more complex. 2992 * for them to differ. Sigh, this fctn could get a bit more complex.
2955 * -b.t. 2993 * -b.t.
2956 * This function is now map tiling safe. 2994 * This function is now map tiling safe.
2957 */ 2995 */
2958int 2996int
2959player_can_view (object *pl, object *op) 2997player_can_view (object *pl, object *op)
2960{ 2998{
2974 3012
2975 get_rangevector (pl, op, &rv, 0x1); 3013 get_rangevector (pl, op, &rv, 0x1);
2976 3014
2977 /* starting with the 'head' part, lets loop 3015 /* starting with the 'head' part, lets loop
2978 * through the object and find if it has any 3016 * through the object and find if it has any
2979 * part that is in the los array but isn't on 3017 * part that is in the los array but isn't on
2980 * a blocked los square. 3018 * a blocked los square.
2981 * we use the archetype to figure out offsets. 3019 * we use the archetype to figure out offsets.
2982 */ 3020 */
2983 while (op) 3021 while (op)
2984 { 3022 {
3011 * and the exit-coordinates sp/hp must both be > 0. 3049 * and the exit-coordinates sp/hp must both be > 0.
3012 * => The intention here is to prevent abuse of the battleground- 3050 * => The intention here is to prevent abuse of the battleground-
3013 * feature (like pickable or hidden battleground tiles). */ 3051 * feature (like pickable or hidden battleground tiles). */
3014 for (object *tmp = op->below; tmp; tmp = tmp->below) 3052 for (object *tmp = op->below; tmp; tmp = tmp->below)
3015 { 3053 {
3016 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3054 if (tmp->flag [FLAG_IS_FLOOR])
3017 { 3055 {
3018 if (QUERY_FLAG (tmp, FLAG_NO_PICK) 3056 if (tmp->flag [FLAG_NO_PICK]
3019 && tmp->type == BATTLEGROUND 3057 && tmp->type == BATTLEGROUND
3020 && tmp->name == shstr_battleground 3058 && tmp->name == shstr_battleground
3021 && EXIT_X (tmp) && EXIT_Y (tmp)) 3059 && EXIT_X (tmp) && EXIT_Y (tmp))
3022 { 3060 {
3023 /* before we assign the exit, check if this is a teambattle */ 3061 /* before we assign the exit, check if this is a teambattle */
3181 strcat (buf, "."); 3219 strcat (buf, ".");
3182 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3220 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3183 } 3221 }
3184 3222
3185 /* evtl. adding flags: */ 3223 /* evtl. adding flags: */
3186 if (QUERY_FLAG (item, FLAG_XRAYS)) 3224 if (item->flag [FLAG_XRAYS])
3187 SET_FLAG (skin, FLAG_XRAYS); 3225 skin->set_flag (FLAG_XRAYS);
3188 if (QUERY_FLAG (item, FLAG_STEALTH)) 3226 if (item->flag [FLAG_STEALTH])
3189 SET_FLAG (skin, FLAG_STEALTH); 3227 skin->set_flag (FLAG_STEALTH);
3190 if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) 3228 if (item->flag [FLAG_SEE_IN_DARK])
3191 SET_FLAG (skin, FLAG_SEE_IN_DARK); 3229 skin->set_flag (FLAG_SEE_IN_DARK);
3192 3230
3193 /* print message if there is one */ 3231 /* print message if there is one */
3194 if (item->msg != NULL) 3232 if (item->msg != NULL)
3195 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3233 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3196 } 3234 }
3238{ 3276{
3239 play_sound (sound_find ("generic_failure")); 3277 play_sound (sound_find ("generic_failure"));
3240 statusmsg (msg, color); 3278 statusmsg (msg, color);
3241} 3279}
3242 3280
3281void
3282object::failmsgf (const char *format, ...)
3283{
3284 if (!contr)
3285 return;
3286
3287 va_list ap;
3288 va_start (ap, format);
3289 contr->failmsg (vformat (format, ap));
3290 va_end (ap);
3291}
3292
3293void
3294player::failmsgf (const char *format, ...)
3295{
3296 va_list ap;
3297 va_start (ap, format);
3298 failmsg (vformat (format, ap));
3299 va_end (ap);
3300}
3301

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines