summaryrefslogtreecommitdiff
path: root/src/map/map.hpp
blob: 7cf43d515c6225e0eb5e6ca1b7b387a5a372fe52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
#pragma once
//    map.hpp - Core of the map server.
//
//    Copyright © ????-2004 Athena Dev Teams
//    Copyright © 2004-2011 The Mana World Development Team
//    Copyright © 2011-2014 Ben Longbons <b.r.longbons@gmail.com>
//
//    This file is part of The Mana World (Athena server)
//
//    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 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 <http://www.gnu.org/licenses/>.

#include "map.t.hpp"

#include "fwd.hpp"

#include <chrono>
#include <functional>
#include <list>

#include "../ints/udl.hpp"

#include "../strings/rstring.hpp"
#include "../strings/astring.hpp"
#include "../strings/vstring.hpp"

#include "../generic/db.hpp"
#include "../generic/dumb_ptr.hpp"
#include "../generic/matrix.hpp"

#include "../net/socket.hpp"
#include "../net/timer.t.hpp"

#include "battle.t.hpp"
#include "../mmo/clif.t.hpp"
#include "mapflag.hpp"
#include "mob.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
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 int MAX_LEVEL = 255;
constexpr int MAX_WALKPATH = 48;
constexpr int MAX_DROP_PER_MAP = 48;

constexpr std::chrono::seconds DEFAULT_AUTOSAVE_INTERVAL = 1_min;

extern map_local undefined_gat;

struct block_list
{
    dumb_ptr<block_list> bl_next, bl_prev;
    BlockId bl_id;
    Borrowed<map_local> bl_m = borrow(undefined_gat);
    short bl_x, bl_y;
    BL bl_type;

    // register keys are ints (interned)
    // Not anymore! Well, sort of.
    DMap<SIR, int> regm;
    // can't be DMap because we want predictable .c_str()s
    // TODO this can change now
    Map<SIR, RString> regstrm;

    // This deletes the copy-ctor also
    // TODO give proper ctors.
    block_list& operator = (block_list&&) = delete;
    virtual ~block_list() {}

private:
    // historically, a lot of code used this.
    // historically, a lot of code crashed.
    dumb_ptr<map_session_data> as_player();
    dumb_ptr<npc_data> as_npc();
    dumb_ptr<mob_data> as_mob();
    dumb_ptr<flooritem_data> as_item();
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();
};

struct walkpath_data
{
    unsigned char path_len, path_pos, path_half;
    Array<DIR, MAX_WALKPATH> path;
};
struct status_change
{
    Timer timer;
    int val1;
};

struct quick_regeneration
{                               // [Fate]
    int amount;                // Amount of HP/SP left to regenerate
    unsigned char speed;        // less is faster (number of half-second ticks to wait between updates)
    unsigned char tickdelay;    // number of ticks to next update
};

enum class AutoMod
{
    off = 0,
    autokill,
    automove,
    autoblock,
    autokick,
};

struct map_session_data : block_list, SessionData
{
    struct
    {
        unsigned auth:1;
        unsigned change_walk_target:1;
        unsigned attack_continue:1;
        unsigned menu_or_input:1;
        unsigned dead_sit:2;
        unsigned skillcastcancel:1;
        unsigned waitingdisconnect:1;
        unsigned lr_flag_is_arrow_2:1;
        unsigned connect_new:1;
        unsigned arrow_atk:1;
        BF attack_type;//:3;
        unsigned skill_flag:1;
        unsigned gangsterparadise:1;
        unsigned produce_flag:1;
        unsigned make_arrow_flag:1;
        unsigned storage_open:1;
        unsigned shroud_active:1;
        unsigned shroud_hides_name_talking:1;
        unsigned shroud_disappears_on_pickup:1;
        unsigned shroud_disappears_on_talk:1;
        unsigned pvpchannel;
        unsigned pvp_rank;
        unsigned npc_dialog_mes:1;
    } state;
    struct
    {
        unsigned unbreakable_weapon:1;
        unsigned unbreakable_armor:1;
        unsigned deaf:1;
    } special_state;
    CharId char_id_;
    int login_id1, login_id2;
    SEX sex;
    ClientVersion client_version;  // tmw client version
    CharKey status_key;
    CharData status;
    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_;
    Session *sess; // use this, you idiots!
    short to_x, to_y;
    interval_t speed, speed_cap;
    Opt1 opt1;
    Opt2 opt2;
    Opt3 opt3;
    DIR dir, head_dir;
    struct walkpath_data walkpath;
    Timer walktimer;
    BlockId npc_id, areanpc_id, npc_shopid;
    // this is important
    int npc_pos;
    int npc_menu;
    int npc_amount;
    // I have no idea exactly what these are doing ...
    // but one should probably be replaced with a ScriptPointer ???
    Option<Borrowed<const ScriptBuffer>> npc_script = None, npc_scriptroot = None;
    std::vector<struct script_data> npc_stackbuf;
    RString npc_str;
    struct
    {
        unsigned storage:1;
    } npc_flags;

    Timer attacktimer;
    BlockId attacktarget;
    ATK attacktarget_lv;
    tick_t attackabletime;

    // used by @hugo and @linus
    BlockId followtarget;

    //tick_t cast_tick;     // [Fate] Next tick at which spellcasting is allowed
    BlockId attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it
    NpcEvent magic_attack;
    // like a weapon.  Check pc_attack_timer() for details.
    // Weapon equipment slot (slot 4) item override
    StatusChange attack_spell_icon_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
    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;

    // [Fate] Used for gradual healing; amount of enqueued regeneration
    struct quick_regeneration quick_regeneration_hp, quick_regeneration_sp;
    // [Fate] XP that can be extracted from this player by healing
    int heal_xp;               // i.e., OTHER players (healers) can partake in this player's XP

    Timer invincible_timer;
    tick_t canact_tick;
    tick_t canmove_tick;
    tick_t canlog_tick;
    interval_t hp_sub, sp_sub;
    interval_t inchealhptick, inchealsptick;

    ItemLook weapontype1;
    earray<int, ATTR, ATTR::COUNT> paramb, paramc, parame, paramcard;
    int hit, flee, flee2;
    interval_t aspd, amotion, dmotion, base_weapon_delay_adjust;
    int watk, watk2;
    int def, def2, mdef, mdef2, critical, matk1, matk2;
    int hprate, sprate, dsprate;
    int base_atk, atk_rate;
    int arrow_atk;
    int arrow_cri, arrow_hit, arrow_range;
    int nhealhp, nhealsp;
    int aspd_rate, speed_rate, hprecov_rate, sprecov_rate, critical_def,
        double_rate;
    int matk_rate;
    int perfect_hit, deadly_strike;
    int critical_rate, hit_rate, flee_rate, flee2_rate, def_rate, def2_rate,
        mdef_rate, mdef2_rate;
    int double_add_rate, speed_add_rate, aspd_add_rate, perfect_hit_add_rate, deadly_strike_add_rate;
    short hp_drain_rate, hp_drain_per, sp_drain_rate, sp_drain_per;

    int die_counter;

    earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;

    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;
    PartyId party_invite;
    AccountId party_invite_account;
    int party_hp, party_x, party_y;

    PartyId partyspy;              // [Syrus22]

    int pvp_point, pvp_rank;
    Timer pvp_timer;

    std::list<NpcEvent> eventqueuel;
    Array<Timer, MAX_EVENTTIMER> eventtimer;

    struct
    {
        unsigned in_progress:1;
    } auto_ban_info;

    tick_t chat_reset_due;
    tick_t chat_repeat_reset_due;
    int chat_lines_in;
    int chat_total_repeats;
    RString chat_lastmsg;

    struct
    {
        unsigned global:1;
        unsigned party:1;
        unsigned whisper:1;
        unsigned guild:1;
    } mute;

    struct
    {
        int kills;
        int casts;
        int items_used;
        int tiles_walked;
        int attacks;
    } activity;

    AutoMod automod;

    tick_t flood_rates[0x220];
    tick_t packet_flood_reset_due;
    int packet_flood_in;

    IP4Address get_ip()
    {
        return sess->client_ip;
    }
};

struct npc_timerevent_list
{
    interval_t timer;
    int pos;
};
struct npc_label_list
{
    ScriptLabel name;
    int pos;
};
struct npc_item_list
{
    ItemNameId nameid;
    int value;
};

struct npc_data : block_list
{
    NpcSubtype npc_subtype;
    short n;
    Species npc_class;
    DIR dir;
    SEX sex;
    DamageType sit;
    interval_t speed;
    NpcName name;
    Opt1 opt1;
    Opt2 opt2;
    Opt3 opt3;
    Opt0 option;
    short flag;

    bool deletion_pending;

    Array<Timer, MAX_EVENTTIMER> eventtimer;

private:
    dumb_ptr<npc_data_script> as_script();
    dumb_ptr<npc_data_shop> as_shop();
    dumb_ptr<npc_data_warp> as_warp();
public:
    dumb_ptr<npc_data_script> is_script();
    dumb_ptr<npc_data_shop> is_shop();
    dumb_ptr<npc_data_warp> is_warp();
};

