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.33 by root, Tue Sep 12 19:20:07 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 */
100 */ 99 */
101 struct object *ACC (RW, env); /* Pointer to the object which is the environment. 100 struct object *ACC (RW, env); /* Pointer to the object which is the environment.
102 * This is typically the container that the object is in. 101 * This is typically the container that the object is in.
103 */ 102 */
104 struct object *ACC (RW, more); /* Pointer to the rest of a large body of objects */ 103 struct object *ACC (RW, more); /* Pointer to the rest of a large body of objects */
105 struct object *ACC (RW, head); /* Points to the main object of a large body */ 104 struct object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different
106 struct mapstruct *ACC (RW, map); /* Pointer to the map in which this object is present */ 105 struct mapstruct *ACC (RW, map); /* Pointer to the map in which this object is present */
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 */
174 struct object *ACC (RW, current_weapon); /* Pointer to the weapon currently used */ 168 struct object *ACC (RW, current_weapon); /* Pointer to the weapon currently used */
175 uint32 ACC (RW, weapontype); /* type of weapon */ 169 uint32 ACC (RW, weapontype); /* type of weapon */
176 uint32 ACC (RW, tooltype); /* type of tool or build facility */ 170 uint32 ACC (RW, tooltype); /* type of tool or build facility */
177 sint8 body_info[NUM_BODY_LOCATIONS]; /* body info as loaded from the file */ 171 sint8 body_info[NUM_BODY_LOCATIONS]; /* body info as loaded from the file */
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 */
180 /* See the doc/Developers/objects for more info about body locations */ 173 /* See the doc/Developers/objects for more info about body locations */
181 174
182 /* Following mostly refers to fields only used for monsters */ 175 /* 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 */ 176 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 */ 177 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 */ 178 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 */ 179 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 */ 180 struct treasureliststruct *ACC (RW, randomitems); /* Items to be generated */
192 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */ 181 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */
222 uint16 ACC (RW, animation_id); /* An index into the animation array */ 211 uint16 ACC (RW, animation_id); /* An index into the animation array */
223 uint8 ACC (RW, anim_speed); /* ticks between animation-frames */ 212 uint8 ACC (RW, anim_speed); /* ticks between animation-frames */
224 uint8 ACC (RW, last_anim); /* last sequence used to draw face */ 213 uint8 ACC (RW, last_anim); /* last sequence used to draw face */
225 sint32 ACC (RW, elevation); /* elevation of this terrain - not currently used */ 214 sint32 ACC (RW, elevation); /* elevation of this terrain - not currently used */
226 uint8 ACC (RW, smoothlevel); /* how to smooth this square around */ 215 uint8 ACC (RW, smoothlevel); /* how to smooth this square around */
216 uint8 ACC (RW, will_apply); /* See crossfire.doc */
227 217
228 MoveType ACC (RW, move_type); /* Type of movement this object uses */ 218 MoveType ACC (RW, move_type); /* Type of movement this object uses */
229 MoveType ACC (RW, move_block); /* What movement types this blocks */ 219 MoveType ACC (RW, move_block); /* What movement types this blocks */
230 MoveType ACC (RW, move_allow); /* What movement types explicitly allowd */ 220 MoveType ACC (RW, move_allow); /* What movement types explicitly allowd */
231 MoveType ACC (RW, move_on); /* Move types affected moving on to this space */ 221 MoveType ACC (RW, move_on); /* Move types affected moving on to this space */
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 // info must hold 256 * 3 bytes currently
243 const char *debug_desc (char *info) const;
244 const char *debug_desc () const;
245
246 // fully recursive iterator
247 struct iterator_base
248 {
249 object *item;
250
251 iterator_base (object *container)
252 : item (container)
253 {
254 }
255
256 operator object *() const { return item; }
257
258 object *operator ->() const { return item; }
259 object &operator * () const { return *item; }
260 };
261
262 // depth-first recursive iterator
263 struct depth_iterator : iterator_base
264 {
265 depth_iterator (object *container);
266 void next ();
267 object *operator ++( ) { next (); return item; }
268 object *operator ++(int) { object *i = item; next (); return i; }
269 };
270
271 object *begin ()
272 {
273 return this;
274 }
275
276 object *end ()
277 {
278 return this;
279 }
280
281protected:
282 friend struct archetype;
283
284 void link ();
285 void unlink ();
286
287 object ();
288 ~object ();
289};
290
238#define get_object() object::create () 291#define get_object() object::create ()
239#define free_object(op) (op)->free (0) 292#define free_object(op) (op)->free (0)
240#define free_object2(op, free_inv) (op)->free (free_inv) 293#define free_object2(op, free_inv) (op)->free (free_inv)
294#define clear_owner(op) (op)->owner = 0
295#define copy_owner(op,other) (op)->owner = (other)->owner
296#define clear_object(op) (op)->clear ()
241 297
242struct object : zero_initialised, object_keep, object_copy, object_pod 298static inline object *
299get_owner (object *op)
243{ 300{
244 static object *create (); 301 return op->get_owner ();
245 void free (bool free_inventory = false); 302}
246 303
247 static void free_mortals (); 304static inline void
248 static bool can_merge (object *op1, object *op2); 305set_owner (object *op, object *owner)
249 306{
250 void clear (); 307 op->set_owner (owner);
251 void clone (object *destination); 308}
252
253protected:
254 friend struct archetype;
255
256 void link ();
257 void unlink ();
258
259 object ();
260 ~object ();
261};
262 309
263#define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2))) 310#define CAN_MERGE(op1,op2) ((op1)->value == (op2)->value && (op1)->name == (op2)->name && object::can_merge ((op1), (op2)))
264 311
265typedef struct oblnk 312typedef struct oblnk
266{ /* Used to link together several objects */ 313{ /* Used to link together several objects */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines