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.274 by root, Wed Apr 21 06:40:57 2010 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 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
25#include <global.h> 27#include <global.h>
26#include <sproto.h> 28#include <sproto.h>
27#include <sounds.h> 29#include <sounds.h>
28#include <living.h> 30#include <living.h>
29#include <object.h> 31#include <object.h>
33#include <algorithm> 35#include <algorithm>
34#include <functional> 36#include <functional>
35 37
36playervec players; 38playervec players;
37 39
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
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{
159 op->contr->maplevel = first_map_path; 44 op->contr->maplevel = first_map_path;
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)
251 132
252 ns->floorbox_update (); 133 ns->floorbox_update ();
253 esrv_send_inventory (ob, ob); 134 esrv_send_inventory (ob, ob);
254 esrv_add_spells (this, 0); 135 esrv_add_spells (this, 0);
255 136
137 ob->flag [FLAG_READY_WEAPON] = false;
138 ob->flag [FLAG_READY_SKILL] = false;
139 ob->flag [FLAG_READY_RANGE] = false;
140 ob->flag [FLAG_READY_BOW] = false;
141
142 ob->update_stats (); // we unapplied stuff above
256 activate (); 143 activate ();
257
258 send_rules (ob);
259 send_news (ob);
260 display_motd (ob);
261 144
262 INVOKE_PLAYER (CONNECT, this); 145 INVOKE_PLAYER (CONNECT, this);
263 INVOKE_PLAYER (LOGIN, this); 146 INVOKE_PLAYER (LOGIN, this);
264} 147}
265 148
282 ns->reset_stats (); 165 ns->reset_stats ();
283 ns->pl = 0; 166 ns->pl = 0;
284 ns = 0; 167 ns = 0;
285 } 168 }
286 169
287 observe = ob; 170 // this is important for the player scheduler to get the correct refcount
171 // when ns = 0
172 observe = viewpoint = ob;
288 173
289 deactivate (); 174 deactivate ();
290} 175}
176
177//-GPL
291 178
292// the need for this function can be explained 179// the need for this function can be explained
293// by load_object not returning the object 180// by load_object not returning the object
294void 181void
295player::set_object (object *op) 182player::set_object (object *op)
296{ 183{
297 ob = observe = op; 184 ob = observe = viewpoint = op;
298 ob->contr = this; /* this aren't yet in archetype */ 185 ob->contr = this; /* this aren't yet in archetype */
299 186
300 ob->speed = 1.0f; 187 ob->speed = 1.0f;
301 ob->speed_left = 0.5f; 188 ob->speed_left = 0.5f;
302 189
303 ob->direction = 5; /* So player faces south */ 190 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} 191}
332 192
333void 193void
334player::set_observe (object *op) 194player::set_observe (object *op)
335{ 195{
336 observe = op ? op : ob; 196 observe = viewpoint = op ? op : ob;
337 do_los = 1; 197 do_los = 1;
338} 198}
199
200void
201player::set_viewpoint (object *op)
202{
203 viewpoint = op ? op : (object *)observe;
204 do_los = 1;
205}
206
207//+GPL
339 208
340player::player () 209player::player ()
341{ 210{
342 /* There are some elements we want initialised to non zero value - 211 /* There are some elements we want initialised to non zero value -
343 * we deal with that below this point. 212 * we deal with that below this point.
365 disconnect (); 234 disconnect ();
366 235
367 attachable::do_destroy (); 236 attachable::do_destroy ();
368 237
369 if (ob) 238 if (ob)
370 {
371 ob->destroy_inv (false);
372 ob->destroy (); 239 ob->destroy ();
373 }
374 240
375 ob = observe = 0; 241 ob = observe = viewpoint = 0;
376} 242}
377 243
378player::~player () 244player::~player ()
379{ 245{
380 /* Clear item stack */ 246 /* Clear item stack */
381 free (stack_items); 247 free (stack_items);
248}
249
250/*
251 * get_player_archetype() return next player archetype from archetype
252 * list. Not very efficient routine, but used only creating new players.
253 * Note: there MUST be at least one player archetype!
254 */
255static archetype *
256get_player_archetype (archetype *at)
257{
258 // archetypes could have been reloaded
259 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
260
261 if (!nat)
262 return at;
263
264 archvec::iterator i = archetypes.find (nat);
265
266 for (;;)
267 {
268 if (++i == archetypes.end ())
269 i = archetypes.begin ();
270 else if (*i == at)
271 cleanup ("not a single player archetype found");
272
273 if ((*i)->type == PLAYER)
274 return *i;
275 }
382} 276}
383 277
384/* Tries to add player on the connection passed in ns. 278/* 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 279 * All we can really get in this is some settings like host and display
386 * mode. 280 * mode.
388player * 282player *
389player::create () 283player::create ()
390{ 284{
391 player *pl = new player; 285 player *pl = new player;
392 286
393 pl->set_object (arch_to_object (get_player_archetype (0))); 287 pl->set_object (get_player_archetype (0)->instance ());
394 288
395 pl->ob->roll_stats (); 289 pl->ob->roll_stats ();
396 pl->ob->stats.wc = 2; 290 pl->ob->stats.wc = 2;
397 pl->ob->run_away = 25; /* Then we panick... */ 291 pl->ob->run_away = 25; /* Then we panick... */
398 292
399 set_first_map (pl->ob); 293 set_first_map (pl->ob);
400 294
401 return pl; 295 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} 296}
431 297
432object * 298object *
433get_nearest_player (object *mon) 299get_nearest_player (object *mon)
434{ 300{
508 */ 374 */
509int 375int
510path_to_player (object *mon, object *pl, unsigned mindiff) 376path_to_player (object *mon, object *pl, unsigned mindiff)
511{ 377{
512 rv_vector rv; 378 rv_vector rv;
513 sint16 x, y;
514 int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; 379 int dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
515 maptile *m, *lastmap;
516 380
517 get_rangevector (mon, pl, &rv, 0); 381 get_rangevector (mon, pl, &rv, 0);
518 382
519 if (rv.distance < mindiff) 383 if (rv.distance < mindiff)
520 return 0; 384 return 0;
521 385
522 x = mon->x; 386 mapxy pos (mon);
523 y = mon->y;
524 m = mon->map;
525 dir = rv.direction; 387 dir = rv.direction;
526 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ 388 lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
527 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 389 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
528 390
529 /* If we can't solve it within the search distance, return now. */ 391 /* If we can't solve it within the search distance, return now. */
530 if (diff > max) 392 if (diff > max)
531 return 0; 393 return 0;
532 394
533 while (diff > 1 && max > 0) 395 while (diff > 1 && max > 0)
534 { 396 {
535 lastx = x; 397 mapxy lastpos = pos;
536 lasty = y;
537 lastmap = m;
538 x = lastx + freearr_x[dir];
539 y = lasty + freearr_y[dir];
540 398
541 mflags = get_map_flags (m, &m, x, y, &x, &y); 399 pos.move (dir);
542 blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK (m, x, y);
543 400
544 /* Space is blocked - try changing direction a little */ 401 /* Space is blocked - try changing direction a little */
545 if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK (mon, blocked) || (mflags & P_BLOCKSVIEW)) 402 if (!pos.normalise ()
546 && (m == mon->map && blocked_link (mon, m, x, y)))) 403 || (((pos->flags () & P_BLOCKSVIEW) || OB_TYPE_MOVE_BLOCK (mon, pos->move_block))
404 && blocked_link (mon, pos.m, pos.x, pos.y)))
547 { 405 {
548 /* recalculate direction from last good location. Possible 406 /* recalculate direction from last good location. Possible
549 * we were not traversing ideal location before. 407 * we were not traversing ideal location before.
550 */ 408 */
551 get_rangevector_from_mapcoord (lastmap, lastx, lasty, pl, &rv, 0); 409 get_rangevector_from_mapcoord (lastpos.m, lastpos.x, lastpos.y, pl, &rv, 0);
552 if (rv.direction != dir) 410 if (rv.direction != dir)
553 { 411 {
554 /* OK - says direction should be different - lets reset the 412 /* OK - says direction should be different - lets reset the
555 * the values so it will try again. 413 * the values so it will try again.
556 */ 414 */
557 x = lastx;
558 y = lasty;
559 m = lastmap; 415 pos = lastpos;
560 dir = firstdir = rv.direction; 416 dir = firstdir = rv.direction;
561 } 417 }
562 else 418 else
563 { 419 {
564 /* direct path is blocked - try taking a side step to 420 /* direct path is blocked - try taking a side step to
571 */ 427 */
572 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) 428 for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++)
573 { 429 {
574 if (i == 0) 430 if (i == 0)
575 continue; /* already did this, so skip it */ 431 continue; /* already did this, so skip it */
432
576 /* Use lastdir here - otherwise, 433 /* Use lastdir here - otherwise,
577 * since the direction that the creature should move in 434 * since the direction that the creature should move in
578 * may change, you could get infinite loops. 435 * may change, you could get infinite loops.
579 * ie, player is northwest, but monster can only 436 * ie, player is northwest, but monster can only
580 * move west, so it does that. It goes some distance, 437 * move west, so it does that. It goes some distance,
582 * can't do that, but now finds it can move east, and 439 * can't do that, but now finds it can move east, and
583 * gets back to its original point. lastdir contains 440 * gets back to its original point. lastdir contains
584 * the last direction the creature has successfully 441 * the last direction the creature has successfully
585 * moved. 442 * moved.
586 */ 443 */
587
588 x = lastx + freearr_x[absdir (lastdir + i)];
589 y = lasty + freearr_y[absdir (lastdir + i)];
590 m = lastmap; 444 pos = lastpos;
591 mflags = get_map_flags (m, &m, x, y, &x, &y); 445 pos.move (absdir (lastdir + i));
592 if (mflags & P_OUT_OF_MAP) 446
447 if (!pos.normalise ())
593 continue; 448 continue;
594 blocked = GET_MAP_MOVE_BLOCK (m, x, y); 449
595 if (OB_TYPE_MOVE_BLOCK (mon, blocked)) 450 mapspace &ms = *pos;
451
452 if (ms.flags () & P_BLOCKSVIEW)
596 continue; 453 continue;
597 if (mflags & P_BLOCKSVIEW) 454
455 if (OB_TYPE_MOVE_BLOCK (mon, ms.move_block))
598 continue; 456 continue;
599 457
600 if (m == mon->map && blocked_link (mon, m, x, y)) 458 if (blocked_link (mon, pos.m, pos.x, pos.y))
601 break; 459 break;
602 } 460 }
461
603 /* go through entire loop without finding a valid 462 /* go through entire loop without finding a valid
604 * sidestep to take - thus, no valid path. 463 * sidestep to take - thus, no valid path.
605 */ 464 */
606 if (i == (DETOUR_AMOUNT + 1)) 465 if (i == DETOUR_AMOUNT + 1)
607 return 0; 466 return 0;
467
608 diff--; 468 diff--;
609 lastdir = dir; 469 lastdir = dir;
610 max--; 470 max--;
611 if (!firstdir) 471 if (!firstdir)
612 firstdir = dir + i; 472 firstdir = dir + i;
616 { 476 {
617 /* we moved towards creature, so diff is less */ 477 /* we moved towards creature, so diff is less */
618 diff--; 478 diff--;
619 max--; 479 max--;
620 lastdir = dir; 480 lastdir = dir;
481
621 if (!firstdir) 482 if (!firstdir)
622 firstdir = dir; 483 firstdir = dir;
623 } 484 }
624 485
625 if (diff <= 1) 486 if (diff <= 1)
626 { 487 {
627 /* Recalculate diff (distance) because we may not have actually 488 /* Recalculate diff (distance) because we may not have actually
628 * headed toward player for entire distance. 489 * headed toward player for entire distance.
629 */ 490 */
630 get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); 491 get_rangevector_from_mapcoord (pos.m, pos.x, pos.y, pl, &rv, 0);
631 diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); 492 diff = ::max (abs (rv.distance_x), abs (rv.distance_y));
632 } 493 }
633 494
634 if (diff > max) 495 if (diff > max)
635 return 0; 496 return 0;
653 next = op->below; 514 next = op->below;
654 515
655 /* Forces get applied per default, unless they have the 516 /* Forces get applied per default, unless they have the
656 * flag "neutral" set. Sorry but I can't think of a better way 517 * flag "neutral" set. Sorry but I can't think of a better way
657 */ 518 */
658 if (op->type == FORCE && !QUERY_FLAG (op, FLAG_NEUTRAL)) 519 if (op->type == FORCE && !op->flag [FLAG_NEUTRAL])
659 SET_FLAG (op, FLAG_APPLIED); 520 op->set_flag (FLAG_APPLIED);
660 521
661 /* we never give weapons/armour if these cannot be used 522 /* we never give weapons/armour if these cannot be used
662 * by this player due to race restrictions 523 * by this player due to race restrictions
663 */ 524 */
664 if (pl->type == PLAYER) 525 if (pl->type == PLAYER)
665 { 526 {
666 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) 527 if ((!pl->flag [FLAG_USE_ARMOUR]
667 && 528 &&
668 (op->type == ARMOUR || op->type == BOOTS 529 (op->type == ARMOUR || op->type == BOOTS
669 || op->type == CLOAK || op->type == HELMET 530 || op->type == CLOAK || op->type == HELMET
670 || op->type == SHIELD || op->type == GLOVES 531 || op->type == SHIELD || op->type == GLOVES
671 || op->type == BRACERS || op->type == GIRDLE)) 532 || op->type == BRACERS || op->type == GIRDLE))
672 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 533 || (!pl->flag [FLAG_USE_WEAPON] && op->type == WEAPON))
673 { 534 {
674 op->destroy (); 535 op->destroy ();
675 continue; 536 continue;
676 } 537 }
677 } 538 }
694 if (op->nrof > 1) 555 if (op->nrof > 1)
695 op->nrof = 1; 556 op->nrof = 1;
696 } 557 }
697 558
698 if (op->type == SPELLBOOK && op->inv) 559 if (op->type == SPELLBOOK && op->inv)
699 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 560 op->inv->clr_flag (FLAG_STARTEQUIP);
700 561
701 /* Give starting characters identified, uncursed, and undamned 562 /* Give starting characters identified, uncursed, and undamned
702 * items. Just don't identify gold or silver, or it won't be 563 * items. Just don't identify gold or silver, or it won't be
703 * merged properly. 564 * merged properly.
704 */ 565 */
705 if (need_identify (op)) 566 if (op->need_identify ())
706 { 567 {
707 SET_FLAG (op, FLAG_IDENTIFIED); 568 op->set_flag (FLAG_IDENTIFIED);
708 CLEAR_FLAG (op, FLAG_CURSED); 569 op->clr_flag (FLAG_CURSED);
709 CLEAR_FLAG (op, FLAG_DAMNED); 570 op->clr_flag (FLAG_DAMNED);
710 } 571 }
711 572
712 if (op->type == SPELL) 573 if (op->type == SPELL)
713 { 574 {
714 op->destroy (); 575 op->destroy ();
715 continue; 576 continue;
716 } 577 }
717 else if (op->type == SKILL) 578 else if (op->type == SKILL)
718 { 579 {
719 SET_FLAG (op, FLAG_CAN_USE_SKILL); 580 op->set_flag (FLAG_CAN_USE_SKILL);
720 op->stats.exp = 0; 581 op->stats.exp = 0;
721 op->level = 1; 582 op->level = 1;
722 } 583 }
723 else /* lock all 'normal items by default */ 584 else /* lock all 'normal items by default */
724 SET_FLAG (op, FLAG_INV_LOCKED); 585 op->set_flag (FLAG_INV_LOCKED);
725 } /* for loop of objects in player inv */ 586 } /* for loop of objects in player inv */
726 587
727 /* Need to set up the skill pointers */ 588 /* Need to set up the skill pointers */
728 pl->contr->link_skills (); 589 pl->contr->link_skills ();
729} 590}
743 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 604 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
744} 605}
745 606
746/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 607/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
747static int 608static int
748roll_stat (void) 609roll_stat ()
749{ 610{
750 int a[4], i, j, k; 611 int a[4], i, j, k;
751 612
752 for (i = 0; i < 4; i++) 613 for (i = 0; i < 4; i++)
753 a[i] = (int) rndm (6) + 1; 614 a[i] = (int) rndm (6) + 1;
850player::chargen_race_done () 711player::chargen_race_done ()
851{ 712{
852 /* this must before then initial items are given */ 713 /* this must before then initial items are given */
853 esrv_new_player (ob->contr); 714 esrv_new_player (ob->contr);
854 715
855 treasurelist *tl = treasurelist::find ("starting_wealth"); 716 treasurelist *tl = treasurelist::find (shstr_starting_wealth);
856 if (tl) 717 if (tl)
857 create_treasure (tl, ob, 0, 0, 0); 718 create_treasure (tl, ob, 0, 0, 0);
858 719
859 INVOKE_PLAYER (BIRTH, ob->contr); 720 INVOKE_PLAYER (BIRTH, ob->contr);
860 INVOKE_PLAYER (LOGIN, ob->contr); 721 INVOKE_PLAYER (LOGIN, ob->contr);
863 724
864 if (ob->msg) 725 if (ob->msg)
865 ob->msg = 0; 726 ob->msg = 0;
866 727
867 start_info (ob); 728 start_info (ob);
868 CLEAR_FLAG (ob, FLAG_WIZ); 729 ob->clr_flag (FLAG_WIZ);
869 give_initial_items (ob, ob->randomitems); 730 give_initial_items (ob, ob->randomitems);
870 esrv_send_inventory (ob, ob); 731 esrv_send_inventory (ob, ob);
871 ob->update_stats (); 732 ob->update_stats ();
872 733
873 /* This moves the player to a different start map, if there 734 /* This moves the player to a different start map, if there
913 ob->stats.hp = ob->stats.maxhp; 774 ob->stats.hp = ob->stats.maxhp;
914 ob->stats.sp = ob->stats.maxsp; 775 ob->stats.sp = ob->stats.maxsp;
915 ob->stats.grace = 0; 776 ob->stats.grace = 0;
916} 777}
917 778
918void 779static void
919flee_player (object *op) 780flee_player (object *op)
920{ 781{
921 int dir, diff; 782 int dir, diff;
922 rv_vector rv; 783 rv_vector rv;
923 784
924 if (op->stats.hp < 0) 785 if (op->stats.hp < 0)
925 { 786 {
926 LOG (llevDebug, "Fleeing player is dead.\n"); 787 LOG (llevDebug, "Fleeing player is dead.\n");
927 CLEAR_FLAG (op, FLAG_SCARED); 788 op->clr_flag (FLAG_SCARED);
928 return; 789 return;
929 } 790 }
930 791
931 if (!op->enemy) 792 if (!op->enemy)
932 { 793 {
933 LOG (llevDebug, "Fleeing player had no enemy.\n"); 794 LOG (llevDebug, "Fleeing player had no enemy.\n");
934 CLEAR_FLAG (op, FLAG_SCARED); 795 op->clr_flag (FLAG_SCARED);
935 return; 796 return;
936 } 797 }
937 798
938 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) 799 if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0))
939 { 800 {
940 op->enemy = NULL; 801 op->enemy = NULL;
941 CLEAR_FLAG (op, FLAG_SCARED); 802 op->clr_flag (FLAG_SCARED);
942 return; 803 return;
943 } 804 }
944 805
945 get_rangevector (op, op->enemy, &rv, 0); 806 get_rangevector (op, op->enemy, &rv, 0);
946 807
947 dir = absdir (4 + rv.direction); 808 dir = absdir (4 + rv.direction);
948 for (diff = 0; diff < 3; diff++) 809 for (diff = 0; diff < 3; diff++)
949 { 810 {
950 int m = 1 - rndm (2) * 2; 811 int m = 1 - rndm (2) * 2;
951 812
952 if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) 813 if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m))))
953 return; 814 return;
954 } 815 }
955 816
956 /* Cornered, get rid of scared */ 817 /* Cornered, get rid of scared */
957 CLEAR_FLAG (op, FLAG_SCARED); 818 op->clr_flag (FLAG_SCARED);
958 op->enemy = NULL; 819 op->enemy = NULL;
959} 820}
960 821
961/* check_pick sees if there is stuff to be picked up/picks up stuff. 822/* 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 823 * It returns 1 if the player should keep on moving, 0 if he should
967{ 828{
968 object *tmp, *next; 829 object *tmp, *next;
969 int stop = 0; 830 int stop = 0;
970 int wvratio; 831 int wvratio;
971 832
972 /* if you're flying, you cna't pick up anything */ 833 /* if you're flying, you can't pick up anything */
973 if (op->move_type & MOVE_FLYING) 834 if (op->move_type & MOVE_FLYING)
974 return 1; 835 return 1;
975 836
976 next = op->below; 837 next = op->below;
977 838
978 int cnt = MAX_ITEM_PER_DROP; 839 int cnt = MAX_ITEM_PER_ACTION;
979#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) 840#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
980 841
981 /* loop while there are items on the floor that are not marked as 842 /* loop while there are items on the floor that are not marked as
982 * destroyed */ 843 * destroyed */
983 while (next && !next->destroyed ()) 844 while (next && !next->destroyed ())
1009 if (op->contr->mode & PU_DEBUG) 870 if (op->contr->mode & PU_DEBUG)
1010 { 871 {
1011 /* some debugging code to figure out item information */ 872 /* some debugging code to figure out item information */
1012 const char *str = tmp->name 873 const char *str = tmp->name
1013 ? format ("item name: %s item type: %d weight/value: %d", 874 ? 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)))) 875 &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", 876 : 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)))); 877 &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
1017 878
1018 new_draw_info (NDI_UNIQUE, 0, op, str); 879 new_draw_info (NDI_UNIQUE, 0, op, str);
1019 } 880 }
1020 881
1021 if (op->contr->mode & PU_INHIBIT) 882 if (op->contr->mode & PU_INHIBIT)
1054 * fighting */ 915 * fighting */
1055 if (op->contr->mode & PU_INHIBIT) 916 if (op->contr->mode & PU_INHIBIT)
1056 return 1; 917 return 1;
1057 918
1058 /* prevent us from turning into auto-thieves :) */ 919 /* prevent us from turning into auto-thieves :) */
1059 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 920 if (tmp->flag [FLAG_UNPAID])
1060 continue; 921 continue;
1061 922
1062 /* ignore known cursed objects */ 923 /* ignore known cursed objects */
1063 if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) 924 if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED)
1064 continue; 925 continue;
1065 926
1066 /* all food and drink if desired */ 927 /* all food and drink if desired */
1067 /* question: don't pick up known-poisonous stuff? */ 928 /* question: don't pick up known-poisonous stuff? */
1068 if (op->contr->mode & PU_FOOD) 929 if (op->contr->mode & PU_FOOD)
1071 CHK_PICK_PICKUP; 932 CHK_PICK_PICKUP;
1072 continue; 933 continue;
1073 } 934 }
1074 935
1075 if (op->contr->mode & PU_DRINK) 936 if (op->contr->mode & PU_DRINK)
1076 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 937 if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED]))
1077 { 938 {
1078 CHK_PICK_PICKUP; 939 CHK_PICK_PICKUP;
1079 continue; 940 continue;
1080 } 941 }
1081 942
1108 continue; 969 continue;
1109 } 970 }
1110 971
1111 /* wands/staves/rods/horns */ 972 /* wands/staves/rods/horns */
1112 if (op->contr->mode & PU_MAGIC_DEVICE) 973 if (op->contr->mode & PU_MAGIC_DEVICE)
1113 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 974 if (tmp->type == WAND
975 || tmp->type == ROD
976 || tmp->type == HORN
977 || tmp->type == POWER_CRYSTAL)
1114 { 978 {
1115 CHK_PICK_PICKUP; 979 CHK_PICK_PICKUP;
1116 continue; 980 continue;
1117 } 981 }
1118 982
1119 /* pick up all magical items */ 983 /* pick up all magical items */
1120 if (op->contr->mode & PU_MAGICAL) 984 if (op->contr->mode & PU_MAGICAL)
1121 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 985 if (tmp->flag [FLAG_KNOWN_MAGICAL]
986 && !tmp->flag [FLAG_KNOWN_CURSED])
1122 { 987 {
1123 CHK_PICK_PICKUP; 988 CHK_PICK_PICKUP;
1124 continue; 989 continue;
1125 } 990 }
1126 991
1133 } 998 }
1134 } 999 }
1135 1000
1136 /* rings & amulets - talismans seems to be typed AMULET */ 1001 /* rings & amulets - talismans seems to be typed AMULET */
1137 if (op->contr->mode & PU_JEWELS) 1002 if (op->contr->mode & PU_JEWELS)
1138 if (tmp->type == RING || tmp->type == AMULET) 1003 if (tmp->type == RING
1004 || tmp->type == AMULET
1005 || tmp->type == GIRDLE
1006 || tmp->type == SKILL_TOOL)
1139 { 1007 {
1140 CHK_PICK_PICKUP; 1008 CHK_PICK_PICKUP;
1141 continue; 1009 continue;
1142 } 1010 }
1143 1011
1192 CHK_PICK_PICKUP; 1060 CHK_PICK_PICKUP;
1193 continue; 1061 continue;
1194 } 1062 }
1195 1063
1196 if (op->contr->mode & PU_GLOVES) 1064 if (op->contr->mode & PU_GLOVES)
1197 if (tmp->type == GLOVES) 1065 if (tmp->type == GLOVES || tmp->type == BRACERS)
1198 { 1066 {
1199 CHK_PICK_PICKUP; 1067 CHK_PICK_PICKUP;
1200 continue; 1068 continue;
1201 } 1069 }
1202 1070
1207 continue; 1075 continue;
1208 } 1076 }
1209 1077
1210 /* hoping to catch throwing daggers here */ 1078 /* hoping to catch throwing daggers here */
1211 if (op->contr->mode & PU_MISSILEWEAPON) 1079 if (op->contr->mode & PU_MISSILEWEAPON)
1212 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1080 if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN])
1213 { 1081 {
1214 CHK_PICK_PICKUP; 1082 CHK_PICK_PICKUP;
1215 continue; 1083 continue;
1216 } 1084 }
1217 1085
1252 fprintf (stderr, "%s", tmp->name); 1120 fprintf (stderr, "%s", tmp->name);
1253 } 1121 }
1254 else 1122 else
1255 fprintf (stderr, "%s", tmp->arch->archname); 1123 fprintf (stderr, "%s", tmp->arch->archname);
1256 fprintf (stderr, ",%d] = ", tmp->type); 1124 fprintf (stderr, ",%d] = ", tmp->type);
1257 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); 1125 fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1))));
1258#endif 1126#endif
1259 CHK_PICK_PICKUP; 1127 CHK_PICK_PICKUP;
1260 continue; 1128 continue;
1261 } 1129 }
1262 } /* the new pickup model */ 1130 } /* the new pickup model */
1263 } 1131 }
1264 1132
1265 return !stop; 1133 return !stop;
1266} 1134}
1267 1135
1136/* routine for both players and monsters. We call this when
1137 * there is a possibility for our action distrubing our hiding
1138 * place or invisiblity spell. Artefact invisiblity causes
1139 * "noise" instead. If we arent invisible to begin with, we
1140 * return 0.
1141 */
1142static int
1143action_makes_visible (object *op)
1144{
1145 if (op->invisible && op->flag [FLAG_ALIVE])
1146 {
1147 if (op->flag [FLAG_MAKE_INVIS])
1148 {
1149 // artefact invisibility is permanent, but we still make noise
1150 // this is important for game-balance.
1151 if (op->contr)
1152 op->make_noise ();
1153
1154 return 0;
1155 }
1156
1157 if (op->contr && op->contr->tmp_invis == 0)
1158 return 0;
1159
1160 /* If monsters, they should become visible */
1161 if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis))
1162 {
1163 new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible");
1164 return 1;
1165 }
1166 }
1167
1168 return 0;
1169}
1170
1268/* 1171/*
1269 * Find an arrow in the inventory and after that 1172 * Find an arrow in the inventory and after that
1270 * in the right type container (quiver). Pointer to the 1173 * in the right type container (quiver). Pointer to the
1271 * found object is returned. 1174 * found object is returned.
1272 */ 1175 */
1273object * 1176static object *
1274find_arrow (object *op, const char *type) 1177find_arrow (object *op, const char *type)
1275{ 1178{
1276 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1179 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1277 if (tmp->type == ARROW && !strcmp (&tmp->race, type)) 1180 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1278 return splay (tmp); 1181 return splay (tmp);
1279 1182
1280 for (object *tmp = op->inv; tmp; tmp = tmp->below) 1183 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1281 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) 1184 if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type))
1282 if (object *arrow = find_arrow (tmp, type)) 1185 if (object *arrow = find_arrow (tmp, type))
1283 { 1186 {
1284 splay (tmp); 1187 splay (tmp);
1285 return arrow; 1188 return arrow;
1286 } 1189 }
1292 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1195 * 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 1196 * 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 1197 * 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. 1198 * the hall. Failing that it does it's best to pick the highest plus arrow.
1296 */ 1199 */
1297object * 1200static object *
1298find_better_arrow (object *op, object *target, shstr_cmp type, int *better) 1201find_better_arrow (object *op, object *target, shstr_cmp type, int *better)
1299{ 1202{
1300 object *tmp = NULL, *arrow, *ntmp; 1203 object *tmp = NULL, *arrow, *ntmp;
1301 int attacknum, attacktype, betterby = 0, i; 1204 int attacknum, attacktype, betterby = 0, i;
1302 1205
1303 if (!type) 1206 if (!type)
1304 return NULL; 1207 return NULL;
1305 1208
1306 for (arrow = op->inv; arrow; arrow = arrow->below) 1209 for (arrow = op->inv; arrow; arrow = arrow->below)
1307 { 1210 {
1308 if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) 1211 if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED])
1309 { 1212 {
1310 i = 0; 1213 i = 0;
1311 ntmp = find_better_arrow (arrow, target, type, &i); 1214 ntmp = find_better_arrow (arrow, target, type, &i);
1312 1215
1313 if (i > betterby) 1216 if (i > betterby)
1371 * find_better_arrow to find a decent arrow to use. 1274 * find_better_arrow to find a decent arrow to use.
1372 * op = the shooter 1275 * op = the shooter
1373 * type = bow->race 1276 * type = bow->race
1374 * dir = fire direction 1277 * dir = fire direction
1375 */ 1278 */
1376object * 1279static object *
1377pick_arrow_target (object *op, shstr_cmp type, int dir) 1280pick_arrow_target (object *op, shstr_cmp type, int dir)
1378{ 1281{
1379 object *tmp = NULL; 1282 object *tmp = NULL;
1380 maptile *m; 1283 maptile *m;
1381 int i, mflags, found, number; 1284 int i, mflags, found, number;
1414 break; 1317 break;
1415 } 1318 }
1416 1319
1417 if (mflags & P_IS_ALIVE) 1320 if (mflags & P_IS_ALIVE)
1418 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 1321 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1419 if (QUERY_FLAG (tmp, FLAG_ALIVE)) 1322 if (tmp->flag [FLAG_ALIVE])
1420 break; 1323 break;
1421 } 1324 }
1422 1325
1423 if (!tmp) 1326 if (!tmp)
1424 return find_arrow (op, type); 1327 return find_arrow (op, type);
1485 { 1388 {
1486 if (op->type == PLAYER) 1389 if (op->type == PLAYER)
1487 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1390 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 */ 1391 /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
1489 else 1392 else
1490 CLEAR_FLAG (op, FLAG_READY_BOW); 1393 op->clr_flag (FLAG_READY_BOW);
1491 1394
1492 return 0; 1395 return 0;
1493 } 1396 }
1494 } 1397 }
1495 1398
1596 * but monsters can't. Putting that code here 1499 * but monsters can't. Putting that code here
1597 * makes the fire_bow code much cleaner. 1500 * makes the fire_bow code much cleaner.
1598 * this function should only be called if 'op' is a player, 1501 * this function should only be called if 'op' is a player,
1599 * hence the function name. 1502 * hence the function name.
1600 */ 1503 */
1601int 1504static int
1602player_fire_bow (object *op, int dir) 1505player_fire_bow (object *op, int dir)
1603{ 1506{
1604 int ret; 1507 int ret;
1605 1508
1606 if (op->contr->bowtype == bow_bestarrow) 1509 if (op->contr->bowtype == bow_bestarrow)
1634} 1537}
1635 1538
1636/* Fires a misc (wand/rod/horn) object in 'dir'. 1539/* Fires a misc (wand/rod/horn) object in 'dir'.
1637 * Broken apart from 'fire' to keep it more readable. 1540 * Broken apart from 'fire' to keep it more readable.
1638 */ 1541 */
1639void 1542static void
1640fire_misc_object (object *op, int dir) 1543fire_misc_object (object *op, int dir)
1641{ 1544{
1642 object *item = op->contr->ranged_ob; 1545 object *item = op->contr->ranged_ob;
1643 1546
1644 if (!item) 1547 if (!item)
1651 { 1554 {
1652 LOG (llevError, "Object %s lacks a spell\n", &item->name); 1555 LOG (llevError, "Object %s lacks a spell\n", &item->name);
1653 return; 1556 return;
1654 } 1557 }
1655 1558
1656 if (!op->change_weapon (item)) 1559 if (!op->apply (item))
1657 return; 1560 return;
1658 1561
1659 if (item->type == WAND) 1562 if (item->type == WAND)
1660 { 1563 {
1661 if (item->stats.food <= 0) 1564 if (item->stats.food <= 0)
1666 return; 1569 return;
1667 } 1570 }
1668 } 1571 }
1669 else if (item->type == ROD || item->type == HORN) 1572 else if (item->type == ROD || item->type == HORN)
1670 { 1573 {
1671 sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); 1574 sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace);
1672 1575
1673 // using the maximum of the rods charge allows at least one spell cast 1576 // using the maximum of the rods charge allows at least one spell cast
1674 // for a rod or horn, this fixes some broken rods. 1577 // for a rod or horn, this fixes some broken rods.
1675 if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) 1578 if (item->stats.hp < min (spell_sp, item->stats.maxhp))
1676 { 1579 {
1677 op->contr->play_sound (sound_find ("wand_poof")); 1580 op->contr->play_sound (sound_find ("wand_poof"));
1678 1581
1679 if (item->type == ROD) 1582 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)); 1583 new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0));
1695 { 1598 {
1696 object *tmp; 1599 object *tmp;
1697 1600
1698 if (item->arch) 1601 if (item->arch)
1699 { 1602 {
1700 CLEAR_FLAG (item, FLAG_ANIMATE); 1603 item->clr_flag (FLAG_ANIMATE);
1701 item->face = item->arch->face; 1604 item->face = item->arch->face;
1702 item->set_speed (0); 1605 item->set_speed (0);
1703 } 1606 }
1704 1607
1705 if (object *pl = item->visible_to ()) 1608 if (object *pl = item->visible_to ())
1712} 1615}
1713 1616
1714/* Received a fire command for the player - go and do it. 1617/* Received a fire command for the player - go and do it.
1715 */ 1618 */
1716bool 1619bool
1717fire (object *op, int dir) 1620fire (object *who, int dir)
1718{ 1621{
1719 int spellcost = 0; 1622 int spellcost = 0;
1720 1623
1721 player *pl = op->contr; 1624 player *pl = who->contr;
1722 1625
1723 if (pl->golem) 1626 if (pl->golem)
1724 { 1627 {
1725 control_golem (op->contr->golem, dir); 1628 control_golem (who->contr->golem, dir);
1726 return false; 1629 return false;
1727 } 1630 }
1728 1631
1729 object *ob = pl->ranged_ob; 1632 object *ob = pl->ranged_ob;
1730 1633
1731 if (!ob) 1634 if (!ob)
1732 return false; 1635 return false;
1733 1636
1734 if (op->speed_left > 0.f) 1637 if (who->speed_left > 0.f)
1735 --op->speed_left; 1638 --who->speed_left;
1736 else 1639 else
1737 return false; 1640 return false;
1738 1641
1739 if (!op->change_weapon (ob)) 1642 if (!who->apply (ob))
1740 return false; 1643 return false;
1741 1644
1742 /* check for loss of invisiblity/hide */ 1645 /* check for loss of invisiblity/hide */
1743 if (action_makes_visible (op)) 1646 if (action_makes_visible (who))
1744 make_visible (op); 1647 make_visible (who);
1745 1648
1746 switch (ob->type) 1649 switch (ob->type)
1747 { 1650 {
1748 case BOW: 1651 case BOW:
1749 player_fire_bow (op, dir); 1652 player_fire_bow (who, dir);
1750 break; 1653 break;
1751 1654
1752 case SPELL: 1655 case SPELL:
1753 spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); 1656 spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0);
1754 break; 1657 break;
1755 1658
1756 case BUILDER: 1659 case BUILDER:
1757 apply_map_builder (op, dir); 1660 apply_map_builder (who, dir);
1758 break; 1661 break;
1759 1662
1760 case SKILL: 1663 case SKILL:
1761 do_skill (op, op, ob, dir, 0); 1664 do_skill (who, who, ob, dir, 0);
1762 break; 1665 break;
1763 1666
1667 case RANGED:
1668 do_skill (who, ob, who->chosen_skill, dir, 0);
1669 break;
1670
1764 default: 1671 default:
1765 fire_misc_object (op, dir); 1672 fire_misc_object (who, dir);
1766 break; 1673 break;
1767 } 1674 }
1768 1675
1769 return true; 1676 return true;
1770} 1677}
1771 1678
1772/* find_key 1679static 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) 1680find_key_ (object *pl, object *container, object *door)
1784{ 1681{
1785 object *tmp, *key; 1682 object *tmp, *key;
1786 1683
1787 /* Should not happen, but sanity checking is never bad */ 1684 /* Should not happen, but sanity checking is never bad */
1788 if (!container->inv) 1685 if (!container->inv)
1809 if (!tmp) 1706 if (!tmp)
1810 { 1707 {
1811 for (tmp = container->inv; tmp; tmp = tmp->below) 1708 for (tmp = container->inv; tmp; tmp = tmp->below)
1812 /* No reason to search empty containers */ 1709 /* No reason to search empty containers */
1813 if (tmp->type == CONTAINER && tmp->inv) 1710 if (tmp->type == CONTAINER && tmp->inv)
1814 if ((key = find_key (pl, tmp, door))) 1711 if ((key = find_key_ (pl, tmp, door)))
1815 return key; 1712 return key;
1816 1713
1817 if (!tmp) 1714 if (!tmp)
1818 return 0; 1715 return 0;
1819 } 1716 }
1838 * inv must have been an container and must have been active. 1735 * inv must have been an container and must have been active.
1839 * 1736 *
1840 * Change the color so that the message doesn't disappear with 1737 * Change the color so that the message doesn't disappear with
1841 * all the others. 1738 * all the others.
1842 */ 1739 */
1843 if (pl->contr->usekeys == key_inventory || 1740 if (pl->contr->usekeys == key_inventory
1844 !QUERY_FLAG (container, FLAG_APPLIED) || 1741 || !container->flag [FLAG_APPLIED]
1845 (pl->contr->usekeys == keyrings && container->race != shstr_keys)) 1742 || (pl->contr->usekeys == keyrings && container->race != shstr_keys))
1846 { 1743 {
1847 new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, 1744 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)); 1745 "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container));
1849 return NULL; 1746 return NULL;
1850 } 1747 }
1851 } 1748 }
1852 1749
1853 return tmp; 1750 return tmp;
1751}
1752
1753/* find_key
1754 * We try to find a key for the door as passed. If we find a key
1755 * and successfully use it, we return the key, otherwise NULL
1756 * This function merges both normal and locked door, since the logic
1757 * for both is the same - just the specific key is different.
1758 * pl is the player,
1759 * inv is the objects inventory to searched
1760 * door is the door we are trying to match against.
1761 * This function can be called recursively to search containers.
1762 */
1763object *
1764find_key (object *pl, object *container, object *door)
1765{
1766 if (door->slaying && is_match_expr (door->slaying))
1767 {
1768 // for match expressions, we try to find the key by applying the match
1769 // to the op itself, which is supposed to find the "key", instead
1770 // of searching through containers ourselves.
1771
1772 return match_one (door->slaying, container, door, pl, pl);
1773 }
1774 else
1775 return find_key_ (pl, container, door);
1854} 1776}
1855 1777
1856/* moved door processing out of move_player_attack. 1778/* moved door processing out of move_player_attack.
1857 * returns 1 if player has opened the door with a key 1779 * returns 1 if player has opened the door with a key
1858 * such that the caller should not do anything more, 1780 * such that the caller should not do anything more,
1908 * going to try and move (not fire weapons). 1830 * going to try and move (not fire weapons).
1909 */ 1831 */
1910bool 1832bool
1911move_player_attack (object *op, int dir) 1833move_player_attack (object *op, int dir)
1912{ 1834{
1913 if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) 1835 if (!op->contr->braced && op->speed_left > 0.f && op->move (dir))
1914 { 1836 {
1915 --op->speed_left; 1837 --op->speed_left;
1916 return true; 1838 return true;
1917 } 1839 }
1918 1840
1919 int on_battleground;
1920
1921 sint16 nx = freearr_x[dir] + op->x; 1841 sint16 nx = freearr_x[dir] + op->x;
1922 sint16 ny = freearr_y[dir] + op->y; 1842 sint16 ny = freearr_y[dir] + op->y;
1923
1924 on_battleground = op_on_battleground (op, 0, 0);
1925 1843
1926 if (out_of_map (op->map, nx, ny)) 1844 if (out_of_map (op->map, nx, ny))
1927 return false; 1845 return false;
1928 1846
1929 /* If braced, or can't move to the square, and it is not out of the 1847 /* If braced, or can't move to the square, and it is not out of the
1979 */ 1897 */
1980 if (op->type == PLAYER 1898 if (op->type == PLAYER
1981 && ((mon->owner && mon->owner->contr 1899 && ((mon->owner && mon->owner->contr
1982 && same_party (mon->owner->contr->party, op->contr->party)) 1900 && same_party (mon->owner->contr->party, op->contr->party))
1983 || mon->owner == op) 1901 || mon->owner == op)
1984 && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) 1902 && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]))
1985 { 1903 {
1986 /* If we're braced, we don't want to switch places with it */ 1904 /* If we're braced, we don't want to switch places with it */
1987 if (op->contr->braced) 1905 if (op->contr->braced)
1988 return false; 1906 return false;
1989 1907
2000 return true; 1918 return true;
2001 } 1919 }
2002 else 1920 else
2003 return false; 1921 return false;
2004 } 1922 }
1923
1924 bool on_battleground = op_on_battleground (op, 0, 0);
2005 1925
2006 /* in certain circumstances, you shouldn't attack friendly 1926 /* in certain circumstances, you shouldn't attack friendly
2007 * creatures. Note that if you are braced, you can't push 1927 * creatures. Note that if you are braced, you can't push
2008 * someone, but put it inside this loop so that you won't 1928 * someone, but put it inside this loop so that you won't
2009 * attack them either. 1929 * attack them either.
2010 */ 1930 */
2011 if ((mon->type == PLAYER || mon->enemy != op) 1931 if ((mon->type == PLAYER || mon->enemy != op)
2012 && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) 1932 && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])
2013 && ((op->contr->peaceful 1933 && ((op->contr->peaceful
2014 || (mon->type == PLAYER && mon->contr->peaceful)) 1934 || (mon->type == PLAYER && mon->contr->peaceful))
2015 && !on_battleground)) 1935 && !on_battleground))
2016 { 1936 {
2017 if (op->speed_left > 0.f) 1937 if (op->speed_left > 0.f)
2033 } 1953 }
2034 } 1954 }
2035 /* If the object is a boulder or other rollable object, then 1955 /* 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. 1956 * roll it if not braced. You can't roll it if you are braced.
2037 */ 1957 */
2038 else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) 1958 else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced))
2039 { 1959 {
2040 if (op->speed_left > 0.f) 1960 if (op->speed_left > 0.f)
2041 { 1961 {
2042 --op->speed_left; 1962 --op->speed_left;
2043 1963
2052 * Way it works is like this: First, it must have some hit points 1972 * 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: 1973 * 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 1974 * 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. 1975 * that party_number -1 is no party, so attacks can still happen.
2056 */ 1976 */
2057 else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && 1977 else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] &&
2058 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) 1978 ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party)))
2059 { 1979 {
2060 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) 1980 if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS])
2061 { 1981 {
2062 --op->contr->weapon_sp_left; 1982 --op->contr->weapon_sp_left;
2074} 1994}
2075 1995
2076bool 1996bool
2077move_player (object *op, int dir) 1997move_player (object *op, int dir)
2078{ 1998{
2079 int pick;
2080
2081 if (!op->map || op->map->in_memory != MAP_ACTIVE) 1999 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2082 return 0; 2000 return 0;
2083 2001
2084 /* Sanity check: make sure dir is valid */ 2002 /* Sanity check: make sure dir is valid */
2085 if ((dir < 0) || (dir >= 9)) 2003 if (dir < 0 || dir > 8)
2086 { 2004 {
2087 LOG (llevError, "move_player: invalid direction %d\n", dir); 2005 LOG (llevError, "move_player: invalid direction %d\n", dir);
2088 return 0; 2006 return 0;
2089 } 2007 }
2090 2008
2091 /* peterm: added following line */ 2009 /* peterm: added following line */
2092 if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) 2010 if (op->flag [FLAG_CONFUSED] && dir)
2093 dir = absdir (dir + rndm (3) + rndm (3) - 2); 2011 dir = absdir (dir + rndm (3) + rndm (3) - 2);
2094 2012
2095 op->facing = dir; 2013 op->facing = dir;
2096 2014
2097 if (op->flag [FLAG_HIDDEN]) 2015 if (op->flag [FLAG_HIDDEN])
2098 do_hidden_move (op); 2016 do_hidden_move (op);
2099 2017
2100 bool retval; 2018 bool retval;
2019 int pick = 0;
2101 2020
2102 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) 2021 if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir)))
2103 retval = RESULT_INT (0); 2022 retval = RESULT_INT (0);
2104 else if (op->contr->fire_on) 2023 else if (op->contr->fire_on)
2105 retval = fire (op, dir); 2024 retval = fire (op, dir);
2136 * players. 2055 * players.
2137 */ 2056 */
2138bool 2057bool
2139handle_newcs_player (object *op) 2058handle_newcs_player (object *op)
2140{ 2059{
2141 if (QUERY_FLAG (op, FLAG_SCARED)) 2060 if (op->flag [FLAG_SCARED])
2142 { 2061 {
2143 if (op->speed_left > 0.f) 2062 if (op->speed_left > 0.f)
2144 { 2063 {
2145 --op->speed_left; 2064 --op->speed_left;
2146 flee_player (op); 2065 flee_player (op);
2162 return move_player (op, op->direction); 2081 return move_player (op, op->direction);
2163 2082
2164 return false; 2083 return false;
2165} 2084}
2166 2085
2167int 2086static int
2168save_life (object *op) 2087save_life (object *op)
2169{ 2088{
2170 if (!QUERY_FLAG (op, FLAG_LIFESAVE)) 2089 if (!op->flag [FLAG_LIFESAVE])
2171 return 0; 2090 return 0;
2172 2091
2173 for (object *tmp = op->inv; tmp; tmp = tmp->below) 2092 for (object *tmp = op->inv; tmp; tmp = tmp->below)
2174 if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) 2093 if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE])
2175 { 2094 {
2176 op->play_sound (sound_find ("ob_evaporate")); 2095 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)); 2096 new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp));
2178 2097
2179 tmp->destroy (); 2098 tmp->destroy ();
2180 CLEAR_FLAG (op, FLAG_LIFESAVE); 2099 op->clr_flag (FLAG_LIFESAVE);
2181 2100
2182 if (op->stats.hp < 0) 2101 if (op->stats.hp < 0)
2183 op->stats.hp = op->stats.maxhp; 2102 op->stats.hp = op->stats.maxhp;
2184 2103
2185 if (op->stats.food < 0) 2104 if (op->stats.food < 0)
2186 op->stats.food = 999; 2105 op->stats.food = MAX_FOOD;
2187 2106
2188 op->update_stats (); 2107 op->update_stats ();
2189 return 1; 2108 return 1;
2190 } 2109 }
2191 2110
2192 LOG (llevError, "Error: LIFESAVE set without applied object.\n"); 2111 LOG (llevError, "Error: LIFESAVE set without applied object.\n");
2193 CLEAR_FLAG (op, FLAG_LIFESAVE); 2112 op->clr_flag (FLAG_LIFESAVE);
2194 enter_player_savebed (op); /* bring him home. */ 2113 enter_player_savebed (op); /* bring him home. */
2195 return 0; 2114 return 0;
2196} 2115}
2197 2116
2198/* This goes throws the inventory and removes unpaid objects, and puts them 2117/* This goes throws the inventory and removes unpaid objects, and puts them
2205{ 2124{
2206 while (op) 2125 while (op)
2207 { 2126 {
2208 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ 2127 object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */
2209 2128
2210 if (QUERY_FLAG (op, FLAG_UNPAID)) 2129 if (op->flag [FLAG_UNPAID])
2211 op->insert_at (env); 2130 op->insert_at (env);
2212 else if (op->inv) 2131 else if (op->inv)
2213 drop_unpaid_items (op->inv, env); 2132 drop_unpaid_items (op->inv, env);
2214 2133
2215 op = next; 2134 op = next;
2219void 2138void
2220object::drop_unpaid_items () 2139object::drop_unpaid_items ()
2221{ 2140{
2222 if (!flag [FLAG_REMOVED]) 2141 if (!flag [FLAG_REMOVED])
2223 ::drop_unpaid_items (inv, this); 2142 ::drop_unpaid_items (inv, this);
2224}
2225
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} 2143}
2262 2144
2263void 2145void
2264do_some_living (object *op) 2146do_some_living (object *op)
2265{ 2147{
2282 * alternate it here for it to work correctly. 2164 * alternate it here for it to work correctly.
2283 */ 2165 */
2284 if (pticks & 2) 2166 if (pticks & 2)
2285 op->invisible--; 2167 op->invisible--;
2286 } 2168 }
2287 else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) 2169 else if (op->invisible && !(op->flag [FLAG_MAKE_INVIS]))
2288 { 2170 {
2289 if (!op->invisible--) 2171 if (!op->invisible--)
2290 { 2172 {
2291 make_visible (op); 2173 make_visible (op);
2292 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); 2174 new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out.");
2359 if (op->stats.sp < op->stats.maxsp) 2241 if (op->stats.sp < op->stats.maxsp)
2360 { 2242 {
2361 op->stats.sp++; 2243 op->stats.sp++;
2362 2244
2363 /* dms do not consume food */ 2245 /* dms do not consume food */
2364 if (!QUERY_FLAG (op, FLAG_WIZ)) 2246 if (!op->flag [FLAG_WIZ])
2365 { 2247 {
2366 op->stats.food--; 2248 op->stats.food--;
2367 2249
2368 if (op->contr->digestion < 0) 2250 if (op->contr->digestion < 0)
2369 op->stats.food += op->contr->digestion; 2251 op->stats.food += op->contr->digestion;
2403 if (op->stats.hp < op->stats.maxhp) 2285 if (op->stats.hp < op->stats.maxhp)
2404 { 2286 {
2405 op->stats.hp++; 2287 op->stats.hp++;
2406 2288
2407 /* dms do not consume food */ 2289 /* dms do not consume food */
2408 if (!QUERY_FLAG (op, FLAG_WIZ)) 2290 if (!op->flag [FLAG_WIZ])
2409 { 2291 {
2410 op->stats.food--; 2292 op->stats.food--;
2411 2293
2412 if (op->contr->digestion < 0) 2294 if (op->contr->digestion < 0)
2413 op->stats.food += op->contr->digestion; 2295 op->stats.food += op->contr->digestion;
2440 penalty = max (0, -op->contr->digestion); 2322 penalty = max (0, -op->contr->digestion);
2441 2323
2442 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); 2324 op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1);
2443 2325
2444 /* dms do not consume food */ 2326 /* dms do not consume food */
2445 if (!QUERY_FLAG (op, FLAG_WIZ)) 2327 if (!op->flag [FLAG_WIZ])
2446 op->stats.food--; 2328 op->stats.food--;
2447 } 2329 }
2448 2330
2449 if (op->stats.food < 0 && op->stats.hp >= 0) 2331 if (op->stats.food < 0 && op->stats.hp >= 0)
2450 { 2332 {
2451 object *flesh = 0; 2333 object *flesh = 0;
2452 2334
2453 for_inv_removable (op, tmp) 2335 for_inv_removable (op, tmp)
2454 { 2336 {
2455 if (QUERY_FLAG (tmp, FLAG_UNPAID)) 2337 if (tmp->flag [FLAG_UNPAID])
2456 continue; 2338 continue;
2457 2339
2458 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) 2340 if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON)
2459 { 2341 {
2460 op->statusmsg ("You blindly grab for a bite of food. " 2342 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.>"); 2343 "H<To prevent you from starving, you ate some random item from your backpack.>");
2462 manual_apply (op, tmp, 0); 2344 op->apply (tmp);
2463 2345
2464 if (op->stats.food >= 0 || op->stats.hp < 0) 2346 if (op->stats.food >= 0 || op->stats.hp < 0)
2465 break; 2347 break;
2466 } 2348 }
2467 else if (tmp->type == FLESH) 2349 else if (tmp->type == FLESH)
2473 */ 2355 */
2474 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) 2356 if (op->stats.food < 0 && op->stats.hp >= 0 && flesh)
2475 { 2357 {
2476 op->statusmsg ("You blindly grab for a bite of food. " 2358 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.>"); 2359 "H<To prevent you from starving, you ate some random item from your backpack.>");
2478 manual_apply (op, flesh, 0); 2360 op->apply (flesh);
2479 } 2361 }
2480 2362
2481 // If player is still starving, alert him! 2363 // If player is still starving, alert him!
2482 if (op->stats.food < 0) 2364 if (op->stats.food < 0)
2483 op->failmsg ("You are starving! " 2365 op->failmsg ("You are starving! "
2495 op->contr->killer->destroy (); 2377 op->contr->killer->destroy ();
2496 } 2378 }
2497 } 2379 }
2498 2380
2499 /* killer should be set here already */ 2381 /* killer should be set here already */
2500 if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) 2382 if (op->stats.hp < 0 && !op->flag [FLAG_WIZ])
2501 kill_player (op); 2383 kill_player (op);
2502 } 2384 }
2503} 2385}
2504 2386
2505/* If the player should die (lack of hp, food, etc), we call this. 2387/* If the player should die (lack of hp, food, etc), we call this.
2520 return; 2402 return;
2521 2403
2522 dynbuf_text deathtab; 2404 dynbuf_text deathtab;
2523 2405
2524 /* restore player */ 2406 /* restore player */
2525 at = archetype::find ("poisoning"); 2407 at = archetype::find (shstr_poisoning);
2526 if (object *tmp = present_arch_in_ob (at, op)) 2408 if (object *tmp = present_arch_in_ob (at, op))
2527 { 2409 {
2528 tmp->destroy (); 2410 tmp->destroy ();
2529 deathtab << "Your body feels cleansed...\r"; 2411 deathtab << "Your body feels cleansed...\r";
2530 } 2412 }
2531 2413
2532 at = archetype::find ("confusion"); 2414 at = archetype::find (shstr_confusion);
2533 if (object *tmp = present_arch_in_ob (at, op)) 2415 if (object *tmp = present_arch_in_ob (at, op))
2534 { 2416 {
2535 tmp->destroy (); 2417 tmp->destroy ();
2536 deathtab << "Your mind feels clearer...\r"; 2418 deathtab << "Your mind feels clearer...\r";
2537 } 2419 }
2539 cure_disease (op, 0, 0); /* remove any disease */ 2421 cure_disease (op, 0, 0); /* remove any disease */
2540 2422
2541 max_it (op->stats.hp , op->stats.maxhp); 2423 max_it (op->stats.hp , op->stats.maxhp);
2542 max_it (op->stats.sp , op->stats.maxsp); 2424 max_it (op->stats.sp , op->stats.maxsp);
2543 max_it (op->stats.grace, op->stats.maxgrace); 2425 max_it (op->stats.grace, op->stats.maxgrace);
2544
2545 if (op->stats.food <= 0) 2426 max_it (op->stats.food , 200);
2546 op->stats.food = 999;
2547 2427
2548 // remove all spell effects that are active 2428 // remove all spell effects that are active
2549 // to avoid long-term effects such as word-of-recall 2429 // to avoid long-term effects such as word-of-recall
2550 for (object *item = op->inv; item; ) 2430 for (object *item = op->inv; item; )
2551 { 2431 {
2564 if (op_on_battleground (op, &x, &y)) 2444 if (op_on_battleground (op, &x, &y))
2565 { 2445 {
2566 deathtab << "You almost died in combat, but local medics have saved your life...\r"; 2446 deathtab << "You almost died in combat, but local medics have saved your life...\r";
2567 2447
2568 /* create a bodypart-trophy to make the winner happy */ 2448 /* create a bodypart-trophy to make the winner happy */
2569 if (object *tmp = arch_to_object (archetype::find ("finger"))) 2449 object *tmp = archetype::find (shstr_finger)->instance ();
2570 { 2450
2571 tmp->name = format ("%s's finger" , &op->name); 2451 tmp->name = format ("%s's finger" , &op->name);
2572 tmp->name_pl = format ("%s's fingers", &op->name); 2452 tmp->name_pl = format ("%s's fingers", &op->name);
2573 tmp->msg = format ( 2453 tmp->msg = format (
2574 "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", 2454 "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, 2455 &op->name, op->contr->title,
2576 (int)op->level, 2456 (int)op->level,
2577 op->contr->killer_name () 2457 op->contr->killer_name ()
2578 ); 2458 );
2579 tmp->value = 0, tmp->type = 0; 2459 tmp->value = 0, tmp->type = 0;
2580 tmp->materialname = "organics"; 2460 tmp->material = name_to_material (shstr_organic);
2581 tmp->insert_at (op, tmp); 2461 tmp->insert_at (op, tmp);
2582 }
2583 2462
2584 /* teleport defeated player to new destination */ 2463 /* teleport defeated player to new destination */
2585 transfer_ob (op, x, y, 0, NULL); 2464 transfer_ob (op, x, y, 0, NULL);
2586 op->contr->braced = 0; 2465 op->contr->braced = 0;
2587 2466
2649 lost_a_stat = 1; 2528 lost_a_stat = 1;
2650 } 2529 }
2651 else 2530 else
2652 { 2531 {
2653 /* deplete a stat */ 2532 /* deplete a stat */
2654 archetype *deparch = archetype::find ("depletion"); 2533 archetype *deparch = archetype::find (shstr_depletion);
2655 object *dep; 2534 object *dep;
2656 2535
2657 dep = present_arch_in_ob (deparch, op); 2536 dep = present_arch_in_ob (deparch, op);
2658 if (!dep) 2537 if (!dep)
2659 { 2538 {
2660 dep = arch_to_object (deparch); 2539 dep = deparch->instance ();
2661 insert_ob_in_ob (dep, op); 2540 insert_ob_in_ob (dep, op);
2662 } 2541 }
2663 lose_this_stat = 1; 2542 lose_this_stat = 1;
2664 if (settings.balanced_stat_loss) 2543 if (settings.balanced_stat_loss)
2665 { 2544 {
2703 * difference. 2582 * difference.
2704 */ 2583 */
2705 if (this_stat >= -50) 2584 if (this_stat >= -50)
2706 { 2585 {
2707 change_attr_value (&(dep->stats), i, -1); 2586 change_attr_value (&(dep->stats), i, -1);
2708 SET_FLAG (dep, FLAG_APPLIED); 2587 dep->set_flag (FLAG_APPLIED);
2709 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); 2588 new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]);
2710 op->update_stats (); 2589 op->update_stats ();
2711 lost_a_stat = 1; 2590 lost_a_stat = 1;
2712 } 2591 }
2713 } 2592 }
2731#endif 2610#endif
2732 2611
2733 /* Put a gravestone up where the character 'almost' died. List the 2612 /* Put a gravestone up where the character 'almost' died. List the
2734 * exp loss on the stone. 2613 * exp loss on the stone.
2735 */ 2614 */
2736 tmp = arch_to_object (archetype::find ("gravestone")); 2615 tmp = archetype::find (shstr_gravestone)->instance ();
2737 tmp->name = format ("%s's gravestone", &op->name); 2616 tmp->name = format ("%s's gravestone", &op->name);
2738 tmp->name_pl = format ("%s's gravestones", &op->name); 2617 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", 2618 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 ()); 2619 &op->name, op->contr->title, op->contr->killer_name ());
2741 tmp->x = op->x, tmp->y = op->y; 2620 tmp->x = op->x, tmp->y = op->y;
2784 2663
2785 force = get_archetype (FORCE_NAME); 2664 force = get_archetype (FORCE_NAME);
2786 /* 50 ticks should be enough time for the spell to abate */ 2665 /* 50 ticks should be enough time for the spell to abate */
2787 force->speed = 0.1f; 2666 force->speed = 0.1f;
2788 force->speed_left = -5.f; 2667 force->speed_left = -5.f;
2789 SET_FLAG (force, FLAG_APPLIED); 2668 force->set_flag (FLAG_APPLIED);
2790 for (at = 0; at < NROFATTACKS; at++) 2669 for (at = 0; at < NROFATTACKS; at++)
2791 if (will_kill_again & (1 << at)) 2670 if (will_kill_again & (1 << at))
2792 force->resist[at] = 100; 2671 force->resist[at] = 100;
2793 2672
2794 insert_ob_in_ob (force, op); 2673 insert_ob_in_ob (force, op);
2796 } 2675 }
2797 2676
2798 op->contr->infobox (MSG_CHANNEL ("death"), deathtab); 2677 op->contr->infobox (MSG_CHANNEL ("death"), deathtab);
2799} 2678}
2800 2679
2801void 2680static void
2802loot_object (object *op) 2681loot_object (object *op)
2803{ /* Grab and destroy some treasure */ 2682{ /* Grab and destroy some treasure */
2804 object *tmp, *tmp2, *next; 2683 object *tmp, *tmp2, *next;
2805 2684
2806 op->close_container (); /* close open sack first */ 2685 op->close_container (); /* close open sack first */
2816 tmp->x = op->x, tmp->y = op->y; 2695 tmp->x = op->x, tmp->y = op->y;
2817 2696
2818 if (tmp->type == CONTAINER) 2697 if (tmp->type == CONTAINER)
2819 loot_object (tmp); /* empty container to ground */ 2698 loot_object (tmp); /* empty container to ground */
2820 2699
2821 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2700 if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3))))
2822 { 2701 {
2823 if (tmp->nrof > 1) 2702 if (tmp->nrof > 1)
2824 { 2703 {
2825 tmp->decrease (rndm (1, tmp->nrof - 1)); 2704 tmp->decrease (rndm (1, tmp->nrof - 1));
2826 insert_ob_in_map (tmp, op->map, NULL, 0); 2705 insert_ob_in_map (tmp, op->map, NULL, 0);
2837 * fix_weight(): Check recursively the weight of all players, and fix 2716 * fix_weight(): Check recursively the weight of all players, and fix
2838 * what needs to be fixed. Refresh windows and fix speed if anything 2717 * what needs to be fixed. Refresh windows and fix speed if anything
2839 * was changed. 2718 * was changed.
2840 */ 2719 */
2841void 2720void
2842fix_weight (void) 2721fix_weight ()
2843{ 2722{
2844 for_all_players (pl) 2723 for_all_players (pl)
2845 { 2724 {
2846 sint32 old = pl->ob->carrying; 2725 sint32 old = pl->ob->carrying;
2847 2726
2854 } 2733 }
2855 } 2734 }
2856} 2735}
2857 2736
2858void 2737void
2859fix_luck (void) 2738fix_luck ()
2860{ 2739{
2861 for_all_players (pl) 2740 for_all_players (pl)
2862 if (!pl->ob->contr->ns->state) 2741 if (!pl->ob->contr->ns->state)
2863 pl->ob->change_luck (0); 2742 pl->ob->change_luck (0);
2864} 2743}
2916} 2795}
2917 2796
2918int 2797int
2919is_true_undead (object *op) 2798is_true_undead (object *op)
2920{ 2799{
2921 if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) 2800 if (op->arch->flag [FLAG_UNDEAD])
2922 return 1; 2801 return 1;
2923 2802
2924 return 0; 2803 return 0;
2925} 2804}
2926 2805
3024 2903
3025 if (who->type == PLAYER) 2904 if (who->type == PLAYER)
3026 player = 1; 2905 player = 1;
3027 2906
3028 else 2907 else
3029 friendly = QUERY_FLAG (who, FLAG_FRIENDLY); 2908 friendly = who->flag [FLAG_FRIENDLY];
3030 2909
3031 /* search adjacent squares */ 2910 /* search adjacent squares */
3032 for (i = 1; i < 9; i++) 2911 for (i = 1; i < 9; i++)
3033 { 2912 {
3034 x = who->x + freearr_x[i]; 2913 x = who->x + freearr_x[i];
3043 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) 2922 if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y)))
3044 continue; 2923 continue;
3045 2924
3046 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) 2925 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
3047 { 2926 {
3048 if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) 2927 if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE])
3049 return 1; 2928 return 1;
3050 else if (tmp->type == PLAYER) 2929 else if (tmp->type == PLAYER)
3051 { 2930 {
3052 /*don't let a hidden DM prevent you from hiding */ 2931 /*don't let a hidden DM prevent you from hiding */
3053 if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0) 2932 if (!tmp->flag [FLAG_WIZ] || tmp->contr->hidden == 0)
3054 return 1; 2933 return 1;
3055 } 2934 }
3056 } 2935 }
3057 } 2936 }
3058 return 0; 2937 return 0;
3108 } 2987 }
3109 2988
3110 return 0; 2989 return 0;
3111} 2990}
3112 2991
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 2992/* op_on_battleground - checks if the given object op (usually
3149 * a player) is standing on a valid battleground-tile, 2993 * a player) is standing on a valid battleground-tile,
3150 * function returns TRUE/FALSE. If true x, y returns the battleground 2994 * function returns TRUE/FALSE. If true x, y returns the battleground
3151 * -exit-coord. (and if x, y not NULL) 2995 * -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 2996 * 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. 3006 * and the exit-coordinates sp/hp must both be > 0.
3163 * => The intention here is to prevent abuse of the battleground- 3007 * => The intention here is to prevent abuse of the battleground-
3164 * feature (like pickable or hidden battleground tiles). */ 3008 * feature (like pickable or hidden battleground tiles). */
3165 for (object *tmp = op->below; tmp; tmp = tmp->below) 3009 for (object *tmp = op->below; tmp; tmp = tmp->below)
3166 { 3010 {
3167 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 3011 if (tmp->flag [FLAG_IS_FLOOR])
3168 { 3012 {
3169 if (QUERY_FLAG (tmp, FLAG_NO_PICK) 3013 if (tmp->flag [FLAG_NO_PICK]
3170 && tmp->type == BATTLEGROUND 3014 && tmp->type == BATTLEGROUND
3171 && tmp->name == shstr_battleground 3015 && tmp->name == shstr_battleground
3172 && EXIT_X (tmp) && EXIT_Y (tmp)) 3016 && EXIT_X (tmp) && EXIT_Y (tmp))
3173 { 3017 {
3174 /* before we assign the exit, check if this is a teambattle */ 3018 /* before we assign the exit, check if this is a teambattle */
3175 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) 3019 if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp))
3176 {
3177 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) 3020 for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below)
3021 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3178 { 3022 {
3179 if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying)
3180 {
3181 if (x && y) 3023 if (x && y)
3182 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); 3024 *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp);
3183 3025
3184 return 1; 3026 return 1;
3185 }
3186 } 3027 }
3187 }
3188 3028
3189 if (x && y) 3029 if (x && y)
3190 *x = EXIT_X (tmp), *y = EXIT_Y (tmp); 3030 *x = EXIT_X (tmp), *y = EXIT_Y (tmp);
3191 3031
3192 return 1; 3032 return 1;
3330 else 3170 else
3331 j = 1; 3171 j = 1;
3332 strcat (buf, spellpathnames[i]); 3172 strcat (buf, spellpathnames[i]);
3333 } 3173 }
3334 } 3174 }
3175
3335 strcat (buf, "."); 3176 strcat (buf, ".");
3336 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); 3177 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf);
3337 } 3178 }
3338 3179
3339 /* evtl. adding flags: */ 3180 /* evtl. adding flags: */
3340 if (QUERY_FLAG (item, FLAG_XRAYS)) 3181 if (item->flag [FLAG_XRAYS])
3341 SET_FLAG (skin, FLAG_XRAYS); 3182 skin->set_flag (FLAG_XRAYS);
3342 if (QUERY_FLAG (item, FLAG_STEALTH)) 3183 if (item->flag [FLAG_STEALTH])
3343 SET_FLAG (skin, FLAG_STEALTH); 3184 skin->set_flag (FLAG_STEALTH);
3344 if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) 3185 if (item->flag [FLAG_SEE_IN_DARK])
3345 SET_FLAG (skin, FLAG_SEE_IN_DARK); 3186 skin->set_flag (FLAG_SEE_IN_DARK);
3346 3187
3347 /* print message if there is one */ 3188 /* print message if there is one */
3348 if (item->msg != NULL) 3189 if (item->msg != NULL)
3349 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); 3190 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg);
3350 } 3191 }
3351 else 3192 else
3352 { 3193 {
3353 /* generate misc. treasure */ 3194 /* generate misc. treasure */
3354 tmp = arch_to_object (tr->item); 3195 tmp = tr->item->instance ();
3355 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); 3196 new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp));
3356 who->insert (tmp); 3197 who->insert (tmp);
3357 } 3198 }
3358} 3199}
3359 3200
3360/** 3201//-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 3202
3377sint8 3203sint8
3378player::darkness_at (maptile *map, int x, int y) const 3204player::darkness_at (maptile *map, int x, int y) const
3379{ 3205{
3380 if (!ns) 3206 if (!ns)
3407{ 3233{
3408 play_sound (sound_find ("generic_failure")); 3234 play_sound (sound_find ("generic_failure"));
3409 statusmsg (msg, color); 3235 statusmsg (msg, color);
3410} 3236}
3411 3237
3238void
3239object::failmsgf (const char *format, ...)
3240{
3241 if (!contr)
3242 return;
3243
3244 va_list ap;
3245 va_start (ap, format);
3246 contr->failmsg (vformat (format, ap));
3247 va_end (ap);
3248}
3249
3250void
3251player::failmsgf (const char *format, ...)
3252{
3253 va_list ap;
3254 va_start (ap, format);
3255 failmsg (vformat (format, ap));
3256 va_end (ap);
3257}
3258

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines