--- deliantra/server/common/object.C 2010/05/06 21:45:49 1.337 +++ deliantra/server/common/object.C 2011/05/01 16:58:15 1.345 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2001 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * @@ -73,6 +73,25 @@ 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 }; +const char *wall_suffix[16] = { + "0", + "1_3", + "1_4", + "2_1_2", + "1_2", + "2_2_4", + "2_2_1", + "3_1", + "1_1", + "2_2_3", + "2_2_2", + "3_3", + "2_1_1", + "3_4", + "3_2", + "4" +}; + static void write_uuid (uval64 skip, bool sync) { @@ -216,14 +235,14 @@ static bool compare_ob_value_lists_one (const object *wants, const object *has) { - /* n-squared behaviour (see kv_get), but I'm hoping both + /* n-squared behaviour (see kv.get), but I'm hoping both * objects with lists are rare, and lists stay short. If not, use a * different structure or at least keep the lists sorted... */ /* For each field in wants, */ - for (key_value *kv = wants->key_values; kv; kv = kv->next) - if (has->kv_get (kv->key) != kv->value) + for (key_value *kv = wants->kv.first; kv; kv = kv->next) + if (has->kv.get (kv->key) != kv->value) return false; /* If we get here, every field in wants has a matching field in has. */ @@ -257,9 +276,10 @@ { /* A couple quick sanity checks */ if (ob1 == ob2 - || ob1->type != ob2->type - || ob1->value != ob2->value - || ob1->name != ob2->name + || ob1->type != ob2->type + || ob1->value != ob2->value + || ob1->name != ob2->name + || ob1->custom_name != ob2->custom_name || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED) return 0; @@ -355,10 +375,10 @@ break; } - if (ob1->key_values || ob2->key_values) + if (!ob1->kv.empty () || !ob2->kv.empty ()) { /* At least one of these has key_values. */ - if ((!ob1->key_values) != (!ob2->key_values)) + if (ob1->kv.empty () != ob2->kv.empty ()) return 0; /* One has fields, but the other one doesn't. */ if (!compare_ob_value_lists (ob1, ob2)) @@ -581,23 +601,6 @@ this->owner = owner; } -/* Zero the key_values on op, decrementing the shared-string - * refcounts and freeing the links. - */ -static void -free_key_values (object *op) -{ - for (key_value *i = op->key_values; i; ) - { - key_value *next = i->next; - delete i; - - i = next; - } - - op->key_values = 0; -} - /* * copy_to first frees everything allocated by the dst object, * and then copies the contents of itself into the second @@ -611,36 +614,11 @@ { dst->remove (); *(object_copy *)dst = *this; - dst->flag [FLAG_REMOVED] = true; - - /* Copy over key_values, if any. */ - if (key_values) - { - key_value *tail = 0; - dst->key_values = 0; - - for (key_value *i = key_values; i; i = i->next) - { - key_value *new_link = new key_value; - - new_link->next = 0; - new_link->key = i->key; - new_link->value = i->value; - /* Try and be clever here, too. */ - if (!dst->key_values) - { - dst->key_values = new_link; - tail = new_link; - } - else - { - tail->next = new_link; - tail = new_link; - } - } - } + // maybe move to object_copy? + dst->kv = kv; + dst->flag [FLAG_REMOVED] = true; dst->activate (); } @@ -650,7 +628,7 @@ if (!uuid.seq) // HACK uuid = UUID::gen (); - // TODO: unclean state changes, should nt be done in copy_to AND instantiate + // TODO: unclean state changes, should not be done in copy_to AND instantiate if (flag [FLAG_RANDOM_SPEED] && speed) speed_left = - speed - rndm (); // TODO animation else @@ -813,7 +791,7 @@ { unlink (); - free_key_values (this); + kv.clear (); } void object::link () @@ -1165,14 +1143,14 @@ { if (expect_false (pl->contr->combat_ob == this)) { - pl->apply (pl->contr->combat_ob, AP_UNAPPLY); + pl->apply (pl->contr->combat_ob, AP_UNAPPLY | AP_IGNORE_CURSE); pl->contr->combat_ob = 0; if (pl->contr->ranged_ob) pl->apply (pl->contr->ranged_ob); } if (expect_false (pl->contr->ranged_ob == this)) { - pl->apply (pl->contr->ranged_ob, AP_UNAPPLY); + pl->apply (pl->contr->ranged_ob, AP_UNAPPLY | AP_IGNORE_CURSE); pl->contr->ranged_ob = 0; if (pl->contr->combat_ob) pl->apply (pl->contr->combat_ob); } @@ -1369,7 +1347,7 @@ if (m == &freed_map)//D TODO: remove soon {//D - LOG (llevError | logBacktrace, "tries to insret object on freed objects map: %s", op->debug_desc ());//D + LOG (llevError | logBacktrace, "tries to insert object on freed objects map: %s", op->debug_desc ());//D }//D /* Ideally, the caller figures this out. However, it complicates a lot @@ -2476,10 +2454,26 @@ return 0; } +/* Zero the key_values on op, decrementing the shared-string + * refcounts and freeing the links. + */ +void +key_values::clear () +{ + for (key_value *kvp = first; kvp; ) + { + key_value *next = kvp->next; + delete kvp; + kvp = next; + } + + first = 0; +} + shstr_tmp -object::kv_get (shstr_tmp key) const +key_values::get (shstr_tmp key) const { - for (key_value *kv = key_values; kv; kv = kv->next) + for (key_value *kv = first; kv; kv = kv->next) if (kv->key == key) return kv->value; @@ -2487,28 +2481,34 @@ } void -object::kv_set (shstr_tmp key, shstr_tmp value) +key_values::add (shstr_tmp key, shstr_tmp value) { - for (key_value *kv = key_values; kv; kv = kv->next) + key_value *kv = new key_value; + + kv->next = first; + kv->key = key; + kv->value = value; + + first = kv; +} + +void +key_values::set (shstr_tmp key, shstr_tmp value) +{ + for (key_value *kv = first; kv; kv = kv->next) if (kv->key == key) { kv->value = value; return; } - key_value *kv = new key_value; - - kv->next = key_values; - kv->key = key; - kv->value = value; - - key_values = kv; + add (key, value); } void -object::kv_del (shstr_tmp key) +key_values::del (shstr_tmp key) { - for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) + for (key_value **kvp = &first; *kvp; kvp = &(*kvp)->next) if ((*kvp)->key == key) { key_value *kv = *kvp; @@ -2518,6 +2518,34 @@ } } +void +key_values::reverse () +{ + key_value *prev = 0; + key_value *head = first; + + while (head) + { + key_value *node = head; + head = head->next; + node->next = prev; + prev = node; + } + + first = prev; +} + +key_values & +key_values::operator =(const key_values &kv) +{ + clear (); + + for (key_value *kvp = kv.first; kvp; kvp = kvp->next) + add (kvp->key, kvp->value); + + reverse (); +} + object::depth_iterator::depth_iterator (object *container) : iterator_base (container) { @@ -2705,7 +2733,7 @@ if (object *force = force_find (name)) force->destroy (); - object *force = get_archetype (FORCE_NAME); + object *force = archetype::get (FORCE_NAME); force->slaying = name; force->force_set_timer (duration); @@ -2799,3 +2827,13 @@ return 0; } +// put marked object first in the inventory +// this is used by identify-like spells so players can influence +// the order a bit. +void +object::splay_marked () +{ + if (object *marked = mark ()) + splay (marked); +} +