class npc_data_script : public npc_data
{
public:
    struct
    {
        // The bytecode unique to this NPC.
        std::unique_ptr<const ScriptBuffer> script;
        // Diameter.
        short xs, ys;
        bool event_needs_map;

        // the npc containing the actual script
        BlockId parent;

        // Whether the timer advances if not beyond end.
        bool timer_active;
        // Tick counter through the timers.
        // It is actually updated when frobbing the thing in any way.
        // If this is timer_eventv().back().timer, it is expired
        // rather than blank. It's probably a bad idea to rely on this.
        interval_t timer;
        // Actual timer that fires the event.
        Timer timerid;
        // Event to be fired, or .end() if no timer.
        std::vector<npc_timerevent_list>::iterator next_event;
        // When the timer started. Needed to get the true diff, or to stop.
        tick_t timertick;
        // List of label events to call.
        std::vector<npc_timerevent_list> timer_eventv;

        // List of (name, offset) label locations in the bytecode
        std::vector<npc_label_list> label_listv;
    } scr;
};

class npc_data_shop : public npc_data
{
public:
    std::vector<npc_item_list> shop_items;
};

class npc_data_warp : public npc_data
{
public:
    struct
    {
        short xs, ys;
        short x, y;
        MapName name;
    } warp;
};

constexpr int MOB_XP_BONUS_BASE = 1024;
constexpr int MOB_XP_BONUS_SHIFT = 10;

struct mob_data : block_list
{
    short n;
    Species mob_class;
    DIR dir;
    MobMode mode;
    struct
    {
        Borrowed<map_local> m = borrow(undefined_gat);
        short x0, y0, xs, ys;
        interval_t delay1, delay2;
    } spawn;
    MobName name;
    struct
    {
        MS state;
        MobSkillState skillstate;
        unsigned attackable:1;
        unsigned steal_flag:1;
        unsigned steal_coin_flag:1;
        unsigned skillcastcancel:1;
        unsigned master_check:1;
        unsigned change_walk_target:1;
        unsigned walk_easy:1;
        unsigned special_mob_ai:3;
    } state;
    Timer timer;
    short to_x, to_y;
    int hp;
    BlockId target_id, attacked_id;
    ATK target_lv;
    struct walkpath_data walkpath;
    tick_t next_walktime;
    tick_t attackabletime;
    tick_t last_deadtime, last_spawntime, last_thinktime;
    tick_t canmove_tick;
    short move_fail_count;
    struct DmgLogEntry
    {
        BlockId id;
        int dmg;
    };
    // logically a map ...
    std::vector<DmgLogEntry> dmglogv;
    std::vector<Item> lootitemv;

    earray<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
    Opt1 opt1;
    Opt2 opt2;
    Opt3 opt3;
    Opt0 option;
    short min_chase;
    Timer deletetimer;

    Timer skilltimer;
    BlockId skilltarget;
    short skillx, skilly;
    SkillID skillid;
    short skilllv;
    struct mob_skill *skillidx;
    std::unique_ptr<tick_t[]> skilldelayup; // [MAX_MOBSKILL];
    LevelElement def_ele;
    BlockId master_id;
    BlockId last_master_id;
    int master_dist;
    int exclusion_src, exclusion_party;
    NpcEvent npc_event;
    // [Fate] mob-specific stats
    earray<unsigned short, mob_stat, mob_stat::LAST> stats;
    short size;
};

struct BlockLists
{
    dumb_ptr<block_list> normal, mobs_only;
};

struct map_abstract
{
    MapName name_;
    // 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() {}
};

struct map_local : map_abstract
{
    Matrix<BlockLists> blocks;
    short xs, ys;
    int npc_num;
    int users;
    MapFlags flag;
    Point save;
    Point resave;
    int mask;
    Array<dumb_ptr<npc_data>, MAX_NPC_PER_MAP> npc;
};

struct map_remote : map_abstract
{
    IP4Address ip;
    uint16_t port;
};

inline
MapCell read_gatp(Borrowed<map_local> m, int x, int y)
{
    assert (0 <= x && x < m->xs);
    assert (0 <= y && y < m->ys);
    return m->gat[x + y * m->xs];
}

struct flooritem_data : block_list
{
    short subx, suby;
    Timer cleartimer;
    BlockId first_get_id, second_get_id, third_get_id;
    tick_t first_get_tick, second_get_tick, third_get_tick;
    Item item_data;
};

extern const CharName WISP_SERVER_NAME;

// 鯖全体情報
void map_setusers(int);
int map_getusers(void);

class MapBlockLock
{
    MapBlockLock(const MapBlockLock&) = delete;
    MapBlockLock& operator = (const MapBlockLock&) = delete;
public:
    MapBlockLock();
    ~MapBlockLock();

