Crossfire Server, Trunk  R21466
player.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
20 #include "global.h"
21 
22 #include <assert.h>
23 #include <stddef.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #ifndef WIN32 /* ---win32 remove headers */
28 #include <pwd.h>
29 #endif
30 
31 #include "server.h"
32 #include "living.h"
33 #include "object.h"
34 #include "shared/newclient.h"
35 #include "shop.h"
36 #include "skills.h"
37 #include "sounds.h"
38 #include "spells.h"
39 #include "sproto.h"
40 
42 
43 static void kill_player_not_permadeath(object *op);
44 static void kill_player_permadeath(object *op);
45 static int action_makes_visible(object *op);
46 
55 player *find_player(const char *plname) {
56  return find_player_options(plname, 0, NULL);
57 }
58 
66 player *find_player_options(const char *plname, int options, const mapstruct *map) {
67  player *pl;
68  player *found = NULL;
69  size_t namelen = strlen(plname);
70  char name[MAX_BUF];
71 
72  for (pl = first_player; pl != NULL; pl = pl->next) {
73  if ((options & FIND_PLAYER_NO_HIDDEN_DM) && (QUERY_FLAG(pl->ob, FLAG_WIZ) && pl->ob->contr->hidden))
74  continue;
75 
76  if (map != NULL && pl->ob->map != map)
77  continue;
78 
79  if (!(options & FIND_PLAYER_PARTIAL_NAME)) {
80  query_name(pl->ob, name, sizeof(name));
81  if (!strcmp(name, plname))
82  return pl;
83  continue;
84  }
85 
86  if (strlen(pl->ob->name) < namelen)
87  continue;
88 
89  if (!strcmp(pl->ob->name, plname))
90  return pl;
91 
92  if (!strncasecmp(pl->ob->name, plname, namelen)) {
93  if (found)
94  return NULL;
95 
96  found = pl;
97  }
98  }
99  return found;
100 }
101 
110 player *find_player_partial_name(const char *plname) {
111  return find_player_options(plname, FIND_PLAYER_PARTIAL_NAME, NULL);
112 }
113 
120  player *pl;
121 
122  for (pl = first_player; pl != NULL; pl = pl->next) {
123  if (&pl->socket == ns)
124  return pl;
125  }
126  return NULL;
127 }
128 
135 void display_motd(const object *op) {
136  char buf[MAX_BUF];
137  char motd[HUGE_BUF];
138  FILE *fp;
139  size_t size;
140 
141  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.motd);
142  fp = fopen(buf, "r");
143  if (fp == NULL) {
144  return;
145  }
146  motd[0] = '\0';
147  size = 0;
148 
149  while (fgets(buf, MAX_BUF, fp) != NULL) {
150  if (*buf != '#') {
151  safe_strcat(motd, buf, &size, sizeof(motd));
152  }
153  }
154 
156  motd);
157  fclose(fp);
158 }
159 
166 void send_rules(const object *op) {
167  char buf[MAX_BUF];
168  char rules[HUGE_BUF];
169  FILE *fp;
170  size_t size;
171 
172  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.rules);
173  fp = fopen(buf, "r");
174  if (fp == NULL) {
175  return;
176  }
177  rules[0] = '\0';
178  size = 0;
179 
180  while (fgets(buf, MAX_BUF, fp) != NULL) {
181  if (size+strlen(buf) >= HUGE_BUF) {
182  LOG(llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
183  break;
184  }
185 
186  if (*buf != '#') {
187  safe_strcat(rules, buf, &size, sizeof(rules));
188  }
189  }
190 
192  MSG_TYPE_ADMIN_RULES, rules);
193  fclose(fp);
194 }
195 
202 void send_news(const object *op) {
203  char buf[MAX_BUF];
204  char news[HUGE_BUF];
205  char subject[MAX_BUF];
206  FILE *fp;
207  size_t size;
208 
209  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.news);
210  fp = fopen(buf, "r");
211  if (fp == NULL)
212  return;
213  news[0] = '\0';
214  subject[0] = '\0';
215  size = 0;
216  while (fgets(buf, MAX_BUF, fp) != NULL) {
217  if (*buf == '#')
218  continue;
219  if (*buf == '%') { /* send one news */
220  if (size > 0)
223  "%s:\n%s",
224  subject, news); /*send previously read news*/
225  safe_strncpy(subject, buf + 1, sizeof(subject));
226  strip_endline(subject);
227  size = 0;
228  news[0] = '\0';
229  } else {
230  if (size+strlen(buf) >= HUGE_BUF) {
231  LOG(llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF);
232  break;
233  }
234  safe_strcat(news, buf, &size, sizeof(news));
235  }
236  }
237 
240  "%s:\n%s",
241  subject, news);
242  fclose(fp);
243 }
244 
253 int playername_ok(const char *cp) {
254  /* Don't allow - or _ as first character in the name */
255  if (*cp == '-' || *cp == '_')
256  return 0;
257 
258  for (; *cp != '\0'; cp++)
259  if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z'))
260  && *cp != '-'
261  && *cp != '_')
262  return 0;
263  return 1;
264 }
265 
282  object *op = arch_to_object(get_player_archetype(NULL));
283  int i;
284 
285  if (!p) {
286  player *tmp;
287 
288  p = (player *)malloc(sizeof(player));
289  if (p == NULL)
291 
292  /* This adds the player in the linked list. There is extra
293  * complexity here because we want to add the new player at the
294  * end of the list - there is in fact no compelling reason that
295  * that needs to be done except for things like output of
296  * 'who'.
297  */
298  tmp = first_player;
299  while (tmp != NULL && tmp->next != NULL)
300  tmp = tmp->next;
301  if (tmp != NULL)
302  tmp->next = p;
303  else
304  first_player = p;
305 
306  p->next = NULL;
307  /* This only needs to be done on initial creation of player
308  * object. the callers of get_player() will copy over the
309  * socket structure to p->socket, and if this is an existing
310  * player object, that has been done. The call to
311  * roll_stats() below will try to send spell information to
312  * the client - if this is non zero (eg, garbage from not
313  * being cleared), that will cause problems. So just clear
314  * it, and no spell data is sent.
315  */
316  p->socket.monitor_spells = 0;
317  } else {
318  /* Only needed when reusing existing player. */
319  clear_player(p);
320  }
321 
322  /* Clears basically the entire player structure except
323  * for next and socket.
324  */
325  memset((void *)((char *)p+offsetof(player, maplevel)), 0, sizeof(player)-offsetof(player, maplevel));
326 
327  /* There are some elements we want initialized to non zero value -
328  * we deal with that below this point.
329  */
330  p->party = NULL;
333  p->swap_first = -1;
334 
335 #ifdef AUTOSAVE
336  p->last_save_tick = 9999999;
337 #endif
338 
339  strcpy(p->savebed_map, first_map_path); /* Init. respawn position */
340 
341  op->contr = p; /* this aren't yet in archetype */
342  p->ob = op;
343  op->speed_left = 0.5;
344  op->speed = 1.0;
345  op->direction = 5; /* So player faces south */
346  op->stats.wc = 2;
347  op->run_away = 25; /* Then we panic... */
348 
349  roll_stats(op);
351  clear_los(p);
352 
353  p->gen_sp_armour = 10;
354  p->last_speed = -1;
355  p->shoottype = range_none;
356  p->bowtype = bow_normal;
357  p->petmode = pet_normal;
358  p->listening = 10;
359  p->last_weapon_sp = -1;
360  p->peaceful = 1; /* default peaceful */
361  p->do_los = 1;
362  p->no_shout = 0; /* default can shout */
363  p->language = -1; // find default language
364  p->unarmed_skill = NULL;
365  p->ticks_played = 0;
366 
367  strncpy(p->title, op->arch->clone.name, sizeof(p->title)-1);
368  p->title[sizeof(p->title)-1] = '\0';
369  op->race = add_string(op->arch->clone.race);
370 
372 
373  /* we need to clear these to -1 and not zero - otherwise,
374  * if a player quits and starts a new character, we wont
375  * send new values to the client, as things like exp start
376  * at zero.
377  */
378  for (i = 0; i < MAX_SKILLS; i++) {
379  p->last_skill_exp[i] = -1;
380  p->last_skill_ob[i] = NULL;
381  }
382  for (i = 0; i < NROFATTACKS; i++) {
383  p->last_resist[i] = -1;
384  }
385  p->last_stats.exp = -1;
386  p->last_weight = (uint32_t)-1;
387 
388  p->socket.update_look = 0;
389  p->socket.look_position = 0;
390  return p;
391 }
392 
399 void set_first_map(object *op) {
400  strcpy(op->contr->maplevel, first_map_path);
401  op->x = -1;
402  op->y = -1;
404 }
405 
418 static void set_player_socket(player *p, socket_struct *ns) {
419  memcpy(&p->socket, ns, sizeof(socket_struct));
420 
421  /* The memcpy above copies the reference to faces sent. So we need to clear
422  * that pointer in ns, otherwise we get a double free.
423  */
424  ns->faces_sent = NULL;
425 
426  if (p->socket.faces_sent == NULL)
428 
429  /* Needed because the socket we just copied over needs to be cleared.
430  * Note that this can result in a client reset if there is partial data
431  * on the incoming socket.
432  */
434 
435 
436 }
437 
455  player *p;
456 
457  p = get_player(NULL);
458  set_player_socket(p, ns);
459 
461 
462  if (!(flags & ADD_PLAYER_NO_MAP))
463  set_first_map(p->ob);
464 
466 
467  /* In this case, the client is provide all the informatin for the
468  * new character, so just return it. Do not display any messages,
469  * etc
470  */
471  if (flags & ADD_PLAYER_NO_STATS_ROLL)
472  return p;
473 
474  if (flags & ADD_PLAYER_NEW) {
475  roll_again(p->ob);
477  } else {
478  send_rules(p->ob);
479  send_news(p->ob);
480  display_motd(p->ob);
481  get_name(p->ob);
482  }
483  return p;
484 }
485 
497  archetype *start = at;
498 
499  for (;;) {
500  if (at == NULL || at->next == NULL)
501  at = first_archetype;
502  else
503  at = at->next;
504  if (at->clone.type == PLAYER)
505  return at;
506  if (at == start) {
507  LOG(llevError, "No Player archetypes\n");
508  exit(-1);
509  }
510  }
511 }
512 
521 object *get_nearest_player(object *mon) {
522  object *op = NULL;
523  player *pl = NULL;
524  objectlink *ol;
525  unsigned lastdist;
526  rv_vector rv;
527 
528  for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) {
529  /* We should not find free objects on this friendly list, but it
530  * does periodically happen. Given that, lets deal with it.
531  * While unlikely, it is possible the next object on the friendly
532  * list is also free, so encapsulate this in a while loop.
533  */
534  while (QUERY_FLAG(ol->ob, FLAG_FREED) || !QUERY_FLAG(ol->ob, FLAG_FRIENDLY)) {
535  object *tmp = ol->ob;
536 
537  /* Can't do much more other than log the fact, because the object
538  * itself will have been cleared.
539  */
540  LOG(llevDebug, "get_nearest_player: Found free/non friendly object on friendly list\n");
541  ol = ol->next;
543  if (!ol)
544  return op;
545  }
546 
547  /* Remove special check for player from this. First, it looks to cause
548  * some crashes (ol->ob->contr not set properly?), but secondly, a more
549  * complicated method of state checking would be needed in any case -
550  * as it was, a clever player could type quit, and the function would
551  * skip them over while waiting for confirmation. Remove
552  * on_same_map check, as monster_can_detect_enemy() also does this
553  */
554  if (!monster_can_detect_enemy(mon, ol->ob, &rv))
555  continue;
556 
557  if (lastdist > rv.distance) {
558  op = ol->ob;
559  lastdist = rv.distance;
560  }
561  }
562  for (pl = first_player; pl != NULL; pl = pl->next) {
563  if (monster_can_detect_enemy(mon, pl->ob, &rv)) {
564  if (lastdist > rv.distance) {
565  op = pl->ob;
566  lastdist = rv.distance;
567  }
568  }
569  }
570  return op;
571 }
572 
582 #define DETOUR_AMOUNT 2
583 
597 #define MAX_SPACES 50
598 
630 int path_to_player(object *mon, object *pl, unsigned mindiff) {
631  rv_vector rv;
632  int16_t x, y;
633  int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
634  mapstruct *m, *lastmap;
635 
636  if (!get_rangevector(mon, pl, &rv, 0))
637  return 0;
638 
639  if (rv.distance < mindiff)
640  return 0;
641 
642  x = mon->x;
643  y = mon->y;
644  m = mon->map;
645  dir = rv.direction;
646  lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
647  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
648  /* If we can't solve it within the search distance, return now. */
649  if (diff > max)
650  return 0;
651  while (diff > 1 && max > 0) {
652  lastx = x;
653  lasty = y;
654  lastmap = m;
655  x = lastx+freearr_x[dir];
656  y = lasty+freearr_y[dir];
657 
658  mflags = get_map_flags(m, &m, x, y, &x, &y);
659  blocked = (mflags&P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK(m, x, y);
660 
661  /* Space is blocked - try changing direction a little */
662  if ((mflags&P_OUT_OF_MAP)
663  || ((OB_TYPE_MOVE_BLOCK(mon, blocked) || (mflags&P_IS_ALIVE))
664  && (m == mon->map && blocked_link(mon, m, x, y)))) {
665  /* recalculate direction from last good location. Possible
666  * we were not traversing ideal location before.
667  */
668  if (get_rangevector_from_mapcoord(lastmap, lastx, lasty, pl, &rv, 0) && rv.direction != dir) {
669  /* OK - says direction should be different - lets reset the
670  * the values so it will try again.
671  */
672  x = lastx;
673  y = lasty;
674  m = lastmap;
675  dir = firstdir = rv.direction;
676  } else {
677  /* direct path is blocked - try taking a side step to
678  * either the left or right.
679  * Note increase the values in the loop below to be
680  * more than -1/1 respectively will mean the monster takes
681  * bigger detour. Have to be careful about these values getting
682  * too big (3 or maybe 4 or higher) as the monster may just try
683  * stepping back and forth
684  */
685  for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) {
686  if (i == 0)
687  continue; /* already did this, so skip it */
688  /* Use lastdir here - otherwise,
689  * since the direction that the creature should move in
690  * may change, you could get infinite loops.
691  * ie, player is northwest, but monster can only
692  * move west, so it does that. It goes some distance,
693  * gets blocked, finds that it should move north,
694  * can't do that, but now finds it can move east, and
695  * gets back to its original point. lastdir contains
696  * the last direction the creature has successfully
697  * moved.
698  */
699 
700  x = lastx+freearr_x[absdir(lastdir+i)];
701  y = lasty+freearr_y[absdir(lastdir+i)];
702  m = lastmap;
703  mflags = get_map_flags(m, &m, x, y, &x, &y);
704  if (mflags&P_OUT_OF_MAP)
705  continue;
706  blocked = GET_MAP_MOVE_BLOCK(m, x, y);
707  if (OB_TYPE_MOVE_BLOCK(mon, blocked))
708  continue;
709  if (mflags&P_IS_ALIVE)
710  continue;
711 
712  if (m == mon->map && blocked_link(mon, m, x, y))
713  break;
714  }
715  /* go through entire loop without finding a valid
716  * sidestep to take - thus, no valid path.
717  */
718  if (i == (DETOUR_AMOUNT+1))
719  return 0;
720  diff--;
721  lastdir = dir;
722  max--;
723  if (!firstdir)
724  firstdir = dir+i;
725  } /* else check alternate directions */
726  } /* if blocked */
727  else {
728  /* we moved towards creature, so diff is less */
729  diff--;
730  max--;
731  lastdir = dir;
732  if (!firstdir)
733  firstdir = dir;
734  }
735  if (diff <= 1) {
736  /* Recalculate diff (distance) because we may not have actually
737  * headed toward player for entire distance.
738  */
739  if (!get_rangevector_from_mapcoord(m, x, y, pl, &rv, 0))
740  return 0;
741  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
742  }
743  if (diff > max)
744  return 0;
745  }
746  /* If we reached the max, didn't find a direction in time */
747  if (!max)
748  return 0;
749 
750  return firstdir;
751 }
752 
763 void give_initial_items(object *pl, treasurelist *items) {
764  if (pl->randomitems != NULL)
765  create_treasure(items, pl, GT_STARTEQUIP|GT_ONLY_GOOD, 1, 0);
766 
767  FOR_INV_PREPARE(pl, op) {
768  /* Forces get applied per default, unless they have the
769  * flag "neutral" set. Sorry but I can't think of a better way
770  */
771  if (op->type == FORCE && !QUERY_FLAG(op, FLAG_NEUTRAL))
772  SET_FLAG(op, FLAG_APPLIED);
773 
774  /* we never give weapons/armour if these cannot be used
775  * by this player due to race restrictions
776  */
777  if (pl->type == PLAYER) {
778  if ((!QUERY_FLAG(pl, FLAG_USE_ARMOUR) && IS_ARMOR(op))
779  || (!QUERY_FLAG(pl, FLAG_USE_WEAPON) && IS_WEAPON(op))
780  || (!QUERY_FLAG(pl, FLAG_USE_SHIELD) && IS_SHIELD(op))) {
781  object_remove(op);
783  continue;
784  }
785  }
786 
787  /* This really needs to be better - we should really give
788  * a substitute spellbook. The problem is that we don't really
789  * have a good idea what to replace it with (need something like
790  * a first level treasurelist for each skill.)
791  * remove duplicate skills also
792  */
793  if (op->type == SPELLBOOK || op->type == SKILL) {
794  int found;
795 
796  found = 0;
797  FOR_BELOW_PREPARE(op, tmp)
798  if (object_can_merge(op, tmp)) {
799  found = 1;
800  break;
801  }
803  if (found) {
804  LOG(llevError, "give_initial_items: Removing duplicate object %s\n", op->name);
805  object_remove(op);
807  continue;
808  }
809  if (op->nrof > 1)
810  op->nrof = 1;
811  }
812 
813  if (op->type == SPELLBOOK && op->inv) {
814  CLEAR_FLAG(op->inv, FLAG_STARTEQUIP);
815  }
816 
817  /* Give starting characters identified, uncursed, and undamned
818  * items. Just don't identify gold or silver, or it won't be
819  * merged properly.
820  */
821  if (!is_identifiable_type(op)) {
823  CLEAR_FLAG(op, FLAG_CURSED);
824  CLEAR_FLAG(op, FLAG_DAMNED);
825  }
826  if (op->type == SKILL) {
828  op->stats.exp = 0;
829  op->level = 1;
830  }
831  /* lock all 'normal items by default */
832  else
834  } FOR_INV_FINISH(); /* for loop of objects in player inv */
835 
836  /* Need to set up the skill pointers */
837  link_player_skills(pl);
838 
843  FOR_INV_PREPARE(pl, op)
844  if ((IS_ARMOR(op) || IS_WEAPON(op) || IS_SHIELD(op)) && !QUERY_FLAG(op, FLAG_APPLIED))
845  apply_manual(pl, op, AP_NOPRINT);
846  FOR_INV_FINISH();
847 }
848 
855 void get_name(object *op) {
856  op->contr->write_buf[0] = '\0';
858  send_query(&op->contr->socket, 0, "What is your name?\n:");
859 }
860 
867 void get_password(object *op) {
868  op->contr->write_buf[0] = '\0';
870  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:");
871 }
872 
879 void play_again(object *op) {
880  SockList sl;
881 
883  op->chosen_skill = NULL;
884 
885  /*
886  * For old clients, ask if they want to play again.
887  * For clients with account support, just return to character seletion (see below).
888  */
889  if (op->contr->socket.login_method == 0) {
890  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
891  }
892  /* a bit of a hack, but there are various places early in th
893  * player creation process that a user can quit (eg, roll
894  * stats) that isn't removing the player. Taking a quick
895  * look, there are many places that call play_again without
896  * removing the player - it probably makes more sense
897  * to leave it to play_again to remove the object in all
898  * cases.
899  */
900  if (!QUERY_FLAG(op, FLAG_REMOVED))
901  object_remove(op);
902  /* Need to set this to null - otherwise, it could point to garbage,
903  * and draw() doesn't check to see if the player is removed, only if
904  * the map is null or not swapped out.
905  */
906  op->map = NULL;
907 
908  SockList_Init(&sl);
909  SockList_AddString(&sl, "player ");
910  SockList_AddInt(&sl, 0);
911  SockList_AddInt(&sl, 0);
912  SockList_AddInt(&sl, 0);
913  SockList_AddChar(&sl, 0);
914 
915  Send_With_Handling(&op->contr->socket, &sl);
916  SockList_Term(&sl);
917 
918  if (op->contr->socket.login_method > 0) {
919  receive_play_again(op, 'a');
920  }
921 }
922 
931 void receive_play_again(object *op, char key) {
932  if (key == 'q' || key == 'Q') {
934  leave(op->contr, 0); /* ericserver will draw the message */
935  return;
936  } else if (key == 'a' || key == 'A') {
937  player *pl = op->contr;
938  const char *name = op->name;
939 
940  add_refcount(name);
943  pl = get_player(pl);
944  op = pl->ob;
946  op->contr->password[0] = '~';
949  if (pl->socket.login_method >= 1 && pl->socket.account_name != NULL) {
950  /* If we are using new login, we send the
951  * list of characters to the client - this should
952  * result in the client popping up this list so
953  * the player can choose which one to play - better
954  * than going to legacy login code.
955  * If the account_name is NULL, it means the client
956  * says it uses account but started playing without logging in.
957  */
960  } else {
961  /* Lets put a space in here */
963  "\n");
964  get_name(op);
965  set_first_map(op);
966  }
967  op->name = name; /* Already added a refcount above */
968  op->name_pl = add_string(name);
969  } else {
970  /* user pressed something else so just ask again... */
971  play_again(op);
972  }
973 }
974 
981 void confirm_password(object *op) {
982  op->contr->write_buf[0] = '\0';
984  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
985 }
986 
997 int get_party_password(object *op, partylist *party) {
998  if (*party_get_password(party) == '\0') {
999  return 0;
1000  }
1001 
1002  op->contr->write_buf[0] = '\0';
1004  op->contr->party_to_join = party;
1005  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:");
1006  return 1;
1007 }
1008 
1015 int roll_stat(void) {
1016  int roll[4], i, low_index, k;
1017 
1018  for (i = 0; i < 4; ++i)
1019  roll[i] = (int)RANDOM()%6+1;
1020 
1021  for (i = 0, low_index = 0, k = 7; i < 4; ++i)
1022  if (roll[i] < k)
1023  k = roll[i],
1024  low_index = i;
1025 
1026  for (i = 0, k = 0; i < 4; ++i) {
1027  if (i != low_index)
1028  k += roll[i];
1029  }
1030  return k;
1031 }
1032 
1039 void roll_stats(object *op) {
1040  int sum = 0;
1041  int i = 0, j = 0;
1042  int statsort[7];
1043 
1044  do {
1045  op->stats.Str = roll_stat();
1046  op->stats.Dex = roll_stat();
1047  op->stats.Int = roll_stat();
1048  op->stats.Con = roll_stat();
1049  op->stats.Wis = roll_stat();
1050  op->stats.Pow = roll_stat();
1051  op->stats.Cha = roll_stat();
1052  sum = op->stats.Str+op->stats.Dex+op->stats.Int+op->stats.Con+op->stats.Wis+op->stats.Pow+op->stats.Cha;
1053  } while (sum != settings.roll_stat_points);
1054 
1055  /* Sort the stats so that rerolling is easier... */
1056  statsort[0] = op->stats.Str;
1057  statsort[1] = op->stats.Dex;
1058  statsort[2] = op->stats.Int;
1059  statsort[3] = op->stats.Con;
1060  statsort[4] = op->stats.Wis;
1061  statsort[5] = op->stats.Pow;
1062  statsort[6] = op->stats.Cha;
1063 
1064  /* a quick and dirty bubblesort? */
1065  do {
1066  if (statsort[i] < statsort[i+1]) {
1067  j = statsort[i];
1068  statsort[i] = statsort[i+1];
1069  statsort[i+1] = j;
1070  i = 0;
1071  } else {
1072  i++;
1073  }
1074  } while (i < 6);
1075 
1076  op->stats.Str = statsort[0];
1077  op->stats.Dex = statsort[1];
1078  op->stats.Con = statsort[2];
1079  op->stats.Int = statsort[3];
1080  op->stats.Wis = statsort[4];
1081  op->stats.Pow = statsort[5];
1082  op->stats.Cha = statsort[6];
1083 
1084  op->contr->orig_stats.Str = op->stats.Str;
1085  op->contr->orig_stats.Dex = op->stats.Dex;
1086  op->contr->orig_stats.Int = op->stats.Int;
1087  op->contr->orig_stats.Con = op->stats.Con;
1088  op->contr->orig_stats.Wis = op->stats.Wis;
1089  op->contr->orig_stats.Pow = op->stats.Pow;
1090  op->contr->orig_stats.Cha = op->stats.Cha;
1091 
1092  op->level = 1;
1093  op->stats.exp = 0;
1094  op->stats.ac = 0;
1095 
1096  op->contr->levhp[1] = 9;
1097  op->contr->levsp[1] = 6;
1098  op->contr->levgrace[1] = 3;
1099 
1100  fix_object(op);
1101  op->stats.hp = op->stats.maxhp;
1102  op->stats.sp = op->stats.maxsp;
1103  op->stats.grace = op->stats.maxgrace;
1104  op->contr->orig_stats = op->stats;
1105 }
1106 
1113 void roll_again(object *op) {
1114  esrv_new_player(op->contr, 0);
1115  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "<y> to roll new stats <n> to use stats\n<1-7> <1-7> to swap stats.\nRoll again (y/n/1-7)? ");
1116 }
1117 
1127 static void swap_stat(object *op, int swap_second) {
1128  signed char tmp;
1129 
1130  if (op->contr->swap_first == -1) {
1131  LOG(llevError, "player.c:swap_stat() - swap_first is -1\n");
1132  return;
1133  }
1134 
1135  tmp = get_attr_value(&op->contr->orig_stats, op->contr->swap_first);
1136 
1137  set_attr_value(&op->contr->orig_stats, op->contr->swap_first, get_attr_value(&op->contr->orig_stats, swap_second));
1138 
1139  set_attr_value(&op->contr->orig_stats, swap_second, tmp);
1140 
1142  "%s done\n",
1143  short_stat_name[swap_second]);
1144 
1145  op->stats.Str = op->contr->orig_stats.Str;
1146  op->stats.Dex = op->contr->orig_stats.Dex;
1147  op->stats.Con = op->contr->orig_stats.Con;
1148  op->stats.Int = op->contr->orig_stats.Int;
1149  op->stats.Wis = op->contr->orig_stats.Wis;
1150  op->stats.Pow = op->contr->orig_stats.Pow;
1151  op->stats.Cha = op->contr->orig_stats.Cha;
1152  op->stats.ac = 0;
1153 
1154  op->level = 1;
1155  op->stats.exp = 0;
1156  op->stats.ac = 0;
1157 
1158  op->contr->levhp[1] = 9;
1159  op->contr->levsp[1] = 6;
1160  op->contr->levgrace[1] = 3;
1161 
1162  fix_object(op);
1163  op->stats.hp = op->stats.maxhp;
1164  op->stats.sp = op->stats.maxsp;
1165  op->stats.grace = op->stats.maxgrace;
1166  op->contr->orig_stats = op->stats;
1167  op->contr->swap_first = -1;
1168 }
1169 
1185 void key_roll_stat(object *op, char key) {
1186  int keynum = key-'0';
1187  static const int8_t stat_trans[] = {
1188  -1,
1189  STRENGTH,
1190  DEXTERITY,
1191  CONSTITUTION,
1192  INTELLIGENCE,
1193  WISDOM,
1194  POWER,
1195  CHARISMA,
1196  };
1197 
1198  if (keynum > 0 && keynum <= 7) {
1199  if (op->contr->swap_first == -1) {
1200  op->contr->swap_first = stat_trans[keynum];
1202  "%s ->",
1203  short_stat_name[stat_trans[keynum]]);
1204  } else
1205  swap_stat(op, stat_trans[keynum]);
1206 
1208  return;
1209  }
1210  switch (key) {
1211  case 'n':
1212  case 'N': {
1213  SET_FLAG(op, FLAG_WIZ);
1214  if (op->map == NULL) {
1215  LOG(llevError, "Map == NULL in state 2\n");
1216  break;
1217  }
1218 
1219  SET_ANIMATION(op, 2); /* So player faces south */
1220  /* Enter exit adds a player otherwise */
1221  add_statbonus(op);
1222  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1224  if (op->msg)
1225  draw_ext_info(NDI_BLUE, 0, op,
1227  op->msg);
1228  return;
1229  }
1230  case 'y':
1231  case 'Y':
1232  roll_stats(op);
1234  return;
1235 
1236  case 'q':
1237  case 'Q':
1238  play_again(op);
1239  return;
1240 
1241  default:
1242  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1243  return;
1244  }
1245  return;
1246 }
1247 
1261 void key_change_class(object *op, char key) {
1262  int tmp_loop;
1263 
1264  if (key == 'q' || key == 'Q') {
1265  object_remove(op);
1266  play_again(op);
1267  return;
1268  }
1269  if (key == 'd' || key == 'D') {
1270  char buf[MAX_BUF];
1271 
1272  /* this must before then initial items are given */
1273  esrv_new_player(op->contr, op->weight+op->carrying);
1274  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1275 
1276  /* Lauwenmark : Here we handle the BORN global event */
1278 
1279  /* Lauwenmark : We then generate a LOGIN event */
1282 
1283  object_set_msg(op, NULL);
1284 
1285  /* We create this now because some of the unique maps will need it
1286  * to save here.
1287  */
1288  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1289  make_path_to_file(buf);
1290 
1291 #ifdef AUTOSAVE
1292  op->contr->last_save_tick = pticks;
1293 #endif
1296  "Welcome to Crossfire!\n Press `?' for help\n");
1297 
1300  "%s entered the game.", op->name);
1301 
1302  CLEAR_FLAG(op, FLAG_WIZ);
1304  link_player_skills(op);
1305  esrv_send_inventory(op, op);
1306  fix_object(op);
1307 
1308  /* This moves the player to a different start map, if there
1309  * is one for this race
1310  */
1311  if (*first_map_ext_path) {
1312  object *tmp;
1313  char mapname[MAX_BUF];
1314  mapstruct *oldmap;
1315 
1316  oldmap = op->map;
1317 
1318  snprintf(mapname, MAX_BUF-1, "%s/%s", first_map_ext_path, op->arch->name);
1319  /*printf("%s\n", mapname);*/
1320  tmp = object_new();
1321  EXIT_PATH(tmp) = add_string(mapname);
1322  EXIT_X(tmp) = op->x;
1323  EXIT_Y(tmp) = op->y;
1324  enter_exit(op, tmp);
1325 
1326  if (oldmap != op->map) {
1327  /* map exists, update bed of reality location, in case player dies */
1328  op->contr->bed_x = op->x;
1329  op->contr->bed_y = op->y;
1330  strlcpy(op->contr->savebed_map, mapname, sizeof(op->contr->savebed_map));
1331  }
1332 
1334  } else {
1335  LOG(llevDebug, "first_map_ext_path not set\n");
1336  }
1337  return;
1338  }
1339 
1340  /* Following actually changes the race - this is the default command
1341  * if we don't match with one of the options above.
1342  */
1343 
1344  tmp_loop = 0;
1345  while (!tmp_loop) {
1346  const char *name = add_string(op->name);
1347  int x = op->x, y = op->y;
1348 
1349  remove_statbonus(op);
1350  object_remove(op);
1351  /* get_player_archetype() is really misnamed - it will
1352  * get the next archetype from the list.
1353  */
1354  op->arch = get_player_archetype(op->arch);
1355  object_copy(&op->arch->clone, op);
1356  op->stats = op->contr->orig_stats;
1357  free_string(op->name);
1358  op->name = name;
1359  free_string(op->name_pl);
1360  op->name_pl = add_string(name);
1361  SET_ANIMATION(op, 2); /* So player faces south */
1362  object_insert_in_map_at(op, op->map, op, 0, x, y);
1363  strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1);
1364  op->contr->title[sizeof(op->contr->title)-1] = '\0';
1365  add_statbonus(op);
1366  tmp_loop = allowed_class(op);
1367  }
1369  esrv_update_item(UPD_FACE, op, op);
1370  fix_object(op);
1371  op->stats.hp = op->stats.maxhp;
1372  op->stats.sp = op->stats.maxsp;
1373  op->stats.grace = 0;
1374  if (op->msg)
1376  op->msg);
1377  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1378 }
1379 
1401 int check_race_and_class(living *stats, archetype *race, archetype *opclass)
1402 {
1403  int i, stat, failure=0;
1404 
1405  for (i = 0; i < NUM_STATS; i++) {
1406  stat = get_attr_value(stats, i);
1407  if (race)
1408  stat += get_attr_value(&race->clone.stats, i);
1409 
1410  if (opclass)
1411  stat += get_attr_value(&opclass->clone.stats, i);
1412 
1413  set_attr_value(stats, i, stat);
1414 
1415  /* We process all stats, regardless if there is a failure
1416  * or not.
1417  */
1418  if (stat < MIN_STAT) failure=1;
1419 
1420  /* Maybe this should be an error? Player is losing
1421  * some stats points here, but it is legal.
1422  */
1423  if (stat > settings.max_stat) stat = settings.max_stat;
1424  }
1425  return failure;
1426 
1427 }
1428 
1451 int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
1452 {
1453  const char *name = add_string(op->name);
1454  char buf[MAX_BUF];
1455  object *inv;
1456 
1457  /* Free any objects in character inventory - they
1458  * shouldn't have any, but there is the potential that
1459  * we give them objects below and then get a creation
1460  * failure (stat out of range), in which case
1461  * those objects would be in the inventory.
1462  */
1463  while (op->inv) {
1464  inv = op->inv;
1465  object_remove(inv);
1466  object_free(inv, 0);
1467  }
1468 
1469  object_copy(&race->clone, op);
1470  free_string(op->name);
1471  op->name = name;
1472  free_string(op->name_pl);
1473  op->name_pl = add_string(name);
1474  SET_ANIMATION(op, 2); /* So player faces south */
1475  strlcpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title));
1476 
1477  if (stats) {
1478  /* Copy over the stats. Use this instead a memcpy because
1479  * we only want to copy over a few specific stats, and
1480  * leave things like maxhp, maxsp, etc, unchanged.
1481  */
1482  int i, stat;
1483  for (i = 0; i < NUM_STATS; i++) {
1484  stat = get_attr_value(stats, i);
1485  set_attr_value(&op->stats, i, stat);
1486  set_attr_value(&op->contr->orig_stats, i, stat);
1487  }
1488  } else {
1489  /* Note that this will repeated increase the stat values
1490  * if the caller does not reset them. Only do this
1491  * if stats is not provided - if stats is provided, those
1492  * are already adjusted.
1493  */
1494  add_statbonus(op);
1495 
1496  /* Checks that all stats are greater than 1. Once again,
1497  * only do this if stats are not provided
1498  */
1499  if (!allowed_class(op)) return 1;
1500  }
1501 
1503  op->stats.hp = op->stats.maxhp;
1504  op->stats.sp = op->stats.maxsp;
1505  op->stats.grace = 0;
1506 
1507  /* this must before then initial items are given */
1508  esrv_new_player(op->contr, op->weight+op->carrying);
1509  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1510 
1511  /* This has to be done before class, otherwise the NOCLASSFACECHANGE
1512  * object is not in the inventory, and racial face will get overwritten.
1513  */
1515 
1516  if (stats) {
1517  /* Apply class information */
1519  } else {
1520  apply_changes_to_player(op, &opclass->clone, 0);
1521 
1522  /* Checks that all stats are greater than 1 */
1523  if (!allowed_class(op)) return 2;
1524  }
1525 
1526  /* Lauwenmark : Here we handle the BORN global event */
1528 
1529  /* Lauwenmark : We then generate a LOGIN event */
1531 
1532  object_set_msg(op, NULL);
1533 
1534  /* We create this now because some of the unique maps will need it
1535  * to save here.
1536  */
1537  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1538  make_path_to_file(buf);
1539 
1540 #ifdef AUTOSAVE
1541  op->contr->last_save_tick = pticks;
1542 #endif
1543 
1544  CLEAR_FLAG(op, FLAG_WIZ);
1545  link_player_skills(op);
1546  fix_object(op);
1547 
1548  esrv_send_inventory(op, op);
1549  esrv_update_item(UPD_FACE, op, op);
1550 
1551  return 0;
1552 
1553 }
1554 
1563 void key_confirm_quit(object *op, char key) {
1564  char buf[MAX_BUF];
1565  mapstruct *mp, *next;
1566 
1567  // this was tested when 'quit' command was issued, but better safe than sorry.
1568  if (QUERY_FLAG(op, FLAG_WAS_WIZ)) {
1570  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOGIN, "Can't quit when in DM mode.");
1571  return;
1572  }
1573 
1574  if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') {
1577  "OK, continuing to play.");
1578  return;
1579  }
1580 
1581  /* Lauwenmark : Here we handle the REMOVE global event */
1583  pets_terminate_all(op);
1584  object_remove(op);
1585  op->direction = 0;
1587  "%s quits the game.",
1588  op->name);
1589 
1590  strcpy(op->contr->killer, "quit");
1591  hiscore_check(op, 0);
1592  party_leave(op);
1593  if (settings.set_title == TRUE)
1594  player_set_own_title(op->contr, "");
1595 
1596 
1597  /* We need to hunt for any per player unique maps in memory and
1598  * get rid of them. The trailing slash in the path is intentional,
1599  * so that players named 'Ab' won't match against players 'Abe' pathname
1600  */
1601  snprintf(buf, sizeof(buf), "%s/%s/%s/", settings.localdir, settings.playerdir, op->name);
1602  for (mp = first_map; mp != NULL; mp = next) {
1603  next = mp->next;
1604  if (!strncmp(mp->path, buf, strlen(buf)))
1605  delete_map(mp);
1606  }
1607 
1608  delete_character(op->name);
1609 
1610  /* Remove player from account list and send back data if needed */
1611  if (op->contr->socket.account_chars != NULL) {
1614  /* char information is reloaded in send_account_players below */
1616  op->contr->socket.account_chars = NULL;
1619  }
1620 
1621  play_again(op);
1622 }
1623 
1630 static void flee_player(object *op) {
1631  int dir, diff;
1632  rv_vector rv;
1633 
1634  if (op->stats.hp < 0) {
1635  LOG(llevDebug, "Fleeing player is dead.\n");
1636  CLEAR_FLAG(op, FLAG_SCARED);
1637  return;
1638  }
1639 
1640  if (op->enemy == NULL) {
1641  LOG(llevDebug, "Fleeing player had no enemy.\n");
1642  CLEAR_FLAG(op, FLAG_SCARED);
1643  return;
1644  }
1645 
1646  /* Seen some crashes here. Since we don't store an
1647  * op->enemy_count, it is possible that something destroys the
1648  * actual enemy, and the object is recycled.
1649  */
1650  if (op->enemy->map == NULL) {
1651  CLEAR_FLAG(op, FLAG_SCARED);
1652  object_set_enemy(op, NULL);
1653  return;
1654  }
1655 
1656  if (!(random_roll(0, 4, op, PREFER_LOW)) && did_make_save(op, op->level, 0)) {
1657  object_set_enemy(op, NULL);
1658  CLEAR_FLAG(op, FLAG_SCARED);
1659  return;
1660  }
1661  if (!get_rangevector(op, op->enemy, &rv, 0)) {
1662  object_set_enemy(op, NULL);
1663  CLEAR_FLAG(op, FLAG_SCARED);
1664  return;
1665  }
1666 
1667  dir = absdir(4+rv.direction);
1668  for (diff = 0; diff < 3; diff++) {
1669  int m = 1-(RANDOM()&2);
1670  if (move_ob(op, absdir(dir+diff*m), op)
1671  || (diff == 0 && move_ob(op, absdir(dir-diff*m), op))) {
1672  return;
1673  }
1674  }
1675  /* Cornered, get rid of scared */
1676  CLEAR_FLAG(op, FLAG_SCARED);
1677  object_set_enemy(op, NULL);
1678 }
1679 
1689 int check_pick(object *op) {
1690  tag_t op_tag;
1691  int stop = 0;
1692  int j, k, wvratio, current_ratio;
1693  char putstring[128], tmpstr[16];
1694 
1695  /* if you're flying, you can't pick up anything */
1696  if (op->move_type&MOVE_FLYING)
1697  return 1;
1698  /* If not a player, don't check anything. */
1699  if (!op->contr) {
1700  return 1;
1701  }
1702 
1703  op_tag = op->count;
1704 
1705  FOR_BELOW_PREPARE(op, tmp) {
1706  if (object_was_destroyed(op, op_tag))
1707  return 0;
1708 
1709  if (!object_can_pick(op, tmp))
1710  continue;
1711 
1712  if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) {
1713  if (object_matches_string(op, tmp, op->contr->search_str))
1714  pick_up(op, tmp);
1715  continue;
1716  }
1717 
1718  /* high not bit set? We're using the old autopickup model */
1719  if (!(op->contr->mode&PU_NEWMODE)) {
1720  switch (op->contr->mode) {
1721  case 0:
1722  return 1; /* don't pick up */
1723 
1724  case 1:
1725  pick_up(op, tmp);
1726  return 1;
1727 
1728  case 2:
1729  pick_up(op, tmp);
1730  return 0;
1731 
1732  case 3:
1733  return 0; /* stop before pickup */
1734 
1735  case 4:
1736  pick_up(op, tmp);
1737  break;
1738 
1739  case 5:
1740  pick_up(op, tmp);
1741  stop = 1;
1742  break;
1743 
1744  case 6:
1745  if (QUERY_FLAG(tmp, FLAG_KNOWN_MAGICAL)
1746  && !QUERY_FLAG(tmp, FLAG_KNOWN_CURSED))
1747  pick_up(op, tmp);
1748  break;
1749 
1750  case 7:
1751  if (tmp->type == MONEY || tmp->type == GEM)
1752  pick_up(op, tmp);
1753  break;
1754 
1755  default:
1756  /* use value density */
1757  if (!QUERY_FLAG(tmp, FLAG_UNPAID)
1758  && (price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))) >= op->contr->mode)
1759  pick_up(op, tmp);
1760  }
1761  } else { /* old model */
1762  /* NEW pickup handling */
1763  if (op->contr->mode&PU_DEBUG) {
1764  /* some debugging code to figure out item information */
1766  "item name: %s item type: %d weight/value: %d",
1767  tmp->name ? tmp->name : tmp->arch->name, tmp->type,
1768  (int)(price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))));
1769 
1770 
1771  snprintf(putstring, sizeof(putstring), "...flags: ");
1772  for (k = 0; k < 4; k++) {
1773  for (j = 0; j < 32; j++) {
1774  if ((tmp->flags[k]>>j)&0x01) {
1775  snprintf(tmpstr, sizeof(tmpstr), "%d ", k*32+j);
1776  strcat(putstring, tmpstr);
1777  }
1778  }
1779  }
1781  putstring);
1782  }
1783  /* philosophy:
1784  * It's easy to grab an item type from a pile, as long as it's
1785  * generic. This takes no game-time. For more detailed pickups
1786  * and selections, select-items should be used. This is a
1787  * grab-as-you-run type mode that's really useful for arrows for
1788  * example.
1789  * The drawback: right now it has no frontend, so you need to
1790  * stick the bits you want into a calculator in hex mode and then
1791  * convert to decimal and then 'pickup <#>
1792  */
1793 
1794  /* the first two modes are exclusive: if NOTHING we return, if
1795  * STOP then we stop. All the rest are applied sequentially,
1796  * meaning if any test passes, the item gets picked up. */
1797 
1798  /* if mode is set to pick nothing up, return */
1799 
1800  if (op->contr->mode == PU_NOTHING)
1801  return 1;
1802 
1803  /* if mode is set to stop when encountering objects, return.
1804  * Take STOP before INHIBIT since it doesn't actually pick
1805  * anything up */
1806 
1807  if (op->contr->mode&PU_STOP)
1808  return 0;
1809 
1810  /* useful for going into stores and not losing your settings... */
1811  /* and for battles where you don't want to get loaded down while
1812  * fighting */
1813  if (op->contr->mode&PU_INHIBIT)
1814  return 1;
1815 
1816  /* prevent us from turning into auto-thieves :) */
1817  if (QUERY_FLAG(tmp, FLAG_UNPAID))
1818  continue;
1819 
1820  /* ignore known cursed objects */
1822  continue;
1823 
1824  /* all food and drink if desired */
1825  /* question: don't pick up known-poisonous stuff? */
1826  if (op->contr->mode&PU_FOOD)
1827  if (tmp->type == FOOD) {
1828  pick_up(op, tmp);
1829  continue;
1830  }
1831  if (op->contr->mode&PU_DRINK)
1832  if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG(tmp, FLAG_KNOWN_CURSED))) {
1833  pick_up(op, tmp);
1834  continue;
1835  }
1836  /* we don't forget dragon food */
1837  if (op->contr->mode&PU_FLESH)
1838  if (tmp->type == FLESH) {
1839  pick_up(op, tmp);
1840  continue;
1841  }
1842  if (op->contr->mode&PU_POTION)
1843  if (tmp->type == POTION) {
1844  pick_up(op, tmp);
1845  continue;
1846  }
1847 
1848  /* spellbooks, skillscrolls and normal books/scrolls */
1849  if (op->contr->mode&PU_SPELLBOOK)
1850  if (tmp->type == SPELLBOOK) {
1851  pick_up(op, tmp);
1852  continue;
1853  }
1854  if (op->contr->mode&PU_SKILLSCROLL)
1855  if (tmp->type == SKILLSCROLL) {
1856  pick_up(op, tmp);
1857  continue;
1858  }
1859  if (op->contr->mode&PU_READABLES)
1860  if (tmp->type == BOOK || tmp->type == SCROLL) {
1861  pick_up(op, tmp);
1862  continue;
1863  }
1864 
1865  /* wands/staves/rods/horns/skill tools */
1866  if (op->contr->mode&PU_MAGIC_DEVICE)
1867  if (tmp->type == WAND || tmp->type == ROD || tmp->type == WEAPON_IMPROVER || tmp->type == ARMOUR_IMPROVER || tmp->type == SKILL_TOOL) {
1868  pick_up(op, tmp);
1869  continue;
1870  }
1871 
1872  /* pick up all magical items */
1873  if (op->contr->mode&PU_MAGICAL)
1875  pick_up(op, tmp);
1876  continue;
1877  }
1878 
1879  if (op->contr->mode&PU_VALUABLES) {
1880  if (tmp->type == MONEY || tmp->type == GEM) {
1881  pick_up(op, tmp);
1882  continue;
1883  }
1884  }
1885 
1886  /* rings & amulets - talismans seems to be typed AMULET */
1887  if (op->contr->mode&PU_JEWELS)
1888  if (tmp->type == RING || tmp->type == AMULET) {
1889  pick_up(op, tmp);
1890  continue;
1891  }
1892 
1893  /* bows and arrows. Bows are good for selling! */
1894  if (op->contr->mode&PU_BOW)
1895  if (tmp->type == BOW) {
1896  pick_up(op, tmp);
1897  continue;
1898  }
1899  if (op->contr->mode&PU_ARROW)
1900  if (tmp->type == ARROW) {
1901  pick_up(op, tmp);
1902  continue;
1903  }
1904 
1905  /* all kinds of armor etc. */
1906  if (op->contr->mode&PU_ARMOUR)
1907  if (tmp->type == ARMOUR) {
1908  pick_up(op, tmp);
1909  continue;
1910  }
1911  if (op->contr->mode&PU_HELMET)
1912  if (tmp->type == HELMET) {
1913  pick_up(op, tmp);
1914  continue;
1915  }
1916  if (op->contr->mode&PU_SHIELD)
1917  if (tmp->type == SHIELD) {
1918  pick_up(op, tmp);
1919  continue;
1920  }
1921  if (op->contr->mode&PU_BOOTS)
1922  if (tmp->type == BOOTS) {
1923  pick_up(op, tmp);
1924  continue;
1925  }
1926  if (op->contr->mode&PU_GLOVES)
1927  if (tmp->type == GLOVES) {
1928  pick_up(op, tmp);
1929  continue;
1930  }
1931  if (op->contr->mode&PU_CLOAK)
1932  if (tmp->type == CLOAK) {
1933  pick_up(op, tmp);
1934  continue;
1935  }
1936 
1937  /* hoping to catch throwing daggers here */
1938  if (op->contr->mode&PU_MISSILEWEAPON)
1939  if (tmp->type == WEAPON && QUERY_FLAG(tmp, FLAG_IS_THROWN)) {
1940  pick_up(op, tmp);
1941  continue;
1942  }
1943 
1944  /* careful: chairs and tables are weapons! */
1945  /* Note that tables and chairs have been changed to not be weapons as of 2011. */
1946  if (op->contr->mode&PU_MELEEWEAPON) {
1947  // The code here used to handle avoiding tables and chairs.
1948  // Since there have been many server-arch prerequisites since the change,
1949  // we should be good not handling them here.
1950  // SilverNexus 2018-12-30
1951  if (tmp->type == WEAPON) {
1952  pick_up(op, tmp);
1953  continue;
1954  }
1955  }
1956 
1957  /* misc stuff that's useful */
1958  if (op->contr->mode&PU_KEY)
1959  if (tmp->type == KEY || tmp->type == SPECIAL_KEY) {
1960  pick_up(op, tmp);
1961  continue;
1962  }
1963 
1964  if (op->contr->mode&PU_CONTAINER && tmp->type == CONTAINER) {
1965  pick_up(op, tmp);
1966  continue;
1967  }
1968 
1969  /* any of the last 4 bits set means we use the ratio for value
1970  * pickups */
1971  if (op->contr->mode&PU_RATIO) {
1972  /* use value density to decide what else to grab.
1973  * >=7 was >= op->contr->mode
1974  * >=7 is the old standard setting. Now we take the last 4 bits
1975  * and multiply them by 5, giving 0..15*5== 5..75 */
1976  wvratio = (op->contr->mode&PU_RATIO)*5;
1977  current_ratio = price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1));
1978  if (current_ratio >= wvratio) {
1979  pick_up(op, tmp);
1980  continue;
1981  }
1982  }
1983  } /* the new pickup model */
1984  } FOR_BELOW_FINISH();
1985  return !stop;
1986 }
1987 
2000 static object *find_arrow(object *op, const char *type) {
2001  object *tmp = NULL;
2002 
2003  FOR_INV_PREPARE(op, inv)
2004  if (!tmp
2005  && inv->type == CONTAINER
2006  && inv->race == type
2007  && QUERY_FLAG(inv, FLAG_APPLIED))
2008  tmp = find_arrow(inv, type);
2009  else if (inv->type == ARROW && inv->race == type)
2010  return inv;
2011  FOR_INV_FINISH();
2012  return tmp;
2013 }
2014 
2032 static object *find_better_arrow(object *op, object *target, const char *type, int *better) {
2033  object *tmp = NULL, *ntmp;
2034  int attacknum, attacktype, betterby = 0, i;
2035 
2036  if (!type)
2037  return NULL;
2038 
2039  FOR_INV_PREPARE(op, arrow) {
2040  if (arrow->type == CONTAINER
2041  && arrow->race == type
2042  && QUERY_FLAG(arrow, FLAG_APPLIED)) {
2043  i = 0;
2044  ntmp = find_better_arrow(arrow, target, type, &i);
2045  if (i > betterby) {
2046  tmp = ntmp;
2047  betterby = i;
2048  }
2049  } else if (arrow->type == ARROW && arrow->race == type) {
2050  /* always prefer assassination/slaying */
2051  if (target->race != NULL
2052  && arrow->slaying != NULL
2053  && strstr(arrow->slaying, target->race)) {
2054  if (arrow->attacktype&AT_DEATH) {
2055  if (better)
2056  *better = 100;
2057  return arrow;
2058  } else {
2059  tmp = arrow;
2060  betterby = (arrow->magic+arrow->stats.dam)*2;
2061  }
2062  } else {
2063  for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) {
2064  attacktype = 1<<attacknum;
2065  if ((arrow->attacktype&attacktype) && (target->arch->clone.resist[attacknum]) < 0)
2066  if (((arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100) > betterby) {
2067  tmp = arrow;
2068  betterby = (arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100;
2069  }
2070  }
2071  if ((2+arrow->magic+arrow->stats.dam) > betterby) {
2072  tmp = arrow;
2073  betterby = 2+arrow->magic+arrow->stats.dam;
2074  }
2075  if (arrow->title && (1+arrow->magic+arrow->stats.dam) > betterby) {
2076  tmp = arrow;
2077  betterby = 1+arrow->magic+arrow->stats.dam;
2078  }
2079  }
2080  }
2081  } FOR_INV_FINISH();
2082  if (tmp == NULL)
2083  return find_arrow(op, type);
2084 
2085  if (better)
2086  *better = betterby;
2087  return tmp;
2088 }
2089 
2102 static object *pick_arrow_target(object *op, const char *type, int dir) {
2103  object *tmp = NULL;
2104  mapstruct *m;
2105  int i, mflags, found, number;
2106  int16_t x, y;
2107 
2108  if (op->map == NULL)
2109  return find_arrow(op, type);
2110 
2111  /* do a dex check */
2112  number = (die_roll(2, 40, op, PREFER_LOW)-2)/2;
2113  if (number > (op->stats.Dex+(op->chosen_skill ? op->chosen_skill->level : op->level)))
2114  return find_arrow(op, type);
2115 
2116  m = op->map;
2117  x = op->x;
2118  y = op->y;
2119 
2120  /* find the first target */
2121  for (i = 0, found = 0; i < 20; i++) {
2122  x += freearr_x[dir];
2123  y += freearr_y[dir];
2124  mflags = get_map_flags(m, &m, x, y, &x, &y);
2125  if (mflags&P_OUT_OF_MAP || mflags&P_BLOCKSVIEW) {
2126  tmp = NULL;
2127  break;
2128  } else if (GET_MAP_MOVE_BLOCK(m, x, y) == MOVE_FLY_LOW) {
2129  /* This block presumes arrows and the like are MOVE_FLY_SLOW -
2130  * perhaps a bad assumption.
2131  */
2132  tmp = NULL;
2133  break;
2134  }
2135  if (mflags&P_IS_ALIVE) {
2136  FOR_MAP_PREPARE(m, x, y, tmp2)
2137  if (QUERY_FLAG(tmp2, FLAG_ALIVE)) {
2138  tmp = tmp2;
2139  found++;
2140  break;
2141  }
2142  FOR_MAP_FINISH();
2143  if (found)
2144  break;
2145  }
2146  }
2147  if (tmp == NULL)
2148  return find_arrow(op, type);
2149 
2150  return find_better_arrow(op, HEAD(tmp), type, NULL);
2151 }
2152 
2171 int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy) {
2172  object *bow;
2173  tag_t tag;
2174  int bowspeed, mflags;
2175  mapstruct *m;
2176 
2177  if (!dir) {
2179  "You can't shoot yourself!");
2180  return 0;
2181  }
2182  if (op->type == PLAYER)
2183  bow = op->contr->ranges[range_bow];
2184  else {
2185  /* Don't check for applied - monsters don't apply bows - in that way, they
2186  * don't need to switch back and forth between bows and weapons.
2187  */
2188  bow = object_find_by_type(op, BOW);
2189  if (!bow) {
2190  LOG(llevError, "Range: bow without activated bow (%s).\n", op->name);
2191  return 0;
2192  }
2193  }
2194  if (!bow->race || !bow->skill) {
2196  "Your %s is broken.",
2197  bow->name);
2198  return 0;
2199  }
2200 
2201  bowspeed = bow->stats.sp+get_dex_bonus(op->stats.Dex);
2202 
2203  /* penalize ROF for bestarrow */
2204  if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
2205  bowspeed -= get_dex_bonus(op->stats.Dex)+5;
2206  if (bowspeed < 1)
2207  bowspeed = 1;
2208 
2209  if (arrow == NULL) {
2210  arrow = find_arrow(op, bow->race);
2211  if (arrow == NULL) {
2212  if (op->type == PLAYER)
2215  "You have no %s left.",
2216  bow->race);
2217  /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
2218  else
2220  return 0;
2221  }
2222  }
2223  mflags = get_map_flags(op->map, &m, sx, sy, &sx, &sy);
2224  if (mflags&P_OUT_OF_MAP) {
2225  return 0;
2226  }
2227  if (GET_MAP_MOVE_BLOCK(m, sx, sy)&MOVE_FLY_LOW) {
2228  return 0;
2229  }
2230 
2231  /* this should not happen, but sometimes does */
2232  if (arrow->nrof == 0) {
2233  object_remove(arrow);
2235  return 0;
2236  }
2237 
2238  arrow = object_split(arrow, 1, NULL, 0);
2239  if (arrow == NULL) {
2241  "You have no %s left.",
2242  bow->race);
2243  return 0;
2244  }
2245  object_set_owner(arrow, op);
2246  if (arrow->skill)
2247  free_string(arrow->skill);
2248  arrow->skill = add_refcount(bow->skill);
2249 
2250  arrow->direction = dir;
2251 
2252  if (op->type == PLAYER) {
2253  op->speed_left = 0.01-(float)FABS(op->speed)*100/bowspeed;
2254  fix_object(op);
2255  }
2256 
2257  if (bow->anim_suffix != NULL)
2258  apply_anim_suffix(op, bow->anim_suffix);
2259 
2260 /* SET_ANIMATION(arrow, arrow->direction);*/
2261  object_update_turn_face(arrow);
2262  arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
2263  arrow->stats.hp = arrow->stats.dam;
2264  arrow->stats.grace = arrow->attacktype;
2265  if (arrow->slaying != NULL)
2266  arrow->spellarg = strdup_local(arrow->slaying);
2267 
2268  /* Note that this was different for monsters - they got their level
2269  * added to the damage. I think the strength bonus is more proper.
2270  */
2271 
2272  arrow->stats.dam += (QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))
2273  +bow->stats.dam
2274  +bow->magic
2275  +arrow->magic;
2276 
2277  /* update the speed */
2278  arrow->speed = (float)((QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))+bow->magic+arrow->magic)/5.0
2279  +(float)bow->stats.dam/7.0;
2280 
2281  if (arrow->speed < 1.0)
2282  arrow->speed = 1.0;
2283  object_update_speed(arrow);
2284  arrow->speed_left = 0;
2285 
2286  if (op->type == PLAYER) {
2287  /* we don't want overflows of wc (sint), so cap the value - mod and pl should be subtracted */
2288  int mod = bow->magic
2289  +arrow->magic
2290  +get_dex_bonus(op->stats.Dex)
2291  +get_thaco_bonus(op->stats.Str)
2292  +arrow->stats.wc
2293  +bow->stats.wc
2294  -wc_mod;
2295  int plmod = (op->chosen_skill ? op->chosen_skill->level : op->level);
2296  if (plmod+mod > 140)
2297  plmod = 140-mod;
2298  else if (plmod+mod < -100)
2299  plmod = -100-mod;
2300  arrow->stats.wc = 20-(int8_t)plmod-(int8_t)mod;
2301 
2302  arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
2303  } else {
2304  arrow->stats.wc = op->stats.wc
2305  -bow->magic
2306  -arrow->magic
2307  -arrow->stats.wc
2308  +wc_mod;
2309 
2310  arrow->level = op->level;
2311  }
2312  if (arrow->attacktype == AT_PHYSICAL)
2313  arrow->attacktype |= bow->attacktype;
2314  if (bow->slaying != NULL)
2315  arrow->slaying = add_string(bow->slaying);
2316 
2317  /* If move_type is ever changed, monster.c:monster_use_bow() needs to be changed too. */
2318  arrow->move_type = MOVE_FLY_LOW;
2319  arrow->move_on = MOVE_FLY_LOW|MOVE_WALK;
2320 
2321  tag = arrow->count;
2322  object_insert_in_map_at(arrow, m, op, 0, sx, sy);
2323 
2324  if (!object_was_destroyed(arrow, tag)) {
2325  play_sound_map(SOUND_TYPE_ITEM, arrow, arrow->direction, "fire");
2326  ob_process(arrow);
2327  }
2328 
2329  return 1;
2330 }
2331 
2342 static int similar_direction(int a, int b) {
2343  /* shortcut the obvious */
2344  if (a == b)
2345  return 1;
2346  /* Made this cleaner using modulus instead of a switch statement
2347  * We only needed the direction and the two adjacent to it
2348  * (8 is adjacent to 1 here) to return true, so a - 1, a, and a + 1
2349  * are the three directions that get "similar" affirmed.
2350  * -- Daniel Hawkins 2015-05-28
2351  */
2352  // The last one for the offset is added afterwards so we get
2353  // 1-8 instead of 0-7 (specifically, 0 becomes 8 without changing
2354  // the other values).
2355  if ((a % 8) + 1 == b || (a + 6 % 8) + 1 == b)
2356  return 1;
2357  return 0;
2358 }
2359 
2376 static int player_fire_bow(object *op, int dir) {
2377  int ret = 0, wcmod = 0;
2378 
2379  if (op->contr->bowtype == bow_bestarrow) {
2380  ret = fire_bow(op, pick_arrow_target(op, op->contr->ranges[range_bow]->race, dir), dir, 0, op->x, op->y);
2381  } else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) {
2382  if (!similar_direction(dir, op->contr->bowtype-bow_n+1))
2383  wcmod = -1;
2384  ret = fire_bow(op, NULL, op->contr->bowtype-bow_n+1, wcmod, op->x, op->y);
2385  } else if (op->contr->bowtype == bow_threewide) {
2386  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2387  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir+2)], op->y+freearr_y[absdir(dir+2)]);
2388  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir-2)], op->y+freearr_y[absdir(dir-2)]);
2389  } else if (op->contr->bowtype == bow_spreadshot) {
2390  ret |= fire_bow(op, NULL, dir, 0, op->x, op->y);
2391  ret |= fire_bow(op, NULL, absdir(dir-1), -5, op->x, op->y);
2392  ret |= fire_bow(op, NULL, absdir(dir+1), -5, op->x, op->y);
2393  } else {
2394  /* Simple case */
2395  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2396  }
2397  return ret;
2398 }
2399 
2412 static void fire_misc_object(object *op, int dir) {
2413  object *item;
2414  char name[MAX_BUF];
2415 
2416  item = op->contr->ranges[range_misc];
2417  if (!item) {
2419  "You have no range item readied.");
2420  return;
2421  }
2422  if (!item->inv) {
2423  LOG(llevError, "Object %s lacks a spell\n", item->name);
2424  return;
2425  }
2426  if (item->type == WAND) {
2427  if (item->stats.food <= 0) {
2428  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2429  query_base_name(item, 0, name, MAX_BUF);
2431  "The %s goes poof.",
2432  name);
2433  return;
2434  }
2435  } else if (item->type == ROD) {
2436  if (item->stats.hp < SP_level_spellpoint_cost(item, item->inv, SPELL_HIGHEST)) {
2437  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2438  query_base_name(item, 0, name, MAX_BUF);
2440  "The %s whines for a while, but nothing happens.",
2441  name);
2442  return;
2443  }
2444  }
2445 
2446  if (cast_spell(op, item, dir, item->inv, NULL)) {
2447  SET_FLAG(op, FLAG_BEEN_APPLIED); /* You now know something about it */
2448  if (item->type == WAND) {
2449  drain_wand_charge(item);
2450  } else if (item->type == ROD) {
2451  drain_rod_charge(item);
2452  }
2453  }
2454 }
2455 
2464 void fire(object *op, int dir) {
2465 
2466  /* check for loss of invisiblity/hide */
2467  if (action_makes_visible(op))
2468  make_visible(op);
2469 
2470  switch (op->contr->shoottype) {
2471  case range_none:
2472  return;
2473 
2474  case range_bow:
2475  player_fire_bow(op, dir);
2476  return;
2477 
2478  case range_magic: /* Casting spells */
2479  cast_spell(op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL);
2480  return;
2481 
2482  case range_misc:
2483  fire_misc_object(op, dir);
2484  return;
2485 
2486  case range_golem: /* Control summoned monsters from scrolls */
2487  if (op->contr->ranges[range_golem] == NULL
2488  || op->contr->golem_count != op->contr->ranges[range_golem]->count) {
2489  op->contr->ranges[range_golem] = NULL;
2490  op->contr->shoottype = range_none;
2491  op->contr->golem_count = 0;
2492  } else
2494  return;
2495 
2496  case range_skill:
2497  if (!op->chosen_skill) {
2498  if (op->type == PLAYER)
2500  "You have no applicable skill to use.");
2501  return;
2502  }
2503  (void)do_skill(op, op, op->chosen_skill, dir, NULL);
2504  return;
2505 
2506  case range_builder:
2507  apply_map_builder(op, dir);
2508  return;
2509 
2510  default:
2512  "Illegal shoot type.");
2513  return;
2514  }
2515 }
2516 
2536 object *find_key(object *pl, object *container, object *door) {
2537  object *tmp, *key;
2538 
2539  /* Should not happen, but sanity checking is never bad */
2540  if (container->inv == NULL)
2541  return NULL;
2542 
2543  /* First, lets try to find a key in the top level inventory */
2544  tmp = NULL;
2545  if (door->type == DOOR) {
2546  int flag = FLAG_UNPAID;
2547  tmp = object_find_by_type_without_flags(container, KEY, &flag, 1);
2548  }
2549  /* For sanity, we should really check door type, but other stuff
2550  * (like containers) can be locked with special keys
2551  */
2552  if (!tmp && door->slaying != NULL) {
2553  tmp = object_find_by_type_and_slaying(container, SPECIAL_KEY, door->slaying);
2554  }
2555  /* No key found - lets search inventories now */
2556  /* If we find and use a key in an inventory, return at that time.
2557  * otherwise, if we search all the inventories and still don't find
2558  * a key, return
2559  */
2560  if (!tmp) {
2561  FOR_INV_PREPARE(container, tmp) {
2562  /* No reason to search empty containers */
2563  if (tmp->type == CONTAINER && tmp->inv) {
2564  key = find_key(pl, tmp, door);
2565  if (key != NULL)
2566  return key;
2567  }
2568  } FOR_INV_FINISH();
2569  return NULL;
2570  }
2571  /* We get down here if we have found a key. Now if its in a container,
2572  * see if we actually want to use it
2573  */
2574  if (pl != container) {
2575  /* Only let players use keys in containers */
2576  if (!pl->contr)
2577  return NULL;
2578  /* cases where this fails:
2579  * If we only search the player inventory, return now since we
2580  * are not in the players inventory.
2581  * If the container is not active, return now since only active
2582  * containers can be used.
2583  * If we only search keyrings and the container does not have
2584  * a race/isn't a keyring.
2585  * No checking for all containers - to fall through past here,
2586  * inv must have been an container and must have been active.
2587  *
2588  * Change the color so that the message doesn't disappear with
2589  * all the others.
2590  */
2591  if (pl->contr->usekeys == key_inventory
2592  || !QUERY_FLAG(container, FLAG_APPLIED)
2593  || (pl->contr->usekeys == keyrings && (!container->race || strcmp(container->race, "keys")))) {
2594  char name_tmp[MAX_BUF], name_cont[MAX_BUF];
2595 
2596  query_name(tmp, name_tmp, MAX_BUF);
2597  query_name(container, name_cont, MAX_BUF);
2600  "The %s in your %s vibrates as you approach the door",
2601  name_tmp, name_cont);
2602  return NULL;
2603  }
2604  }
2605  return tmp;
2606 }
2607 
2618 static int player_attack_door(object *op, object *door) {
2619  /* If its a door, try to find a use a key. If we do destroy the door,
2620  * might as well return immediately as there is nothing more to do -
2621  * otherwise, we fall through to the rest of the code.
2622  */
2623  object *key = find_key(op, op, door);
2624 
2625  assert(door->type == DOOR || door->type == LOCKED_DOOR);
2626 
2627  /* IF we found a key, do some extra work */
2628  if (key) {
2629  char name[HUGE_BUF];
2630 
2631  play_sound_map(SOUND_TYPE_GROUND, door, 0, "open");
2632  if (action_makes_visible(op))
2633  make_visible(op);
2634  if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
2635  spring_trap(door->inv, op);
2636 
2637  query_short_name(key, name, HUGE_BUF);
2640  "You open the door with the %s",
2641  name);
2642 
2643  if (door->type == DOOR)
2644  remove_door(door);
2645  else
2646  remove_locked_door(door); /* remove door without violence ;-) */
2647 
2648  /* Do this after we print the message */
2649  object_decrease_nrof_by_one(key); /* Use up one of the keys */
2650 
2651  return 1; /* Nothing more to do below */
2652 
2653  }
2654 
2655  if (door->type == LOCKED_DOOR) {
2656  /* Might as well return now - no other way to open this */
2658  door->msg);
2659  return 1;
2660  }
2661 
2662  if (door->type == DOOR && op->contr && !op->contr->run_on) {
2663  /* Player so try to pick the door */
2664  object *lock = find_skill_by_name(op, "lockpicking");
2665  if (lock) {
2666  /* Even if the lockpicking failed, don't go on moving, player should explicitely attack or run
2667  * to bash the door. */
2668  do_skill(op, op, lock, op->facing, NULL);
2669  return 1;
2670  }
2671  }
2672 
2673  return 0;
2674 }
2675 
2689 void move_player_attack(object *op, int dir) {
2690  object *mon, *tpl, *mon_owner;
2691  int16_t nx, ny;
2692  int on_battleground;
2693  mapstruct *m;
2694 
2695  if (op->contr->transport)
2696  tpl = op->contr->transport;
2697  else
2698  tpl = op;
2699  assert(tpl->map != NULL); // op must be on a map in order to move it
2700  nx = freearr_x[dir]+tpl->x;
2701  ny = freearr_y[dir]+tpl->y;
2702 
2703  on_battleground = op_on_battleground(tpl, NULL, NULL, NULL);
2704 
2705  // Temporarily store the map we are on before movement.
2706  mapstruct *bef = tpl->map;
2707 
2708  /* If braced, or can't move to the square, and it is not out of the
2709  * map, attack it. Note order of if statement is important - don't
2710  * want to be calling move_ob if braced, because move_ob will move the
2711  * player. This is a pretty nasty hack, because if we could
2712  * move to some space, it then means that if we are braced, we should
2713  * do nothing at all. As it is, if we are braced, we go through
2714  * quite a bit of processing. However, it probably is less than what
2715  * move_ob uses.
2716  */
2717  if ((op->contr->braced || !move_ob(tpl, dir, tpl)) && !out_of_map(tpl->map, nx, ny)) {
2718  if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2719  m = get_map_from_coord(tpl->map, &nx, &ny);
2720  if (!m)
2721  return; /* Don't think this should happen */
2722  } else
2723  m = tpl->map;
2724 
2725  if (GET_MAP_OB(m, nx, ny) == NULL) {
2726  /* LOG(llevError, "player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n");*/
2727  return;
2728  }
2729 
2730  mon = NULL;
2731  /* Go through all the objects, and find ones of interest. Only stop if
2732  * we find a monster - that is something we know we want to attack.
2733  * if its a door or barrel (can roll) see if there may be monsters
2734  * on the space
2735  */
2736  FOR_MAP_PREPARE(m, nx, ny, tmp) {
2737  if (tmp == op) {
2738  continue;
2739  }
2740  if (QUERY_FLAG(tmp, FLAG_ALIVE)) {
2741  mon = tmp;
2742  /* Gros: Objects like (pass-through) doors are alive, but haven't
2743  * their monster flag set - so this is a good way attack real
2744  * monsters in priority.
2745  */
2746  if (QUERY_FLAG(tmp, FLAG_MONSTER))
2747  break;
2748  }
2749  if (tmp->type == LOCKED_DOOR || QUERY_FLAG(tmp, FLAG_CAN_ROLL))
2750  mon = tmp;
2751  } FOR_MAP_FINISH();
2752 
2753  if (mon == NULL) /* This happens anytime the player tries to move */
2754  return; /* into a wall */
2755 
2756  mon = HEAD(mon);
2757  if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2758  if (player_attack_door(op, mon))
2759  return;
2760 
2761  /* The following deals with possibly attacking peaceful
2762  * or friendly creatures. Basically, all players are considered
2763  * unaggressive. If the moving player has peaceful set, then the
2764  * object should be pushed instead of attacked. It is assumed that
2765  * if you are braced, you will not attack friends accidently,
2766  * and thus will not push them.
2767  */
2768 
2769  /* If the creature is a pet, push it even if the player is not
2770  * peaceful. Our assumption is the creature is a pet if the
2771  * player owns it and it is either friendly or unaggressive.
2772  */
2773  mon_owner = object_get_owner(mon);
2774  if ((op->type == PLAYER)
2775  && (mon_owner == op || (mon_owner != NULL && mon_owner->type == PLAYER && mon_owner->contr->party != NULL && mon_owner->contr->party == op->contr->party))
2776  && (QUERY_FLAG(mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))) {
2777  /* If we're braced, we don't want to switch places with it */
2778  if (op->contr->braced)
2779  return;
2780  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2781  (void)push_ob(mon, dir, op);
2782  if (op->contr->tmp_invis || op->hide)
2783  make_visible(op);
2784  return;
2785  }
2786 
2787  /* in certain circumstances, you shouldn't attack friendly
2788  * creatures. Note that if you are braced, you can't push
2789  * someone, but put it inside this loop so that you won't
2790  * attack them either.
2791  */
2792  if ((mon->type == PLAYER || mon->enemy != op)
2793  && (mon->type == PLAYER || QUERY_FLAG(mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG(mon, FLAG_FRIENDLY))
2794  && (op->contr->peaceful && !on_battleground)) {
2795  if (!op->contr->braced) {
2796  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2797  (void)push_ob(mon, dir, op);
2798  } else {
2800  "You withhold your attack");
2801  }
2802  if (op->contr->tmp_invis || op->hide)
2803  make_visible(op);
2804  }
2805 
2806  /* If the object is a boulder or other rollable object, then
2807  * roll it if not braced. You can't roll it if you are braced.
2808  */
2809  else if (QUERY_FLAG(mon, FLAG_CAN_ROLL) && (!op->contr->braced)) {
2810  recursive_roll(mon, dir, op);
2811  if (action_makes_visible(op))
2812  make_visible(op);
2813 
2814  /* Any generic living creature. Including things like doors.
2815  * Way it works is like this: First, it must have some hit points
2816  * and be living. Then, it must be one of the following:
2817  * 1) Not a player, 2) A player, but of a different party. Note
2818  * that party_number -1 is no party, so attacks can still happen.
2819  */
2820  } else if ((mon->stats.hp >= 0)
2821  && QUERY_FLAG(mon, FLAG_ALIVE)
2822  && ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) {
2823  /* If the player hasn't hit something this tick, and does
2824  * so, give them speed boost based on weapon speed. Doing
2825  * it here is better than process_players2, which basically
2826  * incurred a 1 tick offset.
2827  */
2828  if (op->weapon_speed_left < 0) {
2829  op->speed_left = -0.01;
2830  return;
2831  }
2832  op->weapon_speed_left -= 1.0;
2833 
2834  skill_attack(mon, op, 0, NULL, NULL);
2835 
2836  /* If attacking another player, that player gets automatic
2837  * hitback, and doesn't loose luck either.
2838  * Disable hitback on the battleground or if the target is
2839  * the wiz.
2840  */
2841  if (mon->type == PLAYER
2842  && mon->stats.hp >= 0
2843  && !mon->contr->has_hit
2844  && !on_battleground
2845  && !QUERY_FLAG(mon, FLAG_WIZ)) {
2846  short luck = mon->stats.luck;
2847  mon->contr->has_hit = 1;
2848  skill_attack(op, mon, 0, NULL, NULL);
2849  mon->stats.luck = luck;
2850  }
2851  if (action_makes_visible(op))
2852  make_visible(op);
2853  }
2854  } /* if player should attack something */
2855  else if (bef != tpl->map) {
2856  player_map_change_common(op, bef, tpl->map);
2857  }
2858 }
2859 
2866 static void update_transport_block(object *transport, int dir) {
2867  object *part;
2868  int sx, sy, x, y;
2869 
2870  object_get_multi_size(transport, &sx, &sy, NULL, NULL);
2871  assert(sx == sy);
2872 
2873  if (dir == 1 || dir == 5) {
2874  part = transport;
2875  for (y = 0; y <= sy; y++) {
2876  for (x = 0; x < sx; x++) {
2877  part->move_type = transport->move_type;
2878  part = part->more;
2879  }
2880  part->move_type = 0;
2881  part = part->more;
2882  }
2883  } else if (dir == 3 || dir == 7) {
2884  part = transport;
2885  for (y = 0; y < sy; y++) {
2886  for (x = 0; x <= sx; x++) {
2887  part->move_type = transport->move_type;
2888  part = part->more;
2889  }
2890  }
2891  while (part) {
2892  part->move_type = 0;
2893  part = part->more;
2894  }
2895  } else {
2896  for (part = transport; part; part = part->more) {
2897  part->move_type = transport->move_type;
2898  }
2899  }
2900 }
2901 
2911 static int turn_one_transport(object *transport, object *captain, int dir) {
2912  int x, y, scroll_dir = 0;
2913 
2914  assert(transport->type == TRANSPORT);
2915 
2916  x = transport->x;
2917  y = transport->y;
2918 
2919  if (transport->direction == 1 && dir == 8) {
2920  x--;
2921  } else if (transport->direction == 2 && dir == 3) {
2922  y++;
2923  } else if (transport->direction == 3 && dir == 2) {
2924  y--;
2925  } else if (transport->direction == 5 && dir == 6) {
2926  x--;
2927  } else if (transport->direction == 6 && dir == 5) {
2928  x++;
2929  } else if (transport->direction == 7 && dir == 8) {
2930  y--;
2931  } else if (transport->direction == 8 && dir == 7) {
2932  y++;
2933  } else if (transport->direction == 8 && dir == 1) {
2934  x++;
2935  }
2936 
2937  update_transport_block(transport, dir);
2938  object_remove(transport);
2939  if (ob_blocked(transport, transport->map, x, y)) {
2940  update_transport_block(transport, transport->direction);
2941  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2942  return 2;
2943  }
2944 
2945  if (x != transport->x || y != transport->y) {
2946 /* assert(scroll_dir != 0);*/
2947 
2948  FOR_INV_PREPARE(transport, pl) {
2949  if (pl->type == PLAYER) {
2950  pl->contr->do_los = 1;
2951  pl->map = transport->map;
2952  pl->x = x;
2953  pl->y = y;
2954  esrv_map_scroll(&pl->contr->socket, freearr_x[scroll_dir], freearr_y[scroll_dir]);
2955  pl->contr->socket.update_look = 1;
2956  pl->contr->socket.look_position = 0;
2957  }
2958  } FOR_INV_FINISH();
2959  }
2960 
2961  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2962  transport->direction = dir;
2963  transport->facing = dir;
2964  animate_object(transport, dir);
2965  captain->direction = dir;
2966  return 1;
2967 }
2968 
2981 static int turn_transport(object *transport, object *captain, int dir) {
2982  assert(transport->type == TRANSPORT);
2983 
2984  if (object_get_value(transport, "turnable_transport") == NULL) {
2985  transport->direction = dir;
2986  transport->facing = dir;
2987  if (QUERY_FLAG(transport, FLAG_ANIMATE)) {
2988  animate_object(transport, dir);
2989  }
2990  captain->direction = dir;
2991  return 0;
2992  }
2993 
2994  if (transport->direction == dir)
2995  return 0;
2996 
2997  if (absdir(transport->direction-dir) > 2)
2998  return turn_one_transport(transport, captain, absdir(transport->direction+1));
2999  else
3000  return turn_one_transport(transport, captain, absdir(transport->direction-1));
3001 }
3002 
3014 int move_player(object *op, int dir) {
3015  object *transport = op->contr->transport; //< Transport player is in
3016 
3017  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
3018  return 0;
3019 
3020  /* Sanity check: make sure dir is valid */
3021  if ((dir < 0) || (dir >= 9)) {
3022  LOG(llevError, "move_player: invalid direction %d\n", dir);
3023  return 0;
3024  }
3025 
3026  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
3027  dir = get_randomized_dir(dir);
3028 
3029  op->facing = dir;
3030 
3031  if (transport) {
3032  /* transport->contr is set up for the person in charge of the boat.
3033  * if that isn't this person, he can't steer it, etc
3034  */
3035  if (transport->contr != op->contr)
3036  return 0;
3037 
3038  /* Transport is out of movement. But update dir so it at least
3039  * will point in the same direction if player is running.
3040  */
3041  if (transport->speed_left < 0.0) {
3042  return 0;
3043  }
3044  /* Remove transport speed. Give player just a little speed -
3045  * enough so that they will get an action again quickly.
3046  */
3047  transport->speed_left -= 1.0;
3048  if (op->speed_left < 0.0)
3049  op->speed_left = -0.01;
3050 
3051  int turn = turn_transport(transport, op, dir);
3052  if (turn != 0)
3053  return 0;
3054  } else {
3055  if (op->hide) {
3056  do_hidden_move(op);
3057  }
3058 
3059  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
3060  * and leave us with state = 0, which we don't want to change again. */
3061  op->state++; /* player moved, so change animation. */
3062  animate_object(op, op->facing);
3063  }
3064 
3065  if (op->contr->fire_on) {
3066  fire(op, dir);
3067  } else
3068  move_player_attack(op, dir);
3069 
3070  int pick = check_pick(op);
3071 
3072  /* Add special check for newcs players and fire on - this way, the
3073  * server can handle repeat firing.
3074  */
3075  if (op->contr->fire_on || (op->contr->run_on && pick != 0)) {
3076  op->direction = dir;
3077  } else {
3078  op->direction = 0;
3079  }
3080  return 0;
3081 }
3082 
3093 int face_player(object *op, int dir) {
3094  object *transport = op->contr->transport; //< Transport player is in
3095 
3096  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
3097  return 0;
3098 
3099  /* Sanity check: make sure dir is valid */
3100  if ((dir < 0) || (dir >= 9)) {
3101  LOG(llevError, "move_player: invalid direction %d\n", dir);
3102  return 0;
3103  }
3104 
3105  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
3106  dir = get_randomized_dir(dir);
3107 
3108  op->facing = dir;
3109 
3110  if (transport) {
3111  /* transport->contr is set up for the person in charge of the boat.
3112  * if that isn't this person, he can't steer it, etc
3113  */
3114  if (transport->contr != op->contr)
3115  return 0;
3116 
3117  turn_transport(transport, op, dir);
3118  } else {
3119  if (op->hide) {
3120  do_hidden_move(op);
3121  }
3122 
3123  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
3124  * and leave us with state = 0, which we don't want to change again. */
3125  op->state++; /* player moved, so change animation. */
3126  animate_object(op, op->facing);
3127  }
3128 
3129  /* Add special check for newcs players and fire on - this way, the
3130  * server can handle repeat firing.
3131  */
3132  if (op->contr->fire_on || op->contr->run_on) {
3133  op->direction = dir;
3134  } else {
3135  op->direction = 0;
3136  }
3137  return 0;
3138 }
3139 
3152 int handle_newcs_player(object *op) {
3153  if (op->contr->hidden) {
3154  op->invisible = 1000;
3155  /* the socket code flashes the player visible/invisible
3156  * depending on the value if invisible, so we need to
3157  * alternate it here for it to work correctly.
3158  */
3159  if (pticks&2)
3160  op->invisible--;
3161  } else if (op->invisible && !(QUERY_FLAG(op, FLAG_MAKE_INVIS))) {
3162  op->invisible--;
3163  if (!op->invisible) {
3164  make_visible(op);
3166  "Your invisibility spell runs out.");
3167  }
3168  }
3169 
3170  if (QUERY_FLAG(op, FLAG_SCARED)) {
3171  flee_player(op);
3172  /* If player is still scared, that is his action for this tick */
3173  if (QUERY_FLAG(op, FLAG_SCARED)) {
3174  op->speed_left--;
3175  return 0;
3176  }
3177  }
3178 
3179  /* I've been seeing crashes where the golem has been destroyed, but
3180  * the player object still points to the defunct golem. The code that
3181  * destroys the golem looks correct, and it doesn't always happen, so
3182  * put this in a a workaround to clean up the golem pointer.
3183  */
3184  if (op->contr->ranges[range_golem]
3186  op->contr->ranges[range_golem] = NULL;
3187  op->contr->golem_count = 0;
3188  }
3189 
3190  /*
3191  * If the player has been paralyzed, we unmark the flag and give a message to the player
3192  */
3193  if (QUERY_FLAG(op, FLAG_PARALYZED)) {
3195  // TODO: Is this check necessary? We are in player.c, after all.
3196  if (op->type == PLAYER)
3197  {
3199  "You can stretch your stiff joints once more.");
3200  }
3201  }
3202 
3203  if (op->direction && (op->contr->run_on || op->contr->fire_on)) {
3204  /* All move commands take 1 tick, at least for now */
3205  op->speed_left--;
3206 
3207  /* Instead of all the stuff below, let move_player take care
3208  * of it. Also, some of the skill stuff is only put in
3209  * there, as well as the confusion stuff.
3210  */
3211  move_player(op, op->direction);
3212  if (op->speed_left > 0)
3213  return 1;
3214  else
3215  return 0;
3216  }
3217  return 0;
3218 }
3219 
3230 static int save_life(object *op) {
3231  object *tmp;
3232 
3233  if (!QUERY_FLAG(op, FLAG_LIFESAVE))
3234  return 0;
3235 
3237  if (tmp != NULL) {
3238  char name[MAX_BUF];
3239 
3240  query_name(tmp, name, MAX_BUF);
3241  play_sound_map(SOUND_TYPE_ITEM, tmp, 0, "evaporate");
3243  "Your %s vibrates violently, then evaporates.",
3244  name);
3245  object_remove(tmp);
3248  if (op->stats.hp < 0)
3249  op->stats.hp = op->stats.maxhp;
3250  if (op->stats.food < 0)
3251  op->stats.food = MAX_FOOD;
3252  fix_object(op);
3253  return 1;
3254  }
3255  LOG(llevError, "Error: LIFESAVE set without applied object.\n");
3257  enter_player_savebed(op); /* bring him home. */
3258  return 0;
3259 }
3260 
3273 void remove_unpaid_objects(object *op, object *env, int free_items) {
3275  if (QUERY_FLAG(op, FLAG_UNPAID)) {
3276  object_remove(op);
3277  if (free_items)
3279  else
3280  object_insert_in_map_at(op, env->map, NULL, 0, env->x, env->y);
3281  } else if (op->inv)
3282  remove_unpaid_objects(op->inv, env, free_items);
3284 }
3285 
3303 static const char *gravestone_text(object *op, char *buf2, int len) {
3304  char buf[MAX_BUF];
3305  time_t now = time(NULL);
3306 
3307  strncpy(buf2, " R.I.P.\n\n", len);
3308  if (op->type == PLAYER)
3309  snprintf(buf, sizeof(buf), "%s the %s\n", op->name, op->contr->title);
3310  else
3311  snprintf(buf, sizeof(buf), "%s\n", op->name);
3312  strncat(buf2, " ", 20-strlen(buf)/2);
3313  strncat(buf2, buf, len-strlen(buf2)-1);
3314  if (op->type == PLAYER)
3315  snprintf(buf, sizeof(buf), "who was in level %d when killed\n", op->level);
3316  else
3317  snprintf(buf, sizeof(buf), "who was in level %d when died.\n\n", op->level);
3318  strncat(buf2, " ", 20-strlen(buf)/2);
3319  strncat(buf2, buf, len-strlen(buf2)-1);
3320  if (op->type == PLAYER) {
3321  snprintf(buf, sizeof(buf), "by %s.\n\n", op->contr->killer);
3322  strncat(buf2, " ", 21-strlen(buf)/2);
3323  strncat(buf2, buf, len-strlen(buf2)-1);
3324  }
3325  strftime(buf, MAX_BUF, "%b %d %Y\n", localtime(&now));
3326  strncat(buf2, " ", 20-strlen(buf)/2);
3327  strncat(buf2, buf, len-strlen(buf2)-1);
3328  return buf2;
3329 }
3330 
3338 void do_some_living(object *op) {
3339  int last_food = op->stats.food;
3340  int gen_hp, gen_sp, gen_grace;
3341  int rate_hp = 1200;
3342  int rate_sp = 2500;
3343  int rate_grace = 2000;
3344 
3345  if (op->contr->state == ST_PLAYING) {
3346  /* these next three if clauses make it possible to SLOW DOWN
3347  hp/grace/spellpoint regeneration. */
3348  if (op->contr->gen_hp >= 0)
3349  gen_hp = (op->contr->gen_hp+1)*op->stats.maxhp;
3350  else {
3351  gen_hp = op->stats.maxhp;
3352  rate_hp -= rate_hp/2*op->contr->gen_hp;
3353  }
3354  if (op->contr->gen_sp >= 0)
3355  gen_sp = (op->contr->gen_sp+1)*op->stats.maxsp;
3356  else {
3357  gen_sp = op->stats.maxsp;
3358  rate_sp -= rate_sp/2*op->contr->gen_sp;
3359  }
3360  if (op->contr->gen_grace >= 0)
3361  gen_grace = (op->contr->gen_grace+1)*op->stats.maxgrace;
3362  else {
3363  gen_grace = op->stats.maxgrace;
3364  rate_grace -= rate_grace/2*op->contr->gen_grace;
3365  }
3366 
3367  /* Regenerate Spell Points */
3368  if (op->contr->ranges[range_golem] == NULL && --op->last_sp < 0) {
3369  gen_sp = gen_sp*10/MAX(op->contr->gen_sp_armour, 10);
3370  if (op->stats.sp < op->stats.maxsp) {
3371  op->stats.sp++;
3372  /* dms do not consume food */
3373  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3374  op->stats.food--;
3375  if (op->contr->digestion < 0)
3376  op->stats.food += op->contr->digestion;
3377  else if (op->contr->digestion > 0
3378  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3379  op->stats.food = last_food;
3380  }
3381  }
3382  op->last_sp = rate_sp/(MAX(gen_sp, 20)+10);
3383  }
3384 
3385  /* Regenerate Grace */
3386  /* I altered this a little - maximum grace is only achieved through prayer -b.t.*/
3387  if (--op->last_grace < 0) {
3388  if (op->stats.grace < op->stats.maxgrace/2)
3389  op->stats.grace++; /* no penalty in food for regaining grace */
3390  op->last_grace = rate_grace/(MAX(gen_grace, 20)+10);
3391  /* wearing stuff doesn't detract from grace generation. */
3392  }
3393 
3394  /* Regenerate Hit Points (unless you are a wraith player) */
3395  if (--op->last_heal < 0 && !is_wraith_pl(op)) {
3396  if (op->stats.hp < op->stats.maxhp) {
3397  op->stats.hp++;
3398  /* dms do not consume food */
3399  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3400  op->stats.food--;
3401  if (op->contr->digestion < 0)
3402  op->stats.food += op->contr->digestion;
3403  else if (op->contr->digestion > 0
3404  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3405  op->stats.food = last_food;
3406  }
3407  }
3408  op->last_heal = rate_hp/(MAX(gen_hp, 20)+10);
3409  }
3410 
3411  /* Digestion */
3412  if (--op->last_eat < 0) {
3413  int bonus = MAX(op->contr->digestion, 0);
3414  int penalty = MAX(-op->contr->digestion, 0);
3415  if (op->contr->gen_hp > 0)
3416  op->last_eat = 25*(1+bonus)/(op->contr->gen_hp+penalty+1);
3417  else
3418  op->last_eat = 25*(1+bonus)/(penalty+1);
3419  /* dms do not consume food */
3420  if (!QUERY_FLAG(op, FLAG_WIZ))
3421  op->stats.food--;
3422  }
3423  }
3424 
3425  if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) {
3426  if (is_wraith_pl(op))
3427  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "You feel a hunger for living flesh.");
3428  /* Only allow eat if not paralyzed. Otherwise our paralyzed player is "moving" to eat.
3429  * Daniel Hawkins 2017-08-23
3430  */
3431  else if (!QUERY_FLAG(op, FLAG_PARALYZED)){
3432  object *flesh = NULL;
3433 
3434  FOR_INV_PREPARE(op, tmp) {
3435  if (!QUERY_FLAG(tmp, FLAG_UNPAID)) {
3436  if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) {
3438  "You blindly grab for a bite of food.");
3439  apply_manual(op, tmp, 0);
3440  if (op->stats.food >= 0 || op->stats.hp < 0)
3441  break;
3442  } else if (tmp->type == FLESH)
3443  flesh = tmp;
3444  } /* End if paid for object */
3445  } FOR_INV_FINISH(); /* end of for loop */
3446  /* If player is still starving, it means they don't have any food, so
3447  * eat flesh instead.
3448  */
3449  if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) {
3451  "You blindly grab for a bite of food.");
3452  apply_manual(op, flesh, 0);
3453  }
3454  } /* end not wraith and not paralyzed */
3455  else { // Print a message for when the player is starving and paralyzed
3456  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "Your stomach rumbles, but you can't reach your food.");
3457  } /* end not wraith and is paralyzed */
3458  } /* end if player is starving */
3459 
3460  if (op->stats.food < 0 && op->stats.hp > 0){
3461  // We know food < 0, so we want the absolute value of food
3462  int32_t adjust_by = MIN(-(op->stats.food), op->stats.hp);
3463  op->stats.food += adjust_by;
3464  op->stats.hp -= adjust_by;
3465  }
3466 
3467  if (!op->contr->state && !QUERY_FLAG(op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
3468  kill_player(op, NULL);
3469 }
3470 
3477 static void loot_object(object *op) {
3478  object *tmp2;
3479 
3480  if (op->container) { /* close open sack first */
3481  apply_container(op, op->container, AP_NULL);
3482  }
3483 
3484  FOR_INV_PREPARE(op, tmp) {
3485  if (tmp->invisible)
3486  continue;
3487  object_remove(tmp);
3488  tmp->x = op->x,
3489  tmp->y = op->y;
3490  if (tmp->type == CONTAINER) { /* empty container to ground */
3491  loot_object(tmp);
3492  }
3493  if (!QUERY_FLAG(tmp, FLAG_UNIQUE)
3494  && (QUERY_FLAG(tmp, FLAG_STARTEQUIP) || QUERY_FLAG(tmp, FLAG_NO_DROP) || !(RANDOM()%3))) {
3495  if (tmp->nrof > 1) {
3496  tmp2 = object_split(tmp, 1+RANDOM()%(tmp->nrof-1), NULL, 0);
3498  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3499  } else
3501  } else
3502  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3503  } FOR_INV_FINISH();
3504 }
3505 
3517 void kill_player(object *op, const object *killer) {
3518  char buf[MAX_BUF];
3519  int x, y;
3520  archetype *at;
3521  object *tmp;
3522  archetype *trophy = NULL;
3523 
3524  /* Don't die if the player's life can be saved. */
3525  if (save_life(op)) {
3526  return;
3527  }
3528 
3529  /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
3530  * in cities ONLY!!! It is very important that this doesn't get abused.
3531  * Look at op_on_battleground() for more info --AndreasV
3532  */
3533  if (op_on_battleground(op, &x, &y, &trophy)) {
3534  assert(trophy != NULL);
3536  "You have been defeated in combat!\n"
3537  "Local medics have saved your life...");
3538 
3539  /* restore player */
3540  at = find_archetype("poisoning");
3541  if (at != NULL) {
3542  tmp = arch_present_in_ob(at, op);
3543  if (tmp) {
3544  object_remove(tmp);
3547  "Your body feels cleansed");
3548  }
3549  }
3550 
3551  at = find_archetype("confusion");
3552  if (at != NULL) {
3553  tmp = arch_present_in_ob(at, op);
3554  if (tmp) {
3555  object_remove(tmp);
3558  "Your mind feels clearer");
3559  }
3560  }
3561 
3562  cure_disease(op, NULL, NULL); /* remove any disease */
3563  op->stats.hp = op->stats.maxhp;
3564  if (op->stats.food <= 0)
3565  op->stats.food = MAX_FOOD;
3566 
3567  /* create a bodypart-trophy to make the winner happy */
3568  tmp = arch_to_object(trophy);
3569  if (tmp != NULL) {
3570  snprintf(buf, sizeof(buf), "%s's %s", op->name, tmp->name);
3571  tmp->name = add_string(buf);
3572 
3573  snprintf(buf, sizeof(buf),
3574  "This %s was %s %s the %s, who was defeated at level %d by %s.\n",
3575  tmp->name, tmp->type == FLESH ? "cut off" : "taken from",
3576  op->name, op->contr->title,
3577  (int)(op->level), op->contr->killer);
3578 
3579  object_set_msg(tmp, buf);
3580  tmp->type = 0;
3581  tmp->value = 0;
3582  tmp->material = 0;
3583  tmp->materialname = NULL;
3584  object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
3585  }
3586 
3587  /* teleport defeated player to new destination*/
3588  transfer_ob(op, x, y, 0, NULL);
3589  op->contr->braced = 0;
3590  return;
3591  }
3592 
3593  /* Lauwenmark: Handle for plugin death event */
3594  if (execute_event(op, EVENT_DEATH, NULL, NULL, NULL, SCRIPT_FIX_ALL) != 0)
3595  return;
3596 
3597  /* Lauwenmark: Handle for the global death event */
3599  if (op->stats.food < 0) {
3600  snprintf(buf, sizeof(buf), "%s starved to death.", op->name);
3601  strcpy(op->contr->killer, "starvation");
3602  } else {
3603  snprintf(buf, sizeof(buf), "%s died.", op->name);
3604  }
3605  play_sound_player_only(op->contr, SOUND_TYPE_LIVING, op, 0, "death");
3606 
3607  if (settings.not_permadeth == TRUE) {
3609  } else {
3611  }
3612 }
3613 
3622 static void kill_player_not_permadeath(object *op) {
3623  int num_stats_lose;
3624  int will_kill_again;
3625  int lost_a_stat;
3626  int z;
3627  object *tmp;
3628  char buf[MAX_BUF];
3629  archetype *at;
3630 
3631  /* Basically two ways to go - remove a stat permanently, or just
3632  * make it depletion. This bunch of code deals with that aspect
3633  * of death.
3634  */
3636  /* If stat loss is permanent, lose one stat only. */
3637  /* Lower level chars don't lose as many stats because they suffer
3638  more if they do. */
3639  /* Higher level characters can afford things such as potions of
3640  restoration, or better, stat potions. So we slug them that
3641  little bit harder. */
3642  /* GD */
3644  num_stats_lose = 1;
3645  else
3646  num_stats_lose = 1+op->level/BALSL_NUMBER_LOSSES_RATIO;
3647  } else {
3648  num_stats_lose = 1;
3649  }
3650  lost_a_stat = 0;
3651 
3652  for (z = 0; z < num_stats_lose; z++) {
3654  int i;
3655 
3656  /* Pick a random stat and take a point off it. Tell the player
3657  * what he lost.
3658  */
3659  i = RANDOM()%7;
3660  change_attr_value(&(op->stats), i, -1);
3662  change_attr_value(&(op->contr->orig_stats), i, -1);
3664  draw_ext_info(NDI_UNIQUE, 0, op,
3666  lose_msg[i]);
3667  lost_a_stat = 1;
3668  } else {
3669  /* deplete a stat */
3671  if (deparch == NULL) {
3672  continue;
3673  }
3674  object *dep;
3675  int lose_this_stat;
3676  int i;
3677 
3678  i = RANDOM()%7;
3679  dep = arch_present_in_ob(deparch, op);
3680  if (!dep) {
3681  dep = arch_to_object(deparch);
3682  object_insert_in_ob(dep, op);
3683  }
3684  lose_this_stat = 1;
3686  int this_stat;
3687 
3688  /* GD */
3689  /* Get the stat that we're about to deplete. */
3690  this_stat = get_attr_value(&(dep->stats), i);
3691  if (this_stat < 0) {
3692  int loss_chance = 1+op->level/BALSL_LOSS_CHANCE_RATIO;
3693  int keep_chance = this_stat*this_stat;
3694  /* Yes, I am paranoid. Sue me. */
3695  if (keep_chance < 1)
3696  keep_chance = 1;
3697 
3698  /* There is a maximum depletion total per level. */
3699  if (this_stat < -1-op->level/BALSL_MAX_LOSS_RATIO) {
3700  lose_this_stat = 0;
3701  /* Take loss chance vs keep chance to see if we
3702  retain the stat. */
3703  } else {
3704  if (random_roll(0, loss_chance+keep_chance-1, op, PREFER_LOW) < keep_chance)
3705  lose_this_stat = 0;
3706  /* LOG(llevDebug, "Determining stat loss. Stat: %d Keep: %d Lose: %d Result: %s.\n", this_stat, keep_chance, loss_chance, lose_this_stat ? "LOSE" : "KEEP"); */
3707  }
3708  }
3709  }
3710 
3711  if (lose_this_stat) {
3712  int this_stat;
3713 
3714  this_stat = get_attr_value(&(dep->stats), i);
3715  /* We could try to do something clever like find another
3716  * stat to reduce if this fails. But chances are, if
3717  * stats have been depleted to -50, all are pretty low
3718  * and should be roughly the same, so it shouldn't make a
3719  * difference.
3720  */
3721  if (this_stat >= -50) {
3722  change_attr_value(&(dep->stats), i, -1);
3723  SET_FLAG(dep, FLAG_APPLIED);
3725  drain_msg[i]);
3726  fix_object(op);
3727  lost_a_stat = 1;
3728  }
3729  }
3730  }
3731  }
3732  /* If no stat lost, tell the player. */
3733  if (!lost_a_stat) {
3734  /* determine_god() seems to not work sometimes... why is this? Should I be using something else? GD */
3735  const char *god = determine_god(op);
3736 
3737  if (god && (strcmp(god, "none")))
3740  "For a brief moment you feel the holy presence of %s protecting you",
3741  god);
3742  else
3743  draw_ext_info(NDI_UNIQUE, 0, op,
3745  "For a brief moment you feel a holy presence protecting you.");
3746  }
3747 
3748  /* Put a gravestone up where the character 'almost' died. List the
3749  * exp loss on the stone.
3750  */
3751  at = find_archetype("gravestone");
3752  if (at != NULL) {
3753  tmp = arch_to_object(at);
3754  snprintf(buf, sizeof(buf), "%s's gravestone", op->name);
3755  FREE_AND_COPY(tmp->name, buf);
3756  snprintf(buf, sizeof(buf), "%s's gravestones", op->name);
3757  FREE_AND_COPY(tmp->name_pl, buf);
3758  snprintf(buf, sizeof(buf), "RIP\nHere rests the hero %s the %s,\n"
3759  "who was killed\n"
3760  "by %s.\n",
3761  op->name, op->contr->title,
3762  op->contr->killer);
3763  object_set_msg(tmp, buf);
3764  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3765  }
3766 
3767  /* restore player: remove any poisoning, disease and confusion the
3768  * character may be suffering.*/
3769  at = find_archetype("poisoning");
3770  if (at != NULL) {
3771  tmp = arch_present_in_ob(at, op);
3772  if (tmp) {
3773  object_remove(tmp);
3776  "Your body feels cleansed");
3777  }
3778  }
3779 
3780  at = find_archetype("confusion");
3781  if (at != NULL) {
3782  tmp = arch_present_in_ob(at, op);
3783  if (tmp) {
3784  object_remove(tmp);
3787  "Your mind feels clearer");
3788  }
3789  }
3790  cure_disease(op, NULL, NULL); /* remove any disease */
3791 
3792  /* Subtract the experience points, if we died cause of food, give
3793  * us food, and reset HP's...
3794  */
3796  if (op->stats.food < 100)
3797  op->stats.food = 900;
3798  op->stats.hp = op->stats.maxhp;
3799  op->stats.sp = MAX(op->stats.sp, op->stats.maxsp);
3800  op->stats.grace = MAX(op->stats.grace, op->stats.maxgrace);
3801 
3802  /* Check to see if the player is in a shop. IF so, then check to see if
3803  * the player has any unpaid items. If so, remove them and put them back
3804  * in the map.
3805  *
3806  * If they are not in a shop, just free the unpaid items instead of
3807  * putting them back on map.
3808  */
3809  if (shop_contains(op))
3810  remove_unpaid_objects(op->inv, op, 0);
3811  else
3812  remove_unpaid_objects(op->inv, op, 1);
3813 
3814  /* Move player to his current respawn-position (usually last savebed) */
3816 
3817  /* Save the player before inserting the force to reduce chance of abuse. */
3818  op->contr->braced = 0;
3819  op->contr->mode = 0; /* don't pick up in apartment */
3820  if ( op->contr->search_str[0] ) command_search_items(op,NULL); /* turn off search-items */
3821  save_player(op, 1);
3822 
3823  /* it is possible that the player has blown something up
3824  * at his savebed location, and that can have long lasting
3825  * spell effects. So first see if there is a spell effect
3826  * on the space that might harm the player.
3827  */
3828  will_kill_again = 0;
3829  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp)
3830  if (tmp->type == SPELL_EFFECT)
3831  will_kill_again |= tmp->attacktype;
3832  FOR_MAP_FINISH();
3833  if (will_kill_again) {
3834  object *force;
3835  int at;
3836 
3837  force = create_archetype(FORCE_NAME);
3838  /* 50 ticks should be enough time for the spell to abate */
3839  force->speed = 0.1;
3840  force->speed_left = -5.0;
3841  SET_FLAG(force, FLAG_APPLIED);
3842  for (at = 0; at < NROFATTACKS; at++) {
3843  if (will_kill_again&(1<<at))
3844  force->resist[at] = 100;
3845  }
3846  object_insert_in_ob(force, op);
3847  fix_object(op);
3848  }
3849 
3850  /* Tell the player they have died */
3852  "YOU HAVE DIED.");
3853 }
3854 
3861 static void kill_player_permadeath(object *op) {
3862  char buf[MAX_BUF];
3863  char ac_buf[MAX_BUF];
3864  int x, y;
3865  mapstruct *map;
3866  object *tmp;
3867  archetype *at;
3868 
3869  /* save the map location for corpse, gravestone*/
3870  x = op->x;
3871  y = op->y;
3872  map = op->map;
3873 
3874  party_leave(op);
3875  if (settings.set_title == TRUE)
3876  player_set_own_title(op->contr, "");
3877 
3878  /* buf should be the kill message */
3880  buf);
3881  hiscore_check(op, 0);
3882  if (op->contr->ranges[range_golem] != NULL) {
3886  op->contr->ranges[range_golem] = NULL;
3887  op->contr->golem_count = 0;
3888  }
3889  loot_object(op); /* Remove some of the items for good */
3890  object_remove(op);
3891  op->direction = 0;
3892 
3893  if (!QUERY_FLAG(op, FLAG_WAS_WIZ) && op->stats.exp) {
3894  if (settings.resurrection == TRUE) {
3895  /* save playerfile sans equipment when player dies
3896  * -then save it as player.pl.dead so that future resurrection
3897  * -type spells will work on them nicely
3898  */
3899  op->stats.hp = op->stats.maxhp;
3900  op->stats.food = MAX_FOOD;
3901 
3902  /* set the location of where the person will reappear when */
3903  /* maybe resurrection code should fix map also */
3905  sizeof(op->contr->maplevel));
3906  if (op->map != NULL)
3907  op->map = NULL;
3908  op->x = settings.emergency_x;
3909  op->y = settings.emergency_y;
3910  save_player(op, 0);
3911  op->map = map;
3912  /* please see resurrection.c: peterm */
3913  dead_player(op);
3914  } else {
3915  delete_character(op->name);
3916  }
3917  }
3918  play_again(op);
3919 
3920  /* peterm: added to create a corpse at deathsite. */
3921  at = find_archetype("corpse_pl");
3922  if (at != NULL) {
3923  tmp = arch_to_object(at);
3924  snprintf(buf, sizeof(buf), "%s", op->name);
3925  FREE_AND_COPY(tmp->name, buf);
3926  FREE_AND_COPY(tmp->name_pl, buf);
3927  tmp->level = op->level;
3928  object_set_msg(tmp, gravestone_text(op, buf, sizeof(buf)));
3929  SET_FLAG(tmp, FLAG_UNIQUE);
3930  /*
3931  * Put the account name under slaying.
3932  * Does not seem to cause weird effects, but more testing may ensure this.
3933  */
3934  snprintf(ac_buf, sizeof(ac_buf), "%s", op->contr->socket.account_name);
3935  FREE_AND_COPY(tmp->slaying, ac_buf);
3936  object_insert_in_map_at(tmp, map, NULL, 0, x, y);
3937  }
3938 }
3939 
3947 void fix_weight(void) {
3948  player *pl;
3949 
3950  for (pl = first_player; pl != NULL; pl = pl->next) {
3951  int old = pl->ob->carrying, sum = object_sum_weight(pl->ob);
3952 
3953  if (old == sum)
3954  continue;
3955  fix_object(pl->ob);
3956  LOG(llevDebug, "Fixed inventory in %s (%d -> %d)\n", pl->ob->name, old, sum);
3957  }
3958 }
3959 
3963 void fix_luck(void) {
3964  player *pl;
3965 
3966  for (pl = first_player; pl != NULL; pl = pl->next)
3967  if (!pl->ob->contr->state)
3968  change_luck(pl->ob, 0);
3969 }
3970 
3971 
3984 void cast_dust(object *op, object *throw_ob, int dir) {
3985  object *skop, *spob;
3986 
3987  skop = find_skill_by_name(op, throw_ob->skill);
3988 
3989  /* casting POTION 'dusts' is really a use_magic_item skill */
3990  if (op->type == PLAYER && throw_ob->type == POTION && !skop) {
3991  LOG(llevError, "Player %s lacks critical skill use_magic_item!\n", op->name);
3992  return;
3993  }
3994  spob = throw_ob->inv;
3995  if (op->type == PLAYER && spob)
3997  "You cast %s.",
3998  spob->name);
3999 
4000  cast_spell(op, throw_ob, dir, spob, NULL);
4001 
4002  if (!QUERY_FLAG(throw_ob, FLAG_REMOVED))
4003  object_remove(throw_ob);
4004  object_free_drop_inventory(throw_ob);
4005 }
4006 
4013 void make_visible(object *op) {
4014  op->hide = 0;
4015  op->invisible = 0;
4016  if (op->type == PLAYER) {
4017  op->contr->tmp_invis = 0;
4018  if (op->contr->invis_race)
4020  }
4022 }
4023 
4033 int is_true_undead(object *op) {
4034  if (QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
4035  return 1;
4036 
4037  if (op->type == PLAYER)
4038  FOR_INV_PREPARE(op, tmp) {
4039  if (tmp->type == 44 && tmp->stats.Wis)
4040  if (QUERY_FLAG(tmp, FLAG_UNDEAD))
4041  return 1;
4042  } FOR_INV_FINISH();
4043  return 0;
4044 }
4045 
4056 int hideability(object *ob) {
4057  int i, level = 0, mflag;
4058  int16_t x, y;
4059 
4060  if (!ob || !ob->map)
4061  return 0;
4062 
4063  /* so, on normal lighted maps, its hard to hide */
4064  level = ob->map->darkness-2;
4065 
4066  /* this also picks up whether the object is glowing.
4067  * If you carry a light on a non-dark map, its not
4068  * as bad as carrying a light on a pitch dark map
4069  */
4070  if (has_carried_lights(ob))
4071  level = -(10+(2*ob->map->darkness));
4072 
4073  /* scan through all nearby squares for terrain to hide in */
4074  for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x+freearr_x[i], y = ob->y+freearr_y[i]) {
4075  mflag = get_map_flags(ob->map, NULL, x, y, NULL, NULL);
4076  if (mflag&P_OUT_OF_MAP) {
4077  continue;
4078  }
4079  if (mflag&P_BLOCKSVIEW) /* something to hide near! */
4080  level += 2;
4081  else /* open terrain! */
4082  level -= 1;
4083  }
4084 
4085  return level;
4086 }
4087 
4097 void do_hidden_move(object *op) {
4098  int hide = 0, num = random_roll(0, 19, op, PREFER_LOW);
4099  object *skop;
4100 
4101  if (!op || !op->map)
4102  return;
4103 
4105 
4106  /* its *extremely *hard to run and sneak/hide at the same time! */
4107  if (op->type == PLAYER && op->contr->run_on) {
4108  if (!skop || num >= skop->level) {
4110  "You ran too much! You are no longer hidden!");
4111  make_visible(op);
4112  return;
4113  } else
4114  num += 20;
4115  }
4116  num += op->map->difficulty;
4117  hide = hideability(op); /* modify by terrain hidden level */
4118  num -= hide;
4119  if ((op->type == PLAYER && hide < -10)
4120  || ((op->invisible -= num) <= 0)) {
4121  make_visible(op);
4122  if (op->type == PLAYER)
4124  "You moved out of hiding! You are visible!");
4125  } else if (op->type == PLAYER && skop) {
4126  change_exp(op, calc_skill_exp(op, NULL, skop), skop->skill, 0);
4127  }
4128 }
4129 
4138 int stand_near_hostile(object *who) {
4139  int i, friendly = 0, player = 0, mflags;
4140  mapstruct *m;
4141  int16_t x, y;
4142 
4143  if (!who)
4144  return 0;
4145 
4146  if (who->type == PLAYER)
4147  player = 1;
4148  else
4149  friendly = QUERY_FLAG(who, FLAG_FRIENDLY);
4150 
4151  /* search adjacent squares */
4152  for (i = 1; i < 9; i++) {
4153  x = who->x+freearr_x[i];
4154  y = who->y+freearr_y[i];
4155  m = who->map;
4156  mflags = get_map_flags(m, &m, x, y, &x, &y);
4157  /* space must be blocked if there is a monster. If not
4158  * blocked, don't need to check this space.
4159  */
4160  if (mflags&P_OUT_OF_MAP)
4161  continue;
4162  if (OB_TYPE_MOVE_BLOCK(who, GET_MAP_MOVE_BLOCK(m, x, y)))
4163  continue;
4164 
4165  FOR_MAP_PREPARE(m, x, y, tmp) {
4166  if ((player || friendly)
4167  && QUERY_FLAG(tmp, FLAG_MONSTER)
4168  && !QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE))
4169  return 1;
4170  else if (tmp->type == PLAYER) {
4171  /*don't let a hidden DM prevent you from hiding*/
4172  if (!QUERY_FLAG(tmp, FLAG_WIZ) || tmp->contr->hidden == 0)
4173  return 1;
4174  }
4175  } FOR_MAP_FINISH();
4176  }
4177  return 0;
4178 }
4179 
4206 int player_can_view(object *pl, object *op) {
4207  rv_vector rv;
4208  int dx, dy;
4209 
4210  if (pl->type != PLAYER) {
4211  LOG(llevError, "player_can_view() called for non-player object\n");
4212  return -1;
4213  }
4214  if (!pl || !op)
4215  return 0;
4216 
4217  op = HEAD(op);
4218  if (!get_rangevector(pl, op, &rv, 0x1))
4219  return 0;
4220 
4221  /* starting with the 'head' part, lets loop
4222  * through the object and find if it has any
4223  * part that is in the los array but isnt on
4224  * a blocked los square.
4225  * we use the archetype to figure out offsets.
4226  */
4227  while (op) {
4228  dx = rv.distance_x+op->arch->clone.x;
4229  dy = rv.distance_y+op->arch->clone.y;
4230 
4231  /* only the viewable area the player sees is updated by LOS
4232  * code, so we need to restrict ourselves to that range of values
4233  * for any meaningful values.
4234  */
4235  if (FABS(dx) <= (pl->contr->socket.mapx/2)
4236  && FABS(dy) <= (pl->contr->socket.mapy/2)
4237  && !pl->contr->blocked_los[dx+(pl->contr->socket.mapx/2)][dy+(pl->contr->socket.mapy/2)])
4238  return 1;
4239  op = op->more;
4240  }
4241  return 0;
4242 }
4243 
4257 static int action_makes_visible(object *op) {
4258  if (op->invisible && QUERY_FLAG(op, FLAG_ALIVE)) {
4259  if (QUERY_FLAG(op, FLAG_MAKE_INVIS))
4260  return 0;
4261 
4262  if (op->contr && op->contr->tmp_invis == 0)
4263  return 0;
4264 
4265  /* If monsters, they should become visible */
4266  if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) {
4268  "You become %s!",
4269  op->hide ? "unhidden" : "visible");
4270  return 1;
4271  }
4272  }
4273  return 0;
4274 }
4275 
4304 int op_on_battleground(object *op, int *x, int *y, archetype **trophy) {
4305  FOR_BELOW_PREPARE(op, tmp) {
4306  if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
4307  if (QUERY_FLAG(tmp, FLAG_NO_PICK)
4308  && strcmp(tmp->name, "battleground") == 0
4309  && tmp->type == BATTLEGROUND
4310  && EXIT_X(tmp)
4311  && EXIT_Y(tmp)) {
4312  /*before we assign the exit, check if this is a teambattle*/
4313  if (EXIT_ALT_X(tmp) && EXIT_ALT_Y(tmp) && EXIT_PATH(tmp)) {
4314  object *invtmp;
4315 
4316  invtmp = object_find_by_type_and_slaying(op, FORCE, EXIT_PATH(tmp));
4317  if (invtmp != NULL) {
4318  if (x != NULL && y != NULL)
4319  *x = EXIT_ALT_X(tmp),
4320  *y = EXIT_ALT_Y(tmp);
4321  return 1;
4322  }
4323  }
4324  if (x != NULL && y != NULL)
4325  *x = EXIT_X(tmp),
4326  *y = EXIT_Y(tmp);
4327 
4328  /* If 'other_arch' is not specified, give a finger. */
4329  if (trophy != NULL) {
4330  if (tmp->other_arch) {
4331  *trophy = tmp->other_arch;
4332  } else {
4333  *trophy = find_archetype("finger");
4334  }
4335  }
4336  return 1;
4337  }
4338  }
4339  } FOR_BELOW_FINISH();
4340  /* If we got here, did not find a battleground */
4341  return 0;
4342 }
4343 
4354 void dragon_ability_gain(object *who, int atnr, int level) {
4355  treasurelist *trlist = NULL; /* treasurelist */
4356  treasure *tr; /* treasure */
4357  object *tmp, *skop; /* tmp. object */
4358  object *item; /* treasure object */
4359  char buf[MAX_BUF]; /* tmp. string buffer */
4360  int i = 0, j = 0;
4361 
4362  /* get the appropriate treasurelist */
4363  if (atnr == ATNR_FIRE)
4364  trlist = find_treasurelist("dragon_ability_fire");
4365  else if (atnr == ATNR_COLD)
4366  trlist = find_treasurelist("dragon_ability_cold");
4367  else if (atnr == ATNR_ELECTRICITY)
4368  trlist = find_treasurelist("dragon_ability_elec");
4369  else if (atnr == ATNR_POISON)
4370  trlist = find_treasurelist("dragon_ability_poison");
4371 
4372  if (trlist == NULL || who->type != PLAYER)
4373  return;
4374 
4375  // tr->magic is being used to define what level of the metabolism the ability is gained at.
4376  for (tr = trlist->items; tr != NULL && tr->magic != level; tr = tr->next)
4377  ;
4378  if (tr == NULL || tr->item == NULL) {
4379  /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
4380  return;
4381  }
4382 
4383  /* everything seems okay - now bring on the gift: */
4384  item = &(tr->item->clone);
4385 
4386  if (item->type == SPELL) {
4387  if (check_spell_known(who, item->name))
4388  return;
4389 
4392  "You gained the ability of %s",
4393  item->name);
4394  do_learn_spell(who, item, 0);
4395  return;
4396  }
4397 
4398  /* grant direct spell */
4399  if (item->type == SPELLBOOK) {
4400  if (!item->inv) {
4401  LOG(llevDebug, "dragon_ability_gain: Broken spellbook %s\n", item->name);
4402  return;
4403  }
4404  if (check_spell_known(who, item->inv->name))
4405  return;
4406  if (item->invisible) {
4409  "You gained the ability of %s",
4410  item->inv->name);
4411  do_learn_spell(who, item->inv, 0);
4412  return;
4413  }
4414  } else if (item->type == SKILL_TOOL && item->invisible) {
4415  if (item->subtype == SK_CLAWING && (skop = find_skill_by_name(who, item->skill)) != NULL) {
4416  /* should this perhaps be (skop->attackyp&item->attacktype) != item->attacktype ...
4417  * in this way, if the player is missing any of the attacktypes, he gets
4418  * them. As it is now, if the player has any that match the granted skill,
4419  * but not all of them, he gets nothing.
4420  */
4421  if (!(skop->attacktype&item->attacktype)) {
4422  /* Give new attacktype */
4423  skop->attacktype |= item->attacktype;
4424 
4425  /* always add physical if there's none */
4426  skop->attacktype |= AT_PHYSICAL;
4427 
4428  if (item->msg != NULL)
4431  item->msg);
4432 
4433  /* Give player new face */
4434  if (item->animation_id) {
4435  who->face = skop->face;
4436  who->animation_id = item->animation_id;
4437  who->anim_speed = item->anim_speed;
4438  who->last_anim = 0;
4439  who->state = 0;
4440  animate_object(who, who->direction);
4441  }
4442  }
4443  }
4444  } else if (item->type == FORCE) {
4445  /* forces in the treasurelist can alter the player's stats */
4446  object *skin;
4447 
4448  /* first get the dragon skin force */
4449  skin = object_find_by_arch_name(who, "dragon_skin_force");
4450  if (skin == NULL)
4451  return;
4452 
4453  /* adding new spellpath attunements */
4454  if (item->path_attuned > 0 && !(skin->path_attuned&item->path_attuned)) {
4455  skin->path_attuned |= item->path_attuned; /* add attunement to skin */
4456 
4457  /* print message */
4458  snprintf(buf, sizeof(buf), "You feel attuned to ");
4459  for (i = 0, j = 0; i < NRSPELLPATHS; i++) {
4460  if (item->path_attuned&(1<<i)) {
4461  if (j)
4462  strcat(buf, " and ");
4463  else
4464  j = 1;
4465  strcat(buf, spellpathnames[i]);
4466  }
4467  }
4468  strcat(buf, ".");
4471  buf);
4472  }
4473 
4474  /* evtl. adding flags: */
4475  if (QUERY_FLAG(item, FLAG_XRAYS))
4476  SET_FLAG(skin, FLAG_XRAYS);
4477  if (QUERY_FLAG(item, FLAG_STEALTH))
4478  SET_FLAG(skin, FLAG_STEALTH);
4479  if (QUERY_FLAG(item, FLAG_SEE_IN_DARK))
4480  SET_FLAG(skin, FLAG_SEE_IN_DARK);
4481 
4482  /* print message if there is one */
4483  if (item->msg != NULL)
4486  item->msg);
4487  } else {
4488  /* generate misc. treasure */
4489  char name[HUGE_BUF];
4490 
4491  tmp = arch_to_object(tr->item);
4492  query_short_name(tmp, name, HUGE_BUF);
4495  "You gained %s",
4496  name);
4497  tmp = object_insert_in_ob(tmp, who);
4498  if (who->type == PLAYER)
4499  esrv_send_item(who, tmp);
4500  }
4501 }
4502 
4512 void player_unready_range_ob(player *pl, object *ob) {
4513  rangetype i;
4514 
4515  for (i = 0; i < range_size; i++) {
4516  if (pl->ranges[i] == ob) {
4517  pl->ranges[i] = NULL;
4518  if (pl->shoottype == i) {
4519  pl->shoottype = range_none;
4520  }
4521  }
4522  }
4523 }
4524 
4531 
4532  assert(pl);
4533  assert(state >= ST_PLAYING && state <= ST_CHANGE_PASSWORD_CONFIRM);
4534  pl->state = state;
4535 }
float weapon_speed_left
Definition: object.h:331
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...)
Definition: main.c:316
static int player_fire_bow(object *op, int dir)
Definition: player.c:2376
uint8_t login_method
Definition: newserver.h:128
void spring_trap(object *trap, object *victim)
Definition: rune.c:205
static void set_player_socket(player *p, socket_struct *ns)
Definition: player.c:418
char path[HUGE_BUF]
Definition: map.h:365
uint8_t not_permadeth
Definition: global.h:264
int player_can_view(object *pl, object *op)
Definition: player.c:4206
static int player_attack_door(object *op, object *door)
Definition: player.c:2618
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:219
const char * rules
Definition: global.h:281
#define MSG_TYPE_MISC
Definition: newclient.h:389
#define FLAG_NO_DROP
Definition: define.h:289
int8_t Int
Definition: living.h:36
Definition: player.h:92
#define FLAG_SEE_IN_DARK
Definition: define.h:338
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:605
const char * determine_god(object *op)
Definition: gods.c:106
archetype * find_archetype(const char *name)
Definition: arch.c:695
#define FLAG_DAMNED
Definition: define.h:318
#define FLAG_IS_FLOOR
Definition: define.h:303
#define FLAG_UNPAID
Definition: define.h:236
int8_t ac
Definition: living.h:38
#define MOVE_WALK
Definition: define.h:407
#define UP_OBJ_FACE
Definition: object.h:519
#define MSG_TYPE_ADMIN_LOGIN
Definition: newclient.h:478
int swap_first
Definition: player.h:147
#define MSG_TYPE_ATTRIBUTE_GOD
Definition: newclient.h:570
#define ST_GET_PARTY_PASSWORD
Definition: define.h:587
MoveType move_type
Definition: object.h:426
#define EVENT_REMOVE
Definition: plugin.h:93
#define MSG_TYPE_ITEM
Definition: newclient.h:388
uint8_t stat_loss_on_death
Definition: global.h:258
int16_t gen_hp
Definition: player.h:113
void object_free(object *ob, int flags)
Definition: object.c:1411
Definition: object.h:127
player * find_player_options(const char *plname, int options, const mapstruct *map)
Definition: player.c:66
#define DETOUR_AMOUNT
Definition: player.c:582
MoveType move_on
Definition: object.h:429
Definition: object.h:185
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:646
bool shop_contains(object *ob)
Definition: shop.c:1267
uint8_t max_stat
Definition: global.h:327
void enter_exit(object *op, object *exit_ob)
Definition: server.c:722
Definition: map.h:380
Definition: player.h:39
void leave(player *pl, int draw_exit)
Definition: server.c:1210
static void swap_stat(object *op, int swap_second)
Definition: player.c:1127
static void loot_object(object *op)
Definition: player.c:3477
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:433
Definition: object.h:444
const char * race
Definition: object.h:318
void remove_door(object *op)
Definition: time.c:37
int account_remove_player(const char *account_name, const char *player_name)
Definition: account.c:497
char * account_name
Definition: newserver.h:126
#define PU_CONTAINER
Definition: define.h:143
void SockList_Init(SockList *sl)
Definition: lowlevel.c:48
void esrv_send_item(object *pl, object *op)
Definition: main.c:340
#define SET_FLAG(xyz, p)
Definition: define.h:223
sstring add_refcount(sstring str)
Definition: shstr.c:210
#define EXIT_ALT_Y(xyz)
Definition: define.h:460
#define NDI_ALL
Definition: newclient.h:246
int get_party_password(object *op, partylist *party)
Definition: player.c:997
int16_t bed_x
Definition: player.h:98
uint32_t run_on
Definition: player.h:128
#define PU_DEBUG
Definition: define.h:108
char title[BIG_NAME]
Definition: player.h:165
#define FABS(x)
Definition: define.h:22
int cure_disease(object *sufferer, object *caster, sstring skill)
Definition: disease.c:685
uint32_t braced
Definition: player.h:124
unsigned char uint8_t
Definition: win32.h:161
Definition: object.h:221
static struct Command_Line_Options options[]
Definition: init.c:284
#define MSG_TYPE_ITEM_ADD
Definition: newclient.h:639
#define EVENT_DEATH
Definition: plugin.h:67
void SockList_ResetRead(SockList *sl)
Definition: lowlevel.c:75
void get_name(object *op)
Definition: player.c:855
int get_rangevector_from_mapcoord(const mapstruct *m, int x, int y, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2619
void make_path_to_file(const char *filename)
Definition: porting.c:312
char spellparam[MAX_BUF]
Definition: player.h:100
void link_player_skills(object *op)
Definition: player.c:279
static void kill_player_not_permadeath(object *op)
Definition: player.c:3622
int get_dam_bonus(int stat)
Definition: living.c:2372
uint16_t animation_id
Definition: object.h:418
#define MSG_TYPE_COMMAND_FAILURE
Definition: newclient.h:511
#define MSG_TYPE_ITEM_INFO
Definition: newclient.h:641
uint16_t material
Definition: object.h:348
#define FLAG_USE_ARMOUR
Definition: define.h:296
void send_news(const object *op)
Definition: player.c:202
int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy)
Definition: player.c:2171
#define BALSL_NUMBER_LOSSES_RATIO
Definition: config.h:143
#define strdup_local
Definition: compat.h:25
uint8_t anim_speed
Definition: object.h:419
object * object_find_by_type(const object *who, int type)
Definition: object.c:3924
void drain_wand_charge(object *wand)
Definition: spell_util.c:827
int16_t last_resist[NROFATTACKS]
Definition: player.h:155
Definition: object.h:204
uint16_t look_position
Definition: newserver.h:114
EXTERN objectlink * first_friendly_object
Definition: global.h:123
Definition: object.h:112
struct obj * container
Definition: object.h:291
#define EVENT_LOGIN
Definition: plugin.h:88
uint8_t last_anim
Definition: object.h:420
#define PU_STOP
Definition: define.h:110
Definition: object.h:117
#define FLAG_FRIENDLY
Definition: define.h:246
int push_ob(object *who, int dir, object *pusher)
Definition: move.c:417
Definition: living.h:14
#define PU_SHIELD
Definition: define.h:122
char motd[MAX_BUF]
Definition: global.h:280
void fatal(enum fatal_error err)
Definition: utils.c:597
object * mon
Definition: comet_perf.c:74
#define NDI_BROWN
Definition: newclient.h:233
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4304
#define MSG_TYPE_SPELL
Definition: newclient.h:387
static int turn_transport(object *transport, object *captain, int dir)
Definition: player.c:2981
#define SOUND_TYPE_GROUND
Definition: newclient.h:311
treasurelist * find_treasurelist(const char *name)
Definition: treasure.c:290
int save_player(object *op, int flag)
Definition: login.c:212
void dragon_ability_gain(object *who, int atnr, int level)
Definition: player.c:4354
uint32_t in_memory
Definition: map.h:345
const char * playerdir
Definition: global.h:250
int16_t maxgrace
Definition: living.h:45
void free_string(sstring str)
Definition: shstr.c:280
#define PU_KEY
Definition: define.h:128
signed long object_sum_weight(object *op)
Definition: object.c:344
#define HUGE_BUF
Definition: define.h:37
#define SET_ANIMATION(ob, newanim)
Definition: global.h:169
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2386
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:343
void enter_player_maplevel(object *op)
Definition: server.c:667
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4299
Definition: object.h:137
struct treasureliststruct * randomitems
Definition: object.h:387
void pick_up(object *op, object *alt)
Definition: c_object.c:460
#define NDI_BLUE
Definition: newclient.h:226
uint32_t pticks
Definition: time.c:45
void query_base_name(const object *op, int plural, char *buf, size_t size)
Definition: item.c:723
#define ST_CHANGE_PASSWORD_CONFIRM
Definition: define.h:590
int8_t levsp[11]
Definition: player.h:168
object clone
Definition: object.h:472
socket_struct socket
Definition: player.h:94
int16_t invisible
Definition: object.h:361
short freearr_x[SIZEOFFREE]
Definition: object.c:65
#define PREFER_LOW
Definition: define.h:602
Definition: living.h:17
#define ST_CONFIRM_PASSWORD
Definition: define.h:586
rangetype shoottype
Definition: player.h:99
Definition: object.h:240
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.c:275
Definition: object.h:119
Definition: object.h:136
const char * slaying
Definition: object.h:319
#define IS_WEAPON(op)
Definition: define.h:162
void esrv_send_inventory(object *pl, object *op)
Definition: item.c:307
#define FLAG_CONFUSED
Definition: define.h:312
#define FLAG_STEALTH
Definition: define.h:313
static object * pick_arrow_target(object *op, const char *type, int dir)
Definition: player.c:2102
object * ranges[range_size]
Definition: player.h:103
uint8_t subtype
Definition: object.h:340
const char * party_get_password(const partylist *party)
Definition: party.c:254
Definition: object.h:109
void send_account_players(socket_struct *ns)
Definition: request.c:1890
void send_rules(const object *op)
Definition: player.c:166
#define SOUND_TYPE_LIVING
Definition: newclient.h:308
#define FLAG_USE_WEAPON
Definition: define.h:297
uint8_t hide
Definition: object.h:389
int64_t exp
Definition: living.h:47
void fix_luck(void)
Definition: player.c:3963
void play_again(object *op)
Definition: player.c:879
void change_luck(object *op, int value)
Definition: living.c:793
object * object_find_by_type_without_flags(const object *who, int type, int *flags, int num_flags)
Definition: object.c:3948
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Definition: object.c:4102
method_ret ob_process(object *op)
Definition: ob_methods.c:68
void SockList_AddInt(SockList *sl, uint32_t data)
Definition: lowlevel.c:119
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:217
int language
Definition: player.h:201
Definition: object.h:157
#define object_was_destroyed(op, old_tag)
Definition: object.h:68
#define TRUE
Definition: compat.h:10
#define PU_NOTHING
Definition: define.h:106
#define PU_FLESH
Definition: define.h:142
#define PU_FOOD
Definition: define.h:115
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:3079
void party_leave(object *op)
Definition: party.c:123
Definition: living.h:35
void do_some_living(object *op)
Definition: player.c:3338
void give_initial_items(object *pl, treasurelist *items)
Definition: player.c:763
Definition: object.h:139
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:314
void remove_friendly_object(object *op)
Definition: friend.c:56
uint32_t path_attuned
Definition: object.h:344
#define MAX(x, y)
Definition: compat.h:20
void object_update(object *op, int action)
Definition: object.c:1262
#define MSG_TYPE_ITEM_REMOVE
Definition: newclient.h:638
void account_char_free(Account_Char *chars)
Definition: account_char.c:334
void dead_player(object *op)
Definition: resurrection.c:297
int16_t sp
Definition: living.h:42
EXTERN char first_map_ext_path[MAX_BUF]
Definition: global.h:152
void strip_endline(char *buf)
Definition: utils.c:341
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:202
Definition: object.h:187
int path_to_player(object *mon, object *pl, unsigned mindiff)
Definition: player.c:630
void get_password(object *op)
Definition: player.c:867
#define safe_strncpy
Definition: compat.h:23
int is_true_undead(object *op)
Definition: player.c:4033
#define SCRIPT_FIX_ALL
Definition: global.h:368
Definition: object.h:212
player * find_player_partial_name(const char *plname)
Definition: player.c:110
#define PU_NEWMODE
Definition: define.h:111
uint32_t hidden
Definition: player.h:132
void pets_terminate_all(object *owner)
Definition: pets.c:231
static const char * gravestone_text(object *op, char *buf2, int len)
Definition: player.c:3303
struct obj * enemy
Definition: object.h:383
object * get_nearest_player(object *mon)
Definition: player.c:521
#define ST_ROLL_STAT
Definition: define.h:581
int distance_y
Definition: map.h:383
int absdir(int d)
Definition: object.c:3655
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:311
const char *const drain_msg[NUM_STATS]
Definition: living.c:140
Definition: object.h:467
#define ST_PLAYING
Definition: define.h:579
#define PU_MISSILEWEAPON
Definition: define.h:130
char savebed_map[MAX_BUF]
Definition: player.h:97
#define NDI_DK_ORANGE
Definition: newclient.h:227
char * host
Definition: newserver.h:100
Definition: object.h:220
#define MSG_TYPE_APPLY
Definition: newclient.h:384
#define FOR_OB_AND_BELOW_FINISH()
Definition: define.h:792
const char *const spellpathnames[NRSPELLPATHS]
Definition: init.c:105
struct archt * item
Definition: treasure.h:64
uint16_t emergency_y
Definition: global.h:303
static int turn_one_transport(object *transport, object *captain, int dir)
Definition: player.c:2911
#define PU_CLOAK
Definition: define.h:127
int16_t maxsp
Definition: living.h:43
#define MIN(x, y)
Definition: compat.h:17
int8_t Con
Definition: living.h:36
#define FLAG_REMOVED
Definition: define.h:232
int16_t hp
Definition: living.h:40
int check_pick(object *op)
Definition: player.c:1689
#define FLAG_CAN_ROLL
Definition: define.h:254
short freearr_y[SIZEOFFREE]
Definition: object.c:71
partylist * party
Definition: player.h:186
#define FLAG_KNOWN_MAGICAL
Definition: define.h:320
Definition: player.h:32
#define SOUND_TYPE_ITEM
Definition: newclient.h:310
#define NDI_NAVY
Definition: newclient.h:223
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:488
uint32_t no_shout
Definition: player.h:133
object * ob
Definition: object.h:445
#define FIND_PLAYER_PARTIAL_NAME
Definition: player.h:212
#define MOVE_ALL
Definition: define.h:413
uint32_t ticks_played
Definition: player.h:203
void pets_control_golem(object *op, int dir)
Definition: pets.c:648
#define MIN_STAT
Definition: define.h:33
#define FLAG_UNDEAD
Definition: define.h:270
void object_set_owner(object *op, object *owner)
Definition: object.c:634
const char * news
Definition: global.h:282
#define FLAG_READY_SKILL
Definition: define.h:334
void apply_changes_to_player(object *pl, object *change, int limit_stats)
Definition: apply.c:1672
Definition: object.h:241
#define MAP_IN_MEMORY
Definition: map.h:130
struct obj * chosen_skill
Definition: object.h:388
uint32_t update_look
Definition: newserver.h:104
object * find_key(object *pl, object *container, object *door)
Definition: player.c:2536
void object_free_drop_inventory(object *ob)
Definition: object.c:1391
void clear_player(player *pl)
Definition: player.c:33
int16_t y
Definition: object.h:326
void esrv_new_player(player *pl, uint32_t weight)
Definition: request.c:868
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1935
int16_t maxhp
Definition: living.h:41
static void fire_misc_object(object *op, int dir)
Definition: player.c:2412
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
Definition: newclient.h:561
void object_update_turn_face(object *op)
Definition: object.c:1132
#define MSG_TYPE_COMMAND
Definition: newclient.h:379
#define PU_BOOTS
Definition: define.h:125
Definition: object.h:118
int stand_near_hostile(object *who)
Definition: player.c:4138
#define FLAG_ALIVE
Definition: define.h:230
Account_Char * account_chars
Definition: newserver.h:127
#define ADD_PLAYER_NO_STATS_ROLL
Definition: player.h:224
Definition: object.h:114
#define MSG_TYPE_VICTIM
Definition: newclient.h:392
int get_randomized_dir(int dir)
Definition: utils.c:439
object * object_new(void)
Definition: object.c:1070
const char * name_pl
Definition: object.h:315
object * create_archetype(const char *name)
Definition: arch.c:620
void player_set_own_title(struct pl *pl, const char *title)
Definition: player.c:264
int object_can_pick(const object *who, const object *item)
Definition: object.c:3811
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2709
void send_query(socket_struct *ns, uint8_t flags, const char *text)
Definition: request.c:677
float speed_left
Definition: object.h:329
unapplymode unapply
Definition: player.h:108
int is_wraith_pl(object *op)
Definition: player.c:165
int16_t gen_sp
Definition: player.h:114
#define MSG_TYPE_COMMAND_SUCCESS
Definition: newclient.h:510
player * get_player(player *p)
Definition: player.c:281
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:509
int blocked_link(object *ob, mapstruct *m, int sx, int sy)
Definition: map.c:354
#define PU_SKILLSCROLL
Definition: define.h:136
signed short int16_t
Definition: win32.h:160
uint8_t search_items
Definition: global.h:269
void command_search_items(object *op, const char *params)
Definition: c_object.c:2049
const char * materialname
Definition: object.h:347
int32_t weight
Definition: object.h:366
static void kill_player_permadeath(object *op)
Definition: player.c:3861
#define FLAG_CAN_USE_SKILL
Definition: define.h:322
#define MOVE_FLY_LOW
Definition: define.h:408
const char * anim_suffix
Definition: object.h:316
#define ADD_PLAYER_NEW
Definition: player.h:222
uint32_t tmp_invis
Definition: player.h:125
void drain_rod_charge(object *rod)
Definition: spell_util.c:817
int8_t Wis
Definition: living.h:36
int hide(object *op, object *skill)
Definition: skills.c:492
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
#define FLAG_USE_SHIELD
Definition: define.h:237
player * add_player(socket_struct *ns, int flags)
Definition: player.c:454
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:474
void clear_los(player *pl)
Definition: los.c:252
void receive_play_again(object *op, char key)
Definition: player.c:931
#define PU_ARROW
Definition: define.h:120
struct mapdef * map
Definition: object.h:297
void SockList_Term(SockList *sl)
Definition: lowlevel.c:58
char search_str[MAX_BUF]
Definition: player.h:192
#define snprintf
Definition: win32.h:46
#define ARCH_DEPLETION
Definition: object.h:579
void player_map_change_common(object *op, mapstruct *const oldmap, mapstruct *const newmap)
Definition: server.c:265
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:497
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:380
object * transport
Definition: player.h:195
#define FLAG_IDENTIFIED
Definition: define.h:261
#define MOVE_FLYING
Definition: define.h:410
#define FOR_INV_FINISH()
Definition: define.h:715
object * object_find_by_flag_applied(const object *who, int flag)
Definition: object.c:4173
int16_t dam
Definition: living.h:46
uint8_t balanced_stat_loss
Definition: global.h:263
void change_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:265
int die_roll(int num, int size, const object *op, int goodbad)
Definition: utils.c:122
void add_friendly_object(object *op)
Definition: friend.c:30
int32_t carrying
Definition: object.h:368
#define NDI_GREEN
Definition: newclient.h:228
const char * name
Definition: object.h:311
int16_t bed_y
Definition: player.h:98
living orig_stats
Definition: player.h:148
#define PU_INHIBIT
Definition: define.h:109
int distance_x
Definition: map.h:382
#define PU_BOW
Definition: define.h:118
int allowed_class(const object *op)
Definition: living.c:1646
#define MSG_TYPE_COMMAND_NEWPLAYER
Definition: newclient.h:516
static int similar_direction(int a, int b)
Definition: player.c:2342
#define AP_NULL
Definition: define.h:611
uint8_t state
Definition: object.h:350
#define ST_PLAY_AGAIN
Definition: define.h:580
void roll_again(object *op)
Definition: player.c:1113
int execute_global_event(int eventcode,...)
Definition: main.c:370
#define EXIT_PATH(xyz)
Definition: define.h:455
uint8_t state
Definition: player.h:118
#define MSG_TYPE_SPELL_END
Definition: newclient.h:629
uint64_t price_base(const object *obj)
Definition: shop.c:70
uint8_t magic
Definition: treasure.h:71
void display_motd(const object *op)
Definition: player.c:135
#define offsetof(type, member)
Definition: shstr.h:37
#define CS_QUERY_SINGLECHAR
Definition: newclient.h:67
int monster_can_detect_enemy(object *op, object *enemy, rv_vector *rv)
Definition: monster.c:2389
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.c:149
#define FLAG_PARALYZED
Definition: define.h:380
#define PU_RATIO
Definition: define.h:113
int8_t direction
Definition: object.h:335
uint32_t nrof
Definition: object.h:333
uint8_t listening
Definition: player.h:120
void fire(object *op, int dir)
Definition: player.c:2464
int8_t Cha
Definition: living.h:36
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:447
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:304
#define AP_NOPRINT
Definition: define.h:624
void remove_locked_door(object *op)
Definition: time.c:63
#define P_OUT_OF_MAP
Definition: map.h:251
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:192
int do_skill(object *op, object *part, object *skill, int dir, const char *string)
Definition: skill_util.c:412
uint16_t emergency_x
Definition: global.h:303
int move_ob(object *op, int dir, object *originator)
Definition: move.c:58
#define EXIT_X(xyz)
Definition: define.h:457
void do_learn_spell(object *op, object *spell, int special_prayer)
Definition: apply.c:486
Definition: object.h:111
uint32_t has_hit
Definition: player.h:129
struct pl * contr
Definition: object.h:276
#define PU_DRINK
Definition: define.h:116
static void flee_player(object *op)
Definition: player.c:1630
void add_statbonus(object *op)
Definition: living.c:865
#define FLAG_SCARED
Definition: define.h:271
uint8_t darkness
Definition: map.h:346
#define MSG_TYPE_SKILL_FAILURE
Definition: newclient.h:585
player * find_player_socket(const socket_struct *ns)
Definition: player.c:119
#define FLAG_XRAYS
Definition: define.h:301
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:206
void set_first_map(object *op)
Definition: player.c:399
char * spellarg
Definition: object.h:411
int8_t blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]
Definition: player.h:159
uint32_t tag_t
Definition: object.h:12
int8_t luck
Definition: living.h:39
#define ATNR_ELECTRICITY
Definition: attack.h:52
#define ATNR_POISON
Definition: attack.h:59
#define AT_PHYSICAL
Definition: attack.h:76
float speed
Definition: object.h:328
Definition: object.h:214
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define HEAD(op)
Definition: object.h:594
party_rejoin_mode rejoin_party
Definition: player.h:191
#define MSG_TYPE_ADMIN_NEWS
Definition: newclient.h:473
#define FLAG_WIZ
Definition: define.h:231
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2162
#define FLAG_BEEN_APPLIED
Definition: define.h:324
uint32_t golem_count
Definition: player.h:106
#define EXIT_ALT_X(xyz)
Definition: define.h:459
void object_get_multi_size(const object *ob, int *sx, int *sy, int *hx, int *hy)
Definition: object.c:4679
#define MSG_TYPE_COMMAND_DEBUG
Definition: newclient.h:508
#define BALSL_LOSS_CHANCE_RATIO
Definition: config.h:142
#define EXIT_Y(xyz)
Definition: define.h:458
void delete_character(const char *name)
Definition: login.c:87
#define MAX_BUF
Definition: define.h:35
#define MSG_TYPE_ATTACK
Definition: newclient.h:385
#define NRSPELLPATHS
Definition: spells.h:40
#define IS_SHIELD(op)
Definition: define.h:169
Definition: object.h:126
#define PU_READABLES
Definition: define.h:137
#define MSG_TYPE_ADMIN
Definition: newclient.h:377
uint32_t peaceful
Definition: player.h:131
Account_Char * account_char_remove(Account_Char *chars, const char *pl_name)
Definition: account_char.c:298
void do_hidden_move(object *op)
Definition: player.c:4097
int16_t x
Definition: object.h:326
void skill_attack(object *tmp, object *pl, int dir, const char *string, object *skill)
Definition: skill_util.c:1259
int strncasecmp(const char *s1, const char *s2, int n)
Definition: porting.c:224
int8_t levhp[11]
Definition: player.h:167
struct treasurestruct * items
Definition: treasure.h:90
#define MSG_TYPE_ATTRIBUTE_STAT_LOSS
Definition: newclient.h:563
const char * skill
Definition: object.h:321
uint8_t mapx
Definition: newserver.h:116
void fix_weight(void)
Definition: player.c:3947
void esrv_map_scroll(socket_struct *ns, int dx, int dy)
Definition: request.c:1526
int8_t wc
Definition: living.h:37
int roll_stat(void)
Definition: player.c:1015
int64_t last_skill_exp[MAX_SKILLS]
Definition: player.h:138
const char * confdir
Definition: global.h:247
void kill_player(object *op, const object *killer)
Definition: player.c:3517
#define AC_PLAYER_STAT_NO_CHANGE
Definition: define.h:636
#define FLAG_IS_THROWN
Definition: define.h:249
uint16_t difficulty
Definition: map.h:343
static const flag_definition flags[]
void SockList_AddChar(SockList *sl, unsigned char c)
Definition: lowlevel.c:98
#define FOR_MAP_FINISH()
Definition: define.h:768
int8_t Str
Definition: living.h:36
void animate_object(object *op, int dir)
Definition: anim.c:213
int16_t resist[NROFATTACKS]
Definition: object.h:342
#define FLAG_KNOWN_CURSED
Definition: define.h:321
object * ob
Definition: player.h:158
int has_carried_lights(const object *op)
Definition: los.c:315
const char *const lose_msg[NUM_STATS]
Definition: living.c:173
#define FLAG_CURSED
Definition: define.h:317
Definition: object.h:107
unsigned int uint32_t
Definition: win32.h:162
void player_set_state(player *pl, uint8_t state)
Definition: player.c:4530
Definition: object.h:113
void safe_strcat(char *dest, const char *orig, size_t *curlen, size_t maxlen)
Definition: porting.c:346
Definition: object.h:135
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Definition: object.c:4248
bowtype_t bowtype
Definition: player.h:101
int move_player(object *op, int dir)
Definition: player.c:3014
char killer[BIG_NAME]
Definition: player.h:171
#define FLAG_ANIMATE
Definition: define.h:242
int apply_container(object *op, object *sack, int aflags)
Definition: apply.c:223
void key_roll_stat(object *op, char key)
Definition: player.c:1185
#define PU_MELEEWEAPON
Definition: define.h:131
#define PREFER_HIGH
Definition: define.h:601
uint32_t attacktype
Definition: object.h:343
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2480
float last_speed
Definition: player.h:154
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:28
#define MSG_TYPE_VICTIM_DIED
Definition: newclient.h:654
void play_sound_player_only(player *pl, int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:51
#define FLAG_NEUTRAL
Definition: define.h:362
#define RANDOM()
Definition: define.h:682
living last_stats
Definition: player.h:149
int handle_newcs_player(object *op)
Definition: player.c:3152
const char * invis_race
Definition: player.h:135
#define FREE_AND_COPY(sv, nv)
Definition: global.h:211
int16_t grace
Definition: living.h:44
signed char int8_t
Definition: win32.h:158
Definition: object.h:143
uint32_t fire_on
Definition: player.h:127
#define MAX_SPACES
Definition: player.c:597
const char * localdir
Definition: global.h:249
char password[16]
Definition: player.h:176
int32_t last_weight
Definition: player.h:142
tag_t count
Definition: object.h:299
void recursive_roll(object *op, int dir, object *pusher)
Definition: move.c:276
living stats
Definition: object.h:369
static int save_life(object *op)
Definition: player.c:3230
int8_t Dex
Definition: living.h:36
struct archt * arch
Definition: object.h:414
float last_weapon_sp
Definition: player.h:140
#define UPD_FACE
Definition: newclient.h:292
struct oblnk * next
Definition: object.h:446
int playername_ok(const char *cp)
Definition: player.c:253
#define MSG_TYPE_ATTACK_NOATTACK
Definition: newclient.h:613
#define MSG_TYPE_ADMIN_RULES
Definition: newclient.h:472
void account_char_save(const char *account, Account_Char *chars)
Definition: account_char.c:146
int check_race_and_class(living *stats, archetype *race, archetype *opclass)
Definition: player.c:1401
void make_visible(object *op)
Definition: player.c:4013
static archetype * get_player_archetype(archetype *at)
Definition: player.c:496
#define SPELL_HIGHEST
Definition: spells.h:60
unsigned int distance
Definition: map.h:381
uint8_t type
Definition: object.h:339
uint32_t do_los
Definition: player.h:126
void move_player_attack(object *op, int dir)
Definition: player.c:2689
uint32_t mode
Definition: player.h:110
struct Settings settings
Definition: init.c:39
uint32_t monitor_spells
Definition: newserver.h:110
void object_set_enemy(object *op, object *enemy)
Definition: object.c:712
#define ADD_PLAYER_NO_MAP
Definition: player.h:223
struct archt * next
Definition: object.h:469
int direction
Definition: map.h:384
rangetype
Definition: player.h:15
#define FLAG_NO_STRENGTH
Definition: define.h:307
#define FLAG_APPLIED
Definition: define.h:235
#define NROFATTACKS
Definition: attack.h:17
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:551
#define PU_SPELLBOOK
Definition: define.h:135
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2313
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:365
#define FLAG_LIFESAVE
Definition: define.h:306
void remove_unpaid_objects(object *op, object *env, int free_items)
Definition: player.c:3273
signed int int32_t
Definition: win32.h:159
void delete_map(mapstruct *m)
Definition: map.c:1759
#define ST_CHANGE_CLASS
Definition: define.h:582
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:598
const char * msg
Definition: object.h:322
EXTERN char first_map_path[MAX_BUF]
Definition: global.h:151
#define FLAG_MAKE_INVIS
Definition: define.h:329
int object_matches_string(object *pl, object *op, const char *name)
Definition: object.c:4506
void apply_death_exp_penalty(object *op)
Definition: living.c:2227
#define FOR_OB_AND_BELOW_PREPARE(op_)
Definition: define.h:788
#define FLAG_STARTEQUIP
Definition: define.h:268
#define FORCE_NAME
Definition: spells.h:169
#define PU_VALUABLES
Definition: define.h:117
int16_t gen_sp_armour
Definition: player.h:115
#define PU_MAGICAL
Definition: define.h:132
sstring add_string(const char *str)
Definition: shstr.c:124
EXTERN player * first_player
Definition: global.h:117
#define FIND_PLAYER_NO_HIDDEN_DM
Definition: player.h:213
struct pl * next
Definition: player.h:93
static const int32_t MAX_FOOD
Definition: define.h:477
#define GET_MAP_OB(M, X, Y)
Definition: map.h:172
player * find_player(const char *plname)
Definition: player.c:55
void confirm_password(object *op)
Definition: player.c:981
#define PU_JEWELS
Definition: define.h:141
#define FLAG_MONSTER
Definition: define.h:245
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:871
#define EVENT_PLAYER_DEATH
Definition: plugin.h:86
#define MSG_TYPE_SKILL
Definition: newclient.h:383
int8_t Pow
Definition: living.h:36
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:310
struct obj * inv
Definition: object.h:290
uint8_t set_title
Definition: global.h:267
petmode_t petmode
Definition: player.h:102
#define NDI_UNIQUE
Definition: newclient.h:245
int face_player(object *op, int dir)
Definition: player.c:3093
void apply_anim_suffix(object *who, sstring suffix)
Definition: anim.c:319
char maplevel[MAX_BUF]
Definition: player.h:96
Definition: object.h:213
int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
Definition: player.c:1451
#define FLAG_READY_BOW
Definition: define.h:300
#define MSG_SUBTYPE_NONE
Definition: newclient.h:398
usekeytype usekeys
Definition: player.h:107
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
#define CS_QUERY_HIDEINPUT
Definition: newclient.h:68
static int action_makes_visible(object *op)
Definition: player.c:4257
#define PU_GLOVES
Definition: define.h:126
object * last_skill_ob[MAX_SKILLS]
Definition: player.h:137
int did_make_save(const object *op, int level, int bonus)
Definition: living.c:2276
#define FLAG_WAS_WIZ
Definition: define.h:234
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:144
void player_unready_range_ob(player *pl, object *ob)
Definition: player.c:4512
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:761
void roll_stats(object *op)
Definition: player.c:1039
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:107
uint8_t run_away
Definition: object.h:386
#define IS_ARMOR(op)
Definition: define.h:165
void key_change_class(object *op, char key)
Definition: player.c:1261
#define MSG_TYPE_ATTACK_NOKEY
Definition: newclient.h:612
struct mapdef * next
Definition: map.h:326
#define P_BLOCKSVIEW
Definition: map.h:226
void object_set_msg(object *op, const char *msg)
Definition: object.c:4748
static void update_transport_block(object *transport, int dir)
Definition: player.c:2866
#define MSG_TYPE_ATTRIBUTE_RACE
Definition: newclient.h:557
#define ATNR_COLD
Definition: attack.h:53
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:626
#define PU_ARMOUR
Definition: define.h:123
void apply_map_builder(object *pl, int dir)
Definition: build_map.c:959
#define MAX_SKILLS
Definition: skills.h:70
#define FOR_BELOW_PREPARE(op_, it_)
Definition: define.h:742
void remove_statbonus(object *op)
Definition: living.c:842
char * emergency_mapname
Definition: global.h:302
Definition: map.h:325
#define P_IS_ALIVE
Definition: map.h:237
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
int is_identifiable_type(const object *op)
Definition: item.c:1335
#define ST_GET_NAME
Definition: define.h:584
uint8_t roll_stat_points
Definition: global.h:326
const New_Face * face
Definition: object.h:332
char write_buf[MAX_BUF]
Definition: player.h:174
Definition: object.h:167
#define FLAG_UNIQUE
Definition: define.h:288
#define FLAG_NO_PICK
Definition: define.h:239
static object * find_better_arrow(object *op, object *target, const char *type, int *better)
Definition: player.c:2032
int8_t levgrace[11]
Definition: player.h:169
#define PU_POTION
Definition: define.h:133
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2546
const char * unarmed_skill
Definition: player.h:202
Definition: object.h:120
const char *const short_stat_name[NUM_STATS]
Definition: living.c:195
struct treasurestruct * next
Definition: treasure.h:66
void enter_player_savebed(object *op)
Definition: server.c:133
uint8_t mapy
Definition: newserver.h:116
partylist * party_to_join
Definition: player.h:187
int get_dex_bonus(int stat)
Definition: living.c:2348
#define PU_HELMET
Definition: define.h:121
int16_t level
Definition: object.h:352
int8_t facing
Definition: object.h:336
#define FLAG_INV_LOCKED
Definition: define.h:330
void fix_object(object *op)
Definition: living.c:1120
#define BALSL_MAX_LOSS_RATIO
Definition: config.h:144
EXTERN mapstruct * first_map
Definition: global.h:118
void cast_dust(object *op, object *throw_ob, int dir)
Definition: player.c:3984
#define AT_DEATH
Definition: attack.h:93
#define PU_NOT_CURSED
Definition: define.h:140
EXTERN archetype * first_archetype
Definition: global.h:122
struct obj * more
Definition: object.h:295
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:192
object * arch_to_object(archetype *at)
Definition: arch.c:571
void object_update_speed(object *op)
Definition: object.c:1152
int32_t value
Definition: object.h:351
object * object_get_owner(object *op)
Definition: object.c:592
int8_t magic
Definition: object.h:349
uint8_t * faces_sent
Definition: newserver.h:96
static object * find_arrow(object *op, const char *type)
Definition: player.c:2000
const char * name
Definition: object.h:468
#define EVENT_BORN
Definition: plugin.h:83
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:366
#define FOR_BELOW_FINISH()
Definition: define.h:749
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.c:4196
uint8_t resurrection
Definition: global.h:268
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:708
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1469
SockList inbuf
Definition: newserver.h:99
void object_remove(object *op)
Definition: object.c:1668
#define MSG_TYPE_MOTD
Definition: newclient.h:376
int hideability(object *ob)
Definition: player.c:4056
#define PU_MAGIC_DEVICE
Definition: define.h:138
#define ST_GET_PASSWORD
Definition: define.h:585
int32_t food
Definition: living.h:48
#define FLAG_FREED
Definition: define.h:233
void key_confirm_quit(object *op, char key)
Definition: player.c:1563
void Send_With_Handling(socket_struct *ns, SockList *sl)
Definition: lowlevel.c:435
Definition: object.h:224
#define ATNR_FIRE
Definition: attack.h:51
int get_thaco_bonus(int stat)
Definition: living.c:2352
void check_stat_bounds(living *stats, int8_t min_stat, int8_t max_stat)
Definition: living.c:355