Crossfire Server, Trunk
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 <ctype.h>
24 #include <stddef.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #ifndef WIN32 /* ---win32 remove headers */
29 #include <pwd.h>
30 #endif
31 
32 #include "server.h"
33 #include "living.h"
34 #include "object.h"
35 #include "shared/newclient.h"
36 #include "shop.h"
37 #include "skills.h"
38 #include "sounds.h"
39 #include "spells.h"
40 #include "sproto.h"
41 
43 
44 static void kill_player_not_permadeath(object *op);
45 static void kill_player_permadeath(object *op);
46 static int action_makes_visible(object *op);
47 
56 player *find_player(const char *plname) {
57  return find_player_options(plname, 0, NULL);
58 }
59 
67 player *find_player_options(const char *plname, int options, const mapstruct *map) {
68  player *pl;
69  player *found = NULL;
70  size_t namelen = strlen(plname);
71  char name[MAX_BUF];
72 
73  for (pl = first_player; pl != NULL; pl = pl->next) {
75  continue;
76 
77  if (map != NULL && pl->ob->map != map)
78  continue;
79 
81  query_name(pl->ob, name, sizeof(name));
82  if (!strcmp(name, plname))
83  return pl;
84  continue;
85  }
86 
87  if (strlen(pl->ob->name) < namelen)
88  continue;
89 
90  if (!strcmp(pl->ob->name, plname))
91  return pl;
92 
93  if (!strncasecmp(pl->ob->name, plname, namelen)) {
94  if (found)
95  return NULL;
96 
97  found = pl;
98  }
99  }
100  return found;
101 }
102 
111 player *find_player_partial_name(const char *plname) {
112  return find_player_options(plname, FIND_PLAYER_PARTIAL_NAME, NULL);
113 }
114 
121  player *pl;
122 
123  for (pl = first_player; pl != NULL; pl = pl->next) {
124  if (&pl->socket == ns)
125  return pl;
126  }
127  return NULL;
128 }
129 
136 void display_motd(const object *op) {
137  char buf[MAX_BUF];
138  char motd[HUGE_BUF];
139  FILE *fp;
140  size_t size;
141 
142  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.motd);
143  fp = fopen(buf, "r");
144  if (fp == NULL) {
145  return;
146  }
147  motd[0] = '\0';
148  size = 0;
149 
150  while (fgets(buf, MAX_BUF, fp) != NULL) {
151  if (*buf != '#') {
152  safe_strcat(motd, buf, &size, sizeof(motd));
153  }
154  }
155 
157  motd);
158  fclose(fp);
159 }
160 
167 void send_rules(const object *op) {
168  char buf[MAX_BUF];
169  char rules[HUGE_BUF];
170  FILE *fp;
171  size_t size;
172 
173  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.rules);
174  fp = fopen(buf, "r");
175  if (fp == NULL) {
176  return;
177  }
178  rules[0] = '\0';
179  size = 0;
180 
181  while (fgets(buf, MAX_BUF, fp) != NULL) {
182  if (size+strlen(buf) >= HUGE_BUF) {
183  LOG(llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF);
184  break;
185  }
186 
187  if (*buf != '#') {
188  safe_strcat(rules, buf, &size, sizeof(rules));
189  }
190  }
191 
193  MSG_TYPE_ADMIN_RULES, rules);
194  fclose(fp);
195 }
196 
203 void send_news(const object *op) {
204  char buf[MAX_BUF];
205  char news[HUGE_BUF];
206  char subject[MAX_BUF];
207  FILE *fp;
208  size_t size;
209 
210  snprintf(buf, sizeof(buf), "%s/%s", settings.confdir, settings.news);
211  fp = fopen(buf, "r");
212  if (fp == NULL)
213  return;
214  news[0] = '\0';
215  subject[0] = '\0';
216  size = 0;
217  while (fgets(buf, MAX_BUF, fp) != NULL) {
218  if (*buf == '#')
219  continue;
220  if (*buf == '%') { /* send one news */
221  if (size > 0)
224  "%s:\n%s",
225  subject, news); /*send previously read news*/
226  safe_strncpy(subject, buf + 1, sizeof(subject));
227  strip_endline(subject);
228  size = 0;
229  news[0] = '\0';
230  } else {
231  if (size+strlen(buf) >= HUGE_BUF) {
232  LOG(llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF);
233  break;
234  }
235  safe_strcat(news, buf, &size, sizeof(news));
236  }
237  }
238 
241  "%s:\n%s",
242  subject, news);
243  fclose(fp);
244 }
245 
254 int playername_ok(const char *cp) {
255  /* Don't allow - or _ as first character in the name */
256  if (*cp == '-' || *cp == '_')
257  return 0;
258 
259  for (; *cp != '\0'; cp++)
260  if (!isalnum(*cp)
261  && *cp != '-'
262  && *cp != '_')
263  return 0;
264  return 1;
265 }
266 
283  object *op = arch_to_object(get_player_archetype(NULL));
284  int i;
285 
286  if (!p) {
287  player *tmp;
288 
289  p = (player *)malloc(sizeof(player));
290  if (p == NULL)
292 
293  /* This adds the player in the linked list. There is extra
294  * complexity here because we want to add the new player at the
295  * end of the list - there is in fact no compelling reason that
296  * that needs to be done except for things like output of
297  * 'who'.
298  */
299  tmp = first_player;
300  while (tmp != NULL && tmp->next != NULL)
301  tmp = tmp->next;
302  if (tmp != NULL)
303  tmp->next = p;
304  else
305  first_player = p;
306 
307  p->next = NULL;
308  /* This only needs to be done on initial creation of player
309  * object. the callers of get_player() will copy over the
310  * socket structure to p->socket, and if this is an existing
311  * player object, that has been done. The call to
312  * roll_stats() below will try to send spell information to
313  * the client - if this is non zero (eg, garbage from not
314  * being cleared), that will cause problems. So just clear
315  * it, and no spell data is sent.
316  */
317  p->socket.monitor_spells = 0;
318  } else {
319  /* Only needed when reusing existing player. */
320  clear_player(p);
321  }
322 
323  /* Clears basically the entire player structure except
324  * for next and socket.
325  */
326  memset((void *)((char *)p+offsetof(player, maplevel)), 0, sizeof(player)-offsetof(player, maplevel));
327 
328  /* There are some elements we want initialized to non zero value -
329  * we deal with that below this point.
330  */
331  p->party = NULL;
334  p->swap_first = -1;
335 
336 #ifdef AUTOSAVE
337  p->last_save_tick = 9999999;
338 #endif
339 
340  strcpy(p->savebed_map, first_map_path); /* Init. respawn position */
341 
342  op->contr = p; /* this aren't yet in archetype */
343  p->ob = op;
344  op->speed_left = 0.5;
345  op->speed = 1.0;
346  op->direction = 5; /* So player faces south */
347  op->stats.wc = 2;
348  op->run_away = 25; /* Then we panic... */
349 
350  roll_stats(op);
352  clear_los(p);
353 
354  p->gen_sp_armour = 10;
355  p->last_speed = -1;
356  p->shoottype = range_none;
357  p->bowtype = bow_normal;
358  p->petmode = pet_normal;
359  p->listening = 10;
360  p->last_weapon_sp = -1;
361  p->peaceful = 1; /* default peaceful */
362  p->do_los = 1;
363  p->no_shout = 0; /* default can shout */
364  p->language = -1; // find default language
365  p->unarmed_skill = NULL;
366  p->ticks_played = 0;
367 
368  strncpy(p->title, op->arch->clone.name, sizeof(p->title)-1);
369  p->title[sizeof(p->title)-1] = '\0';
370  op->race = add_string(op->arch->clone.race);
371 
373 
374  /* we need to clear these to -1 and not zero - otherwise,
375  * if a player quits and starts a new character, we wont
376  * send new values to the client, as things like exp start
377  * at zero.
378  */
379  for (i = 0; i < MAX_SKILLS; i++) {
380  p->last_skill_exp[i] = -1;
381  p->last_skill_ob[i] = NULL;
382  }
383  for (i = 0; i < NROFATTACKS; i++) {
384  p->last_resist[i] = -1;
385  }
386  p->last_stats.exp = -1;
387  p->last_weight = (uint32_t)-1;
388 
389  p->socket.update_look = 0;
390  p->socket.look_position = 0;
391  return p;
392 }
393 
400 void set_first_map(object *op) {
401  strcpy(op->contr->maplevel, first_map_path);
402  op->x = -1;
403  op->y = -1;
405 }
406 
419 static void set_player_socket(player *p, socket_struct *ns) {
420  memcpy(&p->socket, ns, sizeof(socket_struct));
421 
422  /* The memcpy above copies the reference to faces sent. So we need to clear
423  * that pointer in ns, otherwise we get a double free.
424  */
425  ns->faces_sent = NULL;
426 
427  if (p->socket.faces_sent == NULL)
429 
430  /* Needed because the socket we just copied over needs to be cleared.
431  * Note that this can result in a client reset if there is partial data
432  * on the incoming socket.
433  */
435 
436 
437 }
438 
456  player *p;
457 
458  p = get_player(NULL);
459  ns->status = Ns_Avail;
460  set_player_socket(p, ns);
461 
463 
464  if (!(flags & ADD_PLAYER_NO_MAP))
465  set_first_map(p->ob);
466 
468 
469  /* In this case, the client is provide all the informatin for the
470  * new character, so just return it. Do not display any messages,
471  * etc
472  */
474  return p;
475 
476  if (flags & ADD_PLAYER_NEW) {
477  roll_again(p->ob);
479  } else {
480  send_rules(p->ob);
481  send_news(p->ob);
482  display_motd(p->ob);
483  get_name(p->ob);
484  }
485  return p;
486 }
487 
499  archetype *start = at;
500 
501  for (;;) {
502  at = get_next_archetype(at);
503  if (at == NULL) {
504  at = get_next_archetype(at);
505  }
506  if (at->clone.type == PLAYER)
507  return at;
508  if (at == start) {
509  LOG(llevError, "No Player archetypes\n");
510  exit(-1);
511  }
512  }
513 }
514 
523 object *get_nearest_player(object *mon) {
524  object *op = NULL;
525  player *pl = NULL;
526  objectlink *ol;
527  unsigned lastdist;
528  rv_vector rv;
529 
530  for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) {
531  /* We should not find free objects on this friendly list, but it
532  * does periodically happen. Given that, lets deal with it.
533  * While unlikely, it is possible the next object on the friendly
534  * list is also free, so encapsulate this in a while loop.
535  */
536  while (QUERY_FLAG(ol->ob, FLAG_FREED) || !QUERY_FLAG(ol->ob, FLAG_FRIENDLY)) {
537  object *tmp = ol->ob;
538 
539  /* Can't do much more other than log the fact, because the object
540  * itself will have been cleared.
541  */
542  LOG(llevDebug, "get_nearest_player: Found free/non friendly object on friendly list\n");
543  ol = ol->next;
545  if (!ol)
546  return op;
547  }
548 
549  /* Remove special check for player from this. First, it looks to cause
550  * some crashes (ol->ob->contr not set properly?), but secondly, a more
551  * complicated method of state checking would be needed in any case -
552  * as it was, a clever player could type quit, and the function would
553  * skip them over while waiting for confirmation. Remove
554  * on_same_map check, as monster_can_detect_enemy() also does this
555  */
556  if (!monster_can_detect_enemy(mon, ol->ob, &rv))
557  continue;
558 
559  if (lastdist > rv.distance) {
560  op = ol->ob;
561  lastdist = rv.distance;
562  }
563  }
564  for (pl = first_player; pl != NULL; pl = pl->next) {
565  if (monster_can_detect_enemy(mon, pl->ob, &rv)) {
566  if (lastdist > rv.distance) {
567  op = pl->ob;
568  lastdist = rv.distance;
569  }
570  }
571  }
572  return op;
573 }
574 
584 #define DETOUR_AMOUNT 2
585 
599 #define MAX_SPACES 50
600 
632 int path_to_player(object *mon, object *pl, unsigned mindiff) {
633  rv_vector rv;
634  int16_t x, y;
635  int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
636  mapstruct *m, *lastmap;
637 
638  if (!get_rangevector(mon, pl, &rv, 0))
639  return 0;
640 
641  if (rv.distance < mindiff)
642  return 0;
643 
644  x = mon->x;
645  y = mon->y;
646  m = mon->map;
647  dir = rv.direction;
648  lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
649  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
650  /* If we can't solve it within the search distance, return now. */
651  if (diff > max)
652  return 0;
653  while (diff > 1 && max > 0) {
654  lastx = x;
655  lasty = y;
656  lastmap = m;
657  x = lastx+freearr_x[dir];
658  y = lasty+freearr_y[dir];
659 
660  mflags = get_map_flags(m, &m, x, y, &x, &y);
661  blocked = (mflags&P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK(m, x, y);
662 
663  /* Space is blocked - try changing direction a little */
664  if ((mflags&P_OUT_OF_MAP)
665  || ((OB_TYPE_MOVE_BLOCK(mon, blocked) || (mflags&P_IS_ALIVE))
666  && (m == mon->map && blocked_link(mon, m, x, y)))) {
667  /* recalculate direction from last good location. Possible
668  * we were not traversing ideal location before.
669  */
670  if (get_rangevector_from_mapcoord(lastmap, lastx, lasty, pl, &rv, 0) && rv.direction != dir) {
671  /* OK - says direction should be different - lets reset the
672  * the values so it will try again.
673  */
674  x = lastx;
675  y = lasty;
676  m = lastmap;
677  dir = firstdir = rv.direction;
678  } else {
679  /* direct path is blocked - try taking a side step to
680  * either the left or right.
681  * Note increase the values in the loop below to be
682  * more than -1/1 respectively will mean the monster takes
683  * bigger detour. Have to be careful about these values getting
684  * too big (3 or maybe 4 or higher) as the monster may just try
685  * stepping back and forth
686  */
687  for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) {
688  if (i == 0)
689  continue; /* already did this, so skip it */
690  /* Use lastdir here - otherwise,
691  * since the direction that the creature should move in
692  * may change, you could get infinite loops.
693  * ie, player is northwest, but monster can only
694  * move west, so it does that. It goes some distance,
695  * gets blocked, finds that it should move north,
696  * can't do that, but now finds it can move east, and
697  * gets back to its original point. lastdir contains
698  * the last direction the creature has successfully
699  * moved.
700  */
701 
702  x = lastx+freearr_x[absdir(lastdir+i)];
703  y = lasty+freearr_y[absdir(lastdir+i)];
704  m = lastmap;
705  mflags = get_map_flags(m, &m, x, y, &x, &y);
706  if (mflags&P_OUT_OF_MAP)
707  continue;
708  blocked = GET_MAP_MOVE_BLOCK(m, x, y);
709  if (OB_TYPE_MOVE_BLOCK(mon, blocked))
710  continue;
711  if (mflags&P_IS_ALIVE)
712  continue;
713 
714  if (m == mon->map && blocked_link(mon, m, x, y))
715  break;
716  }
717  /* go through entire loop without finding a valid
718  * sidestep to take - thus, no valid path.
719  */
720  if (i == (DETOUR_AMOUNT+1))
721  return 0;
722  diff--;
723  lastdir = dir;
724  max--;
725  if (!firstdir)
726  firstdir = dir+i;
727  } /* else check alternate directions */
728  } /* if blocked */
729  else {
730  /* we moved towards creature, so diff is less */
731  diff--;
732  max--;
733  lastdir = dir;
734  if (!firstdir)
735  firstdir = dir;
736  }
737  if (diff <= 1) {
738  /* Recalculate diff (distance) because we may not have actually
739  * headed toward player for entire distance.
740  */
741  if (!get_rangevector_from_mapcoord(m, x, y, pl, &rv, 0))
742  return 0;
743  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
744  }
745  if (diff > max)
746  return 0;
747  }
748  /* If we reached the max, didn't find a direction in time */
749  if (!max)
750  return 0;
751 
752  return firstdir;
753 }
754 
765 void give_initial_items(object *pl, treasurelist *items) {
766  if (pl->randomitems != NULL)
768 
769  FOR_INV_PREPARE(pl, op) {
770  /* Forces get applied per default, unless they have the
771  * flag "neutral" set. Sorry but I can't think of a better way
772  */
773  if (op->type == FORCE && !QUERY_FLAG(op, FLAG_NEUTRAL))
775 
776  /* we never give weapons/armour if these cannot be used
777  * by this player due to race restrictions
778  */
779  if (pl->type == PLAYER) {
782  || (!QUERY_FLAG(pl, FLAG_USE_SHIELD) && IS_SHIELD(op))) {
783  object_remove(op);
785  continue;
786  }
787  }
788 
789  /* This really needs to be better - we should really give
790  * a substitute spellbook. The problem is that we don't really
791  * have a good idea what to replace it with (need something like
792  * a first level treasurelist for each skill.)
793  * remove duplicate skills also
794  */
795  if (op->type == SPELLBOOK || op->type == SKILL) {
796  int found;
797 
798  found = 0;
799  // Make sure we set flags that are checked by object_can_merge
800  // *before* we run object_can_merge. Otherwise, we can get two
801  // entries of the same skill.
802  if (op->type == SKILL) {
804  op->stats.exp = 0;
805  op->level = 1;
806  // Since this also happens to the invisible skills, we need this so that the flags match.
808  }
810  if (object_can_merge(op, tmp)) {
811  found = 1;
812  break;
813  }
815  if (found) {
816  LOG(llevError, "give_initial_items: Removing duplicate object %s\n", op->name);
817  object_remove(op);
819  continue;
820  }
821  if (op->nrof > 1)
822  op->nrof = 1;
823  }
824 
825  if (op->type == SPELLBOOK && op->inv) {
827  }
828 
829  /* Give starting characters identified, uncursed, and undamned
830  * items. Just don't identify gold or silver, or it won't be
831  * merged properly.
832  */
833  if (is_identifiable_type(op)) {
837  }
838  /* lock all 'normal items by default */
839  else
841  } FOR_INV_FINISH(); /* for loop of objects in player inv */
842 
843  /* Need to set up the skill pointers */
845 
853  FOR_INV_FINISH();
854 }
855 
862 void get_name(object *op) {
864  send_query(&op->contr->socket, 0, i18n(op, "What is your name?\n:"));
865 }
866 
873 void get_password(object *op) {
875  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "What is your password?\n:"));
876 }
877 
884 void play_again(object *op) {
885  SockList sl;
886 
887  op->contr->socket.status = Ns_Add;
889  op->chosen_skill = NULL;
890 
891  /*
892  * For old clients, ask if they want to play again.
893  * For clients with account support, just return to character seletion (see below).
894  */
895  if (op->contr->socket.login_method == 0) {
896  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Do you want to play again (a/q)?"));
897  }
898  /* a bit of a hack, but there are various places early in th
899  * player creation process that a user can quit (eg, roll
900  * stats) that isn't removing the player. Taking a quick
901  * look, there are many places that call play_again without
902  * removing the player - it probably makes more sense
903  * to leave it to play_again to remove the object in all
904  * cases.
905  */
906  if (!QUERY_FLAG(op, FLAG_REMOVED))
907  object_remove(op);
908  /* Need to set this to null - otherwise, it could point to garbage,
909  * and draw() doesn't check to see if the player is removed, only if
910  * the map is null or not swapped out.
911  */
912  op->map = NULL;
913 
914  SockList_Init(&sl);
915  SockList_AddString(&sl, "player ");
916  SockList_AddInt(&sl, 0);
917  SockList_AddInt(&sl, 0);
918  SockList_AddInt(&sl, 0);
919  SockList_AddChar(&sl, 0);
920 
921  Send_With_Handling(&op->contr->socket, &sl);
922  SockList_Term(&sl);
923 
924  if (op->contr->socket.login_method > 0) {
925  receive_play_again(op, 'a');
926  }
927 }
928 
937 void receive_play_again(object *op, char key) {
938  if (key == 'q' || key == 'Q') {
940  leave(op->contr, 0); /* ericserver will draw the message */
941  return;
942  } else if (key == 'a' || key == 'A') {
943  player *pl = op->contr;
944  const char *name = op->name;
945 
949  pl = get_player(pl);
950  op = pl->ob;
952  op->contr->password[0] = '~';
953  FREE_AND_CLEAR_STR(op->name);
954  FREE_AND_CLEAR_STR(op->name_pl);
955  if (pl->socket.login_method >= 1 && pl->socket.account_name != NULL) {
956  /* If we are using new login, we send the
957  * list of characters to the client - this should
958  * result in the client popping up this list so
959  * the player can choose which one to play - better
960  * than going to legacy login code.
961  * If the account_name is NULL, it means the client
962  * says it uses account but started playing without logging in.
963  */
966  } else {
967  /* Lets put a space in here */
969  "\n");
970  get_name(op);
971  set_first_map(op);
972  }
973  op->name = name; /* Already added a refcount above */
974  op->name_pl = add_string(name);
975  } else {
976  /* user pressed something else so just ask again... */
977  play_again(op);
978  }
979 }
980 
987 void confirm_password(object *op) {
989  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "Please type your password again.\n:"));
990 }
991 
1002 int get_party_password(object *op, partylist *party) {
1003  if (*party_get_password(party) == '\0') {
1004  return 0;
1005  }
1006 
1008  op->contr->party_to_join = party;
1009  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "What is the password?\n:"));
1010  return 1;
1011 }
1012 
1019 int roll_stat(void) {
1020  int roll[4], i, low_index, k;
1021 
1022  for (i = 0; i < 4; ++i)
1023  roll[i] = (int)RANDOM()%6+1;
1024 
1025  for (i = 0, low_index = 0, k = 7; i < 4; ++i)
1026  if (roll[i] < k)
1027  k = roll[i],
1028  low_index = i;
1029 
1030  for (i = 0, k = 0; i < 4; ++i) {
1031  if (i != low_index)
1032  k += roll[i];
1033  }
1034  return k;
1035 }
1036 
1043 void roll_stats(object *op) {
1044  int sum = 0;
1045  int i = 0, j = 0;
1046  int statsort[7];
1047 
1048  do {
1049  op->stats.Str = roll_stat();
1050  op->stats.Dex = roll_stat();
1051  op->stats.Int = roll_stat();
1052  op->stats.Con = roll_stat();
1053  op->stats.Wis = roll_stat();
1054  op->stats.Pow = roll_stat();
1055  op->stats.Cha = roll_stat();
1056  sum = op->stats.Str+op->stats.Dex+op->stats.Int+op->stats.Con+op->stats.Wis+op->stats.Pow+op->stats.Cha;
1057  } while (sum != settings.roll_stat_points);
1058 
1059  /* Sort the stats so that rerolling is easier... */
1060  statsort[0] = op->stats.Str;
1061  statsort[1] = op->stats.Dex;
1062  statsort[2] = op->stats.Int;
1063  statsort[3] = op->stats.Con;
1064  statsort[4] = op->stats.Wis;
1065  statsort[5] = op->stats.Pow;
1066  statsort[6] = op->stats.Cha;
1067 
1068  /* a quick and dirty bubblesort? */
1069  do {
1070  if (statsort[i] < statsort[i+1]) {
1071  j = statsort[i];
1072  statsort[i] = statsort[i+1];
1073  statsort[i+1] = j;
1074  i = 0;
1075  } else {
1076  i++;
1077  }
1078  } while (i < 6);
1079 
1080  op->stats.Str = statsort[0];
1081  op->stats.Dex = statsort[1];
1082  op->stats.Con = statsort[2];
1083  op->stats.Int = statsort[3];
1084  op->stats.Wis = statsort[4];
1085  op->stats.Pow = statsort[5];
1086  op->stats.Cha = statsort[6];
1087 
1088  op->contr->orig_stats.Str = op->stats.Str;
1089  op->contr->orig_stats.Dex = op->stats.Dex;
1090  op->contr->orig_stats.Int = op->stats.Int;
1091  op->contr->orig_stats.Con = op->stats.Con;
1092  op->contr->orig_stats.Wis = op->stats.Wis;
1093  op->contr->orig_stats.Pow = op->stats.Pow;
1094  op->contr->orig_stats.Cha = op->stats.Cha;
1095 
1096  op->level = 1;
1097  op->stats.exp = 0;
1098  op->stats.ac = 0;
1099 
1100  op->contr->levhp[1] = 9;
1101  op->contr->levsp[1] = 6;
1102  op->contr->levgrace[1] = 3;
1103 
1104  fix_object(op);
1105  op->stats.hp = op->stats.maxhp;
1106  op->stats.sp = op->stats.maxsp;
1107  op->stats.grace = op->stats.maxgrace;
1108  op->contr->orig_stats = op->stats;
1109 }
1110 
1117 void roll_again(object *op) {
1118  esrv_new_player(op->contr, 0);
1119  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "<y> to roll new stats <n> to use stats\n<1-7> <1-7> to swap stats.\nRoll again (y/n/1-7)? "));
1120 }
1121 
1131 static void swap_stat(object *op, int swap_second) {
1132  signed char tmp;
1133 
1134  if (op->contr->swap_first == -1) {
1135  LOG(llevError, "player.c:swap_stat() - swap_first is -1\n");
1136  return;
1137  }
1138 
1139  tmp = get_attr_value(&op->contr->orig_stats, op->contr->swap_first);
1140 
1141  set_attr_value(&op->contr->orig_stats, op->contr->swap_first, get_attr_value(&op->contr->orig_stats, swap_second));
1142 
1143  set_attr_value(&op->contr->orig_stats, swap_second, tmp);
1144 
1146  "%s done\n",
1147  short_stat_name[swap_second]);
1148 
1149  op->stats.Str = op->contr->orig_stats.Str;
1150  op->stats.Dex = op->contr->orig_stats.Dex;
1151  op->stats.Con = op->contr->orig_stats.Con;
1152  op->stats.Int = op->contr->orig_stats.Int;
1153  op->stats.Wis = op->contr->orig_stats.Wis;
1154  op->stats.Pow = op->contr->orig_stats.Pow;
1155  op->stats.Cha = op->contr->orig_stats.Cha;
1156  op->stats.ac = 0;
1157 
1158  op->level = 1;
1159  op->stats.exp = 0;
1160  op->stats.ac = 0;
1161 
1162  op->contr->levhp[1] = 9;
1163  op->contr->levsp[1] = 6;
1164  op->contr->levgrace[1] = 3;
1165 
1166  fix_object(op);
1167  op->stats.hp = op->stats.maxhp;
1168  op->stats.sp = op->stats.maxsp;
1169  op->stats.grace = op->stats.maxgrace;
1170  op->contr->orig_stats = op->stats;
1171  op->contr->swap_first = -1;
1172 }
1173 
1189 void key_roll_stat(object *op, char key) {
1190  int keynum = key-'0';
1191  static const int8_t stat_trans[] = {
1192  -1,
1193  STRENGTH,
1194  DEXTERITY,
1195  CONSTITUTION,
1196  INTELLIGENCE,
1197  WISDOM,
1198  POWER,
1199  CHARISMA,
1200  };
1201 
1202  if (keynum > 0 && keynum <= 7) {
1203  if (op->contr->swap_first == -1) {
1204  op->contr->swap_first = stat_trans[keynum];
1206  "%s ->",
1207  short_stat_name[stat_trans[keynum]]);
1208  } else
1209  swap_stat(op, stat_trans[keynum]);
1210 
1211  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1212  return;
1213  }
1214  switch (key) {
1215  case 'n':
1216  case 'N': {
1217  SET_FLAG(op, FLAG_WIZ);
1218  if (op->map == NULL) {
1219  LOG(llevError, "Map == NULL in state 2\n");
1220  break;
1221  }
1222 
1223  SET_ANIMATION(op, 2); /* So player faces south */
1224  /* Enter exit adds a player otherwise */
1225  add_statbonus(op);
1226  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"));
1228  if (op->msg)
1231  op->msg);
1232  return;
1233  }
1234  case 'y':
1235  case 'Y':
1236  roll_stats(op);
1237  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1238  return;
1239 
1240  case 'q':
1241  case 'Q':
1242  play_again(op);
1243  return;
1244 
1245  default:
1246  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Yes, No, Quit or 1-6. Roll again?"));
1247  return;
1248  }
1249  return;
1250 }
1251 
1265 void key_change_class(object *op, char key) {
1266  int tmp_loop;
1267 
1268  if (key == 'q' || key == 'Q') {
1269  object_remove(op);
1270  play_again(op);
1271  return;
1272  }
1273  if (key == 'd' || key == 'D') {
1274  char buf[MAX_BUF];
1275 
1276  /* this must before then initial items are given */
1277  esrv_new_player(op->contr, op->weight+op->carrying);
1278  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1279 
1280  /* Here we handle the BORN global event */
1282 
1283  /* We then generate a LOGIN event */
1284  events_execute_global_event(EVENT_LOGIN, op->contr, op->contr->socket.host);
1285  player_set_state(op->contr, ST_PLAYING);
1286 
1287  object_set_msg(op, NULL);
1288 
1289  /* We create this now because some of the unique maps will need it
1290  * to save here.
1291  */
1292  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1294 
1295 #ifdef AUTOSAVE
1296  op->contr->last_save_tick = pticks;
1297 #endif
1300  "Welcome to Crossfire!\n Press `?' for help\n");
1301 
1304  "%s entered the game.", op->name);
1305 
1307  give_initial_items(op, op->randomitems);
1310  fix_object(op);
1311 
1312  /* This moves the player to a different start map, if there
1313  * is one for this race
1314  */
1315  if (*first_map_ext_path) {
1316  object *tmp;
1317  char mapname[MAX_BUF];
1318  mapstruct *oldmap;
1319 
1320  oldmap = op->map;
1321 
1322  snprintf(mapname, MAX_BUF-1, "%s/%s", first_map_ext_path, op->arch->name);
1323  /*printf("%s\n", mapname);*/
1324  tmp = object_new();
1326  EXIT_X(tmp) = op->x;
1327  EXIT_Y(tmp) = op->y;
1328  enter_exit(op, tmp);
1329 
1330  if (oldmap != op->map) {
1331  /* map exists, update bed of reality location, in case player dies */
1332  op->contr->bed_x = op->x;
1333  op->contr->bed_y = op->y;
1334  strlcpy(op->contr->savebed_map, mapname, sizeof(op->contr->savebed_map));
1335  }
1336 
1338  } else {
1339  LOG(llevDebug, "first_map_ext_path not set\n");
1340  }
1341  return;
1342  }
1343 
1344  /* Following actually changes the race - this is the default command
1345  * if we don't match with one of the options above.
1346  */
1347 
1348  tmp_loop = 0;
1349  while (!tmp_loop) {
1350  const char *name = add_string(op->name);
1351  int x = op->x, y = op->y;
1352 
1354  object_remove(op);
1355  /* get_player_archetype() is really misnamed - it will
1356  * get the next archetype from the list.
1357  */
1358  op->arch = get_player_archetype(op->arch);
1359  object_copy(&op->arch->clone, op);
1360  op->stats = op->contr->orig_stats;
1361  free_string(op->name);
1362  op->name = name;
1363  free_string(op->name_pl);
1364  op->name_pl = add_string(name);
1365  SET_ANIMATION(op, 2); /* So player faces south */
1366  object_insert_in_map_at(op, op->map, op, 0, x, y);
1367  strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1);
1368  op->contr->title[sizeof(op->contr->title)-1] = '\0';
1369  add_statbonus(op);
1370  tmp_loop = allowed_class(op);
1371  }
1374  fix_object(op);
1375  op->stats.hp = op->stats.maxhp;
1376  op->stats.sp = op->stats.maxsp;
1377  op->stats.grace = 0;
1378  if (op->msg)
1380  op->msg);
1381  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Press any key for the next race.\nPress `d' to play this race.\n"));
1382 }
1383 
1405 int check_race_and_class(living *stats, archetype *race, archetype *opclass)
1406 {
1407  int i, stat, failure=0;
1408 
1409  for (i = 0; i < NUM_STATS; i++) {
1410  stat = get_attr_value(stats, i);
1411  if (race)
1412  stat += get_attr_value(&race->clone.stats, i);
1413 
1414  if (opclass)
1415  stat += get_attr_value(&opclass->clone.stats, i);
1416 
1417  set_attr_value(stats, i, stat);
1418 
1419  /* We process all stats, regardless if there is a failure
1420  * or not.
1421  */
1422  if (stat < MIN_STAT) failure=1;
1423 
1424  /* Maybe this should be an error? Player is losing
1425  * some stats points here, but it is legal.
1426  */
1427  if (stat > settings.max_stat) stat = settings.max_stat;
1428  }
1429  return failure;
1430 
1431 }
1432 
1455 int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
1456 {
1457  const char *name = add_string(op->name);
1458  char buf[MAX_BUF];
1459  object *inv;
1460 
1461  /* Free any objects in character inventory - they
1462  * shouldn't have any, but there is the potential that
1463  * we give them objects below and then get a creation
1464  * failure (stat out of range), in which case
1465  * those objects would be in the inventory.
1466  */
1467  while (op->inv) {
1468  inv = op->inv;
1469  object_remove(inv);
1470  object_free(inv, 0);
1471  }
1472 
1473  object_copy(&race->clone, op);
1474  free_string(op->name);
1475  op->name = name;
1476  free_string(op->name_pl);
1477  op->name_pl = add_string(name);
1478  SET_ANIMATION(op, 2); /* So player faces south */
1479  strlcpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title));
1480 
1481  if (stats) {
1482  /* Copy over the stats. Use this instead a memcpy because
1483  * we only want to copy over a few specific stats, and
1484  * leave things like maxhp, maxsp, etc, unchanged.
1485  */
1486  int i, stat;
1487  for (i = 0; i < NUM_STATS; i++) {
1488  stat = get_attr_value(stats, i);
1489  set_attr_value(&op->stats, i, stat);
1490  set_attr_value(&op->contr->orig_stats, i, stat);
1491  }
1492  } else {
1493  /* Note that this will repeated increase the stat values
1494  * if the caller does not reset them. Only do this
1495  * if stats is not provided - if stats is provided, those
1496  * are already adjusted.
1497  */
1498  add_statbonus(op);
1499 
1500  /* Checks that all stats are greater than 1. Once again,
1501  * only do this if stats are not provided
1502  */
1503  if (!allowed_class(op)) return 1;
1504  }
1505 
1507  op->stats.hp = op->stats.maxhp;
1508  op->stats.sp = op->stats.maxsp;
1509  op->stats.grace = 0;
1510 
1511  /* this must before then initial items are given */
1512  esrv_new_player(op->contr, op->weight+op->carrying);
1513  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1514 
1515  /* This has to be done before class, otherwise the NOCLASSFACECHANGE
1516  * object is not in the inventory, and racial face will get overwritten.
1517  */
1518  give_initial_items(op, op->randomitems);
1519 
1520  if (stats) {
1521  /* Apply class information */
1523  } else {
1524  apply_changes_to_player(op, &opclass->clone, 0);
1525 
1526  /* Checks that all stats are greater than 1 */
1527  if (!allowed_class(op)) return 2;
1528  }
1529 
1530  /* Here we handle the BORN global event */
1532 
1533  /* We then generate a LOGIN event */
1534  events_execute_global_event(EVENT_LOGIN, op->contr, op->contr->socket.host);
1535 
1536  object_set_msg(op, NULL);
1537 
1538  /* We create this now because some of the unique maps will need it
1539  * to save here.
1540  */
1541  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1543 
1544 #ifdef AUTOSAVE
1545  op->contr->last_save_tick = pticks;
1546 #endif
1547 
1550  fix_object(op);
1551 
1554  esrv_add_spells(op->contr, NULL);
1555 
1556  return 0;
1557 
1558 }
1559 
1568 void key_confirm_quit(object *op, char key) {
1569  char buf[MAX_BUF];
1570  mapstruct *mp, *next;
1571 
1572  // this was tested when 'quit' command was issued, but better safe than sorry.
1573  if (QUERY_FLAG(op, FLAG_WAS_WIZ)) {
1574  player_set_state(op->contr, ST_PLAYING);
1575  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOGIN, "Can't quit when in DM mode.");
1576  return;
1577  }
1578 
1579  if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') {
1580  player_set_state(op->contr, ST_PLAYING);
1582  "OK, continuing to play.");
1583  return;
1584  }
1585 
1588  object_remove(op);
1589  op->direction = 0;
1591  "%s quits the game.",
1592  op->name);
1593 
1594  strcpy(op->contr->killer, "quit");
1595  hiscore_check(op, 0);
1596  party_leave(op);
1597  if (settings.set_title == TRUE)
1598  player_set_own_title(op->contr, "");
1599 
1600 
1601  /* We need to hunt for any per player unique maps in memory and
1602  * get rid of them. The trailing slash in the path is intentional,
1603  * so that players named 'Ab' won't match against players 'Abe' pathname
1604  */
1605  snprintf(buf, sizeof(buf), "%s/%s/%s/", settings.localdir, settings.playerdir, op->name);
1606  for (mp = first_map; mp != NULL; mp = next) {
1607  next = mp->next;
1608  if (!strncmp(mp->path, buf, strlen(buf)))
1609  delete_map(mp);
1610  }
1611 
1612  delete_character(op->name);
1613 
1614  /* Remove player from account list and send back data if needed */
1615  if (op->contr->socket.account_chars != NULL) {
1616  op->contr->socket.account_chars = account_char_remove(op->contr->socket.account_chars, op->name);
1617  account_char_save(op->contr->socket.account_name, op->contr->socket.account_chars);
1618  /* char information is reloaded in send_account_players below */
1619  account_char_free(op->contr->socket.account_chars);
1620  op->contr->socket.account_chars = NULL;
1621  account_remove_player(op->contr->socket.account_name, op->name);
1622  send_account_players(&op->contr->socket);
1623  }
1624 
1625  play_again(op);
1626 }
1627 
1634 static void flee_player(object *op) {
1635  int dir, diff;
1636  rv_vector rv;
1637 
1638  if (op->stats.hp < 0) {
1639  LOG(llevDebug, "Fleeing player is dead.\n");
1641  return;
1642  }
1643 
1644  if (op->enemy == NULL) {
1645  LOG(llevDebug, "Fleeing player had no enemy.\n");
1647  return;
1648  }
1649 
1650  /* Seen some crashes here. Since we don't store an
1651  * op->enemy_count, it is possible that something destroys the
1652  * actual enemy, and the object is recycled.
1653  */
1654  if (op->enemy->map == NULL) {
1656  object_set_enemy(op, NULL);
1657  return;
1658  }
1659 
1660  if (!(random_roll(0, 4, op, PREFER_LOW)) && did_make_save(op, op->level, 0)) {
1661  object_set_enemy(op, NULL);
1663  return;
1664  }
1665  if (!get_rangevector(op, op->enemy, &rv, 0)) {
1666  object_set_enemy(op, NULL);
1668  return;
1669  }
1670 
1671  dir = absdir(4+rv.direction);
1672  for (diff = 0; diff < 3; diff++) {
1673  int m = 1-(RANDOM()&2);
1674  if (move_ob(op, absdir(dir+diff*m), op)
1675  || (diff == 0 && move_ob(op, absdir(dir-diff*m), op))) {
1676  return;
1677  }
1678  }
1679  /* Cornered, get rid of scared */
1681  object_set_enemy(op, NULL);
1682 }
1683 
1693 int check_pick(object *op) {
1694  tag_t op_tag;
1695  int stop = 0;
1696  int j, k, wvratio, current_ratio;
1697  char putstring[128], tmpstr[16];
1698 
1699  /* if you're flying, you can't pick up anything */
1700  if (op->move_type&MOVE_FLYING)
1701  return 1;
1702  /* If not a player, don't check anything. */
1703  if (!op->contr) {
1704  return 1;
1705  }
1706 
1707  op_tag = op->count;
1708 
1710  if (object_was_destroyed(op, op_tag))
1711  return 0;
1712 
1713  if (!object_can_pick(op, tmp))
1714  continue;
1715 
1716  if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) {
1717  if (object_matches_string(op, tmp, op->contr->search_str))
1718  pick_up(op, tmp);
1719  continue;
1720  }
1721 
1722  /* high not bit set? We're using the old autopickup model */
1723  if (!(op->contr->mode&PU_NEWMODE)) {
1724  switch (op->contr->mode) {
1725  case 0:
1726  return 1; /* don't pick up */
1727 
1728  case 1:
1729  pick_up(op, tmp);
1730  return 1;
1731 
1732  case 2:
1733  pick_up(op, tmp);
1734  return 0;
1735 
1736  case 3:
1737  return 0; /* stop before pickup */
1738 
1739  case 4:
1740  pick_up(op, tmp);
1741  break;
1742 
1743  case 5:
1744  pick_up(op, tmp);
1745  stop = 1;
1746  break;
1747 
1748  case 6:
1751  pick_up(op, tmp);
1752  break;
1753 
1754  case 7:
1755  if (tmp->type == MONEY || tmp->type == GEM)
1756  pick_up(op, tmp);
1757  break;
1758 
1759  default:
1760  /* use value density */
1761  if (!QUERY_FLAG(tmp, FLAG_UNPAID)
1762  && (price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))) >= op->contr->mode)
1763  pick_up(op, tmp);
1764  }
1765  } else { /* old model */
1766  /* NEW pickup handling */
1767  if (op->contr->mode&PU_DEBUG) {
1768  /* some debugging code to figure out item information */
1770  "item name: %s item type: %d weight/value: %d",
1771  tmp->name ? tmp->name : tmp->arch->name, tmp->type,
1772  (int)(price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))));
1773 
1774 
1775  snprintf(putstring, sizeof(putstring), "...flags: ");
1776  for (k = 0; k < 4; k++) {
1777  for (j = 0; j < 32; j++) {
1778  if ((tmp->flags[k]>>j)&0x01) {
1779  snprintf(tmpstr, sizeof(tmpstr), "%d ", k*32+j);
1780  strcat(putstring, tmpstr);
1781  }
1782  }
1783  }
1785  putstring);
1786  }
1787  /* philosophy:
1788  * It's easy to grab an item type from a pile, as long as it's
1789  * generic. This takes no game-time. For more detailed pickups
1790  * and selections, select-items should be used. This is a
1791  * grab-as-you-run type mode that's really useful for arrows for
1792  * example.
1793  * The drawback: right now it has no frontend, so you need to
1794  * stick the bits you want into a calculator in hex mode and then
1795  * convert to decimal and then 'pickup <#>
1796  */
1797 
1798  /* the first two modes are exclusive: if NOTHING we return, if
1799  * STOP then we stop. All the rest are applied sequentially,
1800  * meaning if any test passes, the item gets picked up. */
1801 
1802  /* if mode is set to pick nothing up, return */
1803 
1804  if (op->contr->mode == PU_NOTHING)
1805  return 1;
1806 
1807  /* if mode is set to stop when encountering objects, return.
1808  * Take STOP before INHIBIT since it doesn't actually pick
1809  * anything up */
1810 
1811  if (op->contr->mode&PU_STOP)
1812  return 0;
1813 
1814  /* useful for going into stores and not losing your settings... */
1815  /* and for battles where you don't want to get loaded down while
1816  * fighting */
1817  if (op->contr->mode&PU_INHIBIT)
1818  return 1;
1819 
1820  /* prevent us from turning into auto-thieves :) */
1821  if (QUERY_FLAG(tmp, FLAG_UNPAID))
1822  continue;
1823 
1824  /* ignore known cursed objects */
1825  if (QUERY_FLAG(tmp, FLAG_KNOWN_CURSED) && op->contr->mode&PU_NOT_CURSED)
1826  continue;
1827 
1828  static int checks[] = {
1829  PU_FOOD,
1830  PU_DRINK,
1831  PU_FLESH,
1832  PU_POTION,
1833  PU_SPELLBOOK,
1835  PU_READABLES,
1837  PU_MAGICAL,
1838  PU_VALUABLES,
1839  PU_JEWELS,
1840  PU_BOW,
1841  PU_ARROW,
1842  PU_ARMOUR,
1843  PU_HELMET,
1844  PU_SHIELD,
1845  PU_BOOTS,
1846  PU_GLOVES,
1847  PU_CLOAK,
1850  PU_KEY,
1851  PU_CONTAINER,
1852  PU_CURSED,
1853  0
1854  };
1855  int found = 0;
1856  for (int m = 0; checks[m] != 0; m++) {
1857  if (op->contr->mode & checks[m] && object_matches_pickup_mode(tmp, checks[m])) {
1858  pick_up(op, tmp);
1859  found = 1;
1860  break;
1861  }
1862  }
1863  if (found) {
1864  continue;
1865  }
1866 
1867  /* any of the last 4 bits set means we use the ratio for value
1868  * pickups */
1869  if (op->contr->mode&PU_RATIO) {
1870  /* use value density to decide what else to grab.
1871  * >=7 was >= op->contr->mode
1872  * >=7 is the old standard setting. Now we take the last 4 bits
1873  * and multiply them by 5, giving 0..15*5== 5..75 */
1874  wvratio = (op->contr->mode&PU_RATIO)*5;
1875  current_ratio = price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1));
1876  if (current_ratio >= wvratio) {
1877  pick_up(op, tmp);
1878  continue;
1879  }
1880  }
1881  } /* the new pickup model */
1882  } FOR_BELOW_FINISH();
1883  return !stop;
1884 }
1885 
1898 static object *find_arrow(object *op, const char *type) {
1899  object *tmp = NULL;
1900 
1902  if (!tmp
1903  && inv->type == CONTAINER
1904  && inv->race == type
1906  tmp = find_arrow(inv, type);
1907  else if (inv->type == ARROW && inv->race == type)
1908  return inv;
1909  FOR_INV_FINISH();
1910  return tmp;
1911 }
1912 
1930 static object *find_better_arrow(object *op, object *target, const char *type, int *better) {
1931  object *tmp = NULL, *ntmp;
1932  int attacknum, attacktype, betterby = 0, i;
1933 
1934  if (!type)
1935  return NULL;
1936 
1937  FOR_INV_PREPARE(op, arrow) {
1938  if (arrow->type == CONTAINER
1939  && arrow->race == type
1940  && QUERY_FLAG(arrow, FLAG_APPLIED)) {
1941  i = 0;
1942  ntmp = find_better_arrow(arrow, target, type, &i);
1943  if (i > betterby) {
1944  tmp = ntmp;
1945  betterby = i;
1946  }
1947  } else if (arrow->type == ARROW && arrow->race == type) {
1948  /* always prefer assassination/slaying */
1949  if (target->race != NULL
1950  && arrow->slaying != NULL
1951  && strstr(arrow->slaying, target->race)) {
1952  if (arrow->attacktype&AT_DEATH) {
1953  if (better)
1954  *better = 100;
1955  return arrow;
1956  } else {
1957  tmp = arrow;
1958  betterby = (arrow->magic+arrow->stats.dam)*2;
1959  }
1960  } else {
1961  for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) {
1962  attacktype = 1<<attacknum;
1963  if ((arrow->attacktype&attacktype) && (target->arch->clone.resist[attacknum]) < 0)
1964  if (((arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100) > betterby) {
1965  tmp = arrow;
1966  betterby = (arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100;
1967  }
1968  }
1969  if ((2+arrow->magic+arrow->stats.dam) > betterby) {
1970  tmp = arrow;
1971  betterby = 2+arrow->magic+arrow->stats.dam;
1972  }
1973  if (arrow->title && (1+arrow->magic+arrow->stats.dam) > betterby) {
1974  tmp = arrow;
1975  betterby = 1+arrow->magic+arrow->stats.dam;
1976  }
1977  }
1978  }
1979  } FOR_INV_FINISH();
1980  if (tmp == NULL)
1981  return find_arrow(op, type);
1982 
1983  if (better)
1984  *better = betterby;
1985  return tmp;
1986 }
1987 
2000 static object *pick_arrow_target(object *op, const char *type, int dir) {
2001  object *tmp = NULL;
2002  mapstruct *m;
2003  int i, mflags, found, number;
2004  int16_t x, y;
2005 
2006  if (op->map == NULL)
2007  return find_arrow(op, type);
2008 
2009  /* do a dex check */
2010  number = (die_roll(2, 40, op, PREFER_LOW)-2)/2;
2011  if (number > (op->stats.Dex+(op->chosen_skill ? op->chosen_skill->level : op->level)))
2012  return find_arrow(op, type);
2013 
2014  m = op->map;
2015  x = op->x;
2016  y = op->y;
2017 
2018  /* find the first target */
2019  for (i = 0, found = 0; i < 20; i++) {
2020  x += freearr_x[dir];
2021  y += freearr_y[dir];
2022  mflags = get_map_flags(m, &m, x, y, &x, &y);
2023  if (mflags&P_OUT_OF_MAP || mflags&P_BLOCKSVIEW) {
2024  tmp = NULL;
2025  break;
2026  } else if (GET_MAP_MOVE_BLOCK(m, x, y) == MOVE_FLY_LOW) {
2027  /* This block presumes arrows and the like are MOVE_FLY_SLOW -
2028  * perhaps a bad assumption.
2029  */
2030  tmp = NULL;
2031  break;
2032  }
2033  if (mflags&P_IS_ALIVE) {
2034  FOR_MAP_PREPARE(m, x, y, tmp2)
2035  if (QUERY_FLAG(tmp2, FLAG_ALIVE)) {
2036  tmp = tmp2;
2037  found++;
2038  break;
2039  }
2040  FOR_MAP_FINISH();
2041  if (found)
2042  break;
2043  }
2044  }
2045  if (tmp == NULL)
2046  return find_arrow(op, type);
2047 
2048  return find_better_arrow(op, HEAD(tmp), type, NULL);
2049 }
2050 
2069 int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy) {
2070  object *bow;
2071  tag_t tag;
2072  int bowspeed, mflags;
2073  mapstruct *m;
2074 
2075  if (!dir) {
2077  "You can't shoot yourself!");
2078  return 0;
2079  }
2080  if (op->type == PLAYER)
2081  bow = op->contr->ranges[range_bow];
2082  else {
2083  /* Don't check for applied - monsters don't apply bows - in that way, they
2084  * don't need to switch back and forth between bows and weapons.
2085  */
2086  bow = object_find_by_type(op, BOW);
2087  if (!bow) {
2088  LOG(llevError, "Range: bow without activated bow (%s).\n", op->name);
2089  return 0;
2090  }
2091  }
2092  if (!bow->race || !bow->skill) {
2094  "Your %s is broken.",
2095  bow->name);
2096  return 0;
2097  }
2098 
2099  bowspeed = bow->stats.sp+get_dex_bonus(op->stats.Dex);
2100 
2101  /* penalize ROF for bestarrow */
2102  if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
2103  bowspeed -= get_dex_bonus(op->stats.Dex)+5;
2104  if (bowspeed < 1)
2105  bowspeed = 1;
2106 
2107  if (arrow == NULL) {
2108  arrow = find_arrow(op, bow->race);
2109  if (arrow == NULL) {
2110  if (op->type == PLAYER)
2113  "You have no %s left.",
2114  bow->race);
2115  /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
2116  else
2118  return 0;
2119  }
2120  }
2121  mflags = get_map_flags(op->map, &m, sx, sy, &sx, &sy);
2122  if (mflags&P_OUT_OF_MAP) {
2123  return 0;
2124  }
2125  if (GET_MAP_MOVE_BLOCK(m, sx, sy)&MOVE_FLY_LOW) {
2126  return 0;
2127  }
2128 
2129  /* this should not happen, but sometimes does */
2130  if (arrow->nrof == 0) {
2131  object_remove(arrow);
2133  return 0;
2134  }
2135 
2136  arrow = object_split(arrow, 1, NULL, 0);
2137  if (arrow == NULL) {
2139  "You have no %s left.",
2140  bow->race);
2141  return 0;
2142  }
2143  object_set_owner(arrow, op);
2144  if (arrow->skill)
2145  free_string(arrow->skill);
2146  arrow->skill = add_refcount(bow->skill);
2147 
2148  arrow->direction = dir;
2149 
2150  if (op->type == PLAYER) {
2151  op->speed_left = 0.01-(float)FABS(op->speed)*100/bowspeed;
2152  fix_object(op);
2153  }
2154 
2155  if (bow->anim_suffix != NULL)
2157 
2158 /* SET_ANIMATION(arrow, arrow->direction);*/
2159  object_update_turn_face(arrow);
2160  arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
2161  arrow->stats.hp = arrow->stats.dam;
2162  arrow->stats.grace = arrow->attacktype;
2163  if (arrow->slaying != NULL)
2164  arrow->spellarg = strdup_local(arrow->slaying);
2165 
2166  /* Note that this was different for monsters - they got their level
2167  * added to the damage. I think the strength bonus is more proper.
2168  */
2169 
2170  arrow->stats.dam += (QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))
2171  +bow->stats.dam
2172  +bow->magic
2173  +arrow->magic;
2174 
2175  /* update the speed */
2176  arrow->speed = (float)((QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))+bow->magic+arrow->magic)/5.0
2177  +(float)bow->stats.dam/7.0;
2178 
2179  if (arrow->speed < 1.0)
2180  arrow->speed = 1.0;
2181  object_update_speed(arrow);
2182  arrow->speed_left = 0;
2183 
2184  if (op->type == PLAYER) {
2185  /* we don't want overflows of wc (sint), so cap the value - mod and pl should be subtracted */
2186  int mod = bow->magic
2187  +arrow->magic
2188  +get_dex_bonus(op->stats.Dex)
2189  +get_thaco_bonus(op->stats.Str)
2190  +arrow->stats.wc
2191  +bow->stats.wc
2192  -wc_mod;
2193  int plmod = (op->chosen_skill ? op->chosen_skill->level : op->level);
2194  if (plmod+mod > 140)
2195  plmod = 140-mod;
2196  else if (plmod+mod < -100)
2197  plmod = -100-mod;
2198  arrow->stats.wc = 20-(int8_t)plmod-(int8_t)mod;
2199 
2200  arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
2201  } else {
2202  arrow->stats.wc = op->stats.wc
2203  -bow->magic
2204  -arrow->magic
2205  -arrow->stats.wc
2206  +wc_mod;
2207 
2208  arrow->level = op->level;
2209  }
2210  if (arrow->attacktype == AT_PHYSICAL)
2211  arrow->attacktype |= bow->attacktype;
2212  if (bow->slaying != NULL)
2213  arrow->slaying = add_string(bow->slaying);
2214 
2215  /* If move_type is ever changed, monster.c:monster_use_bow() needs to be changed too. */
2216  arrow->move_type = MOVE_FLY_LOW;
2217  arrow->move_on = MOVE_FLY_LOW|MOVE_WALK;
2218 
2219  tag = arrow->count;
2220  object_insert_in_map_at(arrow, m, op, 0, sx, sy);
2221 
2222  if (!object_was_destroyed(arrow, tag)) {
2223  play_sound_map(SOUND_TYPE_ITEM, arrow, arrow->direction, "fire");
2224  ob_process(arrow);
2225  }
2226 
2227  return 1;
2228 }
2229 
2240 static int similar_direction(int a, int b) {
2241  /* shortcut the obvious */
2242  if (a == b)
2243  return 1;
2244  /* Made this cleaner using modulus instead of a switch statement
2245  * We only needed the direction and the two adjacent to it
2246  * (8 is adjacent to 1 here) to return true, so a - 1, a, and a + 1
2247  * are the three directions that get "similar" affirmed.
2248  * -- Daniel Hawkins 2015-05-28
2249  */
2250  // The last one for the offset is added afterwards so we get
2251  // 1-8 instead of 0-7 (specifically, 0 becomes 8 without changing
2252  // the other values).
2253  if ((a % 8) + 1 == b || (a + 6 % 8) + 1 == b)
2254  return 1;
2255  return 0;
2256 }
2257 
2274 static int player_fire_bow(object *op, int dir) {
2275  int ret = 0, wcmod = 0;
2276 
2277  if (op->contr->bowtype == bow_bestarrow) {
2278  ret = fire_bow(op, pick_arrow_target(op, op->contr->ranges[range_bow]->race, dir), dir, 0, op->x, op->y);
2279  } else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) {
2280  if (!similar_direction(dir, op->contr->bowtype-bow_n+1))
2281  wcmod = -1;
2282  ret = fire_bow(op, NULL, op->contr->bowtype-bow_n+1, wcmod, op->x, op->y);
2283  } else if (op->contr->bowtype == bow_threewide) {
2284  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2285  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir+2)], op->y+freearr_y[absdir(dir+2)]);
2286  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir-2)], op->y+freearr_y[absdir(dir-2)]);
2287  } else if (op->contr->bowtype == bow_spreadshot) {
2288  ret |= fire_bow(op, NULL, dir, 0, op->x, op->y);
2289  ret |= fire_bow(op, NULL, absdir(dir-1), -5, op->x, op->y);
2290  ret |= fire_bow(op, NULL, absdir(dir+1), -5, op->x, op->y);
2291  } else {
2292  /* Simple case */
2293  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2294  }
2295  return ret;
2296 }
2297 
2310 static void fire_misc_object(object *op, int dir) {
2311  object *item;
2312  char name[MAX_BUF];
2313 
2314  item = op->contr->ranges[range_misc];
2315  if (!item) {
2317  "You have no range item readied.");
2318  return;
2319  }
2320  if (!item->inv) {
2321  LOG(llevError, "Object %s lacks a spell\n", item->name);
2322  return;
2323  }
2324  if (item->type == WAND) {
2325  if (item->stats.food <= 0) {
2326  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2329  "The %s goes poof.",
2330  name);
2331  return;
2332  }
2333  } else if (item->type == ROD) {
2334  if (item->stats.hp < SP_level_spellpoint_cost(item, item->inv, SPELL_HIGHEST)) {
2335  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2338  "The %s whines for a while, but nothing happens.",
2339  name);
2340  return;
2341  }
2342  }
2343 
2344  if (cast_spell(op, item, dir, item->inv, NULL)) {
2345  SET_FLAG(op, FLAG_BEEN_APPLIED); /* You now know something about it */
2346  if (item->type == WAND) {
2348  } else if (item->type == ROD) {
2350  }
2351  }
2352 }
2353 
2362 void fire(object *op, int dir) {
2363 
2364  /* check for loss of invisiblity/hide */
2365  if (action_makes_visible(op))
2366  make_visible(op);
2367 
2368  switch (op->contr->shoottype) {
2369  case range_none:
2370  return;
2371 
2372  case range_bow:
2373  player_fire_bow(op, dir);
2374  return;
2375 
2376  case range_magic: /* Casting spells */
2377  cast_spell(op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL);
2378  return;
2379 
2380  case range_misc:
2381  fire_misc_object(op, dir);
2382  return;
2383 
2384  case range_golem: /* Control summoned monsters from scrolls */
2385  if (op->contr->ranges[range_golem] == NULL
2386  || op->contr->golem_count != op->contr->ranges[range_golem]->count) {
2387  op->contr->ranges[range_golem] = NULL;
2388  op->contr->shoottype = range_none;
2389  op->contr->golem_count = 0;
2390  } else
2391  pets_control_golem(op->contr->ranges[range_golem], dir);
2392  return;
2393 
2394  case range_skill:
2395  if (!op->chosen_skill) {
2396  if (op->type == PLAYER)
2398  "You have no applicable skill to use.");
2399  return;
2400  }
2401  (void)do_skill(op, op, op->chosen_skill, dir, NULL);
2402  return;
2403 
2404  case range_builder:
2405  apply_map_builder(op, dir);
2406  return;
2407 
2408  default:
2410  "Illegal shoot type.");
2411  return;
2412  }
2413 }
2414 
2434 object *find_key(object *pl, object *container, object *door) {
2435  object *tmp, *key;
2436 
2437  /* Should not happen, but sanity checking is never bad */
2438  if (container->inv == NULL)
2439  return NULL;
2440 
2441  /* First, lets try to find a key in the top level inventory */
2442  tmp = NULL;
2443  if (door->type == DOOR) {
2444  int flag = FLAG_UNPAID;
2445  tmp = object_find_by_type_without_flags(container, KEY, &flag, 1);
2446  }
2447  /* For sanity, we should really check door type, but other stuff
2448  * (like containers) can be locked with special keys
2449  */
2450  if (!tmp && door->slaying != NULL) {
2452  }
2453  /* No key found - lets search inventories now */
2454  /* If we find and use a key in an inventory, return at that time.
2455  * otherwise, if we search all the inventories and still don't find
2456  * a key, return
2457  */
2458  if (!tmp) {
2459  FOR_INV_PREPARE(container, tmp) {
2460  /* No reason to search empty containers */
2461  if (tmp->type == CONTAINER && tmp->inv) {
2462  key = find_key(pl, tmp, door);
2463  if (key != NULL)
2464  return key;
2465  }
2466  } FOR_INV_FINISH();
2467  return NULL;
2468  }
2469  /* We get down here if we have found a key. Now if its in a container,
2470  * see if we actually want to use it
2471  */
2472  if (pl != container) {
2473  /* Only let players use keys in containers */
2474  if (!pl->contr)
2475  return NULL;
2476  /* cases where this fails:
2477  * If we only search the player inventory, return now since we
2478  * are not in the players inventory.
2479  * If the container is not active, return now since only active
2480  * containers can be used.
2481  * If we only search keyrings and the container does not have
2482  * a race/isn't a keyring.
2483  * No checking for all containers - to fall through past here,
2484  * inv must have been an container and must have been active.
2485  *
2486  * Change the color so that the message doesn't disappear with
2487  * all the others.
2488  */
2489  if (pl->contr->usekeys == key_inventory
2490  || !QUERY_FLAG(container, FLAG_APPLIED)
2491  || (pl->contr->usekeys == keyrings && (!container->race || strcmp(container->race, "keys")))) {
2492  char name_tmp[MAX_BUF], name_cont[MAX_BUF];
2493 
2494  query_name(tmp, name_tmp, MAX_BUF);
2495  query_name(container, name_cont, MAX_BUF);
2498  "The %s in your %s vibrates as you approach the door",
2499  name_tmp, name_cont);
2500  return NULL;
2501  }
2502  }
2503  return tmp;
2504 }
2505 
2516 static int player_attack_door(object *op, object *door) {
2517  /* If its a door, try to find a use a key. If we do destroy the door,
2518  * might as well return immediately as there is nothing more to do -
2519  * otherwise, we fall through to the rest of the code.
2520  */
2521  object *key = find_key(op, op, door);
2522 
2523  assert(door->type == DOOR || door->type == LOCKED_DOOR);
2524 
2525  /* IF we found a key, do some extra work */
2526  if (key) {
2527  char name[HUGE_BUF];
2528 
2529  play_sound_map(SOUND_TYPE_GROUND, door, 0, "open");
2530  if (action_makes_visible(op))
2531  make_visible(op);
2532  if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
2533  spring_trap(door->inv, op);
2534 
2538  "You open the door with the %s",
2539  name);
2540 
2541  if (door->type == DOOR)
2542  remove_door(door);
2543  else
2544  remove_locked_door(door); /* remove door without violence ;-) */
2545 
2546  /* Do this after we print the message */
2547  object_decrease_nrof_by_one(key); /* Use up one of the keys */
2548 
2549  return 1; /* Nothing more to do below */
2550 
2551  }
2552 
2553  if (door->type == LOCKED_DOOR) {
2554  /* Might as well return now - no other way to open this */
2556  door->msg);
2557  return 1;
2558  }
2559 
2560  if (door->type == DOOR && op->contr && !op->contr->run_on) {
2561  /* Player so try to pick the door */
2562  object *lock = find_skill_by_name(op, "lockpicking");
2563  if (lock) {
2564  /* Even if the lockpicking failed, don't go on moving, player should explicitely attack or run
2565  * to bash the door. */
2566  do_skill(op, op, lock, op->facing, NULL);
2567  return 1;
2568  }
2569  }
2570 
2571  return 0;
2572 }
2573 
2587 void move_player_attack(object *op, int dir) {
2588  object *mon, *tpl, *mon_owner;
2589  int16_t nx, ny;
2590  int on_battleground;
2591  mapstruct *m;
2592 
2593  if (op->contr->transport)
2594  tpl = op->contr->transport;
2595  else
2596  tpl = op;
2597  assert(tpl->map != NULL); // op must be on a map in order to move it
2598  nx = freearr_x[dir]+tpl->x;
2599  ny = freearr_y[dir]+tpl->y;
2600 
2601  on_battleground = op_on_battleground(tpl, NULL, NULL, NULL);
2602 
2603  // Temporarily store the map we are on before movement.
2604  mapstruct *bef = tpl->map;
2605 
2606  /* If braced, or can't move to the square, and it is not out of the
2607  * map, attack it. Note order of if statement is important - don't
2608  * want to be calling move_ob if braced, because move_ob will move the
2609  * player. This is a pretty nasty hack, because if we could
2610  * move to some space, it then means that if we are braced, we should
2611  * do nothing at all. As it is, if we are braced, we go through
2612  * quite a bit of processing. However, it probably is less than what
2613  * move_ob uses.
2614  */
2615  if ((op->contr->braced || !move_ob(tpl, dir, tpl)) && !out_of_map(tpl->map, nx, ny)) {
2616  if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2617  m = get_map_from_coord(tpl->map, &nx, &ny);
2618  if (!m)
2619  return; /* Don't think this should happen */
2620  } else
2621  m = tpl->map;
2622 
2623  if (GET_MAP_OB(m, nx, ny) == NULL) {
2624  /* LOG(llevError, "player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n");*/
2625  return;
2626  }
2627 
2628  mon = NULL;
2629  /* Go through all the objects, and find ones of interest. Only stop if
2630  * we find a monster - that is something we know we want to attack.
2631  * if its a door or barrel (can roll) see if there may be monsters
2632  * on the space
2633  */
2634  FOR_MAP_PREPARE(m, nx, ny, tmp) {
2635  if (tmp == op) {
2636  continue;
2637  }
2638  if (QUERY_FLAG(tmp, FLAG_ALIVE)) {
2639  mon = tmp;
2640  /* Gros: Objects like (pass-through) doors are alive, but haven't
2641  * their monster flag set - so this is a good way attack real
2642  * monsters in priority.
2643  */
2644  if (QUERY_FLAG(tmp, FLAG_MONSTER))
2645  break;
2646  }
2647  if (tmp->type == LOCKED_DOOR || QUERY_FLAG(tmp, FLAG_CAN_ROLL))
2648  mon = tmp;
2649  } FOR_MAP_FINISH();
2650 
2651  if (mon == NULL) /* This happens anytime the player tries to move */
2652  return; /* into a wall */
2653 
2654  mon = HEAD(mon);
2655  if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2656  if (player_attack_door(op, mon))
2657  return;
2658 
2659  /* The following deals with possibly attacking peaceful
2660  * or friendly creatures. Basically, all players are considered
2661  * unaggressive. If the moving player has peaceful set, then the
2662  * object should be pushed instead of attacked. It is assumed that
2663  * if you are braced, you will not attack friends accidently,
2664  * and thus will not push them.
2665  */
2666 
2667  /* If the creature is a pet, push it even if the player is not
2668  * peaceful. Our assumption is the creature is a pet if the
2669  * player owns it and it is either friendly or unaggressive.
2670  */
2671  mon_owner = object_get_owner(mon);
2672  if ((op->type == PLAYER)
2673  && (mon_owner == op || (mon_owner != NULL && mon_owner->type == PLAYER && mon_owner->contr->party != NULL && mon_owner->contr->party == op->contr->party))
2675  /* If we're braced, we don't want to switch places with it */
2676  if (op->contr->braced)
2677  return;
2678  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2679  (void)push_ob(mon, dir, op);
2680  if (op->contr->tmp_invis || op->hide)
2681  make_visible(op);
2682  return;
2683  }
2684 
2685  /* in certain circumstances, you shouldn't attack friendly
2686  * creatures. Note that if you are braced, you can't push
2687  * someone, but put it inside this loop so that you won't
2688  * attack them either.
2689  */
2690  if ((mon->type == PLAYER || mon->enemy != op)
2692  && (op->contr->peaceful && !on_battleground)) {
2693  if (!op->contr->braced) {
2694  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2695  (void)push_ob(mon, dir, op);
2696  } else {
2698  "You withhold your attack");
2699  }
2700  if (op->contr->tmp_invis || op->hide)
2701  make_visible(op);
2702  }
2703 
2704  /* If the object is a boulder or other rollable object, then
2705  * roll it if not braced. You can't roll it if you are braced.
2706  */
2707  else if (QUERY_FLAG(mon, FLAG_CAN_ROLL) && (!op->contr->braced)) {
2708  recursive_roll(mon, dir, op);
2709  if (action_makes_visible(op))
2710  make_visible(op);
2711 
2712  /* Any generic living creature. Including things like doors.
2713  * Way it works is like this: First, it must have some hit points
2714  * and be living. Then, it must be one of the following:
2715  * 1) Not a player, 2) A player, but of a different party. Note
2716  * that party_number -1 is no party, so attacks can still happen.
2717  */
2718  } else if ((mon->stats.hp >= 0)
2720  && ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) {
2721  /* If the player hasn't hit something this tick, and does
2722  * so, give them speed boost based on weapon speed. Doing
2723  * it here is better than process_players2, which basically
2724  * incurred a 1 tick offset.
2725  */
2726  if (op->weapon_speed_left < 0) {
2727  op->speed_left = -0.01;
2728  return;
2729  }
2730  op->weapon_speed_left -= 1.0;
2731 
2732  skill_attack(mon, op, 0, NULL, NULL);
2733 
2734  /* If attacking another player, that player gets automatic
2735  * hitback, and doesn't loose luck either.
2736  * Disable hitback on the battleground or if the target is
2737  * the wiz.
2738  */
2739  if (mon->type == PLAYER
2740  && mon->stats.hp >= 0
2741  && !mon->contr->has_hit
2742  && !on_battleground
2743  && !QUERY_FLAG(mon, FLAG_WIZ)) {
2744  short luck = mon->stats.luck;
2745  mon->contr->has_hit = 1;
2746  skill_attack(op, mon, 0, NULL, NULL);
2747  mon->stats.luck = luck;
2748  }
2749  if (action_makes_visible(op))
2750  make_visible(op);
2751  }
2752  } /* if player should attack something */
2753  else if (bef != tpl->map) {
2754  player_map_change_common(op, bef, tpl->map);
2755  }
2756 }
2757 
2764 static void update_transport_block(object *transport, int dir) {
2765  object *part;
2766  int sx, sy, x, y;
2767 
2768  object_get_multi_size(transport, &sx, &sy, NULL, NULL);
2769  assert(sx == sy);
2770 
2771  if (dir == 1 || dir == 5) {
2772  part = transport;
2773  for (y = 0; y <= sy; y++) {
2774  for (x = 0; x < sx; x++) {
2775  part->move_type = transport->move_type;
2776  part = part->more;
2777  }
2778  part->move_type = 0;
2779  part = part->more;
2780  }
2781  } else if (dir == 3 || dir == 7) {
2782  part = transport;
2783  for (y = 0; y < sy; y++) {
2784  for (x = 0; x <= sx; x++) {
2785  part->move_type = transport->move_type;
2786  part = part->more;
2787  }
2788  }
2789  while (part) {
2790  part->move_type = 0;
2791  part = part->more;
2792  }
2793  } else {
2794  for (part = transport; part; part = part->more) {
2795  part->move_type = transport->move_type;
2796  }
2797  }
2798 }
2799 
2809 static int turn_one_transport(object *transport, object *captain, int dir) {
2810  int x, y, scroll_dir = 0;
2811 
2812  assert(transport->type == TRANSPORT);
2813 
2814  x = transport->x;
2815  y = transport->y;
2816 
2817  if (transport->direction == 1 && dir == 8) {
2818  x--;
2819  } else if (transport->direction == 2 && dir == 3) {
2820  y++;
2821  } else if (transport->direction == 3 && dir == 2) {
2822  y--;
2823  } else if (transport->direction == 5 && dir == 6) {
2824  x--;
2825  } else if (transport->direction == 6 && dir == 5) {
2826  x++;
2827  } else if (transport->direction == 7 && dir == 8) {
2828  y--;
2829  } else if (transport->direction == 8 && dir == 7) {
2830  y++;
2831  } else if (transport->direction == 8 && dir == 1) {
2832  x++;
2833  }
2834 
2835  update_transport_block(transport, dir);
2836  object_remove(transport);
2837  if (ob_blocked(transport, transport->map, x, y)) {
2838  update_transport_block(transport, transport->direction);
2839  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2840  return 2;
2841  }
2842 
2843  if (x != transport->x || y != transport->y) {
2844 /* assert(scroll_dir != 0);*/
2845 
2846  FOR_INV_PREPARE(transport, pl) {
2847  if (pl->type == PLAYER) {
2848  pl->contr->do_los = 1;
2849  pl->map = transport->map;
2850  pl->x = x;
2851  pl->y = y;
2852  esrv_map_scroll(&pl->contr->socket, freearr_x[scroll_dir], freearr_y[scroll_dir]);
2853  pl->contr->socket.update_look = 1;
2854  pl->contr->socket.look_position = 0;
2855  }
2856  } FOR_INV_FINISH();
2857  }
2858 
2859  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2860  transport->direction = dir;
2861  transport->facing = dir;
2862  animate_object(transport, dir);
2863  captain->direction = dir;
2864  return 1;
2865 }
2866 
2879 static int turn_transport(object *transport, object *captain, int dir) {
2880  assert(transport->type == TRANSPORT);
2881 
2882  if (object_value_set(transport, "turnable_transport") == false) {
2883  transport->direction = dir;
2884  transport->facing = dir;
2885  if (QUERY_FLAG(transport, FLAG_ANIMATE)) {
2886  animate_object(transport, dir);
2887  }
2888  captain->direction = dir;
2889  return 0;
2890  }
2891 
2892  if (transport->direction == dir)
2893  return 0;
2894 
2895  if (absdir(transport->direction-dir) > 2)
2896  return turn_one_transport(transport, captain, absdir(transport->direction+1));
2897  else
2898  return turn_one_transport(transport, captain, absdir(transport->direction-1));
2899 }
2900 
2912 int move_player(object *op, int dir) {
2913  object *transport = op->contr->transport; //< Transport player is in
2914 
2915  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2916  return 0;
2917 
2918  /* Sanity check: make sure dir is valid */
2919  if ((dir < 0) || (dir >= 9)) {
2920  LOG(llevError, "move_player: invalid direction %d\n", dir);
2921  return 0;
2922  }
2923 
2924  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
2925  dir = get_randomized_dir(dir);
2926 
2927  op->facing = dir;
2928 
2929  if (transport) {
2930  /* transport->contr is set up for the person in charge of the boat.
2931  * if that isn't this person, he can't steer it, etc
2932  */
2933  if (transport->contr != op->contr)
2934  return 0;
2935 
2936  /* Transport is out of movement. But update dir so it at least
2937  * will point in the same direction if player is running.
2938  */
2939  if (transport->speed_left < 0.0) {
2940  return 0;
2941  }
2942  /* Remove transport speed. Give player just a little speed -
2943  * enough so that they will get an action again quickly.
2944  */
2945  transport->speed_left -= 1.0;
2946  if (op->speed_left < 0.0)
2947  op->speed_left = -0.01;
2948 
2949  int turn = turn_transport(transport, op, dir);
2950  if (turn != 0)
2951  return 0;
2952  } else {
2953  if (op->hide) {
2954  do_hidden_move(op);
2955  }
2956 
2957  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
2958  * and leave us with state = 0, which we don't want to change again. */
2959  op->state++; /* player moved, so change animation. */
2960  animate_object(op, op->facing);
2961  }
2962 
2963  if (op->contr->fire_on) {
2964  fire(op, dir);
2965  } else
2966  move_player_attack(op, dir);
2967 
2968  int pick = check_pick(op);
2969 
2970  /* Add special check for newcs players and fire on - this way, the
2971  * server can handle repeat firing.
2972  */
2973  if (op->contr->fire_on || (op->contr->run_on && pick != 0)) {
2974  op->direction = dir;
2975  } else {
2976  op->direction = 0;
2977  }
2978  return 0;
2979 }
2980 
2991 int face_player(object *op, int dir) {
2992  object *transport = op->contr->transport; //< Transport player is in
2993 
2994  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2995  return 0;
2996 
2997  /* Sanity check: make sure dir is valid */
2998  if ((dir < 0) || (dir >= 9)) {
2999  LOG(llevError, "move_player: invalid direction %d\n", dir);
3000  return 0;
3001  }
3002 
3003  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
3004  dir = get_randomized_dir(dir);
3005 
3006  op->facing = dir;
3007 
3008  if (transport) {
3009  /* transport->contr is set up for the person in charge of the boat.
3010  * if that isn't this person, he can't steer it, etc
3011  */
3012  if (transport->contr != op->contr)
3013  return 0;
3014 
3015  turn_transport(transport, op, dir);
3016  } else {
3017  if (op->hide) {
3018  do_hidden_move(op);
3019  }
3020 
3021  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
3022  * and leave us with state = 0, which we don't want to change again. */
3023  op->state++; /* player moved, so change animation. */
3024  animate_object(op, op->facing);
3025  }
3026 
3027  /* Add special check for newcs players and fire on - this way, the
3028  * server can handle repeat firing.
3029  */
3030  if (op->contr->fire_on || op->contr->run_on) {
3031  op->direction = dir;
3032  } else {
3033  op->direction = 0;
3034  }
3035  return 0;
3036 }
3037 
3050 int handle_newcs_player(object *op) {
3051  if (op->contr->hidden) {
3052  op->invisible = 1000;
3053  /* the socket code flashes the player visible/invisible
3054  * depending on the value if invisible, so we need to
3055  * alternate it here for it to work correctly.
3056  */
3057  if (pticks&2)
3058  op->invisible--;
3059  } else if (op->invisible && !(QUERY_FLAG(op, FLAG_MAKE_INVIS))) {
3060  op->invisible--;
3061  if (!op->invisible) {
3062  make_visible(op);
3064  "Your invisibility spell runs out.");
3065  }
3066  }
3067 
3068  if (QUERY_FLAG(op, FLAG_SCARED)) {
3069  flee_player(op);
3070  /* If player is still scared, that is his action for this tick */
3071  if (QUERY_FLAG(op, FLAG_SCARED)) {
3072  op->speed_left--;
3073  return 0;
3074  }
3075  }
3076 
3077  /* I've been seeing crashes where the golem has been destroyed, but
3078  * the player object still points to the defunct golem. The code that
3079  * destroys the golem looks correct, and it doesn't always happen, so
3080  * put this in a a workaround to clean up the golem pointer.
3081  */
3082  if (op->contr->ranges[range_golem]
3083  && ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG(op->contr->ranges[range_golem], FLAG_REMOVED))) {
3084  op->contr->ranges[range_golem] = NULL;
3085  op->contr->golem_count = 0;
3086  }
3087 
3088  /*
3089  * If the player has been paralyzed, we unmark the flag and give a message to the player
3090  */
3091  if (QUERY_FLAG(op, FLAG_PARALYZED)) {
3093  // TODO: Is this check necessary? We are in player.c, after all.
3094  if (op->type == PLAYER)
3095  {
3097  "You can stretch your stiff joints once more.");
3098  }
3099  }
3100 
3101  if (op->direction && (op->contr->run_on || op->contr->fire_on)) {
3102  /* All move commands take 1 tick, at least for now */
3103  op->speed_left--;
3104 
3105  /* Instead of all the stuff below, let move_player take care
3106  * of it. Also, some of the skill stuff is only put in
3107  * there, as well as the confusion stuff.
3108  */
3109  move_player(op, op->direction);
3110  if (op->speed_left > 0)
3111  return 1;
3112  else
3113  return 0;
3114  }
3115  return 0;
3116 }
3117 
3128 static int save_life(object *op) {
3129  object *tmp;
3130 
3131  if (!QUERY_FLAG(op, FLAG_LIFESAVE))
3132  return 0;
3133 
3135  if (tmp != NULL) {
3136  char name[MAX_BUF];
3137 
3139  play_sound_map(SOUND_TYPE_ITEM, tmp, 0, "evaporate");
3141  "Your %s vibrates violently, then evaporates.",
3142  name);
3143  object_remove(tmp);
3146  if (op->stats.hp < 0)
3147  op->stats.hp = op->stats.maxhp;
3148  if (op->stats.food < 0)
3149  op->stats.food = MAX_FOOD;
3150  fix_object(op);
3151  return 1;
3152  }
3153  LOG(llevError, "Error: LIFESAVE set without applied object.\n");
3155  enter_player_savebed(op); /* bring him home. */
3156  return 0;
3157 }
3158 
3171 void remove_unpaid_objects(object *op, object *env, int free_items) {
3173  if (QUERY_FLAG(op, FLAG_UNPAID)) {
3174  object_remove(op);
3175  if (free_items)
3177  else
3178  object_insert_in_map_at(op, env->map, NULL, 0, env->x, env->y);
3179  } else if (op->inv)
3180  remove_unpaid_objects(op->inv, env, free_items);
3182 }
3183 
3201 static const char *gravestone_text(object *op, char *buf2, int len) {
3202  char buf[MAX_BUF];
3203  time_t now = time(NULL);
3204 
3205  strncpy(buf2, " R.I.P.\n\n", len);
3206  if (op->type == PLAYER)
3207  snprintf(buf, sizeof(buf), "%s the %s\n", op->name, op->contr->title);
3208  else
3209  snprintf(buf, sizeof(buf), "%s\n", op->name);
3210  strncat(buf2, " ", 20-strlen(buf)/2);
3211  strncat(buf2, buf, len-strlen(buf2)-1);
3212  if (op->type == PLAYER)
3213  snprintf(buf, sizeof(buf), "who was in level %d when killed\n", op->level);
3214  else
3215  snprintf(buf, sizeof(buf), "who was in level %d when died.\n\n", op->level);
3216  strncat(buf2, " ", 20-strlen(buf)/2);
3217  strncat(buf2, buf, len-strlen(buf2)-1);
3218  if (op->type == PLAYER) {
3219  snprintf(buf, sizeof(buf), "by %s.\n\n", op->contr->killer);
3220  strncat(buf2, " ", 21-strlen(buf)/2);
3221  strncat(buf2, buf, len-strlen(buf2)-1);
3222  }
3223  strftime(buf, MAX_BUF, "%b %d %Y\n", localtime(&now));
3224  strncat(buf2, " ", 20-strlen(buf)/2);
3225  strncat(buf2, buf, len-strlen(buf2)-1);
3226  return buf2;
3227 }
3228 
3236 void do_some_living(object *op) {
3237  int last_food = op->stats.food;
3238  int gen_hp, gen_sp, gen_grace;
3239  int rate_hp = 1200;
3240  int rate_sp = 2500;
3241  int rate_grace = 2000;
3242 
3243  if (op->contr->state == ST_PLAYING) {
3244  /* these next three if clauses make it possible to SLOW DOWN
3245  hp/grace/spellpoint regeneration. */
3246  if (op->contr->gen_hp >= 0)
3247  gen_hp = (op->contr->gen_hp+1)*op->stats.maxhp;
3248  else {
3249  gen_hp = op->stats.maxhp;
3250  rate_hp -= rate_hp/2*op->contr->gen_hp;
3251  }
3252  if (op->contr->gen_sp >= 0)
3253  gen_sp = (op->contr->gen_sp+1)*op->stats.maxsp;
3254  else {
3255  gen_sp = op->stats.maxsp;
3256  rate_sp -= rate_sp/2*op->contr->gen_sp;
3257  }
3258  if (op->contr->gen_grace >= 0)
3259  gen_grace = (op->contr->gen_grace+1)*op->stats.maxgrace;
3260  else {
3261  gen_grace = op->stats.maxgrace;
3262  rate_grace -= rate_grace/2*op->contr->gen_grace;
3263  }
3264 
3265  /* Regenerate Spell Points */
3266  if (op->contr->ranges[range_golem] == NULL && --op->last_sp < 0) {
3267  gen_sp = gen_sp*10/MAX(op->contr->gen_sp_armour, 10);
3268  if (op->stats.sp < op->stats.maxsp) {
3269  op->stats.sp++;
3270  /* dms do not consume food */
3271  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3272  op->stats.food--;
3273  if (op->contr->digestion < 0)
3274  op->stats.food += op->contr->digestion;
3275  else if (op->contr->digestion > 0
3276  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3277  op->stats.food = last_food;
3278  }
3279  }
3280  op->last_sp = rate_sp/(MAX(gen_sp, 20)+10);
3281  }
3282 
3283  /* Regenerate Grace */
3284  /* I altered this a little - maximum grace is only achieved through prayer -b.t.*/
3285  if (--op->last_grace < 0) {
3286  if (op->stats.grace < op->stats.maxgrace/2)
3287  op->stats.grace++; /* no penalty in food for regaining grace */
3288  op->last_grace = rate_grace/(MAX(gen_grace, 20)+10);
3289  /* wearing stuff doesn't detract from grace generation. */
3290  }
3291 
3292  /* Regenerate Hit Points (unless you are a wraith player) */
3293  if (--op->last_heal < 0 && !is_wraith_pl(op)) {
3294  if (op->stats.hp < op->stats.maxhp) {
3295  op->stats.hp++;
3296  /* dms do not consume food */
3297  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3298  op->stats.food--;
3299  if (op->contr->digestion < 0)
3300  op->stats.food += op->contr->digestion;
3301  else if (op->contr->digestion > 0
3302  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3303  op->stats.food = last_food;
3304  }
3305  }
3306  op->last_heal = rate_hp/(MAX(gen_hp, 20)+10);
3307  }
3308 
3309  /* Digestion */
3310  if (--op->last_eat < 0) {
3311  int bonus = MAX(op->contr->digestion, 0);
3312  int penalty = MAX(-op->contr->digestion, 0);
3313  if (op->contr->gen_hp > 0)
3314  op->last_eat = 25*(1+bonus)/(op->contr->gen_hp+penalty+1);
3315  else
3316  op->last_eat = 25*(1+bonus)/(penalty+1);
3317  /* dms do not consume food */
3318  if (!QUERY_FLAG(op, FLAG_WIZ))
3319  op->stats.food--;
3320  }
3321  }
3322 
3323  if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) {
3324  if (is_wraith_pl(op))
3325  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "You feel a hunger for living flesh.");
3326  /* Only allow eat if not paralyzed. Otherwise our paralyzed player is "moving" to eat.
3327  * Daniel Hawkins 2017-08-23
3328  */
3329  else if (!QUERY_FLAG(op, FLAG_PARALYZED)){
3330  object *flesh = NULL;
3331 
3332  FOR_INV_PREPARE(op, tmp) {
3333  if (!QUERY_FLAG(tmp, FLAG_UNPAID)) {
3334  if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) {
3336  "You blindly grab for a bite of food.");
3337  apply_manual(op, tmp, 0);
3338  if (op->stats.food >= 0 || op->stats.hp < 0)
3339  break;
3340  } else if (tmp->type == FLESH)
3341  flesh = tmp;
3342  } /* End if paid for object */
3343  } FOR_INV_FINISH(); /* end of for loop */
3344  /* If player is still starving, it means they don't have any food, so
3345  * eat flesh instead.
3346  */
3347  if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) {
3349  "You blindly grab for a bite of food.");
3350  apply_manual(op, flesh, 0);
3351  }
3352  } /* end not wraith and not paralyzed */
3353  else { // Print a message for when the player is starving and paralyzed
3354  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "Your stomach rumbles, but you can't reach your food.");
3355  } /* end not wraith and is paralyzed */
3356  } /* end if player is starving */
3357 
3358  if (op->stats.food < 0 && op->stats.hp > 0){
3359  // We know food < 0, so we want the absolute value of food
3360  int32_t adjust_by = MIN(-(op->stats.food), op->stats.hp);
3361  op->stats.food += adjust_by;
3362  op->stats.hp -= adjust_by;
3363  }
3364 
3365  if (!op->contr->state && !QUERY_FLAG(op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
3366  kill_player(op, NULL);
3367 }
3368 
3375 static void loot_object(object *op) {
3376  object *tmp2;
3377 
3378  if (op->container) { /* close open sack first */
3379  apply_container(op, op->container, AP_NULL);
3380  }
3381 
3382  FOR_INV_PREPARE(op, tmp) {
3383  if (tmp->invisible)
3384  continue;
3385  object_remove(tmp);
3386  tmp->x = op->x,
3387  tmp->y = op->y;
3388  if (tmp->type == CONTAINER) { /* empty container to ground */
3389  loot_object(tmp);
3390  }
3391  if (!QUERY_FLAG(tmp, FLAG_UNIQUE)
3393  if (tmp->nrof > 1) {
3394  tmp2 = object_split(tmp, 1+RANDOM()%(tmp->nrof-1), NULL, 0);
3396  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3397  } else
3399  } else
3400  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3401  } FOR_INV_FINISH();
3402 }
3403 
3414 static void restore_player(object *op) {
3415  object *tmp;
3416  archetype *at = find_archetype("poisoning");
3417  if (at != NULL) {
3418  tmp = arch_present_in_ob(at, op);
3419  if (tmp) {
3420  object_remove(tmp);
3423  "Your body feels cleansed");
3424  }
3425  }
3426 
3427  at = find_archetype("confusion");
3428  if (at != NULL) {
3429  tmp = arch_present_in_ob(at, op);
3430  if (tmp) {
3431  object_remove(tmp);
3434  "Your mind feels clearer");
3435  }
3436  }
3437 
3438  cure_disease(op, NULL, NULL); /* remove any disease */
3439 }
3440 
3452 void kill_player(object *op, const object *killer) {
3453  char buf[MAX_BUF];
3454  int x, y;
3455  object *tmp;
3456  archetype *trophy = NULL;
3457 
3458  /* Don't die if the player's life can be saved. */
3459  if (save_life(op)) {
3460  return;
3461  }
3462 
3463  /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
3464  * in cities ONLY!!! It is very important that this doesn't get abused.
3465  * Look at op_on_battleground() for more info --AndreasV
3466  */
3467  if (op_on_battleground(op, &x, &y, &trophy)) {
3468  assert(trophy != NULL);
3470  "You have been defeated in combat!\n"
3471  "Local medics have saved your life...");
3472 
3473  /* restore player */
3474  restore_player(op);
3475 
3476  op->stats.hp = op->stats.maxhp;
3477  if (op->stats.food <= 0)
3478  op->stats.food = MAX_FOOD;
3479 
3480  /* create a bodypart-trophy to make the winner happy */
3481  tmp = arch_to_object(trophy);
3482  if (tmp != NULL) {
3483  snprintf(buf, sizeof(buf), "%s's %s", op->name, tmp->name);
3484  tmp->name = add_string(buf);
3485 
3486  snprintf(buf, sizeof(buf),
3487  "This %s was %s %s the %s, who was defeated at level %d by %s.\n",
3488  tmp->name, tmp->type == FLESH ? "cut off" : "taken from",
3489  op->name, op->contr->title,
3490  (int)(op->level), op->contr->killer);
3491 
3493  tmp->type = 0;
3494  tmp->value = 0;
3495  tmp->material = 0;
3496  tmp->materialname = NULL;
3497  object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
3498  }
3499 
3500  /* teleport defeated player to new destination*/
3501  transfer_ob(op, x, y, 0, NULL);
3502  op->contr->braced = 0;
3503  return;
3504  }
3505 
3506  if (events_execute_object_event(op, EVENT_DEATH, NULL, NULL, NULL, SCRIPT_FIX_ALL) != 0)
3507  return;
3508 
3510  if (op->stats.food < 0) {
3511  snprintf(buf, sizeof(buf), "%s starved to death.", op->name);
3512  strcpy(op->contr->killer, "starvation");
3513  } else {
3514  snprintf(buf, sizeof(buf), "%s died.", op->name);
3515  }
3516  play_sound_player_only(op->contr, SOUND_TYPE_LIVING, op, 0, "death");
3517 
3518  if (settings.not_permadeth == TRUE) {
3520  } else {
3522  }
3523 }
3524 
3533 static void kill_player_not_permadeath(object *op) {
3534  int num_stats_lose;
3535  int will_kill_again;
3536  int lost_a_stat;
3537  int z;
3538  object *tmp;
3539  char buf[MAX_BUF];
3540  archetype *at;
3541 
3542  /* Basically two ways to go - remove a stat permanently, or just
3543  * make it depletion. This bunch of code deals with that aspect
3544  * of death.
3545  */
3547  /* If stat loss is permanent, lose one stat only. */
3548  /* Lower level chars don't lose as many stats because they suffer
3549  more if they do. */
3550  /* Higher level characters can afford things such as potions of
3551  restoration, or better, stat potions. So we slug them that
3552  little bit harder. */
3553  /* GD */
3555  num_stats_lose = 1;
3556  else
3557  num_stats_lose = 1+op->level/BALSL_NUMBER_LOSSES_RATIO;
3558  } else {
3559  num_stats_lose = 1;
3560  }
3561  lost_a_stat = 0;
3562 
3563  for (z = 0; z < num_stats_lose; z++) {
3565  int i;
3566 
3567  /* Pick a random stat and take a point off it. Tell the player
3568  * what he lost.
3569  */
3570  i = RANDOM()%7;
3571  change_attr_value(&(op->stats), i, -1);
3573  change_attr_value(&(op->contr->orig_stats), i, -1);
3574  check_stat_bounds(&(op->contr->orig_stats), MIN_STAT, settings.max_stat);
3577  lose_msg[i]);
3578  lost_a_stat = 1;
3579  } else {
3580  /* deplete a stat */
3582  if (deparch == NULL) {
3583  continue;
3584  }
3585  object *dep;
3586  int lose_this_stat;
3587  int i;
3588 
3589  i = RANDOM()%7;
3590  dep = arch_present_in_ob(deparch, op);
3591  if (!dep) {
3592  dep = arch_to_object(deparch);
3593  object_insert_in_ob(dep, op);
3594  }
3595  lose_this_stat = 1;
3597  int this_stat;
3598 
3599  /* GD */
3600  /* Get the stat that we're about to deplete. */
3601  this_stat = get_attr_value(&(dep->stats), i);
3602  if (this_stat < 0) {
3603  int loss_chance = 1+op->level/BALSL_LOSS_CHANCE_RATIO;
3604  int keep_chance = this_stat*this_stat;
3605  /* Yes, I am paranoid. Sue me. */
3606  if (keep_chance < 1)
3607  keep_chance = 1;
3608 
3609  /* There is a maximum depletion total per level. */
3610  if (this_stat < -1-op->level/BALSL_MAX_LOSS_RATIO) {
3611  lose_this_stat = 0;
3612  /* Take loss chance vs keep chance to see if we
3613  retain the stat. */
3614  } else {
3615  if (random_roll(0, loss_chance+keep_chance-1, op, PREFER_LOW) < keep_chance)
3616  lose_this_stat = 0;
3617  /* 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"); */
3618  }
3619  }
3620  }
3621 
3622  if (lose_this_stat) {
3623  int this_stat;
3624 
3625  this_stat = get_attr_value(&(dep->stats), i);
3626  /* We could try to do something clever like find another
3627  * stat to reduce if this fails. But chances are, if
3628  * stats have been depleted to -50, all are pretty low
3629  * and should be roughly the same, so it shouldn't make a
3630  * difference.
3631  */
3632  if (this_stat >= -50) {
3633  change_attr_value(&(dep->stats), i, -1);
3634  SET_FLAG(dep, FLAG_APPLIED);
3636  drain_msg[i]);
3637  fix_object(op);
3638  lost_a_stat = 1;
3639  }
3640  }
3641  }
3642  }
3643  /* If no stat lost, tell the player. */
3644  if (!lost_a_stat) {
3645  /* determine_god() seems to not work sometimes... why is this? Should I be using something else? GD */
3646  const char *god = determine_god(op);
3647 
3648  if (god && (strcmp(god, "none")))
3651  "For a brief moment you feel the holy presence of %s protecting you",
3652  god);
3653  else
3656  "For a brief moment you feel a holy presence protecting you.");
3657  }
3658 
3659  /* Put a gravestone up where the character 'almost' died. List the
3660  * exp loss on the stone.
3661  */
3662  at = find_archetype("gravestone");
3663  if (at != NULL) {
3664  tmp = arch_to_object(at);
3665  snprintf(buf, sizeof(buf), "%s's gravestone", op->name);
3666  FREE_AND_COPY(tmp->name, buf);
3667  snprintf(buf, sizeof(buf), "%s's gravestones", op->name);
3668  FREE_AND_COPY(tmp->name_pl, buf);
3669  snprintf(buf, sizeof(buf), "RIP\nHere rests the hero %s the %s,\n"
3670  "who was killed\n"
3671  "by %s.\n",
3672  op->name, op->contr->title,
3673  op->contr->killer);
3675  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3676  }
3677 
3678  /* restore player: remove any poisoning, disease and confusion the
3679  * character may be suffering.*/
3680  restore_player(op);
3681 
3682  /* Subtract the experience points, if we died cause of food, give
3683  * us food, and reset HP's...
3684  */
3686  if (op->stats.food < 100)
3687  op->stats.food = 900;
3688  op->stats.hp = op->stats.maxhp;
3689  op->stats.sp = MAX(op->stats.sp, op->stats.maxsp);
3690  op->stats.grace = MAX(op->stats.grace, op->stats.maxgrace);
3691 
3692  /* Check to see if the player is in a shop. IF so, then check to see if
3693  * the player has any unpaid items. If so, remove them and put them back
3694  * in the map.
3695  *
3696  * If they are not in a shop, just free the unpaid items instead of
3697  * putting them back on map.
3698  */
3699  if (shop_contains(op))
3700  remove_unpaid_objects(op->inv, op, 0);
3701  else
3702  remove_unpaid_objects(op->inv, op, 1);
3703 
3704  /* Move player to his current respawn-position (usually last savebed) */
3706 
3707  /* Save the player before inserting the force to reduce chance of abuse. */
3708  op->contr->braced = 0;
3709  /* don't pick up in apartment */
3710  if (op->contr->mode & PU_NEWMODE) {
3711  op->contr->mode = op->contr->mode | PU_INHIBIT;
3712  esrv_send_pickup(op->contr);
3713  } else {
3714  op->contr->mode = 0;
3715  }
3716  if ( op->contr->search_str[0] ) command_search_items(op,NULL); /* turn off search-items */
3717  save_player(op, 1);
3718 
3719  /* it is possible that the player has blown something up
3720  * at his savebed location, and that can have long lasting
3721  * spell effects. So first see if there is a spell effect
3722  * on the space that might harm the player.
3723  */
3724  will_kill_again = 0;
3725  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp)
3726  if (tmp->type == SPELL_EFFECT)
3727  will_kill_again |= tmp->attacktype;
3728  FOR_MAP_FINISH();
3729  if (will_kill_again) {
3730  object *force;
3731  int at;
3732 
3734  /* 50 ticks should be enough time for the spell to abate */
3735  force->speed = 0.1;
3736  force->speed_left = -5.0;
3738  for (at = 0; at < NROFATTACKS; at++) {
3739  if (will_kill_again&(1<<at))
3740  force->resist[at] = 100;
3741  }
3743  fix_object(op);
3744  }
3745 
3746  /* Tell the player they have died */
3748  "YOU HAVE DIED.");
3749 }
3750 
3757 static void kill_player_permadeath(object *op) {
3758  char buf[MAX_BUF];
3759  char ac_buf[MAX_BUF];
3760  int x, y;
3761  mapstruct *map;
3762  object *tmp;
3763  archetype *at;
3764 
3765  /* save the map location for corpse, gravestone*/
3766  x = op->x;
3767  y = op->y;
3768  map = op->map;
3769 
3770  party_leave(op);
3771  if (settings.set_title == TRUE)
3772  player_set_own_title(op->contr, "");
3773 
3774  /* buf should be the kill message */
3776  buf);
3777  hiscore_check(op, 0);
3778  if (op->contr->ranges[range_golem] != NULL) {
3779  remove_friendly_object(op->contr->ranges[range_golem]);
3780  object_remove(op->contr->ranges[range_golem]);
3781  object_free_drop_inventory(op->contr->ranges[range_golem]);
3782  op->contr->ranges[range_golem] = NULL;
3783  op->contr->golem_count = 0;
3784  }
3785  loot_object(op); /* Remove some of the items for good */
3786  object_remove(op);
3787  op->direction = 0;
3788 
3789  if (!QUERY_FLAG(op, FLAG_WAS_WIZ) && op->stats.exp) {
3790  if (settings.resurrection == TRUE) {
3791  /* save playerfile sans equipment when player dies
3792  * -then save it as player.pl.dead so that future resurrection
3793  * -type spells will work on them nicely
3794  */
3795  op->stats.hp = op->stats.maxhp;
3796  op->stats.food = MAX_FOOD;
3797 
3798  /* set the location of where the person will reappear when */
3799  /* maybe resurrection code should fix map also */
3800  safe_strncpy(op->contr->maplevel, settings.emergency_mapname,
3801  sizeof(op->contr->maplevel));
3802  if (op->map != NULL)
3803  op->map = NULL;
3804  op->x = settings.emergency_x;
3805  op->y = settings.emergency_y;
3806  save_player(op, 0);
3807  op->map = map;
3808  /* please see resurrection.c: peterm */
3809  dead_player(op);
3810  } else {
3811  delete_character(op->name);
3812  }
3813  }
3814  play_again(op);
3815 
3816  /* peterm: added to create a corpse at deathsite. */
3817  at = find_archetype("corpse_pl");
3818  if (at != NULL) {
3819  tmp = arch_to_object(at);
3820  snprintf(buf, sizeof(buf), "%s", op->name);
3821  FREE_AND_COPY(tmp->name, buf);
3822  FREE_AND_COPY(tmp->name_pl, buf);
3823  tmp->level = op->level;
3824  object_set_msg(tmp, gravestone_text(op, buf, sizeof(buf)));
3826  /*
3827  * Put the account name under slaying.
3828  * Does not seem to cause weird effects, but more testing may ensure this.
3829  */
3830  snprintf(ac_buf, sizeof(ac_buf), "%s", op->contr->socket.account_name);
3831  FREE_AND_COPY(tmp->slaying, ac_buf);
3832  object_insert_in_map_at(tmp, map, NULL, 0, x, y);
3833  }
3834 }
3835 
3843 void fix_weight(void) {
3844  player *pl;
3845 
3846  for (pl = first_player; pl != NULL; pl = pl->next) {
3847  int old = pl->ob->carrying, sum = object_sum_weight(pl->ob);
3848 
3849  if (old == sum)
3850  continue;
3851  fix_object(pl->ob);
3852  LOG(llevDebug, "Fixed inventory in %s (%d -> %d)\n", pl->ob->name, old, sum);
3853  }
3854 }
3855 
3859 void fix_luck(void) {
3860  player *pl;
3861 
3862  for (pl = first_player; pl != NULL; pl = pl->next)
3863  if (!pl->ob->contr->state)
3864  change_luck(pl->ob, 0);
3865 }
3866 
3867 
3880 void cast_dust(object *op, object *throw_ob, int dir) {
3881  object *skop, *spob;
3882 
3883  skop = find_skill_by_name(op, throw_ob->skill);
3884 
3885  /* casting POTION 'dusts' is really a use_magic_item skill */
3886  if (op->type == PLAYER && throw_ob->type == POTION && !skop) {
3887  LOG(llevError, "Player %s lacks critical skill use_magic_item!\n", op->name);
3888  return;
3889  }
3890  spob = throw_ob->inv;
3891  if (op->type == PLAYER && spob)
3893  "You cast %s.",
3894  spob->name);
3895 
3896  cast_spell(op, throw_ob, dir, spob, NULL);
3897 
3898  if (!QUERY_FLAG(throw_ob, FLAG_REMOVED))
3899  object_remove(throw_ob);
3900  object_free_drop_inventory(throw_ob);
3901 }
3902 
3909 void make_visible(object *op) {
3910  op->hide = 0;
3911  op->invisible = 0;
3912  if (op->type == PLAYER) {
3913  op->contr->tmp_invis = 0;
3914  if (op->contr->invis_race)
3915  FREE_AND_CLEAR_STR(op->contr->invis_race);
3916  }
3918 }
3919 
3929 int is_true_undead(object *op) {
3930  if (QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
3931  return 1;
3932 
3933  if (op->type == PLAYER) {
3934  FOR_INV_PREPARE(op, tmp) {
3935  if (tmp->type == 44 && tmp->stats.Wis)
3936  if (QUERY_FLAG(tmp, FLAG_UNDEAD))
3937  return 1;
3938  } FOR_INV_FINISH();
3939  }
3940  return 0;
3941 }
3942 
3953 int hideability(object *ob) {
3954  int i, level = 0, mflag;
3955  int16_t x, y;
3956 
3957  if (!ob || !ob->map)
3958  return 0;
3959 
3960  /* so, on normal lighted maps, its hard to hide */
3961  level = ob->map->darkness-2;
3962 
3963  /* this also picks up whether the object is glowing.
3964  * If you carry a light on a non-dark map, its not
3965  * as bad as carrying a light on a pitch dark map
3966  */
3967  if (has_carried_lights(ob))
3968  level = -(10+(2*ob->map->darkness));
3969 
3970  /* scan through all nearby squares for terrain to hide in */
3971  for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x+freearr_x[i], y = ob->y+freearr_y[i]) {
3972  mflag = get_map_flags(ob->map, NULL, x, y, NULL, NULL);
3973  if (mflag&P_OUT_OF_MAP) {
3974  continue;
3975  }
3976  if (mflag&P_BLOCKSVIEW) /* something to hide near! */
3977  level += 2;
3978  else /* open terrain! */
3979  level -= 1;
3980  }
3981 
3982  return level;
3983 }
3984 
3994 void do_hidden_move(object *op) {
3995  int hide = 0, num = random_roll(0, 19, op, PREFER_LOW);
3996  object *skop;
3997 
3998  if (!op || !op->map)
3999  return;
4000 
4002 
4003  /* its *extremely *hard to run and sneak/hide at the same time! */
4004  if (op->type == PLAYER && op->contr->run_on) {
4005  if (!skop || num >= skop->level) {
4007  "You ran too much! You are no longer hidden!");
4008  make_visible(op);
4009  return;
4010  } else
4011  num += 20;
4012  }
4013  num += op->map->difficulty;
4014  hide = hideability(op); /* modify by terrain hidden level */
4015  num -= hide;
4016  if ((op->type == PLAYER && hide < -10)
4017  || ((op->invisible -= num) <= 0)) {
4018  make_visible(op);
4019  if (op->type == PLAYER)
4021  "You moved out of hiding! You are visible!");
4022  } else if (op->type == PLAYER && skop) {
4023  change_exp(op, calc_skill_exp(op, NULL, skop), skop->skill, 0);
4024  }
4025 }
4026 
4035 int stand_near_hostile(object *who) {
4036  int i, friendly = 0, player = 0, mflags;
4037  mapstruct *m;
4038  int16_t x, y;
4039 
4040  if (!who)
4041  return 0;
4042 
4043  if (who->type == PLAYER)
4044  player = 1;
4045  else
4046  friendly = QUERY_FLAG(who, FLAG_FRIENDLY);
4047 
4048  /* search adjacent squares */
4049  for (i = 1; i < 9; i++) {
4050  x = who->x+freearr_x[i];
4051  y = who->y+freearr_y[i];
4052  m = who->map;
4053  mflags = get_map_flags(m, &m, x, y, &x, &y);
4054  /* space must be blocked if there is a monster. If not
4055  * blocked, don't need to check this space.
4056  */
4057  if (mflags&P_OUT_OF_MAP)
4058  continue;
4060  continue;
4061 
4062  FOR_MAP_PREPARE(m, x, y, tmp) {
4063  if ((player || friendly)
4066  return 1;
4067  else if (tmp->type == PLAYER) {
4068  /*don't let a hidden DM prevent you from hiding*/
4069  if (!QUERY_FLAG(tmp, FLAG_WIZ) || tmp->contr->hidden == 0)
4070  return 1;
4071  }
4072  } FOR_MAP_FINISH();
4073  }
4074  return 0;
4075 }
4076 
4103 int player_can_view(object *pl, object *op) {
4104  rv_vector rv;
4105  int dx, dy;
4106 
4107  if (!pl || !op)
4108  return 0;
4109 
4110  if (pl->type != PLAYER) {
4111  LOG(llevError, "player_can_view() called for non-player object\n");
4112  return -1;
4113  }
4114 
4115  op = HEAD(op);
4116  if (!get_rangevector(pl, op, &rv, 0x1))
4117  return 0;
4118 
4119  /* starting with the 'head' part, lets loop
4120  * through the object and find if it has any
4121  * part that is in the los array but isnt on
4122  * a blocked los square.
4123  * we use the archetype to figure out offsets.
4124  */
4125  while (op) {
4126  dx = rv.distance_x+op->arch->clone.x;
4127  dy = rv.distance_y+op->arch->clone.y;
4128 
4129  /* only the viewable area the player sees is updated by LOS
4130  * code, so we need to restrict ourselves to that range of values
4131  * for any meaningful values.
4132  */
4133  if (FABS(dx) <= (pl->contr->socket.mapx/2)
4134  && FABS(dy) <= (pl->contr->socket.mapy/2)
4135  && !pl->contr->blocked_los[dx+(pl->contr->socket.mapx/2)][dy+(pl->contr->socket.mapy/2)])
4136  return 1;
4137  op = op->more;
4138  }
4139  return 0;
4140 }
4141 
4155 static int action_makes_visible(object *op) {
4156  if (op->invisible && QUERY_FLAG(op, FLAG_ALIVE)) {
4158  return 0;
4159 
4160  if (op->contr && op->contr->tmp_invis == 0)
4161  return 0;
4162 
4163  /* If monsters, they should become visible */
4164  if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) {
4166  "You become %s!",
4167  op->hide ? "unhidden" : "visible");
4168  return 1;
4169  }
4170  }
4171  return 0;
4172 }
4173 
4202 int op_on_battleground(object *op, int *x, int *y, archetype **trophy) {
4204  if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
4206  && strcmp(tmp->name, "battleground") == 0
4207  && tmp->type == BATTLEGROUND
4208  && EXIT_X(tmp)
4209  && EXIT_Y(tmp)) {
4210  /*before we assign the exit, check if this is a teambattle*/
4211  if (EXIT_ALT_X(tmp) && EXIT_ALT_Y(tmp) && EXIT_PATH(tmp)) {
4212  object *invtmp;
4213 
4215  if (invtmp != NULL) {
4216  if (x != NULL && y != NULL)
4217  *x = EXIT_ALT_X(tmp),
4218  *y = EXIT_ALT_Y(tmp);
4219  return 1;
4220  }
4221  }
4222  if (x != NULL && y != NULL)
4223  *x = EXIT_X(tmp),
4224  *y = EXIT_Y(tmp);
4225 
4226  /* If 'other_arch' is not specified, give a finger. */
4227  if (trophy != NULL) {
4228  if (tmp->other_arch) {
4229  *trophy = tmp->other_arch;
4230  } else {
4231  *trophy = find_archetype("finger");
4232  }
4233  }
4234  return 1;
4235  }
4236  }
4237  } FOR_BELOW_FINISH();
4238  /* If we got here, did not find a battleground */
4239  return 0;
4240 }
4241 
4252 void dragon_ability_gain(object *who, int atnr, int level) {
4253  treasurelist *trlist = NULL; /* treasurelist */
4254  treasure *tr; /* treasure */
4255  object *tmp, *skop; /* tmp. object */
4256  object *item; /* treasure object */
4257  char buf[MAX_BUF]; /* tmp. string buffer */
4258  int i = 0, j = 0;
4259 
4260  /* get the appropriate treasurelist */
4261  if (atnr == ATNR_FIRE)
4262  trlist = find_treasurelist("dragon_ability_fire");
4263  else if (atnr == ATNR_COLD)
4264  trlist = find_treasurelist("dragon_ability_cold");
4265  else if (atnr == ATNR_ELECTRICITY)
4266  trlist = find_treasurelist("dragon_ability_elec");
4267  else if (atnr == ATNR_POISON)
4268  trlist = find_treasurelist("dragon_ability_poison");
4269 
4270  if (trlist == NULL || who->type != PLAYER)
4271  return;
4272 
4273  // tr->magic is being used to define what level of the metabolism the ability is gained at.
4274  for (tr = trlist->items; tr != NULL && tr->magic != level; tr = tr->next)
4275  ;
4276  if (tr == NULL || tr->item == NULL) {
4277  /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
4278  return;
4279  }
4280 
4281  /* everything seems okay - now bring on the gift: */
4282  item = &(tr->item->clone);
4283 
4284  if (item->type == SPELL) {
4285  if (check_spell_known(who, item->name))
4286  return;
4287 
4290  "You gained the ability of %s",
4291  item->name);
4292  do_learn_spell(who, item, 0);
4293  return;
4294  }
4295 
4296  /* grant direct spell */
4297  if (item->type == SPELLBOOK) {
4298  if (!item->inv) {
4299  LOG(llevDebug, "dragon_ability_gain: Broken spellbook %s\n", item->name);
4300  return;
4301  }
4302  if (check_spell_known(who, item->inv->name))
4303  return;
4304  if (item->invisible) {
4307  "You gained the ability of %s",
4308  item->inv->name);
4309  do_learn_spell(who, item->inv, 0);
4310  return;
4311  }
4312  } else if (item->type == SKILL_TOOL && item->invisible) {
4313  if (item->subtype == SK_CLAWING && (skop = find_skill_by_name(who, item->skill)) != NULL) {
4314  /* should this perhaps be (skop->attackyp&item->attacktype) != item->attacktype ...
4315  * in this way, if the player is missing any of the attacktypes, he gets
4316  * them. As it is now, if the player has any that match the granted skill,
4317  * but not all of them, he gets nothing.
4318  */
4319  if (!(skop->attacktype&item->attacktype)) {
4320  /* Give new attacktype */
4321  skop->attacktype |= item->attacktype;
4322 
4323  /* always add physical if there's none */
4324  skop->attacktype |= AT_PHYSICAL;
4325 
4326  if (item->msg != NULL)
4329  item->msg);
4330 
4331  /* Give player new face */
4332  if (item->animation) {
4333  who->face = skop->face;
4334  who->animation = item->animation;
4335  who->anim_speed = item->anim_speed;
4336  who->last_anim = 0;
4337  who->state = 0;
4338  animate_object(who, who->direction);
4339  }
4340  }
4341  }
4342  } else if (item->type == FORCE) {
4343  /* forces in the treasurelist can alter the player's stats */
4344  object *skin;
4345 
4346  /* first get the dragon skin force */
4347  skin = object_find_by_arch_name(who, "dragon_skin_force");
4348  if (skin == NULL)
4349  return;
4350 
4351  /* adding new spellpath attunements */
4352  if (item->path_attuned > 0 && !(skin->path_attuned&item->path_attuned)) {
4353  skin->path_attuned |= item->path_attuned; /* add attunement to skin */
4354 
4355  /* print message */
4356  snprintf(buf, sizeof(buf), "You feel attuned to ");
4357  for (i = 0, j = 0; i < NRSPELLPATHS; i++) {
4358  if (item->path_attuned&(1<<i)) {
4359  if (j)
4360  strcat(buf, " and ");
4361  else
4362  j = 1;
4363  strcat(buf, spellpathnames[i]);
4364  }
4365  }
4366  strcat(buf, ".");
4369  buf);
4370  }
4371 
4372  /* evtl. adding flags: */
4373  if (QUERY_FLAG(item, FLAG_XRAYS))
4374  SET_FLAG(skin, FLAG_XRAYS);
4376  SET_FLAG(skin, FLAG_STEALTH);
4378  SET_FLAG(skin, FLAG_SEE_IN_DARK);
4379 
4380  /* print message if there is one */
4381  if (item->msg != NULL)
4384  item->msg);
4385  } else {
4386  /* generate misc. treasure */
4387  char name[HUGE_BUF];
4388 
4389  tmp = arch_to_object(tr->item);
4393  "You gained %s",
4394  name);
4396  if (who->type == PLAYER)
4398  }
4399 }
4400 
4411  rangetype i;
4412 
4413  for (i = 0; i < range_size; i++) {
4414  if (pl->ranges[i] == ob) {
4415  pl->ranges[i] = NULL;
4416  if (pl->shoottype == i) {
4417  pl->shoottype = range_none;
4418  }
4419  }
4420  }
4421 }
4422 
4428 void player_set_state(player *pl, uint8_t state) {
4429 
4430  assert(pl);
4432  pl->state = state;
4433 }
4434 
4442  SockList *sl;
4443  assert(pl);
4447  if (!pl->delayed_buffers) {
4448  LOG(llevError, "Unable to allocated %d delayed buffers, aborting\n", pl->delayed_buffers_allocated);
4450  }
4451  for (uint8_t s = pl->delayed_buffers_allocated - 5; s < pl->delayed_buffers_allocated; s++) {
4452  pl->delayed_buffers[s] = calloc(1, sizeof(SockList));
4453  }
4454  }
4457  SockList_Init(sl);
4458  return sl;
4459 }
object_was_destroyed
#define object_was_destroyed(op, old_tag)
Definition: object.h:68
ADD_PLAYER_NO_STATS_ROLL
#define ADD_PLAYER_NO_STATS_ROLL
Definition: player.h:232
treasurestruct::item
struct archt * item
Definition: treasure.h:64
give.next
def next
Definition: give.py:44
stand_near_hostile
int stand_near_hostile(object *who)
Definition: player.c:4035
GET_MAP_OB
#define GET_MAP_OB(M, X, Y)
Definition: map.h:173
MSG_TYPE_COMMAND_NEWPLAYER
#define MSG_TYPE_COMMAND_NEWPLAYER
Definition: newclient.h:536
do_skill
int do_skill(object *op, object *part, object *skill, int dir, const char *string)
Definition: skill_util.c:422
apply_changes_to_player
void apply_changes_to_player(object *pl, object *change, int limit_stats)
Definition: apply.c:1648
UP_OBJ_FACE
#define UP_OBJ_FACE
Definition: object.h:520
pl::delayed_buffers
SockList ** delayed_buffers
Definition: player.h:211
PLAYER
@ PLAYER
Definition: object.h:107
PU_BOOTS
#define PU_BOOTS
Definition: define.h:125
receive_play_again
void receive_play_again(object *op, char key)
Definition: player.c:937
do_hidden_move
void do_hidden_move(object *op)
Definition: player.c:3994
SockList_AddInt
void SockList_AddInt(SockList *sl, uint32_t data)
Definition: lowlevel.c:124
global.h
FLAG_NEUTRAL
#define FLAG_NEUTRAL
Definition: define.h:354
UPD_FACE
#define UPD_FACE
Definition: newclient.h:317
add_refcount
sstring add_refcount(sstring str)
Definition: shstr.c:210
bow_nw
@ bow_nw
Definition: player.h:39
SOUND_TYPE_ITEM
#define SOUND_TYPE_ITEM
Definition: newclient.h:335
liv::dam
int16_t dam
Definition: living.h:46
object_free
void object_free(object *ob, int flags)
Definition: object.c:1565
fix_weight
void fix_weight(void)
Definition: player.c:3843
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
object_find_by_flag_applied
object * object_find_by_flag_applied(const object *who, int flag)
Definition: object.c:4237
object_remove
void object_remove(object *op)
Definition: object.c:1806
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:728
pets_terminate_all
void pets_terminate_all(object *owner)
Definition: pets.c:225
object_sum_weight
signed long object_sum_weight(object *op)
Definition: object.c:561
get_player
player * get_player(player *p)
Definition: player.c:282
kill_player
void kill_player(object *op, const object *killer)
Definition: player.c:3452
object_set_enemy
void object_set_enemy(object *op, object *enemy)
Definition: object.c:908
obj::face
const Face * face
Definition: object.h:334
ST_GET_PASSWORD
#define ST_GET_PASSWORD
Definition: define.h:547
MSG_TYPE_COMMAND_SUCCESS
#define MSG_TYPE_COMMAND_SUCCESS
Definition: newclient.h:530
FLAG_CONFUSED
#define FLAG_CONFUSED
Definition: define.h:311
BOW
@ BOW
Definition: object.h:118
Settings::emergency_y
uint16_t emergency_y
Definition: global.h:296
remove_statbonus
void remove_statbonus(object *op)
Definition: living.c:846
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
MOVE_ALL
#define MOVE_ALL
Definition: define.h:398
command_search_items
void command_search_items(object *op, const char *params)
Definition: c_object.c:2328
WAND
@ WAND
Definition: object.h:220
range_bow
@ range_bow
Definition: player.h:18
MSG_TYPE_ADMIN_PLAYER
#define MSG_TYPE_ADMIN_PLAYER
Definition: newclient.h:496
FLAG_UNDEAD
#define FLAG_UNDEAD
Definition: define.h:270
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
similar_direction
static int similar_direction(int a, int b)
Definition: player.c:2240
FLESH
@ FLESH
Definition: object.h:187
monster_can_detect_enemy
int monster_can_detect_enemy(object *op, object *enemy, rv_vector *rv)
Definition: monster.c:2522
roll_again
void roll_again(object *op)
Definition: player.c:1117
PU_ARROW
#define PU_ARROW
Definition: define.h:120
PU_NOT_CURSED
#define PU_NOT_CURSED
Definition: define.h:140
esrv_map_scroll
void esrv_map_scroll(socket_struct *ns, int dx, int dy)
Definition: request.c:1613
display_motd
void display_motd(const object *op)
Definition: player.c:136
strdup_local
#define strdup_local
Definition: compat.h:29
Settings::resurrection
uint8_t resurrection
Definition: global.h:262
recursive_roll
void recursive_roll(object *op, int dir, object *pusher)
Definition: move.c:280
socket_struct::look_position
uint16_t look_position
Definition: newserver.h:114
object_update
void object_update(object *op, int action)
Definition: object.c:1407
diamondslots.x
x
Definition: diamondslots.py:15
FLAG_STARTEQUIP
#define FLAG_STARTEQUIP
Definition: define.h:268
obj::count
tag_t count
Definition: object.h:300
obj::map
struct mapdef * map
Definition: object.h:298
MSG_TYPE_SKILL
#define MSG_TYPE_SKILL
Definition: newclient.h:407
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
obj::race
sstring race
Definition: object.h:319
get_next_archetype
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:274
Settings::set_title
uint8_t set_title
Definition: global.h:261
remove_locked_door
void remove_locked_door(object *op)
Definition: time.c:64
pl::peaceful
uint32_t peaceful
Definition: player.h:133
SK_CLAWING
@ SK_CLAWING
Definition: skills.h:50
ARCH_DEPLETION
#define ARCH_DEPLETION
Definition: object.h:577
NDI_GREEN
#define NDI_GREEN
Definition: newclient.h:249
liv::wc
int8_t wc
Definition: living.h:37
KEY
@ KEY
Definition: object.h:127
PU_INHIBIT
#define PU_INHIBIT
Definition: define.h:109
do_learn_spell
void do_learn_spell(object *op, object *spell, int special_prayer)
Definition: apply.c:484
socket_struct
Definition: newserver.h:89
socket_struct::mapx
uint8_t mapx
Definition: newserver.h:116
MAX_SPACES
#define MAX_SPACES
Definition: player.c:599
ST_GET_NAME
#define ST_GET_NAME
Definition: define.h:546
player_get_delayed_buffer
SockList * player_get_delayed_buffer(player *pl)
Definition: player.c:4441
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2302
esrv_new_player
void esrv_new_player(player *pl, uint32_t weight)
Definition: request.c:942
FLAG_SEE_IN_DARK
#define FLAG_SEE_IN_DARK
Definition: define.h:337
Settings::not_permadeth
uint8_t not_permadeth
Definition: global.h:258
price_base
uint64_t price_base(const object *obj)
Definition: shop.c:75
lose_msg
const char *const lose_msg[NUM_STATS]
Definition: living.c:173
object_new
object * object_new(void)
Definition: object.c:1242
esrv_send_inventory
void esrv_send_inventory(object *pl, object *op)
Definition: item.c:312
key_roll_stat
void key_roll_stat(object *op, char key)
Definition: player.c:1189
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
cast_spell
int cast_spell(object *op, object *caster, int dir, object *spell_ob, char *stringarg)
Definition: spell_util.c:1420
disinfect.a
a
Definition: disinfect.py:13
object_find_by_arch_name
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.c:4260
get_player_archetype
static archetype * get_player_archetype(archetype *at)
Definition: player.c:498
obj::path_attuned
uint32_t path_attuned
Definition: object.h:346
SockList_AddString
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.c:154
pl::socket
socket_struct socket
Definition: player.h:94
FOR_BELOW_PREPARE
#define FOR_BELOW_PREPARE(op_, it_)
Definition: define.h:702
GEM
@ GEM
Definition: object.h:167
FLAG_UNIQUE
#define FLAG_UNIQUE
Definition: define.h:287
pl::shoottype
rangetype shoottype
Definition: player.h:99
pl
Definition: player.h:92
MSG_TYPE_VICTIM_DIED
#define MSG_TYPE_VICTIM_DIED
Definition: newclient.h:656
EXIT_PATH
#define EXIT_PATH(xyz)
Definition: define.h:439
TRAP
@ TRAP
Definition: object.h:241
pl::blocked_los
int8_t blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]
Definition: player.h:163
fire
void fire(object *op, int dir)
Definition: player.c:2362
spring_trap
void spring_trap(object *trap, object *victim)
Definition: rune.c:205
apply_map_builder
void apply_map_builder(object *pl, int dir)
Definition: build_map.c:959
PREFER_LOW
#define PREFER_LOW
Definition: define.h:564
PU_FOOD
#define PU_FOOD
Definition: define.h:115
arch_present_in_ob
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:3172
pl::swap_first
int swap_first
Definition: player.h:151
object_matches_string
int object_matches_string(object *pl, object *op, const char *name)
Definition: object.c:4564
esrv_send_pickup
void esrv_send_pickup(player *pl)
Definition: request.c:1740
guildjoin.ob
ob
Definition: guildjoin.py:42
PU_BOW
#define PU_BOW
Definition: define.h:118
liv::hp
int16_t hp
Definition: living.h:40
MSG_TYPE_ATTRIBUTE
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:405
GT_ONLY_GOOD
@ GT_ONLY_GOOD
Definition: treasure.h:34
range_none
@ range_none
Definition: player.h:17
PU_MAGIC_DEVICE
#define PU_MAGIC_DEVICE
Definition: define.h:138
commongive.inv
inv
Definition: commongive.py:28
find_player_socket
player * find_player_socket(const socket_struct *ns)
Definition: player.c:120
SET_ANIMATION
#define SET_ANIMATION(ob, newanim)
Definition: global.h:160
CHARISMA
@ CHARISMA
Definition: living.h:15
party_rejoin_if_exists
@ party_rejoin_if_exists
Definition: player.h:87
set_first_map
void set_first_map(object *op)
Definition: player.c:400
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.c:355
MIN
#define MIN(x, y)
Definition: compat.h:21
CS_QUERY_SINGLECHAR
#define CS_QUERY_SINGLECHAR
Definition: newclient.h:67
pl::ob
object * ob
Definition: player.h:162
play_sound_player_only
void play_sound_player_only(player *pl, int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:51
bow_threewide
@ bow_threewide
Definition: player.h:30
SKILL
@ SKILL
Definition: object.h:143
pl::delayed_buffers_used
uint8_t delayed_buffers_used
Definition: player.h:210
play_sound_map
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:108
object_can_merge
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:422
RUNE
@ RUNE
Definition: object.h:240
pl::bowtype
bowtype_t bowtype
Definition: player.h:101
FLAG_SCARED
#define FLAG_SCARED
Definition: define.h:271
Settings::roll_stat_points
uint8_t roll_stat_points
Definition: global.h:319
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:498
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:257
Ice.tmp
int tmp
Definition: Ice.py:207
PU_MISSILEWEAPON
#define PU_MISSILEWEAPON
Definition: define.h:130
apply_race_and_class
int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
Definition: player.c:1455
NDI_NAVY
#define NDI_NAVY
Definition: newclient.h:244
remove_friendly_object
void remove_friendly_object(object *op)
Definition: friend.c:56
Settings::emergency_x
uint16_t emergency_x
Definition: global.h:296
action_makes_visible
static int action_makes_visible(object *op)
Definition: player.c:4155
TRANSPORT
@ TRANSPORT
Definition: object.h:108
SOUND_TYPE_LIVING
#define SOUND_TYPE_LIVING
Definition: newclient.h:333
socket_struct::inbuf
SockList inbuf
Definition: newserver.h:99
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
PU_FLESH
#define PU_FLESH
Definition: define.h:142
player_set_own_title
void player_set_own_title(struct pl *pl, const char *title)
Definition: player.c:275
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
obj::msg
sstring msg
Definition: object.h:323
PU_READABLES
#define PU_READABLES
Definition: define.h:137
first_map_path
EXTERN char first_map_path[MAX_BUF]
Definition: global.h:143
roll_stats
void roll_stats(object *op)
Definition: player.c:1043
get_rangevector
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2535
move_player
int move_player(object *op, int dir)
Definition: player.c:2912
BALSL_LOSS_CHANCE_RATIO
#define BALSL_LOSS_CHANCE_RATIO
Definition: config.h:142
send_account_players
void send_account_players(socket_struct *ns)
Definition: request.c:1981
skills.h
pl::last_resist
int16_t last_resist[NROFATTACKS]
Definition: player.h:159
PU_POTION
#define PU_POTION
Definition: define.h:133
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Definition: newclient.h:529
roll_stat
int roll_stat(void)
Definition: player.c:1019
esrv_add_spells
void esrv_add_spells(player *pl, object *spell)
Definition: request.c:1854
range_golem
@ range_golem
Definition: player.h:21
pl::last_weapon_sp
float last_weapon_sp
Definition: player.h:142
first_map
EXTERN mapstruct * first_map
Definition: global.h:116
FLAG_INV_LOCKED
#define FLAG_INV_LOCKED
Definition: define.h:329
apply_manual
int apply_manual(object *op, object *tmp, int aflag)
Definition: apply.c:597
create_treasure
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:242
P_IS_ALIVE
#define P_IS_ALIVE
Definition: map.h:238
MSG_TYPE_MISC
#define MSG_TYPE_MISC
Definition: newclient.h:413
get_dex_bonus
int get_dex_bonus(int stat)
Definition: living.c:2354
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
NDI_BLUE
#define NDI_BLUE
Definition: newclient.h:247
FLAG_STEALTH
#define FLAG_STEALTH
Definition: define.h:312
first_friendly_object
EXTERN objectlink * first_friendly_object
Definition: global.h:119
face_player
int face_player(object *op, int dir)
Definition: player.c:2991
events_execute_object_event
int events_execute_object_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: events.cpp:259
BALSL_MAX_LOSS_RATIO
#define BALSL_MAX_LOSS_RATIO
Definition: config.h:144
GT_STARTEQUIP
@ GT_STARTEQUIP
Definition: treasure.h:33
pl::last_speed
float last_speed
Definition: player.h:158
Moving_Fog.z
z
Definition: Moving_Fog.py:17
hiscore_check
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:348
HUGE_BUF
#define HUGE_BUF
Definition: define.h:37
treasurestruct
Definition: treasure.h:63
make_path_to_file
void make_path_to_file(const char *filename)
Definition: porting.c:162
MSG_TYPE_VICTIM
#define MSG_TYPE_VICTIM
Definition: newclient.h:415
ob_process
method_ret ob_process(object *op)
Definition: ob_methods.c:67
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Definition: newclient.h:404
MAX
#define MAX(x, y)
Definition: compat.h:24
WISDOM
@ WISDOM
Definition: living.h:14
player_set_state
void player_set_state(player *pl, uint8_t state)
Definition: player.c:4428
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:288
AT_DEATH
#define AT_DEATH
Definition: attack.h:93
obj::nrof
uint32_t nrof
Definition: object.h:335
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:294
MSG_TYPE_SPELL_END
#define MSG_TYPE_SPELL_END
Definition: newclient.h:634
playername_ok
int playername_ok(const char *cp)
Definition: player.c:254
FOR_BELOW_FINISH
#define FOR_BELOW_FINISH()
Definition: define.h:709
MIN_STAT
#define MIN_STAT
Definition: define.h:33
archt
Definition: object.h:468
settings
struct Settings settings
Definition: init.c:39
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
check_race_and_class
int check_race_and_class(living *stats, archetype *race, archetype *opclass)
Definition: player.c:1405
MSG_TYPE_MOTD
#define MSG_TYPE_MOTD
Definition: newclient.h:401
animate_object
void animate_object(object *op, int dir)
Definition: anim.c:43
range_builder
@ range_builder
Definition: player.h:23
esrv_send_item
void esrv_send_item(object *pl, object *op)
Definition: main.c:355
socket_struct::update_look
uint32_t update_look
Definition: newserver.h:104
rv_vector::distance_y
int distance_y
Definition: map.h:382
MSG_TYPE_COMMAND_DEBUG
#define MSG_TYPE_COMMAND_DEBUG
Definition: newclient.h:528
obj::slaying
sstring slaying
Definition: object.h:320
AP_NULL
#define AP_NULL
Definition: define.h:573
free_string
void free_string(sstring str)
Definition: shstr.c:280
PU_GLOVES
#define PU_GLOVES
Definition: define.h:126
remove_door
void remove_door(object *op)
Definition: time.c:38
PU_CONTAINER
#define PU_CONTAINER
Definition: define.h:143
m
static event_registration m
Definition: citylife.cpp:425
liv::luck
int8_t luck
Definition: living.h:39
handle_newcs_player
int handle_newcs_player(object *op)
Definition: player.c:3050
rv_vector::distance_x
int distance_x
Definition: map.h:381
autojail.who
who
Definition: autojail.py:3
has_carried_lights
int has_carried_lights(const object *op)
Definition: los.c:315
socket_struct::mapy
uint8_t mapy
Definition: newserver.h:116
pl::savebed_map
char savebed_map[MAX_BUF]
Definition: player.h:97
MAP_IN_MEMORY
#define MAP_IN_MEMORY
Definition: map.h:131
object_find_by_type_subtype
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Definition: object.c:4309
liv::exp
int64_t exp
Definition: living.h:47
Ns_Avail
@ Ns_Avail
Definition: newserver.h:65
object_find_by_type_without_flags
object * object_find_by_type_without_flags(const object *who, int type, int *flags, int num_flags)
Definition: object.c:4012
pl::next
struct pl * next
Definition: player.h:93
PREFER_HIGH
#define PREFER_HIGH
Definition: define.h:563
EVENT_LOGIN
#define EVENT_LOGIN
Definition: events.h:43
remove_unpaid_objects
void remove_unpaid_objects(object *op, object *env, int free_items)
Definition: player.c:3171
save_life
static int save_life(object *op)
Definition: player.c:3128
disinfect.map
map
Definition: disinfect.py:4
object_decrease_nrof_by_one
#define object_decrease_nrof_by_one(xyz)
Definition: compat.h:32
POISON
@ POISON
Definition: object.h:113
link_player_skills
void link_player_skills(object *op)
Definition: player.c:290
PU_RATIO
#define PU_RATIO
Definition: define.h:113
Settings::balanced_stat_loss
uint8_t balanced_stat_loss
Definition: global.h:257
BALSL_NUMBER_LOSSES_RATIO
#define BALSL_NUMBER_LOSSES_RATIO
Definition: config.h:143
object_find_by_type_and_slaying
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Definition: object.c:4166
oblnk::next
struct oblnk * next
Definition: object.h:447
MSG_TYPE_ATTRIBUTE_STAT_LOSS
#define MSG_TYPE_ATTRIBUTE_STAT_LOSS
Definition: newclient.h:569
FLAG_WAS_WIZ
#define FLAG_WAS_WIZ
Definition: define.h:234
MSG_TYPE_ADMIN_NEWS
#define MSG_TYPE_ADMIN_NEWS
Definition: newclient.h:495
make_visible
void make_visible(object *op)
Definition: player.c:3909
bow_n
@ bow_n
Definition: player.h:32
obj::name
sstring name
Definition: object.h:312
strip_endline
void strip_endline(char *buf)
Definition: utils.c:341
cast_dust
void cast_dust(object *op, object *throw_ob, int dir)
Definition: player.c:3880
enter_player_savebed
void enter_player_savebed(object *op)
Definition: server.c:138
PU_KEY
#define PU_KEY
Definition: define.h:128
determine_god
const char * determine_god(object *op)
Definition: gods.c:106
MSG_TYPE_ATTRIBUTE_RACE
#define MSG_TYPE_ATTRIBUTE_RACE
Definition: newclient.h:564
pl::state
uint8_t state
Definition: player.h:118
move_player_attack
void move_player_attack(object *op, int dir)
Definition: player.c:2587
is_identifiable_type
int is_identifiable_type(const object *op)
Definition: item.c:1311
bow_bestarrow
@ bow_bestarrow
Definition: player.h:40
ST_CHANGE_PASSWORD_CONFIRM
#define ST_CHANGE_PASSWORD_CONFIRM
Definition: define.h:552
object_copy
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:1053
range_size
@ range_size
Definition: player.h:24
move_ob
int move_ob(object *op, int dir, object *originator)
Definition: move.c:58
MSG_TYPE_APPLY_SUCCESS
#define MSG_TYPE_APPLY_SUCCESS
Definition: newclient.h:603
player_can_view
int player_can_view(object *pl, object *op)
Definition: player.c:4103
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:584
confirm_password
void confirm_password(object *op)
Definition: player.c:987
treasurestruct::magic
uint8_t magic
Definition: treasure.h:71
mon
object * mon
Definition: comet_perf.c:75
pl::unarmed_skill
const char * unarmed_skill
Definition: player.h:206
POTION
@ POTION
Definition: object.h:111
object_update_turn_face
void object_update_turn_face(object *op)
Definition: object.c:1300
pet_normal
@ pet_normal
Definition: player.h:45
MOVE_WALK
#define MOVE_WALK
Definition: define.h:392
FLAG_KNOWN_CURSED
#define FLAG_KNOWN_CURSED
Definition: define.h:320
ST_PLAY_AGAIN
#define ST_PLAY_AGAIN
Definition: define.h:542
ADD_PLAYER_NO_MAP
#define ADD_PLAYER_NO_MAP
Definition: player.h:231
calc_skill_exp
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:658
get_randomized_dir
int get_randomized_dir(int dir)
Definition: utils.c:439
pl::petmode
petmode_t petmode
Definition: player.h:102
key_confirm_quit
void key_confirm_quit(object *op, char key)
Definition: player.c:1568
party_leave
void party_leave(object *op)
Definition: party.c:123
account_remove_player
int account_remove_player(const char *account_name, const char *player_name)
Definition: account.c:479
FOR_OB_AND_BELOW_FINISH
#define FOR_OB_AND_BELOW_FINISH()
Definition: define.h:752
HEAD
#define HEAD(op)
Definition: object.h:594
fatal
void fatal(enum fatal_error err)
Definition: utils.c:597
range_magic
@ range_magic
Definition: player.h:19
apply_container
int apply_container(object *op, object *sack, int aflags)
Definition: apply.c:222
ROD
@ ROD
Definition: object.h:109
object_can_pick
int object_can_pick(const object *who, const object *item)
Definition: object.c:3875
player_unready_range_ob
void player_unready_range_ob(player *pl, object *ob)
Definition: player.c:4410
CONTAINER
@ CONTAINER
Definition: object.h:231
enter_player_maplevel
void enter_player_maplevel(object *op)
Definition: server.c:676
swap_stat
static void swap_stat(object *op, int swap_second)
Definition: player.c:1131
obj::speed_left
float speed_left
Definition: object.h:331
loot_object
static void loot_object(object *op)
Definition: player.c:3375
SockList_AddChar
void SockList_AddChar(SockList *sl, unsigned char c)
Definition: lowlevel.c:103
PU_STOP
#define PU_STOP
Definition: define.h:110
PU_VALUABLES
#define PU_VALUABLES
Definition: define.h:117
find_player
player * find_player(const char *plname)
Definition: player.c:56
FLAG_FREED
#define FLAG_FREED
Definition: define.h:233
delete_character
void delete_character(const char *name)
Definition: login.c:88
Settings::motd
char motd[MAX_BUF]
Definition: global.h:274
LOCKED_DOOR
@ LOCKED_DOOR
Definition: object.h:123
MSG_TYPE_ITEM
#define MSG_TYPE_ITEM
Definition: newclient.h:412
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:367
MSG_TYPE_ATTACK
#define MSG_TYPE_ATTACK
Definition: newclient.h:409
query_short_name
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:509
FLAG_MAKE_INVIS
#define FLAG_MAKE_INVIS
Definition: define.h:328
Settings::rules
const char * rules
Definition: global.h:275
SPECIAL_KEY
@ SPECIAL_KEY
Definition: object.h:124
absdir
int absdir(int d)
Definition: object.c:3722
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
obj::spellarg
char * spellarg
Definition: object.h:413
socket_struct::account_name
char * account_name
Definition: newserver.h:126
get_dam_bonus
int get_dam_bonus(int stat)
Definition: living.c:2378
POWER
@ POWER
Definition: living.h:17
SPELL_HIGHEST
#define SPELL_HIGHEST
Definition: spells.h:60
obj::carrying
int32_t carrying
Definition: object.h:370
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:202
Settings::news
const char * news
Definition: global.h:276
Ice.b
b
Definition: Ice.py:48
get_party_password
int get_party_password(object *op, partylist *party)
Definition: player.c:1002
pl::no_shout
uint32_t no_shout
Definition: player.h:135
first_player
EXTERN player * first_player
Definition: global.h:115
EVENT_BORN
#define EVENT_BORN
Definition: events.h:38
guild_questpoints_apply.mapname
mapname
Definition: guild_questpoints_apply.py:8
obj::x
int16_t x
Definition: object.h:328
DETOUR_AMOUNT
#define DETOUR_AMOUNT
Definition: player.c:584
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
socket_struct::monitor_spells
uint32_t monitor_spells
Definition: newserver.h:110
fix_object
void fix_object(object *op)
Definition: living.c:1126
FLAG_PARALYZED
#define FLAG_PARALYZED
Definition: define.h:371
Settings::stat_loss_on_death
uint8_t stat_loss_on_death
Definition: global.h:252
CFweardisguise.tag
tag
Definition: CFweardisguise.py:25
FLAG_USE_SHIELD
#define FLAG_USE_SHIELD
Definition: define.h:237
key_change_class
void key_change_class(object *op, char key)
Definition: player.c:1265
update_transport_block
static void update_transport_block(object *transport, int dir)
Definition: player.c:2764
leave
void leave(player *pl, int draw_exit)
Definition: server.c:1275
GET_MAP_MOVE_BLOCK
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:193
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:675
FLAG_CAN_ROLL
#define FLAG_CAN_ROLL
Definition: define.h:254
pl::has_hit
uint32_t has_hit
Definition: player.h:131
clear_player
void clear_player(player *pl)
Definition: player.c:33
PU_SPELLBOOK
#define PU_SPELLBOOK
Definition: define.h:135
find_arrow
static object * find_arrow(object *op, const char *type)
Definition: player.c:1898
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
obj::speed
float speed
Definition: object.h:330
say.max
dictionary max
Definition: say.py:148
rangetype
rangetype
Definition: player.h:15
tag_t
uint32_t tag_t
Definition: object.h:12
op_on_battleground
int op_on_battleground(object *op, int *x, int *y, archetype **trophy)
Definition: player.c:4202
PU_MELEEWEAPON
#define PU_MELEEWEAPON
Definition: define.h:131
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
find_better_arrow
static object * find_better_arrow(object *op, object *target, const char *type, int *better)
Definition: player.c:1930
Settings::confdir
const char * confdir
Definition: global.h:243
FLAG_USE_WEAPON
#define FLAG_USE_WEAPON
Definition: define.h:296
sproto.h
ARROW
@ ARROW
Definition: object.h:117
FLAG_NO_DROP
#define FLAG_NO_DROP
Definition: define.h:288
get_name
void get_name(object *op)
Definition: player.c:862
IS_SHIELD
#define IS_SHIELD(op)
Definition: define.h:170
MAX_SKILLS
#define MAX_SKILLS
Definition: skills.h:70
kill_player_not_permadeath
static void kill_player_not_permadeath(object *op)
Definition: player.c:3533
FIND_PLAYER_PARTIAL_NAME
#define FIND_PLAYER_PARTIAL_NAME
Definition: player.h:220
AC_PLAYER_STAT_NO_CHANGE
#define AC_PLAYER_STAT_NO_CHANGE
Definition: define.h:596
FLAG_CAN_USE_SKILL
#define FLAG_CAN_USE_SKILL
Definition: define.h:321
PU_MAGICAL
#define PU_MAGICAL
Definition: define.h:132
apply_death_exp_penalty
void apply_death_exp_penalty(object *op)
Definition: living.c:2233
obj::enemy
struct obj * enemy
Definition: object.h:385
FOR_OB_AND_BELOW_PREPARE
#define FOR_OB_AND_BELOW_PREPARE(op_)
Definition: define.h:748
mapdef
Definition: map.h:324
MSG_TYPE_SPELL
#define MSG_TYPE_SPELL
Definition: newclient.h:411
SP_level_spellpoint_cost
int16_t SP_level_spellpoint_cost(object *caster, object *spell, int flags)
Definition: spell_util.c:235
MSG_SUBTYPE_NONE
#define MSG_SUBTYPE_NONE
Definition: newclient.h:420
delete_map
void delete_map(mapstruct *m)
Definition: map.c:1716
DEXTERITY
@ DEXTERITY
Definition: living.h:12
pl::unapply
unapplymode unapply
Definition: player.h:108
liv
Definition: living.h:35
SockList_Init
void SockList_Init(SockList *sl)
Definition: lowlevel.c:52
PU_HELMET
#define PU_HELMET
Definition: define.h:121
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
player_fire_bow
static int player_fire_bow(object *op, int dir)
Definition: player.c:2274
set_player_socket
static void set_player_socket(player *p, socket_struct *ns)
Definition: player.c:419
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
party_struct
Definition: party.h:10
push_ob
int push_ob(object *who, int dir, object *pusher)
Definition: move.c:421
key_inventory
@ key_inventory
Definition: player.h:53
object_set_owner
void object_set_owner(object *op, object *owner)
Definition: object.c:833
find_skill_by_name
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:202
account_char_remove
Account_Char * account_char_remove(Account_Char *chars, const char *pl_name)
Definition: account_char.c:298
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:220
pl::listening
uint8_t listening
Definition: player.h:120
P_OUT_OF_MAP
#define P_OUT_OF_MAP
Definition: map.h:250
turn_transport
static int turn_transport(object *transport, object *captain, int dir)
Definition: player.c:2879
account_char_save
void account_char_save(const char *account, Account_Char *chars)
Definition: account_char.c:146
env
static std::shared_ptr< inja::Environment > env
Definition: mapper.cpp:2215
EXIT_X
#define EXIT_X(xyz)
Definition: define.h:441
MAX_BUF
#define MAX_BUF
Definition: define.h:35
object_get_multi_size
void object_get_multi_size(const object *ob, int *sx, int *sy, int *hx, int *hy)
Definition: object.c:4731
Ns_Add
@ Ns_Add
Definition: newserver.h:66
ADD_PLAYER_NEW
#define ADD_PLAYER_NEW
Definition: player.h:230
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:281
IS_WEAPON
#define IS_WEAPON(op)
Definition: define.h:163
hideability
int hideability(object *ob)
Definition: player.c:3953
pl::last_weight
int32_t last_weight
Definition: player.h:144
bow_normal
@ bow_normal
Definition: player.h:29
clear_los
void clear_los(player *pl)
Definition: los.c:252
transfer_ob
int transfer_ob(object *op, int x, int y, int randomly, object *originator)
Definition: move.c:150
offsetof
#define offsetof(type, member)
Definition: shstr.h:37
Settings::playerdir
const char * playerdir
Definition: global.h:246
RANDOM
#define RANDOM()
Definition: define.h:642
SockList_Term
void SockList_Term(SockList *sl)
Definition: lowlevel.c:62
account_char_free
void account_char_free(Account_Char *chars)
Definition: account_char.c:334
SK_HIDING
@ SK_HIDING
Definition: skills.h:21
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:196
MOVE_FLY_LOW
#define MOVE_FLY_LOW
Definition: define.h:393
EVENT_PLAYER_DEATH
#define EVENT_PLAYER_DEATH
Definition: events.h:51
dead_player
void dead_player(object *op)
Definition: resurrection.c:297
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
random_roll
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.c:42
MSG_TYPE_ITEM_ADD
#define MSG_TYPE_ITEM_ADD
Definition: newclient.h:643
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
MSG_TYPE_COMMAND_FAILURE
#define MSG_TYPE_COMMAND_FAILURE
Definition: newclient.h:531
FOR_MAP_PREPARE
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:721
obj::y
int16_t y
Definition: object.h:328
FLAG_KNOWN_MAGICAL
#define FLAG_KNOWN_MAGICAL
Definition: define.h:319
FIND_PLAYER_NO_HIDDEN_DM
#define FIND_PLAYER_NO_HIDDEN_DM
Definition: player.h:221
is_wraith_pl
int is_wraith_pl(object *op)
Definition: player.c:176
OUT_OF_REAL_MAP
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:218
ST_PLAYING
#define ST_PLAYING
Definition: define.h:541
player_attack_door
static int player_attack_door(object *op, object *door)
Definition: player.c:2516
obj::arch
struct archt * arch
Definition: object.h:416
treasureliststruct::items
struct treasurestruct * items
Definition: treasure.h:89
object_set_msg
void object_set_msg(object *op, const char *msg)
Definition: object.c:4798
range_misc
@ range_misc
Definition: player.h:20
FLAG_READY_SKILL
#define FLAG_READY_SKILL
Definition: define.h:333
FLAG_READY_BOW
#define FLAG_READY_BOW
Definition: define.h:299
sounds.h
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
ST_CHANGE_CLASS
#define ST_CHANGE_CLASS
Definition: define.h:544
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
Settings::emergency_mapname
char * emergency_mapname
Definition: global.h:295
obj::type
uint8_t type
Definition: object.h:341
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
pticks
uint32_t pticks
Definition: time.c:45
roll-o-matic.stop
def stop()
Definition: roll-o-matic.py:49
FLAG_FRIENDLY
#define FLAG_FRIENDLY
Definition: define.h:246
spells.h
die_roll
int die_roll(int num, int size, const object *op, int goodbad)
Definition: utils.c:122
spellpathnames
const char *const spellpathnames[NRSPELLPATHS]
Definition: init.c:107
EVENT_DEATH
#define EVENT_DEATH
Definition: events.h:24
obj::stats
living stats
Definition: object.h:371
find_player_options
player * find_player_options(const char *plname, int options, const mapstruct *map)
Definition: player.c:67
PU_CLOAK
#define PU_CLOAK
Definition: define.h:127
bow_spreadshot
@ bow_spreadshot
Definition: player.h:31
BATTLEGROUND
@ BATTLEGROUND
Definition: object.h:163
MSG_TYPE_SKILL_FAILURE
#define MSG_TYPE_SKILL_FAILURE
Definition: newclient.h:590
obj::direction
int8_t direction
Definition: object.h:337
find_player_partial_name
player * find_player_partial_name(const char *plname)
Definition: player.c:111
archt::clone
object clone
Definition: object.h:472
pl::language
int language
Definition: player.h:205
party_get_password
const char * party_get_password(const partylist *party)
Definition: party.c:232
get_nearest_player
object * get_nearest_player(object *mon)
Definition: player.c:523
obj::contr
struct pl * contr
Definition: object.h:277
obj::facing
int8_t facing
Definition: object.h:338
pl::gen_sp_armour
int16_t gen_sp_armour
Definition: player.h:115
fire_bow
int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy)
Definition: player.c:2069
ST_CONFIRM_PASSWORD
#define ST_CONFIRM_PASSWORD
Definition: define.h:548
IS_ARMOR
#define IS_ARMOR(op)
Definition: define.h:166
unapply_nochoice
@ unapply_nochoice
Definition: player.h:63
apply_anim_suffix
void apply_anim_suffix(object *who, const char *suffix)
Definition: anim.c:149
SOUND_TYPE_GROUND
#define SOUND_TYPE_GROUND
Definition: newclient.h:336
FLAG_USE_ARMOUR
#define FLAG_USE_ARMOUR
Definition: define.h:295
PU_JEWELS
#define PU_JEWELS
Definition: define.h:141
item
Definition: item.py:1
MSG_TYPE_ITEM_REMOVE
#define MSG_TYPE_ITEM_REMOVE
Definition: newclient.h:642
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
pl::last_skill_exp
int64_t last_skill_exp[MAX_SKILLS]
Definition: player.h:140
did_make_save
int did_make_save(const object *op, int level, int bonus)
Definition: living.c:2282
enter_exit
void enter_exit(object *op, object *exit_ob)
Definition: server.c:721
check_spell_known
object * check_spell_known(object *op, const char *name)
Definition: spell_util.c:393
pl::delayed_buffers_allocated
uint8_t delayed_buffers_allocated
Definition: player.h:209
liv::grace
int16_t grace
Definition: living.h:44
check_pick
int check_pick(object *op)
Definition: player.c:1693
give.op
op
Definition: give.py:33
NDI_ALL
#define NDI_ALL
Definition: newclient.h:263
socket_struct::status
enum Sock_Status status
Definition: newserver.h:90
get_password
void get_password(object *op)
Definition: player.c:873
STRENGTH
@ STRENGTH
Definition: living.h:11
object_value_set
bool object_value_set(const object *op, const char *const key)
Definition: object.c:4384
pl::do_los
uint32_t do_los
Definition: player.h:128
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:278
pl::last_skill_ob
object * last_skill_ob[MAX_SKILLS]
Definition: player.h:139
shop.h
dragon_ability_gain
void dragon_ability_gain(object *who, int atnr, int level)
Definition: player.c:4252
check_stat_bounds
void check_stat_bounds(living *stats, int8_t min_stat, int8_t max_stat)
Definition: living.c:355
gravestone_text
static const char * gravestone_text(object *op, char *buf2, int len)
Definition: player.c:3201
EXIT_ALT_X
#define EXIT_ALT_X(xyz)
Definition: define.h:443
MSG_TYPE_ATTRIBUTE_GOD
#define MSG_TYPE_ATTRIBUTE_GOD
Definition: newclient.h:575
send_news
void send_news(const object *op)
Definition: player.c:203
PU_ARMOUR
#define PU_ARMOUR
Definition: define.h:123
esrv_update_item
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:360
query_base_name
void query_base_name(const object *op, int plural, char *buf, size_t size)
Definition: item.c:685
Settings::max_stat
uint8_t max_stat
Definition: global.h:320
SPELL_EFFECT
@ SPELL_EFFECT
Definition: object.h:215
drain_msg
const char *const drain_msg[NUM_STATS]
Definition: living.c:140
PU_NEWMODE
#define PU_NEWMODE
Definition: define.h:111
rv_vector
Definition: map.h:379
MSG_TYPE_ADMIN_RULES
#define MSG_TYPE_ADMIN_RULES
Definition: newclient.h:494
SKILL_TOOL
@ SKILL_TOOL
Definition: object.h:189
pl::rejoin_party
party_rejoin_mode rejoin_party
Definition: player.h:195
options
static struct Command_Line_Options options[]
Definition: init.c:379
EXIT_Y
#define EXIT_Y(xyz)
Definition: define.h:442
diamondslots.y
y
Definition: diamondslots.py:16
oblnk::ob
object * ob
Definition: object.h:446
FLAG_BEEN_APPLIED
#define FLAG_BEEN_APPLIED
Definition: define.h:323
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
allowed_class
int allowed_class(const object *op)
Definition: living.c:1652
NDI_BROWN
#define NDI_BROWN
Definition: newclient.h:253
object_find_by_type
object * object_find_by_type(const object *who, int type)
Definition: object.c:3988
buf
StringBuffer * buf
Definition: readable.c:1606
AP_NOPRINT
#define AP_NOPRINT
Definition: define.h:585
pl::hidden
uint32_t hidden
Definition: player.h:134
set_attr_value
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:219
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.c:2168
EVENT_REMOVE
#define EVENT_REMOVE
Definition: events.h:52
pl::last_stats
living last_stats
Definition: player.h:153
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2820
SockList_ResetRead
void SockList_ResetRead(SockList *sl)
Definition: lowlevel.c:80
short_stat_name
const char *const short_stat_name[NUM_STATS]
Definition: living.c:195
guild_entry.x1
int x1
Definition: guild_entry.py:33
NDI_DK_ORANGE
#define NDI_DK_ORANGE
Definition: newclient.h:248
object_update_speed
void object_update_speed(object *op)
Definition: object.c:1317
obj::more
struct obj * more
Definition: object.h:296
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
obj::move_type
MoveType move_type
Definition: object.h:428
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
pl::ranges
object * ranges[range_size]
Definition: player.h:103
send_rules
void send_rules(const object *op)
Definition: player.c:167
keyrings
@ keyrings
Definition: player.h:54
castle_read.key
key
Definition: castle_read.py:64
MSG_TYPE_ADMIN_LOGIN
#define MSG_TYPE_ADMIN_LOGIN
Definition: newclient.h:500
FLAG_ANIMATE
#define FLAG_ANIMATE
Definition: define.h:242
restore_player
static void restore_player(object *op)
Definition: player.c:3414
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
Definition: newclient.h:567
obj::skill
sstring skill
Definition: object.h:322
treasurestruct::next
struct treasurestruct * next
Definition: treasure.h:66
newclient.h
save_player
int save_player(object *op, int flag)
Definition: login.c:230
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2067
ST_GET_PARTY_PASSWORD
#define ST_GET_PARTY_PASSWORD
Definition: define.h:549
draw_ext_info
void draw_ext_info(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *message)
Definition: main.c:309
get_attr_value
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:314
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1533
object_matches_pickup_mode
int object_matches_pickup_mode(const object *item, int mode)
Definition: c_object.c:656
FOOD
@ FOOD
Definition: object.h:112
pl::ticks_played
uint32_t ticks_played
Definition: player.h:207
do_some_living
void do_some_living(object *op)
Definition: player.c:3236
add_statbonus
void add_statbonus(object *op)
Definition: living.c:869
i18n
const char * i18n(const object *who, const char *code)
Definition: languages.c:55
get_thaco_bonus
int get_thaco_bonus(int stat)
Definition: living.c:2358
first_map_ext_path
EXTERN char first_map_ext_path[MAX_BUF]
Definition: global.h:144
cure_disease
int cure_disease(object *sufferer, object *caster, sstring skill)
Definition: disease.c:685
pick_arrow_target
static object * pick_arrow_target(object *op, const char *type, int dir)
Definition: player.c:2000
DOOR
@ DOOR
Definition: object.h:126
add_friendly_object
void add_friendly_object(object *op)
Definition: friend.c:30
FLAG_UNPAID
#define FLAG_UNPAID
Definition: define.h:236
FLAG_NO_STRENGTH
#define FLAG_NO_STRENGTH
Definition: define.h:306
quest.state
state
Definition: quest.py:13
fix_luck
void fix_luck(void)
Definition: player.c:3859
PU_NOTHING
#define PU_NOTHING
Definition: define.h:106
OB_TYPE_MOVE_BLOCK
#define OB_TYPE_MOVE_BLOCK(ob1, type)
Definition: define.h:432
level
int level
Definition: readable.c:1604
path_to_player
int path_to_player(object *mon, object *pl, unsigned mindiff)
Definition: player.c:632
socket_struct::login_method
uint8_t login_method
Definition: newserver.h:128
is_true_undead
int is_true_undead(object *op)
Definition: player.c:3929
MSG_TYPE_ATTACK_NOATTACK
#define MSG_TYPE_ATTACK_NOATTACK
Definition: newclient.h:618
play_again
void play_again(object *op)
Definition: player.c:884
DRINK
@ DRINK
Definition: object.h:157
PU_CURSED
#define PU_CURSED
Definition: define.h:144
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
FLAG_XRAYS
#define FLAG_XRAYS
Definition: define.h:300
kill_player_permadeath
static void kill_player_permadeath(object *op)
Definition: player.c:3757
say.item
dictionary item
Definition: say.py:149
give_initial_items
void give_initial_items(object *pl, treasurelist *items)
Definition: player.c:765
Settings::search_items
uint8_t search_items
Definition: global.h:263
turn_one_transport
static int turn_one_transport(object *transport, object *captain, int dir)
Definition: player.c:2809
obj::anim_suffix
sstring anim_suffix
Definition: object.h:317
add_player
player * add_player(socket_struct *ns, int flags)
Definition: player.c:455
obj::move_on
MoveType move_on
Definition: object.h:431
drain_rod_charge
void drain_rod_charge(object *rod)
Definition: spell_util.c:775
range_skill
@ range_skill
Definition: player.h:22
obj::attacktype
uint32_t attacktype
Definition: object.h:345
server.h
oblnk
Definition: object.h:445
PU_DRINK
#define PU_DRINK
Definition: define.h:116
mapdef::path
char path[HUGE_BUF]
Definition: map.h:364
INTELLIGENCE
@ INTELLIGENCE
Definition: living.h:16
shop_contains
bool shop_contains(object *ob)
Definition: shop.c:1287
reputation.killer
def killer
Definition: reputation.py:13
hide
int hide(object *op, object *skill)
Definition: skills.c:494
pl::party
partylist * party
Definition: player.h:188
TRUE
#define TRUE
Definition: compat.h:11
pl::usekeys
usekeytype usekeys
Definition: player.h:107
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
ST_ROLL_STAT
#define ST_ROLL_STAT
Definition: define.h:543
get_map_flags
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:311
pets_control_golem
void pets_control_golem(object *op, int dir)
Definition: pets.c:628
PU_SHIELD
#define PU_SHIELD
Definition: define.h:122
SPELL
@ SPELL
Definition: object.h:214
liv::sp
int16_t sp
Definition: living.h:42
MSG_TYPE_APPLY
#define MSG_TYPE_APPLY
Definition: newclient.h:408
player_map_change_common
void player_map_change_common(object *op, mapstruct *const oldmap, mapstruct *const newmap)
Definition: server.c:270
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
FLAG_CURSED
#define FLAG_CURSED
Definition: define.h:316
find_key
object * find_key(object *pl, object *container, object *door)
Definition: player.c:2434
pick_up
void pick_up(object *op, object *alt)
Definition: c_object.c:519
rv_vector::direction
int direction
Definition: map.h:383
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
living.h
obj::magic
int8_t magic
Definition: object.h:351
obj::resist
int16_t resist[NROFATTACKS]
Definition: object.h:344
send_query
void send_query(socket_struct *ns, uint8_t flags, const char *text)
Definition: request.c:679
Send_With_Handling
void Send_With_Handling(socket_struct *ns, SockList *sl)
Definition: lowlevel.c:440
if
if(!(yy_init))
Definition: loader.c:2589
get_map_from_coord
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2375
mapdef::next
struct mapdef * next
Definition: map.h:325
object_split
object * object_split(object *orig_ob