diff options
Diffstat (limited to 'src/map/map.cpp')
-rw-r--r-- | src/map/map.cpp | 324 |
1 files changed, 165 insertions, 159 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp index b49b225..033f299 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -29,15 +29,17 @@ #include <cassert> #include <cstdlib> -#include <cstring> #include "../compat/nullpo.hpp" #include "../compat/fun.hpp" +#include "../ints/udl.hpp" + #include "../strings/astring.hpp" #include "../strings/zstring.hpp" #include "../strings/xstring.hpp" #include "../strings/vstring.hpp" +#include "../strings/literal.hpp" #include "../generic/db.hpp" #include "../generic/random2.hpp" @@ -47,11 +49,13 @@ #include "../io/tty.hpp" #include "../io/write.hpp" +#include "../net/socket.hpp" +#include "../net/timer.hpp" + #include "../mmo/config_parse.hpp" #include "../mmo/core.hpp" #include "../mmo/extract.hpp" -#include "../mmo/socket.hpp" -#include "../mmo/timer.hpp" +#include "../mmo/utils.hpp" #include "../mmo/version.hpp" #include "atcommand.hpp" @@ -60,8 +64,8 @@ #include "clif.hpp" #include "grfio.hpp" #include "itemdb.hpp" -#include "magic.hpp" -#include "magic-interpreter.hpp" +#include "magic-interpreter.hpp" // for is_spell inline body +#include "magic-stmt.hpp" #include "magic-v2.hpp" #include "mob.hpp" #include "npc.hpp" @@ -74,7 +78,10 @@ #include "../poison.hpp" -DMap<int, dumb_ptr<block_list>> id_db; + +namespace tmwa +{ +DMap<BlockId, dumb_ptr<block_list>> id_db; UPMap<MapName, map_abstract> maps_db; @@ -88,21 +95,21 @@ struct charid2nick }; static -Map<int, struct charid2nick> charid_db; +Map<CharId, struct charid2nick> charid_db; static int users = 0; static -Array<dumb_ptr<block_list>, MAX_FLOORITEM> object; +Array<dumb_ptr<block_list>, unwrap<BlockId>(MAX_FLOORITEM)> object; static -int first_free_object_id = 0, last_object_id = 0; +BlockId first_free_object_id = BlockId(); interval_t autosave_time = DEFAULT_AUTOSAVE_INTERVAL; int save_settings = 0xFFFF; -AString motd_txt = "conf/motd.txt"; +AString motd_txt = "conf/motd.txt"_s; -CharName wisp_server_name = stringish<CharName>("Server"); // can be modified in char-server configuration file +CharName wisp_server_name = stringish<CharName>("Server"_s); // can be modified in char-server configuration file static void map_delmap(MapName mapname); @@ -112,6 +119,10 @@ void SessionDeleter::operator()(SessionData *sd) really_delete1 static_cast<map_session_data *>(sd); } +VString<49> convert_for_printf(NpcEvent ev) +{ + return STRNPRINTF(50, "%s::%s"_fmt, ev.npc, ev.label); +} bool extract(XString str, NpcEvent *ev) { XString mid; @@ -181,12 +192,12 @@ struct block_list bl_head; */ int map_addblock(dumb_ptr<block_list> bl) { - nullpo_ret(bl); + nullpo_retz(bl); if (bl->bl_prev) { if (battle_config.error_log) - PRINTF("map_addblock error : bl->bl_prev!=NULL\n"); + PRINTF("map_addblock error : bl->bl_prev!=nullptr\n"_fmt); return 0; } @@ -226,7 +237,7 @@ int map_addblock(dumb_ptr<block_list> bl) */ int map_delblock(dumb_ptr<block_list> bl) { - nullpo_ret(bl); + nullpo_retz(bl); // 既にblocklistから抜けている if (!bl->bl_prev) @@ -235,7 +246,7 @@ int map_delblock(dumb_ptr<block_list> bl) { // prevがNULLでnextがNULLでないのは有ってはならない if (battle_config.error_log) - PRINTF("map_delblock error : bl->bl_next!=NULL\n"); + PRINTF("map_delblock error : bl->bl_next!=nullptr\n"_fmt); } return 0; } @@ -261,8 +272,8 @@ int map_delblock(dumb_ptr<block_list> bl) { bl->bl_prev->bl_next = bl->bl_next; } - bl->bl_next = NULL; - bl->bl_prev = NULL; + bl->bl_next = nullptr; + bl->bl_prev = nullptr; return 0; } @@ -274,7 +285,7 @@ int map_delblock(dumb_ptr<block_list> bl) int map_count_oncell(map_local *m, int x, int y) { int bx, by; - dumb_ptr<block_list> bl = NULL; + dumb_ptr<block_list> bl = nullptr; int count = 0; if (x < 0 || y < 0 || (x >= m->xs) || (y >= m->ys)) @@ -533,29 +544,27 @@ void map_foreachincell(std::function<void(dumb_ptr<block_list>)> func, * bl->bl_idもこの中で設定して問題無い? *------------------------------------------ */ -int map_addobject(dumb_ptr<block_list> bl) +BlockId map_addobject(dumb_ptr<block_list> bl) { - int i; + BlockId i; if (!bl) { - PRINTF("map_addobject nullpo?\n"); - return 0; + PRINTF("map_addobject nullpo?\n"_fmt); + return BlockId(); } - if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM) - first_free_object_id = 2; - for (i = first_free_object_id; i < MAX_FLOORITEM; i++) - if (!object[i]) + if (first_free_object_id < wrap<BlockId>(2) || first_free_object_id == MAX_FLOORITEM) + first_free_object_id = wrap<BlockId>(2); + for (i = first_free_object_id; i < MAX_FLOORITEM; i = next(i)) + if (!object[i._value]) break; - if (i >= MAX_FLOORITEM) + if (i == MAX_FLOORITEM) { if (battle_config.error_log) - PRINTF("no free object id\n"); - return 0; + PRINTF("no free object id\n"_fmt); + return BlockId(); } first_free_object_id = i; - if (last_object_id < i) - last_object_id = i; - object[i] = bl; + object[i._value] = bl; id_db.put(i, bl); return i; } @@ -565,32 +574,26 @@ int map_addobject(dumb_ptr<block_list> bl) * map_delobjectのfreeしないバージョン *------------------------------------------ */ -int map_delobjectnofree(int id, BL type) +void map_delobjectnofree(BlockId id, BL type) { assert (id < MAX_FLOORITEM); - if (!object[id]) - return 0; + if (!object[id._value]) + return; - if (object[id]->bl_type != type) + if (object[id._value]->bl_type != type) { - FPRINTF(stderr, "Incorrect type: expected %d, got %d\n", + FPRINTF(stderr, "Incorrect type: expected %d, got %d\n"_fmt, type, - object[id]->bl_type); + object[id._value]->bl_type); abort(); } - map_delblock(object[id]); + map_delblock(object[id._value]); id_db.put(id, dumb_ptr<block_list>()); -// map_freeblock(object[id]); - object[id] = nullptr; + object[id._value] = nullptr; - if (first_free_object_id > id) + if (id < first_free_object_id) first_free_object_id = id; - - while (last_object_id > 2 && object[last_object_id] == NULL) - last_object_id--; - - return 0; } /*========================================== @@ -601,21 +604,19 @@ int map_delobjectnofree(int id, BL type) * addとの対称性が無いのが気になる *------------------------------------------ */ -int map_delobject(int id, BL type) +void map_delobject(BlockId id, BL type) { assert (id < MAX_FLOORITEM); - dumb_ptr<block_list> obj = object[id]; + dumb_ptr<block_list> obj = object[id._value]; - if (obj == NULL) - return 0; + if (obj == nullptr) + return; map_delobjectnofree(id, type); if (obj->bl_type == BL::PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from pc_cleanup(obj->is_player()); MapBlockLock::freeblock(obj); - - return 0; } /*========================================== @@ -626,24 +627,28 @@ int map_delobject(int id, BL type) void map_foreachobject(std::function<void(dumb_ptr<block_list>)> func, BL type) { - assert (last_object_id < MAX_FLOORITEM); std::vector<dumb_ptr<block_list>> bl_list; - for (int i = 2; i <= last_object_id; i++) + for (BlockId i = wrap<BlockId>(2); i < MAX_FLOORITEM; i = next(i)) { - if (!object[i]) + if (!object[i._value]) continue; { - if (type != BL::NUL && object[i]->bl_type != type) + if (type != BL::NUL && object[i._value]->bl_type != type) continue; - bl_list.push_back(object[i]); + bl_list.push_back(object[i._value]); } } MapBlockLock lock; for (dumb_ptr<block_list> bl : bl_list) + { + // TODO figure out if the second branch can happen + // bl_prev is non-null for all that are on a map (see bl_head) + // bl_next is only meaningful for objects that are on a map if (bl->bl_prev || bl->bl_next) func(bl); + } } /*========================================== @@ -656,15 +661,15 @@ void map_foreachobject(std::function<void(dumb_ptr<block_list>)> func, * map.h内で#defineしてある *------------------------------------------ */ -void map_clearflooritem_timer(TimerData *tid, tick_t, int id) +void map_clearflooritem_timer(TimerData *tid, tick_t, BlockId id) { assert (id < MAX_FLOORITEM); - dumb_ptr<block_list> obj = object[id]; + dumb_ptr<block_list> obj = object[id._value]; assert (obj && obj->bl_type == BL::ITEM); dumb_ptr<flooritem_data> fitem = obj->is_item(); if (!tid) fitem->cleartimer.cancel(); - clif_clearflooritem(fitem, 0); + clif_clearflooritem(fitem, nullptr); map_delobject(fitem->bl_id, BL::ITEM); } @@ -678,7 +683,7 @@ std::pair<uint16_t, uint16_t> map_randfreecell(map_local *m, if (!bool(read_gatp(m, x + dx, y + dy) & MapCell::UNWALKABLE)) return {static_cast<uint16_t>(x + dx), static_cast<uint16_t>(y + dy)}; } - return {static_cast<uint16_t>(0), static_cast<uint16_t>(0)}; + return {0_u16, 0_u16}; } /// Return a randomly selected passable cell within a given range. @@ -695,36 +700,36 @@ std::pair<uint16_t, uint16_t> map_searchrandfreecell(map_local *m, int x, int y, * item_dataはamount以外をcopyする *------------------------------------------ */ -int map_addflooritem_any(struct item *item_data, int amount, +BlockId map_addflooritem_any(Item *item_data, int amount, map_local *m, int x, int y, dumb_ptr<map_session_data> *owners, interval_t *owner_protection, interval_t lifetime, int dispersal) { - dumb_ptr<flooritem_data> fitem = NULL; + dumb_ptr<flooritem_data> fitem = nullptr; - nullpo_ret(item_data); + nullpo_retr(BlockId(), item_data); auto xy = map_searchrandfreecell(m, x, y, dispersal); if (xy.first == 0 && xy.second == 0) - return 0; + return BlockId(); fitem.new_(); fitem->bl_type = BL::ITEM; - fitem->bl_prev = fitem->bl_next = NULL; + fitem->bl_prev = fitem->bl_next = nullptr; fitem->bl_m = m; fitem->bl_x = xy.first; fitem->bl_y = xy.second; - fitem->first_get_id = 0; + fitem->first_get_id = BlockId(); fitem->first_get_tick = tick_t(); - fitem->second_get_id = 0; + fitem->second_get_id = BlockId(); fitem->second_get_tick = tick_t(); - fitem->third_get_id = 0; + fitem->third_get_id = BlockId(); fitem->third_get_tick = tick_t(); fitem->bl_id = map_addobject(fitem); - if (fitem->bl_id == 0) + if (!fitem->bl_id) { fitem.delete_(); - return 0; + return BlockId(); } tick_t tick = gettick(); @@ -760,7 +765,7 @@ int map_addflooritem_any(struct item *item_data, int amount, return fitem->bl_id; } -int map_addflooritem(struct item *item_data, int amount, +BlockId map_addflooritem(Item *item_data, int amount, map_local *m, int x, int y, dumb_ptr<map_session_data> first_sd, dumb_ptr<map_session_data> second_sd, @@ -784,10 +789,10 @@ int map_addflooritem(struct item *item_data, int amount, * charid_dbへ追加(返信待ちがあれば返信) *------------------------------------------ */ -void map_addchariddb(int charid, CharName name) +void map_addchariddb(CharId charid, CharName name) { struct charid2nick *p = charid_db.search(charid); - if (p == NULL) + if (p == nullptr) p = charid_db.init(charid); p->nick = name; @@ -840,7 +845,7 @@ void map_quit(dumb_ptr<map_session_data> sd) if (sd->trade_partner) // 取引を中断する trade_tradecancel(sd); - if (sd->party_invite > 0) // パーティ勧誘を拒否する + if (sd->party_invite) // パーティ勧誘を拒否する party_reply_invite(sd, sd->party_invite_account, 0); party_send_logout(sd); // パーティのログアウトメッセージ送信 @@ -883,7 +888,7 @@ void map_quit(dumb_ptr<map_session_data> sd) * id番号のPCを探す。居なければNULL *------------------------------------------ */ -dumb_ptr<map_session_data> map_id2sd(int id) +dumb_ptr<map_session_data> map_id2sd(BlockId id) { // This is bogus. // However, there might be differences for de-auth'ed accounts. @@ -899,7 +904,7 @@ dumb_ptr<map_session_data> map_id2sd(int id) bl=numdb_search(id_db,id); if (bl && bl->bl_type==BL::PC) return (struct map_session_data*)bl; - return NULL; + return nullptr; */ for (io::FD i : iter_fds()) { @@ -914,18 +919,18 @@ dumb_ptr<map_session_data> map_id2sd(int id) } } - return NULL; + return nullptr; } /*========================================== * char_id番号の名前を探す *------------------------------------------ */ -CharName map_charid2nick(int id) +CharName map_charid2nick(CharId id) { struct charid2nick *p = charid_db.search(id); - if (p == NULL) + if (p == nullptr) return CharName(); if (p->req_id != 0) return CharName(); @@ -947,7 +952,7 @@ dumb_ptr<map_session_data> map_get_session(io::FD i) return dumb_ptr<map_session_data>(d); } - return NULL; + return nullptr; } static @@ -960,7 +965,7 @@ dumb_ptr<map_session_data> map_get_session_forward(int start) return d; } - return NULL; + return nullptr; } static @@ -973,7 +978,7 @@ dumb_ptr<map_session_data> map_get_session_backward(int start) return d; } - return NULL; + return nullptr; } dumb_ptr<map_session_data> map_get_first_session(void) @@ -999,7 +1004,7 @@ dumb_ptr<map_session_data> map_get_prev_session(dumb_ptr<map_session_data> d) /*========================================== * Search session data from a nick name * (without sensitive case if necessary) - * return map_session_data pointer or NULL + * return map_session_data pointer or nullptr *------------------------------------------ */ dumb_ptr<map_session_data> map_nick2sd(CharName nick) @@ -1018,7 +1023,7 @@ dumb_ptr<map_session_data> map_nick2sd(CharName nick) } } } - return NULL; + return nullptr; } /*========================================== @@ -1026,11 +1031,11 @@ dumb_ptr<map_session_data> map_nick2sd(CharName nick) * 一時objectの場合は配列を引くのみ *------------------------------------------ */ -dumb_ptr<block_list> map_id2bl(int id) +dumb_ptr<block_list> map_id2bl(BlockId id) { - dumb_ptr<block_list> bl = NULL; - if (id < sizeof(object) / sizeof(object[0])) - bl = object[id]; + dumb_ptr<block_list> bl = nullptr; + if (id < MAX_FLOORITEM) + bl = object[id._value]; else bl = id_db.get(id); @@ -1047,12 +1052,12 @@ int map_addnpc(map_local *m, dumb_ptr<npc_data> nd) if (!m) return -1; for (i = 0; i < m->npc_num && i < MAX_NPC_PER_MAP; i++) - if (m->npc[i] == NULL) + if (m->npc[i] == nullptr) break; if (i == MAX_NPC_PER_MAP) { if (battle_config.error_log) - PRINTF("too many NPCs in one map %s\n", m->name_); + PRINTF("too many NPCs in one map %s\n"_fmt, m->name_); return -1; } if (i == m->npc_num) @@ -1060,7 +1065,7 @@ int map_addnpc(map_local *m, dumb_ptr<npc_data> nd) m->npc_num++; } - nullpo_ret(nd); + nullpo_retz(nd); m->npc[i] = nd; nd->n = i; @@ -1081,7 +1086,7 @@ void map_removenpc(void) map_local *m = static_cast<map_local *>(mitp.second.get()); for (int i = 0; i < m->npc_num && i < MAX_NPC_PER_MAP; i++) { - if (m->npc[i] != NULL) + if (m->npc[i] != nullptr) { clif_clearchar(m->npc[i], BeingRemoveWhy::QUIT); map_delblock(m->npc[i]); @@ -1096,7 +1101,7 @@ void map_removenpc(void) } } } - PRINTF("%d NPCs removed.\n", n); + PRINTF("%d NPCs removed.\n"_fmt, n); } /*========================================== @@ -1106,7 +1111,7 @@ void map_removenpc(void) map_local *map_mapname2mapid(MapName name) { map_abstract *md = maps_db.get(name); - if (md == NULL || md->gat == NULL) + if (md == nullptr || md->gat == nullptr) return nullptr; return static_cast<map_local *>(md); } @@ -1118,7 +1123,7 @@ map_local *map_mapname2mapid(MapName name) int map_mapname2ipport(MapName name, IP4Address *ip, int *port) { map_abstract *md = maps_db.get(name); - if (md == NULL || md->gat) + if (md == nullptr || md->gat) return -1; map_remote *mdos = static_cast<map_remote *>(md); *ip = mdos->ip; @@ -1227,12 +1232,12 @@ void map_setcell(map_local *m, int x, int y, MapCell t) int map_setipport(MapName name, IP4Address ip, int port) { map_abstract *md = maps_db.get(name); - if (md == NULL) + if (md == nullptr) { // not exist -> add new data auto mdos = make_unique<map_remote>(); mdos->name_ = name; - mdos->gat = NULL; + mdos->gat = nullptr; mdos->ip = ip; mdos->port = port; maps_db.put(mdos->name_, std::move(mdos)); @@ -1244,7 +1249,7 @@ int map_setipport(MapName name, IP4Address ip, int port) // local -> check data if (ip != clif_getip() || port != clif_getport()) { - PRINTF("from char server : %s -> %s:%d\n", + PRINTF("from char server : %s -> %s:%d\n"_fmt, name, ip, port); return 1; } @@ -1275,7 +1280,7 @@ bool map_readmap(map_local *m, size_t num, MapName fn) int xs = m->xs = gat_v[0] | gat_v[1] << 8; int ys = m->ys = gat_v[2] | gat_v[3] << 8; - PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)", + PRINTF("\rLoading Maps [%zu/%zu]: %-30s (%i, %i)"_fmt, num, maps_db.size(), fn, xs, ys); fflush(stdout); @@ -1328,10 +1333,10 @@ bool map_readallmap(void) } } - PRINTF("\rMaps Loaded: %-65zu\n", maps_db.size()); + PRINTF("\rMaps Loaded: %-65zu\n"_fmt, maps_db.size()); if (maps_removed) { - PRINTF("Cowardly refusing to keep going after removing %d maps.\n", + PRINTF("Cowardly refusing to keep going after removing %d maps.\n"_fmt, maps_removed); return false; } @@ -1346,7 +1351,7 @@ bool map_readallmap(void) static void map_addmap(MapName mapname) { - if (mapname == "clear") + if (mapname == "clear"_s) { maps_db.clear(); return; @@ -1366,7 +1371,7 @@ void map_addmap(MapName mapname) */ void map_delmap(MapName mapname) { - if (mapname == "all") + if (mapname == "all"_s) { maps_db.clear(); return; @@ -1389,13 +1394,13 @@ void map_close_logfile(void) { if (map_logfile) { - AString filename = STRPRINTF("%s.%ld", map_logfile_name, map_logfile_index); + AString filename = STRPRINTF("%s.%ld"_fmt, map_logfile_name, map_logfile_index); const char *args[] = { "gzip", "-f", filename.c_str(), - NULL + nullptr }; char **argv = const_cast<char **>(args); @@ -1406,7 +1411,7 @@ void map_close_logfile(void) execvp("gzip", argv); _exit(1); } - wait(NULL); + wait(nullptr); } } @@ -1416,7 +1421,7 @@ void map_start_logfile(long index) map_logfile_index = index; AString filename_buf = STRPRINTF( - "%s.%ld", + "%s.%ld"_fmt, map_logfile_name, map_logfile_index); map_logfile = make_unique<io::AppendFile>(filename_buf); @@ -1433,11 +1438,11 @@ void map_set_logfile(AString filename) struct timeval tv; map_logfile_name = std::move(filename); - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); map_start_logfile(tv.tv_sec >> LOGFILE_SECONDS_PER_CHUNK_SHIFT); - MAP_LOG("log-start v5"); + MAP_LOG("log-start v5"_fmt); } void map_log(XString line) @@ -1464,12 +1469,12 @@ void map_log(XString line) static bool map_config_read(ZString cfgName) { - struct hostent *h = NULL; + struct hostent *h = nullptr; io::ReadFile in(cfgName); if (!in.is_open()) { - PRINTF("Map configuration file not found at: %s\n", cfgName); + PRINTF("Map configuration file not found at: %s\n"_fmt, cfgName); return false; } @@ -1483,25 +1488,25 @@ bool map_config_read(ZString cfgName) ZString w2; if (!config_split(line, &w1, &w2)) { - PRINTF("Bad config line: %s\n", line); + PRINTF("Bad config line: %s\n"_fmt, line); rv = false; continue; } - if (w1 == "userid") + if (w1 == "userid"_s) { AccountName name = stringish<AccountName>(w2); chrif_setuserid(name); } - else if (w1 == "passwd") + else if (w1 == "passwd"_s) { AccountPass pass = stringish<AccountPass>(w2); chrif_setpasswd(pass); } - else if (w1 == "char_ip") + else if (w1 == "char_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; - if (h != NULL) + if (h != nullptr) { w2ip = IP4Address({ static_cast<uint8_t>(h->h_addr[0]), @@ -1509,25 +1514,25 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Character server IP address : %s -> %s\n", + PRINTF("Character server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } chrif_setip(w2ip); } - else if (w1 == "char_port") + else if (w1 == "char_port"_s) { chrif_setport(atoi(w2.c_str())); } - else if (w1 == "map_ip") + else if (w1 == "map_ip"_s) { h = gethostbyname(w2.c_str()); IP4Address w2ip; - if (h != NULL) + if (h != nullptr) { w2ip = IP4Address({ static_cast<uint8_t>(h->h_addr[0]), @@ -1535,61 +1540,61 @@ bool map_config_read(ZString cfgName) static_cast<uint8_t>(h->h_addr[2]), static_cast<uint8_t>(h->h_addr[3]), }); - PRINTF("Map server IP address : %s -> %s\n", + PRINTF("Map server IP address : %s -> %s\n"_fmt, w2, w2ip); } else { - PRINTF("Bad IP value: %s\n", line); + PRINTF("Bad IP value: %s\n"_fmt, line); return false; } clif_setip(w2ip); } - else if (w1 == "map_port") + else if (w1 == "map_port"_s) { clif_setport(atoi(w2.c_str())); } - else if (w1 == "map") + else if (w1 == "map"_s) { MapName name = VString<15>(w2); map_addmap(name); } - else if (w1 == "delmap") + else if (w1 == "delmap"_s) { MapName name = VString<15>(w2); map_delmap(name); } - else if (w1 == "npc") + else if (w1 == "npc"_s) { npc_addsrcfile(w2); } - else if (w1 == "delnpc") + else if (w1 == "delnpc"_s) { npc_delsrcfile(w2); } - else if (w1 == "autosave_time") + else if (w1 == "autosave_time"_s) { autosave_time = std::chrono::seconds(atoi(w2.c_str())); if (autosave_time <= interval_t::zero()) autosave_time = DEFAULT_AUTOSAVE_INTERVAL; } - else if (w1 == "motd_txt") + else if (w1 == "motd_txt"_s) { motd_txt = w2; } - else if (w1 == "mapreg_txt") + else if (w1 == "mapreg_txt"_s) { mapreg_txt = w2; } - else if (w1 == "gm_log") + else if (w1 == "gm_log"_s) { gm_log = std::move(w2); } - else if (w1 == "log_file") + else if (w1 == "log_file"_s) { map_set_logfile(w2); } - else if (w1 == "import") + else if (w1 == "import"_s) { rv &= map_config_read(w2); } @@ -1656,7 +1661,7 @@ void term_func(void) map_close_logfile(); } -int compare_item(struct item *a, struct item *b) +int compare_item(Item *a, Item *b) { return (a->nameid == b->nameid); } @@ -1664,29 +1669,29 @@ int compare_item(struct item *a, struct item *b) static bool map_confs(XString key, ZString value) { - if (key == "map_conf") + if (key == "map_conf"_s) return map_config_read(value); - if (key == "battle_conf") + if (key == "battle_conf"_s) return battle_config_read(value); - if (key == "atcommand_conf") + if (key == "atcommand_conf"_s) return atcommand_config_read(value); - if (key == "item_db") + if (key == "item_db"_s) return itemdb_readdb(value); - if (key == "mob_db") + if (key == "mob_db"_s) return mob_readdb(value); - if (key == "mob_skill_db") + if (key == "mob_skill_db"_s) return mob_readskilldb(value); - if (key == "skill_db") + if (key == "skill_db"_s) return skill_readdb(value); - if (key == "magic_conf") + if (key == "magic_conf"_s) return load_magic_file_v2(value); - if (key == "resnametable") + if (key == "resnametable"_s) return load_resnametable(value); - if (key == "const_db") + if (key == "const_db"_s) return read_constdb(value); - PRINTF("unknown map conf key: %s\n", AString(key)); + PRINTF("unknown map conf key: %s\n"_fmt, AString(key)); return false; } @@ -1705,22 +1710,22 @@ int do_init(Slice<ZString> argv) ZString argvi = argv.pop_front(); if (argvi.startswith('-')) { - if (argvi == "--help") + if (argvi == "--help"_s) { - PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n", + PRINTF("Usage: %s [--help] [--version] [--write_atcommand_config outfile] [files...]\n"_fmt, argv0); exit(0); } - else if (argvi == "--version") + else if (argvi == "--version"_s) { - PRINTF("%s\n", CURRENT_VERSION_STRING); + PRINTF("%s\n"_fmt, CURRENT_VERSION_STRING); exit(0); } - else if (argvi == "--write-atcommand-config") + else if (argvi == "--write-atcommand-config"_s) { if (!argv) { - PRINTF("Missing argument\n"); + PRINTF("Missing argument\n"_fmt); exit(1); } ZString filename = argv.pop_front(); @@ -1729,7 +1734,7 @@ int do_init(Slice<ZString> argv) } else { - FPRINTF(stderr, "Unknown argument: %s\n", argvi); + FPRINTF(stderr, "Unknown argument: %s\n"_fmt, argvi); runflag = false; } } @@ -1741,7 +1746,7 @@ int do_init(Slice<ZString> argv) } if (!loaded_config_yet) - runflag &= load_config_file("conf/tmwa-map.conf", map_confs); + runflag &= load_config_file("conf/tmwa-map.conf"_s, map_confs); battle_config_check(); runflag &= map_readallmap(); @@ -1758,15 +1763,15 @@ int do_init(Slice<ZString> argv) npc_event_do_oninit(); // npcのOnInitイベント実行 if (battle_config.pk_mode == 1) - PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"); + PRINTF("The server is running in " SGR_BOLD SGR_RED "PK Mode" SGR_RESET "\n"_fmt); - PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n", + PRINTF("The map-server is " SGR_BOLD SGR_GREEN "ready" SGR_RESET " (Server is listening on the port %d).\n\n"_fmt, clif_getport()); return 0; } -int map_scriptcont(dumb_ptr<map_session_data> sd, int id) +int map_scriptcont(dumb_ptr<map_session_data> sd, BlockId id) { dumb_ptr<block_list> bl = map_id2bl(id); @@ -1784,3 +1789,4 @@ int map_scriptcont(dumb_ptr<map_session_data> sd, int id) return 0; } +} // namespace tmwa |