Crossfire Server, Trunk  R20513
artifact.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 <stdlib.h>
23 #include <string.h>
24 #include <ctype.h>
25 
26 #include "loader.h"
27 
40  artifactlist *tl = (artifactlist *)malloc(sizeof(artifactlist));
41  if (tl == NULL)
43  tl->next = NULL;
44  tl->items = NULL;
45  tl->total_chance = 0;
46  return tl;
47 }
48 
59  artifact *t = (artifact *)malloc(sizeof(artifact));
60  if (t == NULL)
62  t->item = NULL;
63  t->next = NULL;
64  t->chance = 0;
65  t->difficulty = 0;
66  t->allowed = NULL;
67  t->allowed_size = 0;
68  return t;
69 }
70 
77 static void free_charlinks(linked_char *lc) {
78  if (lc->next)
79  free_charlinks(lc->next);
80  free(lc);
81 }
82 
95 static void free_artifact(artifact *at) {
96  object *next;
97 
98  if (at->next)
99  free_artifact(at->next);
100  if (at->allowed)
101  free_charlinks(at->allowed);
102  while (at->item) {
103  next = at->item->next;
104  if (at->item->name)
105  free_string(at->item->name);
106  if (at->item->name_pl)
107  free_string(at->item->name_pl);
108  if (at->item->msg)
109  free_string(at->item->msg);
110  if (at->item->title)
111  free_string(at->item->title);
113  free(at->item);
114  at->item = next;
115  }
116  free(at);
117 }
118 
125 static void free_artifactlist(artifactlist *al) {
126  artifactlist *nextal;
127 
128  for (; al != NULL; al = nextal) {
129  nextal = al->next;
130  if (al->items) {
131  free_artifact(al->items);
132  }
133  free(al);
134  }
135 }
136 
140 void free_all_artifacts(void) {
142  first_artifactlist = NULL;
143 }
144 
146 #define ARTIFACT_TRIES 2
147 
155 void generate_artifact(object *op, int difficulty) {
156  const artifactlist *al;
157  const artifact *art;
158  int i;
159 
160  al = find_artifactlist(op->type);
161 
162  if (al == NULL) {
163  return;
164  }
165 
166  for (i = 0; i < ARTIFACT_TRIES; i++) {
167  int roll = RANDOM()%al->total_chance;
168 
169  for (art = al->items; art != NULL; art = art->next) {
170  roll -= art->chance;
171  if (roll < 0)
172  break;
173  }
174 
175  if (art == NULL || roll >= 0) {
176  LOG(llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", op->type);
177  return;
178  }
179  if (!strcmp(art->item->name, "NONE"))
180  return;
181  if (FABS(op->magic) < art->item->magic)
182  continue; /* Not magic enough to be this item */
183 
184  /* Map difficulty not high enough */
185  if (difficulty < art->difficulty)
186  continue;
187 
188  if (!legal_artifact_combination(op, art)) {
189 #ifdef TREASURE_VERBOSE
190  LOG(llevDebug, "%s of %s was not a legal combination.\n", op->name, art->item->name);
191 #endif
192  continue;
193  }
194  give_artifact_abilities(op, art->item);
195  return;
196  }
197 }
198 
203 void give_artifact_abilities(object *op, const object *artifact) {
204  char new_name[MAX_BUF];
205 
206  snprintf(new_name, sizeof(new_name), "of %s", artifact->name);
207  if (op->title)
208  free_string(op->title);
209  op->title = add_string(new_name);
210  if (op->artifact)
211  free_string(op->artifact);
212  op->artifact = add_refcount(artifact->name);
213  add_abilities(op, artifact); /* Give out the bonuses */
214 
215  return;
216 }
217 
221 int legal_artifact_combination(const object *op, const artifact *art) {
222  int neg, success = 0;
223  linked_char *tmp;
224  const char *name;
225 
226  if (art->allowed == (linked_char *)NULL)
227  return 1; /* Ie, "all" */
228  for (tmp = art->allowed; tmp; tmp = tmp->next) {
229 #ifdef TREASURE_VERBOSE
230  LOG(llevDebug, "legal_art: %s\n", tmp->name);
231 #endif
232  if (*tmp->name == '!') {
233  name = tmp->name+1;
234  neg = 1;
235  } else {
236  name = tmp->name;
237  neg = 0;
238  }
239 
240  /* If we match name, then return the opposite of 'neg' */
241  if (!strcmp(name, op->name) || (op->arch && !strcmp(name, op->arch->name)))
242  return !neg;
243 
244  /* Set success as true, since if the match was an inverse, it means
245  * everything is allowed except what we match
246  */
247  else if (neg)
248  success = 1;
249  }
250  return success;
251 }
252 
260 static void compute_face_name(char* buf, size_t size, const char* name, const char* suffix)
261 {
262  const char* dot = name + strlen(name) - 1;
263  while (dot > name && (isdigit(*dot) || (*dot == 'x')))
264  {
265  dot--;
266  }
267 
268  if (*dot == '.')
269  {
270  buf[0] = '0';
271  snprintf(buf, dot - name + 1, "%s", name);
272  snprintf(buf + strlen(buf), size - strlen(buf), "_%s%s", suffix, dot);
273  }
274  else
275  {
276  snprintf(buf, size, "%s_%s", name, suffix);
277  }
278 }
279 
284 void add_abilities(object *op, const object *change) {
285  int i, tmp;
286  char buf[MAX_BUF];
287  sstring key;
288 
289  if (change->face != blank_face) {
290 #ifdef TREASURE_VERBOSE
291  LOG(llevDebug, "FACE: %d\n", change->face->number);
292 #endif
293 
294  object_set_value(op, "identified_face", change->face->name, 1);
295  } else if ((key = object_get_value(change, "face_suffix")) != NULL) {
296  New_Face* face;
297  compute_face_name(buf, sizeof(buf), op->face->name, key);
298  face = &new_faces[find_face(buf, op->face->number)];
299  object_set_value(op, "identified_face", face->name, 1);
300  }
301  if (QUERY_FLAG(change, FLAG_CLIENT_ANIM_RANDOM)) {
302  object_set_value(op, "identified_anim_random", "1", 1);
303  }
304  if (change->anim_speed > 0) {
305  snprintf(buf, sizeof(buf), "%d", change->anim_speed);
306  object_set_value(op, "identified_anim_speed", buf, 1);
307  }
308  if (change->animation_id != 0 && op->arch != NULL) {
309  /* op->arch can be NULL when called from artifact_msg(). */
310  snprintf(buf, sizeof(buf),"%d", change->animation_id);
311  object_set_value(op, "identified_animation", buf, 1);
312  } else if (op->animation_id != 0 && (key = object_get_value(change, "animation_suffix")) != NULL) {
313  snprintf(buf, sizeof(buf), "%s_%s", animations[op->animation_id].name, key);
314  i = try_find_animation(buf);
315  if (i != 0) {
316  snprintf(buf, sizeof(buf),"%d", i);
317  object_set_value(op, "identified_animation", buf, 1);
318  }
319  }
320 
321  for (i = 0; i < NUM_STATS; i++)
322  change_attr_value(&(op->stats), i, get_attr_value(&(change->stats), i));
323 
324  op->attacktype |= change->attacktype;
325  op->path_attuned |= change->path_attuned;
326  op->path_repelled |= change->path_repelled;
327  op->path_denied |= change->path_denied;
328  op->move_type |= change->move_type;
329  op->stats.luck += change->stats.luck;
330 
331  if (QUERY_FLAG(change, FLAG_CURSED))
332  SET_FLAG(op, FLAG_CURSED);
333  if (QUERY_FLAG(change, FLAG_DAMNED))
334  SET_FLAG(op, FLAG_DAMNED);
335  if ((QUERY_FLAG(change, FLAG_CURSED) || QUERY_FLAG(change, FLAG_DAMNED))
336  && op->magic > 0)
337  set_abs_magic(op, -op->magic);
338 
339  if (QUERY_FLAG(change, FLAG_LIFESAVE))
340  SET_FLAG(op, FLAG_LIFESAVE);
341  if (QUERY_FLAG(change, FLAG_REFL_SPELL))
343  if (QUERY_FLAG(change, FLAG_STEALTH))
344  SET_FLAG(op, FLAG_STEALTH);
345  if (QUERY_FLAG(change, FLAG_XRAYS))
346  SET_FLAG(op, FLAG_XRAYS);
347  if (QUERY_FLAG(change, FLAG_BLIND))
348  SET_FLAG(op, FLAG_BLIND);
349  if (QUERY_FLAG(change, FLAG_SEE_IN_DARK))
351  if (QUERY_FLAG(change, FLAG_REFL_MISSILE))
353  if (QUERY_FLAG(change, FLAG_MAKE_INVIS))
355 
356  if (QUERY_FLAG(change, FLAG_STAND_STILL)) {
358  /* so artifacts will join */
359  if (!QUERY_FLAG(op, FLAG_ALIVE))
360  op->speed = 0.0;
362  }
363  if (change->nrof)
364  op->nrof = RANDOM()%((int)change->nrof)+1;
365  op->stats.exp += change->stats.exp; /* Speed modifier */
366  op->stats.wc += change->stats.wc;
367  op->stats.ac += change->stats.ac;
368 
369  if (change->other_arch) {
370  /* Basically, for horns & potions, the other_arch field is the spell
371  * to cast. So convert that to into a spell and put it into
372  * this object.
373  */
374  if (op->type == ROD || op->type == POTION) {
375  object *tmp_obj;
376 
377  /* Remove any spells this object currently has in it */
378  while (op->inv) {
379  tmp_obj = op->inv;
380  object_remove(tmp_obj);
382  }
383  tmp_obj = arch_to_object(change->other_arch);
384  /* This is an artifact, so this function will be called at load time,
385  * thus we don't need to keep the inventory */
386  SET_FLAG(tmp_obj, FLAG_NO_SAVE);
387  object_insert_in_ob(tmp_obj, op);
388  }
389  /* No harm setting this for potions/horns */
390  op->other_arch = change->other_arch;
391  }
392 
393  if (change->stats.hp < 0)
394  op->stats.hp = -change->stats.hp;
395  else
396  op->stats.hp += change->stats.hp;
397  if (change->stats.maxhp < 0)
398  op->stats.maxhp = -change->stats.maxhp;
399  else
400  op->stats.maxhp += change->stats.maxhp;
401  if (change->stats.sp < 0)
402  op->stats.sp = -change->stats.sp;
403  else
404  op->stats.sp += change->stats.sp;
405  if (change->stats.maxsp < 0)
406  op->stats.maxsp = -change->stats.maxsp;
407  else
408  op->stats.maxsp += change->stats.maxsp;
409  if (change->stats.food < 0)
410  op->stats.food = -(change->stats.food);
411  else
412  op->stats.food += change->stats.food;
413  if (change->level < 0)
414  op->level = -(change->level);
415  else
416  op->level += change->level;
417 
418  op->item_power = change->item_power;
419 
420  for (i = 0; i < NROFATTACKS; i++) {
421  if (change->resist[i]) {
422  op->resist[i] += change->resist[i];
423  }
424  }
425  if (change->stats.dam) {
426  if (change->stats.dam < 0)
427  op->stats.dam = (-change->stats.dam);
428  else if (op->stats.dam) {
429  tmp = (int)(((int)op->stats.dam*(int)change->stats.dam)/10);
430  if (tmp == op->stats.dam) {
431  if (change->stats.dam < 10)
432  op->stats.dam--;
433  else
434  op->stats.dam++;
435  } else
436  op->stats.dam = tmp;
437  }
438  }
439  if (change->weight) {
440  if (change->weight < 0)
441  op->weight = (-change->weight);
442  else
443  op->weight = (op->weight*(change->weight))/100;
444  }
445  if (change->last_sp) {
446  if (change->last_sp < 0)
447  op->last_sp = (-change->last_sp);
448  else
449  op->last_sp = (signed char)(((int)op->last_sp*(int)change->last_sp)/(int)100);
450  }
451  if (change->gen_sp_armour) {
452  if (change->gen_sp_armour < 0)
453  op->gen_sp_armour = (-change->gen_sp_armour);
454  else
455  op->gen_sp_armour = (signed char)(((int)op->gen_sp_armour*((int)change->gen_sp_armour))/(int)100);
456  }
457  op->value *= change->value;
458 
459  if (change->material)
460  op->material = change->material;
461 
462  if (change->materialname) {
463  if (op->materialname)
465  op->materialname = add_refcount(change->materialname);
466  }
467 
468  if (change->slaying) {
469  if (op->slaying)
470  free_string(op->slaying);
471  op->slaying = add_refcount(change->slaying);
472  }
473  if (change->race) {
474  if (op->race)
475  free_string(op->race);
476  op->race = add_refcount(change->race);
477  }
478  if (change->msg)
479  object_set_msg(op, change->msg);
480 
481  if (change->inv) {
482  object *copy;
483 
484  FOR_INV_PREPARE(change, inv) {
485  copy = object_new();
486  object_copy(inv, copy);
487  object_insert_in_ob(copy, op);
488  } FOR_INV_FINISH();
489  }
490 }
491 
501  artifactlist *al;
502 
503  for (al = first_artifactlist; al != NULL; al = al->next)
504  if (al->type == type)
505  return al;
506  return NULL;
507 }
508 
513 void init_artifacts(void) {
514  static int has_been_inited = 0;
515  FILE *fp;
516  char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next;
517  artifact *art = NULL;
518  linked_char *tmp;
519  int value;
520  artifactlist *al;
521  archetype dummy_archetype;
522 
523  memset(&dummy_archetype, 0, sizeof(archetype));
524 
525  if (has_been_inited)
526  return;
527  else
528  has_been_inited = 1;
529 
530  artifact_init = 1;
531 
532  snprintf(filename, sizeof(filename), "%s/artifacts", settings.datadir);
533  LOG(llevDebug, "Reading artifacts from %s...\n", filename);
534  if ((fp = fopen(filename, "r")) == NULL) {
535  LOG(llevError, "Can't open %s.\n", filename);
536  return;
537  }
538 
539  while (fgets(buf, HUGE_BUF, fp) != NULL) {
540  if (*buf == '#')
541  continue;
542  if ((cp = strchr(buf, '\n')) != NULL)
543  *cp = '\0';
544  cp = buf;
545  while (*cp == ' ') /* Skip blanks */
546  cp++;
547  if (*cp == '\0')
548  continue;
549 
550  if (!strncmp(cp, "Allowed", 7)) {
551  if (art == NULL) {
552  art = get_empty_artifact();
553  nrofartifacts++;
554  }
555 
556  cp = strchr(cp, ' ')+1;
557  while (*(cp+strlen(cp)-1) == ' ')
558  cp[strlen(cp)-1] = '\0';
559 
560  if (!strcmp(cp, "all"))
561  continue;
562 
563  do {
564  while (*cp == ' ')
565  cp++;
566  nrofallowedstr++;
567  if ((next = strchr(cp, ',')) != NULL)
568  *(next++) = '\0';
569  tmp = (linked_char *)malloc(sizeof(linked_char));
570  tmp->name = add_string(cp);
571  tmp->next = art->allowed;
572  art->allowed = tmp;
573  art->allowed_size++;
574  } while ((cp = next) != NULL);
575  } else if (sscanf(cp, "chance %d", &value))
576  art->chance = (uint16_t)value;
577  else if (sscanf(cp, "difficulty %d", &value))
578  art->difficulty = (uint8_t)value;
579  else if (!strncmp(cp, "Object", 6)) {
580  art->item = (object *)calloc(1, sizeof(object));
581  if (art->item == NULL) {
582  LOG(llevError, "init_artifacts: memory allocation failure.\n");
583  abort();
584  }
585  object_reset(art->item);
586  art->item->arch = &dummy_archetype;
587  if (!load_object(fp, art->item, LO_LINEMODE, MAP_STYLE))
588  LOG(llevError, "Init_Artifacts: Could not load object.\n");
589  art->item->arch = NULL;
590  art->item->name = add_string((strchr(cp, ' ')+1));
592  if (al == NULL) {
593  al = get_empty_artifactlist();
594  al->type = art->item->type;
595  al->next = first_artifactlist;
596  first_artifactlist = al;
597  }
598  art->next = al->items;
599  al->items = art;
600  art = NULL;
601  } else
602  LOG(llevError, "Unknown input in artifact file: %s\n", buf);
603  }
604 
605  fclose(fp);
606 
607  for (al = first_artifactlist; al != NULL; al = al->next) {
608  for (art = al->items; art != NULL; art = art->next) {
609  if (!art->chance)
610  LOG(llevError, "Warning: artifact with no chance: %s\n", art->item->name);
611  else
612  al->total_chance += art->chance;
613  }
614 #if 0
615  LOG(llevDebug, "Artifact list type %d has %d total chance\n", al->type, al->total_chance);
616 #endif
617  }
618 
619  LOG(llevDebug, "done artifacts.\n");
620  artifact_init = 0;
621 }
622 
630 const artifactlist *find_artifactlist(int type) {
631  return find_artifactlist_internal(type);
632 }
633 
640 const artifact *find_artifact(const object *op, const char *name) {
641  artifactlist *list;
642  artifact *at;
643  sstring sname = find_string(name);
644 
645  if (sname == NULL)
646  return NULL;
647 
648  list = find_artifactlist_internal(op->type);
649  if (list == NULL)
650  return NULL;
651 
652  for (at = list->items; at != NULL; at = at->next) {
653  if (at->item->name == sname && legal_artifact_combination(op, at))
654  return at;
655  }
656 
657  return NULL;
658 }
659 
666 void dump_artifacts(void) {
667  artifactlist *al;
668  artifact *art;
669  linked_char *next;
670 
671  fprintf(logfile, "\n");
672  for (al = first_artifactlist; al != NULL; al = al->next) {
673  fprintf(logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance);
674  for (art = al->items; art != NULL; art = art->next) {
675  fprintf(logfile, "Artifact %-30s Difficulty %3d Chance %5d\n", art->item->name, art->difficulty, art->chance);
676  if (art->allowed != NULL) {
677  fprintf(logfile, "\tAllowed combinations:");
678  for (next = art->allowed; next != NULL; next = next->next)
679  fprintf(logfile, "%s,", next->name);
680  fprintf(logfile, "\n");
681  }
682  }
683  }
684  fprintf(logfile, "\n");
685 }
686 
692 unsigned artifact_get_face(const artifact *art) {
693  const archetype *arch = first_archetype;
694 
695  if (art->item->face != blank_face && art->item->face != NULL)
696  return art->item->face->number;
697 
698  if (art->allowed_size > 0) {
699  if (art->allowed->name[0] == '!') {
700  linked_char *allowed;
701  while (arch) {
702  if (arch->clone.type != art->item->type)
703  arch = arch->next;
704 
705  for (allowed = art->allowed; allowed != NULL; allowed = allowed->next) {
706  if (strcmp(arch->name, allowed->name + 1) == 0) {
707  break;
708  }
709  }
710  if (allowed != NULL)
711  continue;
712 
713  if (arch->clone.face == NULL)
714  continue;
715  return arch->clone.face->number;
716  }
717  return (unsigned)-1;
718  } else {
719  const archetype *arch = find_archetype(art->allowed->name);
720  if (arch != NULL)
721  return arch->clone.face->number;
722  return (unsigned)-1;
723  }
724  }
725 
726  while (arch != NULL) {
727  if (arch->clone.type == art->item->type && arch->clone.face != NULL)
728  return arch->clone.face->number;
729 
730  arch = arch->next;
731  }
732  return (unsigned)-1;
733 }
EXTERN FILE * logfile
Used by server/daemon.c.
Definition: global.h:144
Error, serious thing.
Definition: logger.h:11
static artifactlist * find_artifactlist_internal(int type)
Searches the artifact lists and returns one that has the same type of objects on it, non-const version of find_artifactlist() used only during artifact loading.
Definition: artifact.c:500
#define FLAG_SEE_IN_DARK
if set ob not effected by darkness
Definition: define.h:338
archetype * find_archetype(const char *name)
Finds, using the hashtable, which archetype matches the given name.
Definition: arch.c:695
#define FLAG_DAMNED
The object is very cursed.
Definition: define.h:318
uint8_t type
Object type that this list represents.
Definition: artifact.h:27
int8_t ac
Armour Class, how hard to hit, the lower the better.
Definition: living.h:37
#define MAP_STYLE
Active objects shouldn&#39;t be put on active list.
Definition: map.h:98
MoveType move_type
Type of movement this object uses.
Definition: object.h:424
#define LO_LINEMODE
Definition: loader.h:16
const char * race
Human, goblin, dragon, etc.
Definition: object.h:318
#define SET_FLAG(xyz, p)
Definition: define.h:223
sstring add_refcount(sstring str)
This will increase the refcount of the string str.
Definition: shstr.c:210
const artifactlist * find_artifactlist(int type)
Searches the artifact lists and returns one that has the same type of objects on it.
Definition: artifact.c:630
#define FABS(x)
Decstations have trouble with fabs()...
Definition: define.h:22
unsigned artifact_get_face(const artifact *art)
Get a suitable face number for representing an artifact.
Definition: artifact.c:692
unsigned char uint8_t
Definition: win32.h:161
New_Face * new_faces
Contains face information, with names, numbers, magicmap color and such.
Definition: image.c:33
uint16_t animation_id
An index into the animation array.
Definition: object.h:416
uint16_t material
What materials this object consist of.
Definition: object.h:347
const char * name
Name of the animation sequence.
Definition: face.h:27
uint8_t anim_speed
Ticks between animation-frames.
Definition: object.h:417
sstring artifact
If set, the item is the artifact with this name and the matching type.
Definition: object.h:314
#define FLAG_STAND_STILL
NPC will not (ever) move.
Definition: define.h:309
void fatal(enum fatal_error err)
fatal() is meant to be called whenever a fatal signal is intercepted.
Definition: utils.c:596
struct artifactstruct * items
Artifacts for this type.
Definition: artifact.h:30
void free_string(sstring str)
This will reduce the refcount, and if it has reached 0, str will be freed.
Definition: shstr.c:280
#define HUGE_BUF
Used for messages - some can be quite long.
Definition: define.h:37
const char * object_get_value(const object *op, const char *const key)
Get an extra value by key.
Definition: object.c:4246
object clone
An object from which to do object_copy()
Definition: object.h:470
const char * slaying
Which race to do double damage to.
Definition: object.h:319
int32_t last_sp
As last_heal, but for spell points.
Definition: object.h:358
#define FLAG_STEALTH
Will wake monsters with less range.
Definition: define.h:313
See Rod.
Definition: object.h:109
int64_t exp
Experience.
Definition: living.h:46
int8_t get_attr_value(const living *stats, int attr)
Gets the value of a stat.
Definition: living.c:313
uint32_t path_attuned
Paths the object is attuned to.
Definition: object.h:343
int16_t sp
Spell points.
Definition: living.h:41
static void free_artifactlist(artifactlist *al)
Free specified list and its items.
Definition: artifact.c:125
Global type definitions and header inclusions.
uint32_t path_repelled
Paths the object is repelled from.
Definition: object.h:344
struct archt * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:413
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
int16_t maxsp
Max spell points.
Definition: living.h:42
int16_t hp
Hit Points.
Definition: living.h:39
uint16_t number
This is the image id.
Definition: face.h:15
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
Definition: object.c:4375
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
Definition: object.c:1368
const char * name
Face name, as used by archetypes and such.
Definition: face.h:20
const char * title
Of foo, etc.
Definition: object.h:317
static artifactlist * get_empty_artifactlist(void)
Allocate and return the pointer to an empty artifactlist structure.
Definition: artifact.c:39
int16_t maxhp
Max hit points.
Definition: living.h:40
sstring find_string(const char *str)
Searches a string in the shared strings.
Definition: shstr.c:236
#define FLAG_CLIENT_ANIM_RANDOM
Client animate this, randomized.
Definition: define.h:241
uint32_t path_denied
Paths the object is denied access to.
Definition: object.h:345
uint16_t total_chance
Sum of chance for are artifacts on this list.
Definition: artifact.h:28
#define FLAG_ALIVE
Object can fight (or be fought)
Definition: define.h:230
#define FLAG_REFL_SPELL
Spells (some) will reflect from object.
Definition: define.h:275
int legal_artifact_combination(const object *op, const artifact *art)
Checks if op can be combined with art.
Definition: artifact.c:221
struct artifactliststruct * next
Next list of artifacts.
Definition: artifact.h:29
object * object_new(void)
Grabs an object from the list of unused objects, makes sure it is initialised, and returns it...
Definition: object.c:1037
const char * name_pl
The plural name of the object.
Definition: object.h:315
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
Definition: object.c:2690
Defines for loader.l / loader.c.
const char * materialname
Specific material name.
Definition: object.h:346
int32_t weight
Attributes of the object.
Definition: object.h:365
#define snprintf
Definition: win32.h:46
void dump_artifacts(void)
For debugging purposes.
Definition: artifact.c:666
#define FLAG_NO_SAVE
If set (through plugins), the object is not saved on maps.
Definition: define.h:244
uint8_t difficulty
Minimum map difficulty for the artifact to happen.
Definition: artifact.h:17
const artifact * find_artifact(const object *op, const char *name)
Searches and returns a specific artifact, NULL if not found.
Definition: artifact.c:640
struct linked_char * next
Definition: global.h:88
#define FOR_INV_FINISH()
Finishes FOR_INV_PREPARE().
Definition: define.h:712
int16_t dam
How much damage this object does when hitting.
Definition: living.h:45
void change_attr_value(living *stats, int attr, int8_t value)
Like set_attr_value(), but instead the value (which can be negative) is added to the specified stat...
Definition: living.c:264
const char * name
The name of the object, obviously...
Definition: object.h:311
linked_char * allowed
List of archetypes the artifact can affect.
Definition: artifact.h:19
int8_t gen_sp_armour
Sp regen penalty this object has (was last_heal)
Definition: object.h:363
void object_reset(object *op)
Sets to 0 vital variables in an object.
Definition: object.c:704
uint32_t nrof
How many of the objects.
Definition: object.h:333
Number of statistics.
Definition: living.h:18
EXTERN Animations * animations
Definition: global.h:165
See Potion.
Definition: object.h:111
int8_t item_power
Power rating of the object.
Definition: object.h:362
int try_find_animation(const char *name)
Tries to find the animation id that matches name, don&#39;t LOG() an error if not found.
Definition: anim.c:159
#define FLAG_XRAYS
X-ray vision.
Definition: define.h:301
This represents all archetypes for one particular object type.
Definition: artifact.h:26
int8_t luck
Affects thaco and ac from time to time.
Definition: living.h:38
float speed
The overall speed of this object.
Definition: object.h:328
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:121
#define ARTIFACT_TRIES
Give 1 re-roll attempt per artifact.
Definition: artifact.c:146
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
void generate_artifact(object *op, int difficulty)
Decides randomly which artifact the object should be turned into.
Definition: artifact.c:155
This is one artifact, ie one special item.
Definition: artifact.h:14
void give_artifact_abilities(object *op, const object *artifact)
Fixes the given object, giving it the abilities and titles it should have due to the second artifact-...
Definition: artifact.c:203
int8_t wc
Weapon Class, how skilled, the lower the better.
Definition: living.h:36
unsigned short uint16_t
Definition: win32.h:163
void free_all_artifacts(void)
Free all artifact-related information.
Definition: artifact.c:140
struct obj * next
Pointer to the next object in the free/used list.
Definition: object.h:277
int16_t resist[NROFATTACKS]
Resistance adjustments for attacks.
Definition: object.h:341
EXTERN long nrofartifacts
Only used in malloc_info().
Definition: global.h:148
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
#define FLAG_CURSED
The object is cursed.
Definition: define.h:317
const char * datadir
Read only data files.
Definition: global.h:244
EXTERN long nrofallowedstr
Only used in malloc_info().
Definition: global.h:149
#define FLAG_ANIMATE
The object looks at archetype for faces.
Definition: define.h:242
static void free_artifact(artifact *at)
Totally frees an artifact, its next items, and such.
Definition: artifact.c:95
const char * name
Definition: global.h:87
static void free_charlinks(linked_char *lc)
Frees a link structure and its next items.
Definition: artifact.c:77
uint32_t attacktype
Bitmask of attacks this object does.
Definition: object.h:342
#define FLAG_BLIND
If set, object cannot see (visually)
Definition: define.h:337
#define RANDOM()
Definition: define.h:679
New_Face * blank_face
Following can just as easily be pointers, but it is easier to keep them like this.
Definition: image.c:39
living stats
Str, Con, Dex, etc.
Definition: object.h:368
int load_object(FILE *fp, object *op, int bufstate, int map_flags)
struct archt * arch
Pointer to archetype.
Definition: object.h:412
int allowed_size
Length of allowed, for faster computation.
Definition: artifact.h:20
Only for debugging purposes.
Definition: logger.h:13
static void compute_face_name(char *buf, size_t size, const char *name, const char *suffix)
Compute the name of a face with a suffix, taking into account names like &#39;.123&#39; or &#39;...
Definition: artifact.c:260
uint8_t type
PLAYER, BULLET, etc.
Definition: object.h:338
struct Settings settings
Server settings.
Definition: init.c:40
static artifact * get_empty_artifact(void)
Allocate and return the pointer to an empty artifact structure.
Definition: artifact.c:58
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
#define NROFATTACKS
Definition: attack.h:17
#define FLAG_LIFESAVE
Saves a players&#39; life once, then destr.
Definition: define.h:306
void add_abilities(object *op, const object *change)
Used in artifact generation.
Definition: artifact.c:284
const char * msg
If this is a book/sign/magic mouth/etc.
Definition: object.h:322
#define FLAG_MAKE_INVIS
(Item) gives invisibility when applied
Definition: define.h:329
sstring add_string(const char *str)
This will add &#39;str&#39; to the hash table.
Definition: shstr.c:124
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
int artifact_init
1 if doing archetypes initialization
Definition: artifact.c:28
void object_copy(const object *src_ob, object *dest_ob)
Copy object first frees everything allocated by the second object, and then copies the contents of th...
Definition: object.c:838
struct obj * inv
Pointer to the first object in the inventory.
Definition: object.h:290
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
Definition: logger.c:51
void set_abs_magic(object *op, int magic)
Sets magical bonus in an object, and recalculates the effect on the armour variable, and the effect on speed of armour.
Definition: treasure.c:836
void object_set_msg(object *op, const char *msg)
Set the message field of an object.
Definition: object.c:4695
object * item
Special values of the artifact.
Definition: artifact.h:15
uint16_t chance
Chance of the artifact to happen.
Definition: artifact.h:16
const New_Face * face
Face with colors.
Definition: object.h:332
#define FLAG_REFL_MISSILE
Arrows will reflect from object.
Definition: define.h:273
void object_free_key_values(object *op)
Zero the key_values on op, decrementing the shared-string refcounts and freeing the links...
Definition: object.c:727
int16_t level
Level of creature or object.
Definition: object.h:351
unsigned find_face(const char *name, unsigned error)
This returns an the face number of face &#39;name&#39;.
Definition: image.c:303
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.c:571
void object_update_speed(object *op)
Updates the speed of an object.
Definition: object.c:1129
int32_t value
How much money it is worth (or contains)
Definition: object.h:350
int8_t magic
Any magical bonuses to this item.
Definition: object.h:348
const char * name
More definite name, like "generate_kobold".
Definition: object.h:466
void init_artifacts(void)
Builds up the lists of artifacts from the file in the libdir.
Definition: artifact.c:513
#define FOR_INV_PREPARE(op_, it_)
Constructs a loop iterating over the inventory of an object.
Definition: define.h:705
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
Definition: object.c:1654
struct artifactstruct * next
Next artifact in the list.
Definition: artifact.h:18
int32_t food
How much food in stomach.
Definition: living.h:47