--- deliantra/server/include/object.h 2007/05/14 21:32:26 1.122 +++ deliantra/server/include/object.h 2007/06/04 13:04:00 1.130 @@ -1,25 +1,25 @@ /* - * CrossFire, A Multiplayer Online RPG - * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2001 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at crossfire@schmorp.de + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. + * + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen + * + * Crossfire TRT is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ #ifndef OBJECT_H @@ -61,7 +61,7 @@ typedef struct Body_Locations { - const char *save_name; /* Name used to load/save it to disk */ + keyword 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; @@ -109,11 +109,6 @@ #define WILL_APPLY_DOOR 0x08 #define WILL_APPLY_FOOD 0x10 -/* However, if you're keeping a pointer of some sort, you probably - * don't just want it copied, so you'll need to add to common/object.C, - * e.g. ->copy_to () - */ - struct body_slot { signed char info:4; /* body info as loaded from the file */ @@ -299,24 +294,6 @@ do_remove (); } - // move this object to the top of its env's inventory to speed up - // searches for it. - MTH object *inv_splay () - { - if (env && env->inv != this) - { - if (above) above->below = below; - if (below) below->above = above; - - above = 0; - below = env->inv; - below->above = this; - env->inv = this; - } - - return this; - } - static bool can_merge_slow (object *op1, object *op2); // this is often used in time-critical code, so optimise @@ -330,6 +307,7 @@ MTH void set_owner (object *owner); MTH void set_speed (float speed); MTH bool change_weapon (object *ob); + MTH bool change_skill (object *ob); MTH void open_container (object *new_container); MTH void close_container () @@ -337,6 +315,12 @@ open_container (0); } + // overwrite the attachable should_invoke function with a version that also checks ev_want_type + bool should_invoke (event_type event) + { + return ev_want_event [event] || ev_want_type [type] || cb; + } + MTH void instantiate (); // recalculate all stats @@ -418,6 +402,11 @@ return head ? head : this; } + MTH bool is_head () + { + return head_ () == this; + } + MTH std::string long_desc (object *who = 0); MTH std::string describe_monster (object *who = 0); MTH std::string describe_item (object *who = 0); @@ -500,28 +489,31 @@ MTH struct region *region () const; protected: - friend struct archetype; - - void link (); + void link (); void unlink (); object (); ~object (); }; -typedef object_vector objectvec; -typedef object_vector activevec; +// move this object to the top of its env's inventory to speed up +// searches for it. +static object * +splay (object *ob) +{ + if (ob->env && ob->env->inv != ob) + { + if (ob->above) ob->above->below = ob->below; + if (ob->below) ob->below->above = ob->above; -extern objectvec objects; -extern activevec actives; + ob->above = 0; + ob->below = ob->env->inv; + ob->below->above = ob; + ob->env->inv = ob; + } -#define for_all_objects(var) \ - for (unsigned _i = 0; _i < objects.size (); ++_i) \ - declvar (object *, var, objects [_i]) - -#define for_all_actives(var) \ - for (unsigned _i = 0; _i < actives.size (); ++_i) \ - declvar (object *, var, actives [_i]) + return ob; +} typedef struct oblnk { /* Used to link together several objects */ @@ -539,7 +531,6 @@ object *find_skill_by_name (object *who, const char *name); object *find_skill_by_name (object *who, const shstr &sh); object *find_skill_by_number (object *who, int skillno); -int change_skill (object *who, object *new_skill, int flag); /* * The archetype structure is a set of rules on how to generate and manipulate @@ -551,9 +542,9 @@ */ INTERFACE_CLASS (archetype) -struct archetype : zero_initialised, attachable +struct archetype : object { - archetype (); + archetype (const char *name); ~archetype (); void gather_callbacks (AV *&callbacks, event_type event) const; @@ -561,21 +552,41 @@ static archetype *get (const char *name); // find or create static archetype *find (const char *name); - void hash_add (); // add to hashtable - void hash_del (); // remove from hashtable + void link (); + void unlink (); - shstr ACC (RW, name); /* More definite name, like "generate_kobold" */ + int ACC (RW, archid); // index in archvector + shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ + bool ACC (RW, stub); // if true, this is an invalid archetype struct archetype *ACC (RW, next); /* Next archetype in a linked list */ struct archetype *ACC (RW, head); /* The main part of a linked object */ struct archetype *ACC (RW, more); /* Next part of a linked object */ - object ACC (RO, clone); /* An object from which to do ->copy_to () */ uint32 ACC (RW, editable); /* editable flags (mainly for editor) */ - bool ACC (RW, linked); // linked into list of heads - sint8 ACC (RW, tail_x), ACC (RW, tail_y); /* Where the lower right most portion of the object is - * in comparison to the head. - */ + + sint8 ACC (RW, min_x), ACC (RW, min_y); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */ + sint8 ACC (RW, max_x), ACC (RW, max_y); }; +typedef object_vector objectvec; +typedef object_vector activevec; +typedef object_vector archvec; + +extern objectvec objects; +extern activevec actives; +extern archvec archetypes; + +#define for_all_objects(var) \ + for (unsigned _i = 0; _i < objects.size (); ++_i) \ + statementvar (object *, var, objects [_i]) + +#define for_all_actives(var) \ + for (unsigned _i = 0; _i < actives.size (); ++_i) \ + statementvar (object *, var, actives [_i]) + +#define for_all_archetypes(var) \ + for (unsigned _i = 0; _i < archetypes.size (); ++_i) \ + statementvar (archetype *, var, archetypes [_i]) + /* Used by update_object to know if the object being passed is * being added or removed. */