--- deliantra/server/common/object.C 2006/09/08 16:51:42 1.18 +++ deliantra/server/common/object.C 2006/09/10 14:54:02 1.23 @@ -1,6 +1,6 @@ /* * static char *rcsid_object_c = - * "$Id: object.C,v 1.18 2006/09/08 16:51:42 root Exp $"; + * "$Id: object.C,v 1.23 2006/09/10 14:54:02 root Exp $"; */ /* @@ -57,7 +57,6 @@ 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, 1,2,2,2,2,2,3,4,4,4,4,4,5,6,6,6,6,6,7,8,8,8,8,8}; - /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ static int compare_ob_value_lists_one(const object * wants, const object * has) { key_value * wants_field; @@ -532,8 +531,8 @@ void object::clone (object *destination) { - *(object_copy *)destination = *(object_copy *)this; - *(object_pod *)destination = *(object_pod *)this; + *(object_copy *)destination = *this; + *(object_pod *)destination = *this; if (self || cb) INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); @@ -593,23 +592,23 @@ op->speed_left = op2->speed_left - RANDOM() % 200 / 100.0; /* Copy over key_values, if any. */ - if (op2->key_values != NULL) + if (op2->key_values) { - key_value *tail = NULL; + key_value *tail = 0; key_value *i; - op->key_values = NULL; + op->key_values = 0; - for (i = op2->key_values; i != NULL; i = i->next) + for (i = op2->key_values; i; i = i->next) { key_value *new_link = new key_value; - new_link->next = NULL; + new_link->next = 0; new_link->key = i->key; new_link->value = i->value; /* Try and be clever here, too. */ - if (op->key_values == NULL) + if (!op->key_values) { op->key_values = new_link; tail = new_link; @@ -626,34 +625,6 @@ } /* - * get_object() grabs an object from the list of unused objects, makes - * sure it is initialised, and returns it. - * If there are no free objects, expand_objects() is called to get more. - */ - -object *get_object () -{ - object *op = new object; - - op->count = ++ob_count; - - op->next = objects; - - if (objects) - objects->prev = op; - - objects = op; - - SET_FLAG (op, FLAG_REMOVED); - - op->expmul = 1.0; - op->face = blank_face; - op->attacked_by_count = -1; - - return op; -} - -/* * If an object with the IS_TURNABLE() flag needs to be turned due * to the closest player being on the other side, this function can * be called to update the face variable, _and_ how it looks on the map. @@ -824,14 +795,21 @@ if (QUERY_FLAG(op, FLAG_ALIVE) && !(flags & P_IS_ALIVE)) update_now=1; + if (op->type == SAFE_GROUND && !(flags & P_SAFE)) + update_now=1; + if ((move_on | op->move_on) != move_on) update_now=1; + if ((move_off | op->move_off) != move_off) 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 ((move_slow | op->move_slow) != move_slow) + update_now=1; } /* if the object is being removed, we can't make intelligent * decisions, because remove_ob can't really pass the object @@ -855,6 +833,61 @@ update_object(op->more, action); } +static std::vector mortals; + +void object::free_mortals () +{ + for (std::vector::iterator i = mortals.begin (); i != mortals.end (); ++i) + delete *i; + + mortals.clear (); +} + +object::object () +{ + SET_FLAG (this, FLAG_REMOVED); + + expmul = 1.0; + face = blank_face; + attacked_by_count = -1; +} + +object::~object () +{ + free_key_values (this); +} + +void +object::link () +{ + count = ++ob_count; + + prev = 0; + next = objects; + + if (objects) + objects->prev = this; + + objects = this; +} + +void +object::unlink () +{ + count = 0; + + /* Remove this object from the list of used objects */ + if (prev) prev->next = next; + if (next) next->prev = prev; + if (this == objects) objects = next; +} + +object *object::create () +{ + object *op = new object; + op->link (); + return op; +} /* * free_object() frees everything allocated by an object, removes @@ -866,73 +899,64 @@ * If free_inventory is set, free inventory as well. Else drop items in * inventory to the ground. */ - void -free_object (object * ob) +object::free (bool free_inventory) { - free_object2 (ob, 0); -} - -void -free_object2 (object * ob, int free_inventory) -{ - object *tmp, *op; - - if (!QUERY_FLAG (ob, FLAG_REMOVED)) + if (!QUERY_FLAG (this, FLAG_REMOVED)) { LOG (llevDebug, "Free object called with non removed object\n"); - dump_object (ob); + dump_object (this); #ifdef MANY_CORES abort (); #endif } - if (QUERY_FLAG (ob, FLAG_FRIENDLY)) + if (QUERY_FLAG (this, FLAG_FRIENDLY)) { LOG (llevMonster, "Warning: tried to free friendly object.\n"); - remove_friendly_object (ob); + remove_friendly_object (this); } - if (QUERY_FLAG (ob, FLAG_FREED)) + if (QUERY_FLAG (this, FLAG_FREED)) { - dump_object (ob); + dump_object (this); LOG (llevError, "Trying to free freed object.\n%s\n", errmsg); return; } - if (ob->more != NULL) + if (more) { - free_object2 (ob->more, free_inventory); - ob->more = NULL; + more->free (free_inventory); + more = 0; } - if (ob->inv) + if (inv) { /* Only if the space blocks everything do we not process - * if some form of movement is allowed, let objects * drop on that space. */ - if (free_inventory || ob->map == NULL - || ob->map->in_memory != MAP_IN_MEMORY - || (GET_MAP_MOVE_BLOCK (ob->map, ob->x, ob->y) == MOVE_ALL)) + if (free_inventory || !map + || map->in_memory != MAP_IN_MEMORY + || (GET_MAP_MOVE_BLOCK (map, x, y) == MOVE_ALL)) { - op = ob->inv; + object *op = inv; - while (op != NULL) + while (op) { - tmp = op->below; + object *tmp = op->below; remove_ob (op); - free_object2 (op, free_inventory); + op->free (free_inventory); op = tmp; } } else { /* Put objects in inventory onto this space */ - op = ob->inv; + object *op = inv; - while (op != NULL) + while (op) { - tmp = op->below; + object *tmp = op->below; remove_ob (op); if (QUERY_FLAG (op, FLAG_STARTEQUIP) @@ -941,9 +965,9 @@ free_object (op); else { - op->x = ob->x; - op->y = ob->y; - insert_ob_in_map (op, ob->map, NULL, 0); /* Insert in same map as the envir */ + op->x = x; + op->y = y; + insert_ob_in_map (op, map, 0, 0); /* Insert in same map as the envir */ } op = tmp; @@ -952,35 +976,14 @@ } /* Remove object from the active list */ - ob->speed = 0; - update_ob_speed (ob); - - SET_FLAG (ob, FLAG_FREED); - ob->count = 0; - - /* Remove this object from the list of used objects */ - if (ob->prev == NULL) - { - objects = ob->next; - - if (objects != NULL) - objects->prev = NULL; - } - else - { - ob->prev->next = ob->next; - - if (ob->next != NULL) - ob->next->prev = ob->prev; - } + speed = 0; + update_ob_speed (this); - free_key_values (ob); + unlink (); - /* Now link it with the free_objects list: */ - ob->prev = 0; - ob->next = 0; + SET_FLAG (this, FLAG_FREED); - delete ob; + mortals.push_back (this); } /*