ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/object.h
(Generate patch)

Comparing deliantra/server/include/object.h (file contents):
Revision 1.26 by root, Mon Sep 11 11:15:21 2006 UTC vs.
Revision 1.30 by root, Tue Sep 12 01:09:53 2006 UTC

62/* Definition for WILL_APPLY values. Replaces having harcoded values 62/* Definition for WILL_APPLY values. Replaces having harcoded values
63 * sprinkled in the code. Note that some of these also replace fields 63 * sprinkled in the code. Note that some of these also replace fields
64 * that were in the can_apply area. What is the point of having both 64 * that were in the can_apply area. What is the point of having both
65 * can_apply and will_apply? 65 * can_apply and will_apply?
66 */ 66 */
67#define WILL_APPLY_HANDLE 0x1 67#define WILL_APPLY_HANDLE 0x01
68#define WILL_APPLY_TREASURE 0x2 68#define WILL_APPLY_TREASURE 0x02
69#define WILL_APPLY_EARTHWALL 0x4 69#define WILL_APPLY_EARTHWALL 0x04
70#define WILL_APPLY_DOOR 0x8 70#define WILL_APPLY_DOOR 0x08
71#define WILL_APPLY_FOOD 0x10 71#define WILL_APPLY_FOOD 0x10
72 72
73 73
74/* However, if you're keeping a pointer of some sort, you probably 74/* However, if you're keeping a pointer of some sort, you probably
75 * don't just want it copied, so you'll need to add to common/object.C, 75 * don't just want it copied, so you'll need to add to common/object.C,
76 * e.g. copy_object. 76 * e.g. copy_object.
77 */ 77 */
78 78
79// these are not being copied 79// these are not being copied
80ACC_CLASS (object) 80ACC_CLASS (object)
81struct object_keep 81struct object_keep : refcounted
82{ 82{
83 tag_t ACC (RW, count); /* Unique object number for this object */ 83 tag_t ACC (RW, count); /* Unique object number for this object */
84 sint32 ACC (RW, refcount); /* How many objects points to this object */
85 84
86 /* These variables are not changed by copy_object() */ 85 /* These variables are not changed by copy_object() */
87 struct pl *ACC (RW, contr); /* Pointer to the player which control this object */ 86 struct pl *ACC (RW, contr); /* Pointer to the player which control this object */
88 struct object *ACC (RW, next); /* Pointer to the next object in the free/used list */ 87 struct object *ACC (RW, next); /* Pointer to the next object in the free/used list */
89 struct object *ACC (RW, prev); /* Pointer to the previous object in the free/used list */ 88 struct object *ACC (RW, prev); /* Pointer to the previous object in the free/used list */
107}; 106};
108 107
109// these are being copied 108// these are being copied
110struct object_copy : attachable<object> 109struct object_copy : attachable<object>
111{ 110{
112 /* These get an extra add_refcount(), after having been copied by memcpy(). 111 refptr<object> ACC (RW, owner); /* Pointer to the object which controls this one */
113 * All fields beow this point are automatically copied by memcpy. If
114 * adding something that needs a refcount updated, make sure you modify
115 * copy_object to do so. Everything below here also gets cleared
116 * by clear_object()
117 */
118 shstr ACC (RW, name); /* The name of the object, obviously... */ 112 shstr ACC (RW, name); /* The name of the object, obviously... */
119 shstr ACC (RW, name_pl); /* The plural name of the object */ 113 shstr ACC (RW, name_pl); /* The plural name of the object */
120 shstr ACC (RW, title); /* Of foo, etc */ 114 shstr ACC (RW, title); /* Of foo, etc */
121 shstr ACC (RW, race); /* human, goblin, dragon, etc */ 115 shstr ACC (RW, race); /* human, goblin, dragon, etc */
122 shstr ACC (RW, slaying); /* Which race to do double damage to */ 116 shstr ACC (RW, slaying); /* Which race to do double damage to */
178 sint8 body_used[NUM_BODY_LOCATIONS]; /* Calculated value based on items equipped */ 172 sint8 body_used[NUM_BODY_LOCATIONS]; /* Calculated value based on items equipped */
179 uint8 ACC (RW, will_apply); /* See crossfire.doc */ 173 uint8 ACC (RW, will_apply); /* See crossfire.doc */
180 /* See the doc/Developers/objects for more info about body locations */ 174 /* See the doc/Developers/objects for more info about body locations */
181 175
182 /* Following mostly refers to fields only used for monsters */ 176 /* Following mostly refers to fields only used for monsters */
183 struct object *ACC (RW, owner); /* Pointer to the object which controls this one */
184 /* Owner should not be referred to directly - */
185 /* get_owner should be used instead. */
186 tag_t ACC (RW, ownercount); /* What count the owner had (in case owner */ 177 tag_t ACC (RW, ownercount); /* What count the owner had (in case owner has been freed) *///TODO: remove/fix
187 /* has been freed) */
188 struct object *ACC (RW, enemy); /* Monster/player to follow even if not closest */ 178 struct object *ACC (RW, enemy); /* Monster/player to follow even if not closest */
189 struct object *ACC (RW, attacked_by); /* This object start to attack us! only player & monster */ 179 struct object *ACC (RW, attacked_by); /* This object start to attack us! only player & monster */
190 tag_t ACC (RW, attacked_by_count); /* the tag of attacker, so we can be sure */ 180 tag_t ACC (RW, attacked_by_count); /* the tag of attacker, so we can be sure */
191 struct treasureliststruct *ACC (RW, randomitems); /* Items to be generated */ 181 struct treasureliststruct *ACC (RW, randomitems); /* Items to be generated */
192 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */ 182 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */
233 MoveType ACC (RW, move_slow); /* Movement types this slows down */ 223 MoveType ACC (RW, move_slow); /* Movement types this slows down */
234 float ACC (RW, move_slow_penalty); /* How much this slows down the object */ 224 float ACC (RW, move_slow_penalty); /* How much this slows down the object */
235 key_value *key_values; /* Fields not explictly known by the loader. */ 225 key_value *key_values; /* Fields not explictly known by the loader. */
236}; 226};
237 227
228struct object : zero_initialised, object_keep, object_copy, object_pod
229{
230 static object *create ();
231 void free (bool free_inventory = false);
232
233 static void free_mortals ();
234 static bool can_merge (object *op1, object *op2);
235
236 void clear ();
237 void clone (object *destination);
238
239 void set_owner (object *owner);
240 object *get_owner ();
241
242 // fully recursive iterator
243 struct iterator_base
244 {
245 object *item;
246
247 iterator_base (object *container)
248 : item (container)
249 {
250 }
251
252 operator object *() const { return item; }
253
254 object *operator ->() const { return item; }
255 object &operator * () const { return *item; }
256 };
257
258 // depth-first recursive iterator
259 struct depth_iterator : iterator_base
260 {
261 depth_iterator (object *container);
262 void next ();
263 object *operator ++( ) { next (); return item; }
264 object *operator ++(int) { object *i = item; next (); return i; }
265 };
266
267 object *begin ()
268 {
269 return this;
270 }
271
272 object *end ()
273 {
274 return this;
275 }
276
277protected:
278 friend struct archetype;
279
280 void link ();
281 void unlink ();
282
283 object ();
284 ~object ();
285};
286
238#define get_object() object::create () 287#define get_object() object::create ()
239#define free_object(op) (op)->free (0) 288#define free_object(op) (op)->free (0)
240#define free_object2(op, free_inv) (op)->free (free_inv) 289#define free_object2(op, free_inv) (op)->free (free_inv)
290#define clear_owner(op) (op)->owner = 0
291#define copy_owner(op,other) (op)->owner = (other)->owner
292#define clear_object(op) (op)->clear ()
241 293
242struct object : zero_initialised, object_keep, object_copy, object_pod 294static inline object *
295get_owner (object *op)
243{ 296{
244 static object *create (); 297 return op->get_owner ();
245 void free (bool free_inventory = false); 298}
246 299
247 static void free_mortals (); 300static inline void
248 static bool can_merge (object *op1, object *op2); 301set_owner (object *op, object *owner)
249 302{
250 void clear (); 303 op->set_owner (owner);
251 void clone (object *destination); 304}
252
253protected:
254 friend struct archetype;
255
256 void link ();
257 void unlink ();
258
259 object ();
260 ~object ();
261};
262 305
263#define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2))) 306#define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2)))
264 307
265typedef struct oblnk 308typedef struct oblnk
266{ /* Used to link together several objects */ 309{ /* Used to link together several objects */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines