--- deliantra/server/include/object.h 2010/10/11 18:40:43 1.257 +++ deliantra/server/include/object.h 2011/05/03 11:23:48 1.260 @@ -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 * @@ -75,10 +75,59 @@ */ struct key_value : slice_allocated { - key_value *next; + key_value *next; // must be first element shstr key, value; }; +// "crossfires version of a perl hash." +struct key_values +{ + key_value *first; // must be first element + + bool empty() const + { + return !first; + } + + void clear (); + shstr_tmp get (shstr_tmp key) const; + void del (shstr_tmp key); + void set (shstr_tmp key, shstr_tmp value); + + void add (shstr_tmp key, shstr_tmp value); // liek set, but doesn't check for duplicates + void reverse (); // reverses the ordering, to be used after loading an object + key_values &operator =(const key_values &kv); + + // custom extra fields management + struct access_proxy + { + key_values &kv; + shstr_tmp key; + + access_proxy (key_values &kv, shstr_tmp key) + : kv (kv), key (key) + { + } + + const access_proxy &operator =(shstr_tmp value) const + { + kv.set (key, value); + return *this; + } + + operator const shstr_tmp () const { return kv.get (key); } + operator const char *() const { return kv.get (key); } + + private: + void operator =(int); + }; + + const access_proxy operator [](shstr_tmp key) + { + return access_proxy (*this, key); + } +}; + //-GPL struct UUID @@ -324,7 +373,6 @@ */ object *ACC (RW, more); /* Pointer to the rest of a large body of objects */ object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different - key_value *key_values; /* Fields not explictly known by the loader. */ MTH void set_flag (int flagnum) { @@ -336,43 +384,11 @@ flag [flagnum] = false; } - // privates / perl - shstr_tmp kv_get (shstr_tmp key) const; - void kv_del (shstr_tmp key); - void kv_set (shstr_tmp key, shstr_tmp value); + // extra key value pairs + key_values kv; //-GPL - // custom extra fields management - struct key_value_access_proxy - { - object &ob; - shstr_tmp key; - - key_value_access_proxy (object &ob, shstr_tmp key) - : ob (ob), key (key) - { - } - - const key_value_access_proxy &operator =(shstr_tmp value) const - { - ob.kv_set (key, value); - return *this; - } - - operator const shstr_tmp () const { return ob.kv_get (key); } - operator const char *() const { return ob.kv_get (key); } - - private: - void operator =(int); - }; - - // operator [] is too annoying to use - const key_value_access_proxy kv (shstr_tmp key) - { - return key_value_access_proxy (*this, key); - } - bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all MTH void post_load_check (); // do some adjustments after parsing static object *read (object_thawer &f, maptile *map = 0); // map argument due to toal design bogosity, must go. @@ -687,6 +703,9 @@ MTH void activate_recursive (); MTH void deactivate_recursive (); + // prefetch and activate the surrounding area + MTH void prefetch_surrounding_maps (); + // set the given flag on all objects in the inventory recursively MTH void set_flag_inv (int flag, int value = 1);