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.233 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.286 by root, Wed May 4 19:04:45 2011 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 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.
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
26
27#include <algorithm>
28#include <functional>
29
25#include <global.h> 30#include <global.h>
26#include <sproto.h> 31#include <sproto.h>
27#include <sounds.h> 32#include <sounds.h>
28#include <living.h> 33#include <living.h>
29#include <object.h> 34#include <object.h>
30#include <spells.h> 35#include <spells.h>
31#include <skills.h> 36#include <skills.h>
32 37
33#include <algorithm>
34#include <functional>
35
36playervec players; 38playervec players;
37
38void
39display_motd (const object *op)
40{
41 char buf[MAX_BUF];
42 char motd[HUGE_BUF];
43 FILE *fp;
44 int comp;
45 int size;
46
47 sprintf (buf, "%s/%s", settings.confdir, settings.motd);
48 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
49 return;
50
51 motd[0] = '\0';
52 size = 0;
53
54 while (fgets (buf, MAX_BUF, fp))
55 {
56 if (*buf == '#')
57 continue;
58
59 strncat (motd + size, buf, HUGE_BUF - size);
60 size += strlen (buf);
61 }
62
63 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL);
64 close_and_delete (fp, comp);
65}
66
67void
68send_rules (const object *op)
69{
70 char buf[MAX_BUF];
71 char rules[HUGE_BUF];
72 FILE *fp;
73 int comp;
74 int size;
75
76 sprintf (buf, "%s/%s", settings.confdir, settings.rules);
77 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
78 return;
79
80 rules[0] = '\0';
81 size = 0;
82
83 while (fgets (buf, MAX_BUF, fp))
84 {
85 if (*buf == '#')
86 continue;
87
88 if (size + strlen (buf) >= HUGE_BUF)
89 {
90 LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
91 break;
92 }
93
94 strncat (rules + size, buf, HUGE_BUF - size);
95 size += strlen (buf);
96 }
97
98 draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL);
99 close_and_delete (fp, comp);
100}
101
102void
103send_news (const object *op)
104{
105 char buf[MAX_BUF];
106 char news[HUGE_BUF];
107 char subject[MAX_BUF];
108 FILE *fp;
109 int comp;
110 int size;
111
112 sprintf (buf, "%s/%s", settings.confdir, settings.news);
113 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
114 return;
115
116 news[0] = '\0';
117 subject[0] = '\0';
118 size = 0;
119
120 while (fgets (buf, MAX_BUF, fp))
121 {
122 if (*buf == '#')
123 continue;
124
125 if (*buf == '%')
126 { /* send one news */
127 if (size > 0)
128 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
129 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS,
130 "INFORMATION: %s\n%s", (char *)"%s\n%s",
131 subject, news); /*send previously read news */
132
133 strcpy (subject, buf + 1);
134 strip_endline (subject);
135 size = 0;
136 news[0] = '\0';
137 }
138 else
139 {
140 if (size + strlen (buf) >= HUGE_BUF)
141 {
142 LOG (llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF);
143 break;
144 }
145 strncat (news + size, buf, HUGE_BUF - size);
146 size += strlen (buf);
147 }
148 }
149
150 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op,
151 MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news);
152 close_and_delete (fp, comp);
153}
154 39
155/* This loads the first map an puts the player on it. */ 40/* This loads the first map an puts the player on it. */
156static void 41static void
157set_first_map (object *op) 42set_first_map (object *op)
158{ 43{
169 54
170 players.insert (this); 55 players.insert (this);
171 ob->remove (); 56 ob->remove ();
172 ob->map = 0; 57 ob->map = 0;
173 ob->activate_recursive (); 58 ob->activate_recursive ();
174 CLEAR_FLAG (ob, FLAG_FRIENDLY); 59 ob->clr_flag (FLAG_FRIENDLY);
175 add_friendly_object (ob); 60 add_friendly_object (ob);
176} 61}
177 62
178void 63void
179player::deactivate () 64player::deactivate ()
191 ob->remove (); 76 ob->remove ();
192 ob->enemy = 0; // sometimes keeps an extra refcount on itself 77 ob->enemy = 0; // sometimes keeps an extra refcount on itself
193 ob->map = 0; 78 ob->map = 0;
194 party = 0; 79 party = 0;
195 80
196 combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this
197
198 players.erase (this); 81 players.erase (this);
199} 82}
200 83
201// connect the player with a specific client 84// connect the player with a specific client
202// also changes, rationalises, and fixes some incorrect settings 85// also changes, rationalises, and fixes some incorrect settings
222 ob->race = ob->arch->race; 105 ob->race = ob->arch->race;
223 106
224 ob->update_weight (); 107 ob->update_weight ();
225 link_skills (); 108 link_skills ();
226 109
227 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
228
229 assign (title, ob->arch->object::name); 110 assign (title, ob->arch->object::name);
230 111
231 /* if it's a dragon player, set the correct title here */ 112 /* if it's a dragon player, set the correct title here */
232 if (is_dragon_pl (ob)) 113 if (ob->is_dragon ())
233 { 114 {
234 object *tmp, *abil = 0, *skin = 0; 115 object *tmp, *abil = 0, *skin = 0;
235 116
236 for (tmp = ob->inv; tmp; tmp = tmp->below) 117 for (tmp = ob->inv; tmp; tmp = tmp->below)
237 if (tmp->type == FORCE) 118 if (tmp->type == FORCE)
245 126
246 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 127 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
247 128
248 esrv_new_player (this); 129 esrv_new_player (this);
249 130
131 ob->flag [FLAG_READY_WEAPON] = false;
132 ob->flag [FLAG_READY_SKILL] = false;
133 ob->flag [FLAG_READY_RANGE] = false;
134 ob->flag [FLAG_READY_BOW] = false;
135
250 ob->update_stats (); 136 ob->update_stats ();
251 137
252 ns->floorbox_update (); 138 ns->floorbox_update ();
253 esrv_send_inventory (ob, ob); 139 esrv_send_inventory (ob, ob);
254 esrv_add_spells (this, 0); 140 esrv_add_spells (this, 0);
255 141
256 activate (); 142 activate ();
257 143
258 send_rules (ob);
259 send_news (ob);
260 display_motd (ob);
261
262 INVOKE_PLAYER (CONNECT, this); 144 INVOKE_PLAYER (CONNECT, this);
263 INVOKE_PLAYER (LOGIN, this); 145 INVOKE_PLAYER (LOGIN, this);
264} 146}
265 147
266void 148void
282 ns->reset_stats (); 164 ns->reset_stats ();
283 ns->pl = 0; 165 ns->pl = 0;
284 ns = 0; 166 ns = 0;
285 } 167 }
286 168
287 observe = ob; 169 // this is important for the player scheduler to get the correct refcount
170 // when ns = 0
171 observe = viewpoint = ob;
288 172
289 deactivate (); 173 deactivate ();
290} 174}
175
176//-GPL
291 177
292// the need for this function can be explained 178// the need for this function can be explained
293// by load_object not returning the object 179// by load_object not returning the object
294void 180void
295player::set_object (object *op) 181player::set_object (object *op)
296{ 182{
297 ob = observe = op; 183 ob = observe = viewpoint = op;
298 ob->contr = this; /* this aren't yet in archetype */ 184 ob->contr = this; /* this aren't yet in archetype */
299 185
300 ob->speed = 1.0f; 186 ob->speed = 1.0f; // object still inactive, keep it that way
301 ob->speed_left = 0.5f; 187 ob->speed_left = 0.5f;
302 188
303 ob->direction = 5; /* So player faces south */ 189 ob->direction = 5; /* So player faces south */
304
305 ob->flag [FLAG_READY_WEAPON] = false;
306 ob->flag [FLAG_READY_SKILL] = false;
307 ob->flag [FLAG_READY_BOW] = false;
308
309 for (object *op = ob->inv; op; op = op->below)
310 if (op->flag [FLAG_APPLIED])
311 switch (op->type)
312 {
313 case SKILL:
314 ob->flag [FLAG_APPLIED] = false;
315 break;
316
317 case WAND:
318 case ROD:
319 case HORN:
320 case BOW:
321 ranged_ob = op;
322 break;
323
324 case WEAPON:
325 combat_ob = op;
326 break;
327 }
328
329 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
330 ob->deactivate (); // change_weapon activates, fix this better
331} 190}
332 191
333void 192void
334player::set_observe (object *op) 193player::set_observe (object *op)
335{ 194{
336 observe = op ? op : ob; 195 observe = viewpoint = op ? op : ob;
337 do_los = 1; 196 do_los = 1;
338} 197}
198
199void
200player::set_viewpoint (object *op)
201{
202 viewpoint = op ? op : (object *)observe;
203 do_los = 1;
204}
205
206//+GPL
339 207
340player::player () 208player::player ()
341{ 209{
342 /* There are some elements we want initialised to non zero value - 210 /* There are some elements we want initialised to non zero value -
343 * we deal with that below this point. 211 * we deal with that below this point.
365 disconnect (); 233 disconnect ();
366 234
367 attachable::do_destroy (); 235 attachable::do_destroy ();
368 236
369 if (ob) 237 if (ob)
370 {
371 ob->destroy_inv (false);
372 ob->destroy (); 238 ob->destroy ();
373 }
374 239
375 ob = observe = 0; 240 ob = observe = viewpoint = 0;
376} 241}
377 242
378player::~player () 243player::~player ()
379{ 244{
380 /* Clear item stack */ 245 /* Clear item stack */
381 free (stack_items); 246 free (stack_items);
247}
248
249/*
250 * get_player_archetype() return next player archetype from archetype
251 * list. Not very efficient routine, but used only creating new players.
252 * Note: there MUST be at least one player archetype!
253 */
254static archetype *
255get_player_archetype (archetype *at)
256{
257 // archetypes could have been reloaded
258 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
259
260 if (!nat)
261 return at;
262
263 archvec::iterator i = archetypes.find (nat);
264
265 for (;;)
266 {
267 if (++i == archetypes.end ())
268 i = archetypes.begin ();
269 else if (*i == at)
270 cleanup ("not a single player archetype found");
271
272 if ((*i)->type == PLAYER)
273 return *i;
274 }
382} 275}
383 276
384/* Tries to add player on the connection passed in ns. 277/* Tries to add player on the connection passed in ns.
385 * All we can really get in this is some settings like host and display 278 * All we can really get in this is some settings like host and display
386 * mode. 279 * mode.
388player * 281player *
389player::create () 282player::create ()
390{ 283{
391 player *pl = new player; 284 player *pl = new player;
392 285
393 pl->set_object (arch_to_object (get_player_archetype (0))); 286 pl->set_object (get_player_archetype (0)->instance ());
394 287
395 pl->ob->roll_stats (); 288 pl->ob->roll_stats ();
396 pl->ob->stats.wc = 2; 289 pl->ob->stats.wc = 2;
397 pl->ob->run_away = 25; /* Then we panick... */ 290 pl->ob->run_away = 25; /* Then we panick... */
398 291
399 set_first_map (pl->ob); 292 set_first_map (pl->ob);
400 293
401 return pl; 294 return pl;
402}
403
404/*
405 * get_player_archetype() return next player archetype from archetype
406 * list. Not very efficient routine, but used only creating new players.
407 * Note: there MUST be at least one player archetype!
408 */
409archetype *
410get_player_archetype (archetype *at)
411{
412 // archetypes could have been reloaded
413 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
414
415 if (!nat)
416 return at;
417
418 archvec::iterator i = archetypes.find (nat);
419
420 for (;;)
421 {
422 if (++i == archetypes.end ())
423 i = archetypes.begin ();
424 else if (*i == at)
425 cleanup ("not a single player archetype found");
426
427 if ((*i)->type == PLAYER)
428 return *i;
429 }
430} 295}
431 296
432object * 297object *
433get_nearest_player (object *mon) 298get_nearest_player (object *mon)
434{ 299{
508 */ 373 */
509int 374int
510path_to_player (object *mon, object *pl, unsigned mindiff) 375path_to_player (object *mon, object *pl, unsigned mindiff)
511{ 376{
512 rv_vector rv; 377 rv_vector rv;
513 sint16 x, y;
514 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 378 int dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
515 maptile *m, *lastmap;
516 379
517 get_rangevector (mon, pl, &rv, 0); 380 get_rangevector (mon, pl, &rv, 0);
518 381
519 if (rv.distance < mindiff) 382 if (rv.distance < mindiff)
520 return 0; 383 return 0;
521 384
522 x = mon->x; 385 mapxy pos (mon);
523 y = mon->y;
524 m = mon->map;
525 dir = rv.direction; 386 dir = rv.direction;
526 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ 387 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
527 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 388 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
528 389
529 /* If we can't solve it within the search distance, return now. */ 390 /* If we can't solve it within the search distance, return now. */
530 if (diff > max) 391 if (diff > max)
531 return 0; 392 return 0;
532 393
533 while (diff > 1 && max > 0) 394 while (diff > 1 && max > 0)
534 { 395 {
535 lastx = x; 396 mapxy lastpos = pos;
536 lasty = y;
537 lastmap = m;
538 x = lastx + freearr_x[dir];
539 y = lasty + freearr_y[dir];
540 397
541 mflags = get_map_flags (m, &m, x, y, &x, &y); 398 pos.move (dir);
542 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK (m, x, y);
543 399
544 /* Space is blocked - try changing direction a little */ 400 /* Space is blocked - try changing direction a little */
545 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK (mon, blocked) || (mflags & P_BLOCKSVIEW)) 401 if (!pos.normalise ()
546 && (m == mon->map && blocked_link (mon, m, x, y)))) 402 || (((pos->flags () & P_BLOCKSVIEW) || OB_TYPE_MOVE_BLOCK (mon, pos->move_block))
403 && blocked_link (mon, pos.m, pos.x, pos.y)))
547 { 404 {
548 /* recalculate direction from last good location. Possible 405 /* recalculate direction from last good location. Possible
549 * we were not traversing ideal location before. 406 * we were not traversing ideal location before.
550 */ 407 */
551 get_rangevector_from_mapcoord (lastmap, lastx, lasty, pl, &rv, 0); 408 get_rangevector_from_mapcoord (lastpos.m, lastpos.x, lastpos.y, pl, &rv, 0);
552 if (rv.direction != dir) 409 if (rv.direction != dir)
553 { 410 {
554 /* OK - says direction should be different - lets reset the 411 /* OK - says direction should be different - lets reset the
555 * the values so it will try again. 412 * the values so it will try again.
556 */ 413 */
557 x = lastx;
558 y = lasty;
559 m = lastmap; 414 pos = lastpos;
560 dir = firstdir = rv.direction; 415 dir = firstdir = rv.direction;
561 } 416 }
562 else 417 else
563 { 418 {
564 /* direct path is blocked - try taking a side step to 419 /* direct path is blocked - try taking a side step to
571 */ 426 */
572 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) 427 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++)
573 { 428 {
574 if (i == 0) 429 if (i == 0)
575 continue; /* already did this, so skip it */ 430 continue; /* already did this, so skip it */
431
576 /* Use lastdir here - otherwise, 432 /* Use lastdir here - otherwise,
577 * since the direction that the creature should move in 433 * since the direction that the creature should move in
578 * may change, you could get infinite loops. 434 * may change, you could get infinite loops.
579 * ie, player is northwest, but monster can only 435 * ie, player is northwest, but monster can only
580 * move west, so it does that. It goes some distance, 436 * move west, so it does that. It goes some distance,
582 * can't do that, but now finds it can move east, and 438 * can't do that, but now finds it can move east, and
583 * gets back to its original point. lastdir contains 439 * gets back to its original point. lastdir contains
584 * the last direction the creature has successfully 440 * the last direction the creature has successfully
585 * moved. 441 * moved.
586 */ 442 */
587
588 x = lastx + freearr_x[absdir (lastdir + i)];
589 y = lasty + freearr_y[absdir (lastdir + i)];
590 m = lastmap; 443 pos = lastpos;
591 mflags = get_map_flags (m, &m, x, y, &x, &y); 444 pos.move (absdir (lastdir + i));
592 if (mflags & P_OUT_OF_MAP) 445
446 if (!pos.normalise ())
593 continue; 447 continue;
594 blocked = GET_MAP_MOVE_BLOCK (m, x, y); 448
595 if (OB_TYPE_MOVE_BLOCK (mon, blocked)) 449 mapspace &ms = *pos;
450
451 if (ms.flags () & P_BLOCKSVIEW)
596 continue; 452 continue;
597 if (mflags & P_BLOCKSVIEW) 453
454 if (OB_TYPE_MOVE_BLOCK (mon, ms.move_block))
598 continue; 455 continue;
599 456
600 if (m == mon->map && blocked_link (mon, m, x, y)) 457 if (blocked_link (mon, pos.m, pos.x, pos.y))
601 break; 458 break;
602 } 459 }
460
603 /* go through entire loop without finding a valid 461 /* go through entire loop without finding a valid
604 * sidestep to take - thus, no valid path. 462 * sidestep to take - thus, no valid path.
605 */ 463 */
606 if (i == (DETOUR_AMOUNT + 1)) 464 if (i == DETOUR_AMOUNT + 1)
607 return 0; 465 return 0;
466
608 diff--; 467 diff--;
609 lastdir = dir; 468 lastdir = dir;
610 max--; 469 max--;
611 if (!firstdir) 470 if (!firstdir)
612 firstdir = dir + i; 471 firstdir = dir + i;
616 { 475 {
617 /* we moved towards creature, so diff is less */ 476 /* we moved towards creature, so diff is less */
618 diff--; 477 diff--;
619 max--; 478 max--;
620 lastdir = dir; 479 lastdir = dir;
480
621 if (!firstdir) 481 if (!firstdir)
622 firstdir = dir; 482 firstdir = dir;
623 } 483 }
624 484
625 if (diff <= 1) 485 if (diff <= 1)
626 { 486 {
627 /* Recalculate diff (distance) because we may not have actually 487 /* Recalculate diff (distance) because we may not have actually
628 * headed toward player for entire distance. 488 * headed toward player for entire distance.
629 */ 489 */
630 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); 490 get_rangevector_from_mapcoord (pos.m, pos.x, pos.y, pl, &rv, 0);
631 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 491 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
632 } 492 }
633 493
634 if (diff > max) 494 if (diff > max)
635 return 0; 495 return 0;
653 next = op->below; 513 next = op->below;
654 514
655 /* Forces get applied per default, unless they have the 515 /* Forces get applied per default, unless they have the
656 * flag "neutral" set. Sorry but I can't think of a better way 516 * flag "neutral" set. Sorry but I can't think of a better way
657 */ 517 */
658 if (op->type == FORCE && !QUERY_FLAG (op, FLAG_NEUTRAL)) 518 if (op->type == FORCE && !op->flag [FLAG_NEUTRAL])
659 SET_FLAG (op, FLAG_APPLIED); 519 op->set_flag (FLAG_APPLIED);
660 520
661 /* we never give weapons/armour if these cannot be used 521 /* we never give weapons/armour if these cannot be used
662 * by this player due to race restrictions 522 * by this player due to race restrictions
663 */ 523 */
664 if (pl->type == PLAYER) 524 if (pl->type == PLAYER)
665 { 525 {
666 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) 526 if ((!pl->flag [FLAG_USE_ARMOUR]
667 && 527 &&
668 (op->type == ARMOUR || op->type == BOOTS 528 (op->type == ARMOUR || op->type == BOOTS
669 || op->type == CLOAK || op->type == HELMET 529 || op->type == CLOAK || op->type == HELMET
670 || op->type == SHIELD || op->type == GLOVES 530 || op->type == SHIELD || op->type == GLOVES
671 || op->type == BRACERS || op->type == GIRDLE)) 531 || op->type == BRACERS || op->type == GIRDLE))
672 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 532 || (!pl->flag [FLAG_USE_WEAPON] && op->type == WEAPON))
673 { 533 {
674 op->destroy (); 534 op->destroy ();
675 continue; 535 continue;
676 } 536 }
677 } 537 }
694 if (op->nrof > 1) 554 if (op->nrof > 1)
695 op->nrof = 1; 555 op->nrof = 1;
696 } 556 }
697 557
698 if (op->type == SPELLBOOK && op->inv) 558 if (op->type == SPELLBOOK && op->inv)
699 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 559 op->inv->clr_flag (FLAG_STARTEQUIP);
700 560
701 /* Give starting characters identified, uncursed, and undamned 561 /* Give starting characters identified, uncursed, and undamned
702 * items. Just don't identify gold or silver, or it won't be 562 * items. Just don't identify gold or silver, or it won't be
703 * merged properly. 563 * merged properly.
704 */ 564 */
705 if (need_identify (op)) 565 if (op->need_identify ())
706 { 566 {
707 SET_FLAG (op, FLAG_IDENTIFIED); 567 op->set_flag (FLAG_IDENTIFIED);
708 CLEAR_FLAG (op, FLAG_CURSED); 568 op->clr_flag (FLAG_CURSED);
709 CLEAR_FLAG (op, FLAG_DAMNED); 569 op->clr_flag (FLAG_DAMNED);
710 } 570 }
711 571
712 if (op->type == SPELL) 572 if (op->type == SPELL)
713 { 573 {
714 op->destroy (); 574 op->destroy ();
715 continue; 575 continue;
716 } 576 }
717 else if (op->type == SKILL) 577 else if (op->type == SKILL)
718 { 578 {
719 SET_FLAG (op, FLAG_CAN_USE_SKILL); 579 op->set_flag (FLAG_CAN_USE_SKILL);
720 op->stats.exp = 0; 580 op->stats.exp = 0;
721 op->level = 1; 581 op->level = 1;
722 } 582 }
723 else /* lock all 'normal items by default */ 583 else /* lock all 'normal items by default */
724 SET_FLAG (op, FLAG_INV_LOCKED); 584 op->set_flag (FLAG_INV_LOCKED);
725 } /* for loop of objects in player inv */ 585 } /* for loop of objects in player inv */
726 586
727 /* Need to set up the skill pointers */ 587 /* Need to set up the skill pointers */
728 pl->contr->link_skills (); 588 pl->contr->link_skills ();
729} 589}
743 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 603 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
744} 604}
745 605
746/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 606/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
747static int 607static int
748roll_stat (void) 608roll_stat ()
749{ 609{
750 int a[4], i, j, k; 610 int a[4], i, j, k;
751 611
752 for (i = 0; i < 4; i++) 612 for (i = 0; i < 4; i++)
753 a[i] = (int) rndm (6) + 1; 613 a[i] = rndm (1, 6);
754 614
755 for (i = 0, j = 0, k = 7; i < 4; i++) 615 for (i = 0, j = 0, k = 7; i < 4; i++)
756 if (a[i] < k) 616 if (a[i] < k)
757 k = a[i], j = i; 617 k = a[i], j = i;
758 618
850player::chargen_race_done () 710player::chargen_race_done ()
851{ 711{
852 /* this must before then initial items are given */ 712 /* this must before then initial items are given */
853 esrv_new_player (ob->contr); 713 esrv_new_player (ob->contr);
854 714
855 treasurelist *tl = treasurelist::find ("starting_wealth"); 715 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
856 if (tl) 716 if (tl)
857 create_treasure (tl, ob, 0, 0, 0); 717 create_treasure (tl, ob, 0, 0, 0);
858 718
859 INVOKE_PLAYER (BIRTH, ob->contr); 719 INVOKE_PLAYER (BIRTH, ob->contr);
860 INVOKE_PLAYER (LOGIN, ob->contr);
861 720
862 ob->contr->ns->state = ST_PLAYING; 721 ob->contr->ns->state = ST_PLAYING;
863 722
864 if (ob->msg) 723 if (ob->msg)
865 ob->msg = 0; 724 ob->msg = 0;
866 725
867 start_info (ob); 726 start_info (ob);
868 CLEAR_FLAG (ob, FLAG_WIZ); 727 ob->clr_flag (FLAG_WIZ);
869 give_initial_items (ob, ob->randomitems); 728 give_initial_items (ob, ob->randomitems);
870 esrv_send_inventory (ob, ob); 729 esrv_send_inventory (ob, ob);
871 ob->update_stats (); 730 ob->update_stats ();
872 731
873 /* This moves the player to a different start map, if there 732 /* This moves the player to a different start map, if there
913 ob->stats.hp = ob->stats.maxhp; 772 ob->stats.hp = ob->stats.maxhp;
914 ob->stats.sp = ob->stats.maxsp; 773 ob->stats.sp = ob->stats.maxsp;
915 ob->stats.grace = 0; 774 ob->stats.grace = 0;
916} 775}
917 776
918void 777static void
919flee_player (object *op) 778flee_player (object *op)
920{ 779{
921 int dir, diff; 780 int dir, diff;
922 rv_vector rv; 781 rv_vector rv;
923 782
924 if (op->stats.hp < 0) 783 if (op->stats.hp < 0)
925 { 784 {
926 LOG (llevDebug, "Fleeing player is dead.\n"); 785 LOG (llevDebug, "Fleeing player is dead.\n");
927 CLEAR_FLAG (op, FLAG_SCARED); 786 op->clr_flag (FLAG_SCARED);
928 return; 787 return;
929 } 788 }
930 789
931 if (!op->enemy) 790 if (!op->enemy)
932 { 791 {
933 LOG (llevDebug, "Fleeing player had no enemy.\n"); 792 LOG (llevDebug, "Fleeing player had no enemy.\n");
934 CLEAR_FLAG (op, FLAG_SCARED); 793 op->clr_flag (FLAG_SCARED);
935 return; 794 return;
936 } 795 }
937 796
938 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 797 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
939 { 798 {
940 op->enemy = NULL; 799 op->enemy = NULL;
941 CLEAR_FLAG (op, FLAG_SCARED); 800 op->clr_flag (FLAG_SCARED);
942 return; 801 return;
943 } 802 }
944 803
945 get_rangevector (op, op->enemy, &rv, 0); 804 get_rangevector (op, op->enemy, &rv, 0);
946 805
947 dir = absdir (4 + rv.direction); 806 dir = absdir (4 + rv.direction);
948 for (diff = 0; diff < 3; diff++) 807 for (diff = 0; diff < 3; diff++)
949 { 808 {
950 int m = 1 - rndm (2) * 2; 809 int m = 1 - rndm (2) * 2;
951 810
952 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 811 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
953 return; 812 return;
954 } 813 }
955 814
956 /* Cornered, get rid of scared */ 815 /* Cornered, get rid of scared */
957 CLEAR_FLAG (op, FLAG_SCARED); 816 op->clr_flag (FLAG_SCARED);
958 op->enemy = NULL; 817 op->enemy = NULL;
959} 818}
960 819
961/* check_pick sees if there is stuff to be picked up/picks up stuff. 820/* check_pick sees if there is stuff to be picked up/picks up stuff.
962 * It returns 1 if the player should keep on moving, 0 if he should 821 * It returns 1 if the player should keep on moving, 0 if he should
967{ 826{
968 object *tmp, *next; 827 object *tmp, *next;
969 int stop = 0; 828 int stop = 0;
970 int wvratio; 829 int wvratio;
971 830
972 /* if you're flying, you cna't pick up anything */ 831 /* if you're flying, you can't pick up anything */
973 if (op->move_type & MOVE_FLYING) 832 if (op->move_type & MOVE_FLYING)
974 return 1; 833 return 1;
975 834
976 next = op->below; 835 next = op->below;
977 836
978 int cnt = MAX_ITEM_PER_DROP; 837 int cnt = MAX_ITEM_PER_ACTION;
979#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) 838#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
980 839
981 /* loop while there are items on the floor that are not marked as 840 /* loop while there are items on the floor that are not marked as
982 * destroyed */ 841 * destroyed */
983 while (next && !next->destroyed ()) 842 while (next && !next->destroyed ())
1009 if (op->contr->mode & PU_DEBUG) 868 if (op->contr->mode & PU_DEBUG)
1010 { 869 {
1011 /* some debugging code to figure out item information */ 870 /* some debugging code to figure out item information */
1012 const char *str = tmp->name 871 const char *str = tmp->name
1013 ? format ("item name: %s item type: %d weight/value: %d", 872 ? format ("item name: %s item type: %d weight/value: %d",
1014 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))) 873 &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))))
1015 : format ("item name: %s item type: %d weight/value: %d", 874 : format ("item name: %s item type: %d weight/value: %d",
1016 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 875 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
1017 876
1018 new_draw_info (NDI_UNIQUE, 0, op, str); 877 new_draw_info (NDI_UNIQUE, 0, op, str);
1019 } 878 }
1020 879
1021 if (op->contr->mode & PU_INHIBIT) 880 if (op->contr->mode & PU_INHIBIT)
1054 * fighting */ 913 * fighting */
1055 if (op->contr->mode & PU_INHIBIT) 914 if (op->contr->mode & PU_INHIBIT)
1056 return 1; 915 return 1;
1057 916
1058 /* prevent us from turning into auto-thieves :) */ 917 /* prevent us from turning into auto-thieves :) */
1059 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 918 if (tmp->flag [FLAG_UNPAID])
1060 continue; 919 continue;
1061 920
1062 /* ignore known cursed objects */ 921 /* ignore known cursed objects */
1063 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 922 if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED)
1064 continue; 923 continue;
1065 924
1066 /* all food and drink if desired */ 925 /* all food and drink if desired */
1067 /* question: don't pick up known-poisonous stuff? */ 926 /* question: don't pick up known-poisonous stuff? */
1068 if (op->contr->mode & PU_FOOD) 927 if (op->contr->mode & PU_FOOD)
1071 CHK_PICK_PICKUP; 930 CHK_PICK_PICKUP;
1072 continue; 931 continue;
1073 } 932 }
1074 933
1075 if (op->contr->mode & PU_DRINK) 934 if (op->contr->mode & PU_DRINK)
1076 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 935 if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED]))
1077 { 936 {
1078 CHK_PICK_PICKUP; 937 CHK_PICK_PICKUP;
1079 continue; 938 continue;
1080 } 939 }
1081 940
1108 continue; 967 continue;
1109 } 968 }
1110 969
1111 /* wands/staves/rods/horns */ 970 /* wands/staves/rods/horns */
1112 if (op->contr->mode & PU_MAGIC_DEVICE) 971 if (op->contr->mode & PU_MAGIC_DEVICE)
1113 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 972 if (tmp->type == WAND
973 || tmp->type == ROD
974 || tmp->type == HORN
975 || tmp->type == POWER_CRYSTAL)
1114 { 976 {
1115 CHK_PICK_PICKUP; 977 CHK_PICK_PICKUP;
1116 continue; 978 continue;
1117 } 979 }
1118 980
1119 /* pick up all magical items */ 981 /* pick up all magical items */
1120 if (op->contr->mode & PU_MAGICAL) 982 if (op->contr->mode & PU_MAGICAL)
1121 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 983 if (tmp->flag [FLAG_KNOWN_MAGICAL]
984 && !tmp->flag [FLAG_KNOWN_CURSED])
1122 { 985 {
1123 CHK_PICK_PICKUP; 986 CHK_PICK_PICKUP;
1124 continue; 987 continue;
1125 } 988 }
1126 989
1133 } 996 }
1134 } 997 }
1135 998
1136 /* rings & amulets - talismans seems to be typed AMULET */ 999 /* rings & amulets - talismans seems to be typed AMULET */
1137 if (op->contr->mode & PU_JEWELS) 1000 if (op->contr->mode & PU_JEWELS)
1138 if (tmp->type == RING || tmp->type == AMULET) 1001 if (tmp->type == RING
1002 || tmp->type == AMULET
1003 || tmp->type == GIRDLE
1004 || tmp->type == SKILL_TOOL)
1139 { 1005 {
1140 CHK_PICK_PICKUP; 1006 CHK_PICK_PICKUP;
1141 continue; 1007 continue;
1142 } 1008 }
1143 1009
1192 CHK_PICK_PICKUP; 1058 CHK_PICK_PICKUP;
1193 continue; 1059 continue;
1194 } 1060 }
1195 1061
1196 if (op->contr->mode & PU_GLOVES) 1062 if (op->contr->mode & PU_GLOVES)
1197 if (tmp->type == GLOVES) 1063 if (tmp->type == GLOVES || tmp->type == BRACERS)
1198 { 1064 {
1199 CHK_PICK_PICKUP; 1065 CHK_PICK_PICKUP;
1200 continue; 1066 continue;
1201 } 1067 }
1202 1068
1207 continue; 1073 continue;
1208 } 1074 }
1209 1075
1210 /* hoping to catch throwing daggers here */ 1076 /* hoping to catch throwing daggers here */
1211 if (op->contr->mode & PU_MISSILEWEAPON) 1077 if (op->contr->mode & PU_MISSILEWEAPON)
1212 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1078 if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN])
1213 { 1079 {
1214 CHK_PICK_PICKUP; 1080 CHK_PICK_PICKUP;
1215 continue; 1081 continue;
1216 } 1082 }
1217 1083
1252 fprintf (stderr, "%s", tmp->name); 1118 fprintf (stderr, "%s", tmp->name);
1253 } 1119 }
1254 else 1120 else
1255 fprintf (stderr, "%s", tmp->arch->archname); 1121 fprintf (stderr, "%s", tmp->arch->archname);
1256 fprintf (stderr, ",%d] = ", tmp->type); 1122 fprintf (stderr, ",%d] = ", tmp->type);
1257 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1123 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
1258#endif 1124#endif
1259 CHK_PICK_PICKUP; 1125 CHK_PICK_PICKUP;
1260 continue; 1126 continue;
1261 } 1127 }
1262 } /* the new pickup model */ 1128 } /* the new pickup model */
1263 } 1129 }
1264 1130
1265 return !stop; 1131 return !stop;
1266} 1132}
1267 1133
1134/* routine for both players and monsters. We call this when
1135 * there is a possibility for our action distrubing our hiding
1136 * place or invisiblity spell. Artefact invisiblity causes
1137 * "noise" instead. If we arent invisible to begin with, we
1138 * return 0.
1139 */
1140static int
1141action_makes_visible (object *op)
1142{
1143 if (op->invisible && op->flag [FLAG_ALIVE])
1144 {
1145 if (op->flag [FLAG_MAKE_INVIS])
1146 {
1147 // artefact invisibility is permanent, but we still make noise
1148 // this is important for game-balance.
1149 if (op->contr)
1150 op->make_noise ();
1151
1152 return 0;
1153 }
1154
1155 if (op->contr && op->contr->tmp_invis == 0)
1156 return 0;
1157
1158 /* If monsters, they should become visible */
1159 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
1160 {
1161 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
1162 return 1;
1163 }
1164 }
1165
1166 return 0;
1167}
1168
1268/* 1169/*
1269 * Find an arrow in the inventory and after that 1170 * Find an arrow in the inventory and after that
1270 * in the right type container (quiver). Pointer to the 1171 * in the right type container (quiver). Pointer to the
1271 * found object is returned. 1172 * found object is returned.
1272 */ 1173 */
1273object * 1174static object *
1274find_arrow (object *op, const char *type) 1175find_arrow (object *op, const char *type)
1275{ 1176{
1276 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1177 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1277 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1178 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1278 return splay (tmp); 1179 return splay (tmp);
1279 1180
1280 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1181 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1281 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) 1182 if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type))
1282 if (object *arrow = find_arrow (tmp, type)) 1183 if (object *arrow = find_arrow (tmp, type))
1283 { 1184 {
1284 splay (tmp); 1185 splay (tmp);
1285 return arrow; 1186 return arrow;
1286 } 1187 }
1292 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1193 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1293 * against the target. A full test is not performed, simply a basic test 1194 * against the target. A full test is not performed, simply a basic test
1294 * of resistances. The archer is making a quick guess at what he sees down 1195 * of resistances. The archer is making a quick guess at what he sees down
1295 * the hall. Failing that it does it's best to pick the highest plus arrow. 1196 * the hall. Failing that it does it's best to pick the highest plus arrow.
1296 */ 1197 */
1297object * 1198static object *
1298find_better_arrow (object *op, object *target, shstr_cmp type, int *better) 1199find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1299{ 1200{
1300 object *tmp = NULL, *arrow, *ntmp; 1201 object *tmp = NULL, *arrow, *ntmp;
1301 int attacknum, attacktype, betterby = 0, i; 1202 int attacknum, attacktype, betterby = 0, i;
1302 1203
1303 if (!type) 1204 if (!type)
1304 return NULL; 1205 return NULL;
1305 1206
1306 for (arrow = op->inv; arrow; arrow = arrow->below) 1207 for (arrow = op->inv; arrow; arrow = arrow->below)
1307 { 1208 {
1308 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1209 if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED])
1309 { 1210 {
1310 i = 0; 1211 i = 0;
1311 ntmp = find_better_arrow (arrow, target, type, &i); 1212 ntmp = find_better_arrow (arrow, target, type, &i);
1312 1213
1313 if (i > betterby) 1214 if (i > betterby)
1371 * find_better_arrow to find a decent arrow to use. 1272 * find_better_arrow to find a decent arrow to use.
1372 * op = the shooter 1273 * op = the shooter
1373 * type = bow->race 1274 * type = bow->race
1374 * dir = fire direction 1275 * dir = fire direction
1375 */ 1276 */
1376object * 1277static object *
1377pick_arrow_target (object *op, shstr_cmp type, int dir) 1278pick_arrow_target (object *op, shstr_cmp type, int dir)
1378{ 1279{
1379 object *tmp = NULL; 1280 object *tmp = NULL;
1380 maptile *m; 1281 maptile *m;
1381 int i, mflags, found, number; 1282 int i, mflags, found, number;
1414 break; 1315 break;
1415 } 1316 }
1416 1317
1417 if (mflags & P_IS_ALIVE) 1318 if (mflags & P_IS_ALIVE)
1418 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1319 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1419 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1320 if (tmp->flag [FLAG_ALIVE])
1420 break; 1321 break;
1421 } 1322 }
1422 1323
1423 if (!tmp) 1324 if (!tmp)
1424 return find_arrow (op, type); 1325 return find_arrow (op, type);
1485 { 1386 {
1486 if (op->type == PLAYER) 1387 if (op->type == PLAYER)
1487 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1388 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1488 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ 1389 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1489 else 1390 else
1490 CLEAR_FLAG (op, FLAG_READY_BOW); 1391 op->clr_flag (FLAG_READY_BOW);
1491 1392
1492 return 0; 1393 return 0;
1493 } 1394 }
1494 } 1395 }
1495 1396
1544#endif 1445#endif
1545 1446
1546 SET_ANIMATION (arrow, arrow->direction); 1447 SET_ANIMATION (arrow, arrow->direction);
1547 1448
1548 /* update the speed */ 1449 /* update the speed */
1549 arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1550 + bow->stats.dam / 7.f;
1551 1450
1552 arrow->set_speed (max (arrow->speed, 2.f));
1553 arrow->speed_left = 0; 1451 arrow->speed_left = 0;
1452 arrow->set_speed (max (2.f,
1453 ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f
1454 + bow->stats.dam / 7.f
1455 ));
1554 1456
1555 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; 1457 int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc;
1556 1458
1557 if (op->type == PLAYER) 1459 if (op->type == PLAYER)
1558 { 1460 {
1596 * but monsters can't. Putting that code here 1498 * but monsters can't. Putting that code here
1597 * makes the fire_bow code much cleaner. 1499 * makes the fire_bow code much cleaner.
1598 * this function should only be called if 'op' is a player, 1500 * this function should only be called if 'op' is a player,
1599 * hence the function name. 1501 * hence the function name.
1600 */ 1502 */
1601int 1503static int
1602player_fire_bow (object *op, int dir) 1504player_fire_bow (object *op, int dir)
1603{ 1505{
1604 int ret; 1506 int ret;
1605 1507
1606 if (op->contr->bowtype == bow_bestarrow) 1508 if (op->contr->bowtype == bow_bestarrow)
1634} 1536}
1635 1537
1636/* Fires a misc (wand/rod/horn) object in 'dir'. 1538/* Fires a misc (wand/rod/horn) object in 'dir'.
1637 * Broken apart from 'fire' to keep it more readable. 1539 * Broken apart from 'fire' to keep it more readable.
1638 */ 1540 */
1639void 1541static void
1640fire_misc_object (object *op, int dir) 1542fire_misc_object (object *op, int dir)
1641{ 1543{
1642 object *item = op->contr->ranged_ob; 1544 object *item = op->contr->ranged_ob;
1643 1545
1644 if (!item) 1546 if (!item)
1651 { 1553 {
1652 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1554 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1653 return; 1555 return;
1654 } 1556 }
1655 1557
1656 if (!op->change_weapon (item)) 1558 if (!op->apply (item))
1657 return; 1559 return;
1658 1560
1659 if (item->type == WAND) 1561 if (item->type == WAND)
1660 { 1562 {
1661 if (item->stats.food <= 0) 1563 if (item->stats.food <= 0)
1666 return; 1568 return;
1667 } 1569 }
1668 } 1570 }
1669 else if (item->type == ROD || item->type == HORN) 1571 else if (item->type == ROD || item->type == HORN)
1670 { 1572 {
1671 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); 1573 sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace);
1672 1574
1673 // using the maximum of the rods charge allows at least one spell cast 1575 // using the maximum of the rods charge allows at least one spell cast
1674 // for a rod or horn, this fixes some broken rods. 1576 // for a rod or horn, this fixes some broken rods.
1675 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) 1577 if (item->stats.hp < min (spell_sp, item->stats.maxhp))
1676 { 1578 {
1677 op->contr->play_sound (sound_find ("wand_poof")); 1579 op->contr->play_sound (sound_find ("wand_poof"));
1678 1580
1679 if (item->type == ROD) 1581 if (item->type == ROD)
1680 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); 1582 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1695 { 1597 {
1696 object *tmp; 1598 object *tmp;
1697 1599
1698 if (item->arch) 1600 if (item->arch)
1699 { 1601 {
1700 CLEAR_FLAG (item, FLAG_ANIMATE); 1602 item->clr_flag (FLAG_ANIMATE);
1701 item->face = item->arch->face; 1603 item->face = item->arch->face;
1702 item->set_speed (0); 1604 item->set_speed (0);
1703 } 1605 }
1704 1606
1705 if (object *pl = item->visible_to ()) 1607 if (object *pl = item->visible_to ())
1712} 1614}
1713 1615
1714/* Received a fire command for the player - go and do it. 1616/* Received a fire command for the player - go and do it.
1715 */ 1617 */
1716bool 1618bool
1717fire (object *op, int dir) 1619fire (object *who, int dir)
1718{ 1620{
1719 int spellcost = 0; 1621 int spellcost = 0;
1720 1622
1721 player *pl = op->contr; 1623 player *pl = who->contr;
1722 1624
1723 if (pl->golem) 1625 if (pl->golem)
1724 { 1626 {
1725 control_golem (op->contr->golem, dir); 1627 control_golem (who->contr->golem, dir);
1726 return false; 1628 return false;
1727 } 1629 }
1728 1630
1729 object *ob = pl->ranged_ob; 1631 object *ob = pl->ranged_ob;
1730 1632
1731 if (!ob) 1633 if (!ob)
1732 return false; 1634 return false;
1733 1635
1734 if (op->speed_left > 0.f) 1636 if (who->speed_left > 0.f)
1735 --op->speed_left; 1637 --who->speed_left;
1736 else 1638 else
1737 return false; 1639 return false;
1738 1640
1739 if (!op->change_weapon (ob)) 1641 if (!who->apply (ob))
1740 return false; 1642 return false;
1741 1643
1742 /* check for loss of invisiblity/hide */ 1644 /* check for loss of invisiblity/hide */
1743 if (action_makes_visible (op)) 1645 if (action_makes_visible (who))
1744 make_visible (op); 1646 make_visible (who);
1745 1647
1746 switch (ob->type) 1648 switch (ob->type)
1747 { 1649 {
1748 case BOW: 1650 case BOW:
1749 player_fire_bow (op, dir); 1651 player_fire_bow (who, dir);
1750 break; 1652 break;
1751 1653
1752 case SPELL: 1654 case SPELL:
1753 spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); 1655 spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0);
1754 break; 1656 break;
1755 1657
1756 case BUILDER: 1658 case BUILDER:
1757 apply_map_builder (op, dir); 1659 apply_map_builder (who, dir);
1758 break; 1660 break;
1759 1661
1760 case SKILL: 1662 case SKILL:
1761 do_skill (op, op, ob, dir, 0); 1663 do_skill (who, who, ob, dir, 0);
1762 break; 1664 break;
1763 1665
1666 case RANGED:
1667 do_skill (who, ob, who->chosen_skill, dir, 0);
1668 break;
1669
1764 default: 1670 default:
1765 fire_misc_object (op, dir); 1671 fire_misc_object (who, dir);
1766 break; 1672 break;
1767 } 1673 }
1768 1674
1769 return true; 1675 return true;
1770} 1676}
1771 1677
1772/* find_key 1678static object *
1773 * We try to find a key for the door as passed. If we find a key
1774 * and successfully use it, we return the key, otherwise NULL
1775 * This function merges both normal and locked door, since the logic
1776 * for both is the same - just the specific key is different.
1777 * pl is the player,
1778 * inv is the objects inventory to searched
1779 * door is the door we are trying to match against.
1780 * This function can be called recursively to search containers.
1781 */
1782object *
1783find_key (object *pl, object *container, object *door) 1679find_key_ (object *pl, object *container, object *door)
1784{ 1680{
1785 object *tmp, *key; 1681 object *tmp, *key;
1786 1682
1787 /* Should not happen, but sanity checking is never bad */ 1683 /* Should not happen, but sanity checking is never bad */
1788 if (!container->inv) 1684 if (!container->inv)
1809 if (!tmp) 1705 if (!tmp)
1810 { 1706 {
1811 for (tmp = container->inv; tmp; tmp = tmp->below) 1707 for (tmp = container->inv; tmp; tmp = tmp->below)
1812 /* No reason to search empty containers */ 1708 /* No reason to search empty containers */
1813 if (tmp->type == CONTAINER && tmp->inv) 1709 if (tmp->type == CONTAINER && tmp->inv)
1814 if ((key = find_key (pl, tmp, door))) 1710 if ((key = find_key_ (pl, tmp, door)))
1815 return key; 1711 return key;
1816 1712
1817 if (!tmp) 1713 if (!tmp)
1818 return 0; 1714 return 0;
1819 } 1715 }
1838 * inv must have been an container and must have been active. 1734 * inv must have been an container and must have been active.
1839 * 1735 *
1840 * Change the color so that the message doesn't disappear with 1736 * Change the color so that the message doesn't disappear with
1841 * all the others. 1737 * all the others.
1842 */ 1738 */
1843 if (pl->contr->usekeys == key_inventory || 1739 if (pl->contr->usekeys == key_inventory
1844 !QUERY_FLAG (container, FLAG_APPLIED) || 1740 || !container->flag [FLAG_APPLIED]
1845 (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1741 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1846 { 1742 {
1847 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1743 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl,
1848 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); 1744 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1849 return NULL; 1745 return NULL;
1850 } 1746 }
1851 } 1747 }
1852 1748
1853 return tmp; 1749 return tmp;
1750}
1751
1752/* find_key
1753 * We try to find a key for the door as passed. If we find a key
1754 * and successfully use it, we return the key, otherwise NULL
1755 * This function merges both normal and locked door, since the logic
1756 * for both is the same - just the specific key is different.
1757 * pl is the player,
1758 * inv is the objects inventory to searched
1759 * door is the door we are trying to match against.
1760 * This function can be called recursively to search containers.
1761 */
1762object *
1763find_key (object *pl, object *container, object *door)
1764{
1765 if (door->slaying && is_match_expr (door->slaying))
1766 {
1767 // for match expressions, we try to find the key by applying the match
1768 // to the op itself, which is supposed to find the "key", instead
1769 // of searching through containers ourselves.
1770
1771 return match_one (door->slaying, container, door, pl, pl);
1772 }
1773 else
1774 return find_key_ (pl, container, door);
1854} 1775}
1855 1776
1856/* moved door processing out of move_player_attack. 1777/* moved door processing out of move_player_attack.
1857 * returns 1 if player has opened the door with a key 1778 * returns 1 if player has opened the door with a key
1858 * such that the caller should not do anything more, 1779 * such that the caller should not do anything more,
1908 * going to try and move (not fire weapons). 1829 * going to try and move (not fire weapons).
1909 */ 1830 */
1910bool 1831bool
1911move_player_attack (object *op, int dir) 1832move_player_attack (object *op, int dir)
1912{ 1833{
1913 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) 1834 if (!op->contr->braced && op->speed_left > 0.f && op->move (dir))
1914 { 1835 {
1915 --op->speed_left; 1836 --op->speed_left;
1916 return true; 1837 return true;
1917 } 1838 }
1918 1839
1919 int on_battleground;
1920
1921 sint16 nx = freearr_x[dir] + op->x; 1840 sint16 nx = freearr_x[dir] + op->x;
1922 sint16 ny = freearr_y[dir] + op->y; 1841 sint16 ny = freearr_y[dir] + op->y;
1923
1924 on_battleground = op_on_battleground (op, 0, 0);
1925 1842
1926 if (out_of_map (op->map, nx, ny)) 1843 if (out_of_map (op->map, nx, ny))
1927 return false; 1844 return false;
1928 1845
1929 /* If braced, or can't move to the square, and it is not out of the 1846 /* If braced, or can't move to the square, and it is not out of the
1950 || mon->flag [FLAG_CAN_ROLL]) 1867 || mon->flag [FLAG_CAN_ROLL])
1951 && mon != op) 1868 && mon != op)
1952 break; 1869 break;
1953 } 1870 }
1954 1871
1955 if (!mon) /* This happens anytime the player tries to move */ 1872 /* no monster == player tries to move into a wall or so */
1956 return false; /* into a wall */ 1873 if (!mon)
1874 {
1875 for (object *ob = m->at (nx, ny).top; ob; ob = ob->below)
1876 if (op->move_type & ob->move_block)
1877 {
1878 if (ob->move_block == MOVE_ALL)
1879 move_into_wall (op, ob);
1880 else
1881 {
1882 if (op->contr->ns->bumpmsg)
1883 {
1884 op->play_sound (sound_find ("blocked_move"));
1885
1886 op->statusmsg (ob->invisible
1887 ? "Something blocks you."
1888 : format ("Something blocks you from entering the %s.", query_name (ob))
1889 );
1890 }
1891 }
1892
1893 break;
1894 }
1895
1896 return false;
1897 }
1957 1898
1958 mon = mon->head_ (); 1899 mon = mon->head_ ();
1959 1900
1960 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) 1901 if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
1961 if (op->contr->weapon_sp_left > 0.f) 1902 if (op->contr->weapon_sp_left > 0.f)
1979 */ 1920 */
1980 if (op->type == PLAYER 1921 if (op->type == PLAYER
1981 && ((mon->owner && mon->owner->contr 1922 && ((mon->owner && mon->owner->contr
1982 && same_party (mon->owner->contr->party, op->contr->party)) 1923 && same_party (mon->owner->contr->party, op->contr->party))
1983 || mon->owner == op) 1924 || mon->owner == op)
1984 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 1925 && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]))
1985 { 1926 {
1986 /* If we're braced, we don't want to switch places with it */ 1927 /* If we're braced, we don't want to switch places with it */
1987 if (op->contr->braced) 1928 if (op->contr->braced)
1988 return false; 1929 return false;
1989 1930
2000 return true; 1941 return true;
2001 } 1942 }
2002 else 1943 else
2003 return false; 1944 return false;
2004 } 1945 }
1946
1947 bool on_battleground = op_on_battleground (op, 0, 0);
2005 1948
2006 /* in certain circumstances, you shouldn't attack friendly 1949 /* in certain circumstances, you shouldn't attack friendly
2007 * creatures. Note that if you are braced, you can't push 1950 * creatures. Note that if you are braced, you can't push
2008 * someone, but put it inside this loop so that you won't 1951 * someone, but put it inside this loop so that you won't
2009 * attack them either. 1952 * attack them either.
2010 */ 1953 */
2011 if ((mon->type == PLAYER || mon->enemy != op) 1954 if ((mon->type == PLAYER || mon->enemy != op)
2012 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 1955 && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])
2013 && ((op->contr->peaceful 1956 && ((op->contr->peaceful
2014 || (mon->type == PLAYER && mon->contr->peaceful)) 1957 || (mon->type == PLAYER && mon->contr->peaceful))
2015 && !on_battleground)) 1958 && !on_battleground))
2016 { 1959 {
2017 if (op->speed_left > 0.f) 1960 if (op->speed_left > 0.f)
2033 } 1976 }
2034 } 1977 }
2035 /* If the object is a boulder or other rollable object, then 1978 /* If the object is a boulder or other rollable object, then
2036 * roll it if not braced. You can't roll it if you are braced. 1979 * roll it if not braced. You can't roll it if you are braced.
2037 */ 1980 */
2038 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 1981 else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced))
2039 { 1982 {
2040 if (op->speed_left > 0.f) 1983 if (op->speed_left > 0.f)
2041 { 1984 {
2042 --op->speed_left; 1985 --op->speed_left;
2043 1986
2052 * Way it works is like this: First, it must have some hit points 1995 * Way it works is like this: First, it must have some hit points
2053 * and be living. Then, it must be one of the following: 1996 * and be living. Then, it must be one of the following:
2054 * 1) Not a player, 2) A player, but of a different party. Note 1997 * 1) Not a player, 2) A player, but of a different party. Note
2055 * that party_number -1 is no party, so attacks can still happen. 1998 * that party_number -1 is no party, so attacks can still happen.
2056 */ 1999 */
2057 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 2000 else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] &&
2058 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 2001 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2059 { 2002 {
2060 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) 2003 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2061 { 2004 {
2062 --op->contr->weapon_sp_left; 2005 --op->contr->weapon_sp_left;
2074} 2017}
2075 2018
2076bool 2019bool
2077move_player (object *op, int dir) 2020move_player (object *op, int dir)
2078{ 2021{
2079 int pick;
2080
2081 if (!op->map || op->map->in_memory != MAP_ACTIVE) 2022 if (!op->map || op->map->state != MAP_ACTIVE)
2082 return 0; 2023 return 0;
2083 2024
2084 /* Sanity check: make sure dir is valid */ 2025 /* Sanity check: make sure dir is valid */
2085 if ((dir < 0) || (dir >= 9)) 2026 if (dir < 0 || dir > 8)
2086 { 2027 {
2087 LOG (llevError, "move_player: invalid direction %d\n", dir); 2028 LOG (llevError, "move_player: invalid direction %d\n", dir);
2088 return 0; 2029 return 0;
2089 } 2030 }
2090 2031
2091 /* peterm: added following line */ 2032 /* peterm: added following line */
2092 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2033 if (op->flag [FLAG_CONFUSED] && dir)
2093 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2034 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2094 2035
2095 op->facing = dir; 2036 op->facing = dir;
2096 2037
2097 if (op->flag [FLAG_HIDDEN]) 2038 if (op->flag [FLAG_HIDDEN])
2098 do_hidden_move (op); 2039 do_hidden_move (op);
2099 2040
2100 bool retval; 2041 bool retval;
2042 int pick = 0;
2101 2043
2102 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2044 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2103 retval = RESULT_INT (0); 2045 retval = RESULT_INT (0);
2104 else if (op->contr->fire_on) 2046 else if (op->contr->fire_on)
2105 retval = fire (op, dir); 2047 retval = fire (op, dir);
2136 * players. 2078 * players.
2137 */ 2079 */
2138bool 2080bool
2139handle_newcs_player (object *op) 2081handle_newcs_player (object *op)
2140{ 2082{
2141 if (QUERY_FLAG (op, FLAG_SCARED)) 2083 if (op->flag [FLAG_SCARED])
2142 { 2084 {
2143 if (op->speed_left > 0.f) 2085 if (op->speed_left > 0.f)
2144 { 2086 {
2145 --op->speed_left; 2087 --op->speed_left;
2146 flee_player (op); 2088 flee_player (op);
2162 return move_player (op, op->direction); 2104 return move_player (op, op->direction);
2163 2105
2164 return false; 2106 return false;
2165} 2107}
2166 2108
2167int 2109static int
2168save_life (object *op) 2110save_life (object *op)
2169{ 2111{
2170 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2112 if (!op->flag [FLAG_LIFESAVE])
2171 return 0; 2113 return 0;
2172 2114
2173 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2115 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2174 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2116 if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE])
2175 { 2117 {
2176 op->play_sound (sound_find ("ob_evaporate")); 2118 op->play_sound (sound_find ("ob_evaporate"));
2177 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); 2119 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2178 2120
2179 tmp->destroy (); 2121 tmp->destroy ();
2180 CLEAR_FLAG (op, FLAG_LIFESAVE); 2122 op->clr_flag (FLAG_LIFESAVE);
2181 2123
2182 if (op->stats.hp < 0) 2124 if (op->stats.hp < 0)
2183 op->stats.hp = op->stats.maxhp; 2125 op->stats.hp = op->stats.maxhp;
2184 2126
2185 if (op->stats.food < 0) 2127 if (op->stats.food < 0)
2186 op->stats.food = 999; 2128 op->stats.food = MAX_FOOD;
2187 2129
2188 op->update_stats (); 2130 op->update_stats ();
2189 return 1; 2131 return 1;
2190 } 2132 }
2191 2133
2192 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2134 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2193 CLEAR_FLAG (op, FLAG_LIFESAVE); 2135 op->clr_flag (FLAG_LIFESAVE);
2194 enter_player_savebed (op); /* bring him home. */ 2136 enter_player_savebed (op); /* bring him home. */
2195 return 0; 2137 return 0;
2196} 2138}
2197 2139
2198/* This goes throws the inventory and removes unpaid objects, and puts them 2140/* This goes throws the inventory and removes unpaid objects, and puts them
2205{ 2147{
2206 while (op) 2148 while (op)
2207 { 2149 {
2208 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2150 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2209 2151
2210 if (QUERY_FLAG (op, FLAG_UNPAID)) 2152 if (op->flag [FLAG_UNPAID])
2211 op->insert_at (env); 2153 op->insert_at (env);
2212 else if (op->inv) 2154 else if (op->inv)
2213 drop_unpaid_items (op->inv, env); 2155 drop_unpaid_items (op->inv, env);
2214 2156
2215 op = next; 2157 op = next;
2221{ 2163{
2222 if (!flag [FLAG_REMOVED]) 2164 if (!flag [FLAG_REMOVED])
2223 ::drop_unpaid_items (inv, this); 2165 ::drop_unpaid_items (inv, this);
2224} 2166}
2225 2167
2226/*
2227 * Returns pointer a static string containing gravestone text
2228 * Moved from apply.c to player.c - player.c is what
2229 * actually uses this function. player.c may not be quite the
2230 * best, a misc file for object actions is probably better,
2231 * but there isn't one in the server directory.
2232 */
2233const char *
2234gravestone_text (object *op)
2235{
2236 static dynbuf_text buf;
2237
2238 buf << "---- R.I.P. ----\n\n"
2239 << op->name;
2240
2241 if (op->type == PLAYER)
2242 buf << " the " << op->contr->title;
2243
2244 buf << "\n\n";
2245
2246 buf << "who was level ";
2247 buf << (sint32)op->level << "\n\n" // OO breakdown
2248 << " when " << (op->contr ? "killed" : "died") << "\n\n";
2249
2250 if (op->type == PLAYER)
2251 buf << "by " << op->contr->killer_name () << ".\n\n";
2252
2253 {
2254 static char buf2[128];
2255 time_t now = time (NULL);
2256 strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now));
2257 buf << buf2;
2258 }
2259
2260 return buf;
2261}
2262
2263void 2168void
2264do_some_living (object *op) 2169do_some_living (object *op)
2265{ 2170{
2266 int last_food = op->stats.food; 2171 int last_food = op->stats.food;
2267 int gen_hp, gen_sp, gen_grace; 2172 int gen_hp, gen_sp, gen_grace;
2268 int over_hp, over_sp, over_grace;
2269 int i; 2173 int i;
2270 int rate_hp = 1200; 2174 int rate_hp = 1200;
2271 int rate_sp = 2500; 2175 int rate_sp = 2500;
2272 int rate_grace = 2000; 2176 int rate_grace = 2000;
2273 const int max_hp = 1; 2177 const int max_hp = 1;
2279 op->invisible = 1000; 2183 op->invisible = 1000;
2280 /* the socket code flashes the player visible/invisible 2184 /* the socket code flashes the player visible/invisible
2281 * depending on the value of invisible, so we need to 2185 * depending on the value of invisible, so we need to
2282 * alternate it here for it to work correctly. 2186 * alternate it here for it to work correctly.
2283 */ 2187 */
2284 if (pticks & 2) 2188 if (server_tick & 2)
2285 op->invisible--; 2189 op->invisible--;
2286 } 2190 }
2287 else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) 2191 else if (op->invisible && !(op->flag [FLAG_MAKE_INVIS]))
2288 { 2192 {
2289 if (!op->invisible--) 2193 if (!op->invisible--)
2290 { 2194 {
2291 make_visible (op); 2195 make_visible (op);
2292 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2196 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2326 if (--op->last_grace < 0) 2230 if (--op->last_grace < 0)
2327 { 2231 {
2328 if (op->stats.grace < op->stats.maxgrace / 2) 2232 if (op->stats.grace < op->stats.maxgrace / 2)
2329 op->stats.grace++; /* no penalty in food for regaining grace */ 2233 op->stats.grace++; /* no penalty in food for regaining grace */
2330 2234
2235 int temp = gen_grace < 20 ? 30 : gen_grace + 10;
2236
2331 if (max_grace > 1) 2237 if (max_grace > 1)
2332 { 2238 {
2333 over_grace = (gen_grace < 20 ? 30 : gen_grace + 10) / rate_grace; 2239 int over_grace = temp / rate_grace;
2240
2334 if (over_grace > 0) 2241 if (over_grace > 0)
2335 { 2242 {
2336 op->stats.sp += over_grace 2243 op->stats.sp += over_grace + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > (temp % rate_grace)) ? -1 : 0;
2337 + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > ((gen_grace < 20 ? 30 : gen_grace + 10) % rate_grace)) ? -1 : 0;
2338 op->last_grace = 0; 2244 op->last_grace = 0;
2339 } 2245 }
2340 else 2246 else
2341 { 2247 op->last_grace = rate_grace / temp;
2342 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10);
2343 }
2344 } 2248 }
2345 else 2249 else
2346 { 2250 op->last_grace = rate_grace / temp;
2347 op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); 2251
2348 }
2349 /* wearing stuff doesn't detract from grace generation. */ 2252 /* wearing stuff doesn't detract from grace generation. */
2350 } 2253 }
2351 2254
2352 if (op->stats.food > 0) 2255 if (op->stats.food > 0)
2353 { 2256 {
2359 if (op->stats.sp < op->stats.maxsp) 2262 if (op->stats.sp < op->stats.maxsp)
2360 { 2263 {
2361 op->stats.sp++; 2264 op->stats.sp++;
2362 2265
2363 /* dms do not consume food */ 2266 /* dms do not consume food */
2364 if (!QUERY_FLAG (op, FLAG_WIZ)) 2267 if (!op->flag [FLAG_WIZ])
2365 { 2268 {
2366 op->stats.food--; 2269 op->stats.food--;
2367 2270
2368 if (op->contr->digestion < 0) 2271 if (op->contr->digestion < 0)
2369 op->stats.food += op->contr->digestion; 2272 op->stats.food += op->contr->digestion;
2372 } 2275 }
2373 } 2276 }
2374 2277
2375 if (max_sp > 1) 2278 if (max_sp > 1)
2376 { 2279 {
2377 over_sp = (gen_sp + 10) / rate_sp; 2280 int over_sp = (gen_sp + 10) / rate_sp;
2378 if (over_sp > 0) 2281 if (over_sp > 0)
2379 { 2282 {
2380 if (op->stats.sp < op->stats.maxsp) 2283 if (op->stats.sp < op->stats.maxsp)
2381 { 2284 {
2382 op->stats.sp += over_sp > max_sp ? max_sp : over_sp; 2285 op->stats.sp += over_sp > max_sp ? max_sp : over_sp;
2403 if (op->stats.hp < op->stats.maxhp) 2306 if (op->stats.hp < op->stats.maxhp)
2404 { 2307 {
2405 op->stats.hp++; 2308 op->stats.hp++;
2406 2309
2407 /* dms do not consume food */ 2310 /* dms do not consume food */
2408 if (!QUERY_FLAG (op, FLAG_WIZ)) 2311 if (!op->flag [FLAG_WIZ])
2409 { 2312 {
2410 op->stats.food--; 2313 op->stats.food--;
2411 2314
2412 if (op->contr->digestion < 0) 2315 if (op->contr->digestion < 0)
2413 op->stats.food += op->contr->digestion; 2316 op->stats.food += op->contr->digestion;
2414 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) 2317 else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH))
2415 op->stats.food = last_food; 2318 op->stats.food = last_food;
2416 } 2319 }
2417 } 2320 }
2418 2321
2322 int temp = gen_hp < 20 ? 30 : gen_hp + 10;
2323
2419 if (max_hp > 1) 2324 if (max_hp > 1)
2420 { 2325 {
2421 over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; 2326 int over_hp = temp / rate_hp;
2422 2327
2423 if (over_hp > 0) 2328 if (over_hp > 0)
2424 { 2329 {
2425 op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; 2330 op->stats.sp += over_hp + (random_roll (0, rate_hp - 1, op, PREFER_HIGH) > (temp % rate_hp)) ? -1 : 0;
2426 op->last_heal = 0; 2331 op->last_heal = 0;
2427 } 2332 }
2428 else 2333 else
2429 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2334 op->last_heal = rate_hp / temp;
2430 } 2335 }
2431 else 2336 else
2432 op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); 2337 op->last_heal = rate_hp / temp;
2433 } 2338 }
2434 } 2339 }
2435 2340
2436 /* Digestion */ 2341 /* Digestion */
2437 if (--op->last_eat < 0) 2342 if (--op->last_eat < 0)
2440 penalty = max (0, -op->contr->digestion); 2345 penalty = max (0, -op->contr->digestion);
2441 2346
2442 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); 2347 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2443 2348
2444 /* dms do not consume food */ 2349 /* dms do not consume food */
2445 if (!QUERY_FLAG (op, FLAG_WIZ)) 2350 if (!op->flag [FLAG_WIZ])
2446 op->stats.food--; 2351 op->stats.food--;
2447 } 2352 }
2448 2353
2449 if (op->stats.food < 0 && op->stats.hp >= 0) 2354 if (op->stats.food < 0 && op->stats.hp >= 0)
2450 { 2355 {
2451 object *flesh = 0; 2356 object *flesh = 0;
2452 2357
2453 for_inv_removable (op, tmp) 2358 for_inv_removable (op, tmp)
2454 { 2359 {
2455 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 2360 if (tmp->flag [FLAG_UNPAID])
2456 continue; 2361 continue;
2457 2362
2458 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2363 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2459 { 2364 {
2460 op->statusmsg ("You blindly grab for a bite of food. " 2365 op->statusmsg ("You blindly grab for a bite of food. "
2461 "H<To prevent you from starving, you ate some random item from your backpack.>"); 2366 "H<To prevent you from starving, you ate some random item from your backpack.>");
2462 manual_apply (op, tmp, 0); 2367 op->apply (tmp);
2463 2368
2464 if (op->stats.food >= 0 || op->stats.hp < 0) 2369 if (op->stats.food >= 0 || op->stats.hp < 0)
2465 break; 2370 break;
2466 } 2371 }
2467 else if (tmp->type == FLESH) 2372 else if (tmp->type == FLESH)
2473 */ 2378 */
2474 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2379 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2475 { 2380 {
2476 op->statusmsg ("You blindly grab for a bite of food. " 2381 op->statusmsg ("You blindly grab for a bite of food. "
2477 "H<To prevent you from starving, you ate some random item from your backpack.>"); 2382 "H<To prevent you from starving, you ate some random item from your backpack.>");
2478 manual_apply (op, flesh, 0); 2383 op->apply (flesh);
2479 } 2384 }
2480 2385
2481 // If player is still starving, alert him! 2386 // If player is still starving, alert him!
2482 if (op->stats.food < 0) 2387 if (op->stats.food < 0)
2483 op->failmsg ("You are starving! " 2388 op->failmsg ("You are starving! "
2495 op->contr->killer->destroy (); 2400 op->contr->killer->destroy ();
2496 } 2401 }
2497 } 2402 }
2498 2403
2499 /* killer should be set here already */ 2404 /* killer should be set here already */
2500 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2405 if (op->stats.hp < 0 && !op->flag [FLAG_WIZ])
2501 kill_player (op); 2406 kill_player (op);
2502 } 2407 }
2503} 2408}
2504 2409
2505/* If the player should die (lack of hp, food, etc), we call this. 2410/* If the player should die (lack of hp, food, etc), we call this.
2520 return; 2425 return;
2521 2426
2522 dynbuf_text deathtab; 2427 dynbuf_text deathtab;
2523 2428
2524 /* restore player */ 2429 /* restore player */
2525 at = archetype::find ("poisoning"); 2430 at = archetype::find (shstr_poisoning);
2526 if (object *tmp = present_arch_in_ob (at, op)) 2431 if (object *tmp = present_arch_in_ob (at, op))
2527 { 2432 {
2528 tmp->destroy (); 2433 tmp->destroy ();
2529 deathtab << "Your body feels cleansed...\r"; 2434 deathtab << "Your body feels cleansed...\r";
2530 } 2435 }
2531 2436
2532 at = archetype::find ("confusion"); 2437 at = archetype::find (shstr_confusion);
2533 if (object *tmp = present_arch_in_ob (at, op)) 2438 if (object *tmp = present_arch_in_ob (at, op))
2534 { 2439 {
2535 tmp->destroy (); 2440 tmp->destroy ();
2536 deathtab << "Your mind feels clearer...\r"; 2441 deathtab << "Your mind feels clearer...\r";
2537 } 2442 }
2539 cure_disease (op, 0, 0); /* remove any disease */ 2444 cure_disease (op, 0, 0); /* remove any disease */
2540 2445
2541 max_it (op->stats.hp , op->stats.maxhp); 2446 max_it (op->stats.hp , op->stats.maxhp);
2542 max_it (op->stats.sp , op->stats.maxsp); 2447 max_it (op->stats.sp , op->stats.maxsp);
2543 max_it (op->stats.grace, op->stats.maxgrace); 2448 max_it (op->stats.grace, op->stats.maxgrace);
2544
2545 if (op->stats.food <= 0) 2449 max_it (op->stats.food , 200);
2546 op->stats.food = 999;
2547 2450
2548 // remove all spell effects that are active 2451 // remove all spell effects that are active
2549 // to avoid long-term effects such as word-of-recall 2452 // to avoid long-term effects such as word-of-recall
2550 for (object *item = op->inv; item; ) 2453 for (object *item = op->inv; item; )
2551 { 2454 {
2564 if (op_on_battleground (op, &x, &y)) 2467 if (op_on_battleground (op, &x, &y))
2565 { 2468 {
2566 deathtab << "You almost died in combat, but local medics have saved your life...\r"; 2469 deathtab << "You almost died in combat, but local medics have saved your life...\r";
2567 2470
2568 /* create a bodypart-trophy to make the winner happy */ 2471 /* create a bodypart-trophy to make the winner happy */
2569 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2472 object *tmp = archetype::find (shstr_finger)->instance ();
2570 { 2473
2571 tmp->name = format ("%s's finger" , &op->name); 2474 tmp->name = format ("%s's finger" , &op->name);
2572 tmp->name_pl = format ("%s's fingers", &op->name); 2475 tmp->name_pl = format ("%s's fingers", &op->name);
2573 tmp->msg = format ( 2476 tmp->msg = format (
2574 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2477 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n",
2575 &op->name, op->contr->title, 2478 &op->name, op->contr->title,
2576 (int)op->level, 2479 (int)op->level,
2577 op->contr->killer_name () 2480 op->contr->killer_name ()
2578 ); 2481 );
2579 tmp->value = 0, tmp->type = 0; 2482 tmp->value = 0, tmp->type = 0;
2580 tmp->materialname = "organics"; 2483 tmp->material = name_to_material (shstr_organic);
2581 tmp->insert_at (op, tmp); 2484 tmp->insert_at (op, tmp);
2582 }
2583 2485
2584 /* teleport defeated player to new destination */ 2486 /* teleport defeated player to new destination */
2585 transfer_ob (op, x, y, 0, NULL); 2487 transfer_ob (op, x, y, 0, NULL);
2586 op->contr->braced = 0; 2488 op->contr->braced = 0;
2587 2489
2649 lost_a_stat = 1; 2551 lost_a_stat = 1;
2650 } 2552 }
2651 else 2553 else
2652 { 2554 {
2653 /* deplete a stat */ 2555 /* deplete a stat */
2654 archetype *deparch = archetype::find ("depletion"); 2556 archetype *deparch = archetype::find (shstr_depletion);
2655 object *dep; 2557 object *dep;
2656 2558
2657 dep = present_arch_in_ob (deparch, op); 2559 dep = present_arch_in_ob (deparch, op);
2658 if (!dep) 2560 if (!dep)
2659 { 2561 {
2660 dep = arch_to_object (deparch); 2562 dep = deparch->instance ();
2661 insert_ob_in_ob (dep, op); 2563 insert_ob_in_ob (dep, op);
2662 } 2564 }
2663 lose_this_stat = 1; 2565 lose_this_stat = 1;
2664 if (settings.balanced_stat_loss) 2566 if (settings.balanced_stat_loss)
2665 { 2567 {
2703 * difference. 2605 * difference.
2704 */ 2606 */
2705 if (this_stat >= -50) 2607 if (this_stat >= -50)
2706 { 2608 {
2707 change_attr_value (&(dep->stats), i, -1); 2609 change_attr_value (&(dep->stats), i, -1);
2708 SET_FLAG (dep, FLAG_APPLIED); 2610 dep->set_flag (FLAG_APPLIED);
2709 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2611 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2710 op->update_stats (); 2612 op->update_stats ();
2711 lost_a_stat = 1; 2613 lost_a_stat = 1;
2712 } 2614 }
2713 } 2615 }
2731#endif 2633#endif
2732 2634
2733 /* Put a gravestone up where the character 'almost' died. List the 2635 /* Put a gravestone up where the character 'almost' died. List the
2734 * exp loss on the stone. 2636 * exp loss on the stone.
2735 */ 2637 */
2736 tmp = arch_to_object (archetype::find ("gravestone")); 2638 tmp = archetype::find (shstr_gravestone)->instance ();
2737 tmp->name = format ("%s's gravestone", &op->name); 2639 tmp->name = format ("%s's gravestone", &op->name);
2738 tmp->name_pl = format ("%s's gravestones", &op->name); 2640 tmp->name_pl = format ("%s's gravestones", &op->name);
2739 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", 2641 tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n",
2740 &op->name, op->contr->title, op->contr->killer_name ()); 2642 &op->name, op->contr->title, op->contr->killer_name ());
2741 tmp->x = op->x, tmp->y = op->y; 2643 tmp->x = op->x, tmp->y = op->y;
2780 if (will_kill_again) 2682 if (will_kill_again)
2781 { 2683 {
2782 object *force; 2684 object *force;
2783 int at; 2685 int at;
2784 2686
2785 force = get_archetype (FORCE_NAME); 2687 force = archetype::get (FORCE_NAME);
2786 /* 50 ticks should be enough time for the spell to abate */ 2688 /* 50 ticks should be enough time for the spell to abate */
2787 force->speed = 0.1f;
2788 force->speed_left = -5.f; 2689 force->speed_left = -5.f;
2789 SET_FLAG (force, FLAG_APPLIED); 2690 force->set_speed (0.1f);
2691 force->set_flag (FLAG_APPLIED);
2692
2790 for (at = 0; at < NROFATTACKS; at++) 2693 for (at = 0; at < NROFATTACKS; at++)
2791 if (will_kill_again & (1 << at)) 2694 if (will_kill_again & (1 << at))
2792 force->resist[at] = 100; 2695 force->resist[at] = 100;
2793 2696
2794 insert_ob_in_ob (force, op); 2697 insert_ob_in_ob (force, op);
2796 } 2699 }
2797 2700
2798 op->contr->infobox (MSG_CHANNEL ("death"), deathtab); 2701 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2799} 2702}
2800 2703
2801void 2704static void
2802loot_object (object *op) 2705loot_object (object *op)
2803{ /* Grab and destroy some treasure */ 2706{ /* Grab and destroy some treasure */
2804 object *tmp, *tmp2, *next; 2707 object *tmp, *tmp2, *next;
2805 2708
2806 op->close_container (); /* close open sack first */ 2709 op->close_container (); /* close open sack first */
2816 tmp->x = op->x, tmp->y = op->y; 2719 tmp->x = op->x, tmp->y = op->y;
2817 2720
2818 if (tmp->type == CONTAINER) 2721 if (tmp->type == CONTAINER)
2819 loot_object (tmp); /* empty container to ground */ 2722 loot_object (tmp); /* empty container to ground */
2820 2723
2821 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2724 if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3))))
2822 { 2725 {
2823 if (tmp->nrof > 1) 2726 if (tmp->nrof > 1)
2824 { 2727 {
2825 tmp->decrease (rndm (1, tmp->nrof - 1)); 2728 tmp->decrease (rndm (1, tmp->nrof - 1));
2826 insert_ob_in_map (tmp, op->map, NULL, 0); 2729 insert_ob_in_map (tmp, op->map, NULL, 0);
2837 * fix_weight(): Check recursively the weight of all players, and fix 2740 * fix_weight(): Check recursively the weight of all players, and fix
2838 * what needs to be fixed. Refresh windows and fix speed if anything 2741 * what needs to be fixed. Refresh windows and fix speed if anything
2839 * was changed. 2742 * was changed.
2840 */ 2743 */
2841void 2744void
2842fix_weight (void) 2745fix_weight ()
2843{ 2746{
2844 for_all_players (pl) 2747 for_all_players (pl)
2845 { 2748 {
2846 sint32 old = pl->ob->carrying; 2749 sint32 old = pl->ob->carrying;
2847 2750
2854 } 2757 }
2855 } 2758 }
2856} 2759}
2857 2760
2858void 2761void
2859fix_luck (void) 2762fix_luck ()
2860{ 2763{
2861 for_all_players (pl) 2764 for_all_players (pl)
2862 if (!pl->ob->contr->ns->state) 2765 if (!pl->ob->contr->ns->state)
2863 pl->ob->change_luck (0); 2766 pl->ob->change_luck (0);
2864} 2767}
2916} 2819}
2917 2820
2918int 2821int
2919is_true_undead (object *op) 2822is_true_undead (object *op)
2920{ 2823{
2921 if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) 2824 if (op->arch->flag [FLAG_UNDEAD])
2922 return 1; 2825 return 1;
2923 2826
2924 return 0; 2827 return 0;
2925} 2828}
2926 2829
3024 2927
3025 if (who->type == PLAYER) 2928 if (who->type == PLAYER)
3026 player = 1; 2929 player = 1;
3027 2930
3028 else 2931 else
3029 friendly = QUERY_FLAG (who, FLAG_FRIENDLY); 2932 friendly = who->flag [FLAG_FRIENDLY];
3030 2933
3031 /* search adjacent squares */ 2934 /* search adjacent squares */
3032 for (i = 1; i < 9; i++) 2935 for (i = 1; i < 9; i++)
3033 { 2936 {
3034 x = who->x + freearr_x[i]; 2937 x = who->x + freearr_x[i];
3043 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 2946 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
3044 continue; 2947 continue;
3045 2948
3046 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 2949 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
3047 { 2950 {
3048 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 2951 if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE])
3049 return 1; 2952 return 1;
3050 else if (tmp->type == PLAYER) 2953 else if (tmp->type == PLAYER)
3051 { 2954 {
3052 /*don't let a hidden DM prevent you from hiding */ 2955 /*don't let a hidden DM prevent you from hiding */
3053 if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0) 2956 if (!tmp->flag [FLAG_WIZ] || tmp->contr->hidden == 0)
3054 return 1; 2957 return 1;
3055 } 2958 }
3056 } 2959 }
3057 } 2960 }
3058 return 0; 2961 return 0;
3108 } 3011 }
3109 3012
3110 return 0; 3013 return 0;
3111} 3014}
3112 3015
3113/* routine for both players and monsters. We call this when
3114 * there is a possibility for our action distrubing our hiding
3115 * place or invisiblity spell. Artefact invisiblity causes
3116 * "noise" instead. If we arent invisible to begin with, we
3117 * return 0.
3118 */
3119int
3120action_makes_visible (object *op)
3121{
3122 if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE))
3123 {
3124 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
3125 {
3126 // artefact invisibility is permanent, but we still make noise
3127 // this is important for game-balance.
3128 if (op->contr)
3129 op->make_noise ();
3130
3131 return 0;
3132 }
3133
3134 if (op->contr && op->contr->tmp_invis == 0)
3135 return 0;
3136
3137 /* If monsters, they should become visible */
3138 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
3139 {
3140 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
3141 return 1;
3142 }
3143 }
3144
3145 return 0;
3146}
3147
3148/* op_on_battleground - checks if the given object op (usually 3016/* op_on_battleground - checks if the given object op (usually
3149 * a player) is standing on a valid battleground-tile, 3017 * a player) is standing on a valid battleground-tile,
3150 * function returns TRUE/FALSE. If true x, y returns the battleground 3018 * function returns TRUE/FALSE. If true x, y returns the battleground
3151 * -exit-coord. (and if x, y not NULL) 3019 * -exit-coord. (and if x, y not NULL)
3152 * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set 3020 * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set
3162 * and the exit-coordinates sp/hp must both be > 0. 3030 * and the exit-coordinates sp/hp must both be > 0.
3163 * => The intention here is to prevent abuse of the battleground- 3031 * => The intention here is to prevent abuse of the battleground-
3164 * feature (like pickable or hidden battleground tiles). */ 3032 * feature (like pickable or hidden battleground tiles). */
3165 for (object *tmp = op->below; tmp; tmp = tmp->below) 3033 for (object *tmp = op->below; tmp; tmp = tmp->below)
3166 { 3034 {
3167 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3035 if (tmp->flag [FLAG_IS_FLOOR])
3168 { 3036 {
3169 if (QUERY_FLAG (tmp, FLAG_NO_PICK) 3037 if (tmp->flag [FLAG_NO_PICK]
3170 && tmp->type == BATTLEGROUND 3038 && tmp->type == BATTLEGROUND
3171 && tmp->name == shstr_battleground 3039 && tmp->name == shstr_battleground
3172 && EXIT_X (tmp) && EXIT_Y (tmp)) 3040 && EXIT_X (tmp) && EXIT_Y (tmp))
3173 { 3041 {
3174 /* before we assign the exit, check if this is a teambattle */ 3042 /* before we assign the exit, check if this is a teambattle */
3175 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3043 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3176 {
3177 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) 3044 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3045 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3178 { 3046 {
3179 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3180 {
3181 if (x && y) 3047 if (x && y)
3182 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3048 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3183 3049
3184 return 1; 3050 return 1;
3185 }
3186 } 3051 }
3187 }
3188 3052
3189 if (x && y) 3053 if (x && y)
3190 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3054 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3191 3055
3192 return 1; 3056 return 1;
3330 else 3194 else
3331 j = 1; 3195 j = 1;
3332 strcat (buf, spellpathnames[i]); 3196 strcat (buf, spellpathnames[i]);
3333 } 3197 }
3334 } 3198 }
3199
3335 strcat (buf, "."); 3200 strcat (buf, ".");
3336 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3201 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3337 } 3202 }
3338 3203
3339 /* evtl. adding flags: */ 3204 /* evtl. adding flags: */
3340 if (QUERY_FLAG (item, FLAG_XRAYS)) 3205 if (item->flag [FLAG_XRAYS])
3341 SET_FLAG (skin, FLAG_XRAYS); 3206 skin->set_flag (FLAG_XRAYS);
3342 if (QUERY_FLAG (item, FLAG_STEALTH)) 3207 if (item->flag [FLAG_STEALTH])
3343 SET_FLAG (skin, FLAG_STEALTH); 3208 skin->set_flag (FLAG_STEALTH);
3344 if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) 3209 if (item->flag [FLAG_SEE_IN_DARK])
3345 SET_FLAG (skin, FLAG_SEE_IN_DARK); 3210 skin->set_flag (FLAG_SEE_IN_DARK);
3346 3211
3347 /* print message if there is one */ 3212 /* print message if there is one */
3348 if (item->msg != NULL) 3213 if (item->msg != NULL)
3349 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3214 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3350 } 3215 }
3351 else 3216 else
3352 { 3217 {
3353 /* generate misc. treasure */ 3218 /* generate misc. treasure */
3354 tmp = arch_to_object (tr->item); 3219 tmp = tr->item->instance ();
3355 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3220 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3356 who->insert (tmp); 3221 who->insert (tmp);
3357 } 3222 }
3358} 3223}
3359 3224
3360/** 3225//-GPL
3361 * Unready an object for a player. This function does nothing if the object was
3362 * not readied.
3363 */
3364void
3365player_unready_range_ob (player *pl, object *ob)
3366{
3367 if (pl->ob->current_weapon == ob)
3368 pl->ob->current_weapon = 0;
3369
3370 if (pl->combat_ob == ob)
3371 pl->combat_ob = 0;
3372
3373 if (pl->ranged_ob == ob)
3374 pl->ranged_ob = 0;
3375}
3376 3226
3377sint8 3227sint8
3378player::darkness_at (maptile *map, int x, int y) const 3228player::darkness_at (maptile *map, int x, int y) const
3379{ 3229{
3380 if (!ns) 3230 if (!ns)
3407{ 3257{
3408 play_sound (sound_find ("generic_failure")); 3258 play_sound (sound_find ("generic_failure"));
3409 statusmsg (msg, color); 3259 statusmsg (msg, color);
3410} 3260}
3411 3261
3262void
3263object::failmsgf (const char *format, ...)
3264{
3265 if (!contr)
3266 return;
3267
3268 va_list ap;
3269 va_start (ap, format);
3270 contr->failmsg (vformat (format, ap));
3271 va_end (ap);
3272}
3273
3274void
3275player::failmsgf (const char *format, ...)
3276{
3277 va_list ap;
3278 va_start (ap, format);
3279 failmsg (vformat (format, ap));
3280 va_end (ap);
3281}
3282

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines