Crossfire Server, Trunk  R21078
object.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 
19 /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects.
20  object_sub/add_weight will transcend the environment updating the carrying
21  variable. */
22 
23 #include "global.h"
24 
25 #include <assert.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #ifndef WIN32 /* ---win32 exclude headers */
32 #include <sys/types.h>
33 #include <sys/uio.h>
34 #endif /* win32 */
35 
36 #include "loader.h"
37 #include "object.h"
38 #include "skills.h"
39 #include "sproto.h"
40 #include "stringbuffer.h"
41 
42 static int compare_ob_value_lists_one(const object *, const object *);
43 static int compare_ob_value_lists(const object *, const object *);
44 static void expand_objects(void);
45 static void permute(int *, int, int);
46 static int object_set_value_s(object *, const char *, const char *, int);
47 static void object_increase_nrof(object *op, uint32_t i);
48 
49 #ifdef MEMORY_DEBUG
50 int nroffreeobjects = 0;
51 int nrofallocobjects = 0;
52 #undef OBJ_EXPAND
53 #define OBJ_EXPAND 1
54 #else
55 static object objarray[STARTMAX];
58 #endif
59 
60 object *objects;
61 static object *free_objects;
62 object *active_objects;
66  0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1,
67  0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1
68 };
69 
72  0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2,
73  -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3
74 };
75 
78  0, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45,
79  48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49
80 };
81 
84  0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8,
85  1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8
86 };
87 
93 void init_objects(void) {
94  /* Initialize all objects: */
95  objects = NULL;
96  active_objects = NULL;
97 
98 #ifdef MEMORY_DEBUG
99  free_objects = NULL;
100 #else
101  free_objects = objarray;
102  objarray[0].prev = NULL,
103  objarray[0].next = &objarray[1],
104  SET_FLAG(&objarray[0], FLAG_REMOVED);
105  SET_FLAG(&objarray[0], FLAG_FREED);
106  for (int i = 1; i < STARTMAX-1; i++) {
107  objarray[i].next = &objarray[i+1];
108  objarray[i].prev = &objarray[i-1];
109  SET_FLAG(&objarray[i], FLAG_REMOVED);
110  SET_FLAG(&objarray[i], FLAG_FREED);
111  }
112  objarray[STARTMAX-1].next = NULL;
113  objarray[STARTMAX-1].prev = &objarray[STARTMAX-2];
114  SET_FLAG(&objarray[STARTMAX-1], FLAG_REMOVED);
115  SET_FLAG(&objarray[STARTMAX-1], FLAG_FREED);
116 #endif
117 }
118 
129 static int compare_ob_value_lists_one(const object *wants, const object *has) {
130  key_value *wants_field;
131 
132  /* n-squared behaviour (see object_get_key_value()), but I'm hoping both
133  * objects with lists are rare, and lists stay short. If not, use a
134  * different structure or at least keep the lists sorted...
135  */
136 
137  /* For each field in wants, */
138  for (wants_field = wants->key_values; wants_field != NULL; wants_field = wants_field->next) {
139  key_value *has_field;
140 
141  /* Look for a field in has with the same key. */
142  has_field = object_get_key_value(has, wants_field->key);
143 
144  if (has_field == NULL) {
145  /* No field with that name. */
146  return FALSE;
147  }
148 
149  /* Found the matching field. */
150  if (has_field->value != wants_field->value) {
151  /* Values don't match, so this half of the comparison is false. */
152  return FALSE;
153  }
154 
155  /* If we get here, we found a match. Now for the next field in wants. */
156  }
157 
158  /* If we get here, every field in wants has a matching field in has. */
159  return TRUE;
160 }
161 
170 static int compare_ob_value_lists(const object *ob1, const object *ob2) {
171  /* However, there may be fields in has which aren't partnered in wants,
172  * so we need to run the comparison *twice*. :(
173  */
174  return compare_ob_value_lists_one(ob1, ob2) && compare_ob_value_lists_one(ob2, ob1);
175 }
176 
202 int object_can_merge(object *ob1, object *ob2) {
203  /* A couple quicksanity checks */
204  if (ob1 == ob2 || ob1->type != ob2->type)
205  return 0;
206 
207  if (ob1->speed != ob2->speed)
208  return 0;
209  /* Note sure why the following is the case - either the object has to
210  * be animated or have a very low speed. Is this an attempted monster
211  * check?
212  */
213  /*TODO is this check really needed?*/
214  if (!QUERY_FLAG(ob1, FLAG_ANIMATE) && FABS((ob1)->speed) > MIN_ACTIVE_SPEED)
215  return 0;
216 
217  /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that
218  * value could not be stored in a int32_t (which unfortunately sometimes is
219  * used to store nrof).
220  */
221  if (ob1->nrof+ob2->nrof >= 1UL<<31)
222  return 0;
223 
224  /* This is really a spellbook check - really, we should
225  * check all objects in the inventory.
226  */
227  /*TODO is this check really needed?*/
228  if (ob1->inv || ob2->inv) {
229  /* if one object has inventory but the other doesn't, not equiv */
230  if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv))
231  return 0;
232 
233  /* Now check to see if the two inventory objects could merge */
234  if (!object_can_merge(ob1->inv, ob2->inv))
235  return 0;
236 
237  /* inventory ok - still need to check rest of this object to see
238  * if it is valid.
239  */
240  }
241 
242  /* If the objects have been identified, set the BEEN_APPLIED flag.
243  * This is to the comparison of the flags below will be OK. We
244  * just can't ignore the been applied or identified flags, as they
245  * are not equal - just if it has been identified, the been_applied
246  * flags lose any meaning.
247  */
248 
249  /*TODO is this hack on BEEN_APPLIED really needed? */
250  if (QUERY_FLAG(ob1, FLAG_IDENTIFIED))
252 
253  if (QUERY_FLAG(ob2, FLAG_IDENTIFIED))
255 
256 
257  /* Note: FLAG_INV_LOCKED is ignored for merging purposes */
258  if ((ob1->arch != ob2->arch)
259  || (ob1->flags[0] != ob2->flags[0])
260  || (ob1->flags[1] != ob2->flags[1])
261  || (ob1->flags[2] != ob2->flags[2])
262  || ((ob1->flags[3]&~0x84) != (ob2->flags[3]&~0x84)) /* ignore CLIENT_SENT and FLAG_OBJ_ORIGINAL */
263  || (ob1->name != ob2->name)
264  || (ob1->title != ob2->title)
265  || (ob1->msg != ob2->msg)
266  || (ob1->weight != ob2->weight)
267  || (ob1->item_power != ob2->item_power)
268  || (memcmp(&ob1->resist, &ob2->resist, sizeof(ob1->resist)) != 0)
269  || (memcmp(&ob1->stats, &ob2->stats, sizeof(ob1->stats)) != 0)
270  || (ob1->attacktype != ob2->attacktype)
271  || (ob1->magic != ob2->magic)
272  || (ob1->slaying != ob2->slaying)
273  || (ob1->skill != ob2->skill)
274  || (ob1->value != ob2->value)
275  || (ob1->animation_id != ob2->animation_id)
276  || (ob1->client_type != ob2->client_type)
277  || (ob1->materialname != ob2->materialname)
278  || (ob1->lore != ob2->lore)
279  || (ob1->subtype != ob2->subtype)
280  || (ob1->move_type != ob2->move_type)
281  || (ob1->move_block != ob2->move_block)
282  || (ob1->move_allow != ob2->move_allow)
283  || (ob1->move_on != ob2->move_on)
284  || (ob1->move_off != ob2->move_off)
285  || (ob1->move_slow != ob2->move_slow)
286  || (ob1->move_slow_penalty != ob2->move_slow_penalty)
287  || (ob1->map_layer != ob2->map_layer))
288  return 0;
289 
290  /* Don't merge objects that are applied. With the new 'body' code,
291  * it is possible for most any character to have more than one of
292  * some items equipped, and we don't want those to merge.
293  */
294  if (QUERY_FLAG(ob1, FLAG_APPLIED) || QUERY_FLAG(ob2, FLAG_APPLIED))
295  return 0;
296 
297  if (ob1->key_values != NULL || ob2->key_values != NULL) {
298  /* At least one of these has key_values. */
299  if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) {
300  /* One has fields, but the other one doesn't. */
301  return 0;
302  } else {
303  return compare_ob_value_lists(ob1, ob2);
304  }
305  }
306 
307  /*TODO should this really be limited to scrolls?*/
308  switch (ob1->type) {
309  case SCROLL:
310  if (ob1->level != ob2->level)
311  return 0;
312  break;
313  }
314 
315  /* Don't merge items with differing custom names. */
316  if (ob1->custom_name != ob2->custom_name)
317  return 0;
318 
319  /* Everything passes, must be OK. */
320  return 1;
321 }
322 
341 /* TODO should check call this this are made a place where we really need reevaluaton of whole tree */
342 signed long object_sum_weight(object *op) {
343  signed long sum;
344 
345  sum = 0;
346  FOR_INV_PREPARE(op, inv) {
347  if (inv->inv)
348  object_sum_weight(inv);
349  sum += inv->carrying+inv->weight*(inv->nrof ? inv->nrof : 1);
350  } FOR_INV_FINISH();
351  if (op->type == CONTAINER && op->stats.Str)
352  sum = (sum*(100-op->stats.Str))/100;
353  op->carrying = sum;
354  return sum;
355 }
356 
364 object *object_get_env_recursive(object *op) {
365  while (op->env != NULL)
366  op = op->env;
367  return op;
368 }
369 
384 object *object_get_player_container(object *op) {
385  for (; op != NULL && op->type != PLAYER; op = op->env)
386  /*TODO this is patching the structure on the flight as side effect. Shoudln't be needed in clean code */
387  if (op->env == op)
388  op->env = NULL;
389  return op;
390 }
391 
401 static const object *object_get_owner_const(const object *op) {
402  if (op->owner == NULL)
403  return NULL;
404 
405  if (!QUERY_FLAG(op->owner, FLAG_FREED)
406  && !QUERY_FLAG(op->owner, FLAG_REMOVED)
407  && op->owner->count == op->ownercount)
408  return op->owner;
409 
410  LOG(llevError, "Warning, no owner found\n");
411  return NULL;
412 }
413 
425 void object_dump(const object *op, StringBuffer *sb) {
426  if (op == NULL) {
427  stringbuffer_append_string(sb, "[NULL pointer]");
428  return;
429  }
430 
431  /* object *tmp;*/
432 
433  if (op->arch != NULL) {
434  const object *owner;
435 
436  stringbuffer_append_string(sb, "arch ");
437  stringbuffer_append_string(sb, op->arch->name ? op->arch->name : "(null)");
438  stringbuffer_append_string(sb, "\n");
439 
440  if (op->artifact != NULL) {
441  stringbuffer_append_string(sb, "artifact ");
443  stringbuffer_append_string(sb, "\n");
444  }
445 
446  get_ob_diff(sb, op, &empty_archetype->clone);
447  if (op->more) {
448  stringbuffer_append_printf(sb, "more %u\n", op->more->count);
449  }
450  if (op->head) {
451  stringbuffer_append_printf(sb, "head %u\n", op->head->count);
452  }
453  if (op->env) {
454  stringbuffer_append_printf(sb, "env %u\n", op->env->count);
455  }
456  if (op->inv) {
457  stringbuffer_append_printf(sb, "inv %u\n", op->inv->count);
458  }
459  owner = object_get_owner_const(op);
460  if (owner != NULL) {
461  stringbuffer_append_printf(sb, "owner %u\n", owner->count);
462  }
463  stringbuffer_append_string(sb, "end\n");
464  } else {
465  stringbuffer_append_string(sb, "Object ");
466  stringbuffer_append_string(sb, op->name == NULL ? "(null)" : op->name);
467  stringbuffer_append_string(sb, "\nend\n");
468  }
469 }
470 
481 void object_dump_all(void) {
482  object *op;
483 
484  for (op = objects; op != NULL; op = op->next) {
485  StringBuffer *sb;
486  char *diff;
487 
488  sb = stringbuffer_new();
489  object_dump(op, sb);
490  diff = stringbuffer_finish(sb);
491  LOG(llevDebug, "Object %u\n:%s\n", op->count, diff);
492  free(diff);
493  }
494 }
495 
508  object *op;
509 
510  for (op = objects; op != NULL; op = op->next)
511  if (op->count == i)
512  break;
513  return op;
514 }
515 
530 object *object_find_by_name_global(const char *str) {
531  const char *name = add_string(str);
532  object *op;
533 
534  for (op = objects; op != NULL; op = op->next)
535  if (op->name == name)
536  break;
537  free_string(name);
538  return op;
539 }
540 
554 #ifdef MEMORY_DEBUG
555  object *op, *next;
556 
557  for (op = free_objects; op != NULL; ) {
558  next = op->next;
559  free(op);
561  nroffreeobjects--;
562  op = next;
563  }
564  free_objects = NULL;
565 
566  for (op = objects; op != NULL; ) {
567  next = op->next;
568  if (!QUERY_FLAG(op, FLAG_FREED)) {
569  LOG(llevDebug, "non freed object: %s\n", op->name);
570  }
571  op = next;
572  }
573 #endif
574 
575  LOG(llevDebug, "%d allocated objects, %d free objects, STARMAX=%d\n", nrofallocobjects, nroffreeobjects, STARTMAX);
576 }
577 
590 object *object_get_owner(object *op) {
591  if (op->owner == NULL)
592  return NULL;
593 
594  if (!QUERY_FLAG(op->owner, FLAG_FREED)
595  && !QUERY_FLAG(op->owner, FLAG_REMOVED)
596  && op->owner->count == op->ownercount)
597  return op->owner;
598 
599  object_clear_owner(op);
600  return NULL;
601 }
602 
612 void object_clear_owner(object *op) {
613  if (!op)
614  return;
615 
616  op->owner = NULL;
617  op->ownercount = 0;
618 }
619 
632 void object_set_owner(object *op, object *owner) {
633  /* Assign temp to something, so it can't accidentally be NULL */
634  object *tmp = owner;
635  if (op == NULL)
636  return;
637  if (owner == NULL) {
638  object_clear_owner(op);
639  return;
640  }
641 
642  /* next line added to allow objects which own objects */
643  /* Add a check for ownercounts in here, as I got into an endless loop
644  * with the fireball owning a poison cloud which then owned the
645  * fireball. I believe that was caused by one of the objects getting
646  * freed and then another object replacing it. Since the ownercounts
647  * didn't match, this check is valid and I believe that cause is valid.
648  */
649  /*
650  * if owner is NULL, function will have already returned,
651  * so loop should still function as before.
652  */
653  while (tmp) {
654  tmp = object_get_owner(owner);
655  if (tmp)
656  owner = tmp;
657  }
658 
659  /* must not cause owner cycles */
660  assert(op != owner);
661 
662  if (op->owner != NULL)
663  object_clear_owner(op);
664 
665  op->owner = owner;
666  op->ownercount = owner->count;
667 }
668 
688 void object_copy_owner(object *op, object *clone) {
689  object *owner = object_get_owner(clone);
690  if (owner == NULL) {
691  /* players don't have owners - they own themselves. Update
692  * as appropriate.
693  */
694  /*TODO owner=self is dangerous and should be avoided*/
695  if (clone->type != PLAYER)
696  return;
697  owner = clone;
698  }
699  object_set_owner(op, owner);
700 }
701 
710 void object_set_enemy(object *op, object *enemy) {
711  if (op->enemy == enemy) {
712  return;
713  }
714 
715 #if 0
716  if (op->type != PLAYER) {
717  LOG(llevDebug, "object_set_enemy: %s(%lu)->enemy=%s(%lu)\n", op->name, op->count, enemy == NULL ? "NONE" : enemy->name, enemy == NULL ? 0 : enemy->count);
718  }
719 #endif
720  op->enemy = enemy;
721 }
722 
735 void object_reset(object *op) {
736  op->name = NULL;
737  op->name_pl = NULL;
738  op->title = NULL;
739  op->race = NULL;
740  op->slaying = NULL;
741  op->skill = NULL;
742  op->msg = NULL;
743  op->materialname = NULL;
744  op->lore = NULL;
745  object_clear(op);
746 }
747 
758 void object_free_key_values(object *op) {
759  key_value *i;
760  key_value *next = NULL;
761 
762  if (op->key_values == NULL)
763  return;
764 
765  for (i = op->key_values; i != NULL; i = next) {
766  /* Store next *first*. */
767  next = i->next;
768 
769  if (i->key)
771  if (i->value)
773  i->next = NULL;
774  free(i);
775  }
776 
777  op->key_values = NULL;
778 }
779 
790 void object_clear(object *op) {
791  /*TODO this comment must be investigated*/
792  /* redo this to be simpler/more efficient. Was also seeing
793  * crashes in the old code. Move this to the top - am
794  * seeing periodic crashes in this code, and would like to have
795  * as much info available as possible (eg, object name).
796  */
799 
800  /* the memset will clear all these values for us, but we need
801  * to reduce the refcount on them.
802  */
803  if (op->name != NULL)
805  if (op->name_pl != NULL)
807  if (op->title != NULL)
809  if (op->race != NULL)
811  if (op->slaying != NULL)
813  if (op->skill != NULL)
815  if (op->msg != NULL)
816  FREE_AND_CLEAR_STR(op->msg);
817  if (op->lore != NULL)
819  if (op->materialname != NULL)
821  if (op->discrete_damage != NULL)
823 
824  /* Remove object from friendly list if needed. */
825  if (QUERY_FLAG(op, FLAG_FRIENDLY))
827 
828  memset((void *)((char *)op+offsetof(object, name)), 0, sizeof(object)-offsetof(object, name));
829  /* Below here, we clear things that are not done by the memset,
830  * or set default values that are not zero.
831  */
832  /* This is more or less true */
833  SET_FLAG(op, FLAG_REMOVED);
834 
835 
836  op->contr = NULL;
837  op->below = NULL;
838  op->above = NULL;
839  op->inv = NULL;
840  op->container = NULL;
841  op->env = NULL;
842  op->more = NULL;
843  op->head = NULL;
844  op->map = NULL;
845  op->active_next = NULL;
846  op->active_prev = NULL;
847  /* What is not cleared is next, prev, and count */
848 
849  op->expmul = 1.0;
850  op->face = blank_face;
851  op->attacked_by_count = -1;
853  op->casting_time = -1;
854 }
855 
869 void object_copy(const object *src_ob, object *dest_ob) {
870  int is_freed = QUERY_FLAG(dest_ob, FLAG_FREED), is_removed = QUERY_FLAG(dest_ob, FLAG_REMOVED);
871 
872  /* Decrement the refcounts, but don't bother zeroing the fields;
873  they'll be overwritten by memcpy. */
874  if (dest_ob->artifact != NULL)
875  free_string(dest_ob->artifact);
876  if (dest_ob->name != NULL)
877  free_string(dest_ob->name);
878  if (dest_ob->name_pl != NULL)
879  free_string(dest_ob->name_pl);
880  if (dest_ob->anim_suffix != NULL)
881  free_string(dest_ob->anim_suffix);
882  if (dest_ob->title != NULL)
883  free_string(dest_ob->title);
884  if (dest_ob->race != NULL)
885  free_string(dest_ob->race);
886  if (dest_ob->slaying != NULL)
887  free_string(dest_ob->slaying);
888  if (dest_ob->skill != NULL)
889  free_string(dest_ob->skill);
890  if (dest_ob->msg != NULL)
891  free_string(dest_ob->msg);
892  if (dest_ob->lore != NULL)
893  free_string(dest_ob->lore);
894  if (dest_ob->materialname != NULL)
895  free_string(dest_ob->materialname);
896  if (dest_ob->custom_name != NULL)
897  free_string(dest_ob->custom_name);
898  if (dest_ob->discrete_damage != NULL)
900  if (dest_ob->spell_tags != NULL)
901  FREE_AND_CLEAR(dest_ob->spell_tags);
902 
903  /* Basically, same code as from object_clear() */
904 
905  object_free_key_values(dest_ob);
906  free_dialog_information(dest_ob);
907 
908  /* Copy all attributes below name (name included). */
909  (void)memcpy((void *)((char *)dest_ob+offsetof(object, name)),
910  (void *)((char *)src_ob+offsetof(object, name)),
911  sizeof(object)-offsetof(object, name));
912 
913  if (is_freed)
914  SET_FLAG(dest_ob, FLAG_FREED);
915  if (is_removed)
916  SET_FLAG(dest_ob, FLAG_REMOVED);
917  if (dest_ob->artifact != NULL)
918  add_refcount(dest_ob->artifact);
919  if (dest_ob->name != NULL)
920  add_refcount(dest_ob->name);
921  if (dest_ob->name_pl != NULL)
922  add_refcount(dest_ob->name_pl);
923  if (dest_ob->anim_suffix != NULL)
924  add_refcount(dest_ob->anim_suffix);
925  if (dest_ob->title != NULL)
926  add_refcount(dest_ob->title);
927  if (dest_ob->race != NULL)
928  add_refcount(dest_ob->race);
929  if (dest_ob->slaying != NULL)
930  add_refcount(dest_ob->slaying);
931  if (dest_ob->skill != NULL)
932  add_refcount(dest_ob->skill);
933  if (dest_ob->lore != NULL)
934  add_refcount(dest_ob->lore);
935  if (dest_ob->msg != NULL)
936  add_refcount(dest_ob->msg);
937  if (dest_ob->custom_name != NULL)
938  add_refcount(dest_ob->custom_name);
939  if (dest_ob->materialname != NULL)
940  add_refcount(dest_ob->materialname);
941  if (dest_ob->discrete_damage != NULL) {
942  dest_ob->discrete_damage = malloc(sizeof(int16_t)*NROFATTACKS);
943  memcpy(dest_ob->discrete_damage, src_ob->discrete_damage, sizeof(int16_t)*NROFATTACKS);
944  }
945 
946  if (dest_ob->spell_tags != NULL) {
947  dest_ob->spell_tags = malloc(sizeof(tag_t)*SPELL_TAG_SIZE);
948  memcpy(dest_ob->spell_tags, src_ob->spell_tags, sizeof(tag_t)*SPELL_TAG_SIZE);
949  }
950 
951  /* If archetype is a temporary one, we need to update reference count, because
952  * that archetype will be freed by object_free_drop_inventory() when the last object is removed.
953  */
954  if (dest_ob->arch->reference_count > 0)
955  dest_ob->arch->reference_count++;
956 
957  if (src_ob->speed < 0)
958  dest_ob->speed_left = src_ob->speed_left-RANDOM()%200/100.0;
959 
960  /* Copy over key_values, if any. */
961  if (src_ob->key_values != NULL) {
962  key_value *tail = NULL;
963  key_value *i;
964 
965  dest_ob->key_values = NULL;
966 
967  for (i = src_ob->key_values; i != NULL; i = i->next) {
968  key_value *new_link = malloc(sizeof(key_value));
969 
970  new_link->next = NULL;
971  new_link->key = add_refcount(i->key);
972  if (i->value)
973  new_link->value = add_refcount(i->value);
974  else
975  new_link->value = NULL;
976 
977  /* Try and be clever here, too. */
978  if (dest_ob->key_values == NULL) {
979  dest_ob->key_values = new_link;
980  tail = new_link;
981  } else {
982  tail->next = new_link;
983  tail = new_link;
984  }
985  }
986  }
987 
988  /* This way, dialog information will be parsed again when/if needed. */
989  CLEAR_FLAG(dest_ob, FLAG_DIALOG_PARSED);
990 
991  object_update_speed(dest_ob);
992 }
993 
1006 void object_copy_with_inv(const object *src_ob, object *dest_ob) {
1007  object_copy(src_ob, dest_ob);
1008  FOR_INV_PREPARE(src_ob, walk) {
1009  object *tmp;
1010 
1011  tmp = object_new();
1012  object_copy_with_inv(walk, tmp);
1013  object_insert_in_ob(tmp, dest_ob);
1014  } FOR_INV_FINISH();
1015 }
1016 
1024 static void expand_objects(void) {
1025  int i;
1026  object *new;
1027 
1028  new = (object *)CALLOC(OBJ_EXPAND, sizeof(object));
1029 
1030  if (new == NULL)
1032  free_objects = new;
1033  new[0].prev = NULL;
1034  new[0].next = &new[1],
1035  SET_FLAG(&new[0], FLAG_REMOVED);
1036  SET_FLAG(&new[0], FLAG_FREED);
1037 
1038  for (i = 1; i < OBJ_EXPAND-1; i++) {
1039  new[i].next = &new[i+1],
1040  new[i].prev = &new[i-1],
1041  SET_FLAG(&new[i], FLAG_REMOVED);
1042  SET_FLAG(&new[i], FLAG_FREED);
1043  }
1044  new[OBJ_EXPAND-1].prev = &new[OBJ_EXPAND-2],
1045  new[OBJ_EXPAND-1].next = NULL,
1046  SET_FLAG(&new[OBJ_EXPAND-1], FLAG_REMOVED);
1047  SET_FLAG(&new[OBJ_EXPAND-1], FLAG_FREED);
1048 
1051 }
1052 
1068 object *object_new(void) {
1069  object *op;
1070 #ifdef MEMORY_DEBUG
1071  /* FIXME: However this doesn't work since object_free2() sometimes add
1072  * objects back to the free_objects linked list, and some functions mess
1073  * with the object after return of object_free2(). This is bad and should be
1074  * fixed. But it would need fairly extensive changes and a lot of debugging.
1075  */
1076  op = calloc(1, sizeof(object));
1077  if (op == NULL)
1079 #else
1080  if (free_objects == NULL) {
1081  expand_objects();
1082  }
1083  op = free_objects;
1084  if (!QUERY_FLAG(op, FLAG_FREED)) {
1085  LOG(llevError, "Fatal: Getting busy object.\n");
1086 #ifdef MANY_CORES
1087  abort();
1088 #endif
1089  }
1090  free_objects = op->next;
1091  if (free_objects != NULL)
1092  free_objects->prev = NULL;
1093  nroffreeobjects--;
1094 #endif
1095  op->count = ++ob_count;
1096  op->name = NULL;
1097  op->name_pl = NULL;
1098  op->title = NULL;
1099  op->race = NULL;
1100  op->slaying = NULL;
1101  op->skill = NULL;
1102  op->lore = NULL;
1103  op->msg = NULL;
1104  op->materialname = NULL;
1105  op->next = objects;
1106  op->prev = NULL;
1107  op->active_next = NULL;
1108  op->active_prev = NULL;
1109  op->discrete_damage = NULL;
1110  op->spell_tags = NULL;
1111  if (objects != NULL)
1112  objects->prev = op;
1113  objects = op;
1114  object_clear(op);
1115  SET_FLAG(op, FLAG_REMOVED);
1116  return op;
1117 }
1118 
1130 void object_update_turn_face(object *op) {
1131  if (op->animation_id == 0 || !QUERY_FLAG(op, FLAG_IS_TURNABLE))
1132  return;
1133  animate_object(op, op->direction);
1134 }
1135 
1150 void object_update_speed(object *op) {
1151  /* FIXME what the hell is this crappy hack?*/
1152  extern int arch_init;
1153 
1154  /* No reason putting the archetypes objects on the speed list,
1155  * since they never really need to be updated.
1156  */
1157 
1158  if (QUERY_FLAG(op, FLAG_FREED) && op->speed) {
1159  LOG(llevError, "Object %s is freed but has speed.\n", op->name);
1160 #ifdef MANY_CORES
1161  abort();
1162 #else
1163  op->speed = 0;
1164 #endif
1165  }
1166  if (arch_init) {
1167  return;
1168  }
1169  if (FABS(op->speed) > MIN_ACTIVE_SPEED) {
1170  /* If already on active list, don't do anything */
1171  /* TODO this check can probably be simplified a lot */
1172  if (op->active_next || op->active_prev || op == active_objects)
1173  return;
1174 
1175  /* process_events() expects us to insert the object at the beginning
1176  * of the list. */
1178  if (op->active_next != NULL)
1179  op->active_next->active_prev = op;
1180  active_objects = op;
1181  } else {
1182  /* If not on the active list, nothing needs to be done */
1183  if (!op->active_next && !op->active_prev && op != active_objects)
1184  return;
1185 
1186  if (op->active_prev == NULL) {
1187  active_objects = op->active_next;
1188  if (op->active_next != NULL)
1189  op->active_next->active_prev = NULL;
1190  } else {
1191  op->active_prev->active_next = op->active_next;
1192  if (op->active_next)
1193  op->active_next->active_prev = op->active_prev;
1194  }
1195  op->active_next = NULL;
1196  op->active_prev = NULL;
1197  }
1198 }
1199 
1216  /* If not on the active list, nothing needs to be done */
1217  if (!op->active_next && !op->active_prev && op != active_objects)
1218  return;
1219 
1220  if (op->active_prev == NULL) {
1221  active_objects = op->active_next;
1222  if (op->active_next != NULL)
1223  op->active_next->active_prev = NULL;
1224  } else {
1225  op->active_prev->active_next = op->active_next;
1226  if (op->active_next)
1227  op->active_next->active_prev = op->active_prev;
1228  }
1229  op->active_next = NULL;
1230  op->active_prev = NULL;
1231 }
1232 
1260 void object_update(object *op, int action) {
1261  int update_now = 0, flags;
1262  MoveType move_on, move_off, move_block, move_slow;
1263  object *pl;
1264 
1265  if (op == NULL) {
1266  /* this should never happen */
1267  LOG(llevDebug, "object_update() called for NULL object.\n");
1268  return;
1269  }
1270 
1271  if (op->env != NULL) {
1272  /* Animation is currently handled by client, so nothing
1273  * to do in this case.
1274  */
1275  return;
1276  }
1277 
1278  /* If the map is saving, don't do anything as everything is
1279  * going to get freed anyways.
1280  */
1281  if (!op->map || op->map->in_memory == MAP_SAVING)
1282  return;
1283 
1284  /* make sure the object is within map boundaries */
1285  if (op->x < 0 || op->x >= MAP_WIDTH(op->map)
1286  || op->y < 0 || op->y >= MAP_HEIGHT(op->map)) {
1287  LOG(llevError, "object_update() called for object out of map!\n");
1288 #ifdef MANY_CORES
1289  abort();
1290 #endif
1291  return;
1292  }
1293 
1294  flags = GET_MAP_FLAGS(op->map, op->x, op->y);
1295  SET_MAP_FLAGS(op->map, op->x, op->y, flags|P_NEED_UPDATE);
1296  move_slow = GET_MAP_MOVE_SLOW(op->map, op->x, op->y);
1297  move_on = GET_MAP_MOVE_ON(op->map, op->x, op->y);
1298  move_block = GET_MAP_MOVE_BLOCK(op->map, op->x, op->y);
1299  move_off = GET_MAP_MOVE_OFF(op->map, op->x, op->y);
1300 
1301  if (action == UP_OBJ_INSERT) {
1303  update_now = 1;
1304 
1305  if (QUERY_FLAG(op, FLAG_NO_MAGIC) && !(flags&P_NO_MAGIC))
1306  update_now = 1;
1307 
1308  if (QUERY_FLAG(op, FLAG_DAMNED) && !(flags&P_NO_CLERIC))
1309  update_now = 1;
1310 
1311  if (QUERY_FLAG(op, FLAG_ALIVE) && !(flags&P_IS_ALIVE))
1312  update_now = 1;
1313 
1314  if ((move_on|op->move_on) != move_on)
1315  update_now = 1;
1316  if ((move_off|op->move_off) != move_off)
1317  update_now = 1;
1318  /* This isn't perfect, but I don't expect a lot of objects to
1319  * to have move_allow right now.
1320  */
1321  if (((move_block|op->move_block)&~op->move_allow) != move_block)
1322  update_now = 1;
1323  if ((move_slow|op->move_slow) != move_slow)
1324  update_now = 1;
1325 
1326  if (op->type == PLAYER)
1327  update_now = 1;
1328  /* if the object is being removed, we can't make intelligent
1329  * decisions, because object_remove() can't really pass the object
1330  * that is being removed.
1331  */
1332  } else if (action == UP_OBJ_REMOVE) {
1333  update_now = 1;
1334  } else if (action == UP_OBJ_FACE || action == UP_OBJ_CHANGE) {
1335  /* In addition to sending info to client, need to update space
1336  * information.
1337  */
1338  if (action == UP_OBJ_CHANGE)
1339  update_now = 1;
1340 
1341  /* There is a player on this space - we may need to send an
1342  * update to the client.
1343  * If this object is supposed to be animated by the client,
1344  * nothing to do here - let the client animate it.
1345  * We can't use FLAG_ANIMATE, as that is basically set for
1346  * all objects with multiple faces, regardless if they are animated.
1347  * (levers have it set for example).
1348  */
1349  if (flags&P_PLAYER
1352  pl = GET_MAP_PLAYER(op->map, op->x, op->y);
1353 
1354  /* If update_look is set, we're going to send this entire space
1355  * to the client, so no reason to send face information now.
1356  */
1357  if (!pl->contr->socket.update_look) {
1358  esrv_update_item(UPD_FACE, pl, op);
1359  }
1360  }
1361  } else {
1362  LOG(llevError, "object_update called with invalid action: %d\n", action);
1363  }
1364 
1365  if (update_now) {
1366  SET_MAP_FLAGS(op->map, op->x, op->y, flags|P_NO_ERROR|P_NEED_UPDATE);
1367  update_position(op->map, op->x, op->y);
1368  }
1369 
1370  if (op->more != NULL)
1371  object_update(op->more, action);
1372 }
1373 
1389 void object_free_drop_inventory(object *ob) {
1390  object_free2(ob, 0);
1391 }
1392 
1412 void object_free2(object *ob, int flags) {
1413  if (!QUERY_FLAG(ob, FLAG_REMOVED)) {
1414  StringBuffer *sb;
1415  char *diff;
1416 
1417  LOG(llevDebug, "Free object called with non removed object\n");
1418  sb = stringbuffer_new();
1419  object_dump(ob, sb);
1420  diff = stringbuffer_finish(sb);
1421  LOG(llevError, "%s", diff);
1422  free(diff);
1423 #ifdef MANY_CORES
1424  abort();
1425 #endif
1426  }
1427  if (QUERY_FLAG(ob, FLAG_FRIENDLY)) {
1428  LOG(llevMonster, "Warning: tried to free friendly object.\n");
1430  }
1431  if (QUERY_FLAG(ob, FLAG_FREED)) {
1432  StringBuffer *sb;
1433  char *diff;
1434 
1435  sb = stringbuffer_new();
1436  object_dump(ob, sb);
1437  diff = stringbuffer_finish(sb);
1438  LOG(llevError, "Trying to free freed object.\n%s\n", diff);
1439  free(diff);
1440  return;
1441  }
1442 
1443  if ((flags & FREE_OBJ_NO_DESTROY_CALLBACK) == 0) {
1444  /* Handle for plugin destroy event */
1445  execute_event(ob, EVENT_DESTROY, NULL, NULL, NULL, SCRIPT_FIX_NOTHING);
1446  }
1447 
1448  if (ob->inv) {
1449  /* Only if the space blocks everything do we not process -
1450  * if some form of movemnt is allowed, let objects
1451  * drop on that space.
1452  */
1453  if ((flags & FREE_OBJ_FREE_INVENTORY) != 0
1454  || ob->map == NULL
1455  || ob->map->in_memory != MAP_IN_MEMORY
1456  || (GET_MAP_MOVE_BLOCK(ob->map, ob->x, ob->y) == MOVE_ALL)) {
1457  FOR_INV_PREPARE(ob, op) {
1458  object_remove(op);
1459  object_free2(op, flags);
1460  } FOR_INV_FINISH();
1461  } else { /* Put objects in inventory onto this space */
1462  FOR_INV_PREPARE(ob, op) {
1463  object_remove(op);
1464  /* No drop means no drop, including its inventory */
1465  if (QUERY_FLAG(op, FLAG_NO_DROP))
1466  object_free2(op, FREE_OBJ_FREE_INVENTORY);
1467  else if (QUERY_FLAG(op, FLAG_STARTEQUIP)
1468  || QUERY_FLAG(op, FLAG_NO_DROP)
1469  || op->type == RUNE
1470  || op->type == TRAP
1473  else {
1474  object *part;
1475 
1476  /* If it's a multi-tile object, scatter dropped items randomly */
1477  if (ob->more) {
1478  int partcount = 0;
1479  /* Get the number of non-head parts */
1480  for (part = ob; part; part = part->more) {
1481  partcount++;
1482  }
1483  /* Select a random part */
1484  partcount = RANDOM()%partcount;
1485  for (part = ob; partcount > 0; partcount--) {
1486  part = part->more;
1487  }
1488  } else {
1489  part = ob;
1490  }
1491 
1492  if (QUERY_FLAG(op, FLAG_ALIVE)) {
1493  object_insert_to_free_spot_or_free(op, part->map, part->x, part->y, 0, SIZEOFFREE, NULL);
1494  } else {
1495  int f = 0;
1496  if (flags & FREE_OBJ_DROP_ABOVE_FLOOR)
1498  object_insert_in_map_at(op, part->map, NULL, f, part->x, part->y); /* Insert in same map as the envir */
1499  }
1500  }
1501  } FOR_INV_FINISH();
1502  }
1503  }
1504 
1505  if (ob->more != NULL) {
1506  object_free2(ob->more, flags);
1507  ob->more = NULL;
1508  }
1509 
1510  /* Remove object from the active list */
1511  ob->speed = 0;
1512  object_update_speed(ob);
1513 
1514  SET_FLAG(ob, FLAG_FREED);
1515  ob->count = 0;
1516 
1517  /* Remove this object from the list of used objects */
1518  if (ob->prev == NULL) {
1519  objects = ob->next;
1520  if (objects != NULL)
1521  objects->prev = NULL;
1522  } else {
1523  ob->prev->next = ob->next;
1524  if (ob->next != NULL)
1525  ob->next->prev = ob->prev;
1526  }
1527 
1528  if (ob->artifact != NULL) FREE_AND_CLEAR_STR(ob->artifact);
1529  if (ob->name != NULL) FREE_AND_CLEAR_STR(ob->name);
1530  if (ob->name_pl != NULL) FREE_AND_CLEAR_STR(ob->name_pl);
1531  if (ob->title != NULL) FREE_AND_CLEAR_STR(ob->title);
1532  if (ob->race != NULL) FREE_AND_CLEAR_STR(ob->race);
1533  if (ob->slaying != NULL) FREE_AND_CLEAR_STR(ob->slaying);
1534  if (ob->skill != NULL) FREE_AND_CLEAR_STR(ob->skill);
1535  if (ob->lore != NULL) FREE_AND_CLEAR_STR(ob->lore);
1536  if (ob->msg != NULL) FREE_AND_CLEAR_STR(ob->msg);
1537  if (ob->materialname != NULL) FREE_AND_CLEAR_STR(ob->materialname);
1538  if (ob->discrete_damage != NULL) FREE_AND_CLEAR(ob->discrete_damage);
1539  if (ob->spell_tags) FREE_AND_CLEAR(ob->spell_tags);
1540 
1541  /* Why aren't events freed? */
1543 
1545 
1546  /* Test whether archetype is a temporary one, and if so look whether it should be trashed. */
1547  if (ob->arch && ob->arch->reference_count > 0) {
1548  if (--ob->arch->reference_count == 0) {
1549  free_arch(ob->arch);
1550  }
1551  }
1552 
1553 #ifdef MEMORY_DEBUG
1554  free(ob);
1555 #else
1556  /* Now link it with the free_objects list: */
1557  ob->prev = NULL;
1558  ob->next = free_objects;
1559  if (free_objects != NULL)
1560  free_objects->prev = ob;
1561  free_objects = ob;
1562  nroffreeobjects++;
1563 #endif
1564 }
1565 
1576  int i = 0;
1577  object *tmp = free_objects;
1578 
1579  while (tmp != NULL)
1580  tmp = tmp->next,
1581  i++;
1582  return i;
1583 }
1584 
1595  int i = 0;
1596  object *tmp = objects;
1597 
1598  while (tmp != NULL)
1599  tmp = tmp->next,
1600  i++;
1601  return i;
1602 }
1603 
1614  int i = 0;
1615  object *tmp = active_objects;
1616 
1617  while (tmp != NULL)
1618  tmp = tmp->active_next,
1619  i++;
1620  return i;
1621 }
1622 
1640 void object_sub_weight(object *op, signed long weight) {
1641  while (op != NULL) {
1642  if (op->type == CONTAINER) {
1643  weight = (signed long)(weight*(100-op->stats.Str)/100);
1644  }
1645  op->carrying -= weight;
1646  op = op->env;
1647  }
1648 }
1649 
1669 void object_remove(object *op) {
1670  object *last = NULL;
1671  object *otmp;
1672  tag_t tag;
1673  int check_walk_off;
1674  mapstruct *m;
1675  int16_t x, y;
1676 
1677  if (QUERY_FLAG(op, FLAG_REMOVED)) {
1678  StringBuffer *sb;
1679  char *diff;
1680 
1681  sb = stringbuffer_new();
1682  object_dump(op, sb);
1683  diff = stringbuffer_finish(sb);
1684  LOG(llevError, "Trying to remove removed object.\n%s\n", diff);
1685  free(diff);
1686  abort();
1687  }
1688  if (op->more != NULL)
1689  object_remove(op->more);
1690 
1691  SET_FLAG(op, FLAG_REMOVED);
1692 
1693  /*
1694  * In this case, the object to be removed is in someones
1695  * inventory.
1696  */
1697  /* TODO try to call a generic inventory weight adjusting function like object_sub_weight */
1698  if (op->env != NULL) {
1699  player *pl = NULL;
1700 
1701  if (op->nrof)
1702  object_sub_weight(op->env, op->weight*op->nrof);
1703  else
1704  object_sub_weight(op->env, op->weight+op->carrying);
1705 
1706  /* Update in two cases: item is in a player, or in a container the player is looking into. */
1707  if (op->env->contr != NULL && op->head == NULL) {
1708  pl = op->env->contr;
1709  } else if (op->env->type == CONTAINER && QUERY_FLAG(op->env, FLAG_APPLIED)) {
1710 
1711  if (op->env->env && op->env->env->contr)
1712  /* Container is in player's inventory. */
1713  pl = op->env->env->contr;
1714  else if (op->env->map) {
1715  /* Container on map, look above for player. */
1716  object *above = op->env->above;
1717 
1718  while (above && !above->contr)
1719  above = above->above;
1720  if (above)
1721  pl = above->contr;
1722  }
1723  }
1724 
1725  /* NO_FIX_PLAYER is set when a great many changes are being
1726  * made to players inventory. If set, avoiding the call
1727  * to save cpu time.
1728  */
1729  otmp = object_get_player_container(op->env);
1730  if (otmp != NULL
1731  && otmp->contr
1732  && !QUERY_FLAG(otmp, FLAG_NO_FIX_PLAYER))
1733  fix_object(otmp);
1734 
1735  if (op->above != NULL)
1736  op->above->below = op->below;
1737  else
1738  op->env->inv = op->below;
1739 
1740  if (op->below != NULL)
1741  op->below->above = op->above;
1742 
1743  /* we set up values so that it could be inserted into
1744  * the map, but we don't actually do that - it is up
1745  * to the caller to decide what we want to do.
1746  */
1747  op->x = op->env->x;
1748  op->y = op->env->y;
1749  op->ox = op->x;
1750  op->oy = op->y;
1751  op->map = op->env->map;
1752  op->above = NULL;
1753  op->below = NULL;
1754  /* send the delitem before resetting env, so container's contents be may
1755  * refreshed */
1756  if (LOOK_OBJ(op) && pl != NULL)
1757  esrv_del_item(pl, op);
1758  op->env = NULL;
1759  return;
1760  }
1761 
1762  /* If we get here, we are removing it from a map */
1763  if (op->map == NULL)
1764  return;
1765 
1766  if (op->contr != NULL && !op->contr->hidden)
1767  op->map->players--;
1768 
1769  x = op->x;
1770  y = op->y;
1771  m = get_map_from_coord(op->map, &x, &y);
1772 
1773  if (!m) {
1774  LOG(llevError, "object_remove called when object was on map but appears to not be within valid coordinates? %s (%d,%d)\n", op->map->path, op->x, op->y);
1775  abort();
1776  }
1777  if (op->map != m) {
1778  LOG(llevError, "object_remove: Object not really on map it claimed to be on? %s != %s, %d,%d != %d,%d\n", op->map->path, m->path, op->x, op->y, x, y);
1779  }
1780 
1781  /* link the object above us */
1782  if (op->above)
1783  op->above->below = op->below;
1784  else
1785  SET_MAP_TOP(m, x, y, op->below); /* we were top, set new top */
1786 
1787  /* Relink the object below us, if there is one */
1788  if (op->below) {
1789  op->below->above = op->above;
1790  } else {
1791  /* Nothing below, which means we need to relink map object for this space
1792  * use translated coordinates in case some oddness with map tiling is
1793  * evident
1794  */
1795  /*TODO is this check really needed?*/
1796  if (GET_MAP_OB(m, x, y) != op) {
1797  StringBuffer *sb;
1798  char *diff;
1799 
1800  sb = stringbuffer_new();
1801  object_dump(op, sb);
1802  diff = stringbuffer_finish(sb);
1803  LOG(llevError, "object_remove: GET_MAP_OB on %s does not return object to be removed even though it appears to be on the bottom?\n%s\n", m->path, diff);
1804  free(diff);
1805 
1806  sb = stringbuffer_new();
1807  object_dump(GET_MAP_OB(m, x, y), sb);
1808  diff = stringbuffer_finish(sb);
1809  LOG(llevError, "%s\n", diff);
1810  free(diff);
1811  }
1812  SET_MAP_OB(m, x, y, op->above); /* goes on above it. */
1813  }
1814  op->above = NULL;
1815  op->below = NULL;
1816 
1817  if (op->map->in_memory == MAP_SAVING)
1818  return;
1819 
1820  tag = op->count;
1821  check_walk_off = !QUERY_FLAG(op, FLAG_NO_APPLY);
1822  FOR_MAP_PREPARE(m, x, y, tmp) {
1823  /* No point updating the players look faces if he is the object
1824  * being removed.
1825  */
1826 
1827  if (tmp->type == PLAYER && tmp != op) {
1828  /* If a container that the player is currently using somehow gets
1829  * removed (most likely destroyed), update the player view
1830  * appropriately.
1831  */
1832  if (tmp->container == op) {
1833  CLEAR_FLAG(op, FLAG_APPLIED);
1834  tmp->container = NULL;
1835  }
1836  tmp->contr->socket.update_look = 1;
1837  }
1838  /* See if player moving off should effect something */
1839  if (check_walk_off
1840  && ((op->move_type&tmp->move_off) && (op->move_type&~tmp->move_off&~tmp->move_block) == 0)) {
1841  ob_move_on(tmp, op, NULL);
1842  if (object_was_destroyed(op, tag)) {
1843  LOG(llevError, "BUG: object_remove(): name %s, archname %s destroyed leaving object\n", tmp->name, tmp->arch->name);
1844  }
1845  }
1846 
1847  /* Eneq(@csd.uu.se): Fixed this to skip tmp->above=tmp */
1848  if (tmp->above == tmp)
1849  tmp->above = NULL;
1850  last = tmp;
1851  } FOR_MAP_FINISH();
1852  /* last == NULL or there are no objects on this space */
1853  if (last == NULL) {
1854  /* set P_NEED_UPDATE, otherwise update_position will complain. In theory,
1855  * we could preserve the flags (GET_MAP_FLAGS), but update_position figures
1856  * those out anyways, and if there are any flags set right now, they won't
1857  * be correct anyways.
1858  */
1859  SET_MAP_FLAGS(op->map, op->x, op->y, P_NEED_UPDATE);
1860  update_position(op->map, op->x, op->y);
1861  } else
1863 
1864  if (QUERY_FLAG(op, FLAG_BLOCKSVIEW) || (op->glow_radius != 0))
1865  update_all_los(op->map, op->x, op->y);
1866 }
1867 
1884 object *object_merge(object *op, object *top) {
1885  if (!op->nrof)
1886  return NULL;
1887 
1888  if (top == NULL)
1889  for (top = op; top != NULL && top->above != NULL; top = top->above)
1890  ;
1892  if (top == op)
1893  continue;
1894  if (object_can_merge(op, top)) {
1895  object_increase_nrof(top, op->nrof);
1896  /*
1897  * Previous behavior set weight to zero here.
1898  * This, however, caused the object_sub_weight
1899  * call in object_remove to subtract zero weight
1900  * when removing the object. Thus, until inventory
1901  * weight is next recalculated, the object merged
1902  * into another pile added weight in object_increase_nrof
1903  * but did not remove the weight from the original
1904  * instance of itself in object_remove, essentially
1905  * counting for double weight for several minutes.
1906  *
1907  * SilverNexus 2014-05-27
1908  */
1909  object_remove(op);
1911  return top;
1912  }
1914  return NULL;
1915 }
1916 
1936 object *object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y) {
1937  object *tmp;
1938 
1939  op = HEAD(op);
1940  for (tmp = op; tmp; tmp = tmp->more) {
1941  tmp->x = x+tmp->arch->clone.x;
1942  tmp->y = y+tmp->arch->clone.y;
1943  tmp->map = m;
1944  }
1945  return object_insert_in_map(op, m, originator, flag);
1946 }
1947 
1968 void object_merge_spell(object *op, int16_t x, int16_t y) {
1969  int i;
1970 
1971  /* We try to do some merging of spell objects - if something has same owner,
1972  * is same type of spell, and going in the same direction, it is somewhat
1973  * mergable.
1974  *
1975  * If the spell object has an other_arch, don't merge - when the spell
1976  * does something, like explodes, it will use this other_arch, and
1977  * if we merge, there is no easy way to make the correct values be
1978  * set on this new object (values should be doubled, tripled, etc.)
1979  *
1980  * We also care about speed - only process objects that will not be
1981  * active this tick. Without this, the results are incorrect - think
1982  * of a case where tmp would normally get processed this tick, but
1983  * get merges with op, which does not get processed.
1984  */
1985  FOR_MAP_PREPARE(op->map, x, y, tmp) {
1986  if (op->type == tmp->type
1987  && op->subtype == tmp->subtype
1988  && op->direction == tmp->direction
1989  && op->owner == tmp->owner && op->ownercount == tmp->ownercount
1990  && op->range == tmp->range
1991  && op->stats.wc == tmp->stats.wc
1992  && op->level == tmp->level
1993  && op->attacktype == tmp->attacktype
1994  && op->speed == tmp->speed
1995  && !tmp->other_arch
1996  && (tmp->speed_left+tmp->speed) < 0.0
1997  && op != tmp) {
1998  /* Quick test - if one or the other objects already have hash tables
1999  * set up, and that hash bucket contains a value that doesn't
2000  * match what we want to set it up, we won't be able to merge.
2001  * Note that these two if statements are the same, except
2002  * for which object they are checking against. They could
2003  * be merged, but the line wrapping would be large enough
2004  * that IMO it would become difficult to read the different clauses
2005  * so its cleaner just to do 2 statements - MSW
2006  */
2007  if (op->spell_tags
2008  && !OB_SPELL_TAG_MATCH(op, (tag_t)tmp->stats.maxhp)
2009  && OB_SPELL_TAG_HASH(op, tmp->stats.maxhp) != 0)
2010  continue;
2011 
2012  if (tmp->spell_tags
2013  && !OB_SPELL_TAG_MATCH(tmp, (tag_t)op->stats.maxhp)
2014  && OB_SPELL_TAG_HASH(tmp, op->stats.maxhp) != 0)
2015  continue;
2016 
2017  /* If we merge, the data from tmp->spell_tags gets copied into op.
2018  * so we need to make sure that slot isn't filled up.
2019  */
2020  if (tmp->spell_tags
2021  && !OB_SPELL_TAG_MATCH(tmp, (tag_t)tmp->stats.maxhp)
2022  && OB_SPELL_TAG_HASH(tmp, tmp->stats.maxhp) != 0)
2023  continue;
2024 
2025  /* If both objects have spell_tags, we need to see if there are conflicting
2026  * values - if there are, we won't be able to merge then.
2027  */
2028  if (tmp->spell_tags && op->spell_tags) {
2029  int need_copy = 0;
2030 
2031  for (i = 0; i < SPELL_TAG_SIZE; i++) {
2032  /* If the two tag values in the hash are set, but are
2033  * not set to the same value, then these objects
2034  * can not be merged.
2035  */
2036  if (op->spell_tags[i] && tmp->spell_tags[i]
2037  && op->spell_tags[i] != tmp->spell_tags[i]) {
2039  break;
2040  }
2041  /* If one tag is set and the other is not, that is
2042  * fine, but we have to note that we need to copy
2043  * the data in that case.
2044  */
2045  if ((!op->spell_tags[i] && tmp->spell_tags[i])
2046  || (op->spell_tags[i] && !tmp->spell_tags[i])) {
2047  need_copy = 1;
2048  }
2049  }
2050  /* If we did not get through entire array, it means
2051  * we got a conflicting hash, and so we won't be
2052  * able to merge these - just continue processing
2053  * object on this space.
2054  */
2055  if (i <= SPELL_TAG_SIZE)
2056  continue;
2057 
2058  /* Ok - everything checked out - we should be able to
2059  * merge tmp in op. So lets copy the tag data if
2060  * needed. Note that this is a selective copy, as
2061  * we don't want to clear values that may be set in op.
2062  */
2063  if (need_copy) {
2064  for (i = 0; i < SPELL_TAG_SIZE; i++)
2065  if (!op->spell_tags[i]
2066  && tmp->spell_tags[i]
2067  && tmp->spell_tags[i] != (tag_t)op->stats.maxhp)
2068  op->spell_tags[i] = tmp->spell_tags[i];
2069  }
2070  FREE_AND_CLEAR(tmp->spell_tags);
2071  }
2072 
2073  /* if tmp has a spell_tags table, copy it to op and free tmps */
2074  if (tmp->spell_tags && !op->spell_tags) {
2075  op->spell_tags = tmp->spell_tags;
2076  tmp->spell_tags = NULL;
2077 
2078  /* We don't need to keep a copy of our maxhp value
2079  * in the copied over value
2080  */
2081  if (OB_SPELL_TAG_MATCH(op, (tag_t)op->stats.maxhp))
2082  OB_SPELL_TAG_HASH(op, op->stats.maxhp) = 0;
2083  }
2084 
2085  /* For spells to work correctly, we need to record what spell
2086  * tags we've merged in with this effect. This is used
2087  * in ok_to_put_more() to see if a spell effect is already on
2088  * the space.
2089  */
2090  if (op->stats.maxhp != tmp->stats.maxhp) {
2091 #ifdef OBJECT_DEBUG
2092  /* This if statement should never happen - the logic above should
2093  * have prevented it. It is a problem, because by now its possible
2094  * we've destroyed the spell_tags in tmp, so we can't really
2095  * just bail out.
2096  */
2097 
2098  if (op->spell_tags
2099  && OB_SPELL_TAG_HASH(op, tmp->stats.maxhp) != 0
2100  && !OB_SPELL_TAG_MATCH(op, tmp->stats.maxhp)) {
2101  LOG(llevError, "object_insert_in_map: Got non matching spell tags: %d != %d\n", OB_SPELL_TAG_HASH(op, tmp->stats.maxhp), tmp->stats.maxhp);
2102  }
2103 #endif
2104  if (!op->spell_tags)
2105  op->spell_tags = calloc(SPELL_TAG_SIZE, sizeof(tag_t));
2106 
2107  OB_SPELL_TAG_HASH(op, tmp->stats.maxhp) = tmp->stats.maxhp;
2108  }
2109 
2111  op->speed_left = MAX(op->speed_left, tmp->speed_left);
2112 
2113  if (tmp->duration != op->duration) {
2114  /* We need to use tmp_dam here because otherwise the
2115  * calculations can overflow the size of stats.dam.
2116  */
2117  int tmp_dam = tmp->stats.dam*(tmp->duration+1)+
2118  op->stats.dam*(op->duration+1);
2119 
2120  op->duration = MAX(op->duration, tmp->duration);
2121  tmp_dam /= op->duration+1;
2122  op->stats.dam = tmp_dam+1;
2123  } else {
2124  /* in this case, duration is the same, so simply adding
2125  * up damage works.
2126  */
2127  op->stats.dam += tmp->stats.dam;
2128  }
2129 
2130  object_remove(tmp);
2132  }
2133  } FOR_MAP_FINISH();
2134 }
2135 
2167 object *object_insert_in_map(object *op, mapstruct *m, object *originator, int flag) {
2168  object *tmp, *top, *floor = NULL;
2169  int16_t x, y;
2170 
2171  if (QUERY_FLAG(op, FLAG_FREED)) {
2172  LOG(llevError, "Trying to insert freed object!\n");
2173  return NULL;
2174  }
2175  if (m == NULL) {
2176  StringBuffer *sb;
2177  char *diff;
2178 
2179  sb = stringbuffer_new();
2180  object_dump(op, sb);
2181  diff = stringbuffer_finish(sb);
2182  LOG(llevError, "Trying to insert in null-map!\n%s\n", diff);
2183  free(diff);
2184  return op;
2185  }
2186  if (out_of_map(m, op->x, op->y)) {
2187  StringBuffer *sb;
2188  char *diff;
2189 
2190  sb = stringbuffer_new();
2191  object_dump(op, sb);
2192  diff = stringbuffer_finish(sb);
2193  LOG(llevError, "Trying to insert object outside the map.\n%s\n", diff);
2194  free(diff);
2195 #ifdef MANY_CORES
2196  /* Better to catch this here, as otherwise the next use of this object
2197  * is likely to cause a crash. Better to find out where it is getting
2198  * improperly inserted.
2199  */
2200  abort();
2201 #endif
2202  return op;
2203  }
2204  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
2205  StringBuffer *sb;
2206  char *diff;
2207 
2208  sb = stringbuffer_new();
2209  object_dump(op, sb);
2210  diff = stringbuffer_finish(sb);
2211  LOG(llevError, "Trying to insert (map) inserted object.\n%s\n", diff);
2212  free(diff);
2213  return op;
2214  }
2215  if (op->more != NULL) {
2216  /* The part may be on a different map. */
2217 
2218  object *more = op->more;
2219 
2220  /* We really need the caller to normalize coordinates - if
2221  * we set the map, that doesn't work if the location is within
2222  * a map and this is straddling an edge. So only if coordinate
2223  * is clear wrong do we normalize it.
2224  */
2225  if (OUT_OF_REAL_MAP(more->map, more->x, more->y)) {
2226  /* Debugging information so you can see the last coordinates this object had */
2227  more->ox = more->x;
2228  more->oy = more->y;
2229  more->map = get_map_from_coord(more->map, &more->x, &more->y);
2230  } else if (!more->map) {
2231  /* For backwards compatibility - when not dealing with tiled maps,
2232  * more->map should always point to the parent.
2233  */
2234  more->map = m;
2235  }
2236 
2237  if (object_insert_in_map(more, more->map, originator, flag) == NULL) {
2238  if (!op->head)
2239  LOG(llevError, "BUG: object_insert_in_map(): inserting op->more killed op\n");
2240  return NULL;
2241  }
2242  }
2243  CLEAR_FLAG(op, FLAG_REMOVED);
2244 
2245  /* Debugging information so you can see the last coordinates this object had */
2246  op->ox = op->x;
2247  op->oy = op->y;
2248  x = op->x;
2249  y = op->y;
2250  op->map = get_map_from_coord(m, &x, &y);
2251 
2252  /* this has to be done after we translate the coordinates. */
2253  if (op->nrof
2254  && !(flag&INS_NO_MERGE)
2255  && op->type != SPELL_EFFECT) {
2256  FOR_MAP_PREPARE(op->map, x, y, tmp) {
2257  if (object_can_merge(op, tmp)) {
2258  op->nrof += tmp->nrof;
2259  object_remove(tmp);
2261  }
2262  } FOR_MAP_FINISH();
2263  } else if (op->type == SPELL_EFFECT
2264  && !op->range
2265  && !op->other_arch
2266  && (op->speed_left+op->speed) < 0.0) {
2267  object_merge_spell(op, x, y);
2268  }
2269 
2270  /* Ideally, the caller figures this out. However, it complicates a lot
2271  * of areas of callers (eg, anything that uses object_find_free_spot() would now
2272  * need extra work
2273  */
2274  if (op->map != m) {
2275  /* coordinates should not change unless map also changes */
2276  op->x = x;
2277  op->y = y;
2278  }
2279 
2280  if (op->type != LAMP)
2281  /* lamps use the FLAG_APPLIED to keep the light/unlit status, so don't reset it.
2282  Other objects just get unapplied, since the container "drops" them. */
2283  CLEAR_FLAG(op, FLAG_APPLIED);
2285  if (!QUERY_FLAG(op, FLAG_ALIVE))
2287 
2288  /* In many places, a player is passed as the originator, which
2289  * is fine. However, if the player is on a transport, they are not
2290  * actually on the map, so we can't use them for the linked pointers,
2291  * nor should the walk on function below use them either.
2292  */
2293  if (originator && originator->contr && originator->contr->transport)
2294  originator = originator->contr->transport;
2295 
2296  if (flag&INS_BELOW_ORIGINATOR) {
2297  if (originator->map != op->map
2298  || originator->x != op->x
2299  || originator->y != op->y) {
2300  LOG(llevError, "object_insert_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
2301  abort();
2302  }
2303  op->above = originator;
2304  op->below = originator->below;
2305  if (op->below)
2306  op->below->above = op;
2307  else
2308  SET_MAP_OB(op->map, op->x, op->y, op);
2309  /* since *below *originator, no need to update top */
2310  originator->below = op;
2311  } else {
2312  /* If there are other objects, then */
2313  /* This test is incorrect i think, as ins_above_floor_only needs the floor variable
2314  if ((!(flag&INS_MAP_LOAD)) && ((top = GET_MAP_OB(op->map, op->x, op->y)) != NULL)) {
2315  */
2316  object *last;
2317 
2318  /*
2319  * If there are multiple objects on this space, we do some trickier handling.
2320  * We've already dealt with merging if appropriate.
2321  * Generally, we want to put the new object on top. But if
2322  * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last
2323  * floor, we want to insert above that and no further.
2324  * Also, if there are spell objects on this space, we stop processing
2325  * once we get to them. This reduces the need to traverse over all of
2326  * them when adding another one - this saves quite a bit of cpu time
2327  * when lots of spells are cast in one area. Currently, it is presumed
2328  * that flying non pickable objects are spell objects.
2329  */
2330  last = NULL;
2331  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
2332  if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)
2333  || QUERY_FLAG(tmp, FLAG_OVERLAY_FLOOR))
2334  floor = tmp;
2335 
2336  if (QUERY_FLAG(tmp, FLAG_NO_PICK)
2338  && !QUERY_FLAG(tmp, FLAG_IS_FLOOR)) {
2339  /* We insert above tmp, so we want this object below this */
2340  break;
2341  }
2342  last = tmp;
2343  } FOR_MAP_FINISH();
2344  top = last;
2345 
2346  if (flag&INS_MAP_LOAD)
2347  top = GET_MAP_TOP(op->map, op->x, op->y);
2348  if (flag&INS_ABOVE_FLOOR_ONLY)
2349  top = floor;
2350 
2351  /* Top is the object that our object (op) is going to get inserted above. */
2352 
2353  /* First object on this space */
2354  if (!top) {
2355  op->above = GET_MAP_OB(op->map, op->x, op->y);
2356  if (op->above)
2357  op->above->below = op;
2358  op->below = NULL;
2359  SET_MAP_OB(op->map, op->x, op->y, op);
2360  } else { /* get inserted into the stack above top */
2361  op->above = top->above;
2362  if (op->above)
2363  op->above->below = op;
2364  op->below = top;
2365  top->above = op;
2366  }
2367  if (op->above == NULL)
2368  SET_MAP_TOP(op->map, op->x, op->y, op);
2369  } /* else not INS_BELOW_ORIGINATOR */
2370 
2371  if (op->type == PLAYER)
2372  op->contr->do_los = 1;
2373 
2374  /* If we have a floor, we know the player, if any, will be above
2375  * it, so save a few ticks and start from there.
2376  */
2377  if (!(flag&INS_MAP_LOAD)) {
2378  tmp = floor ? floor : GET_MAP_OB(op->map, op->x, op->y);
2380  if (tmp->type == PLAYER)
2381  tmp->contr->socket.update_look = 1;
2383  }
2384 
2385  /* If this object glows, it may affect lighting conditions that are
2386  * visible to others on this map. But update_all_los is really
2387  * an inefficient way to do this, as it means los for all players
2388  * on the map will get recalculated. The players could very well
2389  * be far away from this change and not affected in any way -
2390  * this should get redone to only look for players within range,
2391  * or just updating the P_NEED_UPDATE for spaces within this area
2392  * of effect may be sufficient.
2393  */
2394  if (MAP_DARKNESS(op->map) && (op->glow_radius != 0))
2395  update_all_los(op->map, op->x, op->y);
2396 
2397  /* updates flags (blocked, alive, no magic, etc) for this map space */
2399 
2400  if (op->contr && !op->contr->hidden)
2401  op->map->players++;
2402 
2403  /* Don't know if moving this to the end will break anything. However,
2404  * we want to have update_look set above before calling this.
2405  *
2406  * object_check_move_on() must be after this because code called from
2407  * object_check_move_on() depends on correct map flags (so functions like
2408  * blocked() and wall() work properly), and these flags are updated by
2409  * object_update().
2410  */
2411 
2412  /* if this is not the head or flag has been passed, don't check walk on status */
2413 
2414  if (!(flag&INS_NO_WALK_ON) && !op->head) {
2415  if (object_check_move_on(op, originator))
2416  return NULL;
2417 
2418  /* If we are a multi part object, lets work our way through the check
2419  * walk on's.
2420  */
2421  for (tmp = op->more; tmp != NULL; tmp = tmp->more)
2422  if (object_check_move_on(tmp, originator))
2423  return NULL;
2424  }
2425  return op;
2426 }
2427 
2440 void object_replace_insert_in_map(const char *arch_string, object *op) {
2441  object *tmp1;
2442 
2443  /* first search for itself and remove any old instances */
2444  FOR_MAP_PREPARE(op->map, op->x, op->y, tmp) {
2445  if (!strcmp(tmp->arch->name, arch_string)) { /* same archetype */
2446  object_remove(tmp);
2448  }
2449  } FOR_MAP_FINISH();
2450 
2451  tmp1 = arch_to_object(find_archetype(arch_string));
2452  object_insert_in_map_at(tmp1, op->map, op, INS_BELOW_ORIGINATOR, op->x, op->y);
2453 }
2454 
2478 object *object_split(object *orig_ob, uint32_t nr, char *err, size_t size) {
2479  object *newob;
2480 
2481  if (MAX(1, orig_ob->nrof) < nr) {
2482  /* If err is set, the caller knows that nr can be wrong (player trying to drop items), thus don't log that. */
2483  if (err)
2484  snprintf(err, size, "There are only %u %ss.", orig_ob->nrof ? orig_ob->nrof : 1, orig_ob->name);
2485  else
2486  LOG(llevDebug, "There are only %u %ss.\n", orig_ob->nrof ? orig_ob->nrof : 1, orig_ob->name);
2487  return NULL;
2488  }
2489  newob = object_create_clone(orig_ob);
2490  if (orig_ob->nrof == 0) {
2491  if (!QUERY_FLAG(orig_ob, FLAG_REMOVED)) {
2492  object_remove(orig_ob);
2493  }
2495  } else {
2496  newob->nrof = nr;
2497  object_decrease_nrof(orig_ob, nr);
2498  }
2499 
2500  return newob;
2501 }
2502 
2520 object *object_decrease_nrof(object *op, uint32_t i) {
2521  object *tmp;
2522 
2523  if (i == 0) /* objects with op->nrof require this check */
2524  return op;
2525 
2526  if (i > op->nrof)
2527  i = op->nrof;
2528 
2529  if (QUERY_FLAG(op, FLAG_REMOVED)) {
2530  op->nrof -= i;
2531  } else if (op->env != NULL) {
2532  if (i < op->nrof) {
2533  player *pl;
2534  /* is this object in the players inventory, or sub container
2535  * therein?
2536  */
2537  tmp = object_get_player_container(op->env);
2538  /* nope. Is this a container the player has opened?
2539  * If so, set tmp to that player.
2540  * IMO, searching through all the players will mostly
2541  * likely be quicker than following op->env to the map,
2542  * and then searching the map for a player.
2543  */
2544  if (!tmp) {
2545  for (pl = first_player; pl; pl = pl->next)
2546  if (pl->ob->container == op->env)
2547  break;
2548  if (pl)
2549  tmp = pl->ob;
2550  else
2551  tmp = NULL;
2552  }
2553 
2554  /* Because of weight reduction by container and integer arithmetic,
2555  * there is no guarantee the rounded weight of combined items will be
2556  * the same as the sum of rounded weights.
2557  * Therefore just remove the current weight, and add the new.
2558  * Same adjustment done in object_increase_nrof().
2559  */
2560  object_sub_weight(op->env, op->weight * op->nrof);
2561  op->nrof -= i;
2562  object_add_weight(op->env, op->weight * op->nrof);
2563  if (tmp) {
2564  esrv_update_item(UPD_NROF, tmp, op);
2565  esrv_update_item(UPD_WEIGHT, tmp, op->env);
2566  fix_object(tmp);
2567  }
2568  } else {
2569  object_remove(op);
2570  op->nrof = 0;
2571  }
2572  } else {
2573  /* On a map. */
2574  if (i < op->nrof) {
2575  op->nrof -= i;
2576 
2577  FOR_MAP_PREPARE(op->map, op->x, op->y, pl)
2578  if (pl->contr) {
2579  pl->contr->socket.update_look = 1;
2580  break;
2581  }
2582  FOR_MAP_FINISH();
2583  } else {
2584  object_remove(op);
2585  op->nrof = 0;
2586  }
2587  }
2588 
2589  if (op->nrof) {
2590  return op;
2591  } else {
2593  return NULL;
2594  }
2595 }
2596 
2607 static void object_increase_nrof(object *op, uint32_t i) {
2608  object *tmp;
2609 
2610  if (i == 0) /* objects with op->nrof require this check */
2611  return;
2612 
2613  if (QUERY_FLAG(op, FLAG_REMOVED)) {
2614  op->nrof += i;
2615  } else if (op->env != NULL) {
2616  player *pl;
2617  /* is this object in the players inventory, or sub container
2618  * therein?
2619  */
2620  tmp = object_get_player_container(op->env);
2621  /* nope. Is this a container the player has opened?
2622  * If so, set tmp to that player.
2623  * IMO, searching through all the players will mostly
2624  * likely be quicker than following op->env to the map,
2625  * and then searching the map for a player.
2626  */
2627  if (!tmp) {
2628  for (pl = first_player; pl; pl = pl->next)
2629  if (pl->ob->container == op->env)
2630  break;
2631  if (pl)
2632  tmp = pl->ob;
2633  else
2634  tmp = NULL;
2635  }
2636 
2637  /* Because of weight reduction by container and integer arithmetic,
2638  * there is no guarantee the rounded weight of combined items will be
2639  * the same as the sum of rounded weights.
2640  * Therefore just remove the current weight, and add the new.
2641  * Same adjustment done in object_decrease_nrof().
2642  */
2643  object_sub_weight(op->env, op->weight * op->nrof);
2644  op->nrof += i;
2645  object_add_weight(op->env, op->weight * op->nrof);
2646  if (tmp) {
2647  esrv_update_item(UPD_NROF, tmp, op);
2648  // Why don't we need to update weight of op->env here?
2649  }
2650  } else {
2651  /* On a map. */
2652  op->nrof += i;
2653 
2654  FOR_MAP_PREPARE(op->map, op->x, op->y, pl)
2655  if (pl->contr) {
2656  pl->contr->socket.update_look = 1;
2657  break;
2658  }
2659  FOR_MAP_FINISH();
2660  }
2661 }
2662 
2680 void object_add_weight(object *op, signed long weight) {
2681  while (op != NULL) {
2682  if (op->type == CONTAINER) {
2683  weight = (signed long)(weight*(100-op->stats.Str)/100);
2684  }
2685  op->carrying += weight;
2686  op = op->env;
2687  }
2688 }
2689 
2707 object *object_insert_in_ob(object *op, object *where) {
2708  object *otmp;
2709 
2710  if (!QUERY_FLAG(op, FLAG_REMOVED)) {
2711  StringBuffer *sb;
2712  char *diff;
2713 
2714  sb = stringbuffer_new();
2715  object_dump(op, sb);
2716  diff = stringbuffer_finish(sb);
2717  LOG(llevError, "Trying to insert (ob) inserted object.\n%s\n", diff);
2718  free(diff);
2719  return op;
2720  }
2721 
2722  if (where == NULL) {
2723  StringBuffer *sb;
2724  char *diff;
2725 
2726  sb = stringbuffer_new();
2727  object_dump(op, sb);
2728  diff = stringbuffer_finish(sb);
2729  LOG(llevError, "Trying to put object in NULL.\n%s\n", diff);
2730  free(diff);
2731  return op;
2732  }
2733  if (where->head) {
2734  LOG(llevDebug, "Warning: Tried to insert object wrong part of multipart object.\n");
2735  }
2736  where = HEAD(where);
2737  if (op->more) {
2738  LOG(llevError, "Tried to insert multipart object %s (%u)\n", op->name, op->count);
2739  return op;
2740  }
2742  CLEAR_FLAG(op, FLAG_REMOVED);
2743  if (op->nrof) {
2744  FOR_INV_PREPARE(where, tmp)
2745  if (object_can_merge(tmp, op)) {
2746  /* return the original object and remove inserted object
2747  * (client needs the original object) */
2748  object_increase_nrof(tmp, op->nrof);
2749  SET_FLAG(op, FLAG_REMOVED);
2750  object_free2(op, FREE_OBJ_FREE_INVENTORY | FREE_OBJ_NO_DESTROY_CALLBACK); /* free the inserted object */
2751  return tmp;
2752  }
2753  FOR_INV_FINISH();
2754 
2755  /* the item couldn't merge. */
2756  object_add_weight(where, op->weight*op->nrof);
2757  } else
2758  object_add_weight(where, op->weight+op->carrying);
2759 
2760  op->map = NULL;
2761  op->env = where;
2762  op->above = NULL;
2763  op->below = NULL;
2764  op->x = 0,
2765  op->y = 0;
2766  op->ox = 0,
2767  op->oy = 0;
2768 
2769  /* Client has no idea of ordering so lets not bother ordering it here.
2770  * It sure simplifies this function...
2771  */
2772  if (where->inv == NULL)
2773  where->inv = op;
2774  else {
2775  op->below = where->inv;
2776  op->below->above = op;
2777  where->inv = op;
2778  }
2779 
2780  /* Update in 2 cases: object goes into player's inventory, or object goes into container the player
2781  * is looking into. */
2782  if (where->contr != NULL)
2783  esrv_send_item(where, op);
2784  else if (where->type == CONTAINER && QUERY_FLAG(where, FLAG_APPLIED)) {
2785  object *pl = NULL;
2786 
2787  if (op->env->env && op->env->env->contr)
2788  /* Container is in player's inventory. */
2789  pl = op->env->env;
2790  else if (op->env->map) {
2791  /* Container on map, look above for player. */
2792  FOR_ABOVE_PREPARE(op->env, above)
2793  if (above->contr) {
2794  pl = above;
2795  break;
2796  }
2797  FOR_ABOVE_FINISH();
2798  }
2799  if (pl)
2800  esrv_send_item(pl, op);
2801  }
2802 
2803  otmp = object_get_player_container(where);
2804  if (otmp && otmp->contr != NULL) {
2805  if (!QUERY_FLAG(otmp, FLAG_NO_FIX_PLAYER)
2806  && (QUERY_FLAG(op, FLAG_APPLIED) || op->type == SKILL || op->glow_radius != 0))
2807  /* fix_object will only consider applied items, or skills, or items with a glow radius.
2808  thus no need to call it if our object hasn't that. */
2809  fix_object(otmp);
2810  }
2811 
2812  /* reset the light list and los of the players on the map */
2813  if (op->glow_radius != 0 && where->map) {
2814 #ifdef DEBUG_LIGHTS
2815  LOG(llevDebug, " object_insert_in_ob(): got %s to insert in map/op\n", op->name);
2816 #endif /* DEBUG_LIGHTS */
2817  if (MAP_DARKNESS(where->map)) {
2818  SET_MAP_FLAGS(where->map, where->x, where->y, P_NEED_UPDATE);
2819  update_position(where->map, where->x, where->y);
2820  update_all_los(where->map, where->x, where->y);
2821  }
2822  }
2823 
2824  return op;
2825 }
2826 
2852 int object_check_move_on(object *op, object *originator) {
2853  object *tmp;
2854  tag_t tag;
2855  mapstruct *m = op->map;
2856  int x = op->x, y = op->y;
2857  MoveType move_on, move_slow, move_block;
2858 
2859  if (QUERY_FLAG(op, FLAG_NO_APPLY))
2860  return 0;
2861 
2862  tag = op->count;
2863 
2864  move_on = GET_MAP_MOVE_ON(op->map, op->x, op->y);
2865  move_slow = GET_MAP_MOVE_SLOW(op->map, op->x, op->y);
2866  move_block = GET_MAP_MOVE_BLOCK(op->map, op->x, op->y);
2867 
2868  /* if nothing on this space will slow op down or be applied,
2869  * no need to do checking below. have to make sure move_type
2870  * is set, as lots of objects don't have it set - we treat that
2871  * as walking.
2872  */
2873  if (op->move_type
2874  && !(op->move_type&move_on)
2875  && !(op->move_type&move_slow))
2876  return 0;
2877 
2878  /* This is basically inverse logic of that below - basically,
2879  * if the object can avoid the move on or slow move, they do so,
2880  * but can't do it if the alternate movement they are using is
2881  * blocked. Logic on this seems confusing, but does seem correct.
2882  */
2883  if ((op->move_type&~move_on&~move_block) != 0
2884  && (op->move_type&~move_slow&~move_block) != 0)
2885  return 0;
2886 
2887  /* The objects have to be checked from top to bottom.
2888  * Hence, we first go to the top:
2889  */
2890 
2891  tmp = GET_MAP_OB(op->map, op->x, op->y);
2893  if (tmp->above == NULL)
2894  break;
2895  /* Trim the search when we find the first other spell effect
2896  * this helps performance so that if a space has 50 spell objects,
2897  * we don't need to check all of them.
2898  */
2899  if ((tmp->move_type&MOVE_FLY_LOW) && QUERY_FLAG(tmp, FLAG_NO_PICK))
2900  break;
2903  if (tmp == op)
2904  continue; /* Can't apply yourself */
2905 
2906  /* Check to see if one of the movement types should be slowed down.
2907  * Second check makes sure that the movement types not being slowed
2908  * (~slow_move) is not blocked on this space - just because the
2909  * space doesn't slow down swimming (for example), if you can't actually
2910  * swim on that space, can't use it to avoid the penalty.
2911  */
2912  if (!QUERY_FLAG(op, FLAG_WIZPASS)) {
2913  if ((!op->move_type && tmp->move_slow&MOVE_WALK)
2914  || ((op->move_type&tmp->move_slow) && (op->move_type&~tmp->move_slow&~tmp->move_block) == 0)) {
2915  float diff;
2916 
2917  diff = tmp->move_slow_penalty*FABS(op->speed);
2918  if (op->type == PLAYER) {
2921  diff /= 4.0;
2922  }
2923  }
2924  op->speed_left -= diff;
2925  }
2926  }
2927 
2928  /* Basically same logic as above, except now for actual apply. */
2929  if ((!op->move_type && tmp->move_on&MOVE_WALK)
2930  || ((op->move_type&tmp->move_on) && (op->move_type&~tmp->move_on&~tmp->move_block) == 0)) {
2931  ob_move_on(tmp, op, originator);
2932  if (object_was_destroyed(op, tag))
2933  return 1;
2934 
2935  /* what the person/creature stepped onto has moved the object
2936  * someplace new. Don't process any further - if we did,
2937  * have a feeling strange problems would result.
2938  */
2939  if (op->map != m || op->x != x || op->y != y)
2940  return 0;
2941  }
2943  return 0;
2944 }
2945 
2961 object *map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at) {
2962  if (m == NULL || out_of_map(m, x, y)) {
2963  LOG(llevError, "Present_arch called outside map.\n");
2964  return NULL;
2965  }
2966 
2967  FOR_MAP_PREPARE(m, x, y, tmp)
2968  if (tmp->arch == at)
2969  return tmp;
2970  FOR_MAP_FINISH();
2971 
2972  return NULL;
2973 }
2974 
2991 object *map_find_by_type(mapstruct *m, int x, int y, uint8_t type) {
2992  if (out_of_map(m, x, y)) {
2993  LOG(llevError, "Present called outside map.\n");
2994  return NULL;
2995  }
2996 
2997  FOR_MAP_PREPARE(m, x, y, tmp)
2998  if (tmp->type == type)
2999  return tmp;
3000  FOR_MAP_FINISH();
3001 
3002  return NULL;
3003 }
3004 
3018 object *object_present_in_ob(uint8_t type, const object *op) {
3019  object *tmp;
3020 
3021  for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
3022  if (tmp->type == type)
3023  return tmp;
3024 
3025  return NULL;
3026 }
3027 
3056 object *object_present_in_ob_by_name(int type, const char *str, const object *op) {
3057  object *tmp;
3058 
3059  for (tmp = op->inv; tmp != NULL; tmp = tmp->below) {
3060  if ((type == -1 || tmp->type == type) && !strcmp(str, tmp->name))
3061  return tmp;
3062  }
3063  return NULL;
3064 }
3065 
3078 object *arch_present_in_ob(const archetype *at, const object *op) {
3079  object *tmp;
3080 
3081  for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
3082  if (tmp->arch == at)
3083  return tmp;
3084  return NULL;
3085 }
3086 
3098 void object_set_flag_inv(object*op, int flag) {
3099  object *tmp;
3100 
3101  for (tmp = op->inv; tmp != NULL; tmp = tmp->below) {
3102  SET_FLAG(tmp, flag);
3103  object_set_flag_inv(tmp, flag);
3104  }
3105 }
3106 
3118 void object_unset_flag_inv(object*op, int flag) {
3119  object *tmp;
3120 
3121  for (tmp = op->inv; tmp != NULL; tmp = tmp->below) {
3122  CLEAR_FLAG(tmp, flag);
3123  object_unset_flag_inv(tmp, flag);
3124  }
3125 }
3126 
3139 void object_set_cheat(object *op) {
3140  SET_FLAG(op, FLAG_WAS_WIZ);
3142 }
3143 
3164 int object_find_multi_free_spot_around(const object *ob, const object *gen, int16_t *hx, int16_t *hy) {
3165  int genx, geny, genx2, geny2, sx, sy, sx2, sy2, ix, iy, nx, ny, i, flag;
3166  int freecount = 0;
3167 
3168  ob = HEAD(ob);
3169 
3170  object_get_multi_size(ob, &sx, &sy, &sx2, &sy2);
3171  object_get_multi_size(gen, &genx, &geny, &genx2, &geny2);
3172  /*
3173  * sx and sy are now the coords of the bottom right corner of ob relative to the head.
3174  * genx and geny are now the coords of the bottom right corner of gen relative to the head.
3175  * sx2 and sy2 are now the coords of the head of ob relative to the top left corner.
3176  * genx2 and geny2 are now the coords of the head of gen relative to the top left corner.
3177  */
3178 
3179  sx++;
3180  sy++;
3181  genx++;
3182  geny++;
3183  /*
3184  * sx, sy, genx, and geny, are now the size of the object, excluding parts left and above
3185  * the head.
3186  */
3187 
3188  ix = gen->x-sx-genx2;
3189  iy = gen->y-sy-geny2;
3190  sx += genx+sx2;
3191  sy += geny+sy2;
3192  /*
3193  * ix and iy are the map coords of the top left square where the head of ob could possibly
3194  * be placed. sx and sy are now the size of the square to search for placement of the head
3195  * relative to ix and iy.
3196  */
3197 
3198  /*
3199  * Loop around the square of possible positions for the head of ob object:
3200  */
3201  for (i = 0; i < (sx+sx+sy+sy); i++) {
3202  if (i <= sx) {
3203  nx = i+ix;
3204  ny = iy;
3205  } else if (i <= sx+sy) {
3206  nx = ix+sx;
3207  ny = iy+i-sx;
3208  } else if (i <= sx+sy+sx) {
3209  nx = ix+sx-(i-(sx+sy));
3210  ny = iy+sy;
3211  } else {
3212  nx = ix;
3213  ny = iy+sy-(i-(sx+sy+sx));
3214  }
3215  /* Check if the spot is free. */
3216  flag = ob_blocked(ob, gen->map, nx, ny);
3217  if (!flag) {
3218  freecount++;
3219  }
3220  }
3221  /* If no free spaces, return. */
3222  if (!freecount)
3223  return -1;
3224 
3225  /* Choose a random valid position */
3226  freecount = RANDOM()%freecount;
3227  for (i = 0; i < sx+sx+sy+sy; i++) {
3228  if (i <= sx) {
3229  nx = i+ix;
3230  ny = iy;
3231  } else if (i <= sx+sy) {
3232  nx = ix+sx;
3233  ny = iy+i-sx;
3234  } else if (i <= sx+sy+sx) {
3235  nx = ix+sx-(i-(sx+sy));
3236  ny = iy+sy;
3237  } else {
3238  nx = ix;
3239  ny = iy+sy-(i-(sx+sy+sx));
3240  }
3241 
3242  /* Make sure it's within map. */
3243  if (nx < 0 || nx >= MAP_WIDTH(gen->map)
3244  || ny < 0 || ny >= MAP_HEIGHT(gen->map))
3245  continue;
3246 
3247  /* Check if the spot is free.*/
3248  flag = ob_blocked(ob, gen->map, nx, ny);
3249  if (!flag) {
3250  freecount--;
3251  if (freecount <= 0) {
3252  *hx = nx;
3253  *hy = ny;
3254  return 0;
3255  }
3256  }
3257  }
3258  return -1;
3259 }
3260 
3283 int object_find_multi_free_spot_within_radius(const object *ob, const object *gen, int *hx, int *hy) {
3284  int genx, geny, genx2, geny2, sx, sy, sx2, sy2, ix, iy, nx, ny, i, flag;
3285  int8_t x, y, radius;
3286  int freecount = 0, freecountstop = 0;
3287  const char *value;
3288  int8_t *x_array;
3289  int8_t *y_array;
3290 
3291  /* If radius is not set, default to 1 */
3292  value = object_get_value(gen, "generator_radius");
3293  if (value) {
3294  radius = (int8_t)strtol(value, NULL, 10);
3295  if (radius < 1) {
3296  radius = 1;
3297  }
3298  } else {
3299  radius = 1;
3300  }
3301 
3302  ob = HEAD(ob);
3303 
3304  object_get_multi_size(ob, &sx, &sy, &sx2, &sy2);
3305  object_get_multi_size(gen, &genx, &geny, &genx2, &geny2);
3306  /*
3307  * sx and sy are now the coords of the bottom right corner
3308  * of ob relative to the head.
3309  * genx and geny are now the coords of the bottom right corner
3310  * of gen relative to the head.
3311  * sx2 and sy2 are now the coords of the head of ob relative
3312  * to the top left corner.
3313  * genx2 and geny2 are now the coords of the head of gen relative
3314  * to the top left corner.
3315  */
3316 
3317  sx++;
3318  sy++;
3319  genx++;
3320  geny++;
3321  /*
3322  * sx, sy, genx, and geny, are now the size of the object,
3323  * excluding parts left and above the head.
3324  */
3325 
3326  ix = gen->x-sx-genx2-radius+1;
3327  iy = gen->y-sy-geny2-radius+1;
3328  sx += genx+sx2+radius*2-1;
3329  sy += geny+sy2+radius*2-1;
3330 
3331  /*
3332  * ix and iy are the map coords of the top left square where
3333  * the head of ob could possibly be placed. sx and sy are now
3334  * the size of the square to search for placement of the head
3335  * relative to ix and iy.
3336  */
3337 
3338  /* Create arrays large enough to hold free space coordinates */
3339  x_array = malloc(sx*sy*sizeof(int8_t));
3340  y_array = malloc(sx*sy*sizeof(int8_t));
3341 
3342  /*
3343  * Loop through the area of possible positions for the head of ob object:
3344  */
3345  for (x = 0; x < sx; x++) {
3346  for (y = 0; y < sy; y++) {
3347  nx = ix+x;
3348  ny = iy+y;
3349 
3350 
3351  /* Make sure it's within map. */
3352  if (get_map_flags(gen->map, NULL, nx, ny, NULL, NULL)&P_OUT_OF_MAP) {
3353  continue;
3354  }
3355 
3356  /* Check if the spot is free. */
3357  flag = ob_blocked(ob, gen->map, nx, ny);
3358  if (!flag) {
3359  x_array[freecount] = nx;
3360  y_array[freecount] = ny;
3361  freecount++;
3362  }
3363  }
3364  }
3365  /* If no free spaces, return. */
3366  if (!freecount) {
3367  free(x_array);
3368  free(y_array);
3369  return -1;
3370  }
3371 
3372  /* Choose a random valid position */
3373  freecountstop = RANDOM()%freecount;
3374  for (i = 0; i < freecount; i++) {
3375  nx = x_array[i];
3376  ny = y_array[i];
3377 
3378  /* Check if the spot is free.*/
3379  flag = ob_blocked(ob, gen->map, nx, ny);
3380  if (!flag) {
3381  freecountstop--;
3382  if (freecountstop <= 0) {
3383  *hx = nx;
3384  *hy = ny;
3385  free(x_array);
3386  free(y_array);
3387  return 0;
3388  }
3389  }
3390  }
3391  free(x_array);
3392  free(y_array);
3393  return -1;
3394 }
3395 
3432 int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop) {
3433  int i, index = 0, flag;
3434  static int altern[SIZEOFFREE];
3435 
3436  for (i = start; i < stop; i++) {
3437  flag = ob_blocked(ob, m, x+freearr_x[i], y+freearr_y[i]);
3438  if (!flag)
3439  altern[index++] = i;
3440 
3441  /* Basically, if we find a wall on a space, we cut down the search size.
3442  * In this way, we won't return spaces that are on another side of a wall.
3443  * This mostly work, but it cuts down the search size in all directions -
3444  * if the space being examined only has a wall to the north and empty
3445  * spaces in all the other directions, this will reduce the search space
3446  * to only the spaces immediately surrounding the target area, and
3447  * won't look 2 spaces south of the target space.
3448  */
3449  else if ((flag&AB_NO_PASS) && maxfree[i] < stop)
3450  stop = maxfree[i];
3451  }
3452  if (!index)
3453  return -1;
3454  return altern[RANDOM()%index];
3455 }
3456 
3475 int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y) {
3476  int i;
3477 
3478  for (i = 0; i < SIZEOFFREE; i++) {
3479  if (!ob_blocked(ob, m, x+freearr_x[i], y+freearr_y[i]))
3480  return i;
3481  }
3482  return -1;
3483 }
3484 
3494 static void permute(int *arr, int begin, int end) {
3495  int i, j, tmp, len;
3496 
3497  len = end-begin;
3498  for (i = begin; i < end; i++) {
3499  j = begin+RANDOM()%len;
3500 
3501  tmp = arr[i];
3502  arr[i] = arr[j];
3503  arr[j] = tmp;
3504  }
3505 }
3506 
3518 void get_search_arr(int *search_arr) {
3519  int i;
3520 
3521  for (i = 0; i < SIZEOFFREE; i++) {
3522  search_arr[i] = i;
3523  }
3524 
3525  permute(search_arr, 1, SIZEOFFREE1+1);
3526  permute(search_arr, SIZEOFFREE1+1, SIZEOFFREE2+1);
3527  permute(search_arr, SIZEOFFREE2+1, SIZEOFFREE);
3528 }
3529 
3551 int map_find_dir(mapstruct *m, int x, int y, object *exclude) {
3552  int i, max = SIZEOFFREE, mflags;
3553  int16_t nx, ny;
3554  mapstruct *mp;
3555  MoveType blocked, move_type;
3556 
3557  if (exclude && exclude->head) {
3558  exclude = exclude->head;
3559  move_type = exclude->move_type;
3560  } else {
3561  /* If we don't have anything, presume it can use all movement types. */
3562  move_type = MOVE_ALL;
3563  }
3564 
3565  for (i = 1; i < max; i++) {
3566  mp = m;
3567  nx = x+freearr_x[i];
3568  ny = y+freearr_y[i];
3569 
3570  mflags = get_map_flags(m, &mp, nx, ny, &nx, &ny);
3571  if (mflags&P_OUT_OF_MAP) {
3572  max = maxfree[i];
3573  } else {
3574  blocked = GET_MAP_MOVE_BLOCK(mp, nx, ny);
3575 
3576  if ((move_type&blocked) == move_type) {
3577  max = maxfree[i];
3578  } else if (mflags&P_IS_ALIVE) {
3579  FOR_MAP_PREPARE(mp, nx, ny, tmp) {
3580  if ((QUERY_FLAG(tmp, FLAG_MONSTER) || tmp->type == PLAYER)
3581  && (tmp != exclude || (tmp->head && tmp->head != exclude))) {
3582  return freedir[i];
3583  }
3584  } FOR_MAP_FINISH();
3585  }
3586  }
3587  }
3588  return 0;
3589 }
3590 
3601 int object_distance(const object *ob1, const object *ob2) {
3602  int i;
3603 
3604  i = (ob1->x-ob2->x)*(ob1->x-ob2->x)+
3605  (ob1->y-ob2->y)*(ob1->y-ob2->y);
3606  return i;
3607 }
3608 
3617 int find_dir_2(int x, int y) {
3618  int q;
3619 
3620  if (!y)
3621  q = -300*x;
3622  else
3623  q = x*100/y;
3624  if (y > 0) {
3625  if (q < -242)
3626  return 3;
3627  if (q < -41)
3628  return 2;
3629  if (q < 41)
3630  return 1;
3631  if (q < 242)
3632  return 8;
3633  return 7;
3634  }
3635  if (q < -242)
3636  return 7;
3637  if (q < -41)
3638  return 6;
3639  if (q < 41)
3640  return 5;
3641  if (q < 242)
3642  return 4;
3643  return 3;
3644 }
3645 
3654 int absdir(int d) {
3655  // Shortcut for modulus that work becuase we have a power of 2
3656  d &= 7;
3657  // 0 needs to be 8
3658  if (!d)
3659  d = 8;
3660  return d;
3661 }
3662 
3672 int dirdiff(int dir1, int dir2) {
3673  int d;
3674 
3675  d = abs(dir1-dir2);
3676  if (d > 4)
3677  d = 8-d;
3678  return d;
3679 }
3680 
3692 static const int reduction_dir[SIZEOFFREE][3] = {
3693  { 0, 0, 0 }, /* 0 */
3694  { 0, 0, 0 }, /* 1 */
3695  { 0, 0, 0 }, /* 2 */
3696  { 0, 0, 0 }, /* 3 */
3697  { 0, 0, 0 }, /* 4 */
3698  { 0, 0, 0 }, /* 5 */
3699  { 0, 0, 0 }, /* 6 */
3700  { 0, 0, 0 }, /* 7 */
3701  { 0, 0, 0 }, /* 8 */
3702  { 8, 1, 2 }, /* 9 */
3703  { 1, 2, -1 }, /* 10 */
3704  { 2, 10, 12 }, /* 11 */
3705  { 2, 3, -1 }, /* 12 */
3706  { 2, 3, 4 }, /* 13 */
3707  { 3, 4, -1 }, /* 14 */
3708  { 4, 14, 16 }, /* 15 */
3709  { 5, 4, -1 }, /* 16 */
3710  { 4, 5, 6 }, /* 17 */
3711  { 6, 5, -1 }, /* 18 */
3712  { 6, 20, 18 }, /* 19 */
3713  { 7, 6, -1 }, /* 20 */
3714  { 6, 7, 8 }, /* 21 */
3715  { 7, 8, -1 }, /* 22 */
3716  { 8, 22, 24 }, /* 23 */
3717  { 8, 1, -1 }, /* 24 */
3718  { 24, 9, 10 }, /* 25 */
3719  { 9, 10, -1 }, /* 26 */
3720  { 10, 11, -1 }, /* 27 */
3721  { 27, 11, 29 }, /* 28 */
3722  { 11, 12, -1 }, /* 29 */
3723  { 12, 13, -1 }, /* 30 */
3724  { 12, 13, 14 }, /* 31 */
3725  { 13, 14, -1 }, /* 32 */
3726  { 14, 15, -1 }, /* 33 */
3727  { 33, 15, 35 }, /* 34 */
3728  { 16, 15, -1 }, /* 35 */
3729  { 17, 16, -1 }, /* 36 */
3730  { 18, 17, 16 }, /* 37 */
3731  { 18, 17, -1 }, /* 38 */
3732  { 18, 19, -1 }, /* 39 */
3733  { 41, 19, 39 }, /* 40 */
3734  { 19, 20, -1 }, /* 41 */
3735  { 20, 21, -1 }, /* 42 */
3736  { 20, 21, 22 }, /* 43 */
3737  { 21, 22, -1 }, /* 44 */
3738  { 23, 22, -1 }, /* 45 */
3739  { 45, 47, 23 }, /* 46 */
3740  { 23, 24, -1 }, /* 47 */
3741  { 24, 9, -1 } /* 48 */
3742 };
3743 
3762 int can_see_monsterP(mapstruct *m, int x, int y, int dir) {
3763  int16_t dx, dy;
3764  int mflags;
3765 
3766  if (dir < 0)
3767  return 0; /* exit condition: invalid direction */
3768 
3769  dx = x+freearr_x[dir];
3770  dy = y+freearr_y[dir];
3771 
3772  mflags = get_map_flags(m, &m, dx, dy, &dx, &dy);
3773 
3774  /* This functional arguably was incorrect before - it was
3775  * checking for P_WALL - that was basically seeing if
3776  * we could move to the monster - this is being more
3777  * literal on if we can see it. To know if we can actually
3778  * move to the monster, we'd need the monster passed in or
3779  * at least its move type.
3780  */
3781  if (mflags&(P_OUT_OF_MAP|P_BLOCKSVIEW))
3782  return 0;
3783 
3784  /* yes, can see. */
3785  if (dir < 9)
3786  return 1;
3787  return can_see_monsterP(m, x, y, reduction_dir[dir][0])|
3788  can_see_monsterP(m, x, y, reduction_dir[dir][1])|
3789  can_see_monsterP(m, x, y, reduction_dir[dir][2]);
3790 }
3791 
3810 int object_can_pick(const object *who, const object *item) {
3811  /* I re-wrote this as a series of if statements
3812  * instead of a nested return (foo & bar && yaz)
3813  * - I think this is much more readable,
3814  * and likely compiler effectively optimizes it the
3815  * same.
3816  */
3817  if (item->weight <= 0)
3818  return 0;
3819  if (QUERY_FLAG(item, FLAG_NO_PICK))
3820  return 0;
3821  if (QUERY_FLAG(item, FLAG_ALIVE))
3822  return 0;
3823  if (item->invisible)
3824  return 0;
3825  if (item->type == TRANSPORT && item->contr != NULL) {
3826  return 0;
3827  }
3828 
3829  /* Weight limit for monsters */
3830  if (who->type != PLAYER && ((uint32_t)(who->weight+who->carrying+item->weight)) > get_weight_limit(who->stats.Str))
3831  return 0;
3832 
3833  /* Can not pick up multipart objects */
3834  if (item->head || item->more)
3835  return 0;
3836 
3837  /* Everything passes, so OK to pick up */
3838  return 1;
3839 }
3840 
3852 object *object_create_clone(object *asrc) {
3853  object *dst = NULL, *tmp, *src, *part, *prev;
3854 
3855  if (!asrc)
3856  return NULL;
3857  src = HEAD(asrc);
3858 
3859  prev = NULL;
3860  for (part = src; part; part = part->more) {
3861  tmp = object_new();
3862  object_copy(part, tmp);
3863  /*
3864  * Need to reset the weight, since object_insert_in_ob() later will
3865  * recompute this field.
3866  */
3867  tmp->carrying = tmp->arch->clone.carrying;
3868  tmp->x -= src->x;
3869  tmp->y -= src->y;
3870  if (!part->head) {
3871  dst = tmp;
3872  tmp->head = NULL;
3873  } else {
3874  tmp->head = dst;
3875  }
3876  tmp->more = NULL;
3877  if (prev)
3878  prev->more = tmp;
3879  prev = tmp;
3880  }
3881  /*** copy inventory ***/
3882  FOR_INV_PREPARE(src, item)
3883  (void)object_insert_in_ob(object_create_clone(item), dst);
3884  FOR_INV_FINISH();
3885 
3886  return dst;
3887 }
3888 
3899 object *object_find_by_name(const object *who, const char *name) {
3900  const char *name_shared = add_string(name);
3901  object *tmp;
3902 
3903  for (tmp = who->inv; tmp; tmp = tmp->below)
3904  if (tmp->name == name_shared)
3905  break;
3906  free_string(name_shared);
3907  return tmp;
3908 }
3909 
3923 object *object_find_by_type(const object *who, int type) {
3924  object *tmp;
3925 
3926  for (tmp = who->inv; tmp; tmp = tmp->below)
3927  if (tmp->type == type)
3928  return tmp;
3929 
3930  return NULL;
3931 }
3932 
3948 object *object_find_by_type2(const object *who, int type1, int type2) {
3949  object *tmp;
3950 
3951  for (tmp = who->inv; tmp; tmp = tmp->below)
3952  if (tmp->type == type1 || tmp->type == type2)
3953  return tmp;
3954 
3955  return NULL;
3956 }
3957 
3971 object *object_find_by_tag(const object *who, tag_t tag) {
3972  object *tmp;
3973 
3974  for (tmp = who->inv; tmp; tmp = tmp->below)
3975  if (tmp->count == tag)
3976  return tmp;
3977 
3978  return NULL;
3979 }
3980 
3994 object *object_find_by_type_applied(const object *who, int type) {
3995  object *tmp;
3996 
3997  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
3998  if (tmp->type == type && QUERY_FLAG(tmp, FLAG_APPLIED))
3999  return tmp;
4000 
4001  return NULL;
4002 }
4003 
4019 object *object_find_by_type_and_name(const object *who, int type, const char *name) {
4020  object *tmp;
4021 
4022  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4023  if (tmp->type == type && strcmp(tmp->name, name) == 0)
4024  return tmp;
4025 
4026  return NULL;
4027 }
4028 
4044 object *object_find_by_type_and_race(const object *who, int type, const char *race) {
4045  object *tmp;
4046 
4047  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4048  if (tmp->type == type && strcmp(tmp->race, race) == 0)
4049  return tmp;
4050 
4051  return NULL;
4052 }
4053 
4069 object *object_find_by_type_and_slaying(const object *who, int type, const char *slaying) {
4070  object *tmp;
4071 
4072  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4073  if (tmp->type == type && tmp->slaying != NULL && strcmp(tmp->slaying, slaying) == 0)
4074  return tmp;
4075 
4076  return NULL;
4077 }
4078 
4094 object *object_find_by_type_and_skill(const object *who, int type, const char *skill) {
4095  object *tmp;
4096 
4097  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4098  if (tmp->type == SKILL && tmp->skill != NULL && strcmp(tmp->skill, skill) == 0)
4099  return tmp;
4100 
4101  return NULL;
4102 }
4103 
4117 object *object_find_by_flag(const object *who, int flag) {
4118  object *tmp;
4119 
4120  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4121  if (QUERY_FLAG(tmp, flag))
4122  return tmp;
4123 
4124  return NULL;
4125 }
4126 
4140 object *object_find_by_flag_applied(const object *who, int flag) {
4141  object *tmp;
4142 
4143  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4144  if (QUERY_FLAG(tmp, FLAG_APPLIED) && QUERY_FLAG(tmp, flag))
4145  return tmp;
4146 
4147  return NULL;
4148 }
4149 
4163 object *object_find_by_arch_name(const object *who, const char *name) {
4164  object *tmp;
4165 
4166  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4167  if (strcmp(tmp->arch->name, name) == 0)
4168  return tmp;
4169 
4170  return NULL;
4171 }
4172 
4188 object *object_find_by_type_and_arch_name(const object *who, int type, const char *name) {
4189  object *tmp;
4190 
4191  for (tmp = who->inv; tmp != NULL; tmp = tmp->below)
4192  if (tmp->type == type && strcmp(tmp->arch->name, name) == 0)
4193  return tmp;
4194 
4195  return NULL;
4196 }
4197 
4215 object *object_find_by_type_subtype(const object *who, int type, int subtype) {
4216  object *tmp;
4217 
4218  for (tmp = who->inv; tmp; tmp = tmp->below)
4219  if (tmp->type == type && tmp->subtype == subtype)
4220  return tmp;
4221 
4222  return NULL;
4223 }
4224 
4238 key_value *object_get_key_value(const object *ob, const char *key) {
4239  key_value *link;
4240 
4241  for (link = ob->key_values; link != NULL; link = link->next) {
4242  if (link->key == key) {
4243  return link;
4244  }
4245  }
4246 
4247  return NULL;
4248 }
4249 
4266 const char *object_get_value(const object *op, const char *const key) {
4267  key_value *link;
4268  const char *canonical_key;
4269 
4270  canonical_key = find_string(key);
4271 
4272  if (canonical_key == NULL) {
4273  /* 1. There being a field named key on any object
4274  * implies there'd be a shared string to find.
4275  * 2. Since there isn't, no object has this field.
4276  * 3. Therefore, *this *object doesn't have this field.
4277  */
4278  return NULL;
4279  }
4280 
4281  /* This is copied from object_get_key_value() above -
4282  * only 4 lines, and saves the function call overhead.
4283  */
4284  for (link = op->key_values; link != NULL; link = link->next) {
4285  if (link->key == canonical_key) {
4286  return link->value;
4287  }
4288  }
4289  return NULL;
4290 }
4291 
4309 static int object_set_value_s(object *op, const char *canonical_key, const char *value, int add_key) {
4310  key_value *field = NULL, *last = NULL;
4311 
4312  for (field = op->key_values; field != NULL; field = field->next) {
4313  if (field->key != canonical_key) {
4314  last = field;
4315  continue;
4316  }
4317 
4318  if (field->value)
4319  FREE_AND_CLEAR_STR(field->value);
4320  if (value)
4321  field->value = add_string(value);
4322  else {
4323  /* Basically, if the archetype has this key set,
4324  * we need to store the null value so when we save
4325  * it, we save the empty value so that when we load,
4326  * we get this value back again.
4327  */
4328  if (object_get_key_value(&op->arch->clone, canonical_key))
4329  field->value = NULL;
4330  else {
4331  /* Delete this link */
4332  if (field->key)
4333  FREE_AND_CLEAR_STR(field->key);
4334  if (field->value)
4335  FREE_AND_CLEAR_STR(field->value);
4336  if (last)
4337  last->next = field->next;
4338  else
4339  op->key_values = field->next;
4340  free(field);
4341  }
4342  }
4343  return TRUE;
4344  }
4345  /* IF we get here, key doesn't exist */
4346 
4347  /* No field, we'll have to add it. */
4348 
4349  if (!add_key) {
4350  return FALSE;
4351  }
4352  /* There isn't any good reason to store a null
4353  * value in the key/value list. If the archetype has
4354  * this key, then we should also have it, so shouldn't
4355  * be here. If user wants to store empty strings,
4356  * should pass in ""
4357  */
4358  if (value == NULL)
4359  return TRUE;
4360 
4361  field = malloc(sizeof(key_value));
4362 
4363  field->key = add_refcount(canonical_key);
4364  field->value = add_string(value);
4365  /* Usual prepend-addition. */
4366  field->next = op->key_values;
4367  op->key_values = field;
4368 
4369  return TRUE;
4370 }
4371 
4395 int object_set_value(object *op, const char *key, const char *value, int add_key) {
4396  const char *canonical_key = NULL;
4397  int floating_ref = FALSE;
4398  int ret;
4399 
4400  /* HACK This mess is to make sure set_ob_value() passes a shared string
4401  * to object_get_key_value(), without leaving a leaked refcount.
4402  */
4403 
4404  canonical_key = find_string(key);
4405  if (canonical_key == NULL) {
4406  canonical_key = add_string(key);
4407  floating_ref = TRUE;
4408  }
4409 
4410  ret = object_set_value_s(op, canonical_key, value, add_key);
4411 
4412  if (floating_ref) {
4413  free_string(canonical_key);
4414  }
4415 
4416  return ret;
4417 }
4418 
4473 int object_matches_string(object *pl, object *op, const char *name) {
4474  char *cp, local_name[MAX_BUF], name_op[MAX_BUF], name_short[HUGE_BUF], bname_s[MAX_BUF], bname_p[MAX_BUF];
4475  int count, retval = 0;
4476  /* strtok is destructive to name */
4477  safe_strncpy(local_name, name, sizeof(local_name));
4478 
4479  for (cp = strtok(local_name, ","); cp; cp = strtok(NULL, ",")) {
4480  while (cp[0] == ' ')
4481  ++cp; /* get rid of spaces */
4482 
4483  /* LOG(llevDebug, "Trying to match %s\n", cp);*/
4484  /* All is a very generic match - low match value */
4485  if (!strcmp(cp, "all"))
4486  return 1;
4487 
4488  /* unpaid is a little more specific */
4489  if (!strcmp(cp, "unpaid") && QUERY_FLAG(op, FLAG_UNPAID))
4490  return 2;
4491  if (!strcmp(cp, "cursed")
4493  && (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)))
4494  return 2;
4495 
4496  if (!strcmp(cp, "unlocked") && !QUERY_FLAG(op, FLAG_INV_LOCKED))
4497  return 2;
4498 
4499  /* Allow for things like '100 arrows' */
4500  count = atoi(cp);
4501  if (count != 0) {
4502  cp = strchr(cp, ' ');
4503  while (cp && cp[0] == ' ')
4504  ++cp; /* get rid of spaces */
4505  } else {
4506  if (pl->type == PLAYER)
4507  count = pl->contr->count;
4508  else
4509  count = 0;
4510  }
4511 
4512  if (!cp || cp[0] == '\0' || count < 0)
4513  return 0;
4514 
4515  /* The code here should go from highest retval to lowest. That
4516  * is because of the 'else' handling - we don't want to match on
4517  * something and set a low retval, even though it may match a higher retcal
4518  * later. So keep it in descending order here, so we try for the best
4519  * match first, and work downward.
4520  */
4521  query_name(op, name_op, MAX_BUF);
4522  query_short_name(op, name_short, HUGE_BUF);
4523  query_base_name(op, 0, bname_s, MAX_BUF);
4524  query_base_name(op, 1, bname_p, MAX_BUF);
4525 
4526  if (!strcasecmp(cp, name_op))
4527  retval = 20;
4528  else if (!strcasecmp(cp, name_short))
4529  retval = 18;
4530  else if (!strcasecmp(cp, bname_s))
4531  retval = 16;
4532  else if (!strcasecmp(cp, bname_p))
4533  retval = 16;
4534  else if (op->custom_name && !strcasecmp(cp, op->custom_name))
4535  retval = 15;
4536  else if (!strncasecmp(cp, bname_s, strlen(cp)))
4537  retval = 14;
4538  else if (!strncasecmp(cp, bname_p, strlen(cp)))
4539  retval = 14;
4540  /* Do substring checks, so things like 'Str+1' will match.
4541  * retval of these should perhaps be lower - they are lower
4542  * then the specific strcasecmp aboves, but still higher than
4543  * some other match criteria.
4544  */
4545  else if (strstr(bname_p, cp))
4546  retval = 12;
4547  else if (strstr(bname_s, cp))
4548  retval = 12;
4549  else if (strstr(name_short, cp))
4550  retval = 12;
4551  /* Check against plural/non plural based on count. */
4552  else if (count > 1 && !strcasecmp(cp, op->name_pl)) {
4553  retval = 6;
4554  } else if (count == 1 && !strcasecmp(op->name, cp)) {
4555  retval = 6;
4556  }
4557  /* base name matched - not bad */
4558  else if (strcasecmp(cp, op->name) == 0 && !count)
4559  retval = 4;
4560  /* Check for partial custom name, but give a real low priority */
4561  else if (op->custom_name && strstr(op->custom_name, cp))
4562  retval = 3;
4563 
4564  if (retval) {
4565  if (pl->type == PLAYER)
4566  pl->contr->count = count;
4567  return retval;
4568  }
4569  }
4570  return 0;
4571 }
4572 
4584 void object_fix_multipart(object *tmp) {
4585  archetype *at;
4586  object *op, *last;
4587 
4588  if (!tmp->map) {
4589  LOG(llevError, "object_fix_multipart: not on a map!\n");
4590  return;
4591  }
4592 
4593  /* already multipart - don't do anything more */
4594  if (tmp->head || tmp->more)
4595  return;
4596 
4597  /* If there is nothing more to this object, this for loop
4598  * won't do anything.
4599  */
4600  for (at = tmp->arch->more, last = tmp; at != NULL; at = at->more, last = op) {
4601  op = arch_to_object(at);
4602 
4603  /* update x,y coordinates */
4604  op->x += tmp->x;
4605  op->y += tmp->y;
4606  op->head = tmp;
4607  op->map = tmp->map;
4608  last->more = op;
4609  if (tmp->name != op->name) {
4610  if (op->name)
4611  free_string(op->name);
4612  op->name = add_string(tmp->name);
4613  }
4614  if (tmp->title != op->title) {
4615  if (op->title)
4616  free_string(op->title);
4617  op->title = add_string(tmp->title);
4618  }
4619  /* we could link all the parts onto tmp, and then just
4620  * call object_insert_in_map once, but the effect is the same,
4621  * as object_insert_in_map will call itself with each part, and
4622  * the coding is simpler to just to it here with each part.
4623  */
4625  } /* for at = tmp->arch->more */
4626 }
4627 
4646 void object_get_multi_size(const object *ob, int *sx, int *sy, int *hx, int *hy) {
4647  archetype *part;
4648  int maxx = 0, maxy = 0, minx = 0, miny = 0;
4649 
4650  ob = HEAD(ob);
4651  *sx = 1;
4652  *sy = 1;
4653  if (ob->arch->more) {
4654  for (part = ob->arch; part; part = part->more) {
4655  if (part->clone.x > maxx)
4656  maxx = part->clone.x;
4657  if (part->clone.y > maxy)
4658  maxy = part->clone.y;
4659  if (part->clone.x < minx)
4660  minx = part->clone.x;
4661  if (part->clone.y < miny)
4662  miny = part->clone.y;
4663  }
4664  }
4665  if (sx)
4666  *sx = maxx;
4667  if (sy)
4668  *sy = maxy;
4669  if (hx)
4670  *hx = -minx;
4671  if (hy)
4672  *hy = -miny;
4673 }
4674 
4695 void object_insert_to_free_spot_or_free(object *op, mapstruct *map, int x, int y, int start, int stop, object *originator) {
4696  int pos;
4697 
4698  pos = object_find_free_spot(op, map, x, y, start, stop);
4699  if (pos == -1) {
4701  return;
4702  }
4703 
4704  object_insert_in_map_at(op, map, originator, 0, x+freearr_x[pos], y+freearr_y[pos]);
4705 }
4706 
4715 void object_set_msg(object *op, const char *msg) {
4716  if (op->msg != NULL) {
4717  free_string(op->msg);
4718  }
4719 
4720  if (msg != NULL) {
4721  // If the message does not have a trailing newline, add one.
4722  if (*msg != '\0' && strchr(msg, '\0')[-1] != '\n') {
4724  stringbuffer_append_string(sb, msg);
4725  stringbuffer_append_string(sb, "\n");
4726  op->msg = stringbuffer_finish_shared(sb);
4727  } else {
4728  op->msg = add_string(msg);
4729  }
4730  } else {
4731  op->msg = NULL;
4732  }
4733 }
4734 
4736 const char *const move_name[] = {
4737  "walk",
4738  "fly_low",
4739  "fly_high",
4740  "swim",
4741  "boat",
4742  NULL
4743 };
4744 
4745 /* This array equates the FLAG_ values with the V_ values. Use -1 to
4746  * put gaps in the array that should not be processed.
4747  * The order matches the order of the define values in 'define.h'.
4748  */
4755 static const char *const flag_names[NUM_FLAGS+1] = {
4756  "alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid",
4757  "can_use_shield", "no_pick", "client_anim_sync", "client_anim_random", /* 10 */
4758  "is_animated", NULL /* FLAG_DIALOG_PARSED, not saved */,
4759  NULL /* flying */, "monster", "friendly", "generator",
4760  "is_thrown", "auto_apply", "treasure", "player sold", /* 20 */
4761  "see_invisible", "can_roll", "overlay_floor",
4762  "is_turnable", NULL /* walk_off */, NULL /* fly_on */,
4763  NULL /*fly_off*/, "is_used_up", "identified", "reflecting", /* 30 */
4764  "changing", "splitting", "hitback", "startequip",
4765  "blocksview", "undead", "scared", "unaggressive",
4766  "reflect_missile", "reflect_spell", /* 40 */
4767  "no_magic", "no_fix_player", "is_lightable", "tear_down",
4768  "run_away", NULL /*pass_thru */, NULL /*can_pass_thru*/,
4769  NULL /*"pick_up"*/, "unique", "no_drop", /* 50 */
4770  NULL /* wizcast*/, "can_cast_spell", "can_use_scroll", "can_use_range",
4771  "can_use_bow", "can_use_armour", "can_use_weapon",
4772  "can_use_ring", "has_ready_range", "has_ready_bow", /* 60 */
4773  "xrays", NULL, "is_floor", "lifesave", "no_strength", "sleep",
4774  "stand_still", "random_movement", "only_attack", "confused", /* 70 */
4775  "stealth", NULL, NULL, "cursed", "damned",
4776  "see_anywhere", "known_magical", "known_cursed",
4777  "can_use_skill", "been_applied", /* 80 */
4778  "has_ready_scroll", NULL, NULL,
4779  NULL, "make_invisible", "inv_locked", "is_wooded",
4780  "is_hilly", "has_ready_skill", "has_ready_weapon", /* 90 */
4781  "no_skill_ident", "is_blind", "can_see_in_dark", "is_cauldron",
4782  NULL, "no_steal", "one_hit", NULL, "berserk", "neutral", /* 100 */
4783  "no_attack", "no_damage", NULL, NULL, "activate_on_push",
4784  "activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */
4785  NULL, "blessed", "known_blessed"
4786 };
4787 
4797 {
4798  static char retbuf[MAX_BUF], retbuf_all[MAX_BUF];
4799  int i, all_count = 0, count;
4800 
4801  strcpy(retbuf, "");
4802  strcpy(retbuf_all, " all");
4803 
4804  /* Quick check, and probably fairly common */
4805  if (mt == MOVE_ALL) {
4806  stringbuffer_append_string(sb, "all");
4807  return;
4808  }
4809  if (mt == 0) {
4810  stringbuffer_append_string(sb, "0");
4811  return;
4812  }
4813 
4814  /* We basically slide the bits down. Why look at MOVE_ALL?
4815  * because we may want to return a string like 'all -swim',
4816  * and if we just looked at mt, we couldn't get that.
4817  */
4818  for (i = MOVE_ALL, count = 0; i != 0; i >>= 1, count++) {
4819  if (mt&(1<<count)) {
4820  strcat(retbuf, " ");
4821  strcat(retbuf, move_name[count]);
4822  } else {
4823  strcat(retbuf_all, " -");
4824  strcat(retbuf_all, move_name[count]);
4825  all_count++;
4826  }
4827  }
4828  /* Basically, if there is a single negation, return it, eg
4829  * 'all -swim'. But more than that, just return the
4830  * enumerated values. It doesn't make sense to return
4831  * 'all -walk -fly_low' - it is shorter to return 'fly_high swim'
4832  */
4833  if (all_count <= 1)
4834  stringbuffer_append_string(sb, retbuf_all+1);
4835  else
4836  stringbuffer_append_string(sb, retbuf+1);
4837 }
4838 
4840 #define ADD_STRINGLINE_ENTRY(sb__, entryname__, entryvalue__) do {\
4841  stringbuffer_append_string(sb__, entryname__);\
4842  stringbuffer_append_string(sb__, entryvalue__);\
4843  stringbuffer_append_string(sb__, "\n");\
4844  } while (0)
4845 
4846 #define FAST_SAVE_LONG(sb__, entryname__, entryvalue__) \
4847  stringbuffer_append_printf(sb__, "%s%ld\n", entryname__, (long int)entryvalue__)
4848 
4849 #define FAST_SAVE_DOUBLE(sb__, entryname__, entryvalue__) \
4850  stringbuffer_append_printf(sb__, "%s%f\n", entryname__, entryvalue__)
4851 
4865 void get_ob_diff(StringBuffer *sb, const object *op, const object *op2) {
4866  static char buf2[64];
4867  int tmp;
4868  int i;
4869  key_value *my_field;
4870  key_value *arch_field;
4871 
4872  /* This saves the key/value lists. We do it first so that any
4873  * keys that match field names will be overwritten by the loader.
4874  */
4875  for (my_field = op->key_values; my_field != NULL; my_field = my_field->next) {
4876  /* Find the field in the opposing member. */
4877  arch_field = object_get_key_value(op2, my_field->key);
4878 
4879  /* If there's no partnering field, or it's got a different value, save our field. */
4880  if (arch_field == NULL || my_field->value != arch_field->value) {
4881  stringbuffer_append_string(sb, my_field->key);
4882  stringbuffer_append_string(sb, " ");
4883  /* If this is null, then saving it as a space should
4884  * cause it to be null again.
4885  */
4886  if (my_field->value)
4887  stringbuffer_append_string(sb, my_field->value);
4888  stringbuffer_append_string(sb, "\n");
4889  }
4890  }
4891  /* We don't need to worry about the arch's extra fields - they
4892  * will get taken care of the object_copy() function.
4893  */
4894 
4895  if (op->name && op->name != op2->name) {
4896  ADD_STRINGLINE_ENTRY(sb, "name ", op->name);
4897  }
4898  if (op->name_pl && op->name_pl != op2->name_pl) {
4899  ADD_STRINGLINE_ENTRY(sb, "name_pl ", op->name_pl);
4900  }
4901  if (op->anim_suffix && op->anim_suffix != op2->anim_suffix) {
4902  ADD_STRINGLINE_ENTRY(sb, "anim_suffix ", op->anim_suffix);
4903  }
4904  if (op->custom_name && op->custom_name != op2->custom_name) {
4905  ADD_STRINGLINE_ENTRY(sb, "custom_name ", op->custom_name);
4906  }
4907  if (op->title && op->title != op2->title) {
4908  ADD_STRINGLINE_ENTRY(sb, "title ", op->title);
4909  }
4910  if (op->race && op->race != op2->race) {
4911  ADD_STRINGLINE_ENTRY(sb, "race ", op->race);
4912  }
4913  if (op->slaying && op->slaying != op2->slaying) {
4914  ADD_STRINGLINE_ENTRY(sb, "slaying ", op->slaying);
4915  }
4916  if (op->skill && op->skill != op2->skill) {
4917  ADD_STRINGLINE_ENTRY(sb, "skill ", op->skill);
4918  }
4919  if (op->msg && op->msg != op2->msg) {
4920  stringbuffer_append_string(sb, "msg\n");
4922  stringbuffer_append_string(sb, "endmsg\n");
4923  }
4924  if (op->lore && op->lore != op2->lore) {
4925  stringbuffer_append_string(sb, "lore\n");
4927  stringbuffer_append_string(sb, "endlore\n");
4928  }
4929  if (op->other_arch != op2->other_arch && op->other_arch != NULL && op->other_arch->name) {
4930  ADD_STRINGLINE_ENTRY(sb, "other_arch ", op->other_arch->name);
4931  }
4932  if (op->face != op2->face) {
4933  ADD_STRINGLINE_ENTRY(sb, "face ", op->face->name);
4934  }
4935 
4936  if (op->animation_id != op2->animation_id) {
4937  if (op->animation_id) {
4938  ADD_STRINGLINE_ENTRY(sb, "animation ", animations[GET_ANIM_ID(op)].name);
4939  if (!QUERY_FLAG (op, FLAG_ANIMATE)) {
4940  stringbuffer_append_string(sb, "is_animated 0\n");
4941  }
4942  } else {
4943  stringbuffer_append_string(sb, "animation NONE\n");
4944  }
4945  }
4946  if (op->stats.Str != op2->stats.Str)
4947  FAST_SAVE_LONG(sb, "Str ", op->stats.Str);
4948  if (op->stats.Dex != op2->stats.Dex)
4949  FAST_SAVE_LONG(sb, "Dex ", op->stats.Dex);
4950  if (op->stats.Con != op2->stats.Con)
4951  FAST_SAVE_LONG(sb, "Con ", op->stats.Con);
4952  if (op->stats.Wis != op2->stats.Wis)
4953  FAST_SAVE_LONG(sb, "Wis ", op->stats.Wis);
4954  if (op->stats.Pow != op2->stats.Pow)
4955  FAST_SAVE_LONG(sb, "Pow ", op->stats.Pow);
4956  if (op->stats.Cha != op2->stats.Cha)
4957  FAST_SAVE_LONG(sb, "Cha ", op->stats.Cha);
4958  if (op->stats.Int != op2->stats.Int)
4959  FAST_SAVE_LONG(sb, "Int ", op->stats.Int);
4960  if (op->stats.hp != op2->stats.hp)
4961  FAST_SAVE_LONG(sb, "hp ", op->stats.hp);
4962  if (op->stats.maxhp != op2->stats.maxhp)
4963  FAST_SAVE_LONG(sb, "maxhp ", op->stats.maxhp);
4964  if (op->stats.sp != op2->stats.sp)
4965  FAST_SAVE_LONG(sb, "sp ", op->stats.sp);
4966  if (op->stats.maxsp != op2->stats.maxsp)
4967  FAST_SAVE_LONG(sb, "maxsp ", op->stats.maxsp);
4968  if (op->stats.grace != op2->stats.grace)
4969  FAST_SAVE_LONG(sb, "grace ", op->stats.grace);
4970  if (op->stats.maxgrace != op2->stats.maxgrace)
4971  FAST_SAVE_LONG(sb, "maxgrace ", op->stats.maxgrace);
4972 
4973  if (op->stats.exp != op2->stats.exp) {
4974  snprintf(buf2, sizeof(buf2), "%"FMT64, op->stats.exp);
4975  ADD_STRINGLINE_ENTRY(sb, "exp ", buf2);
4976  }
4977 
4978  if (op->perm_exp != op2->perm_exp) {
4979  snprintf(buf2, sizeof(buf2), "%"FMT64, op->perm_exp);
4980  ADD_STRINGLINE_ENTRY(sb, "perm_exp ", buf2);
4981  }
4982 
4983  if (op->expmul != op2->expmul)
4984  FAST_SAVE_DOUBLE(sb, "expmul ", op->expmul);
4985  if (op->stats.food != op2->stats.food)
4986  FAST_SAVE_LONG(sb, "food ", op->stats.food);
4987  if (op->stats.dam != op2->stats.dam)
4988  FAST_SAVE_LONG(sb, "dam ", op->stats.dam);
4989  if (op->stats.luck != op2->stats.luck)
4990  FAST_SAVE_LONG(sb, "luck ", op->stats.luck);
4991  if (op->stats.wc != op2->stats.wc)
4992  FAST_SAVE_LONG(sb, "wc ", op->stats.wc);
4993  if (op->stats.ac != op2->stats.ac)
4994  FAST_SAVE_LONG(sb, "ac ", op->stats.ac);
4995  if (op->x != op2->x)
4996  FAST_SAVE_LONG(sb, "x ", op->x);
4997  if (op->y != op2->y)
4998  FAST_SAVE_LONG(sb, "y ", op->y);
4999  if (op->speed != op2->speed) {
5000  FAST_SAVE_DOUBLE(sb, "speed ", op->speed);
5001  }
5002  if (op->speed > 0 && op->speed_left != op2->speed_left) {
5003  FAST_SAVE_DOUBLE(sb, "speed_left ", op->speed_left);
5004  }
5005  if (op->weapon_speed != op2->weapon_speed) {
5006  FAST_SAVE_DOUBLE(sb, "weapon_speed ", op->weapon_speed);
5007  }
5008  if (op->weapon_speed > 0 && op->weapon_speed_left != op2->weapon_speed_left) {
5009  FAST_SAVE_DOUBLE(sb, "weapon_speed_left ", op->weapon_speed_left);
5010  }
5011  if (op->move_status != op2->move_status)
5012  FAST_SAVE_LONG(sb, "move_state ", op->move_status);
5013  if (op->attack_movement != op2->attack_movement)
5014  FAST_SAVE_LONG(sb, "attack_movement ", op->attack_movement);
5015  if (op->nrof != op2->nrof)
5016  FAST_SAVE_LONG(sb, "nrof ", op->nrof);
5017  if (op->level != op2->level)
5018  FAST_SAVE_LONG(sb, "level ", op->level);
5019  if (op->direction != op2->direction)
5020  FAST_SAVE_LONG(sb, "direction ", op->direction);
5021  if (op->type != op2->type)
5022  FAST_SAVE_LONG(sb, "type ", op->type);
5023  if (op->subtype != op2->subtype)
5024  FAST_SAVE_LONG(sb, "subtype ", op->subtype);
5025  if (op->attacktype != op2->attacktype)
5026  FAST_SAVE_LONG(sb, "attacktype ", op->attacktype);
5027 
5028  for (tmp = 0; tmp < NROFATTACKS; tmp++) {
5029  if (op->resist[tmp] != op2->resist[tmp]) {
5030  stringbuffer_append_string(sb, "resist_");
5031  FAST_SAVE_LONG(sb, resist_save[tmp], op->resist[tmp]);
5032  }
5033  }
5034 
5035  if (op->path_attuned != op2->path_attuned)
5036  FAST_SAVE_LONG(sb, "path_attuned ", op->path_attuned);
5037  if (op->path_repelled != op2->path_repelled)
5038  FAST_SAVE_LONG(sb, "path_repelled ", op->path_repelled);
5039  if (op->path_denied != op2->path_denied)
5040  FAST_SAVE_LONG(sb, "path_denied ", op->path_denied);
5041  if (op->material != op2->material)
5042  FAST_SAVE_LONG(sb, "material ", op->material);
5043  if (op->materialname && op->materialname != op2->materialname) {
5044  ADD_STRINGLINE_ENTRY(sb, "materialname ", op->materialname);
5045  }
5046  if (op->value != op2->value)
5047  FAST_SAVE_LONG(sb, "value ", op->value);
5048  if (op->carrying != op2->carrying)
5049  FAST_SAVE_LONG(sb, "carrying ", op->carrying);
5050  if (op->weight != op2->weight)
5051  FAST_SAVE_LONG(sb, "weight ", op->weight);
5052  if (op->invisible != op2->invisible)
5053  FAST_SAVE_LONG(sb, "invisible ", op->invisible);
5054  if (op->state != op2->state)
5055  FAST_SAVE_LONG(sb, "state ", op->state);
5056  if (op->magic != op2->magic)
5057  FAST_SAVE_LONG(sb, "magic ", op->magic);
5058  if (op->last_heal != op2->last_heal)
5059  FAST_SAVE_LONG(sb, "last_heal ", op->last_heal);
5060  if (op->last_sp != op2->last_sp)
5061  FAST_SAVE_LONG(sb, "last_sp ", op->last_sp);
5062  if (op->last_grace != op2->last_grace)
5063  FAST_SAVE_LONG(sb, "last_grace ", op->last_grace);
5064  if (op->last_eat != op2->last_eat)
5065  FAST_SAVE_LONG(sb, "last_eat ", op->last_eat);
5066  if (QUERY_FLAG(op, FLAG_IS_LINKED) && (tmp = get_button_value(op)))
5067  FAST_SAVE_LONG(sb, "connected ", tmp);
5068  if (op->glow_radius != op2->glow_radius)
5069  FAST_SAVE_LONG(sb, "glow_radius ", op->glow_radius);
5070  if (op->randomitems != op2->randomitems) {
5071  ADD_STRINGLINE_ENTRY(sb, "randomitems ", op->randomitems ? op->randomitems->name : "none");
5072  }
5073 
5074  if (op->run_away != op2->run_away)
5075  FAST_SAVE_LONG(sb, "run_away ", op->run_away);
5076  if (op->pick_up != op2->pick_up)
5077  FAST_SAVE_LONG(sb, "pick_up ", op->pick_up);
5078  if (op->weight_limit != op2->weight_limit)
5079  FAST_SAVE_LONG(sb, "container ", op->weight_limit);
5080  if (op->will_apply != op2->will_apply)
5081  FAST_SAVE_LONG(sb, "will_apply ", op->will_apply);
5082  if (op->smoothlevel != op2->smoothlevel)
5083  FAST_SAVE_LONG(sb, "smoothlevel ", op->smoothlevel);
5084 
5085  if (op->map_layer != op2->map_layer)
5086  ADD_STRINGLINE_ENTRY(sb, "map_layer ", map_layer_name[op->map_layer]);
5087 
5088  if (op->weapontype && op->weapontype != op2->weapontype) {
5089  FAST_SAVE_LONG(sb, "weapontype ", op->weapontype);
5090  }
5091  if (op->client_type && op->client_type != op2->client_type) {
5092  FAST_SAVE_LONG(sb, "client_type ", op->client_type);
5093  }
5094 
5095  if (op->item_power != op2->item_power) {
5096  FAST_SAVE_LONG(sb, "item_power ", op->item_power);
5097  }
5098 
5099  if (op->duration != op2->duration)
5100  FAST_SAVE_LONG(sb, "duration ", op->duration);
5101 
5102  if (op->range != op2->range)
5103  FAST_SAVE_LONG(sb, "range ", op->range);
5104 
5105  if (op->range_modifier != op2->range_modifier)
5106  FAST_SAVE_LONG(sb, "range_modifier ", op->range_modifier);
5107 
5108  if (op->duration_modifier != op2->duration_modifier)
5109  FAST_SAVE_LONG(sb, "duration_modifier ", op->duration_modifier);
5110 
5111  if (op->dam_modifier != op2->dam_modifier)
5112  FAST_SAVE_LONG(sb, "dam_modifier ", op->dam_modifier);
5113 
5114  if (op->gen_sp_armour != op2->gen_sp_armour) {
5115  FAST_SAVE_LONG(sb, "gen_sp_armour ", op->gen_sp_armour);
5116  }
5117 
5118  /* I've kept the old int move type saving code commented out.
5119  * In an ideal world, we'd know if we want to do a quick
5120  * save (say to a temp map, where we don't care about strings),
5121  * or a slower save/dm dump, where printing out strings is handy.
5122  */
5123  if (op->move_type != op2->move_type) {
5124  /*FAST_SAVE_LONG(sb, "move_type ", op->move_type)*/
5125  stringbuffer_append_string(sb, "move_type ");
5127  stringbuffer_append_string(sb, "\n");
5128  }
5129  if (op->move_block != op2->move_block) {
5130  /*FAST_SAVE_LONG(sb, "move_block ", op->move_block)*/
5131  stringbuffer_append_string(sb, "move_block ");
5133  stringbuffer_append_string(sb, "\n");
5134  }
5135  if (op->move_allow != op2->move_allow) {
5136  /*FAST_SAVE_LONG(sb, "move_allow ", op->move_allow);*/
5137  stringbuffer_append_string(sb, "move_allow ");
5139  stringbuffer_append_string(sb, "\n");
5140  }
5141  if (op->move_on != op2->move_on) {
5142  /*FAST_SAVE_LONG(sb, "move_on ", op->move_on);*/
5143  stringbuffer_append_string(sb, "move_on ");
5144  get_string_move_type(sb, op->move_on);
5145  stringbuffer_append_string(sb, "\n");
5146  }
5147  if (op->move_off != op2->move_off) {
5148  /*FAST_SAVE_LONG(sb, "move_off ", op->move_off);*/
5149  stringbuffer_append_string(sb, "move_off ");
5150  get_string_move_type(sb, op->move_off);
5151  stringbuffer_append_string(sb, "\n");
5152  }
5153  if (op->move_slow != op2->move_slow) {
5154  /*FAST_SAVE_LONG(sb, "move_slow ", op->move_slow);*/
5155  stringbuffer_append_string(sb, "move_slow ");
5157  stringbuffer_append_string(sb, "\n");
5158  }
5159 
5160  if (op->move_slow_penalty != op2->move_slow_penalty) {
5161  FAST_SAVE_DOUBLE(sb, "move_slow_penalty ", op->move_slow_penalty);
5162  }
5163 
5164  if (!COMPARE_FLAGS(op, op2)) {
5165  for (tmp = 0; tmp <= NUM_FLAGS; tmp++) {
5166  if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) {
5167  ADD_STRINGLINE_ENTRY(sb, flag_names[tmp], QUERY_FLAG(op, tmp) ? " 1" : " 0");
5168  }
5169  }
5170  }
5171 
5172  /* Save body locations */
5173  for (i = 0; i < NUM_BODY_LOCATIONS; i++) {
5174  if (op->body_info[i] != op2->body_info[i]) {
5175  stringbuffer_append_string(sb, body_locations[i].save_name);
5176  FAST_SAVE_LONG(sb, " ", op->body_info[i]);
5177  }
5178  }
5179 
5180  /* Save discrete damage if applicable
5181  * Note that given how the discrete_damage allocation is done, there can't be any case where
5182  * op->discrete_damage == NULL && op2->discrete_damage != NULL.
5183  */
5184  if (op->discrete_damage) {
5185  for (i = 0; i < NROFATTACKS; i++) {
5186  if (op2->discrete_damage == NULL || op2->discrete_damage[i] != op->discrete_damage[i]) {
5187  stringbuffer_append_string(sb, "damage_");
5188  FAST_SAVE_LONG(sb, resist_save[i], op->discrete_damage[i]);
5189  }
5190  }
5191  }
5192 }
5193 
5198 void save_object_in_sb(StringBuffer *sb, const object *op, const int flag) {
5199  archetype *at = op->arch;
5200  if (at == NULL)
5201  at = empty_archetype;
5202 
5203  stringbuffer_append_printf(sb, "arch %s\n", at->name);
5204 
5205  if (op->arch->reference_count > 0) {
5206  /* The object is a custom item/monster, so we handle its save differently.
5207  * We compare the custom archetype to the "original" one, then only save hp/gr/sp
5208  * which are the only values we can't recompute later - all others are modified by items in inventory.
5209  * Note that hp/gr/sp will appear twice in save, but last value will take precedence.
5210  */
5211  archetype *original = find_archetype(op->arch->name);
5212  if (!original) {
5213  LOG(llevError, "could not find original archetype %s for custom monster!\n", op->arch->name);
5214  abort();
5215  }
5216  get_ob_diff(sb, &op->arch->clone, &original->clone);
5217  if (op->stats.hp != op->arch->clone.stats.hp)
5218  FAST_SAVE_LONG(sb, "hp ", op->stats.hp);
5219  if (op->stats.sp != op->arch->clone.stats.sp)
5220  FAST_SAVE_LONG(sb, "sp ", op->stats.sp);
5221  if (op->stats.grace != op->arch->clone.stats.grace)
5222  FAST_SAVE_LONG(sb, "grace ", op->stats.grace);
5223  if (op->x != op->arch->clone.x)
5224  FAST_SAVE_LONG(sb, "x ", op->x);
5225  if (op->y != op->arch->clone.y)
5226  FAST_SAVE_LONG(sb, "y ", op->y);
5227  }
5228  else {
5229  /* if op is an artifact, then find the "standard" artifact to use that for the diff */
5230  if (op->artifact != NULL) {
5231  object *base;
5232  const artifact *artifact;
5233 
5234  artifact = find_artifact(op, op->artifact);
5235  if (artifact == NULL) {
5236  LOG(llevError, "could not find artifact %s [%d] to save data\n", op->artifact, op->type);
5237  get_ob_diff(sb, op, &at->clone);
5238  } else {
5239  stringbuffer_append_printf(sb, "artifact %s\n", op->artifact);
5240  base = arch_to_object(at);
5241  give_artifact_abilities(base, artifact->item);
5242  get_ob_diff(sb, op, base);
5244  }
5245  } else {
5246  get_ob_diff(sb, op, &at->clone);
5247  }
5248  }
5249 
5250  /* Eneq(@csd.uu.se): Added this to allow containers being saved with contents*/
5251  FOR_INV_PREPARE(op, tmp)
5252  save_object_in_sb(sb, tmp, flag);
5253  FOR_INV_FINISH();
5254 
5255  stringbuffer_append_string(sb, "end\n");
5256 }
5257 
5270 int save_object(FILE *fp, object *op, int flag) {
5271  /* Even if the object does have an owner, it would seem that we should
5272  * still save it.
5273  */
5274  if (object_get_owner(op) != NULL || fp == NULL)
5275  return SAVE_ERROR_OK;
5276 
5277  /* If it is unpaid and we don't want to save those, just return. */
5278  if (!(flag&SAVE_FLAG_SAVE_UNPAID) && (QUERY_FLAG(op, FLAG_UNPAID))) {
5279  return SAVE_ERROR_OK;
5280  }
5281 
5282  /* If the object has no_save set, just return */
5283  if (QUERY_FLAG(op, FLAG_NO_SAVE))
5284  return SAVE_ERROR_OK;
5285 
5287  save_object_in_sb(sb, op, flag);
5288  char *cp = stringbuffer_finish(sb);
5289  if (fputs(cp, fp) == EOF) {
5290  free(cp);
5291  return SAVE_ERROR_WRITE;
5292  } else {
5293  free(cp);
5294  return SAVE_ERROR_OK;
5295  }
5296 }
float weapon_speed_left
Definition: object.h:331
static int compare_ob_value_lists(const object *, const object *)
Definition: object.c:170
int object_distance(const object *ob1, const object *ob2)
Definition: object.c:3601
object * object_find_by_type_and_name(const object *who, int type, const char *name)
Definition: object.c:4019
#define FLAG_NO_MAGIC
Definition: define.h:276
char path[HUGE_BUF]
Definition: map.h:365
int find_dir_2(int x, int y)
Definition: object.c:3617
#define SET_MAP_OB(M, X, Y, tmp)
Definition: map.h:177
int reference_count
Definition: object.h:473
#define FLAG_NO_DROP
Definition: define.h:289
int8_t Int
Definition: living.h:36
#define NUM_BODY_LOCATIONS
Definition: object.h:13
Definition: player.h:92
archetype * find_archetype(const char *name)
Definition: arch.c:692
#define ADD_STRINGLINE_ENTRY(sb__, entryname__, entryvalue__)
Definition: object.c:4840
#define FLAG_DAMNED
Definition: define.h:318
#define FLAG_IS_FLOOR
Definition: define.h:303
#define FLAG_UNPAID
Definition: define.h:236
int8_t ac
Definition: living.h:38
struct _key_value * next
Definition: object.h:43
#define MOVE_WALK
Definition: define.h:407
int32_t weight_limit
Definition: object.h:366
#define UP_OBJ_FACE
Definition: object.h:517
tag_t ownercount
Definition: object.h:380
#define FLAG_IS_LINKED
Definition: define.h:316
MoveType move_type
Definition: object.h:424
#define INS_BELOW_ORIGINATOR
Definition: object.h:570
#define GET_MAP_MOVE_OFF(M, X, Y)
Definition: map.h:207
uint8_t dam_modifier
Definition: object.h:407
MoveType move_on
Definition: object.h:427
EXTERN long ob_count
Definition: global.h:154
#define P_PLAYER
Definition: map.h:236
#define SAVE_ERROR_OK
Definition: map.h:143
struct Statistics statistics
Definition: init.c:115
const char * race
Definition: object.h:318
#define P_NEED_UPDATE
Definition: map.h:239
#define FOR_OB_AND_ABOVE_PREPARE(op_)
Definition: define.h:776
uint16_t attack_movement
Definition: object.h:391
#define OBJ_EXPAND
Definition: config.h:565
void esrv_send_item(object *pl, object *op)
Definition: main.c:339
tag_t attacked_by_count
Definition: object.h:383
#define SET_FLAG(xyz, p)
Definition: define.h:223
sstring add_refcount(sstring str)
Definition: shstr.c:210
void object_clear_owner(object *op)
Definition: object.c:612
MoveType move_allow
Definition: object.h:426
void object_sub_weight(object *op, signed long weight)
Definition: object.c:1640
object * object_find_by_type_applied(const object *who, int type)
Definition: object.c:3994
#define FABS(x)
Definition: define.h:22
unsigned char uint8_t
Definition: win32.h:161
Definition: object.h:221
void object_free_all_data(void)
Definition: object.c:553
void object_copy_owner(object *op, object *clone)
Definition: object.c:688
uint16_t animation_id
Definition: object.h:416
uint16_t material
Definition: object.h:347
tag_t * spell_tags
Definition: object.h:436
sstring artifact
Definition: object.h:314
object * object_find_by_type(const object *who, int type)
Definition: object.c:3923
uint64_t spell_merges
Definition: global.h:346
#define EVENT_DESTROY
Definition: plugin.h:77
object * object_get_env_recursive(object *op)
Definition: object.c:364
struct obj * container
Definition: object.h:291
#define FLAG_FRIENDLY
Definition: define.h:246
void object_copy_with_inv(const object *src_ob, object *dest_ob)
Definition: object.c:1006
sstring stringbuffer_finish_shared(StringBuffer *sb)
Definition: stringbuffer.c:85
#define P_NO_MAGIC
Definition: map.h:227
int16_t players
Definition: map.h:344
void fatal(enum fatal_error err)
Definition: utils.c:597
static void get_string_move_type(StringBuffer *sb, MoveType mt)
Definition: object.c:4796
int8_t range
Definition: object.h:405
void init_objects(void)
Definition: object.c:93
#define FLAG_NO_FIX_PLAYER
Definition: define.h:277
#define LOOK_OBJ(ob)
Definition: object.h:505
StringBuffer * stringbuffer_new(void)
Definition: stringbuffer.c:57
uint32_t in_memory
Definition: map.h:345
void get_search_arr(int *search_arr)
Definition: object.c:3518
unsigned char MoveType
Definition: define.h:432
int32_t last_heal
Definition: object.h:357
int16_t maxgrace
Definition: living.h:45
void free_string(sstring str)
Definition: shstr.c:280
#define UP_OBJ_INSERT
Definition: object.h:514
signed long object_sum_weight(object *op)
Definition: object.c:342
#define HUGE_BUF
Definition: define.h:37
void object_fix_multipart(object *tmp)
Definition: object.c:4584
mapstruct * get_map_from_coord(mapstruct *m, int16_t *x, int16_t *y)
Definition: map.c:2380
void esrv_update_item(int flags, object *pl, object *op)
Definition: main.c:342
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4266
struct treasureliststruct * randomitems
Definition: object.h:385
void query_base_name(const object *op, int plural, char *buf, size_t size)
Definition: item.c:720
#define MAP_HEIGHT(m)
Definition: map.h:80
object clone
Definition: object.h:470
int16_t duration
Definition: object.h:403
socket_struct socket
Definition: player.h:94
int16_t invisible
Definition: object.h:360
short freearr_x[SIZEOFFREE]
Definition: object.c:65
int object_find_multi_free_spot_within_radius(const object *ob, const object *gen, int *hx, int *hy)
Definition: object.c:3283
uint8_t duration_modifier
Definition: object.h:404
Definition: object.h:240
int object_count_active(void)
Definition: object.c:1613
const char * key
Definition: object.h:41
struct obj * prev
Definition: object.h:278
const char * slaying
Definition: object.h:319
object * object_find_by_flag(const object *who, int flag)
Definition: object.c:4117
int32_t last_sp
Definition: object.h:358
int object_check_move_on(object *op, object *originator)
Definition: object.c:2852
uint8_t subtype
Definition: object.h:339
int64_t exp
Definition: living.h:47
#define FREE_OBJ_NO_DESTROY_CALLBACK
Definition: object.h:531
int arch_init
Definition: arch.c:41
struct obj * above
Definition: object.h:288
void object_dump_all(void)
Definition: object.c:481
double expmul
Definition: object.h:395
object * object_find_by_type_and_slaying(const object *who, int type, const char *slaying)
Definition: object.c:4069
#define OUT_OF_REAL_MAP(M, X, Y)
Definition: map.h:217
#define object_was_destroyed(op, old_tag)
Definition: object.h:68
#define TRUE
Definition: compat.h:10
int freedir[SIZEOFFREE]
Definition: object.c:83
object * arch_present_in_ob(const archetype *at, const object *op)
Definition: object.c:3078
body_locations_struct body_locations[NUM_BODY_LOCATIONS]
Definition: item.c:54
#define FALSE
Definition: compat.h:11
void remove_friendly_object(object *op)
Definition: friend.c:56
uint32_t path_attuned
Definition: object.h:343
#define MAX(x, y)
Definition: compat.h:20
void object_update(object *op, int action)
Definition: object.c:1260
int16_t sp
Definition: living.h:42
uint32_t get_weight_limit(int stat)
Definition: living.c:2281
int object_can_merge(object *ob1, object *ob2)
Definition: object.c:202
uint8_t smoothlevel
Definition: object.h:421
uint32_t path_repelled
Definition: object.h:344
#define safe_strncpy
Definition: compat.h:23
uint32_t hidden
Definition: player.h:132
void free_dialog_information(object *op)
Definition: dialog.c:32
struct obj * enemy
Definition: object.h:381
struct archt * other_arch
Definition: object.h:413
#define FAST_SAVE_LONG(sb__, entryname__, entryvalue__)
Definition: object.c:4846
int absdir(int d)
Definition: object.c:3654
object * object_find_by_name(const object *who, const char *name)
Definition: object.c:3899
Definition: object.h:465
uint8_t casting_time
Definition: global.h:266
uint64_t spell_hash_full
Definition: global.h:347
#define FOR_OB_AND_BELOW_FINISH()
Definition: define.h:791
int16_t maxsp
Definition: living.h:43
int8_t Con
Definition: living.h:36
#define FLAG_REMOVED
Definition: define.h:232
int16_t hp
Definition: living.h:40
#define CALLOC(x, y)
Definition: compat.h:27
int nrofallocobjects
Definition: object.c:57
short freearr_y[SIZEOFFREE]
Definition: object.c:71
object * active_objects
Definition: object.c:62
static const int reduction_dir[SIZEOFFREE][3]
Definition: object.c:3692
#define SAVE_ERROR_WRITE
Definition: map.h:146
void object_set_flag_inv(object *op, int flag)
Definition: object.c:3098
#define MOVE_ALL
Definition: define.h:413
void esrv_del_item(player *pl, object *ob)
Definition: main.c:355
int object_find_multi_free_spot_around(const object *ob, const object *gen, int16_t *hx, int16_t *hy)
Definition: object.c:3164
void object_set_owner(object *op, object *owner)
Definition: object.c:632
int16_t * discrete_damage
Definition: object.h:435
#define SAVE_FLAG_SAVE_UNPAID
Definition: map.h:110
Definition: object.h:241
const char * lore
Definition: object.h:323
#define MAP_IN_MEMORY
Definition: map.h:130
int object_set_value(object *op, const char *key, const char *value, int add_key)
Definition: object.c:4395
uint32_t update_look
Definition: newserver.h:104
void object_free_drop_inventory(object *ob)
Definition: object.c:1389
const char * name
Definition: face.h:20
const char * title
Definition: object.h:317
int16_t y
Definition: object.h:326
key_value * object_get_key_value(const object *ob, const char *key)
Definition: object.c:4238
object * object_insert_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
Definition: object.c:1936
int16_t maxhp
Definition: living.h:41
sstring find_string(const char *str)
Definition: shstr.c:236
void object_replace_insert_in_map(const char *arch_string, object *op)
Definition: object.c:2440
int dirdiff(int dir1, int dir2)
Definition: object.c:3672
void object_update_turn_face(object *op)
Definition: object.c:1130
#define FREE_OBJ_FREE_INVENTORY
Definition: object.h:530
void object_dump(const object *op, StringBuffer *sb)
Definition: object.c:425
#define FLAG_CLIENT_ANIM_RANDOM
Definition: define.h:241
EXTERN archetype * empty_archetype
Definition: global.h:149
uint32_t path_denied
Definition: object.h:345
int maxfree[SIZEOFFREE]
Definition: object.c:77
#define STARTMAX
Definition: config.h:564
#define FLAG_ALIVE
Definition: define.h:230
object * object_new(void)
Definition: object.c:1068
const char * name_pl
Definition: object.h:315
#define FLAG_OBJ_ORIGINAL
Definition: define.h:365
void stringbuffer_append_string(StringBuffer *sb, const char *str)
Definition: stringbuffer.c:95
object * object_find_by_tag_global(tag_t i)
Definition: object.c:507
#define FOR_OB_AND_ABOVE_FINISH()
Definition: define.h:780
int object_can_pick(const object *who, const object *item)
Definition: object.c:3810
object * object_insert_in_ob(object *op, object *where)
Definition: object.c:2707
float speed_left
Definition: object.h:329
#define MAP_DARKNESS(m)
Definition: map.h:75
#define FLAG_NO_STEAL
Definition: define.h:343
signed short int16_t
Definition: win32.h:160
int16_t ox
Definition: object.h:327
const char * materialname
Definition: object.h:346
int32_t weight
Definition: object.h:365
#define MOVE_FLY_LOW
Definition: define.h:408
const char * anim_suffix
Definition: object.h:316
#define FOR_ABOVE_FINISH()
Definition: define.h:731
void update_all_los(const mapstruct *map, int x, int y)
Definition: los.c:536
uint8_t range_modifier
Definition: object.h:406
int8_t Wis
Definition: living.h:36
uint32_t flags[4]
Definition: object.h:415
struct mapdef * map
Definition: object.h:297
void free_arch(archetype *at)
Definition: arch.c:263
#define snprintf
Definition: win32.h:46
struct obj * active_prev
Definition: object.h:283
#define FLAG_NO_SAVE
Definition: define.h:244
int ob_blocked(const object *ob, mapstruct *m, int16_t x, int16_t y)
Definition: map.c:487
const char *const move_name[]
Definition: object.c:4736
const artifact * find_artifact(const object *op, const char *name)
Definition: artifact.c:657
#define FLAG_CLIENT_ANIM_SYNC
Definition: define.h:240
object * transport
Definition: player.h:195
#define FLAG_IDENTIFIED
Definition: define.h:261
#define FOR_INV_FINISH()
Definition: define.h:714
object * object_find_by_flag_applied(const object *who, int flag)
Definition: object.c:4140
void object_remove_from_active_list(object *op)
Definition: object.c:1215
#define FMT64
Definition: compat.h:12
void update_position(mapstruct *m, int x, int y)
Definition: map.c:2131
int16_t dam
Definition: living.h:46
int object_count_free(void)
Definition: object.c:1575
int32_t carrying
Definition: object.h:367
object * objects
Definition: object.c:60
#define FLAG_BLOCKSVIEW
Definition: define.h:269
struct artifactstruct artifact
static const char *const flag_names[NUM_FLAGS+1]
Definition: object.c:4755
const char * name
Definition: object.h:311
struct obj * env
Definition: object.h:293
#define FOR_ABOVE_PREPARE(op_, it_)
Definition: define.h:724
int64_t perm_exp
Definition: object.h:369
int8_t gen_sp_armour
Definition: object.h:363
#define OB_SPELL_TAG_MATCH(op, count)
Definition: object.h:93
int save_object(FILE *fp, object *op, int flag)
Definition: object.c:5270
uint8_t state
Definition: object.h:349
struct obj * below
Definition: object.h:287
struct archt * more
Definition: object.h:469
#define INS_NO_WALK_ON
Definition: object.h:568
object * object_present_in_ob(uint8_t type, const object *op)
Definition: object.c:3018
#define offsetof(type, member)
Definition: shstr.h:37
#define FLAG_IS_A_TEMPLATE
Definition: define.h:375
int16_t last_grace
Definition: object.h:359
void object_reset(object *op)
Definition: object.c:735
#define GET_MAP_TOP(M, X, Y)
Definition: map.h:174
int8_t direction
Definition: object.h:334
object * object_create_clone(object *asrc)
Definition: object.c:3852
#define NUM_FLAGS
Definition: define.h:385
uint32_t nrof
Definition: object.h:333
int8_t Cha
Definition: living.h:36
#define GET_MAP_MOVE_ON(M, X, Y)
Definition: map.h:202
#define FLAG_OVERLAY_FLOOR
Definition: define.h:255
#define SIZEOFFREE
Definition: define.h:154
#define P_OUT_OF_MAP
Definition: map.h:251
MoveType move_off
Definition: object.h:428
#define GET_MAP_MOVE_BLOCK(M, X, Y)
Definition: map.h:192
object * object_find_by_name_global(const char *str)
Definition: object.c:530
EXTERN Animations * animations
Definition: global.h:163
struct pl * contr
Definition: object.h:276
int8_t item_power
Definition: object.h:362
object * object_insert_in_map(object *op, mapstruct *m, object *originator, int flag)
Definition: object.c:2167
void object_clear(object *op)
Definition: object.c:790
int16_t oy
Definition: object.h:327
#define FREE_AND_CLEAR_STR(xyz)
Definition: global.h:206
#define MAP_SAVING
Definition: map.h:133
#define UPD_WEIGHT
Definition: newclient.h:291
uint32_t tag_t
Definition: object.h:12
object * object_find_by_type_and_race(const object *who, int type, const char *race)
Definition: object.c:4044
int8_t luck
Definition: living.h:39
float speed
Definition: object.h:328
#define QUERY_FLAG(xyz, p)
Definition: define.h:225
#define CLEAR_FLAG(xyz, p)
Definition: define.h:224
#define HEAD(op)
Definition: object.h:592
#define INS_ABOVE_FLOOR_ONLY
Definition: object.h:567
#define FLAG_BEEN_APPLIED
Definition: define.h:324
void object_get_multi_size(const object *ob, int *sx, int *sy, int *hx, int *hy)
Definition: object.c:4646
#define MAX_BUF
Definition: define.h:35
static object * free_objects
Definition: object.c:61
struct obj * active_next
Definition: object.h:279
static void expand_objects(void)
Definition: object.c:1024
void give_artifact_abilities(object *op, const object *artifact)
Definition: artifact.c:203
method_ret ob_move_on(object *op, object *victim, object *originator)
Definition: ob_methods.c:105
int16_t x
Definition: object.h:326
int strncasecmp(const char *s1, const char *s2, int n)
Definition: porting.c:224
const char *const map_layer_name[MAP_LAYERS]
Definition: map.c:44
int nroffreeobjects
Definition: object.c:56
MoveType move_slow
Definition: object.h:429
const char * skill
Definition: object.h:321
int32_t last_eat
Definition: object.h:356
Definition: object.h:201
int8_t wc
Definition: living.h:37
int object_find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
Definition: object.c:3475
void object_insert_to_free_spot_or_free(object *op, mapstruct *map, int x, int y, int start, int stop, object *originator)
Definition: object.c:4695
static const flag_definition flags[]
#define FOR_MAP_FINISH()
Definition: define.h:767
key_value * key_values
Definition: object.h:433
struct obj * next
Definition: object.h:277
int8_t Str
Definition: living.h:36
#define COMPARE_FLAGS(p, q)
Definition: define.h:226
void animate_object(object *op, int dir)
Definition: anim.c:212
#define FLAG_NO_APPLY
Definition: define.h:302
int16_t resist[NROFATTACKS]
Definition: object.h:341
#define FLAG_KNOWN_CURSED
Definition: define.h:321
object * ob
Definition: player.h:158
object * object_find_by_tag(const object *who, tag_t tag)
Definition: object.c:3971
#define GET_MAP_FLAGS(M, X, Y)
Definition: map.h:161
#define FLAG_IS_HILLY
Definition: define.h:333
#define SPELL_TAG_SIZE
Definition: object.h:81
#define FLAG_CURSED
Definition: define.h:317
Definition: object.h:107
unsigned int uint32_t
Definition: win32.h:162
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Definition: object.c:4215
#define SET_MAP_FLAGS(M, X, Y, C)
Definition: map.h:163
#define FLAG_ANIMATE
Definition: define.h:242
int8_t body_info[NUM_BODY_LOCATIONS]
Definition: object.h:372
const char * name
Definition: treasure.h:83
object * object_find_by_type_and_skill(const object *who, int type, const char *skill)
Definition: object.c:4094
uint32_t attacktype
Definition: object.h:342
object * object_split(object *orig_ob, uint32_t nr, char *err, size_t size)
Definition: object.c:2478
uint8_t map_layer
Definition: object.h:422
#define INS_NO_MERGE
Definition: object.h:566
object * object_decrease_nrof(object *op, uint32_t i)
Definition: object.c:2520
void save_object_in_sb(StringBuffer *sb, const object *op, const int flag)
Definition: object.c:5198
#define UP_OBJ_CHANGE
Definition: object.h:516
struct obj * owner
Definition: object.h:377
#define RANDOM()
Definition: define.h:681
int16_t grace
Definition: living.h:44
#define UPD_NROF
Definition: newclient.h:296
signed char int8_t
Definition: win32.h:158
Definition: object.h:143
#define GET_MAP_PLAYER(M, X, Y)
Definition: map.h:168
New_Face * blank_face
Definition: image.c:39
const char * custom_name
Definition: object.h:432
#define UP_OBJ_REMOVE
Definition: object.h:515
int get_button_value(const object *button)
Definition: button.c:754
tag_t count
Definition: object.h:299
living stats
Definition: object.h:368
uint16_t client_type
Definition: object.h:340
int8_t Dex
Definition: living.h:36
struct archt * arch
Definition: object.h:412
#define AB_NO_PASS
Definition: map.h:235
#define UPD_FACE
Definition: newclient.h:292
#define MAP_WIDTH(m)
Definition: map.h:78
uint8_t will_apply
Definition: object.h:392
uint8_t type
Definition: object.h:338
uint32_t do_los
Definition: player.h:126
struct Settings settings
Definition: init.c:40
void object_set_enemy(object *op, object *enemy)
Definition: object.c:710
void object_free2(object *ob, int flags)
Definition: object.c:1412
uint32_t weapontype
Definition: object.h:371
#define FLAG_APPLIED
Definition: define.h:235
#define NROFATTACKS
Definition: attack.h:17
object * object_merge(object *op, object *top)
Definition: object.c:1884
void query_short_name(const object *op, char *buf, size_t size)
Definition: item.c:548
object * object_get_player_container(object *op)
Definition: object.c:384
int out_of_map(mapstruct *m, int x, int y)
Definition: map.c:2306
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
Definition: main.c:364
static object objarray[STARTMAX]
Definition: object.c:55
#define SIZEOFFREE2
Definition: define.h:153
#define OB_SPELL_TAG_HASH(op, count)
Definition: object.h:87
int object_count_used(void)
Definition: object.c:1594
static const object * object_get_owner_const(const object *op)
Definition: object.c:401
const char * msg
Definition: object.h:322
const char * value
Definition: object.h:42
static void permute(int *, int, int)
Definition: object.c:3494
int16_t casting_time
Definition: object.h:402
void object_unset_flag_inv(object *op, int flag)
Definition: object.c:3118
int object_matches_string(object *pl, object *op, const char *name)
Definition: object.c:4473
#define FOR_OB_AND_BELOW_PREPARE(op_)
Definition: define.h:787
#define FLAG_STARTEQUIP
Definition: define.h:268
void object_merge_spell(object *op, int16_t x, int16_t y)
Definition: object.c:1968
int map_find_dir(mapstruct *m, int x, int y, object *exclude)
Definition: object.c:3551
#define GET_ANIM_ID(ob)
Definition: global.h:171
sstring add_string(const char *str)
Definition: shstr.c:124
EXTERN player * first_player
Definition: global.h:117
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
Definition: stringbuffer.c:104
struct pl * next
Definition: player.h:93
#define MIN_ACTIVE_SPEED
Definition: define.h:676
void object_add_weight(object *op, signed long weight)
Definition: object.c:2680
#define GET_MAP_OB(M, X, Y)
Definition: map.h:172
int strcasecmp(const char *s1, const char *s2)
Definition: porting.c:256
int8_t glow_radius
Definition: object.h:364
#define FLAG_MONSTER
Definition: define.h:245
void object_copy(const object *src_ob, object *dest_ob)
Definition: object.c:869
int8_t Pow
Definition: living.h:36
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
Definition: map.c:300
struct obj * inv
Definition: object.h:290
void object_set_cheat(object *op)
Definition: object.c:3139
#define SIZEOFFREE1
Definition: define.h:152
struct obj * head
Definition: object.h:296
#define MOVE_FLY_HIGH
Definition: define.h:409
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
static void object_increase_nrof(object *op, uint32_t i)
Definition: object.c:2607
EXTERN const char *const resist_save[NROFATTACKS]
Definition: attack.h:139
#define SET_MAP_TOP(M, X, Y, tmp)
Definition: map.h:179
#define FLAG_WAS_WIZ
Definition: define.h:234
uint8_t pick_up
Definition: object.h:361
#define FOR_MAP_PREPARE(map_, mx_, my_, it_)
Definition: define.h:760
#define FREE_OBJ_DROP_ABOVE_FLOOR
Definition: object.h:532
MoveType move_block
Definition: object.h:425
uint8_t run_away
Definition: object.h:384
#define GET_MAP_MOVE_SLOW(M, X, Y)
Definition: map.h:197
#define P_BLOCKSVIEW
Definition: map.h:226
void object_set_msg(object *op, const char *msg)
Definition: object.c:4715
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
Definition: object.c:3762
int object_find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
Definition: object.c:3432
#define FLAG_DIALOG_PARSED
Definition: define.h:243
#define FAST_SAVE_DOUBLE(sb__, entryname__, entryvalue__)
Definition: object.c:4849
#define P_NO_ERROR
Definition: map.h:240
float move_slow_penalty
Definition: object.h:430
void query_name(const object *op, char *buf, size_t size)
Definition: item.c:623
object * item
Definition: artifact.h:15
object * find_skill_by_number(object *who, int skillno)
Definition: main.c:351
object * map_find_by_archetype(mapstruct *m, int x, int y, const archetype *at)
Definition: object.c:2961
Definition: map.h:325
#define P_IS_ALIVE
Definition: map.h:237
void get_ob_diff(StringBuffer *sb, const object *op, const object *op2)
Definition: object.c:4865
const New_Face * face
Definition: object.h:332
#define FREE_AND_CLEAR(xyz)
Definition: global.h:201
#define FLAG_IS_WOODED
Definition: define.h:331
#define FLAG_NO_PICK
Definition: define.h:239
object * object_find_by_type_and_arch_name(const object *who, int type, const char *name)
Definition: object.c:4188
#define FLAG_WIZPASS
Definition: define.h:315
int32_t move_status
Definition: object.h:390
void object_free_key_values(object *op)
Definition: object.c:758
int16_t level
Definition: object.h:351
#define FLAG_INV_LOCKED
Definition: define.h:330
void fix_object(object *op)
Definition: living.c:1119
float weapon_speed
Definition: object.h:330
struct obj * more
Definition: object.h:295
object * arch_to_object(archetype *at)
Definition: arch.c:569
void object_update_speed(object *op)
Definition: object.c:1150
#define SCRIPT_FIX_NOTHING
Definition: global.h:362
int32_t value
Definition: object.h:350
object * object_get_owner(object *op)
Definition: object.c:590
int8_t magic
Definition: object.h:348
const char * name
Definition: object.h:466
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.c:76
#define P_NO_CLERIC
Definition: map.h:238
object * object_find_by_arch_name(const object *who, const char *name)
Definition: object.c:4163
object * object_present_in_ob_by_name(int type, const char *str, const object *op)
Definition: object.c:3056
#define FOR_INV_PREPARE(op_, it_)
Definition: define.h:707
void object_remove(object *op)
Definition: object.c:1669
object * map_find_by_type(mapstruct *m, int x, int y, uint8_t type)
Definition: object.c:2991
static int compare_ob_value_lists_one(const object *, const object *)
Definition: object.c:129
#define INS_MAP_LOAD
Definition: object.h:571
object * object_find_by_type2(const object *who, int type1, int type2)
Definition: object.c:3948
int32_t food
Definition: living.h:48
#define FLAG_FREED
Definition: define.h:233
uint32_t count
Definition: player.h:109
static int object_set_value_s(object *, const char *, const char *, int)
Definition: object.c:4309
#define FLAG_IS_TURNABLE
Definition: define.h:256