diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/char/char.cpp | 16 | ||||
-rw-r--r-- | src/login/login.cpp | 20 | ||||
-rw-r--r-- | src/map/atcommand.cpp | 4 | ||||
-rw-r--r-- | src/map/battle.cpp | 20 | ||||
-rw-r--r-- | src/map/chrif.cpp | 8 | ||||
-rw-r--r-- | src/map/clif.cpp | 14 | ||||
-rw-r--r-- | src/map/magic-stmt.cpp | 2 | ||||
-rw-r--r-- | src/map/map.hpp | 6 | ||||
-rw-r--r-- | src/map/mob.cpp | 36 | ||||
-rw-r--r-- | src/map/npc.cpp | 14 | ||||
-rw-r--r-- | src/map/party.cpp | 2 | ||||
-rw-r--r-- | src/map/pc.cpp | 46 | ||||
-rw-r--r-- | src/map/script.cpp | 6 | ||||
-rw-r--r-- | src/map/skill.cpp | 10 | ||||
-rw-r--r-- | src/mmo/consts.hpp | 4 | ||||
-rw-r--r-- | src/net/timer.cpp | 8 | ||||
-rw-r--r-- | src/net/timer.t.hpp | 22 |
17 files changed, 130 insertions, 108 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp index 392943a..8d3bccb 100644 --- a/src/char/char.cpp +++ b/src/char/char.cpp @@ -90,11 +90,11 @@ Array<int, MAX_MAP_SERVERS> server_freezeflag; // Map-server anti-freeze syst static int anti_freeze_enable = 0; static -std::chrono::seconds anti_freeze_interval = std::chrono::seconds(6); +std::chrono::seconds anti_freeze_interval = 6_s; constexpr std::chrono::milliseconds DEFAULT_AUTOSAVE_INTERVAL = - std::chrono::minutes(5); + 5_min; static Session *login_session, *char_session; @@ -3037,7 +3037,7 @@ bool char_config(XString w1, ZString w2) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), - std::chrono::seconds(5)); + 5_s); } else { @@ -3130,13 +3130,13 @@ int do_init(Slice<ZString> argv) char_session = make_listen_port(char_port, SessionParsers{parse_char, delete_char}); - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, check_connect_login_server, - std::chrono::seconds(10) + 10_s ).detach(); - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, send_users_tologin, - std::chrono::seconds(5) + 5_s ).detach(); Timer(gettick() + autosave_time, mmo_char_sync_timer, @@ -3145,7 +3145,7 @@ int do_init(Slice<ZString> argv) if (anti_freeze_enable > 0) { - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, map_anti_freeze_system, anti_freeze_interval ).detach(); diff --git a/src/login/login.cpp b/src/login/login.cpp index a8bc7a0..1d6b909 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -133,7 +133,7 @@ int save_unknown_packets = 0; static tick_t creation_time_GM_account_file; static -std::chrono::seconds gm_account_filename_check_timer = std::chrono::seconds(15); +std::chrono::seconds gm_account_filename_check_timer = 15_s; static int display_parse_login = 0; // 0: no, 1: yes @@ -151,7 +151,7 @@ Array<int, MAX_SERVERS> server_freezeflag; // Char-server anti-freeze system. static int anti_freeze_enable = 0; static -std::chrono::seconds anti_freeze_interval = std::chrono::seconds(15); +std::chrono::seconds anti_freeze_interval = 15_s; static Session *login_session; @@ -3489,7 +3489,7 @@ bool login_config(XString w1, ZString w2) { anti_freeze_interval = std::max( std::chrono::seconds(atoi(w2.c_str())), - std::chrono::seconds(5)); + 5_s); } else if (w1 == "update_host"_s) { @@ -3574,14 +3574,14 @@ bool display_conf_warnings(void) { PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); PRINTF(" -> set to 15 sec (default).\n"_fmt); - gm_account_filename_check_timer = std::chrono::seconds(15); + gm_account_filename_check_timer = 15_s; rv = false; } - else if (gm_account_filename_check_timer == std::chrono::seconds(1)) + else if (gm_account_filename_check_timer == 1_s) { PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n"_fmt); PRINTF(" -> set to 2 sec (minimum value).\n"_fmt); - gm_account_filename_check_timer = std::chrono::seconds(2); + gm_account_filename_check_timer = 2_s; rv = false; } @@ -3939,14 +3939,14 @@ int do_init(Slice<ZString> argv) login_session = make_listen_port(login_port, SessionParsers{.func_parse= parse_login, .func_delete= delete_login}); - Timer(gettick() + std::chrono::minutes(5), + Timer(gettick() + 5_min, check_auth_sync, - std::chrono::minutes(5) + 5_min ).detach(); if (anti_freeze_enable > 0) { - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, char_anti_freeze_system, anti_freeze_interval ).detach(); @@ -3955,7 +3955,7 @@ int do_init(Slice<ZString> argv) // add timer to check GM accounts file modification std::chrono::seconds j = gm_account_filename_check_timer; if (j == interval_t::zero()) - j = std::chrono::minutes(1); + j = 1_min; Timer(gettick() + j, check_GM_file, j).detach(); diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index e6e321d..a17838f 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -1613,7 +1613,7 @@ ATCE atcommand_pvpon(Session *s, dumb_ptr<map_session_data> sd, { if (sd->bl_m == pl_sd->bl_m && !pl_sd->pvp_timer) { - pl_sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200), + pl_sd->pvp_timer = Timer(gettick() + 200_ms, std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, pl_sd->bl_id)); pl_sd->pvp_rank = 0; pl_sd->pvp_lastusers = 0; @@ -4403,7 +4403,7 @@ ATCE atcommand_summon(Session *, dumb_ptr<map_session_data> sd, md->master_id = sd->bl_id; md->state.special_mob_ai = 1; md->mode = get_mob_db(md->mob_class).mode | MobMode::AGGRESSIVE; - md->deletetimer = Timer(tick + std::chrono::minutes(1), + md->deletetimer = Timer(tick + 1_min, std::bind(mob_timer_delete, ph::_1, ph::_2, id)); clif_misceffect(md, 344); diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 5219675..c0459a7 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -712,16 +712,16 @@ int battle_get_mdef2(dumb_ptr<block_list> bl) */ interval_t battle_get_speed(dumb_ptr<block_list> bl) { - nullpo_retr(std::chrono::seconds(1), bl); + nullpo_retr(1_s, bl); if (bl->bl_type == BL::PC) return bl->is_player()->speed; else { - interval_t speed = std::chrono::seconds(1); + interval_t speed = 1_s; if (bl->bl_type == BL::MOB) speed = static_cast<interval_t>(bl->is_mob()->stats[mob_stat::SPEED]); - return std::max(speed, std::chrono::milliseconds(1)); + return std::max(speed, 1_ms); } } @@ -733,13 +733,13 @@ interval_t battle_get_speed(dumb_ptr<block_list> bl) // TODO figure out what all the doubling is about interval_t battle_get_adelay(dumb_ptr<block_list> bl) { - nullpo_retr(std::chrono::seconds(4), bl); + nullpo_retr(4_s, bl); if (bl->bl_type == BL::PC) return bl->is_player()->aspd * 2; else { eptr<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data = battle_get_sc_data(bl); - interval_t adelay = std::chrono::seconds(4); + interval_t adelay = 4_s; int aspd_rate = 100; if (bl->bl_type == BL::MOB) adelay = static_cast<interval_t>(bl->is_mob()->stats[mob_stat::ADELAY]); @@ -761,13 +761,13 @@ interval_t battle_get_adelay(dumb_ptr<block_list> bl) interval_t battle_get_amotion(dumb_ptr<block_list> bl) { - nullpo_retr(std::chrono::seconds(2), bl); + nullpo_retr(2_s, bl); if (bl->bl_type == BL::PC) return bl->is_player()->amotion; else { eptr<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data = battle_get_sc_data(bl); - interval_t amotion = std::chrono::seconds(2); + interval_t amotion = 2_s; int aspd_rate = 100; if (bl->bl_type == BL::MOB) amotion = static_cast<interval_t>(get_mob_db(bl->is_mob()->mob_class).amotion); @@ -798,7 +798,7 @@ interval_t battle_get_dmotion(dumb_ptr<block_list> bl) return bl->is_player()->dmotion; } else - return std::chrono::seconds(2); + return 2_s; } LevelElement battle_get_element(dumb_ptr<block_list> bl) @@ -2052,7 +2052,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, && (sd->status.weapon == ItemLook::_16 || sd->status.weapon >= ItemLook::SINGLE_HANDED_COUNT) && wd.damage2 == 0) - clif_damage(src, target, tick + std::chrono::milliseconds(10), + clif_damage(src, target, tick + 10_ms, wd.amotion, wd.dmotion, 0, 1, DamageType::NORMAL, 0); } @@ -2580,7 +2580,7 @@ bool battle_config_read(ZString cfgName) void battle_config_check() { { - if (static_cast<interval_t>(battle_config.flooritem_lifetime) < std::chrono::seconds(1)) + if (static_cast<interval_t>(battle_config.flooritem_lifetime) < 1_s) battle_config.flooritem_lifetime = std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count(); if (battle_config.restart_hp_rate < 0) battle_config.restart_hp_rate = 0; diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 7c47ea7..0748f43 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -1322,13 +1322,13 @@ void check_connect_char_server(TimerData *, tick_t) */ void do_init_chrif(void) { - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, check_connect_char_server, - std::chrono::seconds(10) + 10_s ).detach(); - Timer(gettick() + std::chrono::seconds(1), + Timer(gettick() + 1_s, send_users_tochar, - std::chrono::seconds(5) + 5_s ).detach(); } } // namespace tmwa diff --git a/src/map/clif.cpp b/src/map/clif.cpp index a8a57e6..eae922d 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -1139,7 +1139,7 @@ void clif_waitclose(TimerData *, tick_t, Session *s) */ void clif_setwaitclose(Session *s) { - s->timed_close = Timer(gettick() + std::chrono::seconds(5), + s->timed_close = Timer(gettick() + 5_s, std::bind(clif_waitclose, ph::_1, ph::_2, s) ); @@ -3457,7 +3457,7 @@ RecvResult clif_parse_LoadEndAck(Session *s, dumb_ptr<map_session_data> sd) if (!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris] - sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200), + sd->pvp_timer = Timer(gettick() + 200_ms, std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, sd->bl_id)); sd->pvp_rank = 0; @@ -3587,7 +3587,7 @@ void clif_do_quit_game(Session *s, dumb_ptr<map_session_data> sd) /* Rovert's prevent logout option fixed [Valaris] */ if (!battle_config.prevent_logout - || tick >= sd->canlog_tick + std::chrono::seconds(10)) + || tick >= sd->canlog_tick + 10_s) { clif_setwaitclose(s); fixed_18b.okay = 0; @@ -3966,7 +3966,7 @@ RecvResult clif_parse_Restart(Session *s, dumb_ptr<map_session_data> sd) case 0x01: /* Rovert's Prevent logout option - Fixed [Valaris] */ if (!battle_config.prevent_logout - || gettick() >= sd->canlog_tick + std::chrono::seconds(10)) + || gettick() >= sd->canlog_tick + 10_s) { chrif_charselectreq(sd); } @@ -5398,7 +5398,7 @@ uint16_t clif_check_packet_flood(Session *s, int cmd) // Default rate is 100ms interval_t rate = clif_parse_func_table[cmd].rate; if (rate == interval_t::zero()) - rate = std::chrono::milliseconds(100); + rate = 100_ms; // ActionRequest - attacks are allowed a faster rate than sit/stand if (cmd == 0x89) @@ -5413,9 +5413,9 @@ uint16_t clif_check_packet_flood(Session *s, int cmd) return 0; } if (damage_type == DamageType::NORMAL || damage_type == DamageType::CONTINUOUS) - rate = std::chrono::milliseconds(20); + rate = 20_ms; else - rate = std::chrono::seconds(1); + rate = 1_s; } // Restore this code when mana1.0 is released diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 57fbe66..cbd97a8 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -305,7 +305,7 @@ dumb_ptr<npc_data> local_spell_effect(map_local *m, int x, int y, int effect, interval_t tdelay) { /* 1 minute should be enough for all interesting spell effects, I hope */ - std::chrono::seconds delay = std::chrono::seconds(30); + std::chrono::seconds delay = 30_s; dumb_ptr<npc_data> effect_npc = npc_spawn_text(m, x, y, INVISIBLE_NPC, NpcName(), "?"_s); BlockId effect_npc_id = effect_npc->bl_id; diff --git a/src/map/map.hpp b/src/map/map.hpp index e9a37b6..0e4815c 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -57,16 +57,16 @@ 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); +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 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 diff --git a/src/map/mob.cpp b/src/map/mob.cpp index f9edda9..fad3083 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -59,7 +59,7 @@ namespace tmwa { -constexpr interval_t MIN_MOBTHINKTIME = std::chrono::milliseconds(100); +constexpr interval_t MIN_MOBTHINKTIME = 100_ms; // Move probability in the negligent mode MOB (rate of 1000 minute) constexpr random_::Fraction MOB_LAZYMOVEPERC {50, 1000}; @@ -672,7 +672,7 @@ int mob_walk(dumb_ptr<mob_data> md, tick_t tick, unsigned char data) { i = i / 2; if (md->walkpath.path_half == 0) - i = std::max(i, std::chrono::milliseconds(1)); + i = std::max(i, 1_ms); md->timer = Timer(tick + i, std::bind(mob_timer, ph::_1, ph::_2, md->bl_id, md->walkpath.path_pos)); @@ -879,7 +879,7 @@ int mob_changestate(dumb_ptr<mob_data> md, MS state, bool type) { tick_t tick = gettick(); interval_t i = md->attackabletime - tick; - if (i > interval_t::zero() && i < std::chrono::seconds(2)) + if (i > interval_t::zero() && i < 2_s) md->timer = Timer(md->attackabletime, std::bind(mob_timer, ph::_1, ph::_2, md->bl_id, 0)); @@ -892,7 +892,7 @@ int mob_changestate(dumb_ptr<mob_data> md, MS state, bool type) } else { - md->attackabletime = tick + std::chrono::milliseconds(1); + md->attackabletime = tick + 1_ms; md->timer = Timer(md->attackabletime, std::bind(mob_timer, ph::_1, ph::_2, md->bl_id, 0)); @@ -1058,7 +1058,7 @@ int mob_setdelayspawn(BlockId id) tick_t spawntime1 = md->last_spawntime + md->spawn.delay1; tick_t spawntime2 = md->last_deadtime + md->spawn.delay2; - tick_t spawntime3 = gettick() + std::chrono::seconds(5); + tick_t spawntime3 = gettick() + 5_s; tick_t spawntime = std::max({spawntime1, spawntime2, spawntime3}); Timer(spawntime, @@ -1121,7 +1121,7 @@ int mob_spawn(BlockId id) if (i >= 50) { - Timer(tick + std::chrono::seconds(5), + Timer(tick + 5_s, std::bind(mob_delayspawn, ph::_1, ph::_2, id) ).detach(); @@ -1151,7 +1151,7 @@ int mob_spawn(BlockId id) md->state.skillstate = MobSkillState::MSS_IDLE; assert (!md->timer); md->last_thinktime = tick; - md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(random_::to(50)); + md->next_walktime = tick + 5_s + std::chrono::milliseconds(random_::to(50)); md->attackabletime = tick; md->canmove_tick = tick; @@ -1160,7 +1160,7 @@ int mob_spawn(BlockId id) // md->skilltimer = nullptr; md->skilldelayup = make_unique<tick_t[]>(get_mob_db(md->mob_class).skills.size()); for (size_t i = 0; i < get_mob_db(md->mob_class).skills.size(); i++) - md->skilldelayup[i] = tick - std::chrono::hours(10); + md->skilldelayup[i] = tick - 10_h; md->skillid = SkillID(); md->skilllv = 0; @@ -1640,7 +1640,7 @@ int mob_ai_sub_hard_slavemob(dumb_ptr<mob_data> md, tick_t tick) while (ret && i < 10); } - md->next_walktime = tick + std::chrono::milliseconds(500); + md->next_walktime = tick + 500_ms; md->state.master_check = 1; } @@ -1684,7 +1684,7 @@ int mob_unlocktarget(dumb_ptr<mob_data> md, tick_t tick) md->target_id = BlockId(); md->state.attackable = false; md->state.skillstate = MobSkillState::MSS_IDLE; - md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(random_::to(3000)); + md->next_walktime = tick + 3_s + std::chrono::milliseconds(random_::to(3000)); return 0; } @@ -1738,7 +1738,7 @@ int mob_randomwalk(dumb_ptr<mob_data> md, tick_t tick) else c += speed; } - md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(random_::to(3000)) + c; + md->next_walktime = tick + 3_s + std::chrono::milliseconds(random_::to(3000)) + c; md->state.skillstate = MobSkillState::MSS_WALK; return 1; } @@ -1919,7 +1919,7 @@ void mob_ai_sub_hard(dumb_ptr<block_list> bl, tick_t tick) else { // 追跡 - md->next_walktime = tick + std::chrono::milliseconds(500); + md->next_walktime = tick + 500_ms; i = 0; do { @@ -2003,7 +2003,7 @@ void mob_ai_sub_hard(dumb_ptr<block_list> bl, tick_t tick) && (md->next_walktime < tick || distance(md->to_x, md->to_y, tbl->bl_x, tbl->bl_y) <= 0)) return; // 既に移動中 - md->next_walktime = tick + std::chrono::milliseconds(500); + md->next_walktime = tick + 500_ms; dx = tbl->bl_x - md->bl_x; dy = tbl->bl_y - md->bl_y; ret = mob_walktoxy(md, md->bl_x + dx, md->bl_y + dy, 0); @@ -2045,11 +2045,11 @@ void mob_ai_sub_hard(dumb_ptr<block_list> bl, tick_t tick) { // if walktime is more than 7 seconds in the future, // set it to somewhere between 3 and 5 seconds - if (md->next_walktime > tick + std::chrono::seconds(7) + if (md->next_walktime > tick + 7_s && (md->walkpath.path_len == 0 || md->walkpath.path_pos >= md->walkpath.path_len)) { - md->next_walktime = tick + std::chrono::seconds(3) + md->next_walktime = tick + 3_s + std::chrono::milliseconds(random_::to(2000)); } @@ -2148,7 +2148,7 @@ void mob_ai_sub_lazy(dumb_ptr<block_list> bl, tick_t tick) mob_warp(md, nullptr, -1, -1, BeingRemoveWhy::NEGATIVE1); } - md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(random_::to(10 * 1000)); + md->next_walktime = tick + 5_s + std::chrono::milliseconds(random_::to(10 * 1000)); } } @@ -2640,7 +2640,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, ditem.first_sd = mvp_sd; ditem.second_sd = second_sd; ditem.third_sd = third_sd; - Timer(tick + std::chrono::milliseconds(500) + static_cast<interval_t>(i), + Timer(tick + 500_ms + static_cast<interval_t>(i), std::bind(mob_delay_item_drop, ph::_1, ph::_2, ditem) ).detach(); @@ -2658,7 +2658,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, ditem.second_sd = second_sd; ditem.third_sd = third_sd; // ? - Timer(tick + std::chrono::milliseconds(540) + static_cast<interval_t>(i), + Timer(tick + 540_ms + static_cast<interval_t>(i), std::bind(mob_delay_item_drop2, ph::_1, ph::_2, ditem) ).detach(); diff --git a/src/map/npc.cpp b/src/map/npc.cpp index 16090b2..a6427d6 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -181,7 +181,7 @@ int npc_event_dequeue(dumb_ptr<map_session_data> sd) if (!sd->eventqueuel.empty()) { - if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueuel.front())) + if (!pc_addeventtimer(sd, 100_ms, sd->eventqueuel.front())) { PRINTF("npc_event_dequeue(): Event timer is full.\n"_fmt); return 0; @@ -318,9 +318,9 @@ int npc_event_do_oninit(void) int c = npc_event_doall(stringish<ScriptLabel>("OnInit"_s)); PRINTF("npc: OnInit Event done. (%d npc)\n"_fmt, c); - Timer(gettick() + std::chrono::milliseconds(100), + Timer(gettick() + 100_ms, npc_event_do_clock, - std::chrono::seconds(1) + 1_s ).detach(); return 0; @@ -1042,7 +1042,7 @@ int npc_parse_warp(XString w1, XString, NpcName w3, XString w4) nd->npc_class = WARP_CLASS; else nd->npc_class = WARP_DEBUG_CLASS; - nd->speed = std::chrono::milliseconds(200); + nd->speed = 200_ms; nd->option = Option::ZERO; nd->opt1 = Opt1::ZERO; nd->opt2 = Opt2::ZERO; @@ -1157,7 +1157,7 @@ int npc_parse_shop(XString w1, XString, NpcName w3, ZString w4a) nd->flag = 0; nd->name = w3; nd->npc_class = npc_class; - nd->speed = std::chrono::milliseconds(200); + nd->speed = 200_ms; nd->option = Option::ZERO; nd->opt1 = Opt1::ZERO; nd->opt2 = Opt2::ZERO; @@ -1338,7 +1338,7 @@ int npc_parse_script(XString w1, XString w2, NpcName w3, ZString w4, nd->dir = dir; nd->flag = 0; nd->npc_class = npc_class; - nd->speed = std::chrono::milliseconds(200); + nd->speed = 200_ms; nd->scr.script = std::move(script); nd->option = Option::ZERO; nd->opt1 = Opt1::ZERO; @@ -1620,7 +1620,7 @@ dumb_ptr<npc_data> npc_spawn_text(map_local *m, int x, int y, retval->message = message; retval->npc_class = npc_class; - retval->speed = std::chrono::milliseconds(200); + retval->speed = 200_ms; clif_spawnnpc(retval); map_addblock(retval); diff --git a/src/map/party.cpp b/src/map/party.cpp index 7784a02..8713c60 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -46,7 +46,7 @@ namespace tmwa { // 座標やHP送信の間隔 -constexpr interval_t PARTY_SEND_XYHP_INVERVAL = std::chrono::seconds(1); +constexpr interval_t PARTY_SEND_XYHP_INVERVAL = 1_s; static Map<PartyId, PartyMost> party_db; diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 3b3a6b3..fbc64a7 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -68,7 +68,7 @@ namespace tmwa { // PVP順位計算の間隔 constexpr std::chrono::milliseconds PVP_CALCRANK_INTERVAL = - std::chrono::seconds(1); + 1_s; //define it here, since the ifdef only occurs in this file #define USE_ASTRAL_SOUL_SKILL @@ -121,23 +121,23 @@ int sp_coefficient_0 = 100; static //const earray<interval_t, ItemLook, ItemLook::SINGLE_HANDED_COUNT> aspd_base_0 //= {{ -std::chrono::milliseconds(650), -std::chrono::milliseconds(700), -std::chrono::milliseconds(750), -std::chrono::milliseconds(600), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(800), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(700), -std::chrono::milliseconds(700), -std::chrono::milliseconds(650), -std::chrono::milliseconds(900), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(2000), -std::chrono::milliseconds(2000), +650_ms, +700_ms, +750_ms, +600_ms, +2000_ms, +2000_ms, +800_ms, +2000_ms, +700_ms, +700_ms, +650_ms, +900_ms, +2000_ms, +2000_ms, +2000_ms, +2000_ms, +2000_ms, }}; static const int exp_table_0[MAX_LEVEL] = @@ -1393,7 +1393,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) if (sd->speed_rate != 100) sd->speed = sd->speed * sd->speed_rate / 100; - sd->speed = std::max(sd->speed, std::chrono::milliseconds(1)); + sd->speed = std::max(sd->speed, 1_ms); if (aspd_rate != 100) sd->aspd = sd->aspd * aspd_rate / 100; @@ -1403,7 +1403,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) sd->aspd = std::max(sd->aspd, static_cast<interval_t>(battle_config.max_aspd)); sd->amotion = sd->aspd; sd->dmotion = std::chrono::milliseconds(800 - sd->paramc[ATTR::AGI] * 4); - sd->dmotion = std::max(sd->dmotion, std::chrono::milliseconds(400)); + sd->dmotion = std::max(sd->dmotion, 400_ms); if (sd->status.hp > sd->status.max_hp) sd->status.hp = sd->status.max_hp; @@ -2528,7 +2528,7 @@ void pc_walk(TimerData *, tick_t tick, BlockId id, unsigned char data) { i = i / 2; if (sd->walkpath.path_half == 0) - i = std::max(i, std::chrono::milliseconds(1)); + i = std::max(i, 1_ms); sd->walktimer = Timer(tick + i, std::bind(pc_walk, ph::_1, ph::_2, @@ -2864,7 +2864,7 @@ int pc_attack(dumb_ptr<map_session_data> sd, BlockId target_id, int type) sd->state.attack_continue = type; interval_t d = sd->attackabletime - gettick(); - if (d > interval_t::zero() && d < std::chrono::seconds(2)) + if (d > interval_t::zero() && d < 2_s) { // 攻撃delay中 sd->attacktimer = Timer(sd->attackabletime, std::bind(pc_attack_timer, ph::_1, ph::_2, @@ -5173,7 +5173,7 @@ void pc_autosave(TimerData *, tick_t) interval_t interval = autosave_time / (clif_countusers() + 1); if (interval <= interval_t::zero()) - interval = std::chrono::milliseconds(1); + interval = 1_ms; Timer(gettick() + interval, pc_autosave ).detach(); diff --git a/src/map/script.cpp b/src/map/script.cpp index adc7789..37861e5 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -99,7 +99,7 @@ Map<SIR, RString> mapregstr_db; static int mapreg_dirty = -1; AString mapreg_txt = "save/mapreg.txt"_s; -constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10); +constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = 10_s; Map<ScriptLabel, int> scriptlabel_db; static @@ -3131,7 +3131,7 @@ void builtin_sc_start(ScriptState *st) int val1; StatusChange type = static_cast<StatusChange>(conv_num(st, &AARGO2(2))); interval_t tick = static_cast<interval_t>(conv_num(st, &AARGO2(3))); - if (tick < std::chrono::seconds(1)) + if (tick < 1_s) // work around old behaviour of: // speed potion // atk potion @@ -3307,7 +3307,7 @@ void builtin_pvpon(ScriptState *st) { if (m == pl_sd->bl_m && !pl_sd->pvp_timer) { - pl_sd->pvp_timer = Timer(gettick() + std::chrono::milliseconds(200), + pl_sd->pvp_timer = Timer(gettick() + 200_ms, std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, pl_sd->bl_id)); pl_sd->pvp_rank = 0; diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 5b5ca63..f579920 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -883,7 +883,7 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, BlockId id, StatusCh md->hp -= hp; } } - sc_data[type].timer = Timer(tick + std::chrono::seconds(1), + sc_data[type].timer = Timer(tick + 1_s, std::bind(skill_status_change_timer, ph::_1, ph::_2, bl->bl_id, type)); return; @@ -891,7 +891,7 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, BlockId id, StatusCh } else { - sc_data[type].timer = Timer(tick + std::chrono::seconds(2), + sc_data[type].timer = Timer(tick + 2_s, std::bind(skill_status_change_timer, ph::_1, ph::_2, bl->bl_id, type)); return; @@ -903,7 +903,7 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, BlockId id, StatusCh /* 時間切れ無し?? */ case StatusChange::SC_WEIGHT50: case StatusChange::SC_WEIGHT90: - sc_data[type].timer = Timer(tick + std::chrono::minutes(10), + sc_data[type].timer = Timer(tick + 10_min, std::bind(skill_status_change_timer, ph::_1, ph::_2, bl->bl_id, type)); return; @@ -1029,12 +1029,12 @@ int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, } // huh? - tick = std::chrono::seconds(1); + tick = 1_s; break; case StatusChange::SC_WEIGHT50: case StatusChange::SC_WEIGHT90: - tick = std::chrono::minutes(10); + tick = 10_min; break; case StatusChange::SC_HASTE: diff --git a/src/mmo/consts.hpp b/src/mmo/consts.hpp index 2a20cff..c1a7eb6 100644 --- a/src/mmo/consts.hpp +++ b/src/mmo/consts.hpp @@ -41,9 +41,9 @@ constexpr int TRADE_MAX = 10; constexpr int GLOBAL_REG_NUM = 96; constexpr size_t ACCOUNT_REG_NUM = 16; constexpr size_t ACCOUNT_REG2_NUM = 16; -constexpr interval_t DEFAULT_WALK_SPEED = std::chrono::milliseconds(150); +constexpr interval_t DEFAULT_WALK_SPEED = 150_ms; constexpr interval_t MIN_WALK_SPEED = interval_t::zero(); -constexpr interval_t MAX_WALK_SPEED = std::chrono::seconds(1); +constexpr interval_t MAX_WALK_SPEED = 1_s; constexpr int MAX_STORAGE = 300; constexpr int MAX_PARTY = 12; diff --git a/src/net/timer.cpp b/src/net/timer.cpp index 8d03c17..6a22616 100644 --- a/src/net/timer.cpp +++ b/src/net/timer.cpp @@ -166,7 +166,7 @@ interval_t do_timer(tick_t tick) { /// Number of milliseconds until it calls this again // this says to wait 1 sec if all timers get popped - interval_t nextmin = std::chrono::seconds(1); + interval_t nextmin = 1_s; while (dumb_ptr<TimerData> td = top_timer_heap()) { @@ -186,7 +186,7 @@ interval_t do_timer(tick_t tick) td->owner->detach(); // If we are too far past the requested tick, call with // the current tick instead to fix reregistration problems - if (td->tick + std::chrono::seconds(1) < tick) + if (td->tick + 1_s < tick) td->func(td.operator->(), tick); else td->func(td.operator->(), td->tick); @@ -196,14 +196,14 @@ interval_t do_timer(tick_t tick) td.delete_(); continue; } - if (td->tick + std::chrono::seconds(1) < tick) + if (td->tick + 1_s < tick) td->tick = tick + td->interval; else td->tick += td->interval; push_timer_heap(td); } - return std::max(nextmin, std::chrono::milliseconds(10)); + return std::max(nextmin, 10_ms); } tick_t file_modified(ZString name) diff --git a/src/net/timer.t.hpp b/src/net/timer.t.hpp index e983e07..c27389e 100644 --- a/src/net/timer.t.hpp +++ b/src/net/timer.t.hpp @@ -34,6 +34,28 @@ namespace tmwa { +constexpr +std::chrono::nanoseconds operator ""_ns(unsigned long long ns) +{ return std::chrono::nanoseconds(ns); } +constexpr +std::chrono::microseconds operator ""_us(unsigned long long us) +{ return std::chrono::microseconds(us); } +constexpr +std::chrono::milliseconds operator ""_ms(unsigned long long ms) +{ return std::chrono::milliseconds(ms); } +constexpr +std::chrono::seconds operator ""_s(unsigned long long s) +{ return std::chrono::seconds(s); } +constexpr +std::chrono::minutes operator ""_min(unsigned long long min) +{ return std::chrono::minutes(min); } +constexpr +std::chrono::hours operator ""_h(unsigned long long h) +{ return std::chrono::hours(h); } +constexpr +std::chrono::duration<int, std::ratio<60*60*24>> operator ""_d(unsigned long long d) +{ return std::chrono::duration<int, std::ratio<60*60*24>>(d); } + /// An implementation of the C++ "clock" concept, exposing /// durations in milliseconds. class milli_clock |