Crossfire Server, Branches 1.12  R18729
treasure.c
Go to the documentation of this file.
1 
2 /*
3  * static char *rcs_treasure_c =
4  * "$Id: treasure.c 13896 2010-09-26 13:57:17Z ryo_saeba $";
5  */
6 
7 /*
8  CrossFire, A Multiplayer game for X-windows
9 
10  Copyright (C) 2002-2006 Mark Wedel & Crossfire Development Team
11  Copyright (C) 1992 Frank Tore Johansen
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 
27  The authors can be reached via e-mail at crossfire-devel@real-time.com
28 */
29 
36 #define ALLOWED_COMBINATION
37 
44 #define TREASURE_DEBUG
45 
46 /* TREASURE_VERBOSE enables copious output concerning artifact generation */
47 /* #define TREASURE_VERBOSE */
48 
49 #include <stdlib.h>
50 #include <global.h>
51 #include <treasure.h>
52 #include <loader.h>
53 #include <sproto.h>
54 
55 
56 static void change_treasure(treasure *t, object *op); /* overrule default values */
57 static int special_potion(object *op);
58 static void fix_flesh_item(object *item, object *donor);
59 
60 extern const char *const spell_mapping[];
67  int prev_warn = warn_archetypes;
68 
69  warn_archetypes = 1;
70  if (ring_arch == NULL)
71  ring_arch = find_archetype("ring");
72  if (amulet_arch == NULL)
73  amulet_arch = find_archetype("amulet");
74  if (staff_arch == NULL)
75  staff_arch = find_archetype("staff");
76  if (crown_arch == NULL)
77  crown_arch = find_archetype("crown");
78  warn_archetypes = prev_warn;
79 }
80 
92  treasurelist *tl = (treasurelist *)malloc(sizeof(treasurelist));
93  if (tl == NULL)
95  memset(tl, 0, sizeof(treasurelist));
96  return tl;
97 }
98 
110  treasure *t = (treasure *)calloc(1, sizeof(treasure));
111  if (t == NULL)
113  t->item = NULL;
114  t->name = NULL;
115  t->next = NULL;
116  t->next_yes = NULL;
117  t->next_no = NULL;
118  t->chance = 100;
119  t->magic = 0;
120  t->nrof = 0;
121  return t;
122 }
123 
138 static treasure *load_treasure(FILE *fp, int *line) {
139  char buf[MAX_BUF], *cp, variable[MAX_BUF];
141  int value;
142 
143  nroftreasures++;
144  while (fgets(buf, MAX_BUF, fp) != NULL) {
145  (*line)++;
146 
147  if (*buf == '#')
148  continue;
149  if ((cp = strchr(buf, '\n')) != NULL)
150  *cp = '\0';
151  cp = buf;
152  while (isspace(*cp)) /* Skip blanks */
153  cp++;
154 
155  if (sscanf(cp, "arch %s", variable)) {
156  if ((t->item = find_archetype(variable)) == NULL)
157  LOG(llevError, "Treasure lacks archetype: %s\n", variable);
158  } else if (sscanf(cp, "list %s", variable))
159  t->name = add_string(variable);
160  else if (sscanf(cp, "change_name %s", variable))
161  t->change_arch.name = add_string(variable);
162  else if (sscanf(cp, "change_title %s", variable))
163  t->change_arch.title = add_string(variable);
164  else if (sscanf(cp, "change_slaying %s", variable))
165  t->change_arch.slaying = add_string(variable);
166  else if (sscanf(cp, "chance %d", &value))
167  t->chance = (uint8)value;
168  else if (sscanf(cp, "nrof %d", &value))
169  t->nrof = (uint16)value;
170  else if (sscanf(cp, "magic %d", &value))
171  t->magic = (uint8)value;
172  else if (!strcmp(cp, "yes"))
173  t->next_yes = load_treasure(fp, line);
174  else if (!strcmp(cp, "no"))
175  t->next_no = load_treasure(fp, line);
176  else if (!strcmp(cp, "end"))
177  return t;
178  else if (!strcmp(cp, "more")) {
179  t->next = load_treasure(fp, line);
180  return t;
181  } else
182  LOG(llevError, "Unknown treasure-command: '%s', last entry %s, line %d\n", cp, t->name ? t->name : "null", *line);
183  }
184  LOG(llevError, "treasure lacks 'end'.\n");
185  return t;
186 }
187 
188 #ifdef TREASURE_DEBUG
189 
200 static void check_treasurelist(const treasure *t, const treasurelist *tl) {
201  if (t->item == NULL && t->name == NULL)
202  LOG(llevError, "Treasurelist %s has element with no name or archetype\n", tl->name);
203  if (t->chance >= 100 && t->next_yes && (t->next || t->next_no))
204  LOG(llevError, "Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", tl->name);
205  /* find_treasurelist will print out its own error message */
206  if (t->name && strcmp(t->name, "NONE"))
208  if (t->next)
209  check_treasurelist(t->next, tl);
210  if (t->next_yes)
212  if (t->next_no)
213  check_treasurelist(t->next_no, tl);
214 }
215 #endif
216 
224 void load_treasures(void) {
225  FILE *fp;
226  char filename[MAX_BUF], buf[MAX_BUF], name[MAX_BUF];
227  treasurelist *previous = NULL;
228  treasure *t;
229  int comp, line = 0;
230 
231  snprintf(filename, sizeof(filename), "%s/%s", settings.datadir, settings.treasures);
232  if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) {
233  LOG(llevError, "Can't open treasure file.\n");
234  return;
235  }
236  while (fgets(buf, MAX_BUF, fp) != NULL) {
237  line++;
238  if (*buf == '#')
239  continue;
240 
241  if (sscanf(buf, "treasureone %s\n", name) || sscanf(buf, "treasure %s\n", name)) {
243 
244  tl->name = add_string(name);
245  if (previous == NULL)
246  first_treasurelist = tl;
247  else
248  previous->next = tl;
249  previous = tl;
250  tl->items = load_treasure(fp, &line);
251 
252  /* This is a one of the many items on the list should be generated.
253  * Add up the chance total, and check to make sure the yes & no
254  * fields of the treasures are not being used.
255  */
256  if (!strncmp(buf, "treasureone", 11)) {
257  for (t = tl->items; t != NULL; t = t->next) {
258 #ifdef TREASURE_DEBUG
259  if (t->next_yes || t->next_no) {
260  LOG(llevError, "Treasure %s is one item, but on treasure %s\n", tl->name, t->item ? t->item->name : t->name);
261  LOG(llevError, " the next_yes or next_no field is set\n");
262  }
263 #endif
264  tl->total_chance += t->chance;
265  }
266  }
267  } else
268  LOG(llevError, "Treasure-list didn't understand: %s, line %d\n", buf, line);
269  }
270  close_and_delete(fp, comp);
271 
272 #ifdef TREASURE_DEBUG
273  /* Perform some checks on how valid the treasure data actually is.
274  * verify that list transitions work (ie, the list that it is supposed
275  * to transition to exists). Also, verify that at least the name
276  * or archetype is set for each treasure element.
277  */
278  for (previous = first_treasurelist; previous != NULL; previous = previous->next)
279  check_treasurelist(previous->items, previous);
280 #endif
281 }
282 
295 treasurelist *find_treasurelist(const char *name) {
296  const char *tmp = find_string(name);
297  treasurelist *tl;
298 
299  /* Special cases - randomitems of none is to override default. If
300  * first_treasurelist is null, it means we are on the first pass of
301  * of loading archetyps, so for now, just return - second pass will
302  * init these values.
303  */
304  if (!strcmp(name, "none") || (!first_treasurelist))
305  return NULL;
306  if (tmp != NULL)
307  for (tl = first_treasurelist; tl != NULL; tl = tl->next)
308  if (tmp == tl->name)
309  return tl;
310  LOG(llevError, "Couldn't find treasurelist %s\n", name);
311  return NULL;
312 }
313 
314 
326 static void put_treasure(object *op, object *creator, int flags) {
327  /* Bit of a hack - spells should never be put onto the map. The entire
328  * treasure stuff is a problem - there is no clear idea of knowing
329  * this is the original object, or if this is an object that should be created
330  * by another object.
331  */
332  if (flags&GT_ENVIRONMENT && op->type != SPELL) {
333  op->x = creator->x;
334  op->y = creator->y;
336  insert_ob_in_map(op, creator->map, op, INS_NO_MERGE|INS_NO_WALK_ON);
337  } else {
338  op = insert_ob_in_ob(op, creator);
339  if ((flags&GT_APPLY) && QUERY_FLAG(creator, FLAG_MONSTER))
340  monster_check_apply(creator, op);
341  }
342 }
343 
354 static void change_treasure(treasure *t, object *op) {
355  /* CMD: change_name xxxx */
356  if (t->change_arch.name) {
358  /* not great, but better than something that is completely wrong */
360  }
361 
362  if (t->change_arch.title) {
363  if (op->title)
364  free_string(op->title);
365  op->title = add_string(t->change_arch.title);
366  }
367 
368  if (t->change_arch.slaying) {
369  if (op->slaying)
370  free_string(op->slaying);
372  }
373 }
374 
390 static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries) {
391  object *tmp;
392 
393 
394  if ((int)t->chance >= 100 || (RANDOM()%100+1) < (int)t->chance) {
395  if (t->name) {
396  if (strcmp(t->name, "NONE") && difficulty >= t->magic)
397  create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries);
398  } else {
399  if (t->item->clone.invisible != 0 || !(flag&GT_INVISIBLE)) {
400  tmp = arch_to_object(t->item);
401  if (t->nrof && tmp->nrof <= 1)
402  tmp->nrof = RANDOM()%((int)t->nrof)+1;
403  fix_generated_item(tmp, op, difficulty, t->magic, flag);
404  change_treasure(t, tmp);
405  put_treasure(tmp, op, flag);
406  }
407  }
408  if (t->next_yes != NULL)
409  create_all_treasures(t->next_yes, op, flag, difficulty, tries);
410  } else
411  if (t->next_no != NULL)
412  create_all_treasures(t->next_no, op, flag, difficulty, tries);
413  if (t->next != NULL)
414  create_all_treasures(t->next, op, flag, difficulty, tries);
415 }
416 
435 static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries) {
436  int value = RANDOM()%tl->total_chance;
437  treasure *t;
438 
439  if (tries++ > 100) {
440  LOG(llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n");
441  return;
442  }
443 
444  for (t = tl->items; t != NULL; t = t->next) {
445  value -= t->chance;
446  if (value < 0)
447  break;
448  }
449 
450  if (!t || value >= 0) {
451  LOG(llevError, "create_one_treasure: got null object or not able to find treasure\n");
452  abort();
453  return;
454  }
455  if (t->name) {
456  if (!strcmp(t->name, "NONE"))
457  return;
458  if (difficulty >= t->magic)
459  create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries);
460  else if (t->nrof)
461  create_one_treasure(tl, op, flag, difficulty, tries);
462  return;
463  }
464  if ((t->item) && (flag&GT_ONLY_GOOD)) { /* Generate only good items, damnit !*/
465  if (QUERY_FLAG(&(t->item->clone), FLAG_CURSED)
466  || QUERY_FLAG(&(t->item->clone), FLAG_DAMNED)) {
467  create_one_treasure(tl, op, flag, difficulty, tries+1);
468  return;
469  }
470  }
471  if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) {
472  object *tmp = arch_to_object(t->item);
473 
474  if (!tmp)
475  return;
476  if (t->nrof && tmp->nrof <= 1)
477  tmp->nrof = RANDOM()%((int)t->nrof)+1;
478  fix_generated_item(tmp, op, difficulty, t->magic, flag);
479  change_treasure(t, tmp);
480  put_treasure(tmp, op, flag);
481  }
482 }
483 
499 void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries) {
500  if (tries++ > 100) {
501  LOG(llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
502  return;
503  }
504  if (t->total_chance)
505  create_one_treasure(t, op, flag, difficulty, tries);
506  else
507  create_all_treasures(t->items, op, flag, difficulty, tries);
508 }
509 
524 object *generate_treasure(treasurelist *t, int difficulty) {
525  object *ob = get_object(), *tmp;
526 
527  create_treasure(t, ob, 0, difficulty, 0);
528 
529  /* Don't want to free the object we are about to return */
530  tmp = ob->inv;
531  if (tmp != NULL)
532  remove_ob(tmp);
533  if (ob->inv) {
534  LOG(llevError, "In generate treasure, created multiple objects.\n");
535  }
536  free_object(ob);
537  return tmp;
538 }
539 
554 static int level_for_item(const object *op, int difficulty, int retmult) {
555  int level, mult, olevel;
556 
557  mult = 0;
558  if (!op->inv) {
559  LOG(llevError, "level_for_item: Object %s has no inventory!\n", op->name);
560  return 0;
561  }
562  level = op->inv->level;
563 
564  /* Basically, we set mult to the lowest spell increase attribute that is
565  * not zero - zero's mean no modification is done, so we don't want those.
566  * given we want non zero results, we can't just use a few MIN's here.
567  */
568  mult = op->inv->dam_modifier;
569  if (op->inv->range_modifier && (op->inv->range_modifier < mult || mult == 0))
570  mult = op->inv->range_modifier;
571  if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult == 0))
572  mult = op->inv->duration_modifier;
573 
574  if (mult == 0)
575  mult = 5;
576 
577  if (retmult)
578  return mult;
579 
580  olevel = mult*rndm(0, difficulty)+level;
581  if (olevel > MAX_SPELLITEM_LEVEL)
582  olevel = MAX_SPELLITEM_LEVEL;
583 
584  return olevel;
585 }
586 
594 static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1] = {
595 /*chance of magic difficulty*/
596 /* +0 +1 +2 +3 +4 */
597  { 94, 3, 2, 1, 0 }, /*1*/
598  { 94, 3, 2, 1, 0 }, /*2*/
599  { 94, 3, 2, 1, 0 }, /*3*/
600  { 94, 3, 2, 1, 0 }, /*4*/
601  { 94, 3, 2, 1, 0 }, /*5*/
602  { 90, 4, 3, 2, 1 }, /*6*/
603  { 90, 4, 3, 2, 1 }, /*7*/
604  { 90, 4, 3, 2, 1 }, /*8*/
605  { 90, 4, 3, 2, 1 }, /*9*/
606  { 90, 4, 3, 2, 1 }, /*10*/
607  { 85, 6, 4, 3, 2 }, /*11*/
608  { 85, 6, 4, 3, 2 }, /*12*/
609  { 85, 6, 4, 3, 2 }, /*13*/
610  { 85, 6, 4, 3, 2 }, /*14*/
611  { 85, 6, 4, 3, 2 }, /*15*/
612  { 81, 8, 5, 4, 3 }, /*16*/
613  { 81, 8, 5, 4, 3 }, /*17*/
614  { 81, 8, 5, 4, 3 }, /*18*/
615  { 81, 8, 5, 4, 3 }, /*19*/
616  { 81, 8, 5, 4, 3 }, /*20*/
617  { 75, 10, 6, 5, 4 }, /*21*/
618  { 75, 10, 6, 5, 4 }, /*22*/
619  { 75, 10, 6, 5, 4 }, /*23*/
620  { 75, 10, 6, 5, 4 }, /*24*/
621  { 75, 10, 6, 5, 4 }, /*25*/
622  { 70, 12, 7, 6, 5 }, /*26*/
623  { 70, 12, 7, 6, 5 }, /*27*/
624  { 70, 12, 7, 6, 5 }, /*28*/
625  { 70, 12, 7, 6, 5 }, /*29*/
626  { 70, 12, 7, 6, 5 }, /*30*/
627  { 70, 9, 8, 7, 6 }, /*31*/
628  { 70, 9, 8, 7, 6 }, /*32*/
629  { 70, 9, 8, 7, 6 }, /*33*/
630  { 70, 9, 8, 7, 6 }, /*34*/
631  { 70, 9, 8, 7, 6 }, /*35*/
632  { 70, 6, 9, 8, 7 }, /*36*/
633  { 70, 6, 9, 8, 7 }, /*37*/
634  { 70, 6, 9, 8, 7 }, /*38*/
635  { 70, 6, 9, 8, 7 }, /*39*/
636  { 70, 6, 9, 8, 7 }, /*40*/
637  { 70, 3, 10, 9, 8 }, /*41*/
638  { 70, 3, 10, 9, 8 }, /*42*/
639  { 70, 3, 10, 9, 8 }, /*43*/
640  { 70, 3, 10, 9, 8 }, /*44*/
641  { 70, 3, 10, 9, 8 }, /*45*/
642  { 70, 2, 9, 10, 9 }, /*46*/
643  { 70, 2, 9, 10, 9 }, /*47*/
644  { 70, 2, 9, 10, 9 }, /*48*/
645  { 70, 2, 9, 10, 9 }, /*49*/
646  { 70, 2, 9, 10, 9 }, /*50*/
647  { 70, 2, 7, 11, 10 }, /*51*/
648  { 70, 2, 7, 11, 10 }, /*52*/
649  { 70, 2, 7, 11, 10 }, /*53*/
650  { 70, 2, 7, 11, 10 }, /*54*/
651  { 70, 2, 7, 11, 10 }, /*55*/
652  { 70, 2, 5, 12, 11 }, /*56*/
653  { 70, 2, 5, 12, 11 }, /*57*/
654  { 70, 2, 5, 12, 11 }, /*58*/
655  { 70, 2, 5, 12, 11 }, /*59*/
656  { 70, 2, 5, 12, 11 }, /*60*/
657  { 70, 2, 3, 13, 12 }, /*61*/
658  { 70, 2, 3, 13, 12 }, /*62*/
659  { 70, 2, 3, 13, 12 }, /*63*/
660  { 70, 2, 3, 13, 12 }, /*64*/
661  { 70, 2, 3, 13, 12 }, /*65*/
662  { 70, 2, 3, 12, 13 }, /*66*/
663  { 70, 2, 3, 12, 13 }, /*67*/
664  { 70, 2, 3, 12, 13 }, /*68*/
665  { 70, 2, 3, 12, 13 }, /*69*/
666  { 70, 2, 3, 12, 13 }, /*70*/
667  { 70, 2, 3, 11, 14 }, /*71*/
668  { 70, 2, 3, 11, 14 }, /*72*/
669  { 70, 2, 3, 11, 14 }, /*73*/
670  { 70, 2, 3, 11, 14 }, /*74*/
671  { 70, 2, 3, 11, 14 }, /*75*/
672  { 70, 2, 3, 10, 15 }, /*76*/
673  { 70, 2, 3, 10, 15 }, /*77*/
674  { 70, 2, 3, 10, 15 }, /*78*/
675  { 70, 2, 3, 10, 15 }, /*79*/
676  { 70, 2, 3, 10, 15 }, /*80*/
677  { 70, 2, 3, 9, 16 }, /*81*/
678  { 70, 2, 3, 9, 16 }, /*82*/
679  { 70, 2, 3, 9, 16 }, /*83*/
680  { 70, 2, 3, 9, 16 }, /*84*/
681  { 70, 2, 3, 9, 16 }, /*85*/
682  { 70, 2, 3, 8, 17 }, /*86*/
683  { 70, 2, 3, 8, 17 }, /*87*/
684  { 70, 2, 3, 8, 17 }, /*88*/
685  { 70, 2, 3, 8, 17 }, /*89*/
686  { 70, 2, 3, 8, 17 }, /*90*/
687  { 70, 2, 3, 7, 18 }, /*91*/
688  { 70, 2, 3, 7, 18 }, /*92*/
689  { 70, 2, 3, 7, 18 }, /*93*/
690  { 70, 2, 3, 7, 18 }, /*94*/
691  { 70, 2, 3, 7, 18 }, /*95*/
692  { 70, 2, 3, 6, 19 }, /*96*/
693  { 70, 2, 3, 6, 19 }, /*97*/
694  { 70, 2, 3, 6, 19 }, /*98*/
695  { 70, 2, 3, 6, 19 }, /*99*/
696  { 70, 2, 3, 6, 19 }, /*100*/
697  { 70, 2, 3, 6, 19 }, /*101*/
698  { 70, 2, 3, 6, 19 }, /*101*/
699  { 70, 2, 3, 6, 19 }, /*102*/
700  { 70, 2, 3, 6, 19 }, /*103*/
701  { 70, 2, 3, 6, 19 }, /*104*/
702  { 70, 2, 3, 6, 19 }, /*105*/
703  { 70, 2, 3, 6, 19 }, /*106*/
704  { 70, 2, 3, 6, 19 }, /*107*/
705  { 70, 2, 3, 6, 19 }, /*108*/
706  { 70, 2, 3, 6, 19 }, /*109*/
707  { 70, 2, 3, 6, 19 }, /*110*/
708  { 70, 2, 3, 6, 19 }, /*111*/
709  { 70, 2, 3, 6, 19 }, /*112*/
710  { 70, 2, 3, 6, 19 }, /*113*/
711  { 70, 2, 3, 6, 19 }, /*114*/
712  { 70, 2, 3, 6, 19 }, /*115*/
713  { 70, 2, 3, 6, 19 }, /*116*/
714  { 70, 2, 3, 6, 19 }, /*117*/
715  { 70, 2, 3, 6, 19 }, /*118*/
716  { 70, 2, 3, 6, 19 }, /*119*/
717  { 70, 2, 3, 6, 19 }, /*120*/
718  { 70, 2, 3, 6, 19 }, /*121*/
719  { 70, 2, 3, 6, 19 }, /*122*/
720  { 70, 2, 3, 6, 19 }, /*123*/
721  { 70, 2, 3, 6, 19 }, /*124*/
722  { 70, 2, 3, 6, 19 }, /*125*/
723  { 70, 2, 3, 6, 19 }, /*126*/
724  { 70, 2, 3, 6, 19 }, /*127*/
725  { 70, 2, 3, 6, 19 }, /*128*/
726  { 70, 2, 3, 6, 19 }, /*129*/
727  { 70, 2, 3, 6, 19 }, /*130*/
728  { 70, 2, 3, 6, 19 }, /*131*/
729  { 70, 2, 3, 6, 19 }, /*132*/
730  { 70, 2, 3, 6, 19 }, /*133*/
731  { 70, 2, 3, 6, 19 }, /*134*/
732  { 70, 2, 3, 6, 19 }, /*135*/
733  { 70, 2, 3, 6, 19 }, /*136*/
734  { 70, 2, 3, 6, 19 }, /*137*/
735  { 70, 2, 3, 6, 19 }, /*138*/
736  { 70, 2, 3, 6, 19 }, /*139*/
737  { 70, 2, 3, 6, 19 }, /*140*/
738  { 70, 2, 3, 6, 19 }, /*141*/
739  { 70, 2, 3, 6, 19 }, /*142*/
740  { 70, 2, 3, 6, 19 }, /*143*/
741  { 70, 2, 3, 6, 19 }, /*144*/
742  { 70, 2, 3, 6, 19 }, /*145*/
743  { 70, 2, 3, 6, 19 }, /*146*/
744  { 70, 2, 3, 6, 19 }, /*147*/
745  { 70, 2, 3, 6, 19 }, /*148*/
746  { 70, 2, 3, 6, 19 }, /*149*/
747  { 70, 2, 3, 6, 19 }, /*150*/
748  { 70, 2, 3, 6, 19 }, /*151*/
749  { 70, 2, 3, 6, 19 }, /*152*/
750  { 70, 2, 3, 6, 19 }, /*153*/
751  { 70, 2, 3, 6, 19 }, /*154*/
752  { 70, 2, 3, 6, 19 }, /*155*/
753  { 70, 2, 3, 6, 19 }, /*156*/
754  { 70, 2, 3, 6, 19 }, /*157*/
755  { 70, 2, 3, 6, 19 }, /*158*/
756  { 70, 2, 3, 6, 19 }, /*159*/
757  { 70, 2, 3, 6, 19 }, /*160*/
758  { 70, 2, 3, 6, 19 }, /*161*/
759  { 70, 2, 3, 6, 19 }, /*162*/
760  { 70, 2, 3, 6, 19 }, /*163*/
761  { 70, 2, 3, 6, 19 }, /*164*/
762  { 70, 2, 3, 6, 19 }, /*165*/
763  { 70, 2, 3, 6, 19 }, /*166*/
764  { 70, 2, 3, 6, 19 }, /*167*/
765  { 70, 2, 3, 6, 19 }, /*168*/
766  { 70, 2, 3, 6, 19 }, /*169*/
767  { 70, 2, 3, 6, 19 }, /*170*/
768  { 70, 2, 3, 6, 19 }, /*171*/
769  { 70, 2, 3, 6, 19 }, /*172*/
770  { 70, 2, 3, 6, 19 }, /*173*/
771  { 70, 2, 3, 6, 19 }, /*174*/
772  { 70, 2, 3, 6, 19 }, /*175*/
773  { 70, 2, 3, 6, 19 }, /*176*/
774  { 70, 2, 3, 6, 19 }, /*177*/
775  { 70, 2, 3, 6, 19 }, /*178*/
776  { 70, 2, 3, 6, 19 }, /*179*/
777  { 70, 2, 3, 6, 19 }, /*180*/
778  { 70, 2, 3, 6, 19 }, /*181*/
779  { 70, 2, 3, 6, 19 }, /*182*/
780  { 70, 2, 3, 6, 19 }, /*183*/
781  { 70, 2, 3, 6, 19 }, /*184*/
782  { 70, 2, 3, 6, 19 }, /*185*/
783  { 70, 2, 3, 6, 19 }, /*186*/
784  { 70, 2, 3, 6, 19 }, /*187*/
785  { 70, 2, 3, 6, 19 }, /*188*/
786  { 70, 2, 3, 6, 19 }, /*189*/
787  { 70, 2, 3, 6, 19 }, /*190*/
788  { 70, 2, 3, 6, 19 }, /*191*/
789  { 70, 2, 3, 6, 19 }, /*192*/
790  { 70, 2, 3, 6, 19 }, /*193*/
791  { 70, 2, 3, 6, 19 }, /*194*/
792  { 70, 2, 3, 6, 19 }, /*195*/
793  { 70, 2, 3, 6, 19 }, /*196*/
794  { 70, 2, 3, 6, 19 }, /*197*/
795  { 70, 2, 3, 6, 19 }, /*198*/
796  { 70, 2, 3, 6, 19 }, /*199*/
797  { 70, 2, 3, 6, 19 }, /*200*/
798 
799 };
800 
808 static int magic_from_difficulty(int difficulty) {
809  int percent, loop;
810 
811  difficulty--;
812  if (difficulty < 0)
813  difficulty = 0;
814 
815  if (difficulty >= DIFFLEVELS)
816  difficulty = DIFFLEVELS-1;
817 
818  percent = RANDOM()%100;
819 
820  for (loop = 0; loop < (MAXMAGIC+1); ++loop) {
821  percent -= difftomagic_list[difficulty][loop];
822  if (percent < 0)
823  break;
824  }
825  if (loop == (MAXMAGIC+1)) {
826  LOG(llevError, "Warning, table for difficulty %d bad.\n", difficulty);
827  loop = 0;
828  }
829  /* LOG(llevDebug, "Chose magic %d for difficulty %d\n", loop, difficulty);*/
830  return (RANDOM()%3) ? loop : -loop;
831 }
832 
844 void set_abs_magic(object *op, int magic) {
845  if (!magic)
846  return;
847 
848  op->magic = magic;
849  if (op->arch) {
850  if (op->type == ARMOUR)
851  ARMOUR_SPEED(op) = (ARMOUR_SPEED(&op->arch->clone)*(100+magic*10))/100;
852 
853  if (magic < 0 && !(RANDOM()%3)) /* You can't just check the weight always */
854  magic = (-magic);
855  op->weight = (op->arch->clone.weight*(100-magic*10))/100;
856  } else {
857  if (op->type == ARMOUR)
858  ARMOUR_SPEED(op) = (ARMOUR_SPEED(op)*(100+magic*10))/100;
859  if (magic < 0 && !(RANDOM()%3)) /* You can't just check the weight always */
860  magic = (-magic);
861  op->weight = (op->weight*(100-magic*10))/100;
862  }
863 }
864 
880 static void set_magic(int difficulty, object *op, int max_magic, int flags) {
881  int i;
882 
883  i = magic_from_difficulty(difficulty);
884  if ((flags&GT_ONLY_GOOD) && i < 0)
885  i = -i;
886  if (i > max_magic)
887  i = max_magic;
888  set_abs_magic(op, i);
889  if (i < 0)
890  SET_FLAG(op, FLAG_CURSED);
891 }
892 
909 static void set_ring_bonus(object *op, int bonus) {
910  int r = RANDOM()%(bonus > 0 ? 25 : 11);
911 
912  if (op->type == AMULET) {
913  if (!(RANDOM()%21))
914  r = 20+RANDOM()%2;
915  else {
916  if (RANDOM()&2)
917  r = 10;
918  else
919  r = 11+RANDOM()%9;
920  }
921  }
922 
923  switch (r) {
924  /* Redone by MSW 2000-11-26 to have much less code. Also,
925  * bonuses and penalties will stack and add to existing values.
926  * of the item.
927  */
928  case 0:
929  case 1:
930  case 2:
931  case 3:
932  case 4:
933  case 5:
934  case 6:
935  set_attr_value(&op->stats, r, (signed char)(bonus+get_attr_value(&op->stats, r)));
936  break;
937 
938  case 7:
939  op->stats.dam += bonus;
940  break;
941 
942  case 8:
943  op->stats.wc += bonus;
944  break;
945 
946  case 9:
947  op->stats.food += bonus; /* hunger/sustenance */
948  break;
949 
950  case 10:
951  op->stats.ac += bonus;
952  break;
953 
954  /* Item that gives protections/vulnerabilities */
955  case 11:
956  case 12:
957  case 13:
958  case 14:
959  case 15:
960  case 16:
961  case 17:
962  case 18:
963  case 19: {
964  int b = 5+FABS(bonus), val, resist = RANDOM()%num_resist_table;
965 
966  /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */
967  val = 10+RANDOM()%b+RANDOM()%b+RANDOM()%b+RANDOM()%b;
968 
969  /* Cursed items need to have higher negative values to equal out with
970  * positive values for how protections work out. Put another
971  * little random element in since that they don't always end up with
972  * even values.
973  */
974  if (bonus < 0)
975  val = 2*-val-RANDOM()%b;
976  if (val > 35)
977  val = 35; /* Upper limit */
978  b = 0;
979  while (op->resist[resist_table[resist]] != 0 && b < 4) {
980  resist = RANDOM()%num_resist_table;
981  }
982  if (b == 4)
983  return; /* Not able to find a free resistance */
984  op->resist[resist_table[resist]] = val;
985  /* We should probably do something more clever here to adjust value
986  * based on how good a resistance we gave.
987  */
988  break;
989  }
990 
991  case 20:
992  if (op->type == AMULET) {
994  op->value *= 11;
995  } else {
996  op->stats.hp = 1; /* regenerate hit points */
997  op->value *= 4;
998  }
999  break;
1000 
1001  case 21:
1002  if (op->type == AMULET) {
1004  op->value *= 9;
1005  } else {
1006  op->stats.sp = 1; /* regenerate spell points */
1007  op->value *= 3;
1008  }
1009  break;
1010 
1011  case 22:
1012  op->stats.exp += bonus; /* Speed! */
1013  op->value = (op->value*2)/3;
1014  break;
1015  }
1016  if (bonus > 0)
1017  op->value *= 2*bonus;
1018  else
1019  op->value = -(op->value*2*bonus)/3;
1020 }
1021 
1030 static int get_magic(int diff) {
1031  int i;
1032 
1033  if (diff < 3)
1034  diff = 3;
1035  for (i = 0; i < 4; i++)
1036  if (RANDOM()%diff)
1037  return i;
1038  return 4;
1039 }
1040 
1041 #define DICE2 (get_magic(2) == 2 ? 2 : 1)
1042 #define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)
1043 
1070 void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags) {
1071  int was_magic = op->magic, num_enchantments = 0, save_item_power;
1072 
1073  if (!creator || creator->type == op->type)
1074  creator = op; /* safety & to prevent polymorphed objects giving attributes */
1075 
1076  /* If we make an artifact, this information will be destroyed */
1077  save_item_power = op->item_power;
1078  op->item_power = 0;
1079 
1080  if (op->randomitems && op->type != SPELL) {
1081  create_treasure(op->randomitems, op, flags, difficulty, 0);
1082  if (!op->inv)
1083  LOG(llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->name);
1084  /* So the treasure doesn't get created again */
1085  op->randomitems = NULL;
1086  }
1087 
1088  if (difficulty < 1)
1089  difficulty = 1;
1090  if (!(flags&GT_MINIMAL)) {
1091  if (op->arch == crown_arch) {
1092  set_magic(difficulty > 25 ? 30 : difficulty+5, op, max_magic, flags);
1093  num_enchantments = calc_item_power(op, 1);
1094  generate_artifact(op, difficulty);
1095  } else {
1096  if (!op->magic && max_magic)
1097  set_magic(difficulty, op, max_magic, flags);
1098  num_enchantments = calc_item_power(op, 1);
1099  if ((!was_magic && !(RANDOM()%CHANCE_FOR_ARTIFACT))
1100  || op->type == HORN
1101  || difficulty >= 999)
1102  generate_artifact(op, difficulty);
1103  }
1104 
1105  /* Object was made an artifact. Calculate its item_power rating.
1106  * the item_power in the object is what the artifact adds.
1107  */
1108  if (op->title) {
1109  /* if save_item_power is set, then most likely we started with an
1110  * artifact and have added new abilities to it - this is rare, but
1111  * but I have seen things like 'strange rings of fire'. So just
1112  * figure out the power from the base power plus what this one adds.
1113  * Note that since item_power is not quite linear, this actually
1114  * ends up being somewhat of a bonus.
1115  */
1116  if (save_item_power)
1117  op->item_power = save_item_power+get_power_from_ench(op->item_power);
1118  else
1119  op->item_power += get_power_from_ench(num_enchantments);
1120  } else if (save_item_power) {
1121  /* restore the item_power field to the object if we haven't changed
1122  * it. we don't care about num_enchantments - that will basically
1123  * just have calculated some value from the base attributes of the
1124  * archetype.
1125  */
1126  op->item_power = save_item_power;
1127  } else {
1128  /* item_power was zero. This is suspicious, as it may be because it
1129  * was never previously calculated. Let's compute a value and see if
1130  * it is non-zero. If it indeed is, then assign it as the new
1131  * item_power value.
1132  * - gros, 21th of July 2006.
1133  */
1134  op->item_power = calc_item_power(op, 0);
1135  save_item_power = op->item_power; /* Just in case it would get used
1136  * again below */
1137  }
1138  } else {
1139  /* If flag is GT_MINIMAL, we want to restore item power */
1140  op->item_power = save_item_power;
1141  }
1142 
1143  /* materialtype modifications. Note we allow this on artifacts. */
1144 
1145  set_materialname(op, difficulty, NULL);
1146 
1147  if (flags&GT_MINIMAL) {
1148  if (op->type == POTION)
1149  /* Handle healing and magic power potions */
1150  if (op->stats.sp && !op->randomitems) {
1151  object *tmp;
1152 
1153  tmp = create_archetype(spell_mapping[op->stats.sp]);
1154  insert_ob_in_ob(tmp, op);
1155  op->stats.sp = 0;
1156  }
1157  } else if (!op->title) { /* Only modify object if not special */
1158  switch (op->type) {
1159  case WEAPON:
1160  case ARMOUR:
1161  case SHIELD:
1162  case HELMET:
1163  case CLOAK:
1164  if (QUERY_FLAG(op, FLAG_CURSED) && !(RANDOM()%4))
1165  set_ring_bonus(op, -DICE2);
1166  break;
1167 
1168  case BRACERS:
1169  if (!(RANDOM()%(QUERY_FLAG(op, FLAG_CURSED) ? 5 : 20))) {
1171  if (!QUERY_FLAG(op, FLAG_CURSED))
1172  op->value *= 3;
1173  }
1174  break;
1175 
1176  case POTION: {
1177  int too_many_tries = 0, is_special = 0;
1178 
1179  /* Handle healing and magic power potions */
1180  if (op->stats.sp && !op->randomitems) {
1181  object *tmp;
1182 
1183  tmp = create_archetype(spell_mapping[op->stats.sp]);
1184  insert_ob_in_ob(tmp, op);
1185  op->stats.sp = 0;
1186  }
1187 
1188  while (!(is_special = special_potion(op)) && !op->inv) {
1189  generate_artifact(op, difficulty);
1190  if (too_many_tries++ > 10)
1191  break;
1192  }
1193  /* don't want to change value for healing/magic power potions,
1194  * since the value set on those is already correct.
1195  */
1196  if (op->inv && op->randomitems) {
1197  /* value multiplier is same as for scrolls */
1198  op->value = (op->value*op->inv->value);
1199  op->level = op->inv->level/2+RANDOM()%difficulty+RANDOM()%difficulty;
1200  } else {
1201  FREE_AND_COPY(op->name, "potion");
1202  FREE_AND_COPY(op->name_pl, "potions");
1203  }
1204  if (!(flags&GT_ONLY_GOOD) && RANDOM()%2)
1205  SET_FLAG(op, FLAG_CURSED);
1206  break;
1207  }
1208 
1209  case AMULET:
1210  if (op->arch == amulet_arch)
1211  op->value *= 5; /* Since it's not just decoration */
1212  case RING:
1213  if (op->arch == NULL) {
1214  remove_ob(op);
1215  free_object(op);
1216  op = NULL;
1217  break;
1218  }
1219  if (op->arch != ring_arch && op->arch != amulet_arch)
1220  /* It's a special artifact!*/
1221  break;
1222 
1223  if (!(flags&GT_ONLY_GOOD) && !(RANDOM()%3))
1224  SET_FLAG(op, FLAG_CURSED);
1226  if (op->type != RING) /* Amulets have only one ability */
1227  break;
1228  if (!(RANDOM()%4)) {
1229  int d = (RANDOM()%2 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2;
1230  if (d > 0)
1231  op->value *= 3;
1232  set_ring_bonus(op, d);
1233  if (!(RANDOM()%4)) {
1234  int d = (RANDOM()%3 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2;
1235  if (d > 0)
1236  op->value *= 5;
1237  set_ring_bonus(op, d);
1238  }
1239  }
1240  if (GET_ANIM_ID(op))
1241  SET_ANIMATION(op, RANDOM()%((int)NUM_ANIMATIONS(op)));
1242  break;
1243 
1244  case BOOK:
1245  /* Is it an empty book?, if yes lets make a special
1246  * msg for it, and tailor its properties based on the
1247  * creator and/or map level we found it on.
1248  */
1249  if (!op->msg && RANDOM()%10) {
1250  /* set the book level properly */
1251  if (creator->level == 0 || QUERY_FLAG(creator, FLAG_ALIVE)) {
1252  if (op->map && op->map->difficulty)
1253  op->level = RANDOM()%(op->map->difficulty)+RANDOM()%10+1;
1254  else
1255  op->level = RANDOM()%20+1;
1256  } else
1257  op->level = RANDOM()%creator->level;
1258 
1259  tailor_readable_ob(op, -1);
1260  /* books w/ info are worth more! */
1261  op->value *= ((op->level > 10 ? op->level : (op->level+1)/2)*((strlen(op->msg)/250)+1));
1262  /* creator related stuff */
1263 
1264  /* for library, chained books. Note that some monsters have
1265  * no_pick set - we don't want to set no pick in that case.
1266  */
1267  if (QUERY_FLAG(creator, FLAG_NO_PICK)
1268  && !QUERY_FLAG(creator, FLAG_MONSTER))
1269  SET_FLAG(op, FLAG_NO_PICK);
1270  if (creator->slaying && !op->slaying) /* for check_inv floors */
1271  op->slaying = add_string(creator->slaying);
1272 
1273  /* add exp so reading it gives xp (once)*/
1274  op->stats.exp = op->value > 10000 ? op->value/5 : op->value/10;
1275  }
1276  break;
1277 
1278  case SPELLBOOK:
1279  op->value = op->value*op->inv->value;
1280  /* add exp so learning gives xp */
1281  op->level = op->inv->level;
1282  op->stats.exp = op->value;
1283  /* some more fun */
1284  if (!(flags&GT_ONLY_GOOD) && rndm(1, 100) <= 5) {
1285  if (rndm(1, 6) <= 1)
1286  SET_FLAG(op, FLAG_DAMNED);
1287  else
1288  SET_FLAG(op, FLAG_CURSED);
1289  } else if (rndm(1, 100) <= 1) {
1290  SET_FLAG(op, FLAG_BLESSED);
1291  }
1292  break;
1293 
1294  case WAND:
1295  /* nrof in the treasure list is number of charges,
1296  * not number of wands. So copy that into food (charges),
1297  * and reset nrof.
1298  */
1299  op->stats.food = op->inv->nrof;
1300  op->nrof = 1;
1301  /* If the spell changes by level, choose a random level
1302  * for it, and adjust price. If the spell doesn't
1303  * change by level, just set the wand to the level of
1304  * the spell, and value calculation is simpler.
1305  */
1306  if (op->inv->duration_modifier
1307  || op->inv->dam_modifier
1308  || op->inv->range_modifier) {
1309  op->level = level_for_item(op, difficulty, 0);
1310  op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50);
1311  } else {
1312  op->level = op->inv->level;
1313  op->value = op->value*op->inv->value;
1314  }
1315  break;
1316 
1317  case ROD:
1318  op->level = level_for_item(op, difficulty, 0);
1319  /* Add 50 to both level an divisor to keep prices a little
1320  * more reasonable. Otherwise, a high level version of a
1321  * low level spell can be worth tons a money (eg, level 20
1322  * rod, level 2 spell = 10 time multiplier). This way, the
1323  * value are a bit more reasonable.
1324  */
1325  op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50);
1326  /* maxhp is used to denote how many 'charges' the rod holds
1327  * before */
1328  if (op->stats.maxhp)
1329  op->stats.maxhp *= MAX(op->inv->stats.sp, op->inv->stats.grace);
1330  else
1331  op->stats.maxhp = 2*MAX(op->inv->stats.sp, op->inv->stats.grace);
1332 
1333  op->stats.hp = op->stats.maxhp;
1334  break;
1335 
1336  case SCROLL:
1337  op->level = level_for_item(op, difficulty, 0);
1338  op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50);
1339  /* add exp so reading them properly gives xp */
1340  op->stats.exp = op->value/5;
1341  op->nrof = op->inv->nrof;
1342  /* some more fun */
1343  if (!(flags&GT_ONLY_GOOD) && rndm(1, 100) <= 20) {
1344  if (rndm(1, 6) <= 1)
1345  SET_FLAG(op, FLAG_DAMNED);
1346  else
1347  SET_FLAG(op, FLAG_CURSED);
1348  } else if (rndm(1, 100) <= 2) {
1349  SET_FLAG(op, FLAG_BLESSED);
1350  }
1351  break;
1352 
1353  case RUNE:
1354  trap_adjust(op, difficulty);
1355  break;
1356 
1357  case TRAP:
1358  trap_adjust(op, difficulty);
1359  break;
1360  } /* switch type */
1361  }
1362  if (flags&GT_STARTEQUIP) {
1363  if (op->nrof < 2
1364  && op->type != CONTAINER
1365  && op->type != MONEY
1366  && !QUERY_FLAG(op, FLAG_IS_THROWN))
1368  else if (op->type != MONEY)
1369  op->value = 0;
1370  }
1371 
1372  if (!(flags&GT_ENVIRONMENT))
1373  fix_flesh_item(op, creator);
1374 }
1375 
1376 /*
1377  *
1378  *
1379  * CODE DEALING WITH ARTIFACTS STARTS HERE
1380  *
1381  *
1382  */
1383 
1394  artifactlist *tl = (artifactlist *)malloc(sizeof(artifactlist));
1395  if (tl == NULL)
1397  tl->next = NULL;
1398  tl->items = NULL;
1399  tl->total_chance = 0;
1400  return tl;
1401 }
1402 
1413  artifact *t = (artifact *)malloc(sizeof(artifact));
1414  if (t == NULL)
1416  t->item = NULL;
1417  t->next = NULL;
1418  t->chance = 0;
1419  t->difficulty = 0;
1420  t->allowed = NULL;
1421  return t;
1422 }
1423 
1432  artifactlist *al;
1433 
1434  for (al = first_artifactlist; al != NULL; al = al->next)
1435  if (al->type == type)
1436  return al;
1437  return NULL;
1438 }
1439 
1446 void dump_artifacts(void) {
1447  artifactlist *al;
1448  artifact *art;
1449  linked_char *next;
1450 
1451  fprintf(logfile, "\n");
1452  for (al = first_artifactlist; al != NULL; al = al->next) {
1453  fprintf(logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance);
1454  for (art = al->items; art != NULL; art = art->next) {
1455  fprintf(logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", art->item->name, art->difficulty, art->chance);
1456  if (art->allowed != NULL) {
1457  fprintf(logfile, "\tAllowed combinations:");
1458  for (next = art->allowed; next != NULL; next = next->next)
1459  fprintf(logfile, "%s,", next->name);
1460  fprintf(logfile, "\n");
1461  }
1462  }
1463  }
1464  fprintf(logfile, "\n");
1465 }
1466 
1470 static void dump_monster_treasure_rec(const char *name, treasure *t, int depth) {
1471  treasurelist *tl;
1472  int i;
1473 
1474  if (depth > 100)
1475  return;
1476 
1477  while (t != NULL) {
1478  if (t->name != NULL) {
1479  for (i = 0; i < depth; i++)
1480  fprintf(logfile, " ");
1481  fprintf(logfile, "{ (list: %s)\n", t->name);
1482  tl = find_treasurelist(t->name);
1483  dump_monster_treasure_rec(name, tl->items, depth+2);
1484  for (i = 0; i < depth; i++)
1485  fprintf(logfile, " ");
1486  fprintf(logfile, "} (end of list: %s)\n", t->name);
1487  } else {
1488  for (i = 0; i < depth; i++)
1489  fprintf(logfile, " ");
1490  if (t->item->clone.type == FLESH)
1491  fprintf(logfile, "%s's %s\n", name, t->item->clone.name);
1492  else
1493  fprintf(logfile, "%s\n", t->item->clone.name);
1494  }
1495  if (t->next_yes != NULL) {
1496  for (i = 0; i < depth; i++)
1497  fprintf(logfile, " ");
1498  fprintf(logfile, " (if yes)\n");
1499  dump_monster_treasure_rec(name, t->next_yes, depth+1);
1500  }
1501  if (t->next_no != NULL) {
1502  for (i = 0; i < depth; i++)
1503  fprintf(logfile, " ");
1504  fprintf(logfile, " (if no)\n");
1505  dump_monster_treasure_rec(name, t->next_no, depth+1);
1506  }
1507  t = t->next;
1508  }
1509 }
1510 
1515 void dump_monster_treasure(const char *name) {
1516  archetype *at;
1517  int found;
1518 
1519  found = 0;
1520  fprintf(logfile, "\n");
1521  for (at = first_archetype; at != NULL; at = at->next)
1522  if (!strcasecmp(at->clone.name, name) && at->clone.title == NULL) {
1523  fprintf(logfile, "treasures for %s (arch: %s)\n", at->clone.name, at->name);
1524  if (at->clone.randomitems != NULL)
1526  else
1527  fprintf(logfile, "(nothing)\n");
1528  fprintf(logfile, "\n");
1529  found++;
1530  }
1531  if (found == 0)
1532  fprintf(logfile, "No objects have the name %s!\n\n", name);
1533 }
1534 
1539 void init_artifacts(void) {
1540  static int has_been_inited = 0;
1541  FILE *fp;
1542  char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next;
1543  artifact *art = NULL;
1544  linked_char *tmp;
1545  int value, comp;
1546  artifactlist *al;
1547  archetype dummy_archetype;
1548 
1549  memset(&dummy_archetype, 0, sizeof(archetype));
1550 
1551  if (has_been_inited)
1552  return;
1553  else
1554  has_been_inited = 1;
1555 
1556  artifact_init = 1;
1557 
1558  snprintf(filename, sizeof(filename), "%s/artifacts", settings.datadir);
1559  LOG(llevDebug, "Reading artifacts from %s...\n", filename);
1560  if ((fp = open_and_uncompress(filename, 0, &comp)) == NULL) {
1561  LOG(llevError, "Can't open %s.\n", filename);
1562  return;
1563  }
1564 
1565  while (fgets(buf, HUGE_BUF, fp) != NULL) {
1566  if (*buf == '#')
1567  continue;
1568  if ((cp = strchr(buf, '\n')) != NULL)
1569  *cp = '\0';
1570  cp = buf;
1571  while (*cp == ' ') /* Skip blanks */
1572  cp++;
1573  if (*cp == '\0')
1574  continue;
1575 
1576  if (!strncmp(cp, "Allowed", 7)) {
1577  if (art == NULL) {
1578  art = get_empty_artifact();
1579  nrofartifacts++;
1580  }
1581 
1582  cp = strchr(cp, ' ')+1;
1583  while (*(cp+strlen(cp)-1) == ' ')
1584  cp[strlen(cp)-1] = '\0';
1585 
1586  if (!strcmp(cp, "all"))
1587  continue;
1588 
1589  do {
1590  while (*cp == ' ')
1591  cp++;
1592  nrofallowedstr++;
1593  if ((next = strchr(cp, ',')) != NULL)
1594  *(next++) = '\0';
1595  tmp = (linked_char *)malloc(sizeof(linked_char));
1596  tmp->name = add_string(cp);
1597  tmp->next = art->allowed;
1598  art->allowed = tmp;
1599  } while ((cp = next) != NULL);
1600  } else if (sscanf(cp, "chance %d", &value))
1601  art->chance = (uint16)value;
1602  else if (sscanf(cp, "difficulty %d", &value))
1603  art->difficulty = (uint8)value;
1604  else if (!strncmp(cp, "Object", 6)) {
1605  art->item = (object *)calloc(1, sizeof(object));
1606  if (art->item == NULL) {
1607  LOG(llevError, "init_artifacts: memory allocation failure.\n");
1608  abort();
1609  }
1610  reset_object(art->item);
1611  art->item->arch = &dummy_archetype;
1612  if (!load_object(fp, art->item, LO_LINEMODE, 0))
1613  LOG(llevError, "Init_Artifacts: Could not load object.\n");
1614  art->item->arch = NULL;
1615  art->item->name = add_string((strchr(cp, ' ')+1));
1616  al = find_artifactlist(art->item->type);
1617  if (al == NULL) {
1618  al = get_empty_artifactlist();
1619  al->type = art->item->type;
1620  al->next = first_artifactlist;
1621  first_artifactlist = al;
1622  }
1623  art->next = al->items;
1624  al->items = art;
1625  art = NULL;
1626  } else
1627  LOG(llevError, "Unknown input in artifact file: %s\n", buf);
1628  }
1629 
1630  close_and_delete(fp, comp);
1631 
1632  for (al = first_artifactlist; al != NULL; al = al->next) {
1633  for (art = al->items; art != NULL; art = art->next) {
1634  if (!art->chance)
1635  LOG(llevError, "Warning: artifact with no chance: %s\n", art->item->name);
1636  else
1637  al->total_chance += art->chance;
1638  }
1639 #if 0
1640  LOG(llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
1641 #endif
1642  }
1643 
1644  LOG(llevDebug, "done artifacts.\n");
1645  artifact_init = 0;
1646 }
1647 
1648 
1653 void add_abilities(object *op, object *change) {
1654  int i, tmp;
1655 
1656  if (change->face != blank_face) {
1657 #ifdef TREASURE_VERBOSE
1658  LOG(llevDebug, "FACE: %d\n", change->face->number);
1659 #endif
1660  op->face = change->face;
1661  }
1662  if (change->animation_id != 0) {
1663  op->animation_id = change->animation_id;
1664  SET_FLAG(op, FLAG_ANIMATE);
1665  animate_object(op, op->facing);
1666  }
1667 
1668  for (i = 0; i < NUM_STATS; i++)
1669  change_attr_value(&(op->stats), i, get_attr_value(&(change->stats), i));
1670 
1671  op->attacktype |= change->attacktype;
1672  op->path_attuned |= change->path_attuned;
1673  op->path_repelled |= change->path_repelled;
1674  op->path_denied |= change->path_denied;
1675  op->move_type |= change->move_type;
1676  op->stats.luck += change->stats.luck;
1677 
1678  if (QUERY_FLAG(change, FLAG_CURSED))
1679  SET_FLAG(op, FLAG_CURSED);
1680  if (QUERY_FLAG(change, FLAG_DAMNED))
1681  SET_FLAG(op, FLAG_DAMNED);
1682  if ((QUERY_FLAG(change, FLAG_CURSED) || QUERY_FLAG(change, FLAG_DAMNED))
1683  && op->magic > 0)
1684  set_abs_magic(op, -op->magic);
1685 
1686  if (QUERY_FLAG(change, FLAG_LIFESAVE))
1687  SET_FLAG(op, FLAG_LIFESAVE);
1688  if (QUERY_FLAG(change, FLAG_REFL_SPELL))
1690  if (QUERY_FLAG(change, FLAG_STEALTH))
1691  SET_FLAG(op, FLAG_STEALTH);
1692  if (QUERY_FLAG(change, FLAG_XRAYS))
1693  SET_FLAG(op, FLAG_XRAYS);
1694  if (QUERY_FLAG(change, FLAG_BLIND))
1695  SET_FLAG(op, FLAG_BLIND);
1696  if (QUERY_FLAG(change, FLAG_SEE_IN_DARK))
1698  if (QUERY_FLAG(change, FLAG_REFL_MISSILE))
1700  if (QUERY_FLAG(change, FLAG_MAKE_INVIS))
1702 
1703  if (QUERY_FLAG(change, FLAG_STAND_STILL)) {
1704  CLEAR_FLAG(op, FLAG_ANIMATE);
1705  /* so artifacts will join */
1706  if (!QUERY_FLAG(op, FLAG_ALIVE))
1707  op->speed = 0.0;
1708  update_ob_speed(op);
1709  }
1710  if (change->nrof)
1711  op->nrof = RANDOM()%((int)change->nrof)+1;
1712  op->stats.exp += change->stats.exp; /* Speed modifier */
1713  op->stats.wc += change->stats.wc;
1714  op->stats.ac += change->stats.ac;
1715 
1716  if (change->other_arch) {
1717  /* Basically, for horns & potions, the other_arch field is the spell
1718  * to cast. So convert that to into a spell and put it into
1719  * this object.
1720  */
1721  if (op->type == HORN || op->type == POTION) {
1722  object *tmp_obj;
1723 
1724  /* Remove any spells this object currently has in it */
1725  while (op->inv) {
1726  tmp_obj = op->inv;
1727  remove_ob(tmp_obj);
1728  free_object(tmp_obj);
1729  }
1730  tmp_obj = arch_to_object(change->other_arch);
1731  insert_ob_in_ob(tmp_obj, op);
1732  }
1733  /* No harm setting this for potions/horns */
1734  op->other_arch = change->other_arch;
1735  }
1736 
1737  if (change->stats.hp < 0)
1738  op->stats.hp = -change->stats.hp;
1739  else
1740  op->stats.hp += change->stats.hp;
1741  if (change->stats.maxhp < 0)
1742  op->stats.maxhp = -change->stats.maxhp;
1743  else
1744  op->stats.maxhp += change->stats.maxhp;
1745  if (change->stats.sp < 0)
1746  op->stats.sp = -change->stats.sp;
1747  else
1748  op->stats.sp += change->stats.sp;
1749  if (change->stats.maxsp < 0)
1750  op->stats.maxsp = -change->stats.maxsp;
1751  else
1752  op->stats.maxsp += change->stats.maxsp;
1753  if (change->stats.food < 0)
1754  op->stats.food = -(change->stats.food);
1755  else
1756  op->stats.food += change->stats.food;
1757  if (change->level < 0)
1758  op->level = -(change->level);
1759  else
1760  op->level += change->level;
1761 
1762  if (change->gen_sp_armour < 0)
1763  op->gen_sp_armour = -(change->gen_sp_armour);
1764  else
1765  op->gen_sp_armour = (op->gen_sp_armour*(change->gen_sp_armour))/100;
1766 
1767  op->item_power = change->item_power;
1768 
1769  for (i = 0; i < NROFATTACKS; i++) {
1770  if (change->resist[i]) {
1771  op->resist[i] += change->resist[i];
1772  }
1773  }
1774  if (change->stats.dam) {
1775  if (change->stats.dam < 0)
1776  op->stats.dam = (-change->stats.dam);
1777  else if (op->stats.dam) {
1778  tmp = (int)(((int)op->stats.dam*(int)change->stats.dam)/10);
1779  if (tmp == op->stats.dam) {
1780  if (change->stats.dam < 10)
1781  op->stats.dam--;
1782  else
1783  op->stats.dam++;
1784  } else
1785  op->stats.dam = tmp;
1786  }
1787  }
1788  if (change->weight) {
1789  if (change->weight < 0)
1790  op->weight = (-change->weight);
1791  else
1792  op->weight = (op->weight*(change->weight))/100;
1793  }
1794  if (change->last_sp) {
1795  if (change->last_sp < 0)
1796  op->last_sp = (-change->last_sp);
1797  else
1798  op->last_sp = (signed char)(((int)op->last_sp*(int)change->last_sp)/(int)100);
1799  }
1800  if (change->gen_sp_armour) {
1801  if (change->gen_sp_armour < 0)
1802  op->gen_sp_armour = (-change->gen_sp_armour);
1803  else
1804  op->gen_sp_armour = (signed char)(((int)op->gen_sp_armour*((int)change->gen_sp_armour))/(int)100);
1805  }
1806  op->value *= change->value;
1807 
1808  if (change->material)
1809  op->material = change->material;
1810 
1811  if (change->materialname) {
1812  if (op->materialname)
1814  op->materialname = add_refcount(change->materialname);
1815  }
1816 
1817  if (change->slaying) {
1818  if (op->slaying)
1819  free_string(op->slaying);
1820  op->slaying = add_refcount(change->slaying);
1821  }
1822  if (change->race) {
1823  if (op->race)
1824  free_string(op->race);
1825  op->race = add_refcount(change->race);
1826  }
1827  if (change->msg) {
1828  if (op->msg)
1829  free_string(op->msg);
1830  op->msg = add_refcount(change->msg);
1831  }
1832 
1833  if (change->inv) {
1834  object *inv = change->inv;
1835  object *copy;
1836 
1837  while (inv) {
1838  copy = get_object();
1839  copy_object(inv, copy);
1840  insert_ob_in_ob(copy, op);
1841  inv = inv->below;
1842  }
1843  }
1844 }
1845 
1849 int legal_artifact_combination(object *op, artifact *art) {
1850  int neg, success = 0;
1851  linked_char *tmp;
1852  const char *name;
1853 
1854  if (art->allowed == (linked_char *)NULL)
1855  return 1; /* Ie, "all" */
1856  for (tmp = art->allowed; tmp; tmp = tmp->next) {
1857 #ifdef TREASURE_VERBOSE
1858  LOG(llevDebug, "legal_art: %s\n", tmp->name);
1859 #endif
1860  if (*tmp->name == '!')
1861  name = tmp->name+1,
1862  neg = 1;
1863  else
1864  name = tmp->name,
1865  neg = 0;
1866 
1867  /* If we match name, then return the opposite of 'neg' */
1868  if (!strcmp(name, op->name) || (op->arch && !strcmp(name, op->arch->name)))
1869  return !neg;
1870 
1871  /* Set success as true, since if the match was an inverse, it means
1872  * everything is allowed except what we match
1873  */
1874  else if (neg)
1875  success = 1;
1876  }
1877  return success;
1878 }
1879 
1884 void give_artifact_abilities(object *op, object *artifact) {
1885  char new_name[MAX_BUF];
1886 
1887  snprintf(new_name, sizeof(new_name), "of %s", artifact->name);
1888  if (op->title)
1889  free_string(op->title);
1890  op->title = add_string(new_name);
1891  add_abilities(op, artifact); /* Give out the bonuses */
1892 
1893  return;
1894 }
1895 
1897 #define ARTIFACT_TRIES 2
1898 
1906 void generate_artifact(object *op, int difficulty) {
1907  artifactlist *al;
1908  artifact *art;
1909  int i;
1910 
1911  al = find_artifactlist(op->type);
1912 
1913  if (al == NULL) {
1914  return;
1915  }
1916 
1917  for (i = 0; i < ARTIFACT_TRIES; i++) {
1918  int roll = RANDOM()%al->total_chance;
1919 
1920  for (art = al->items; art != NULL; art = art->next) {
1921  roll -= art->chance;
1922  if (roll < 0)
1923  break;
1924  }
1925 
1926  if (art == NULL || roll >= 0) {
1927  LOG(llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type);
1928  return;
1929  }
1930  if (!strcmp(art->item->name, "NONE"))
1931  return;
1932  if (FABS(op->magic) < art->item->magic)
1933  continue; /* Not magic enough to be this item */
1934 
1935  /* Map difficulty not high enough */
1936  if (difficulty < art->difficulty)
1937  continue;
1938 
1939  if (!legal_artifact_combination(op, art)) {
1940 #ifdef TREASURE_VERBOSE
1941  LOG(llevDebug, "%s of %s was not a legal combination.\n", op->name, art->item->name);
1942 #endif
1943  continue;
1944  }
1945  give_artifact_abilities(op, art->item);
1946  return;
1947  }
1948 }
1949 
1955 static void fix_flesh_item(object *item, object *donor) {
1956  char tmpbuf[MAX_BUF];
1957  int i;
1958 
1959  if (item->type == FLESH && donor && QUERY_FLAG(donor, FLAG_MONSTER)) {
1960  /* change the name */
1961  snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name);
1962  FREE_AND_COPY(item->name, tmpbuf);
1963  snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name_pl);
1964  FREE_AND_COPY(item->name_pl, tmpbuf);
1965 
1966  /* store original arch in other_arch */
1967  if (!item->other_arch) {
1968  if (!donor->arch->reference_count) {
1969  item->other_arch = donor->arch;
1970  } else {
1971  /* If dealing with custom monsters, other_arch still needs to
1972  * point back to the original. Otherwise what happens
1973  * is that other_arch points at the custom archetype, but
1974  * that can be freed. Reference count doesn't work because
1975  * the loader will not be able to resolve the other_arch at
1976  * load time (server may has restarted, etc.)
1977  */
1978  archetype *original = find_archetype(donor->arch->name);
1979 
1980  if (original)
1981  item->other_arch = original;
1982  else {
1983  LOG(llevError, "could not find original archetype %s for custom monster!\n", donor->arch->name);
1984  abort();
1985  }
1986  }
1987  }
1988 
1989  /* weight is FLESH weight/100 * donor */
1990  if ((item->weight = (signed long)(((double)item->weight/(double)100.0)*(double)donor->weight)) == 0)
1991  item->weight = 1;
1992 
1993  /* value is multiplied by level of donor */
1994  item->value *= isqrt(donor->level*2);
1995 
1996  /* food value */
1997  item->stats.food += (donor->stats.hp/100)+donor->stats.Con;
1998 
1999  /* flesh items inherit some abilities of donor, but not full effect. */
2000  for (i = 0; i < NROFATTACKS; i++)
2001  item->resist[i] = donor->resist[i]/2;
2002 
2003  /* item inherits donor's level and exp (important for dragons) */
2004  item->level = donor->level;
2005  item->stats.exp = donor->stats.exp;
2006 
2007  /* if donor has some attacktypes, the flesh is poisonous */
2008  if (donor->attacktype&AT_POISON)
2009  item->type = POISON;
2010  if (donor->attacktype&AT_ACID)
2011  item->stats.hp = -1*item->stats.food;
2012  SET_FLAG(item, FLAG_NO_STEAL);
2013  }
2014 }
2015 
2024 static int special_potion(object *op) {
2025  int i;
2026 
2027  if (op->attacktype)
2028  return 1;
2029 
2030  if (op->stats.Str
2031  || op->stats.Dex
2032  || op->stats.Con
2033  || op->stats.Pow
2034  || op->stats.Wis
2035  || op->stats.Int
2036  || op->stats.Cha)
2037  return 1;
2038 
2039  for (i = 0; i < NROFATTACKS; i++)
2040  if (op->resist[i])
2041  return 1;
2042 
2043  return 0;
2044 }
2045 
2053  if (t->next)
2055  if (t->next_yes)
2057  if (t->next_no)
2059  free(t);
2060 }
2061 
2068 static void free_charlinks(linked_char *lc) {
2069  if (lc->next)
2070  free_charlinks(lc->next);
2071  free(lc);
2072 }
2073 
2086 static void free_artifact(artifact *at) {
2087  object *next;
2088 
2089  if (at->next)
2090  free_artifact(at->next);
2091  if (at->allowed)
2092  free_charlinks(at->allowed);
2093  while (at->item) {
2094  next = at->item->next;
2095  if (at->item->name)
2096  free_string(at->item->name);
2097  if (at->item->name_pl)
2098  free_string(at->item->name_pl);
2099  if (at->item->msg)
2100  free_string(at->item->msg);
2101  if (at->item->title)
2102  free_string(at->item->title);
2103  free_key_values(at->item);
2104  free(at->item);
2105  at->item = next;
2106  }
2107  free(at);
2108 }
2109 
2117  artifactlist *nextal;
2118 
2119  for (; al != NULL; al = nextal) {
2120  nextal = al->next;
2121  if (al->items) {
2122  free_artifact(al->items);
2123  }
2124  free(al);
2125  }
2126 }
2127 
2132  treasurelist *tl, *next;
2133 
2134  for (tl = first_treasurelist; tl != NULL; tl = next) {
2135  next = tl->next;
2136  if (tl->name)
2137  free_string(tl->name);
2138  if (tl->items)
2140  free(tl);
2141  }
2143  first_artifactlist = NULL;
2144 }
EXTERN FILE * logfile
Definition: global.h:220
int legal_artifact_combination(object *op, artifact *art)
Definition: treasure.c:1849
int reference_count
Definition: object.h:329
#define RING
Definition: define.h:232
sint8 Int
Definition: living.h:78
#define FLAG_SEE_IN_DARK
Definition: define.h:634
archetype * find_archetype(const char *name)
Definition: arch.c:700
#define FLAG_DAMNED
Definition: define.h:614
sint8 ac
Definition: living.h:79
MoveType move_type
Definition: object.h:277
#define LO_LINEMODE
Definition: loader.h:44
#define OUT_OF_MEMORY
Definition: define.h:94
static void free_treasurestruct(treasure *t)
Definition: treasure.c:2052
const char *const spell_mapping[]
const char * race
Definition: object.h:171
#define ARTIFACT_TRIES
Definition: treasure.c:1897
const char * name
Definition: treasure.h:81
struct _change_arch change_arch
Definition: treasure.h:98
#define SET_FLAG(xyz, p)
Definition: define.h:510
sstring add_refcount(sstring str)
Definition: shstr.c:202
#define MAXMAGIC
Definition: treasure.h:41
uint8 range_modifier
Definition: object.h:257
int get_power_from_ench(int ench)
Definition: item.c:240
#define FABS(x)
Definition: define.h:61
void dump_artifacts(void)
Definition: treasure.c:1446
sint16 total_chance
Definition: treasure.h:113
#define TRAP
Definition: define.h:326
#define WAND
Definition: define.h:291
uint16 material
Definition: object.h:198
#define FLAG_STAND_STILL
Definition: define.h:605
#define MONEY
Definition: define.h:148
struct artifactstruct * items
Definition: artifact.h:52
static void free_charlinks(linked_char *lc)
Definition: treasure.c:2068
treasurelist * find_treasurelist(const char *name)
Definition: treasure.c:295
sint8 get_attr_value(const living *stats, int attr)
Definition: living.c:377
void free_string(sstring str)
Definition: shstr.c:272
#define HUGE_BUF
Definition: define.h:83
#define SET_ANIMATION(ob, newanim)
Definition: global.h:247
struct treasureliststruct * randomitems
Definition: object.h:236
object clone
Definition: object.h:326
struct treasureliststruct * next
Definition: treasure.h:118
sint16 invisible
Definition: object.h:211
#define POTION
Definition: define.h:117
const char * slaying
Definition: object.h:172
sint32 last_sp
Definition: object.h:209
#define SCROLL
Definition: define.h:293
#define FLAG_STEALTH
Definition: define.h:609
static int level_for_item(const object *op, int difficulty, int retmult)
Definition: treasure.c:554
sint64 exp
Definition: living.h:88
#define RUNE
Definition: define.h:325
void close_and_delete(FILE *fp, int compressed)
Definition: porting.c:748
#define CLOAK
Definition: define.h:268
sint16 x
Definition: object.h:179
uint32 path_attuned
Definition: object.h:194
sint16 sp
Definition: living.h:83
void change_attr_value(living *stats, int attr, sint8 value)
Definition: living.c:336
static artifactlist * get_empty_artifactlist(void)
Definition: treasure.c:1393
uint32 path_repelled
Definition: object.h:195
struct archt * other_arch
Definition: object.h:264
const char * treasures
Definition: global.h:340
#define ARMOUR
Definition: define.h:128
Definition: object.h:321
uint8 dam_modifier
Definition: object.h:258
struct archt * item
Definition: treasure.h:93
sint16 maxsp
Definition: living.h:84
sint8 Con
Definition: living.h:78
sint16 hp
Definition: living.h:81
static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:390
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:499
static int get_magic(int diff)
Definition: treasure.c:1030
void trap_adjust(object *trap, int difficulty)
Definition: standalone.c:222
void set_materialname(object *op, int difficulty, materialtype_t *nmt)
Definition: utils.c:314
void add_abilities(object *op, object *change)
Definition: treasure.c:1653
int rndm(int min, int max)
Definition: utils.c:174
#define AMULET
Definition: define.h:153
uint16 number
Definition: face.h:43
const char * title
Definition: object.h:170
EXTERN archetype * amulet_arch
Definition: global.h:238
void remove_ob(object *op)
Definition: object.c:1515
sint16 maxhp
Definition: living.h:82
sstring find_string(const char *str)
Definition: shstr.c:228
#define POISON
Definition: define.h:119
static artifact * get_empty_artifact(void)
Definition: treasure.c:1412
uint32 path_denied
Definition: object.h:196
#define FLAG_ALIVE
Definition: define.h:526
#define FLAG_REFL_SPELL
Definition: define.h:571
struct artifactliststruct * next
Definition: artifact.h:51
const char * name_pl
Definition: object.h:168
object * create_archetype(const char *name)
Definition: arch.c:625
#define FLAG_OBJ_ORIGINAL
Definition: define.h:661
artifactlist * find_artifactlist(int type)
Definition: treasure.c:1431
#define DIFFLEVELS
Definition: treasure.h:44
static void change_treasure(treasure *t, object *op)
Definition: treasure.c:354
#define FLAG_NO_STEAL
Definition: define.h:639
const char * materialname
Definition: object.h:197
sint32 weight
Definition: object.h:216
void free_all_treasures(void)
Definition: treasure.c:2131
static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1]
Definition: treasure.c:594
sint8 Wis
Definition: living.h:78
#define CHANCE_FOR_ARTIFACT
Definition: treasure.h:38
static int special_potion(object *op)
Definition: treasure.c:2024
#define MAX_SPELLITEM_LEVEL
Definition: treasure.h:47
struct mapdef * map
Definition: object.h:155
uint8 difficulty
Definition: artifact.h:40
int artifact_init
Definition: treasure.c:61
void set_attr_value(living *stats, int attr, sint8 value)
Definition: living.c:296
#define HORN
Definition: define.h:147
static void check_treasurelist(const treasure *t, const treasurelist *tl)
Definition: treasure.c:200
struct linked_char * next
Definition: global.h:161
uint16 chance
Definition: artifact.h:39
sint16 dam
Definition: living.h:87
const char * name
Definition: object.h:167
void monster_check_apply(object *mon, object *item)
Definition: standalone.c:219
#define SPELL
Definition: define.h:283
const char * title
Definition: treasure.h:82
linked_char * allowed
Definition: artifact.h:42
#define ARMOUR_SPEED(xyz)
Definition: define.h:788
#define FLESH
Definition: define.h:234
struct obj * below
Definition: object.h:145
void load_treasures(void)
Definition: treasure.c:224
uint16 difficulty
Definition: map.h:364
#define INS_NO_WALK_ON
Definition: object.h:396
void fatal(int err)
Definition: glue.c:60
void generate_artifact(object *op, int difficulty)
Definition: treasure.c:1906
void tailor_readable_ob(object *book, int msg_type)
Definition: readable.c:2010
uint32 nrof
Definition: object.h:184
unsigned char uint8
Definition: global.h:75
sint8 Cha
Definition: living.h:78
EXTERN int resist_table[]
Definition: attack.h:162
static treasurelist * get_empty_treasurelist(void)
Definition: treasure.c:91
static treasure * load_treasure(FILE *fp, int *line)
Definition: treasure.c:138
sint8 facing
Definition: object.h:186
sint16 y
Definition: object.h:179
sint8 item_power
Definition: object.h:213
#define WEAPON
Definition: define.h:127
#define FLAG_XRAYS
Definition: define.h:597
EXTERN treasurelist * first_treasurelist
Definition: global.h:193
struct treasurestruct * next_no
Definition: treasure.h:97
uint16 total_chance
Definition: artifact.h:50
#define MAX(x, y)
Definition: define.h:70
sint8 luck
Definition: living.h:80
float speed
Definition: object.h:181
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
#define CLEAR_FLAG(xyz, p)
Definition: define.h:512
EXTERN artifactlist * first_artifactlist
Definition: global.h:194
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
Definition: treasure.c:1070
object * insert_ob_in_ob(object *op, object *where)
Definition: object.c:2510
#define MAX_BUF
Definition: define.h:81
object * get_object(void)
Definition: object.c:921
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:1992
#define BOOK
Definition: define.h:120
unsigned short uint16
Definition: global.h:67
#define BRACERS
Definition: define.h:286
struct treasurestruct * items
Definition: treasure.h:119
sint8 wc
Definition: living.h:79
EXTERN archetype * crown_arch
Definition: global.h:238
#define FLAG_IS_THROWN
Definition: define.h:545
static void set_magic(int difficulty, object *op, int max_magic, int flags)
Definition: treasure.c:880
static const flag_definition flags[]
struct obj * next
Definition: object.h:135
sint8 Str
Definition: living.h:78
void animate_object(object *op, int dir)
Definition: anim.c:186
sint16 resist[NROFATTACKS]
Definition: object.h:192
EXTERN long nrofartifacts
Definition: global.h:224
static void put_treasure(object *op, object *creator, int flags)
Definition: treasure.c:326
#define FLAG_CURSED
Definition: define.h:613
const char * datadir
Definition: global.h:334
EXTERN long nrofallowedstr
Definition: global.h:225
#define SHIELD
Definition: define.h:145
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
#define AT_POISON
Definition: attack.h:114
#define num_resist_table
Definition: attack.h:257
#define FLAG_ANIMATE
Definition: define.h:538
const char * name
Definition: global.h:160
static void free_artifact(artifact *at)
Definition: treasure.c:2086
const char * name
Definition: treasure.h:112
uint32 attacktype
Definition: object.h:193
#define NUM_STATS
Definition: living.h:48
#define INS_NO_MERGE
Definition: object.h:394
#define FLAG_BLIND
Definition: define.h:633
struct treasurestruct * next_yes
Definition: treasure.h:96
#define CONTAINER
Definition: define.h:306
sint16 grace
Definition: living.h:85
#define FREE_AND_COPY(sv, nv)
Definition: global.h:288
#define NUM_ANIMATIONS(ob)
Definition: global.h:255
New_Face * blank_face
Definition: image.c:66
living stats
Definition: object.h:219
int load_object(FILE *fp, object *op, int bufstate, int map_flags)
sint8 Dex
Definition: living.h:78
struct archt * arch
Definition: object.h:263
void dump_monster_treasure(const char *name)
Definition: treasure.c:1515
EXTERN archetype * staff_arch
Definition: global.h:238
void reset_object(object *op)
Definition: object.c:639
struct Settings settings
Definition: init.c:48
int isqrt(int n)
Definition: porting.c:573
static int magic_from_difficulty(int difficulty)
Definition: treasure.c:808
void free_key_values(object *op)
Definition: object.c:659
struct archt * next
Definition: object.h:323
#define NROFATTACKS
Definition: attack.h:45
#define FLAG_LIFESAVE
Definition: define.h:602
const char * msg
Definition: object.h:175
#define FLAG_MAKE_INVIS
Definition: define.h:625
uint16 animation_id
Definition: object.h:267
#define FLAG_STARTEQUIP
Definition: define.h:564
void update_ob_speed(object *op)
Definition: object.c:1008
#define GET_ANIM_ID(ob)
Definition: global.h:249
sstring add_string(const char *str)
Definition: shstr.c:116
#define DICE2
Definition: treasure.c:1041
int strcasecmp(const char *s1, const char *s2)
Definition: porting.c:434
const char * slaying
Definition: treasure.h:83
#define FLAG_MONSTER
Definition: define.h:541
sint8 Pow
Definition: living.h:78
struct obj * inv
Definition: object.h:148
#define HELMET
Definition: define.h:146
#define SPELLBOOK
Definition: define.h:266
void give_artifact_abilities(object *op, object *artifact)
Definition: treasure.c:1884
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
static void fix_flesh_item(object *item, object *donor)
Definition: treasure.c:1955
EXTERN long warn_archetypes
Definition: global.h:208
EXTERN archetype * ring_arch
Definition: global.h:238
#define ROD
Definition: define.h:115
uint16 nrof
Definition: treasure.h:105
void set_abs_magic(object *op, int magic)
Definition: treasure.c:844
void copy_object(object *op2, object *op)
Definition: object.c:758
int calc_item_power(const object *op, int flag)
Definition: item.c:264
object * item
Definition: artifact.h:38
static void free_artifactlist(artifactlist *al)
Definition: treasure.c:2116
object * generate_treasure(treasurelist *t, int difficulty)
Definition: treasure.c:524
void free_object(object *ob)
Definition: object.c:1238
static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:435
New_Face * face
Definition: object.h:183
#define FLAG_BLESSED
Definition: define.h:674
static void set_ring_bonus(object *op, int bonus)
Definition: treasure.c:909
#define FLAG_NO_PICK
Definition: define.h:535
struct treasurestruct * next
Definition: treasure.h:95
#define FLAG_REFL_MISSILE
Definition: define.h:569
sint16 level
Definition: object.h:202
#define AT_ACID
Definition: attack.h:110
const char * name
Definition: treasure.h:94
void init_archetype_pointers(void)
Definition: treasure.c:66
EXTERN archetype * first_archetype
Definition: global.h:195
object * arch_to_object(archetype *at)
Definition: arch.c:576
FILE * open_and_uncompress(const char *name, int flag, int *compressed)
Definition: porting.c:724
sint32 value
Definition: object.h:201
sint8 magic
Definition: object.h:199
uint8 duration_modifier
Definition: object.h:255
uint8 chance
Definition: treasure.h:99
const char * name
Definition: object.h:322
static treasure * get_empty_treasure(void)
Definition: treasure.c:109
uint8 type
Definition: object.h:189
struct artifactstruct * next
Definition: artifact.h:41
void init_artifacts(void)
Definition: treasure.c:1539
static void dump_monster_treasure_rec(const char *name, treasure *t, int depth)
Definition: treasure.c:1470
sint8 gen_sp_armour
Definition: object.h:214
sint32 food
Definition: living.h:89
EXTERN long nroftreasures
Definition: global.h:223