diff options
Diffstat (limited to 'src/map/map.hpp')
-rw-r--r-- | src/map/map.hpp | 151 |
1 files changed, 64 insertions, 87 deletions
diff --git a/src/map/map.hpp b/src/map/map.hpp index d88ff54..f57dcee 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -20,17 +20,16 @@ // 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 "fwd.hpp" - #include "map.t.hpp" +#include "fwd.hpp" + #include <chrono> #include <functional> #include <list> #include "../ints/udl.hpp" -#include "../strings/fwd.hpp" #include "../strings/rstring.hpp" #include "../strings/astring.hpp" #include "../strings/vstring.hpp" @@ -42,18 +41,19 @@ #include "../net/socket.hpp" #include "../net/timer.t.hpp" -#include "../mmo/utils.hpp" - #include "battle.t.hpp" -#include "clif.t.hpp" +#include "../mmo/clif.t.hpp" #include "mapflag.hpp" #include "mob.t.hpp" -#include "script.hpp" // change to script.t.hpp -#include "skill.t.hpp" +#include "script-buffer.hpp" +#include "script-persist.hpp" +#include "../mmo/skill.t.hpp" namespace tmwa { +namespace map +{ constexpr int MAX_NPC_PER_MAP = 512; constexpr int BLOCK_SIZE = 8; #define AREA_SIZE battle_config.area_size @@ -61,47 +61,19 @@ 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 = 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 = 1_min; - -// formerly VString<49>, as name::label -struct NpcEvent -{ - NpcName npc; - ScriptLabel label; +constexpr std::chrono::seconds DEFAULT_AUTOSAVE_INTERVAL = 1_min; - explicit operator bool() - { - return npc || label; - } - bool operator !() - { - return !bool(*this); - } - - friend bool operator == (const NpcEvent& l, const NpcEvent& r) - { - return l.npc == r.npc && l.label == r.label; - } - - friend bool operator < (const NpcEvent& l, const NpcEvent& r) - { - return l.npc < r.npc || (l.npc == r.npc && l.label < r.label); - } - - friend VString<49> convert_for_printf(NpcEvent ev); -}; -bool extract(XString str, NpcEvent *ev); +extern map_local undefined_gat; struct block_list { dumb_ptr<block_list> bl_next, bl_prev; BlockId bl_id; - map_local *bl_m; + Borrowed<map_local> bl_m = borrow(undefined_gat); short bl_x, bl_y; BL bl_type; @@ -156,7 +128,7 @@ struct map_session_data : block_list, SessionData unsigned dead_sit:2; unsigned skillcastcancel:1; unsigned waitingdisconnect:1; - unsigned lr_flag:2; + unsigned lr_flag_is_arrow_2:1; unsigned connect_new:1; unsigned arrow_atk:1; BF attack_type;//:3; @@ -170,11 +142,10 @@ struct map_session_data : block_list, SessionData unsigned shroud_disappears_on_pickup:1; unsigned shroud_disappears_on_talk:1; unsigned seen_motd:1; + unsigned pvpchannel; } state; struct { - unsigned killer:1; - unsigned killable:1; unsigned unbreakable_weapon:1; unsigned unbreakable_armor:1; unsigned deaf:1; @@ -185,7 +156,19 @@ struct map_session_data : block_list, SessionData unsigned char tmw_version; // tmw client version CharKey status_key; CharData status; - GenericArray<struct item_data *, InventoryIndexing<IOff0, MAX_INVENTORY>> inventory_data; + GenericArray<Option<Borrowed<struct item_data>>, InventoryIndexing<IOff0, MAX_INVENTORY>> inventory_data = + {{ + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, None, None, + }}; // explicit is better than implicit earray<IOff0, EQUIP, EQUIP::COUNT> equip_index_maybe; int weight, max_weight; MapName mapname_; @@ -205,13 +188,12 @@ struct map_session_data : block_list, SessionData int npc_amount; // I have no idea exactly what these are doing ... // but one should probably be replaced with a ScriptPointer ??? - const ScriptBuffer *npc_script, *npc_scriptroot; + Option<Borrowed<const ScriptBuffer>> npc_script = None, npc_scriptroot = None; std::vector<struct script_data> npc_stackbuf; RString npc_str; struct { unsigned storage:1; - unsigned divorce:1; } npc_flags; Timer attacktimer; @@ -235,7 +217,7 @@ struct map_session_data : block_list, SessionData short spellpower_bonus_target, spellpower_bonus_current; // [Fate] Spellpower boni. _current is the active one. //_current slowly approximates _target, and _target is determined by equipment. - short attackrange, attackrange_; + short attackrange; // [Fate] Used for gradual healing; amount of enqueued regeneration struct quick_regeneration quick_regeneration_hp, quick_regeneration_sp; @@ -249,18 +231,17 @@ struct map_session_data : block_list, SessionData interval_t hp_sub, sp_sub; interval_t inchealhptick, inchealsptick; - ItemLook weapontype1, weapontype2; + ItemLook weapontype1; earray<int, ATTR, ATTR::COUNT> paramb, paramc, parame, paramcard; int hit, flee, flee2; interval_t aspd, amotion, dmotion; int watk, watk2; int def, def2, mdef, mdef2, critical, matk1, matk2; int hprate, sprate, dsprate; - int watk_, watk_2; int base_atk, atk_rate; int arrow_atk; int arrow_cri, arrow_hit, arrow_range; - int nhealhp, nhealsp, nshealhp, nshealsp, nsshealhp, nsshealsp; + int nhealhp, nhealsp; int aspd_rate, speed_rate, hprecov_rate, sprecov_rate, critical_def, double_rate; int matk_rate; @@ -269,9 +250,6 @@ struct map_session_data : block_list, SessionData mdef_rate, mdef2_rate; int double_add_rate, speed_add_rate, aspd_add_rate, perfect_hit_add; short hp_drain_rate, hp_drain_per, sp_drain_rate, sp_drain_per; - short hp_drain_rate_, hp_drain_per_, sp_drain_rate_, sp_drain_per_; - short break_weapon_rate, break_armor_rate; - short add_steal_rate; int die_counter; @@ -283,7 +261,6 @@ struct map_session_data : block_list, SessionData Map<SIR, RString> regstrm; earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data; - short sc_count; AccountId trade_partner; Array<IOff2, TRADE_MAX> deal_item_index; @@ -298,11 +275,8 @@ struct map_session_data : block_list, SessionData PartyId partyspy; // [Syrus22] - int catch_target_class; - int pvp_point, pvp_rank; Timer pvp_timer; - int pvp_lastusers; std::list<NpcEvent> eventqueuel; Array<Timer, MAX_EVENTTIMER> eventtimer; @@ -312,14 +286,14 @@ struct map_session_data : block_list, SessionData unsigned in_progress:1; } auto_ban_info; - TimeT chat_reset_due; - TimeT chat_repeat_reset_due; + tick_t chat_reset_due; + tick_t chat_repeat_reset_due; int chat_lines_in; int chat_total_repeats; RString chat_lastmsg; tick_t flood_rates[0x220]; - TimeT packet_flood_reset_due; + tick_t packet_flood_reset_due; int packet_flood_in; IP4Address get_ip() @@ -355,7 +329,7 @@ struct npc_data : block_list Opt1 opt1; Opt2 opt2; Opt3 opt3; - Option option; + Opt0 option; short flag; std::list<RString> eventqueuel; @@ -383,6 +357,7 @@ public: std::unique_ptr<const ScriptBuffer> script; // Diameter. short xs, ys; + bool event_needs_map; // Whether the timer advances if not beyond end. bool timer_active; @@ -439,7 +414,7 @@ struct mob_data : block_list MobMode mode; struct { - map_local *m; + Borrowed<map_local> m = borrow(undefined_gat); short x0, y0, xs, ys; interval_t delay1, delay2; } spawn; @@ -478,11 +453,10 @@ struct mob_data : block_list std::vector<Item> lootitemv; earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data; - short sc_count; Opt1 opt1; Opt2 opt2; Opt3 opt3; - Option option; + Opt0 option; short min_chase; Timer deletetimer; @@ -514,10 +488,10 @@ struct map_abstract // gat is nullptr for map_remote and non-nullptr for map_local std::unique_ptr<MapCell[]> gat; + map_abstract() = default; + map_abstract(map_abstract&&) = default; virtual ~map_abstract() {} }; -extern -UPMap<MapName, map_abstract> maps_db; struct map_local : map_abstract { @@ -538,7 +512,7 @@ struct map_remote : map_abstract }; inline -MapCell read_gatp(map_local *m, int x, int y) +MapCell read_gatp(Borrowed<map_local> m, int x, int y) { assert (0 <= x && x < m->xs); assert (0 <= y && y < m->ys); @@ -554,12 +528,7 @@ struct flooritem_data : block_list Item item_data; }; -extern interval_t autosave_time; -extern int save_settings; - -extern AString motd_txt; - -extern CharName wisp_server_name; +extern const CharName WISP_SERVER_NAME; // 鯖全体情報 void map_setusers(int); @@ -580,21 +549,21 @@ public: int map_addblock(dumb_ptr<block_list>); int map_delblock(dumb_ptr<block_list>); void map_foreachinarea(std::function<void(dumb_ptr<block_list>)>, - map_local *, + Borrowed<map_local>, int, int, int, int, BL); // -- moonsoul (added map_foreachincell) void map_foreachincell(std::function<void(dumb_ptr<block_list>)>, - map_local *, + Borrowed<map_local>, int, int, BL); void map_foreachinmovearea(std::function<void(dumb_ptr<block_list>)>, - map_local *, + Borrowed<map_local>, int, int, int, int, int, int, BL); //block関連に追加 -int map_count_oncell(map_local *m, int x, int y); +int map_count_oncell(Borrowed<map_local> m, int x, int y); // 一時的object関連 BlockId map_addobject(dumb_ptr<block_list>); void map_delobject(BlockId, BL type); @@ -604,7 +573,7 @@ void map_foreachobject(std::function<void(dumb_ptr<block_list>)>, // void map_quit(dumb_ptr<map_session_data>); // npc -int map_addnpc(map_local *, dumb_ptr<npc_data>); +int map_addnpc(Borrowed<map_local>, dumb_ptr<npc_data>); void map_log(XString line); #define MAP_LOG(format, ...) \ @@ -612,7 +581,7 @@ void map_log(XString line); #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"_s)), sd->bl_x, sd->bl_y, ## __VA_ARGS__) + sd->status_key.char_id, (sd->bl_m->name_), sd->bl_x, sd->bl_y, ## __VA_ARGS__) // 床アイテム関連 void map_clearflooritem_timer(TimerData *, tick_t, BlockId); @@ -622,17 +591,15 @@ void map_clearflooritem(BlockId id) map_clearflooritem_timer(nullptr, tick_t(), id); } BlockId map_addflooritem_any(Item *, int amount, - map_local *m, int x, int y, + Borrowed<map_local> m, int x, int y, dumb_ptr<map_session_data> *owners, interval_t *owner_protection, interval_t lifetime, int dispersal); BlockId map_addflooritem(Item *, int, - map_local *, int, int, + Borrowed<map_local>, int, int, dumb_ptr<map_session_data>, dumb_ptr<map_session_data>, dumb_ptr<map_session_data>); // キャラid=>キャラ名 変換関連 -extern -DMap<BlockId, dumb_ptr<block_list>> id_db; void map_addchariddb(CharId charid, CharName name); CharName map_charid2nick(CharId); @@ -671,8 +638,8 @@ dumb_ptr<magic::invocation> map_id_is_spell(BlockId id) } -map_local *map_mapname2mapid(MapName); -int map_mapname2ipport(MapName, IP4Address *, int *); +Option<Borrowed<map_local>> map_mapname2mapid(MapName); +int map_mapname2ipport(MapName, Borrowed<IP4Address>, Borrowed<int>); int map_setipport(MapName name, IP4Address ip, int port); void map_addiddb(dumb_ptr<block_list>); void map_deliddb(dumb_ptr<block_list> bl); @@ -689,14 +656,14 @@ dumb_ptr<map_session_data> map_get_prev_session( dumb_ptr<map_session_data> current); // gat関連 -MapCell map_getcell(map_local *, int, int); -void map_setcell(map_local *, int, int, MapCell); +MapCell map_getcell(Borrowed<map_local>, int, int); +void map_setcell(Borrowed<map_local>, int, int, MapCell); // その他 bool map_check_dir(DIR s_dir, DIR t_dir); DIR map_calc_dir(dumb_ptr<block_list> src, int x, int y); -std::pair<uint16_t, uint16_t> map_randfreecell(map_local *m, +std::pair<uint16_t, uint16_t> map_randfreecell(Borrowed<map_local> m, uint16_t x, uint16_t y, uint16_t w, uint16_t h); inline dumb_ptr<map_session_data> block_list::as_player() { return dumb_ptr<map_session_data>(static_cast<map_session_data *>(this)) ; } @@ -722,4 +689,14 @@ 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 ; } + +void map_addmap(MapName mapname); +void map_delmap(MapName mapname); + +struct charid2nick +{ + CharName nick; + int req_id; +}; +} // namespace map } // namespace tmwa |