--- deliantra/server/include/object.h 2006/02/07 23:29:55 1.2 +++ deliantra/server/include/object.h 2006/08/26 23:36:32 1.7 @@ -29,6 +29,9 @@ #ifndef OBJECT_H #define OBJECT_H +#include "cfperl.h" +#include "shstr.h" + typedef uint32 tag_t; #define NUM_BODY_LOCATIONS 12 #define BODY_ARMS 1 @@ -36,9 +39,9 @@ /* See common/item.c */ typedef struct Body_Locations { - char *save_name; /* Name used to load/save it to disk */ - char *use_name; /* Name used when describing an item we can use */ - char *nonuse_name; /* Name to describe objects we can't use */ + const char *save_name; /* Name used to load/save it to disk */ + const char *use_name; /* Name used when describing an item we can use */ + const char *nonuse_name; /* Name to describe objects we can't use */ } Body_Locations; extern Body_Locations body_locations[NUM_BODY_LOCATIONS]; @@ -97,32 +100,37 @@ * This structure is best viewed with about a 100 width screen. * MSW 2002-07-05 */ -typedef struct obj { + +struct object_simple : extendable { + data_type get_dt () const { return DT_OBJECT; } + /* These variables are not changed by copy_object() */ struct pl *contr; /* Pointer to the player which control this object */ - struct obj *next; /* Pointer to the next object in the free/used list */ - struct obj *prev; /* Pointer to the previous object in the free/used list*/ - struct obj *active_next; /* Next & previous object in the 'active' */ - struct obj *active_prev; /* List. This is used in process_events */ + struct object *next; /* Pointer to the next object in the free/used list */ + struct object *prev; /* Pointer to the previous object in the free/used list*/ + struct object *active_next; /* Next & previous object in the 'active' */ + struct object *active_prev; /* List. This is used in process_events */ /* so that the entire object list does not */ /* need to be gone through. */ - struct obj *below; /* Pointer to the object stacked below this one */ - struct obj *above; /* Pointer to the object stacked above this one */ + struct object *below; /* Pointer to the object stacked below this one */ + struct object *above; /* Pointer to the object stacked above this one */ /* Note: stacked in the *same* environment*/ - struct obj *inv; /* Pointer to the first object in the inventory */ - struct obj *container; /* Current container being used. I think this + struct object *inv; /* Pointer to the first object in the inventory */ + struct object *container; /* Current container being used. I think this * is only used by the player right now. */ - struct obj *env; /* Pointer to the object which is the environment. + struct object *env; /* Pointer to the object which is the environment. * This is typically the container that the object is in. */ - struct obj *more; /* Pointer to the rest of a large body of objects */ - struct obj *head; /* Points to the main object of a large body */ - struct mapdef *map; /* Pointer to the map in which this object is present */ + struct object *more; /* Pointer to the rest of a large body of objects */ + struct object *head; /* Points to the main object of a large body */ + struct mapstruct *map; /* Pointer to the map in which this object is present */ tag_t count; /* Unique object number for this object */ uint16 refcount; /* How many objects points to this object */ +}; +struct object_special { /* These get an extra add_refcount(), after having been copied by memcpy(). * All fields beow this point are automatically copied by memcpy. If * adding something that needs a refcount updated, make sure you modify @@ -183,7 +191,7 @@ sint64 perm_exp; /* Permanent exp */ const char *current_weapon_script; /* The script of the currently used weapon. Executed */ /* each time the object attacks something */ - struct obj *current_weapon; /* Pointer to the weapon currently used */ + struct object *current_weapon; /* Pointer to the weapon currently used */ uint32 weapontype; /* type of weapon */ uint32 tooltype; /* type of tool or build facility */ sint8 body_info[NUM_BODY_LOCATIONS]; /* body info as loaded from the file */ @@ -191,24 +199,24 @@ /* See the doc/Developers/objects for more info about body locations */ /* Following mostly refers to fields only used for monsters */ - struct obj *owner; /* Pointer to the object which controls this one */ + struct object *owner; /* Pointer to the object which controls this one */ /* Owner should not be referred to directly - */ /* get_owner should be used instead. */ tag_t ownercount; /* What count the owner had (in case owner */ /* has been freed) */ - struct obj *enemy; /* Monster/player to follow even if not closest */ - struct obj *attacked_by; /* This object start to attack us! only player & monster */ + struct object *enemy; /* Monster/player to follow even if not closest */ + struct object *attacked_by; /* This object start to attack us! only player & monster */ tag_t attacked_by_count; /* the tag of attacker, so we can be sure */ struct treasureliststruct *randomitems; /* Items to be generated */ uint16 run_away; /* Monster runs away if it's hp goes below this percentage. */ - struct obj *chosen_skill; /* the skill chosen to use */ + struct object *chosen_skill; /* the skill chosen to use */ uint32 hide; /* The object is hidden, not invisible */ /* changes made by kholland@sunlab.cit.cornell.edu */ /* allows different movement patterns for attackers */ sint32 move_status; /* What stage in attack mode */ uint16 attack_movement;/* What kind of attack movement */ uint8 will_apply; /* See crossfire.doc */ - struct obj *spellitem; /* Spell ability monster is choosing to use */ + struct object *spellitem; /* Spell ability monster is choosing to use */ double expmul; /* needed experience = (calc_exp*expmul) - means some */ /* races/classes can need less/more exp to gain levels */ @@ -219,7 +227,7 @@ sint16 duration; /* How long the spell lasts */ uint8 duration_modifier; /* how level modifies duration */ sint16 casting_time; /* time left before spell goes off */ - struct obj *spell; /* Spell that was being cast */ + struct object *spell; /* Spell that was being cast */ uint16 start_holding; char *spellarg; uint8 dam_modifier; /* How going up in level effects damage */ @@ -239,6 +247,7 @@ MoveType move_type; /* Type of movement this object uses */ MoveType move_block; /* What movement types this blocks */ + MoveType move_allow; /* What movement types explicitly allowd */ MoveType move_on; /* Move types affected moving on to this space */ MoveType move_off; /* Move types affected moving off this space */ MoveType move_slow; /* Movement types this slows down */ @@ -248,7 +257,28 @@ const char *custom_name; /* Custom name assigned by player */ key_value *key_values; /* Fields not explictly known by the loader. */ -} object; +}; + +struct object : object_special, object_simple { + void instantiate_ (); + void instantiate () + { + if (attach) + { + instantiate_ (); + free_string (attach); + attach = 0; + } + } + void clone (object *destination) + { + if (attach) + destination->attach = add_refcount (attach); + + if (self || cb) + INVOKE_OBJECT (CLONE, this, ARG_OBJECT (destination)); + } +}; typedef struct oblnk { /* Used to link together several objects */ object *ob; @@ -344,6 +374,4 @@ #define ARCH_DEPLETION "depletion" #define ARCH_SYMPTOM "symptom" -extern void (*object_free_callback)(object *ob); // called for every object_free - #endif