Crossfire Server, Trunk
treasure.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
20 #include "global.h"
21 
22 #include <ctype.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <math.h>
26 
27 #include "loader.h"
28 #include "sproto.h"
29 #include "treasure.h"
30 
37 static int resist_table[] = {
43 };
44 
46 #define num_resist_table 19
47 
48 static void change_treasure(treasure *t, object *op); /* overrule default values */
49 static int special_potion(object *op);
50 static void fix_flesh_item(object *item, const object *donor);
51 
56  if (ring_arch == NULL)
57  ring_arch = find_archetype("ring");
58  if (amulet_arch == NULL)
59  amulet_arch = find_archetype("amulet");
60  if (crown_arch == NULL)
61  crown_arch = find_archetype("crown");
62 }
63 
75 static void put_treasure(object *op, object *creator, int flags) {
76  /* Bit of a hack - spells should never be put onto the map. The entire
77  * treasure stuff is a problem - there is no clear idea of knowing
78  * this is the original object, or if this is an object that should be created
79  * by another object.
80  */
81  if (flags&GT_ENVIRONMENT && op->type != SPELL) {
83  object_insert_in_map_at(op, creator->map, op, INS_NO_MERGE|INS_NO_WALK_ON, creator->x, creator->y);
84  } else
85  object_insert_in_ob(op, creator);
86 }
87 
98 static void change_treasure(treasure *t, object *op) {
99  /* CMD: change_name xxxx */
100  if (t->change_arch.name) {
101  FREE_AND_COPY(op->name, t->change_arch.name);
102  /* not great, but better than something that is completely wrong */
103  FREE_AND_COPY(op->name_pl, t->change_arch.name);
104  }
105 
106  if (t->change_arch.title) {
107  if (op->title)
108  free_string(op->title);
109  op->title = add_string(t->change_arch.title);
110  }
111 
112  if (t->change_arch.slaying) {
113  if (op->slaying)
114  free_string(op->slaying);
115  op->slaying = add_string(t->change_arch.slaying);
116  }
117 }
118 
134 static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries) {
135  object *tmp;
136 
137  if ((int)t->chance >= 100 || (RANDOM()%100+1) < t->chance) {
138  if (t->name) {
139  if (strcmp(t->name, "NONE") && difficulty >= t->magic)
140  create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries);
141  } else {
142  if (t->item->clone.invisible != 0 || !(flag&GT_INVISIBLE)) {
143  tmp = arch_to_object(t->item);
144  if (t->nrof && tmp->nrof <= 1)
145  tmp->nrof = RANDOM()%((int)t->nrof)+1;
146  fix_generated_item(tmp, op, difficulty, t->magic, flag);
148  put_treasure(tmp, op, flag);
149  }
150  }
151  if (t->next_yes != NULL)
152  create_all_treasures(t->next_yes, op, flag, difficulty, tries);
153  } else
154  if (t->next_no != NULL)
155  create_all_treasures(t->next_no, op, flag, difficulty, tries);
156  if (t->next != NULL)
157  create_all_treasures(t->next, op, flag, difficulty, tries);
158 }
159 
178 static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries) {
179  int value = RANDOM()%tl->total_chance;
180  treasure *t;
181 
182  if (tries++ > 100) {
183  LOG(llevDebug, "create_one_treasure: tries exceeded 100, returning without making treasure\n");
184  return;
185  }
186 
187  for (t = tl->items; t != NULL; t = t->next) {
188  value -= t->chance;
189  if (value < 0)
190  break;
191  }
192 
193  if (!t || value >= 0) {
194  LOG(llevError, "create_one_treasure: got null object or not able to find treasure\n");
195  abort();
196  }
197  if (t->name) {
198  if (!strcmp(t->name, "NONE"))
199  return;
200  if (difficulty >= t->magic)
201  create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries);
202  else if (t->nrof)
203  create_one_treasure(tl, op, flag, difficulty, tries);
204  return;
205  }
206  if ((t->item) && (flag&GT_ONLY_GOOD)) { /* Generate only good items, damnit !*/
207  if (QUERY_FLAG(&(t->item->clone), FLAG_CURSED)
208  || QUERY_FLAG(&(t->item->clone), FLAG_DAMNED)) {
209  create_one_treasure(tl, op, flag, difficulty, tries+1);
210  return;
211  }
212  }
213  if ((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) {
214  object *tmp = arch_to_object(t->item);
215 
216  if (!tmp)
217  return;
218  if (t->nrof && tmp->nrof <= 1)
219  tmp->nrof = RANDOM()%((int)t->nrof)+1;
220  fix_generated_item(tmp, op, difficulty, t->magic, flag);
222  put_treasure(tmp, op, flag);
223  }
224 }
225 
241 void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries) {
242  if (tries++ > 100) {
243  LOG(llevDebug, "createtreasure: tries exceeded 100, returning without making treasure\n");
244  return;
245  }
246  if (!t->items) {
247  LOG(llevError, "Empty treasure list %s\n", t->name);
248  return;
249  }
250  if (t->total_chance)
251  create_one_treasure(t, op, flag, difficulty, tries);
252  else
253  create_all_treasures(t->items, op, flag, difficulty, tries);
254 }
255 
273 object *generate_treasure(treasurelist *t, int difficulty) {
274  object *ob = object_new(), *tmp;
275 
276  create_treasure(t, ob, 0, difficulty, 0);
277 
278  /* Don't want to free the object we are about to return */
279  tmp = ob->inv;
280  if (tmp != NULL)
282  if (ob->inv) {
283  LOG(llevError, "In generate treasure, created multiple objects.\n");
284  }
286  return tmp;
287 }
288 
301 static int level_for_item(const object *op, int difficulty) {
302  int level, mult, olevel;
303 
304  if (!op->inv) {
305  LOG(llevError, "level_for_item: Object %s has no inventory!\n", op->name);
306  return 0;
307  }
308  level = op->inv->level;
309 
310  /* Basically, we set mult to the lowest spell increase attribute that is
311  * not zero - zero's mean no modification is done, so we don't want those.
312  * given we want non zero results, we can't just use a few MIN's here.
313  */
314  mult = op->inv->dam_modifier;
315  if (op->inv->range_modifier && (op->inv->range_modifier < mult || mult == 0))
316  mult = op->inv->range_modifier;
317  if (op->inv->duration_modifier && (op->inv->duration_modifier < mult || mult == 0))
318  mult = op->inv->duration_modifier;
319 
320  if (mult == 0)
321  mult = 5;
322 
323  olevel = mult*rndm(0, difficulty)+level;
324  if (olevel > MAX_SPELLITEM_LEVEL)
325  olevel = MAX_SPELLITEM_LEVEL;
326 
327  return olevel;
328 }
329 
337 static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1] = {
338 /*chance of magic difficulty*/
339 /* +0 +1 +2 +3 +4 */
340  { 94, 3, 2, 1, 0 }, /*1*/
341  { 94, 3, 2, 1, 0 }, /*2*/
342  { 94, 3, 2, 1, 0 }, /*3*/
343  { 94, 3, 2, 1, 0 }, /*4*/
344  { 94, 3, 2, 1, 0 }, /*5*/
345  { 90, 4, 3, 2, 1 }, /*6*/
346  { 90, 4, 3, 2, 1 }, /*7*/
347  { 90, 4, 3, 2, 1 }, /*8*/
348  { 90, 4, 3, 2, 1 }, /*9*/
349  { 90, 4, 3, 2, 1 }, /*10*/
350  { 85, 6, 4, 3, 2 }, /*11*/
351  { 85, 6, 4, 3, 2 }, /*12*/
352  { 85, 6, 4, 3, 2 }, /*13*/
353  { 85, 6, 4, 3, 2 }, /*14*/
354  { 85, 6, 4, 3, 2 }, /*15*/
355  { 81, 8, 5, 4, 3 }, /*16*/
356  { 81, 8, 5, 4, 3 }, /*17*/
357  { 81, 8, 5, 4, 3 }, /*18*/
358  { 81, 8, 5, 4, 3 }, /*19*/
359  { 81, 8, 5, 4, 3 }, /*20*/
360  { 75, 10, 6, 5, 4 }, /*21*/
361  { 75, 10, 6, 5, 4 }, /*22*/
362  { 75, 10, 6, 5, 4 }, /*23*/
363  { 75, 10, 6, 5, 4 }, /*24*/
364  { 75, 10, 6, 5, 4 }, /*25*/
365  { 70, 12, 7, 6, 5 }, /*26*/
366  { 70, 12, 7, 6, 5 }, /*27*/
367  { 70, 12, 7, 6, 5 }, /*28*/
368  { 70, 12, 7, 6, 5 }, /*29*/
369  { 70, 12, 7, 6, 5 }, /*30*/
370  { 70, 9, 8, 7, 6 }, /*31*/
371  { 70, 9, 8, 7, 6 }, /*32*/
372  { 70, 9, 8, 7, 6 }, /*33*/
373  { 70, 9, 8, 7, 6 }, /*34*/
374  { 70, 9, 8, 7, 6 }, /*35*/
375  { 70, 6, 9, 8, 7 }, /*36*/
376  { 70, 6, 9, 8, 7 }, /*37*/
377  { 70, 6, 9, 8, 7 }, /*38*/
378  { 70, 6, 9, 8, 7 }, /*39*/
379  { 70, 6, 9, 8, 7 }, /*40*/
380  { 70, 3, 10, 9, 8 }, /*41*/
381  { 70, 3, 10, 9, 8 }, /*42*/
382  { 70, 3, 10, 9, 8 }, /*43*/
383  { 70, 3, 10, 9, 8 }, /*44*/
384  { 70, 3, 10, 9, 8 }, /*45*/
385  { 70, 2, 9, 10, 9 }, /*46*/
386  { 70, 2, 9, 10, 9 }, /*47*/
387  { 70, 2, 9, 10, 9 }, /*48*/
388  { 70, 2, 9, 10, 9 }, /*49*/
389  { 70, 2, 9, 10, 9 }, /*50*/
390  { 70, 2, 7, 11, 10 }, /*51*/
391  { 70, 2, 7, 11, 10 }, /*52*/
392  { 70, 2, 7, 11, 10 }, /*53*/
393  { 70, 2, 7, 11, 10 }, /*54*/
394  { 70, 2, 7, 11, 10 }, /*55*/
395  { 70, 2, 5, 12, 11 }, /*56*/
396  { 70, 2, 5, 12, 11 }, /*57*/
397  { 70, 2, 5, 12, 11 }, /*58*/
398  { 70, 2, 5, 12, 11 }, /*59*/
399  { 70, 2, 5, 12, 11 }, /*60*/
400  { 70, 2, 3, 13, 12 }, /*61*/
401  { 70, 2, 3, 13, 12 }, /*62*/
402  { 70, 2, 3, 13, 12 }, /*63*/
403  { 70, 2, 3, 13, 12 }, /*64*/
404  { 70, 2, 3, 13, 12 }, /*65*/
405  { 70, 2, 3, 12, 13 }, /*66*/
406  { 70, 2, 3, 12, 13 }, /*67*/
407  { 70, 2, 3, 12, 13 }, /*68*/
408  { 70, 2, 3, 12, 13 }, /*69*/
409  { 70, 2, 3, 12, 13 }, /*70*/
410  { 70, 2, 3, 11, 14 }, /*71*/
411  { 70, 2, 3, 11, 14 }, /*72*/
412  { 70, 2, 3, 11, 14 }, /*73*/
413  { 70, 2, 3, 11, 14 }, /*74*/
414  { 70, 2, 3, 11, 14 }, /*75*/
415  { 70, 2, 3, 10, 15 }, /*76*/
416  { 70, 2, 3, 10, 15 }, /*77*/
417  { 70, 2, 3, 10, 15 }, /*78*/
418  { 70, 2, 3, 10, 15 }, /*79*/
419  { 70, 2, 3, 10, 15 }, /*80*/
420  { 70, 2, 3, 9, 16 }, /*81*/
421  { 70, 2, 3, 9, 16 }, /*82*/
422  { 70, 2, 3, 9, 16 }, /*83*/
423  { 70, 2, 3, 9, 16 }, /*84*/
424  { 70, 2, 3, 9, 16 }, /*85*/
425  { 70, 2, 3, 8, 17 }, /*86*/
426  { 70, 2, 3, 8, 17 }, /*87*/
427  { 70, 2, 3, 8, 17 }, /*88*/
428  { 70, 2, 3, 8, 17 }, /*89*/
429  { 70, 2, 3, 8, 17 }, /*90*/
430  { 70, 2, 3, 7, 18 }, /*91*/
431  { 70, 2, 3, 7, 18 }, /*92*/
432  { 70, 2, 3, 7, 18 }, /*93*/
433  { 70, 2, 3, 7, 18 }, /*94*/
434  { 70, 2, 3, 7, 18 }, /*95*/
435  { 70, 2, 3, 6, 19 }, /*96*/
436  { 70, 2, 3, 6, 19 }, /*97*/
437  { 70, 2, 3, 6, 19 }, /*98*/
438  { 70, 2, 3, 6, 19 }, /*99*/
439  { 70, 2, 3, 6, 19 }, /*100*/
440  { 70, 2, 3, 6, 19 }, /*101*/
441  { 70, 2, 3, 6, 19 }, /*101*/
442  { 70, 2, 3, 6, 19 }, /*102*/
443  { 70, 2, 3, 6, 19 }, /*103*/
444  { 70, 2, 3, 6, 19 }, /*104*/
445  { 70, 2, 3, 6, 19 }, /*105*/
446  { 70, 2, 3, 6, 19 }, /*106*/
447  { 70, 2, 3, 6, 19 }, /*107*/
448  { 70, 2, 3, 6, 19 }, /*108*/
449  { 70, 2, 3, 6, 19 }, /*109*/
450  { 70, 2, 3, 6, 19 }, /*110*/
451  { 70, 2, 3, 6, 19 }, /*111*/
452  { 70, 2, 3, 6, 19 }, /*112*/
453  { 70, 2, 3, 6, 19 }, /*113*/
454  { 70, 2, 3, 6, 19 }, /*114*/
455  { 70, 2, 3, 6, 19 }, /*115*/
456  { 70, 2, 3, 6, 19 }, /*116*/
457  { 70, 2, 3, 6, 19 }, /*117*/
458  { 70, 2, 3, 6, 19 }, /*118*/
459  { 70, 2, 3, 6, 19 }, /*119*/
460  { 70, 2, 3, 6, 19 }, /*120*/
461  { 70, 2, 3, 6, 19 }, /*121*/
462  { 70, 2, 3, 6, 19 }, /*122*/
463  { 70, 2, 3, 6, 19 }, /*123*/
464  { 70, 2, 3, 6, 19 }, /*124*/
465  { 70, 2, 3, 6, 19 }, /*125*/
466  { 70, 2, 3, 6, 19 }, /*126*/
467  { 70, 2, 3, 6, 19 }, /*127*/
468  { 70, 2, 3, 6, 19 }, /*128*/
469  { 70, 2, 3, 6, 19 }, /*129*/
470  { 70, 2, 3, 6, 19 }, /*130*/
471  { 70, 2, 3, 6, 19 }, /*131*/
472  { 70, 2, 3, 6, 19 }, /*132*/
473  { 70, 2, 3, 6, 19 }, /*133*/
474  { 70, 2, 3, 6, 19 }, /*134*/
475  { 70, 2, 3, 6, 19 }, /*135*/
476  { 70, 2, 3, 6, 19 }, /*136*/
477  { 70, 2, 3, 6, 19 }, /*137*/
478  { 70, 2, 3, 6, 19 }, /*138*/
479  { 70, 2, 3, 6, 19 }, /*139*/
480  { 70, 2, 3, 6, 19 }, /*140*/
481  { 70, 2, 3, 6, 19 }, /*141*/
482  { 70, 2, 3, 6, 19 }, /*142*/
483  { 70, 2, 3, 6, 19 }, /*143*/
484  { 70, 2, 3, 6, 19 }, /*144*/
485  { 70, 2, 3, 6, 19 }, /*145*/
486  { 70, 2, 3, 6, 19 }, /*146*/
487  { 70, 2, 3, 6, 19 }, /*147*/
488  { 70, 2, 3, 6, 19 }, /*148*/
489  { 70, 2, 3, 6, 19 }, /*149*/
490  { 70, 2, 3, 6, 19 }, /*150*/
491  { 70, 2, 3, 6, 19 }, /*151*/
492  { 70, 2, 3, 6, 19 }, /*152*/
493  { 70, 2, 3, 6, 19 }, /*153*/
494  { 70, 2, 3, 6, 19 }, /*154*/
495  { 70, 2, 3, 6, 19 }, /*155*/
496  { 70, 2, 3, 6, 19 }, /*156*/
497  { 70, 2, 3, 6, 19 }, /*157*/
498  { 70, 2, 3, 6, 19 }, /*158*/
499  { 70, 2, 3, 6, 19 }, /*159*/
500  { 70, 2, 3, 6, 19 }, /*160*/
501  { 70, 2, 3, 6, 19 }, /*161*/
502  { 70, 2, 3, 6, 19 }, /*162*/
503  { 70, 2, 3, 6, 19 }, /*163*/
504  { 70, 2, 3, 6, 19 }, /*164*/
505  { 70, 2, 3, 6, 19 }, /*165*/
506  { 70, 2, 3, 6, 19 }, /*166*/
507  { 70, 2, 3, 6, 19 }, /*167*/
508  { 70, 2, 3, 6, 19 }, /*168*/
509  { 70, 2, 3, 6, 19 }, /*169*/
510  { 70, 2, 3, 6, 19 }, /*170*/
511  { 70, 2, 3, 6, 19 }, /*171*/
512  { 70, 2, 3, 6, 19 }, /*172*/
513  { 70, 2, 3, 6, 19 }, /*173*/
514  { 70, 2, 3, 6, 19 }, /*174*/
515  { 70, 2, 3, 6, 19 }, /*175*/
516  { 70, 2, 3, 6, 19 }, /*176*/
517  { 70, 2, 3, 6, 19 }, /*177*/
518  { 70, 2, 3, 6, 19 }, /*178*/
519  { 70, 2, 3, 6, 19 }, /*179*/
520  { 70, 2, 3, 6, 19 }, /*180*/
521  { 70, 2, 3, 6, 19 }, /*181*/
522  { 70, 2, 3, 6, 19 }, /*182*/
523  { 70, 2, 3, 6, 19 }, /*183*/
524  { 70, 2, 3, 6, 19 }, /*184*/
525  { 70, 2, 3, 6, 19 }, /*185*/
526  { 70, 2, 3, 6, 19 }, /*186*/
527  { 70, 2, 3, 6, 19 }, /*187*/
528  { 70, 2, 3, 6, 19 }, /*188*/
529  { 70, 2, 3, 6, 19 }, /*189*/
530  { 70, 2, 3, 6, 19 }, /*190*/
531  { 70, 2, 3, 6, 19 }, /*191*/
532  { 70, 2, 3, 6, 19 }, /*192*/
533  { 70, 2, 3, 6, 19 }, /*193*/
534  { 70, 2, 3, 6, 19 }, /*194*/
535  { 70, 2, 3, 6, 19 }, /*195*/
536  { 70, 2, 3, 6, 19 }, /*196*/
537  { 70, 2, 3, 6, 19 }, /*197*/
538  { 70, 2, 3, 6, 19 }, /*198*/
539  { 70, 2, 3, 6, 19 }, /*199*/
540  { 70, 2, 3, 6, 19 }, /*200*/
541 };
542 
550 static int magic_from_difficulty(int difficulty) {
551  int percent, loop;
552 
553  difficulty--;
554  if (difficulty < 0)
555  difficulty = 0;
556 
557  if (difficulty >= DIFFLEVELS)
558  difficulty = DIFFLEVELS-1;
559 
560  percent = RANDOM()%100;
561 
562  for (loop = 0; loop < (MAXMAGIC+1); ++loop) {
563  percent -= difftomagic_list[difficulty][loop];
564  if (percent < 0)
565  break;
566  }
567  if (loop == (MAXMAGIC+1)) {
568  LOG(llevError, "Warning, table for difficulty %d bad.\n", difficulty);
569  loop = 0;
570  }
571  /* LOG(llevDebug, "Chose magic %d for difficulty %d\n", loop, difficulty);*/
572  return (RANDOM()%3) ? loop : -loop;
573 }
574 
590 void set_abs_magic(object *op, int magic) {
591  int32_t base_weight, base_speed;
592  if (!magic)
593  return;
594 
595  op->magic = magic;
596  if (op->arch) {
597  base_weight = op->arch->clone.weight;
598  base_speed = ARMOUR_SPEED(&op->arch->clone);
599  }
600  else {
601  base_weight = op->weight;
602  base_speed = ARMOUR_SPEED(op);
603  }
604  // Now we do the calculations
605  if (op->type == ARMOUR) {
607  ARMOUR_SPEED(op) = base_speed*(100+magic*settings.armor_speed_improvement)/100;
608  else
609  // This could have been done with a loop, but that seems to be less scalable.
610  // This will introduce less roundoff error than a loop, anyway
611  ARMOUR_SPEED(op) = (int32_t)(base_speed * pow(((float)(100+settings.armor_speed_improvement))/100, magic));
612  }
613  // Prepare for handling the weight. Sometimes cursed ones will have low weight like good ones.
614  if (magic < 0 && !(RANDOM()%3)) /* You can't just check the weight always */
615  magic = (-magic);
617  op->weight = (base_weight*(100-magic*settings.armor_weight_reduction))/100;
618  else
619  op->weight = (int32_t)(base_weight * pow(((float)(100-settings.armor_weight_reduction))/100, magic));
620 
621 }
622 
638 static void set_magic(int difficulty, object *op, int max_magic, int flags) {
639  int i;
640 
641  i = magic_from_difficulty(difficulty);
642  if ((flags&GT_ONLY_GOOD) && i < 0)
643  i = -i;
644  if (i > max_magic)
645  i = max_magic;
646  set_abs_magic(op, i);
647  if (i < 0)
649 }
650 
667 static void set_ring_bonus(object *op, int bonus) {
668  int r = RANDOM()%(bonus > 0 ? 25 : 11);
669 
670  if (op->type == AMULET) {
671  if (!(RANDOM()%21))
672  r = 20+RANDOM()%2;
673  else {
674  if (RANDOM()&2)
675  r = 10;
676  else
677  r = 11+RANDOM()%9;
678  }
679  }
680 
681  switch (r) {
682  /* Redone by MSW 2000-11-26 to have much less code. Also,
683  * bonuses and penalties will stack and add to existing values.
684  * of the item.
685  */
686  case 0:
687  case 1:
688  case 2:
689  case 3:
690  case 4:
691  case 5:
692  case 6:
693  set_attr_value(&op->stats, r, (signed char)(bonus+get_attr_value(&op->stats, r)));
694  break;
695 
696  case 7:
697  op->stats.dam += bonus;
698  break;
699 
700  case 8:
701  op->stats.wc += bonus;
702  break;
703 
704  case 9:
705  op->stats.food += bonus; /* hunger/sustenance */
706  break;
707 
708  case 10:
709  op->stats.ac += bonus;
710  break;
711 
712  /* Item that gives protections/vulnerabilities */
713  case 11:
714  case 12:
715  case 13:
716  case 14:
717  case 15:
718  case 16:
719  case 17:
720  case 18:
721  case 19: {
722  int b = 5+FABS(bonus), val, resist = RANDOM()%num_resist_table;
723 
724  /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */
725  val = 10+RANDOM()%b+RANDOM()%b+RANDOM()%b+RANDOM()%b;
726 
727  /* Cursed items need to have higher negative values to equal out with
728  * positive values for how protections work out. Put another
729  * little random element in since that they don't always end up with
730  * even values.
731  */
732  if (bonus < 0)
733  val = 2*-val-RANDOM()%b;
734  if (val > 35)
735  val = 35; /* Upper limit */
736  b = 0;
737  while (op->resist[resist_table[resist]] != 0 && b++ < 4) {
738  resist = RANDOM()%num_resist_table;
739  }
740  if (b == 4)
741  return; /* Not able to find a free resistance */
742  op->resist[resist_table[resist]] = val;
743  /* We should probably do something more clever here to adjust value
744  * based on how good a resistance we gave.
745  */
746  break;
747  }
748 
749  case 20:
750  if (op->type == AMULET) {
752  op->value *= 11;
753  } else {
754  op->stats.hp = 1; /* regenerate hit points */
755  op->value *= 4;
756  }
757  break;
758 
759  case 21:
760  if (op->type == AMULET) {
762  op->value *= 9;
763  } else {
764  op->stats.sp = 1; /* regenerate spell points */
765  op->value *= 3;
766  }
767  break;
768 
769  case 22:
770  op->stats.exp += bonus; /* Speed! */
771  op->value = (op->value*2)/3;
772  break;
773  }
774  if (bonus > 0)
775  op->value *= 2*bonus;
776  else
777  op->value = -(op->value*2*bonus)/3;
778 }
779 
788 static int get_magic(int diff) {
789  int i;
790 
791  if (diff < 3)
792  diff = 3;
793  for (i = 0; i < 4; i++)
794  if (RANDOM()%diff)
795  return i;
796  return 4;
797 }
798 
809 static void trap_adjust(object *trap, int difficulty) {
810  int i;
811 
812  /* now we set the trap level to match the difficulty of the level
813  * the formula below will give a level from 1 to (2*difficulty) with
814  * a peak probability at difficulty
815  */
816 
817  trap->level = rndm(0, difficulty-1)+rndm(0, difficulty-1);
818  if (trap->level < 1)
819  trap->level = 1;
820 
821  /* set the hiddenness of the trap, similar formula to above */
822  trap->stats.Cha = rndm(0, 19)+rndm(0, difficulty-1)+rndm(0, difficulty-1);
823 
824  if (!trap->other_arch && !trap->inv) {
825  /* set the damage of the trap.
826  * we get 0-4 pts of damage per level of difficulty of the map in
827  * the trap
828  */
829 
830  trap->stats.dam = 0;
831  for (i = 0; i < difficulty; i++)
832  trap->stats.dam += rndm(0, 4);
833 
834  /* the poison trap special case */
835  if (trap->attacktype&AT_POISON) {
836  trap->stats.dam = rndm(0, difficulty-1);
837  if (trap->stats.dam < 1)
838  trap->stats.dam = 1;
839  }
840 
841  /* so we get an appropriate amnt of exp for AT_DEATH traps */
842  if (trap->attacktype&AT_DEATH)
843  trap->stats.dam = 127;
844  }
845 }
846 
847 #define DICE2 (get_magic(2) == 2 ? 2 : 1)
848 #define DICESPELL (RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3+RANDOM()%3)
849 
876 void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags) {
877  int was_magic = op->magic, num_enchantments = 0, save_item_power;
878 
879  if (!creator || creator->type == op->type)
880  creator = op; /* safety & to prevent polymorphed objects giving attributes */
881 
882  /* If we make an artifact, this information will be destroyed */
883  save_item_power = op->item_power;
884  op->item_power = 0;
885 
886  if (op->randomitems && op->type != SPELL) {
887  create_treasure(op->randomitems, op, flags, difficulty, 0);
888  if (!op->inv)
889  LOG(llevDebug, "fix_generated_item: Unable to generate treasure for %s\n", op->name);
890  /* So the treasure doesn't get created again */
891  op->randomitems = NULL;
892  }
893 
894  if (difficulty < 1)
895  difficulty = 1;
896  if (!(flags&GT_MINIMAL)) {
897  if (op->arch == crown_arch) {
898  set_magic(difficulty > 25 ? 30 : difficulty+5, op, max_magic, flags);
899  num_enchantments = calc_item_power(op);
900  generate_artifact(op, difficulty);
901  } else {
902  if (!op->magic && max_magic)
903  set_magic(difficulty, op, max_magic, flags);
904  num_enchantments = calc_item_power(op);
905  if ((!was_magic && !(RANDOM()%CHANCE_FOR_ARTIFACT))
906  || op->type == ROD
907  || difficulty >= 999)
908  generate_artifact(op, difficulty);
909  }
910 
911  /* Object was made an artifact. Calculate its item_power rating.
912  * the item_power in the object is what the artifact adds.
913  */
914  if (op->title) {
915  /* if save_item_power is set, then most likely we started with an
916  * artifact and have added new abilities to it - this is rare, but
917  * but I have seen things like 'strange rings of fire'. So just
918  * figure out the power from the base power plus what this one adds.
919  * Note that since item_power is not quite linear, this actually
920  * ends up being somewhat of a bonus.
921  */
922  if (save_item_power)
923  op->item_power = save_item_power+get_power_from_ench(op->item_power);
924  else
925  op->item_power += get_power_from_ench(num_enchantments);
926  } else if (save_item_power) {
927  /* restore the item_power field to the object if we haven't changed
928  * it. we don't care about num_enchantments - that will basically
929  * just have calculated some value from the base attributes of the
930  * archetype.
931  */
932  op->item_power = save_item_power;
933  } else {
934  /* item_power was zero. This is suspicious, as it may be because it
935  * was never previously calculated. Let's compute a value and see if
936  * it is non-zero. If it indeed is, then assign it as the new
937  * item_power value.
938  * - gros, 21th of July 2006.
939  */
940  op->item_power = calc_item_power(op);
941  save_item_power = op->item_power; /* Just in case it would get used
942  * again below */
943  }
944  } else {
945  /* If flag is GT_MINIMAL, we want to restore item power */
946  op->item_power = save_item_power;
947  }
948 
949  /* materialtype modifications. Note we allow this on artifacts. */
951 
952  if (flags&GT_MINIMAL) {
953  if (op->type == POTION)
954  /* Handle healing and magic power potions */
955  if (op->stats.sp && !op->randomitems) {
956  object *tmp;
957  if (spell_mapping[op->stats.sp]) {
958  tmp = create_archetype(spell_mapping[op->stats.sp]);
960  }
961  op->stats.sp = 0;
962  }
963  } else if (!op->title) { /* Only modify object if not special */
964  switch (op->type) {
965  case WEAPON:
966  case ARMOUR:
967  case SHIELD:
968  case HELMET:
969  case CLOAK:
970  if (QUERY_FLAG(op, FLAG_CURSED) && !(RANDOM()%4))
972  break;
973 
974  case BRACERS:
975  if (!(RANDOM()%(QUERY_FLAG(op, FLAG_CURSED) ? 5 : 20))) {
977  if (!QUERY_FLAG(op, FLAG_CURSED))
978  op->value *= 3;
979  }
980  break;
981 
982  case POTION: {
983  int too_many_tries = 0, is_special = 0;
984 
985  /* Handle healing and magic power potions */
986  if (op->stats.sp && !op->randomitems) {
987  object *tmp;
988 
989  tmp = create_archetype(spell_mapping[op->stats.sp]);
991  op->stats.sp = 0;
992  }
993 
994  while (!(is_special = special_potion(op)) && !op->inv) {
995  generate_artifact(op, difficulty);
996  if (too_many_tries++ > 10)
997  break;
998  }
999  /* don't want to change value for healing/magic power potions,
1000  * since the value set on those is already correct.
1001  */
1002  if (op->inv && op->randomitems) {
1003  /* value multiplier is same as for scrolls */
1004  op->value = (op->value*op->inv->value);
1005  op->level = op->inv->level/2+RANDOM()%difficulty+RANDOM()%difficulty;
1006  } else {
1007  FREE_AND_COPY(op->name, "potion");
1008  FREE_AND_COPY(op->name_pl, "potions");
1009  }
1010  if (!(flags&GT_ONLY_GOOD) && RANDOM()%2)
1012  break;
1013  }
1014 
1015  case AMULET:
1016  if (op->arch == amulet_arch)
1017  op->value *= 5; /* Since it's not just decoration */
1018  /* fall through */
1019  case RING:
1020  if (op->arch == NULL) {
1021  object_remove(op);
1023  op = NULL;
1024  break;
1025  }
1026  if (op->arch != ring_arch && op->arch != amulet_arch)
1027  /* It's a special artifact!*/
1028  break;
1029 
1030  if (GET_ANIM_ID(op))
1031  SET_ANIMATION(op, RANDOM()%((int)NUM_ANIMATIONS(op)));
1032  if (!(flags&GT_ONLY_GOOD) && !(RANDOM()%3))
1035  if (op->type != RING) /* Amulets have only one ability */
1036  break;
1037  if (!(RANDOM()%4)) {
1038  int d = (RANDOM()%2 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2;
1039  if (d > 0)
1040  op->value *= 3;
1041  set_ring_bonus(op, d);
1042  if (!(RANDOM()%4)) {
1043  int d = (RANDOM()%3 || QUERY_FLAG(op, FLAG_CURSED)) ? -DICE2 : DICE2;
1044  if (d > 0)
1045  op->value *= 5;
1046  set_ring_bonus(op, d);
1047  }
1048  }
1049  break;
1050 
1051  case BOOK:
1052  /* Is it an empty book?, if yes lets make a special
1053  * msg for it, and tailor its properties based on the
1054  * creator and/or map level we found it on.
1055  */
1056  if (!op->msg && RANDOM()%10) {
1057  /* set the book level properly */
1058  if (creator->level == 0 || QUERY_FLAG(creator, FLAG_ALIVE)) {
1059  if (op->map && op->map->difficulty)
1060  op->level = RANDOM()%(op->map->difficulty)+RANDOM()%10+1;
1061  else
1062  op->level = RANDOM()%20+1;
1063  } else
1064  op->level = RANDOM()%creator->level;
1065 
1066  tailor_readable_ob(op, creator->stats.sp);
1067  /* books w/ info are worth more! */
1068  if (op->msg != NULL)
1069  op->value *= ((op->level > 10 ? op->level : (op->level+1)/2)*((strlen(op->msg)/250)+1));
1070  /* creator related stuff */
1071 
1072  if (creator->slaying && !op->slaying) /* for check_inv floors */
1073  op->slaying = add_string(creator->slaying);
1074 
1075  /* add exp so reading it gives xp (once)*/
1076  op->stats.exp = op->value > 10000 ? op->value/5 : op->value/10;
1077  }
1078  /* for library, chained books. Note that some monsters have
1079  * no_pick set - we don't want to set no pick in that case. */
1080  if (QUERY_FLAG(creator, FLAG_NO_PICK)
1081  && !QUERY_FLAG(creator, FLAG_MONSTER))
1083  break;
1084 
1085  case SPELLBOOK:
1086  op->value = op->value*op->inv->value;
1087  /* add exp so learning gives xp */
1088  op->level = op->inv->level;
1089  op->stats.exp = op->value;
1090  /* some more fun */
1091  if (!(flags&GT_ONLY_GOOD) && rndm(1, 100) <= 5) {
1092  if (rndm(1, 6) <= 1)
1094  else
1096  } else if (rndm(1, 100) <= 1) {
1098  }
1099  break;
1100 
1101  case WAND:
1102  /* nrof in the treasure list is number of charges,
1103  * not number of wands. So copy that into food (charges),
1104  * and reset nrof.
1105  */
1106  op->stats.food = op->inv->nrof;
1107  op->nrof = 1;
1108  /* If the spell changes by level, choose a random level
1109  * for it, and adjust price. If the spell doesn't
1110  * change by level, just set the wand to the level of
1111  * the spell, and value calculation is simpler.
1112  */
1113  if (op->inv->duration_modifier
1114  || op->inv->dam_modifier
1115  || op->inv->range_modifier) {
1116  op->level = level_for_item(op, difficulty);
1117  op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50);
1118  } else {
1119  op->level = op->inv->level;
1120  op->value = op->value*op->inv->value;
1121  }
1122  break;
1123 
1124  case ROD:
1125  op->level = level_for_item(op, difficulty);
1126  rod_adjust(op);
1127  break;
1128 
1129  case SCROLL:
1130  op->level = level_for_item(op, difficulty);
1131  op->value = op->value*op->inv->value*(op->level+50)/(op->inv->level+50);
1132  /* add exp so reading them properly gives xp */
1133  op->stats.exp = op->value/5;
1134  op->nrof = op->inv->nrof;
1135  /* some more fun */
1136  if (!(flags&GT_ONLY_GOOD) && rndm(1, 100) <= 20) {
1137  if (rndm(1, 6) <= 1)
1139  else
1141  } else if (rndm(1, 100) <= 2) {
1143  }
1144  break;
1145 
1146  case RUNE:
1147  trap_adjust(op, difficulty);
1148  break;
1149 
1150  case TRAP:
1151  trap_adjust(op, difficulty);
1152  break;
1153  } /* switch type */
1154  }
1155  if (flags&GT_STARTEQUIP) {
1156  if (op->nrof < 2
1157  && op->type != CONTAINER
1158  && op->type != MONEY
1161  else if (op->type != MONEY)
1162  op->value = 0;
1163  }
1164 
1165  if (!(flags&GT_ENVIRONMENT))
1166  fix_flesh_item(op, creator);
1167 }
1168 
1172 static void dump_monster_treasure_rec(const char *name, treasure *t, int depth) {
1173  treasurelist *tl;
1174  int i;
1175 
1176  if (depth > 100)
1177  return;
1178 
1179  while (t != NULL) {
1180  if (t->name != NULL) {
1181  for (i = 0; i < depth; i++)
1182  fprintf(logfile, " ");
1183  fprintf(logfile, "{ (list: %s)\n", t->name);
1184  tl = find_treasurelist(t->name);
1185  dump_monster_treasure_rec(name, tl->items, depth+2);
1186  for (i = 0; i < depth; i++)
1187  fprintf(logfile, " ");
1188  fprintf(logfile, "} (end of list: %s)\n", t->name);
1189  } else {
1190  for (i = 0; i < depth; i++)
1191  fprintf(logfile, " ");
1192  if (t->item->clone.type == FLESH)
1193  fprintf(logfile, "%s's %s\n", name, t->item->clone.name);
1194  else
1195  fprintf(logfile, "%s\n", t->item->clone.name);
1196  }
1197  if (t->next_yes != NULL) {
1198  for (i = 0; i < depth; i++)
1199  fprintf(logfile, " ");
1200  fprintf(logfile, " (if yes)\n");
1201  dump_monster_treasure_rec(name, t->next_yes, depth+1);
1202  }
1203  if (t->next_no != NULL) {
1204  for (i = 0; i < depth; i++)
1205  fprintf(logfile, " ");
1206  fprintf(logfile, " (if no)\n");
1207  dump_monster_treasure_rec(name, t->next_no, depth+1);
1208  }
1209  t = t->next;
1210  }
1211 }
1212 
1217 void dump_monster_treasure(const char *name) {
1218  archetype *at;
1219  int found;
1220 
1221  found = 0;
1222  fprintf(logfile, "\n");
1223  for (at = get_next_archetype(NULL); at != NULL; at = get_next_archetype(at))
1224  if (!strcasecmp(at->clone.name, name) && at->clone.title == NULL) {
1225  fprintf(logfile, "treasures for %s (arch: %s)\n", at->clone.name, at->name);
1226  if (at->clone.randomitems != NULL)
1228  else
1229  fprintf(logfile, "(nothing)\n");
1230  fprintf(logfile, "\n");
1231  found++;
1232  }
1233 
1234  if (found == 0)
1235  fprintf(logfile, "No objects have the name %s!\n\n", name);
1236 }
1237 
1245 static void fix_flesh_item(object *item, const object *donor) {
1246  char tmpbuf[MAX_BUF];
1247  int i;
1248 
1249  if (item->type == FLESH && donor && QUERY_FLAG(donor, FLAG_MONSTER)) {
1250  /* change the name */
1251  snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name);
1252  FREE_AND_COPY(item->name, tmpbuf);
1253  snprintf(tmpbuf, sizeof(tmpbuf), "%s's %s", donor->name, item->name_pl);
1254  FREE_AND_COPY(item->name_pl, tmpbuf);
1255 
1256  /* store original arch in other_arch */
1257  if (!item->other_arch) {
1258  if (!donor->arch->reference_count) {
1259  item->other_arch = donor->arch;
1260  } else {
1261  /* If dealing with custom monsters, other_arch still needs to
1262  * point back to the original. Otherwise what happens
1263  * is that other_arch points at the custom archetype, but
1264  * that can be freed. Reference count doesn't work because
1265  * the loader will not be able to resolve the other_arch at
1266  * load time (server may has restarted, etc.)
1267  */
1268  archetype *original = find_archetype(donor->arch->name);
1269 
1270  if (original)
1271  item->other_arch = original;
1272  else {
1273  LOG(llevError, "could not find original archetype %s for custom monster!\n", donor->arch->name);
1274  abort();
1275  }
1276  }
1277  }
1278 
1279  /* weight is FLESH weight/100 * donor */
1280  if ((item->weight = (signed long)(((double)item->weight/(double)100.0)*(double)donor->weight)) == 0)
1281  item->weight = 1;
1282 
1283  /* value is multiplied by level of donor */
1284  item->value *= isqrt(donor->level*2);
1285 
1286  /* food value */
1287  item->stats.food += (donor->stats.hp/100)+donor->stats.Con;
1288 
1289  /* flesh items inherit some abilities of donor, but not full effect. */
1290  for (i = 0; i < NROFATTACKS; i++)
1291  item->resist[i] = donor->resist[i]/2;
1292 
1293  /* item inherits donor's level and exp (important for dragons) */
1294  item->level = donor->level;
1295  item->stats.exp = donor->stats.exp;
1296 
1297  /* if donor has some attacktypes, the flesh is poisonous */
1298  if (donor->attacktype&AT_POISON)
1299  item->type = POISON;
1300  if (donor->attacktype&AT_ACID)
1301  item->stats.hp = -1*item->stats.food;
1303 
1304  /* attempt to change the face - will take a face named "donor's arch"_"item's face". We ignore the animation for now */
1305  if (item->face != NULL) {
1306  snprintf(tmpbuf, sizeof(tmpbuf), "%s_%s", donor->arch->name, item->face->name);
1307  item->face = try_find_face(tmpbuf, item->face);
1308  }
1309  }
1310 }
1311 
1320 static int special_potion(object *op) {
1321  int i;
1322 
1323  if (op->attacktype)
1324  return 1;
1325 
1326  if (op->stats.Str
1327  || op->stats.Dex
1328  || op->stats.Con
1329  || op->stats.Pow
1330  || op->stats.Wis
1331  || op->stats.Int
1332  || op->stats.Cha)
1333  return 1;
1334 
1335  for (i = 0; i < NROFATTACKS; i++)
1336  if (op->resist[i])
1337  return 1;
1338 
1339  return 0;
1340 }
1341 
1354  treasure *t = (treasure *)calloc(1, sizeof(treasure));
1355  if (t == NULL)
1357  t->item = NULL;
1358  t->name = NULL;
1359  t->next = NULL;
1360  t->next_yes = NULL;
1361  t->next_no = NULL;
1362  t->chance = 100;
1363  t->magic = 0;
1364  t->nrof = 0;
1365  return t;
1366 }
1367 
1375  if (t->next)
1376  treasure_free(t->next);
1377  if (t->next_yes)
1378  treasure_free(t->next_yes);
1379  if (t->next_no)
1380  treasure_free(t->next_no);
1381  free(t);
1382 }
1383 
1384 
1392  treasure *added = get_empty_treasure();
1393  if (list->items == NULL || position <= 0) {
1394  added->next = list->items;
1395  list->items = added;
1396  return added;
1397  }
1398  treasure *prev = list->items;
1399  position--;
1400  while (position > 0 && prev->next) {
1401  position--;
1402  prev = prev->next;
1403  }
1404  added->next = prev->next;
1405  prev->next = added;
1406  return added;
1407 }
1408 
1415  if (list->items == 0 || position < 0) {
1416  return;
1417  }
1418  if (position == 0) {
1419  treasure *next = list->items->next;
1420  list->items->next = NULL;
1421  treasure_free(list->items);
1422  list->items = next;
1423  return;
1424  }
1425  position--;
1426  treasure *prev = list->items;
1427  while (prev && position > 0) {
1428  position--;
1429  prev = prev->next;
1430  }
1431  if (!prev) {
1432  return;
1433  }
1434  treasure *next = prev->next->next;
1435  prev->next->next = NULL;
1436  treasure_free(prev->next);
1437  prev->next = next;
1438 }
give.next
def next
Definition: give.py:44
ATNR_PARALYZE
#define ATNR_PARALYZE
Definition: attack.h:61
global.h
fix_flesh_item
static void fix_flesh_item(object *item, const object *donor)
Definition: treasure.c:1245
liv::dam
int16_t dam
Definition: living.h:46
INS_NO_WALK_ON
#define INS_NO_WALK_ON
Definition: object.h:569
add_string
sstring add_string(const char *str)
Definition: shstr.c:124
object_remove
void object_remove(object *op)
Definition: object.c:1819
AT_POISON
#define AT_POISON
Definition: attack.h:86
BRACERS
@ BRACERS
Definition: object.h:217
llevError
@ llevError
Definition: logger.h:11
FABS
#define FABS(x)
Definition: define.h:22
WAND
@ WAND
Definition: object.h:220
SET_FLAG
#define SET_FLAG(xyz, p)
Definition: define.h:224
Settings::armor_speed_linear
uint8_t armor_speed_linear
Definition: global.h:306
FLESH
@ FLESH
Definition: object.h:187
ATNR_ACID
#define ATNR_ACID
Definition: attack.h:55
level_for_item
static int level_for_item(const object *op, int difficulty)
Definition: treasure.c:301
FLAG_STARTEQUIP
#define FLAG_STARTEQUIP
Definition: define.h:268
obj::map
struct mapdef * map
Definition: object.h:300
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
FLAG_REFL_MISSILE
#define FLAG_REFL_MISSILE
Definition: define.h:273
get_next_archetype
archetype * get_next_archetype(archetype *current)
Definition: assets.cpp:278
trap_adjust
static void trap_adjust(object *trap, int difficulty)
Definition: treasure.c:809
object_new
object * object_new(void)
Definition: object.c:1255
calc_item_power
int calc_item_power(const object *op)
Definition: item.c:239
FLAG_OBJ_ORIGINAL
#define FLAG_OBJ_ORIGINAL
Definition: define.h:357
TRAP
@ TRAP
Definition: object.h:241
ARMOUR
@ ARMOUR
Definition: object.h:120
set_materialname
void set_materialname(object *op)
Definition: utils.c:301
guildoracle.list
list
Definition: guildoracle.py:87
WEAPON
@ WEAPON
Definition: object.h:119
guildjoin.ob
ob
Definition: guildjoin.py:42
liv::hp
int16_t hp
Definition: living.h:40
GT_ONLY_GOOD
@ GT_ONLY_GOOD
Definition: treasure.h:34
SET_ANIMATION
#define SET_ANIMATION(ob, newanim)
Definition: global.h:161
ATNR_SLOW
#define ATNR_SLOW
Definition: attack.h:60
AMULET
@ AMULET
Definition: object.h:139
num_resist_table
#define num_resist_table
Definition: treasure.c:46
MAXMAGIC
#define MAXMAGIC
Definition: treasure.h:13
RUNE
@ RUNE
Definition: object.h:240
treasure_free
void treasure_free(treasure *t)
Definition: treasure.c:1374
MAX_SPELLITEM_LEVEL
#define MAX_SPELLITEM_LEVEL
Definition: treasure.h:19
ATNR_DISEASE
#define ATNR_DISEASE
Definition: attack.h:74
find_treasurelist
treasurelist * find_treasurelist(const char *name)
Definition: assets.cpp:261
Ice.tmp
int tmp
Definition: Ice.py:207
FLAG_BLESSED
#define FLAG_BLESSED
Definition: define.h:369
rod_adjust
void rod_adjust(object *rod)
Definition: main.c:391
ATNR_PHYSICAL
#define ATNR_PHYSICAL
Definition: attack.h:49
ARMOUR_SPEED
#define ARMOUR_SPEED(xyz)
Definition: define.h:466
flags
static const flag_definition flags[]
Definition: gridarta-types-convert.c:101
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
create_all_treasures
static void create_all_treasures(treasure *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:134
ATNR_TURN_UNDEAD
#define ATNR_TURN_UNDEAD
Definition: attack.h:62
create_treasure
void create_treasure(treasurelist *t, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:241
amulet_arch
EXTERN archetype * amulet_arch
Definition: global.h:154
GT_STARTEQUIP
@ GT_STARTEQUIP
Definition: treasure.h:33
obj::randomitems
struct treasureliststruct * randomitems
Definition: object.h:391
treasure_remove_item
void treasure_remove_item(treasurelist *list, int position)
Definition: treasure.c:1414
treasurestruct
Definition: treasure.h:63
isqrt
int isqrt(int n)
Definition: utils.c:569
AT_DEATH
#define AT_DEATH
Definition: attack.h:93
FLAG_NO_PICK
#define FLAG_NO_PICK
Definition: define.h:239
ATNR_CONFUSION
#define ATNR_CONFUSION
Definition: attack.h:54
ATNR_HOLYWORD
#define ATNR_HOLYWORD
Definition: attack.h:70
archt
Definition: object.h:470
settings
struct Settings settings
Definition: init.c:39
FLAG_ALIVE
#define FLAG_ALIVE
Definition: define.h:230
obj::slaying
sstring slaying
Definition: object.h:322
free_string
void free_string(sstring str)
Definition: shstr.c:280
ATNR_BLIND
#define ATNR_BLIND
Definition: attack.h:71
CLOAK
@ CLOAK
Definition: object.h:204
liv::exp
int64_t exp
Definition: living.h:47
HELMET
@ HELMET
Definition: object.h:136
POISON
@ POISON
Definition: object.h:113
obj::name
sstring name
Definition: object.h:314
POTION
@ POTION
Definition: object.h:111
GT_INVISIBLE
@ GT_INVISIBLE
Definition: treasure.h:32
resist_table
static int resist_table[]
Definition: treasure.c:37
special_potion
static int special_potion(object *op)
Definition: treasure.c:1320
liv::Cha
int8_t Cha
Definition: living.h:36
fatal
void fatal(enum fatal_error err)
Definition: utils.c:580
ROD
@ ROD
Definition: object.h:109
CONTAINER
@ CONTAINER
Definition: object.h:231
get_magic
static int get_magic(int diff)
Definition: treasure.c:788
difftomagic_list
static const int difftomagic_list[DIFFLEVELS][MAXMAGIC+1]
Definition: treasure.c:337
generate_artifact
void generate_artifact(object *op, int difficulty)
Definition: artifact.c:187
change_treasure
static void change_treasure(treasure *t, object *op)
Definition: treasure.c:98
Settings::armor_weight_reduction
int armor_weight_reduction
Definition: global.h:303
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:203
Ice.b
b
Definition: Ice.py:48
crown_arch
EXTERN archetype * crown_arch
Definition: global.h:154
obj::x
int16_t x
Definition: object.h:330
INS_NO_MERGE
#define INS_NO_MERGE
Definition: object.h:567
FLAG_DAMNED
#define FLAG_DAMNED
Definition: define.h:317
ATNR_DRAIN
#define ATNR_DRAIN
Definition: attack.h:56
obj::other_arch
struct archt * other_arch
Definition: object.h:419
rndm
int rndm(int min, int max)
Definition: utils.c:162
liv::Con
int8_t Con
Definition: living.h:36
ATNR_POISON
#define ATNR_POISON
Definition: attack.h:59
sproto.h
ATNR_DEATH
#define ATNR_DEATH
Definition: attack.h:66
FLAG_NO_STEAL
#define FLAG_NO_STEAL
Definition: define.h:342
set_magic
static void set_magic(int difficulty, object *op, int max_magic, int flags)
Definition: treasure.c:638
GET_ANIM_ID
#define GET_ANIM_ID(ob)
Definition: global.h:164
BOOK
@ BOOK
Definition: object.h:114
GT_ENVIRONMENT
@ GT_ENVIRONMENT
Definition: treasure.h:31
logfile
EXTERN FILE * logfile
Definition: global.h:136
RING
@ RING
Definition: object.h:185
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
treasure.h
MAX_BUF
#define MAX_BUF
Definition: define.h:35
fix_generated_item
void fix_generated_item(object *op, object *creator, int difficulty, int max_magic, int flags)
Definition: treasure.c:876
create_archetype
object * create_archetype(const char *name)
Definition: arch.cpp:281
RANDOM
#define RANDOM()
Definition: define.h:644
ATNR_FIRE
#define ATNR_FIRE
Definition: attack.h:51
is_valid_types_gen.found
found
Definition: is_valid_types_gen.py:39
obj::y
int16_t y
Definition: object.h:330
put_treasure
static void put_treasure(object *op, object *creator, int flags)
Definition: treasure.c:75
treasureliststruct::total_chance
int16_t total_chance
Definition: treasure.h:84
obj::title
sstring title
Definition: object.h:320
obj::arch
struct archt * arch
Definition: object.h:418
treasureliststruct::items
struct treasurestruct * items
Definition: treasure.h:89
tailor_readable_ob
void tailor_readable_ob(object *book, int msg_type)
Definition: readable.c:1928
treasure_insert
treasure * treasure_insert(treasurelist *list, int position)
Definition: treasure.c:1391
FLAG_REFL_SPELL
#define FLAG_REFL_SPELL
Definition: define.h:275
obj::type
uint8_t type
Definition: object.h:343
Floor.t
t
Definition: Floor.py:62
obj::stats
living stats
Definition: object.h:373
archt::clone
object clone
Definition: object.h:474
get_empty_treasure
treasure * get_empty_treasure(void)
Definition: treasure.c:1353
obj::weight
int32_t weight
Definition: object.h:370
ATNR_DEPLETE
#define ATNR_DEPLETE
Definition: attack.h:65
item
Definition: item.py:1
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
archt::reference_count
int reference_count
Definition: object.h:477
give.op
op
Definition: give.py:33
autojail.value
value
Definition: autojail.py:6
get_power_from_ench
int get_power_from_ench(int ench)
Definition: item.c:211
find_archetype
archetype * find_archetype(const char *name)
Definition: assets.cpp:282
dump_monster_treasure
void dump_monster_treasure(const char *name)
Definition: treasure.c:1217
ATNR_MAGIC
#define ATNR_MAGIC
Definition: attack.h:50
magic_from_difficulty
static int magic_from_difficulty(int difficulty)
Definition: treasure.c:550
set_attr_value
void set_attr_value(living *stats, int attr, int8_t value)
Definition: living.c:219
CHANCE_FOR_ARTIFACT
#define CHANCE_FOR_ARTIFACT
Definition: treasure.h:10
NUM_ANIMATIONS
#define NUM_ANIMATIONS(ob)
Definition: global.h:170
object_insert_in_ob
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2833
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:232
DIFFLEVELS
#define DIFFLEVELS
Definition: treasure.h:16
Settings::armor_weight_linear
uint8_t armor_weight_linear
Definition: global.h:304
strcasecmp
int strcasecmp(const char *s1, const char *s2)
make_face_from_files.int
int
Definition: make_face_from_files.py:26
DICE2
#define DICE2
Definition: treasure.c:847
AT_ACID
#define AT_ACID
Definition: attack.h:82
loader.h
treasurestruct::next
struct treasurestruct * next
Definition: treasure.h:66
object_insert_in_map_at
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:2080
get_attr_value
int8_t get_attr_value(const living *stats, int attr)
Definition: living.c:314
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.c:1546
try_find_face
const Face * try_find_face(const char *name, const Face *error)
Definition: assets.cpp:310
level
int level
Definition: readable.c:1608
generate_treasure
object * generate_treasure(treasurelist *t, int difficulty)
Definition: treasure.c:273
archt::name
sstring name
Definition: object.h:471
ATNR_GHOSTHIT
#define ATNR_GHOSTHIT
Definition: attack.h:58
set_abs_magic
void set_abs_magic(object *op, int magic)
Definition: treasure.c:590
ATNR_COLD
#define ATNR_COLD
Definition: attack.h:53
SCROLL
@ SCROLL
Definition: object.h:221
create_one_treasure
static void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, int tries)
Definition: treasure.c:178
obj::attacktype
uint32_t attacktype
Definition: object.h:347
ATNR_ELECTRICITY
#define ATNR_ELECTRICITY
Definition: attack.h:52
SPELL
@ SPELL
Definition: object.h:214
ring_arch
EXTERN archetype * ring_arch
Definition: global.h:154
liv::sp
int16_t sp
Definition: living.h:42
SHIELD
@ SHIELD
Definition: object.h:135
init_archetype_pointers
void init_archetype_pointers(void)
Definition: treasure.c:55
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition: define.h:48
FLAG_CURSED
#define FLAG_CURSED
Definition: define.h:316
spell_mapping
const char *const spell_mapping[SPELL_MAPPINGS]
Definition: object.c:74
ATNR_LIFE_STEALING
#define ATNR_LIFE_STEALING
Definition: attack.h:73
obj::resist
int16_t resist[NROFATTACKS]
Definition: object.h:346
FLAG_IS_THROWN
#define FLAG_IS_THROWN
Definition: define.h:249
if
if(!(yy_init))
Definition: loader.c:2626
set_ring_bonus
static void set_ring_bonus(object *op, int bonus)
Definition: treasure.c:667
Settings::armor_speed_improvement
int armor_speed_improvement
Definition: global.h:305
SPELLBOOK
@ SPELLBOOK
Definition: object.h:203
GT_MINIMAL
@ GT_MINIMAL
Definition: treasure.h:36
ring_occidental_mages.r
r
Definition: ring_occidental_mages.py:6
dump_monster_treasure_rec
static void dump_monster_treasure_rec(const char *name, treasure *t, int depth)
Definition: treasure.c:1172
obj::level
int16_t level
Definition: object.h:356
llevDebug
@ llevDebug
Definition: logger.h:13
MONEY
@ MONEY
Definition: object.h:137
treasureliststruct
Definition: treasure.h:82
obj::inv
struct obj * inv
Definition: object.h:293
give.name
name
Definition: give.py:27
ATNR_FEAR
#define ATNR_FEAR
Definition: attack.h:63
level
Definition: level.py:1