Crossfire Server, Trunk
living.cpp
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 
22 #include <assert.h>
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "global.h"
28 #include "sproto.h"
29 #include "living.h"
30 
31 static float get_con_bonus(int stat);
32 static float get_sp_bonus(int stat);
33 static float get_grace_bonus(int stat);
34 static size_t get_index(int stat, size_t max_index);
35 
41 #define ADD_EXP(exptotal, exp) do { exptotal += exp; if (exptotal > MAX_EXPERIENCE) exptotal = MAX_EXPERIENCE; } while (0)
42 #define ADD_TOTALEXP(exptotal, exp) do { exptotal += exp; if (exptotal > MAX_TOTAL_EXPERIENCE) exptotal = MAX_TOTAL_EXPERIENCE; } while(0)
43 
58 #define INT_FEAR_BONUS 0
59 #define INT_TURN_BONUS 1
60 #define INT_CLERIC_CHANCE 2
61 #define INT_LEARN_SPELL 3
62 #define INT_CHA_BONUS 4
63 #define INT_DEX_BONUS 5
64 #define INT_DAM_BONUS 6
65 #define INT_THAC0_BONUS 7
66 #define INT_WEIGHT_LIMIT 8
67 #define NUM_INT_BONUSES 9
68 
70 
75 static const char *int_bonus_names[NUM_INT_BONUSES] = {
76  "cha_fear_bonus", "wis_turn_bonus", "wis_cleric_chance", "int_wis_learn_spell",
77  "cha_shop_bonus", "dex_bonus", "str_damage_bonus", "str_hit_bonus",
78  "str_weight_limit",
79 };
80 
85 #define FLOAT_CON_BONUS 0
86 #define FLOAT_DEX_BONUS 1
87 #define FLOAT_SP_BONUS 2
88 #define FLOAT_GRACE_BONUS 3
89 #define NUM_FLOAT_BONUSES 4
91 static const char *float_bonus_names[NUM_FLOAT_BONUSES] = {
92  "con_hp_bonus", "dex_speed_bonus", "pow_int_sp_bonus", "wis_pow_grace_bonus"
93 };
94 
95 /*
96  * Since this is nowhere defined ...
97  * Both come in handy at least in function add_exp()
98  */
99 #define MAX_EXPERIENCE levels[settings.max_level]
100 
101 extern int64_t *levels;
102 
103 #define MAX_SAVE_LEVEL 110
104 
113 static const int savethrow[MAX_SAVE_LEVEL+1] = {
114  18,
115  18, 17, 16, 15, 14, 14, 13, 13, 12, 12,
116  12, 11, 11, 11, 11, 10, 10, 10, 10, 9,
117  9, 9, 9, 9, 8, 8, 8, 8, 8, 8,
118  7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
119  6, 6, 6, 6, 6, 5, 5, 5, 5, 5,
120  5, 5, 5, 5, 4, 4, 4, 4, 4, 4,
121  4, 4, 4, 4, 3, 3, 3, 3, 3, 3,
122  3, 3, 3, 3, 3, 2, 2, 2, 2, 2,
123  2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
124  1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
125  1, 1, 1, 1, 1, 1, 1, 1, 1, 1
126 };
127 
129 const char *const attacks[NROFATTACKS] = {
130  "physical", "magical", "fire", "electricity", "cold",
131  "confusion", "acid", "drain", "weaponmagic", "ghosthit",
132  "poison", "slow", "paralyze", "turn undead", "fear",
133  "cancellation", "depletion", "death", "chaos", "counterspell",
134  "god power", "holy power", "blinding", "", "life stealing",
135  "disease"
136 };
137 
139 const char *const drain_msg[NUM_STATS] = {
140  "You feel drained of strength.",
141  "You feel drained of agility.",
142  "You feel drained of health.",
143  "You feel drained of wisdom.",
144  "You feel drained of charisma.",
145  "You feel drained of intelligence.",
146  "You feel drained of power."
147 };
148 
150 const char *const restore_msg[NUM_STATS] = {
151  "You feel your strength return.",
152  "You feel your agility return.",
153  "You feel your health return.",
154  "You feel your wisdom return.",
155  "You feel your charisma return.",
156  "You feel your intelligence return.",
157  "You feel your power return."
158 };
159 
161 const char *const gain_msg[NUM_STATS] = {
162  "You feel stronger.",
163  "You feel more agile.",
164  "You feel healthy.",
165  "You feel wiser.",
166  "You seem to look better.",
167  "You feel smarter.",
168  "You feel more potent."
169 };
170 
172 const char *const lose_msg[NUM_STATS] = {
173  "You feel weaker!",
174  "You feel clumsy!",
175  "You feel less healthy!",
176  "You feel foolish!",
177  "You look ugly!",
178  "You feel stupid!",
179  "You feel less potent!"
180 };
181 
183 const char *const statname[NUM_STATS] = {
184  "strength",
185  "dexterity",
186  "constitution",
187  "wisdom",
188  "charisma",
189  "intelligence",
190  "power"
191 };
192 
194 const char *const short_stat_name[NUM_STATS] = {
195  "Str",
196  "Dex",
197  "Con",
198  "Wis",
199  "Cha",
200  "Int",
201  "Pow"
202 };
203 
218 void set_attr_value(living *stats, int attr, int8_t value) {
219  switch (attr) {
220  case STRENGTH:
221  stats->Str = value;
222  break;
223 
224  case DEXTERITY:
225  stats->Dex = value;
226  break;
227 
228  case CONSTITUTION:
229  stats->Con = value;
230  break;
231 
232  case WISDOM:
233  stats->Wis = value;
234  break;
235 
236  case POWER:
237  stats->Pow = value;
238  break;
239 
240  case CHARISMA:
241  stats->Cha = value;
242  break;
243 
244  case INTELLIGENCE:
245  stats->Int = value;
246  break;
247  }
248 }
249 
264 void change_attr_value(living *stats, int attr, int8_t value) {
265  if (value == 0)
266  return;
267  switch (attr) {
268  case STRENGTH:
269  stats->Str += value;
270  break;
271 
272  case DEXTERITY:
273  stats->Dex += value;
274  break;
275 
276  case CONSTITUTION:
277  stats->Con += value;
278  break;
279 
280  case WISDOM:
281  stats->Wis += value;
282  break;
283 
284  case POWER:
285  stats->Pow += value;
286  break;
287 
288  case CHARISMA:
289  stats->Cha += value;
290  break;
291 
292  case INTELLIGENCE:
293  stats->Int += value;
294  break;
295 
296  default:
297  LOG(llevError, "Invalid attribute in change_attr_value: %d\n", attr);
298  }
299 }
300 
313 int8_t get_attr_value(const living *stats, int attr) {
314  switch (attr) {
315  case STRENGTH:
316  return(stats->Str);
317 
318  case DEXTERITY:
319  return(stats->Dex);
320 
321  case CONSTITUTION:
322  return(stats->Con);
323 
324  case WISDOM:
325  return(stats->Wis);
326 
327  case CHARISMA:
328  return(stats->Cha);
329 
330  case INTELLIGENCE:
331  return(stats->Int);
332 
333  case POWER:
334  return(stats->Pow);
335  }
336  return 0;
337 }
338 
354 void check_stat_bounds(living *stats, int8_t min_stat, int8_t max_stat) {
355  int i, v;
356  for (i = 0; i < NUM_STATS; i++)
357  if ((v = get_attr_value(stats, i)) > max_stat)
358  set_attr_value(stats, i, max_stat);
359  else if (v < min_stat)
360  set_attr_value(stats, i, min_stat);
361 }
362 
363 
369 #define DIFF_MSG(flag, subtype1, subtype2, msg1, msg2) \
370  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, (flag > 0) ? subtype1 : subtype2, (flag > 0) ? msg1 : msg2);
371 
394 int change_abil(object *op, object *tmp) {
395  int flag = QUERY_FLAG(tmp, FLAG_APPLIED) ? 1 : -1, i, j, success = 0;
396  object refop;
397  int potion_max = 0;
398 
399  /* remember what object was like before it was changed. note that
400  * refop is a local copy of op only to be used for detecting changes
401  * found by fix_object. refop is not a real object
402  */
403  memcpy(&refop, op, sizeof(object));
404 
405  if (op->type == PLAYER) {
406  if (tmp->type == POTION) {
407  potion_max = 1;
408  for (j = 0; j < NUM_STATS; j++) {
409  int nstat, ostat;
410 
411  ostat = get_attr_value(&(op->contr->orig_stats), j);
412  i = get_attr_value(&(tmp->stats), j);
413 
414  /* nstat is what the stat will be after use of the potion */
415  nstat = flag*i+ostat;
416 
417  /* Do some bounds checking. While I don't think any
418  * potions do so right now, there is the potential for potions
419  * that adjust that stat by more than one point, so we need
420  * to allow for that.
421  */
422  if (nstat < 1 && i*flag < 0)
423  nstat = 1;
424  else if (nstat > 20+get_attr_value(&(op->arch->clone.stats), j)) {
425  nstat = 20+get_attr_value(&(op->arch->clone.stats), j);
426  }
427  if (nstat != ostat) {
428  set_attr_value(&(op->contr->orig_stats), j, nstat);
429  potion_max = 0;
430  } else if (i) {
431  /* potion is useless - player has already hit the natural maximum */
432  potion_max = 1;
433  }
434  }
435  /* This section of code ups the characters normal stats also. I am not
436  * sure if this is strictly necessary, being that fix_object probably
437  * recalculates this anyway.
438  */
439  for (j = 0; j < NUM_STATS; j++)
440  change_attr_value(&(op->stats), j, flag*get_attr_value(&(tmp->stats), j));
442  } /* end of potion handling code */
443  }
444 
445  /* reset attributes that fix_object doesn't reset since it doesn't search
446  * everything to set
447  */
448  if (flag == -1) {
449  op->attacktype &= ~tmp->attacktype;
450  op->path_attuned &= ~tmp->path_attuned;
451  op->path_repelled &= ~tmp->path_repelled;
452  op->path_denied &= ~tmp->path_denied;
453  /* Presuming here that creatures only have move_type,
454  * and not the other move_ fields.
455  */
456  op->move_type &= ~tmp->move_type;
457  }
458 
459  /* call fix_object since op object could have whatever attribute due
460  * to multiple items. if fix_object always has to be called after
461  * change_ability then might as well call it from here
462  */
463  fix_object(op);
464 
465  /* Fix player won't add the bows ability to the player, so don't
466  * print out message if this is a bow.
467  */
468  if (tmp->attacktype&AT_CONFUSION && tmp->type != BOW) {
469  success = 1;
471  "Your hands begin to glow red.",
472  "Your hands stop glowing red.");
473  }
474  if (QUERY_FLAG(op, FLAG_LIFESAVE) != QUERY_FLAG(&refop, FLAG_LIFESAVE)) {
475  success = 1;
477  "You feel very protected.",
478  "You don't feel protected anymore.");
479  }
481  success = 1;
483  "A magic force shimmers around you.",
484  "The magic force fades away.");
485  }
487  success = 1;
489  "You feel more safe now, somehow.",
490  "Suddenly you feel less safe, somehow.");
491  }
492  /* movement type has changed. We don't care about cases where
493  * user has multiple items giving the same type appled like we
494  * used to - that is more work than what we gain, plus messages
495  * can be misleading (a little higher could be miscontrued from
496  * from fly high)
497  */
498  if (tmp->move_type && op->move_type != refop.move_type) {
499  success = 1;
500 
501  /* MOVE_FLY_HIGH trumps MOVE_FLY_LOW - changing your move_fly_low
502  * status doesn't make a difference if you are flying high
503  */
504  if (tmp->move_type&MOVE_FLY_LOW && !(op->move_type&MOVE_FLY_HIGH)) {
506  "You start to float in the air!",
507  "You float down to the ground.");
508  }
509 
510  if (tmp->move_type&MOVE_FLY_HIGH) {
511  /* double conditional - second case covers if you have move_fly_low -
512  * in that case, you don't actually land
513  */
515  "You soar into the air!.",
516  (op->move_type&MOVE_FLY_LOW ? "You glide closer to the ground.":
517  "You float down to the ground."));
518  }
519  if (tmp->move_type&MOVE_SWIM)
521  "You feel ready for a swim",
522  "You no longer feel like swimming");
523 
524  /* Changing move status may mean you are affected by things you weren't before */
526  }
527 
528  /* becoming UNDEAD... a special treatment for this flag. Only those not
529  * originally undead may change their status
530  */
531  if (!QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
532  if (QUERY_FLAG(op, FLAG_UNDEAD) != QUERY_FLAG(&refop, FLAG_UNDEAD)) {
533  success = 1;
534  if (flag > 0) {
535  if (op->race)
536  free_string(op->race);
537  op->race = add_string("undead");
538  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, "Your lifeforce drains away!");
539  } else {
540  if (op->race)
541  free_string(op->race);
542  if (op->arch->clone.race)
543  op->race = add_string(op->arch->clone.race);
544  else
545  op->race = NULL;
546  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_RACE, "Your lifeforce returns!");
547  }
548  }
549 
550  if (QUERY_FLAG(op, FLAG_STEALTH) != QUERY_FLAG(&refop, FLAG_STEALTH)) {
551  success = 1;
553  "You walk more quietly.",
554  "You walk more noisily.");
555  }
557  success = 1;
559  "You become transparent.",
560  "You can see yourself.");
561  }
562  /* blinded you can tell if more blinded since blinded player has minimal
563  * vision
564  */
565  if (QUERY_FLAG(tmp, FLAG_BLIND)) {
566  success = 1;
567  if (flag > 0) {
568  if (QUERY_FLAG(op, FLAG_WIZ))
570  else {
573  if (op->type == PLAYER)
574  op->contr->do_los = 1;
575  }
576  } else {
577  if (QUERY_FLAG(op, FLAG_WIZ))
578  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END, "Your mortal self can now see again.");
579  else {
582  if (op->type == PLAYER)
583  op->contr->do_los = 1;
584  }
585  }
586  }
587 
589  success = 1;
590  if (op->type == PLAYER)
591  op->contr->do_los = 1;
593  "Your vision is better in the dark.",
594  "You see less well in the dark.");
595  }
596 
597  if (QUERY_FLAG(op, FLAG_XRAYS) != QUERY_FLAG(&refop, FLAG_XRAYS)) {
598  success = 1;
599  if (flag > 0) {
600  if (QUERY_FLAG(op, FLAG_WIZ))
601  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_START, "Your vision becomes a little clearer.");
602  else {
603  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_START, "Everything becomes transparent.");
604  if (op->type == PLAYER)
605  op->contr->do_los = 1;
606  }
607  } else {
608  if (QUERY_FLAG(op, FLAG_WIZ))
609  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END, "Your vision becomes a bit out of focus.");
610  else {
611  draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END, "Everything suddenly looks very solid.");
612  if (op->type == PLAYER)
613  op->contr->do_los = 1;
614  }
615  }
616  }
617 
618  if (tmp->stats.luck) {
619  success = 1;
621  "You feel more lucky.",
622  "You feel less lucky.");
623  }
624 
625  if (tmp->stats.hp && op->type == PLAYER) {
626  success = 1;
628  "You feel much more healthy!",
629  "You feel much less healthy!");
630  }
631 
632  if (tmp->stats.sp && op->type == PLAYER && tmp->type != SKILL) {
633  success = 1;
635  "You feel one with the powers of magic!",
636  "You suddenly feel very mundane.");
637  }
638 
639  /* for the future when artifacts set this -b.t. */
640  if (tmp->stats.grace && op->type == PLAYER) {
641  success = 1;
643  "You feel closer to your god!",
644  "You suddenly feel less holy.");
645  }
646 
647  if (tmp->stats.wc && op->type == PLAYER) {
648  success = 1;
650  "You feel more confident in combat.",
651  "You feel less confident in combat.");
652  }
653 
654  if (tmp->stats.ac && op->type == PLAYER) {
655  success = 1;
657  "You feel more confident in your dodging skills.",
658  "You feel less confident in your dodging skills.");
659  }
660 
661  if (tmp->stats.exp && tmp->type != SKILL && op->type == PLAYER) {
662  success = 1;
664  "You feel like you're moving faster.",
665  "You feel like you're moving more slowly.");
666  }
667 
668  if (tmp->stats.food && op->type == PLAYER) {
669  success = 1;
671  "You feel your digestion slowing down.",
672  "You feel your digestion speeding up.");
673  }
674 
675  /* Messages for changed resistance */
676  for (i = 0; i < NROFATTACKS; i++) {
677  if (i == ATNR_PHYSICAL)
678  continue; /* Don't display about armour */
679 
680  if (op->resist[i] != refop.resist[i]) {
681  success = 1;
682  if (op->resist[i] > refop.resist[i])
684  "Your resistance to %s rises to %d%%.",
685  change_resist_msg[i], op->resist[i]);
686  else
688  "Your resistance to %s drops to %d%%.",
689  change_resist_msg[i], op->resist[i]);
690  }
691  }
692 
693  if (!potion_max) {
694  for (j = 0; j < NUM_STATS; j++) {
695  if ((i = get_attr_value(&(tmp->stats), j)) != 0) {
696  /* Check that the attribute value isn't already min or max value. */
697  int curr_val = get_attr_value(&op->stats, j);
698  if ((curr_val > MIN_STAT && i < 0) || (curr_val < settings.max_stat && i > 0)) {
699  success = 1;
701  }
702  }
703  }
704  }
705  return success;
706 }
707 
716 void drain_stat(object *op) {
718 }
719 
728 void drain_specific_stat(object *op, int deplete_stats) {
729  object *tmp;
730  archetype *at;
731 
733  if (!at) {
734  return;
735  } else {
736  tmp = arch_present_in_ob(at, op);
737  if (!tmp) {
738  tmp = arch_to_object(at);
741  }
742  }
743 
745  change_attr_value(&tmp->stats, deplete_stats, -1);
746  fix_object(op);
747 }
748 
755 int remove_depletion(object *op, int level) {
756  object *depl;
757  archetype *at;
758  int i, count = 0;
759 
760  if ((at = find_archetype(ARCH_DEPLETION)) == NULL) {
761  return 0;
762  }
763 
764  depl = arch_present_in_ob(at, op);
765 
766  if (depl == NULL)
767  return 0;
768 
769  if (level != -1 && level < op->level)
770  return 0;
771 
772  for (i = 0; i < NUM_STATS; i++) {
773  if (get_attr_value(&depl->stats, i)) {
774  count++;
777  }
778  }
779 
780  object_remove(depl);
782  fix_object(op);
783 
784  return (count == 0) ? 0 : 1;
785 }
786 
796 void change_luck(object *op, int value) {
797  object *tmp;
798  archetype *at;
799  int new_luck;
800 
801  at = find_archetype("luck");
802  if (!at)
803  ;
804  else {
805  tmp = arch_present_in_ob(at, op);
806  if (!tmp) {
807  if (!value)
808  return;
809  tmp = arch_to_object(at);
812  }
813  if (value) {
814  /* Limit the luck value of the bad luck object to +/-100. This
815  * (arbitrary) value prevents overflows (both in the bad luck object and
816  * in op itself).
817  */
818  new_luck = tmp->stats.luck+value;
819  if (new_luck >= -100 && new_luck <= 100) {
820  op->stats.luck += value;
821  tmp->stats.luck = new_luck;
822  }
823  } else {
824  if (!tmp->stats.luck) {
825  return;
826  }
827  /* Randomly change the players luck. Basically, we move it
828  * back neutral (if greater>0, subtract, otherwise add)
829  */
830  if (RANDOM()%(FABS(tmp->stats.luck)) >= RANDOM()%30) {
831  int diff = tmp->stats.luck > 0 ? -1 : 1;
832  op->stats.luck += diff;
833  tmp->stats.luck += diff;
834  }
835  }
836  }
837 }
838 
845 void remove_statbonus(object *op) {
846  op->stats.Str -= op->arch->clone.stats.Str;
847  op->stats.Dex -= op->arch->clone.stats.Dex;
848  op->stats.Con -= op->arch->clone.stats.Con;
849  op->stats.Wis -= op->arch->clone.stats.Wis;
850  op->stats.Pow -= op->arch->clone.stats.Pow;
851  op->stats.Cha -= op->arch->clone.stats.Cha;
852  op->stats.Int -= op->arch->clone.stats.Int;
853  op->contr->orig_stats.Str -= op->arch->clone.stats.Str;
854  op->contr->orig_stats.Dex -= op->arch->clone.stats.Dex;
855  op->contr->orig_stats.Con -= op->arch->clone.stats.Con;
856  op->contr->orig_stats.Wis -= op->arch->clone.stats.Wis;
857  op->contr->orig_stats.Pow -= op->arch->clone.stats.Pow;
858  op->contr->orig_stats.Cha -= op->arch->clone.stats.Cha;
859  op->contr->orig_stats.Int -= op->arch->clone.stats.Int;
860 }
861 
868 void add_statbonus(object *op) {
869  op->stats.Str += op->arch->clone.stats.Str;
870  op->stats.Dex += op->arch->clone.stats.Dex;
871  op->stats.Con += op->arch->clone.stats.Con;
872  op->stats.Wis += op->arch->clone.stats.Wis;
873  op->stats.Pow += op->arch->clone.stats.Pow;
874  op->stats.Cha += op->arch->clone.stats.Cha;
875  op->stats.Int += op->arch->clone.stats.Int;
876  op->contr->orig_stats.Str += op->arch->clone.stats.Str;
877  op->contr->orig_stats.Dex += op->arch->clone.stats.Dex;
878  op->contr->orig_stats.Con += op->arch->clone.stats.Con;
879  op->contr->orig_stats.Wis += op->arch->clone.stats.Wis;
880  op->contr->orig_stats.Pow += op->arch->clone.stats.Pow;
881  op->contr->orig_stats.Cha += op->arch->clone.stats.Cha;
882  op->contr->orig_stats.Int += op->arch->clone.stats.Int;
883 }
884 
897 static void fix_player(object *op, int *ac, int *wc, const object *grace_obj, const object *mana_obj, const object *wc_obj, int weapon_speed, float added_speed)
898 {
899  int pl_level, i;
900  float maxhp, tmpf;
901 
902  if (op->type != PLAYER)
903  return;
904 
906  pl_level = op->level;
907 
908  if (pl_level < 1)
909  pl_level = 1; /* safety, we should always get 1 levels worth of hp! */
910 
911  /*
912  * We store maxhp as a float to hold any fractional hp bonuses,
913  * (eg, 2.5 con bonus). While it may seem simpler to just
914  * do a get_con_bonus() * min(level,10), there is also a 1 hp/level
915  * minimum (including bonus), se we have to do the logic on a
916  * level basis.
917  */
918  maxhp = 0.0;
919  for (i = 1, op->stats.maxhp = 0; i <= pl_level && i <= 10; i++) {
920 
921  tmpf = op->contr->levhp[i]+get_con_bonus(op->stats.Con);
922 
923  /* always get at least 1 hp/level */
924  if (tmpf < 1.0) tmpf = 1.0;
925 
926  maxhp += tmpf;
927  }
928 
929  /* Add 0.5 so that this rounds normally - the cast just drops the
930  * fraction, so 1.5 becomes 1.
931  */
932  op->stats.maxhp = (int)(maxhp + 0.5);
933  if (op->level > 10)
934  op->stats.maxhp += 2 * (op->level - 10);
935 
936  op->stats.maxhp += op->arch->clone.stats.maxhp;
937 
938  if (op->stats.hp > op->stats.maxhp)
939  op->stats.hp = op->stats.maxhp;
940 
941  /* Sp gain is controlled by the level of the player's
942  * relevant experience object (mana_obj, see above) */
943 
944  /* set maxsp */
945  if (!mana_obj || !mana_obj->level) {
946  op->stats.maxsp = 1;
947  } else {
948  float sp_tmp = 0.0, mana_bonus;
949  int mana_lvl_max;
950 
951  mana_lvl_max = (mana_obj->level >10 ? 10: mana_obj->level);
952  mana_bonus = (2.0*get_sp_bonus(op->stats.Pow)+get_sp_bonus(op->stats.Int)) / 3.0;
953 
954  for (i = 1; i <= mana_lvl_max; i++) {
955  float stmp;
956 
957  stmp = op->contr->levsp[i] + mana_bonus;
958 
959  /* Got some extra bonus at first level */
960  if (i == 1) stmp += mana_bonus;
961 
962  if (stmp < 1.0)
963  stmp = 1.0;
964 
965  sp_tmp += stmp;
966  }
967 
968  op->stats.maxsp = (int)sp_tmp+op->arch->clone.stats.maxsp;
969 
970  if (mana_obj->level > 10)
971  op->stats.maxsp += 2 * (mana_obj->level - 10);
972  }
973 
974  /* Characters can get their sp supercharged via rune of transferrance */
975  if (op->stats.sp > op->stats.maxsp*2)
976  op->stats.sp = op->stats.maxsp*2;
977 
978  /* set maxgrace, notice 3-4 lines below it depends on both Wis and Pow */
979  if (!grace_obj || !grace_obj->level) {
980  op->stats.maxgrace = 1;
981  } else {
982  /* store grace in a float - this way, the divisions below don't create
983  * big jumps when you go from level to level - with int's, it then
984  * becomes big jumps when the sums of the bonuses jump to the next
985  * step of 8 - with floats, even fractional ones are useful.
986  */
987  float sp_tmp = 0.0, grace_bonus;
988 
989  grace_bonus = (get_grace_bonus(op->stats.Pow)+2.0*get_grace_bonus(op->stats.Wis)) / 3.0;
990 
991  for (i = 1; i <= grace_obj->level && i <= 10; i++) {
992  float grace_tmp = op->contr->levgrace[i] + grace_bonus;
993 
994  /* Got some extra bonus at first level */
995  if (i == 1)
996  grace_tmp += grace_bonus;
997 
998  if (grace_tmp < 1.0)
999  grace_tmp = 1.0;
1000  sp_tmp += grace_tmp;
1001  }
1002  op->stats.maxgrace = (int)sp_tmp+op->arch->clone.stats.maxgrace;
1003 
1004  /* two grace points per level after 11 */
1005  if (grace_obj->level > 10)
1006  op->stats.maxgrace += 2 * (grace_obj->level - 10);
1007  }
1008  /* No limit on grace vs maxgrace */
1009 
1010  if (op->contr->braced) {
1011  (*ac) += 2;
1012  (*wc) += 4;
1013  } else
1014  (*ac) -= get_dex_bonus(op->stats.Dex);
1015 
1016  /* In new exp/skills system, wc bonuses are related to
1017  * the players level in a relevant exp object (wc_obj)
1018  * not the general player level -b.t.
1019  * I changed this slightly so that wc bonuses are better
1020  * than before. This is to balance out the fact that
1021  * the player no longer gets a personal weapon w/ 1
1022  * improvement every level, now its fighterlevel/5. So
1023  * we give the player a bonus here in wc and dam
1024  * to make up for the change. Note that I left the
1025  * monster bonus the same as before. -b.t.
1026  */
1027 
1028  if (wc_obj && wc_obj->level >= 1) {
1029  const char *wc_in = object_get_value(wc_obj, "wc_increase_rate");
1030  int wc_increase_rate;
1031 
1032  wc_increase_rate = wc_in?atoi(wc_in):5;
1033  assert(wc_increase_rate != 0);
1034 
1035  (*wc) -= get_thaco_bonus(op->stats.Str);
1036  (*wc) -= (wc_obj->level-1)/wc_increase_rate;
1037  op->stats.dam += (wc_obj->level-1)/4;
1038  } else {
1039  (*wc) -= (((op->level-1)/5)+get_thaco_bonus(op->stats.Str));
1040  }
1041  op->stats.dam += get_dam_bonus(op->stats.Str);
1042 
1043  if (op->stats.dam < 1)
1044  op->stats.dam = 1;
1045 
1046  /* Player speed is nominally 0.75, plus a bonus read in from the file
1047  * lib/config/stat_bonus. Currently, this is roughly:
1048  * -0.1 for Dex 1
1049  * +0 for Dex 8 through 11
1050  * +0.25 for Dex 30.
1051  */
1052 
1053  op->speed = MAX_PLAYER_SPEED+get_speed_bonus(op->stats.Dex);
1054 
1055  if (settings.search_items && op->contr->search_str[0])
1056  op->speed -= 0.25;
1057 
1058  if (op->attacktype == 0)
1059  op->attacktype = op->arch->clone.attacktype;
1060 
1061 
1062  /* First block is for encumbrance of the player */
1063 
1064  /* The check for FREE_PLAYER_LOAD_PERCENT < 1.0 is really a safety. One would
1065  * think that it should never be the case if that is set to 1.0, that carrying
1066  * would be above the limit. But it could be if character is weakened and
1067  * was otherwise at limit. Without that safety, could get divide by zeros.
1068  */
1069  if (op->carrying > (get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT)
1070  && (FREE_PLAYER_LOAD_PERCENT < 1.0)) {
1071  int extra_weight = op->carrying-get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT;
1072 
1073  op->contr->character_load = (float)extra_weight/(float)(get_weight_limit(op->stats.Str)*(1.0-FREE_PLAYER_LOAD_PERCENT));
1074 
1075  /* character_load is used for weapon speed below, so sanitize value */
1076  if (op->contr->character_load >= 1.0)
1077  op->contr->character_load = 1.0;
1078 
1079  /* If a character is fully loaded, they will always get cut down to min
1080  * speed no matter what their dex. Note that magic is below, so
1081  * still helps out.
1082  */
1083  if (op->speed > MAX_PLAYER_SPEED)
1084  op->speed -= op->contr->character_load*(op->speed-MIN_PLAYER_SPEED);
1085  else
1086  op->speed -= op->contr->character_load*(MAX_PLAYER_SPEED-MIN_PLAYER_SPEED);
1087  } else {
1088  op->contr->character_load = 0;
1089  }
1090 
1091  /* This block is for weapon speed */
1092  op->weapon_speed = BASE_WEAPON_SPEED+get_speed_bonus(op->stats.Dex)-weapon_speed/20.0+added_speed/10.0;
1093  if (wc_obj) {
1094  op->weapon_speed += 0.005*wc_obj->level;
1095  } else
1096  op->weapon_speed += 0.005*op->level;
1097 
1098  /* character_load=1.0 means character is fully loaded, 0.0 is unloaded. Multiplying
1099  * by 0.2 for penalty is purely arbitrary, but slows things down without completely
1100  * stopping them.
1101  */
1102  op->weapon_speed -= op->contr->character_load*0.2;
1103 
1104  if (op->weapon_speed < 0.05)
1105  op->weapon_speed = 0.05;
1106 
1107  /* It is quite possible that a player's spell costing might have changed,
1108  * so we will check that now.
1109  */
1110  esrv_update_spells(op->contr);
1111 }
1132 void fix_object(object *op) {
1133  int i;
1134  float max = 9, added_speed = 0, speed_reduce_from_disease = 1;
1135  int weapon_speed = 0;
1136  int best_wc = 0, best_ac = 0, wc = 0, ac = 0;
1137  int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS];
1138  const object *grace_obj = NULL, *mana_obj = NULL, *wc_obj = NULL;
1139 
1140  /* First task is to clear all the values back to their original values */
1141  if (op->type == PLAYER) {
1142  for (i = 0; i < NUM_STATS; i++) {
1143  set_attr_value(&(op->stats), i, get_attr_value(&(op->contr->orig_stats), i));
1144  set_attr_value(&(op->contr->applied_stats), i, 0);
1145  }
1147  op->contr->encumbrance = 0;
1148 
1149  op->attacktype = 0;
1150  op->contr->digestion = 0;
1151  op->contr->gen_hp = 0;
1152  op->contr->gen_sp = 0;
1153  op->contr->gen_grace = 0;
1154  op->contr->gen_sp_armour = 10;
1155  op->contr->item_power = 0;
1156 
1157  /* Don't clobber all the range_ values. range_golem otherwise
1158  * gets reset for no good reason, and we don't want to reset
1159  * range_magic (what spell is readied). These three below
1160  * well get filled in based on what the player has equipped.
1161  */
1162  op->contr->ranges[range_bow] = NULL;
1163  op->contr->ranges[range_misc] = NULL;
1164  op->contr->ranges[range_skill] = NULL;
1165  } /* If player */
1166  memcpy(op->body_used, op->body_info, sizeof(op->body_info));
1167 
1168  if (op->slaying != NULL) {
1169  free_string(op->slaying);
1170  op->slaying = NULL;
1171  }
1172  if (!QUERY_FLAG(op, FLAG_WIZ)) {
1175  }
1176 
1181  if (!QUERY_FLAG(&op->arch->clone, FLAG_REFL_SPELL))
1183  if (!QUERY_FLAG(&op->arch->clone, FLAG_REFL_MISSILE))
1185  if (!QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
1187  if (!QUERY_FLAG(&op->arch->clone, FLAG_SEE_IN_DARK))
1190 
1191  op->path_attuned = op->arch->clone.path_attuned;
1192  op->path_repelled = op->arch->clone.path_repelled;
1193  op->path_denied = op->arch->clone.path_denied;
1194  op->glow_radius = op->arch->clone.glow_radius;
1195  op->move_type = op->arch->clone.move_type;
1196  op->chosen_skill = NULL;
1197 
1198  /* initializing resistances from the values in player/monster's
1199  * archetype clone
1200  */
1201  memcpy(&op->resist, &op->arch->clone.resist, sizeof(op->resist));
1202 
1203  for (i = 0; i < NROFATTACKS; i++) {
1204  if (op->resist[i] > 0)
1205  prot[i] = op->resist[i], vuln[i] = 0;
1206  else
1207  vuln[i] = -(op->resist[i]), prot[i] = 0;
1208  potion_resist[i] = 0;
1209  }
1210 
1211  wc = op->arch->clone.stats.wc;
1212  op->stats.dam = op->arch->clone.stats.dam;
1213 
1214  /* for players which cannot use armour, they gain AC -1 per 3 levels,
1215  * plus a small amount of physical resist, those poor suckers. ;)
1216  * the fact that maxlevel is factored in could be considered sort of bogus -
1217  * we should probably give them some bonus and cap it off - otherwise,
1218  * basically, if a server updates its max level, these playes may find
1219  * that their protection from physical goes down
1220  */
1221  if (!QUERY_FLAG(op, FLAG_USE_ARMOUR) && op->type == PLAYER) {
1222  ac = MAX(-10, op->arch->clone.stats.ac-op->level/3);
1223  prot[ATNR_PHYSICAL] += ((100-prot[AT_PHYSICAL])*(80*op->level/settings.max_level))/100;
1224  } else
1225  ac = op->arch->clone.stats.ac;
1226 
1227  op->stats.luck = op->arch->clone.stats.luck;
1228  op->speed = op->arch->clone.speed;
1229 
1230  /* OK - we've reset most all the objects attributes to sane values.
1231  * now go through and make adjustments for what the player has equipped.
1232  */
1233 
1234  FOR_INV_PREPARE(op, tmp) {
1235  /* See note in map.c:update_position about making this additive
1236  * since light sources are never applied, need to put check here.
1237  */
1238  if (tmp->glow_radius > op->glow_radius)
1239  op->glow_radius = tmp->glow_radius;
1240 
1241  /* This happens because apply_potion calls change_abil with the potion
1242  * applied so we can tell the player what chagned. But change_abil
1243  * then calls this function.
1244  */
1245  if (QUERY_FLAG(tmp, FLAG_APPLIED) && tmp->type == POTION)
1246  continue;
1247 
1248  /* For some things, we don't care what is equipped */
1249  if (tmp->type == SKILL) {
1250  /* Want to take the highest skill here. */
1251  if (IS_MANA_SKILL(tmp->subtype)) {
1252  if (!mana_obj)
1253  mana_obj = tmp;
1254  else if (tmp->level > mana_obj->level)
1255  mana_obj = tmp;
1256  }
1257  if (IS_GRACE_SKILL(tmp->subtype)) {
1258  if (!grace_obj)
1259  grace_obj = tmp;
1260  else if (tmp->level > grace_obj->level)
1261  grace_obj = tmp;
1262  }
1263  }
1264 
1265  /* Container objects are not meant to adjust a players, but other applied
1266  * objects need to make adjustments.
1267  * This block should handle all player specific changes
1268  * The check for Praying is a bit of a hack - god given bonuses are put
1269  * in the praying skill, and the player should always get those.
1270  * It also means we need to put in additional checks for applied below,
1271  * because the skill shouldn't count against body positions being used
1272  * up, etc.
1273  */
1274  if ((QUERY_FLAG(tmp, FLAG_APPLIED) && tmp->type != CONTAINER && tmp->type != CLOSE_CON)
1275  || (tmp->type == SKILL && tmp->subtype == SK_PRAYING)) {
1276  if (op->type == PLAYER) {
1277  if (tmp->type == BOW)
1278  op->contr->ranges[range_bow] = tmp;
1279 
1280  if (tmp->type == WAND || tmp->type == ROD)
1281  op->contr->ranges[range_misc] = tmp;
1282 
1283  for (i = 0; i < NUM_STATS; i++) {
1284  int8_t value;
1285 
1286  value = get_attr_value(&(tmp->stats), i);
1287  change_attr_value(&(op->stats), i, value);
1288  if (strcmp(tmp->arch->clone.name, ARCH_DEPLETION) != 0)
1289  change_attr_value(&(op->contr->applied_stats), i, value);
1290  }
1291 
1292  /* For this temporary calculation, allow wider range of stat - if we have
1293  * having that gives +5 and different object that gives -5 and stat
1294  * is maxed, we don't want different results based on order of
1295  * inventory.
1296  */
1298 
1299  /* these are the items that currently can change digestion, regeneration,
1300  * spell point recovery and mana point recovery. Seems sort of an arbitary
1301  * list, but other items store other info into stats array.
1302  */
1303  switch (tmp->type)
1304  {
1305  case WEAPON:
1306  case ARMOUR:
1307  case HELMET:
1308  case SHIELD:
1309  case RING:
1310  case BOOTS:
1311  case GLOVES:
1312  case AMULET:
1313  case GIRDLE:
1314  case BRACERS:
1315  case CLOAK:
1316  case DISEASE:
1317  case FORCE:
1318  case SKILL:
1319  op->contr->digestion += tmp->stats.food;
1320  op->contr->gen_hp += tmp->stats.hp;
1321  op->contr->gen_sp += tmp->stats.sp;
1322  op->contr->gen_grace += tmp->stats.grace;
1323  op->contr->gen_sp_armour += tmp->gen_sp_armour;
1324  /*FALLTHROUGH*/
1325 
1326  /* Bow and skill utils need to update item_power specifically.
1327  * This should fix bug #648
1328  * Neila Hawkins 2017-08-09
1329  */
1330  case BOW:
1331  case SKILL_TOOL:
1332  op->contr->item_power += tmp->item_power;
1333  break;
1334  }
1335  } /* if this is a player */
1336 
1337  /* Update slots used for items */
1338  if (QUERY_FLAG(tmp, FLAG_APPLIED)) {
1339  for (i = 0; i < NUM_BODY_LOCATIONS; i++)
1340  op->body_used[i] += tmp->body_info[i];
1341  }
1342 
1343  if (tmp->type == SYMPTOM && tmp->last_sp) {
1344  /* Should take the worst disease of the bunch */
1345  if (((float)tmp->last_sp/100.0) < speed_reduce_from_disease)
1346  speed_reduce_from_disease = (float)tmp->last_sp/100.0;
1347  }
1348 
1349  /* Pos. and neg. protections are counted separate (-> pro/vuln).
1350  * (Negative protections are calculated extactly like positive.)
1351  * Resistance from potions are treated special as well. If there's
1352  * more than one potion-effect, the bigger prot.-value is taken.
1353  */
1354  if (tmp->type != POTION) {
1355  for (i = 0; i < NROFATTACKS; i++) {
1356  /* Potential for cursed potions, in which case we just can use
1357  * a straight MAX, as potion_resist is initialized to zero.
1358  */
1359  if (tmp->type == POTION_RESIST_EFFECT) {
1360  if (potion_resist[i])
1361  potion_resist[i] = MAX(potion_resist[i], tmp->resist[i]);
1362  else
1363  potion_resist[i] = tmp->resist[i];
1364  } else if (tmp->resist[i] > 0)
1365  prot[i] += ((100-prot[i])*tmp->resist[i])/100;
1366  else if (tmp->resist[i] < 0)
1367  vuln[i] += ((100-vuln[i])*(-tmp->resist[i]))/100;
1368  }
1369  }
1370 
1371  /* There may be other things that should not adjust the attacktype */
1372  if (tmp->type != BOW && tmp->type != SYMPTOM)
1373  op->attacktype |= tmp->attacktype;
1374 
1375  op->path_attuned |= tmp->path_attuned;
1376  op->path_repelled |= tmp->path_repelled;
1377  op->path_denied |= tmp->path_denied;
1378  op->stats.luck += tmp->stats.luck;
1379  op->move_type |= tmp->move_type;
1380 
1387  if (QUERY_FLAG(tmp, FLAG_STEALTH))
1389  if (QUERY_FLAG(tmp, FLAG_XRAYS))
1391  if (QUERY_FLAG(tmp, FLAG_BLIND))
1395  if (QUERY_FLAG(tmp, FLAG_PROBE))
1397 
1398  // Items can make the wielder confused.
1401 
1402  if (QUERY_FLAG(tmp, FLAG_UNDEAD) && !QUERY_FLAG(&op->arch->clone, FLAG_UNDEAD))
1404 
1405  if (QUERY_FLAG(tmp, FLAG_MAKE_INVIS)) {
1407  op->invisible = 1;
1408  }
1409 
1410  if (tmp->stats.exp && tmp->type != SKILL) {
1411  added_speed += (float)tmp->stats.exp/3.0;
1412  }
1413 
1414  switch (tmp->type) {
1415  /* skills modifying the character -b.t. */
1416  /* for all skills and skill granting objects */
1417  case SKILL:
1418  if (!QUERY_FLAG(tmp, FLAG_APPLIED))
1419  break;
1420 
1421  if (IS_COMBAT_SKILL(tmp->subtype))
1422  wc_obj = tmp;
1423 
1424  if (op->chosen_skill) {
1425  LOG(llevDebug, "fix_object, op %s has multiple skills applied\n", op->name);
1426  }
1427  op->chosen_skill = tmp;
1428  if (tmp->stats.dam > 0) { /* skill is a 'weapon' */
1430  weapon_speed = (int)WEAPON_SPEED(tmp);
1431  if (weapon_speed < 0)
1432  weapon_speed = 0;
1433  op->stats.dam += tmp->stats.dam*(1+(op->chosen_skill->level/9));
1434  op->stats.dam += tmp->magic;
1435  }
1436  if (tmp->stats.wc)
1437  wc -= (tmp->stats.wc+tmp->magic);
1438 
1439  if (tmp->slaying != NULL) {
1440  if (op->slaying != NULL)
1441  free_string(op->slaying);
1442  add_refcount(op->slaying = tmp->slaying);
1443  }
1444 
1445  if (tmp->stats.ac)
1446  ac -= (tmp->stats.ac+tmp->magic);
1447  if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1448  op->contr->encumbrance += (int)3*tmp->weight/1000;
1449  if (op->type == PLAYER)
1450  op->contr->ranges[range_skill] = op;
1451  break;
1452 
1453  case SKILL_TOOL:
1454  if (op->chosen_skill) {
1455  LOG(llevDebug, "fix_object, op %s has multiple skills applied\n", op->name);
1456  }
1457  op->chosen_skill = tmp;
1458  if (op->type == PLAYER)
1459  op->contr->ranges[range_skill] = op;
1460  break;
1461 
1462  case SHIELD:
1463  if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1464  op->contr->encumbrance += (int)tmp->weight/2000;
1465  /* fall through */
1466  case RING:
1467  case AMULET:
1468  case GIRDLE:
1469  case HELMET:
1470  case BOOTS:
1471  case GLOVES:
1472  case CLOAK:
1473  if (tmp->stats.wc)
1474  wc -= tmp->stats.wc;
1475  if (tmp->stats.dam)
1476  op->stats.dam += (tmp->stats.dam+tmp->magic);
1477  if (tmp->stats.ac)
1478  ac -= (tmp->stats.ac+tmp->magic);
1479  break;
1480 
1481  case WEAPON:
1482  wc -= tmp->stats.wc;
1483  if (tmp->stats.ac && tmp->stats.ac+tmp->magic > 0)
1484  ac -= tmp->stats.ac+tmp->magic;
1485  op->stats.dam += (tmp->stats.dam+tmp->magic);
1486  weapon_speed = ((int)WEAPON_SPEED(tmp)*2-tmp->magic)/2;
1487  if (weapon_speed < 0)
1488  weapon_speed = 0;
1489  if (tmp->slaying != NULL) {
1490  if (op->slaying != NULL)
1491  free_string(op->slaying);
1492  add_refcount(op->slaying = tmp->slaying);
1493  }
1494  /* If there is desire that two handed weapons should do
1495  * extra strength damage, this is where the code should
1496  * go.
1497  */
1498  op->current_weapon = tmp;
1499  if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1500  op->contr->encumbrance += (int)3*tmp->weight/1000;
1501  break;
1502 
1503  case ARMOUR: /* Only the best of these three are used: */
1504  if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1505  op->contr->encumbrance += (int)tmp->weight/1000;
1506 
1507  /* ARMOUR falls through to here */
1508  /* fall through */
1509  case BRACERS:
1510  case FORCE:
1511  // Code simplification to reduce branching -- we don't need to sub/add ac and wc all the time.
1512  // Neila Hawkins 2018-05-28
1513  if (tmp->stats.wc) {
1514  // Since we are alreay here, make sure wc stacking also occurs for serpentman players.
1515  if (tmp->type == BRACERS && op->type == PLAYER && op->arch->name && strcmp(op->arch->name, "serpentman_player") == 0)
1516  {
1517  // Apply ac from bracers directly.
1518  // This also grants the side effect that armor and bracer ac are separate for serpentmen,
1519  // But that should be better than the extra bracers being mostly useless.
1520  wc -= tmp->stats.wc;
1521  }
1522  else if (best_wc < tmp->stats.wc) {
1523  wc += best_wc;
1524  best_wc = tmp->stats.wc;
1525  wc -= tmp->stats.wc;
1526  }
1527  }
1528  if (tmp->stats.ac) {
1529  /*
1530  * If we have a serpentman player, then we do bracers differently
1531  * to allow for both bracers they equip to apply to ac, instead of only the best.
1532  *
1533  * Neila Hawkins 2018-05-28
1534  */
1535  if (tmp->type == BRACERS && op->type == PLAYER && op->arch->name && strcmp(op->arch->name, "serpentman_player") == 0)
1536  {
1537  // Apply ac from bracers directly.
1538  // This also grants the side effect that armor and bracer ac are separate for serpentmen,
1539  // But that should be better than the extra bracers being mostly useless.
1540  ac -= tmp->stats.ac+tmp->magic;
1541  }
1542  else if (best_ac < tmp->stats.ac+tmp->magic) {
1543  ac += best_ac; /* Remove last bonus */
1544  best_ac = tmp->stats.ac+tmp->magic;
1545  ac -= (tmp->stats.ac+tmp->magic);
1546  }
1547  }
1548  if (tmp->stats.dam && tmp->type == BRACERS)
1549  op->stats.dam += (tmp->stats.dam+tmp->magic);
1550  if (ARMOUR_SPEED(tmp) && ARMOUR_SPEED(tmp)/10.0 < max)
1551  max = ARMOUR_SPEED(tmp)/10.0;
1552  break;
1553  } /* switch tmp->type */
1554  } /* item is equipped */
1555  } FOR_INV_FINISH(); /* for loop of items */
1556 
1557  /* We've gone through all the objects the player has equipped. For many things, we
1558  * have generated intermediate values which we now need to assign.
1559  */
1560 
1561  /* 'total resistance = total protections - total vulnerabilities'.
1562  * If there is an uncursed potion in effect, granting more protection
1563  * than that, we take: 'total resistance = resistance from potion'.
1564  * If there is a cursed (and no uncursed) potion in effect, we take
1565  * 'total resistance = vulnerability from cursed potion'.
1566  */
1567  for (i = 0; i < NROFATTACKS; i++) {
1568  op->resist[i] = prot[i]-vuln[i];
1569  if (potion_resist[i]
1570  && ((potion_resist[i] > op->resist[i]) || (potion_resist[i] < 0)))
1571  op->resist[i] = potion_resist[i];
1572  }
1573 
1574  fix_player(op, &ac, &wc, grace_obj, mana_obj, wc_obj, weapon_speed, added_speed);
1575 
1576  op->speed = op->speed*speed_reduce_from_disease;
1577 
1578  /* Max is determined by armour */
1579  if (op->speed > max)
1580  op->speed = max;
1581 
1582  op->speed += added_speed/10.0;
1583 
1584 
1585  /* Put a lower limit on speed. Note with this speed, you move once every
1586  * 20 ticks or so. This amounts to once every 3 seconds of realtime.
1587  */
1588  if (op->speed < 0.05 && op->type == PLAYER)
1589  op->speed = 0.05;
1590  /*
1591  * A lower limit should also apply to monsters. By ensuring speeds are
1592  * loaded in as positive, we can properly do this. Otherwise, slow effects
1593  * either push the monster's speed to be more negative (if we leave the input
1594  * speed as negative) or can reduce the speed by more than the monster's speed,
1595  * making it turn negative (if we load speeds as positive always).
1596  *
1597  * For whatever reason, op->type is 0 for some monsters, making FLAG_MONSTER
1598  * the useful information that indicates whether it is a monster or not.
1599  *
1600  * MIN_ACTIVE_SPEED is super low, so make our speed threshold be about .005 instead
1601  */
1602  if (op->speed < MIN_ACTIVE_SPEED*500 && QUERY_FLAG(op, FLAG_MONSTER)) {
1603  // If added_speed is less than zero, we're probably working with a slow effect.
1604  if (added_speed > 0)
1605  LOG(llevInfo, "fix_object: Monster %s has negative speed of %f.\n",
1606  op->name ? op->name : "(null)", op->speed);
1607  op->speed = MIN_ACTIVE_SPEED*500;
1608  }
1609 
1610  /* I want to limit the power of small monsters with big weapons: */
1611  if (op->type != PLAYER
1612  && op->stats.dam > op->arch->clone.stats.dam*3)
1613  op->stats.dam = op->arch->clone.stats.dam*3;
1614 
1615  /* Prevent overflows of wc - best you can get is ABS(120) - this
1616  * should be more than enough - remember, AC is also in 8 bits,
1617  * so its value is the same.
1618  */
1619  if (wc > 120)
1620  wc = 120;
1621  else if (wc < -120)
1622  wc = -120;
1623  op->stats.wc = wc;
1624 
1625  if (ac > 120)
1626  ac = 120;
1627  else if (ac < -120)
1628  ac = -120;
1629  op->stats.ac = ac;
1630 
1631  /* if for some reason the creature doesn't have any move type,
1632  * give them walking as a default.
1633  * The second case is a special case - to more closely mimic the
1634  * old behaviour - if your flying, your not walking - just
1635  * one or the other.
1636  */
1637  if (op->move_type == 0)
1638  op->move_type = MOVE_WALK;
1639  else if (op->move_type&(MOVE_FLY_LOW|MOVE_FLY_HIGH))
1640  op->move_type &= ~MOVE_WALK;
1641 
1643 }
1644 
1657 int allowed_class(const object *op) {
1658  return op->stats.Dex > 0
1659  && op->stats.Str > 0
1660  && op->stats.Con > 0
1661  && op->stats.Int > 0
1662  && op->stats.Wis > 0
1663  && op->stats.Pow > 0
1664  && op->stats.Cha > 0;
1665 }
1666 
1684 void set_dragon_name(object *pl, const object *abil, const object *skin) {
1685  int atnr = -1; /* attacknumber of highest level */
1686  int level = 0; /* highest level */
1687  int i;
1688 
1689  /* Perhaps do something more clever? */
1690  if (!abil || !skin)
1691  return;
1692 
1693  /* first, look for the highest level */
1694  for (i = 0; i < NROFATTACKS; i++) {
1695  if (atnr_is_dragon_enabled(i)
1696  && (atnr == -1 || abil->resist[i] > abil->resist[atnr])) {
1697  level = abil->resist[i];
1698  atnr = i;
1699  }
1700  }
1701 
1702  /* now if there are equals at highest level, pick the one with focus,
1703  or else at random */
1704  if (atnr_is_dragon_enabled(abil->stats.exp)
1705  && abil->resist[abil->stats.exp] >= level)
1706  atnr = abil->stats.exp;
1707 
1708  level = (int)(level/5.);
1709 
1710  /* now set the new title */
1711  if (pl->contr != NULL) {
1712  player_set_dragon_title(pl->contr, level, attacks[atnr], skin->resist[atnr]);
1713  }
1714 }
1715 
1724 static void dragon_level_gain(object *who) {
1725  object *abil = NULL; /* pointer to dragon ability force*/
1726  object *skin = NULL; /* pointer to dragon skin force*/
1727 
1728  /* now grab the 'dragon_ability'-forces from the player's inventory */
1729  abil = object_find_by_type_and_arch_name(who, FORCE, "dragon_ability_force");
1730  skin = object_find_by_type_and_arch_name(who, FORCE, "dragon_skin_force");
1731  /* if the force is missing -> bail out */
1732  if (abil == NULL)
1733  return;
1734 
1735  /* The ability_force keeps track of maximum level ever achieved.
1736  * New abilties can only be gained by surpassing this max level
1737  */
1738  if (who->level > abil->level) {
1739  /* increase our focused ability */
1740  int lev = ++(abil->resist[abil->stats.exp]);
1741 
1742  if (lev > 0) {
1743  /* try to hand out a new ability-gift
1744  * if not the right level, this will handout nothing.
1745  */
1746  dragon_ability_gain(who, (int)abil->stats.exp, lev);
1747  }
1748 
1749  if (abil->last_eat > 0 && atnr_is_dragon_enabled(abil->last_eat)) {
1750  /* apply new ability focus */
1752  "Your metabolism now focuses on %s!",
1753  change_resist_msg[abil->last_eat]);
1754 
1755  abil->stats.exp = abil->last_eat;
1756  abil->last_eat = 0;
1757  }
1758 
1759  abil->level = who->level;
1760  }
1761 
1762  /* last but not least, set the new title for the dragon */
1763  set_dragon_name(who, abil, skin);
1764 }
1765 
1784 object *give_skill_by_name(object *op, const char *skill_name) {
1785  object *skill_obj;
1786  archetype *skill_arch;
1787 
1788  skill_arch = get_archetype_by_skill_name(skill_name, SKILL);
1789  if (!skill_arch) {
1790  LOG(llevError, "add_player_exp: couldn't find skill %s\n", skill_name);
1791  return NULL;
1792  }
1793  skill_obj = arch_to_object(skill_arch); /* never returns NULL. */
1794 
1795  /* clear the flag - exp goes into this bucket, but player
1796  * still doesn't know it.
1797  */
1798  CLEAR_FLAG(skill_obj, FLAG_CAN_USE_SKILL);
1799  skill_obj->stats.exp = 0;
1800  skill_obj->level = 1;
1801  // If we inexplicably have the skill (due to a skill merge bug, for example)
1802  // not reassigning skill_obj results in us pointing to a freed object.
1803  skill_obj = object_insert_in_ob(skill_obj, op);
1804  if (op->contr) {
1806  }
1807  return skill_obj;
1808 }
1809 
1826 void player_lvl_adj(object *who, object *op) {
1827  char buf[MAX_BUF];
1828 
1829  assert(who);
1830 
1831  if (!op) /* when rolling stats */
1832  op = who;
1833 
1834  if (op->level < settings.max_level && op->stats.exp >= level_exp(op->level+1, who->expmul)) {
1835  do{
1836  op->level++;
1837 
1838  if (op == who && op->stats.exp > 1 && is_dragon_pl(who))
1840 
1841  /* Only roll these if it is the player (who) that gained the level */
1842  if (op == who && (who->level < 11) && who->type == PLAYER) {
1843  who->contr->levhp[who->level] = die_roll(2, 4, who, PREFER_HIGH)+1;
1844  who->contr->levsp[who->level] = die_roll(2, 3, who, PREFER_HIGH);
1845  who->contr->levgrace[who->level] = die_roll(2, 2, who, PREFER_HIGH)-1;
1846  }
1847 
1848  fix_object(who); // TODO: Call this only once per function call?
1849  if (op->level > 1) {
1850  if (op->type != PLAYER)
1851  snprintf(buf, sizeof(buf), "You are now level %d in the %s skill.", op->level, op->name);
1852  else
1853  snprintf(buf, sizeof(buf), "You are now level %d.", op->level);
1854 
1856  }
1857  } while (op->level < settings.max_level && op->stats.exp >= level_exp(op->level+1, who->expmul)); /* To increase more levels */
1858  } else if (op->level > 1 && op->stats.exp < level_exp(op->level, who->expmul)) {
1859  do{
1860  op->level--;
1861  fix_object(who); // TODO: Call this only once per function call?
1862  if (op->type != PLAYER)
1863  snprintf(buf, sizeof(buf), "You are now level %d in the %s skill.", op->level, op->name);
1864  else
1865  snprintf(buf, sizeof(buf), "You are now level %d.", op->level);
1866 
1868  } while (op->level > 1 && op->stats.exp < level_exp(op->level, who->expmul)); /* To decrease more levels */
1869  }
1870 }
1871 
1881 int64_t level_exp(int level, double expmul) {
1882  if (level > settings.max_level)
1883  return expmul*levels[settings.max_level];
1884  return expmul*levels[level];
1885 }
1886 
1893 int exp_level(int64_t exp) {
1894  int level = 1;
1895  while ( level < settings.max_level && levels[level+1] <= exp )
1896  ++level;
1897  return level;
1898 }
1899 
1910 void calc_perm_exp(object *op) {
1911  if (op->total_exp < op->stats.exp)
1912  op->total_exp = op->stats.exp;
1913 
1914  /* Cap permanent experience. */
1915  if (op->total_exp < 0)
1916  op->total_exp = 0;
1917  else if (op->total_exp > MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio)
1918  op->total_exp = MAX_EXPERIENCE * 100 / settings.permanent_exp_ratio;
1919 }
1920 
1928 object* find_applied_skill_by_name(const object* op, const char* name) {
1929  for (int i = 0; i < MAX_SKILLS; i++) {
1930  if (op->contr->last_skill_ob[i] != NULL) {
1931  // Skill objects can be removed without updating last_skill_ob. Clean
1932  // them up here if that's the case.
1933  if (QUERY_FLAG(op->contr->last_skill_ob[i], FLAG_REMOVED)) {
1934  LOG(llevDebug, "pruning removed object from last_skill_ob\n");
1935  op->contr->last_skill_ob[i] = NULL;
1936  continue;
1937  }
1938 
1939  if (op->contr->last_skill_ob[i]->skill != NULL) {
1940  if (!strcmp(op->contr->last_skill_ob[i]->skill, name)) {
1941  return op->contr->last_skill_ob[i];
1942  }
1943  } else {
1944  LOG(llevError,
1945  "%s's skill object %s does not have a skill name\n",
1946  op->name, op->contr->last_skill_ob[i]->name);
1947  }
1948  }
1949  }
1950  return NULL;
1951 }
1952 
1967 static void add_player_exp(object *op, int64_t exp, const char *skill_name, int flag) {
1968  object *skill_obj = NULL;
1969  int64_t limit, exp_to_add;
1970  int64_t added_skill_exp = 0, added_skill_total_exp = 0;
1971 
1972  /* prevents some forms of abuse. */
1973  if (op->contr->braced)
1974  exp = exp/5;
1975 
1976  /* Try to find the matching skill.
1977  * We do a shortcut/time saving mechanism first - see if it matches
1978  * chosen_skill. This means we don't need to search through
1979  * the players inventory.
1980  */
1981  if (skill_name) {
1982  if (op->chosen_skill
1983  && op->chosen_skill->type == SKILL
1984  && !strcmp(skill_name, op->chosen_skill->skill))
1985  skill_obj = op->chosen_skill;
1986  else {
1987  skill_obj = find_applied_skill_by_name(op, skill_name);
1988 
1989  /* Player doesn't have the skill. Check to see what to do, and give
1990  * it to the player if necessary
1991  */
1992  if (!skill_obj) {
1993  if (flag == SK_EXP_NONE)
1994  return;
1995  else if (flag == SK_EXP_ADD_SKILL)
1996  skill_obj = give_skill_by_name(op, skill_name);
1997  }
1998  }
1999  }
2000 
2001  /* Basically, you can never gain more experience in one shot
2002  * than half what you need to gain for next level.
2003  */
2004  exp_to_add = exp;
2005  /*
2006  * Make sure we aren't trying to go backwards when we hit maximum level,
2007  * but make sure we can still add to our permanent experience.
2008  *
2009  * -- Neila Hawkins 2015-05-24
2010  */
2011  if (op->level == settings.max_level)
2012  limit = levels[op->level] / 2;
2013  else
2014  limit = (levels[op->level+1]-levels[op->level])/2;
2015 
2016  if (exp_to_add > limit)
2017  exp_to_add = limit;
2018 
2019  if (skill_obj) {
2020  exp_to_add = exp;
2021  /*
2022  * Make sure we aren't trying to go backwards when we hit maximum level,
2023  * but make sure we can still add to our permanent experience.
2024  *
2025  * -- Neila Hawkins 2015-05-24
2026  */
2027  if (skill_obj->level == settings.max_level)
2028  limit = levels[skill_obj->level] / 2;
2029  else
2030  limit = (levels[skill_obj->level+1]-levels[skill_obj->level])/2;
2031 
2032  if (exp_to_add > limit)
2033  exp_to_add = limit;
2034  added_skill_exp = skill_obj->stats.exp;
2035  ADD_EXP(skill_obj->stats.exp, exp_to_add);
2036  added_skill_exp = skill_obj->stats.exp - added_skill_exp;
2038  added_skill_total_exp = skill_obj->total_exp;
2039  ADD_TOTALEXP(skill_obj->total_exp, exp_to_add);
2040  added_skill_total_exp = skill_obj->total_exp - added_skill_total_exp;
2041  calc_perm_exp(skill_obj);
2042  }
2043  player_lvl_adj(op, skill_obj);
2044  }
2045  else {
2046  added_skill_exp = added_skill_total_exp = exp_to_add;
2047  }
2048 
2049  ADD_EXP(op->stats.exp, (float)added_skill_exp*(skill_obj ? skill_obj->expmul : 1));
2051  ADD_TOTALEXP(op->total_exp, (float)added_skill_total_exp*(skill_obj ? skill_obj->expmul : 1));
2052  calc_perm_exp(op);
2053  }
2054 
2055  player_lvl_adj(op, NULL);
2056 }
2057 
2073 int64_t check_exp_loss(const object *op, int64_t exp) {
2074  int64_t del_exp;
2075 
2076  if (exp > op->stats.exp)
2077  exp = op->stats.exp;
2079  del_exp = (op->stats.exp-PERM_EXP(op->total_exp))*PERM_EXP_MAX_LOSS_RATIO;
2080  if (del_exp < 0)
2081  del_exp = 0;
2082  if (exp > del_exp)
2083  exp = del_exp;
2084  }
2085  return exp;
2086 }
2087 
2098 int64_t check_exp_adjust(const object *op, int64_t exp) {
2099  if (exp < 0)
2100  return check_exp_loss(op, exp);
2101  else
2102  return MIN(exp, MAX_EXPERIENCE-op->stats.exp);
2103 }
2104 
2127 static void subtract_player_exp(object *op, int64_t exp, const char *skill, int flag) {
2128  float fraction = (float)exp/(float)op->stats.exp;
2129  int64_t del_exp;
2130 
2132  if (tmp->type == SKILL && tmp->stats.exp) {
2133  if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp(tmp->skill, skill)) {
2134  del_exp = check_exp_loss(tmp, exp);
2135  tmp->stats.exp -= del_exp;
2136  player_lvl_adj(op, tmp);
2137  } else if (flag != SK_SUBTRACT_SKILL_EXP) {
2138  /* only want to process other skills if we are not trying
2139  * to match a specific skill.
2140  */
2141  del_exp = check_exp_loss(tmp, tmp->stats.exp*fraction);
2142  tmp->stats.exp -= del_exp;
2143  player_lvl_adj(op, tmp);
2144  }
2145  }
2146  FOR_INV_FINISH();
2147  if (flag != SK_SUBTRACT_SKILL_EXP) {
2148  del_exp = check_exp_loss(op, exp);
2149  op->stats.exp -= del_exp;
2150  player_lvl_adj(op, NULL);
2151  }
2152 }
2153 
2175 void change_exp(object *op, int64_t exp, const char *skill_name, int flag) {
2176  /* safety */
2177  if (!op) {
2178  LOG(llevError, "change_exp() called for null object!\n");
2179  return;
2180  }
2181 
2182  /* if no change in exp, just return - most of the below code
2183  * won't do anything if the value is 0 anyways.
2184  */
2185  if (exp == 0)
2186  return;
2187 
2188  /* Monsters are easy - we just adjust their exp - we
2189  * don't adjust level, since in most cases it is unrelated to
2190  * the exp they have - the monsters exp represents what its
2191  * worth.
2192  */
2193  if (op->type != PLAYER && op->type != WEAPON) {
2194  /* Sanity check */
2195  if (!QUERY_FLAG(op, FLAG_ALIVE))
2196  return;
2197 
2198  /* reset exp to max allowed value. We subtract from
2199  * MAX_EXPERIENCE to prevent overflows. If the player somehow has
2200  * more than max exp, just return.
2201  */
2202  if (exp > 0 && (op->stats.exp > (MAX_EXPERIENCE-exp))) {
2203  exp = MAX_EXPERIENCE-op->stats.exp;
2204  if (exp < 0)
2205  return;
2206  }
2207 
2208  op->stats.exp += exp;
2209  } else if (op->type == WEAPON) { /* Weapons -- this allows us to make magic weapons that get stronger the more they are used. */
2210  // Handle adding exp -- Don't use level because other stuff already uses that.
2211  // The caller should determine what percentage of base exp this is.
2212  ADD_TOTALEXP(op->total_exp, exp);
2213  if (exp > 0) {
2214  // Check for a level-up
2215  while (level_exp(op->item_power+1, 1) < op->total_exp) {
2216  ++(op->item_power);
2217  }
2218  } else { /* Removing exp allows for the weapon's power to be reset if needed. */
2219  // Recalculate level
2220  while (level_exp(op->item_power, 1) > op->total_exp) {
2221  --(op->item_power);
2222  }
2223  }
2224  } else { /* Players only */
2225  if (exp > 0)
2226  add_player_exp(op, exp, skill_name, flag);
2227  else
2228  subtract_player_exp(op, FABS(exp), skill_name, flag);
2229  }
2230 }
2231 
2241  int64_t loss;
2242  int64_t percentage_loss; /* defined by the setting 'death_penalty_percent' */
2243  int64_t level_loss; /* defined by the setting 'death_penalty_levels */
2244 
2246  if (tmp->type == SKILL && tmp->stats.exp) {
2247  percentage_loss = tmp->stats.exp*settings.death_penalty_ratio/100;
2248  level_loss = tmp->stats.exp-levels[MAX(0, tmp->level-settings.death_penalty_level)];
2249 
2250  /* With the revised exp system, you can get cases where
2251  * losing several levels would still require that you have more
2252  * exp than you currently have - this is true if the levels
2253  * tables is a lot harder.
2254  */
2255  if (level_loss < 0)
2256  level_loss = 0;
2257 
2258  loss = check_exp_loss(tmp, MIN(level_loss, percentage_loss));
2259 
2260  tmp->stats.exp -= loss;
2261  player_lvl_adj(op, tmp);
2262  }
2263  FOR_INV_FINISH();
2264 
2265  percentage_loss = op->stats.exp*settings.death_penalty_ratio/100;
2266  level_loss = op->stats.exp-levels[MAX(0, op->level-settings.death_penalty_level)];
2267  if (level_loss < 0)
2268  level_loss = 0;
2269  loss = check_exp_loss(op, MIN(level_loss, percentage_loss));
2270 
2271  op->stats.exp -= loss;
2272  player_lvl_adj(op, NULL);
2273 }
2274 
2289 int did_make_save(const object *op, int level, int bonus) {
2290  if (level > MAX_SAVE_LEVEL)
2292 
2293  if ((random_roll(1, 20, op, PREFER_HIGH)+bonus) < savethrow[level])
2294  return 0;
2295  return 1;
2296 }
2297 
2319 void share_exp(object *op, int64_t exp, const char *skill, int flag) {
2320  int shares = 0, count = 0;
2321  player *pl;
2322  partylist *party;
2323 
2324  if (op->type != PLAYER || op->contr->party == NULL) {
2325  change_exp(op, exp, skill, 0);
2326  return;
2327  }
2328 
2329  party = op->contr->party;
2330 
2331  for (pl = first_player; pl != NULL; pl = pl->next) {
2332  if (party && pl->ob->contr->party == party && on_same_map(pl->ob, op)) {
2333  count++;
2334  shares += (pl->ob->level+4);
2335  }
2336  }
2337 
2338  assert(shares > 0);
2339 
2340  if (count == 1 || shares > exp)
2341  change_exp(op, exp, skill, flag);
2342  else {
2343  int64_t share = exp/shares, given = 0, nexp;
2344  for (pl = first_player; pl != NULL; pl = pl->next) {
2345  if (party && pl->ob->contr->party == party && on_same_map(pl->ob, op)) {
2346  nexp = (pl->ob->level+4)*share;
2347  change_exp(pl->ob, nexp, skill, SK_EXP_TOTAL);
2348  given += nexp;
2349  }
2350  }
2351  exp -= given;
2352  /* give any remainder to the player */
2353  change_exp(op, exp, skill, flag);
2354  }
2355 }
2356 
2357 int get_cha_bonus(int stat) {
2359 }
2360 
2361 int get_dex_bonus(int stat) {
2363 }
2364 
2365 int get_thaco_bonus(int stat) {
2367 }
2368 
2369 uint32_t get_weight_limit(int stat) {
2371 }
2372 
2373 int get_learn_spell(int stat) {
2375 }
2376 
2377 int get_cleric_chance(int stat) {
2379 }
2380 
2381 int get_turn_bonus(int stat) {
2383 }
2384 
2385 int get_dam_bonus(int stat) {
2387 }
2388 
2389 float get_speed_bonus(int stat) {
2391 }
2392 
2393 int get_fear_bonus(int stat) {
2395 }
2396 
2397 static float get_con_bonus(int stat) {
2399 }
2400 
2401 static float get_sp_bonus(int stat) {
2403 }
2404 
2405 static float get_grace_bonus(int stat) {
2407 }
2408 
2417 static size_t get_index(int stat, size_t max_index) {
2418  size_t index;
2419 
2420  if (stat < 0) {
2421  return 0;
2422  }
2423 
2424  index = (size_t)stat;
2425  return MIN(index, max_index);
2426 }
2427 
2445 static int load_table_int(int **bonuses, FILE *fp, char *bonus_name)
2446 {
2447  char buf[MAX_BUF], *cp;
2448  int on_stat = 0, tmp_bonus;
2449 
2450  *bonuses = static_cast<int *>(calloc(settings.max_stat+1, sizeof(int)));
2451 
2452  while (fgets(buf, MAX_BUF-1, fp) != NULL) {
2453  if (buf[0] == '#')
2454  continue;
2455 
2456  /* Skip over empty lines */
2457  if (buf[0] == '\n')
2458  continue;
2459 
2460  /* Do not care about opening brace */
2461  if (buf[0] == '{')
2462  continue;
2463 
2464  if (buf[0] == '}') {
2465  if ((on_stat-1) != settings.max_stat) {
2466  LOG(llevError,"Number of bonus does not match max stat (%d!=%d, bonus=%s)\n",
2467  on_stat, settings.max_stat, bonus_name);
2468  return 1;
2469  }
2470  else return 0;
2471  }
2472 
2473  /* If not any of the above values, must be the stat table,
2474  * or so we hope.
2475  */
2476  cp = buf;
2477  while (*cp != 0) {
2478  /* Skip over any non numbers */
2479  while (!isdigit(*cp) && *cp!='.' && *cp!='-' && *cp!='+' && *cp != 0)
2480  cp++;
2481 
2482  if (*cp == 0) break;
2483 
2484  tmp_bonus = atoi(cp);
2485 
2486  if (on_stat > settings.max_stat) {
2487  LOG(llevError,"Number of bonus entries exceed max stat (line=%s, bonus=%s)\n",
2488  buf, bonus_name);
2489  return 1;
2490  }
2491  (*bonuses)[on_stat] = tmp_bonus;
2492  on_stat++;
2493 
2494  /* Skip over any digits, as that is the number we just processed */
2495  while ((isdigit(*cp) || *cp=='-' || *cp=='+') && *cp != 0)
2496  cp++;
2497  }
2498  }
2499  /* This should never happen - we should always get the closing brace */
2500  LOG(llevError,"Reached end of file without getting close brace? bonus=%s\n", bonus_name);
2501  return 1;
2502 }
2503 
2521 static int load_table_float(float **bonuses, FILE *fp, char *bonus_name)
2522 {
2523  char buf[MAX_BUF], *cp;
2524  int on_stat = 0;
2525  float tmp_bonus;
2526 
2527  *bonuses = static_cast<float *>(calloc(settings.max_stat+1, sizeof(float)));
2528 
2529  while (fgets(buf, MAX_BUF-1, fp) != NULL) {
2530  if (buf[0] == '#')
2531  continue;
2532 
2533  /* Skip over empty lines */
2534  if (buf[0] == '\n')
2535  continue;
2536 
2537  /* Do not care about opening brace */
2538  if (buf[0] == '{')
2539  continue;
2540 
2541  if (buf[0] == '}') {
2542  if ((on_stat-1) != settings.max_stat) {
2543  LOG(llevError,"Number of bonus does not match max stat (%d!=%d, bonus=%s)\n",
2544  on_stat, settings.max_stat, bonus_name);
2545  return 1;
2546  }
2547  else return 0;
2548  }
2549 
2550  /* If not any of the above values, must be the stat table,
2551  * or so we hope.
2552  */
2553  cp = buf;
2554  while (*cp != 0) {
2555  /* Skip over any non numbers */
2556  while (!isdigit(*cp) && *cp!='.' && *cp!='-' && *cp!='+' && *cp != 0)
2557  cp++;
2558 
2559  if (*cp == 0) break;
2560 
2561  tmp_bonus = atof(cp);
2562 
2563  if (on_stat > settings.max_stat) {
2564  LOG(llevError,"Number of bonus entries exceed max stat (line=%s, bonus=%s)\n",
2565  buf, bonus_name);
2566  return 1;
2567  }
2568  (*bonuses)[on_stat] = tmp_bonus;
2569  on_stat++;
2570 
2571  /* Skip over any digits, as that is the number we just processed
2572  * since this is floats, also skip over any dots.
2573  */
2574  while ((isdigit(*cp) || *cp=='-' || *cp=='+' || *cp=='.') && *cp != 0)
2575  cp++;
2576  }
2577  }
2578  /* This should never happen - we should always get the closing brace */
2579  LOG(llevError,"Reached end of file without getting close brace? bonus=%s\n", bonus_name);
2580  return 1;
2581 }
2582 
2583 
2591 void init_stats() {
2592  char buf[MAX_BUF], *cp;
2593  int error=0, i;
2594  FILE *fp;
2595  float *new_float_bonuses[NUM_FLOAT_BONUSES];
2596  int *new_int_bonuses[NUM_INT_BONUSES];
2597 
2598  snprintf(buf, sizeof(buf), "%s/stat_bonus", settings.confdir);
2599 
2600  memset(new_int_bonuses, 0, NUM_INT_BONUSES * sizeof(int));
2601  memset(new_float_bonuses, 0, NUM_FLOAT_BONUSES * sizeof(float));
2602 
2603  if ((fp = fopen(buf, "r")) == NULL) {
2604  LOG(llevError, "Fatal error: could not open experience table (%s)\n", buf);
2605  exit(1);
2606  }
2607  while (fgets(buf, MAX_BUF-1, fp) != NULL) {
2608  if (buf[0] == '#')
2609  continue;
2610 
2611  /* eliminate newline */
2612  if ((cp = strrchr(buf, '\n')) != NULL)
2613  *cp = '\0';
2614 
2615  /* Skip over empty lines */
2616  if (buf[0] == 0)
2617  continue;
2618 
2619  /* Skip over leading spaces */
2620  cp = buf;
2621  while (isspace(*cp) && *cp != 0)
2622  cp++;
2623 
2624  if (!strncasecmp(cp, "max_stat", 8)) {
2625  int newmax = atoi(cp+8);
2626 
2627  /* newmax must be at least MIN_STAT and we do not currently
2628  * cupport decrease max stat on the fly - why this might be possible,
2629  * bounds checking for all objects would be needed, potentionally resetting
2630  * them.
2631  * If this is a reload, then on error, we just return without doing work.
2632  * If this is initial load, having an invalid stat range is an error, so
2633  * exit the program.
2634  */
2635  if (newmax < MIN_STAT || newmax < settings.max_stat) {
2636  LOG(llevError, "Got invalid max_stat (%d) from stat_bonus file\n", newmax);
2637  fclose(fp);
2638  exit(1);
2639  }
2640  settings.max_stat = newmax;
2641  continue;
2642  }
2643  /* max_stat needs to be set before any of the bonus values - we
2644  * need to know how large to make the array.
2645  */
2646  if (settings.max_stat == 0) {
2647  LOG(llevError, "Got bonus line or otherwise unknown value before max stat! (%s)\n",
2648  buf);
2649  fclose(fp);
2650  exit(1);
2651  }
2652 
2653  for (i=0; i<NUM_INT_BONUSES; i++) {
2654  if (!strncasecmp(cp, int_bonus_names[i], strlen(int_bonus_names[i]))) {
2655  error = load_table_int(&new_int_bonuses[i], fp, cp);
2656  break;
2657  }
2658  }
2659  /* If we did not find a match in the int bonuses, check the
2660  * float bonuses now.
2661  */
2662  if (i == NUM_INT_BONUSES) {
2663  for (i=0; i<NUM_FLOAT_BONUSES; i++) {
2664  if (!strncasecmp(cp, float_bonus_names[i], strlen(float_bonus_names[i]))) {
2665  error = load_table_float(&new_float_bonuses[i], fp, cp);
2666  break;
2667  }
2668  }
2669  /* This may not actually be a critical error */
2670  if (i == NUM_FLOAT_BONUSES) {
2671  LOG(llevError,"Unknown line in stat_bonus file: %s\n", buf);
2672  }
2673  }
2674  if (error) break;
2675  }
2676  fclose(fp);
2677 
2678  /* Make sure that we have load tables for all the bonuses.
2679  * This is critical on initial load, but on reloads, it enusres that
2680  * all the bonus data matches.
2681  */
2682  for (i=0; i<NUM_INT_BONUSES; i++) {
2683  if (!new_int_bonuses[i]) {
2684  LOG(llevError,"No bonus loaded for %s\n", int_bonus_names[i]);
2685  error=2;
2686  }
2687  }
2688 
2689  for (i=0; i<NUM_FLOAT_BONUSES; i++) {
2690  if (!new_float_bonuses[i]) {
2691  LOG(llevError,"No bonus loaded for %s\n", float_bonus_names[i]);
2692  error=2;
2693  }
2694  }
2695 
2696  /* If we got an error, we just free up the data we read in and return/exit.
2697  * if no error, we make the tables we just read in into the default
2698  * tables.
2699  */
2700  if (error) {
2701  if (error==1)
2702  LOG(llevError,"Got error reading stat_bonus: %s\n", buf);
2703  exit(1);
2704  } else {
2705  /* Everything check out - now copy the data into
2706  * the live arrays.
2707  */
2708  for (i=0; i<NUM_INT_BONUSES; i++) {
2709  free(int_bonuses[i]);
2710  int_bonuses[i] = new_int_bonuses[i];
2711  new_int_bonuses[i] = NULL;
2712  }
2713 
2714  for (i=0; i<NUM_FLOAT_BONUSES; i++) {
2715  free(float_bonuses[i]);
2716  float_bonuses[i] = new_float_bonuses[i];
2717  new_float_bonuses[i] = NULL;
2718  }
2719  }
2720 }
INT_THAC0_BONUS
#define INT_THAC0_BONUS
Definition: living.cpp:65
ADD_TOTALEXP
#define ADD_TOTALEXP(exptotal, exp)
Definition: living.cpp:42
fix_player
static void fix_player(object *op, int *ac, int *wc, const object *grace_obj, const object *mana_obj, const object *wc_obj, int weapon_speed, float added_speed)
Definition: living.cpp:897
living::exp
int64_t exp
Definition: living.h:47
get_grace_bonus
static float get_grace_bonus(int stat)
Definition: living.cpp:2405
PLAYER
@ PLAYER
Definition: object.h:112
global.h
get_cha_bonus
int get_cha_bonus(int stat)
Definition: living.cpp:2357
first_player
player * first_player
Definition: init.cpp:106
settings
struct Settings settings
Definition: init.cpp:139
Settings::max_level
int16_t max_level
Definition: global.h:302
DIFF_MSG
#define DIFF_MSG(flag, subtype1, subtype2, msg1, msg2)
Definition: living.cpp:369
NUM_BODY_LOCATIONS
#define NUM_BODY_LOCATIONS
Definition: object.h:15
FLAG_CONFUSED
#define FLAG_CONFUSED
Definition: define.h:311
BOW
@ BOW
Definition: object.h:123
BRACERS
@ BRACERS
Definition: object.h:222
levels
int64_t * levels
Definition: exp.cpp:26
find_applied_skill_by_name
object * find_applied_skill_by_name(const object *op, const char *name)
Definition: living.cpp:1928
CLOSE_CON
@ CLOSE_CON
Definition: object.h:234
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
SYMPTOM
@ SYMPTOM
Definition: object.h:250
WAND
@ WAND
Definition: object.h:225
range_bow
@ range_bow
Definition: player.h:31
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.cpp:58
FLAG_UNDEAD
#define FLAG_UNDEAD
Definition: define.h:270
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
drain_specific_stat
void drain_specific_stat(object *op, int deplete_stats)
Definition: living.cpp:728
player
Definition: player.h:105
GLOVES
@ GLOVES
Definition: object.h:218
GIRDLE
@ GIRDLE
Definition: object.h:228
get_fear_bonus
int get_fear_bonus(int stat)
Definition: living.cpp:2393
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
FLAG_REFL_MISSILE
#define FLAG_REFL_MISSILE
Definition: define.h:273
ARCH_DEPLETION
#define ARCH_DEPLETION
Definition: object.h:590
MSG_TYPE_ATTRIBUTE_ATTACKTYPE_GAIN
#define MSG_TYPE_ATTRIBUTE_ATTACKTYPE_GAIN
Definition: newclient.h:552
MSG_TYPE_ATTRIBUTE_LEVEL_GAIN
#define MSG_TYPE_ATTRIBUTE_LEVEL_GAIN
Definition: newclient.h:573
get_cleric_chance
int get_cleric_chance(int stat)
Definition: living.cpp:2377
FLOAT_SP_BONUS
#define FLOAT_SP_BONUS
Definition: living.cpp:87
FLAG_SEE_IN_DARK
#define FLAG_SEE_IN_DARK
Definition: define.h:337
MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END
#define MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END
Definition: newclient.h:577
Settings::permanent_exp_ratio
uint8_t permanent_exp_ratio
Definition: global.h:258
AT_PHYSICAL
#define AT_PHYSICAL
Definition: attack.h:76
if
if(!(yy_init))
Definition: loader.cpp:36428
NUM_FLOAT_BONUSES
#define NUM_FLOAT_BONUSES
Definition: living.cpp:89
float_bonuses
static float * float_bonuses[NUM_FLOAT_BONUSES]
Definition: living.cpp:90
living::Dex
int8_t Dex
Definition: living.h:36
ARMOUR
@ ARMOUR
Definition: object.h:125
int_bonus_names
static const char * int_bonus_names[NUM_INT_BONUSES]
Definition: living.cpp:75
give_skill_by_name
object * give_skill_by_name(object *op, const char *skill_name)
Definition: living.cpp:1784
WEAPON
@ WEAPON
Definition: object.h:124
arch_present_in_ob
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.cpp:3222
object::expmul
double expmul
Definition: object.h:407
SK_PRAYING
@ SK_PRAYING
Definition: skills.h:49
MSG_TYPE_ATTRIBUTE
#define MSG_TYPE_ATTRIBUTE
Definition: newclient.h:408
MSG_TYPE_ATTRIBUTE_PROTECTION_LOSS
#define MSG_TYPE_ATTRIBUTE_PROTECTION_LOSS
Definition: newclient.h:559
check_exp_adjust
int64_t check_exp_adjust(const object *op, int64_t exp)
Definition: living.cpp:2098
get_sp_bonus
static float get_sp_bonus(int stat)
Definition: living.cpp:2401
CHARISMA
@ CHARISMA
Definition: living.h:15
AMULET
@ AMULET
Definition: object.h:144
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
calc_perm_exp
void calc_perm_exp(object *op)
Definition: living.cpp:1910
MIN
#define MIN(x, y)
Definition: compat.h:21
gain_msg
const char *const gain_msg[NUM_STATS]
Definition: living.cpp:161
allowed_class
int allowed_class(const object *op)
Definition: living.cpp:1657
SKILL
@ SKILL
Definition: object.h:148
INT_WEIGHT_LIMIT
#define INT_WEIGHT_LIMIT
Definition: living.cpp:66
esrv_update_spells
void esrv_update_spells(player *pl)
Definition: main.cpp:386
fix_object
void fix_object(object *op)
Definition: living.cpp:1132
Ice.tmp
int tmp
Definition: Ice.py:207
NDI_RED
#define NDI_RED
Definition: newclient.h:248
FLOAT_CON_BONUS
#define FLOAT_CON_BONUS
Definition: living.cpp:85
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
POTION_RESIST_EFFECT
@ POTION_RESIST_EFFECT
Definition: object.h:230
ARMOUR_SPEED
#define ARMOUR_SPEED(xyz)
Definition: define.h:466
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
curse_on_apply.ac
ac
Definition: curse_on_apply.py:4
FLAG_PROBE
#define FLAG_PROBE
Definition: define.h:257
partylist
Definition: party.h:10
SK_EXP_NONE
#define SK_EXP_NONE
Definition: skills.h:80
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.cpp:4346
FLAG_APPLIED
#define FLAG_APPLIED
Definition: define.h:235
NDI_BLUE
#define NDI_BLUE
Definition: newclient.h:250
object::level
int16_t level
Definition: object.h:361
FLAG_STEALTH
#define FLAG_STEALTH
Definition: define.h:312
FLAG_BLIND
#define FLAG_BLIND
Definition: define.h:336
buf
StringBuffer * buf
Definition: readable.cpp:1565
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.cpp:2857
INT_TURN_BONUS
#define INT_TURN_BONUS
Definition: living.cpp:59
init_stats
void init_stats()
Definition: living.cpp:2591
MAX
#define MAX(x, y)
Definition: compat.h:24
WISDOM
@ WISDOM
Definition: living.h:14
MIN_PLAYER_SPEED
#define MIN_PLAYER_SPEED
Definition: config.h:96
object::resist
int16_t resist[NROFATTACKS]
Definition: object.h:351
lose_msg
const char *const lose_msg[NUM_STATS]
Definition: living.cpp:172
MIN_STAT
#define MIN_STAT
Definition: define.h:33
dragon_ability_gain
void dragon_ability_gain(object *who, int atnr, int level)
Definition: main.cpp:365
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
add_statbonus
void add_statbonus(object *op)
Definition: living.cpp:868
short_stat_name
const char *const short_stat_name[NUM_STATS]
Definition: living.cpp:194
load_table_int
static int load_table_int(int **bonuses, FILE *fp, char *bonus_name)
Definition: living.cpp:2445
Settings::spell_encumbrance
uint8_t spell_encumbrance
Definition: global.h:268
autojail.who
who
Definition: autojail.py:3
CLOAK
@ CLOAK
Definition: object.h:209
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
PREFER_HIGH
#define PREFER_HIGH
Definition: define.h:563
HELMET
@ HELMET
Definition: object.h:141
MSG_TYPE_ATTRIBUTE_STAT_LOSS
#define MSG_TYPE_ATTRIBUTE_STAT_LOSS
Definition: newclient.h:572
add_refcount
sstring add_refcount(sstring str)
Definition: shstr.cpp:210
MSG_TYPE_ATTRIBUTE_RACE
#define MSG_TYPE_ATTRIBUTE_RACE
Definition: newclient.h:567
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_START
Definition: newclient.h:568
Settings::death_penalty_ratio
uint8_t death_penalty_ratio
Definition: global.h:259
NUM_INT_BONUSES
#define NUM_INT_BONUSES
Definition: living.cpp:67
MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN
#define MSG_TYPE_ATTRIBUTE_PROTECTION_GAIN
Definition: newclient.h:558
POTION
@ POTION
Definition: object.h:116
subtract_player_exp
static void subtract_player_exp(object *op, int64_t exp, const char *skill, int flag)
Definition: living.cpp:2127
MOVE_WALK
#define MOVE_WALK
Definition: define.h:392
add_string
sstring add_string(const char *str)
Definition: shstr.cpp:124
FLOAT_DEX_BONUS
#define FLOAT_DEX_BONUS
Definition: living.cpp:86
ROD
@ ROD
Definition: object.h:114
CONTAINER
@ CONTAINER
Definition: object.h:236
object::move_type
MoveType move_type
Definition: object.h:436
set_attr_value
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.cpp:218
load_table_float
static int load_table_float(float **bonuses, FILE *fp, char *bonus_name)
Definition: living.cpp:2521
MSG_TYPE_ATTRIBUTE_STAT_GAIN
#define MSG_TYPE_ATTRIBUTE_STAT_GAIN
Definition: newclient.h:571
exp_level
int exp_level(int64_t exp)
Definition: living.cpp:1893
FLAG_MAKE_INVIS
#define FLAG_MAKE_INVIS
Definition: define.h:328
object::last_eat
int32_t last_eat
Definition: object.h:366
change_resist_msg
const char *const change_resist_msg[NROFATTACKS]
Definition: init.cpp:70
MSG_TYPE_ATTRIBUTE_MOVE
#define MSG_TYPE_ATTRIBUTE_MOVE
Definition: newclient.h:565
POWER
@ POWER
Definition: living.h:17
object_update_speed
void object_update_speed(object *op)
Definition: object.cpp:1349
IS_GRACE_SKILL
#define IS_GRACE_SKILL(num)
Definition: skills.h:120
player_lvl_adj
void player_lvl_adj(object *who, object *op)
Definition: living.cpp:1826
INT_CHA_BONUS
#define INT_CHA_BONUS
Definition: living.cpp:62
get_index
static size_t get_index(int stat, size_t max_index)
Definition: living.cpp:2417
FOR_INV_FINISH
#define FOR_INV_FINISH()
Definition: define.h:677
change_exp
void change_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.cpp:2175
int_bonuses
static int * int_bonuses[NUM_INT_BONUSES]
Definition: living.cpp:69
disinfect.count
int count
Definition: disinfect.py:7
say.max
dictionary max
Definition: say.py:148
dragon_level_gain
static void dragon_level_gain(object *who)
Definition: living.cpp:1724
level_exp
int64_t level_exp(int level, double expmul)
Definition: living.cpp:1881
archetype
Definition: object.h:483
Settings::confdir
const char * confdir
Definition: global.h:247
sproto.h
drain_msg
const char *const drain_msg[NUM_STATS]
Definition: living.cpp:139
statname
const char *const statname[NUM_STATS]
Definition: living.cpp:183
MAX_SKILLS
#define MAX_SKILLS
Definition: skills.h:70
FLAG_CAN_USE_SKILL
#define FLAG_CAN_USE_SKILL
Definition: define.h:321
IS_COMBAT_SKILL
#define IS_COMBAT_SKILL(num)
Definition: skills.h:91
living::Int
int8_t Int
Definition: living.h:36
random_roll
int random_roll(int min, int max, const object *op, int goodbad)
Definition: utils.cpp:42
RING
@ RING
Definition: object.h:190
add_player_exp
static void add_player_exp(object *op, int64_t exp, const char *skill_name, int flag)
Definition: living.cpp:1967
get_dam_bonus
int get_dam_bonus(int stat)
Definition: living.cpp:2385
DEXTERITY
@ DEXTERITY
Definition: living.h:12
Settings::death_penalty_level
uint8_t death_penalty_level
Definition: global.h:260
living
Definition: living.h:35
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
apply_death_exp_penalty
void apply_death_exp_penalty(object *op)
Definition: living.cpp:2240
get_dex_bonus
int get_dex_bonus(int stat)
Definition: living.cpp:2361
MAX_BUF
#define MAX_BUF
Definition: define.h:35
MAX_EXPERIENCE
#define MAX_EXPERIENCE
Definition: living.cpp:99
get_weight_limit
uint32_t get_weight_limit(int stat)
Definition: living.cpp:2369
free_string
void free_string(sstring str)
Definition: shstr.cpp:280
RANDOM
#define RANDOM()
Definition: define.h:644
MOVE_FLY_LOW
#define MOVE_FLY_LOW
Definition: define.h:393
ADD_EXP
#define ADD_EXP(exptotal, exp)
Definition: living.cpp:41
change_abil
int change_abil(object *op, object *tmp)
Definition: living.cpp:394
MSG_TYPE_ATTRIBUTE_ATTACKTYPE_LOSS
#define MSG_TYPE_ATTRIBUTE_ATTACKTYPE_LOSS
Definition: newclient.h:553
living::Wis
int8_t Wis
Definition: living.h:36
range_misc
@ range_misc
Definition: player.h:33
FLAG_REMOVED
#define FLAG_REMOVED
Definition: define.h:232
PERM_EXP
#define PERM_EXP(exptotal)
Definition: global.h:230
FLAG_REFL_SPELL
#define FLAG_REFL_SPELL
Definition: define.h:275
FLAG_WIZ
#define FLAG_WIZ
Definition: define.h:231
llevInfo
@ llevInfo
Definition: logger.h:12
NDI_UNIQUE
#define NDI_UNIQUE
Definition: newclient.h:265
get_thaco_bonus
int get_thaco_bonus(int stat)
Definition: living.cpp:2365
WEAPON_SPEED
#define WEAPON_SPEED(xyz)
Definition: define.h:468
is_dragon_pl
int is_dragon_pl(const object *op)
Definition: player.cpp:122
get_learn_spell
int get_learn_spell(int stat)
Definition: living.cpp:2373
FLAG_USE_ARMOUR
#define FLAG_USE_ARMOUR
Definition: define.h:295
DISEASE
@ DISEASE
Definition: object.h:249
attacks
const char *const attacks[NROFATTACKS]
Definition: living.cpp:129
change_attr_value
void change_attr_value(living *stats, int attr, int8_t value)
Definition: living.cpp:264
drain_stat
void drain_stat(object *op)
Definition: living.cpp:716
living::Cha
int8_t Cha
Definition: living.h:36
give.op
op
Definition: give.py:33
autojail.value
value
Definition: autojail.py:6
STRENGTH
@ STRENGTH
Definition: living.h:11
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:266
get_turn_bonus
int get_turn_bonus(int stat)
Definition: living.cpp:2381
change_luck
void change_luck(object *op, int value)
Definition: living.cpp:796
get_speed_bonus
float get_speed_bonus(int stat)
Definition: living.cpp:2389
did_make_save
int did_make_save(const object *op, int level, int bonus)
Definition: living.cpp:2289
Settings::max_stat
uint8_t max_stat
Definition: global.h:324
SKILL_TOOL
@ SKILL_TOOL
Definition: object.h:194
INT_DAM_BONUS
#define INT_DAM_BONUS
Definition: living.cpp:64
on_same_map
int on_same_map(const object *op1, const object *op2)
Definition: map.cpp:2598
CLEAR_FLAG
#define CLEAR_FLAG(xyz, p)
Definition: define.h:225
npc_dialog.index
int index
Definition: npc_dialog.py:102
SK_SUBTRACT_SKILL_EXP
#define SK_SUBTRACT_SKILL_EXP
Definition: skills.h:81
share_exp
void share_exp(object *op, int64_t exp, const char *skill, int flag)
Definition: living.cpp:2319
atnr_is_dragon_enabled
int atnr_is_dragon_enabled(int attacknr)
Definition: player.cpp:103
die_roll
int die_roll(int num, int size, const object *op, int goodbad)
Definition: utils.cpp:122
object_find_by_type_and_arch_name
object * object_find_by_type_and_arch_name(const object *who, int type, const char *name)
Definition: object.cpp:4277
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
level
int level
Definition: readable.cpp:1563
float_bonus_names
static const char * float_bonus_names[NUM_FLOAT_BONUSES]
Definition: living.cpp:91
INT_FEAR_BONUS
#define INT_FEAR_BONUS
Definition: living.cpp:58
restore_msg
const char *const restore_msg[NUM_STATS]
Definition: living.cpp:150
MAX_SAVE_LEVEL
#define MAX_SAVE_LEVEL
Definition: living.cpp:103
PERM_EXP_MAX_LOSS_RATIO
#define PERM_EXP_MAX_LOSS_RATIO
Definition: config.h:290
make_face_from_files.int
int
Definition: make_face_from_files.py:32
MIN_ACTIVE_SPEED
#define MIN_ACTIVE_SPEED
Definition: define.h:639
MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
#define MSG_TYPE_ATTRIBUTE_BAD_EFFECT_END
Definition: newclient.h:570
check_exp_loss
int64_t check_exp_loss(const object *op, int64_t exp)
Definition: living.cpp:2073
player_set_dragon_title
void player_set_dragon_title(player *pl, int level, const char *attack, int skin_resist)
Definition: player.cpp:202
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.cpp:308
MOVE_FLY_HIGH
#define MOVE_FLY_HIGH
Definition: define.h:394
object_remove
void object_remove(object *op)
Definition: object.cpp:1833
MSG_TYPE_ATTRIBUTE_LEVEL_LOSS
#define MSG_TYPE_ATTRIBUTE_LEVEL_LOSS
Definition: newclient.h:574
remove_depletion
int remove_depletion(object *op, int level)
Definition: living.cpp:755
AT_CONFUSION
#define AT_CONFUSION
Definition: attack.h:81
SK_EXP_TOTAL
#define SK_EXP_TOTAL
Definition: skills.h:79
remove_statbonus
void remove_statbonus(object *op)
Definition: living.cpp:845
object_check_move_on
int object_check_move_on(object *op, object *originator)
Definition: object.cpp:3012
FLOAT_GRACE_BONUS
#define FLOAT_GRACE_BONUS
Definition: living.cpp:88
INT_LEARN_SPELL
#define INT_LEARN_SPELL
Definition: living.cpp:61
SK_EXP_ADD_SKILL
#define SK_EXP_ADD_SKILL
Definition: skills.h:78
FLAG_XRAYS
#define FLAG_XRAYS
Definition: define.h:300
report.error
def error(pl)
Definition: report.py:43
Settings::search_items
uint8_t search_items
Definition: global.h:267
object::stats
living stats
Definition: object.h:378
MOVE_SWIM
#define MOVE_SWIM
Definition: define.h:396
get_attr_value
int8_t get_attr_value(const living *stats, int attr)
Definition: living.cpp:313
range_skill
@ range_skill
Definition: player.h:35
savethrow
static const int savethrow[MAX_SAVE_LEVEL+1]
Definition: living.cpp:113
MAX_PLAYER_SPEED
#define MAX_PLAYER_SPEED
Definition: config.h:97
INTELLIGENCE
@ INTELLIGENCE
Definition: living.h:16
BOOTS
@ BOOTS
Definition: object.h:217
object::total_exp
int64_t total_exp
Definition: object.h:379
TRUE
#define TRUE
Definition: compat.h:11
link_player_skills
void link_player_skills(object *op)
Definition: player.cpp:287
get_con_bonus
static float get_con_bonus(int stat)
Definition: living.cpp:2397
FLAG_READY_WEAPON
#define FLAG_READY_WEAPON
Definition: define.h:334
set_dragon_name
void set_dragon_name(object *pl, const object *abil, const object *skin)
Definition: living.cpp:1684
living::Pow
int8_t Pow
Definition: living.h:36
SHIELD
@ SHIELD
Definition: object.h:140
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
check_stat_bounds
void check_stat_bounds(living *stats, int8_t min_stat, int8_t max_stat)
Definition: living.cpp:354
living.h
NUM_STATS
@ NUM_STATS
Definition: living.h:18
INT_CLERIC_CHANCE
#define INT_CLERIC_CHANCE
Definition: living.cpp:60
FOR_INV_PREPARE
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:670
FORCE
@ FORCE
Definition: object.h:229
BASE_WEAPON_SPEED
#define BASE_WEAPON_SPEED
Definition: config.h:108
INT_DEX_BONUS
#define INT_DEX_BONUS
Definition: living.cpp:63
MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_START
#define MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_START
Definition: newclient.h:575
CONSTITUTION
@ CONSTITUTION
Definition: living.h:13
llevDebug
@ llevDebug
Definition: logger.h:13
FLAG_LIFESAVE
#define FLAG_LIFESAVE
Definition: define.h:305
IS_MANA_SKILL
#define IS_MANA_SKILL(num)
Definition: skills.h:106
living::Con
int8_t Con
Definition: living.h:36
give.name
name
Definition: give.py:27
living::Str
int8_t Str
Definition: living.h:36
FREE_PLAYER_LOAD_PERCENT
#define FREE_PLAYER_LOAD_PERCENT
Definition: config.h:98
get_archetype_by_skill_name
archetype * get_archetype_by_skill_name(const char *skill, int type)
Definition: arch.cpp:80
level
Definition: level.py:1