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