ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/object.h
Revision: 1.17
Committed: Sun Sep 3 22:45:56 2006 UTC (17 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.16: +0 -5 lines
Log Message:
string scanning (e.g. for patch) is not implemented ATM but should be easy
to add with an alternative constructor for object_thawer.

Rewrote flex scanner to be simpler, faster and more modularised.

Initial speedup: 16%

(ah well)

File Contents

# Content
1 /*
2 CrossFire, A Multiplayer game for X-windows
3
4 Copyright (C) 2001 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 The authors can be reached via e-mail at crossfire-devel@real-time.com
22 */
23
24 #ifndef OBJECT_H
25 #define OBJECT_H
26
27 #include "cfperl.h"
28 #include "shstr.h"
29
30 typedef uint32 tag_t;
31 #define NUM_BODY_LOCATIONS 12
32 #define BODY_ARMS 1
33
34 /* See common/item.c */
35
36 typedef struct Body_Locations {
37 const char *save_name; /* Name used to load/save it to disk */
38 const char *use_name; /* Name used when describing an item we can use */
39 const char *nonuse_name; /* Name to describe objects we can't use */
40 } Body_Locations;
41
42 extern Body_Locations body_locations[NUM_BODY_LOCATIONS];
43
44 /*
45 * Each object (this also means archetypes!) could have a few of these
46 * "dangling" from it; this could also end up containing 'parse errors'.
47 *
48 * key and value are shared-strings.
49 *
50 * Please use get_ob_key_value(), set_ob_key_value() from object.c rather than
51 * accessing the list directly.
52 * Exception is if you want to walk this list for some reason.
53 */
54 struct key_value {
55 key_value *next;
56 shstr key, value;
57 };
58
59
60 /* Definition for WILL_APPLY values. Replaces having harcoded values
61 * sprinkled in the code. Note that some of these also replace fields
62 * that were in the can_apply area. What is the point of having both
63 * can_apply and will_apply?
64 */
65 #define WILL_APPLY_HANDLE 0x1
66 #define WILL_APPLY_TREASURE 0x2
67 #define WILL_APPLY_EARTHWALL 0x4
68 #define WILL_APPLY_DOOR 0x8
69 #define WILL_APPLY_FOOD 0x10
70
71
72 /* However, if you're keeping a pointer of some sort, you probably
73 * don't just want it copied, so you'll need to add to common/object.C,
74 * e.g. copy_object.
75 */
76
77 struct object_simple : attachable<object> {
78 tag_t count; /* Unique object number for this object */
79 uint16 refcount; /* How many objects points to this object */
80
81 /* These variables are not changed by copy_object() */
82 struct pl *contr; /* Pointer to the player which control this object */
83 struct object *next; /* Pointer to the next object in the free/used list */
84 struct object *prev; /* Pointer to the previous object in the free/used list*/
85 struct object *active_next; /* Next & previous object in the 'active' */
86 struct object *active_prev; /* List. This is used in process_events */
87 /* so that the entire object list does not */
88 /* need to be gone through. */
89 struct object *below; /* Pointer to the object stacked below this one */
90 struct object *above; /* Pointer to the object stacked above this one */
91 /* Note: stacked in the *same* environment*/
92 struct object *inv; /* Pointer to the first object in the inventory */
93 struct object *container; /* Current container being used. I think this
94 * is only used by the player right now.
95 */
96 struct object *env; /* Pointer to the object which is the environment.
97 * This is typically the container that the object is in.
98 */
99 struct object *more; /* Pointer to the rest of a large body of objects */
100 struct object *head; /* Points to the main object of a large body */
101 struct mapstruct *map; /* Pointer to the map in which this object is present */
102 };
103
104 struct object_special {
105 /* These get an extra add_refcount(), after having been copied by memcpy().
106 * All fields beow this point are automatically copied by memcpy. If
107 * adding something that needs a refcount updated, make sure you modify
108 * copy_object to do so. Everything below here also gets cleared
109 * by clear_object()
110 */
111 shstr name; /* The name of the object, obviously... */
112 shstr name_pl; /* The plural name of the object */
113 shstr title; /* Of foo, etc */
114 shstr race; /* human, goblin, dragon, etc */
115 shstr slaying; /* Which race to do double damage to */
116 /* If this is an exit, this is the filename */
117 shstr skill; /* Name of the skill this object uses/grants */
118 shstr msg; /* If this is a book/sign/magic mouth/etc */
119 shstr lore; /* Obscure information about this object, */
120 /* To get put into books and the like. */
121
122 sint16 x,y; /* Position in the map for this object */
123 float speed; /* The overall speed of this object */
124 float speed_left; /* How much speed is left to spend this round */
125 uint32 nrof; /* How many of the objects */
126 New_Face *face; /* Face with colors */
127 sint8 direction; /* Means the object is moving that way. */
128 sint8 facing; /* Object is oriented/facing that way. */
129
130 /* This next big block are basically used for monsters and equipment */
131 uint8 type; /* PLAYER, BULLET, etc. See define.h */
132 uint8 subtype; /* subtype of object */
133 uint16 client_type; /* Public type information. see doc/Developers/objects */
134 sint16 resist[NROFATTACKS]; /* Resistance adjustments for attacks */
135 uint32 attacktype; /* Bitmask of attacks this object does */
136 uint32 path_attuned; /* Paths the object is attuned to */
137 uint32 path_repelled; /* Paths the object is repelled from */
138 uint32 path_denied; /* Paths the object is denied access to */
139 uint16 material; /* What materials this object consist of */
140 shstr materialname; /* specific material name */
141 sint8 magic; /* Any magical bonuses to this item */
142 uint8 state; /* How the object was last drawn (animation) */
143 sint32 value; /* How much money it is worth (or contains) */
144 sint16 level; /* Level of creature or object */
145 /* Note that the last_.. values are sometimes used for non obvious
146 * meanings by some objects, eg, sp penalty, permanent exp.
147 */
148 sint32 last_heal; /* Last healed. Depends on constitution */
149 sint32 last_sp; /* As last_heal, but for spell points */
150 sint16 last_grace; /* as last_sp, except for grace */
151 sint16 last_eat; /* How long since we last ate */
152 sint16 invisible; /* How much longer the object will be invis */
153 uint8 pick_up; /* See crossfire.doc */
154 sint8 item_power; /* power rating of the object */
155 sint8 gen_sp_armour; /* sp regen penalty this object has (was last_heal)*/
156 sint32 weight; /* Attributes of the object */
157 sint32 weight_limit; /* Weight-limit of object */
158 sint32 carrying; /* How much weight this object contains */
159 sint8 glow_radius; /* indicates the glow radius of the object */
160 living stats; /* Str, Con, Dex, etc */
161 sint64 perm_exp; /* Permanent exp */
162 struct object *current_weapon; /* Pointer to the weapon currently used */
163 uint32 weapontype; /* type of weapon */
164 uint32 tooltype; /* type of tool or build facility */
165 sint8 body_info[NUM_BODY_LOCATIONS]; /* body info as loaded from the file */
166 sint8 body_used[NUM_BODY_LOCATIONS]; /* Calculated value based on items equipped */
167 /* See the doc/Developers/objects for more info about body locations */
168
169 /* Following mostly refers to fields only used for monsters */
170 struct object *owner; /* Pointer to the object which controls this one */
171 /* Owner should not be referred to directly - */
172 /* get_owner should be used instead. */
173 tag_t ownercount; /* What count the owner had (in case owner */
174 /* has been freed) */
175 struct object *enemy; /* Monster/player to follow even if not closest */
176 struct object *attacked_by; /* This object start to attack us! only player & monster */
177 tag_t attacked_by_count; /* the tag of attacker, so we can be sure */
178 struct treasureliststruct *randomitems; /* Items to be generated */
179 uint16 run_away; /* Monster runs away if it's hp goes below this percentage. */
180 struct object *chosen_skill; /* the skill chosen to use */
181 uint32 hide; /* The object is hidden, not invisible */
182 /* changes made by kholland@sunlab.cit.cornell.edu */
183 /* allows different movement patterns for attackers */
184 sint32 move_status; /* What stage in attack mode */
185 uint16 attack_movement;/* What kind of attack movement */
186 uint8 will_apply; /* See crossfire.doc */
187 struct object *spellitem; /* Spell ability monster is choosing to use */
188 double expmul; /* needed experience = (calc_exp*expmul) - means some */
189 /* races/classes can need less/more exp to gain levels */
190
191 /* Spell related information, may be useful elsewhere
192 * Note that other fields are used - these files are basically
193 * only used in spells.
194 */
195 sint16 duration; /* How long the spell lasts */
196 uint8 duration_modifier; /* how level modifies duration */
197 sint16 casting_time; /* time left before spell goes off */
198 struct object *spell; /* Spell that was being cast */
199 uint16 start_holding;
200 char *spellarg;
201 uint8 dam_modifier; /* How going up in level effects damage */
202 sint8 range; /* Range of the spell */
203 uint8 range_modifier; /* How going up in level effects range */
204
205 /* Following are values used by any object */
206 struct archt *arch; /* Pointer to archetype */
207 struct archt *other_arch; /* Pointer used for various things - mostly used for what */
208 /* this objects turns into or what this object creates */
209 uint32 flags[4]; /* various flags */
210 uint16 animation_id; /* An index into the animation array */
211 uint8 anim_speed; /* ticks between animation-frames */
212 uint8 last_anim; /* last sequence used to draw face */
213 sint32 elevation; /* elevation of this terrain - not currently used */
214 uint8 smoothlevel; /* how to smooth this square around*/
215
216 MoveType move_type; /* Type of movement this object uses */
217 MoveType move_block; /* What movement types this blocks */
218 MoveType move_allow; /* What movement types explicitly allowd */
219 MoveType move_on; /* Move types affected moving on to this space */
220 MoveType move_off; /* Move types affected moving off this space */
221 MoveType move_slow; /* Movement types this slows down */
222 float move_slow_penalty; /* How much this slows down the object */
223
224 shstr custom_name; /* Custom name assigned by player */
225 key_value *key_values; /* Fields not explictly known by the loader. */
226 };
227
228 struct object : object_special, object_simple, zero_initialised {
229 void clone (object *destination)
230 {
231 destination->attach = attach;
232
233 if (self || cb)
234 INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination));
235 }
236 };
237
238 typedef struct oblnk { /* Used to link together several objects */
239 object *ob;
240 struct oblnk *next;
241 tag_t id;
242 } objectlink;
243
244 typedef struct oblinkpt { /* Used to link together several object links */
245 struct oblnk *link;
246 long value; /* Used as connected value in buttons/gates */
247 struct oblinkpt *next;
248 } oblinkpt;
249
250 /*
251 * The archetype structure is a set of rules on how to generate and manipulate
252 * objects which point to archetypes.
253 * This probably belongs in arch.h, but there really doesn't appear to
254 * be much left in the archetype - all it really is is a holder for the
255 * object and pointers. This structure should get removed, and just replaced
256 * by the object structure
257 */
258
259 typedef struct archt : zero_initialised
260 {
261 shstr name; /* More definite name, like "generate_kobold" */
262 struct archt *next; /* Next archetype in a linked list */
263 struct archt *head; /* The main part of a linked object */
264 struct archt *more; /* Next part of a linked object */
265 object clone; /* An object from which to do copy_object() */
266 uint32 editable; /* editable flags (mainly for editor) */
267 sint8 tail_x, tail_y; /* Where the lower right most portion of the object is
268 * in comparison to the head.
269 */
270 } archetype;
271
272 extern object *objects;
273 extern object *active_objects;
274 extern object *free_objects;
275 extern object objarray[STARTMAX];
276
277 extern int nrofallocobjects;
278 extern int nroffreeobjects;
279
280 /* This returns TRUE if the object is something that
281 * should be displayed in the look window
282 */
283 #define LOOK_OBJ(ob) (!ob->invisible && ob->type!=PLAYER && ob->type!=EVENT_CONNECTOR)
284
285 /* Used by update_object to know if the object being passed is
286 * being added or removed.
287 */
288 #define UP_OBJ_INSERT 1
289 #define UP_OBJ_REMOVE 2
290 #define UP_OBJ_CHANGE 3
291 #define UP_OBJ_FACE 4 /* Only thing that changed was the face */
292
293 /* These are flags passed to insert_ob_in_map and
294 * insert_ob_in_ob. Note that all flags may not be meaningful
295 * for both functions.
296 * Most are fairly explanatory:
297 * INS_NO_MERGE: don't try to merge inserted object with ones alrady
298 * on space.
299 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor.
300 * INS_NO_WALK_ON: Don't call check_walk_on against the
301 * originator - saves cpu time if you know the inserted object
302 * is not meaningful in terms of having an effect.
303 * INS_ON_TOP: Always put object on top. Generally only needed when loading
304 * files from disk and ordering needs to be preserved.
305 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator -
306 * Use for treasure chests so the new object is the highest thing
307 * beneath the player, but not actually above it. Note - the
308 * map and x,y coordinates for the object to be inserted must
309 * match the originator.
310 * INS_MAP_LOAD: disable lots of checkings done at insertion to
311 * speed up map loading process, as we assume the ordering in
312 * loaded map is correct.
313 *
314 * Note that INS_BELOW_ORIGINATOR, INS_ON_TOP, INS_ABOVE_FLOOR_ONLY
315 * are mutually exclusive. The behaviour for passing more than one
316 * should be considered undefined - while you may notice what happens
317 * right now if you pass more than one, that could very well change
318 * in future revisions of the code.
319 */
320 #define INS_NO_MERGE 0x0001
321 #define INS_ABOVE_FLOOR_ONLY 0x0002
322 #define INS_NO_WALK_ON 0x0004
323 #define INS_ON_TOP 0x0008
324 #define INS_BELOW_ORIGINATOR 0x0010
325 #define INS_MAP_LOAD 0x0020
326
327 #define ARCH_SINGULARITY "singularity"
328 #define ARCH_SINGULARITY_LEN 11
329 #define ARCH_DETECT_MAGIC "detect_magic"
330 #define ARCH_DEPLETION "depletion"
331 #define ARCH_SYMPTOM "symptom"
332
333 #endif