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.20 by root, Fri Sep 8 16:51:44 2006 UTC vs.
Revision 1.29 by root, Mon Sep 11 23:33:29 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 uint16 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 */
105 struct object *ACC (RW, head); /* Points to the main object of a large body */ 104 struct object *ACC (RW, head); /* Points to the main object of a large body */
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 */
151 uint32 ACC (RW, path_denied); /* Paths the object is denied access to */ 145 uint32 ACC (RW, path_denied); /* Paths the object is denied access to */
152 uint16 ACC (RW, material); /* What materials this object consist of */ 146 uint16 ACC (RW, material); /* What materials this object consist of */
153 sint8 ACC (RW, magic); /* Any magical bonuses to this item */ 147 sint8 ACC (RW, magic); /* Any magical bonuses to this item */
154 uint8 ACC (RW, state); /* How the object was last drawn (animation) */ 148 uint8 ACC (RW, state); /* How the object was last drawn (animation) */
155 sint32 ACC (RW, value); /* How much money it is worth (or contains) */ 149 sint32 ACC (RW, value); /* How much money it is worth (or contains) */
156 sint16 ACC (RW, level); /* Level of creature or object */
157 /* Note that the last_.. values are sometimes used for non obvious 150 /* Note that the last_.. values are sometimes used for non obvious
158 * meanings by some objects, eg, sp penalty, permanent exp. 151 * meanings by some objects, eg, sp penalty, permanent exp.
159 */ 152 */
160 sint32 ACC (RW, last_heal); /* Last healed. Depends on constitution */ 153 sint32 ACC (RW, last_heal); /* Last healed. Depends on constitution */
161 sint32 ACC (RW, last_sp); /* As last_heal, but for spell points */ 154 sint32 ACC (RW, last_sp); /* As last_heal, but for spell points */
162 sint16 ACC (RW, last_grace); /* as last_sp, except for grace */ 155 sint16 ACC (RW, last_grace); /* as last_sp, except for grace */
163 sint16 ACC (RW, last_eat); /* How long since we last ate */ 156 sint16 ACC (RW, last_eat); /* How long since we last ate */
164 sint16 ACC (RW, invisible); /* How much longer the object will be invis */ 157 sint16 ACC (RW, invisible); /* How much longer the object will be invis */
158 sint16 ACC (RW, level); /* Level of creature or object */
165 uint8 ACC (RW, pick_up); /* See crossfire.doc */ 159 uint8 ACC (RW, pick_up); /* See crossfire.doc */
166 sint8 ACC (RW, item_power); /* power rating of the object */ 160 sint8 ACC (RW, item_power); /* power rating of the object */
167 sint8 ACC (RW, gen_sp_armour); /* sp regen penalty this object has (was last_heal) */ 161 sint8 ACC (RW, gen_sp_armour); /* sp regen penalty this object has (was last_heal) */
162 sint8 ACC (RW, glow_radius); /* indicates the glow radius of the object */
168 sint32 ACC (RW, weight); /* Attributes of the object */ 163 sint32 ACC (RW, weight); /* Attributes of the object */
169 sint32 ACC (RW, weight_limit); /* Weight-limit of object */ 164 sint32 ACC (RW, weight_limit); /* Weight-limit of object */
170 sint32 ACC (RW, carrying); /* How much weight this object contains */ 165 sint32 ACC (RW, carrying); /* How much weight this object contains */
171 sint8 ACC (RW, glow_radius); /* indicates the glow radius of the object */
172 living ACC (RO, stats); /* Str, Con, Dex, etc */ 166 living ACC (RO, stats); /* Str, Con, Dex, etc */
173 sint64 ACC (RW, perm_exp); /* Permanent exp */ 167 sint64 ACC (RW, perm_exp); /* Permanent exp */
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 */
173 uint8 ACC (RW, will_apply); /* See crossfire.doc */
179 /* See the doc/Developers/objects for more info about body locations */ 174 /* See the doc/Developers/objects for more info about body locations */
180 175
181 /* Following mostly refers to fields only used for monsters */ 176 /* Following mostly refers to fields only used for monsters */
182 struct object *ACC (RW, owner); /* Pointer to the object which controls this one */
183 /* Owner should not be referred to directly - */
184 /* get_owner should be used instead. */
185 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
186 /* has been freed) */
187 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 */
188 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 */
189 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 */
190 struct treasureliststruct *ACC (RW, randomitems); /* Items to be generated */ 181 struct treasureliststruct *ACC (RW, randomitems); /* Items to be generated */
191 uint16 ACC (RW, run_away); /* Monster runs away if it's hp goes below this percentage. */
192 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */ 182 struct object *ACC (RW, chosen_skill); /* the skill chosen to use */
193 uint32 ACC (RW, hide); /* The object is hidden, not invisible */ 183 uint32 ACC (RW, hide); /* The object is hidden, not invisible */
194 /* changes made by kholland@sunlab.cit.cornell.edu */ 184 /* changes made by kholland@sunlab.cit.cornell.edu */
195 /* allows different movement patterns for attackers */ 185 /* allows different movement patterns for attackers */
196 sint32 ACC (RW, move_status); /* What stage in attack mode */ 186 sint32 ACC (RW, move_status); /* What stage in attack mode */
197 uint16 ACC (RW, attack_movement); /* What kind of attack movement */ 187 uint16 ACC (RW, attack_movement); /* What kind of attack movement */
198 uint8 ACC (RW, will_apply); /* See crossfire.doc */ 188 uint16 ACC (RW, run_away); /* Monster runs away if it's hp goes below this percentage. */
199 struct object *ACC (RW, spellitem); /* Spell ability monster is choosing to use */ 189 struct object *ACC (RW, spellitem); /* Spell ability monster is choosing to use */
200 double ACC (RW, expmul); /* needed experience = (calc_exp*expmul) - means some */ 190 float ACC (RW, expmul); /* needed experience = (calc_exp*expmul) - means some */
201 /* races/classes can need less/more exp to gain levels */ 191 /* races/classes can need less/more exp to gain levels */
202 192
203 /* Spell related information, may be useful elsewhere 193 /* Spell related information, may be useful elsewhere
204 * Note that other fields are used - these files are basically 194 * Note that other fields are used - these files are basically
205 * only used in spells. 195 * only used in spells.
206 */ 196 */
207 sint16 ACC (RW, duration); /* How long the spell lasts */ 197 sint16 ACC (RW, duration); /* How long the spell lasts */
198 sint16 ACC (RW, casting_time); /* time left before spell goes off */
199 uint16 ACC (RW, start_holding);
200 struct object *ACC (RW, spell); /* Spell that was being cast */
201 char *ACC (RW, spellarg);
208 uint8 ACC (RW, duration_modifier); /* how level modifies duration */ 202 uint8 ACC (RW, duration_modifier); /* how level modifies duration */
209 sint16 ACC (RW, casting_time); /* time left before spell goes off */
210 struct object *ACC (RW, spell); /* Spell that was being cast */
211 uint16 ACC (RW, start_holding);
212 char *ACC (RW, spellarg);
213 uint8 ACC (RW, dam_modifier); /* How going up in level effects damage */ 203 uint8 ACC (RW, dam_modifier); /* How going up in level effects damage */
214 sint8 ACC (RW, range); /* Range of the spell */ 204 sint8 ACC (RW, range); /* Range of the spell */
215 uint8 ACC (RW, range_modifier); /* How going up in level effects range */ 205 uint8 ACC (RW, range_modifier); /* How going up in level effects range */
216 206
217 /* Following are values used by any object */ 207 /* Following are values used by any object */
218 struct archt *ACC (RW, arch); /* Pointer to archetype */ 208 struct archetype *ACC (RW, arch); /* Pointer to archetype */
219 struct archt *ACC (RW, other_arch); /* Pointer used for various things - mostly used for what */ 209 struct archetype *ACC (RW, other_arch); /* Pointer used for various things - mostly used for what */
220 /* this objects turns into or what this object creates */ 210 /* this objects turns into or what this object creates */
221 uint32 flags[4]; /* various flags */ 211 uint32 flags[4]; /* various flags */
222 uint16 ACC (RW, animation_id); /* An index into the animation array */ 212 uint16 ACC (RW, animation_id); /* An index into the animation array */
223 uint8 ACC (RW, anim_speed); /* ticks between animation-frames */ 213 uint8 ACC (RW, anim_speed); /* ticks between animation-frames */
224 uint8 ACC (RW, last_anim); /* last sequence used to draw face */ 214 uint8 ACC (RW, last_anim); /* last sequence used to draw face */
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
238struct object : zero_initialised, object_keep, object_copy, object_pod 228struct object : zero_initialised, object_keep, object_copy, object_pod
239{ 229{
230 static object *create ();
231 void free (bool free_inventory = false);
232
233 static void free_mortals ();
240 static bool can_merge (object * op1, object * op2); 234 static bool can_merge (object *op1, object *op2);
241 235
242 void clear (); 236 void clear ();
243 void clone (object * destination); 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 *item)
248 : item(item)
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 struct deep_iterator : iterator_base
259 {
260 deep_iterator (object *op) : iterator_base (op) { }
261
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->inv ? this->inv : end ();
270 }
271
272 object *end ()
273 {
274 return this->below;
275 }
276
277protected:
278 friend struct archetype;
279
280 void link ();
281 void unlink ();
282
283 object ();
284 ~object ();
244}; 285};
286
287#define get_object() object::create ()
288#define free_object(op) (op)->free (0)
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 ()
293
294static inline object *
295get_owner (object *op)
296{
297 return op->get_owner ();
298}
299
300static inline void
301set_owner (object *op, object *owner)
302{
303 op->set_owner (owner);
304}
245 305
246#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)))
247 307
248typedef struct oblnk 308typedef struct oblnk
249{ /* Used to link together several objects */ 309{ /* Used to link together several objects */
267 * object and pointers. This structure should get removed, and just replaced 327 * object and pointers. This structure should get removed, and just replaced
268 * by the object structure 328 * by the object structure
269 */ 329 */
270 330
271ACC_CLASS(archetype) 331ACC_CLASS(archetype)
272struct archt : zero_initialised 332struct archetype : zero_initialised
273{ 333{
334 archetype ();
335 ~archetype ();
336
274 shstr ACC (RW, name); /* More definite name, like "generate_kobold" */ 337 shstr ACC (RW, name); /* More definite name, like "generate_kobold" */
275 struct archt *ACC (RW, next); /* Next archetype in a linked list */ 338 struct archetype *ACC (RW, next); /* Next archetype in a linked list */
276 struct archt *ACC (RW, head); /* The main part of a linked object */ 339 struct archetype *ACC (RW, head); /* The main part of a linked object */
277 struct archt *ACC (RW, more); /* Next part of a linked object */ 340 struct archetype *ACC (RW, more); /* Next part of a linked object */
278 object ACC (RO, clone); /* An object from which to do copy_object() */ 341 object ACC (RO, clone); /* An object from which to do copy_object() */
279 uint32 ACC (RW, editable); /* editable flags (mainly for editor) */ 342 uint32 ACC (RW, editable); /* editable flags (mainly for editor) */
280 sint8 ACC (RW, tail_x), ACC (RW, tail_y); /* Where the lower right most portion of the object is 343 sint8 ACC (RW, tail_x), ACC (RW, tail_y); /* Where the lower right most portion of the object is
281 * in comparison to the head. 344 * in comparison to the head.
282 */ 345 */
283} archetype; 346};
284 347
285extern object *objects; 348extern object *objects;
286extern object *active_objects; 349extern object *active_objects;
287 350
288extern int nrofallocobjects; 351extern int nrofallocobjects;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines