summaryrefslogtreecommitdiff
path: root/src/map/pc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/pc.cpp')
-rw-r--r--src/map/pc.cpp828
1 files changed, 416 insertions, 412 deletions
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 0256eff..03e2e76 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -23,24 +23,27 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <cassert>
-#include <cstdlib>
-#include <cstring>
-#include "../compat/alg.hpp"
+#include <algorithm>
+
#include "../compat/fun.hpp"
#include "../compat/nullpo.hpp"
#include "../strings/rstring.hpp"
#include "../strings/astring.hpp"
#include "../strings/zstring.hpp"
+#include "../strings/literal.hpp"
#include "../generic/random.hpp"
#include "../io/cxxstdio.hpp"
#include "../io/read.hpp"
-#include "../mmo/socket.hpp"
-#include "../mmo/timer.hpp"
+#include "../net/timer.hpp"
+
+#include "../mmo/utils.hpp"
+
+#include "../proto2/char-map.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
@@ -48,9 +51,8 @@
#include "clif.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
-#include "magic.hpp"
+#include "magic-stmt.hpp"
#include "map.hpp"
-#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp"
#include "path.hpp"
@@ -61,9 +63,12 @@
#include "../poison.hpp"
+
+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
@@ -86,7 +91,7 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200;
MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \
sd->status.base_level, sd->status.base_exp, \
sd->status.job_level, sd->status.job_exp, sd->status.skill_point, \
- sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount")))
+ sd->status.zeny, pc_readaccountreg(sd, stringish<VarName>("BankAccount"_s)))
#define MAP_LOG_MAGIC(sd, suffix) \
MAP_LOG_PC(sd, "MAGIC %d %d %d %d %d %d EXP %d %d " suffix, \
@@ -96,8 +101,8 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200;
sd->status.skill[SkillID::TMW_MAGIC_TRANSMUTE].lv, \
sd->status.skill[SkillID::TMW_MAGIC_NATURE].lv, \
sd->status.skill[SkillID::TMW_MAGIC_ETHER].lv, \
- pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) & 0xffff, \
- (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE")) >> 24) & 0xff)
+ pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) & 0xffff, \
+ (pc_readglobalreg(sd, stringish<VarName>("MAGIC_EXPERIENCE"_s)) >> 24) & 0xff)
static //const
int max_weight_base_0 = 20000;
@@ -116,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] =
@@ -248,8 +253,9 @@ earray<EPOS, EQUIP, EQUIP::COUNT> equip_pos //=
EPOS::ARROW,
}};
+// TODO use DMap<>
static
-std::map<int, uint8_t> gm_accountm;
+std::map<AccountId, GmLevel> gm_accountm;
static
int pc_checkoverhp(dumb_ptr<map_session_data> sd);
@@ -265,20 +271,20 @@ void pc_setdead(dumb_ptr<map_session_data> sd)
sd->state.dead_sit = 1;
}
-uint8_t pc_isGM(dumb_ptr<map_session_data> sd)
+GmLevel pc_isGM(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retr(GmLevel(), sd);
auto it = gm_accountm.find(sd->status_key.account_id);
if (it != gm_accountm.end())
return it->second;
- return 0;
+ return GmLevel();
}
int pc_iskiller(dumb_ptr<map_session_data> src,
dumb_ptr<map_session_data> target)
{
- nullpo_ret(src);
+ nullpo_retz(src);
if (src->bl_type != BL::PC)
return 0;
@@ -293,7 +299,7 @@ int pc_iskiller(dumb_ptr<map_session_data> src,
return 0;
}
-void pc_set_gm_level(int account_id, uint8_t level)
+void pc_set_gm_level(AccountId account_id, GmLevel level)
{
if (level)
gm_accountm[account_id] = level;
@@ -312,17 +318,17 @@ int distance(int x0, int y0, int x1, int y1)
}
static
-void pc_invincible_timer(TimerData *, tick_t, int id)
+void pc_invincible_timer(TimerData *, tick_t, BlockId id)
{
dumb_ptr<map_session_data> sd = map_id2sd(id);
- assert (sd != NULL);
+ assert (sd != nullptr);
assert (sd->bl_type == BL::PC);
}
int pc_setinvincibletimer(dumb_ptr<map_session_data> sd, interval_t val)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->invincible_timer = Timer(gettick() + val,
std::bind(pc_invincible_timer, ph::_1, ph::_2,
@@ -332,7 +338,7 @@ int pc_setinvincibletimer(dumb_ptr<map_session_data> sd, interval_t val)
int pc_delinvincibletimer(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->invincible_timer.cancel();
return 0;
@@ -340,7 +346,7 @@ int pc_delinvincibletimer(dumb_ptr<map_session_data> sd)
int pc_setrestartvalue(dumb_ptr<map_session_data> sd, int type)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
{
if (battle_config.restart_hp_rate < 50)
@@ -380,7 +386,7 @@ int pc_setrestartvalue(dumb_ptr<map_session_data> sd, int type)
*/
static
void pc_counttargeted_sub(dumb_ptr<block_list> bl,
- int id, int *c, dumb_ptr<block_list> src, ATK target_lv)
+ BlockId id, int *c, dumb_ptr<block_list> src, ATK target_lv)
{
nullpo_retv(bl);
@@ -458,7 +464,7 @@ void pc_makesavestatus(dumb_ptr<map_session_data> sd)
if (sd->bl_m->flag.get(MapFlag::NOSAVE))
{
map_local *m = sd->bl_m;
- if (m->save.map_ == "SavePoint")
+ if (m->save.map_ == "SavePoint"_s)
sd->status.last_point = sd->status.save_point;
else
sd->status.last_point = m->save;
@@ -469,16 +475,21 @@ void pc_makesavestatus(dumb_ptr<map_session_data> sd)
* 接続時の初期化
*------------------------------------------
*/
-int pc_setnewpc(dumb_ptr<map_session_data> sd, int account_id, int char_id,
- int login_id1, tick_t client_tick, SEX sex)
-{
- nullpo_ret(sd);
-
- sd->bl_id = account_id;
- sd->char_id = char_id;
+int pc_setnewpc(dumb_ptr<map_session_data> sd, AccountId account_id, CharId char_id,
+ int login_id1, uint32_t client_tick, SEX sex)
+{
+ nullpo_retz(sd);
+
+ // TODO this is the primary surface
+ sd->bl_id = account_to_block(account_id);
+ sd->char_id_ = char_id;
+ // TODO figure out wtf is going on here.
+ // shouldn't these things be in the .status_key.char_id ?
+ // My guess is that this stuff happens even for non-auth'ed connections
+ // Possible fix: char send auth before client is allowed to know my IP?
sd->login_id1 = login_id1;
sd->login_id2 = 0; // at this point, we can not know the value :(
- sd->client_tick = client_tick;
+ (void)client_tick;
sd->sex = sex;
sd->state.auth = 0;
sd->bl_type = BL::PC;
@@ -489,7 +500,7 @@ int pc_setnewpc(dumb_ptr<map_session_data> sd, int account_id, int char_id,
return 0;
}
-EPOS pc_equippoint(dumb_ptr<map_session_data> sd, int n)
+EPOS pc_equippoint(dumb_ptr<map_session_data> sd, IOff0 n)
{
nullpo_retr(EPOS::ZERO, sd);
@@ -504,13 +515,11 @@ EPOS pc_equippoint(dumb_ptr<map_session_data> sd, int n)
static
int pc_setinventorydata(dumb_ptr<map_session_data> sd)
{
- int i, id;
+ nullpo_retz(sd);
- nullpo_ret(sd);
-
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
- id = sd->status.inventory[i].nameid;
+ ItemNameId id = sd->status.inventory[i].nameid;
sd->inventory_data[i] = itemdb_search(id);
}
return 0;
@@ -519,7 +528,7 @@ int pc_setinventorydata(dumb_ptr<map_session_data> sd)
static
int pc_calcweapontype(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->weapontype1 != ItemLook::NONE
&& sd->weapontype2 == ItemLook::NONE)
@@ -562,14 +571,14 @@ int pc_calcweapontype(dumb_ptr<map_session_data> sd)
static
int pc_setequipindex(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (EQUIP i : EQUIPs)
- sd->equip_index_maybe[i] = -1;
+ sd->equip_index_maybe[i] = IOff0::from(-1);
- for (int i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
- if (sd->status.inventory[i].nameid <= 0)
+ if (!sd->status.inventory[i].nameid)
continue;
if (bool(sd->status.inventory[i].equip))
{
@@ -608,22 +617,22 @@ int pc_setequipindex(dumb_ptr<map_session_data> sd)
}
static
-int pc_isequip(dumb_ptr<map_session_data> sd, int n)
+int pc_isequip(dumb_ptr<map_session_data> sd, IOff0 n)
{
struct item_data *item;
eptr<struct status_change, StatusChange, StatusChange::MAX_STATUSCHANGE> sc_data;
//転生や養子の場合の元の職業を算出する
- nullpo_ret(sd);
+ nullpo_retz(sd);
item = sd->inventory_data[n];
sc_data = battle_get_sc_data(sd);
- if (battle_config.gm_all_equipment > 0
- && pc_isGM(sd) >= battle_config.gm_all_equipment)
+ GmLevel gm_all_equipment = GmLevel::from(static_cast<uint32_t>(battle_config.gm_all_equipment));
+ if (gm_all_equipment && pc_isGM(sd).satisfies(gm_all_equipment))
return 1;
- if (item == NULL)
+ if (item == nullptr)
return 0;
if (item->sex != SEX::NEUTRAL && sd->status.sex != item->sex)
return 0;
@@ -638,16 +647,16 @@ int pc_isequip(dumb_ptr<map_session_data> sd, int n)
* char鯖から送られてきたステータスを設定
*------------------------------------------
*/
-int pc_authok(int id, int login_id2, TimeT connect_until_time,
+int pc_authok(AccountId id, int login_id2, TimeT connect_until_time,
short tmw_version, const CharKey *st_key, const CharData *st_data)
{
- dumb_ptr<map_session_data> sd = NULL;
+ dumb_ptr<map_session_data> sd = nullptr;
- struct party *p;
+ PartyPair p;
tick_t tick = gettick();
- sd = map_id2sd(id);
- if (sd == NULL)
+ sd = map_id2sd(account_to_block(id));
+ if (sd == nullptr)
return 1;
sd->login_id2 = login_id2;
@@ -662,14 +671,14 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
return 1;
}
- MAP_LOG_STATS(sd, "LOGIN");
- MAP_LOG_XP(sd, "LOGIN");
- MAP_LOG_MAGIC(sd, "LOGIN");
+ MAP_LOG_STATS(sd, "LOGIN"_fmt);
+ MAP_LOG_XP(sd, "LOGIN"_fmt);
+ MAP_LOG_MAGIC(sd, "LOGIN"_fmt);
really_memzero_this(&sd->state);
// 基本的な初期化
sd->state.connect_new = 1;
- sd->bl_prev = sd->bl_next = NULL;
+ sd->bl_prev = sd->bl_next = nullptr;
sd->weapontype1 = sd->weapontype2 = ItemLook::NONE;
sd->speed = DEFAULT_WALK_SPEED;
@@ -682,7 +691,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
// sd->invincible_timer = nullptr;
sd->deal_locked = 0;
- sd->trade_partner = 0;
+ sd->trade_partner = AccountId();
sd->inchealhptick = interval_t::zero();
sd->inchealsptick = interval_t::zero();
@@ -702,7 +711,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
// The above is no longer accurate now that we use <chrono>, but
// I'm still not reverting this.
// -o11c
- sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK");
+ sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK"_s);
// アカウント変数の送信要求
intif_request_accountreg(sd);
@@ -725,17 +734,17 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
// This would leak information.
// It's better to make it obvious that players can see you.
if (false && bool(old_option & Option::INVISIBILITY))
- is_atcommand(sd->sess, sd, "@invisible", 0);
+ is_atcommand(sd->sess, sd, "@invisible"_s, GmLevel());
if (bool(old_option & Option::HIDE))
- is_atcommand(sd->sess, sd, "@hide", 0);
+ is_atcommand(sd->sess, sd, "@hide"_s, GmLevel());
// atcommand_hide might already send it, but also might not
clif_changeoption(sd);
}
// パーティー関係の初期化
sd->party_sended = 0;
- sd->party_invite = 0;
+ sd->party_invite = PartyId();
sd->party_x = -1;
sd->party_y = -1;
sd->party_hp = -1;
@@ -748,8 +757,8 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
sd->status.last_point.y, BeingRemoveWhy::GONE);
// パーティ、ギルドデータの要求
- if (sd->status.party_id > 0
- && (p = party_search(sd->status.party_id)) == NULL)
+ if (sd->status.party_id
+ && !(p = party_search(sd->status.party_id)))
party_request_info(sd->status.party_id);
// pvpの設定
@@ -765,19 +774,19 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
map_addchariddb(sd->status_key.char_id, sd->status_key.name);
//スパノビ用死にカウンターのスクリプト変数からの読み出しとsdへのセット
- sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"));
+ sd->die_counter = pc_readglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s));
// ステータス初期計算など
pc_calcstatus(sd, 1);
if (pc_isGM(sd))
{
- PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n",
- sd->status_key.name, sd->status_key.account_id, pc_isGM(sd));
+ PRINTF("Connection accepted: character '%s' (account: %d; GM level %d).\n"_fmt,
+ sd->status_key.name, sd->status_key.account_id, pc_isGM(sd));
clif_updatestatus(sd, SP::GM);
}
else
- PRINTF("Connection accepted: Character '%s' (account: %d).\n",
+ PRINTF("Connection accepted: Character '%s' (account: %d).\n"_fmt,
sd->status_key.name, sd->status_key.account_id);
sd->auto_ban_info.in_progress = 0;
@@ -796,11 +805,11 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time,
// message of the limited time of the account
if (connect_until_time)
{
- // don't display if it's unlimited or unknow value
- char tmpstr[] = WITH_TIMESTAMP("Your account time limit is: ");
- REPLACE_TIMESTAMP(tmpstr, connect_until_time);
+ timestamp_seconds_buffer buffer;
+ stamp_time(buffer, &connect_until_time);
+ AString tmpstr = STRPRINTF("Your account time limit is: %s"_fmt, buffer);
- clif_wis_message(sd->sess, wisp_server_name, const_(tmpstr));
+ clif_wis_message(sd->sess, wisp_server_name, tmpstr);
}
pc_calcstatus(sd, 1);
@@ -817,7 +826,7 @@ void pc_show_motd(dumb_ptr<map_session_data> sd)
// If you remove the sending of this message,
// the license does not permit you to publicly use this software.
- clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool");
+ clif_displaymessage(sd->sess, "This server is Free Software, for details type @source in chat or use the tmwa-source tool"_s);
sd->state.seen_motd = true;
io::ReadFile in(motd_txt);
@@ -835,12 +844,12 @@ void pc_show_motd(dumb_ptr<map_session_data> sd)
* session idに問題ありなので後始末
*------------------------------------------
*/
-int pc_authfail(int id)
+int pc_authfail(AccountId id)
{
dumb_ptr<map_session_data> sd;
- sd = map_id2sd(id);
- if (sd == NULL)
+ sd = map_id2sd(account_to_block(id));
+ if (sd == nullptr)
return 1;
clif_authfail_fd(sd->sess, 0);
@@ -853,7 +862,7 @@ int pc_calc_skillpoint(dumb_ptr<map_session_data> sd)
{
int i, skill_points = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (i = 0; i < skill_pool_skills_size; i++) {
int lv = sd->status.skill[skill_pool_skills[i]].lv;
@@ -872,7 +881,7 @@ int pc_checkweighticon(dumb_ptr<map_session_data> sd)
{
int flag = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->weight * 2 >= sd->max_weight
&& !sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer)
@@ -907,7 +916,7 @@ void pc_set_weapon_look(dumb_ptr<map_session_data> sd)
{
if (sd->attack_spell_override)
clif_changelook(sd, LOOK::WEAPON,
- sd->attack_spell_look_override);
+ unwrap<ItemNameId>(sd->attack_spell_look_override));
else
clif_changelook(sd, LOOK::WEAPON,
static_cast<uint16_t>(sd->status.weapon));
@@ -931,7 +940,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
int aspd_rate, refinedef = 0;
int str, dstr, dex;
- nullpo_ret(sd);
+ nullpo_retz(sd);
interval_t b_speed = sd->speed;
b_max_hp = sd->status.max_hp;
@@ -942,7 +951,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
b_max_weight = sd->max_weight;
earray<int, ATTR, ATTR::COUNT> b_paramb = sd->paramb;
earray<int, ATTR, ATTR::COUNT> b_parame = sd->paramc;
- earray<skill_value, SkillID, MAX_SKILL> b_skill = sd->status.skill;
+ earray<SkillValue, SkillID, MAX_SKILL> b_skill = sd->status.skill;
b_hit = sd->hit;
b_flee = sd->flee;
interval_t b_aspd = sd->aspd;
@@ -964,10 +973,10 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
if (first & 1)
{
sd->weight = 0;
- for (int i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
- if (sd->status.inventory[i].nameid == 0
- || sd->inventory_data[i] == NULL)
+ if (!sd->status.inventory[i].nameid
+ || sd->inventory_data[i] == nullptr)
continue;
sd->weight +=
sd->inventory_data[i]->weight *
@@ -1035,8 +1044,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
for (EQUIP i : EQUIPs_noarrow)
{
- int index = sd->equip_index_maybe[i];
- if (index < 0)
+ IOff0 index = sd->equip_index_maybe[i];
+ if (!index.ok())
continue;
if (i == EQUIP::WEAPON && sd->equip_index_maybe[EQUIP::SHIELD] == index)
continue;
@@ -1060,7 +1069,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
if (sd->spellpower_bonus_target < 0)
sd->spellpower_bonus_target =
(sd->spellpower_bonus_target * 256) /
- (min(128 + skill_power(sd, SkillID::TMW_ASTRAL_SOUL), 256));
+ (std::min(128 + skill_power(sd, SkillID::TMW_ASTRAL_SOUL), 256));
#endif
if (sd->spellpower_bonus_target < sd->spellpower_bonus_current)
@@ -1071,8 +1080,8 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
// 装備品によるステータス変化はここで実行
for (EQUIP i : EQUIPs_noarrow)
{
- int index = sd->equip_index_maybe[i];
- if (index < 0)
+ IOff0 index = sd->equip_index_maybe[i];
+ if (!index.ok())
continue;
if (i == EQUIP::WEAPON && sd->equip_index_maybe[EQUIP::SHIELD] == index)
continue;
@@ -1099,11 +1108,11 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
{
argrec_t arg[2] =
{
- {"@slotId", static_cast<int>(i)},
- {"@itemId", sd->inventory_data[index]->nameid},
+ {"@slotId"_s, static_cast<int>(i)},
+ {"@itemId"_s, unwrap<ItemNameId>(sd->inventory_data[index]->nameid)},
};
run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0),
- sd->bl_id, 0,
+ sd->bl_id, BlockId(),
arg);
}
sd->state.lr_flag = 0;
@@ -1113,14 +1122,14 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
//二刀流武器以外
argrec_t arg[2] =
{
- {"@slotId", static_cast<int>(i)},
- {"@itemId", sd->inventory_data[index]->nameid},
+ {"@slotId"_s, static_cast<int>(i)},
+ {"@itemId"_s, unwrap<ItemNameId>(sd->inventory_data[index]->nameid)},
};
sd->watk += sd->inventory_data[index]->atk;
sd->attackrange += sd->inventory_data[index]->range;
run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0),
- sd->bl_id, 0,
+ sd->bl_id, BlockId(),
arg);
}
}
@@ -1128,12 +1137,12 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
{
argrec_t arg[2] =
{
- {"@slotId", static_cast<int>(i)},
- {"@itemId", sd->inventory_data[index]->nameid},
+ {"@slotId"_s, static_cast<int>(i)},
+ {"@itemId"_s, unwrap<ItemNameId>(sd->inventory_data[index]->nameid)},
};
sd->watk += sd->inventory_data[index]->atk;
run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0),
- sd->bl_id, 0,
+ sd->bl_id, BlockId(),
arg);
}
}
@@ -1147,20 +1156,20 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
sd->watk_2 += skill_power(sd, SkillID::TMW_BRAWLING) >> 3; // +25 for 200
}
- int aidx = sd->equip_index_maybe[EQUIP::ARROW];
- if (aidx >= 0)
- { // 矢
- int index = aidx;
+ IOff0 aidx = sd->equip_index_maybe[EQUIP::ARROW];
+ if (aidx.ok())
+ {
+ IOff0 index = aidx;
if (sd->inventory_data[index])
{ //まだ属性が入っていない
argrec_t arg[2] =
{
- {"@slotId", static_cast<int>(EQUIP::ARROW)},
- {"@itemId", sd->inventory_data[index]->nameid},
+ {"@slotId"_s, static_cast<int>(EQUIP::ARROW)},
+ {"@itemId"_s, unwrap<ItemNameId>(sd->inventory_data[index]->nameid)},
};
sd->state.lr_flag = 2;
run_script_l(ScriptPointer(sd->inventory_data[index]->equip_script.get(), 0),
- sd->bl_id, 0,
+ sd->bl_id, BlockId(),
arg);
sd->state.lr_flag = 0;
sd->arrow_atk += sd->inventory_data[index]->atk;
@@ -1189,7 +1198,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
sd->aspd_rate = 20;
for (ATTR attr : ATTRs)
- sd->paramc[attr] = max(0, sd->status.attrs[attr] + sd->paramb[attr] + sd->parame[attr]);
+ sd->paramc[attr] = std::max(0, sd->status.attrs[attr] + sd->paramb[attr] + sd->parame[attr]);
if (sd->status.weapon == ItemLook::BOW
|| sd->status.weapon == ItemLook::_13
@@ -1206,7 +1215,6 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
}
dstr = str / 10;
sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[ATTR::LUK] / 5;
-//FPRINTF(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[ATTR::LUK]/5);
sd->matk1 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 5) * (sd->paramc[ATTR::INT] / 5);
sd->matk2 += sd->paramc[ATTR::INT] + (sd->paramc[ATTR::INT] / 7) * (sd->paramc[ATTR::INT] / 7);
if (sd->matk1 < sd->matk2)
@@ -1304,7 +1312,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
if (sd->attackrange > 2)
{
// [fate] ranged weapon?
- sd->attackrange += min(skill_power(sd, SkillID::AC_OWL) / 60, 3);
+ sd->attackrange += std::min(skill_power(sd, SkillID::AC_OWL) / 60, 3);
sd->hit += skill_power(sd, SkillID::AC_OWL) / 10; // 20 for 200
}
@@ -1385,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;
@@ -1395,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;
@@ -1479,7 +1487,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
*/
int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
switch (type)
{
@@ -1731,7 +1739,7 @@ int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val)
break;
default:
if (battle_config.error_log)
- PRINTF("pc_bonus: unknown type %d %d !\n",
+ PRINTF("pc_bonus: unknown type %d %d !\n"_fmt,
type, val);
break;
}
@@ -1744,7 +1752,7 @@ int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val)
*/
int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
switch (type)
{
@@ -1776,7 +1784,7 @@ int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val)
#endif
default:
if (battle_config.error_log)
- PRINTF("pc_bonus2: unknown type %d %d %d!\n",
+ PRINTF("pc_bonus2: unknown type %d %d %d!\n"_fmt,
type, type2, val);
break;
}
@@ -1789,12 +1797,12 @@ int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val)
*/
int pc_skill(dumb_ptr<map_session_data> sd, SkillID id, int level, int flag)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (level > MAX_SKILL_LEVEL)
{
if (battle_config.error_log)
- PRINTF("support card skill only!\n");
+ PRINTF("support card skill only!\n"_fmt);
return 0;
}
if (!flag && (sd->status.skill[id].lv || level == 0))
@@ -1817,16 +1825,14 @@ int pc_skill(dumb_ptr<map_session_data> sd, SkillID id, int level, int flag)
* 3万個制限にかかるか確認
*------------------------------------------
*/
-ADDITEM pc_checkadditem(dumb_ptr<map_session_data> sd, int nameid, int amount)
+ADDITEM pc_checkadditem(dumb_ptr<map_session_data> sd, ItemNameId nameid, int amount)
{
- int i;
-
nullpo_retr(ADDITEM::ZERO, sd);
if (itemdb_isequip(nameid))
return ADDITEM::NEW;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
if (sd->status.inventory[i].nameid == nameid)
{
@@ -1847,13 +1853,13 @@ ADDITEM pc_checkadditem(dumb_ptr<map_session_data> sd, int nameid, int amount)
*/
int pc_inventoryblank(dumb_ptr<map_session_data> sd)
{
- int i, b;
+ int b = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
- for (i = 0, b = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
- if (sd->status.inventory[i].nameid == 0)
+ if (!sd->status.inventory[i].nameid)
b++;
}
@@ -1866,7 +1872,7 @@ int pc_inventoryblank(dumb_ptr<map_session_data> sd)
*/
int pc_payzeny(dumb_ptr<map_session_data> sd, int zeny)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
double z = sd->status.zeny;
if (sd->status.zeny < zeny || z - zeny > MAX_ZENY)
@@ -1883,7 +1889,7 @@ int pc_payzeny(dumb_ptr<map_session_data> sd, int zeny)
*/
int pc_getzeny(dumb_ptr<map_session_data> sd, int zeny)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
double z = sd->status.zeny;
if (z + zeny > MAX_ZENY)
@@ -1901,30 +1907,27 @@ int pc_getzeny(dumb_ptr<map_session_data> sd, int zeny)
* アイテムを探して、インデックスを返す
*------------------------------------------
*/
-int pc_search_inventory(dumb_ptr<map_session_data> sd, int item_id)
+IOff0 pc_search_inventory(dumb_ptr<map_session_data> sd, ItemNameId item_id)
{
- int i;
+ nullpo_retr(IOff0::from(-1), sd);
- nullpo_retr(-1, sd);
-
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
if (sd->status.inventory[i].nameid == item_id &&
- (sd->status.inventory[i].amount > 0 || item_id == 0))
+ (sd->status.inventory[i].amount > 0 || !item_id))
return i;
}
- return -1;
+ return IOff0::from(-1);
}
-int pc_count_all_items(dumb_ptr<map_session_data> player, int item_id)
+int pc_count_all_items(dumb_ptr<map_session_data> player, ItemNameId item_id)
{
- int i;
int count = 0;
- nullpo_ret(player);
+ nullpo_retz(player);
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
if (player->status.inventory[i].nameid == item_id)
count += player->status.inventory[i].amount;
@@ -1933,14 +1936,14 @@ int pc_count_all_items(dumb_ptr<map_session_data> player, int item_id)
return count;
}
-int pc_remove_items(dumb_ptr<map_session_data> player, int item_id, int count)
+int pc_remove_items(dumb_ptr<map_session_data> player, ItemNameId item_id, int count)
{
- int i;
-
- nullpo_ret(player);
+ nullpo_retz(player);
- for (i = 0; i < MAX_INVENTORY && count; i++)
+ for (IOff0 i : IOff0::iter())
{
+ if (!count)
+ break;
if (player->status.inventory[i].nameid == item_id)
{
int to_delete = count;
@@ -1964,29 +1967,30 @@ int pc_remove_items(dumb_ptr<map_session_data> player, int item_id, int count)
* アイテム追加。個数のみitem構造体の数字を無視
*------------------------------------------
*/
-PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data,
+PickupFail pc_additem(dumb_ptr<map_session_data> sd, Item *item_data,
int amount)
{
struct item_data *data;
- int i, w;
+ int w;
- MAP_LOG_PC(sd, "PICKUP %d %d", item_data->nameid, amount);
+ MAP_LOG_PC(sd, "PICKUP %d %d"_fmt, item_data->nameid, amount);
nullpo_retr(PickupFail::BAD_ITEM, sd);
nullpo_retr(PickupFail::BAD_ITEM, item_data);
- if (item_data->nameid <= 0 || amount <= 0)
+ if (!item_data->nameid || amount <= 0)
return PickupFail::BAD_ITEM;
data = itemdb_search(item_data->nameid);
if ((w = data->weight * amount) + sd->weight > sd->max_weight)
return PickupFail::TOO_HEAVY;
- i = MAX_INVENTORY;
+ IOff0 i = IOff0::from(MAX_INVENTORY);
if (!itemdb_isequip2(data))
{
- // 装 備品ではないので、既所有品なら個数のみ変化させる
- for (i = 0; i < MAX_INVENTORY; i++)
+ // TODO see if there's any nicer way to preserve the foreach var
+ for (i = IOff0::from(0); i != IOff0::from(MAX_INVENTORY); ++i)
+ {
if (sd->status.inventory[i].nameid == item_data->nameid)
{
if (sd->status.inventory[i].amount + amount > MAX_AMOUNT)
@@ -1995,12 +1999,12 @@ PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data,
clif_additem(sd, i, amount, PickupFail::OKAY);
break;
}
+ }
}
- if (i >= MAX_INVENTORY)
+ if (!i.ok())
{
- // 装 備品か未所有品だったので空き欄へ追加
- i = pc_search_inventory(sd, 0);
- if (i >= 0)
+ i = pc_search_inventory(sd, ItemNameId());
+ if (i.ok())
{
sd->status.inventory[i] = *item_data;
@@ -2024,16 +2028,16 @@ PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data,
* アイテムを減らす
*------------------------------------------
*/
-int pc_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int type)
+int pc_delitem(dumb_ptr<map_session_data> sd, IOff0 n, int amount, int type)
{
nullpo_retr(1, sd);
- if (sd->trade_partner != 0)
+ if (sd->trade_partner)
trade_tradecancel(sd);
- if (sd->status.inventory[n].nameid == 0 || amount <= 0
+ if (!sd->status.inventory[n].nameid || amount <= 0
|| sd->status.inventory[n].amount < amount
- || sd->inventory_data[n] == NULL)
+ || sd->inventory_data[n] == nullptr)
return 1;
sd->status.inventory[n].amount -= amount;
@@ -2042,8 +2046,8 @@ int pc_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int type)
{
if (bool(sd->status.inventory[n].equip))
pc_unequipitem(sd, n, CalcStatus::NOW);
- sd->status.inventory[n] = item{};
- sd->inventory_data[n] = NULL;
+ sd->status.inventory[n] = Item{};
+ sd->inventory_data[n] = nullptr;
}
if (!(type & 1))
clif_delitem(sd, n, amount);
@@ -2057,14 +2061,14 @@ int pc_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int type)
* アイテムを落す
*------------------------------------------
*/
-int pc_dropitem(dumb_ptr<map_session_data> sd, int n, int amount)
+int pc_dropitem(dumb_ptr<map_session_data> sd, IOff0 n, int amount)
{
nullpo_retr(1, sd);
- if (sd->trade_partner != 0 || sd->npc_id != 0 || sd->state.storage_open)
+ if (sd->trade_partner || sd->npc_id || sd->state.storage_open)
return 0; // no dropping while trading/npc/storage
- if (n < 0 || n >= MAX_INVENTORY)
+ if (!n.ok())
return 0;
if (amount <= 0)
@@ -2072,13 +2076,13 @@ int pc_dropitem(dumb_ptr<map_session_data> sd, int n, int amount)
pc_unequipinvyitem(sd, n, CalcStatus::NOW);
- if (sd->status.inventory[n].nameid <= 0 ||
+ if (!sd->status.inventory[n].nameid ||
sd->status.inventory[n].amount < amount ||
- sd->trade_partner != 0 || sd->status.inventory[n].amount <= 0)
+ sd->trade_partner || sd->status.inventory[n].amount <= 0)
return 1;
map_addflooritem(&sd->status.inventory[n], amount,
sd->bl_m, sd->bl_x, sd->bl_y,
- NULL, NULL, NULL);
+ nullptr, nullptr, nullptr);
pc_delitem(sd, n, amount, 0);
return 0;
@@ -2090,9 +2094,9 @@ int pc_dropitem(dumb_ptr<map_session_data> sd, int n, int amount)
*/
static
-int can_pick_item_up_from(dumb_ptr<map_session_data> self, int other_id)
+int can_pick_item_up_from(dumb_ptr<map_session_data> self, BlockId other_id)
{
- struct party *p = party_search(self->status.party_id);
+ PartyPair p = party_search(self->status.party_id);
/* From ourselves or from no-one? */
if (!self || self->bl_id == other_id || !other_id)
@@ -2133,19 +2137,19 @@ int pc_takeitem(dumb_ptr<map_session_data> sd, dumb_ptr<flooritem_data> fitem)
tick_t tick = gettick();
int can_take;
- nullpo_ret(sd);
- nullpo_ret(fitem);
+ nullpo_retz(sd);
+ nullpo_retz(fitem);
/* Sometimes the owners reported to us are buggy: */
if (fitem->first_get_id == fitem->third_get_id
|| fitem->second_get_id == fitem->third_get_id)
- fitem->third_get_id = 0;
+ fitem->third_get_id = BlockId();
if (fitem->first_get_id == fitem->second_get_id)
{
fitem->second_get_id = fitem->third_get_id;
- fitem->third_get_id = 0;
+ fitem->third_get_id = BlockId();
}
can_take = can_pick_item_up_from(sd, fitem->first_get_id);
@@ -2167,7 +2171,7 @@ int pc_takeitem(dumb_ptr<map_session_data> sd, dumb_ptr<flooritem_data> fitem)
PickupFail flag = pc_additem(sd, &fitem->item_data, fitem->item_data.amount);
if (flag != PickupFail::OKAY)
// 重量overで取得失敗
- clif_additem(sd, 0, 0, flag);
+ clif_additem(sd, IOff0::from(0), 0, flag);
else
{
// 取得成功
@@ -2180,22 +2184,22 @@ int pc_takeitem(dumb_ptr<map_session_data> sd, dumb_ptr<flooritem_data> fitem)
}
/* Otherwise, we can't pick up */
- clif_additem(sd, 0, 0, PickupFail::DROP_STEAL);
+ clif_additem(sd, IOff0::from(0), 0, PickupFail::DROP_STEAL);
return 0;
}
static
-int pc_isUseitem(dumb_ptr<map_session_data> sd, int n)
+int pc_isUseitem(dumb_ptr<map_session_data> sd, IOff0 n)
{
struct item_data *item;
- int nameid;
+ ItemNameId nameid;
- nullpo_ret(sd);
+ nullpo_retz(sd);
item = sd->inventory_data[n];
nameid = sd->status.inventory[n].nameid;
- if (item == NULL)
+ if (item == nullptr)
return 0;
if (itemdb_type(nameid) != ItemType::USE)
return 0;
@@ -2212,16 +2216,16 @@ int pc_isUseitem(dumb_ptr<map_session_data> sd, int n)
* アイテムを使う
*------------------------------------------
*/
-int pc_useitem(dumb_ptr<map_session_data> sd, int n)
+int pc_useitem(dumb_ptr<map_session_data> sd, IOff0 n)
{
int amount;
nullpo_retr(1, sd);
- if (n >= 0 && n < MAX_INVENTORY && sd->inventory_data[n])
+ if (n.ok() && sd->inventory_data[n])
{
amount = sd->status.inventory[n].amount;
- if (sd->status.inventory[n].nameid <= 0
+ if (!sd->status.inventory[n].nameid
|| sd->status.inventory[n].amount <= 0
|| !pc_isUseitem(sd, n))
{
@@ -2233,7 +2237,7 @@ int pc_useitem(dumb_ptr<map_session_data> sd, int n)
clif_useitemack(sd, n, amount - 1, 1);
pc_delitem(sd, n, 1, 1);
- run_script(ScriptPointer(script, 0), sd->bl_id, 0);
+ run_script(ScriptPointer(script, 0), sd->bl_id, BlockId());
}
return 0;
@@ -2251,14 +2255,14 @@ int pc_setpos(dumb_ptr<map_session_data> sd,
{
MapName mapname_;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->trade_partner) // 取引を中断する
trade_tradecancel(sd);
if (sd->state.storage_open)
storage_storage_quit(sd); // 倉庫を開いてるなら保存する
- if (sd->party_invite > 0) // パーティ勧誘を拒否する
+ if (sd->party_invite) // パーティ勧誘を拒否する
party_reply_invite(sd, sd->party_invite_account, 0);
skill_castcancel(sd, 0); // 詠唱中断
@@ -2314,7 +2318,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd,
if (x || y)
{
if (battle_config.error_log)
- PRINTF("stacked (%d,%d)\n", x, y);
+ PRINTF("stacked (%d,%d)\n"_fmt, x, y);
}
do
{
@@ -2324,7 +2328,7 @@ int pc_setpos(dumb_ptr<map_session_data> sd,
while (bool(read_gatp(m, x, y) & MapCell::UNWALKABLE));
}
- if (sd->mapname_ && sd->bl_prev != NULL)
+ if (sd->mapname_ && sd->bl_prev != nullptr)
{
clif_clearchar(sd, clrtype);
map_delblock(sd);
@@ -2355,7 +2359,7 @@ int pc_randomwarp(dumb_ptr<map_session_data> sd, BeingRemoveWhy type)
{
int x, y, i = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
map_local *m = sd->bl_m;
@@ -2385,7 +2389,7 @@ int pc_can_reach(dumb_ptr<map_session_data> sd, int x, int y)
{
struct walkpath_data wpd;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->bl_x == x && sd->bl_y == y) // 同じマス
return 1;
@@ -2422,14 +2426,14 @@ interval_t calc_next_walk_step(dumb_ptr<map_session_data> sd)
*------------------------------------------
*/
static
-void pc_walk(TimerData *, tick_t tick, int id, unsigned char data)
+void pc_walk(TimerData *, tick_t tick, BlockId id, unsigned char data)
{
dumb_ptr<map_session_data> sd;
int moveblock;
int x, y, dx, dy;
sd = map_id2sd(id);
- if (sd == NULL)
+ if (sd == nullptr)
return;
if (sd->walkpath.path_pos >= sd->walkpath.path_len
@@ -2497,10 +2501,10 @@ void pc_walk(TimerData *, tick_t tick, int id, unsigned char data)
BL::NUL);
// sd->walktimer = nullptr;
- if (sd->status.party_id > 0)
+ if (sd->status.party_id)
{ // パーティのHP情報通知検査
- struct party *p = party_search(sd->status.party_id);
- if (p != NULL)
+ PartyPair p = party_search(sd->status.party_id);
+ if (p)
{
int p_flag = 0;
map_foreachinmovearea(std::bind(party_send_hp_check, ph::_1, sd->status.party_id, &p_flag),
@@ -2517,14 +2521,14 @@ void pc_walk(TimerData *, tick_t tick, int id, unsigned char data)
if (bool(map_getcell(sd->bl_m, x, y) & MapCell::NPC_NEAR))
npc_touch_areanpc(sd, sd->bl_m, x, y);
else
- sd->areanpc_id = 0;
+ sd->areanpc_id = BlockId();
}
interval_t i = calc_next_walk_step(sd);
if (i > interval_t::zero())
{
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,
@@ -2570,7 +2574,7 @@ int pc_walktoxy_sub(dumb_ptr<map_session_data> sd)
int pc_walktoxy(dumb_ptr<map_session_data> sd, int x, int y)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->to_x = x;
sd->to_y = y;
@@ -2598,7 +2602,7 @@ int pc_walktoxy(dumb_ptr<map_session_data> sd, int x, int y)
*/
int pc_stop_walking(dumb_ptr<map_session_data> sd, int type)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->walktimer.cancel();
@@ -2623,7 +2627,7 @@ void pc_touch_all_relevant_npcs(dumb_ptr<map_session_data> sd)
if (bool(map_getcell(sd->bl_m, sd->bl_x, sd->bl_y) & MapCell::NPC_NEAR))
npc_touch_areanpc(sd, sd->bl_m, sd->bl_x, sd->bl_y);
else
- sd->areanpc_id = 0;
+ sd->areanpc_id = BlockId();
}
/*==========================================
@@ -2637,7 +2641,7 @@ int pc_movepos(dumb_ptr<map_session_data> sd, int dst_x, int dst_y)
struct walkpath_data wpd;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (path_search(&wpd, sd->bl_m, sd->bl_x, sd->bl_y, dst_x, dst_y, 0))
return 1;
@@ -2671,10 +2675,10 @@ int pc_movepos(dumb_ptr<map_session_data> sd, int dst_x, int dst_y)
-dx, -dy,
BL::NUL);
- if (sd->status.party_id > 0)
+ if (sd->status.party_id)
{ // パーティのHP情報通知検査
- struct party *p = party_search(sd->status.party_id);
- if (p != NULL)
+ PartyPair p = party_search(sd->status.party_id);
+ if (p)
{
int flag = 0;
map_foreachinmovearea(std::bind(party_send_hp_check, ph::_1, sd->status.party_id, &flag),
@@ -2701,7 +2705,7 @@ int pc_movepos(dumb_ptr<map_session_data> sd, int dst_x, int dst_y)
*/
int pc_checkskill(dumb_ptr<map_session_data> sd, SkillID skill_id)
{
- if (sd == NULL)
+ if (sd == nullptr)
return 0;
return sd->status.skill[skill_id].lv;
@@ -2711,9 +2715,9 @@ int pc_checkskill(dumb_ptr<map_session_data> sd, SkillID skill_id)
* 装 備品のチェック
*------------------------------------------
*/
-int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos)
+IOff0 pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos)
{
- nullpo_retr(-1, sd);
+ nullpo_retr(IOff0::from(-1), sd);
for (EQUIP i : EQUIPs)
{
@@ -2721,7 +2725,7 @@ int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos)
return sd->equip_index_maybe[i];
}
- return -1;
+ return IOff0::from(-1);
}
/*==========================================
@@ -2729,7 +2733,7 @@ int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos)
*------------------------------------------
*/
static
-void pc_attack_timer(TimerData *, tick_t tick, int id)
+void pc_attack_timer(TimerData *, tick_t tick, BlockId id)
{
dumb_ptr<map_session_data> sd;
dumb_ptr<block_list> bl;
@@ -2737,14 +2741,14 @@ void pc_attack_timer(TimerData *, tick_t tick, int id)
int dist, range;
sd = map_id2sd(id);
- if (sd == NULL)
+ if (sd == nullptr)
return;
- if (sd->bl_prev == NULL)
+ if (sd->bl_prev == nullptr)
return;
bl = map_id2bl(sd->attacktarget);
- if (bl == NULL || bl->bl_prev == NULL)
+ if (bl == nullptr || bl->bl_prev == nullptr)
return;
if (bl->bl_type == BL::PC && pc_isdead(bl->is_player()))
@@ -2760,7 +2764,7 @@ void pc_attack_timer(TimerData *, tick_t tick, int id)
return;
Option *opt = battle_get_option(bl);
- if (opt != NULL && bool(*opt & Option::REAL_ANY_HIDE))
+ if (opt != nullptr && bool(*opt & Option::REAL_ANY_HIDE))
return;
if (!battle_config.skill_delay_attack_enable)
@@ -2836,19 +2840,19 @@ void pc_attack_timer(TimerData *, tick_t tick, int id)
* typeが1なら継続攻撃
*------------------------------------------
*/
-int pc_attack(dumb_ptr<map_session_data> sd, int target_id, int type)
+int pc_attack(dumb_ptr<map_session_data> sd, BlockId target_id, int type)
{
dumb_ptr<block_list> bl;
- nullpo_ret(sd);
+ nullpo_retz(sd);
bl = map_id2bl(target_id);
- if (bl == NULL)
+ if (bl == nullptr)
return 1;
if (bl->bl_type == BL::NPC)
{ // monster npcs [Valaris]
- npc_click(sd, RFIFOL(sd->sess, 2));
+ npc_click(sd, target_id);
return 0;
}
@@ -2860,7 +2864,7 @@ int pc_attack(dumb_ptr<map_session_data> sd, int 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,
@@ -2881,11 +2885,11 @@ int pc_attack(dumb_ptr<map_session_data> sd, int target_id, int type)
*/
int pc_stopattack(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->attacktimer.cancel();
- sd->attacktarget = 0;
+ sd->attacktarget = BlockId();
sd->state.attack_continue = 0;
return 0;
@@ -2896,7 +2900,7 @@ int pc_checkbaselevelup(dumb_ptr<map_session_data> sd)
{
int next = pc_nextbaseexp(sd);
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.base_exp >= next && next > 0)
{
@@ -2915,7 +2919,7 @@ int pc_checkbaselevelup(dumb_ptr<map_session_data> sd)
//レベルアップしたのでパーティー情報を更新する
//(公平範囲チェック)
party_send_movemap(sd);
- MAP_LOG_XP(sd, "LEVELUP");
+ MAP_LOG_XP(sd, "LEVELUP"_fmt);
return 1;
}
@@ -2937,8 +2941,7 @@ int pc_skillpt_potential(dumb_ptr<map_session_data> sd)
{
int potential = 0;
- for (SkillID skill_id = SkillID(); skill_id < MAX_SKILL;
- skill_id = SkillID(uint16_t(skill_id) + 1))
+ for (SkillID skill_id : erange(SkillID(), MAX_SKILL))
if (sd->status.skill[skill_id].lv
&& sd->status.skill[skill_id].lv < skill_db[skill_id].max_raise)
potential += RAISE_COST(skill_db[skill_id].max_raise)
@@ -2952,7 +2955,7 @@ int pc_checkjoblevelup(dumb_ptr<map_session_data> sd)
{
int next = pc_nextjobexp(sd);
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.job_exp >= next && next > 0)
{
@@ -2971,7 +2974,7 @@ int pc_checkjoblevelup(dumb_ptr<map_session_data> sd)
clif_updatestatus(sd, SP::SKILLPOINT);
pc_calcstatus(sd, 0);
- MAP_LOG_PC(sd, "SKILLPOINTS-UP %d", sd->status.skill_point);
+ MAP_LOG_PC(sd, "SKILLPOINTS-UP %d"_fmt, sd->status.skill_point);
if (sd->status.job_level < 250
&& sd->status.job_level < sd->status.base_level * 2)
@@ -2987,21 +2990,21 @@ int pc_checkjoblevelup(dumb_ptr<map_session_data> sd)
int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp,
PC_GAINEXP_REASON reason)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
- if (sd->bl_prev == NULL || pc_isdead(sd))
+ if (sd->bl_prev == nullptr || pc_isdead(sd))
return 0;
- earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //=
+ earray<LString, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons //=
{{
- "KILLXP",
- "HEALXP",
- "SCRIPTXP",
- "SHAREXP",
+ "KILLXP"_s,
+ "HEALXP"_s,
+ "SCRIPTXP"_s,
+ "SHAREXP"_s,
/* Insert new types here */
- "UNKNOWNXP"
+ "UNKNOWNXP"_s
}};
- MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp, reasons[reason]);
+ MAP_LOG_PC(sd, "GAINXP %d %d %s"_fmt, base_exp, job_exp, reasons[reason]);
if (!battle_config.multi_level_up && pc_nextbaseafter(sd))
{
@@ -3029,7 +3032,8 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp,
if (sd->status.base_exp < 0)
sd->status.base_exp = 0;
- while (pc_checkbaselevelup(sd));
+ while (pc_checkbaselevelup(sd))
+ {}
clif_updatestatus(sd, SP::BASEEXP);
if (!battle_config.multi_level_up && pc_nextjobafter(sd))
@@ -3046,14 +3050,15 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp,
if (sd->status.job_exp < 0)
sd->status.job_exp = 0;
- while (pc_checkjoblevelup(sd));
+ while (pc_checkjoblevelup(sd))
+ {}
clif_updatestatus(sd, SP::JOBEXP);
if (battle_config.disp_experience)
{
AString output = STRPRINTF(
- "Experienced Gained Base:%d Job:%d",
+ "Experienced Gained Base:%d Job:%d"_fmt,
base_exp, job_exp);
clif_displaymessage(sd->sess, output);
}
@@ -3064,7 +3069,7 @@ int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp,
int pc_extract_healer_exp(dumb_ptr<map_session_data> sd, int max)
{
int amount;
- nullpo_ret(sd);
+ nullpo_retz(sd);
amount = sd->heal_xp;
if (max < amount)
@@ -3080,7 +3085,7 @@ int pc_extract_healer_exp(dumb_ptr<map_session_data> sd, int max)
*/
int pc_nextbaseexp(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.base_level >= MAX_LEVEL || sd->status.base_level <= 0)
return 0;
@@ -3108,7 +3113,7 @@ int pc_nextjobexp(dumb_ptr<map_session_data> sd)
*/
int pc_nextbaseafter(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.base_level >= MAX_LEVEL || sd->status.base_level <= 0)
return 0;
@@ -3122,7 +3127,7 @@ int pc_nextbaseafter(dumb_ptr<map_session_data> sd)
*/
int pc_nextjobafter(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.job_level >= MAX_LEVEL || sd->status.job_level <= 0)
return 0;
@@ -3156,7 +3161,7 @@ int pc_statusup(dumb_ptr<map_session_data> sd, SP type)
{
int need, val = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (SP::STR <= type && type <= SP::LUK)
val = sd->status.attrs[sp_to_attr(type)];
@@ -3181,7 +3186,7 @@ int pc_statusup(dumb_ptr<map_session_data> sd, SP type)
pc_calcstatus(sd, 0);
clif_statusupack(sd, type, 1, val);
- MAP_LOG_STATS(sd, "STATUP");
+ MAP_LOG_STATS(sd, "STATUP"_fmt);
return 0;
}
@@ -3192,7 +3197,7 @@ int pc_statusup(dumb_ptr<map_session_data> sd, SP type)
*/
int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (type < SP::STR || type > SP::LUK)
{
@@ -3208,7 +3213,7 @@ int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val)
clif_updatestatus(sd, type);
pc_calcstatus(sd, 0);
clif_statusupack(sd, type, 1, val);
- MAP_LOG_STATS(sd, "STATUP2");
+ MAP_LOG_STATS(sd, "STATUP2"_fmt);
return 0;
}
@@ -3219,7 +3224,7 @@ int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val)
*/
int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.skill[skill_num].lv
&& sd->status.skill_point >= sd->status.skill[skill_num].lv
@@ -3232,7 +3237,7 @@ int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num)
clif_skillup(sd, skill_num);
clif_updatestatus(sd, SP::SKILLPOINT);
clif_skillinfoblock(sd);
- MAP_LOG_PC(sd, "SKILLUP %d %d %d",
+ MAP_LOG_PC(sd, "SKILLUP %d %d %d"_fmt,
skill_num, sd->status.skill[skill_num].lv,
skill_power(sd, skill_num));
}
@@ -3246,7 +3251,7 @@ int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num)
*/
int pc_resetlvl(dumb_ptr<map_session_data> sd, int type)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (SkillID i : erange(SkillID(1), MAX_SKILL))
{
@@ -3309,13 +3314,13 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type)
for (EQUIP i : EQUIPs)
{
// unequip items that can't be equipped by base 1 [Valaris]
- short *idx = &sd->equip_index_maybe[i];
- if (*idx >= 0)
+ IOff0 *idx = &sd->equip_index_maybe[i];
+ if ((*idx).ok())
{
if (!pc_isequip(sd, *idx))
{
pc_unequipitem(sd, *idx, CalcStatus::LATER);
- *idx = -1;
+ *idx = IOff0::from(-1);
}
}
}
@@ -3323,7 +3328,7 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type)
clif_skillinfoblock(sd);
pc_calcstatus(sd, 0);
- MAP_LOG_STATS(sd, "STATRESET");
+ MAP_LOG_STATS(sd, "STATRESET"_fmt);
return 0;
}
@@ -3335,7 +3340,7 @@ int pc_resetlvl(dumb_ptr<map_session_data> sd, int type)
int pc_resetstate(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->status.status_point = stat_p[sd->status.base_level - 1];
@@ -3361,7 +3366,7 @@ int pc_resetskill(dumb_ptr<map_session_data> sd)
{
int skill;
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->status.skill_point += pc_calc_skillpoint(sd);
@@ -3386,7 +3391,7 @@ int pc_resetskill(dumb_ptr<map_session_data> sd)
int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
int damage)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
// 既に死んでいたら無効
if (pc_isdead(sd))
@@ -3401,17 +3406,17 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
{
if (src->bl_type == BL::PC)
{
- MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d",
- src->is_player()->status_key.char_id,
- damage);
+ MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d"_fmt,
+ src->is_player()->status_key.char_id,
+ damage);
}
else
{
- MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d", src->bl_id, damage);
+ MAP_LOG_PC(sd, "INJURED-BY MOB%d FOR %d"_fmt, src->bl_id, damage);
}
}
else
- MAP_LOG_PC(sd, "INJURED-BY null FOR %d", damage);
+ MAP_LOG_PC(sd, "INJURED-BY null FOR %d"_fmt, damage);
pc_stop_walking(sd, 3);
// 演奏/ダンスの中断
@@ -3427,17 +3432,17 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
sd->canlog_tick = gettick();
- if (sd->status.party_id > 0)
+ if (sd->status.party_id)
{ // on-the-fly party hp updates [Valaris]
- struct party *p = party_search(sd->status.party_id);
- if (p != NULL)
+ PartyPair p = party_search(sd->status.party_id);
+ if (p)
clif_party_hp(p, sd);
} // end addition [Valaris]
return 0;
}
- MAP_LOG_PC(sd, "DEAD%s", "");
+ MAP_LOG_PC(sd, "DEAD%s"_fmt, ""_s);
// Character is dead!
@@ -3452,7 +3457,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
pc_stop_walking(sd, 0);
skill_castcancel(sd, 0); // 詠唱の中止
clif_clearchar(sd, BeingRemoveWhy::DEAD);
- pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"), ++sd->die_counter); //死にカウンター書き込み
+ pc_setglobalreg(sd, stringish<VarName>("PC_DIE_COUNTER"_s), ++sd->die_counter); //死にカウンター書き込み
skill_status_change_clear(sd, 0); // ステータス異常を解除する
clif_updatestatus(sd, SP::HP);
pc_calcstatus(sd, 0);
@@ -3544,14 +3549,14 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
// [Fate] PK death, trigger scripts
argrec_t arg[3] =
{
- {"@killerrid", src->bl_id},
- {"@victimrid", sd->bl_id},
- {"@victimlvl", sd->status.base_level},
+ {"@killerrid"_s, static_cast<int32_t>(unwrap<BlockId>(src->bl_id))},
+ {"@victimrid"_s, static_cast<int32_t>(unwrap<BlockId>(sd->bl_id))},
+ {"@victimlvl"_s, sd->status.base_level},
};
- npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"), sd->bl_id, arg);
- npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"), src->bl_id, arg);
+ npc_event_doall_l(stringish<ScriptLabel>("OnPCKilledEvent"_s), sd->bl_id, arg);
+ npc_event_doall_l(stringish<ScriptLabel>("OnPCKillEvent"_s), src->bl_id, arg);
}
- npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"), sd->bl_id, nullptr);
+ npc_event_doall_l(stringish<ScriptLabel>("OnPCDieEvent"_s), sd->bl_id, nullptr);
return 0;
}
@@ -3567,7 +3572,7 @@ int pc_readparam(dumb_ptr<map_session_data> sd, SP type)
{
int val = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
switch (type)
{
@@ -3587,7 +3592,7 @@ int pc_readparam(dumb_ptr<map_session_data> sd, SP type)
val = sd->status.job_level;
break;
case SP::CLASS:
- val = sd->status.species;
+ val = unwrap<Species>(sd->status.species);
break;
case SP::SEX:
val = static_cast<uint8_t>(sd->sex);
@@ -3643,7 +3648,7 @@ int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val)
{
int i = 0, up_level = 50;
- nullpo_ret(sd);
+ nullpo_retz(sd);
switch (type)
{
@@ -3691,7 +3696,7 @@ int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val)
clif_updatestatus(sd, type);
break;
case SP::CLASS:
- sd->status.species = val;
+ sd->status.species = wrap<Species>(val);
break;
case SP::SKILLPOINT:
sd->status.skill_point = val;
@@ -3762,10 +3767,7 @@ int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val)
*/
int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp)
{
-// if(battle_config.battle_log)
-// PRINTF("heal %d %d\n",hp,sp);
-
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (pc_checkoverhp(sd))
{
@@ -3786,7 +3788,7 @@ int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage(NULL, sd, 1);
+ pc_damage(nullptr, sd, 1);
hp = 0;
}
sd->status.sp += sp;
@@ -3797,10 +3799,10 @@ int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp)
if (sp)
clif_updatestatus(sd, SP::SP);
- if (sd->status.party_id > 0)
+ if (sd->status.party_id)
{ // on-the-fly party hp updates [Valaris]
- struct party *p = party_search(sd->status.party_id);
- if (p != NULL)
+ PartyPair p = party_search(sd->status.party_id);
+ if (p)
clif_party_hp(p, sd);
} // end addition [Valaris]
@@ -3847,9 +3849,9 @@ void pc_heal_quick_accumulate(int new_amount,
int average_speed = ((new_speed * new_amount) + (current_speed * current_amount)) / (current_amount + new_amount); // new_amount > 0, current_amount >= 0
quick_regen->speed = average_speed;
- quick_regen->amount = min(current_amount + new_amount, max);
+ quick_regen->amount = std::min(current_amount + new_amount, max);
- quick_regen->tickdelay = min(quick_regen->speed, quick_regen->tickdelay);
+ quick_regen->tickdelay = std::min(quick_regen->speed, quick_regen->tickdelay);
}
int pc_itemheal(dumb_ptr<map_session_data> sd, int hp, int sp)
@@ -3884,7 +3886,7 @@ int pc_itemheal(dumb_ptr<map_session_data> sd, int hp, int sp)
static
int pc_itemheal_effect(dumb_ptr<map_session_data> sd, int hp, int sp)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (pc_checkoverhp(sd))
{
@@ -3914,7 +3916,7 @@ int pc_itemheal_effect(dumb_ptr<map_session_data> sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage(NULL, sd, 1);
+ pc_damage(nullptr, sd, 1);
hp = 0;
}
sd->status.sp += sp;
@@ -3934,7 +3936,7 @@ int pc_itemheal_effect(dumb_ptr<map_session_data> sd, int hp, int sp)
*/
int pc_percentheal(dumb_ptr<map_session_data> sd, int hp, int sp)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (pc_checkoverhp(sd))
{
@@ -3955,7 +3957,7 @@ int pc_percentheal(dumb_ptr<map_session_data> sd, int hp, int sp)
else if (hp <= -100)
{
sd->status.hp = 0;
- pc_damage(NULL, sd, 1);
+ pc_damage(nullptr, sd, 1);
}
else
{
@@ -3965,7 +3967,7 @@ int pc_percentheal(dumb_ptr<map_session_data> sd, int hp, int sp)
if (sd->status.hp <= 0)
{
sd->status.hp = 0;
- pc_damage(NULL, sd, 1);
+ pc_damage(nullptr, sd, 1);
hp = 0;
}
}
@@ -4003,7 +4005,7 @@ int pc_percentheal(dumb_ptr<map_session_data> sd, int hp, int sp)
*/
int pc_changelook(dumb_ptr<map_session_data> sd, LOOK type, int val)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
switch (type)
{
@@ -4014,13 +4016,13 @@ int pc_changelook(dumb_ptr<map_session_data> sd, LOOK type, int val)
sd->status.weapon = static_cast<ItemLook>(static_cast<uint16_t>(val));
break;
case LOOK::HEAD_BOTTOM:
- sd->status.head_bottom = val;
+ sd->status.head_bottom = wrap<ItemNameId>(val);
break;
case LOOK::HEAD_TOP:
- sd->status.head_top = val;
+ sd->status.head_top = wrap<ItemNameId>(val);
break;
case LOOK::HEAD_MID:
- sd->status.head_mid = val;
+ sd->status.head_mid = wrap<ItemNameId>(val);
break;
case LOOK::HAIR_COLOR:
sd->status.hair_color = val;
@@ -4029,7 +4031,7 @@ int pc_changelook(dumb_ptr<map_session_data> sd, LOOK type, int val)
sd->status.clothes_color = val;
break;
case LOOK::SHIELD:
- sd->status.shield = val;
+ sd->status.shield = wrap<ItemNameId>(val);
break;
case LOOK::SHOES:
break;
@@ -4045,7 +4047,7 @@ int pc_changelook(dumb_ptr<map_session_data> sd, LOOK type, int val)
*/
int pc_setoption(dumb_ptr<map_session_data> sd, Option type)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
sd->status.option = type;
clif_changeoption(sd);
@@ -4060,7 +4062,7 @@ int pc_setoption(dumb_ptr<map_session_data> sd, Option type)
*/
int pc_readreg(dumb_ptr<map_session_data> sd, SIR reg)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
return sd->regm.get(reg);
}
@@ -4116,7 +4118,7 @@ int pc_readglobalreg(dumb_ptr<map_session_data> sd, VarName reg)
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
assert (sd->status.global_reg_num < GLOBAL_REG_NUM);
for (i = 0; i < sd->status.global_reg_num; i++)
@@ -4136,10 +4138,10 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val)
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
//PC_DIE_COUNTERがスクリプトなどで変更された時の処理
- if (reg == stringish<VarName>("PC_DIE_COUNTER") && sd->die_counter != val)
+ if (reg == stringish<VarName>("PC_DIE_COUNTER"_s) && sd->die_counter != val)
{
sd->die_counter = val;
pc_calcstatus(sd, 0);
@@ -4175,7 +4177,7 @@ int pc_setglobalreg(dumb_ptr<map_session_data> sd, VarName reg, int val)
return 0;
}
if (battle_config.error_log)
- PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n",
+ PRINTF("pc_setglobalreg : couldn't set %s (GLOBAL_REG_NUM = %d)\n"_fmt,
reg, GLOBAL_REG_NUM);
return 1;
@@ -4189,7 +4191,7 @@ int pc_readaccountreg(dumb_ptr<map_session_data> sd, VarName reg)
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
assert (sd->status.account_reg_num < ACCOUNT_REG_NUM);
for (i = 0; i < sd->status.account_reg_num; i++)
@@ -4209,7 +4211,7 @@ int pc_setaccountreg(dumb_ptr<map_session_data> sd, VarName reg, int val)
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (val == 0)
{
@@ -4244,7 +4246,7 @@ int pc_setaccountreg(dumb_ptr<map_session_data> sd, VarName reg, int val)
return 0;
}
if (battle_config.error_log)
- PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %d)\n",
+ PRINTF("pc_setaccountreg : couldn't set %s (ACCOUNT_REG_NUM = %zu)\n"_fmt,
reg, ACCOUNT_REG_NUM);
return 1;
@@ -4258,7 +4260,7 @@ int pc_readaccountreg2(dumb_ptr<map_session_data> sd, VarName reg)
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (i = 0; i < sd->status.account_reg2_num; i++)
{
@@ -4312,8 +4314,8 @@ int pc_setaccountreg2(dumb_ptr<map_session_data> sd, VarName reg, int val)
return 0;
}
if (battle_config.error_log)
- PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %d)\n",
- reg, ACCOUNT_REG2_NUM);
+ PRINTF("pc_setaccountreg2 : couldn't set %s (ACCOUNT_REG2_NUM = %zu)\n"_fmt,
+ reg, ACCOUNT_REG2_NUM);
return 1;
}
@@ -4323,10 +4325,10 @@ int pc_setaccountreg2(dumb_ptr<map_session_data> sd, VarName reg, int val)
*------------------------------------------
*/
static
-void pc_eventtimer(TimerData *, tick_t, int id, NpcEvent data)
+void pc_eventtimer(TimerData *, tick_t, BlockId id, NpcEvent data)
{
dumb_ptr<map_session_data> sd = map_id2sd(id);
- assert (sd != NULL);
+ assert (sd != nullptr);
npc_event(sd, data, 0);
}
@@ -4339,7 +4341,7 @@ int pc_addeventtimer(dumb_ptr<map_session_data> sd, interval_t tick, NpcEvent na
{
int i;
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (i = 0; i < MAX_EVENTTIMER; i++)
if (!sd->eventtimer[i])
@@ -4362,7 +4364,7 @@ int pc_addeventtimer(dumb_ptr<map_session_data> sd, interval_t tick, NpcEvent na
*/
int pc_cleareventtimer(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
for (int i = 0; i < MAX_EVENTTIMER; i++)
sd->eventtimer[i].cancel();
@@ -4378,7 +4380,7 @@ int pc_cleareventtimer(dumb_ptr<map_session_data> sd)
*------------------------------------------
*/
static
-int pc_signal_advanced_equipment_change(dumb_ptr<map_session_data> sd, int n)
+int pc_signal_advanced_equipment_change(dumb_ptr<map_session_data> sd, IOff0 n)
{
if (bool(sd->status.inventory[n].equip & EPOS::SHOES))
clif_changelook(sd, LOOK::SHOES, 0);
@@ -4393,17 +4395,17 @@ int pc_signal_advanced_equipment_change(dumb_ptr<map_session_data> sd, int n)
return 0;
}
-int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
+int pc_equipitem(dumb_ptr<map_session_data> sd, IOff0 n, EPOS)
{
- int nameid;
+ ItemNameId nameid;
struct item_data *id;
//ソス]ソスソスソスソスソス{ソスqソスフ場合ソスフ鯉ソスソスフ職ソスニゑソスソスZソスoソスソスソスソス
- nullpo_ret(sd);
+ nullpo_retz(sd);
- if (n < 0 || n >= MAX_INVENTORY)
+ if (!n.ok())
{
- clif_equipitemack(sd, 0, EPOS::ZERO, 0);
+ clif_equipitemack(sd, IOff0::from(0), EPOS::ZERO, 0);
return 0;
}
@@ -4414,7 +4416,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
EPOS pos = pc_equippoint(sd, n);
if (battle_config.battle_log)
- PRINTF("equip %d (%d) %x:%x\n",
+ PRINTF("equip %d (%d) %x:%x\n"_fmt,
nameid, n, id->equip, pos);
if (!pc_isequip(sd, n) || pos == EPOS::ZERO)
{
@@ -4428,11 +4430,11 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
{
// アクセサリ用例外処理
EPOS epor = EPOS::ZERO;
- int midx = sd->equip_index_maybe[EQUIP::MISC2];
- int cidx = sd->equip_index_maybe[EQUIP::CAPE];
- if (midx >= 0)
+ IOff0 midx = sd->equip_index_maybe[EQUIP::MISC2];
+ IOff0 cidx = sd->equip_index_maybe[EQUIP::CAPE];
+ if (midx.ok())
epor |= sd->status.inventory[midx].equip;
- if (cidx >= 0)
+ if (cidx.ok())
epor |= sd->status.inventory[cidx].equip;
epor &= (EPOS::MISC2 | EPOS::CAPE);
pos = (epor == EPOS::CAPE ? EPOS::MISC2 : EPOS::CAPE);
@@ -4442,8 +4444,8 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
{
if (bool(pos & equip_pos[i]))
{
- short *idx = &sd->equip_index_maybe[i];
- if (*idx >= 0) //Slot taken, remove item from there.
+ IOff0 *idx = &sd->equip_index_maybe[i];
+ if ((*idx).ok()) //Slot taken, remove item from there.
pc_unequipitem(sd, *idx, CalcStatus::LATER);
*idx = n;
}
@@ -4468,7 +4470,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
}
sd->status.inventory[n].equip = pos;
- int view_i = 0;
+ ItemNameId view_i;
ItemLook view_l = ItemLook::NONE;
// TODO: This is ugly.
if (sd->inventory_data[n])
@@ -4495,7 +4497,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
{
if (sd->inventory_data[n]->type == ItemType::WEAPON)
{
- sd->status.shield = 0;
+ sd->status.shield = ItemNameId();
if (sd->status.inventory[n].equip == EPOS::SHIELD)
sd->weapontype2 = view_l;
}
@@ -4507,26 +4509,26 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
}
else
{
- sd->status.shield = 0;
+ sd->status.shield = ItemNameId();
sd->weapontype2 = ItemLook::NONE;
}
pc_calcweapontype(sd);
- clif_changelook(sd, LOOK::SHIELD, sd->status.shield);
+ clif_changelook(sd, LOOK::SHIELD, unwrap<ItemNameId>(sd->status.shield));
}
if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
sd->status.head_bottom = view_i;
- clif_changelook(sd, LOOK::HEAD_BOTTOM, sd->status.head_bottom);
+ clif_changelook(sd, LOOK::HEAD_BOTTOM, unwrap<ItemNameId>(sd->status.head_bottom));
}
if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
sd->status.head_top = view_i;
- clif_changelook(sd, LOOK::HEAD_TOP, sd->status.head_top);
+ clif_changelook(sd, LOOK::HEAD_TOP, unwrap<ItemNameId>(sd->status.head_top));
}
if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
sd->status.head_mid = view_i;
- clif_changelook(sd, LOOK::HEAD_MID, sd->status.head_mid);
+ clif_changelook(sd, LOOK::HEAD_MID, unwrap<ItemNameId>(sd->status.head_mid));
}
pc_signal_advanced_equipment_change(sd, n);
@@ -4539,14 +4541,14 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS)
* 装 備した物を外す
*------------------------------------------
*/
-int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
+int pc_unequipitem(dumb_ptr<map_session_data> sd, IOff0 n, CalcStatus type)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
// -- moonsoul (if player is berserk then cannot unequip)
//
if (battle_config.battle_log)
- PRINTF("unequip %d %x:%x\n",
+ PRINTF("unequip %d %x:%x\n"_fmt,
n, pc_equippoint(sd, n),
sd->status.inventory[n].equip);
if (bool(sd->status.inventory[n].equip))
@@ -4554,7 +4556,7 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
for (EQUIP i : EQUIPs)
{
if (bool(sd->status.inventory[n].equip & equip_pos[i]))
- sd->equip_index_maybe[i] = -1;
+ sd->equip_index_maybe[i] = IOff0::from(-1);
}
if (bool(sd->status.inventory[n].equip & EPOS::WEAPON))
{
@@ -4565,26 +4567,25 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
}
if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
- sd->status.shield = 0;
+ sd->status.shield = ItemNameId();
sd->weapontype2 = ItemLook::NONE;
pc_calcweapontype(sd);
- clif_changelook(sd, LOOK::SHIELD, sd->status.shield);
+ clif_changelook(sd, LOOK::SHIELD, unwrap<ItemNameId>(sd->status.shield));
}
if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
- sd->status.head_bottom = 0;
- clif_changelook(sd, LOOK::HEAD_BOTTOM,
- sd->status.head_bottom);
+ sd->status.head_bottom = ItemNameId();
+ clif_changelook(sd, LOOK::HEAD_BOTTOM, unwrap<ItemNameId>(sd->status.head_bottom));
}
if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
- sd->status.head_top = 0;
- clif_changelook(sd, LOOK::HEAD_TOP, sd->status.head_top);
+ sd->status.head_top = ItemNameId();
+ clif_changelook(sd, LOOK::HEAD_TOP, unwrap<ItemNameId>(sd->status.head_top));
}
if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
- sd->status.head_mid = 0;
- clif_changelook(sd, LOOK::HEAD_MID, sd->status.head_mid);
+ sd->status.head_mid = ItemNameId();
+ clif_changelook(sd, LOOK::HEAD_MID, unwrap<ItemNameId>(sd->status.head_mid));
}
pc_signal_advanced_equipment_change(sd, n);
@@ -4603,7 +4604,7 @@ int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
return 0;
}
-int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
+int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, IOff0 n, CalcStatus type)
{
nullpo_retr(1, sd);
@@ -4615,7 +4616,7 @@ int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
{
//Slot taken, remove item from there.
pc_unequipitem(sd, sd->equip_index_maybe[i], type);
- sd->equip_index_maybe[i] = -1;
+ sd->equip_index_maybe[i] = IOff0::from(-1);
}
}
@@ -4629,30 +4630,31 @@ int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type)
*/
int pc_checkitem(dumb_ptr<map_session_data> sd)
{
- int i, j, k, id, calc_flag = 0;
+ int calc_flag = 0;
- nullpo_ret(sd);
+ nullpo_retz(sd);
- // 所持品空き詰め
- for (i = j = 0; i < MAX_INVENTORY; i++)
+ IOff0 j = IOff0::from(0);
+ for (IOff0 i : IOff0::iter())
{
- if ((id = sd->status.inventory[i].nameid) == 0)
+ if (!(sd->status.inventory[i].nameid))
continue;
- if (i > j)
+ if (i != j)
{
sd->status.inventory[j] = sd->status.inventory[i];
sd->inventory_data[j] = sd->inventory_data[i];
}
- j++;
+ ++j;
+ }
+ for (IOff0 k = j; k != IOff0::from(MAX_INVENTORY); ++k)
+ {
+ sd->status.inventory[k] = Item{};
+ sd->inventory_data[k] = nullptr;
}
- for (k = j; k < MAX_INVENTORY; ++k)
- sd->status.inventory[k] = item{};
- for (k = j; k < MAX_INVENTORY; k++)
- sd->inventory_data[k] = NULL;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (IOff0 i : IOff0::iter())
{
- if (sd->status.inventory[i].nameid == 0)
+ if (!sd->status.inventory[i].nameid)
continue;
if (bool(sd->status.inventory[i].equip & ~pc_equippoint(sd, i)))
{
@@ -4670,7 +4672,7 @@ int pc_checkitem(dumb_ptr<map_session_data> sd)
int pc_checkoverhp(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.hp == sd->status.max_hp)
return 1;
@@ -4686,7 +4688,7 @@ int pc_checkoverhp(dumb_ptr<map_session_data> sd)
int pc_checkoversp(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (sd->status.sp == sd->status.max_sp)
return 1;
@@ -4723,9 +4725,9 @@ void pc_calc_pvprank_sub(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd2
*/
int pc_calc_pvprank(dumb_ptr<map_session_data> sd)
{
- nullpo_ret(sd);
+ nullpo_retz(sd);
map_local *m = sd->bl_m;
- nullpo_ret(m);
+ nullpo_retz(m);
if (!(m->flag.get(MapFlag::PVP)))
return 0;
@@ -4742,20 +4744,22 @@ int pc_calc_pvprank(dumb_ptr<map_session_data> sd)
* PVP順位計算(timer)
*------------------------------------------
*/
-void pc_calc_pvprank_timer(TimerData *, tick_t, int id)
+void pc_calc_pvprank_timer(TimerData *, tick_t, BlockId id)
{
- dumb_ptr<map_session_data> sd = NULL;
+ dumb_ptr<map_session_data> sd = nullptr;
if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris]
return;
sd = map_id2sd(id);
- if (sd == NULL)
+ if (sd == nullptr)
return;
sd->pvp_timer.cancel();
if (pc_calc_pvprank(sd) > 0)
+ {
sd->pvp_timer = Timer(gettick() + PVP_CALCRANK_INTERVAL,
std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
id));
+ }
}
/*==========================================
@@ -4763,14 +4767,14 @@ void pc_calc_pvprank_timer(TimerData *, tick_t, int id)
*------------------------------------------
*/
static
-int pc_ismarried(dumb_ptr<map_session_data> sd)
+CharId pc_ismarried(dumb_ptr<map_session_data> sd)
{
- if (sd == NULL)
- return -1;
- if (sd->status.partner_id > 0)
+ if (sd == nullptr)
+ return CharId();
+ if (sd->status.partner_id)
return sd->status.partner_id;
else
- return 0;
+ return CharId();
}
/*==========================================
@@ -4779,8 +4783,8 @@ int pc_ismarried(dumb_ptr<map_session_data> sd)
*/
int pc_marriage(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> dstsd)
{
- if (sd == NULL || dstsd == NULL || sd->status.partner_id > 0
- || dstsd->status.partner_id > 0)
+ if (sd == nullptr || dstsd == nullptr || sd->status.partner_id
+ || dstsd->status.partner_id)
return -1;
sd->status.partner_id = dstsd->status_key.char_id;
dstsd->status.partner_id = sd->status_key.char_id;
@@ -4793,23 +4797,23 @@ int pc_marriage(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> dstsd)
*/
int pc_divorce(dumb_ptr<map_session_data> sd)
{
- dumb_ptr<map_session_data> p_sd = NULL;
- if (sd == NULL || !pc_ismarried(sd))
+ dumb_ptr<map_session_data> p_sd = nullptr;
+ if (sd == nullptr || !pc_ismarried(sd))
return -1;
// If both are on map server we don't need to bother the char server
if ((p_sd =
- map_nick2sd(map_charid2nick(sd->status.partner_id))) != NULL)
+ map_nick2sd(map_charid2nick(sd->status.partner_id))) != nullptr)
{
if (p_sd->status.partner_id != sd->status_key.char_id
|| sd->status.partner_id != p_sd->status_key.char_id)
{
- PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",
+ PRINTF("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n"_fmt,
sd->status.partner_id, p_sd->status.partner_id);
return -1;
}
- p_sd->status.partner_id = 0;
- sd->status.partner_id = 0;
+ p_sd->status.partner_id = CharId();
+ sd->status.partner_id = CharId();
if (sd->npc_flags.divorce)
{
@@ -4829,17 +4833,17 @@ int pc_divorce(dumb_ptr<map_session_data> sd)
*/
dumb_ptr<map_session_data> pc_get_partner(dumb_ptr<map_session_data> sd)
{
- dumb_ptr<map_session_data> p_sd = NULL;
- if (sd == NULL || !pc_ismarried(sd))
- return NULL;
+ dumb_ptr<map_session_data> p_sd = nullptr;
+ if (sd == nullptr || !pc_ismarried(sd))
+ return nullptr;
CharName nick = map_charid2nick(sd->status.partner_id);
if (!nick.to__actual())
- return NULL;
+ return nullptr;
- if ((p_sd = map_nick2sd(nick)) == NULL)
- return NULL;
+ if ((p_sd = map_nick2sd(nick)) == nullptr)
+ return nullptr;
return p_sd;
}
@@ -4890,7 +4894,7 @@ int pc_natural_heal_hp(dumb_ptr<map_session_data> sd)
int bhp;
int bonus;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (pc_checkoverhp(sd))
{
@@ -4962,7 +4966,7 @@ int pc_natural_heal_sp(dumb_ptr<map_session_data> sd)
int bsp;
int bonus;
- nullpo_ret(sd);
+ nullpo_retz(sd);
if (pc_checkoversp(sd))
{
@@ -5035,7 +5039,7 @@ int pc_quickregenerate_effect(struct quick_regeneration *quick_regen,
if (!(quick_regen->tickdelay--))
{
int bonus =
- min(heal_speed * battle_config.itemheal_regeneration_factor,
+ std::min(heal_speed * battle_config.itemheal_regeneration_factor,
quick_regen->amount);
quick_regen->amount -= bonus;
@@ -5171,21 +5175,20 @@ 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();
}
-int pc_read_gm_account(Session *s)
+int pc_read_gm_account(Session *, const std::vector<Packet_Repeat<0x2b15>>& repeat)
{
gm_accountm.clear();
- // (RFIFOW(fd, 2) - 4) / 5
- for (int i = 4; i < RFIFOW(s, 2); i += 5)
+ for (const auto& i : repeat)
{
- int account_id = RFIFOL(s, i);
- uint8_t level = RFIFOB(s, i + 4);
+ AccountId account_id = i.account_id;
+ GmLevel level = i.gm_level;
gm_accountm[account_id] = level;
}
return gm_accountm.size();
@@ -5265,13 +5268,14 @@ int pc_logout(dumb_ptr<map_session_data> sd) // [fate] Player logs out
// Removed because it's buggy, see above.
if (sd->cast_tick > tick)
{
- if (pc_setglobalreg(sd, "MAGIC_CAST_TICK", sd->cast_tick - tick))
+ if (pc_setglobalreg(sd, "MAGIC_CAST_TICK"_s, sd->cast_tick - tick))
sd->status.sp = 1;
}
else
#endif
- pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"), 0);
+ pc_setglobalreg(sd, stringish<VarName>("MAGIC_CAST_TICK"_s), 0);
- MAP_LOG_STATS(sd, "LOGOUT");
+ MAP_LOG_STATS(sd, "LOGOUT"_fmt);
return 0;
}
+} // namespace tmwa