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  p->socket.account_chars = 0;
319  } else {
320  /* Only needed when reusing existing player. */
321  clear_player(p);
322  }
323 
324  /* Clears basically the entire player structure except
325  * for next and socket.
326  */
327  memset((void *)((char *)p+offsetof(player, maplevel)), 0, sizeof(player)-offsetof(player, maplevel));
328 
329  /* There are some elements we want initialized to non zero value -
330  * we deal with that below this point.
331  */
332  p->party = NULL;
335  p->swap_first = -1;
336 
337 #ifdef AUTOSAVE
338  p->last_save_tick = 9999999;
339 #endif
340 
341  strcpy(p->savebed_map, first_map_path); /* Init. respawn position */
342 
343  op->contr = p; /* this aren't yet in archetype */
344  p->ob = op;
345  op->speed_left = 0.5;
346  op->speed = 1.0;
347  op->direction = 5; /* So player faces south */
348  op->stats.wc = 2;
349  op->run_away = 25; /* Then we panic... */
350 
351  roll_stats(op);
353  clear_los(p);
354 
355  p->gen_sp_armour = 10;
356  p->last_speed = -1;
357  p->shoottype = range_none;
358  p->bowtype = bow_normal;
359  p->petmode = pet_normal;
360  p->listening = 10;
361  p->last_weapon_sp = -1;
362  p->peaceful = 1; /* default peaceful */
363  p->do_los = 1;
364  p->no_shout = 0; /* default can shout */
365  p->language = -1; // find default language
366  p->unarmed_skill = NULL;
367  p->ticks_played = 0;
368 
369  strncpy(p->title, op->arch->clone.name, sizeof(p->title)-1);
370  p->title[sizeof(p->title)-1] = '\0';
371  op->race = add_string(op->arch->clone.race);
372 
374 
375  /* we need to clear these to -1 and not zero - otherwise,
376  * if a player quits and starts a new character, we wont
377  * send new values to the client, as things like exp start
378  * at zero.
379  */
380  for (i = 0; i < MAX_SKILLS; i++) {
381  p->last_skill_exp[i] = -1;
382  p->last_skill_ob[i] = NULL;
383  }
384  for (i = 0; i < NROFATTACKS; i++) {
385  p->last_resist[i] = -1;
386  }
387  p->last_stats.exp = -1;
388  p->last_weight = (uint32_t)-1;
389 
390  p->socket.update_look = 0;
391  p->socket.look_position = 0;
392  return p;
393 }
394 
401 void set_first_map(object *op) {
402  strcpy(op->contr->maplevel, first_map_path);
403  op->x = -1;
404  op->y = -1;
406 }
407 
420 static void set_player_socket(player *p, socket_struct *ns) {
421  if (p->socket.account_chars) {
423  }
424 
425  memcpy(&p->socket, ns, sizeof(socket_struct));
426 
427  /* The memcpy above copies the reference to faces sent. So we need to clear
428  * that pointer in ns, otherwise we get a double free.
429  */
430  ns->faces_sent = NULL;
431  ns->host = strdup_local("");
432  ns->account_name = strdup_local("");
433  ns->account_chars = NULL; // If not NULL, the reference is now kept by p
434 
435  if (p->socket.faces_sent == NULL)
437 
438  /* Needed because the socket we just copied over needs to be cleared.
439  * Note that this can result in a client reset if there is partial data
440  * on the incoming socket.
441  */
443 
444 
445 }
446 
464  player *p;
465 
466  p = get_player(NULL);
467  ns->status = Ns_Avail;
468  set_player_socket(p, ns);
469 
471 
472  if (!(flags & ADD_PLAYER_NO_MAP))
473  set_first_map(p->ob);
474 
476 
477  /* In this case, the client is provide all the informatin for the
478  * new character, so just return it. Do not display any messages,
479  * etc
480  */
482  return p;
483 
484  if (flags & ADD_PLAYER_NEW) {
485  roll_again(p->ob);
487  } else {
488  send_rules(p->ob);
489  send_news(p->ob);
490  display_motd(p->ob);
491  get_name(p->ob);
492  }
493  return p;
494 }
495 
507  archetype *start = at;
508 
509  for (;;) {
510  at = get_next_archetype(at);
511  if (at == NULL) {
512  at = get_next_archetype(at);
513  }
514  if (at->clone.type == PLAYER)
515  return at;
516  if (at == start) {
517  LOG(llevError, "No Player archetypes\n");
518  exit(-1);
519  }
520  }
521 }
522 
531 object *get_nearest_player(object *mon) {
532  object *op = NULL;
533  player *pl = NULL;
534  objectlink *ol;
535  unsigned lastdist;
536  rv_vector rv;
537 
538  for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) {
539  /* We should not find free objects on this friendly list, but it
540  * does periodically happen. Given that, lets deal with it.
541  * While unlikely, it is possible the next object on the friendly
542  * list is also free, so encapsulate this in a while loop.
543  */
544  while (QUERY_FLAG(ol->ob, FLAG_FREED) || !QUERY_FLAG(ol->ob, FLAG_FRIENDLY)) {
545  object *tmp = ol->ob;
546 
547  /* Can't do much more other than log the fact, because the object
548  * itself will have been cleared.
549  */
550  LOG(llevDebug, "get_nearest_player: Found free/non friendly object on friendly list\n");
551  ol = ol->next;
553  if (!ol)
554  return op;
555  }
556 
557  /* Remove special check for player from this. First, it looks to cause
558  * some crashes (ol->ob->contr not set properly?), but secondly, a more
559  * complicated method of state checking would be needed in any case -
560  * as it was, a clever player could type quit, and the function would
561  * skip them over while waiting for confirmation. Remove
562  * on_same_map check, as monster_can_detect_enemy() also does this
563  */
564  if (!monster_can_detect_enemy(mon, ol->ob, &rv))
565  continue;
566 
567  if (lastdist > rv.distance) {
568  op = ol->ob;
569  lastdist = rv.distance;
570  }
571  }
572  for (pl = first_player; pl != NULL; pl = pl->next) {
573  if (monster_can_detect_enemy(mon, pl->ob, &rv)) {
574  if (lastdist > rv.distance) {
575  op = pl->ob;
576  lastdist = rv.distance;
577  }
578  }
579  }
580  return op;
581 }
582 
583 object *get_nearest_criminal(object *mon) {
584  object *op = NULL;
585  for (player *pl = first_player; pl != NULL; pl = pl->next) {
586  rv_vector rv;
587  if (monster_can_detect_enemy(mon, pl->ob, &rv) && is_criminal(pl->ob)) {
588  op = pl->ob;
589  }
590  }
591  return op;
592 }
593 
603 #define DETOUR_AMOUNT 2
604 
618 #define MAX_SPACES 50
619 
651 int path_to_player(object *mon, object *pl, unsigned mindiff) {
652  rv_vector rv;
653  int16_t x, y;
654  int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked;
655  mapstruct *m, *lastmap;
656 
657  if (!get_rangevector(mon, pl, &rv, 0))
658  return 0;
659 
660  if (rv.distance < mindiff)
661  return 0;
662 
663  x = mon->x;
664  y = mon->y;
665  m = mon->map;
666  dir = rv.direction;
667  lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */
668  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
669  /* If we can't solve it within the search distance, return now. */
670  if (diff > max)
671  return 0;
672  while (diff > 1 && max > 0) {
673  lastx = x;
674  lasty = y;
675  lastmap = m;
676  x = lastx+freearr_x[dir];
677  y = lasty+freearr_y[dir];
678 
679  mflags = get_map_flags(m, &m, x, y, &x, &y);
680  blocked = (mflags&P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK(m, x, y);
681 
682  /* Space is blocked - try changing direction a little */
683  if ((mflags&P_OUT_OF_MAP)
684  || ((OB_TYPE_MOVE_BLOCK(mon, blocked) || (mflags&P_IS_ALIVE))
685  && (m == mon->map && blocked_link(mon, m, x, y)))) {
686  /* recalculate direction from last good location. Possible
687  * we were not traversing ideal location before.
688  */
689  if (get_rangevector_from_mapcoord(lastmap, lastx, lasty, pl, &rv, 0) && rv.direction != dir) {
690  /* OK - says direction should be different - lets reset the
691  * the values so it will try again.
692  */
693  x = lastx;
694  y = lasty;
695  m = lastmap;
696  dir = firstdir = rv.direction;
697  } else {
698  /* direct path is blocked - try taking a side step to
699  * either the left or right.
700  * Note increase the values in the loop below to be
701  * more than -1/1 respectively will mean the monster takes
702  * bigger detour. Have to be careful about these values getting
703  * too big (3 or maybe 4 or higher) as the monster may just try
704  * stepping back and forth
705  */
706  for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) {
707  if (i == 0)
708  continue; /* already did this, so skip it */
709  /* Use lastdir here - otherwise,
710  * since the direction that the creature should move in
711  * may change, you could get infinite loops.
712  * ie, player is northwest, but monster can only
713  * move west, so it does that. It goes some distance,
714  * gets blocked, finds that it should move north,
715  * can't do that, but now finds it can move east, and
716  * gets back to its original point. lastdir contains
717  * the last direction the creature has successfully
718  * moved.
719  */
720 
721  x = lastx+freearr_x[absdir(lastdir+i)];
722  y = lasty+freearr_y[absdir(lastdir+i)];
723  m = lastmap;
724  mflags = get_map_flags(m, &m, x, y, &x, &y);
725  if (mflags&P_OUT_OF_MAP)
726  continue;
727  blocked = GET_MAP_MOVE_BLOCK(m, x, y);
728  if (OB_TYPE_MOVE_BLOCK(mon, blocked))
729  continue;
730  if (mflags&P_IS_ALIVE)
731  continue;
732 
733  if (m == mon->map && blocked_link(mon, m, x, y))
734  break;
735  }
736  /* go through entire loop without finding a valid
737  * sidestep to take - thus, no valid path.
738  */
739  if (i == (DETOUR_AMOUNT+1))
740  return 0;
741  diff--;
742  lastdir = dir;
743  max--;
744  if (!firstdir)
745  firstdir = dir+i;
746  } /* else check alternate directions */
747  } /* if blocked */
748  else {
749  /* we moved towards creature, so diff is less */
750  diff--;
751  max--;
752  lastdir = dir;
753  if (!firstdir)
754  firstdir = dir;
755  }
756  if (diff <= 1) {
757  /* Recalculate diff (distance) because we may not have actually
758  * headed toward player for entire distance.
759  */
760  if (!get_rangevector_from_mapcoord(m, x, y, pl, &rv, 0))
761  return 0;
762  diff = MAX(FABS(rv.distance_x), FABS(rv.distance_y));
763  }
764  if (diff > max)
765  return 0;
766  }
767  /* If we reached the max, didn't find a direction in time */
768  if (!max)
769  return 0;
770 
771  return firstdir;
772 }
773 
784 void give_initial_items(object *pl, treasurelist *items) {
785  if (pl->randomitems != NULL)
787 
788  FOR_INV_PREPARE(pl, op) {
789  /* Forces get applied per default, unless they have the
790  * flag "neutral" set. Sorry but I can't think of a better way
791  */
792  if (op->type == FORCE && !QUERY_FLAG(op, FLAG_NEUTRAL))
794 
795  /* we never give weapons/armour if these cannot be used
796  * by this player due to race restrictions
797  */
798  if (pl->type == PLAYER) {
801  || (!QUERY_FLAG(pl, FLAG_USE_SHIELD) && IS_SHIELD(op))) {
802  object_remove(op);
804  continue;
805  }
806  }
807 
808  /* This really needs to be better - we should really give
809  * a substitute spellbook. The problem is that we don't really
810  * have a good idea what to replace it with (need something like
811  * a first level treasurelist for each skill.)
812  * remove duplicate skills also
813  */
814  if (op->type == SPELLBOOK || op->type == SKILL) {
815  int found;
816 
817  found = 0;
818  // Make sure we set flags that are checked by object_can_merge
819  // *before* we run object_can_merge. Otherwise, we can get two
820  // entries of the same skill.
821  if (op->type == SKILL) {
823  op->stats.exp = 0;
824  op->level = 1;
825  // Since this also happens to the invisible skills, we need this so that the flags match.
827  }
829  if (object_can_merge(op, tmp)) {
830  found = 1;
831  break;
832  }
834  if (found) {
835  LOG(llevError, "give_initial_items: Removing duplicate object %s\n", op->name);
836  object_remove(op);
838  continue;
839  }
840  if (op->nrof > 1)
841  op->nrof = 1;
842  }
843 
844  if (op->type == SPELLBOOK && op->inv) {
846  }
847 
848  /* Give starting characters identified, uncursed, and undamned
849  * items. Just don't identify gold or silver, or it won't be
850  * merged properly.
851  */
852  if (is_identifiable_type(op)) {
856  }
857  /* lock all 'normal items by default */
858  else
860  } FOR_INV_FINISH(); /* for loop of objects in player inv */
861 
862  /* Need to set up the skill pointers */
864 
872  FOR_INV_FINISH();
873 }
874 
881 void get_name(object *op) {
883  send_query(&op->contr->socket, 0, i18n(op, "What is your name?\n:"));
884 }
885 
892 void get_password(object *op) {
894  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "What is your password?\n:"));
895 }
896 
903 void play_again(object *op) {
904  SockList sl;
905 
906  op->contr->socket.status = Ns_Add;
908  op->chosen_skill = NULL;
909 
910  /*
911  * For old clients, ask if they want to play again.
912  * For clients with account support, just return to character seletion (see below).
913  */
914  if (op->contr->socket.login_method == 0) {
915  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Do you want to play again (a/q)?"));
916  }
917  /* a bit of a hack, but there are various places early in th
918  * player creation process that a user can quit (eg, roll
919  * stats) that isn't removing the player. Taking a quick
920  * look, there are many places that call play_again without
921  * removing the player - it probably makes more sense
922  * to leave it to play_again to remove the object in all
923  * cases.
924  */
925  if (!QUERY_FLAG(op, FLAG_REMOVED))
926  object_remove(op);
927  /* Need to set this to null - otherwise, it could point to garbage,
928  * and draw() doesn't check to see if the player is removed, only if
929  * the map is null or not swapped out.
930  */
931  op->map = NULL;
932 
933  SockList_Init(&sl);
934  SockList_AddString(&sl, "player ");
935  SockList_AddInt(&sl, 0);
936  SockList_AddInt(&sl, 0);
937  SockList_AddInt(&sl, 0);
938  SockList_AddChar(&sl, 0);
939 
940  Send_With_Handling(&op->contr->socket, &sl);
941  SockList_Term(&sl);
942 
943  if (op->contr->socket.login_method > 0) {
944  receive_play_again(op, 'a');
945  }
946 }
947 
956 void receive_play_again(object *op, char key) {
957  if (key == 'q' || key == 'Q') {
959  leave(op->contr, 0); /* ericserver will draw the message */
960  return;
961  } else if (key == 'a' || key == 'A') {
962  player *pl = op->contr;
963  const char *name = op->name;
964 
968  pl = get_player(pl);
969  op = pl->ob;
971  op->contr->password[0] = '~';
972  FREE_AND_CLEAR_STR(op->name);
973  FREE_AND_CLEAR_STR(op->name_pl);
974  if (pl->socket.login_method >= 1 && pl->socket.account_name != NULL) {
975  /* If we are using new login, we send the
976  * list of characters to the client - this should
977  * result in the client popping up this list so
978  * the player can choose which one to play - better
979  * than going to legacy login code.
980  * If the account_name is NULL, it means the client
981  * says it uses account but started playing without logging in.
982  */
985  } else {
986  /* Lets put a space in here */
988  "\n");
989  get_name(op);
990  set_first_map(op);
991  }
992  op->name = name; /* Already added a refcount above */
993  op->name_pl = add_string(name);
994  } else {
995  /* user pressed something else so just ask again... */
996  play_again(op);
997  }
998 }
999 
1006 void confirm_password(object *op) {
1008  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "Please type your password again.\n:"));
1009 }
1010 
1021 int get_party_password(object *op, partylist *party) {
1022  if (*party_get_password(party) == '\0') {
1023  return 0;
1024  }
1025 
1027  op->contr->party_to_join = party;
1028  send_query(&op->contr->socket, CS_QUERY_HIDEINPUT, i18n(op, "What is the password?\n:"));
1029  return 1;
1030 }
1031 
1038 int roll_stat(void) {
1039  int roll[4], i, low_index, k;
1040 
1041  for (i = 0; i < 4; ++i)
1042  roll[i] = (int)RANDOM()%6+1;
1043 
1044  for (i = 0, low_index = 0, k = 7; i < 4; ++i)
1045  if (roll[i] < k)
1046  k = roll[i],
1047  low_index = i;
1048 
1049  for (i = 0, k = 0; i < 4; ++i) {
1050  if (i != low_index)
1051  k += roll[i];
1052  }
1053  return k;
1054 }
1055 
1062 void roll_stats(object *op) {
1063  int sum = 0;
1064  int i = 0, j = 0;
1065  int statsort[7];
1066 
1067  do {
1068  op->stats.Str = roll_stat();
1069  op->stats.Dex = roll_stat();
1070  op->stats.Int = roll_stat();
1071  op->stats.Con = roll_stat();
1072  op->stats.Wis = roll_stat();
1073  op->stats.Pow = roll_stat();
1074  op->stats.Cha = roll_stat();
1075  sum = op->stats.Str+op->stats.Dex+op->stats.Int+op->stats.Con+op->stats.Wis+op->stats.Pow+op->stats.Cha;
1076  } while (sum != settings.roll_stat_points);
1077 
1078  /* Sort the stats so that rerolling is easier... */
1079  statsort[0] = op->stats.Str;
1080  statsort[1] = op->stats.Dex;
1081  statsort[2] = op->stats.Int;
1082  statsort[3] = op->stats.Con;
1083  statsort[4] = op->stats.Wis;
1084  statsort[5] = op->stats.Pow;
1085  statsort[6] = op->stats.Cha;
1086 
1087  /* a quick and dirty bubblesort? */
1088  do {
1089  if (statsort[i] < statsort[i+1]) {
1090  j = statsort[i];
1091  statsort[i] = statsort[i+1];
1092  statsort[i+1] = j;
1093  i = 0;
1094  } else {
1095  i++;
1096  }
1097  } while (i < 6);
1098 
1099  op->stats.Str = statsort[0];
1100  op->stats.Dex = statsort[1];
1101  op->stats.Con = statsort[2];
1102  op->stats.Int = statsort[3];
1103  op->stats.Wis = statsort[4];
1104  op->stats.Pow = statsort[5];
1105  op->stats.Cha = statsort[6];
1106 
1107  op->contr->orig_stats.Str = op->stats.Str;
1108  op->contr->orig_stats.Dex = op->stats.Dex;
1109  op->contr->orig_stats.Int = op->stats.Int;
1110  op->contr->orig_stats.Con = op->stats.Con;
1111  op->contr->orig_stats.Wis = op->stats.Wis;
1112  op->contr->orig_stats.Pow = op->stats.Pow;
1113  op->contr->orig_stats.Cha = op->stats.Cha;
1114 
1115  op->level = 1;
1116  op->stats.exp = 0;
1117  op->stats.ac = 0;
1118 
1119  op->contr->levhp[1] = 9;
1120  op->contr->levsp[1] = 6;
1121  op->contr->levgrace[1] = 3;
1122 
1123  fix_object(op);
1124  op->stats.hp = op->stats.maxhp;
1125  op->stats.sp = op->stats.maxsp;
1126  op->stats.grace = op->stats.maxgrace;
1127  op->contr->orig_stats = op->stats;
1128 }
1129 
1136 void roll_again(object *op) {
1137  esrv_new_player(op->contr, 0);
1138  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)? "));
1139 }
1140 
1150 static void swap_stat(object *op, int swap_second) {
1151  signed char tmp;
1152 
1153  if (op->contr->swap_first == -1) {
1154  LOG(llevError, "player.c:swap_stat() - swap_first is -1\n");
1155  return;
1156  }
1157 
1158  tmp = get_attr_value(&op->contr->orig_stats, op->contr->swap_first);
1159 
1160  set_attr_value(&op->contr->orig_stats, op->contr->swap_first, get_attr_value(&op->contr->orig_stats, swap_second));
1161 
1162  set_attr_value(&op->contr->orig_stats, swap_second, tmp);
1163 
1165  "%s done\n",
1166  short_stat_name[swap_second]);
1167 
1168  op->stats.Str = op->contr->orig_stats.Str;
1169  op->stats.Dex = op->contr->orig_stats.Dex;
1170  op->stats.Con = op->contr->orig_stats.Con;
1171  op->stats.Int = op->contr->orig_stats.Int;
1172  op->stats.Wis = op->contr->orig_stats.Wis;
1173  op->stats.Pow = op->contr->orig_stats.Pow;
1174  op->stats.Cha = op->contr->orig_stats.Cha;
1175  op->stats.ac = 0;
1176 
1177  op->level = 1;
1178  op->stats.exp = 0;
1179  op->stats.ac = 0;
1180 
1181  op->contr->levhp[1] = 9;
1182  op->contr->levsp[1] = 6;
1183  op->contr->levgrace[1] = 3;
1184 
1185  fix_object(op);
1186  op->stats.hp = op->stats.maxhp;
1187  op->stats.sp = op->stats.maxsp;
1188  op->stats.grace = op->stats.maxgrace;
1189  op->contr->orig_stats = op->stats;
1190  op->contr->swap_first = -1;
1191 }
1192 
1208 void key_roll_stat(object *op, char key) {
1209  int keynum = key-'0';
1210  static const int8_t stat_trans[] = {
1211  -1,
1212  STRENGTH,
1213  DEXTERITY,
1214  CONSTITUTION,
1215  INTELLIGENCE,
1216  WISDOM,
1217  POWER,
1218  CHARISMA,
1219  };
1220 
1221  if (keynum > 0 && keynum <= 7) {
1222  if (op->contr->swap_first == -1) {
1223  op->contr->swap_first = stat_trans[keynum];
1225  "%s ->",
1226  short_stat_name[stat_trans[keynum]]);
1227  } else
1228  swap_stat(op, stat_trans[keynum]);
1229 
1230  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1231  return;
1232  }
1233  switch (key) {
1234  case 'n':
1235  case 'N': {
1236  SET_FLAG(op, FLAG_WIZ);
1237  if (op->map == NULL) {
1238  LOG(llevError, "Map == NULL in state 2\n");
1239  break;
1240  }
1241 
1242  SET_ANIMATION(op, 2); /* So player faces south */
1243  /* Enter exit adds a player otherwise */
1244  add_statbonus(op);
1245  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"));
1247  if (op->msg)
1250  op->msg);
1251  return;
1252  }
1253  case 'y':
1254  case 'Y':
1255  roll_stats(op);
1256  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, "");
1257  return;
1258 
1259  case 'q':
1260  case 'Q':
1261  play_again(op);
1262  return;
1263 
1264  default:
1265  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Yes, No, Quit or 1-6. Roll again?"));
1266  return;
1267  }
1268  return;
1269 }
1270 
1284 void key_change_class(object *op, char key) {
1285  int tmp_loop;
1286 
1287  if (key == 'q' || key == 'Q') {
1288  object_remove(op);
1289  play_again(op);
1290  return;
1291  }
1292  if (key == 'd' || key == 'D') {
1293  char buf[MAX_BUF];
1294 
1295  /* this must before then initial items are given */
1296  esrv_new_player(op->contr, op->weight+op->carrying);
1297  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1298 
1299  /* Here we handle the BORN global event */
1301 
1302  /* We then generate a LOGIN event */
1303  events_execute_global_event(EVENT_LOGIN, op->contr, op->contr->socket.host);
1304  player_set_state(op->contr, ST_PLAYING);
1305 
1306  object_set_msg(op, NULL);
1307 
1308  /* We create this now because some of the unique maps will need it
1309  * to save here.
1310  */
1311  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1313 
1314 #ifdef AUTOSAVE
1315  op->contr->last_save_tick = pticks;
1316 #endif
1319  "Welcome to Crossfire!\n Press `?' for help\n");
1320 
1323  "%s entered the game.", op->name);
1324 
1326  give_initial_items(op, op->randomitems);
1329  fix_object(op);
1330 
1331  /* This moves the player to a different start map, if there
1332  * is one for this race
1333  */
1334  if (*first_map_ext_path) {
1335  object *tmp;
1336  char mapname[MAX_BUF];
1337  mapstruct *oldmap;
1338 
1339  oldmap = op->map;
1340 
1341  snprintf(mapname, MAX_BUF-1, "%s/%s", first_map_ext_path, op->arch->name);
1342  /*printf("%s\n", mapname);*/
1343  tmp = object_new();
1345  EXIT_X(tmp) = op->x;
1346  EXIT_Y(tmp) = op->y;
1347  enter_exit(op, tmp);
1348 
1349  if (oldmap != op->map) {
1350  /* map exists, update bed of reality location, in case player dies */
1351  op->contr->bed_x = op->x;
1352  op->contr->bed_y = op->y;
1353  strlcpy(op->contr->savebed_map, mapname, sizeof(op->contr->savebed_map));
1354  }
1355 
1357  } else {
1358  LOG(llevDebug, "first_map_ext_path not set\n");
1359  }
1360  return;
1361  }
1362 
1363  /* Following actually changes the race - this is the default command
1364  * if we don't match with one of the options above.
1365  */
1366 
1367  tmp_loop = 0;
1368  while (!tmp_loop) {
1369  const char *name = add_string(op->name);
1370  int x = op->x, y = op->y;
1371 
1373  object_remove(op);
1374  /* get_player_archetype() is really misnamed - it will
1375  * get the next archetype from the list.
1376  */
1377  op->arch = get_player_archetype(op->arch);
1378  object_copy(&op->arch->clone, op);
1379  op->stats = op->contr->orig_stats;
1380  free_string(op->name);
1381  op->name = name;
1382  free_string(op->name_pl);
1383  op->name_pl = add_string(name);
1384  SET_ANIMATION(op, 2); /* So player faces south */
1385  object_insert_in_map_at(op, op->map, op, 0, x, y);
1386  strncpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title)-1);
1387  op->contr->title[sizeof(op->contr->title)-1] = '\0';
1388  add_statbonus(op);
1389  tmp_loop = allowed_class(op);
1390  }
1393  fix_object(op);
1394  op->stats.hp = op->stats.maxhp;
1395  op->stats.sp = op->stats.maxsp;
1396  op->stats.grace = 0;
1397  if (op->msg)
1399  op->msg);
1400  send_query(&op->contr->socket, CS_QUERY_SINGLECHAR, i18n(op, "Press any key for the next race.\nPress `d' to play this race.\n"));
1401 }
1402 
1424 int check_race_and_class(living *stats, archetype *race, archetype *opclass)
1425 {
1426  int i, stat, failure=0;
1427 
1428  for (i = 0; i < NUM_STATS; i++) {
1429  stat = get_attr_value(stats, i);
1430  if (race)
1431  stat += get_attr_value(&race->clone.stats, i);
1432 
1433  if (opclass)
1434  stat += get_attr_value(&opclass->clone.stats, i);
1435 
1436  set_attr_value(stats, i, stat);
1437 
1438  /* We process all stats, regardless if there is a failure
1439  * or not.
1440  */
1441  if (stat < MIN_STAT) failure=1;
1442 
1443  /* Maybe this should be an error? Player is losing
1444  * some stats points here, but it is legal.
1445  */
1446  if (stat > settings.max_stat) stat = settings.max_stat;
1447  }
1448  return failure;
1449 
1450 }
1451 
1474 int apply_race_and_class(object *op, archetype *race, archetype *opclass, living *stats)
1475 {
1476  const char *name = add_string(op->name);
1477  char buf[MAX_BUF];
1478  object *inv;
1479 
1480  /* Free any objects in character inventory - they
1481  * shouldn't have any, but there is the potential that
1482  * we give them objects below and then get a creation
1483  * failure (stat out of range), in which case
1484  * those objects would be in the inventory.
1485  */
1486  while (op->inv) {
1487  inv = op->inv;
1488  object_remove(inv);
1489  object_free(inv, 0);
1490  }
1491 
1492  object_copy(&race->clone, op);
1493  free_string(op->name);
1494  op->name = name;
1495  free_string(op->name_pl);
1496  op->name_pl = add_string(name);
1497  SET_ANIMATION(op, 2); /* So player faces south */
1498  strlcpy(op->contr->title, op->arch->clone.name, sizeof(op->contr->title));
1499 
1500  if (stats) {
1501  /* Copy over the stats. Use this instead a memcpy because
1502  * we only want to copy over a few specific stats, and
1503  * leave things like maxhp, maxsp, etc, unchanged.
1504  */
1505  int i, stat;
1506  for (i = 0; i < NUM_STATS; i++) {
1507  stat = get_attr_value(stats, i);
1508  set_attr_value(&op->stats, i, stat);
1509  set_attr_value(&op->contr->orig_stats, i, stat);
1510  }
1511  } else {
1512  /* Note that this will repeated increase the stat values
1513  * if the caller does not reset them. Only do this
1514  * if stats is not provided - if stats is provided, those
1515  * are already adjusted.
1516  */
1517  add_statbonus(op);
1518 
1519  /* Checks that all stats are greater than 1. Once again,
1520  * only do this if stats are not provided
1521  */
1522  if (!allowed_class(op)) return 1;
1523  }
1524 
1526  op->stats.hp = op->stats.maxhp;
1527  op->stats.sp = op->stats.maxsp;
1528  op->stats.grace = 0;
1529 
1530  /* this must before then initial items are given */
1531  esrv_new_player(op->contr, op->weight+op->carrying);
1532  create_treasure(find_treasurelist("starting_wealth"), op, 0, 0, 0);
1533 
1534  /* This has to be done before class, otherwise the NOCLASSFACECHANGE
1535  * object is not in the inventory, and racial face will get overwritten.
1536  */
1537  give_initial_items(op, op->randomitems);
1538 
1539  if (stats) {
1540  /* Apply class information */
1542  } else {
1543  apply_changes_to_player(op, &opclass->clone, 0);
1544 
1545  /* Checks that all stats are greater than 1 */
1546  if (!allowed_class(op)) return 2;
1547  }
1548 
1549  /* Here we handle the BORN global event */
1551 
1552  /* We then generate a LOGIN event */
1553  events_execute_global_event(EVENT_LOGIN, op->contr, op->contr->socket.host);
1554 
1555  object_set_msg(op, NULL);
1556 
1557  /* We create this now because some of the unique maps will need it
1558  * to save here.
1559  */
1560  snprintf(buf, sizeof(buf), "%s/%s/%s", settings.localdir, settings.playerdir, op->name);
1562 
1563 #ifdef AUTOSAVE
1564  op->contr->last_save_tick = pticks;
1565 #endif
1566 
1569  fix_object(op);
1570 
1573  esrv_add_spells(op->contr, NULL);
1574 
1575  return 0;
1576 
1577 }
1578 
1587 void key_confirm_quit(object *op, char key) {
1588  char buf[MAX_BUF];
1589  mapstruct *mp, *next;
1590 
1591  // this was tested when 'quit' command was issued, but better safe than sorry.
1592  if (QUERY_FLAG(op, FLAG_WIZ)) {
1593  player_set_state(op->contr, ST_PLAYING);
1594  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOGIN, "Can't quit when in DM mode.");
1595  return;
1596  }
1597 
1598  if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') {
1599  player_set_state(op->contr, ST_PLAYING);
1601  "OK, continuing to play.");
1602  return;
1603  }
1604 
1607  object_remove(op);
1608  op->direction = 0;
1610  "%s quits the game.",
1611  op->name);
1612 
1613  strcpy(op->contr->killer, "quit");
1614  hiscore_check(op, 0);
1615  party_leave(op);
1616  if (settings.set_title == TRUE)
1617  player_set_own_title(op->contr, "");
1618 
1619 
1620  /* We need to hunt for any per player unique maps in memory and
1621  * get rid of them. The trailing slash in the path is intentional,
1622  * so that players named 'Ab' won't match against players 'Abe' pathname
1623  */
1624  snprintf(buf, sizeof(buf), "%s/%s/%s/", settings.localdir, settings.playerdir, op->name);
1625  for (mp = first_map; mp != NULL; mp = next) {
1626  next = mp->next;
1627  if (!strncmp(mp->path, buf, strlen(buf)))
1628  delete_map(mp);
1629  }
1630 
1631  delete_character(op->name);
1632 
1633  /* Remove player from account list and send back data if needed */
1634  if (op->contr->socket.account_chars != NULL) {
1635  account_char_remove(op->contr->socket.account_chars, op->name);
1636  account_char_save(op->contr->socket.account_chars);
1637  /* char information is reloaded in send_account_players below */
1638  account_char_free(op->contr->socket.account_chars);
1639  op->contr->socket.account_chars = NULL;
1640  account_remove_player(op->contr->socket.account_name, op->name);
1641  send_account_players(&op->contr->socket);
1642  }
1643 
1644  play_again(op);
1645 }
1646 
1653 static void flee_player(object *op) {
1654  int dir, diff;
1655  rv_vector rv;
1656 
1657  if (op->stats.hp < 0) {
1658  LOG(llevDebug, "Fleeing player is dead.\n");
1660  return;
1661  }
1662 
1663  if (op->enemy == NULL) {
1664  LOG(llevDebug, "Fleeing player had no enemy.\n");
1666  return;
1667  }
1668 
1669  /* Seen some crashes here. Since we don't store an
1670  * op->enemy_count, it is possible that something destroys the
1671  * actual enemy, and the object is recycled.
1672  */
1673  if (op->enemy->map == NULL) {
1675  object_set_enemy(op, NULL);
1676  return;
1677  }
1678 
1679  if (!(random_roll(0, 4, op, PREFER_LOW)) && did_make_save(op, op->level, 0)) {
1680  object_set_enemy(op, NULL);
1682  return;
1683  }
1684  if (!get_rangevector(op, op->enemy, &rv, 0)) {
1685  object_set_enemy(op, NULL);
1687  return;
1688  }
1689 
1690  dir = absdir(4+rv.direction);
1691  for (diff = 0; diff < 3; diff++) {
1692  int m = 1-(RANDOM()&2);
1693  if (move_ob(op, absdir(dir+diff*m), op)
1694  || (diff == 0 && move_ob(op, absdir(dir-diff*m), op))) {
1695  return;
1696  }
1697  }
1698  /* Cornered, get rid of scared */
1700  object_set_enemy(op, NULL);
1701 }
1702 
1712 int check_pick(object *op) {
1713  tag_t op_tag;
1714  int stop = 0;
1715  int j, k, wvratio, current_ratio;
1716  char putstring[128], tmpstr[16];
1717 
1718  /* if you're flying, you can't pick up anything */
1719  if (op->move_type&MOVE_FLYING)
1720  return 1;
1721  /* If not a player, don't check anything. */
1722  if (!op->contr) {
1723  return 1;
1724  }
1725 
1726  op_tag = op->count;
1727 
1729  if (object_was_destroyed(op, op_tag))
1730  return 0;
1731 
1732  if (!object_can_pick(op, tmp))
1733  continue;
1734 
1735  if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) {
1736  if (object_matches_string(op, tmp, op->contr->search_str))
1737  pick_up(op, tmp);
1738  continue;
1739  }
1740 
1741  /* high not bit set? We're using the old autopickup model */
1742  if (!(op->contr->mode&PU_NEWMODE)) {
1743  switch (op->contr->mode) {
1744  case 0:
1745  return 1; /* don't pick up */
1746 
1747  case 1:
1748  pick_up(op, tmp);
1749  return 1;
1750 
1751  case 2:
1752  pick_up(op, tmp);
1753  return 0;
1754 
1755  case 3:
1756  return 0; /* stop before pickup */
1757 
1758  case 4:
1759  pick_up(op, tmp);
1760  break;
1761 
1762  case 5:
1763  pick_up(op, tmp);
1764  stop = 1;
1765  break;
1766 
1767  case 6:
1770  pick_up(op, tmp);
1771  break;
1772 
1773  case 7:
1774  if (tmp->type == MONEY || tmp->type == GEM)
1775  pick_up(op, tmp);
1776  break;
1777 
1778  default:
1779  /* use value density */
1780  if (!QUERY_FLAG(tmp, FLAG_UNPAID)
1781  && (price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))) >= op->contr->mode)
1782  pick_up(op, tmp);
1783  }
1784  } else { /* old model */
1785  /* NEW pickup handling */
1786  if (op->contr->mode&PU_DEBUG) {
1787  /* some debugging code to figure out item information */
1789  "item name: %s item type: %d weight/value: %d",
1790  tmp->name ? tmp->name : tmp->arch->name, tmp->type,
1791  (int)(price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1))));
1792 
1793 
1794  snprintf(putstring, sizeof(putstring), "...flags: ");
1795  for (k = 0; k < 4; k++) {
1796  for (j = 0; j < 32; j++) {
1797  if ((tmp->flags[k]>>j)&0x01) {
1798  snprintf(tmpstr, sizeof(tmpstr), "%d ", k*32+j);
1799  strcat(putstring, tmpstr);
1800  }
1801  }
1802  }
1804  putstring);
1805  }
1806  /* philosophy:
1807  * It's easy to grab an item type from a pile, as long as it's
1808  * generic. This takes no game-time. For more detailed pickups
1809  * and selections, select-items should be used. This is a
1810  * grab-as-you-run type mode that's really useful for arrows for
1811  * example.
1812  * The drawback: right now it has no frontend, so you need to
1813  * stick the bits you want into a calculator in hex mode and then
1814  * convert to decimal and then 'pickup <#>
1815  */
1816 
1817  /* the first two modes are exclusive: if NOTHING we return, if
1818  * STOP then we stop. All the rest are applied sequentially,
1819  * meaning if any test passes, the item gets picked up. */
1820 
1821  /* if mode is set to pick nothing up, return */
1822 
1823  if (op->contr->mode == PU_NOTHING)
1824  return 1;
1825 
1826  /* if mode is set to stop when encountering objects, return.
1827  * Take STOP before INHIBIT since it doesn't actually pick
1828  * anything up */
1829 
1830  if (op->contr->mode&PU_STOP)
1831  return 0;
1832 
1833  /* useful for going into stores and not losing your settings... */
1834  /* and for battles where you don't want to get loaded down while
1835  * fighting */
1836  if (op->contr->mode&PU_INHIBIT)
1837  return 1;
1838 
1839  /* prevent us from turning into auto-thieves :) */
1840  if (QUERY_FLAG(tmp, FLAG_UNPAID))
1841  continue;
1842 
1843  /* ignore known cursed objects */
1844  if (QUERY_FLAG(tmp, FLAG_KNOWN_CURSED) && op->contr->mode&PU_NOT_CURSED)
1845  continue;
1846 
1847  static int checks[] = {
1848  PU_FOOD,
1849  PU_DRINK,
1850  PU_FLESH,
1851  PU_POTION,
1852  PU_SPELLBOOK,
1854  PU_READABLES,
1856  PU_MAGICAL,
1857  PU_VALUABLES,
1858  PU_JEWELS,
1859  PU_BOW,
1860  PU_ARROW,
1861  PU_ARMOUR,
1862  PU_HELMET,
1863  PU_SHIELD,
1864  PU_BOOTS,
1865  PU_GLOVES,
1866  PU_CLOAK,
1869  PU_KEY,
1870  PU_CONTAINER,
1871  PU_CURSED,
1872  0
1873  };
1874  int found = 0;
1875  for (int m = 0; checks[m] != 0; m++) {
1876  if (op->contr->mode & checks[m] && object_matches_pickup_mode(tmp, checks[m])) {
1877  pick_up(op, tmp);
1878  found = 1;
1879  break;
1880  }
1881  }
1882  if (found) {
1883  continue;
1884  }
1885 
1886  /* any of the last 4 bits set means we use the ratio for value
1887  * pickups */
1888  if (op->contr->mode&PU_RATIO) {
1889  /* use value density to decide what else to grab.
1890  * >=7 was >= op->contr->mode
1891  * >=7 is the old standard setting. Now we take the last 4 bits
1892  * and multiply them by 5, giving 0..15*5== 5..75 */
1893  wvratio = (op->contr->mode&PU_RATIO)*5;
1894  current_ratio = price_base(tmp)*100/(tmp->weight*MAX(tmp->nrof, 1));
1895  if (current_ratio >= wvratio) {
1896  pick_up(op, tmp);
1897  continue;
1898  }
1899  }
1900  } /* the new pickup model */
1901  } FOR_BELOW_FINISH();
1902  return !stop;
1903 }
1904 
1917 static object *find_arrow(object *op, const char *type) {
1918  object *tmp = NULL;
1919 
1921  if (!tmp
1922  && inv->type == CONTAINER
1923  && inv->race == type
1925  tmp = find_arrow(inv, type);
1926  else if (inv->type == ARROW && inv->race == type)
1927  return inv;
1928  FOR_INV_FINISH();
1929  return tmp;
1930 }
1931 
1949 static object *find_better_arrow(object *op, object *target, const char *type, int *better) {
1950  object *tmp = NULL, *ntmp;
1951  int attacknum, attacktype, betterby = 0, i;
1952 
1953  if (!type)
1954  return NULL;
1955 
1956  FOR_INV_PREPARE(op, arrow) {
1957  if (arrow->type == CONTAINER
1958  && arrow->race == type
1959  && QUERY_FLAG(arrow, FLAG_APPLIED)) {
1960  i = 0;
1961  ntmp = find_better_arrow(arrow, target, type, &i);
1962  if (i > betterby) {
1963  tmp = ntmp;
1964  betterby = i;
1965  }
1966  } else if (arrow->type == ARROW && arrow->race == type) {
1967  /* always prefer assassination/slaying */
1968  if (target->race != NULL
1969  && arrow->slaying != NULL
1970  && strstr(arrow->slaying, target->race)) {
1971  if (arrow->attacktype&AT_DEATH) {
1972  if (better)
1973  *better = 100;
1974  return arrow;
1975  } else {
1976  tmp = arrow;
1977  betterby = (arrow->magic+arrow->stats.dam)*2;
1978  }
1979  } else {
1980  for (attacknum = 0; attacknum < NROFATTACKS; attacknum++) {
1981  attacktype = 1<<attacknum;
1982  if ((arrow->attacktype&attacktype) && (target->arch->clone.resist[attacknum]) < 0)
1983  if (((arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100) > betterby) {
1984  tmp = arrow;
1985  betterby = (arrow->magic+arrow->stats.dam)*(100-target->arch->clone.resist[attacknum])/100;
1986  }
1987  }
1988  if ((2+arrow->magic+arrow->stats.dam) > betterby) {
1989  tmp = arrow;
1990  betterby = 2+arrow->magic+arrow->stats.dam;
1991  }
1992  if (arrow->title && (1+arrow->magic+arrow->stats.dam) > betterby) {
1993  tmp = arrow;
1994  betterby = 1+arrow->magic+arrow->stats.dam;
1995  }
1996  }
1997  }
1998  } FOR_INV_FINISH();
1999  if (tmp == NULL)
2000  return find_arrow(op, type);
2001 
2002  if (better)
2003  *better = betterby;
2004  return tmp;
2005 }
2006 
2019 static object *pick_arrow_target(object *op, const char *type, int dir) {
2020  object *tmp = NULL;
2021  mapstruct *m;
2022  int i, mflags, found, number;
2023  int16_t x, y;
2024 
2025  if (op->map == NULL)
2026  return find_arrow(op, type);
2027 
2028  /* do a dex check */
2029  number = (die_roll(2, 40, op, PREFER_LOW)-2)/2;
2030  if (number > (op->stats.Dex+(op->chosen_skill ? op->chosen_skill->level : op->level)))
2031  return find_arrow(op, type);
2032 
2033  m = op->map;
2034  x = op->x;
2035  y = op->y;
2036 
2037  /* find the first target */
2038  for (i = 0, found = 0; i < 20; i++) {
2039  x += freearr_x[dir];
2040  y += freearr_y[dir];
2041  mflags = get_map_flags(m, &m, x, y, &x, &y);
2042  if (mflags&P_OUT_OF_MAP || mflags&P_BLOCKSVIEW) {
2043  tmp = NULL;
2044  break;
2045  } else if (GET_MAP_MOVE_BLOCK(m, x, y) == MOVE_FLY_LOW) {
2046  /* This block presumes arrows and the like are MOVE_FLY_SLOW -
2047  * perhaps a bad assumption.
2048  */
2049  tmp = NULL;
2050  break;
2051  }
2052  if (mflags&P_IS_ALIVE) {
2053  FOR_MAP_PREPARE(m, x, y, tmp2)
2054  if (QUERY_FLAG(tmp2, FLAG_ALIVE)) {
2055  tmp = tmp2;
2056  found++;
2057  break;
2058  }
2059  FOR_MAP_FINISH();
2060  if (found)
2061  break;
2062  }
2063  }
2064  if (tmp == NULL)
2065  return find_arrow(op, type);
2066 
2067  return find_better_arrow(op, HEAD(tmp), type, NULL);
2068 }
2069 
2088 int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy) {
2089  object *bow;
2090  tag_t tag;
2091  int bowspeed, mflags;
2092  mapstruct *m;
2093 
2094  if (!dir) {
2096  "You can't shoot yourself!");
2097  return 0;
2098  }
2099  if (op->type == PLAYER)
2100  bow = op->contr->ranges[range_bow];
2101  else {
2102  /* Don't check for applied - monsters don't apply bows - in that way, they
2103  * don't need to switch back and forth between bows and weapons.
2104  */
2105  bow = object_find_by_type(op, BOW);
2106  if (!bow) {
2107  LOG(llevError, "Range: bow without activated bow (%s).\n", op->name);
2108  return 0;
2109  }
2110  }
2111  if (!bow->race || !bow->skill) {
2113  "Your %s is broken.",
2114  bow->name);
2115  return 0;
2116  }
2117 
2118  bowspeed = bow->stats.sp+get_dex_bonus(op->stats.Dex);
2119 
2120  /* penalize ROF for bestarrow */
2121  if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow)
2122  bowspeed -= get_dex_bonus(op->stats.Dex)+5;
2123  if (bowspeed < 1)
2124  bowspeed = 1;
2125 
2126  if (arrow == NULL) {
2127  arrow = find_arrow(op, bow->race);
2128  if (arrow == NULL) {
2129  if (op->type == PLAYER)
2132  "You have no %s left.",
2133  bow->race);
2134  /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */
2135  else
2137  return 0;
2138  }
2139  }
2140  mflags = get_map_flags(op->map, &m, sx, sy, &sx, &sy);
2141  if (mflags&P_OUT_OF_MAP) {
2142  return 0;
2143  }
2144  if (GET_MAP_MOVE_BLOCK(m, sx, sy)&MOVE_FLY_LOW) {
2145  return 0;
2146  }
2147 
2148  /* this should not happen, but sometimes does */
2149  if (arrow->nrof == 0) {
2150  object_remove(arrow);
2152  return 0;
2153  }
2154 
2155  arrow = object_split(arrow, 1, NULL, 0);
2156  if (arrow == NULL) {
2158  "You have no %s left.",
2159  bow->race);
2160  return 0;
2161  }
2162  object_set_owner(arrow, op);
2163  if (arrow->skill)
2164  free_string(arrow->skill);
2165  arrow->skill = add_refcount(bow->skill);
2166 
2167  arrow->direction = dir;
2168 
2169  if (op->type == PLAYER) {
2170  op->speed_left = 0.01-(float)FABS(op->speed)*100/bowspeed;
2171  fix_object(op);
2172  }
2173 
2174  if (bow->anim_suffix != NULL)
2176 
2177 /* SET_ANIMATION(arrow, arrow->direction);*/
2178  object_update_turn_face(arrow);
2179  arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */
2180  arrow->stats.hp = arrow->stats.dam;
2181  arrow->stats.grace = arrow->attacktype;
2182  if (arrow->slaying != NULL)
2183  arrow->spellarg = strdup_local(arrow->slaying);
2184 
2185  /* Note that this was different for monsters - they got their level
2186  * added to the damage. I think the strength bonus is more proper.
2187  */
2188 
2189  arrow->stats.dam += (QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))
2190  +bow->stats.dam
2191  +bow->magic
2192  +arrow->magic;
2193 
2194  /* update the speed */
2195  arrow->speed = (float)((QUERY_FLAG(bow, FLAG_NO_STRENGTH) ? 0 : get_dam_bonus(op->stats.Str))+bow->magic+arrow->magic)/5.0
2196  +(float)bow->stats.dam/7.0;
2197 
2198  if (arrow->speed < 1.0)
2199  arrow->speed = 1.0;
2200  object_update_speed(arrow);
2201  arrow->speed_left = 0;
2202 
2203  if (op->type == PLAYER) {
2204  /* we don't want overflows of wc (sint), so cap the value - mod and pl should be subtracted */
2205  int mod = bow->magic
2206  +arrow->magic
2207  +get_dex_bonus(op->stats.Dex)
2208  +get_thaco_bonus(op->stats.Str)
2209  +arrow->stats.wc
2210  +bow->stats.wc
2211  -wc_mod;
2212  int plmod = (op->chosen_skill ? op->chosen_skill->level : op->level);
2213  if (plmod+mod > 140)
2214  plmod = 140-mod;
2215  else if (plmod+mod < -100)
2216  plmod = -100-mod;
2217  arrow->stats.wc = 20-(int8_t)plmod-(int8_t)mod;
2218 
2219  arrow->level = op->chosen_skill ? op->chosen_skill->level : op->level;
2220  } else {
2221  arrow->stats.wc = op->stats.wc
2222  -bow->magic
2223  -arrow->magic
2224  -arrow->stats.wc
2225  +wc_mod;
2226 
2227  arrow->level = op->level;
2228  }
2229  if (arrow->attacktype == AT_PHYSICAL)
2230  arrow->attacktype |= bow->attacktype;
2231  if (bow->slaying != NULL)
2232  arrow->slaying = add_string(bow->slaying);
2233 
2234  /* If move_type is ever changed, monster.c:monster_use_bow() needs to be changed too. */
2235  arrow->move_type = MOVE_FLY_LOW;
2236  arrow->move_on = MOVE_FLY_LOW|MOVE_WALK;
2237 
2238  tag = arrow->count;
2239  object_insert_in_map_at(arrow, m, op, 0, sx, sy);
2240 
2241  if (!object_was_destroyed(arrow, tag)) {
2242  play_sound_map(SOUND_TYPE_ITEM, arrow, arrow->direction, "fire");
2243  ob_process(arrow);
2244  }
2245 
2246  return 1;
2247 }
2248 
2259 static int similar_direction(int a, int b) {
2260  /* shortcut the obvious */
2261  if (a == b)
2262  return 1;
2263  /* Made this cleaner using modulus instead of a switch statement
2264  * We only needed the direction and the two adjacent to it
2265  * (8 is adjacent to 1 here) to return true, so a - 1, a, and a + 1
2266  * are the three directions that get "similar" affirmed.
2267  * -- Daniel Hawkins 2015-05-28
2268  */
2269  // The last one for the offset is added afterwards so we get
2270  // 1-8 instead of 0-7 (specifically, 0 becomes 8 without changing
2271  // the other values).
2272  if ((a % 8) + 1 == b || (a + 6 % 8) + 1 == b)
2273  return 1;
2274  return 0;
2275 }
2276 
2293 static int player_fire_bow(object *op, int dir) {
2294  int ret = 0, wcmod = 0;
2295 
2296  if (op->contr->bowtype == bow_bestarrow) {
2297  ret = fire_bow(op, pick_arrow_target(op, op->contr->ranges[range_bow]->race, dir), dir, 0, op->x, op->y);
2298  } else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) {
2299  if (!similar_direction(dir, op->contr->bowtype-bow_n+1))
2300  wcmod = -1;
2301  ret = fire_bow(op, NULL, op->contr->bowtype-bow_n+1, wcmod, op->x, op->y);
2302  } else if (op->contr->bowtype == bow_threewide) {
2303  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2304  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir+2)], op->y+freearr_y[absdir(dir+2)]);
2305  ret |= fire_bow(op, NULL, dir, -5, op->x+freearr_x[absdir(dir-2)], op->y+freearr_y[absdir(dir-2)]);
2306  } else if (op->contr->bowtype == bow_spreadshot) {
2307  ret |= fire_bow(op, NULL, dir, 0, op->x, op->y);
2308  ret |= fire_bow(op, NULL, absdir(dir-1), -5, op->x, op->y);
2309  ret |= fire_bow(op, NULL, absdir(dir+1), -5, op->x, op->y);
2310  } else {
2311  /* Simple case */
2312  ret = fire_bow(op, NULL, dir, 0, op->x, op->y);
2313  }
2314  return ret;
2315 }
2316 
2329 static void fire_misc_object(object *op, int dir) {
2330  object *item;
2331  char name[MAX_BUF];
2332 
2333  item = op->contr->ranges[range_misc];
2334  if (!item) {
2336  "You have no range item readied.");
2337  return;
2338  }
2339  if (!item->inv) {
2340  LOG(llevError, "Object %s lacks a spell\n", item->name);
2341  return;
2342  }
2343  if (item->type == WAND) {
2344  if (item->stats.food <= 0) {
2345  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2348  "The %s goes poof.",
2349  name);
2350  return;
2351  }
2352  } else if (item->type == ROD) {
2353  if (item->stats.hp < SP_level_spellpoint_cost(item, item->inv, SPELL_HIGHEST)) {
2354  play_sound_player_only(op->contr, SOUND_TYPE_ITEM, item, 0, "poof");
2357  "The %s whines for a while, but nothing happens.",
2358  name);
2359  return;
2360  }
2361  }
2362 
2363  if (cast_spell(op, item, dir, item->inv, NULL)) {
2364  SET_FLAG(op, FLAG_BEEN_APPLIED); /* You now know something about it */
2365  if (item->type == WAND) {
2367  } else if (item->type == ROD) {
2369  }
2370  }
2371 }
2372 
2381 void fire(object *op, int dir) {
2382 
2383  /* check for loss of invisiblity/hide */
2384  if (action_makes_visible(op))
2385  make_visible(op);
2386 
2387  switch (op->contr->shoottype) {
2388  case range_none:
2389  return;
2390 
2391  case range_bow:
2392  player_fire_bow(op, dir);
2393  return;
2394 
2395  case range_magic: /* Casting spells */
2396  cast_spell(op, op, dir, op->contr->ranges[range_magic], op->contr->spellparam[0] ? op->contr->spellparam : NULL);
2397  return;
2398 
2399  case range_misc:
2400  fire_misc_object(op, dir);
2401  return;
2402 
2403  case range_golem: /* Control summoned monsters from scrolls */
2404  if (op->contr->ranges[range_golem] == NULL
2405  || op->contr->golem_count != op->contr->ranges[range_golem]->count) {
2406  op->contr->ranges[range_golem] = NULL;
2407  op->contr->shoottype = range_none;
2408  op->contr->golem_count = 0;
2409  } else
2410  pets_control_golem(op->contr->ranges[range_golem], dir);
2411  return;
2412 
2413  case range_skill:
2414  if (!op->chosen_skill) {
2415  if (op->type == PLAYER)
2417  "You have no applicable skill to use.");
2418  return;
2419  }
2420  (void)do_skill(op, op, op->chosen_skill, dir, NULL);
2421  return;
2422 
2423  case range_builder:
2424  apply_map_builder(op, dir);
2425  return;
2426 
2427  default:
2429  "Illegal shoot type.");
2430  return;
2431  }
2432 }
2433 
2453 object *find_key(object *pl, object *container, object *door) {
2454  object *tmp, *key;
2455 
2456  /* Should not happen, but sanity checking is never bad */
2457  if (container->inv == NULL)
2458  return NULL;
2459 
2460  /* First, lets try to find a key in the top level inventory */
2461  tmp = NULL;
2462  if (door->type == DOOR) {
2463  int flag = FLAG_UNPAID;
2464  tmp = object_find_by_type_without_flags(container, KEY, &flag, 1);
2465  }
2466  /* For sanity, we should really check door type, but other stuff
2467  * (like containers) can be locked with special keys
2468  */
2469  if (!tmp && door->slaying != NULL) {
2471  }
2472  /* No key found - lets search inventories now */
2473  /* If we find and use a key in an inventory, return at that time.
2474  * otherwise, if we search all the inventories and still don't find
2475  * a key, return
2476  */
2477  if (!tmp) {
2478  FOR_INV_PREPARE(container, tmp) {
2479  /* No reason to search empty containers */
2480  if (tmp->type == CONTAINER && tmp->inv) {
2481  key = find_key(pl, tmp, door);
2482  if (key != NULL)
2483  return key;
2484  }
2485  } FOR_INV_FINISH();
2486  return NULL;
2487  }
2488  /* We get down here if we have found a key. Now if its in a container,
2489  * see if we actually want to use it
2490  */
2491  if (pl != container) {
2492  /* Only let players use keys in containers */
2493  if (!pl->contr)
2494  return NULL;
2495  /* cases where this fails:
2496  * If we only search the player inventory, return now since we
2497  * are not in the players inventory.
2498  * If the container is not active, return now since only active
2499  * containers can be used.
2500  * If we only search keyrings and the container does not have
2501  * a race/isn't a keyring.
2502  * No checking for all containers - to fall through past here,
2503  * inv must have been an container and must have been active.
2504  *
2505  * Change the color so that the message doesn't disappear with
2506  * all the others.
2507  */
2508  if (pl->contr->usekeys == key_inventory
2509  || !QUERY_FLAG(container, FLAG_APPLIED)
2510  || (pl->contr->usekeys == keyrings && (!container->race || strcmp(container->race, "keys")))) {
2511  char name_tmp[MAX_BUF], name_cont[MAX_BUF];
2512 
2513  query_name(tmp, name_tmp, MAX_BUF);
2514  query_name(container, name_cont, MAX_BUF);
2517  "The %s in your %s vibrates as you approach the door",
2518  name_tmp, name_cont);
2519  return NULL;
2520  }
2521  }
2522  return tmp;
2523 }
2524 
2535 static int player_attack_door(object *op, object *door) {
2536  /* If its a door, try to find a use a key. If we do destroy the door,
2537  * might as well return immediately as there is nothing more to do -
2538  * otherwise, we fall through to the rest of the code.
2539  */
2540  object *key = find_key(op, op, door);
2541 
2542  assert(door->type == DOOR || door->type == LOCKED_DOOR);
2543 
2544  /* IF we found a key, do some extra work */
2545  if (key) {
2546  char name[HUGE_BUF];
2547 
2548  play_sound_map(SOUND_TYPE_GROUND, door, 0, "open");
2549  if (action_makes_visible(op))
2550  make_visible(op);
2551  if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP))
2552  spring_trap(door->inv, op);
2553 
2557  "You open the door with the %s",
2558  name);
2559 
2560  if (door->type == DOOR)
2561  remove_door(door);
2562  else
2563  remove_locked_door(door); /* remove door without violence ;-) */
2564 
2565  /* Do this after we print the message */
2566  object_decrease_nrof_by_one(key); /* Use up one of the keys */
2567 
2568  return 1; /* Nothing more to do below */
2569 
2570  }
2571 
2572  if (door->type == LOCKED_DOOR) {
2573  /* Might as well return now - no other way to open this */
2575  door->msg);
2576  return 1;
2577  }
2578 
2579  if (door->type == DOOR && op->contr && !op->contr->run_on) {
2580  /* Player so try to pick the door */
2581  object *lock = find_skill_by_name(op, "lockpicking");
2582  if (lock) {
2583  /* Even if the lockpicking failed, don't go on moving, player should explicitely attack or run
2584  * to bash the door. */
2585  do_skill(op, op, lock, op->facing, NULL);
2586  return 1;
2587  }
2588  }
2589 
2590  return 0;
2591 }
2592 
2606 void move_player_attack(object *op, int dir) {
2607  object *mon, *tpl, *mon_owner;
2608  int16_t nx, ny;
2609  int on_battleground;
2610  mapstruct *m;
2611 
2612  if (op->contr->transport)
2613  tpl = op->contr->transport;
2614  else
2615  tpl = op;
2616  assert(tpl->map != NULL); // op must be on a map in order to move it
2617  nx = freearr_x[dir]+tpl->x;
2618  ny = freearr_y[dir]+tpl->y;
2619 
2620  on_battleground = op_on_battleground(tpl, NULL, NULL, NULL);
2621 
2622  // Temporarily store the map we are on before movement.
2623  mapstruct *bef = tpl->map;
2624 
2625  /* If braced, or can't move to the square, and it is not out of the
2626  * map, attack it. Note order of if statement is important - don't
2627  * want to be calling move_ob if braced, because move_ob will move the
2628  * player. This is a pretty nasty hack, because if we could
2629  * move to some space, it then means that if we are braced, we should
2630  * do nothing at all. As it is, if we are braced, we go through
2631  * quite a bit of processing. However, it probably is less than what
2632  * move_ob uses.
2633  */
2634  if ((op->contr->braced || !move_ob(tpl, dir, tpl)) && !out_of_map(tpl->map, nx, ny)) {
2635  if (OUT_OF_REAL_MAP(tpl->map, nx, ny)) {
2636  m = get_map_from_coord(tpl->map, &nx, &ny);
2637  if (!m)
2638  return; /* Don't think this should happen */
2639  } else
2640  m = tpl->map;
2641 
2642  if (GET_MAP_OB(m, nx, ny) == NULL) {
2643  /* LOG(llevError, "player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n");*/
2644  return;
2645  }
2646 
2647  mon = NULL;
2648  /* Go through all the objects, and find ones of interest. Only stop if
2649  * we find a monster - that is something we know we want to attack.
2650  * if its a door or barrel (can roll) see if there may be monsters
2651  * on the space
2652  */
2653  FOR_MAP_PREPARE(m, nx, ny, tmp) {
2654  if (tmp == op) {
2655  continue;
2656  }
2657  if (QUERY_FLAG(tmp, FLAG_ALIVE)) {
2658  mon = tmp;
2659  /* Gros: Objects like (pass-through) doors are alive, but haven't
2660  * their monster flag set - so this is a good way attack real
2661  * monsters in priority.
2662  */
2663  if (QUERY_FLAG(tmp, FLAG_MONSTER))
2664  break;
2665  }
2666  if (tmp->type == LOCKED_DOOR || QUERY_FLAG(tmp, FLAG_CAN_ROLL))
2667  mon = tmp;
2668  } FOR_MAP_FINISH();
2669 
2670  if (mon == NULL) /* This happens anytime the player tries to move */
2671  return; /* into a wall */
2672 
2673  mon = HEAD(mon);
2674  if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR))
2675  if (player_attack_door(op, mon))
2676  return;
2677 
2678  /* The following deals with possibly attacking peaceful
2679  * or friendly creatures. Basically, all players are considered
2680  * unaggressive. If the moving player has peaceful set, then the
2681  * object should be pushed instead of attacked. It is assumed that
2682  * if you are braced, you will not attack friends accidently,
2683  * and thus will not push them.
2684  */
2685 
2686  /* If the creature is a pet, push it even if the player is not
2687  * peaceful. Our assumption is the creature is a pet if the
2688  * player owns it and it is either friendly or unaggressive.
2689  */
2690  mon_owner = object_get_owner(mon);
2691  if ((op->type == PLAYER)
2692  && (mon_owner == op || (mon_owner != NULL && mon_owner->type == PLAYER && mon_owner->contr->party != NULL && mon_owner->contr->party == op->contr->party))
2694  /* If we're braced, we don't want to switch places with it */
2695  if (op->contr->braced)
2696  return;
2697  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2698  (void)push_ob(mon, dir, op);
2699  if (op->contr->tmp_invis || op->hide)
2700  make_visible(op);
2701  return;
2702  }
2703 
2704  /* in certain circumstances, you shouldn't attack friendly
2705  * creatures. Note that if you are braced, you can't push
2706  * someone, but put it inside this loop so that you won't
2707  * attack them either.
2708  */
2709  if ((mon->type == PLAYER || mon->enemy != op)
2711  && (op->contr->peaceful && !on_battleground)) {
2712  if (!op->contr->braced) {
2713  play_sound_map(SOUND_TYPE_LIVING, mon, dir, "push");
2714  (void)push_ob(mon, dir, op);
2715  } else {
2717  "You withhold your attack");
2718  }
2719  if (op->contr->tmp_invis || op->hide)
2720  make_visible(op);
2721  }
2722 
2723  /* If the object is a boulder or other rollable object, then
2724  * roll it if not braced. You can't roll it if you are braced.
2725  */
2726  else if (QUERY_FLAG(mon, FLAG_CAN_ROLL) && (!op->contr->braced)) {
2727  recursive_roll(mon, dir, op);
2728  if (action_makes_visible(op))
2729  make_visible(op);
2730 
2731  /* Any generic living creature. Including things like doors.
2732  * Way it works is like this: First, it must have some hit points
2733  * and be living. Then, it must be one of the following:
2734  * 1) Not a player, 2) A player, but of a different party. Note
2735  * that party_number -1 is no party, so attacks can still happen.
2736  */
2737  } else if ((mon->stats.hp >= 0)
2739  && ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) {
2740  /* If the player hasn't hit something this tick, and does
2741  * so, give them speed boost based on weapon speed. Doing
2742  * it here is better than process_players2, which basically
2743  * incurred a 1 tick offset.
2744  */
2745  if (op->weapon_speed_left < 0) {
2746  op->speed_left = -0.01;
2747  return;
2748  }
2749  op->weapon_speed_left -= 1.0;
2750 
2751  skill_attack(mon, op, 0, NULL, NULL);
2752 
2753  /* If attacking another player, that player gets automatic
2754  * hitback, and doesn't loose luck either.
2755  * Disable hitback on the battleground or if the target is
2756  * the wiz.
2757  */
2758  if (mon->type == PLAYER
2759  && mon->stats.hp >= 0
2760  && !mon->contr->has_hit
2761  && !on_battleground
2762  && !QUERY_FLAG(mon, FLAG_WIZ)) {
2763  short luck = mon->stats.luck;
2764  mon->contr->has_hit = 1;
2765  skill_attack(op, mon, 0, NULL, NULL);
2766  mon->stats.luck = luck;
2767  }
2768  if (action_makes_visible(op))
2769  make_visible(op);
2770  }
2771  } /* if player should attack something */
2772  else if (bef != tpl->map) {
2773  player_map_change_common(op, bef, tpl->map);
2774  }
2775 }
2776 
2783 static void update_transport_block(object *transport, int dir) {
2784  object *part;
2785  int sx, sy, x, y;
2786 
2787  object_get_multi_size(transport, &sx, &sy, NULL, NULL);
2788  assert(sx == sy);
2789 
2790  if (dir == 1 || dir == 5) {
2791  part = transport;
2792  for (y = 0; y <= sy; y++) {
2793  for (x = 0; x < sx; x++) {
2794  part->move_type = transport->move_type;
2795  part = part->more;
2796  }
2797  part->move_type = 0;
2798  part = part->more;
2799  }
2800  } else if (dir == 3 || dir == 7) {
2801  part = transport;
2802  for (y = 0; y < sy; y++) {
2803  for (x = 0; x <= sx; x++) {
2804  part->move_type = transport->move_type;
2805  part = part->more;
2806  }
2807  }
2808  while (part) {
2809  part->move_type = 0;
2810  part = part->more;
2811  }
2812  } else {
2813  for (part = transport; part; part = part->more) {
2814  part->move_type = transport->move_type;
2815  }
2816  }
2817 }
2818 
2828 static int turn_one_transport(object *transport, object *captain, int dir) {
2829  int x, y, scroll_dir = 0;
2830 
2831  assert(transport->type == TRANSPORT);
2832 
2833  x = transport->x;
2834  y = transport->y;
2835 
2836  if (transport->direction == 1 && dir == 8) {
2837  x--;
2838  } else if (transport->direction == 2 && dir == 3) {
2839  y++;
2840  } else if (transport->direction == 3 && dir == 2) {
2841  y--;
2842  } else if (transport->direction == 5 && dir == 6) {
2843  x--;
2844  } else if (transport->direction == 6 && dir == 5) {
2845  x++;
2846  } else if (transport->direction == 7 && dir == 8) {
2847  y--;
2848  } else if (transport->direction == 8 && dir == 7) {
2849  y++;
2850  } else if (transport->direction == 8 && dir == 1) {
2851  x++;
2852  }
2853 
2854  update_transport_block(transport, dir);
2855  object_remove(transport);
2856  if (ob_blocked(transport, transport->map, x, y)) {
2857  update_transport_block(transport, transport->direction);
2858  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2859  return 2;
2860  }
2861 
2862  if (x != transport->x || y != transport->y) {
2863 /* assert(scroll_dir != 0);*/
2864 
2865  FOR_INV_PREPARE(transport, pl) {
2866  if (pl->type == PLAYER) {
2867  pl->contr->do_los = 1;
2868  pl->map = transport->map;
2869  pl->x = x;
2870  pl->y = y;
2871  esrv_map_scroll(&pl->contr->socket, freearr_x[scroll_dir], freearr_y[scroll_dir]);
2872  pl->contr->socket.update_look = 1;
2873  pl->contr->socket.look_position = 0;
2874  }
2875  } FOR_INV_FINISH();
2876  }
2877 
2878  object_insert_in_map_at(transport, transport->map, NULL, 0, x, y);
2879  transport->direction = dir;
2880  transport->facing = dir;
2881  animate_object(transport, dir);
2882  captain->direction = dir;
2883  return 1;
2884 }
2885 
2898 static int turn_transport(object *transport, object *captain, int dir) {
2899  assert(transport->type == TRANSPORT);
2900 
2901  if (object_value_set(transport, "turnable_transport") == false) {
2902  transport->direction = dir;
2903  transport->facing = dir;
2904  if (QUERY_FLAG(transport, FLAG_ANIMATE)) {
2905  animate_object(transport, dir);
2906  }
2907  captain->direction = dir;
2908  return 0;
2909  }
2910 
2911  if (transport->direction == dir)
2912  return 0;
2913 
2914  if (absdir(transport->direction-dir) > 2)
2915  return turn_one_transport(transport, captain, absdir(transport->direction+1));
2916  else
2917  return turn_one_transport(transport, captain, absdir(transport->direction-1));
2918 }
2919 
2931 int move_player(object *op, int dir) {
2932  object *transport = op->contr->transport; //< Transport player is in
2933 
2934  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
2935  return 0;
2936 
2937  /* Sanity check: make sure dir is valid */
2938  if ((dir < 0) || (dir >= 9)) {
2939  LOG(llevError, "move_player: invalid direction %d\n", dir);
2940  return 0;
2941  }
2942 
2943  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
2944  dir = get_randomized_dir(dir);
2945 
2946  op->facing = dir;
2947 
2948  if (transport) {
2949  /* transport->contr is set up for the person in charge of the boat.
2950  * if that isn't this person, he can't steer it, etc
2951  */
2952  if (transport->contr != op->contr)
2953  return 0;
2954 
2955  /* Transport is out of movement. But update dir so it at least
2956  * will point in the same direction if player is running.
2957  */
2958  if (transport->speed_left < 0.0) {
2959  return 0;
2960  }
2961  /* Remove transport speed. Give player just a little speed -
2962  * enough so that they will get an action again quickly.
2963  */
2964  transport->speed_left -= 1.0;
2965  if (op->speed_left < 0.0)
2966  op->speed_left = -0.01;
2967 
2968  int turn = turn_transport(transport, op, dir);
2969  if (turn != 0)
2970  return 0;
2971  } else {
2972  if (op->hide) {
2973  do_hidden_move(op);
2974  }
2975 
2976  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
2977  * and leave us with state = 0, which we don't want to change again. */
2978  op->state++; /* player moved, so change animation. */
2979  animate_object(op, op->facing);
2980  }
2981 
2982  if (op->contr->fire_on) {
2983  fire(op, dir);
2984  } else
2985  move_player_attack(op, dir);
2986 
2987  int pick = check_pick(op);
2988 
2989  /* Add special check for newcs players and fire on - this way, the
2990  * server can handle repeat firing.
2991  */
2992  if (op->contr->fire_on || (op->contr->run_on && pick != 0)) {
2993  op->direction = dir;
2994  } else {
2995  op->direction = 0;
2996  }
2997  return 0;
2998 }
2999 
3010 int face_player(object *op, int dir) {
3011  object *transport = op->contr->transport; //< Transport player is in
3012 
3013  if (!transport && (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY))
3014  return 0;
3015 
3016  /* Sanity check: make sure dir is valid */
3017  if ((dir < 0) || (dir >= 9)) {
3018  LOG(llevError, "move_player: invalid direction %d\n", dir);
3019  return 0;
3020  }
3021 
3022  if (QUERY_FLAG(op, FLAG_CONFUSED) && dir)
3023  dir = get_randomized_dir(dir);
3024 
3025  op->facing = dir;
3026 
3027  if (transport) {
3028  /* transport->contr is set up for the person in charge of the boat.
3029  * if that isn't this person, he can't steer it, etc
3030  */
3031  if (transport->contr != op->contr)
3032  return 0;
3033 
3034  turn_transport(transport, op, dir);
3035  } else {
3036  if (op->hide) {
3037  do_hidden_move(op);
3038  }
3039 
3040  /* it is important to change the animation now, as fire or move_player_attack can start a compound animation,
3041  * and leave us with state = 0, which we don't want to change again. */
3042  op->state++; /* player moved, so change animation. */
3043  animate_object(op, op->facing);
3044  }
3045 
3046  /* Add special check for newcs players and fire on - this way, the
3047  * server can handle repeat firing.
3048  */
3049  if (op->contr->fire_on || op->contr->run_on) {
3050  op->direction = dir;
3051  } else {
3052  op->direction = 0;
3053  }
3054  return 0;
3055 }
3056 
3069 int handle_newcs_player(object *op) {
3070  if (op->contr->hidden) {
3071  op->invisible = 1000;
3072  /* the socket code flashes the player visible/invisible
3073  * depending on the value if invisible, so we need to
3074  * alternate it here for it to work correctly.
3075  */
3076  if (pticks&2)
3077  op->invisible--;
3078  } else if (op->invisible && !(QUERY_FLAG(op, FLAG_MAKE_INVIS))) {
3079  op->invisible--;
3080  if (!op->invisible) {
3081  make_visible(op);
3083  "Your invisibility spell runs out.");
3084  }
3085  }
3086 
3087  if (QUERY_FLAG(op, FLAG_SCARED)) {
3088  flee_player(op);
3089  /* If player is still scared, that is his action for this tick */
3090  if (QUERY_FLAG(op, FLAG_SCARED)) {
3091  op->speed_left--;
3092  return 0;
3093  }
3094  }
3095 
3096  /* I've been seeing crashes where the golem has been destroyed, but
3097  * the player object still points to the defunct golem. The code that
3098  * destroys the golem looks correct, and it doesn't always happen, so
3099  * put this in a a workaround to clean up the golem pointer.
3100  */
3101  if (op->contr->ranges[range_golem]
3102  && ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG(op->contr->ranges[range_golem], FLAG_REMOVED))) {
3103  op->contr->ranges[range_golem] = NULL;
3104  op->contr->golem_count = 0;
3105  }
3106 
3107  /*
3108  * If the player has been paralyzed, we unmark the flag and give a message to the player
3109  */
3110  if (QUERY_FLAG(op, FLAG_PARALYZED)) {
3112  // TODO: Is this check necessary? We are in player.c, after all.
3113  if (op->type == PLAYER)
3114  {
3116  "You can stretch your stiff joints once more.");
3117  }
3118  }
3119 
3120  if (op->direction && (op->contr->run_on || op->contr->fire_on)) {
3121  /* All move commands take 1 tick, at least for now */
3122  op->speed_left--;
3123 
3124  /* Instead of all the stuff below, let move_player take care
3125  * of it. Also, some of the skill stuff is only put in
3126  * there, as well as the confusion stuff.
3127  */
3128  move_player(op, op->direction);
3129  if (op->speed_left > 0)
3130  return 1;
3131  else
3132  return 0;
3133  }
3134  return 0;
3135 }
3136 
3147 static int save_life(object *op) {
3148  object *tmp;
3149 
3150  if (!QUERY_FLAG(op, FLAG_LIFESAVE))
3151  return 0;
3152 
3154  if (tmp != NULL) {
3155  char name[MAX_BUF];
3156 
3158  play_sound_map(SOUND_TYPE_ITEM, tmp, 0, "evaporate");
3160  "Your %s vibrates violently, then evaporates.",
3161  name);
3162  object_remove(tmp);
3165  if (op->stats.hp < 0)
3166  op->stats.hp = op->stats.maxhp;
3167  if (op->stats.food < 0)
3168  op->stats.food = MAX_FOOD;
3169  fix_object(op);
3170  return 1;
3171  }
3172  LOG(llevError, "Error: LIFESAVE set without applied object.\n");
3174  enter_player_savebed(op); /* bring him home. */
3175  return 0;
3176 }
3177 
3190 void remove_unpaid_objects(object *op, object *env, int free_items) {
3192  if (QUERY_FLAG(op, FLAG_UNPAID)) {
3193  object_remove(op);
3194  if (free_items)
3196  else
3197  object_insert_in_map_at(op, env->map, NULL, 0, env->x, env->y);
3198  } else if (op->inv)
3199  remove_unpaid_objects(op->inv, env, free_items);
3201 }
3202 
3220 static const char *gravestone_text(object *op, char *buf2, int len) {
3221  char buf[MAX_BUF];
3222  time_t now = time(NULL);
3223 
3224  strncpy(buf2, " R.I.P.\n\n", len);
3225  if (op->type == PLAYER)
3226  snprintf(buf, sizeof(buf), "%s the %s\n", op->name, op->contr->title);
3227  else
3228  snprintf(buf, sizeof(buf), "%s\n", op->name);
3229  strncat(buf2, " ", 20-strlen(buf)/2);
3230  strncat(buf2, buf, len-strlen(buf2)-1);
3231  if (op->type == PLAYER)
3232  snprintf(buf, sizeof(buf), "who was in level %d when killed\n", op->level);
3233  else
3234  snprintf(buf, sizeof(buf), "who was in level %d when died.\n\n", op->level);
3235  strncat(buf2, " ", 20-strlen(buf)/2);
3236  strncat(buf2, buf, len-strlen(buf2)-1);
3237  if (op->type == PLAYER) {
3238  snprintf(buf, sizeof(buf), "by %s.\n\n", op->contr->killer);
3239  strncat(buf2, " ", 21-strlen(buf)/2);
3240  strncat(buf2, buf, len-strlen(buf2)-1);
3241  }
3242  strftime(buf, MAX_BUF, "%b %d %Y\n", localtime(&now));
3243  strncat(buf2, " ", 20-strlen(buf)/2);
3244  strncat(buf2, buf, len-strlen(buf2)-1);
3245  return buf2;
3246 }
3247 
3255 void do_some_living(object *op) {
3256  int last_food = op->stats.food;
3257  int gen_hp, gen_sp, gen_grace;
3258  int rate_hp = 1200;
3259  int rate_sp = 2500;
3260  int rate_grace = 2000;
3261 
3262  if (op->contr->state == ST_PLAYING) {
3263  /* these next three if clauses make it possible to SLOW DOWN
3264  hp/grace/spellpoint regeneration. */
3265  if (op->contr->gen_hp >= 0)
3266  gen_hp = (op->contr->gen_hp+1)*op->stats.maxhp;
3267  else {
3268  gen_hp = op->stats.maxhp;
3269  rate_hp -= rate_hp/2*op->contr->gen_hp;
3270  }
3271  if (op->contr->gen_sp >= 0)
3272  gen_sp = (op->contr->gen_sp+1)*op->stats.maxsp;
3273  else {
3274  gen_sp = op->stats.maxsp;
3275  rate_sp -= rate_sp/2*op->contr->gen_sp;
3276  }
3277  if (op->contr->gen_grace >= 0)
3278  gen_grace = (op->contr->gen_grace+1)*op->stats.maxgrace;
3279  else {
3280  gen_grace = op->stats.maxgrace;
3281  rate_grace -= rate_grace/2*op->contr->gen_grace;
3282  }
3283 
3284  /* Regenerate Spell Points */
3285  if (op->contr->ranges[range_golem] == NULL && --op->last_sp < 0) {
3286  gen_sp = gen_sp*10/MAX(op->contr->gen_sp_armour, 10);
3287  if (op->stats.sp < op->stats.maxsp) {
3288  op->stats.sp++;
3289  /* dms do not consume food */
3290  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3291  op->stats.food--;
3292  if (op->contr->digestion < 0)
3293  op->stats.food += op->contr->digestion;
3294  else if (op->contr->digestion > 0
3295  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3296  op->stats.food = last_food;
3297  }
3298  }
3299  op->last_sp = rate_sp/(MAX(gen_sp, 20)+10);
3300  }
3301 
3302  /* Regenerate Grace */
3303  /* I altered this a little - maximum grace is only achieved through prayer -b.t.*/
3304  if (--op->last_grace < 0) {
3305  if (op->stats.grace < op->stats.maxgrace/2)
3306  op->stats.grace++; /* no penalty in food for regaining grace */
3307  op->last_grace = rate_grace/(MAX(gen_grace, 20)+10);
3308  /* wearing stuff doesn't detract from grace generation. */
3309  }
3310 
3311  /* Regenerate Hit Points (unless you are a wraith player) */
3312  if (--op->last_heal < 0 && !is_wraith_pl(op)) {
3313  if (op->stats.hp < op->stats.maxhp) {
3314  op->stats.hp++;
3315  /* dms do not consume food */
3316  if (!QUERY_FLAG(op, FLAG_WIZ)) {
3317  op->stats.food--;
3318  if (op->contr->digestion < 0)
3319  op->stats.food += op->contr->digestion;
3320  else if (op->contr->digestion > 0
3321  && random_roll(0, op->contr->digestion, op, PREFER_HIGH))
3322  op->stats.food = last_food;
3323  }
3324  }
3325  op->last_heal = rate_hp/(MAX(gen_hp, 20)+10);
3326  }
3327 
3328  /* Digestion */
3329  if (--op->last_eat < 0) {
3330  int bonus = MAX(op->contr->digestion, 0);
3331  int penalty = MAX(-op->contr->digestion, 0);
3332  if (op->contr->gen_hp > 0)
3333  op->last_eat = 25*(1+bonus)/(op->contr->gen_hp+penalty+1);
3334  else
3335  op->last_eat = 25*(1+bonus)/(penalty+1);
3336  /* dms do not consume food */
3337  if (!QUERY_FLAG(op, FLAG_WIZ))
3338  op->stats.food--;
3339  }
3340  }
3341 
3342  if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) {
3343  if (is_wraith_pl(op))
3344  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "You feel a hunger for living flesh.");
3345  /* Only allow eat if not paralyzed. Otherwise our paralyzed player is "moving" to eat.
3346  * Daniel Hawkins 2017-08-23
3347  */
3348  else if (!QUERY_FLAG(op, FLAG_PARALYZED)){
3349  object *flesh = NULL;
3350 
3351  FOR_INV_PREPARE(op, tmp) {
3352  if (!QUERY_FLAG(tmp, FLAG_UNPAID)) {
3353  if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) {
3355  "You blindly grab for a bite of food.");
3356  apply_manual(op, tmp, 0);
3357  if (op->stats.food >= 0 || op->stats.hp < 0)
3358  break;
3359  } else if (tmp->type == FLESH)
3360  flesh = tmp;
3361  } /* End if paid for object */
3362  } FOR_INV_FINISH(); /* end of for loop */
3363  /* If player is still starving, it means they don't have any food, so
3364  * eat flesh instead.
3365  */
3366  if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) {
3368  "You blindly grab for a bite of food.");
3369  apply_manual(op, flesh, 0);
3370  }
3371  } /* end not wraith and not paralyzed */
3372  else { // Print a message for when the player is starving and paralyzed
3373  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, "Your stomach rumbles, but you can't reach your food.");
3374  } /* end not wraith and is paralyzed */
3375  } /* end if player is starving */
3376 
3377  if (op->stats.food < 0 && op->stats.hp > 0){
3378  // We know food < 0, so we want the absolute value of food
3379  int32_t adjust_by = MIN(-(op->stats.food), op->stats.hp);
3380  op->stats.food += adjust_by;
3381  op->stats.hp -= adjust_by;
3382  }
3383 
3384  if (!op->contr->state && !QUERY_FLAG(op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
3385  kill_player(op, NULL);
3386 }
3387 
3394 static void loot_object(object *op) {
3395  object *tmp2;
3396 
3397  if (op->container) { /* close open sack first */
3398  apply_container(op, op->container, AP_NULL);
3399  }
3400 
3401  FOR_INV_PREPARE(op, tmp) {
3402  if (tmp->invisible)
3403  continue;
3404  object_remove(tmp);
3405  tmp->x = op->x,
3406  tmp->y = op->y;
3407  if (tmp->type == CONTAINER) { /* empty container to ground */
3408  loot_object(tmp);
3409  }
3410  if (!QUERY_FLAG(tmp, FLAG_UNIQUE)
3412  if (tmp->nrof > 1) {
3413  tmp2 = object_split(tmp, 1+RANDOM()%(tmp->nrof-1), NULL, 0);
3415  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3416  } else
3418  } else
3419  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3420  } FOR_INV_FINISH();
3421 }
3422 
3433 static void restore_player(object *op) {
3434  object *tmp;
3435  archetype *at = find_archetype("poisoning");
3436  if (at != NULL) {
3437  tmp = arch_present_in_ob(at, op);
3438  if (tmp) {
3439  object_remove(tmp);
3442  "Your body feels cleansed");
3443  }
3444  }
3445 
3446  at = find_archetype("confusion");
3447  if (at != NULL) {
3448  tmp = arch_present_in_ob(at, op);
3449  if (tmp) {
3450  object_remove(tmp);
3453  "Your mind feels clearer");
3454  }
3455  }
3456 
3457  cure_disease(op, NULL, NULL); /* remove any disease */
3458 }
3459 
3471 void kill_player(object *op, const object *killer) {
3472  char buf[MAX_BUF];
3473  int x, y;
3474  object *tmp;
3475  archetype *trophy = NULL;
3476 
3477  /* Don't die if the player's life can be saved. */
3478  if (save_life(op)) {
3479  return;
3480  }
3481 
3482  /* If player dies on BATTLEGROUND, no stat/exp loss! For Combat-Arenas
3483  * in cities ONLY!!! It is very important that this doesn't get abused.
3484  * Look at op_on_battleground() for more info --AndreasV
3485  */
3486  if (op_on_battleground(op, &x, &y, &trophy)) {
3487  assert(trophy != NULL);
3489  "You have been defeated in combat!\n"
3490  "Local medics have saved your life...");
3491 
3492  /* restore player */
3493  restore_player(op);
3494 
3495  op->stats.hp = op->stats.maxhp;
3496  if (op->stats.food <= 0)
3497  op->stats.food = MAX_FOOD;
3498 
3499  /* create a bodypart-trophy to make the winner happy */
3500  tmp = arch_to_object(trophy);
3501  if (tmp != NULL) {
3502  snprintf(buf, sizeof(buf), "%s's %s", op->name, tmp->name);
3503  tmp->name = add_string(buf);
3504 
3505  snprintf(buf, sizeof(buf),
3506  "This %s was %s %s the %s, who was defeated at level %d by %s.\n",
3507  tmp->name, tmp->type == FLESH ? "cut off" : "taken from",
3508  op->name, op->contr->title,
3509  (int)(op->level), op->contr->killer);
3510 
3512  tmp->type = 0;
3513  tmp->value = 0;
3514  tmp->material = 0;
3515  tmp->materialname = NULL;
3516  object_insert_in_map_at(tmp, op->map, op, 0, op->x, op->y);
3517  }
3518 
3519  /* teleport defeated player to new destination*/
3520  transfer_ob(op, x, y, 0, NULL);
3521  op->contr->braced = 0;
3522  return;
3523  }
3524 
3525  if (events_execute_object_event(op, EVENT_DEATH, NULL, NULL, NULL, SCRIPT_FIX_ALL) != 0)
3526  return;
3527 
3529  if (op->stats.food < 0) {
3530  snprintf(buf, sizeof(buf), "%s starved to death.", op->name);
3531  strcpy(op->contr->killer, "starvation");
3532  } else {
3533  snprintf(buf, sizeof(buf), "%s died.", op->name);
3534  }
3535  play_sound_player_only(op->contr, SOUND_TYPE_LIVING, op, 0, "death");
3536 
3537  if (settings.not_permadeth == TRUE) {
3539  } else {
3541  }
3542 }
3543 
3552 static void kill_player_not_permadeath(object *op) {
3553  int num_stats_lose;
3554  int will_kill_again;
3555  int lost_a_stat;
3556  int z;
3557  object *tmp;
3558  char buf[MAX_BUF];
3559  archetype *at;
3560 
3561  /* Basically two ways to go - remove a stat permanently, or just
3562  * make it depletion. This bunch of code deals with that aspect
3563  * of death.
3564  */
3566  /* If stat loss is permanent, lose one stat only. */
3567  /* Lower level chars don't lose as many stats because they suffer
3568  more if they do. */
3569  /* Higher level characters can afford things such as potions of
3570  restoration, or better, stat potions. So we slug them that
3571  little bit harder. */
3572  /* GD */
3574  num_stats_lose = 1;
3575  else
3576  num_stats_lose = 1+op->level/BALSL_NUMBER_LOSSES_RATIO;
3577  } else {
3578  num_stats_lose = 1;
3579  }
3580  lost_a_stat = 0;
3581 
3582  for (z = 0; z < num_stats_lose; z++) {
3584  int i;
3585 
3586  /* Pick a random stat and take a point off it. Tell the player
3587  * what he lost.
3588  */
3589  i = RANDOM()%7;
3590  change_attr_value(&(op->stats), i, -1);
3592  change_attr_value(&(op->contr->orig_stats), i, -1);
3593  check_stat_bounds(&(op->contr->orig_stats), MIN_STAT, settings.max_stat);
3596  lose_msg[i]);
3597  lost_a_stat = 1;
3598  } else {
3599  /* deplete a stat */
3601  if (deparch == NULL) {
3602  continue;
3603  }
3604  object *dep;
3605  int lose_this_stat;
3606  int i;
3607 
3608  i = RANDOM()%7;
3609  dep = arch_present_in_ob(deparch, op);
3610  if (!dep) {
3611  dep = arch_to_object(deparch);
3612  object_insert_in_ob(dep, op);
3613  }
3614  lose_this_stat = 1;
3616  int this_stat;
3617 
3618  /* GD */
3619  /* Get the stat that we're about to deplete. */
3620  this_stat = get_attr_value(&(dep->stats), i);
3621  if (this_stat < 0) {
3622  int loss_chance = 1+op->level/BALSL_LOSS_CHANCE_RATIO;
3623  int keep_chance = this_stat*this_stat;
3624  /* Yes, I am paranoid. Sue me. */
3625  if (keep_chance < 1)
3626  keep_chance = 1;
3627 
3628  /* There is a maximum depletion total per level. */
3629  if (this_stat < -1-op->level/BALSL_MAX_LOSS_RATIO) {
3630  lose_this_stat = 0;
3631  /* Take loss chance vs keep chance to see if we
3632  retain the stat. */
3633  } else {
3634  if (random_roll(0, loss_chance+keep_chance-1, op, PREFER_LOW) < keep_chance)
3635  lose_this_stat = 0;
3636  /* 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"); */
3637  }
3638  }
3639  }
3640 
3641  if (lose_this_stat) {
3642  int this_stat;
3643 
3644  this_stat = get_attr_value(&(dep->stats), i);
3645  /* We could try to do something clever like find another
3646  * stat to reduce if this fails. But chances are, if
3647  * stats have been depleted to -50, all are pretty low
3648  * and should be roughly the same, so it shouldn't make a
3649  * difference.
3650  */
3651  if (this_stat >= -50) {
3652  change_attr_value(&(dep->stats), i, -1);
3653  SET_FLAG(dep, FLAG_APPLIED);
3655  drain_msg[i]);
3656  fix_object(op);
3657  lost_a_stat = 1;
3658  }
3659  }
3660  }
3661  }
3662  /* If no stat lost, tell the player. */
3663  if (!lost_a_stat) {
3664  /* determine_god() seems to not work sometimes... why is this? Should I be using something else? GD */
3665  const char *god = determine_god(op);
3666 
3667  if (god && (strcmp(god, "none")))
3670  "For a brief moment you feel the holy presence of %s protecting you",
3671  god);
3672  else
3675  "For a brief moment you feel a holy presence protecting you.");
3676  }
3677 
3678  /* Put a gravestone up where the character 'almost' died. List the
3679  * exp loss on the stone.
3680  */
3681  at = find_archetype("gravestone");
3682  if (at != NULL) {
3683  tmp = arch_to_object(at);
3684  snprintf(buf, sizeof(buf), "%s's gravestone", op->name);
3685  FREE_AND_COPY(tmp->name, buf);
3686  snprintf(buf, sizeof(buf), "%s's gravestones", op->name);
3687  FREE_AND_COPY(tmp->name_pl, buf);
3688  snprintf(buf, sizeof(buf), "RIP\nHere rests the hero %s the %s,\n"
3689  "who was killed\n"
3690  "by %s.\n",
3691  op->name, op->contr->title,
3692  op->contr->killer);
3694  object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y);
3695  }
3696 
3697  /* restore player: remove any poisoning, disease and confusion the
3698  * character may be suffering.*/
3699  restore_player(op);
3700 
3701  /* Subtract the experience points, if we died cause of food, give
3702  * us food, and reset HP's...
3703  */
3705  if (op->stats.food < 100)
3706  op->stats.food = 900;
3707  op->stats.hp = op->stats.maxhp;
3708  op->stats.sp = MAX(op->stats.sp, op->stats.maxsp);
3709  op->stats.grace = MAX(op->stats.grace, op->stats.maxgrace);
3710 
3711  /* Check to see if the player is in a shop. IF so, then check to see if
3712  * the player has any unpaid items. If so, remove them and put them back
3713  * in the map.
3714  *
3715  * If they are not in a shop, just free the unpaid items instead of
3716  * putting them back on map.
3717  */
3718  if (shop_contains(op))
3719  remove_unpaid_objects(op->inv, op, 0);
3720  else
3721  remove_unpaid_objects(op->inv, op, 1);
3722 
3723  /* Move player to his current respawn-position (usually last savebed) */
3725 
3726  /* Save the player before inserting the force to reduce chance of abuse. */
3727  op->contr->braced = 0;
3728  /* don't pick up in apartment */
3729  if (op->contr->mode & PU_NEWMODE) {
3730  op->contr->mode = op->contr->mode | PU_INHIBIT;
3731  esrv_send_pickup(op->contr);
3732  } else {
3733  op->contr->mode = 0;
3734  }
3735  if ( op->contr->search_str[0] ) command_search_items(op,NULL); /* turn off search-items */
3736  save_player(op, 1);
3737 
3738  /* it is possible that the player has blown something up
3739  * at his savebed location, and that can have long lasting
3740  * spell effects. So first see if there is a spell effect
3741  * on the space that might harm the player.
3742  */
3743  will_kill_again = 0;
3744  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp)
3745  if (tmp->type == SPELL_EFFECT)
3746  will_kill_again |= tmp->attacktype;
3747  FOR_MAP_FINISH();
3748  if (will_kill_again) {
3749  object *force;
3750  int at;
3751 
3753  /* 50 ticks should be enough time for the spell to abate */
3754  force->speed = 0.1;
3755  force->speed_left = -5.0;
3757  for (at = 0; at < NROFATTACKS; at++) {
3758  if (will_kill_again&(1<<at))
3759  force->resist[at] = 100;
3760  }
3762  fix_object(op);
3763  }
3764 
3765  /* Tell the player they have died */
3767  "YOU HAVE DIED.");
3768 }
3769 
3776 static void kill_player_permadeath(object *op) {
3777  char buf[MAX_BUF];
3778  char ac_buf[MAX_BUF];
3779  int x, y;
3780  mapstruct *map;
3781  object *tmp;
3782  archetype *at;
3783 
3784  /* save the map location for corpse, gravestone*/
3785  x = op->x;
3786  y = op->y;
3787  map = op->map;
3788 
3789  party_leave(op);
3790  if (settings.set_title == TRUE)
3791  player_set_own_title(op->contr, "");
3792 
3793  /* buf should be the kill message */
3795  buf);
3796  hiscore_check(op, 0);
3797  if (op->contr->ranges[range_golem] != NULL) {
3798  remove_friendly_object(op->contr->ranges[range_golem]);
3799  object_remove(op->contr->ranges[range_golem]);
3800  object_free_drop_inventory(op->contr->ranges[range_golem]);
3801  op->contr->ranges[range_golem] = NULL;
3802  op->contr->golem_count = 0;
3803  }
3804  loot_object(op); /* Remove some of the items for good */
3805  object_remove(op);
3806  op->direction = 0;
3807 
3808  if (!QUERY_FLAG(op, FLAG_WAS_WIZ) && op->stats.exp) {
3809  if (settings.resurrection == TRUE) {
3810  /* save playerfile sans equipment when player dies
3811  * -then save it as player.pl.dead so that future resurrection
3812  * -type spells will work on them nicely
3813  */
3814  op->stats.hp = op->stats.maxhp;
3815  op->stats.food = MAX_FOOD;
3816 
3817  /* set the location of where the person will reappear when */
3818  /* maybe resurrection code should fix map also */
3819  safe_strncpy(op->contr->maplevel, settings.emergency_mapname,
3820  sizeof(op->contr->maplevel));
3821  if (op->map != NULL)
3822  op->map = NULL;
3823  op->x = settings.emergency_x;
3824  op->y = settings.emergency_y;
3825  save_player(op, 0);
3826  op->map = map;
3827  /* please see resurrection.c: peterm */
3828  dead_player(op);
3829  } else {
3830  delete_character(op->name);
3831  }
3832  }
3833  play_again(op);
3834 
3835  /* peterm: added to create a corpse at deathsite. */
3836  at = find_archetype("corpse_pl");
3837  if (at != NULL) {
3838  tmp = arch_to_object(at);
3839  snprintf(buf, sizeof(buf), "%s", op->name);
3840  FREE_AND_COPY(tmp->name, buf);
3841  FREE_AND_COPY(tmp->name_pl, buf);
3842  tmp->level = op->level;
3843  object_set_msg(tmp, gravestone_text(op, buf, sizeof(buf)));
3845  /*
3846  * Put the account name under slaying.
3847  * Does not seem to cause weird effects, but more testing may ensure this.
3848  */
3849  snprintf(ac_buf, sizeof(ac_buf), "%s", op->contr->socket.account_name);
3850  FREE_AND_COPY(tmp->slaying, ac_buf);
3851  object_insert_in_map_at(tmp, map, NULL, 0, x, y);
3852  }
3853 }
3854 
3862 void fix_weight(void) {
3863  player *pl;
3864 
3865  for (pl = first_player; pl != NULL; pl = pl->next) {
3866  int old = pl->ob->carrying, sum = object_sum_weight(pl->ob);
3867 
3868  if (old == sum)
3869  continue;
3870  fix_object(pl->ob);
3871  LOG(llevDebug, "Fixed inventory in %s (%d -> %d)\n", pl->ob->name, old, sum);
3872  }
3873 }
3874 
3878 void fix_luck(void) {
3879  player *pl;
3880 
3881  for (pl = first_player; pl != NULL; pl = pl->next)
3882  if (!pl->ob->contr->state)
3883  change_luck(pl->ob, 0);
3884 }
3885 
3886 
3899 void cast_dust(object *op, object *throw_ob, int dir) {
3900  object *skop, *spob;
3901 
3902  skop = find_skill_by_name(op, throw_ob->skill);
3903 
3904  /* casting POTION 'dusts' is really a use_magic_item skill */
3905  if (op->type == PLAYER && throw_ob->type == POTION && !skop) {
3906  LOG(llevError, "Player %s lacks critical skill use_magic_item!\n", op->name);
3907  return;
3908  }
3909  spob = throw_ob->inv;
3910  if (op->type == PLAYER && spob)
3912  "You cast %s.",
3913  spob->name);
3914 
3915  cast_spell(op, throw_ob, dir, spob, NULL);
3916 
3917  if (!QUERY_FLAG(throw_ob, FLAG_REMOVED))
3918  object_remove(throw_ob);
3919  object_free_drop_inventory(throw_ob);
3920 }
3921 
3928 void make_visible(object *op) {
3929  op->hide = 0;
3930  op->invisible = 0;
3931  if (op->type == PLAYER) {
3932  op->contr->tmp_invis = 0;
3933  if (op->contr->invis_race)
3934  FREE_AND_CLEAR_STR(op->contr->invis_race);
3935  }
3937 }
3938 
3948 int is_true_undead(object *op) {
3949  if (QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
3950  return 1;
3951 
3952  if (op->type == PLAYER) {
3953  FOR_INV_PREPARE(op, tmp) {
3954  if (tmp->type == 44 && tmp->stats.Wis)
3955  if (QUERY_FLAG(tmp, FLAG_UNDEAD))
3956  return 1;
3957  } FOR_INV_FINISH();
3958  }
3959  return 0;
3960 }
3961 
3972 int hideability(object *ob) {
3973  int i, level = 0, mflag;
3974  int16_t x, y;
3975 
3976  if (!ob || !ob->map)
3977  return 0;
3978 
3979  /* so, on normal lighted maps, its hard to hide */
3980  level = ob->map->darkness-2;
3981 
3982  /* this also picks up whether the object is glowing.
3983  * If you carry a light on a non-dark map, its not
3984  * as bad as carrying a light on a pitch dark map
3985  */
3986  if (has_carried_lights(ob))
3987  level = -(10+(2*ob->map->darkness));
3988 
3989  /* scan through all nearby squares for terrain to hide in */
3990  for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x+freearr_x[i], y = ob->y+freearr_y[i]) {
3991  mflag = get_map_flags(ob->map, NULL, x, y, NULL, NULL);
3992  if (mflag&P_OUT_OF_MAP) {
3993  continue;
3994  }
3995  if (mflag&P_BLOCKSVIEW) /* something to hide near! */
3996  level += 2;
3997  else /* open terrain! */
3998  level -= 1;
3999  }
4000 
4001  return level;
4002 }
4003 
4013 void do_hidden_move(object *op) {
4014  int hide = 0, num = random_roll(0, 19, op, PREFER_LOW);
4015  object *skop;
4016 
4017  if (!op || !op->map)
4018  return;
4019 
4021 
4022  /* its *extremely *hard to run and sneak/hide at the same time! */
4023  if (op->type == PLAYER && op->contr->run_on) {
4024  if (!skop || num >= skop->level) {
4026  "You ran too much! You are no longer hidden!");
4027  make_visible(op);
4028  return;
4029  } else
4030  num += 20;
4031  }
4032  num += op->map->difficulty;
4033  hide = hideability(op); /* modify by terrain hidden level */
4034  num -= hide;
4035  if ((op->type == PLAYER && hide < -10)
4036  || ((op->invisible -= num) <= 0)) {
4037  make_visible(op);
4038  if (op->type == PLAYER)
4040  "You moved out of hiding! You are visible!");
4041  } else if (op->type == PLAYER && skop) {
4042  change_exp(op, calc_skill_exp(op, NULL, skop), skop->skill, 0);
4043  }
4044 }
4045 
4054 int stand_near_hostile(object *who) {
4055  int i, friendly = 0, player = 0, mflags;
4056  mapstruct *m;
4057  int16_t x, y;
4058 
4059  if (!who)
4060  return 0;
4061 
4062  if (who->type == PLAYER)
4063  player = 1;
4064  else
4065  friendly = QUERY_FLAG(who, FLAG_FRIENDLY);
4066 
4067  /* search adjacent squares */
4068  for (i = 1; i < 9; i++) {
4069  x = who->x+freearr_x[i];
4070  y = who->y+freearr_y[i];
4071  m = who->map;
4072  mflags = get_map_flags(m, &m, x, y, &x, &y);
4073  /* space must be blocked if there is a monster. If not
4074  * blocked, don't need to check this space.
4075  */
4076  if (mflags&P_OUT_OF_MAP)
4077  continue;
4079  continue;
4080 
4081  FOR_MAP_PREPARE(m, x, y, tmp) {
4082  if ((player || friendly)
4085  return 1;
4086  else if (tmp->type == PLAYER) {
4087  /*don't let a hidden DM prevent you from hiding*/
4088  if (!QUERY_FLAG(tmp, FLAG_WIZ) || tmp->contr->hidden == 0)
4089  return 1;
4090  }
4091  } FOR_MAP_FINISH();
4092  }
4093  return 0;
4094 }
4095 
4122 int player_can_view(object *pl, object *op) {
4123  rv_vector rv;
4124  int dx, dy;
4125 
4126  if (!pl || !op)
4127  return 0;
4128 
4129  if (pl->type != PLAYER) {
4130  LOG(llevError, "player_can_view() called for non-player object\n");
4131  return -1;
4132  }
4133 
4134  op = HEAD(op);
4135  if (!get_rangevector(pl, op, &rv, 0x1))
4136  return 0;
4137 
4138  /* starting with the 'head' part, lets loop
4139  * through the object and find if it has any
4140  * part that is in the los array but isnt on
4141  * a blocked los square.
4142  * we use the archetype to figure out offsets.
4143  */
4144  while (op) {
4145  dx = rv.distance_x+op->arch->clone.x;
4146  dy = rv.distance_y+op->arch->clone.y;
4147 
4148  /* only the viewable area the player sees is updated by LOS
4149  * code, so we need to restrict ourselves to that range of values
4150  * for any meaningful values.
4151  */
4152  if (FABS(dx) <= (pl->contr->socket.mapx/2)
4153  && FABS(dy) <= (pl->contr->socket.mapy/2)
4154  && !pl->contr->blocked_los[dx+(pl->contr->socket.mapx/2)][dy+(pl->contr->socket.mapy/2)])
4155  return 1;
4156  op = op->more;
4157  }
4158  return 0;
4159 }
4160 
4174 static int action_makes_visible(object *op) {
4175  if (op->invisible && QUERY_FLAG(op, FLAG_ALIVE)) {
4177  return 0;
4178 
4179  if (op->contr && op->contr->tmp_invis == 0)
4180  return 0;
4181 
4182  /* If monsters, they should become visible */
4183  if (op->hide || !op->contr || (op->contr && op->contr->tmp_invis)) {
4185  "You become %s!",
4186  op->hide ? "unhidden" : "visible");
4187  return 1;
4188  }
4189  }
4190  return 0;
4191 }
4192 
4221 int op_on_battleground(object *op, int *x, int *y, archetype **trophy) {
4223  if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
4225  && strcmp(tmp->name, "battleground") == 0
4226  && tmp->type == BATTLEGROUND
4227  && EXIT_X(tmp)
4228  && EXIT_Y(tmp)) {
4229  /*before we assign the exit, check if this is a teambattle*/
4230  if (EXIT_ALT_X(tmp) && EXIT_ALT_Y(tmp) && EXIT_PATH(tmp)) {
4231  object *invtmp;
4232 
4234  if (invtmp != NULL) {
4235  if (x != NULL && y != NULL)
4236  *x = EXIT_ALT_X(tmp),
4237  *y = EXIT_ALT_Y(tmp);
4238  return 1;
4239  }
4240  }
4241  if (x != NULL && y != NULL)
4242  *x = EXIT_X(tmp),
4243  *y = EXIT_Y(tmp);
4244 
4245  /* If 'other_arch' is not specified, give a finger. */
4246  if (trophy != NULL) {
4247  if (tmp->other_arch) {
4248  *trophy = tmp->other_arch;
4249  } else {
4250  *trophy = find_archetype("finger");
4251  }
4252  }
4253  return 1;
4254  }
4255  }
4256  } FOR_BELOW_FINISH();
4257  /* If we got here, did not find a battleground */
4258  return 0;
4259 }
4260 
4271 void dragon_ability_gain(object *who, int atnr, int level) {
4272  treasurelist *trlist = NULL; /* treasurelist */
4273  treasure *tr; /* treasure */
4274  object *tmp, *skop; /* tmp. object */
4275  object *item; /* treasure object */
4276  char buf[MAX_BUF]; /* tmp. string buffer */
4277  int i = 0, j = 0;
4278 
4279  /* get the appropriate treasurelist */
4280  if (atnr == ATNR_FIRE)
4281  trlist = find_treasurelist("dragon_ability_fire");
4282  else if (atnr == ATNR_COLD)
4283  trlist = find_treasurelist("dragon_ability_cold");
4284  else if (atnr == ATNR_ELECTRICITY)
4285  trlist = find_treasurelist("dragon_ability_elec");
4286  else if (atnr == ATNR_POISON)
4287  trlist = find_treasurelist("dragon_ability_poison");
4288 
4289  if (trlist == NULL || who->type != PLAYER)
4290  return;
4291 
4292  // tr->magic is being used to define what level of the metabolism the ability is gained at.
4293  for (tr = trlist->items; tr != NULL && tr->magic != level; tr = tr->next)
4294  ;
4295  if (tr == NULL || tr->item == NULL) {
4296  /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */
4297  return;
4298  }
4299 
4300  /* everything seems okay - now bring on the gift: */
4301  item = &(tr->item->clone);
4302 
4303  if (item->type == SPELL) {
4304  if (check_spell_known(who, item->name))
4305  return;
4306 
4309  "You gained the ability of %s",
4310  item->name);
4311  do_learn_spell(who, item, 0);
4312  return;
4313  }
4314 
4315  /* grant direct spell */
4316  if (item->type == SPELLBOOK) {
4317  if (!item->inv) {
4318  LOG(llevDebug, "dragon_ability_gain: Broken spellbook %s\n", item->name);
4319  return;
4320  }
4321  if (check_spell_known(who, item->inv->name))
4322  return;
4323  if (item->invisible) {
4326  "You gained the ability of %s",
4327  item->inv->name);
4328  do_learn_spell(who, item->inv, 0);
4329  return;
4330  }
4331  } else if (item->type == SKILL_TOOL && item->invisible) {
4332  if (item->subtype == SK_CLAWING && (skop = find_skill_by_name(who, item->skill)) != NULL) {
4333  /* should this perhaps be (skop->attackyp&item->attacktype) != item->attacktype ...
4334  * in this way, if the player is missing any of the attacktypes, he gets
4335  * them. As it is now, if the player has any that match the granted skill,
4336  * but not all of them, he gets nothing.
4337  */
4338  if (!(skop->attacktype&item->attacktype)) {
4339  /* Give new attacktype */
4340  skop->attacktype |= item->attacktype;
4341 
4342  /* always add physical if there's none */
4343  skop->attacktype |= AT_PHYSICAL;
4344 
4345  if (item->msg != NULL)
4348  item->msg);
4349 
4350  /* Give player new face */
4351  if (item->animation) {
4352  who->face = skop->face;
4353  who->animation = item->animation;
4354  who->anim_speed = item->anim_speed;
4355  who->last_anim = 0;
4356  who->state = 0;
4357  animate_object(who, who->direction);
4358  }
4359  }
4360  }
4361  } else if (item->type == FORCE) {
4362  /* forces in the treasurelist can alter the player's stats */
4363  object *skin;
4364 
4365  /* first get the dragon skin force */
4366  skin = object_find_by_arch_name(who, "dragon_skin_force");
4367  if (skin == NULL)
4368  return;
4369 
4370  /* adding new spellpath attunements */
4371  if (item->path_attuned > 0 && !(skin->path_attuned&item->path_attuned)) {
4372  skin->path_attuned |= item->path_attuned; /* add attunement to skin */
4373 
4374  /* print message */
4375  snprintf(buf, sizeof(buf), "You feel attuned to ");
4376  for (i = 0, j = 0; i < NRSPELLPATHS; i++) {
4377  if (item->path_attuned&(1<<i)) {
4378  if (j)
4379  strcat(buf, " and ");
4380  else
4381  j = 1;
4382  strcat(buf, spellpathnames[i]);
4383  }
4384  }
4385  strcat(buf, ".");
4388  buf);
4389  }
4390 
4391  /* evtl. adding flags: */
4392  if (QUERY_FLAG(item, FLAG_XRAYS))
4393  SET_FLAG(skin, FLAG_XRAYS);
4395  SET_FLAG(skin, FLAG_STEALTH);
4397  SET_FLAG(skin, FLAG_SEE_IN_DARK);
4398 
4399  /* print message if there is one */
4400  if (item->msg != NULL)
4403  item->msg);
4404  } else {
4405  /* generate misc. treasure */
4406  char name[HUGE_BUF];
4407 
4408  tmp = arch_to_object(tr->item);
4412  "You gained %s",
4413  name);
4415  if (who->type == PLAYER)
4417  }
4418 }
4419 
4430  rangetype i;
4431 
4432  for (i = 0; i < range_size; i++) {
4433  if (pl->ranges[i] == ob) {
4434  pl->ranges[i] = NULL;
4435  if (pl->shoottype == i) {
4436  pl->shoottype = range_none;
4437  }
4438  }
4439  }
4440 }
4441 
4447 void player_set_state(player *pl, uint8_t state) {
4448 
4449  assert(pl);
4450  assert(state <= ST_CHANGE_PASSWORD_CONFIRM);
4451  pl->state = state;
4452 }
4453 
4461  SockList *sl;
4462  assert(pl);
4466  if (!pl->delayed_buffers) {
4467  LOG(llevError, "Unable to allocated %d delayed buffers, aborting\n", pl->delayed_buffers_allocated);
4469  }
4470  for (uint8_t s = pl->delayed_buffers_allocated - 5; s < pl->delayed_buffers_allocated; s++) {
4471  pl->delayed_buffers[s] = calloc(1, sizeof(SockList));
4472  }
4473  }
4476  SockList_Init(sl);
4477  return sl;
4478 }
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:246
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:4054
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:1668
UP_OBJ_FACE
#define UP_OBJ_FACE
Definition: object.h:520
pl::delayed_buffers
SockList ** delayed_buffers
Definition: player.h:225
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:956
do_hidden_move
void do_hidden_move(object *op)
Definition: player.c:4013
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:52
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:1578
fix_weight
void fix_weight(void)
Definition: player.c:3862
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:4200
object_remove
void object_remove(object *op)
Definition: object.c:1819
safe_strncpy
#define safe_strncpy
Definition: compat.h:27
FOR_MAP_FINISH
#define FOR_MAP_FINISH()
Definition: define.h:730
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:572
get_player
player * get_player(player *p)
Definition: player.c:282
kill_player
void kill_player(object *op, const object *killer)
Definition: player.c:3471
object_set_enemy
void object_set_enemy(object *op, object *enemy)
Definition: object.c:919
obj::face
const Face * face
Definition: object.h:336
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:297
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:31
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:2259
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:2569
roll_again
void roll_again(object *op)
Definition: player.c:1136
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:263
recursive_roll
void recursive_roll(object *op, int dir, object *pusher)
Definition: move.c:293
socket_struct::look_position
uint16_t look_position
Definition: newserver.h:114
object_update
void object_update(object *op, int action)
Definition: object.c:1420
diamondslots.x
x
Definition: diamondslots.py:15
FLAG_STARTEQUIP
#define FLAG_STARTEQUIP
Definition: define.h:268
obj::count
tag_t count
Definition: object.h:302
obj::map
struct mapdef * map
Definition: object.h:300
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:321
get_next_archetype
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:278
Settings::set_title
uint8_t set_title
Definition: global.h:262
remove_locked_door
void remove_locked_door(object *op)
Definition: time.c:64
pl::peaceful
uint32_t peaceful
Definition: player.h:146
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:618
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:4460
out_of_map
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2312
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:259
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:1255
esrv_send_inventory
void esrv_send_inventory(object *pl, object *op)
Definition: item.c:315
key_roll_stat
void key_roll_stat(object *op, char key)
Definition: player.c:1208
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:4223
get_player_archetype
static archetype * get_player_archetype(archetype *at)
Definition: player.c:506
obj::path_attuned
uint32_t path_attuned
Definition: object.h:348
SockList_AddString
void SockList_AddString(SockList *sl, const char *data)
Definition: lowlevel.c:154
pl::socket
socket_struct socket
Definition: player.h:107
FOR_BELOW_PREPARE
#define FOR_BELOW_PREPARE(op_, it_)
Definition: define.h:704
GEM
@ GEM
Definition: object.h:167
FLAG_UNIQUE
#define FLAG_UNIQUE
Definition: define.h:287
pl::shoottype
rangetype shoottype
Definition: player.h:112
pl
Definition: player.h:105
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:177
fire
void fire(object *op, int dir)
Definition: player.c:2381
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:3193
pl::swap_first
int swap_first
Definition: player.h:165
object_matches_string
int object_matches_string(object *pl, object *op, const char *name)
Definition: object.c:4545
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:30
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:161
CHARISMA
@ CHARISMA
Definition: living.h:15
party_rejoin_if_exists
@ party_rejoin_if_exists
Definition: player.h:100
set_first_map
void set_first_map(object *op)
Definition: player.c:401
blocked_link
int blocked_link(object *ob, mapstruct *m, int16_t sx, int16_t sy)
Definition: map.c:345
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:176
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:43
SKILL
@ SKILL
Definition: object.h:143
pl::delayed_buffers_used
uint8_t delayed_buffers_used
Definition: player.h:224
play_sound_map
void play_sound_map(int8_t sound_type, object *emitter, int dir, const char *action)
Definition: sounds.c:113
object_can_merge
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:433
RUNE
@ RUNE
Definition: object.h:240
pl::bowtype
bowtype_t bowtype
Definition: player.h:114
FLAG_SCARED
#define FLAG_SCARED
Definition: define.h:271
Settings::roll_stat_points
uint8_t roll_stat_points
Definition: global.h:320
ob_blocked
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:488
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:261
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:1474
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:297
action_makes_visible
static int action_makes_visible(object *op)
Definition: player.c:4174
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:325
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:1062
get_rangevector
int get_rangevector(object *op1, const object *op2, rv_vector *retval, int flags)
Definition: map.c:2545
move_player
int move_player(object *op, int dir)
Definition: player.c:2931
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:173
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:1038
esrv_add_spells
void esrv_add_spells(player *pl, object *spell)
Definition: request.c:1854
range_golem
@ range_golem
Definition: player.h:34
pl::last_weapon_sp
float last_weapon_sp
Definition: player.h:156
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:241
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:3010
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:274
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:172
Moving_Fog.z
z
Definition: Moving_Fog.py:17
hiscore_check
void hiscore_check(object *op, int quiet)
Definition: hiscore.c:346
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:4447
freearr_x
short freearr_x[SIZEOFFREE]
Definition: object.c:299
AT_DEATH
#define AT_DEATH
Definition: attack.h:93
obj::nrof
uint32_t nrof
Definition: object.h:337
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
freearr_y
short freearr_y[SIZEOFFREE]
Definition: object.c:305
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:711
MIN_STAT
#define MIN_STAT
Definition: define.h:33
archt
Definition: object.h:470
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:1424
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:36
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:383
MSG_TYPE_COMMAND_DEBUG
#define MSG_TYPE_COMMAND_DEBUG
Definition: newclient.h:528
obj::slaying
sstring slaying
Definition: object.h:322
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:427
liv::luck
int8_t luck
Definition: living.h:39
handle_newcs_player
int handle_newcs_player(object *op)
Definition: player.c:3069
rv_vector::distance_x
int distance_x
Definition: map.h:382
socket_struct::account_chars
Account_Chars * account_chars
Definition: newserver.h:127
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:110
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:4272
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:3975
pl::next
struct pl * next
Definition: player.h:106
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:3190
save_life
static int save_life(object *op)
Definition: player.c:3147
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:258
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:4129
oblnk::next
struct oblnk * next
Definition: object.h:449
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:3928
bow_n
@ bow_n
Definition: player.h:45
obj::name
sstring name
Definition: object.h:314
strip_endline
void strip_endline(char *buf)
Definition: utils.c:324
cast_dust
void cast_dust(object *op, object *throw_ob, int dir)
Definition: player.c:3899
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:131
move_player_attack
void move_player_attack(object *op, int dir)
Definition: player.c:2606
is_identifiable_type
int is_identifiable_type(const object *op)
Definition: item.c:1312
bow_bestarrow
@ bow_bestarrow
Definition: player.h:53
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:1064
range_size
@ range_size
Definition: player.h:37
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:4122
query_name
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:585
confirm_password
void confirm_password(object *op)
Definition: player.c:1006
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:220
POTION
@ POTION
Definition: object.h:111
object_update_turn_face
void object_update_turn_face(object *op)
Definition: object.c:1313
pet_normal
@ pet_normal
Definition: player.h:58
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:245
calc_skill_exp
int64_t calc_skill_exp(const object *who, const object *op, const object *skill)
Definition: skill_util.c:658
account_char_free
void account_char_free(Account_Chars *chars)
Definition: account_char.c:362
get_randomized_dir
int get_randomized_dir(int dir)
Definition: utils.c:422
pl::petmode
petmode_t petmode
Definition: player.h:115
key_confirm_quit
void key_confirm_quit(object *op, char key)
Definition: player.c:1587
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:754
HEAD
#define HEAD(op)
Definition: object.h:594
fatal
void fatal(enum fatal_error err)
Definition: utils.c:580
range_magic
@ range_magic
Definition: player.h:32
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:3838
player_unready_range_ob
void player_unready_range_ob(player *pl, object *ob)
Definition: player.c:4429
CONTAINER
@ CONTAINER
Definition: object.h:231
enter_player_maplevel
void enter_player_maplevel(object *op)
Definition: server.c:687
swap_stat
static void swap_stat(object *op, int swap_second)
Definition: player.c:1150
obj::speed_left
float speed_left
Definition: object.h:333
loot_object
static void loot_object(object *op)
Definition: player.c:3394
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:275
LOCKED_DOOR
@ LOCKED_DOOR
Definition: object.h:123
MSG_TYPE_ITEM
#define MSG_TYPE_ITEM
Definition: newclient.h:412
socket_struct::host
char * host
Definition: newserver.h:100
SCRIPT_FIX_ALL
#define SCRIPT_FIX_ALL
Definition: global.h:379
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:510
FLAG_MAKE_INVIS
#define FLAG_MAKE_INVIS
Definition: define.h:328
Settings::rules
const char * rules
Definition: global.h:276
SPECIAL_KEY
@ SPECIAL_KEY
Definition: object.h:124
absdir
int absdir(int d)
Definition: object.c:3685
MOVE_FLYING
#define MOVE_FLYING
Definition: define.h:395
obj::spellarg
char * spellarg
Definition: object.h:415
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:372
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:203
Settings::news
const char * news
Definition: global.h:277
Ice.b
b
Definition: Ice.py:48
get_party_password
int get_party_password(object *op, partylist *party)
Definition: player.c:1021
pl::no_shout
uint32_t no_shout
Definition: player.h:148
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:330
DETOUR_AMOUNT
#define DETOUR_AMOUNT
Definition: player.c:603
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:253
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:1284
update_transport_block
static void update_transport_block(object *transport, int dir)
Definition: player.c:2783
leave
void leave(player *pl, int draw_exit)
Definition: server.c:1302
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:677
FLAG_CAN_ROLL
#define FLAG_CAN_ROLL
Definition: define.h:254
pl::has_hit
uint32_t has_hit
Definition: player.h:144
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:1917
FLAG_UNAGGRESSIVE
#define FLAG_UNAGGRESSIVE
Definition: define.h:272
obj::speed
float speed
Definition: object.h:332
say.max
dictionary max
Definition: say.py:148
rangetype
rangetype
Definition: player.h:28
is_criminal
bool is_criminal(object *op)
Definition: player.c:315
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:4221
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:1949
Settings::confdir
const char * confdir
Definition: global.h:244
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:881
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:3552
FIND_PLAYER_PARTIAL_NAME
#define FIND_PLAYER_PARTIAL_NAME
Definition: player.h:234
AC_PLAYER_STAT_NO_CHANGE
#define AC_PLAYER_STAT_NO_CHANGE
Definition: define.h:597
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:387
FOR_OB_AND_BELOW_PREPARE
#define FOR_OB_AND_BELOW_PREPARE(op_)
Definition: define.h:750
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:1722
DEXTERITY
@ DEXTERITY
Definition: living.h:12
pl::unapply
unapplymode unapply
Definition: player.h:121
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:2293
set_player_socket
static void set_player_socket(player *p, socket_struct *ns)
Definition: player.c:420
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:434
key_inventory
@ key_inventory
Definition: player.h:66
object_set_owner
void object_set_owner(object *op, object *owner)
Definition: object.c:844
find_skill_by_name
object * find_skill_by_name(object *who, const char *name)
Definition: skill_util.c:202
strlcpy
size_t strlcpy(char *dst, const char *src, size_t size)
Definition: porting.c:220
pl::listening
uint8_t listening
Definition: player.h:133
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:2898
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:4714
Ns_Add
@ Ns_Add
Definition: newserver.h:66
ADD_PLAYER_NEW
#define ADD_PLAYER_NEW
Definition: player.h:244
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:3972
pl::last_weight
int32_t last_weight
Definition: player.h:158
bow_normal
@ bow_normal
Definition: player.h:42
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:163
offsetof
#define offsetof(type, member)
Definition: shstr.h:37
Settings::playerdir
const char * playerdir
Definition: global.h:247
RANDOM
#define RANDOM()
Definition: define.h:644
SockList_Term
void SockList_Term(SockList *sl)
Definition: lowlevel.c:62
SK_HIDING
@ SK_HIDING
Definition: skills.h:21
FREE_AND_CLEAR_STR
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:197
MOVE_FLY_LOW
#define MOVE_FLY_LOW
Definition: define.h:393
EVENT_PLAYER_DEATH
#define EVENT_PLAYER_DEATH
Definition: events.h:52
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:723
obj::y
int16_t y
Definition: object.h:330
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:235
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:2535
obj::arch
struct archt * arch
Definition: object.h:418
treasureliststruct::items
struct treasurestruct * items
Definition: treasure.h:89
object_set_msg
void object_set_msg(object *op, const char *msg)
Definition: object.c:4781
range_misc
@ range_misc
Definition: player.h:33
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:296
obj::type
uint8_t type
Definition: object.h:343
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:262
pticks
uint32_t pticks
Definition: time.c:47
roll-o-matic.stop
def stop()
Definition: roll-o-matic.py:78
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:373
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:44
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:339
find_player_partial_name
player * find_player_partial_name(const char *plname)
Definition: player.c:111
archt::clone
object clone
Definition: object.h:474
pl::language
int language
Definition: player.h:219
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:531
obj::contr
struct pl * contr
Definition: object.h:279
obj::facing
int8_t facing
Definition: object.h:340
pl::gen_sp_armour
int16_t gen_sp_armour
Definition: player.h:128
fire_bow
int fire_bow(object *op, object *arrow, int dir, int wc_mod, int16_t sx, int16_t sy)
Definition: player.c:2088
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:76
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:154
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:732
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:223
liv::grace
int16_t grace
Definition: living.h:44
check_pick
int check_pick(object *op)
Definition: player.c:1712
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:892
STRENGTH
@ STRENGTH
Definition: living.h:11
object_value_set
bool object_value_set(const object *op, const char *const key)
Definition: object.c:4347
pl::do_los
uint32_t do_los
Definition: player.h:141
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:282
pl::last_skill_ob
object * last_skill_ob[MAX_SKILLS]
Definition: player.h:153
shop.h
dragon_ability_gain
void dragon_ability_gain(object *who, int atnr, int level)
Definition: player.c:4271
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:3220
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:686
Settings::max_stat
uint8_t max_stat
Definition: global.h:321
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:380
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:209
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:448
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:3951
buf
StringBuffer * buf
Definition: readable.c:1610
AP_NOPRINT
#define AP_NOPRINT
Definition: define.h:585
pl::hidden
uint32_t hidden
Definition: player.h:147
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:53
pl::last_stats
living last_stats
Definition: player.h:167
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
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:1330
obj::more
struct obj * more
Definition: object.h:298
socket_struct::faces_sent
uint8_t * faces_sent
Definition: newserver.h:96
obj::move_type
MoveType move_type
Definition: object.h:430
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
pl::ranges
object * ranges[range_size]
Definition: player.h:116
send_rules
void send_rules(const object *op)
Definition: player.c:167
keyrings
@ keyrings
Definition: player.h:67
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:3433
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
Definition: newclient.h:567
obj::skill
sstring skill
Definition: object.h:324
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:2080
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:1546
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:221
do_some_living
void do_some_living(object *op)
Definition: player.c:3255
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:2019
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:3878
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:1608
path_to_player
int path_to_player(object *mon, object *pl, unsigned mindiff)
Definition: player.c:651
socket_struct::login_method
uint8_t login_method
Definition: newserver.h:128
is_true_undead
int is_true_undead(object *op)
Definition: player.c:3948
MSG_TYPE_ATTACK_NOATTACK
#define MSG_TYPE_ATTACK_NOATTACK
Definition: newclient.h:618
play_again
void play_again(object *op)
Definition: player.c:903
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:3776
say.item
dictionary item
Definition: say.py:149
give_initial_items
void give_initial_items(object *pl, treasurelist *items)
Definition: player.c:784
Settings::search_items
uint8_t search_items
Definition: global.h:264
turn_one_transport
static int turn_one_transport(object *transport, object *captain, int dir)
Definition: player.c:2828
obj::anim_suffix
sstring anim_suffix
Definition: object.h:319
add_player
player * add_player(socket_struct *ns, int flags)
Definition: player.c:463
obj::move_on
MoveType move_on
Definition: object.h:433
drain_rod_charge
void drain_rod_charge(object *rod)
Definition: spell_util.c:775
range_skill
@ range_skill
Definition: player.h:35
obj::attacktype
uint32_t attacktype
Definition: object.h:347
server.h
oblnk
Definition: object.h:447
PU_DRINK
#define PU_DRINK
Definition: define.h:116
mapdef::path
char path[HUGE_BUF]
Definition: map.h:365
INTELLIGENCE
@ INTELLIGENCE
Definition: living.h:16
shop_contains
bool shop_contains(object *ob)
Definition: shop.c:1276
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:202
TRUE
#define TRUE
Definition: compat.h:11
pl::usekeys
usekeytype usekeys
Definition: player.h:120
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:301
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:276