--- deliantra/server/common/object.c 2006/02/07 23:29:55 1.2 +++ deliantra/server/common/object.c 2006/06/04 19:46:55 1.6 @@ -71,7 +71,7 @@ /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ -static int compare_ob_value_lists_one(object * wants, object * has) { +static int compare_ob_value_lists_one(const object * wants, const object * has) { key_value * wants_field; /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both @@ -105,7 +105,7 @@ } /* Returns TRUE if ob1 has the same key_values as ob2. */ -static int compare_ob_value_lists(object * ob1, object * ob2) { +static int compare_ob_value_lists(const object * ob1, const object * ob2) { /* However, there may be fields in has which aren't partnered in wants, * so we need to run the comparison *twice*. :( */ @@ -200,6 +200,7 @@ (ob1->subtype != ob2->subtype) || (ob1->move_type != ob2->move_type) || (ob1->move_block != ob2->move_block) || + (ob1->move_allow != ob2->move_allow) || (ob1->move_on != ob2->move_on) || (ob1->move_off != ob2->move_off) || (ob1->move_slow != ob2->move_slow) || @@ -214,22 +215,22 @@ if (QUERY_FLAG(ob1, FLAG_APPLIED) || QUERY_FLAG(ob2, FLAG_APPLIED)) return 0; + switch (ob1->type) { + case SCROLL: + if (ob1->level != ob2->level) return 0; + break; + + } if (ob1->key_values != NULL || ob2->key_values != NULL) { /* At least one of these has key_values. */ if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) { /* One has fields, but the other one doesn't. */ return 0; - } else { - return compare_ob_value_lists(ob1, ob2); + } else if (!compare_ob_value_lists(ob1, ob2)) { + return 0; } } - switch (ob1->type) { - case SCROLL: - if (ob1->level != ob2->level) return 0; - break; - - } /* Everything passes, must be OK. */ return 1; } @@ -387,7 +388,7 @@ * If it's not a multi-object, it is returned. */ -object *get_nearest_part(object *op,object *pl) { +object *get_nearest_part(object *op, const object *pl) { object *tmp,*closest; int last_dist,i; if(op->more==NULL) @@ -416,7 +417,7 @@ * Enables features like "patch food 999" */ -object *find_object_name(char *str) { +object *find_object_name(const char *str) { const char *name=add_string(str); object *op; for(op=objects;op!=NULL;op=op->next) @@ -1021,7 +1022,11 @@ if ((move_on | op->move_on) != move_on) update_now=1; if ((move_off | op->move_off) != move_off) update_now=1; - if ((move_block | op->move_block) != move_block) update_now=1; + /* This isn't perfect, but I don't expect a lot of objects to + * to have move_allow right now. + */ + if (((move_block | op->move_block) & ~op->move_allow) != move_block) + update_now=1; if ((move_slow | op->move_slow) != move_slow) update_now=1; } /* if the object is being removed, we can't make intelligent @@ -1513,10 +1518,22 @@ object *more = op->more; - /* Debugging information so you can see the last coordinates this object had */ - more->ox = more->x; - more->oy = more->y; - more->map = get_map_from_coord(m, &more->x, &more->y); + /* We really need the caller to normalize coordinates - if + * we set the map, that doesn't work if the location is within + * a map and this is straddling an edge. So only if coordinate + * is clear wrong do we normalize it. + */ + if (OUT_OF_REAL_MAP(more->map, more->x, more->y)) { + /* Debugging information so you can see the last coordinates this object had */ + more->ox = more->x; + more->oy = more->y; + more->map = get_map_from_coord(m, &more->x, &more->y); + } else if (!more->map) { + /* For backwards compatibility - when not dealing with tiled maps, + * more->map should always point to the parent. + */ + more->map = m; + } if (insert_ob_in_map(more, more->map, originator, flag) == NULL) { if ( ! op->head) @@ -1529,9 +1546,14 @@ /* Debugging information so you can see the last coordinates this object had */ op->ox=op->x; op->oy=op->y; + + /* Ideally, the caller figures this out. However, it complicates a lot + * of areas of callers (eg, anything that uses find_free_spot would now + * need extra work + */ + op->map=get_map_from_coord(m, &op->x, &op->y); x = op->x; y = op->y; - op->map=get_map_from_coord(m, &x, &y); /* this has to be done after we translate the coordinates. */ @@ -1544,16 +1566,6 @@ } } - /* Ideally, the caller figures this out. However, it complicates a lot - * of areas of callers (eg, anything that uses find_free_spot would now - * need extra work - */ - if (op->map != m) { - /* coordinates should not change unless map also changes */ - op->x = x; - op->y = y; - } - CLEAR_FLAG(op,FLAG_APPLIED); /* hack for fixing F_APPLIED in items of dead people */ CLEAR_FLAG(op, FLAG_INV_LOCKED); if (!QUERY_FLAG(op, FLAG_ALIVE)) @@ -1708,7 +1720,7 @@ * finds an object of its own type, it'll remove that one first. * op is the object to insert it under: supplies x and the map. */ -void replace_insert_ob_in_map(char *arch_string, object *op) { +void replace_insert_ob_in_map(const char *arch_string, object *op) { object *tmp; object *tmp1; @@ -2086,7 +2098,7 @@ * The first matching object is returned, or NULL if none. */ -object *present_arch(archetype *at, mapstruct *m, int x, int y) { +object *present_arch(const archetype *at, mapstruct *m, int x, int y) { object *tmp; if(m==NULL || out_of_map(m,x,y)) { LOG(llevError,"Present_arch called outside map.\n"); @@ -2122,7 +2134,7 @@ * The first matching object is returned, or NULL if none. */ -object *present_in_ob(unsigned char type,object *op) { +object *present_in_ob(unsigned char type, const object *op) { object *tmp; for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) if(tmp->type==type) @@ -2145,7 +2157,7 @@ * to be unique. */ -object *present_in_ob_by_name(int type, char *str,object *op) { +object *present_in_ob_by_name(int type, const char *str, const object *op) { object *tmp; for(tmp=op->inv; tmp!=NULL; tmp=tmp->below) { @@ -2161,7 +2173,7 @@ * The first matching object is returned, or NULL if none. */ -object *present_arch_in_ob(archetype *at, object *op) { +object *present_arch_in_ob(const archetype *at, const object *op) { object *tmp; for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) if( tmp->arch == at) @@ -2225,7 +2237,7 @@ * customized, changed states, etc. */ -int find_free_spot(object *ob, mapstruct *m,int x,int y,int start,int stop) { +int find_free_spot(const object *ob, mapstruct *m,int x,int y,int start,int stop) { int i,index=0, flag; static int altern[SIZEOFFREE]; @@ -2256,7 +2268,7 @@ * Changed 0.93.2: Have it return -1 if there is no free spot available. */ -int find_first_free_spot(object *ob, mapstruct *m,int x,int y) { +int find_first_free_spot(const object *ob, mapstruct *m,int x,int y) { int i; for(i=0;ix - ob2->x)*(ob1->x - ob2->x)+ (ob1->y - ob2->y)*(ob1->y - ob2->y); @@ -2542,7 +2554,7 @@ * Add a check so we can't pick up invisible objects (0.93.8) */ -int can_pick(object *who,object *item) { +int can_pick(const object *who, const object *item) { return /*QUERY_FLAG(who,FLAG_WIZ)||*/ (item->weight>0&&!QUERY_FLAG(item,FLAG_NO_PICK)&& !QUERY_FLAG(item,FLAG_ALIVE)&&!item->invisible && @@ -2587,7 +2599,7 @@ } /* return true if the object was destroyed, 0 otherwise */ -int was_destroyed (object *op, tag_t old_tag) +int was_destroyed (const object *op, tag_t old_tag) { /* checking for FLAG_FREED isn't necessary, but makes this function more * robust */ @@ -2601,7 +2613,7 @@ /* Remember not to use load_object_str in a time-critical situation. */ /* Also remember that multiparts objects are not supported for now. */ -object* load_object_str(char *obstr) +object* load_object_str(const char *obstr) { object *op; FILE *tempfile; @@ -2635,7 +2647,7 @@ * has the same type and subtype match. * returns NULL if no match. */ -object *find_obj_by_type_subtype(object *who, int type, int subtype) +object *find_obj_by_type_subtype(const object *who, int type, int subtype) { object *tmp; @@ -2651,7 +2663,7 @@ * key must be a passed in shared string - otherwise, this won't * do the desired thing. */ -key_value * get_ob_key_link(object * ob, const char * key) { +key_value * get_ob_key_link(const object * ob, const char * key) { key_value * link; for (link = ob->key_values; link != NULL; link = link->next) { @@ -2670,7 +2682,7 @@ * * The returned string is shared. */ -const char * get_ob_key_value(object * op, const char * const key) { +const char * get_ob_key_value(const object * op, const char * const key) { key_value * link; const char * canonical_key; @@ -2710,8 +2722,6 @@ int set_ob_key_value_s(object * op, const char * canonical_key, const char * value, int add_key) { key_value * field = NULL, *last=NULL; - LOG(llevDebug, "set_ob_value_s: '%s' '%s' %d\n", canonical_key, value, add_key); - for (field=op->key_values; field != NULL; field=field->next) { if (field->key != canonical_key) { last = field;