43 #include <sys/types.h>
55 static void permute(
int *,
int,
int);
76 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,
77 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1
82 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,
83 -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3
88 0, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45,
89 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
94 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,
95 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8
117 for (wants_field = wants->
key_values; wants_field != NULL; wants_field = wants_field->
next) {
123 if (has_field == NULL) {
181 if ((ob1 == ob2) || (ob1->
type != ob2->
type))
205 if (ob1->
inv || ob2->
inv) {
239 || ((ob1->
flags[3]&~0x4) != (ob2->
flags[3]&~0x4))
321 for (sum = 0, inv = op->
inv; inv != NULL; inv = inv->
below) {
327 sum = (sum*(100-op->
stats.
Str))/100;
340 while (op->
env != NULL)
380 if (op->
arch != NULL) {
419 for (op = objects; op != NULL; op = op->
next) {
442 for (op = objects; op != NULL; op = op->
next)
463 for (op = objects; op != NULL; op = op->
next)
464 if (op->
name == name)
483 for (op = free_objects; op != NULL; ) {
491 for (op = objects; op != NULL; ) {
525 if (op->
owner == NULL)
532 LOG(
llevError,
"I had to clean an owner when in get_owner, this isn't my job.\n");
580 && owner != owner->
owner
582 owner = owner->
owner;
588 LOG(
llevError,
"owner id %d could not be resolved to a parent owner in set_owner(). This is bad!"
589 "owner=%p owner->owner=%p owner->ownercount=%d owner->owner->count=%d\n",
666 for (i = op->
key_values; i != NULL; i = next) {
717 memset((
void *)((
char *)op+
offsetof(
object, name)), 0,
sizeof(
object)-
offsetof(
object, name));
783 (void)memcpy((
void *)((
char *)op+
offsetof(
object, name)),
784 (
void *)((
char *)op2+
offsetof(
object, name)),
785 sizeof(
object)-
offsetof(
object, name));
829 new_link->
next = NULL;
834 new_link->
value = NULL;
841 tail->
next = new_link;
866 for (walk = src_ob->
inv; walk != NULL; walk = walk->
below) {
890 new[0].
next = &
new[1],
895 new[i].next = &
new[i+1],
896 new[i].prev = &
new[i-1],
900 new[OBJ_EXPAND-1].prev = &
new[OBJ_EXPAND-2],
901 new[OBJ_EXPAND-1].next = NULL,
924 if (free_objects == NULL) {
942 op = realloc(op,
sizeof(
object));
954 free_objects = op->
next;
955 if (free_objects != NULL)
956 free_objects->
prev = NULL;
1038 active_objects = op;
1113 int update_now = 0,
flags;
1114 MoveType move_on, move_off, move_block, move_slow;
1119 LOG(
llevDebug,
"update_object() called for NULL object.\n");
1123 if (op->
env != NULL) {
1139 LOG(
llevError,
"update_object() called for object out of map!\n");
1166 if ((move_on|op->
move_on) != move_on)
1168 if ((move_off|op->
move_off) != move_off)
1175 if ((move_slow|op->
move_slow) != move_slow)
1214 LOG(
llevError,
"update_object called with invalid action: %d\n", action);
1222 if (op->
more != NULL)
1265 LOG(
llevDebug,
"Free object called with non removed object\n");
1286 LOG(
llevError,
"Trying to free freed object.\n%s\n", diff);
1304 while (op != NULL) {
1312 while (op != NULL) {
1327 for (part = ob; part; part = part->
more) {
1331 partcount = RANDOM()%partcount;
1332 for (part = ob; partcount > 0; partcount--) {
1361 if (ob->
more != NULL) {
1374 if (ob->
prev == NULL) {
1376 if (objects != NULL)
1377 objects->
prev = NULL;
1380 if (ob->
next != NULL)
1408 #if defined(MEMORY_DEBUG) && (MEMORY_DEBUG > 2)
1412 memset(ob, 0,
sizeof(
object));
1420 if (free_objects != NULL)
1421 free_objects->
prev = ob;
1490 while (op != NULL) {
1492 weight = (
signed long)(weight*(100-op->
stats.
Str)/100);
1516 object *tmp, *last = NULL;
1530 LOG(
llevError,
"Trying to remove removed object.\n%s\n", diff);
1534 if (op->
more != NULL)
1544 if (op->
env != NULL) {
1564 while (above && !above->
contr)
1565 above = above->
above;
1582 if (op->
above != NULL)
1587 if (op->
below != NULL)
1606 if (op->
map == NULL)
1617 LOG(
llevError,
"remove_ob 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);
1621 LOG(
llevError,
"remove_ob: 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);
1646 LOG(
llevError,
"remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom?\n%s\n", diff);
1691 if (tmp->
above == tmp)
1729 for (top = op; top != NULL && top->
above != NULL; top = top->
above)
1731 for (; top != NULL; top = top->
below) {
1766 for (tmp = op; tmp; tmp = tmp->
more) {
1769 if (op != tmp && !tmp->
map)
1793 object *tmp, *above;
1810 for (tmp =
GET_MAP_OB(op->
map, x, y); tmp != NULL; tmp = above) {
1882 if (i <= SPELL_TAG_SIZE)
1993 object *tmp, *top, *floor = NULL;
2007 LOG(
llevError,
"Trying to insert in null-map!\n%s\n", diff);
2018 LOG(
llevError,
"Trying to insert object outside the map.\n%s\n", diff);
2036 LOG(
llevError,
"Trying to insert (map) inserted object.\n%s\n", diff);
2040 if (op->
more != NULL) {
2043 object *more = op->
more;
2055 }
else if (!more->
map) {
2064 LOG(
llevError,
"BUG: insert_ob_in_map(): inserting op->more killed op\n");
2122 if (originator->
map != op->
map
2123 || originator->
x != op->
x
2124 || originator->
y != op->
y) {
2125 LOG(
llevError,
"insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
2128 op->
above = originator;
2135 originator->
below = op;
2142 object *last = NULL;
2157 while (top != NULL) {
2202 if (op->
above == NULL)
2255 for (tmp = op->
more; tmp != NULL; tmp = tmp->
more)
2276 for (tmp =
GET_MAP_OB(op->
map, op->
x, op->
y); tmp != NULL; tmp = tmp1) {
2278 if (!strcmp(tmp->
arch->
name, arch_string)) {
2316 if (orig_ob->
nrof < nr) {
2319 snprintf(err, size,
"There are only %u %ss.", orig_ob->
nrof ? orig_ob->
nrof : 1, orig_ob->
name);
2357 }
else if (op->
env != NULL) {
2395 while (pl && !pl->
contr)
2397 if (pl && pl->
contr)
2432 }
else if (op->
env != NULL) {
2465 while (pl && !pl->
contr)
2467 if (pl && pl->
contr)
2487 while (op != NULL) {
2489 weight = (
signed long)(weight*(100-op->
stats.
Str)/100);
2520 LOG(
llevError,
"Trying to insert (ob) inserted object.\n%s\n", diff);
2525 if (where == NULL) {
2532 LOG(
llevError,
"Trying to put object in NULL.\n%s\n", diff);
2537 LOG(
llevDebug,
"Warning: Tried to insert object wrong part of multipart object.\n");
2538 where = where->
head;
2547 for (tmp = where->
inv; tmp != NULL; tmp = tmp->
below)
2574 if (where->
inv == NULL)
2584 if (where->
contr != NULL)
2596 while (above && !above->
contr)
2597 above = above->
above;
2606 if (otmp && otmp->
contr != NULL) {
2617 LOG(
llevDebug,
" insert_ob_in_ob(): got %s to insert in map/op\n", op->
name);
2655 int x = op->
x, y = op->
y;
2656 MoveType move_on, move_slow, move_block;
2682 if ((op->
move_type&~move_on&~move_block) != 0
2683 && (op->
move_type&~move_slow&~move_block) != 0)
2698 for (; tmp != NULL; tmp = tmp->
below) {
2736 if (op->
map != m || op->
x != x || op->
y != y)
2764 if (tmp->
arch == at)
2791 if (tmp->
type == type)
2809 for (tmp = op->
inv; tmp != NULL; tmp = tmp->
below)
2810 if (tmp->
type == type)
2843 for (tmp = op->
inv; tmp != NULL; tmp = tmp->
below) {
2844 if ((type == -1 || tmp->
type == type) && (!strcmp(str, tmp->
name)))
2862 for (tmp = op->
inv; tmp != NULL; tmp = tmp->
below)
2863 if (tmp->
arch == at)
2880 for (tmp = op->
inv; tmp != NULL; tmp = tmp->
below) {
2898 for (tmp = op->
inv; tmp != NULL; tmp = tmp->
below) {
2936 int genx, geny, genx2, geny2, sx, sy, sx2, sy2, ix, iy, nx, ny, i, flag;
2960 ix = gen->
x-sx-genx2;
2961 iy = gen->
y-sy-geny2;
2973 for (i = 0; i < (sx+sx+sy+sy); i++) {
2977 }
else if (i <= (sx+sy)) {
2980 }
else if (i <= (sx+sy+sx)) {
2981 nx = ix+sx-(i-(sx+sy));
2985 ny = iy+sy-(i-(sx+sy+sx));
2998 freecount = RANDOM()%freecount;
2999 for (i = 0; i < (sx+sx+sy+sy); i++) {
3003 }
else if (i <= (sx+sy)) {
3006 }
else if (i <= (sx+sy+sx)) {
3007 nx = ix+sx-(i-(sx+sy));
3011 ny = iy+sy-(i-(sx+sy+sx));
3023 if (freecount <= 0) {
3053 int genx, geny, genx2, geny2, sx, sy, sx2, sy2, ix, iy, nx, ny, i, flag;
3055 int freecount = 0, freecountstop = 0;
3096 ix = gen->
x-sx-genx2-radius+1;
3097 iy = gen->
y-sy-geny2-radius+1;
3098 sx += genx+sx2+radius*2-1;
3099 sy += geny+sy2+radius*2-1;
3109 x_array = malloc(sx*sy*
sizeof(
sint8));
3110 y_array = malloc(sx*sy*
sizeof(
sint8));
3115 for (x = 0; x < sx; x++) {
3116 for (y = 0; y < sy; y++) {
3129 x_array[freecount] = nx;
3130 y_array[freecount] = ny;
3143 freecountstop = RANDOM()%freecount;
3144 for (i = 0; i < freecount; i++) {
3152 if (freecountstop <= 0) {
3201 int i, index = 0, flag;
3204 for (i = start; i < stop; i++) {
3207 altern[index++] = i;
3222 return altern[RANDOM()%index];
3259 static void permute(
int *arr,
int begin,
int end) {
3263 for (i = begin; i < end; i++) {
3264 j = begin+RANDOM()%len;
3320 if (exclude && exclude->
head) {
3321 exclude = exclude->
head;
3328 for (i = 1; i < max; i++) {
3339 if ((move_type&blocked) == move_type) {
3344 && (tmp != exclude ||(tmp->
head && tmp->
head != exclude))) {
3367 i = (ob1->
x-ob2->
x)*(ob1->
x-ob2->
x)+
3368 (ob1->
y-ob2->
y)*(ob1->
y-ob2->
y);
3609 object *dst = NULL, *tmp, *src, *part, *prev, *item;
3618 for (part = src; part; part = part->more) {
3635 for (item = src->inv; item; item = item->below) {
3659 for (tmp = who->
inv; tmp; tmp = tmp->
below)
3680 if (link->
key == key) {
3703 const char *canonical_key;
3707 if (canonical_key == NULL) {
3720 if (link->
key == canonical_key) {
3744 LOG(
llevDebug,
"set_ob_value_s: '%s' '%s' %d\n", canonical_key, value ? value :
"null", add_key);
3746 for (field = op->
key_values; field != NULL; field = field->
next) {
3747 if (field->
key != canonical_key) {
3763 field->
value = NULL;
3771 last->next = field->
next;
3827 const char *canonical_key = NULL;
3828 int floating_ref =
FALSE;
3836 if (canonical_key == NULL) {
3838 floating_ref =
TRUE;
3903 int count, retval = 0;
3904 strcpy(local_name, name);
3906 for (cp = strtok(local_name,
","); cp; cp = strtok(NULL,
",")) {
3907 while (cp[0] ==
' ')
3912 if (!strcmp(cp,
"all"))
3918 if (!strcmp(cp,
"cursed")
3927 if ((count = atoi(cp)) != 0) {
3928 cp = strchr(cp,
' ');
3929 while (cp && cp[0] ==
' ')
3938 if (!cp || cp[0] ==
'\0' || count < 0)
3971 else if (strstr(bname_p, cp))
3973 else if (strstr(bname_s, cp))
3975 else if (strstr(name_short, cp))
4012 LOG(
llevError,
"fix_multipart_object: not on a map!\n");
4023 for (at = tmp->
arch->
more, last = tmp; at != NULL; at = at->
more, last = op) {
4068 int maxx = 0, maxy = 0, minx = 0, miny = 0;
4075 for (part = ob->
arch; part; part = part->
more) {
4076 if (part->
clone.
x > maxx)
4078 if (part->
clone.
y > maxy)
4080 if (part->
clone.
x < minx)
4082 if (part->
clone.
y < miny)
static int compare_ob_value_lists(const object *, const object *)
int find_dir_2(int x, int y)
#define SET_MAP_OB(M, X, Y, tmp)
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, sint16 x, sint16 y, sint16 *nx, sint16 *ny)
archetype * find_archetype(const char *name)
#define INS_BELOW_ORIGINATOR
int find_multi_free_spot_within_radius(object *ob, object *gen, int *hx, int *hy)
#define GET_MAP_MOVE_OFF(M, X, Y)
const char * get_ob_key_value(const object *op, const char *const key)
object * find_obj_by_type_subtype(const object *who, int type, int subtype)
struct Statistics statistics
void set_owner(object *op, object *owner)
long strtol(register char *str, char **ptr, register int base)
void merge_spell(object *op, sint16 x, sint16 y)
void esrv_send_item(object *pl, object *op)
object * present_in_ob(uint8 type, const object *op)
sstring add_refcount(sstring str)
static int set_ob_key_value_s(object *, const char *, const char *, int)
int find_multi_free_spot_around(object *ob, object *gen, int *hx, int *hy)
object * object_get_env_recursive(object *op)
void unflag_inv(object *op, int flag)
void remove_from_active_list(object *op)
object * insert_ob_in_map_at(object *op, mapstruct *m, object *originator, int flag, int x, int y)
#define FLAG_NO_FIX_PLAYER
StringBuffer * stringbuffer_new(void)
void get_search_arr(int *search_arr)
object * find_object_name(const char *str)
void free_string(sstring str)
#define SET_ANIMATION(ob, newanim)
void esrv_update_item(int flags, object *pl, object *op)
int item_matched_string(object *pl, object *op, const char *name)
void query_base_name(const object *op, int plural, char *buf, size_t size)
short freearr_x[SIZEOFFREE]
void flag_inv(object *op, int flag)
object * merge_ob(object *op, object *top)
void update_object(object *op, int action)
#define OUT_OF_REAL_MAP(M, X, Y)
void remove_friendly_object(object *op)
signed long sum_weight(object *op)
void get_multi_size(object *ob, int *sx, int *sy, int *hx, int *hy)
object * find_object(tag_t i)
int distance(const object *ob1, const object *ob2)
void free_dialog_information(object *op)
struct archt * other_arch
short freearr_y[SIZEOFFREE]
static const int reduction_dir[SIZEOFFREE][3]
void fix_multipart_object(object *tmp)
void remove_ob(object *op)
sstring find_string(const char *str)
int dirdiff(int dir1, int dir2)
#define FLAG_CLIENT_ANIM_RANDOM
EXTERN archetype * empty_archetype
void clear_owner(object *op)
#define FLAG_OBJ_ORIGINAL
void stringbuffer_append_string(StringBuffer *sb, const char *str)
object * get_player_container(object *op)
const char * materialname
void update_all_los(const mapstruct *map, int x, int y)
void free_arch(archetype *at)
void dump_object(object *op, StringBuffer *sb)
#define FLAG_CLIENT_ANIM_SYNC
int find_first_free_spot(const object *ob, mapstruct *m, int x, int y)
void update_position(mapstruct *m, int x, int y)
int can_merge(object *ob1, object *ob2)
#define OB_SPELL_TAG_MATCH(op, count)
object * get_owner(object *op)
object * present(uint8 type, mapstruct *m, int x, int y)
#define offsetof(type, member)
#define FLAG_IS_A_TEMPLATE
#define GET_MAP_TOP(M, X, Y)
object * object_create_clone(object *asrc)
int find_dir(mapstruct *m, int x, int y, object *exclude)
object * present_in_ob_by_name(int type, const char *str, const object *op)
#define GET_MAP_MOVE_ON(M, X, Y)
#define FLAG_OVERLAY_FLOOR
mapstruct * get_map_from_coord(mapstruct *m, sint16 *x, sint16 *y)
#define GET_MAP_MOVE_BLOCK(M, X, Y)
int can_pick(const object *who, const object *item)
#define FREE_AND_CLEAR_STR(xyz)
void add_weight(object *op, signed long weight)
object * present_arch(const archetype *at, mapstruct *m, int x, int y)
#define QUERY_FLAG(xyz, p)
#define CLEAR_FLAG(xyz, p)
#define INS_ABOVE_FLOOR_ONLY
#define FLAG_BEEN_APPLIED
object * insert_ob_in_ob(object *op, object *where)
static void expand_objects(void)
method_ret ob_move_on(object *op, object *victim, object *originator)
object * get_object(void)
int strncasecmp(const char *s1, const char *s2, int n)
object * insert_ob_in_map(object *op, mapstruct *m, object *originator, int flag)
void copy_owner(object *op, object *clone)
static const flag_definition flags[]
sint16 resist[NROFATTACKS]
#define FLAG_KNOWN_CURSED
#define GET_MAP_FLAGS(M, X, Y)
int snprintf(char *dest, int max, const char *format,...)
void get_ob_diff(StringBuffer *sb, object *op, object *op2)
#define SET_MAP_FLAGS(M, X, Y, C)
int set_ob_key_value(object *op, const char *key, const char *value, int add_key)
void free_object2(object *ob, int free_inventory)
#define GET_MAP_PLAYER(M, X, Y)
void update_turn_face(object *op)
void set_cheat(object *op)
object * present_arch_in_ob(const archetype *at, const object *op)
object * decrease_ob_nr(object *op, uint32 i)
void reset_object(object *op)
void free_key_values(object *op)
void dump_all_objects(void)
void query_short_name(const object *op, char *buf, size_t size)
int out_of_map(mapstruct *m, int x, int y)
int execute_event(object *op, int eventcode, object *activator, object *third, const char *message, int fix)
object objarray[STARTMAX]
#define OB_SPELL_TAG_HASH(op, count)
static void permute(int *, int, int)
void update_ob_speed(object *op)
sstring add_string(const char *str)
EXTERN player * first_player
void stringbuffer_append_printf(StringBuffer *sb, const char *format,...)
void copy_object_with_inv(object *src_ob, object *dest_ob)
#define GET_MAP_OB(M, X, Y)
int strcasecmp(const char *s1, const char *s2)
int find_free_spot(const object *ob, mapstruct *m, int x, int y, int start, int stop)
void clear_object(object *op)
void LOG(LogLevel logLevel, const char *format,...)
object * get_split_ob(object *orig_ob, uint32 nr, char *err, size_t size)
void sub_weight(object *op, signed long weight)
#define SET_MAP_TOP(M, X, Y, tmp)
#define was_destroyed(op, old_tag)
#define GET_MAP_MOVE_SLOW(M, X, Y)
int can_see_monsterP(mapstruct *m, int x, int y, int dir)
#define FLAG_DIALOG_PARSED
void copy_object(object *op2, object *op)
int check_move_on(object *op, object *originator)
void query_name(const object *op, char *buf, size_t size)
object * find_skill_by_number(object *who, int skillno)
void free_object(object *ob)
#define FREE_AND_CLEAR(xyz)
void replace_insert_ob_in_map(const char *arch_string, object *op)
void esrv_del_item(player *pl, int tag)
void fix_object(object *op)
void free_all_object_data(void)
object * arch_to_object(archetype *at)
#define SCRIPT_FIX_NOTHING
char * stringbuffer_finish(StringBuffer *sb)
key_value * get_ob_key_link(const object *ob, const char *key)
static int compare_ob_value_lists_one(const object *, const object *)
int ob_blocked(const object *ob, mapstruct *m, sint16 x, sint16 y)
static void increase_ob_nr(object *op, uint32 i)