diff options
Diffstat (limited to 'src/map/map.hpp')
-rw-r--r-- | src/map/map.hpp | 192 |
1 files changed, 90 insertions, 102 deletions
diff --git a/src/map/map.hpp b/src/map/map.hpp index 0cec5e8..55f4823 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -1,5 +1,4 @@ -#ifndef TMWA_MAP_MAP_HPP -#define TMWA_MAP_MAP_HPP +#pragma once // map.hpp - Core of the map server. // // Copyright © ????-2004 Athena Dev Teams @@ -21,48 +20,53 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -# include "../sanity.hpp" +#include "fwd.hpp" -# include "map.t.hpp" +#include "map.t.hpp" -# include <netinet/in.h> +#include <chrono> +#include <functional> +#include <list> -# include <functional> -# include <list> +#include "../ints/udl.hpp" -# include "../strings/fwd.hpp" -# include "../strings/rstring.hpp" -# include "../strings/astring.hpp" -# include "../strings/vstring.hpp" +#include "../strings/fwd.hpp" +#include "../strings/rstring.hpp" +#include "../strings/astring.hpp" +#include "../strings/vstring.hpp" -# include "../generic/db.hpp" -# include "../generic/matrix.hpp" +#include "../generic/db.hpp" +#include "../generic/dumb_ptr.hpp" +#include "../generic/matrix.hpp" -# include "../io/cxxstdio.hpp" +#include "../net/socket.hpp" +#include "../net/timer.t.hpp" -# include "../mmo/socket.hpp" -# include "../mmo/timer.t.hpp" +#include "../mmo/utils.hpp" -# include "battle.t.hpp" -# include "magic-interpreter.t.hpp" -# include "mapflag.hpp" -# include "mob.t.hpp" -# include "script.hpp" // change to script.t.hpp -# include "skill.t.hpp" +#include "battle.t.hpp" +#include "clif.t.hpp" +#include "mapflag.hpp" +#include "mob.t.hpp" +#include "script.hpp" // change to script.t.hpp +#include "skill.t.hpp" + +namespace tmwa +{ constexpr int MAX_NPC_PER_MAP = 512; constexpr int BLOCK_SIZE = 8; -# define AREA_SIZE battle_config.area_size -constexpr std::chrono::seconds LIFETIME_FLOORITEM = std::chrono::minutes(1); +#define AREA_SIZE battle_config.area_size +constexpr std::chrono::seconds LIFETIME_FLOORITEM = 1_min; constexpr int MAX_SKILL_LEVEL = 100; constexpr int MAX_EVENTTIMER = 32; -constexpr interval_t NATURAL_HEAL_INTERVAL = std::chrono::milliseconds(500); -constexpr int MAX_FLOORITEM = 500000; +constexpr interval_t NATURAL_HEAL_INTERVAL = 500_ms; +constexpr BlockId MAX_FLOORITEM = wrap<BlockId>(500000_u32); constexpr int MAX_LEVEL = 255; constexpr int MAX_WALKPATH = 48; constexpr int MAX_DROP_PER_MAP = 48; -constexpr interval_t DEFAULT_AUTOSAVE_INTERVAL = std::chrono::minutes(1); +constexpr interval_t DEFAULT_AUTOSAVE_INTERVAL = 1_min; // formerly VString<49>, as name::label struct NpcEvent @@ -89,24 +93,14 @@ struct NpcEvent return l.npc < r.npc || (l.npc == r.npc && l.label < r.label); } - friend VString<49> convert_for_printf(NpcEvent ev) - { - return STRNPRINTF(50, "%s::%s", ev.npc, ev.label); - } + friend VString<49> convert_for_printf(NpcEvent ev); }; bool extract(XString str, NpcEvent *ev); -struct map_session_data; -struct npc_data; -struct mob_data; -struct flooritem_data; -struct invocation; -struct map_local; - struct block_list { dumb_ptr<block_list> bl_next, bl_prev; - int bl_id; + BlockId bl_id; map_local *bl_m; short bl_x, bl_y; BL bl_type; @@ -123,13 +117,13 @@ private: dumb_ptr<npc_data> as_npc(); dumb_ptr<mob_data> as_mob(); dumb_ptr<flooritem_data> as_item(); - dumb_ptr<invocation> as_spell(); + dumb_ptr<magic::invocation> as_spell(); public: dumb_ptr<map_session_data> is_player(); dumb_ptr<npc_data> is_npc(); dumb_ptr<mob_data> is_mob(); dumb_ptr<flooritem_data> is_item(); - dumb_ptr<invocation> is_spell(); + dumb_ptr<magic::invocation> is_spell(); }; struct walkpath_data @@ -141,14 +135,9 @@ struct status_change { Timer timer; int val1; - int spell_invocation; /* [Fate] If triggered by a spell, record here */ + BlockId spell_invocation; /* [Fate] If triggered by a spell, record here */ }; -struct invocation; - -struct npc_data; -struct item_data; - struct quick_regeneration { // [Fate] int amount; // Amount of HP/SP left to regenerate @@ -190,13 +179,14 @@ struct map_session_data : block_list, SessionData unsigned unbreakable_armor:1; unsigned deaf:1; } special_state; - int char_id, login_id1, login_id2; + CharId char_id_; + int login_id1, login_id2; SEX sex; unsigned char tmw_version; // tmw client version CharKey status_key; CharData status; - Array<struct item_data *, MAX_INVENTORY> inventory_data; - earray<short, EQUIP, EQUIP::COUNT> equip_index_maybe; + GenericArray<struct item_data *, InventoryIndexing<IOff0, MAX_INVENTORY>> inventory_data; + earray<IOff0, EQUIP, EQUIP::COUNT> equip_index_maybe; int weight, max_weight; MapName mapname_; Session *sess; // use this, you idiots! @@ -206,10 +196,9 @@ struct map_session_data : block_list, SessionData Opt2 opt2; Opt3 opt3; DIR dir, head_dir; - tick_t client_tick, server_tick; struct walkpath_data walkpath; Timer walktimer; - int npc_id, areanpc_id, npc_shopid; + BlockId npc_id, areanpc_id, npc_shopid; // this is important int npc_pos; int npc_menu; @@ -226,20 +215,20 @@ struct map_session_data : block_list, SessionData } npc_flags; Timer attacktimer; - int attacktarget; + BlockId attacktarget; ATK attacktarget_lv; tick_t attackabletime; // used by @hugo and @linus - int followtarget; + BlockId followtarget; tick_t cast_tick; // [Fate] Next tick at which spellcasting is allowed - dumb_ptr<invocation> active_spells; // [Fate] Singly-linked list of active spells linked to this PC - int attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it + dumb_ptr<magic::invocation> active_spells; // [Fate] Singly-linked list of active spells linked to this PC + BlockId attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it // like a weapon. Check pc_attack_timer() for details. // Weapon equipment slot (slot 4) item override StatusChange attack_spell_icon_override; - short attack_spell_look_override; // Weapon `look' (attack animation) override + ItemNameId attack_spell_look_override; // Weapon `look' (attack animation) override short attack_spell_charges; // [Fate] Remaining number of charges for the attack spell interval_t attack_spell_delay; // [Fate] ms delay after spell attack short attack_spell_range; // [Fate] spell range @@ -296,16 +285,18 @@ struct map_session_data : block_list, SessionData earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data; short sc_count; - int trade_partner; - Array<int, TRADE_MAX> deal_item_index; + AccountId trade_partner; + Array<IOff2, TRADE_MAX> deal_item_index; Array<int, TRADE_MAX> deal_item_amount; int deal_zeny; short deal_locked; - int party_sended, party_invite, party_invite_account; + int party_sended; + PartyId party_invite; + AccountId party_invite_account; int party_hp, party_x, party_y; - int partyspy; // [Syrus22] + PartyId partyspy; // [Syrus22] int catch_target_class; @@ -349,18 +340,15 @@ struct npc_label_list }; struct npc_item_list { - int nameid, value; + ItemNameId nameid; + int value; }; -class npc_data_script; -class npc_data_shop; -class npc_data_warp; -class npc_data_message; struct npc_data : block_list { NpcSubtype npc_subtype; short n; - short npc_class; + Species npc_class; DIR dir; interval_t speed; NpcName name; @@ -446,7 +434,7 @@ constexpr int MOB_XP_BONUS_SHIFT = 10; struct mob_data : block_list { short n; - short mob_class; + Species mob_class; DIR dir; MobMode mode; struct @@ -472,7 +460,7 @@ struct mob_data : block_list Timer timer; short to_x, to_y; int hp; - int target_id, attacked_id; + BlockId target_id, attacked_id; ATK target_lv; struct walkpath_data walkpath; tick_t next_walktime; @@ -482,12 +470,12 @@ struct mob_data : block_list short move_fail_count; struct DmgLogEntry { - int id; + BlockId id; int dmg; }; // logically a map ... std::vector<DmgLogEntry> dmglogv; - std::vector<struct item> lootitemv; + std::vector<Item> lootitemv; earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data; short sc_count; @@ -499,14 +487,15 @@ struct mob_data : block_list Timer deletetimer; Timer skilltimer; - int skilltarget; + BlockId skilltarget; short skillx, skilly; SkillID skillid; short skilllv; struct mob_skill *skillidx; std::unique_ptr<tick_t[]> skilldelayup; // [MAX_MOBSKILL]; LevelElement def_ele; - int master_id, master_dist; + BlockId master_id; + int master_dist; int exclusion_src, exclusion_party; NpcEvent npc_event; // [Fate] mob-specific stats @@ -522,7 +511,7 @@ struct BlockLists struct map_abstract { MapName name_; - // gat is NULL for map_remote and non-NULL or map_local + // gat is nullptr for map_remote and non-nullptr or map_local std::unique_ptr<MapCell[]> gat; virtual ~map_abstract() {} @@ -537,8 +526,8 @@ struct map_local : map_abstract int npc_num; int users; MapFlags flag; - struct point save; - struct point resave; + Point save; + Point resave; Array<dumb_ptr<npc_data>, MAX_NPC_PER_MAP> npc; }; @@ -560,9 +549,9 @@ struct flooritem_data : block_list { short subx, suby; Timer cleartimer; - int first_get_id, second_get_id, third_get_id; + BlockId first_get_id, second_get_id, third_get_id; tick_t first_get_tick, second_get_tick, third_get_tick; - struct item item_data; + Item item_data; }; extern interval_t autosave_time; @@ -607,9 +596,9 @@ void map_foreachinmovearea(std::function<void(dumb_ptr<block_list>)>, //block関連に追加 int map_count_oncell(map_local *m, int x, int y); // 一時的object関連 -int map_addobject(dumb_ptr<block_list>); -int map_delobject(int, BL type); -int map_delobjectnofree(int id, BL type); +BlockId map_addobject(dumb_ptr<block_list>); +void map_delobject(BlockId, BL type); +void map_delobjectnofree(BlockId id, BL type); void map_foreachobject(std::function<void(dumb_ptr<block_list>)>, BL); // @@ -618,64 +607,64 @@ void map_quit(dumb_ptr<map_session_data>); int map_addnpc(map_local *, dumb_ptr<npc_data>); void map_log(XString line); -# define MAP_LOG(format, ...) \ +#define MAP_LOG(format, ...) \ map_log(STRPRINTF(format, ## __VA_ARGS__)) -# define MAP_LOG_PC(sd, fmt, ...) \ +#define MAP_LOG_PC(sd, fmt, ...) \ MAP_LOG("PC%d %s:%d,%d " fmt, \ - sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat")), sd->bl_x, sd->bl_y, ## __VA_ARGS__) + sd->status_key.char_id, (sd->bl_m ? sd->bl_m->name_ : stringish<MapName>("undefined.gat"_s)), sd->bl_x, sd->bl_y, ## __VA_ARGS__) // 床アイテム関連 -void map_clearflooritem_timer(TimerData *, tick_t, int); +void map_clearflooritem_timer(TimerData *, tick_t, BlockId); inline -void map_clearflooritem(int id) +void map_clearflooritem(BlockId id) { map_clearflooritem_timer(nullptr, tick_t(), id); } -int map_addflooritem_any(struct item *, int amount, +BlockId map_addflooritem_any(Item *, int amount, map_local *m, int x, int y, dumb_ptr<map_session_data> *owners, interval_t *owner_protection, interval_t lifetime, int dispersal); -int map_addflooritem(struct item *, int, +BlockId map_addflooritem(Item *, int, map_local *, int, int, dumb_ptr<map_session_data>, dumb_ptr<map_session_data>, dumb_ptr<map_session_data>); // キャラid=>キャラ名 変換関連 extern -DMap<int, dumb_ptr<block_list>> id_db; -void map_addchariddb(int charid, CharName name); -CharName map_charid2nick(int); +DMap<BlockId, dumb_ptr<block_list>> id_db; +void map_addchariddb(CharId charid, CharName name); +CharName map_charid2nick(CharId); -dumb_ptr<map_session_data> map_id2sd(int); -dumb_ptr<block_list> map_id2bl(int); +dumb_ptr<map_session_data> map_id2sd(BlockId); +dumb_ptr<block_list> map_id2bl(BlockId); inline -dumb_ptr<map_session_data> map_id_is_player(int id) +dumb_ptr<map_session_data> map_id_is_player(BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); return bl ? bl->is_player() : nullptr; } inline -dumb_ptr<npc_data> map_id_is_npc(int id) +dumb_ptr<npc_data> map_id_is_npc(BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); return bl ? bl->is_npc() : nullptr; } inline -dumb_ptr<mob_data> map_id_is_mob(int id) +dumb_ptr<mob_data> map_id_is_mob(BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); return bl ? bl->is_mob() : nullptr; } inline -dumb_ptr<flooritem_data> map_id_is_item(int id) +dumb_ptr<flooritem_data> map_id_is_item(BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); return bl ? bl->is_item() : nullptr; } inline -dumb_ptr<invocation> map_id_is_spell(int id) +dumb_ptr<magic::invocation> map_id_is_spell(BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); return bl ? bl->is_spell() : nullptr; @@ -688,9 +677,9 @@ int map_setipport(MapName name, IP4Address ip, int port); void map_addiddb(dumb_ptr<block_list>); void map_deliddb(dumb_ptr<block_list> bl); void map_addnickdb(dumb_ptr<map_session_data>); -int map_scriptcont(dumb_ptr<map_session_data> sd, int id); /* Continues a script either on a spell or on an NPC */ +int map_scriptcont(dumb_ptr<map_session_data> sd, BlockId id); /* Continues a script either on a spell or on an NPC */ dumb_ptr<map_session_data> map_nick2sd(CharName); -int compare_item(struct item *a, struct item *b); +int compare_item(Item *a, Item *b); dumb_ptr<map_session_data> map_get_first_session(void); dumb_ptr<map_session_data> map_get_last_session(void); @@ -733,5 +722,4 @@ inline dumb_ptr<npc_data_script> npc_data::is_script() { return npc_subtype == N inline dumb_ptr<npc_data_shop> npc_data::is_shop() { return npc_subtype == NpcSubtype::SHOP ? as_shop() : nullptr ; } inline dumb_ptr<npc_data_warp> npc_data::is_warp() { return npc_subtype == NpcSubtype::WARP ? as_warp() : nullptr ; } inline dumb_ptr<npc_data_message> npc_data::is_message() { return npc_subtype == NpcSubtype::MESSAGE ? as_message() : nullptr ; } - -#endif // TMWA_MAP_MAP_HPP +} // namespace tmwa |