--- deliantra/server/common/object.C 2006/09/04 13:55:54 1.15 +++ deliantra/server/common/object.C 2006/09/08 18:26:22 1.20 @@ -1,6 +1,6 @@ /* * static char *rcsid_object_c = - * "$Id: object.C,v 1.15 2006/09/04 13:55:54 root Exp $"; + * "$Id: object.C,v 1.20 2006/09/08 18:26:22 root Exp $"; */ /* @@ -113,116 +113,134 @@ * check weight */ -int CAN_MERGE(object *ob1, object *ob2) { - - /* A couple quicksanity checks */ - if ((ob1 == ob2) || (ob1->type != ob2->type)) return 0; - - if (ob1->speed != ob2->speed) return 0; - /* Note sure why the following is the case - either the object has to - * be animated or have a very low speed. Is this an attempted monster - * check? - */ - if (!QUERY_FLAG(ob1,FLAG_ANIMATE) && FABS((ob1)->speed) > MIN_ACTIVE_SPEED) - return 0; - - /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that - * value could not be stored in a sint32 (which unfortunately sometimes is - * used to store nrof). - */ - if (ob1->nrof+ob2->nrof >= 1UL<<31) - return 0; - - /* This is really a spellbook check - really, we should - * check all objects in the inventory. - */ - if (ob1->inv || ob2->inv) { - /* if one object has inventory but the other doesn't, not equiv */ - if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) return 0; - - /* Now check to see if the two inventory objects could merge */ - if (!CAN_MERGE(ob1->inv, ob2->inv)) return 0; +bool +object::can_merge (object *ob1, object *ob2) +{ + /* A couple quicksanity checks */ + if ((ob1 == ob2) || (ob1->type != ob2->type)) + return 0; + + if (ob1->speed != ob2->speed) + return 0; + + /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that + * value could not be stored in a sint32 (which unfortunately sometimes is + * used to store nrof). + */ + if (ob1->nrof + ob2->nrof >= 1UL << 31) + return 0; + + /* If the objects have been identified, set the BEEN_APPLIED flag. + * This is to the comparison of the flags below will be OK. We + * just can't ignore the been applied or identified flags, as they + * are not equal - just if it has been identified, the been_applied + * flags lose any meaning. + */ + if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) + SET_FLAG (ob1, FLAG_BEEN_APPLIED); + + if (QUERY_FLAG (ob2, FLAG_IDENTIFIED)) + SET_FLAG (ob2, FLAG_BEEN_APPLIED); + + + /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something + * being locked in inventory should prevent merging. + * 0x4 in flags3 is CLIENT_SENT + */ + if ((ob1->arch != ob2->arch) || + (ob1->flags[0] != ob2->flags[0]) || + (ob1->flags[1] != ob2->flags[1]) || + ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~0x400000)) || + ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) || + (ob1->name != ob2->name) || + (ob1->title != ob2->title) || + (ob1->msg != ob2->msg) || + (ob1->weight != ob2->weight) || + (memcmp (&ob1->resist, &ob2->resist, sizeof (ob1->resist)) != 0) || + (memcmp (&ob1->stats, &ob2->stats, sizeof (ob1->stats)) != 0) || + (ob1->attacktype != ob2->attacktype) || + (ob1->magic != ob2->magic) || + (ob1->slaying != ob2->slaying) || + (ob1->skill != ob2->skill) || + (ob1->value != ob2->value) || + (ob1->animation_id != ob2->animation_id) || + (ob1->client_type != ob2->client_type) || + (ob1->materialname != ob2->materialname) || + (ob1->lore != ob2->lore) || + (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) || + (ob1->move_slow_penalty != ob2->move_slow_penalty)) + return 0; + + /* This is really a spellbook check - really, we should + * check all objects in the inventory. + */ + if (ob1->inv || ob2->inv) + { + /* if one object has inventory but the other doesn't, not equiv */ + if ((ob1->inv && !ob2->inv) || (ob2->inv && !ob1->inv)) + return 0; + + /* Now check to see if the two inventory objects could merge */ + if (!CAN_MERGE (ob1->inv, ob2->inv)) + return 0; - /* inventory ok - still need to check rest of this object to see - * if it is valid. - */ + /* inventory ok - still need to check rest of this object to see + * if it is valid. + */ } - /* If the objects have been identified, set the BEEN_APPLIED flag. - * This is to the comparison of the flags below will be OK. We - * just can't ignore the been applied or identified flags, as they - * are not equal - just if it has been identified, the been_applied - * flags lose any meaning. - */ - if (QUERY_FLAG(ob1, FLAG_IDENTIFIED)) - SET_FLAG(ob1, FLAG_BEEN_APPLIED); + /* Don't merge objects that are applied. With the new 'body' code, + * it is possible for most any character to have more than one of + * some items equipped, and we don't want those to merge. + */ + if (QUERY_FLAG (ob1, FLAG_APPLIED) || QUERY_FLAG (ob2, FLAG_APPLIED)) + return 0; + + /* Note sure why the following is the case - either the object has to + * be animated or have a very low speed. Is this an attempted monster + * check? + */ + if (!QUERY_FLAG (ob1, FLAG_ANIMATE) + && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) + return 0; - if (QUERY_FLAG(ob2, FLAG_IDENTIFIED)) - SET_FLAG(ob2, FLAG_BEEN_APPLIED); + 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 if (!compare_ob_value_lists (ob1, ob2)) + return 0; + } - /* the 0x400000 on flags2 is FLAG_INV_LOCK. I don't think something - * being locked in inventory should prevent merging. - * 0x4 in flags3 is CLIENT_SENT - */ - if ((ob1->arch != ob2->arch) || - (ob1->flags[0] != ob2->flags[0]) || - (ob1->flags[1] != ob2->flags[1]) || - ((ob1->flags[2] & ~0x400000) != (ob2->flags[2] & ~ 0x400000)) || - ((ob1->flags[3] & ~0x4) != (ob2->flags[3] & ~0x4)) || - (ob1->name != ob2->name) || - (ob1->title != ob2->title) || - (ob1->msg != ob2->msg) || - (ob1->weight != ob2->weight) || - (memcmp(&ob1->resist, &ob2->resist, sizeof(ob1->resist))!=0) || - (memcmp(&ob1->stats, &ob2->stats, sizeof(ob1->stats))!=0) || - (ob1->attacktype != ob2->attacktype) || - (ob1->magic != ob2->magic) || - (ob1->slaying != ob2->slaying) || - (ob1->skill != ob2->skill) || - (ob1->value != ob2->value) || - (ob1->animation_id != ob2->animation_id) || - (ob1->client_type != ob2->client_type) || - (ob1->materialname != ob2->materialname) || - (ob1->lore != ob2->lore) || - (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) || - (ob1->move_slow_penalty != ob2->move_slow_penalty) - ) - return 0; - - /* Don't merge objects that are applied. With the new 'body' code, - * it is possible for most any character to have more than one of - * some items equipped, and we don't want those to merge. - */ - if (QUERY_FLAG(ob1, FLAG_APPLIED) || QUERY_FLAG(ob2, FLAG_APPLIED)) - return 0; + //TODO: generate an event or call into perl for additional checks + if (ob1->self || ob2->self) + { + ob1->optimise (); + ob2->optimise (); - 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 if (!compare_ob_value_lists(ob1, ob2)) { - return 0; - } + if (ob1->self || ob2->self) + return 0; } - /* Everything passes, must be OK. */ - return 1; + /* Everything passes, must be OK. */ + return 1; } - /* * sum_weight() is a recursive function which calculates the weight * an object is carrying. It goes through in figures out how much @@ -607,36 +625,26 @@ update_ob_speed (op); } -/* - * 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::object () { - object *op = new object; + count = ++ob_count; - op->count = ++ob_count; - - op->active_next = 0; - op->active_prev = 0; - - op->next = objects; - op->prev = 0; + next = objects; if (objects) - objects->prev = op; + objects->prev = this; - objects = op; + objects = this; - SET_FLAG (op, FLAG_REMOVED); + SET_FLAG (this, FLAG_REMOVED); - op->expmul = 1.0; - op->face = blank_face; - op->attacked_by_count = -1; + expmul = 1.0; + face = blank_face; + attacked_by_count = -1; +} - return op; +object::~object () +{ } /* @@ -810,14 +818,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 @@ -895,7 +910,7 @@ if (ob->inv) { /* Only if the space blocks everything do we not process - - * if some form of movemnt is allowed, let objects + * if some form of movement is allowed, let objects * drop on that space. */ if (free_inventory || ob->map == NULL