--- deliantra/server/include/player.h 2006/08/29 07:33:58 1.9 +++ deliantra/server/include/player.h 2007/08/16 06:36:56 1.68 @@ -1,222 +1,260 @@ /* - * static char *rcsid_player_h = - * "$Id$"; + * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. + * + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,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 3 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, see . + * + * The authors can be reached via e-mail to */ -/* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 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-devel@real-time.com -*/ - -#define NUM_OUTPUT_BUFS 5 -typedef struct { - const char *buf; /* Actual string pointer */ - uint32 first_update; /* First time this message was stored */ - uint16 count; /* How many times we got this message */ -} Output_Buf; +enum bowtype_t +{ + bow_normal = 0, + bow_threewide = 1, + bow_spreadshot = 2, + bow_n = 3, /* must stay at 3 */ + bow_ne = 4, + bow_e = 5, + bow_se = 6, + bow_s = 7, + bow_sw = 8, + bow_w = 9, + bow_nw = 10, /* must stay at 10 */ + bow_bestarrow = 11 +}; +enum petmode_t +{ + pet_normal = 0, + pet_sad = 1, + pet_defend = 2, + pet_arena = 3, +}; -/* wand/rod/horn rolled into range_misc. They all use the same body location - * anyways. - */ -enum rangetype { - range_bottom = -1, - range_none = 0, - range_bow = 1, - range_magic = 2, - range_misc = 3, - range_golem = 4, - range_skill = 5, - range_builder = 6, - range_size = 7 -}; - -enum bowtype_t { - bow_normal = 0, - bow_threewide = 1, - bow_spreadshot = 2, - bow_n = 3, /* must stay at 3 */ - bow_ne = 4, - bow_e = 5, - bow_se = 6, - bow_s = 7, - bow_sw = 8, - bow_w = 9, - bow_nw = 10, /* must stay at 10 */ - bow_bestarrow = 11 -}; - -typedef enum _petmode { - pet_normal = 0, - pet_sad = 1, - pet_defend = 2, - pet_arena = 3 -} petmode_t; - -typedef enum usekeytype { - key_inventory=0, - keyrings=1, - containers=2 -} usekeytype; +enum usekeytype +{ + key_inventory = 0, + keyrings = 1, + containers = 2, +}; /* This is used to control what to do when we need to unapply * an object before we can apply another one. */ -typedef enum unapplymode { - unapply_nochoice=0, /* Will unapply objects when there no choice to unapply */ - unapply_never=1, /* will not unapply objects automatically */ - unapply_always=2 /* Will unapply whatever is necessary - this goes beyond */ - /* no choice - if there are multiple ojbect of the same type */ - /* that need to be unapplied, there is no way for the player */ - /* to control which of these will be unapplied. */ -} unapplymode; - -/* not really the player, but tied pretty closely */ -typedef struct party_struct { - char * partyleader; - char passwd[9]; - struct party_struct *next; - char *partyname; - -#ifdef PARTY_KILL_LOG - struct party_kill { - char killer[MAX_NAME+1],dead[MAX_NAME+1]; - sint64 exp; - } party_kills[PARTY_KILL_LOG]; -#endif - sint64 total_exp; - uint32 kills; -} partylist; - -// memsettable part of player -struct player_memset -{ - object *ob; /* The object representing the player */ - mapstruct *loading; /* When entering a map in progress of loading, not really used */ - rangetype shoottype; /* Which range-attack is being used by player */ - bowtype_t bowtype; /* which firemode? */ - petmode_t petmode; /* which petmode? */ - object *ranges[range_size];/* object for each range. Set up in fix player. Note */ - /* That not all are used, it is just nice to map this 1:1 */ - /* With the range names */ - uint32 golem_count; /* To track the golem */ - usekeytype usekeys; /* Method for finding keys for doors */ - unapplymode unapply; /* Method for auto unapply */ - uint32 count; /* Any numbers typed before a command */ - uint32 mode; /* Mode of player for pickup. */ - - sint8 digestion; /* Any bonuses/penalties to digestion */ - sint8 gen_hp; /* Bonuses to regeneration speed of hp */ - sint8 gen_sp; /* Bonuses to regeneration speed of sp */ - sint8 gen_sp_armour; /* Penalty to sp regen from armour */ - sint8 gen_grace; /* Bonuses to regeneration speed of grace */ - sint16 item_power; /* Total item power of objects equipped */ - uint8 state; /* Input state of the player (name, password, etc */ - uint8 listening; /* Which priority will be used in info_all */ - sint8 last_level; /* Last level we sent to client */ - - /* Try to put all the bitfields together - saves some small amount of memory */ - uint32 braced:1; /* Will not move if braced, only attack */ - uint32 tmp_invis:1; /* Will invis go away when we attack ? */ - const char *invis_race; /* What race invisible to? */ - uint32 do_los:1; /* If true, need to call update_los() in draw(), and clear */ - uint32 fire_on:1; /* Player should fire object, not move */ - uint32 run_on:1; /* Player should keep moving in dir until run is off */ - uint32 has_hit:1; /* If set, weapon_sp instead of speed will count */ - uint32 name_changed:1; /* If true, the player has set a name. */ - uint32 peaceful:1; /* If set, won't attack friendly creatures */ - uint32 hidden:1; /* If True, player (DM) is hidden from view */ - uint32 explore:1; /* if True, player is in explore mode */ - uint32 no_shout:1; /* if True, player is *not* able to use shout command */ - - object *last_skill_ob[NUM_SKILLS]; /* the exp object */ - sint64 last_skill_exp[NUM_SKILLS]; /* shadow register. if != exp. obj update client */ - - float weapon_sp; /* Penalties to speed when fighting w speed >ws/10*/ - float last_weapon_sp; /* if diff than weapon_sp, update client */ - uint16 last_flags; /* fire/run on flags for last tick */ - sint32 last_weight; /* Last weight as sent to client; -1 means do not send weight */ - sint32 last_weight_limit; /* Last weight limit transmitted to client */ - uint32 last_path_attuned; /* Last spell attunment sent to client */ - uint32 last_path_repelled; /* Last spell repelled sent to client */ - uint32 last_path_denied; /* Last spell denied sent to client */ - living orig_stats; /* Permanent real stats of player */ - living last_stats; /* Last stats as sent to client */ - float last_speed; /* Last speed as sent to client */ - sint16 last_resist[NROFATTACKS]; /* last resist values sent to client */ - int Swap_First; /* First stat player has selected to swap */ - object *last_used; /* Pointer to object last picked or applied */ - uint32 last_used_id; /* Safety measures to be sure it's the same */ - sint8 blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]; /* array showing what spaces */ - /* the player can see. For maps smaller than */ - /* MAP_CLIENT_.., the upper left is used */ - - sint16 bed_x, bed_y; /* x,y - coordinates of respawn (savebed) */ - char savebed_map[MAX_BUF]; /* map where player will respawn after death */ - char maplevel[MAX_BUF]; /* On which level is the player? */ - char spellparam[MAX_BUF]; /* What param to add to spells */ - - char own_title[MAX_NAME]; /* Title the player has chosen for themself */ - /* Note that for dragon players, this is filled in for them */ - char title[BIG_NAME]; /* Default title, like fighter, wizard, etc */ - - sint8 levhp[11]; /* What the player gained on that level */ - sint8 levsp[11]; /* Same for sp */ - sint8 levgrace[11]; /* And same for grace */ - - char killer[BIG_NAME]; /* Who killed this player. */ - char last_tell[MAX_NAME]; /* last player that told you something [mids 01/14/2002] */ - - char write_buf[MAX_BUF]; /* Holds arbitrary input from client */ - char input_buf[MAX_BUF]; /* Holds command to run */ - char password[16]; /* 2 (seed) + 11 (crypted) + 1 (EOS) + 2 (safety) = 16 */ - -#ifdef SAVE_INTERVAL - time_t last_save_time; -#endif /* SAVE_INTERVAL */ -#ifdef AUTOSAVE - uint32 last_save_tick; -#endif - partylist *party; /* Party this player is part of */ - partylist *party_to_join; /* used when player wants to join a party */ - /* but we will have to get password first */ - /* so we have to remember which party to */ - /* join */ - char search_str[MAX_BUF]; /* Item we are looking for */ - sint16 encumbrance; /* How much our player is encumbered */ - Output_Buf outputs[NUM_OUTPUT_BUFS]; /* holds output strings to client */ - uint16 outputs_sync; /* How often to print, no matter what */ - uint16 outputs_count; /* Print if this count is exceeded */ - object *mark; /* marked object */ - uint32 mark_count; /* count of mark object */ - /* Special DM fields */ - tag_t* stack_items; /* Item stack for patch/dump/... commands */ - int stack_position; /* Current stack position, 0 for no item */ -}; - -typedef struct pl : player_memset, attachable -{ - static data_type get_dt () { return DT_PLAYER; } - - struct pl *next; /* Pointer to next player, NULL if this is last */ - NewSocket socket; /* Socket information for this player */ -} player; +enum unapplymode +{ + unapply_nochoice = 0, /* Will unapply objects when there no choice to unapply */ + unapply_never = 1, /* will not unapply objects automatically */ + unapply_always = 2 /* Will unapply whatever is necessary - this goes beyond */ + /* no choice - if there are multiple ojbect of the same type */ + /* that need to be unapplied, there is no way for the player */ + /* to control which of these will be unapplied. */ +}; + +/* not really the player, but tied pretty closely */ +INTERFACE_CLASS (partylist) +struct partylist +{ + char *ACC (RW, partyleader); + char ACC (RW, passwd)[9]; + partylist *ACC (RW, next); + char *ACC (RW, partyname); + + struct party_kill + { + char killer[MAX_NAME + 1], dead[MAX_NAME + 1]; + sint64 exp; + } party_kills[PARTY_KILL_LOG]; + sint64 ACC (RW, total_exp); + uint32 ACC (RW, kills); +}; + +// used for pet monster logic etc. +static bool +same_party (partylist *a, partylist *b) +{ + return a == b && a; +} + +INTERFACE_CLASS (player) +struct player : zero_initialised, attachable +{ + client *ACC (RO, ns); /* Socket information for this player, ALWAYS valid when a player is on a map */ + object *ACC (RW, ob); /* The object representing the player, ALWAYS valid */ + object_vector_index ACC (RO, active); + + bowtype_t ACC (RW, bowtype); /* which firemode? */ + petmode_t ACC (RW, petmode); /* which petmode? */ + usekeytype ACC (RW, usekeys); /* Method for finding keys for doors */ + unapplymode ACC (RW, unapply); /* Method for auto unapply */ + uint32 ACC (RW, count); /* Any numbers typed before a command */ + uint32 ACC (RW, mode); /* Mode of player for pickup. */ + + int ACC (RW, digestion); /* Any bonuses/penalties to digestion */ + int ACC (RW, gen_hp); /* Bonuses to regeneration speed of hp */ + int ACC (RW, gen_sp); /* Bonuses to regeneration speed of sp */ + int ACC (RW, gen_sp_armour); /* Penalty to sp regen from armour */ + int ACC (RW, gen_grace); /* Bonuses to regeneration speed of grace */ + int ACC (RW, item_power); /* Total item power of objects equipped */ + uint8 ACC (RW, listening); /* Which priority will be used in info_all */ + uint8 ACC (RW, gender); /* 0 male, 1 female, others not yte defined */ + + /* Try to put all the bitfields together - saves some small amount of memory */ + bool ACC (RW, braced); /* Will not move if braced, only attack */ + bool ACC (RW, tmp_invis); /* Will invis go away when we attack ? */ + bool ACC (RW, do_los); /* If true, need to call update_los() in draw(), and clear */ + bool ACC (RW, fire_on); /* Player should fire object, not move */ + bool ACC (RW, run_on); /* Player should keep moving in dir until run is off */ + bool ACC (RW, peaceful); /* If set, won't attack friendly creatures */ + bool ACC (RW, hidden); /* If True, player (DM) is hidden from view */ + + float ACC (RW, weapon_sp); /* Penalties to speed when fighting w speed >ws/10 */ + float ACC (RW, weapon_sp_left); // same as speed_left, but for attacks + living ACC (RO, orig_stats); /* Permanent real stats of player */ + object_ptr last_skill_ob[NUM_SKILLS]; /* the exp object */ + object_ptr ACC (RW, last_used); /* Pointer to object last picked or applied */ + + object_ptr ACC (RW, combat_ob); // which weapon/bow/skill to use for direct attacks + object_ptr ACC (RW, ranged_ob); // which skill/item/spell to use for ranged attacks + object_ptr ACC (RW, golem); // the currently controlled golem + object_ptr ACC (RW, observe); // the object that is being observed (or 0) + + sint16 ACC (RW, bed_x), ACC (RW, bed_y); /* x,y - coordinates of respawn (savebed) */ + shstr ACC (RW, savebed_map); /* map where player will respawn after death */ + shstr ACC (RW, maplevel); /* On which level is the player? */ + char ACC (RW, spellparam)[MAX_BUF]; /* What param to add to spells */ + + char ACC (RW, own_title)[MAX_NAME]; /* Title the player has chosen for themself */ + /* Note that for dragon players, this is filled in for them */ + char ACC (RW, title)[64]; /* Default title, like fighter, wizard, etc */ + + sint8 ACC (RW, levhp[11]); /* What the player gained on that level */ + sint8 ACC (RW, levsp[11]); /* Same for sp */ + sint8 ACC (RW, levgrace[11]); /* And same for grace */ + + char ACC (RW, killer)[64]; /* Who killed this player. */ + + char write_buf[MAX_BUF]; /* Holds arbitrary input from client */ /* should go */ + char ACC (RW, password)[16]; /* 2 (seed) + 11 (crypted) + 1 (EOS) + 2 (safety) = 16 */ + + partylist *ACC (RW, party); /* Party this player is part of */ + partylist *ACC (RW, party_to_join); /* used when player wants to join a party */ + /* but we will have to get password first */ + /* so we have to remember which party to */ + /* join */ + char ACC (RW, search_str)[MAX_BUF]; /* Item we are looking for */ + sint16 ACC (RW, encumbrance); /* How much our player is encumbered */ + uint16 ACC (RW, outputs_sync); /* How often to print, no matter what */ + uint16 ACC (RW, outputs_count); /* Print if this count is exceeded */ + object_ptr ACC (RW, mark); /* marked object */ + /* Special DM fields */ + tag_t *stack_items; /* Item stack for patch/dump/... commands */ + int ACC (RW, stack_position); /* Current stack position, 0 for no item */ + sint8 blocked_los[MAP_CLIENT_X][MAP_CLIENT_Y]; /* array showing what spaces */ + /* the player can see. For maps smaller than */ + /* MAP_CLIENT_.., the upper left is used */ + + shstr ACC (RW, invis_race); /* What race invisible to? */ + + MTH static player *create (); + + static player *load_pl (object_thawer &thawer); + MTH static player *load_pl (const char *path); + + bool save_pl (object_freezer &freezer); + MTH bool save_pl (const char *path); + + void do_destroy (); + void gather_callbacks (AV *&callbacks, event_type event) const; + + MTH void play_sound (faceidx sound, int dx = 0, int dy = 0) const + { + if (ns) + ns->play_sound (sound, dx, dy); + } + + // wether the player can "see" this mapspace or not, decided by los + // 0 - nothing see, 100 - fully visible + MTH sint8 visibility_at (maptile *map, int x, int y) const; + + MTH void connect (client *ns); + MTH void disconnect (); + + MTH void activate (); + MTH void deactivate (); + + MTH void chargen_race_done (); + MTH void chargen_race_next (); + + MTH void set_observe (object *ob); + + void send_msg (int color, const char *type, const char *msg) + { + ns->send_msg (color, type, msg); + } + + // a prominent box that can easily be escaped away or so + // should be used for informative output such as who, maps etc. + // will stay on-screen + void infobox (const char *msg, int color = NDI_BLACK) + { + send_msg (NDI_REPLY, LOG_CHANNEL, msg); + } + + // a prominent msg that signifies some important event, + // an improvement potion effect potion. should not be long. + // might time out after a while + void statusmsg (const char *msg, int color = NDI_BLACK) + { + send_msg (NDI_REPLY | color, INFO_CHANNEL, msg); + } + + // a prominent box that signifies some error such as a failed + // improvement potion. should not be long. + void errormsg (const char *msg, int color = NDI_RED) + { + play_sound (sound_find ("errormsg")); + statusmsg (msg, color); + } + + ~player (); + +private: + void set_object (object *op); + player (); +}; + +typedef object_vector playervec; + +extern playervec players; + +#define for_all_players(var) \ + for (unsigned _i = 0; _i < ::players.size (); ++_i) \ + statementvar (player *, var, ::players [_i]) + +inline void +object::statusmsg (const char *msg, int color) +{ + if (expect_true (contr)) contr->statusmsg (msg, color); +} + +inline void +object::errormsg (const char *msg, int color) +{ + if (expect_true (contr)) contr->errormsg (msg, color); +}