    static
    void freeblock(dumb_ptr<block_list>);
};

int map_addblock(dumb_ptr<block_list>);
int map_delblock(dumb_ptr<block_list>);
void map_foreachinarea(std::function<void(dumb_ptr<block_list>)>,
        Borrowed<map_local>,
        int, int, int, int,
        BL);
// -- moonsoul (added map_foreachincell)
void map_foreachincell(std::function<void(dumb_ptr<block_list>)>,
        Borrowed<map_local>,
        int, int,
        BL);
void map_foreachinmovearea(std::function<void(dumb_ptr<block_list>)>,
        Borrowed<map_local>,
        int, int, int, int,
        int, int,
        BL);
//block関連に追加
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);
void map_delobjectnofree(BlockId id, BL type);
void map_foreachobject(std::function<void(dumb_ptr<block_list>)>,
        BL);
//
void map_quit(dumb_ptr<map_session_data>);
// npc
int map_addnpc(Borrowed<map_local>, dumb_ptr<npc_data>);

void map_log(XString line);
#define MAP_LOG(format, ...)    \
    map_log(STRPRINTF(format, ## __VA_ARGS__))

#define MAP_LOG_AND_ECHO(...)   \
    do {                        \
      PRINTF(__VA_ARGS__);      \
      MAP_LOG(__VA_ARGS__);     \
    } while (0)

#define MAP_LOG_PC(sd, fmt, ...)    \
    MAP_LOG("PC%d %s:%d,%d " fmt,   \
            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);
inline
void map_clearflooritem(BlockId id)
{
    map_clearflooritem_timer(nullptr, tick_t(), id);
}
BlockId map_addflooritem_any(Item *, int amount,
        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,
        Borrowed<map_local>, int, int,
        dumb_ptr<map_session_data>, dumb_ptr<map_session_data>,
        dumb_ptr<map_session_data>);

// キャラid=>キャラ名 変換関連
void map_addchariddb(CharId charid, CharName name);
CharName map_charid2nick(CharId);

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(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(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(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(BlockId id)
{
    dumb_ptr<block_list> bl = map_id2bl(id);
    return bl ? bl->is_item() : nullptr;
}

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);
void map_addnickdb(dumb_ptr<map_session_data>);
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(Item *a, Item *b);

dumb_ptr<map_session_data> map_get_first_session(void);
dumb_ptr<map_session_data> map_get_last_session(void);
dumb_ptr<map_session_data> map_get_next_session(
        dumb_ptr<map_session_data> current);
dumb_ptr<map_session_data> map_get_prev_session(
        dumb_ptr<map_session_data> current);

// gat関連
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(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)) ; }
inline dumb_ptr<npc_data> block_list::as_npc() { return dumb_ptr<npc_data>(static_cast<npc_data *>(this)) ; }
inline dumb_ptr<mob_data> block_list::as_mob() { return dumb_ptr<mob_data>(static_cast<mob_data *>(this)) ; }
inline dumb_ptr<flooritem_data> block_list::as_item() { return dumb_ptr<flooritem_data>(static_cast<flooritem_data *>(this)) ; }

inline dumb_ptr<map_session_data> block_list::is_player() { return bl_type == BL::PC ? as_player() : nullptr; }
inline dumb_ptr<npc_data> block_list::is_npc() { return bl_type == BL::NPC ? as_npc() : nullptr; }
inline dumb_ptr<mob_data> block_list::is_mob() { return bl_type == BL::MOB ? as_mob() : nullptr; }
inline dumb_ptr<flooritem_data> block_list::is_item() { return bl_type == BL::ITEM ? as_item() : nullptr; }

// struct invocation is defined in another header

inline dumb_ptr<npc_data_script> npc_data::as_script() { return dumb_ptr<npc_data_script>(static_cast<npc_data_script *>(this)) ; }
inline dumb_ptr<npc_data_shop> npc_data::as_shop() { return dumb_ptr<npc_data_shop>(static_cast<npc_data_shop *>(this)) ; }
inline dumb_ptr<npc_data_warp> npc_data::as_warp() { return dumb_ptr<npc_data_warp>(static_cast<npc_data_warp *>(this)) ; }

inline dumb_ptr<npc_data_script> npc_data::is_script() { return npc_subtype == NpcSubtype::SCRIPT ? as_script() : nullptr ; }
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 ; }

void map_addmap(MapName mapname);
void map_delmap(MapName mapname);

struct charid2nick
{
    CharName nick;
    int req_id;
};

struct AuthFifoEntry
{
    AccountId account_id;
    CharId char_id;
    int login_id1, login_id2;
    IP4Address ip;
    int delflag;
};
} // namespace map
} // namespace tmwa