summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/char/char.cpp116
-rw-r--r--src/char/int_storage.cpp19
-rw-r--r--src/common/mmo.hpp62
-rw-r--r--src/common/utils2.hpp24
-rw-r--r--src/map/atcommand.cpp165
-rw-r--r--src/map/battle.cpp200
-rw-r--r--src/map/battle.hpp41
-rw-r--r--src/map/battle.t.hpp96
-rw-r--r--src/map/chrif.cpp12
-rw-r--r--src/map/clif.cpp293
-rw-r--r--src/map/clif.hpp14
-rw-r--r--src/map/itemdb.cpp58
-rw-r--r--src/map/itemdb.hpp4
-rw-r--r--src/map/magic-expr-eval.hpp10
-rw-r--r--src/map/magic-expr.cpp66
-rw-r--r--src/map/magic-expr.hpp13
-rw-r--r--src/map/magic-interpreter-base.cpp17
-rw-r--r--src/map/magic-interpreter-parser.ypp27
-rw-r--r--src/map/magic-interpreter.hpp119
-rw-r--r--src/map/magic-interpreter.t.hpp210
-rw-r--r--src/map/magic-stmt.cpp26
-rw-r--r--src/map/magic.cpp4
-rw-r--r--src/map/map.cpp44
-rw-r--r--src/map/map.hpp166
-rw-r--r--src/map/map.t.hpp536
-rw-r--r--src/map/mob.cpp214
-rw-r--r--src/map/mob.hpp8
-rw-r--r--src/map/npc.cpp6
-rw-r--r--src/map/pc.cpp876
-rw-r--r--src/map/pc.hpp45
-rw-r--r--src/map/pc.t.hpp49
-rw-r--r--src/map/script.cpp107
-rw-r--r--src/map/skill-pools.cpp16
-rw-r--r--src/map/skill.cpp486
-rw-r--r--src/map/skill.hpp29
-rw-r--r--src/map/skill.t.hpp21
-rw-r--r--src/map/storage.cpp6
-rw-r--r--src/map/trade.cpp51
38 files changed, 2486 insertions, 1770 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 67268f4..391f81f 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -222,7 +222,9 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
}
str_p += sprintf(str_p, "%d\t%d,%d\t%s\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d\t%d,%d,%d,%d,%d,%d\t%d,%d" "\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d\t%d,%d,%d,%d,%d" "\t%s,%d,%d\t%s,%d,%d,%d\t", p->char_id, p->account_id, p->char_num, p->name, //
- p->pc_class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, p->status_point, p->skill_point, uint16_t(p->option), p->karma, p->manner, //
+ p->pc_class, p->base_level, p->job_level, p->base_exp, p->job_exp, p->zeny, p->hp, p->max_hp, p->sp, p->max_sp,
+ p->attrs[ATTR::STR], p->attrs[ATTR::AGI], p->attrs[ATTR::VIT], p->attrs[ATTR::INT], p->attrs[ATTR::DEX], p->attrs[ATTR::LUK],
+ p->status_point, p->skill_point, uint16_t(p->option), p->karma, p->manner, //
p->party_id, 0/*guild_id*/, 0, p->hair, p->hair_color, p->clothes_color, p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, p->last_point.map, p->last_point.x, p->last_point.y, //
p->save_point.map, p->save_point.x, p->save_point.y,
p->partner_id);
@@ -239,8 +241,10 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
if (p->inventory[i].nameid)
{
str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->inventory[i].id, p->inventory[i].nameid,
- p->inventory[i].amount, p->inventory[i].equip,
+ p->inventory[i].id,
+ p->inventory[i].nameid,
+ p->inventory[i].amount,
+ uint16_t(p->inventory[i].equip),
p->inventory[i].identify,
p->inventory[i].refine,
p->inventory[i].attribute,
@@ -256,12 +260,18 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
if (p->cart[i].nameid)
{
str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->cart[i].id, p->cart[i].nameid,
- p->cart[i].amount, p->cart[i].equip,
- p->cart[i].identify, p->cart[i].refine,
- p->cart[i].attribute, p->cart[i].card[0],
- p->cart[i].card[1], p->cart[i].card[2],
- p->cart[i].card[3], p->cart[i].broken);
+ p->cart[i].id,
+ p->cart[i].nameid,
+ p->cart[i].amount,
+ uint16_t(p->cart[i].equip),
+ p->cart[i].identify,
+ p->cart[i].refine,
+ p->cart[i].attribute,
+ p->cart[i].card[0],
+ p->cart[i].card[1],
+ p->cart[i].card[2],
+ p->cart[i].card[3],
+ p->cart[i].broken);
}
*(str_p++) = '\t';
@@ -271,7 +281,7 @@ int mmo_char_tostr(char *str, struct mmo_charstatus *p)
{
str_p +=
sprintf(str_p, "%d,%d ", uint16_t(p->skill[i].id),
- p->skill[i].lv | (p->skill[i].flags << 16));
+ p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16));
}
*(str_p++) = '\t';
@@ -352,12 +362,12 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
p->max_hp = tmp_int[10];
p->sp = tmp_int[11];
p->max_sp = tmp_int[12];
- p->str = tmp_int[13];
- p->agi = tmp_int[14];
- p->vit = tmp_int[15];
- p->int_ = tmp_int[16];
- p->dex = tmp_int[17];
- p->luk = tmp_int[18];
+ p->attrs[ATTR::STR] = tmp_int[13];
+ p->attrs[ATTR::AGI] = tmp_int[14];
+ p->attrs[ATTR::VIT] = tmp_int[15];
+ p->attrs[ATTR::INT] = tmp_int[16];
+ p->attrs[ATTR::DEX] = tmp_int[17];
+ p->attrs[ATTR::LUK] = tmp_int[18];
p->status_point = tmp_int[19];
p->skill_point = tmp_int[20];
p->option = Option(tmp_int[21]);
@@ -453,7 +463,7 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
p->inventory[i].id = tmp_int[0];
p->inventory[i].nameid = tmp_int[1];
p->inventory[i].amount = tmp_int[2];
- p->inventory[i].equip = tmp_int[3];
+ p->inventory[i].equip = EPOS(tmp_int[3]);
p->inventory[i].identify = tmp_int[4];
p->inventory[i].refine = tmp_int[5];
p->inventory[i].attribute = tmp_int[6];
@@ -492,7 +502,7 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
p->cart[i].id = tmp_int[0];
p->cart[i].nameid = tmp_int[1];
p->cart[i].amount = tmp_int[2];
- p->cart[i].equip = tmp_int[3];
+ p->cart[i].equip = EPOS(tmp_int[3]);
p->cart[i].identify = tmp_int[4];
p->cart[i].refine = tmp_int[5];
p->cart[i].attribute = tmp_int[6];
@@ -516,7 +526,7 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p)
SkillID skill_id = SkillID(tmp_int[0]);
p->skill[skill_id].id = skill_id;
p->skill[skill_id].lv = tmp_int[1] & 0xffff;
- p->skill[skill_id].flags = ((tmp_int[1] >> 16) & 0xffff);
+ p->skill[skill_id].flags = SkillFlags(tmp_int[1] >> 16);
next += len;
if (str[next] == ' ')
next++;
@@ -954,14 +964,14 @@ int make_new_char(int fd, unsigned char *dat)
char_dat[i].base_exp = 0;
char_dat[i].job_exp = 0;
char_dat[i].zeny = start_zeny;
- char_dat[i].str = dat[24];
- char_dat[i].agi = dat[25];
- char_dat[i].vit = dat[26];
- char_dat[i].int_ = dat[27];
- char_dat[i].dex = dat[28];
- char_dat[i].luk = dat[29];
- char_dat[i].max_hp = 40 * (100 + char_dat[i].vit) / 100;
- char_dat[i].max_sp = 11 * (100 + char_dat[i].int_) / 100;
+ char_dat[i].attrs[ATTR::STR] = dat[24];
+ char_dat[i].attrs[ATTR::AGI] = dat[25];
+ char_dat[i].attrs[ATTR::VIT] = dat[26];
+ char_dat[i].attrs[ATTR::INT] = dat[27];
+ char_dat[i].attrs[ATTR::DEX] = dat[28];
+ char_dat[i].attrs[ATTR::LUK] = dat[29];
+ char_dat[i].max_hp = 40 * (100 + char_dat[i].attrs[ATTR::VIT]) / 100;
+ char_dat[i].max_sp = 11 * (100 + char_dat[i].attrs[ATTR::INT]) / 100;
char_dat[i].hp = char_dat[i].max_hp;
char_dat[i].sp = char_dat[i].max_sp;
char_dat[i].status_point = 0;
@@ -976,12 +986,12 @@ int make_new_char(int fd, unsigned char *dat)
char_dat[i].clothes_color = 0;
char_dat[i].inventory[0].nameid = start_weapon; // Knife
char_dat[i].inventory[0].amount = 1;
- char_dat[i].inventory[0].equip = 0x02;
+ char_dat[i].inventory[0].equip = EPOS::WEAPON;
char_dat[i].inventory[0].identify = 1;
char_dat[i].inventory[0].broken = 0;
char_dat[i].inventory[1].nameid = start_armor; // Cotton Shirt
char_dat[i].inventory[1].amount = 1;
- char_dat[i].inventory[1].equip = 0x10;
+ char_dat[i].inventory[1].equip = EPOS::TORSO;
char_dat[i].inventory[1].identify = 1;
char_dat[i].inventory[1].broken = 0;
char_dat[i].weapon = 1;
@@ -1524,12 +1534,12 @@ int count_users(void)
// [Fate] Find inventory item based on equipment mask, return view. ID must match view ID (!).
//----------------------------------------
static
-int find_equip_view(struct mmo_charstatus *p, unsigned int equipmask)
+int find_equip_view(struct mmo_charstatus *p, EPOS equipmask)
{
int i;
for (i = 0; i < MAX_INVENTORY; i++)
if (p->inventory[i].nameid && p->inventory[i].amount
- && p->inventory[i].equip & equipmask)
+ && bool(p->inventory[i].equip & equipmask))
return p->inventory[i].nameid;
return 0;
}
@@ -1573,10 +1583,10 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
WFIFOL(fd, j + 12) = p->job_exp;
WFIFOL(fd, j + 16) = 0; //p->job_level; // [Fate] We no longer reveal this to the player, as its meaning is weird.
- WFIFOW(fd, j + 20) = find_equip_view(p, 0x0040); // 9: shoes
- WFIFOW(fd, j + 22) = find_equip_view(p, 0x0004); // 10: gloves
- WFIFOW(fd, j + 24) = find_equip_view(p, 0x0008); // 11: cape
- WFIFOW(fd, j + 26) = find_equip_view(p, 0x0010); // 12: misc1
+ WFIFOW(fd, j + 20) = find_equip_view(p, EPOS::SHOES);
+ WFIFOW(fd, j + 22) = find_equip_view(p, EPOS::GLOVES);
+ WFIFOW(fd, j + 24) = find_equip_view(p, EPOS::CAPE);
+ WFIFOW(fd, j + 26) = find_equip_view(p, EPOS::TORSO);
WFIFOL(fd, j + 28) = uint16_t(p->option);
WFIFOL(fd, j + 32) = p->karma;
@@ -1599,17 +1609,17 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
WFIFOW(fd, j + 66) = p->head_top;
WFIFOW(fd, j + 68) = p->head_mid;
WFIFOW(fd, j + 70) = p->hair_color;
- WFIFOW(fd, j + 72) = find_equip_view(p, 0x0080); // 13: misc2
+ WFIFOW(fd, j + 72) = find_equip_view(p, EPOS::MISC2);
// WFIFOW(fd,j+72) = p->clothes_color;
memcpy(WFIFOP(fd, j + 74), p->name, 24);
- WFIFOB(fd, j + 98) = (p->str > 255) ? 255 : p->str;
- WFIFOB(fd, j + 99) = (p->agi > 255) ? 255 : p->agi;
- WFIFOB(fd, j + 100) = (p->vit > 255) ? 255 : p->vit;
- WFIFOB(fd, j + 101) = (p->int_ > 255) ? 255 : p->int_;
- WFIFOB(fd, j + 102) = (p->dex > 255) ? 255 : p->dex;
- WFIFOB(fd, j + 103) = (p->luk > 255) ? 255 : p->luk;
+ WFIFOB(fd, j + 98) = min(p->attrs[ATTR::STR], 255);
+ WFIFOB(fd, j + 99) = min(p->attrs[ATTR::AGI], 255);
+ WFIFOB(fd, j + 100) = min(p->attrs[ATTR::VIT], 255);
+ WFIFOB(fd, j + 101) = min(p->attrs[ATTR::INT], 255);
+ WFIFOB(fd, j + 102) = min(p->attrs[ATTR::DEX], 255);
+ WFIFOB(fd, j + 103) = min(p->attrs[ATTR::LUK], 255);
WFIFOB(fd, j + 104) = p->char_num;
}
@@ -1913,8 +1923,8 @@ void parse_tologin(int fd)
for (j = 0; j < MAX_INVENTORY; j++)
{
if (char_dat[i].inventory[j].nameid
- && char_dat[i].inventory[j].equip)
- char_dat[i].inventory[j].equip = 0;
+ && bool(char_dat[i].inventory[j].equip))
+ char_dat[i].inventory[j].equip = EPOS::ZERO;
}
char_dat[i].weapon = 0;
char_dat[i].shield = 0;
@@ -3183,18 +3193,12 @@ void parse_char(int fd)
memcpy(WFIFOP(fd, 2 + 74), char_dat[i].name, 24);
- WFIFOB(fd, 2 + 98) =
- (char_dat[i].str > 255) ? 255 : char_dat[i].str;
- WFIFOB(fd, 2 + 99) =
- (char_dat[i].agi > 255) ? 255 : char_dat[i].agi;
- WFIFOB(fd, 2 + 100) =
- (char_dat[i].vit > 255) ? 255 : char_dat[i].vit;
- WFIFOB(fd, 2 + 101) =
- (char_dat[i].int_ > 255) ? 255 : char_dat[i].int_;
- WFIFOB(fd, 2 + 102) =
- (char_dat[i].dex > 255) ? 255 : char_dat[i].dex;
- WFIFOB(fd, 2 + 103) =
- (char_dat[i].luk > 255) ? 255 : char_dat[i].luk;
+ WFIFOB(fd, 2 + 98) = min(char_dat[i].attrs[ATTR::STR], 255);
+ WFIFOB(fd, 2 + 99) = min(char_dat[i].attrs[ATTR::AGI], 255);
+ WFIFOB(fd, 2 + 100) = min(char_dat[i].attrs[ATTR::VIT], 255);
+ WFIFOB(fd, 2 + 101) = min(char_dat[i].attrs[ATTR::INT], 255);
+ WFIFOB(fd, 2 + 102) = min(char_dat[i].attrs[ATTR::DEX], 255);
+ WFIFOB(fd, 2 + 103) = min(char_dat[i].attrs[ATTR::LUK], 255);
WFIFOB(fd, 2 + 104) = char_dat[i].char_num;
WFIFOSET(fd, 108);
diff --git a/src/char/int_storage.cpp b/src/char/int_storage.cpp
index b0bc300..05553b9 100644
--- a/src/char/int_storage.cpp
+++ b/src/char/int_storage.cpp
@@ -30,12 +30,17 @@ int storage_tostr(char *str, struct storage *p)
if ((p->storage_[i].nameid) && (p->storage_[i].amount))
{
str_p += sprintf(str_p, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d ",
- p->storage_[i].id, p->storage_[i].nameid,
- p->storage_[i].amount, p->storage_[i].equip,
- p->storage_[i].identify, p->storage_[i].refine,
+ p->storage_[i].id,
+ p->storage_[i].nameid,
+ p->storage_[i].amount,
+ uint16_t(p->storage_[i].equip),
+ p->storage_[i].identify,
+ p->storage_[i].refine,
p->storage_[i].attribute,
- p->storage_[i].card[0], p->storage_[i].card[1],
- p->storage_[i].card[2], p->storage_[i].card[3]);
+ p->storage_[i].card[0],
+ p->storage_[i].card[1],
+ p->storage_[i].card[2],
+ p->storage_[i].card[3]);
f++;
}
@@ -73,7 +78,7 @@ int storage_fromstr(char *str, struct storage *p)
p->storage_[i].id = tmp_int[0];
p->storage_[i].nameid = tmp_int[1];
p->storage_[i].amount = tmp_int[2];
- p->storage_[i].equip = tmp_int[3];
+ p->storage_[i].equip = EPOS(tmp_int[3] );
p->storage_[i].identify = tmp_int[4];
p->storage_[i].refine = tmp_int[5];
p->storage_[i].attribute = tmp_int[6];
@@ -95,7 +100,7 @@ int storage_fromstr(char *str, struct storage *p)
p->storage_[i].id = tmp_int[0];
p->storage_[i].nameid = tmp_int[1];
p->storage_[i].amount = tmp_int[2];
- p->storage_[i].equip = tmp_int[3];
+ p->storage_[i].equip = EPOS(tmp_int[3]);
p->storage_[i].identify = tmp_int[4];
p->storage_[i].refine = tmp_int[5];
p->storage_[i].attribute = tmp_int[6];
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index 8489ef1..cda097a 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -51,12 +51,35 @@ constexpr SkillID MAX_SKILL = SkillID(474); // not 450
# define CHAR_CONF_NAME "conf/char_athena.conf"
+namespace e
+{
+enum class EPOS : uint16_t
+{
+ ZERO = 0x0000,
+
+ LEGS = 0x0001,
+ WEAPON = 0x0002,
+ GLOVES = 0x0004,
+ CAPE = 0x0008,
+ MISC1 = 0x0010,
+ SHIELD = 0x0020,
+ SHOES = 0x0040,
+ MISC2 = 0x0080,
+ HAT = 0x0100,
+ TORSO = 0x0200,
+
+ ARROW = 0x8000,
+};
+ENUM_BITWISE_OPERATORS(EPOS)
+}
+using e::EPOS;
+
struct item
{
int id;
short nameid;
short amount;
- unsigned short equip;
+ EPOS equip;
char identify;
char refine;
char attribute;
@@ -70,10 +93,17 @@ struct point
short x, y;
};
+namespace e
+{
+enum class SkillFlags : uint16_t;
+}
+using e::SkillFlags;
+
struct skill
{
SkillID id;
- unsigned short lv, flags;
+ unsigned short lv;
+ SkillFlags flags;
};
struct global_reg
@@ -83,7 +113,33 @@ struct global_reg
};
// Option and Opt1..3 in map.hpp
+namespace e
+{
enum class Option : uint16_t;
+}
+using e::Option;
+
+enum class ATTR
+{
+ STR = 0,
+ AGI = 1,
+ VIT = 2,
+ INT = 3,
+ DEX = 4,
+ LUK = 5,
+
+ COUNT = 6,
+};
+
+constexpr ATTR ATTRs[6] =
+{
+ ATTR::STR,
+ ATTR::AGI,
+ ATTR::VIT,
+ ATTR::INT,
+ ATTR::DEX,
+ ATTR::LUK,
+};
struct mmo_charstatus
{
@@ -106,7 +162,7 @@ struct mmo_charstatus
char name[24];
unsigned char base_level, job_level;
- short str, agi, vit, int_, dex, luk;
+ earray<short, ATTR, ATTR::COUNT> attrs;
unsigned char char_num, sex;
unsigned long mapip;
diff --git a/src/common/utils2.hpp b/src/common/utils2.hpp
index 326b12f..aa97959 100644
--- a/src/common/utils2.hpp
+++ b/src/common/utils2.hpp
@@ -93,6 +93,18 @@ struct underlying_type
>::type type;
};
+template<class E, bool=std::is_enum<E>::value>
+struct remove_enum
+{
+ typedef E type;
+};
+template<class E>
+struct remove_enum<E, true>
+{
+ typedef typename underlying_type<E>::type type;
+};
+
+
#define ENUM_BITWISE_OPERATORS(E) \
inline \
E operator & (E l, E r) \
@@ -175,3 +187,15 @@ IteratorPair<EnumValueIterator<E>> erange(E b, E e)
namespace std { namespace placeholders {} }
namespace ph = std::placeholders;
+
+template<class A, class B>
+typename std::common_type<A, B>::type min(A a, B b)
+{
+ return a < b ? a : b;
+}
+
+template<class A, class B>
+typename std::common_type<A, B>::type max(A a, B b)
+{
+ return b < a ? a : b;
+}
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 7691789..853d8b4 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -87,6 +87,7 @@ ATCOMMAND_FUNC(packet);
ATCOMMAND_FUNC(statuspoint);
ATCOMMAND_FUNC(skillpoint);
ATCOMMAND_FUNC(zeny);
+template<ATTR attr>
ATCOMMAND_FUNC(param);
ATCOMMAND_FUNC(recall);
ATCOMMAND_FUNC(recallall);
@@ -253,12 +254,12 @@ AtCommandInfo atcommand_info[] = {
{AtCommand_StatusPoint, "@stpoint", 60, atcommand_statuspoint},
{AtCommand_SkillPoint, "@skpoint", 60, atcommand_skillpoint},
{AtCommand_Zeny, "@zeny", 60, atcommand_zeny},
- {AtCommand_Strength, "@str", 60, atcommand_param},
- {AtCommand_Agility, "@agi", 60, atcommand_param},
- {AtCommand_Vitality, "@vit", 60, atcommand_param},
- {AtCommand_Intelligence, "@int", 60, atcommand_param},
- {AtCommand_Dexterity, "@dex", 60, atcommand_param},
- {AtCommand_Luck, "@luk", 60, atcommand_param},
+ {AtCommand_Strength, "@str", 60, atcommand_param<ATTR::STR>},
+ {AtCommand_Agility, "@agi", 60, atcommand_param<ATTR::AGI>},
+ {AtCommand_Vitality, "@vit", 60, atcommand_param<ATTR::VIT>},
+ {AtCommand_Intelligence, "@int", 60, atcommand_param<ATTR::INT>},
+ {AtCommand_Dexterity, "@dex", 60, atcommand_param<ATTR::DEX>},
+ {AtCommand_Luck, "@luk", 60, atcommand_param<ATTR::LUK>},
{AtCommand_Recall, "@recall", 60, atcommand_recall}, // + /recall
{AtCommand_Revive, "@revive", 60, atcommand_revive},
{AtCommand_CharacterStats, "@charstats", 40, atcommand_character_stats},
@@ -1909,7 +1910,7 @@ int atcommand_item(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
char item_name[100];
- int number = 0, item_id, flag;
+ int number = 0, item_id;
struct item item_tmp;
struct item_data *item_data;
int get_count, i;
@@ -1935,8 +1936,10 @@ int atcommand_item(const int fd, struct map_session_data *sd,
if (item_id >= 500)
{
get_count = number;
- if (item_data->type == 4 || item_data->type == 5 ||
- item_data->type == 7 || item_data->type == 8)
+ if (item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8)
{
get_count = 1;
}
@@ -1945,9 +1948,10 @@ int atcommand_item(const int fd, struct map_session_data *sd,
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = item_id;
item_tmp.identify = 1;
- if ((flag =
- pc_additem((struct map_session_data *) sd, &item_tmp,
- get_count)))
+ PickupFail flag;
+ if ((flag = pc_additem((struct map_session_data *) sd,
+ &item_tmp, get_count))
+ != PickupFail::OKAY)
clif_additem((struct map_session_data *) sd, 0, 0, flag);
}
clif_displaymessage(fd, "Item created.");
@@ -1973,7 +1977,7 @@ int atcommand_itemreset(const int fd, struct map_session_data *sd,
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].amount
- && sd->status.inventory[i].equip == 0)
+ && sd->status.inventory[i].equip == EPOS::ZERO)
pc_delitem(sd, i, sd->status.inventory[i].amount, 0);
}
clif_displaymessage(fd, "All of your items have been removed.");
@@ -2909,7 +2913,6 @@ int atcommand_produce(const int fd, struct map_session_data *sd,
{
char item_name[100];
int item_id, attribute = 0, star = 0;
- int flag = 0;
struct item_data *item_data;
struct item tmp_item;
char output[200];
@@ -2947,7 +2950,8 @@ int atcommand_produce(const int fd, struct map_session_data *sd,
tmp_item.card[1] = ((star * 5) << 8) + attribute;
*((unsigned long *) (&tmp_item.card[2])) = sd->char_id;
clif_misceffect(&sd->bl, 3); // 他人にも成功を通知
- if ((flag = pc_additem(sd, &tmp_item, 1)))
+ PickupFail flag;
+ if ((flag = pc_additem(sd, &tmp_item, 1)) != PickupFail::OKAY)
clif_additem(sd, 0, 0, flag);
}
else
@@ -3217,16 +3221,11 @@ int atcommand_zeny(const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
+template<ATTR attr>
int atcommand_param(const int fd, struct map_session_data *sd,
- const char *command, const char *message)
+ const char *, const char *message)
{
- int i, index, value = 0, new_value;
- const char *param[] =
- { "@str", "@agi", "@vit", "@int", "@dex", "@luk", NULL };
- short *status[] = {
- &sd->status.str, &sd->status.agi, &sd->status.vit,
- &sd->status.int_, &sd->status.dex, &sd->status.luk
- };
+ int value = 0, new_value;
char output[200];
memset(output, '\0', sizeof(output));
@@ -3240,34 +3239,17 @@ int atcommand_param(const int fd, struct map_session_data *sd,
return -1;
}
- index = -1;
- for (i = 0; param[i] != NULL; i++)
- {
- if (strcasecmp(command, param[i]) == 0)
- {
- index = i;
- break;
- }
- }
- if (index < 0 || index > MAX_STATUS_TYPE)
- { // normaly impossible...
- sprintf(output,
- "Please, enter a valid value (usage: @str,@agi,@vit,@int,@dex,@luk <+/-adjustement>).");
- clif_displaymessage(fd, output);
- return -1;
- }
-
- new_value = (int) *status[index] + value;
+ new_value = (int) sd->status.attrs[attr] + value;
if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
new_value = battle_config.max_parameter;
else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
new_value = 1;
- if (new_value != (int) *status[index])
+ if (new_value != sd->status.attrs[attr])
{
- *status[index] = new_value;
- clif_updatestatus(sd, SP_STR + index);
- clif_updatestatus(sd, SP_USTR + index);
+ sd->status.attrs[attr] = new_value;
+ clif_updatestatus(sd, attr_to_sp(attr));
+ clif_updatestatus(sd, attr_to_usp(attr));
pc_calcstatus(sd, 0);
clif_displaymessage(fd, "Stat changed.");
}
@@ -3291,32 +3273,26 @@ int atcommand_param(const int fd, struct map_session_data *sd,
int atcommand_all_stats(const int fd, struct map_session_data *sd,
const char *, const char *message)
{
- int index, count, value = 0, new_value;
- short *status[] = {
- &sd->status.str, &sd->status.agi, &sd->status.vit,
- &sd->status.int_, &sd->status.dex, &sd->status.luk
- };
+ int count, value = 0, new_value;
if (!message || !*message || sscanf(message, "%d", &value) < 1
|| value == 0)
value = battle_config.max_parameter;
count = 0;
- for (index = 0; index < (int)(sizeof(status) / sizeof(status[0]));
- index++)
+ for (ATTR attr : ATTRs)
{
-
- new_value = (int) *status[index] + value;
+ new_value = sd->status.attrs[attr] + value;
if (value > 0 && (value > battle_config.max_parameter || new_value > battle_config.max_parameter)) // fix positiv overflow
new_value = battle_config.max_parameter;
else if (value < 0 && (value < -battle_config.max_parameter || new_value < 1)) // fix negativ overflow
new_value = 1;
- if (new_value != (int) *status[index])
+ if (new_value != sd->status.attrs[attr])
{
- *status[index] = new_value;
- clif_updatestatus(sd, SP_STR + index);
- clif_updatestatus(sd, SP_USTR + index);
+ sd->status.attrs[attr] = new_value;
+ clif_updatestatus(sd, attr_to_sp(attr));
+ clif_updatestatus(sd, attr_to_usp(attr));
pc_calcstatus(sd, 0);
count++;
}
@@ -3471,17 +3447,17 @@ int atcommand_character_stats(const int fd, struct map_session_data *,
clif_displaymessage(fd, output);
sprintf(output, "MaxSp - %d", pl_sd->status.max_sp);
clif_displaymessage(fd, output);
- sprintf(output, "Str - %3d", pl_sd->status.str);
+ sprintf(output, "Str - %3d", pl_sd->status.attrs[ATTR::STR]);
clif_displaymessage(fd, output);
- sprintf(output, "Agi - %3d", pl_sd->status.agi);
+ sprintf(output, "Agi - %3d", pl_sd->status.attrs[ATTR::AGI]);
clif_displaymessage(fd, output);
- sprintf(output, "Vit - %3d", pl_sd->status.vit);
+ sprintf(output, "Vit - %3d", pl_sd->status.attrs[ATTR::VIT]);
clif_displaymessage(fd, output);
- sprintf(output, "Int - %3d", pl_sd->status.int_);
+ sprintf(output, "Int - %3d", pl_sd->status.attrs[ATTR::INT]);
clif_displaymessage(fd, output);
- sprintf(output, "Dex - %3d", pl_sd->status.dex);
+ sprintf(output, "Dex - %3d", pl_sd->status.attrs[ATTR::DEX]);
clif_displaymessage(fd, output);
- sprintf(output, "Luk - %3d", pl_sd->status.luk);
+ sprintf(output, "Luk - %3d", pl_sd->status.attrs[ATTR::LUK]);
clif_displaymessage(fd, output);
sprintf(output, "Zeny - %d", pl_sd->status.zeny);
clif_displaymessage(fd, output);
@@ -3532,8 +3508,8 @@ int atcommand_character_stats_all(const int fd, struct map_session_data *,
clif_displaymessage(fd, output);
sprintf(output,
"STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s",
- pl_sd->status.str, pl_sd->status.agi, pl_sd->status.vit,
- pl_sd->status.int_, pl_sd->status.dex, pl_sd->status.luk,
+ pl_sd->status.attrs[ATTR::STR], pl_sd->status.attrs[ATTR::AGI], pl_sd->status.attrs[ATTR::VIT],
+ pl_sd->status.attrs[ATTR::INT], pl_sd->status.attrs[ATTR::DEX], pl_sd->status.attrs[ATTR::LUK],
pl_sd->status.zeny, gmlevel);
clif_displaymessage(fd, output);
clif_displaymessage(fd, "--------");
@@ -4551,7 +4527,7 @@ int atcommand_lostskill(const int fd, struct map_session_data *sd,
if (pc_checkskill(sd, skill_id) > 0)
{
sd->status.skill[skill_id].lv = 0;
- sd->status.skill[skill_id].flags = 0;
+ sd->status.skill[skill_id].flags = SkillFlags::ZERO;
clif_skillinfoblock(sd);
clif_displaymessage(fd, "You have forgotten the skill.");
}
@@ -4609,7 +4585,7 @@ int atcommand_charlostskill(const int fd, struct map_session_data *,
if (pc_checkskill(pl_sd, skill_id) > 0)
{
pl_sd->status.skill[skill_id].lv = 0;
- pl_sd->status.skill[skill_id].flags = 0;
+ pl_sd->status.skill[skill_id].flags = SkillFlags::ZERO;
clif_skillinfoblock(pl_sd);
clif_displaymessage(fd, "This player has forgotten the skill.");
}
@@ -4915,8 +4891,8 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd,
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip)
- pc_unequipitem(pl_sd, i, 0);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
pc_delitem(pl_sd, i, sd->status.inventory[i].amount, 0);
}
}
@@ -6686,7 +6662,7 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
{
struct map_session_data *pl_sd;
struct item_data *item_data, *item_temp;
- int i, j, equip, count, counter, counter2;
+ int i, j, count, counter, counter2;
char character[100], output[200], equipstr[100], outputtmp[200];
memset(character, '\0', sizeof(character));
@@ -6722,36 +6698,37 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd,
pl_sd->status.name);
clif_displaymessage(fd, output);
}
- if ((equip = pl_sd->status.inventory[i].equip))
+ EPOS equip;
+ if (bool(equip = pl_sd->status.inventory[i].equip))
{
strcpy(equipstr, "| equiped: ");
- if (equip & 4)
+ if (bool(equip & EPOS::GLOVES))
strcat(equipstr, "robe/gargment, ");
- if (equip & 8)
+ if (bool(equip & EPOS::CAPE))
strcat(equipstr, "left accessory, ");
- if (equip & 16)
+ if (bool(equip & EPOS::MISC1))
strcat(equipstr, "body/armor, ");
- if ((equip & 34) == 2)
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::WEAPON)
strcat(equipstr, "right hand, ");
- if ((equip & 34) == 32)
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == EPOS::SHIELD)
strcat(equipstr, "left hand, ");
- if ((equip & 34) == 34)
+ if ((equip & (EPOS::WEAPON | EPOS::SHIELD)) == (EPOS::WEAPON | EPOS::SHIELD))
strcat(equipstr, "both hands, ");
- if (equip & 64)
+ if (bool(equip & EPOS::SHOES))
strcat(equipstr, "feet, ");
- if (equip & 128)
+ if (bool(equip & EPOS::MISC2))
strcat(equipstr, "right accessory, ");
- if ((equip & 769) == 1)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::LEGS)
strcat(equipstr, "lower head, ");
- if ((equip & 769) == 256)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::HAT)
strcat(equipstr, "top head, ");
- if ((equip & 769) == 257)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::HAT | EPOS::LEGS))
strcat(equipstr, "lower/top head, ");
- if ((equip & 769) == 512)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == EPOS::TORSO)
strcat(equipstr, "mid head, ");
- if ((equip & 769) == 512)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::LEGS))
strcat(equipstr, "lower/mid head, ");
- if ((equip & 769) == 769)
+ if ((equip & (EPOS::TORSO | EPOS::HAT | EPOS::LEGS)) == (EPOS::TORSO | EPOS::HAT | EPOS::LEGS))
strcat(equipstr, "lower/mid/top head, ");
// remove final ', '
equipstr[strlen(equipstr) - 2] = '\0';
@@ -7266,8 +7243,8 @@ int atcommand_dropall(const int, struct map_session_data *sd,
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip != 0)
- pc_unequipitem(sd, i, 0);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
pc_dropitem(sd, i, sd->status.inventory[i].amount);
}
}
@@ -7295,8 +7272,8 @@ int atcommand_chardropall(const int fd, struct map_session_data *,
{
if (pl_sd->status.inventory[i].amount)
{
- if (pl_sd->status.inventory[i].equip != 0)
- pc_unequipitem(pl_sd, i, 0);
+ if (bool(pl_sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
pc_dropitem(pl_sd, i, pl_sd->status.inventory[i].amount);
}
}
@@ -7338,8 +7315,8 @@ int atcommand_storeall(const int fd, struct map_session_data *sd,
{
if (sd->status.inventory[i].amount)
{
- if (sd->status.inventory[i].equip != 0)
- pc_unequipitem(sd, i, 0);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
storage_storageadd(sd, i, sd->status.inventory[i].amount);
}
}
@@ -7377,8 +7354,8 @@ int atcommand_charstoreall(const int fd, struct map_session_data *sd,
{
if (pl_sd->status.inventory[i].amount)
{
- if (pl_sd->status.inventory[i].equip != 0)
- pc_unequipitem(pl_sd, i, 0);
+ if (bool(pl_sd->status.inventory[i].equip))
+ pc_unequipitem(pl_sd, i, CalcStatus::NOW);
storage_storageadd(pl_sd, i, sd->status.inventory[i].amount);
}
}
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index 6d650cc..88a322b 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -43,7 +43,7 @@ int distance(int x0, int y0, int x1, int y1)
*/
static
int battle_counttargeted(struct block_list *bl, struct block_list *src,
- int target_lv)
+ ATK target_lv)
{
nullpo_ret(bl);
if (bl->type == BL_PC)
@@ -192,7 +192,7 @@ int battle_get_str(struct block_list *bl)
if (bl->type == BL_MOB && ((struct mob_data *) bl))
str = ((struct mob_data *) bl)->stats[MOB_STR];
else if (bl->type == BL_PC && ((struct map_session_data *) bl))
- return ((struct map_session_data *) bl)->paramc[0];
+ return ((struct map_session_data *) bl)->paramc[ATTR::STR];
if (sc_data)
{
@@ -232,7 +232,7 @@ int battle_get_agi(struct block_list *bl)
if (bl->type == BL_MOB && (struct mob_data *) bl)
agi = ((struct mob_data *) bl)->stats[MOB_AGI];
else if (bl->type == BL_PC && (struct map_session_data *) bl)
- agi = ((struct map_session_data *) bl)->paramc[1];
+ agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI];
if (sc_data)
{
@@ -271,7 +271,7 @@ int battle_get_vit(struct block_list *bl)
if (bl->type == BL_MOB && (struct mob_data *) bl)
vit = ((struct mob_data *) bl)->stats[MOB_VIT];
else if (bl->type == BL_PC && (struct map_session_data *) bl)
- vit = ((struct map_session_data *) bl)->paramc[2];
+ vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT];
if (sc_data)
{
if (sc_data[SC_STRIPARMOR].timer != -1 && bl->type != BL_PC)
@@ -300,7 +300,7 @@ int battle_get_int(struct block_list *bl)
if (bl->type == BL_MOB && (struct mob_data *) bl)
int_ = ((struct mob_data *) bl)->stats[MOB_INT];
else if (bl->type == BL_PC && (struct map_session_data *) bl)
- int_ = ((struct map_session_data *) bl)->paramc[3];
+ int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT];
if (sc_data)
{
@@ -338,7 +338,7 @@ int battle_get_dex(struct block_list *bl)
if (bl->type == BL_MOB && (struct mob_data *) bl)
dex = ((struct mob_data *) bl)->stats[MOB_DEX];
else if (bl->type == BL_PC && (struct map_session_data *) bl)
- dex = ((struct map_session_data *) bl)->paramc[4];
+ dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX];
if (sc_data)
{
@@ -381,7 +381,7 @@ int battle_get_luk(struct block_list *bl)
if (bl->type == BL_MOB && (struct mob_data *) bl)
luk = ((struct mob_data *) bl)->stats[MOB_LUK];
else if (bl->type == BL_PC && (struct map_session_data *) bl)
- luk = ((struct map_session_data *) bl)->paramc[5];
+ luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK];
if (sc_data)
{
@@ -495,7 +495,7 @@ int battle_get_flee2(struct block_list *bl)
flee2 = battle_get_luk(bl) + 10;
flee2 +=
((struct map_session_data *) bl)->flee2 -
- (((struct map_session_data *) bl)->paramc[5] + 10);
+ (((struct map_session_data *) bl)->paramc[ATTR::LUK] + 10);
}
else
flee2 = battle_get_luk(bl) + 1;
@@ -533,7 +533,7 @@ int battle_get_critical(struct block_list *bl)
critical = battle_get_luk(bl) * 2 + 10;
critical +=
((struct map_session_data *) bl)->critical -
- ((((struct map_session_data *) bl)->paramc[5] * 3) + 10);
+ ((((struct map_session_data *) bl)->paramc[ATTR::LUK] * 3) + 10);
}
else
critical = battle_get_luk(bl) * 3 + 1;
@@ -924,7 +924,7 @@ int battle_get_mdef2(struct block_list *bl)
else if (bl->type == BL_PC)
mdef2 =
((struct map_session_data *) bl)->mdef2 +
- (((struct map_session_data *) bl)->paramc[2] >> 1);
+ (((struct map_session_data *) bl)->paramc[ATTR::VIT] >> 1);
if (sc_data)
{
if (sc_data[SC_MINDBREAKER].timer != -1 && bl->type != BL_PC)
@@ -1324,8 +1324,7 @@ int battle_get_mexp(struct block_list *bl)
return 0;
}
-int battle_get_stat(int stat_id /* SP_VIT or similar */ ,
- struct block_list *bl)
+int battle_get_stat(SP stat_id, struct block_list *bl)
{
switch (stat_id)
{
@@ -1586,7 +1585,7 @@ int battle_attr_fix(int damage, int atk_elem, int def_elem)
static
int battle_calc_damage(struct block_list *src, struct block_list *bl,
int damage, int div_,
- SkillID skill_num, int, int flag)
+ SkillID skill_num, int, BF flag)
{
struct map_session_data *sd = NULL;
struct mob_data *md = NULL;
@@ -1606,8 +1605,10 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
if (sc_count != NULL && *sc_count > 0)
{
- if (sc_data[SC_SAFETYWALL].timer != -1 && damage > 0
- && flag & BF_WEAPON && flag & BF_SHORT
+ if (sc_data[SC_SAFETYWALL].timer != -1
+ && damage > 0
+ && bool(flag & BF_WEAPON)
+ && bool(flag & BF_SHORT)
&& skill_num != NPC_GUIDEDATTACK)
{
// セーフティウォール
@@ -1618,15 +1619,19 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
skill_unit_move(bl, gettick(), 1); // 重ね掛けチェック
damage = 0;
}
- if (sc_data[SC_PNEUMA].timer != -1 && damage > 0 && flag & BF_WEAPON
- && flag & BF_LONG && skill_num != NPC_GUIDEDATTACK)
+ if (sc_data[SC_PNEUMA].timer != -1
+ && damage > 0
+ && bool(flag & BF_WEAPON)
+ && bool(flag & BF_LONG)
+ && skill_num != NPC_GUIDEDATTACK)
{
// ニューマ
damage = 0;
}
- if (sc_data[SC_ROKISWEIL].timer != -1 && damage > 0 &&
- flag & BF_MAGIC)
+ if (sc_data[SC_ROKISWEIL].timer != -1
+ && damage > 0
+ && bool(flag & BF_MAGIC))
{
// ニューマ
damage = 0;
@@ -1641,30 +1646,36 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
//属性場のダメージ増加
if (sc_data[SC_VOLCANO].timer != -1)
{ // ボルケーノ
- if (flag & BF_SKILL && skill_get_pl(skill_num) == 3)
+ if (bool(flag & BF_SKILL)
+ && skill_get_pl(skill_num) == 3)
damage += damage * sc_data[SC_VOLCANO].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element(bl) == 3))
+ else if (!bool(flag & BF_SKILL)
+ && (battle_get_attack_element(bl) == 3))
damage += damage * sc_data[SC_VOLCANO].val4 / 100;
}
if (sc_data[SC_VIOLENTGALE].timer != -1)
{ // バイオレントゲイル
- if (flag & BF_SKILL && skill_get_pl(skill_num) == 4)
+ if (bool(flag & BF_SKILL)
+ && skill_get_pl(skill_num) == 4)
damage += damage * sc_data[SC_VIOLENTGALE].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element(bl) == 4))
+ else if (!bool(flag & BF_SKILL)
+ && (battle_get_attack_element(bl) == 4))
damage += damage * sc_data[SC_VIOLENTGALE].val4 / 100;
}
if (sc_data[SC_DELUGE].timer != -1)
{ // デリュージ
- if (flag & BF_SKILL && skill_get_pl(skill_num) == 1)
+ if (bool(flag & BF_SKILL)
+ && skill_get_pl(skill_num) == 1)
damage += damage * sc_data[SC_DELUGE].val4 / 100;
- else if (!(flag & BF_SKILL) && (battle_get_attack_element(bl) == 1))
+ else if (!bool(flag & BF_SKILL)
+ && (battle_get_attack_element(bl) == 1))
damage += damage * sc_data[SC_DELUGE].val4 / 100;
}
if (sc_data[SC_ENERGYCOAT].timer != -1 && damage > 0
- && flag & BF_WEAPON)
+ && bool(flag & BF_WEAPON))
{ // エナジーコート
if (sd)
{
@@ -1689,7 +1700,7 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
// キリエエレイソン
struct status_change *sc = &sc_data[SC_KYRIE];
sc->val2 -= damage;
- if (flag & BF_WEAPON)
+ if (bool(flag & BF_WEAPON))
{
if (sc->val2 >= 0)
damage = 0;
@@ -1707,14 +1718,14 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
damage = 0;
}
if (sc_data[SC_LANDPROTECTOR].timer != -1 && damage > 0
- && flag & BF_MAGIC)
+ && bool(flag & BF_MAGIC))
{
// ニューマ
damage = 0;
}
if (sc_data[SC_AUTOGUARD].timer != -1 && damage > 0
- && flag & BF_WEAPON)
+ && bool(flag & BF_WEAPON))
{
if (MRAND(100) < sc_data[SC_AUTOGUARD].val2)
{
@@ -1728,14 +1739,14 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
// -- moonsoul (chance to block attacks with new Lord Knight skill parrying)
//
if (sc_data[SC_PARRYING].timer != -1 && damage > 0
- && flag & BF_WEAPON)
+ && bool(flag & BF_WEAPON))
{
if (MRAND(100) < sc_data[SC_PARRYING].val2)
damage = 0;
}
// リジェクトソード
if (sc_data[SC_REJECTSWORD].timer != -1 && damage > 0
- && flag & BF_WEAPON
+ && bool(flag & BF_WEAPON)
&& // the logic was always broken, I've simplfied to what it
// was doing, it's not like this will be sticking around long
((src->type == BL_PC
@@ -1752,7 +1763,8 @@ int battle_calc_damage(struct block_list *src, struct block_list *bl,
}
}
- if (battle_config.skill_min_damage || flag & BF_MISC)
+ if (battle_config.skill_min_damage
+ || bool(flag & BF_MISC))
{
if (div_ < 255)
{
@@ -1943,7 +1955,9 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
struct Damage wd;
int damage, damage2 = 0, type, div_, blewcount =
skill_get_blewcount(skill_num, skill_lv);
- int flag, skill, ac_flag = 0, dmg_lv = 0;
+ BF flag;
+ int skill, ac_flag = 0;
+ ATK dmg_lv = ATK::ZERO;
int t_mode = 0, t_size = 1, s_race = 0, s_ele = 0;
eptr<struct status_change, StatusChange> sc_data, t_sc_data;
@@ -2009,7 +2023,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
|| battle_config.vit_penaly_type > 0)
target_count +=
battle_counttargeted(target, src,
- battle_config.agi_penaly_count_lv);
+ ATK(battle_config.agi_penaly_count_lv)); // FIXME
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
@@ -2349,7 +2363,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
int t_def;
target_count =
1 + battle_counttargeted(target, src,
- battle_config.vit_penaly_count_lv);
+ ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
@@ -2464,16 +2478,17 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
break;
}
}
- if (flag & BF_LONG)
+ if (bool(flag & BF_LONG))
cardfix = cardfix * (100 - tsd->long_attack_def_rate) / 100;
- if (flag & BF_SHORT)
+ if (bool(flag & BF_SHORT))
cardfix = cardfix * (100 - tsd->near_attack_def_rate) / 100;
damage = damage * cardfix / 100;
}
if (t_sc_data)
{
int cardfix = 100;
- if (t_sc_data[SC_DEFENDER].timer != -1 && flag & BF_LONG)
+ if (t_sc_data[SC_DEFENDER].timer != -1
+ && bool(flag & BF_LONG))
cardfix = cardfix * (100 - t_sc_data[SC_DEFENDER].val2) / 100;
if (cardfix != 100)
damage = damage * cardfix / 100;
@@ -2596,7 +2611,9 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
struct Damage wd;
int damage, damage2, damage4 = 0, type, div_, blewcount =
skill_get_blewcount(skill_num, skill_lv);
- int flag, skill, dmg_lv = 0;
+ BF flag;
+ int skill;
+ ATK dmg_lv = ATK::ZERO;
int t_mode = 0, t_race = 0, t_size = 1, s_race = 7, s_ele = 0;
eptr<struct status_change, StatusChange> sc_data, t_sc_data;
int atkmax_ = 0, atkmin_ = 0, s_ele_; //二刀流用
@@ -2671,7 +2688,8 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
// 回避率計算、回避判定は後で
flee = battle_get_flee(target);
if (battle_config.agi_penaly_type > 0 || battle_config.vit_penaly_type > 0) //AGI、VITペナルティ設定が有効
- target_count += battle_counttargeted(target, src, battle_config.agi_penaly_count_lv); //対象の数を算出
+ target_count += battle_counttargeted(target, src,
+ ATK(battle_config.agi_penaly_count_lv)); //対象の数を算出
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
@@ -2699,9 +2717,9 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
int dy = abs(src->y - target->y);
int malus_dist;
- target_distance = MAX(dx, dy);
+ target_distance = max(dx, dy);
malus_dist =
- MAX(0, target_distance - (skill_power(sd, AC_OWL) / 75));
+ max(0, target_distance - (skill_power(sd, AC_OWL) / 75));
hitrate -= (malus_dist * (malus_dist + 1));
}
@@ -2735,14 +2753,14 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
atkmin = atkmin_ = dex; //最低ATKはDEXで初期化?
sd->state.arrow_atk = 0; //arrow_atk初期化
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]])
+ if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
atkmin =
atkmin * (80 +
- sd->inventory_data[sd->equip_index[9]]->wlv * 20) / 100;
- if (sd->equip_index[8] >= 0 && sd->inventory_data[sd->equip_index[8]])
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->wlv * 20) / 100;
+ if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
atkmin_ =
atkmin_ * (80 +
- sd->inventory_data[sd->equip_index[8]]->wlv * 20) /
+ sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->wlv * 20) /
100;
if (sd->status.weapon == 11)
{ //武器が弓矢の場合
@@ -3468,7 +3486,7 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
int t_def;
target_count =
1 + battle_counttargeted(target, src,
- battle_config.vit_penaly_count_lv);
+ ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
@@ -3592,11 +3610,11 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
}
if (skill_num == CR_SHIELDBOOMERANG)
{
- if (sd->equip_index[8] >= 0)
+ if (sd->equip_index[EQUIP::SHIELD] >= 0)
{
- int index = sd->equip_index[8];
+ int index = sd->equip_index[EQUIP::SHIELD];
if (sd->inventory_data[index]
- && sd->inventory_data[index]->type == 5)
+ && sd->inventory_data[index]->type == ItemType::ARMOR)
{
damage += sd->inventory_data[index]->weight / 10;
damage +=
@@ -3607,11 +3625,11 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
}
if (skill_num == LK_SPIRALPIERCE)
{ /* スパイラルピアース */
- if (sd->equip_index[9] >= 0)
+ if (sd->equip_index[EQUIP::WEAPON] >= 0)
{ //重量で追加ダメージらしいのでシールドブーメランを参考に追加
- int index = sd->equip_index[9];
+ int index = sd->equip_index[EQUIP::WEAPON];
if (sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
+ && sd->inventory_data[index]->type == ItemType::WEAPON)
{
damage +=
(int)(double)(sd->inventory_data[index]->weight *
@@ -3787,9 +3805,9 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
break;
}
}
- if (flag & BF_LONG)
+ if (bool(flag & BF_LONG))
cardfix = cardfix * (100 - tsd->long_attack_def_rate) / 100; //遠距離攻撃はダメージ減少(ホルンCとか)
- if (flag & BF_SHORT)
+ if (bool(flag & BF_SHORT))
cardfix = cardfix * (100 - tsd->near_attack_def_rate) / 100; //近距離攻撃はダメージ減少(該当無し?)
damage = damage * cardfix / 100; //カード補正によるダメージ減少
damage2 = damage2 * cardfix / 100; //カード補正による左手ダメージ減少
@@ -3800,7 +3818,8 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
if (t_sc_data)
{
cardfix = 100;
- if (t_sc_data[SC_DEFENDER].timer != -1 && flag & BF_LONG) //ディフェンダー状態で遠距離攻撃
+ if (t_sc_data[SC_DEFENDER].timer != -1
+ && bool(flag & BF_LONG)) //ディフェンダー状態で遠距離攻撃
cardfix = cardfix * (100 - t_sc_data[SC_DEFENDER].val2) / 100; //ディフェンダーによる減衰
if (cardfix != 100)
{
@@ -4096,7 +4115,6 @@ struct Damage battle_calc_magic_attack(struct block_list *bl,
int matk1, matk2, damage = 0, div_ = 1, blewcount =
skill_get_blewcount(skill_num, skill_lv), rdamage = 0;
struct Damage md;
- int aflag;
int normalmagic_flag = 1;
int ele = 0, race = 7, t_ele = 0, t_race = 7, t_mode =
0, cardfix, t_class, i;
@@ -4130,7 +4148,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl,
if (target->type == BL_PC)
tsd = (struct map_session_data *) target;
- aflag = BF_MAGIC | BF_LONG | BF_SKILL;
+ BF aflag = BF_MAGIC | BF_LONG | BF_SKILL;
if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE)
{
@@ -4432,7 +4450,7 @@ struct Damage battle_calc_misc_attack(struct block_list *bl,
struct Damage md;
int damagefix = 1;
- int aflag = BF_MISC | BF_LONG | BF_SKILL;
+ BF aflag = BF_MISC | BF_LONG | BF_SKILL;
//return前の処理があるので情報出力部のみ変更
if (bl == NULL || target == NULL)
@@ -4574,7 +4592,7 @@ struct Damage battle_calc_misc_attack(struct block_list *bl,
* ダメージ計算一括処理用
*------------------------------------------
*/
-struct Damage battle_calc_attack(int attack_type,
+struct Damage battle_calc_attack(BF attack_type,
struct block_list *bl,
struct block_list *target, SkillID skill_num,
int skill_lv, int flag)
@@ -4596,7 +4614,7 @@ struct Damage battle_calc_attack(int attack_type,
default:
if (battle_config.error_log)
printf("battle_calc_attack: unknwon attack type ! %d\n",
- attack_type);
+ uint16_t(attack_type));
break;
}
return d;
@@ -4606,8 +4624,8 @@ struct Damage battle_calc_attack(int attack_type,
* 通常攻撃処理まとめ
*------------------------------------------
*/
-int battle_weapon_attack(struct block_list *src, struct block_list *target,
- unsigned int tick, int flag)
+ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
+ unsigned int tick, BCT flag)
{
struct map_session_data *sd = NULL;
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(src);
@@ -4616,30 +4634,30 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
int damage, rdamage = 0;
struct Damage wd;
- nullpo_ret(src);
- nullpo_ret(target);
+ nullpo_retr(ATK::ZERO, src);
+ nullpo_retr(ATK::ZERO, target);
if (src->type == BL_PC)
sd = (struct map_session_data *) src;
if (src->prev == NULL || target->prev == NULL)
- return 0;
+ return ATK::ZERO;
if (src->type == BL_PC && pc_isdead(sd))
- return 0;
+ return ATK::ZERO;
if (target->type == BL_PC
&& pc_isdead((struct map_session_data *) target))
- return 0;
+ return ATK::ZERO;
Opt1 *opt1 = battle_get_opt1(src);
if (opt1 != NULL && bool(*opt1))
{
battle_stopattack(src);
- return 0;
+ return ATK::ZERO;
}
if (sc_data && sc_data[SC_BLADESTOP].timer != -1)
{
battle_stopattack(src);
- return 0;
+ return ATK::ZERO;
}
race = battle_get_race(target);
@@ -4650,18 +4668,18 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
// 攻撃対象となりうるので攻撃
if (sd && sd->status.weapon == 11)
{
- if (sd->equip_index[10] >= 0)
+ if (sd->equip_index[EQUIP::ARROW] >= 0)
{
if (battle_config.arrow_decrement)
- pc_delitem(sd, sd->equip_index[10], 1, 0);
+ pc_delitem(sd, sd->equip_index[EQUIP::ARROW], 1, 0);
}
else
{
clif_arrow_fail(sd, 0);
- return 0;
+ return ATK::ZERO;
}
}
- if (flag & 0x8000)
+ if (flag & BCT_mid_x80)
{
if (sd && battle_config.pc_attack_direction_change)
sd->dir = sd->head_dir =
@@ -4671,7 +4689,7 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
((struct mob_data *) src)->dir =
map_calc_dir(src, target->x, target->y);
wd = battle_calc_weapon_attack(src, target, KN_AUTOCOUNTER,
- flag & 0xff, 0);
+ flag.lo, 0);
}
else
wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0);
@@ -4696,7 +4714,7 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
if ((damage = wd.damage + wd.damage2) > 0 && src != target)
{
- if (wd.flag & BF_SHORT)
+ if (bool(wd.flag & BF_SHORT))
{
if (target->type == BL_PC)
{
@@ -4718,7 +4736,7 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
rdamage = 1;
}
}
- else if (wd.flag & BF_LONG)
+ else if (bool(wd.flag & BF_LONG))
{
if (target->type == BL_PC)
{
@@ -4766,15 +4784,15 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
0, 1, 0, 0);
}
if (sd && sd->splash_range > 0 && (wd.damage > 0 || wd.damage2 > 0))
- skill_castend_damage_id(src, target, SkillID::ZERO, -1, tick, 0);
+ skill_castend_damage_id(src, target, SkillID::ZERO, -1, tick, BCT_ZERO);
map_freeblock_lock();
if (src->type == BL_PC)
{
- int weapon_index = sd->equip_index[9];
+ int weapon_index = sd->equip_index[EQUIP::WEAPON];
int weapon = 0;
if (sd->inventory_data[weapon_index]
- && sd->status.inventory[weapon_index].equip & 0x2)
+ && bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON))
weapon = sd->inventory_data[weapon_index]->nameid;
MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d",
@@ -4982,7 +5000,8 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
pc_heal(sd, 0, -sp);
}
}
- if (wd.flag & BF_WEAPON && src != target
+ if (bool(wd.flag & BF_WEAPON)
+ && src != target
&& (wd.damage > 0 || wd.damage2 > 0))
{
int hp = 0, sp = 0;
@@ -5018,8 +5037,8 @@ int battle_weapon_attack(struct block_list *src, struct block_list *target,
{
if (t_sc_data[SC_AUTOCOUNTER].val3 == src->id)
battle_weapon_attack(target, src, tick,
- 0x8000 |
- t_sc_data[SC_AUTOCOUNTER].val1);
+ BCT_mid_x80 |
+ t_sc_data[SC_AUTOCOUNTER].val1_bct());
skill_status_change_end(target, SC_AUTOCOUNTER, -1);
}
if (t_sc_data && t_sc_data[SC_BLADESTOP_WAIT].timer != -1)
@@ -5071,7 +5090,7 @@ int battle_check_undead(int race, int element)
*------------------------------------------
*/
int battle_check_target(struct block_list *src, struct block_list *target,
- int flag)
+ BCT flag)
{
int s_p, t_p;
struct block_list *ss = src;
@@ -5079,15 +5098,15 @@ int battle_check_target(struct block_list *src, struct block_list *target,
nullpo_ret(src);
nullpo_ret(target);
- if (flag & 0x40000)
+ if (flag & BCT_ENEMY)
{ // 反転フラグ
- int ret = battle_check_target(src, target, flag & 0x30000);
+ int ret = battle_check_target(src, target, flag & (BCT_PARTY | BCT_ALL));
if (ret != -1)
return !ret;
return -1;
}
- if (flag & 0x20000)
+ if (flag & BCT_ALL)
{
if (target->type == BL_MOB || target->type == BL_PC)
return 1;
@@ -5110,7 +5129,6 @@ int battle_check_target(struct block_list *src, struct block_list *target,
case 0x8f:
case 0x98:
return 0;
- break;
}
}
@@ -5187,7 +5205,7 @@ int battle_check_target(struct block_list *src, struct block_list *target,
t_p = battle_get_party_id(target);
- if (flag & 0x10000)
+ if (flag & BCT_PARTY)
{
if (s_p && t_p && s_p == t_p) // 同じパーティなら肯定(味方)
return 1;
@@ -5377,11 +5395,11 @@ int battle_config_read(const char *cfgName)
battle_config.agi_penaly_type = 0;
battle_config.agi_penaly_count = 3;
battle_config.agi_penaly_num = 0;
- battle_config.agi_penaly_count_lv = ATK_FLEE;
+ battle_config.agi_penaly_count_lv = int(ATK_FLEE); // FIXME
battle_config.vit_penaly_type = 0;
battle_config.vit_penaly_count = 3;
battle_config.vit_penaly_num = 0;
- battle_config.vit_penaly_count_lv = ATK_DEF;
+ battle_config.vit_penaly_count_lv = int(ATK_DEF); // FIXME
battle_config.player_defense_type = 0;
battle_config.monster_defense_type = 0;
battle_config.magic_defense_type = 0;
diff --git a/src/map/battle.hpp b/src/map/battle.hpp
index 25590ad..0c417d9 100644
--- a/src/map/battle.hpp
+++ b/src/map/battle.hpp
@@ -1,6 +1,8 @@
#ifndef BATTLE_HPP
#define BATTLE_HPP
+#include "battle.t.hpp"
+
#include "../common/utils.hpp"
#include "map.t.hpp"
@@ -13,8 +15,8 @@ struct Damage
int type, div_;
int amotion, dmotion;
int blewcount;
- int flag;
- int dmg_lv; //囲まれ減算計算用 0:スキル攻撃 ATK_LUCKY,ATK_FLEE,ATK_DEF
+ BF flag;
+ ATK dmg_lv;
};
// 属性表(読み込みはpc.c、battle_attr_fixで使用)
@@ -26,27 +28,13 @@ struct block_list;
// ダメージ計算
-struct Damage battle_calc_attack(int attack_type,
+struct Damage battle_calc_attack(BF attack_type,
struct block_list *bl, struct block_list *target,
SkillID skill_num, int skill_lv, int flag);
// 属性修正計算
int battle_attr_fix(int damage, int atk_elem, int def_elem);
-enum
-{ // 最終計算のフラグ
- BF_WEAPON = 0x0001,
- BF_MAGIC = 0x0002,
- BF_MISC = 0x0004,
- BF_SHORT = 0x0010,
- BF_LONG = 0x0040,
- BF_SKILL = 0x0100,
- BF_NORMAL = 0x0200,
- BF_WEAPONMASK = 0x000f,
- BF_RANGEMASK = 0x00f0,
- BF_SKILLMASK = 0x0f00,
-};
-
// 実際にHPを増減
int battle_damage(struct block_list *bl, struct block_list *target,
int damage, int flag);
@@ -58,8 +46,8 @@ int battle_stopattack(struct block_list *bl);
int battle_stopwalking(struct block_list *bl, int type);
// 通常攻撃処理まとめ
-int battle_weapon_attack(struct block_list *bl, struct block_list *target,
- unsigned int tick, int flag);
+ATK battle_weapon_attack(struct block_list *bl, struct block_list *target,
+ unsigned int tick, BCT flag);
int battle_is_unarmed(struct block_list *bl);
int battle_get_class(struct block_list *bl);
@@ -88,8 +76,7 @@ int battle_get_party_id(struct block_list *bl);
int battle_get_race(struct block_list *bl);
int battle_get_mode(struct block_list *bl);
int battle_get_mexp(struct block_list *bl);
-int battle_get_stat(int stat_id /* SP_VIT or similar */ ,
- struct block_list *bl);
+int battle_get_stat(SP stat_id, struct block_list *bl);
eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl);
short *battle_get_sc_count(struct block_list *bl);
@@ -98,19 +85,9 @@ Opt2 *battle_get_opt2(struct block_list *bl);
Opt3 *battle_get_opt3(struct block_list *bl);
Option *battle_get_option(struct block_list *bl);
-enum
-{
- BCT_NOENEMY = 0x00000,
- BCT_PARTY = 0x10000,
- BCT_ENEMY = 0x40000,
- BCT_NOPARTY = 0x50000,
- BCT_ALL = 0x20000,
- BCT_NOONE = 0x60000,
-};
-
int battle_check_undead(int race, int element);
int battle_check_target(struct block_list *src, struct block_list *target,
- int flag);
+ BCT flag);
int battle_check_range(struct block_list *src, struct block_list *bl,
int range);
diff --git a/src/map/battle.t.hpp b/src/map/battle.t.hpp
new file mode 100644
index 0000000..b0222a2
--- /dev/null
+++ b/src/map/battle.t.hpp
@@ -0,0 +1,96 @@
+#ifndef BATTLE_T_HPP
+#define BATTLE_T_HPP
+
+#include "../common/utils.hpp"
+
+namespace e
+{
+enum class BF : uint16_t
+{
+ ZERO = 0x0000,
+ NEGATIVE_1 = 0xffff,
+
+ WEAPON = 0x0001,
+#define BF_WEAPON BF::WEAPON
+ MAGIC = 0x0002,
+#define BF_MAGIC BF::MAGIC
+ MISC = 0x0004,
+#define BF_MISC BF::MISC
+ SHORT = 0x0010,
+#define BF_SHORT BF::SHORT
+ LONG = 0x0040,
+#define BF_LONG BF::LONG
+ SKILL = 0x0100,
+#define BF_SKILL BF::SKILL
+ NORMAL = 0x0200,
+#define BF_NORMAL BF::NORMAL
+ WEAPONMASK = 0x000f,
+#define BF_WEAPONMASK BF::WEAPONMASK
+ RANGEMASK = 0x00f0,
+#define BF_RANGEMASK BF::RANGEMASK
+ SKILLMASK = 0x0f00,
+#define BF_SKILLMASK BF::SKILLMASK
+};
+ENUM_BITWISE_OPERATORS(BF)
+}
+using e::BF;
+
+struct BCT
+{
+ // former representation:
+ uint8_t lo; // 0x 00 00 00 ff
+ uint8_t mid; // 0x 00 00 ff 00
+ uint8_t classic:4; // 0x 00 0f 00 00
+ uint8_t level:4; // 0x 00 f0 00 00
+ uint8_t unused; // 0x ff 00 00 00
+
+ operator bool() { return lo || mid || classic || level || unused; }
+};
+
+constexpr
+BCT operator & (BCT l, BCT r) { return {uint8_t(l.lo & r.lo), uint8_t(l.mid & r.mid), uint8_t(l.classic & r.classic), uint8_t(l.level & r.level), uint8_t(l.unused & r.unused) }; }
+constexpr
+BCT operator | (BCT l, BCT r) { return {uint8_t(l.lo | r.lo), uint8_t(l.mid | r.mid), uint8_t(l.classic | r.classic), uint8_t(l.level | r.level), uint8_t(l.unused | r.unused) }; }
+constexpr
+BCT operator ^ (BCT l, BCT r) { return {uint8_t(l.lo ^ r.lo), uint8_t(l.mid ^ r.mid), uint8_t(l.classic ^ r.classic), uint8_t(l.level ^ r.level), uint8_t(l.unused ^ r.unused) }; }
+inline
+BCT& operator &= (BCT& l, BCT r) { return l = l & r; }
+inline
+BCT& operator |= (BCT& l, BCT r) { return l = l & r; }
+inline
+BCT& operator ^= (BCT& l, BCT r) { return l = l & r; }
+// BCT operator ~(BCT r);
+
+constexpr
+bool operator == (BCT l, BCT r) { return l.lo == r.lo && l.mid == r.mid && l.classic == r.classic && l.level == r.level && l.unused == r.unused; };
+constexpr
+bool operator != (BCT l, BCT r) { return !(l == r); }
+
+constexpr
+BCT BCT_NOENEMY = {0x00, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_ZERO = BCT_NOENEMY;
+constexpr
+BCT BCT_PARTY = {0x00, 0x00, 0x1, 0x0, 0x00};
+constexpr
+BCT BCT_ENEMY = {0x00, 0x00, 0x4, 0x0, 0x00};
+constexpr
+BCT BCT_NOPARTY = {0x00, 0x00, 0x5, 0x0, 0x00};
+constexpr
+BCT BCT_ALL = {0x00, 0x00, 0x2, 0x0, 0x00};
+constexpr
+BCT BCT_NOONE = {0x00, 0x00, 0x6, 0x0, 0x00};
+
+constexpr
+BCT BCT_lo_x01 = {0x01, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_lo_x02 = {0x02, 0x00, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_mid_x05 = {0x00, 0x05, 0x0, 0x0, 0x00};
+constexpr
+BCT BCT_mid_x80 = {0x00, 0x80, 0x0, 0x0, 0x00};
+
+constexpr
+BCT BCT_highnib = {0x00, 0x00, 0x0, 0xf, 0x00};
+
+#endif // BATTLE_T_HPP
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index c387c91..c7b8554 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -671,8 +671,8 @@ int chrif_changedsex(int fd)
for (i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid
- && sd->status.inventory[i].equip)
- pc_unequipitem((struct map_session_data *) sd, i, 0);
+ && bool(sd->status.inventory[i].equip))
+ pc_unequipitem((struct map_session_data *) sd, i, CalcStatus::NOW);
}
// reset skill of some job
if (s_class.job == 19 || s_class.job == 4020
@@ -972,7 +972,7 @@ void ladmin_itemfrob_fix_item(int source, int dest, struct item *item)
if (item && item->nameid == source)
{
item->nameid = dest;
- item->equip = 0;
+ item->equip = EPOS::ZERO;
}
}
@@ -1013,8 +1013,8 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id)
if (item && item->nameid == source_id)
{
item->nameid = dest_id;
- if (item->equip)
- pc_unequipitem(pc, j, 0);
+ if (bool(item->equip))
+ pc_unequipitem(pc, j, CalcStatus::NOW);
item->nameid = dest_id;
}
}
@@ -1056,7 +1056,7 @@ void ladmin_itemfrob(int fd)
struct block_list *bl = (struct block_list *) map_get_first_session();
// flooritems
- map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), 0 /* any object */);
+ map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL_NUL /* any object */);
// player characters (and, hopefully, mobs)
while (bl->next)
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index 3844eb9..cf47d2f 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -90,24 +90,41 @@ const int packet_len_table[0x220] = {
};
// local define
-enum
+enum class SendWho
{
ALL_CLIENT,
+#define ALL_CLIENT SendWho::ALL_CLIENT
ALL_SAMEMAP,
+#define ALL_SAMEMAP SendWho::ALL_SAMEMAP
AREA,
+#define AREA SendWho::AREA
AREA_WOS,
+#define AREA_WOS SendWho::AREA_WOS
AREA_WOC,
+#define AREA_WOC SendWho::AREA_WOC
AREA_WOSC,
+#define AREA_WOSC SendWho::AREA_WOSC
AREA_CHAT_WOC,
- CHAT,
+#define AREA_CHAT_WOC SendWho::AREA_CHAT_WOC
+ // temporary rename to avoid collision with BL::CHAT_
+ CHAT_,
+#define CHAT_ SendWho::CHAT_
CHAT_WOS,
+#define CHAT_WOS SendWho::CHAT_WOS
PARTY,
+#define PARTY SendWho::PARTY
PARTY_WOS,
+#define PARTY_WOS SendWho::PARTY_WOS
PARTY_SAMEMAP,
+#define PARTY_SAMEMAP SendWho::PARTY_SAMEMAP
PARTY_SAMEMAP_WOS,
+#define PARTY_SAMEMAP_WOS SendWho::PARTY_SAMEMAP_WOS
PARTY_AREA,
+#define PARTY_AREA SendWho::PARTY_AREA
PARTY_AREA_WOS,
+#define PARTY_AREA_WOS SendWho::PARTY_AREA_WOS
SELF,
+#define SELF SendWho::SELF
};
#define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+= (pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; }
@@ -126,7 +143,7 @@ int map_fd;
char talkie_mes[80];
static
-int clif_changelook_towards(struct block_list *bl, int type, int val,
+int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
struct map_session_data *dstsd);
/*==========================================
@@ -226,7 +243,7 @@ char *clif_validate_chat(struct map_session_data *sd, int type,
*/
static
void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
- struct block_list *src_bl, int type)
+ struct block_list *src_bl, SendWho type)
{
nullpo_retv(bl);
struct map_session_data *sd = (struct map_session_data *) bl;
@@ -285,7 +302,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
*------------------------------------------
*/
static
-int clif_send(const uint8_t *buf, int len, struct block_list *bl, int type)
+int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
{
int i;
struct map_session_data *sd;
@@ -365,7 +382,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, int type)
bl->m, bl->x - (AREA_SIZE), bl->y - (AREA_SIZE),
bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL_PC);
break;
- case CHAT:
+ case CHAT_:
case CHAT_WOS:
cd = (struct chat_data *) bl;
if (bl->type == BL_PC)
@@ -740,26 +757,26 @@ int clif_set0078(struct map_session_data *sd, unsigned char *buf)
WBUFB(buf, 18) = sd->attack_spell_look_override;
else
{
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]]
+ if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]
&& sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
WBUFW(buf, 18) =
- sd->inventory_data[sd->equip_index[9]]->view_id;
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
WBUFW(buf, 18) =
- sd->status.inventory[sd->equip_index[9]].nameid;
+ sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
WBUFW(buf, 18) = 0;
}
- if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]] && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]] && sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
- WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[8]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
+ WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
- WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[8]].nameid;
+ WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
WBUFW(buf, 20) = 0;
@@ -826,23 +843,23 @@ int clif_set007b(struct map_session_data *sd, unsigned char *buf)
WBUFW(buf, 12) = uint16_t(sd->status.option);
WBUFW(buf, 14) = sd->view_class;
WBUFW(buf, 16) = sd->status.hair;
- if (sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]]
+ if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]
&& sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
- WBUFW(buf, 18) = sd->inventory_data[sd->equip_index[9]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
+ WBUFW(buf, 18) = sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
- WBUFW(buf, 18) = sd->status.inventory[sd->equip_index[9]].nameid;
+ WBUFW(buf, 18) = sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
WBUFW(buf, 18) = 0;
- if (sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]] && sd->view_class != 22)
+ if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]] && sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
- WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[8]]->view_id;
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
+ WBUFW(buf, 20) = sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
- WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[8]].nameid;
+ WBUFW(buf, 20) = sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
WBUFW(buf, 20) = 0;
@@ -989,21 +1006,22 @@ int clif_npc0078(struct npc_data *nd, unsigned char *buf)
/* These indices are derived from equip_pos in pc.c and some guesswork */
static
-int equip_points[LOOK_LAST + 1] = {
- -1, /* 0: base */
- -1, /* 1: hair */
- 9, /* 2: weapon */
- 4, /* 3: head botom -- leg armour */
- 6, /* 4: head top -- hat */
- 5, /* 5: head mid -- torso armour */
- -1, /* 6: hair colour */
- -1, /* 6: clothes colour */
- 8, /* 6: shield */
- 2, /* 9: shoes */
- 3, /* gloves */
- 1, /* cape */
- 7, /* misc1 */
- 0, /* misc2 */
+earray<EQUIP, LOOK, LOOK::COUNT> equip_points =
+{
+ EQUIP::NONE, // base
+ EQUIP::NONE, // hair
+ EQUIP::WEAPON, // weapon
+ EQUIP::LEGS, // head botom -- leg armour
+ EQUIP::HAT, // head top -- hat
+ EQUIP::TORSO, // head mid -- torso armour
+ EQUIP::NONE, // hair colour
+ EQUIP::NONE, // clothes colour
+ EQUIP::SHIELD, // shield
+ EQUIP::SHOES, // shoes
+ EQUIP::GLOVES, // gloves
+ EQUIP::CAPE, // cape
+ EQUIP::MISC1, // misc1
+ EQUIP::MISC2, // misc2
};
/*==========================================
@@ -1378,7 +1396,7 @@ int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
if (!id->flag.value_notdc)
val = pc_modifybuyvalue(sd, val);
WFIFOL(fd, 8 + i * 11) = val;
- WFIFOB(fd, 12 + i * 11) = id->type;
+ WFIFOB(fd, 12 + i * 11) = uint8_t(id->type);
if (id->view_id > 0)
WFIFOW(fd, 13 + i * 11) = id->view_id;
else
@@ -1582,7 +1600,7 @@ int clif_cutin(struct map_session_data *sd, const char *image, int type)
*
*------------------------------------------
*/
-int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
+int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail)
{
int fd, j;
unsigned char *buf;
@@ -1591,7 +1609,7 @@ int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
fd = sd->fd;
buf = WFIFOP(fd, 0);
- if (fail)
+ if (fail != PickupFail::OKAY)
{
WBUFW(buf, 0) = 0xa0;
WBUFW(buf, 2) = n + 2;
@@ -1606,7 +1624,7 @@ int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
WBUFW(buf, 17) = 0;
WBUFW(buf, 19) = 0;
WBUFB(buf, 21) = 0;
- WBUFB(buf, 22) = fail;
+ WBUFB(buf, 22) = uint8_t(fail);
}
else
{
@@ -1659,11 +1677,11 @@ int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
else
WBUFW(buf, 17) = sd->status.inventory[n].card[3];
}
- WBUFW(buf, 19) = pc_equippoint(sd, n);
- WBUFB(buf, 21) =
- (sd->inventory_data[n]->type ==
- 7) ? 4 : sd->inventory_data[n]->type;
- WBUFB(buf, 22) = fail;
+ WBUFW(buf, 19) = uint16_t(pc_equippoint(sd, n));
+ WBUFB(buf, 21) = uint8_t(sd->inventory_data[n]->type == ItemType::_7
+ ? ItemType::WEAPON
+ : sd->inventory_data[n]->type);
+ WBUFB(buf, 22) = uint8_t(fail);
}
WFIFOSET(fd, packet_len_table[0xa0]);
@@ -1715,17 +1733,17 @@ int clif_itemlist(struct map_session_data *sd)
WBUFW(buf, n * 18 + 6) = sd->inventory_data[i]->view_id;
else
WBUFW(buf, n * 18 + 6) = sd->status.inventory[i].nameid;
- WBUFB(buf, n * 18 + 8) = sd->inventory_data[i]->type;
+ WBUFB(buf, n * 18 + 8) = uint8_t(sd->inventory_data[i]->type);
WBUFB(buf, n * 18 + 9) = sd->status.inventory[i].identify;
WBUFW(buf, n * 18 + 10) = sd->status.inventory[i].amount;
- if (sd->inventory_data[i]->equip == 0x8000)
+ if (sd->inventory_data[i]->equip == EPOS::ARROW)
{
- WBUFW(buf, n * 18 + 12) = 0x8000;
- if (sd->status.inventory[i].equip)
+ WBUFW(buf, n * 18 + 12) = uint16_t(EPOS::ARROW);
+ if (bool(sd->status.inventory[i].equip))
arrow = i; // ついでに矢装備チェック
}
else
- WBUFW(buf, n * 18 + 12) = 0;
+ WBUFW(buf, n * 18 + 12) = uint16_t(EPOS::ZERO);
WBUFW(buf, n * 18 + 14) = sd->status.inventory[i].card[0];
WBUFW(buf, n * 18 + 16) = sd->status.inventory[i].card[1];
WBUFW(buf, n * 18 + 18) = sd->status.inventory[i].card[2];
@@ -1767,12 +1785,13 @@ int clif_equiplist(struct map_session_data *sd)
WBUFW(buf, n * 20 + 6) = sd->inventory_data[i]->view_id;
else
WBUFW(buf, n * 20 + 6) = sd->status.inventory[i].nameid;
- WBUFB(buf, n * 20 + 8) =
- (sd->inventory_data[i]->type ==
- 7) ? 4 : sd->inventory_data[i]->type;
+ WBUFB(buf, n * 20 + 8) = uint8_t(
+ sd->inventory_data[i]->type == ItemType::_7
+ ? ItemType::WEAPON
+ : sd->inventory_data[i]->type);
WBUFB(buf, n * 20 + 9) = sd->status.inventory[i].identify;
- WBUFW(buf, n * 20 + 10) = pc_equippoint(sd, i);
- WBUFW(buf, n * 20 + 12) = sd->status.inventory[i].equip;
+ WBUFW(buf, n * 20 + 10) = uint16_t(pc_equippoint(sd, i));
+ WBUFW(buf, n * 20 + 12) = uint16_t(sd->status.inventory[i].equip);
if (sd->status.inventory[i].broken == 1)
WBUFB(buf, n * 20 + 14) = 1; // is weapon broken [Valaris]
else
@@ -1849,7 +1868,7 @@ int clif_storageitemlist(struct map_session_data *sd, struct storage *stor)
WBUFW(buf, n * 18 + 6) = id->view_id;
else
WBUFW(buf, n * 18 + 6) = stor->storage_[i].nameid;
- WBUFB(buf, n * 18 + 8) = id->type;;
+ WBUFB(buf, n * 18 + 8) = uint8_t(id->type);
WBUFB(buf, n * 18 + 9) = stor->storage_[i].identify;
WBUFW(buf, n * 18 + 10) = stor->storage_[i].amount;
WBUFW(buf, n * 18 + 12) = 0;
@@ -1895,10 +1914,10 @@ int clif_storageequiplist(struct map_session_data *sd, struct storage *stor)
WBUFW(buf, n * 20 + 6) = id->view_id;
else
WBUFW(buf, n * 20 + 6) = stor->storage_[i].nameid;
- WBUFB(buf, n * 20 + 8) = id->type;
+ WBUFB(buf, n * 20 + 8) = uint8_t(id->type);
WBUFB(buf, n * 20 + 9) = stor->storage_[i].identify;
- WBUFW(buf, n * 20 + 10) = id->equip;
- WBUFW(buf, n * 20 + 12) = stor->storage_[i].equip;
+ WBUFW(buf, n * 20 + 10) = uint16_t(id->equip);
+ WBUFW(buf, n * 20 + 12) = uint16_t(stor->storage_[i].equip);
if (stor->storage_[i].broken == 1)
WBUFB(buf, n * 20 + 14) = 1; //is weapon broken [Valaris]
else
@@ -1951,7 +1970,7 @@ int clif_storageequiplist(struct map_session_data *sd, struct storage *stor)
* 表示専用数字はこの中で計算して送る
*------------------------------------------
*/
-int clif_updatestatus(struct map_session_data *sd, int type)
+int clif_updatestatus(struct map_session_data *sd, SP type)
{
int fd, len = 8;
@@ -1960,14 +1979,15 @@ int clif_updatestatus(struct map_session_data *sd, int type)
fd = sd->fd;
WFIFOW(fd, 0) = 0xb0;
- WFIFOW(fd, 2) = type;
+ WFIFOW(fd, 2) = uint16_t(type);
switch (type)
{
// 00b0
case SP_WEIGHT:
pc_checkweighticon(sd);
+ // is this because pc_checkweighticon can send other packets?
WFIFOW(fd, 0) = 0xb0;
- WFIFOW(fd, 2) = type;
+ WFIFOW(fd, 2) = uint16_t(type);
WFIFOL(fd, 4) = sd->weight;
break;
case SP_MAXWEIGHT:
@@ -2072,8 +2092,7 @@ int clif_updatestatus(struct map_session_data *sd, int type)
case SP_UDEX:
case SP_ULUK:
WFIFOW(fd, 0) = 0xbe;
- WFIFOB(fd, 4) =
- pc_need_status_point(sd, type - SP_USTR + SP_STR);
+ WFIFOB(fd, 4) = pc_need_status_point(sd, usp_to_sp(type));
len = 5;
break;
@@ -2087,46 +2106,19 @@ int clif_updatestatus(struct map_session_data *sd, int type)
// 0141 終了
case SP_STR:
- WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.str;
- WFIFOL(fd, 10) = sd->paramb[0] + sd->parame[0];
- len = 14;
- break;
case SP_AGI:
- WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.agi;
- WFIFOL(fd, 10) = sd->paramb[1] + sd->parame[1];
- len = 14;
- break;
case SP_VIT:
- WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.vit;
- WFIFOL(fd, 10) = sd->paramb[2] + sd->parame[2];
- len = 14;
- break;
case SP_INT:
- WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.int_;
- WFIFOL(fd, 10) = sd->paramb[3] + sd->parame[3];
- len = 14;
- break;
case SP_DEX:
- WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.dex;
- WFIFOL(fd, 10) = sd->paramb[4] + sd->parame[4];
- len = 14;
- break;
case SP_LUK:
+ {
+ ATTR attr = sp_to_attr(type);
WFIFOW(fd, 0) = 0x141;
- WFIFOL(fd, 2) = type;
- WFIFOL(fd, 6) = sd->status.luk;
- WFIFOL(fd, 10) = sd->paramb[5] + sd->parame[5];
+ WFIFOL(fd, 2) = uint16_t(type);
+ WFIFOL(fd, 6) = sd->status.attrs[attr];
+ WFIFOL(fd, 10) = sd->paramb[attr] + sd->parame[attr];
len = 14;
+ }
break;
case SP_GM:
@@ -2135,7 +2127,8 @@ int clif_updatestatus(struct map_session_data *sd, int type)
default:
if (battle_config.error_log)
- printf("clif_updatestatus : make %d routine\n", type);
+ printf("clif_updatestatus : make %d routine\n",
+ uint16_t(type));
return 1;
}
WFIFOSET(fd, len);
@@ -2147,12 +2140,12 @@ int clif_updatestatus(struct map_session_data *sd, int type)
*
*------------------------------------------
*/
-int clif_changelook(struct block_list *bl, int type, int val)
+int clif_changelook(struct block_list *bl, LOOK type, int val)
{
return clif_changelook_towards(bl, type, val, NULL);
}
-int clif_changelook_towards(struct block_list *bl, int type, int val,
+int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
struct map_session_data *dstsd)
{
unsigned char rbuf[32];
@@ -2177,9 +2170,9 @@ int clif_changelook_towards(struct block_list *bl, int type, int val,
WBUFL(buf, 2) = bl->id;
if (type >= LOOK_SHOES)
{
- int equip_point = equip_points[type];
+ EQUIP equip_point = equip_points[type];
- WBUFB(buf, 6) = type;
+ WBUFB(buf, 6) = uint16_t(type);
if (sd->equip_index[equip_point] >= 0
&& sd->inventory_data[sd->equip_index[equip_point]])
{
@@ -2204,31 +2197,31 @@ int clif_changelook_towards(struct block_list *bl, int type, int val,
WBUFW(buf, 7) = sd->attack_spell_look_override;
else
{
- if (sd->equip_index[9] >= 0
- && sd->inventory_data[sd->equip_index[9]]
+ if (sd->equip_index[EQUIP::WEAPON] >= 0
+ && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]
&& sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[9]]->view_id > 0)
+ if (sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id > 0)
WBUFW(buf, 7) =
- sd->inventory_data[sd->equip_index[9]]->view_id;
+ sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->view_id;
else
WBUFW(buf, 7) =
- sd->status.inventory[sd->equip_index[9]].nameid;
+ sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].nameid;
}
else
WBUFW(buf, 7) = 0;
}
- if (sd->equip_index[8] >= 0
- && sd->equip_index[8] != sd->equip_index[9]
- && sd->inventory_data[sd->equip_index[8]]
+ if (sd->equip_index[EQUIP::SHIELD] >= 0
+ && sd->equip_index[EQUIP::SHIELD] != sd->equip_index[EQUIP::WEAPON]
+ && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]
&& sd->view_class != 22)
{
- if (sd->inventory_data[sd->equip_index[8]]->view_id > 0)
+ if (sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id > 0)
WBUFW(buf, 9) =
- sd->inventory_data[sd->equip_index[8]]->view_id;
+ sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->view_id;
else
WBUFW(buf, 9) =
- sd->status.inventory[sd->equip_index[8]].nameid;
+ sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].nameid;
}
else
WBUFW(buf, 9) = 0;
@@ -2242,7 +2235,7 @@ int clif_changelook_towards(struct block_list *bl, int type, int val,
{
WBUFW(buf, 0) = 0x1d7;
WBUFL(buf, 2) = bl->id;
- WBUFB(buf, 6) = type;
+ WBUFB(buf, 6) = uint8_t(type);
WBUFW(buf, 7) = val;
WBUFW(buf, 9) = 0;
if (dstsd)
@@ -2270,17 +2263,18 @@ int clif_initialstatus(struct map_session_data *sd)
WBUFW(buf, 0) = 0xbd;
WBUFW(buf, 2) = sd->status.status_point;
- WBUFB(buf, 4) = (sd->status.str > 255) ? 255 : sd->status.str;
+
+ WBUFB(buf, 4) = min(sd->status.attrs[ATTR::STR], 255);
WBUFB(buf, 5) = pc_need_status_point(sd, SP_STR);
- WBUFB(buf, 6) = (sd->status.agi > 255) ? 255 : sd->status.agi;
+ WBUFB(buf, 6) = min(sd->status.attrs[ATTR::AGI], 255);
WBUFB(buf, 7) = pc_need_status_point(sd, SP_AGI);
- WBUFB(buf, 8) = (sd->status.vit > 255) ? 255 : sd->status.vit;
+ WBUFB(buf, 8) = min(sd->status.attrs[ATTR::VIT], 255);
WBUFB(buf, 9) = pc_need_status_point(sd, SP_VIT);
- WBUFB(buf, 10) = (sd->status.int_ > 255) ? 255 : sd->status.int_;
+ WBUFB(buf, 10) = min(sd->status.attrs[ATTR::INT], 255);
WBUFB(buf, 11) = pc_need_status_point(sd, SP_INT);
- WBUFB(buf, 12) = (sd->status.dex > 255) ? 255 : sd->status.dex;
+ WBUFB(buf, 12) = min(sd->status.attrs[ATTR::DEX], 255);
WBUFB(buf, 13) = pc_need_status_point(sd, SP_DEX);
- WBUFB(buf, 14) = (sd->status.luk > 255) ? 255 : sd->status.luk;
+ WBUFB(buf, 14) = min(sd->status.attrs[ATTR::LUK], 255);
WBUFB(buf, 15) = pc_need_status_point(sd, SP_LUK);
WBUFW(buf, 16) = sd->base_atk + sd->watk;
@@ -2358,7 +2352,7 @@ int clif_arrow_fail(struct map_session_data *sd, int type)
*
*------------------------------------------
*/
-int clif_statusupack(struct map_session_data *sd, int type, int ok, int val)
+int clif_statusupack(struct map_session_data *sd, SP type, int ok, int val)
{
int fd;
@@ -2366,7 +2360,7 @@ int clif_statusupack(struct map_session_data *sd, int type, int ok, int val)
fd = sd->fd;
WFIFOW(fd, 0) = 0xbc;
- WFIFOW(fd, 2) = type;
+ WFIFOW(fd, 2) = uint16_t(type);
WFIFOB(fd, 4) = ok;
WFIFOB(fd, 5) = val;
WFIFOSET(fd, packet_len_table[0xbc]);
@@ -2378,7 +2372,7 @@ int clif_statusupack(struct map_session_data *sd, int type, int ok, int val)
*
*------------------------------------------
*/
-int clif_equipitemack(struct map_session_data *sd, int n, int pos, int ok)
+int clif_equipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
{
int fd;
@@ -2387,7 +2381,7 @@ int clif_equipitemack(struct map_session_data *sd, int n, int pos, int ok)
fd = sd->fd;
WFIFOW(fd, 0) = 0xaa;
WFIFOW(fd, 2) = n + 2;
- WFIFOW(fd, 4) = pos;
+ WFIFOW(fd, 4) = uint16_t(pos);
WFIFOB(fd, 6) = ok;
WFIFOSET(fd, packet_len_table[0xaa]);
@@ -2398,7 +2392,7 @@ int clif_equipitemack(struct map_session_data *sd, int n, int pos, int ok)
*
*------------------------------------------
*/
-int clif_unequipitemack(struct map_session_data *sd, int n, int pos, int ok)
+int clif_unequipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
{
int fd;
@@ -2407,7 +2401,7 @@ int clif_unequipitemack(struct map_session_data *sd, int n, int pos, int ok)
fd = sd->fd;
WFIFOW(fd, 0) = 0xac;
WFIFOW(fd, 2) = n + 2;
- WFIFOW(fd, 4) = pos;
+ WFIFOW(fd, 4) = uint16_t(pos);
WFIFOB(fd, 6) = ok;
WFIFOSET(fd, packet_len_table[0xac]);
@@ -2842,9 +2836,7 @@ int clif_storageclose(struct map_session_data *sd)
void clif_changelook_accessories(struct block_list *bl,
struct map_session_data *dest)
{
- int i;
-
- for (i = LOOK_SHOES; i <= LOOK_LAST; i++)
+ for (LOOK i = LOOK_SHOES; i < LOOK::COUNT; i = LOOK(uint8_t(i) + 1))
clif_changelook_towards(bl, i, 0, dest);
}
@@ -3107,7 +3099,8 @@ void clif_getareachar(struct block_list *bl, struct map_session_data *sd)
break;
default:
if (battle_config.error_log)
- printf("get area char ??? %d\n", bl->type);
+ printf("get area char ??? %d\n",
+ uint8_t(bl->type));
break;
}
}
@@ -3279,10 +3272,9 @@ int clif_skillinfoblock(struct map_session_data *sd)
// [Fate] Version 1 and later don't crash because of bad skill IDs anymore
WFIFOW(fd, len) = uint16_t(id);
WFIFOW(fd, len + 2) = skill_get_inf(id);
- WFIFOW(fd, len + 4) =
- skill_db[i].poolflags | (sd->status.
- skill[i].flags &
- (SKILL_POOL_ACTIVATED));
+ WFIFOW(fd, len + 4) = uint16_t(
+ skill_db[i].poolflags
+ | (sd->status.skill[i].flags & SKILL_POOL_ACTIVATED));
WFIFOW(fd, len + 6) = sd->status.skill[i].lv;
WFIFOW(fd, len + 8) = skill_get_sp(id, sd->status.skill[i].lv);
range = skill_get_range(id, sd->status.skill[i].lv);
@@ -4144,13 +4136,13 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
skill_status_change_start(&sd->bl, SC_ENDURE, 10, 1, 0, 0, 0, 0);
for (i = 0; i < MAX_INVENTORY; i++)
{
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& sd->status.inventory[i].broken == 1)
skill_status_change_start(&sd->bl, SC_BROKNWEAPON, 0, 0, 0, 0, 0,
0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& sd->status.inventory[i].broken == 1)
skill_status_change_start(&sd->bl, SC_BROKNARMOR, 0, 0, 0, 0, 0,
0);
@@ -4160,7 +4152,7 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
map_foreachinarea(std::bind(clif_getareachar, ph::_1, sd), sd->bl.m, sd->bl.x - AREA_SIZE,
sd->bl.y - AREA_SIZE, sd->bl.x + AREA_SIZE,
- sd->bl.y + AREA_SIZE, 0);
+ sd->bl.y + AREA_SIZE, BL_NUL);
}
/*==========================================
@@ -4372,7 +4364,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
default:
if (battle_config.error_log)
printf("clif_parse_GetCharNameRequest : bad type %d (%d)\n",
- bl->type, account_id);
+ uint8_t(bl->type), account_id);
break;
}
}
@@ -4903,9 +4895,12 @@ void clif_parse_EquipItem(int fd, struct map_session_data *sd)
//ペット用装備であるかないか
if (sd->inventory_data[index])
{
- if (sd->inventory_data[index]->type == 10)
- RFIFOW(fd, 4) = 0x8000; // 矢を無理やり装備できるように(−−;
- pc_equipitem(sd, index, RFIFOW(fd, 4));
+ if (sd->inventory_data[index]->type == ItemType::ARROW)
+ // 矢を無理やり装備できるように(−−;
+ RFIFOW(fd, 4) = uint16_t(EPOS::ARROW);
+
+ // Note: the EPOS argument to pc_equipitem is actually ignored
+ pc_equipitem(sd, index, EPOS(RFIFOW(fd, 4)));
}
}
@@ -4937,7 +4932,7 @@ void clif_parse_UnequipItem(int fd, struct map_session_data *sd)
if (sd->npc_id != 0
|| sd->opt1 != Opt1::ZERO)
return;
- pc_unequipitem(sd, index, 0);
+ pc_unequipitem(sd, index, CalcStatus::NOW);
}
/*==========================================
@@ -5098,7 +5093,7 @@ void clif_parse_StopAttack(int, struct map_session_data *sd)
static
void clif_parse_StatusUp(int fd, struct map_session_data *sd)
{
- pc_statusup(sd, RFIFOW(fd, 2));
+ pc_statusup(sd, SP(RFIFOW(fd, 2)));
}
/*==========================================
@@ -5604,7 +5599,7 @@ void clif_parse_GMKick(int fd, struct map_session_data *sd)
else if (target->type == BL_MOB)
{
struct mob_data *md = (struct mob_data *) target;
- sd->state.attack_type = 0;
+ sd->state.attack_type = BF::ZERO;
mob_damage(&sd->bl, md, md->hp, 2);
}
else
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index fd8c9b1..2158d3a 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -6,6 +6,8 @@
#include <sys/socket.h>
#include <sys/types.h>
+#include "pc.t.hpp"
+
#include "map.hpp"
#include "storage.hpp"
@@ -50,18 +52,18 @@ int clif_scriptinput(struct map_session_data *, int); //self
int clif_scriptinputstr(struct map_session_data *sd, int npcid); // self
int clif_cutin(struct map_session_data *, const char *, int); //self
int clif_viewpoint(struct map_session_data *, int, int, int, int, int, int); //self
-int clif_additem(struct map_session_data *, int, int, int); //self
+int clif_additem(struct map_session_data *, int, int, PickupFail); //self
int clif_delitem(struct map_session_data *, int, int); //self
-int clif_updatestatus(struct map_session_data *, int); //self
+int clif_updatestatus(struct map_session_data *, SP); //self
int clif_damage(struct block_list *, struct block_list *, unsigned int, int, int, int, int, int, int); // area
#define clif_takeitem(src,dst) clif_damage(src,dst,0,0,0,0,0,1,0)
-int clif_changelook(struct block_list *, int, int); // area
+int clif_changelook(struct block_list *, LOOK, int); // area
void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc.
int clif_arrowequip(struct map_session_data *sd, int val); //self
int clif_arrow_fail(struct map_session_data *sd, int type); //self
-int clif_statusupack(struct map_session_data *, int, int, int); // self
-int clif_equipitemack(struct map_session_data *, int, int, int); // self
-int clif_unequipitemack(struct map_session_data *, int, int, int); // self
+int clif_statusupack(struct map_session_data *, SP, int, int); // self
+int clif_equipitemack(struct map_session_data *, int, EPOS, int); // self
+int clif_unequipitemack(struct map_session_data *, int, EPOS, int); // self
int clif_misceffect(struct block_list *, int); // area
int clif_changeoption(struct block_list *); // area
int clif_useitemack(struct map_session_data *, int, int, int); // self
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 19b5d3e..58206ba 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -159,21 +159,21 @@ struct item_data *itemdb_search(int nameid)
id->view_id = 0;
if (nameid > 500 && nameid < 600)
- id->type = 0; //heal item
+ id->type = ItemType::USE;
else if (nameid > 600 && nameid < 700)
- id->type = 2; //use item
+ id->type = ItemType::_2;
else if ((nameid > 700 && nameid < 1100) ||
(nameid > 7000 && nameid < 8000))
- id->type = 3; //correction
+ id->type = ItemType::JUNK;
else if (nameid >= 1750 && nameid < 1771)
- id->type = 10; //arrow
+ id->type = ItemType::ARROW;
else if (nameid > 1100 && nameid < 2000)
- id->type = 4; //weapon
+ id->type = ItemType::WEAPON;
else if ((nameid > 2100 && nameid < 3000) ||
(nameid > 5000 && nameid < 6000))
- id->type = 5; //armor
+ id->type = ItemType::ARMOR;
else if (nameid > 4000 && nameid < 5000)
- id->type = 6; //card
+ id->type = ItemType::_6;
return id;
}
@@ -184,10 +184,12 @@ struct item_data *itemdb_search(int nameid)
*/
int itemdb_isequip(int nameid)
{
- int type = itemdb_type(nameid);
- if (type == 0 || type == 2 || type == 3 || type == 6 || type == 10)
- return 0;
- return 1;
+ ItemType type = itemdb_type(nameid);
+ return !(type == ItemType::USE
+ || type == ItemType::_2
+ || type == ItemType::JUNK
+ || type == ItemType::_6
+ || type == ItemType::ARROW);
}
/*==========================================
@@ -196,15 +198,14 @@ int itemdb_isequip(int nameid)
*/
int itemdb_isequip2(struct item_data *data)
{
- if (data)
- {
- int type = data->type;
- if (type == 0 || type == 2 || type == 3 || type == 6 || type == 10)
- return 0;
- else
- return 1;
- }
- return 0;
+ if (!data)
+ return false;
+ ItemType type = data->type;
+ return !(type == ItemType::USE
+ || type == ItemType::_2
+ || type == ItemType::JUNK
+ || type == ItemType::_6
+ || type == ItemType::ARROW);
}
/*==========================================
@@ -213,10 +214,10 @@ int itemdb_isequip2(struct item_data *data)
*/
int itemdb_isequip3(int nameid)
{
- int type = itemdb_type(nameid);
- if (type == 4 || type == 5 || type == 8)
- return 1;
- return 0;
+ ItemType type = itemdb_type(nameid);
+ return (type == ItemType::WEAPON
+ || type == ItemType::ARMOR
+ || type == ItemType::_8);
}
//
@@ -238,8 +239,9 @@ int itemdb_read_itemslottable(void)
buf[s] = 0;
for (p = buf; p - buf < s;)
{
- int nameid, equip;
- sscanf(p, "%d#%d#", &nameid, &equip);
+ int nameid, equip_;
+ sscanf(p, "%d#%d#", &nameid, &equip_);
+ EPOS equip = EPOS(equip_);
itemdb_search(nameid)->equip = equip;
p = strchr(p, 10);
if (!p)
@@ -314,7 +316,7 @@ int itemdb_readdb(void)
id = itemdb_search(nameid);
memcpy(id->name, str[1], 24);
memcpy(id->jname, str[2], 24);
- id->type = atoi(str[3]);
+ id->type = ItemType(atoi(str[3]));
id->value_buy = atoi(str[4]);
id->value_sell = atoi(str[5]);
if (id->value_buy == 0 && id->value_sell == 0)
@@ -335,7 +337,7 @@ int itemdb_readdb(void)
id->magic_bonus = atoi(str[10]);
id->slot = atoi(str[11]);
id->sex = atoi(str[12]);
- id->equip = atoi(str[13]);
+ id->equip = EPOS(atoi(str[13]));
id->wlv = atoi(str[14]);
id->elv = atoi(str[15]);
id->look = atoi(str[16]);
diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp
index 97d39dd..e503d9a 100644
--- a/src/map/itemdb.hpp
+++ b/src/map/itemdb.hpp
@@ -12,9 +12,9 @@ struct item_data
char cardillustname[64];
int value_buy;
int value_sell;
- int type;
+ ItemType type;
int sex;
- int equip;
+ EPOS equip;
int weight;
int atk;
int def;
diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp
index f5ca6af..da9a0a4 100644
--- a/src/map/magic-expr-eval.hpp
+++ b/src/map/magic-expr-eval.hpp
@@ -4,9 +4,11 @@
/* Helper definitions for dealing with functions and operations */
static
-int heading_x[8] = { 0, -1, -1, -1, 0, 1, 1, 1 };
+earray<int, DIR, DIR::COUNT> heading_x =
+{ 0, -1, -1, -1, 0, 1, 1, 1 };
static
-int heading_y[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
+earray<int, DIR, DIR::COUNT> heading_y =
+{ 1, 1, 0, -1, -1, -1, 0, 1 };
int magic_signature_check(const char *opname, const char *funname, const char *signature,
int args_nr, val_t *args, int line, int column);
@@ -15,7 +17,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height,
area_t *area);
#define ARGINT(x) args[x].v.v_int
-#define ARGDIR(x) args[x].v.v_int
+#define ARGDIR(x) args[x].v.v_dir
#define ARGSTR(x) args[x].v.v_string
#define ARGENTITY(x) args[x].v.v_entity
#define ARGLOCATION(x) args[x].v.v_location
@@ -24,7 +26,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height,
#define ARGINVOCATION(x) args[x].v.v_invocation
#define RESULTINT result->v.v_int
-#define RESULTDIR result->v.v_int
+#define RESULTDIR result->v.v_dir
#define RESULTSTR result->v.v_string
#define RESULTENTITY result->v.v_entity
#define RESULTLOCATION result->v.v_location
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index bb93670..4a5449d 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -168,7 +168,7 @@ void stringify(val_t *v, int within_op)
default:
fprintf(stderr, "[magic] INTERNAL ERROR: Cannot stringify %d\n",
- v->ty);
+ uint8_t(v->ty));
return;
}
@@ -188,7 +188,7 @@ void intify(val_t *v)
}
static
-area_t *area_new(int ty)
+area_t *area_new(AREA ty)
{
area_t *retval;
CREATE(retval, area_t, 1);
@@ -450,14 +450,14 @@ int fun_bitshr(env_t *, int, val_t *result, val_t *args)
static
int fun_max(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = MAX(ARGINT(0), ARGINT(1));
+ RESULTINT = max(ARGINT(0), ARGINT(1));
return 0;
}
static
int fun_min(env_t *, int, val_t *result, val_t *args)
{
- RESULTINT = MIN(ARGINT(0), ARGINT(1));
+ RESULTINT = min(ARGINT(0), ARGINT(1));
return 0;
}
@@ -695,9 +695,9 @@ static
int fun_random_dir(env_t *, int, val_t *result, val_t *args)
{
if (ARGINT(0))
- RESULTDIR = mt_random() & 0x7;
+ RESULTDIR = DIR(MRAND(8));
else
- RESULTDIR = (mt_random() & 0x3) * 2;
+ RESULTDIR = DIR(MRAND(4) * 2);
return 0;
}
@@ -724,7 +724,12 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable)
if (!item_data)
return 1;
- must_add_sequentially = (item_data->type == 4 || item_data->type == 5 || item_data->type == 7 || item_data->type == 8); /* Very elegant. */
+ // Very elegant.
+ must_add_sequentially = (
+ item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8);
if (stackable)
*stackable = !must_add_sequentially;
@@ -758,20 +763,19 @@ int fun_is_equipped(env_t *, int, val_t *result, val_t *args)
character_t *chr = (ETY(0) == BL_PC) ? ARGPC(0) : NULL;
int stackable;
struct item item;
- int i;
- int retval = 0;
+ bool retval = false;
GET_ARG_ITEM(1, item, stackable);
if (!chr)
return 1;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
if (chr->equip_index[i] >= 0
&& chr->status.inventory[chr->equip_index[i]].nameid ==
item.nameid)
{
- retval = i + 1;
+ retval = true;
break;
}
@@ -856,9 +860,9 @@ static
int fun_distance(env_t *, int, val_t *result, val_t *args)
{
if (ARGLOCATION(0).m != ARGLOCATION(1).m)
- RESULTINT = INT_MAX;
+ RESULTINT = 0x7fffffff;
else
- RESULTINT = MAX(abs(ARGLOCATION(0).x - ARGLOCATION(1).x),
+ RESULTINT = max(abs(ARGLOCATION(0).x - ARGLOCATION(1).x),
abs(ARGLOCATION(0).y - ARGLOCATION(1).y));
return 0;
}
@@ -867,7 +871,7 @@ static
int fun_rdistance(env_t *, int, val_t *result, val_t *args)
{
if (ARGLOCATION(0).m != ARGLOCATION(1).m)
- RESULTINT = INT_MAX;
+ RESULTINT = 0x7fffffff;
else
{
int dx = ARGLOCATION(0).x - ARGLOCATION(1).x;
@@ -945,8 +949,8 @@ void magic_random_location(location_t *dest, area_t *area)
int start_x = x;
int start_y = y;
int i;
- int initial_dir = mt_random() & 0x7;
- int dir = initial_dir;
+ DIR initial_dir = DIR(MRAND(8));
+ DIR dir = initial_dir;
/* try all directions, up to a distance to 10, for a free slot */
do
@@ -960,7 +964,7 @@ void magic_random_location(location_t *dest, area_t *area)
y += heading_y[dir];
}
- dir = (dir + 1) & 0x7;
+ dir = DIR((uint8_t(dir) + 1) % 8);
}
while (map_is_solid(m, x, y) && dir != initial_dir);
@@ -974,7 +978,8 @@ void magic_random_location(location_t *dest, area_t *area)
}
default:
- fprintf(stderr, "Unknown area type %d\n", area->ty);
+ fprintf(stderr, "Unknown area type %d\n",
+ uint8_t(area->ty));
}
}
@@ -1441,7 +1446,7 @@ area_t *eval_area(env_t *env, e_area_t *expr)
area->a.a_bar.width = width.v.v_int;
area->a.a_bar.depth = depth.v.v_int;
- area->a.a_bar.dir = dir.v.v_int;
+ area->a.a_bar.dir = dir.v.v_dir;
if (CHECK_TYPE(&width, TY_INT)
&& CHECK_TYPE(&depth, TY_INT)
@@ -1468,14 +1473,14 @@ area_t *eval_area(env_t *env, e_area_t *expr)
default:
fprintf(stderr, "INTERNAL ERROR: Unknown area type %d\n",
- area->ty);
+ uint8_t(area->ty));
free(area);
return NULL;
}
}
static
-int type_key(char ty_key)
+TY type_key(char ty_key)
{
switch (ty_key)
{
@@ -1496,7 +1501,7 @@ int type_key(char ty_key)
case 'I':
return TY_INVOCATION;
default:
- return -1;
+ return TY::NEGATIVE_1;
}
}
@@ -1508,8 +1513,8 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
{
val_t *arg = &args[i];
char ty_key = signature[i];
- int ty = arg->ty;
- int desired_ty = type_key(ty_key);
+ TY ty = arg->ty;
+ TY desired_ty = type_key(ty_key);
if (ty == TY_ENTITY)
{
@@ -1536,7 +1541,7 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
if (ty == TY_FAIL && ty_key != '_')
return 1; /* Fail `in a sane way': This is a perfectly permissible error */
- if (ty == desired_ty || desired_ty < 0 /* `dontcare' */ )
+ if (ty == desired_ty || desired_ty == TY::NEGATIVE_1)
continue;
if (ty == TY_UNDEF)
@@ -1575,7 +1580,8 @@ int magic_signature_check(const char *opname, const char *funname, const char *s
if (ty != TY_FAIL)
fprintf(stderr,
"[magic-eval]: L%d:%d: Argument #%d to %s `%s' of incorrect type (%d)\n",
- line, column, i + 1, opname, funname, ty);
+ line, column, i + 1, opname, funname,
+ uint8_t(ty));
return 1;
}
}
@@ -1625,8 +1631,8 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr)
dest->ty = TY_FAIL;
else
{
- int dest_ty = type_key(f->ret_ty);
- if (dest_ty != -1)
+ TY dest_ty = type_key(f->ret_ty);
+ if (dest_ty != TY::NEGATIVE_1)
dest->ty = dest_ty;
/* translate entity back into persistent int */
@@ -1690,7 +1696,7 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr)
default:
fprintf(stderr,
"[magic] INTERNAL ERROR: Unknown expression type %d\n",
- expr->ty);
+ uint8_t(expr->ty));
break;
}
}
@@ -1724,7 +1730,7 @@ char *magic_eval_str(env_t *env, expr_t *expr)
return result.v.v_string;
}
-expr_t *magic_new_expr(int ty)
+expr_t *magic_new_expr(EXPR ty)
{
expr_t *expr = (expr_t *) malloc(sizeof(expr_t));
expr->ty = ty;
diff --git a/src/map/magic-expr.hpp b/src/map/magic-expr.hpp
index 2e9c5ec..4fd6041 100644
--- a/src/map/magic-expr.hpp
+++ b/src/map/magic-expr.hpp
@@ -4,17 +4,6 @@
#include "magic-interpreter.hpp"
#include "magic-interpreter-aux.hpp"
-#ifndef MAX
-# define MAX(x,y) (((x)>(y)) ? (x) : (y))
-#endif
-#ifndef MIN
-# define MIN(x,y) (((x)<(y)) ? (x) : (y))
-#endif
-
-#ifndef INT_MAX
-# define INT_MAX (1<<30) // It's more than that, but this is quite sufficient for our purposes.
-#endif
-
/*
* Argument types:
* i : int
@@ -74,7 +63,7 @@ char *magic_eval_str(env_t *env, expr_t *expr);
int map_is_solid(int m, int x, int y);
-expr_t *magic_new_expr(int ty);
+expr_t *magic_new_expr(EXPR ty);
void magic_clear_var(val_t *v);
diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp
index 229dadb..ec59d38 100644
--- a/src/map/magic-interpreter-base.cpp
+++ b/src/map/magic-interpreter-base.cpp
@@ -4,7 +4,7 @@
#include "magic-interpreter-aux.hpp"
static
-void set_int_p(val_t *v, int i, int t)
+void set_int_p(val_t *v, int i, TY t)
{
v->ty = t;
v->v.v_int = i;
@@ -208,7 +208,7 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell,
default:
free(param);
fprintf(stderr, "Unexpected spellarg type %d\n",
- spell->spellarg_ty);
+ uint8_t(spell->spellarg_ty));
}
set_env_entity(VAR_CASTER, &caster->bl);
@@ -328,7 +328,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster,
unsigned int casttime = (unsigned int) check->casttime;
if (VAR(VAR_MIN_CASTTIME).ty == TY_INT)
- casttime = MAX(casttime, VAR(VAR_MIN_CASTTIME).v.v_int);
+ casttime = max(casttime, VAR(VAR_MIN_CASTTIME).v.v_int);
caster->cast_tick = tick + casttime; /* Make sure not to cast too frequently */
@@ -401,7 +401,8 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
return NULL;
default:
- fprintf(stderr, "Unexpected spellguard type %d\n", guard->ty);
+ fprintf(stderr, "Unexpected spellguard type %d\n",
+ uint8_t(guard->ty));
return NULL;
}
@@ -459,7 +460,7 @@ void spell_set_location(invocation_t *invocation, entity_t *entity)
void spell_update_location(invocation_t *invocation)
{
- if (invocation->spell->flags & SPELL_FLAG_LOCAL)
+ if (bool(invocation->spell->flags & SPELL_FLAG_LOCAL))
return;
else
{
@@ -517,7 +518,7 @@ invocation_t *spell_clone_effect(invocation_t *base)
retval->subject = 0;
retval->status_change_refs_nr = 0;
retval->status_change_refs = NULL;
- retval->flags = 0;
+ retval->flags = INVOCATION_FLAG::ZERO;
retval->bl.id = 0;
retval->bl.prev = NULL;
@@ -533,9 +534,9 @@ void spell_bind(character_t *subject, invocation_t *invocation)
{
/* Only bind nonlocal spells */
- if (!(invocation->spell->flags & SPELL_FLAG_LOCAL))
+ if (!bool(invocation->spell->flags & SPELL_FLAG_LOCAL))
{
- if (invocation->flags & INVOCATION_FLAG_BOUND
+ if (bool(invocation->flags & INVOCATION_FLAG_BOUND)
|| invocation->subject || invocation->next_invocation)
{
int *i = NULL;
diff --git a/src/map/magic-interpreter-parser.ypp b/src/map/magic-interpreter-parser.ypp
index 860103a..2b80ffb 100644
--- a/src/map/magic-interpreter-parser.ypp
+++ b/src/map/magic-interpreter-parser.ypp
@@ -38,10 +38,10 @@ static
spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b);
static
-spellguard_t *new_spellguard(int ty);
+spellguard_t *new_spellguard(SPELLGUARD ty);
static
-effect_t *new_effect(int ty);
+effect_t *new_effect(EFFECT_ ty);
static
effect_t *set_effect_continuation(effect_t *src, effect_t *continuation);
@@ -78,6 +78,9 @@ val_t *find_constant(char *name);
%union {
int i;
+ SPELL_FLAG spell_flags;
+ SPELLARG spell_arg;
+ FOREACH_FILTER foreach_filter;
char *s;
int op;
magic_conf_t *magic_conf;
@@ -88,7 +91,7 @@ val_t *find_constant(char *name);
args_rec_t arg_list;
struct { int letdefs_nr; letdef_t *letdefs; } letdefs;
spell_t *spell;
- struct { int id, ty; } spellarg_def;
+ struct { int id; SPELLARG ty; } spellarg_def;
letdef_t vardef;
spellguard_t *spellguard;
component_t *components;
@@ -189,15 +192,15 @@ val_t *find_constant(char *name);
%type <components> items
%type <components> item_list
%type <i> item_name
-%type <i> selection;
+%type <foreach_filter> selection;
%type <effect> effect
%type <effect> effect_list
%type <effect> maybe_trigger
%type <effect> maybe_end
-%type <i> spell_flags;
+%type <spell_flags> spell_flags;
%type <expr> expr
-%type <i> arg_ty
+%type <spell_arg> arg_ty
%type <proc> proc_formals_list
%type <proc> proc_formals_list_ne
@@ -300,19 +303,19 @@ spellconf_option : ID '=' expr
}
spell_flags : /* empty */
- { $$ = 0; }
+ { $$ = SPELL_FLAG::ZERO; }
| LOCAL spell_flags
- { if ($2 & SPELL_FLAG_LOCAL)
+ { if (bool($2 & SPELL_FLAG_LOCAL))
fail(@1.first_line, @1.first_column, "`LOCAL' specified more than once");
$$ = $2 | SPELL_FLAG_LOCAL;
}
| NONMAGIC spell_flags
- { if ($2 & SPELL_FLAG_NONMAGIC)
+ { if (bool($2 & SPELL_FLAG_NONMAGIC))
fail(@1.first_line, @1.first_column, "`NONMAGIC' specified more than once");
$$ = $2 | SPELL_FLAG_NONMAGIC;
}
| SILENT spell_flags
- { if ($2 & SPELL_FLAG_SILENT)
+ { if (bool($2 & SPELL_FLAG_SILENT))
fail(@1.first_line, @1.first_column, "`SILENT' specified more than once");
$$ = $2 | SPELL_FLAG_SILENT;
}
@@ -841,7 +844,7 @@ spell_t *new_spell(spellguard_t *guard)
}
static
-spellguard_t *new_spellguard(int ty)
+spellguard_t *new_spellguard(SPELLGUARD ty)
{
spellguard_t *retval = (spellguard_t *)calloc(1, sizeof(spellguard_t));
retval->ty = ty;
@@ -879,7 +882,7 @@ spellguard_t *spellguard_implication(spellguard_t *a, spellguard_t *b)
}
static
-effect_t *new_effect(int ty)
+effect_t *new_effect(EFFECT_ ty)
{
effect_t *effect = (effect_t *) calloc(1, sizeof(effect_t));
effect->ty = ty;
diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp
index 744d367..e79f0ab 100644
--- a/src/map/magic-interpreter.hpp
+++ b/src/map/magic-interpreter.hpp
@@ -1,6 +1,8 @@
#ifndef MAGIC_INTERPRETER_HPP
#define MAGIC_INTERPRETER_HPP
+#include "magic-interpreter.t.hpp"
+
#include <cmath>
#include <cstdio>
#include <cstdlib>
@@ -27,34 +29,6 @@
#include "storage.hpp"
#include "trade.hpp"
-#define SPELLARG_NONE 0 /* No spell parameter */
-#define SPELLARG_PC 1 /* Spell parameter describes pc (defaults to self) */
-#define SPELLARG_STRING 2 /* Spell parameter describes pc (defaults to self) */
-
-/* ------ */
-/* Values */
-/* ------ */
-
-#define TY_UNDEF 0
-#define TY_INT 1
-#define TY_DIR 2
-#define TY_STRING 3
-#define TY_ENTITY 5
-#define TY_LOCATION 6
-#define TY_AREA 7
-#define TY_SPELL 8
-#define TY_INVOCATION 9
-#define TY_FAIL 127
-
-#define DIR_S 0
-#define DIR_SW 1
-#define DIR_W 2
-#define DIR_NW 3
-#define DIR_N 4
-#define DIR_NE 5
-#define DIR_E 6
-#define DIR_SE 7
-
struct expr;
struct val;
struct location;
@@ -68,11 +42,6 @@ typedef struct location
int x, y;
} location_t;
-#define AREA_LOCATION 0
-#define AREA_UNION 1
-#define AREA_RECT 2
-#define AREA_BAR 3
-
typedef struct area
{
union a
@@ -81,7 +50,8 @@ typedef struct area
struct
{
location_t loc;
- int width, depth, dir;
+ int width, depth;
+ DIR dir;
} a_bar;
struct
{
@@ -91,7 +61,7 @@ typedef struct area
struct area *a_union[2];
} a;
int size;
- unsigned char ty;
+ AREA ty;
} area_t;
typedef struct val
@@ -99,6 +69,7 @@ typedef struct val
union v
{
int v_int;
+ DIR v_dir;
char *v_string;
entity_t *v_entity; /* Used ONLY during operation/function invocation; otherwise we use v_int */
area_t *v_area;
@@ -106,7 +77,7 @@ typedef struct val
struct invocation *v_invocation; /* Used ONLY during operation/function invocation; otherwise we use v_int */
struct spell *v_spell;
} v;
- unsigned char ty;
+ TY ty;
} val_t;
/* ----------- */
@@ -115,13 +86,6 @@ typedef struct val
#define MAX_ARGS 7 /* Max. # of args used in builtin primitive functions */
-#define EXPR_VAL 0
-#define EXPR_LOCATION 1
-#define EXPR_AREA 2
-#define EXPR_FUNAPP 3
-#define EXPR_ID 4
-#define EXPR_SPELLFIELD 5
-
typedef struct e_location
{
struct expr *m, *x, *y;
@@ -144,7 +108,7 @@ typedef struct e_area
} a_rect;
struct e_area *a_union[2];
} a;
- unsigned char ty;
+ AREA ty;
} e_area_t;
typedef struct expr
@@ -167,33 +131,9 @@ typedef struct expr
int id;
} e_field;
} e;
- unsigned char ty;
+ EXPR ty;
} expr_t;
-/* ------- */
-/* Effects */
-/* ------- */
-
-#define EFFECT_SKIP 0
-#define EFFECT_ABORT 1
-#define EFFECT_ASSIGN 2
-#define EFFECT_FOREACH 3
-#define EFFECT_FOR 4
-#define EFFECT_IF 5
-#define EFFECT_SLEEP 6
-#define EFFECT_SCRIPT 7
-#define EFFECT_BREAK 8
-#define EFFECT_OP 9
-#define EFFECT_END 10
-#define EFFECT_CALL 11
-
-#define FOREACH_FILTER_MOB 1
-#define FOREACH_FILTER_PC 2
-#define FOREACH_FILTER_ENTITY 3
-#define FOREACH_FILTER_TARGET 4
-#define FOREACH_FILTER_SPELL 5
-#define FOREACH_FILTER_NPC 6
-
typedef struct effect
{
struct effect *next;
@@ -209,7 +149,7 @@ typedef struct effect
int id;
expr_t *area;
struct effect *body;
- unsigned char filter;
+ FOREACH_FILTER filter;
} e_foreach;
struct
{
@@ -238,7 +178,7 @@ typedef struct effect
struct effect *body;
} e_call;
} e;
- unsigned char ty;
+ EFFECT_ ty;
} effect_t;
/* ---------- */
@@ -252,17 +192,6 @@ typedef struct component
int count;
} component_t;
-/* ----------- */
-/* Spellguards */
-/* ----------- */
-
-#define SPELLGUARD_CONDITION 0
-#define SPELLGUARD_COMPONENTS 1
-#define SPELLGUARD_CATALYSTS 2
-#define SPELLGUARD_CHOICE 3
-#define SPELLGUARD_MANA 4
-#define SPELLGUARD_CASTTIME 5
-#define SPELLGUARD_EFFECT 6
typedef struct effect_set
{
@@ -282,7 +211,7 @@ typedef struct spellguard
struct spellguard *s_alt; /* either `next' or `s.s_alt' */
effect_set_t s_effect;
} s;
- unsigned char ty;
+ SPELLGUARD ty;
} spellguard_t;
/* ------ */
@@ -295,18 +224,14 @@ typedef struct letdef
expr_t *expr;
} letdef_t;
-#define SPELL_FLAG_LOCAL (1 << 0) // spell associated not with caster but with place
-#define SPELL_FLAG_SILENT (1 << 1) // spell invocation never uttered
-#define SPELL_FLAG_NONMAGIC (1 << 2) // `magic word' only: don't require spellcasting ability
-
typedef struct spell
{
char *name;
char *invocation;
int index; // Relative location in the definitions file
- int flags;
+ SPELL_FLAG flags;
int arg;
- int spellarg_ty;
+ SPELLARG spellarg_ty;
int letdefs_nr;
letdef_t *letdefs;
@@ -347,6 +272,7 @@ typedef struct
/* Execution environment */
+// these are not an enum they're a nasty intern hack
#define VAR_MIN_CASTTIME 0
#define VAR_OBSCURE_CHANCE 1
#define VAR_CASTER 2
@@ -367,10 +293,6 @@ typedef struct env
#define MAX_STACK_SIZE 32
-#define CONT_STACK_FOREACH 0
-#define CONT_STACK_FOR 1
-#define CONT_STACK_PROC 2
-
typedef struct cont_activation_record
{
effect_t *return_location;
@@ -378,7 +300,8 @@ typedef struct cont_activation_record
{
struct
{
- int id, ty;
+ int id;
+ TY ty;
effect_t *body;
int entities_nr;
int *entities;
@@ -397,7 +320,7 @@ typedef struct cont_activation_record
val_t *old_actuals;
} c_proc;
} c;
- unsigned char ty;
+ CONT_STACK ty;
} cont_activation_record_t;
typedef struct status_change_ref
@@ -406,16 +329,12 @@ typedef struct status_change_ref
int bl_id;
} status_change_ref_t;
-#define INVOCATION_FLAG_BOUND (1 << 0) /* Bound directly to the caster (i.e., ignore its location) */
-#define INVOCATION_FLAG_ABORTED (1 << 1) /* Used `abort' to terminate */
-#define INVOCATION_FLAG_STOPATTACK (1 << 2) /* On magical attacks: if we run out of steam, stop attacking altogether */
-
typedef struct invocation
{
struct block_list bl;
struct invocation *next_invocation; /* used for spells directly associated with a caster: they form a singly-linked list */
- int flags;
+ INVOCATION_FLAG flags;
env_t *env;
spell_t *spell;
diff --git a/src/map/magic-interpreter.t.hpp b/src/map/magic-interpreter.t.hpp
new file mode 100644
index 0000000..f5cb309
--- /dev/null
+++ b/src/map/magic-interpreter.t.hpp
@@ -0,0 +1,210 @@
+#ifndef MAGIC_INTERPRETER_T_HPP
+#define MAGIC_INTERPRETER_T_HPP
+
+#include "../common/utils.hpp"
+
+enum class SPELLARG : uint8_t
+{
+ NONE,
+#define SPELLARG_NONE SPELLARG::NONE
+ PC,
+#define SPELLARG_PC SPELLARG::PC
+ STRING,
+#define SPELLARG_STRING SPELLARG::STRING
+};
+
+enum class TY : uint8_t
+{
+ UNDEF,
+#define TY_UNDEF TY::UNDEF
+ INT,
+#define TY_INT TY::INT
+ DIR,
+#define TY_DIR TY::DIR
+ STRING,
+#define TY_STRING TY::STRING
+ ENTITY,
+#define TY_ENTITY TY::ENTITY
+ LOCATION,
+#define TY_LOCATION TY::LOCATION
+ AREA,
+#define TY_AREA TY::AREA
+ SPELL,
+#define TY_SPELL TY::SPELL
+ INVOCATION,
+#define TY_INVOCATION TY::INVOCATION
+ FAIL = 127,
+#define TY_FAIL TY::FAIL
+
+ NEGATIVE_1 = 255,
+};
+
+// Note: there is also a typedef by this name in <dirent.h>
+// but we should be fine since we never include it.
+// (in the long term we should still rename this though)
+enum class DIR : uint8_t
+{
+ S = 0,
+#define DIR_S DIR::S
+ SW = 1,
+#define DIR_SW DIR::SW
+ W = 2,
+#define DIR_W DIR::W
+ NW = 3,
+#define DIR_NW DIR::NW
+ N = 4,
+#define DIR_N DIR::N
+ NE = 5,
+#define DIR_NE DIR::NE
+ E = 6,
+#define DIR_E DIR::E
+ SE = 7,
+#define DIR_SE DIR::SE
+
+ COUNT,
+};
+
+enum class AREA : uint8_t
+{
+ LOCATION,
+#define AREA_LOCATION AREA::LOCATION
+ UNION,
+#define AREA_UNION AREA::UNION
+ RECT,
+#define AREA_RECT AREA::RECT
+ BAR,
+#define AREA_BAR AREA::BAR
+};
+
+enum class EXPR : uint8_t
+{
+ VAL,
+#define EXPR_VAL EXPR::VAL
+ LOCATION,
+#define EXPR_LOCATION EXPR::LOCATION
+ AREA,
+#define EXPR_AREA EXPR::AREA
+ FUNAPP,
+#define EXPR_FUNAPP EXPR::FUNAPP
+ ID,
+#define EXPR_ID EXPR::ID
+ SPELLFIELD,
+#define EXPR_SPELLFIELD EXPR::SPELLFIELD
+};
+
+// temporary rename to avoid collision with enum value
+// in magic-interpreter-parser
+enum class EFFECT_ : uint8_t
+{
+ SKIP,
+#define EFFECT_SKIP EFFECT_::SKIP
+ ABORT,
+#define EFFECT_ABORT EFFECT_::ABORT
+ ASSIGN,
+#define EFFECT_ASSIGN EFFECT_::ASSIGN
+ FOREACH,
+#define EFFECT_FOREACH EFFECT_::FOREACH
+ FOR,
+#define EFFECT_FOR EFFECT_::FOR
+ IF,
+#define EFFECT_IF EFFECT_::IF
+ SLEEP,
+#define EFFECT_SLEEP EFFECT_::SLEEP
+ // temporary rename to avoid collision with NpcSubtype
+ SCRIPT_,
+#define EFFECT_SCRIPT EFFECT_::SCRIPT_
+ BREAK,
+#define EFFECT_BREAK EFFECT_::BREAK
+ OP,
+#define EFFECT_OP EFFECT_::OP
+ END,
+#define EFFECT_END EFFECT_::END
+ CALL,
+#define EFFECT_CALL EFFECT_::CALL
+};
+
+enum class FOREACH_FILTER : uint8_t
+{
+ MOB,
+#define FOREACH_FILTER_MOB FOREACH_FILTER::MOB
+ PC,
+#define FOREACH_FILTER_PC FOREACH_FILTER::PC
+ ENTITY,
+#define FOREACH_FILTER_ENTITY FOREACH_FILTER::ENTITY
+ TARGET,
+#define FOREACH_FILTER_TARGET FOREACH_FILTER::TARGET
+ SPELL,
+#define FOREACH_FILTER_SPELL FOREACH_FILTER::SPELL
+ NPC,
+#define FOREACH_FILTER_NPC FOREACH_FILTER::NPC
+};
+
+enum class SPELLGUARD : uint8_t
+{
+ CONDITION,
+#define SPELLGUARD_CONDITION SPELLGUARD::CONDITION
+ COMPONENTS,
+#define SPELLGUARD_COMPONENTS SPELLGUARD::COMPONENTS
+ CATALYSTS,
+#define SPELLGUARD_CATALYSTS SPELLGUARD::CATALYSTS
+ CHOICE,
+#define SPELLGUARD_CHOICE SPELLGUARD::CHOICE
+ MANA,
+#define SPELLGUARD_MANA SPELLGUARD::MANA
+ CASTTIME,
+#define SPELLGUARD_CASTTIME SPELLGUARD::CASTTIME
+ EFFECT,
+#define SPELLGUARD_EFFECT SPELLGUARD::EFFECT
+};
+
+namespace e
+{
+enum class SPELL_FLAG : uint8_t
+{
+ ZERO = 0,
+
+ // spell associated not with caster but with place
+ LOCAL = 1 << 0,
+#define SPELL_FLAG_LOCAL SPELL_FLAG::LOCAL
+ // spell invocation never uttered
+ SILENT = 1 << 1,
+#define SPELL_FLAG_SILENT SPELL_FLAG::SILENT
+ // `magic word' only: don't require spellcasting ability
+ NONMAGIC = 1 << 2,
+#define SPELL_FLAG_NONMAGIC SPELL_FLAG::NONMAGIC
+};
+ENUM_BITWISE_OPERATORS(SPELL_FLAG)
+}
+using e::SPELL_FLAG;
+
+enum class CONT_STACK : uint8_t
+{
+ FOREACH,
+#define CONT_STACK_FOREACH CONT_STACK::FOREACH
+ FOR,
+#define CONT_STACK_FOR CONT_STACK::FOR
+ PROC,
+#define CONT_STACK_PROC CONT_STACK::PROC
+};
+
+namespace e
+{
+enum class INVOCATION_FLAG : uint8_t
+{
+ ZERO = 0,
+
+ // Bound directly to the caster (i.e., ignore its location)
+ BOUND = 1 << 0,
+#define INVOCATION_FLAG_BOUND INVOCATION_FLAG::BOUND
+ // Used `abort' to terminate
+ ABORTED = 1 << 1,
+#define INVOCATION_FLAG_ABORTED INVOCATION_FLAG::ABORTED
+ // On magical attacks: if we run out of steam, stop attacking altogether
+ STOPATTACK = 1 << 2,
+#define INVOCATION_FLAG_STOPATTACK INVOCATION_FLAG::STOPATTACK
+};
+ENUM_BITWISE_OPERATORS(INVOCATION_FLAG)
+}
+using e::INVOCATION_FLAG;
+
+#endif // MAGIC_INTERPRETER_T_HPP
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index 19d6636..d176dad 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -96,7 +96,7 @@ void spell_free_invocation(invocation_t *invocation)
invocation->status_change_refs_nr = 0;
}
- if (invocation->flags & INVOCATION_FLAG_BOUND)
+ if (bool(invocation->flags & INVOCATION_FLAG_BOUND))
{
entity_t *e = map_id2bl(invocation->subject);
if (e && e->type == BL_PC)
@@ -448,7 +448,7 @@ static
int op_move(env_t *, int, val_t *args)
{
entity_t *subject = ARGENTITY(0);
- int dir = ARGDIR(1);
+ DIR dir = ARGDIR(1);
int newx = subject->x + heading_x[dir];
int newy = subject->y + heading_y[dir];
@@ -853,7 +853,8 @@ int op_gain_exp(env_t *, int, val_t *args)
if (!c)
return 1;
- pc_gainexp_reason(c, ARGINT(1), ARGINT(2), ARGINT(3));
+ pc_gainexp_reason(c, ARGINT(1), ARGINT(2),
+ PC_GAINEXP_REASON(ARGINT(3)));
return 0;
}
@@ -1050,8 +1051,7 @@ effect_t *return_to_stack(invocation_t *invocation)
static
cont_activation_record_t *add_stack_entry(invocation_t *invocation,
- int ty,
- effect_t *return_location)
+ CONT_STACK ty, effect_t *return_location)
{
cont_activation_record_t *ar =
invocation->stack + invocation->stack_size++;
@@ -1074,7 +1074,7 @@ void find_entities_in_area_c(entity_t *target,
int *entities_allocd_p,
int *entities_nr_p,
int **entities_p,
- int filter)
+ FOREACH_FILTER filter)
{
/* The following macro adds an entity to the result list: */
#define ADD_ENTITY(e) \
@@ -1121,7 +1121,7 @@ void find_entities_in_area_c(entity_t *target,
invocation_t *invocation = (invocation_t *) target;
/* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster(case BL_PC). */
- if (invocation->flags & INVOCATION_FLAG_BOUND)
+ if (bool(invocation->flags & INVOCATION_FLAG_BOUND))
return;
else
break; /* Add the spell */
@@ -1145,7 +1145,7 @@ void find_entities_in_area_c(entity_t *target,
static
void find_entities_in_area(area_t *area, int *entities_allocd_p,
- int *entities_nr_p, int **entities_p, int filter)
+ int *entities_nr_p, int **entities_p, FOREACH_FILTER filter)
{
switch (area->ty)
{
@@ -1162,7 +1162,7 @@ void find_entities_in_area(area_t *area, int *entities_allocd_p,
magic_area_rect(&m, &x, &y, &width, &height, area);
map_foreachinarea(std::bind(find_entities_in_area_c, ph::_1, entities_allocd_p, entities_nr_p, entities_p, filter),
m, x, y, x + width, y + height,
- 0 /* filter elsewhere */);
+ BL_NUL /* filter elsewhere */);
}
}
}
@@ -1172,7 +1172,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach,
effect_t *return_location)
{
val_t area;
- int filter = foreach->e.e_foreach.filter;
+ FOREACH_FILTER filter = foreach->e.e_foreach.filter;
int id = foreach->e.e_foreach.id;
effect_t *body = foreach->e.e_foreach.body;
@@ -1526,7 +1526,7 @@ int spell_run(invocation_t *invocation, int allow_delete)
default:
fprintf(stderr,
"[magic] INTERNAL ERROR: Unknown effect %d\n",
- e->ty);
+ uint8_t(e->ty));
}
if (!next)
@@ -1592,7 +1592,7 @@ int spell_attack(int caster_id, int target_id)
invocation = (invocation_t *) map_id2bl(caster->attack_spell_override);
- if (invocation && invocation->flags & INVOCATION_FLAG_STOPATTACK)
+ if (invocation && bool(invocation->flags & INVOCATION_FLAG_STOPATTACK))
stop_attack = 1;
if (invocation && caster->attack_spell_charges > 0)
@@ -1610,7 +1610,7 @@ int spell_attack(int caster_id, int target_id)
invocation =
(invocation_t *) map_id2bl(caster->attack_spell_override);
- if (invocation && !(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort:
+ if (invocation && !bool(invocation->flags & INVOCATION_FLAG_ABORTED)) // If we didn't abort:
caster->attack_spell_charges--;
}
diff --git a/src/map/magic.cpp b/src/map/magic.cpp
index 20155aa..5c2daf3 100644
--- a/src/map/magic.cpp
+++ b/src/map/magic.cpp
@@ -89,7 +89,7 @@ int magic_message(character_t *caster, char *spell_, size_t)
spell_create_env(&magic_conf, spell, caster, power, parameter);
effect_set_t *effects;
- if ((spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1))
+ if (bool(spell->flags & SPELL_FLAG_NONMAGIC) || (power >= 1))
effects = spell_trigger(spell, caster, env, &near_miss);
else
effects = NULL;
@@ -111,7 +111,7 @@ int magic_message(character_t *caster, char *spell_, size_t)
spell_bind(caster, invocation);
spell_execute(invocation);
- return (spell->flags & SPELL_FLAG_SILENT) ? -1 : 1;
+ return bool(spell->flags & SPELL_FLAG_SILENT) ? -1 : 1;
}
else
magic_free_env(env);
diff --git a/src/map/map.cpp b/src/map/map.cpp
index d4a9289..6323a96 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -333,7 +333,7 @@ int map_count_oncell(int m, int x, int y)
void map_foreachinarea(std::function<void(struct block_list *)> func,
int m,
int x0, int y0, int x1, int y1,
- int type)
+ BL type)
{
int bx, by;
struct block_list *bl = NULL;
@@ -349,7 +349,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func,
x1 = map[m].xs - 1;
if (y1 >= map[m].ys)
y1 = map[m].ys - 1;
- if (type == 0 || type != BL_MOB)
+ if (type == BL_NUL || type != BL_MOB)
for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++)
{
for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++)
@@ -358,7 +358,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL_NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -366,7 +366,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func,
}
}
}
- if (type == 0 || type == BL_MOB)
+ if (type == BL_NUL || type == BL_MOB)
for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++)
{
for (bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++)
@@ -411,7 +411,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
int m,
int x0, int y0, int x1, int y1,
int dx, int dy,
- int type)
+ BL type)
{
int bx, by;
struct block_list *bl = NULL;
@@ -458,7 +458,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL_NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -468,7 +468,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
c = map[m].block_mob_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL_NUL && bl->type != type)
continue;
if (bl && bl->x >= x0 && bl->x <= x1 && bl->y >= y0
&& bl->y <= y1 && bl_list_count < BL_LIST_MAX)
@@ -497,7 +497,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL_NUL && bl->type != type)
continue;
if ((bl)
&& !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0
@@ -516,7 +516,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
c = map[m].block_mob_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (bl && type && bl->type != type)
+ if (bl && type != BL_NUL && bl->type != type)
continue;
if ((bl)
&& !(bl->x >= x0 && bl->x <= x1 && bl->y >= y0
@@ -560,7 +560,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func,
void map_foreachincell(std::function<void(struct block_list *)> func,
int m,
int x, int y,
- int type)
+ BL type)
{
int bx, by;
struct block_list *bl = NULL;
@@ -569,20 +569,20 @@ void map_foreachincell(std::function<void(struct block_list *)> func,
by = y / BLOCK_SIZE;
bx = x / BLOCK_SIZE;
- if (type == 0 || type != BL_MOB)
+ if (type == BL_NUL || type != BL_MOB)
{
bl = map[m].block[bx + by * map[m].bxs];
c = map[m].block_count[bx + by * map[m].bxs];
for (i = 0; i < c && bl; i++, bl = bl->next)
{
- if (type && bl && bl->type != type)
+ if (type != BL_NUL && bl && bl->type != type)
continue;
if (bl && bl->x == x && bl->y == y && bl_list_count < BL_LIST_MAX)
bl_list[bl_list_count++] = bl;
}
}
- if (type == 0 || type == BL_MOB)
+ if (type == BL_NUL || type == BL_MOB)
{
bl = map[m].block_mob[bx + by * map[m].bxs];
c = map[m].block_mob_count[bx + by * map[m].bxs];
@@ -649,15 +649,16 @@ int map_addobject(struct block_list *bl)
* map_delobjectのfreeしないバージョン
*------------------------------------------
*/
-int map_delobjectnofree(int id, int type)
+int map_delobjectnofree(int id, BL type)
{
if (object[id] == NULL)
return 0;
if (object[id]->type != type)
{
- fprintf(stderr, "Incorrect type: expected %d, got %d\n", type,
- object[id]->type);
+ fprintf(stderr, "Incorrect type: expected %d, got %d\n",
+ uint8_t(type),
+ uint8_t(object[id]->type));
abort();
}
@@ -683,7 +684,7 @@ int map_delobjectnofree(int id, int type)
* addとの対称性が無いのが気になる
*------------------------------------------
*/
-int map_delobject(int id, int type)
+int map_delobject(int id, BL type)
{
struct block_list *obj = object[id];
@@ -705,7 +706,7 @@ int map_delobject(int id, int type)
*------------------------------------------
*/
void map_foreachobject(std::function<void(struct block_list *)> func,
- int type)
+ BL type)
{
int i;
int blockcount = bl_list_count;
@@ -714,7 +715,7 @@ void map_foreachobject(std::function<void(struct block_list *)> func,
{
if (object[i])
{
- if (type && object[i]->type != type)
+ if (type != BL_NUL && object[i]->type != type)
continue;
if (bl_list_count >= BL_LIST_MAX)
{
@@ -2011,8 +2012,9 @@ void term_func(void)
for (map_id = 0; map_id < map_num; map_id++)
{
if (map[map_id].m)
- map_foreachinarea(cleanup_sub, map_id, 0, 0, map[map_id].xs,
- map[map_id].ys, 0);
+ map_foreachinarea(cleanup_sub, map_id,
+ 0, 0, map[map_id].xs, map[map_id].ys,
+ BL_NUL);
}
for (i = 0; i < fd_max; i++)
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 93032bb..7f75427 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -13,17 +13,11 @@
#include "../common/mmo.hpp"
#include "../common/timer.hpp"
+#include "battle.t.hpp"
#include "mob.t.hpp"
#include "script.hpp" // change to script.t.hpp
#include "skill.t.hpp"
-#ifndef MAX
-# define MAX(x,y) (((x)>(y)) ? (x) : (y))
-#endif
-#ifndef MIN
-# define MIN(x,y) (((x)<(y)) ? (x) : (y))
-#endif
-
#define MAX_PC_CLASS (1+6+6+1+6+1+1+1+1+4023)
#define PC_CLASS_BASE 0
#define PC_CLASS_BASE2 (PC_CLASS_BASE + 4001)
@@ -57,8 +51,8 @@ struct block_list
struct block_list *next, *prev;
int id;
short m, x, y;
- unsigned char type;
- unsigned char subtype;
+ BL type;
+ NpcSubtype subtype;
};
struct walkpath_data
@@ -81,6 +75,7 @@ struct status_change
int timer;
int val1, val2, val3, val4;
SkillID val1_sk() { return SkillID(val1); }
+ BCT& val1_bct() { return reinterpret_cast<BCT&>(val1); }
int spell_invocation; /* [Fate] If triggered by a spell, record here */
};
@@ -102,7 +97,7 @@ struct skill_unit_group
int src_id;
int party_id;
int map, range;
- int target_flag;
+ BCT target_flag;
unsigned int tick;
int limit, interval;
@@ -129,8 +124,33 @@ struct skill_timerskill
short x, y;
SkillID skill_id;
short skill_lv;
- int type;
- int flag;
+ union sktst
+ {
+ int32_t n;
+ struct { uint16_t x, y; } xy;
+ BF bf;
+
+ static sktst from_n(int32_t n)
+ {
+ sktst r;
+ r.n = n;
+ return r;
+ }
+ static sktst from_xy(uint16_t x, uint16_t y)
+ {
+ sktst r;
+ r.xy.x = x;
+ r.xy.y = y;
+ return r;
+ }
+ static sktst from_bf(BF bf)
+ {
+ sktst r;
+ r.bf = bf;
+ return r;
+ }
+ } type;
+ BCT flag;
};
struct npc_data;
@@ -161,7 +181,7 @@ struct map_session_data
unsigned lr_flag:2;
unsigned connect_new:1;
unsigned arrow_atk:1;
- unsigned attack_type:3;
+ BF attack_type;//:3;
unsigned skill_flag:1;
unsigned gangsterparadise:1;
unsigned produce_flag:1;
@@ -194,7 +214,7 @@ struct map_session_data
unsigned char tmw_version; // tmw client version
struct mmo_charstatus status;
struct item_data *inventory_data[MAX_INVENTORY];
- short equip_index[11];
+ earray<short, EQUIP, EQUIP::COUNT> equip_index;
int weight, max_weight;
int cart_weight, cart_max_weight, cart_num, cart_max_num;
char mapname[24];
@@ -225,7 +245,7 @@ struct map_session_data
int attacktimer;
int attacktarget;
- short attacktarget_lv;
+ ATK attacktarget_lv;
unsigned int attackabletime;
int followtimer; // [MouseJstr]
@@ -281,7 +301,7 @@ struct map_session_data
short view_class;
short weapontype1, weapontype2;
short disguiseflag, disguise; // [Valaris]
- int paramb[6], paramc[6], parame[6], paramcard[6];
+ earray<int, ATTR, ATTR::COUNT> paramb, paramc, parame, paramcard;
int hit, flee, flee2, aspd, amotion, dmotion;
int watk, watk2, atkmods[3];
int def, def2, mdef, mdef2, critical, matk1, matk2;
@@ -461,20 +481,6 @@ struct npc_data
#define MOB_SENSIBLE_MASK 0xf000 // fate: mob mode flags that I actually understand
-enum mob_stat
-{
- MOB_LV,
- MOB_MAX_HP,
- MOB_STR, MOB_AGI, MOB_VIT, MOB_INT, MOB_DEX, MOB_LUK,
- MOB_ATK1, MOB_ATK2, // low and high attacks
- MOB_ADELAY, // attack delay
- MOB_DEF, MOB_MDEF,
- MOB_SPEED,
- // These must come last:
- MOB_XP_BONUS, /* [Fate] Encoded as base to 1024: 1024 means 100% */
- MOB_LAST,
-};
-
#define MOB_XP_BONUS_BASE 1024
#define MOB_XP_BONUS_SHIFT 10
@@ -488,9 +494,9 @@ struct mob_data
int spawndelay1, spawndelay2;
struct
{
- unsigned state:8;
+ MS state;
MSS skillstate;
- unsigned targettype:1;
+ unsigned attackable:1;
unsigned steal_flag:1;
unsigned steal_coin_flag:1;
unsigned skillcastcancel:1;
@@ -503,7 +509,7 @@ struct mob_data
short to_x, to_y;
int hp;
int target_id, attacked_id;
- short target_lv;
+ ATK target_lv;
struct walkpath_data walkpath;
unsigned int next_walktime;
unsigned int attackabletime;
@@ -541,19 +547,11 @@ struct mob_data
struct skill_unit_group skillunit[MAX_MOBSKILLUNITGROUP];
struct skill_unit_group_tickset skillunittick[MAX_SKILLUNITGROUPTICKSET];
char npc_event[50];
- unsigned short stats[MOB_LAST]; // [Fate] mob-specific stats
+ // [Fate] mob-specific stats
+ earray<unsigned short, mob_stat, mob_stat::LAST> stats;
short size;
};
-enum
-{ MS_IDLE, MS_WALK, MS_ATTACK, MS_DEAD, MS_DELAY };
-
-enum
-{ NONE_ATTACKABLE, ATTACKABLE };
-
-enum
-{ ATK_LUCKY = 1, ATK_FLEE, ATK_DEF }; // 囲まれペナルティ計算用
-
struct map_data
{
char name[24];
@@ -619,7 +617,7 @@ extern int map_num;
inline
uint8_t read_gatp(struct map_data *m, int x, int y)
{
- return (m->gat[x + y * m->xs]);
+ return m->gat[x + y * m->xs];
}
inline
uint8_t read_gat(int m, int x, int y)
@@ -637,78 +635,12 @@ struct flooritem_data
struct item item_data;
};
-enum
-{
- SP_SPEED, SP_BASEEXP, SP_JOBEXP, SP_KARMA, _sp_manner, SP_HP, SP_MAXHP, SP_SP, // 0-7
- SP_MAXSP, SP_STATUSPOINT, SP_0a, SP_BASELEVEL, SP_SKILLPOINT, SP_STR, SP_AGI, SP_VIT, // 8-15
- SP_INT, SP_DEX, SP_LUK, SP_CLASS, SP_ZENY, SP_SEX, SP_NEXTBASEEXP, SP_NEXTJOBEXP, // 16-23
- SP_WEIGHT, SP_MAXWEIGHT, SP_1a, SP_1b, SP_1c, SP_1d, SP_1e, SP_1f, // 24-31
- SP_USTR, SP_UAGI, SP_UVIT, SP_UINT, SP_UDEX, SP_ULUK, SP_26, SP_27, // 32-39
- SP_28, SP_ATK1, SP_ATK2, SP_MATK1, SP_MATK2, SP_DEF1, SP_DEF2, SP_MDEF1, // 40-47
- SP_MDEF2, SP_HIT, SP_FLEE1, SP_FLEE2, SP_CRITICAL, SP_ASPD, SP_36, SP_JOBLEVEL, // 48-55
- SP_UPPER, SP_PARTNER, SP_CART, SP_FAME, SP_UNBREAKABLE, //56-58
- SP_DEAF = 70,
- SP_GM = 500,
-
- // original 1000-
- SP_ATTACKRANGE = 1000, SP_ATKELE, SP_DEFELE, // 1000-1002
- SP_CASTRATE, SP_MAXHPRATE, SP_MAXSPRATE, SP_SPRATE, // 1003-1006
- SP_ADDELE, SP_ADDRACE, SP_ADDSIZE, SP_SUBELE, SP_SUBRACE, // 1007-1011
- SP_ADDEFF, SP_RESEFF, // 1012-1013
- SP_BASE_ATK, SP_ASPD_RATE, SP_HP_RECOV_RATE, SP_SP_RECOV_RATE, SP_SPEED_RATE, // 1014-1018
- SP_CRITICAL_DEF, SP_NEAR_ATK_DEF, SP_LONG_ATK_DEF, // 1019-1021
- SP_DOUBLE_RATE, SP_DOUBLE_ADD_RATE, SP_MATK, SP_MATK_RATE, // 1022-1025
- SP_IGNORE_DEF_ELE, SP_IGNORE_DEF_RACE, // 1026-1027
- SP_ATK_RATE, SP_SPEED_ADDRATE, SP_ASPD_ADDRATE, // 1028-1030
- SP_MAGIC_ATK_DEF, SP_MISC_ATK_DEF, // 1031-1032
- SP_IGNORE_MDEF_ELE, SP_IGNORE_MDEF_RACE, // 1033-1034
- SP_MAGIC_ADDELE, SP_MAGIC_ADDRACE, SP_MAGIC_SUBRACE, // 1035-1037
- SP_PERFECT_HIT_RATE, SP_PERFECT_HIT_ADD_RATE, SP_CRITICAL_RATE, SP_GET_ZENY_NUM, SP_ADD_GET_ZENY_NUM, // 1038-1042
- SP_ADD_DAMAGE_CLASS, SP_ADD_MAGIC_DAMAGE_CLASS, SP_ADD_DEF_CLASS, SP_ADD_MDEF_CLASS, // 1043-1046
- SP_ADD_MONSTER_DROP_ITEM, SP_DEF_RATIO_ATK_ELE, SP_DEF_RATIO_ATK_RACE, SP_ADD_SPEED, // 1047-1050
- SP_HIT_RATE, SP_FLEE_RATE, SP_FLEE2_RATE, SP_DEF_RATE, SP_DEF2_RATE, SP_MDEF_RATE, SP_MDEF2_RATE, // 1051-1057
- SP_SPLASH_RANGE, SP_SPLASH_ADD_RANGE, SP_AUTOSPELL, SP_HP_DRAIN_RATE, SP_SP_DRAIN_RATE, // 1058-1062
- SP_SHORT_WEAPON_DAMAGE_RETURN, SP_LONG_WEAPON_DAMAGE_RETURN, SP_WEAPON_COMA_ELE, SP_WEAPON_COMA_RACE, // 1063-1066
- SP_ADDEFF2, SP_BREAK_WEAPON_RATE, SP_BREAK_ARMOR_RATE, SP_ADD_STEAL_RATE, // 1067-1070
- SP_MAGIC_DAMAGE_RETURN, SP_RANDOM_ATTACK_INCREASE, SP_ALL_STATS, SP_AGI_VIT, SP_AGI_DEX_STR, SP_PERFECT_HIDE, // 1071-1077
- SP_DISGUISE, // 1077
-
- SP_RESTART_FULL_RECORVER = 2000, SP_NO_CASTCANCEL, SP_NO_SIZEFIX, SP_NO_MAGIC_DAMAGE, SP_NO_WEAPON_DAMAGE, SP_NO_GEMSTONE, // 2000-2005
- SP_NO_CASTCANCEL2, SP_INFINITE_ENDURE, SP_UNBREAKABLE_WEAPON, SP_UNBREAKABLE_ARMOR // 2006-2009
-};
-
-enum
-{
- LOOK_BASE,
- LOOK_HAIR,
- LOOK_WEAPON,
- LOOK_HEAD_BOTTOM,
- LOOK_HEAD_TOP,
- LOOK_HEAD_MID,
- LOOK_HAIR_COLOR,
- LOOK_CLOTHES_COLOR,
- LOOK_SHIELD,
- LOOK_SHOES, /* 9 */
- LOOK_GLOVES,
- LOOK_CAPE,
- LOOK_MISC1,
- LOOK_MISC2,
-};
-
-enum
-{
- EQUIP_SHIELD = 8,
- EQUIP_WEAPON = 9
-};
-
-#define LOOK_LAST LOOK_MISC2
-
struct chat_data
{
struct block_list bl;
char pass[8]; /* password */
- char title[61]; /* room title MAX 60 */
+ char title[61]; /* room title max 60 */
unsigned char limit; /* join limit */
unsigned char trigger;
unsigned char users; /* current users */
@@ -743,25 +675,25 @@ int map_delblock(struct block_list *);
void map_foreachinarea(std::function<void(struct block_list *)>,
int,
int, int, int, int,
- int);
+ BL);
// -- moonsoul (added map_foreachincell)
void map_foreachincell(std::function<void(struct block_list *)>,
int,
int, int,
- int);
+ BL);
void map_foreachinmovearea(std::function<void(struct block_list *)>,
int,
int, int, int, int,
int, int,
- int);
+ BL);
//block関連に追加
int map_count_oncell(int m, int x, int y);
// 一時的object関連
int map_addobject(struct block_list *);
-int map_delobject(int, int type);
-int map_delobjectnofree(int id, int type);
+int map_delobject(int, BL type);
+int map_delobjectnofree(int id, BL type);
void map_foreachobject(std::function<void(struct block_list *)>,
- int);
+ BL);
//
int map_quit(struct map_session_data *);
// npc
diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp
index 3562fa3..027a394 100644
--- a/src/map/map.t.hpp
+++ b/src/map/map.t.hpp
@@ -1,8 +1,11 @@
#ifndef MAP_T_HPP
#define MAP_T_HPP
+#include "../common/mmo.hpp"
#include "../common/utils.hpp"
+namespace e
+{
// [Fate] status.option properties. These are persistent status changes.
// IDs that are not listed are not used in the code (to the best of my knowledge)
enum class Option : uint16_t
@@ -79,10 +82,535 @@ enum class Opt3 : uint16_t
ENUM_BITWISE_OPERATORS(Option)
ENUM_BITWISE_OPERATORS(Opt2)
ENUM_BITWISE_OPERATORS(Opt3)
+}
+using e::Option;
+using e::Opt1;
+using e::Opt2;
+using e::Opt3;
+
+enum class BL : uint8_t
+{
+ NUL,
+#define BL_NUL BL::NUL
+ PC,
+#define BL_PC BL::PC
+ NPC,
+#define BL_NPC BL::NPC
+ MOB,
+#define BL_MOB BL::MOB
+ ITEM,
+#define BL_ITEM BL::ITEM
+ CHAT,
+#define BL_CHAT BL::CHAT
+ SKILL,
+#define BL_SKILL BL::SKILL
+ SPELL,
+#define BL_SPELL BL::SPELL
+};
+enum class NpcSubtype : uint8_t
+{
+ WARP,
+#define WARP NpcSubtype::WARP
+ SHOP,
+#define SHOP NpcSubtype::SHOP
+ SCRIPT,
+#define SCRIPT NpcSubtype::SCRIPT
+ MONS,
+#define MONS NpcSubtype::MONS
+ MESSAGE,
+#define MESSAGE NpcSubtype::MESSAGE
+};
+
+enum class mob_stat
+{
+ LV,
+#define MOB_LV mob_stat::LV
+ MAX_HP,
+#define MOB_MAX_HP mob_stat::MAX_HP
+ STR,
+#define MOB_STR mob_stat::STR
+ AGI,
+#define MOB_AGI mob_stat::AGI
+ VIT,
+#define MOB_VIT mob_stat::VIT
+ INT,
+#define MOB_INT mob_stat::INT
+ DEX,
+#define MOB_DEX mob_stat::DEX
+ LUK,
+#define MOB_LUK mob_stat::LUK
+ // low and high attacks
+ ATK1,
+#define MOB_ATK1 mob_stat::ATK1
+ ATK2,
+#define MOB_ATK2 mob_stat::ATK2
+ // attack delay
+ ADELAY,
+#define MOB_ADELAY mob_stat::ADELAY
+ DEF,
+#define MOB_DEF mob_stat::DEF
+ MDEF,
+#define MOB_MDEF mob_stat::MDEF
+ SPEED,
+#define MOB_SPEED mob_stat::SPEED
+ // These must come last:
+ // [Fate] Encoded as base to 1024: 1024 means 100%
+ XP_BONUS,
+#define MOB_XP_BONUS mob_stat::XP_BONUS
+ LAST,
+#define MOB_LAST mob_stat::LAST
+};
+
+enum class MS : uint8_t
+{
+ IDLE,
+#define MS_IDLE MS::IDLE
+ WALK,
+#define MS_WALK MS::WALK
+ ATTACK,
+#define MS_ATTACK MS::ATTACK
+ DEAD,
+#define MS_DEAD MS::DEAD
+ DELAY,
+#define MS_DELAY MS::DELAY
+};
+
+enum class ATK
+{
+ ZERO = 0,
+
+ LUCKY,
+#define ATK_LUCKY ATK::LUCKY
+ FLEE,
+#define ATK_FLEE ATK::FLEE
+ DEF,
+#define ATK_DEF ATK::DEF
+};
+
+enum class SP : uint16_t
+{
+ SPEED = 0,
+#define SP_SPEED SP::SPEED
+
+ // when used as "no stat"
+ ZERO = 0,
+
+ BASEEXP = 1,
+#define SP_BASEEXP SP::BASEEXP
+ JOBEXP = 2,
+#define SP_JOBEXP SP::JOBEXP
+ KARMA = 3,
+#define SP_KARMA SP::KARMA
+ HP = 5,
+#define SP_HP SP::HP
+ MAXHP = 6,
+#define SP_MAXHP SP::MAXHP
+ SP = 7,
+#define SP_SP SP::SP
+ MAXSP = 8,
+#define SP_MAXSP SP::MAXSP
+ STATUSPOINT = 9,
+#define SP_STATUSPOINT SP::STATUSPOINT
+ BASELEVEL = 11,
+#define SP_BASELEVEL SP::BASELEVEL
+ SKILLPOINT = 12,
+#define SP_SKILLPOINT SP::SKILLPOINT
+ STR = 13,
+#define SP_STR SP::STR
+ AGI = 14,
+#define SP_AGI SP::AGI
+ VIT = 15,
+#define SP_VIT SP::VIT
+ INT = 16,
+#define SP_INT SP::INT
+ DEX = 17,
+#define SP_DEX SP::DEX
+ LUK = 18,
+#define SP_LUK SP::LUK
+ CLASS = 19,
+#define SP_CLASS SP::CLASS
+ ZENY = 20,
+#define SP_ZENY SP::ZENY
+ SEX = 21,
+#define SP_SEX SP::SEX
+ NEXTBASEEXP = 22,
+#define SP_NEXTBASEEXP SP::NEXTBASEEXP
+ NEXTJOBEXP = 23,
+#define SP_NEXTJOBEXP SP::NEXTJOBEXP
+ WEIGHT = 24,
+#define SP_WEIGHT SP::WEIGHT
+ MAXWEIGHT = 25,
+#define SP_MAXWEIGHT SP::MAXWEIGHT
+ USTR = 32,
+#define SP_USTR SP::USTR
+ UAGI = 33,
+#define SP_UAGI SP::UAGI
+ UVIT = 34,
+#define SP_UVIT SP::UVIT
+ UINT = 35,
+#define SP_UINT SP::UINT
+ UDEX = 36,
+#define SP_UDEX SP::UDEX
+ ULUK = 37,
+#define SP_ULUK SP::ULUK
+ ATK1 = 41,
+#define SP_ATK1 SP::ATK1
+ ATK2 = 42,
+#define SP_ATK2 SP::ATK2
+ MATK1 = 43,
+#define SP_MATK1 SP::MATK1
+ MATK2 = 44,
+#define SP_MATK2 SP::MATK2
+ DEF1 = 45,
+#define SP_DEF1 SP::DEF1
+ DEF2 = 46,
+#define SP_DEF2 SP::DEF2
+ MDEF1 = 47,
+#define SP_MDEF1 SP::MDEF1
+ MDEF2 = 48,
+#define SP_MDEF2 SP::MDEF2
+ HIT = 49,
+#define SP_HIT SP::HIT
+ FLEE1 = 50,
+#define SP_FLEE1 SP::FLEE1
+ FLEE2 = 51,
+#define SP_FLEE2 SP::FLEE2
+ CRITICAL = 52,
+#define SP_CRITICAL SP::CRITICAL
+ ASPD = 53,
+#define SP_ASPD SP::ASPD
+ JOBLEVEL = 55,
+#define SP_JOBLEVEL SP::JOBLEVEL
+ UPPER = 56,
+#define SP_UPPER SP::UPPER
+ PARTNER = 57,
+#define SP_PARTNER SP::PARTNER
+ CART = 58,
+#define SP_CART SP::CART
+ FAME = 59,
+#define SP_FAME SP::FAME
+ UNBREAKABLE = 60,
+#define SP_UNBREAKABLE SP::UNBREAKABLE
+ DEAF = 70,
+#define SP_DEAF SP::DEAF
+
+ GM = 500,
+#define SP_GM SP::GM
+
+ ATTACKRANGE = 1000,
+#define SP_ATTACKRANGE SP::ATTACKRANGE
+ ATKELE = 1001,
+#define SP_ATKELE SP::ATKELE
+ DEFELE = 1002,
+#define SP_DEFELE SP::DEFELE
+ CASTRATE = 1003,
+#define SP_CASTRATE SP::CASTRATE
+ MAXHPRATE = 1004,
+#define SP_MAXHPRATE SP::MAXHPRATE
+ MAXSPRATE = 1005,
+#define SP_MAXSPRATE SP::MAXSPRATE
+ SPRATE = 1006,
+#define SP_SPRATE SP::SPRATE
+ ADDELE = 1007,
+#define SP_ADDELE SP::ADDELE
+ ADDRACE = 1008,
+#define SP_ADDRACE SP::ADDRACE
+ ADDSIZE = 1009,
+#define SP_ADDSIZE SP::ADDSIZE
+ SUBELE = 1010,
+#define SP_SUBELE SP::SUBELE
+ SUBRACE = 1011,
+#define SP_SUBRACE SP::SUBRACE
+ ADDEFF = 1012,
+#define SP_ADDEFF SP::ADDEFF
+ RESEFF = 1013,
+#define SP_RESEFF SP::RESEFF
+ BASE_ATK = 1014,
+#define SP_BASE_ATK SP::BASE_ATK
+ ASPD_RATE = 1015,
+#define SP_ASPD_RATE SP::ASPD_RATE
+ HP_RECOV_RATE = 1016,
+#define SP_HP_RECOV_RATE SP::HP_RECOV_RATE
+ SP_RECOV_RATE = 1017,
+#define SP_SP_RECOV_RATE SP::SP_RECOV_RATE
+ SPEED_RATE = 1018,
+#define SP_SPEED_RATE SP::SPEED_RATE
+ CRITICAL_DEF = 1019,
+#define SP_CRITICAL_DEF SP::CRITICAL_DEF
+ NEAR_ATK_DEF = 1020,
+#define SP_NEAR_ATK_DEF SP::NEAR_ATK_DEF
+ LONG_ATK_DEF = 1021,
+#define SP_LONG_ATK_DEF SP::LONG_ATK_DEF
+ DOUBLE_RATE = 1022,
+#define SP_DOUBLE_RATE SP::DOUBLE_RATE
+ DOUBLE_ADD_RATE = 1023,
+#define SP_DOUBLE_ADD_RATE SP::DOUBLE_ADD_RATE
+ MATK = 1024,
+#define SP_MATK SP::MATK
+ MATK_RATE = 1025,
+#define SP_MATK_RATE SP::MATK_RATE
+ IGNORE_DEF_ELE = 1026,
+#define SP_IGNORE_DEF_ELE SP::IGNORE_DEF_ELE
+ IGNORE_DEF_RACE = 1027,
+#define SP_IGNORE_DEF_RACE SP::IGNORE_DEF_RACE
+ ATK_RATE = 1028,
+#define SP_ATK_RATE SP::ATK_RATE
+ SPEED_ADDRATE = 1029,
+#define SP_SPEED_ADDRATE SP::SPEED_ADDRATE
+ ASPD_ADDRATE = 1030,
+#define SP_ASPD_ADDRATE SP::ASPD_ADDRATE
+ MAGIC_ATK_DEF = 1031,
+#define SP_MAGIC_ATK_DEF SP::MAGIC_ATK_DEF
+ MISC_ATK_DEF = 1032,
+#define SP_MISC_ATK_DEF SP::MISC_ATK_DEF
+ IGNORE_MDEF_ELE = 1033,
+#define SP_IGNORE_MDEF_ELE SP::IGNORE_MDEF_ELE
+ IGNORE_MDEF_RACE = 1034,
+#define SP_IGNORE_MDEF_RACE SP::IGNORE_MDEF_RACE
+ MAGIC_ADDELE = 1035,
+#define SP_MAGIC_ADDELE SP::MAGIC_ADDELE
+ MAGIC_ADDRACE = 1036,
+#define SP_MAGIC_ADDRACE SP::MAGIC_ADDRACE
+ MAGIC_SUBRACE = 1037,
+#define SP_MAGIC_SUBRACE SP::MAGIC_SUBRACE
+ PERFECT_HIT_RATE = 1038,
+#define SP_PERFECT_HIT_RATE SP::PERFECT_HIT_RATE
+ PERFECT_HIT_ADD_RATE = 1039,
+#define SP_PERFECT_HIT_ADD_RATE SP::PERFECT_HIT_ADD_RATE
+ CRITICAL_RATE = 1040,
+#define SP_CRITICAL_RATE SP::CRITICAL_RATE
+ GET_ZENY_NUM = 1041,
+#define SP_GET_ZENY_NUM SP::GET_ZENY_NUM
+ ADD_GET_ZENY_NUM = 1042,
+#define SP_ADD_GET_ZENY_NUM SP::ADD_GET_ZENY_NUM
+ ADD_DAMAGE_CLASS = 1043,
+#define SP_ADD_DAMAGE_CLASS SP::ADD_DAMAGE_CLASS
+ ADD_MAGIC_DAMAGE_CLASS = 1044,
+#define SP_ADD_MAGIC_DAMAGE_CLASS SP::ADD_MAGIC_DAMAGE_CLASS
+ ADD_DEF_CLASS = 1045,
+#define SP_ADD_DEF_CLASS SP::ADD_DEF_CLASS
+ ADD_MDEF_CLASS = 1046,
+#define SP_ADD_MDEF_CLASS SP::ADD_MDEF_CLASS
+ ADD_MONSTER_DROP_ITEM = 1047,
+#define SP_ADD_MONSTER_DROP_ITEM SP::ADD_MONSTER_DROP_ITEM
+ DEF_RATIO_ATK_ELE = 1048,
+#define SP_DEF_RATIO_ATK_ELE SP::DEF_RATIO_ATK_ELE
+ DEF_RATIO_ATK_RACE = 1049,
+#define SP_DEF_RATIO_ATK_RACE SP::DEF_RATIO_ATK_RACE
+ ADD_SPEED = 1050,
+#define SP_ADD_SPEED SP::ADD_SPEED
+ HIT_RATE = 1051,
+#define SP_HIT_RATE SP::HIT_RATE
+ FLEE_RATE = 1052,
+#define SP_FLEE_RATE SP::FLEE_RATE
+ FLEE2_RATE = 1053,
+#define SP_FLEE2_RATE SP::FLEE2_RATE
+ DEF_RATE = 1054,
+#define SP_DEF_RATE SP::DEF_RATE
+ DEF2_RATE = 1055,
+#define SP_DEF2_RATE SP::DEF2_RATE
+ MDEF_RATE = 1056,
+#define SP_MDEF_RATE SP::MDEF_RATE
+ MDEF2_RATE = 1057,
+#define SP_MDEF2_RATE SP::MDEF2_RATE
+ SPLASH_RANGE = 1058,
+#define SP_SPLASH_RANGE SP::SPLASH_RANGE
+ SPLASH_ADD_RANGE = 1059,
+#define SP_SPLASH_ADD_RANGE SP::SPLASH_ADD_RANGE
+ AUTOSPELL = 1060,
+#define SP_AUTOSPELL SP::AUTOSPELL
+ HP_DRAIN_RATE = 1061,
+#define SP_HP_DRAIN_RATE SP::HP_DRAIN_RATE
+ SP_DRAIN_RATE = 1062,
+#define SP_SP_DRAIN_RATE SP::SP_DRAIN_RATE
+ SHORT_WEAPON_DAMAGE_RETURN = 1063,
+#define SP_SHORT_WEAPON_DAMAGE_RETURN SP::SHORT_WEAPON_DAMAGE_RETURN
+ LONG_WEAPON_DAMAGE_RETURN = 1064,
+#define SP_LONG_WEAPON_DAMAGE_RETURN SP::LONG_WEAPON_DAMAGE_RETURN
+ WEAPON_COMA_ELE = 1065,
+#define SP_WEAPON_COMA_ELE SP::WEAPON_COMA_ELE
+ WEAPON_COMA_RACE = 1066,
+#define SP_WEAPON_COMA_RACE SP::WEAPON_COMA_RACE
+ ADDEFF2 = 1067,
+#define SP_ADDEFF2 SP::ADDEFF2
+ BREAK_WEAPON_RATE = 1068,
+#define SP_BREAK_WEAPON_RATE SP::BREAK_WEAPON_RATE
+ BREAK_ARMOR_RATE = 1069,
+#define SP_BREAK_ARMOR_RATE SP::BREAK_ARMOR_RATE
+ ADD_STEAL_RATE = 1070,
+#define SP_ADD_STEAL_RATE SP::ADD_STEAL_RATE
+ MAGIC_DAMAGE_RETURN = 1071,
+#define SP_MAGIC_DAMAGE_RETURN SP::MAGIC_DAMAGE_RETURN
+ RANDOM_ATTACK_INCREASE = 1072,
+#define SP_RANDOM_ATTACK_INCREASE SP::RANDOM_ATTACK_INCREASE
+ ALL_STATS = 1073,
+#define SP_ALL_STATS SP::ALL_STATS
+ AGI_VIT = 1074,
+#define SP_AGI_VIT SP::AGI_VIT
+ AGI_DEX_STR = 1075,
+#define SP_AGI_DEX_STR SP::AGI_DEX_STR
+ PERFECT_HIDE = 1076,
+#define SP_PERFECT_HIDE SP::PERFECT_HIDE
+ DISGUISE = 1077,
+#define SP_DISGUISE SP::DISGUISE
+
+ RESTART_FULL_RECORVER = 2000,
+#define SP_RESTART_FULL_RECORVER SP::RESTART_FULL_RECORVER
+ NO_CASTCANCEL = 2001,
+#define SP_NO_CASTCANCEL SP::NO_CASTCANCEL
+ NO_SIZEFIX = 2002,
+#define SP_NO_SIZEFIX SP::NO_SIZEFIX
+ NO_MAGIC_DAMAGE = 2003,
+#define SP_NO_MAGIC_DAMAGE SP::NO_MAGIC_DAMAGE
+ NO_WEAPON_DAMAGE = 2004,
+#define SP_NO_WEAPON_DAMAGE SP::NO_WEAPON_DAMAGE
+ NO_GEMSTONE = 2005,
+#define SP_NO_GEMSTONE SP::NO_GEMSTONE
+ NO_CASTCANCEL2 = 2006,
+#define SP_NO_CASTCANCEL2 SP::NO_CASTCANCEL2
+ INFINITE_ENDURE = 2007,
+#define SP_INFINITE_ENDURE SP::INFINITE_ENDURE
+ UNBREAKABLE_WEAPON = 2008,
+#define SP_UNBREAKABLE_WEAPON SP::UNBREAKABLE_WEAPON
+ SP_UNBREAKABLE_ARMOR = 2009,
+#define SP_UNBREAKABLE_ARMOR SP::UNBREAKABLE_ARMOR
+};
+
+constexpr
+SP attr_to_sp(ATTR attr)
+{
+ return SP(uint16_t(attr) + uint16_t(SP::STR));
+}
+
+constexpr
+ATTR sp_to_attr(SP sp)
+{
+ return ATTR(uint16_t(sp) - uint16_t(SP::STR));
+}
+
+constexpr
+SP attr_to_usp(ATTR attr)
+{
+ return SP(uint16_t(attr) + uint16_t(SP::USTR));
+}
+
+constexpr
+ATTR usp_to_attr(SP sp)
+{
+ return ATTR(uint16_t(sp) - uint16_t(SP::USTR));
+}
+
+constexpr
+SP sp_to_usp(SP sp)
+{
+ return attr_to_usp(sp_to_attr(sp));
+};
+
+constexpr
+SP usp_to_sp(SP sp)
+{
+ return attr_to_sp(usp_to_attr(sp));
+};
+
+
+enum class LOOK : uint8_t
+{
+ BASE = 0,
+#define LOOK_BASE LOOK::BASE
+ HAIR = 1,
+#define LOOK_HAIR LOOK::HAIR
+ WEAPON = 2,
+#define LOOK_WEAPON LOOK::WEAPON
+ HEAD_BOTTOM = 3,
+#define LOOK_HEAD_BOTTOM LOOK::HEAD_BOTTOM
+ HEAD_TOP = 4,
+#define LOOK_HEAD_TOP LOOK::HEAD_TOP
+ HEAD_MID = 5,
+#define LOOK_HEAD_MID LOOK::HEAD_MID
+ HAIR_COLOR = 6,
+#define LOOK_HAIR_COLOR LOOK::HAIR_COLOR
+ CLOTHES_COLOR = 7,
+#define LOOK_CLOTHES_COLOR LOOK::CLOTHES_COLOR
+ SHIELD = 8,
+#define LOOK_SHIELD LOOK::SHIELD
+ SHOES = 9,
+#define LOOK_SHOES LOOK::SHOES
+ GLOVES = 10,
+#define LOOK_GLOVES LOOK::GLOVES
+ CAPE = 11,
+#define LOOK_CAPE LOOK::CAPE
+ MISC1 = 12,
+#define LOOK_MISC1 LOOK::MISC1
+ MISC2 = 13,
+#define LOOK_MISC2 LOOK::MISC2
+ COUNT,
+};
+
+enum class EQUIP
+{
+ NONE = -1,
+ MISC2 = 0,
+ CAPE = 1,
+ SHOES = 2,
+ GLOVES = 3,
+ LEGS = 4, // also called "head bottom"
+ TORSO = 5, // also called "head middle"
+ HAT = 6, // also called "head top"
+ MISC1 = 7,
+ SHIELD = 8,
+#define EQUIP_SHIELD EQUIP::SHIELD
+ WEAPON = 9,
+#define EQUIP_WEAPON EQUIP::WEAPON
+ ARROW = 10,
+ COUNT = 11,
+};
+
+constexpr
+EQUIP EQUIPs[] =
+{
+ EQUIP::MISC2,
+ EQUIP::CAPE,
+ EQUIP::SHOES,
+ EQUIP::GLOVES,
+ EQUIP::LEGS,
+ EQUIP::TORSO,
+ EQUIP::HAT,
+ EQUIP::MISC1,
+ EQUIP::SHIELD,
+ EQUIP::WEAPON,
+ EQUIP::ARROW,
+};
+
+constexpr
+EQUIP EQUIPs_noarrow[] =
+{
+ EQUIP::MISC2,
+ EQUIP::CAPE,
+ EQUIP::SHOES,
+ EQUIP::GLOVES,
+ EQUIP::LEGS,
+ EQUIP::TORSO,
+ EQUIP::HAT,
+ EQUIP::MISC1,
+ EQUIP::SHIELD,
+ EQUIP::WEAPON,
+};
+
+enum class ItemType : uint8_t
+{
+ USE = 0, // in eA, healing only
+ _1 = 1, // unused
+ _2 = 2, // in eA, other usable items
+ JUNK = 3, // "useless" items (e.g. quests)
+ WEAPON = 4, // all weapons
+ ARMOR = 5, // all other equipment
+ _6 = 6, // in eA, card
+ _7 = 7, // in eA, pet egg
+ _8 = 8, // in eA, pet equipment
+ _9 = 9, // unused
+ ARROW = 10, // ammo
+ _11 = 11, // in eA, delayed use (special script)
+};
-enum
-{ BL_NUL, BL_PC, BL_NPC, BL_MOB, BL_ITEM, BL_CHAT, BL_SKILL, BL_SPELL };
-enum
-{ WARP, SHOP, SCRIPT, MONS, MESSAGE };
#endif // MAP_T_HPP
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index 064fba4..abd6260 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -122,7 +122,8 @@ int mob_spawn_dataset(struct mob_data *md, const char *mobname, int mob_class)
// For one 256th of change, we give out that many 1024th fractions of XP change
// (i.e., 1024 means a 100% XP increase for a single point of adjustment, 4 means 100% XP bonus for doubling the value)
static
-int mutation_value[MOB_XP_BONUS] = {
+earray<int, mob_stat, MOB_XP_BONUS> mutation_value =
+{
2, // MOB_LV
3, // MOB_MAX_HP
1, // MOB_STR
@@ -142,7 +143,8 @@ int mutation_value[MOB_XP_BONUS] = {
// The mutation scale indicates how far `up' we can go, with 256 indicating 100% Note that this may stack with multiple
// calls to `mutate'.
static
-int mutation_scale[MOB_XP_BONUS] = {
+earray<int, mob_stat, MOB_XP_BONUS> mutation_scale =
+{
16, // MOB_LV
256, // MOB_MAX_HP
32, // MOB_STR
@@ -167,7 +169,8 @@ int mutation_scale[MOB_XP_BONUS] = {
// (3) third, compute the percentage stat change relative to mutation_base (p1)
// (4) fourth, compute the XP mofication based on the smaller of (p0, p1).
static
-int mutation_base[MOB_XP_BONUS] = {
+earray<int, mob_stat, MOB_XP_BONUS> mutation_base =
+{
30, // MOB_LV
-1, // MOB_MAX_HP
20, // MOB_STR
@@ -188,8 +191,9 @@ int mutation_base[MOB_XP_BONUS] = {
* Mutates a MOB. For large `direction' values, calling this multiple times will give bigger XP boni.
*----------------------------------------
*/
+// intensity: positive: strengthen, negative: weaken. 256 = 100%.
static
-void mob_mutate(struct mob_data *md, int stat, int intensity) // intensity: positive: strengthen, negative: weaken. 256 = 100%.
+void mob_mutate(struct mob_data *md, mob_stat stat, int intensity)
{
int old_stat;
int new_stat;
@@ -197,7 +201,7 @@ void mob_mutate(struct mob_data *md, int stat, int intensity) // intensity: po
const int mut_base = mutation_base[stat];
int sign = 1;
- if (!md || stat < 0 || stat >= MOB_XP_BONUS || intensity == 0)
+ if (!md || stat >= MOB_XP_BONUS || intensity == 0)
return;
while (intensity > mutation_scale[stat])
@@ -273,13 +277,13 @@ int mob_gen_exp(struct mob_db *mob)
if (100 == mob->def)
mod_def = 1;
double effective_hp =
- ((50 - mob->luk) * mob->max_hp / 50.0) +
- (2 * mob->luk * mob->max_hp / mod_def);
+ ((50 - mob->attrs[ATTR::LUK]) * mob->max_hp / 50.0) +
+ (2 * mob->attrs[ATTR::LUK] * mob->max_hp / mod_def);
double attack_factor =
- (mob->atk1 + mob->atk2 + mob->str / 3.0 + mob->dex / 2.0 +
- mob->luk) * (1872.0 / mob->adelay) / 4;
+ (mob->atk1 + mob->atk2 + mob->attrs[ATTR::STR] / 3.0 + mob->attrs[ATTR::DEX] / 2.0 +
+ mob->attrs[ATTR::LUK]) * (1872.0 / mob->adelay) / 4;
double dodge_factor =
- pow(mob->lv + mob->agi + mob->luk / 2.0, 4.0 / 3.0);
+ pow(mob->lv + mob->attrs[ATTR::AGI] + mob->attrs[ATTR::LUK] / 2.0, 4.0 / 3.0);
double persuit_factor =
(3 + mob->range) * (mob->mode % 2) * 1000 / mob->speed;
double aggression_factor = (mob->mode & 4) == 4 ? 10.0 / 9.0 : 1.0;
@@ -305,12 +309,12 @@ void mob_init(struct mob_data *md)
md->stats[MOB_LV] = mob_db[mob_class].lv;
md->stats[MOB_MAX_HP] = mob_db[mob_class].max_hp;
- md->stats[MOB_STR] = mob_db[mob_class].str;
- md->stats[MOB_AGI] = mob_db[mob_class].agi;
- md->stats[MOB_VIT] = mob_db[mob_class].vit;
- md->stats[MOB_INT] = mob_db[mob_class].int_;
- md->stats[MOB_DEX] = mob_db[mob_class].dex;
- md->stats[MOB_LUK] = mob_db[mob_class].luk;
+ md->stats[MOB_STR] = mob_db[mob_class].attrs[ATTR::STR];
+ md->stats[MOB_AGI] = mob_db[mob_class].attrs[ATTR::AGI];
+ md->stats[MOB_VIT] = mob_db[mob_class].attrs[ATTR::VIT];
+ md->stats[MOB_INT] = mob_db[mob_class].attrs[ATTR::INT];
+ md->stats[MOB_DEX] = mob_db[mob_class].attrs[ATTR::DEX];
+ md->stats[MOB_LUK] = mob_db[mob_class].attrs[ATTR::LUK];
md->stats[MOB_ATK1] = mob_db[mob_class].atk1;
md->stats[MOB_ATK2] = mob_db[mob_class].atk2;
md->stats[MOB_ADELAY] = mob_db[mob_class].adelay;
@@ -321,10 +325,11 @@ void mob_init(struct mob_data *md)
for (i = 0; i < mutations_nr; i++)
{
- int stat_nr = MRAND(MOB_XP_BONUS + 1);
+ mob_stat stat_nr = mob_stat(MRAND(unsigned(MOB_LAST)));
int strength;
- if (stat_nr >= MOB_XP_BONUS)
+ // double chance to modify hp
+ if (stat_nr == MOB_XP_BONUS)
stat_nr = MOB_MAX_HP;
strength =
@@ -783,7 +788,7 @@ int mob_check_attack(struct mob_data *md)
if ((tbl = map_id2bl(md->target_id)) == NULL)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
@@ -801,7 +806,7 @@ int mob_check_attack(struct mob_data *md)
|| distance(md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
}
@@ -811,7 +816,7 @@ int mob_check_attack(struct mob_data *md)
|| distance(md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
}
@@ -825,7 +830,7 @@ int mob_check_attack(struct mob_data *md)
if (!(mode & 0x80))
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
if (tsd && !(mode & 0x20) && (tsd->sc_data[SC_TRICKDEAD].timer != -1 ||
@@ -834,7 +839,7 @@ int mob_check_attack(struct mob_data *md)
&& race != 4 && race != 6)))
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
return 0;
}
@@ -852,7 +857,7 @@ void mob_ancillary_attack(struct block_list *bl,
struct block_list *mdbl, struct block_list *tbl, unsigned int tick)
{
if (bl != tbl)
- battle_weapon_attack(mdbl, bl, tick, 0);
+ battle_weapon_attack(mdbl, bl, tick, BCT_ZERO);
}
/*==========================================
@@ -881,7 +886,7 @@ int mob_attack(struct mob_data *md, unsigned int tick, int)
if (mobskill_use(md, tick, MSC::NEVER_EQUAL))
return 0;
- md->target_lv = battle_weapon_attack(&md->bl, tbl, tick, 0);
+ md->target_lv = battle_weapon_attack(&md->bl, tbl, tick, BCT_ZERO);
// If you are reading this, please note:
// it is highly platform-specific that this even works at all.
int radius = battle_config.mob_splash_radius;
@@ -920,7 +925,7 @@ void mob_stopattacked(struct map_session_data *sd, int id)
* The timer in which the mob's states changes
*------------------------------------------
*/
-int mob_changestate(struct mob_data *md, int state, int type)
+int mob_changestate(struct mob_data *md, MS state, int type)
{
unsigned int tick;
int i;
@@ -982,7 +987,7 @@ int mob_changestate(struct mob_data *md, int state, int type)
delete_timer(md->deletetimer, mob_timer_delete);
md->deletetimer = -1;
md->hp = md->target_id = md->attacked_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
break;
}
@@ -1005,12 +1010,12 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
return;
}
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (!bl || bl->type == BL_NUL || bl->type != BL_MOB)
return;
nullpo_retv(md = (struct mob_data *) bl);
- if (!md->bl.type || md->bl.type != BL_MOB)
+ if (md->bl.type == BL_NUL || md->bl.type != BL_MOB)
return;
if (md->timer != tid)
@@ -1038,7 +1043,8 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
break;
default:
if (battle_config.error_log == 1)
- printf("mob_timer : %d ?\n", md->state.state);
+ printf("mob_timer : %d ?\n",
+ uint8_t(md->state.state));
break;
}
map_freeblock_unlock();
@@ -1122,7 +1128,7 @@ int mob_setdelayspawn(int id)
if ((bl = map_id2bl(id)) == NULL)
return -1;
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (!bl || bl->type == BL_NUL || bl->type != BL_MOB)
return -1;
nullpo_retr(-1, md = (struct mob_data *) bl);
@@ -1177,12 +1183,12 @@ int mob_spawn(int id)
nullpo_retr(-1, bl = map_id2bl(id));
- if (!bl || !bl->type || bl->type != BL_MOB)
+ if (!bl || bl->type == BL_NUL || bl->type != BL_MOB)
return -1;
nullpo_retr(-1, md = (struct mob_data *) bl);
- if (!md || !md->bl.type || md->bl.type != BL_MOB)
+ if (!md || md->bl.type == BL_NUL || md->bl.type != BL_MOB)
return -1;
md->last_spawntime = tick;
@@ -1314,7 +1320,7 @@ int distance(int x0, int y0, int x1, int y1)
int mob_stopattack(struct mob_data *md)
{
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->attacked_id = 0;
return 0;
}
@@ -1456,7 +1462,7 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist)
return 0;
}
// Nothing will be carried out if there is no mind of changing TAGE by TAGE ending.
- if ((md->target_id > 0 && md->state.targettype == ATTACKABLE)
+ if ((md->target_id > 0 && md->state.attackable)
&& (!(mode & 0x04) || MRAND(100) > 25))
return 0;
@@ -1479,9 +1485,9 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist)
md->target_id = bl->id; // Since there was no disturbance, it locks on to target.
if (bl->type == BL_PC || bl->type == BL_MOB)
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
else
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->min_chase = dist + 13;
if (md->min_chase > 26)
md->min_chase = 26;
@@ -1543,7 +1549,7 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl,
MRAND(1000) < 1000 / (++(*pcc)))
{ // 範囲内PCで等確率にする
smd->target_id = tsd->bl.id;
- smd->state.targettype = ATTACKABLE;
+ smd->state.attackable = true;
smd->min_chase = 13;
}
}
@@ -1558,7 +1564,7 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl,
MRAND(1000) < 1000 / (++(*pcc)))
{ // 範囲内で等確率にする
smd->target_id = bl->id;
- smd->state.targettype = ATTACKABLE;
+ smd->state.attackable = true;
smd->min_chase = 13;
}
}
@@ -1598,7 +1604,7 @@ void mob_ai_sub_hard_lootsearch(struct block_list *bl, struct mob_data *md, int
MRAND(1000) < 1000 / (++(*itc)))
{ // It is made a probability, such as within the limits PC.
md->target_id = bl->id;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->min_chase = 13;
}
}
@@ -1620,11 +1626,11 @@ void mob_ai_sub_hard_linksearch(struct block_list *bl, struct mob_data *md, stru
nullpo_retv(target);
// same family free in a range at a link monster -- it will be made to lock if MOB is
-/* if ((md->target_id > 0 && md->state.targettype == ATTACKABLE) && mob_db[md->mob_class].mode&0x08){
- if ( tmd->mob_class==md->mob_class && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE) && tmd->bl.m == md->bl.m){
+/* if ((md->target_id > 0 && md->state.attackable) && mob_db[md->mob_class].mode&0x08){
+ if ( tmd->mob_class==md->mob_class && (!tmd->target_id || !md->state.attackable) && tmd->bl.m == md->bl.m){
if ( mob_can_reach(tmd,target,12) ){ // Reachability judging
tmd->target_id=md->target_id;
- tmd->state.targettype = ATTACKABLE;
+ tmd->state.attackable = true;
tmd->min_chase=13;
}
}
@@ -1632,12 +1638,12 @@ void mob_ai_sub_hard_linksearch(struct block_list *bl, struct mob_data *md, stru
if (md->attacked_id > 0 && mob_db[md->mob_class].mode & 0x08)
{
if (tmd->mob_class == md->mob_class && tmd->bl.m == md->bl.m
- && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE))
+ && (!tmd->target_id || !md->state.attackable))
{
if (mob_can_reach(tmd, target, 12))
{ // Reachability judging
tmd->target_id = md->attacked_id;
- tmd->state.targettype = ATTACKABLE;
+ tmd->state.attackable = true;
tmd->min_chase = 13;
}
}
@@ -1687,7 +1693,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
}
// Although there is the master, since it is somewhat far, it approaches.
- if ((!md->target_id || md->state.targettype == NONE_ATTACKABLE)
+ if ((!md->target_id || !md->state.attackable)
&& mob_can_move(md)
&& (md->walkpath.path_pos >= md->walkpath.path_len
|| md->walkpath.path_len == 0) && md->master_dist < 15)
@@ -1746,8 +1752,8 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
}
// There is the master, the master locks a target and he does not lock.
- if ((mmd->target_id > 0 && mmd->state.targettype == ATTACKABLE)
- && (!md->target_id || md->state.targettype == NONE_ATTACKABLE))
+ if ((mmd->target_id > 0 && mmd->state.attackable)
+ && (!md->target_id || !md->state.attackable))
{
struct map_session_data *sd = map_id2sd(mmd->target_id);
if (sd != NULL && !pc_isdead(sd) && sd->invincible_timer == -1
@@ -1762,7 +1768,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
{ // 妨害がないか判定
md->target_id = sd->bl.id;
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
md->min_chase =
5 + distance(md->bl.x, md->bl.y, sd->bl.x, sd->bl.y);
md->state.master_check = 1;
@@ -1771,7 +1777,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
}
// There is the master, the master locks a target and he does not lock.
-/* if ((md->target_id>0 && mmd->state.targettype == ATTACKABLE) && (!mmd->target_id || mmd->state.targettype == NONE_ATTACKABLE) ){
+/* if ((md->target_id>0 && mmd->state.attackable) && (!mmd->target_id || !mmd->state.attackable) ){
struct map_session_data *sd=map_id2sd(md->target_id);
if (sd!=NULL && !pc_isdead(sd) && sd->invincible_timer == -1 && !pc_isinvisible(sd)){
@@ -1782,7 +1788,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
) ){ // It judges whether there is any disturbance.
mmd->target_id=sd->bl.id;
- mmd->state.targettype = ATTACKABLE;
+ mmd->state.attackable = true;
mmd->min_chase=5+distance(mmd->bl.x,mmd->bl.y,sd->bl.x,sd->bl.y);
}
}
@@ -1801,7 +1807,7 @@ int mob_unlocktarget(struct mob_data *md, int tick)
nullpo_ret(md);
md->target_id = 0;
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->state.skillstate = MSS_IDLE;
md->next_walktime = tick + MPRAND(3000, 3000);
return 0;
@@ -1924,7 +1930,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
// It checks to see it was attacked first (if active, it is target change at 25% of probability).
if (mode > 0 && md->attacked_id > 0
- && (!md->target_id || md->state.targettype == NONE_ATTACKABLE
+ && (!md->target_id || !md->state.attackable
|| (mode & 0x04 && MRAND(100) < 25)))
{
struct block_list *abl = map_id2bl(md->attacked_id);
@@ -1942,7 +1948,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
else
{
md->target_id = md->attacked_id; // set target
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
attack_type = 1;
md->attacked_id = 0;
md->min_chase = dist + 13;
@@ -1958,7 +1964,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
mob_ai_sub_hard_slavemob(md, tick);
// アクティヴモンスターの策敵 (?? of a bitter taste TIVU monster)
- if ((!md->target_id || md->state.targettype == NONE_ATTACKABLE)
+ if ((!md->target_id || !md->state.attackable)
&& mode & 0x04 && !md->state.master_check
&& battle_config.monster_active_enable == 1)
{
@@ -1967,7 +1973,8 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
{
map_foreachinarea(std::bind(mob_ai_sub_hard_activesearch, ph::_1, md, &i),
md->bl.m, md->bl.x - AREA_SIZE * 2, md->bl.y - AREA_SIZE * 2,
- md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2, 0);
+ md->bl.x + AREA_SIZE * 2, md->bl.y + AREA_SIZE * 2,
+ BL_NUL);
}
else
{
@@ -2247,7 +2254,7 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick)
if (md == NULL)
return;
- if (!md->bl.type || md->bl.type != BL_MOB)
+ if (md->bl.type == BL_NUL || md->bl.type != BL_MOB)
return;
if (DIFF_TICK(tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10)
@@ -2334,7 +2341,7 @@ void mob_delay_item_drop(timer_id, tick_t, custom_id_t id, custom_data_t)
{
struct delay_item_drop *ditem;
struct item temp_item;
- int flag;
+ PickupFail flag;
nullpo_retv(ditem = (struct delay_item_drop *) id);
@@ -2347,7 +2354,8 @@ void mob_delay_item_drop(timer_id, tick_t, custom_id_t id, custom_data_t)
{
if (ditem->first_sd
&& (flag =
- pc_additem(ditem->first_sd, &temp_item, ditem->amount)))
+ pc_additem(ditem->first_sd, &temp_item, ditem->amount))
+ != PickupFail::OKAY)
{
clif_additem(ditem->first_sd, 0, 0, flag);
map_addflooritem(&temp_item, 1, ditem->m, ditem->x, ditem->y,
@@ -2372,7 +2380,7 @@ static
void mob_delay_item_drop2(timer_id, tick_t, custom_id_t id, custom_data_t)
{
struct delay_item_drop2 *ditem;
- int flag;
+ PickupFail flag;
nullpo_retv(ditem = (struct delay_item_drop2 *) id);
@@ -2381,7 +2389,8 @@ void mob_delay_item_drop2(timer_id, tick_t, custom_id_t id, custom_data_t)
if (ditem->first_sd
&& (flag =
pc_additem(ditem->first_sd, &ditem->item_data,
- ditem->item_data.amount)))
+ ditem->item_data.amount))
+ != PickupFail::OKAY)
{
clif_additem(ditem->first_sd, 0, 0, flag);
map_addflooritem(&ditem->item_data, ditem->item_data.amount,
@@ -2499,7 +2508,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
NULL;
double tdmg, temp;
struct item item;
- int ret;
+ PickupFail ret;
int skill, sp;
nullpo_ret(md); //srcはNULLで呼ばれる場合もあるので、他でチェック
@@ -2821,7 +2830,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
if (drop_rate <= 0 && battle_config.drop_rate0item == 1)
drop_rate = 1;
if (battle_config.drops_by_luk > 0 && sd && md)
- drop_rate += (sd->status.luk * battle_config.drops_by_luk) / 100; // drops affected by luk [Valaris]
+ drop_rate += (sd->status.attrs[ATTR::LUK] * battle_config.drops_by_luk) / 100; // drops affected by luk [Valaris]
if (sd && md && battle_config.pk_mode == 1
&& (mob_db[md->mob_class].lv - sd->status.base_level >= 20))
drop_rate *= 1.25; // pk_mode increase drops if 20 level difference [Valaris]
@@ -2932,7 +2941,8 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
map_addflooritem(&item, 1, mvp_sd->bl.m, mvp_sd->bl.x,
mvp_sd->bl.y, mvp_sd, second_sd,
third_sd, 1);
- else if ((ret = pc_additem(mvp_sd, &item, 1)))
+ else if ((ret = pc_additem(mvp_sd, &item, 1))
+ != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, ret);
map_addflooritem(&item, 1, mvp_sd->bl.m, mvp_sd->bl.x,
@@ -3168,7 +3178,7 @@ int mob_warp(struct mob_data *md, int m, int x, int y, int type)
}
md->target_id = 0; // タゲを解除する
- md->state.targettype = NONE_ATTACKABLE;
+ md->state.attackable = false;
md->attacked_id = 0;
md->state.skillstate = MSS_IDLE;
mob_changestate(md, MS_IDLE, 0);
@@ -3307,7 +3317,8 @@ int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag)
*------------------------------------------
*/
static
-void mob_counttargeted_sub(struct block_list *bl, int id, int *c, struct block_list *src, int target_lv)
+void mob_counttargeted_sub(struct block_list *bl,
+ int id, int *c, struct block_list *src, ATK target_lv)
{
nullpo_retv(bl);
nullpo_retv(c);
@@ -3335,7 +3346,7 @@ void mob_counttargeted_sub(struct block_list *bl, int id, int *c, struct block_l
*------------------------------------------
*/
int mob_counttargeted(struct mob_data *md, struct block_list *src,
- int target_lv)
+ ATK target_lv)
{
int c = 0;
@@ -3343,7 +3354,8 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src,
map_foreachinarea(std::bind(mob_counttargeted_sub, ph::_1, md->bl.id, &c, src, target_lv),
md->bl.m, md->bl.x - AREA_SIZE, md->bl.y - AREA_SIZE,
- md->bl.x + AREA_SIZE, md->bl.y + AREA_SIZE, 0);
+ md->bl.x + AREA_SIZE, md->bl.y + AREA_SIZE,
+ BL_NUL);
return c;
}
@@ -3460,7 +3472,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
case 0:
case 2:
skill_castend_damage_id(&md->bl, bl, md->skillid, md->skilllv,
- tick, 0);
+ tick, BCT_ZERO);
break;
case 1: // 支援系
if (!mob_db[md->mob_class].skill[md->skillidx].val[0] &&
@@ -3469,10 +3481,10 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
&& battle_check_undead(battle_get_race(bl),
battle_get_elem_type(bl)))
skill_castend_damage_id(&md->bl, bl, md->skillid,
- md->skilllv, tick, 0);
+ md->skilllv, tick, BCT_ZERO);
else
skill_castend_nodamage_id(&md->bl, bl, md->skillid,
- md->skilllv, tick, 0);
+ md->skilllv, tick, BCT_ZERO);
break;
}
}
@@ -3604,7 +3616,7 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data
mob_stop_walking(md, 0);
skill_castend_pos2(&md->bl, md->skillx, md->skilly, md->skillid,
- md->skilllv, tick, 0);
+ md->skilllv, tick, BCT_ZERO);
return;
}
@@ -3619,7 +3631,7 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target,
int casttime, range;
struct mob_skill *ms;
SkillID skill_id;
- int skill_lv, forcecast = 0;
+ int skill_lv;
nullpo_ret(md);
nullpo_ret(ms = &mob_db[md->mob_class].skill[skill_idx]);
@@ -3677,17 +3689,11 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target,
&& battle_check_undead(battle_get_race(target),
battle_get_elem_type(target)))
{ /* 敵がアンデッドなら */
- forcecast = 1; /* ターンアンデットと同じ詠唱時間 */
casttime =
skill_castfix(&md->bl,
skill_get_cast(PR_TURNUNDEAD, skill_lv));
}
break;
- case MO_EXTREMITYFIST: /*阿修羅覇鳳拳 */
- case SA_MAGICROD:
- case SA_SPELLBREAKER:
- forcecast = 1;
- break;
}
if (battle_config.mob_skill_log == 1)
@@ -3975,13 +3981,13 @@ int mobskill_use(struct mob_data *md, unsigned int tick,
flag = (mob_countslave(md) < ms[ii].cond2i);
break;
case MSC_ATTACKPCGT: // attack pc > num
- flag = (mob_counttargeted(md, NULL, 0) > ms[ii].cond2i);
+ flag = (mob_counttargeted(md, NULL, ATK::ZERO) > ms[ii].cond2i);
break;
case MSC_SLAVELE: // slave <= num
flag = (mob_countslave(md) <= ms[ii].cond2i);
break;
case MSC_ATTACKPCGE: // attack pc >= num
- flag = (mob_counttargeted(md, NULL, 0) >= ms[ii].cond2i);
+ flag = (mob_counttargeted(md, NULL, ATK::ZERO) >= ms[ii].cond2i);
break;
case MSC_SKILLUSED: // specificated skill used
flag = (event == MSC_SKILLUSED
@@ -4109,16 +4115,16 @@ int mobskill_use(struct mob_data *md, unsigned int tick,
* Skill use event processing
*------------------------------------------
*/
-int mobskill_event(struct mob_data *md, int flag)
+int mobskill_event(struct mob_data *md, BF flag)
{
nullpo_ret(md);
- if (flag == -1 && mobskill_use(md, gettick(), MSC_CASTTARGETED))
+ if (flag == BF::NEGATIVE_1 && mobskill_use(md, gettick(), MSC_CASTTARGETED))
return 1;
- if ((flag & BF_SHORT)
+ if (bool(flag & BF_SHORT)
&& mobskill_use(md, gettick(), MSC_CLOSEDATTACKED))
return 1;
- if ((flag & BF_LONG)
+ if (bool(flag & BF_LONG)
&& mobskill_use(md, gettick(), MSC_LONGRANGEATTACKED))
return 1;
return 0;
@@ -4148,12 +4154,12 @@ int mob_makedummymobdb(int mob_class)
mob_db[mob_class].atk2 = 10;
mob_db[mob_class].def = 0;
mob_db[mob_class].mdef = 0;
- mob_db[mob_class].str = 1;
- mob_db[mob_class].agi = 1;
- mob_db[mob_class].vit = 1;
- mob_db[mob_class].int_ = 1;
- mob_db[mob_class].dex = 6;
- mob_db[mob_class].luk = 2;
+ mob_db[mob_class].attrs[ATTR::STR] = 1;
+ mob_db[mob_class].attrs[ATTR::AGI] = 1;
+ mob_db[mob_class].attrs[ATTR::VIT] = 1;
+ mob_db[mob_class].attrs[ATTR::INT] = 1;
+ mob_db[mob_class].attrs[ATTR::DEX] = 6;
+ mob_db[mob_class].attrs[ATTR::LUK] = 2;
mob_db[mob_class].range2 = 10;
mob_db[mob_class].range3 = 10;
mob_db[mob_class].size = 0;
@@ -4270,12 +4276,12 @@ int mob_readdb(void)
mob_db[mob_class].atk2 = atoi(str[10]);
mob_db[mob_class].def = atoi(str[11]);
mob_db[mob_class].mdef = atoi(str[12]);
- mob_db[mob_class].str = atoi(str[13]);
- mob_db[mob_class].agi = atoi(str[14]);
- mob_db[mob_class].vit = atoi(str[15]);
- mob_db[mob_class].int_ = atoi(str[16]);
- mob_db[mob_class].dex = atoi(str[17]);
- mob_db[mob_class].luk = atoi(str[18]);
+ mob_db[mob_class].attrs[ATTR::STR] = atoi(str[13]);
+ mob_db[mob_class].attrs[ATTR::AGI] = atoi(str[14]);
+ mob_db[mob_class].attrs[ATTR::VIT] = atoi(str[15]);
+ mob_db[mob_class].attrs[ATTR::INT] = atoi(str[16]);
+ mob_db[mob_class].attrs[ATTR::DEX] = atoi(str[17]);
+ mob_db[mob_class].attrs[ATTR::LUK] = atoi(str[18]);
mob_db[mob_class].range2 = atoi(str[19]);
mob_db[mob_class].range3 = atoi(str[20]);
mob_db[mob_class].size = atoi(str[21]);
@@ -4289,28 +4295,30 @@ int mob_readdb(void)
for (int i = 0; i < 8; i++)
{
- int rate = 0, type, ratemin, ratemax;
+ int rate = 0, ratemin, ratemax;
mob_db[mob_class].dropitem[i].nameid = atoi(str[29 + i * 2]);
- type = itemdb_type(mob_db[mob_class].dropitem[i].nameid);
- if (type == 0)
+ ItemType type = itemdb_type(mob_db[mob_class].dropitem[i].nameid);
+ if (type == ItemType::USE)
{ // Added [Valaris]
rate = battle_config.item_rate_heal;
ratemin = battle_config.item_drop_heal_min;
ratemax = battle_config.item_drop_heal_max;
}
- else if (type == 2)
+ else if (type == ItemType::_2)
{
rate = battle_config.item_rate_use;
ratemin = battle_config.item_drop_use_min;
ratemax = battle_config.item_drop_use_max; // End
}
- else if (type == 4 || type == 5 || type == 8)
+ else if (type == ItemType::WEAPON
+ || type == ItemType::ARMOR
+ || type == ItemType::_8)
{
rate = battle_config.item_rate_equip;
ratemin = battle_config.item_drop_equip_min;
ratemax = battle_config.item_drop_equip_max;
}
- else if (type == 6)
+ else if (type == ItemType::_6)
{
rate = battle_config.item_rate_card;
ratemin = battle_config.item_drop_card_min;
diff --git a/src/map/mob.hpp b/src/map/mob.hpp
index 8157b3e..70fcf06 100644
--- a/src/map/mob.hpp
+++ b/src/map/mob.hpp
@@ -35,7 +35,7 @@ struct mob_db
int base_exp, job_exp;
int atk1, atk2;
int def, mdef;
- int str, agi, vit, int_, dex, luk;
+ earray<int, ATTR, ATTR::COUNT> attrs;
int range, range2, range3;
int size, race, element, mode;
int speed, adelay, amotion, dmotion;
@@ -75,7 +75,7 @@ int mob_stop_walking(struct mob_data *md, int type);
int mob_stopattack(struct mob_data *);
int mob_spawn(int);
int mob_damage(struct block_list *, struct mob_data *, int, int);
-int mob_changestate(struct mob_data *md, int state, int type);
+int mob_changestate(struct mob_data *md, MS state, int type);
int mob_heal(struct mob_data *, int);
int mob_get_viewclass(int);
int mob_get_sex(int);
@@ -97,14 +97,14 @@ void mob_timer_delete(timer_id, tick_t, custom_id_t, custom_data_t);
int mob_deleteslave(struct mob_data *md);
int mob_counttargeted(struct mob_data *md, struct block_list *src,
- int target_lv);
+ ATK target_lv);
int mob_class_change(struct mob_data *md, int *value);
int mob_warp(struct mob_data *md, int m, int x, int y, int type);
int mobskill_use(struct mob_data *md, unsigned int tick,
MSC event, SkillID skill=SkillID::ZERO);
-int mobskill_event(struct mob_data *md, int flag);
+int mobskill_event(struct mob_data *md, BF flag);
void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag);
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index 54c21b3..c40e946 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -928,8 +928,10 @@ int npc_buylist(struct map_session_data *sd, int n,
item_tmp.identify = 1; // npc販売アイテムは鑑定済み
if (amount > 1
- && (item_data->type == 4 || item_data->type == 5
- || item_data->type == 7 || item_data->type == 8))
+ && (item_data->type == ItemType::WEAPON
+ || item_data->type == ItemType::ARMOR
+ || item_data->type == ItemType::_7
+ || item_data->type == ItemType::_8))
{
for (j = 0; j < amount; j++)
{
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 7703b2f..8a5a587 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -39,7 +39,7 @@
#define MAP_LOG_STATS(sd, suffix) \
MAP_LOG_PC(sd, "STAT %d %d %d %d %d %d " suffix, \
- sd->status.str, sd->status.agi, sd->status.vit, sd->status.int_, sd->status.dex, sd->status.luk)
+ sd->status.attrs[ATTR::STR], sd->status.attrs[ATTR::AGI], sd->status.attrs[ATTR::VIT], sd->status.attrs[ATTR::INT], sd->status.attrs[ATTR::DEX], sd->status.attrs[ATTR::LUK])
#define MAP_LOG_XP(sd, suffix) \
MAP_LOG_PC(sd, "XP %d %d JOB %d %d %d ZENY %d + %d " suffix, \
@@ -102,9 +102,19 @@ static
int diry[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
static
-unsigned int equip_pos[11] =
- { 0x0080, 0x0008, 0x0040, 0x0004, 0x0001, 0x0200, 0x0100, 0x0010, 0x0020,
- 0x0002, 0x8000
+earray<EPOS, EQUIP, EQUIP::COUNT> equip_pos =
+{
+ EPOS::MISC2,
+ EPOS::CAPE,
+ EPOS::SHOES,
+ EPOS::GLOVES,
+ EPOS::LEGS,
+ EPOS::TORSO,
+ EPOS::HAT,
+ EPOS::MISC1,
+ EPOS::SHIELD,
+ EPOS::WEAPON,
+ EPOS::ARROW,
};
//static struct dbt *gm_account_db;
@@ -409,7 +419,8 @@ int pc_setrestartvalue(struct map_session_data *sd, int type)
*------------------------------------------
*/
static
-void pc_counttargeted_sub(struct block_list *bl, int id, int *c, struct block_list *src, int target_lv)
+void pc_counttargeted_sub(struct block_list *bl,
+ int id, int *c, struct block_list *src, ATK target_lv)
{
nullpo_retv(bl);
@@ -434,12 +445,12 @@ void pc_counttargeted_sub(struct block_list *bl, int id, int *c, struct block_li
}
int pc_counttargeted(struct map_session_data *sd, struct block_list *src,
- int target_lv)
+ ATK target_lv)
{
int c = 0;
map_foreachinarea(std::bind(pc_counttargeted_sub, ph::_1, sd->bl.id, &c, src, target_lv),
sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
- sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, 0);
+ sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE, BL_NUL);
return c;
}
@@ -518,27 +529,27 @@ int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id,
return 0;
}
-int pc_equippoint(struct map_session_data *sd, int n)
+EPOS pc_equippoint(struct map_session_data *sd, int n)
{
- int ep = 0;
//転生や養子の場合の元の職業を算出する
struct pc_base_job s_class;
- nullpo_ret(sd);
+ nullpo_retr(EPOS::ZERO, sd);
if (!sd->inventory_data[n])
- return 0;
+ return EPOS::ZERO;
s_class = pc_calc_base_job(sd->status.pc_class);
- ep = sd->inventory_data[n]->equip;
- if ((sd->inventory_data[n]->look == 1 || sd->inventory_data[n]->look == 2
- || sd->inventory_data[n]->look == 6) && (ep == 2
- &&
- (pc_checkskill(sd, AS_LEFT)
- > 0 || s_class.job == 12)))
+ EPOS ep = sd->inventory_data[n]->equip;
+ if ((sd->inventory_data[n]->look == 1
+ || sd->inventory_data[n]->look == 2
+ || sd->inventory_data[n]->look == 6)
+ && (ep == EPOS::WEAPON
+ && (pc_checkskill(sd, AS_LEFT) > 0
+ || s_class.job == 12)))
{
- return 34;
+ return EPOS::SHIELD | EPOS::WEAPON;
}
return ep;
@@ -589,36 +600,34 @@ int pc_calcweapontype(struct map_session_data *sd)
static
int pc_setequipindex(struct map_session_data *sd)
{
- int i, j;
-
nullpo_ret(sd);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
sd->equip_index[i] = -1;
- for (i = 0; i < MAX_INVENTORY; i++)
+ for (int i = 0; i < MAX_INVENTORY; i++)
{
if (sd->status.inventory[i].nameid <= 0)
continue;
- if (sd->status.inventory[i].equip)
+ if (bool(sd->status.inventory[i].equip))
{
- for (j = 0; j < 11; j++)
- if (sd->status.inventory[i].equip & equip_pos[j])
+ for (EQUIP j : EQUIPs)
+ if (bool(sd->status.inventory[i].equip & equip_pos[j]))
sd->equip_index[j] = i;
- if (sd->status.inventory[i].equip & 0x0002)
+ if (bool(sd->status.inventory[i].equip & EPOS::WEAPON))
{
if (sd->inventory_data[i])
sd->weapontype1 = sd->inventory_data[i]->look;
else
sd->weapontype1 = 0;
}
- if (sd->status.inventory[i].equip & 0x0020)
+ if (bool(sd->status.inventory[i].equip & EPOS::SHIELD))
{
if (sd->inventory_data[i])
{
- if (sd->inventory_data[i]->type == 4)
+ if (sd->inventory_data[i]->type == ItemType::WEAPON)
{
- if (sd->status.inventory[i].equip == 0x0020)
+ if (sd->status.inventory[i].equip == EPOS::SHIELD)
sd->weapontype2 = sd->inventory_data[i]->look;
else
sd->weapontype2 = 0;
@@ -663,15 +672,21 @@ int pc_isequip(struct map_session_data *sd, int n)
if (map[sd->bl.m].flag.pvp
&& (item->flag.no_equip == 1 || item->flag.no_equip == 3))
return 0;
- if (item->equip & 0x0002 && sc_data
+ if (bool(item->equip & EPOS::WEAPON)
+ && sc_data
&& sc_data[SC_STRIPWEAPON].timer != -1)
return 0;
- if (item->equip & 0x0020 && sc_data
+ if (bool(item->equip & EPOS::SHIELD)
+ && sc_data
&& sc_data[SC_STRIPSHIELD].timer != -1)
return 0;
- if (item->equip & 0x0010 && sc_data && sc_data[SC_STRIPARMOR].timer != -1)
+ if (bool(item->equip & EPOS::MISC1)
+ && sc_data
+ && sc_data[SC_STRIPARMOR].timer != -1)
return 0;
- if (item->equip & 0x0100 && sc_data && sc_data[SC_STRIPHELM].timer != -1)
+ if (bool(item->equip & EPOS::HAT)
+ && sc_data
+ && sc_data[SC_STRIPHELM].timer != -1)
return 0;
return 1;
}
@@ -695,15 +710,15 @@ int pc_breakweapon(struct map_session_data *sd)
for (i = 0; i < MAX_INVENTORY; i++)
{
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& !sd->status.inventory[i].broken)
{
item = sd->inventory_data[i];
sd->status.inventory[i].broken = 1;
- //pc_unequipitem(sd,i,0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0002
+ //pc_unequipitem(sd,i,CalcStatus::NOW);
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& sd->status.inventory[i].broken == 1)
{
sprintf(output, "%s has broken.", item->jname);
@@ -740,15 +755,15 @@ int pc_breakarmor(struct map_session_data *sd)
for (i = 0; i < MAX_INVENTORY; i++)
{
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& !sd->status.inventory[i].broken)
{
item = sd->inventory_data[i];
sd->status.inventory[i].broken = 1;
- //pc_unequipitem(sd,i,0);
- if (sd->status.inventory[i].equip
- && sd->status.inventory[i].equip & 0x0010
+ //pc_unequipitem(sd,i,CalcStatus::NOW);
+ if (bool(sd->status.inventory[i].equip)
+ && bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& sd->status.inventory[i].broken == 1)
{
sprintf(output, "%s has broken.", item->jname);
@@ -1265,7 +1280,7 @@ void pc_set_weapon_look(struct map_session_data *sd)
int pc_calcstatus(struct map_session_data *sd, int first)
{
int b_speed, b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight,
- b_paramb[6], b_parame[6], b_hit, b_flee;
+ b_hit, b_flee;
int b_aspd, b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2, b_class;
int b_base_atk;
@@ -1287,8 +1302,8 @@ int pc_calcstatus(struct map_session_data *sd, int first)
b_sp = sd->status.sp;
b_weight = sd->weight;
b_max_weight = sd->max_weight;
- memcpy(b_paramb, &sd->paramb, sizeof(b_paramb));
- memcpy(b_parame, &sd->paramc, sizeof(b_parame));
+ earray<int, ATTR, ATTR::COUNT> b_paramb = sd->paramb;
+ earray<int, ATTR, ATTR::COUNT> b_parame = sd->paramc;
b_skill = sd->status.skill;
b_hit = sd->hit;
b_flee = sd->flee;
@@ -1310,7 +1325,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
pc_calc_skilltree(sd); // スキルツリーの計算
- sd->max_weight = max_weight_base[s_class.job] + sd->status.str * 300;
+ sd->max_weight = max_weight_base[s_class.job] + sd->status.attrs[ATTR::STR] * 300;
if (first & 1)
{
@@ -1339,8 +1354,11 @@ int pc_calcstatus(struct map_session_data *sd, int first)
}
}
- memset(sd->paramb, 0, sizeof(sd->paramb));
- memset(sd->parame, 0, sizeof(sd->parame));
+ for (auto& p : sd->paramb)
+ p = 0;
+ for (auto& p : sd->parame)
+ p = 0;
+
sd->hit = 0;
sd->flee = 0;
sd->flee2 = 0;
@@ -1466,17 +1484,18 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->spellpower_bonus_target = 0;
- for (int i = 0; i < 10; i++)
+ for (EQUIP i : EQUIPs_noarrow)
{
index = sd->equip_index[i];
if (index < 0)
continue;
- if (i == 9 && sd->equip_index[8] == index)
+ if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index)
continue;
- if (i == 5 && sd->equip_index[4] == index)
+ if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index)
continue;
- if (i == 6
- && (sd->equip_index[5] == index || sd->equip_index[4] == index))
+ if (i == EQUIP::HAT
+ && (sd->equip_index[EQUIP::TORSO] == index
+ || sd->equip_index[EQUIP::LEGS] == index))
continue;
if (sd->inventory_data[index])
@@ -1484,7 +1503,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->spellpower_bonus_target +=
sd->inventory_data[index]->magic_bonus;
- if (sd->inventory_data[index]->type == 4)
+ if (sd->inventory_data[index]->type == ItemType::WEAPON)
{
if (sd->status.inventory[index].card[0] != 0x00ff
&& sd->status.inventory[index].card[0] != 0x00fe
@@ -1498,11 +1517,11 @@ int pc_calcstatus(struct map_session_data *sd, int first)
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
- if (i == 8
- && sd->status.inventory[index].equip == 0x20)
+ if (i == EQUIP::SHIELD
+ && sd->status.inventory[index].equip == EPOS::SHIELD)
sd->state.lr_flag = 1;
run_script_l(itemdb_equipscript(c), 0, sd->bl.id,
0, 2, arg);
@@ -1511,7 +1530,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
}
}
}
- else if (sd->inventory_data[index]->type == 5)
+ else if (sd->inventory_data[index]->type == ItemType::ARMOR)
{ // 防具
if (sd->status.inventory[index].card[0] != 0x00ff
&& sd->status.inventory[index].card[0] != 0x00fe
@@ -1524,7 +1543,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (c > 0) {
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
run_script_l(itemdb_equipscript(c), 0, sd->bl.id,
@@ -1540,7 +1559,7 @@ int pc_calcstatus(struct 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, TMW_ASTRAL_SOUL), 256));
+ (min(128 + skill_power(sd, TMW_ASTRAL_SOUL), 256));
#endif
if (sd->spellpower_bonus_target < sd->spellpower_bonus_current)
@@ -1549,28 +1568,30 @@ int pc_calcstatus(struct map_session_data *sd, int first)
wele = sd->atk_ele;
wele_ = sd->atk_ele_;
def_ele = sd->def_ele;
- memcpy(sd->paramcard, sd->parame, sizeof(sd->paramcard));
+ sd->paramcard = sd->parame;
// 装備品によるステータス変化はここで実行
- for (int i = 0; i < 10; i++)
+ for (EQUIP i : EQUIPs_noarrow)
{
index = sd->equip_index[i];
if (index < 0)
continue;
- if (i == 9 && sd->equip_index[8] == index)
+ if (i == EQUIP::WEAPON && sd->equip_index[EQUIP::SHIELD] == index)
continue;
- if (i == 5 && sd->equip_index[4] == index)
+ if (i == EQUIP::TORSO && sd->equip_index[EQUIP::LEGS] == index)
continue;
- if (i == 6
- && (sd->equip_index[5] == index || sd->equip_index[4] == index))
+ if (i == EQUIP::HAT
+ && (sd->equip_index[EQUIP::TORSO] == index
+ || sd->equip_index[EQUIP::LEGS] == index))
continue;
if (sd->inventory_data[index])
{
sd->def += sd->inventory_data[index]->def;
- if (sd->inventory_data[index]->type == 4)
+ if (sd->inventory_data[index]->type == ItemType::WEAPON)
{
int r, wlv = sd->inventory_data[index]->wlv;
- if (i == 8 && sd->status.inventory[index].equip == 0x20)
+ if (i == EQUIP::SHIELD
+ && sd->status.inventory[index].equip == EPOS::SHIELD)
{
//二刀流用データ入力
sd->watk_ += sd->inventory_data[index]->atk;
@@ -1589,7 +1610,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
run_script_l(sd->inventory_data[index]->equip_script, 0,
@@ -1601,7 +1622,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
{ //二刀流武器以外
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->watk += sd->inventory_data[index]->atk;
@@ -1620,11 +1641,11 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->bl.id, 0, 2, arg);
}
}
- else if (sd->inventory_data[index]->type == 5)
+ else if (sd->inventory_data[index]->type == ItemType::ARMOR)
{
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = i;
+ arg[0].v.i = int(i);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->watk += sd->inventory_data[index]->atk;
@@ -1644,14 +1665,14 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->watk_2 += skill_power(sd, TMW_BRAWLING) >> 3; // +25 for 200
}
- if (sd->equip_index[10] >= 0)
+ if (sd->equip_index[EQUIP::ARROW] >= 0)
{ // 矢
- index = sd->equip_index[10];
+ index = sd->equip_index[EQUIP::ARROW];
if (sd->inventory_data[index])
{ //まだ属性が入っていない
argrec_t arg[2];
arg[0].name = "@slotId";
- arg[0].v.i = 10;
+ arg[0].v.i = int(EQUIP::ARROW);
arg[1].name = "@itemId";
arg[1].v.i = sd->inventory_data[index]->nameid;
sd->state.lr_flag = 2;
@@ -1712,20 +1733,20 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->sc_data[SC_CONCENTRATE].timer != -1
&& sd->sc_data[SC_QUAGMIRE].timer == -1)
{ // 集中力向上
- sd->paramb[1] +=
- (sd->status.agi + sd->paramb[1] + sd->parame[1] -
- sd->paramcard[1]) * (2 +
+ sd->paramb[ATTR::AGI] +=
+ (sd->status.attrs[ATTR::AGI] + sd->paramb[ATTR::AGI] + sd->parame[ATTR::AGI] -
+ sd->paramcard[ATTR::AGI]) * (2 +
sd->sc_data[SC_CONCENTRATE].val1) / 100;
- sd->paramb[4] +=
- (sd->status.dex + sd->paramb[4] + sd->parame[4] -
- sd->paramcard[4]) * (2 +
+ sd->paramb[ATTR::DEX] +=
+ (sd->status.attrs[ATTR::DEX] + sd->paramb[ATTR::DEX] + sd->parame[ATTR::DEX] -
+ sd->paramcard[ATTR::DEX]) * (2 +
sd->sc_data[SC_CONCENTRATE].val1) / 100;
}
if (sd->sc_data[SC_INCREASEAGI].timer != -1
&& sd->sc_data[SC_QUAGMIRE].timer == -1
&& sd->sc_data[SC_DONTFORGETME].timer == -1)
{ // 速度増加
- sd->paramb[1] += 2 + sd->sc_data[SC_INCREASEAGI].val1;
+ sd->paramb[ATTR::AGI] += 2 + sd->sc_data[SC_INCREASEAGI].val1;
sd->speed -= sd->speed * 25 / 100;
}
if (sd->sc_data[SC_DECREASEAGI].timer != -1) // 速度減少(agiはbattle.cで)
@@ -1736,30 +1757,26 @@ int pc_calcstatus(struct map_session_data *sd, int first)
100;
if (sd->sc_data[SC_BLESSING].timer != -1)
{ // ブレッシング
- sd->paramb[0] += sd->sc_data[SC_BLESSING].val1;
- sd->paramb[3] += sd->sc_data[SC_BLESSING].val1;
- sd->paramb[4] += sd->sc_data[SC_BLESSING].val1;
+ sd->paramb[ATTR::STR] += sd->sc_data[SC_BLESSING].val1;
+ sd->paramb[ATTR::INT] += sd->sc_data[SC_BLESSING].val1;
+ sd->paramb[ATTR::DEX] += sd->sc_data[SC_BLESSING].val1;
}
if (sd->sc_data[SC_GLORIA].timer != -1) // グロリア
- sd->paramb[5] += 30;
+ sd->paramb[ATTR::LUK] += 30;
if (sd->sc_data[SC_LOUD].timer != -1 && sd->sc_data[SC_QUAGMIRE].timer == -1) // ラウドボイス
- sd->paramb[0] += 4;
+ sd->paramb[ATTR::STR] += 4;
if (sd->sc_data[SC_QUAGMIRE].timer != -1)
{ // クァグマイア
sd->speed = sd->speed * 3 / 2;
- sd->paramb[1] -=
- (sd->status.agi + sd->paramb[1] + sd->parame[1]) / 2;
- sd->paramb[4] -=
- (sd->status.dex + sd->paramb[4] + sd->parame[4]) / 2;
+ sd->paramb[ATTR::AGI] -=
+ (sd->status.attrs[ATTR::AGI] + sd->paramb[ATTR::AGI] + sd->parame[ATTR::AGI]) / 2;
+ sd->paramb[ATTR::DEX] -=
+ (sd->status.attrs[ATTR::DEX] + sd->paramb[ATTR::DEX] + sd->parame[ATTR::DEX]) / 2;
}
if (sd->sc_data[SC_TRUESIGHT].timer != -1)
{ // トゥルーサイト
- sd->paramb[0] += 5;
- sd->paramb[1] += 5;
- sd->paramb[2] += 5;
- sd->paramb[3] += 5;
- sd->paramb[4] += 5;
- sd->paramb[5] += 5;
+ for (auto& p : sd->paramb)
+ p += 5;
}
}
sd->speed -= skill_power(sd, TMW_SPEED) >> 3;
@@ -1767,44 +1784,26 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->aspd_rate < 20)
sd->aspd_rate = 20;
-/*
- //1度も死んでないJob70スパノビに+10
- if (s_class.job == 23 && sd->die_counter == 0 && sd->status.job_level >= 70){
- sd->paramb[0]+= 15;
- sd->paramb[1]+= 15;
- sd->paramb[2]+= 15;
- sd->paramb[3]+= 15;
- sd->paramb[4]+= 15;
- sd->paramb[5]+= 15;
- }
-*/
- sd->paramc[0] = sd->status.str + sd->paramb[0] + sd->parame[0];
- sd->paramc[1] = sd->status.agi + sd->paramb[1] + sd->parame[1];
- sd->paramc[2] = sd->status.vit + sd->paramb[2] + sd->parame[2];
- sd->paramc[3] = sd->status.int_ + sd->paramb[3] + sd->parame[3];
- sd->paramc[4] = sd->status.dex + sd->paramb[4] + sd->parame[4];
- sd->paramc[5] = sd->status.luk + sd->paramb[5] + sd->parame[5];
- for (int i = 0; i < 6; i++)
- if (sd->paramc[i] < 0)
- sd->paramc[i] = 0;
+ for (ATTR attr : ATTRs)
+ sd->paramc[attr] = max(0, sd->status.attrs[attr] + sd->paramb[attr] + sd->parame[attr]);
if (sd->status.weapon == 11 || sd->status.weapon == 13
|| sd->status.weapon == 14)
{
- str = sd->paramc[4];
- dex = sd->paramc[0];
+ str = sd->paramc[ATTR::DEX];
+ dex = sd->paramc[ATTR::STR];
}
else
{
- str = sd->paramc[0];
- dex = sd->paramc[4];
+ str = sd->paramc[ATTR::STR];
+ dex = sd->paramc[ATTR::DEX];
sd->critical += ((dex * 3) >> 1);
}
dstr = str / 10;
- sd->base_atk += str + dstr * dstr + dex / 5 + sd->paramc[5] / 5;
-//fprintf(stderr, "baseatk = %d = x + %d + %d + %d + %d\n", sd->base_atk, str, dstr*dstr, dex/5, sd->paramc[5]/5);
- sd->matk1 += sd->paramc[3] + (sd->paramc[3] / 5) * (sd->paramc[3] / 5);
- sd->matk2 += sd->paramc[3] + (sd->paramc[3] / 7) * (sd->paramc[3] / 7);
+ 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)
{
int temp = sd->matk2;
@@ -1826,12 +1825,12 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->matk1 < 0)
sd->matk1 = 0;
- sd->hit += sd->paramc[4] + sd->status.base_level;
- sd->flee += sd->paramc[1] + sd->status.base_level;
- sd->def2 += sd->paramc[2];
- sd->mdef2 += sd->paramc[3];
- sd->flee2 += sd->paramc[5] + 10;
- sd->critical += (sd->paramc[5] * 3) + 10;
+ sd->hit += sd->paramc[ATTR::DEX] + sd->status.base_level;
+ sd->flee += sd->paramc[ATTR::AGI] + sd->status.base_level;
+ sd->def2 += sd->paramc[ATTR::VIT];
+ sd->mdef2 += sd->paramc[ATTR::INT];
+ sd->flee2 += sd->paramc[ATTR::LUK] + 10;
+ sd->critical += (sd->paramc[ATTR::LUK] * 3) + 10;
// 200 is the maximum of the skill
// def2 is the defence gained by vit, whereas "def", which is gained by armor, stays as is
@@ -1879,20 +1878,19 @@ int pc_calcstatus(struct map_session_data *sd, int first)
// 二刀流 ASPD 修正
if (sd->status.weapon <= 16)
- sd->aspd +=
- aspd_base[s_class.job][sd->status.weapon] - (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->status.weapon] / 1000;
+ sd->aspd += aspd_base[s_class.job][sd->status.weapon]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base[s_class.job][sd->status.weapon] / 1000;
else
- sd->aspd += ((aspd_base[s_class.job][sd->weapontype1] -
- (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->weapontype1] / 1000) +
- (aspd_base[s_class.job][sd->weapontype2] -
- (sd->paramc[1] * 4 +
- sd->paramc[4]) *
- aspd_base[s_class.job][sd->weapontype2] / 1000)) * 140 /
- 200;
+ sd->aspd += (
+ (aspd_base[s_class.job][sd->weapontype1]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base[s_class.job][sd->weapontype1] / 1000)
+ + (aspd_base[s_class.job][sd->weapontype2]
+ - (sd->paramc[ATTR::AGI] * 4 + sd->paramc[ATTR::DEX])
+ * aspd_base[s_class.job][sd->weapontype2] / 1000)
+ )
+ * 140 / 200;
aspd_rate = sd->aspd_rate;
@@ -1907,7 +1905,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->attackrange > 2)
{ // [fate] ranged weapon?
- sd->attackrange += MIN(skill_power(sd, AC_OWL) / 60, 3);
+ sd->attackrange += min(skill_power(sd, AC_OWL) / 60, 3);
sd->hit += skill_power(sd, AC_OWL) / 10; // 20 for 200
}
@@ -1944,12 +1942,12 @@ int pc_calcstatus(struct map_session_data *sd, int first)
bl = sd->status.base_level;
- sd->status.max_hp +=
- (3500 + bl * hp_coefficient2[s_class.job] +
- hp_sigma_val[s_class.job][(bl > 0) ? bl - 1 : 0]) / 100 * (100 +
- sd->paramc
- [2]) /
- 100 + (sd->parame[2] - sd->paramcard[2]);
+ sd->status.max_hp += (
+ 3500
+ + bl * hp_coefficient2[s_class.job]
+ + hp_sigma_val[s_class.job][(bl > 0) ? bl - 1 : 0]
+ ) / 100 * (100 + sd->paramc[ATTR::VIT]) / 100
+ + (sd->parame[ATTR::VIT] - sd->paramcard[ATTR::VIT]);
if (s_class.upper == 1) // [MouseJstr]
sd->status.max_hp = sd->status.max_hp * 130 / 100;
if (sd->hprate != 100)
@@ -1975,10 +1973,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->status.max_hp = 1; // end
// 最大SP計算
- sd->status.max_sp +=
- ((sp_coefficient[s_class.job] * bl) + 1000) / 100 * (100 +
- sd->paramc[3]) /
- 100 + (sd->parame[3] - sd->paramcard[3]);
+ sd->status.max_sp += ((sp_coefficient[s_class.job] * bl) + 1000)
+ / 100 * (100 + sd->paramc[ATTR::INT]) / 100
+ + (sd->parame[ATTR::INT] - sd->paramcard[ATTR::INT]);
if (s_class.upper == 1) // [MouseJstr]
sd->status.max_sp = sd->status.max_sp * 130 / 100;
if (sd->sprate != 100)
@@ -1993,7 +1990,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->status.max_sp = battle_config.max_sp;
//自然回復HP
- sd->nhealhp = 1 + (sd->paramc[2] / 5) + (sd->status.max_hp / 200);
+ sd->nhealhp = 1 + (sd->paramc[ATTR::VIT] / 5) + (sd->status.max_hp / 200);
if ((skill = pc_checkskill(sd, SM_RECOVERY)) > 0)
{ // HP回復力向上
sd->nshealhp = skill * 5 + (sd->status.max_hp * skill / 500);
@@ -2001,9 +1998,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->nshealhp = 0x7fff;
}
//自然回復SP
- sd->nhealsp = 1 + (sd->paramc[3] / 6) + (sd->status.max_sp / 100);
- if (sd->paramc[3] >= 120)
- sd->nhealsp += ((sd->paramc[3] - 120) >> 1) + 4;
+ sd->nhealsp = 1 + (sd->paramc[ATTR::INT] / 6) + (sd->status.max_sp / 100);
+ if (sd->paramc[ATTR::INT] >= 120)
+ sd->nhealsp += ((sd->paramc[ATTR::INT] - 120) >> 1) + 4;
if ((skill = pc_checkskill(sd, MG_SRECOVERY)) > 0)
{ // SP回復力向上
sd->nshealsp = skill * 3 + (sd->status.max_sp * skill / 500);
@@ -2077,9 +2074,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->sc_data[SC_IMPOSITIO].timer != -1)
{ // インポシティオマヌス
sd->watk += sd->sc_data[SC_IMPOSITIO].val1 * 5;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
+ && sd->inventory_data[index]->type == ItemType::WEAPON)
sd->watk_ += sd->sc_data[SC_IMPOSITIO].val1 * 5;
}
if (sd->sc_data[SC_PROVOKE].timer != -1)
@@ -2090,9 +2087,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->base_atk * (100 + 2 * sd->sc_data[SC_PROVOKE].val1) / 100;
sd->watk =
sd->watk * (100 + 2 * sd->sc_data[SC_PROVOKE].val1) / 100;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
+ && sd->inventory_data[index]->type == ItemType::WEAPON)
sd->watk_ =
sd->watk_ * (100 +
2 * sd->sc_data[SC_PROVOKE].val1) / 100;
@@ -2117,25 +2114,25 @@ int pc_calcstatus(struct map_session_data *sd, int first)
{ // 戦太鼓の響き
sd->watk += sd->sc_data[SC_DRUMBATTLE].val2;
sd->def += sd->sc_data[SC_DRUMBATTLE].val3;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
+ && sd->inventory_data[index]->type == ItemType::WEAPON)
sd->watk_ += sd->sc_data[SC_DRUMBATTLE].val2;
}
if (sd->sc_data[SC_NIBELUNGEN].timer != -1)
{ // ニーベルングの指輪
- index = sd->equip_index[9];
+ index = sd->equip_index[EQUIP::WEAPON];
if (index >= 0 && sd->inventory_data[index]
&& sd->inventory_data[index]->wlv == 3)
sd->watk += sd->sc_data[SC_NIBELUNGEN].val3;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
&& sd->inventory_data[index]->wlv == 3)
sd->watk_ += sd->sc_data[SC_NIBELUNGEN].val3;
if (index >= 0 && sd->inventory_data[index]
&& sd->inventory_data[index]->wlv == 4)
sd->watk += sd->sc_data[SC_NIBELUNGEN].val2;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
&& sd->inventory_data[index]->wlv == 4)
sd->watk_ += sd->sc_data[SC_NIBELUNGEN].val2;
@@ -2157,9 +2154,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->watk =
sd->watk * (100 +
5 * sd->sc_data[SC_CONCENTRATION].val1) / 100;
- index = sd->equip_index[8];
+ index = sd->equip_index[EQUIP::SHIELD];
if (index >= 0 && sd->inventory_data[index]
- && sd->inventory_data[index]->type == 4)
+ && sd->inventory_data[index]->type == ItemType::WEAPON)
sd->watk_ =
sd->watk * (100 +
5 * sd->sc_data[SC_CONCENTRATION].val1) / 100;
@@ -2394,7 +2391,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->aspd < battle_config.max_aspd)
sd->aspd = battle_config.max_aspd;
sd->amotion = sd->aspd;
- sd->dmotion = 800 - sd->paramc[1] * 4;
+ sd->dmotion = 800 - sd->paramc[ATTR::AGI] * 4;
if (sd->dmotion < 400)
sd->dmotion = 400;
if (sd->skilltimer != -1 && (skill = pc_checkskill(sd, SA_FREECAST)) > 0)
@@ -2442,9 +2439,9 @@ int pc_calcstatus(struct map_session_data *sd, int first)
clif_updatestatus(sd, SP_MAXWEIGHT);
pc_checkweighticon(sd);
}
- for (int i = 0; i < 6; i++)
+ for (ATTR i : ATTRs)
if (b_paramb[i] + b_parame[i] != sd->paramb[i] + sd->parame[i])
- clif_updatestatus(sd, SP_STR + i);
+ clif_updatestatus(sd, attr_to_sp(i));
if (b_hit != sd->hit)
clif_updatestatus(sd, SP_HIT);
if (b_flee != sd->flee)
@@ -2500,7 +2497,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
* 装 備品による能力等のボーナス設定
*------------------------------------------
*/
-int pc_bonus(struct map_session_data *sd, int type, int val)
+int pc_bonus(struct map_session_data *sd, SP type, int val)
{
nullpo_ret(sd);
@@ -2513,7 +2510,7 @@ int pc_bonus(struct map_session_data *sd, int type, int val)
case SP_DEX:
case SP_LUK:
if (sd->state.lr_flag != 2)
- sd->parame[type - SP_STR] += val;
+ sd->parame[sp_to_attr(type)] += val;
break;
case SP_ATK1:
if (!sd->state.lr_flag)
@@ -2831,38 +2828,34 @@ int pc_bonus(struct map_session_data *sd, int type, int val)
case SP_ALL_STATS: // [Valaris]
if (sd->state.lr_flag != 2)
{
- sd->parame[SP_STR - SP_STR] += val;
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_VIT - SP_STR] += val;
- sd->parame[SP_INT - SP_STR] += val;
- sd->parame[SP_DEX - SP_STR] += val;
- sd->parame[SP_LUK - SP_STR] += val;
- clif_updatestatus(sd, 13);
- clif_updatestatus(sd, 14);
- clif_updatestatus(sd, 15);
- clif_updatestatus(sd, 16);
- clif_updatestatus(sd, 17);
- clif_updatestatus(sd, 18);
+ for (ATTR attr : ATTRs)
+ sd->parame[attr] += val;
+ clif_updatestatus(sd, SP_STR);
+ clif_updatestatus(sd, SP_AGI);
+ clif_updatestatus(sd, SP_VIT);
+ clif_updatestatus(sd, SP_INT);
+ clif_updatestatus(sd, SP_DEX);
+ clif_updatestatus(sd, SP_LUK);
}
break;
case SP_AGI_VIT: // [Valaris]
if (sd->state.lr_flag != 2)
{
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_VIT - SP_STR] += val;
- clif_updatestatus(sd, 14);
- clif_updatestatus(sd, 15);
+ sd->parame[ATTR::AGI] += val;
+ sd->parame[ATTR::VIT] += val;
+ clif_updatestatus(sd, SP_AGI);
+ clif_updatestatus(sd, SP_VIT);
}
break;
case SP_AGI_DEX_STR: // [Valaris]
if (sd->state.lr_flag != 2)
{
- sd->parame[SP_AGI - SP_STR] += val;
- sd->parame[SP_DEX - SP_STR] += val;
- sd->parame[SP_STR - SP_STR] += val;
- clif_updatestatus(sd, 14);
- clif_updatestatus(sd, 17);
- clif_updatestatus(sd, 13);
+ sd->parame[ATTR::AGI] += val;
+ sd->parame[ATTR::DEX] += val;
+ sd->parame[ATTR::STR] += val;
+ clif_updatestatus(sd, SP_AGI);
+ clif_updatestatus(sd, SP_DEX);
+ clif_updatestatus(sd, SP_STR);
}
break;
case SP_PERFECT_HIDE: // [Valaris]
@@ -2896,7 +2889,8 @@ int pc_bonus(struct map_session_data *sd, int type, int val)
break;
default:
if (battle_config.error_log)
- printf("pc_bonus: unknown type %d %d !\n", type, val);
+ printf("pc_bonus: unknown type %d %d !\n",
+ uint16_t(type), val);
break;
}
return 0;
@@ -2906,7 +2900,7 @@ int pc_bonus(struct map_session_data *sd, int type, int val)
* ソスソス ソスソスソスiソスノゑソスソスソスソス\ソスヘ難ソスソスフボソス[ソスiソスXソスン抵ソス
*------------------------------------------
*/
-int pc_bonus2(struct map_session_data *sd, int type, int type2, int val)
+int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val)
{
int i;
@@ -3119,14 +3113,14 @@ int pc_bonus2(struct map_session_data *sd, int type, int type2, int val)
} // end addition
default:
if (battle_config.error_log)
- printf("pc_bonus2: unknown type %d %d %d!\n", type, type2,
- val);
+ printf("pc_bonus2: unknown type %d %d %d!\n",
+ uint16_t(type), type2, val);
break;
}
return 0;
}
-int pc_bonus3(struct map_session_data *sd, int type, int type2, int type3,
+int pc_bonus3(struct map_session_data *sd, SP type, int type2, int type3,
int val)
{
int i;
@@ -3168,8 +3162,8 @@ int pc_bonus3(struct map_session_data *sd, int type, int type2, int type3,
break;
default:
if (battle_config.error_log)
- printf("pc_bonus3: unknown type %d %d %d %d!\n", type, type2,
- type3, val);
+ printf("pc_bonus3: unknown type %d %d %d %d!\n",
+ uint16_t(type), type2, type3, val);
break;
}
@@ -3256,11 +3250,11 @@ int pc_modifysellvalue(struct map_session_data *sd, int orig_value)
* 3万個制限にかかるか確認
*------------------------------------------
*/
-int pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
+ADDITEM pc_checkadditem(struct map_session_data *sd, int nameid, int amount)
{
int i;
- nullpo_ret(sd);
+ nullpo_retr(ADDITEM::ZERO, sd);
if (itemdb_isequip(nameid))
return ADDITEM_NEW;
@@ -3407,7 +3401,7 @@ int pc_remove_items(struct map_session_data *player, int item_id, int count)
* アイテム追加。個数のみitem構造体の数字を無視
*------------------------------------------
*/
-int pc_additem(struct map_session_data *sd, struct item *item_data,
+PickupFail pc_additem(struct map_session_data *sd, struct item *item_data,
int amount)
{
struct item_data *data;
@@ -3415,14 +3409,14 @@ int pc_additem(struct map_session_data *sd, struct item *item_data,
MAP_LOG_PC(sd, "PICKUP %d %d", item_data->nameid, amount);
- nullpo_retr(1, sd);
- nullpo_retr(1, item_data);
+ nullpo_retr(PickupFail::BAD_ITEM, sd);
+ nullpo_retr(PickupFail::BAD_ITEM, item_data);
if (item_data->nameid <= 0 || amount <= 0)
- return 1;
+ return PickupFail::BAD_ITEM;
data = itemdb_search(item_data->nameid);
if ((w = data->weight * amount) + sd->weight > sd->max_weight)
- return 2;
+ return PickupFail::TOO_HEAVY;
i = MAX_INVENTORY;
@@ -3437,9 +3431,9 @@ int pc_additem(struct map_session_data *sd, struct item *item_data,
&& sd->status.inventory[i].card[3] == item_data->card[3])
{
if (sd->status.inventory[i].amount + amount > MAX_AMOUNT)
- return 5;
+ return PickupFail::STACK_FULL;
sd->status.inventory[i].amount += amount;
- clif_additem(sd, i, amount, 0);
+ clif_additem(sd, i, amount, PickupFail::OKAY);
break;
}
}
@@ -3452,20 +3446,20 @@ int pc_additem(struct map_session_data *sd, struct item *item_data,
memcpy(&sd->status.inventory[i], item_data,
sizeof(sd->status.inventory[0]));
- if (item_data->equip)
- sd->status.inventory[i].equip = 0;
+ if (bool(item_data->equip))
+ sd->status.inventory[i].equip = EPOS::ZERO;
sd->status.inventory[i].amount = amount;
sd->inventory_data[i] = data;
- clif_additem(sd, i, amount, 0);
+ clif_additem(sd, i, amount, PickupFail::OKAY);
}
else
- return 4;
+ return PickupFail::INV_FULL;
}
sd->weight += w;
clif_updatestatus(sd, SP_WEIGHT);
- return 0;
+ return PickupFail::OKAY;
}
/*==========================================
@@ -3488,8 +3482,8 @@ int pc_delitem(struct map_session_data *sd, int n, int amount, int type)
sd->weight -= sd->inventory_data[n]->weight * amount;
if (sd->status.inventory[n].amount <= 0)
{
- if (sd->status.inventory[n].equip)
- pc_unequipitem(sd, n, 0);
+ if (bool(sd->status.inventory[n].equip))
+ pc_unequipitem(sd, n, CalcStatus::NOW);
memset(&sd->status.inventory[n], 0,
sizeof(sd->status.inventory[0]));
sd->inventory_data[n] = NULL;
@@ -3519,7 +3513,7 @@ int pc_dropitem(struct map_session_data *sd, int n, int amount)
if (amount <= 0)
return 0;
- pc_unequipinvyitem(sd, n, 0);
+ pc_unequipinvyitem(sd, n, CalcStatus::NOW);
if (sd->status.inventory[n].nameid <= 0 ||
sd->status.inventory[n].amount < amount ||
@@ -3578,7 +3572,6 @@ int can_pick_item_up_from(struct map_session_data *self, int other_id)
int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
{
- int flag;
unsigned int tick = gettick();
int can_take;
@@ -3613,8 +3606,8 @@ int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
{
/* Can pick up */
- if ((flag =
- pc_additem(sd, &fitem->item_data, fitem->item_data.amount)))
+ PickupFail flag = pc_additem(sd, &fitem->item_data, fitem->item_data.amount);
+ if (flag != PickupFail::OKAY)
// 重量overで取得失敗
clif_additem(sd, 0, 0, flag);
else
@@ -3629,7 +3622,7 @@ int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
}
/* Otherwise, we can't pick up */
- clif_additem(sd, 0, 0, 6);
+ clif_additem(sd, 0, 0, PickupFail::DROP_STEAL);
return 0;
}
@@ -3646,7 +3639,7 @@ int pc_isUseitem(struct map_session_data *sd, int n)
if (item == NULL)
return 0;
- if (itemdb_type(nameid) != 0)
+ if (itemdb_type(nameid) != ItemType::USE)
return 0;
if (nameid == 601
&& (map[sd->bl.m].flag.noteleport))
@@ -3760,7 +3753,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
{
if (sd != NULL && bl != NULL && bl->type == BL_MOB)
{
- int i, skill, rate, itemid, flag, count;
+ int i, skill, rate, itemid, count;
struct mob_data *md;
md = (struct mob_data *) bl;
if (!md->state.steal_flag && mob_db[md->mob_class].mexp <= 0 &&
@@ -3769,7 +3762,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
md->sc_data[SC_FREEZE].timer == -1 &&
(!(md->mob_class > 1324 && md->mob_class < 1364))) // prevent stealing from treasure boxes [Valaris]
{
- skill = sd->paramc[4] - mob_db[md->mob_class].dex
+ skill = sd->paramc[ATTR::DEX] - mob_db[md->mob_class].attrs[ATTR::DEX]
+ pc_checkskill(sd, TF_STEAL) + 10;
if (0 < skill)
@@ -3779,7 +3772,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
i = rand() % 8;
itemid = mob_db[md->mob_class].dropitem[i].nameid;
- if (itemid > 0 && itemdb_type(itemid) != 6)
+ if (itemid > 0 && itemdb_type(itemid) != ItemType::_6)
{
rate =
(mob_db[md->mob_class].dropitem[i].p /
@@ -3793,14 +3786,14 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
tmp_item.nameid = itemid;
tmp_item.amount = 1;
tmp_item.identify = 1;
- flag = pc_additem(sd, &tmp_item, 1);
+ PickupFail flag = pc_additem(sd, &tmp_item, 1);
if (battle_config.show_steal_in_same_party)
{
party_foreachsamemap(
std::bind(pc_show_steal, ph::_1, sd, tmp_item.nameid, 0), sd, 1);
}
- if (flag)
+ if (flag != PickupFail::OKAY)
{
if (battle_config.show_steal_in_same_party)
{
@@ -3838,7 +3831,7 @@ int pc_steal_coin(struct map_session_data *sd, struct block_list *bl)
skill = pc_checkskill(sd, RG_STEALCOIN) * 10;
rate =
skill + (sd->status.base_level - mob_db[md->mob_class].lv) * 3 +
- sd->paramc[4] * 2 + sd->paramc[5] * 2;
+ sd->paramc[ATTR::DEX] * 2 + sd->paramc[ATTR::LUK] * 2;
if (MRAND(1000) < rate)
{
pc_getzeny(sd, mob_db[md->mob_class].lv * 10 + MRAND(100));
@@ -4137,7 +4130,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
x + AREA_SIZE, y + AREA_SIZE,
dx, dy,
- 0);
+ BL_NUL);
x += dx;
y += dy;
@@ -4158,7 +4151,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
x + AREA_SIZE, y + AREA_SIZE,
-dx, -dy,
- 0);
+ BL_NUL);
sd->walktimer = -1;
if (sd->status.party_id > 0)
@@ -4333,7 +4326,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y)
sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
dx, dy,
- 0);
+ BL_NUL);
if (moveblock)
map_delblock(&sd->bl);
@@ -4346,7 +4339,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y)
sd->bl.m, sd->bl.x - AREA_SIZE, sd->bl.y - AREA_SIZE,
sd->bl.x + AREA_SIZE, sd->bl.y + AREA_SIZE,
-dx, -dy,
- 0);
+ BL_NUL);
if (sd->status.party_id > 0)
{ // パーティのHP情報通知検査
@@ -4470,15 +4463,13 @@ int pc_checkallowskill(struct map_session_data *sd)
* 装 備品のチェック
*------------------------------------------
*/
-int pc_checkequip(struct map_session_data *sd, int pos)
+int pc_checkequip(struct map_session_data *sd, EPOS pos)
{
- int i;
-
nullpo_retr(-1, sd);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
return sd->equip_index[i];
}
@@ -4653,7 +4644,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
map_freeblock_lock();
pc_stop_walking(sd, 0);
sd->attacktarget_lv =
- battle_weapon_attack(&sd->bl, bl, tick, 0);
+ battle_weapon_attack(&sd->bl, bl, tick, BCT_ZERO);
if (!(battle_config.pc_cloak_check_type & 2)
&& sd->sc_data[SC_CLOAKING].timer != -1)
skill_status_change_end(&sd->bl, SC_CLOAKING, -1);
@@ -4873,7 +4864,7 @@ int pc_gainexp(struct map_session_data *sd, int base_exp, int job_exp)
}
int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp,
- int reason)
+ PC_GAINEXP_REASON reason)
{
char output[256];
nullpo_ret(sd);
@@ -4884,9 +4875,13 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp,
if ((battle_config.pvp_exp == 0) && map[sd->bl.m].flag.pvp) // [MouseJstr]
return 0; // no exp on pvp maps
- MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp,
- ((reason ==
- 2) ? "SCRIPTXP" : ((reason == 1) ? "HEALXP" : "KILLXP")));
+ earray<const char *, PC_GAINEXP_REASON, PC_GAINEXP_REASON::COUNT> reasons =
+ {
+ "KILLXP",
+ "HEALXP",
+ "SCRIPTXP",
+ };
+ MAP_LOG_PC(sd, "GAINXP %d %d %s", base_exp, job_exp, reasons[reason]);
if (sd->sc_data[SC_RICHMANKIM].timer != -1)
{ // added bounds checking [Vaalris]
@@ -5078,7 +5073,7 @@ int pc_nextjobafter(struct map_session_data *sd)
* 必要ステータスポイント計算
*------------------------------------------
*/
-int pc_need_status_point(struct map_session_data *sd, int type)
+int pc_need_status_point(struct map_session_data *sd, SP type)
{
int val;
@@ -5086,12 +5081,7 @@ int pc_need_status_point(struct map_session_data *sd, int type)
if (type < SP_STR || type > SP_LUK)
return -1;
- val =
- type == SP_STR ? sd->status.str :
- type == SP_AGI ? sd->status.agi :
- type == SP_VIT ? sd->status.vit :
- type == SP_INT ? sd->status.int_ :
- type == SP_DEX ? sd->status.dex : sd->status.luk;
+ val = sd->status.attrs[sp_to_attr(type)];
return (val + 9) / 10 + 1;
}
@@ -5100,33 +5090,14 @@ int pc_need_status_point(struct map_session_data *sd, int type)
* 能力値成長
*------------------------------------------
*/
-int pc_statusup(struct map_session_data *sd, int type)
+int pc_statusup(struct map_session_data *sd, SP type)
{
int need, val = 0;
nullpo_ret(sd);
- switch (type)
- {
- case SP_STR:
- val = sd->status.str;
- break;
- case SP_AGI:
- val = sd->status.agi;
- break;
- case SP_VIT:
- val = sd->status.vit;
- break;
- case SP_INT:
- val = sd->status.int_;
- break;
- case SP_DEX:
- val = sd->status.dex;
- break;
- case SP_LUK:
- val = sd->status.luk;
- break;
- }
+ if (SP_STR <= type && type <= SP_LUK)
+ val = sd->status.attrs[sp_to_attr(type)];
need = pc_need_status_point(sd, type);
if (type < SP_STR || type > SP_LUK || need < 0
@@ -5137,31 +5108,11 @@ int pc_statusup(struct map_session_data *sd, int type)
clif_updatestatus(sd, SP_STATUSPOINT);
return 1;
}
- switch (type)
- {
- case SP_STR:
- val = ++sd->status.str;
- break;
- case SP_AGI:
- val = ++sd->status.agi;
- break;
- case SP_VIT:
- val = ++sd->status.vit;
- break;
- case SP_INT:
- val = ++sd->status.int_;
- break;
- case SP_DEX:
- val = ++sd->status.dex;
- break;
- case SP_LUK:
- val = ++sd->status.luk;
- break;
- }
+ val = ++sd->status.attrs[sp_to_attr(type)];
sd->status.status_point -= need;
if (need != pc_need_status_point(sd, type))
{
- clif_updatestatus(sd, type - SP_STR + SP_USTR);
+ clif_updatestatus(sd, sp_to_usp(type));
}
clif_updatestatus(sd, SP_STATUSPOINT);
clif_updatestatus(sd, type);
@@ -5177,7 +5128,7 @@ int pc_statusup(struct map_session_data *sd, int type)
* 能力値成長
*------------------------------------------
*/
-int pc_statusup2(struct map_session_data *sd, int type, int val)
+int pc_statusup2(struct map_session_data *sd, SP type, int val)
{
nullpo_ret(sd);
@@ -5186,64 +5137,11 @@ int pc_statusup2(struct map_session_data *sd, int type, int val)
clif_statusupack(sd, type, 0, 0);
return 1;
}
- switch (type)
- {
- case SP_STR:
- if (sd->status.str + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.str + val < 1)
- val = 1;
- else
- val += sd->status.str;
- sd->status.str = val;
- break;
- case SP_AGI:
- if (sd->status.agi + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.agi + val < 1)
- val = 1;
- else
- val += sd->status.agi;
- sd->status.agi = val;
- break;
- case SP_VIT:
- if (sd->status.vit + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.vit + val < 1)
- val = 1;
- else
- val += sd->status.vit;
- sd->status.vit = val;
- break;
- case SP_INT:
- if (sd->status.int_ + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.int_ + val < 1)
- val = 1;
- else
- val += sd->status.int_;
- sd->status.int_ = val;
- break;
- case SP_DEX:
- if (sd->status.dex + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.dex + val < 1)
- val = 1;
- else
- val += sd->status.dex;
- sd->status.dex = val;
- break;
- case SP_LUK:
- if (sd->status.luk + val >= battle_config.max_parameter)
- val = battle_config.max_parameter;
- else if (sd->status.luk + val < 1)
- val = 1;
- else
- val = sd->status.luk + val;
- sd->status.luk = val;
- break;
- }
- clif_updatestatus(sd, type - SP_STR + SP_USTR);
+ ATTR attr = sp_to_attr(type);
+ val = sd->status.attrs[attr] + val;
+ val = std::min(val, battle_config.max_parameter);
+ val = std::max(val, 1);
+ clif_updatestatus(sd, sp_to_usp(type));
clif_updatestatus(sd, type);
pc_calcstatus(sd, 0);
clif_statusupack(sd, type, 1, val);
@@ -5353,12 +5251,8 @@ int pc_resetlvl(struct map_session_data *sd, int type)
sd->status.job_exp = 0;
sd->status.option = Option::ZERO;
- sd->status.str = 1;
- sd->status.agi = 1;
- sd->status.vit = 1;
- sd->status.int_ = 1;
- sd->status.dex = 1;
- sd->status.luk = 1;
+ for (ATTR attr : ATTRs)
+ sd->status.attrs[attr] = 1;
if (sd->status.pc_class == 4001)
sd->status.status_point = 100;
}
@@ -5403,12 +5297,13 @@ int pc_resetlvl(struct map_session_data *sd, int type)
clif_updatestatus(sd, SP_UDEX);
clif_updatestatus(sd, SP_ULUK); // End Addition
- for (int i = 0; i < 11; i++)
- { // unequip items that can't be equipped by base 1 [Valaris]
+ for (EQUIP i : EQUIPs)
+ {
+ // unequip items that can't be equipped by base 1 [Valaris]
if (sd->equip_index[i] >= 0)
if (!pc_isequip(sd, sd->equip_index[i]))
{
- pc_unequipitem(sd, sd->equip_index[i], 1);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
sd->equip_index[i] = -1;
}
}
@@ -5436,26 +5331,12 @@ int pc_resetstate(struct map_session_data *sd)
clif_updatestatus(sd, SP_STATUSPOINT);
- sd->status.str = 1;
- sd->status.agi = 1;
- sd->status.vit = 1;
- sd->status.int_ = 1;
- sd->status.dex = 1;
- sd->status.luk = 1;
-
- clif_updatestatus(sd, SP_STR);
- clif_updatestatus(sd, SP_AGI);
- clif_updatestatus(sd, SP_VIT);
- clif_updatestatus(sd, SP_INT);
- clif_updatestatus(sd, SP_DEX);
- clif_updatestatus(sd, SP_LUK);
-
- clif_updatestatus(sd, SP_USTR); // Updates needed stat points - Valaris
- clif_updatestatus(sd, SP_UAGI);
- clif_updatestatus(sd, SP_UVIT);
- clif_updatestatus(sd, SP_UINT);
- clif_updatestatus(sd, SP_UDEX);
- clif_updatestatus(sd, SP_ULUK); // End Addition
+ for (ATTR attr : ATTRs)
+ sd->status.attrs[attr] = 1;
+ for (ATTR attr : ATTRs)
+ clif_updatestatus(sd, attr_to_sp(attr));
+ for (ATTR attr : ATTRs)
+ clif_updatestatus(sd, attr_to_usp(attr));
pc_calcstatus(sd, 0);
@@ -5478,7 +5359,7 @@ int pc_resetskill(struct map_session_data *sd)
if ((skill = pc_checkskill(sd, i)) > 0)
{
sd->status.skill[i].lv = 0;
- sd->status.skill[i].flags = 0;
+ sd->status.skill[i].flags = SkillFlags::ZERO;
}
clif_updatestatus(sd, SP_SKILLPOINT);
@@ -5679,8 +5560,8 @@ int pc_damage(struct block_list *src, struct map_session_data *sd,
for (i = 0; i < MAX_INVENTORY; i++)
{
int k;
- if ((type == 1 && !sd->status.inventory[i].equip)
- || (type == 2 && sd->status.inventory[i].equip)
+ if ((type == 1 && !bool(sd->status.inventory[i].equip))
+ || (type == 2 && bool(sd->status.inventory[i].equip))
|| type == 3)
{
//InventoryIndexを格納
@@ -5700,8 +5581,8 @@ int pc_damage(struct block_list *src, struct map_session_data *sd,
int n = eq_n[MRAND(eq_num)]; //該当アイテムの中からランダム
if (MRAND(10000) < per)
{
- if (sd->status.inventory[n].equip)
- pc_unequipitem(sd, n, 0);
+ if (bool(sd->status.inventory[n].equip))
+ pc_unequipitem(sd, n, CalcStatus::NOW);
pc_dropitem(sd, n, 1);
}
}
@@ -5712,12 +5593,12 @@ int pc_damage(struct block_list *src, struct map_session_data *sd,
{
if (sd->status.inventory[i].nameid == id //ItemIDが一致していて
&& MRAND(10000) < per //ドロップ率判定もOKで
- && ((type == 1 && !sd->status.inventory[i].equip) //タイプ判定もOKならドロップ
- || (type == 2 && sd->status.inventory[i].equip)
+ && ((type == 1 && !bool(sd->status.inventory[i].equip)) //タイプ判定もOKならドロップ
+ || (type == 2 && bool(sd->status.inventory[i].equip))
|| type == 3))
{
- if (sd->status.inventory[i].equip)
- pc_unequipitem(sd, i, 0);
+ if (bool(sd->status.inventory[i].equip))
+ pc_unequipitem(sd, i, CalcStatus::NOW);
pc_dropitem(sd, i, 1);
break;
}
@@ -5773,7 +5654,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd,
* script用PCステータス読み出し
*------------------------------------------
*/
-int pc_readparam(struct map_session_data *sd, int type)
+int pc_readparam(struct map_session_data *sd, SP type)
{
int val = 0;
struct pc_base_job s_class;
@@ -5842,22 +5723,12 @@ int pc_readparam(struct map_session_data *sd, int type)
val = sd->status.max_sp;
break;
case SP_STR:
- val = sd->status.str;
- break;
case SP_AGI:
- val = sd->status.agi;
- break;
case SP_VIT:
- val = sd->status.vit;
- break;
case SP_INT:
- val = sd->status.int_;
- break;
case SP_DEX:
- val = sd->status.dex;
- break;
case SP_LUK:
- val = sd->status.luk;
+ val = sd->status.attrs[sp_to_attr(type)];
break;
case SP_FAME:
val = sd->fame;
@@ -5871,7 +5742,7 @@ int pc_readparam(struct map_session_data *sd, int type)
* script用PCステータス設定
*------------------------------------------
*/
-int pc_setparam(struct map_session_data *sd, int type, int val)
+int pc_setparam(struct map_session_data *sd, SP type, int val)
{
int i = 0, up_level = 50;
struct pc_base_job s_class;
@@ -5978,22 +5849,12 @@ int pc_setparam(struct map_session_data *sd, int type, int val)
sd->status.max_sp = val;
break;
case SP_STR:
- sd->status.str = val;
- break;
case SP_AGI:
- sd->status.agi = val;
- break;
case SP_VIT:
- sd->status.vit = val;
- break;
case SP_INT:
- sd->status.int_ = val;
- break;
case SP_DEX:
- sd->status.dex = val;
- break;
case SP_LUK:
- sd->status.luk = val;
+ sd->status.attrs[sp_to_attr(type)] = val;
break;
case SP_FAME:
sd->fame = val;
@@ -6098,9 +5959,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 = min(current_amount + new_amount, max);
- quick_regen->tickdelay = MIN(quick_regen->speed, quick_regen->tickdelay);
+ quick_regen->tickdelay = min(quick_regen->speed, quick_regen->tickdelay);
}
int pc_itemheal(struct map_session_data *sd, int hp, int sp)
@@ -6164,7 +6025,7 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp)
if (hp > 0)
{
bonus =
- (sd->paramc[2] << 1) + 100 + pc_checkskill(sd, SM_RECOVERY) * 10;
+ (sd->paramc[ATTR::VIT] << 1) + 100 + pc_checkskill(sd, SM_RECOVERY) * 10;
if (bonus != 100)
hp = hp * bonus / 100;
bonus = 100 + pc_checkskill(sd, AM_LEARNINGPOTION) * 5;
@@ -6174,7 +6035,7 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp)
if (sp > 0)
{
bonus =
- (sd->paramc[3] << 1) + 100 + pc_checkskill(sd,
+ (sd->paramc[ATTR::INT] << 1) + 100 + pc_checkskill(sd,
MG_SRECOVERY) * 10;
if (bonus != 100)
sp = sp * bonus / 100;
@@ -6288,7 +6149,6 @@ int pc_percentheal(struct map_session_data *sd, int hp, int sp)
*/
int pc_jobchange(struct map_session_data *sd, int job, int upper)
{
- int i;
int b_class = 0;
//転生や養子の場合の元の職業を算出する
struct pc_base_job s_class = pc_calc_base_job(sd->status.pc_class);
@@ -6341,11 +6201,11 @@ int pc_jobchange(struct map_session_data *sd, int job, int upper)
clif_updatestatus(sd, SP_JOBEXP);
clif_updatestatus(sd, SP_NEXTJOBEXP);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
if (sd->equip_index[i] >= 0)
if (!pc_isequip(sd, sd->equip_index[i]))
- pc_unequipitem(sd, sd->equip_index[i], 1); // 装備外し
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER); // 装備外し
}
clif_changelook(&sd->bl, LOOK_BASE, sd->view_class); // move sprite update to prevent client crashes with incompatible equipment [Valaris]
@@ -6392,7 +6252,7 @@ int pc_equiplookall(struct map_session_data *sd)
* 見た目変更
*------------------------------------------
*/
-int pc_changelook(struct map_session_data *sd, int type, int val)
+int pc_changelook(struct map_session_data *sd, LOOK type, int val)
{
nullpo_ret(sd);
@@ -6977,22 +6837,22 @@ int pc_cleareventtimer(struct map_session_data *sd)
static
int pc_signal_advanced_equipment_change(struct map_session_data *sd, int n)
{
- if (sd->status.inventory[n].equip & 0x0040)
+ if (bool(sd->status.inventory[n].equip & EPOS::SHOES))
clif_changelook(&sd->bl, LOOK_SHOES, 0);
- if (sd->status.inventory[n].equip & 0x0004)
+ if (bool(sd->status.inventory[n].equip & EPOS::GLOVES))
clif_changelook(&sd->bl, LOOK_GLOVES, 0);
- if (sd->status.inventory[n].equip & 0x0008)
+ if (bool(sd->status.inventory[n].equip & EPOS::CAPE))
clif_changelook(&sd->bl, LOOK_CAPE, 0);
- if (sd->status.inventory[n].equip & 0x0010)
+ if (bool(sd->status.inventory[n].equip & EPOS::MISC1))
clif_changelook(&sd->bl, LOOK_MISC1, 0);
- if (sd->status.inventory[n].equip & 0x0080)
+ if (bool(sd->status.inventory[n].equip & EPOS::MISC2))
clif_changelook(&sd->bl, LOOK_MISC2, 0);
return 0;
}
-int pc_equipitem(struct map_session_data *sd, int n, int pos)
+int pc_equipitem(struct map_session_data *sd, int n, EPOS)
{
- int i, nameid, arrow, view;
+ int nameid, arrow, view;
struct item_data *id;
//ソス]ソスソスソスソスソス{ソスqソスフ場合ソスフ鯉ソスソスフ職ソスニゑソスソスZソスoソスソスソスソス
@@ -7000,19 +6860,20 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
if (n < 0 || n >= MAX_INVENTORY)
{
- clif_equipitemack(sd, 0, 0, 0);
+ clif_equipitemack(sd, 0, EPOS::ZERO, 0);
return 0;
}
nameid = sd->status.inventory[n].nameid;
id = sd->inventory_data[n];
- pos = pc_equippoint(sd, n);
+ EPOS pos = pc_equippoint(sd, n);
if (battle_config.battle_log)
- printf("equip %d (%d) %x:%x\n", nameid, n, id->equip, pos);
- if (!pc_isequip(sd, n) || !pos || sd->status.inventory[n].broken == 1)
+ printf("equip %d (%d) %x:%x\n",
+ nameid, n, uint16_t(id->equip), uint16_t(pos));
+ if (!pc_isequip(sd, n) || pos == EPOS::ZERO || sd->status.inventory[n].broken == 1)
{ // [Valaris]
- clif_equipitemack(sd, n, 0, 0); // fail
+ clif_equipitemack(sd, n, EPOS::ZERO, 0); // fail
return 0;
}
@@ -7020,47 +6881,50 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
//
if (sd->sc_data[SC_BERSERK].timer != -1)
{
- clif_equipitemack(sd, n, 0, 0); // fail
+ clif_equipitemack(sd, n, EPOS::ZERO, 0); // fail
return 0;
}
- if (pos == 0x88)
- { // アクセサリ用例外処理
- int epor = 0;
- if (sd->equip_index[0] >= 0)
- epor |= sd->status.inventory[sd->equip_index[0]].equip;
- if (sd->equip_index[1] >= 0)
- epor |= sd->status.inventory[sd->equip_index[1]].equip;
- epor &= 0x88;
- pos = epor == 0x08 ? 0x80 : 0x08;
+ if (bool(pos == (EPOS::MISC2 | EPOS::CAPE)))
+ {
+ // アクセサリ用例外処理
+ EPOS epor = EPOS::ZERO;
+ if (sd->equip_index[EQUIP::MISC2] >= 0)
+ epor |= sd->status.inventory[sd->equip_index[EQUIP::MISC2]].equip;
+ if (sd->equip_index[EQUIP::CAPE] >= 0)
+ epor |= sd->status.inventory[sd->equip_index[EQUIP::CAPE]].equip;
+ epor &= (EPOS::MISC2 | EPOS::CAPE);
+ pos = (epor == EPOS::CAPE ? EPOS::MISC2 : EPOS::CAPE);
}
// 二刀流処理
- if ((pos == 0x22) // 一応、装備要求箇所が二刀流武器かチェックする
- && (id->equip == 2) // 単 手武器
+ if ((pos == (EPOS::SHIELD | EPOS::WEAPON)) // 一応、装備要求箇所が二刀流武器かチェックする
+ && (id->equip == EPOS::WEAPON) // 単 手武器
&& (pc_checkskill(sd, AS_LEFT) > 0 || sd->status.pc_class == 12)) // 左手修錬有
{
- int tpos = 0;
- if (sd->equip_index[8] >= 0)
- tpos |= sd->status.inventory[sd->equip_index[8]].equip;
- if (sd->equip_index[9] >= 0)
- tpos |= sd->status.inventory[sd->equip_index[9]].equip;
- tpos &= 0x02;
- pos = tpos == 0x02 ? 0x20 : 0x02;
+ EPOS tpos = EPOS::ZERO;
+ if (sd->equip_index[EQUIP::SHIELD] >= 0)
+ tpos |= sd->status.inventory[sd->equip_index[EQUIP::SHIELD]].equip;
+ if (sd->equip_index[EQUIP::WEAPON] >= 0)
+ tpos |= sd->status.inventory[sd->equip_index[EQUIP::WEAPON]].equip;
+ tpos &= EPOS::WEAPON;
+ pos = tpos == EPOS::WEAPON ? EPOS::SHIELD : EPOS::WEAPON;
}
- arrow = pc_search_inventory(sd, pc_checkequip(sd, 9)); // Added by RoVeRT
- for (i = 0; i < 11; i++)
+ // TODO: make this code do what it's supposed to do,
+ // instead of what it does
+ arrow = pc_search_inventory(sd, pc_checkequip(sd, EPOS::LEGS | EPOS::CAPE)); // Added by RoVeRT
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
{
if (sd->equip_index[i] >= 0) //Slot taken, remove item from there.
- pc_unequipitem(sd, sd->equip_index[i], 1);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
sd->equip_index[i] = n;
}
}
// 弓矢装備
- if (pos == 0x8000)
+ if (pos == EPOS::ARROW)
{
clif_arrowequip(sd, n);
clif_arrow_fail(sd, 3); // 3=矢が装備できました
@@ -7068,13 +6932,13 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
else
{
/* Don't update re-equipping if we're using a spell */
- if (!(pos == 4 && sd->attack_spell_override))
+ if (!(pos == EPOS::GLOVES && sd->attack_spell_override))
clif_equipitemack(sd, n, pos, 1);
}
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (pos & equip_pos[i])
+ if (bool(pos & equip_pos[i]))
sd->equip_index[i] = n;
}
sd->status.inventory[n].equip = pos;
@@ -7090,23 +6954,23 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
view = 0;
}
- if (sd->status.inventory[n].equip & 0x0002)
+ if (bool(sd->status.inventory[n].equip & EPOS::WEAPON))
{
sd->weapontype1 = view;
pc_calcweapontype(sd);
pc_set_weapon_look(sd);
}
- if (sd->status.inventory[n].equip & 0x0020)
+ if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
if (sd->inventory_data[n])
{
- if (sd->inventory_data[n]->type == 4)
+ if (sd->inventory_data[n]->type == ItemType::WEAPON)
{
sd->status.shield = 0;
- if (sd->status.inventory[n].equip == 0x0020)
+ if (sd->status.inventory[n].equip == EPOS::SHIELD)
sd->weapontype2 = view;
}
- else if (sd->inventory_data[n]->type == 5)
+ else if (sd->inventory_data[n]->type == ItemType::ARMOR)
{
sd->status.shield = view;
sd->weapontype2 = 0;
@@ -7117,17 +6981,17 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
pc_calcweapontype(sd);
clif_changelook(&sd->bl, LOOK_SHIELD, sd->status.shield);
}
- if (sd->status.inventory[n].equip & 0x0001)
+ if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
sd->status.head_bottom = view;
clif_changelook(&sd->bl, LOOK_HEAD_BOTTOM, sd->status.head_bottom);
}
- if (sd->status.inventory[n].equip & 0x0100)
+ if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
sd->status.head_top = view;
clif_changelook(&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
}
- if (sd->status.inventory[n].equip & 0x0200)
+ if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
sd->status.head_mid = view;
clif_changelook(&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
@@ -7138,7 +7002,7 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
if (itemdb_look(sd->status.inventory[n].nameid) == 11 && arrow)
{ // Added by RoVeRT
clif_arrowequip(sd, arrow);
- sd->status.inventory[arrow].equip = 32768;
+ sd->status.inventory[arrow].equip = EPOS::ARROW;
}
pc_calcstatus(sd, 0);
@@ -7167,7 +7031,7 @@ int pc_equipitem(struct map_session_data *sd, int n, int pos)
* 装 備した物を外す
*------------------------------------------
*/
-int pc_unequipitem(struct map_session_data *sd, int n, int type)
+int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type)
{
nullpo_ret(sd);
@@ -7175,46 +7039,46 @@ int pc_unequipitem(struct map_session_data *sd, int n, int type)
//
if (sd->sc_data[SC_BERSERK].timer != -1)
{
- clif_unequipitemack(sd, n, 0, 0);
+ clif_unequipitemack(sd, n, EPOS::ZERO, 0);
return 0;
}
if (battle_config.battle_log)
- printf("unequip %d %x:%x\n", n, pc_equippoint(sd, n),
- sd->status.inventory[n].equip);
- if (sd->status.inventory[n].equip)
+ printf("unequip %d %x:%x\n",
+ n, uint16_t(pc_equippoint(sd, n)),
+ uint16_t(sd->status.inventory[n].equip));
+ if (bool(sd->status.inventory[n].equip))
{
- int i;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (sd->status.inventory[n].equip & equip_pos[i])
+ if (bool(sd->status.inventory[n].equip & equip_pos[i]))
sd->equip_index[i] = -1;
}
- if (sd->status.inventory[n].equip & 0x0002)
+ if (bool(sd->status.inventory[n].equip & EPOS::WEAPON))
{
sd->weapontype1 = 0;
sd->status.weapon = sd->weapontype2;
pc_calcweapontype(sd);
pc_set_weapon_look(sd);
}
- if (sd->status.inventory[n].equip & 0x0020)
+ if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
sd->status.shield = sd->weapontype2 = 0;
pc_calcweapontype(sd);
clif_changelook(&sd->bl, LOOK_SHIELD, sd->status.shield);
}
- if (sd->status.inventory[n].equip & 0x0001)
+ if (bool(sd->status.inventory[n].equip & EPOS::LEGS))
{
sd->status.head_bottom = 0;
clif_changelook(&sd->bl, LOOK_HEAD_BOTTOM,
sd->status.head_bottom);
}
- if (sd->status.inventory[n].equip & 0x0100)
+ if (bool(sd->status.inventory[n].equip & EPOS::HAT))
{
sd->status.head_top = 0;
clif_changelook(&sd->bl, LOOK_HEAD_TOP, sd->status.head_top);
}
- if (sd->status.inventory[n].equip & 0x0200)
+ if (bool(sd->status.inventory[n].equip & EPOS::TORSO))
{
sd->status.head_mid = 0;
clif_changelook(&sd->bl, LOOK_HEAD_MID, sd->status.head_mid);
@@ -7222,22 +7086,22 @@ int pc_unequipitem(struct map_session_data *sd, int n, int type)
pc_signal_advanced_equipment_change(sd, n);
if (sd->sc_data[SC_BROKNWEAPON].timer != -1
- && sd->status.inventory[n].equip & 0x0002
- && sd->status.inventory[i].broken == 1)
+ && bool(sd->status.inventory[n].equip & EPOS::WEAPON)
+ && sd->status.inventory[n].broken == 1)
skill_status_change_end(&sd->bl, SC_BROKNWEAPON, -1);
clif_unequipitemack(sd, n, sd->status.inventory[n].equip, 1);
- sd->status.inventory[n].equip = 0;
- if (!type)
+ sd->status.inventory[n].equip = EPOS::ZERO;
+ if (type == CalcStatus::NOW)
pc_checkallowskill(sd);
if (sd->weapontype1 == 0 && sd->weapontype2 == 0)
skill_encchant_eremental_end(&sd->bl, StatusChange::NEGATIVE1);
}
else
{
- clif_unequipitemack(sd, n, 0, 0);
+ clif_unequipitemack(sd, n, EPOS::ZERO, 0);
}
- if (!type)
+ if (type == CalcStatus::NOW)
{
pc_calcstatus(sd, 0);
if (sd->sc_data[SC_SIGNUMCRUCIS].timer != -1
@@ -7248,16 +7112,17 @@ int pc_unequipitem(struct map_session_data *sd, int n, int type)
return 0;
}
-int pc_unequipinvyitem(struct map_session_data *sd, int n, int type)
+int pc_unequipinvyitem(struct map_session_data *sd, int n, CalcStatus type)
{
- int i;
-
nullpo_retr(1, sd);
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
{
- if (equip_pos[i] > 0 && sd->equip_index[i] == n)
- { //Slot taken, remove item from there.
+ if (equip_pos[i] != EPOS::ZERO
+ && !bool(equip_pos[i] & EPOS::ARROW) // probably a bug
+ && sd->equip_index[i] == n)
+ {
+ //Slot taken, remove item from there.
pc_unequipitem(sd, sd->equip_index[i], type);
sd->equip_index[i] = -1;
}
@@ -7338,16 +7203,17 @@ int pc_checkitem(struct map_session_data *sd)
if (sd->status.inventory[i].nameid == 0)
continue;
- if (sd->status.inventory[i].equip & ~pc_equippoint(sd, i))
+ if (bool(sd->status.inventory[i].equip & ~pc_equippoint(sd, i)))
{
- sd->status.inventory[i].equip = 0;
+ sd->status.inventory[i].equip = EPOS::ZERO;
calc_flag = 1;
}
//装備制限チェック
- if (sd->status.inventory[i].equip && map[sd->bl.m].flag.pvp
+ if (bool(sd->status.inventory[i].equip)
+ && map[sd->bl.m].flag.pvp
&& (it->flag.no_equip == 1 || it->flag.no_equip == 3))
{ //PvP制限
- sd->status.inventory[i].equip = 0;
+ sd->status.inventory[i].equip = EPOS::ZERO;
calc_flag = 1;
}
}
@@ -7895,7 +7761,7 @@ int pc_quickregenerate_effect(struct quick_regeneration *quick_regen,
if (!(quick_regen->tickdelay--))
{
int bonus =
- MIN(heal_speed * battle_config.itemheal_regeneration_factor,
+ min(heal_speed * battle_config.itemheal_regeneration_factor,
quick_regen->amount);
quick_regen->amount -= bonus;
diff --git a/src/map/pc.hpp b/src/map/pc.hpp
index c881178..97163b1 100644
--- a/src/map/pc.hpp
+++ b/src/map/pc.hpp
@@ -1,6 +1,8 @@
#ifndef PC_HPP
#define PC_HPP
+#include "pc.t.hpp"
+
#include "map.hpp"
inline
@@ -69,20 +71,20 @@ int pc_getrefinebonus(int lv, int type);
void pc_invisibility(struct map_session_data *sd, int enabled); // [Fate]
int pc_counttargeted(struct map_session_data *sd, struct block_list *src,
- int target_lv);
+ ATK target_lv);
int pc_setrestartvalue(struct map_session_data *sd, int type);
int pc_makesavestatus(struct map_session_data *);
int pc_setnewpc(struct map_session_data *, int, int, int, int, int, int);
int pc_authok(int, int, time_t, short tmw_version, struct mmo_charstatus *);
int pc_authfail(int);
-int pc_equippoint(struct map_session_data *sd, int n);
+EPOS pc_equippoint(struct map_session_data *sd, int n);
int pc_breakweapon(struct map_session_data *sd); // weapon breaking [Valaris]
int pc_breakarmor(struct map_session_data *sd); // armor breaking [Valaris]
int pc_checkskill(struct map_session_data *sd, SkillID skill_id);
-int pc_checkequip(struct map_session_data *sd, int pos);
+int pc_checkequip(struct map_session_data *sd, EPOS pos);
int pc_walktoxy(struct map_session_data *, int, int);
int pc_stop_walking(struct map_session_data *, int);
@@ -91,11 +93,11 @@ int pc_setpos(struct map_session_data *, const char *, int, int, int);
int pc_setsavepoint(struct map_session_data *, const char *, int, int);
int pc_randomwarp(struct map_session_data *sd, int type);
-int pc_checkadditem(struct map_session_data *, int, int);
+ADDITEM pc_checkadditem(struct map_session_data *, int, int);
int pc_inventoryblank(struct map_session_data *);
int pc_search_inventory(struct map_session_data *sd, int item_id);
int pc_payzeny(struct map_session_data *, int);
-int pc_additem(struct map_session_data *, struct item *, int);
+PickupFail pc_additem(struct map_session_data *, struct item *, int);
int pc_getzeny(struct map_session_data *, int);
int pc_delitem(struct map_session_data *, int, int, int);
int pc_checkitem(struct map_session_data *);
@@ -109,9 +111,9 @@ int pc_dropitem(struct map_session_data *, int, int);
int pc_checkweighticon(struct map_session_data *sd);
int pc_calcstatus(struct map_session_data *, int);
-int pc_bonus(struct map_session_data *, int, int);
-int pc_bonus2(struct map_session_data *sd, int, int, int);
-int pc_bonus3(struct map_session_data *sd, int, int, int, int);
+int pc_bonus(struct map_session_data *, SP, int);
+int pc_bonus2(struct map_session_data *sd, SP, int, int);
+int pc_bonus3(struct map_session_data *sd, SP, int, int, int);
int pc_skill(struct map_session_data *, SkillID, int, int);
int pc_steal_item(struct map_session_data *sd, struct block_list *bl);
@@ -125,25 +127,23 @@ int pc_stopattack(struct map_session_data *);
int pc_gainexp(struct map_session_data *, int, int);
-#define PC_GAINEXP_REASON_KILLING 0
-#define PC_GAINEXP_REASON_HEALING 1
-#define PC_GAINEXP_REASON_SCRIPT 2
-int pc_gainexp_reason(struct map_session_data *, int, int, int reason);
+int pc_gainexp_reason(struct map_session_data *, int, int,
+ PC_GAINEXP_REASON reason);
int pc_extract_healer_exp(struct map_session_data *, int max); // [Fate] Used by healers: extract healer-xp from the target, return result (up to max)
int pc_nextbaseexp(struct map_session_data *);
int pc_nextjobexp(struct map_session_data *);
-int pc_need_status_point(struct map_session_data *, int);
-int pc_statusup(struct map_session_data *, int);
-int pc_statusup2(struct map_session_data *, int, int);
+int pc_need_status_point(struct map_session_data *, SP);
+int pc_statusup(struct map_session_data *, SP);
+int pc_statusup2(struct map_session_data *, SP, int);
int pc_skillup(struct map_session_data *, SkillID);
int pc_allskillup(struct map_session_data *);
int pc_resetlvl(struct map_session_data *, int type);
int pc_resetstate(struct map_session_data *);
int pc_resetskill(struct map_session_data *);
-int pc_equipitem(struct map_session_data *, int, int);
-int pc_unequipitem(struct map_session_data *, int, int);
-int pc_unequipinvyitem(struct map_session_data *, int, int);
+int pc_equipitem(struct map_session_data *, int, EPOS);
+int pc_unequipitem(struct map_session_data *, int, CalcStatus);
+int pc_unequipinvyitem(struct map_session_data *, int, CalcStatus);
int pc_useitem(struct map_session_data *, int);
int pc_damage(struct block_list *, struct map_session_data *, int);
@@ -155,10 +155,10 @@ int pc_setoption(struct map_session_data *, Option);
int pc_setcart(struct map_session_data *sd, int type);
int pc_setfalcon(struct map_session_data *sd);
int pc_setriding(struct map_session_data *sd);
-int pc_changelook(struct map_session_data *, int, int);
+int pc_changelook(struct map_session_data *, LOOK, int);
-int pc_readparam(struct map_session_data *, int);
-int pc_setparam(struct map_session_data *, int, int);
+int pc_readparam(struct map_session_data *, SP);
+int pc_setparam(struct map_session_data *, SP, int);
int pc_readreg(struct map_session_data *, int);
int pc_setreg(struct map_session_data *, int, int);
char *pc_readregstr(struct map_session_data *sd, int reg);
@@ -207,9 +207,6 @@ int pc_logout(struct map_session_data *sd); // [fate] Player logs out
int do_init_pc(void);
-enum
-{ ADDITEM_EXIST, ADDITEM_NEW, ADDITEM_OVERAMOUNT };
-
// timer for night.day
extern timer_id day_timer_tid;
extern timer_id night_timer_tid;
diff --git a/src/map/pc.t.hpp b/src/map/pc.t.hpp
new file mode 100644
index 0000000..3a21691
--- /dev/null
+++ b/src/map/pc.t.hpp
@@ -0,0 +1,49 @@
+#ifndef PC_T_HPP
+#define PC_T_HPP
+
+#include <cstdint>
+
+enum class PC_GAINEXP_REASON
+{
+ KILLING = 0,
+#define PC_GAINEXP_REASON_KILLING PC_GAINEXP_REASON::KILLING
+ HEALING = 1,
+#define PC_GAINEXP_REASON_HEALING PC_GAINEXP_REASON::HEALING
+ // temporary rename to avoid collision with npc subtypes
+ SCRIPT_ = 2,
+#define PC_GAINEXP_REASON_SCRIPT PC_GAINEXP_REASON::SCRIPT_
+
+ COUNT,
+};
+
+enum class ADDITEM
+{
+ EXIST,
+#define ADDITEM_EXIST ADDITEM::EXIST
+ NEW,
+#define ADDITEM_NEW ADDITEM::NEW
+ OVERAMOUNT,
+#define ADDITEM_OVERAMOUNT ADDITEM::OVERAMOUNT
+
+ // when used as error in nullpo_retr
+ ZERO = 0,
+};
+
+enum class CalcStatus
+{
+ NOW,
+ LATER ,
+};
+
+enum class PickupFail : uint8_t
+{
+ OKAY = 0,
+ BAD_ITEM = 1,
+ TOO_HEAVY = 2,
+ TOO_FAR = 3,
+ INV_FULL = 4,
+ STACK_FULL = 5,
+ DROP_STEAL = 6,
+};
+
+#endif // PC_T_HPP
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 43451ef..cb43f64 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -1056,7 +1056,7 @@ void get_val(ScriptState *st, struct script_data *data)
if (sd)
data->u.num =
pc_readparam(sd,
- str_data[data->u.num & 0x00ffffff].val);
+ SP(str_data[data->u.num & 0x00ffffff].val));
}
else if (prefix == '@' || prefix == 'l')
{
@@ -1135,7 +1135,7 @@ void set_reg(struct map_session_data *sd, int num, const char *name, struct scri
int val = vd.u.num;
if (str_data[num & 0x00ffffff].type == ScriptCode::PARAM)
{
- pc_setparam(sd, str_data[num & 0x00ffffff].val, val);
+ pc_setparam(sd, SP(str_data[num & 0x00ffffff].val), val);
}
else if (prefix == '@' || prefix == 'l')
{
@@ -1967,10 +1967,8 @@ void builtin_getelementofarray(ScriptState *st)
static
void builtin_setlook(ScriptState *st)
{
- int type, val;
-
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ LOOK type = LOOK(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
pc_changelook(script_rid2sd(st), type, val);
@@ -2067,7 +2065,7 @@ void builtin_checkweight(ScriptState *st)
static
void builtin_getitem(ScriptState *st)
{
- int nameid, amount, flag = 0;
+ int nameid, amount;
struct item item_tmp;
struct map_session_data *sd;
struct script_data *data;
@@ -2092,18 +2090,19 @@ void builtin_getitem(ScriptState *st)
{
return; //return if amount <=0, skip the useles iteration
}
+ bool flag1 = false;
//Violet Box, Blue Box, etc - random item pick
if (nameid < 0)
{ // ランダム
nameid = itemdb_searchrandomid(-nameid);
- flag = 1;
+ flag1 = 1;
}
if (nameid > 0)
{
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = nameid;
- if (!flag)
+ if (!flag1)
item_tmp.identify = 1;
else
item_tmp.identify = !itemdb_isequip3(nameid);
@@ -2111,7 +2110,8 @@ void builtin_getitem(ScriptState *st)
sd = map_id2sd(conv_num(st, &(st->stack->stack_data[st->start + 5])));
if (sd == NULL) //アイテムを渡す相手がいなかったらお帰り
return;
- if ((flag = pc_additem(sd, &item_tmp, amount)))
+ PickupFail flag;
+ if ((flag = pc_additem(sd, &item_tmp, amount)) != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, flag);
map_addflooritem(&item_tmp, amount, sd->bl.m, sd->bl.x, sd->bl.y,
@@ -2219,7 +2219,7 @@ void builtin_delitem(ScriptState *st)
{
if (sd->status.inventory[i].nameid <= 0
|| sd->inventory_data[i] == NULL
- || sd->inventory_data[i]->type != 7
+ || sd->inventory_data[i]->type != ItemType::_7
|| sd->status.inventory[i].amount <= 0)
continue;
}
@@ -2252,10 +2252,9 @@ void builtin_delitem(ScriptState *st)
static
void builtin_readparam(ScriptState *st)
{
- int type;
struct map_session_data *sd;
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
if (st->end > st->start + 3)
sd = map_nick2sd(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
@@ -2360,18 +2359,20 @@ void builtin_strcharinfo(ScriptState *st)
}
-unsigned int equip[10] =
+// indexed by the equip_* in db/const.txt
+// TODO change to use EQUIP
+EPOS equip[10] =
{
- 0x0100,
- 0x0010,
- 0x0020,
- 0x0002,
- 0x0004,
- 0x0040,
- 0x0008,
- 0x0080,
- 0x0200,
- 0x0001,
+ EPOS::HAT,
+ EPOS::MISC1,
+ EPOS::SHIELD,
+ EPOS::WEAPON,
+ EPOS::GLOVES,
+ EPOS::SHOES,
+ EPOS::CAPE,
+ EPOS::MISC2,
+ EPOS::TORSO,
+ EPOS::LEGS,
};
/*==========================================
@@ -2446,12 +2447,9 @@ void builtin_getequipname(ScriptState *st)
static
void builtin_statusup2(ScriptState *st)
{
- int type, val;
- struct map_session_data *sd;
-
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd(st);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ struct map_session_data *sd = script_rid2sd(st);
pc_statusup2(sd, type, val);
}
@@ -2463,12 +2461,9 @@ void builtin_statusup2(ScriptState *st)
static
void builtin_bonus(ScriptState *st)
{
- int type, val;
- struct map_session_data *sd;
-
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- sd = script_rid2sd(st);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ struct map_session_data *sd = script_rid2sd(st);
pc_bonus(sd, type, val);
}
@@ -2480,13 +2475,10 @@ void builtin_bonus(ScriptState *st)
static
void builtin_bonus2(ScriptState *st)
{
- int type, type2, val;
- struct map_session_data *sd;
-
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- type2 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
- val = conv_num(st, &(st->stack->stack_data[st->start + 4]));
- sd = script_rid2sd(st);
+ SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int type2 = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ int val = conv_num(st, &(st->stack->stack_data[st->start + 4]));
+ struct map_session_data *sd = script_rid2sd(st);
pc_bonus2(sd, type, type2, val);
}
@@ -3818,7 +3810,7 @@ void builtin_getinventorylist(ScriptState *st)
pc_setreg(sd, add_str("@inventorylist_amount") + (j << 24),
sd->status.inventory[i].amount);
pc_setreg(sd, add_str("@inventorylist_equip") + (j << 24),
- sd->status.inventory[i].equip);
+ uint16_t(sd->status.inventory[i].equip));
pc_setreg(sd, add_str("@inventorylist_refine") + (j << 24),
sd->status.inventory[i].refine);
pc_setreg(sd, add_str("@inventorylist_identify") + (j << 24),
@@ -3861,7 +3853,7 @@ void builtin_getactivatedpoolskilllist(ScriptState *st)
pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
sd->status.skill[skill_id].lv);
pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
- sd->status.skill[skill_id].flags);
+ uint16_t(sd->status.skill[skill_id].flags));
pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
skill_name(skill_id));
++count;
@@ -3884,14 +3876,15 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st)
{
SkillID skill_id = skill_pool_skills[i];
- if (sd->status.skill[skill_id].id == skill_id && !(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
+ if (sd->status.skill[skill_id].id == skill_id
+ && !bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
{
pc_setreg(sd, add_str("@skilllist_id") + (count << 24),
uint16_t(sd->status.skill[skill_id].id));
pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
sd->status.skill[skill_id].lv);
pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
- sd->status.skill[skill_id].flags);
+ uint16_t(sd->status.skill[skill_id].flags));
pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
skill_name(skill_id));
++count;
@@ -4021,14 +4014,13 @@ static
void builtin_nude(ScriptState *st)
{
struct map_session_data *sd = script_rid2sd(st);
- int i;
if (sd == NULL)
return;
- for (i = 0; i < 11; i++)
+ for (EQUIP i : EQUIPs)
if (sd->equip_index[i] >= 0)
- pc_unequipitem(sd, sd->equip_index[i], i);
+ pc_unequipitem(sd, sd->equip_index[i], CalcStatus::LATER);
pc_calcstatus(sd, 0);
}
@@ -4045,10 +4037,11 @@ void builtin_unequipbyid(ScriptState *st)
if (sd == NULL)
return;
- int slot_id = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ EQUIP slot_id = EQUIP(conv_num(st, &(st->stack->stack_data[st->start + 2])));
- if (slot_id >= 0 && slot_id < 11 && sd->equip_index[slot_id] >= 0)
- pc_unequipitem(sd, sd->equip_index[slot_id], slot_id);
+ if (slot_id >= EQUIP() && slot_id < EQUIP::COUNT
+ && sd->equip_index[slot_id] >= 0)
+ pc_unequipitem(sd, sd->equip_index[slot_id], CalcStatus::LATER);
pc_calcstatus(sd, 0);
@@ -4159,12 +4152,10 @@ void builtin_npctalk(ScriptState *st)
static
void builtin_getlook(ScriptState *st)
{
- int type, val;
- struct map_session_data *sd;
- sd = script_rid2sd(st);
+ struct map_session_data *sd = script_rid2sd(st);
- type = conv_num(st, &(st->stack->stack_data[st->start + 2]));
- val = -1;
+ LOOK type = LOOK(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ int val = -1;
switch (type)
{
case LOOK_HAIR: //1
diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp
index b936518..c20c863 100644
--- a/src/map/skill-pools.cpp
+++ b/src/map/skill-pools.cpp
@@ -43,7 +43,7 @@ int skill_pool(struct map_session_data *sd, SkillID *skills)
for (i = 0; count < MAX_SKILL_POOL && i < skill_pool_skills_size; i++)
{
SkillID skill_id = skill_pool_skills[i];
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
{
if (skills)
skills[count] = skill_id;
@@ -66,7 +66,7 @@ int skill_pool_max(struct map_session_data *sd)
int skill_pool_activate(struct map_session_data *sd, SkillID skill_id)
{
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
return 0; // Already there
else if (sd->status.skill[skill_id].id == skill_id // knows the skill
&& (skill_pool_size(sd) < skill_pool_max(sd)))
@@ -82,14 +82,14 @@ int skill_pool_activate(struct map_session_data *sd, SkillID skill_id)
return 1; // failed
}
-int skill_pool_is_activated(struct map_session_data *sd, SkillID skill_id)
+bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill_id)
{
- return sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED;
+ return bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED);
}
int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id)
{
- if (sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED)
+ if (bool(sd->status.skill[skill_id].flags & SKILL_POOL_ACTIVATED))
{
sd->status.skill[skill_id].flags &= ~SKILL_POOL_ACTIVATED;
MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", uint16_t(skill_id));
@@ -103,18 +103,18 @@ int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id)
// Yields the stat associated with a skill.
// Returns zero if none, or SP_STR, SP_VIT, ... otherwise
static
-int skill_stat(SkillID skill_id)
+SP skill_stat(SkillID skill_id)
{
return skill_db[skill_id].stat;
}
int skill_power(struct map_session_data *sd, SkillID skill_id)
{
- int stat = skill_stat(skill_id);
+ SP stat = skill_stat(skill_id);
int stat_value, skill_value;
int result;
- if (stat == 0 || !skill_pool_is_activated(sd, skill_id))
+ if (stat == SP::ZERO || !skill_pool_is_activated(sd, skill_id))
return 0;
stat_value = battle_get_stat(stat, &(sd->bl));
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index 06351dc..3050012 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -962,11 +962,11 @@ earray<struct skill_db, SkillID, MAX_SKILL_DB> skill_db;
static
int skill_addtimerskill(struct block_list *src, unsigned int tick,
int target, int x, int y, SkillID skill_id, int skill_lv,
- int type, int flag);
+ skill_timerskill::sktst type, BCT flag);
static
-int skill_attack(int attack_type, struct block_list *src,
+int skill_attack(BF attack_type, struct block_list *src,
struct block_list *dsrc, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick, int flag);
+ SkillID skillid, int skilllv, unsigned int tick, BCT flag);
static
void skill_brandishspear_dir(struct square *tc, int dir, int are);
static
@@ -1307,7 +1307,7 @@ int skill_get_unit_id(SkillID id, int flag)
*------------------------------------------
*/
int skill_additional_effect(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, int attack_type,
+ SkillID skillid, int skilllv, BF attack_type,
unsigned int tick)
{
struct map_session_data *sd = NULL;
@@ -1379,12 +1379,12 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
/* 自動鷹 */
if (sd && pc_isfalcon(sd) && sd->status.weapon == 11
&& (skill = pc_checkskill(sd, HT_BLITZBEAT)) > 0
- && MRAND(1000) <= sd->paramc[5] * 10 / 3 + 1)
+ && MRAND(1000) <= sd->paramc[ATTR::LUK] * 10 / 3 + 1)
{
int lv = (sd->status.job_level + 9) / 10;
skill_castend_damage_id(src, bl, HT_BLITZBEAT,
(skill < lv) ? skill : lv, tick,
- 0xf00000);
+ BCT_highnib);
}
// スナッチャー
if (sd && sd->status.weapon != 11
@@ -1707,7 +1707,9 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
break;
}
- if (not (sd && skillid != MC_CARTREVOLUTION && attack_type & BF_WEAPON))
+ if (not (sd
+ && skillid != MC_CARTREVOLUTION
+ && bool(attack_type & BF_WEAPON)))
return 0;
earray<int, BadSC, BadSC::COUNT> arr_sc_def_card1 =
{
@@ -1792,7 +1794,8 @@ int skill_blown(struct block_list *src, struct block_list *target, int count)
{
int dx = 0, dy = 0, nx, ny;
int x = target->x, y = target->y;
- int ret, prev_state = MS_IDLE;
+ int ret;
+ MS prev_state = MS_IDLE;
int moveblock;
struct map_session_data *sd = NULL;
struct mob_data *md = NULL;
@@ -1869,7 +1872,7 @@ int skill_blown(struct block_list *src, struct block_list *target, int count)
map_foreachinmovearea(std::bind(clif_pcoutsight, ph::_1, sd),
target->m, x - AREA_SIZE, y - AREA_SIZE,
x + AREA_SIZE, y + AREA_SIZE,
- dx, dy, 0);
+ dx, dy, BL_NUL);
else if (md)
map_foreachinmovearea(std::bind(clif_moboutsight, ph::_1, md),
target->m, x - AREA_SIZE, y - AREA_SIZE,
@@ -1903,7 +1906,7 @@ int skill_blown(struct block_list *src, struct block_list *target, int count)
map_foreachinmovearea(std::bind(clif_pcinsight, ph::_1, sd),
target->m, nx - AREA_SIZE, ny - AREA_SIZE,
nx + AREA_SIZE, ny + AREA_SIZE,
- -dx, -dy, 0);
+ -dx, -dy, BL_NUL);
if (count & 0x20000)
sd->walktimer = -1;
}
@@ -1934,9 +1937,9 @@ int skill_blown(struct block_list *src, struct block_list *target, int count)
*-------------------------------------------------------------------------
*/
-int skill_attack(int attack_type, struct block_list *src,
- struct block_list *dsrc, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick, int flag)
+int skill_attack(BF attack_type, struct block_list *src,
+ struct block_list *dsrc, struct block_list *bl,
+ SkillID skillid, int skilllv, unsigned int tick, BCT flag)
{
struct Damage dmg;
eptr<struct status_change, StatusChange> sc_data;
@@ -1988,7 +1991,9 @@ int skill_attack(int attack_type, struct block_list *src,
dmg = battle_calc_attack(attack_type, src, bl, skillid, skilllv, flag & 0xff); //ダメージ計算
//マジックロッド処理ここから
- if (attack_type & BF_MAGIC && sc_data && sc_data[SC_MAGICROD].timer != -1
+ if (bool(attack_type & BF_MAGIC)
+ && sc_data
+ && sc_data[SC_MAGICROD].timer != -1
&& src == dsrc)
{ //魔法攻撃でマジックロッド状態でsrc=dsrcなら
dmg.damage = dmg.damage2 = 0; //ダメージ0
@@ -2121,7 +2126,10 @@ int skill_attack(int attack_type, struct block_list *src,
//使用者がPCの場合の処理ここまで
//武器スキル?ここから
//AppleGirl Was Here
- if (attack_type & BF_MAGIC && damage > 0 && src != bl && src == dsrc)
+ if (bool(attack_type & BF_MAGIC)
+ && damage > 0
+ && src != bl
+ && src == dsrc)
{ //Blah Blah
if (bl->type == BL_PC)
{ //Blah Blah
@@ -2135,9 +2143,12 @@ int skill_attack(int attack_type, struct block_list *src,
}
}
//Stop Here
- if (attack_type & BF_WEAPON && damage > 0 && src != bl && src == dsrc)
+ if (bool(attack_type & BF_WEAPON)
+ && damage > 0
+ && src != bl
+ && src == dsrc)
{ //武器スキル&ダメージあり&使用者と対象者が違う&src=dsrc
- if (dmg.flag & BF_SHORT)
+ if (bool(dmg.flag & BF_SHORT))
{ //近距離攻撃時?※
if (bl->type == BL_PC)
{ //対象がPCの時
@@ -2157,7 +2168,7 @@ int skill_attack(int attack_type, struct block_list *src,
rdamage = 1;
}
}
- else if (dmg.flag & BF_LONG)
+ else if (bool(dmg.flag & BF_LONG))
{ //遠距離攻撃時?※
if (bl->type == BL_PC)
{ //対象がPCの時
@@ -2220,7 +2231,9 @@ int skill_attack(int attack_type, struct block_list *src,
rate = rate + (s_lv - t_lv);
if (MRAND(100) < rate)
skill_addtimerskill(src, tick + 800, bl->id, 0, 0, skillid,
- skilllv, 0, flag);
+ skilllv,
+ skill_timerskill::sktst::from_n(0),
+ flag);
}
/*
if (damage > 0 && dmg.flag&BF_SKILL && bl->type==BL_PC && pc_checkskill((struct map_session_data *)bl,RG_PLAGIARISM)){
@@ -2273,7 +2286,10 @@ int skill_attack(int attack_type, struct block_list *src,
}
}
- if (src->type == BL_PC && dmg.flag & BF_WEAPON && src != bl && src == dsrc
+ if (src->type == BL_PC
+ && bool(dmg.flag & BF_WEAPON)
+ && src != bl
+ && src == dsrc
&& damage > 0)
{
struct map_session_data *sd = (struct map_session_data *) src;
@@ -2306,13 +2322,14 @@ int skill_attack(int attack_type, struct block_list *src,
if ((skillid != KN_BOWLINGBASH || flag) && rdamage > 0)
battle_damage(bl, src, rdamage, 0);
- if (attack_type & BF_WEAPON && sc_data
+ if (bool(attack_type & BF_WEAPON)
+ && sc_data
&& sc_data[SC_AUTOCOUNTER].timer != -1
&& sc_data[SC_AUTOCOUNTER].val4 > 0)
{
if (sc_data[SC_AUTOCOUNTER].val3 == dsrc->id)
battle_weapon_attack(bl, dsrc, tick,
- 0x8000 | sc_data[SC_AUTOCOUNTER].val1);
+ BCT_mid_x80 | sc_data[SC_AUTOCOUNTER].val1_bct());
skill_status_change_end(bl, SC_AUTOCOUNTER, -1);
}
@@ -2321,24 +2338,14 @@ int skill_attack(int attack_type, struct block_list *src,
return (dmg.damage + dmg.damage2); /* 与ダメを返す */
}
-/*==========================================
- * スキル範囲攻撃用(map_foreachinareaから呼ばれる)
- * flagについて:16進図を確認
- * MSB <- 00fTffff ->LSB
- * T =ターゲット選択用(BCT_*)
- * ffff=自由に使用可能
- * 0 =予約。0に固定
- *------------------------------------------
- */
-static
-int skill_area_temp[8]; /* 一時変数。必要なら使う。 */
typedef int(*SkillFunc)(struct block_list *, struct block_list *,
SkillID, int,
- unsigned int, int);
+ unsigned int, BCT);
+
static
void skill_area_sub(struct block_list *bl,
struct block_list *src, SkillID skill_id, int skill_lv,
- unsigned int tick, int flag, SkillFunc func)
+ unsigned int tick, BCT flag, SkillFunc func)
{
nullpo_retv(bl);
@@ -2451,7 +2458,7 @@ int skill_check_unit_range2(int m, int x, int y, int range)
map_foreachinarea(std::bind(skill_check_unit_range2_sub, ph::_1, &c),
m, x - range, y - range,
- x + range, y + range, 0);
+ x + range, y + range, BL_NUL);
return c;
}
@@ -2459,13 +2466,17 @@ int skill_check_unit_range2(int m, int x, int y, int range)
/*=========================================================================
* 範囲スキル使用処理小分けここから
*/
-/* 対象の数をカウントする。(skill_area_temp[0]を初期化しておくこと) */
+static
+BCT skill_area_temp_counter;
static
int skill_area_sub_count(struct block_list *, struct block_list *,
- SkillID, int, unsigned int, int)
+ SkillID, int, unsigned int, BCT)
{
- if (skill_area_temp[0] < 0xffff)
- skill_area_temp[0]++;
+ if (skill_area_temp_counter.lo == 0xff
+ && skill_area_temp_counter.mid == 0xff)
+ return 0;
+ if (!++skill_area_temp_counter.lo)
+ ++skill_area_temp_counter.mid;
return 0;
}
@@ -2601,11 +2612,12 @@ void skill_timer(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
range = 15; //視界全体
map_foreachinarea(std::bind(skill_frostjoke_scream, ph::_1, src, skl->skill_id, skl->skill_lv, tick),
src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0);
+ src->x + range, src->y + range,
+ BL_NUL);
break;
default:
- skill_attack(skl->type, src, src, target, skl->skill_id,
+ skill_attack(skl->type.bf, src, src, target, skl->skill_id,
skl->skill_lv, tick, skl->flag);
break;
}
@@ -2617,10 +2629,10 @@ void skill_timer(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
switch (skl->skill_id)
{
case WZ_METEOR:
- if (skl->type >= 0)
+ if (skl->type.n >= 0)
{
skill_unitsetting(src, skl->skill_id, skl->skill_lv,
- skl->type >> 16, skl->type & 0xFFFF,
+ skl->type.xy.x, skl->type.xy.y,
0);
}
else
@@ -2638,7 +2650,7 @@ void skill_timer(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
int skill_addtimerskill(struct block_list *src, unsigned int tick,
int target, int x, int y,
SkillID skill_id, int skill_lv,
- int type, int flag)
+ skill_timerskill::sktst type, BCT flag)
{
int i;
@@ -2742,14 +2754,19 @@ int skill_cleartimerskill(struct block_list *src)
* -------------------------------------------------------------------------
*/
+// these variables are set in the 'else' branches,
+// and used in the (recursive) 'if' branch
+static int skill_area_temp_id, skill_area_temp_x, skill_area_temp_y, skill_area_temp_hp;
+
+
/*==========================================
* スキル使用(詠唱完了、ID指定攻撃系)
* (スパゲッティに向けて1歩前進!(ダメポ))
*------------------------------------------
*/
int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv,
- unsigned int tick, int flag)
+ SkillID skillid, int skilllv,
+ unsigned int tick, BCT flag)
{
struct map_session_data *sd = NULL;
@@ -2908,7 +2925,8 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
{
for (int i = 1; i < sd->spiritball_old; i++)
skill_addtimerskill(src, tick + i * 200, bl->id, 0,
- 0, skillid, skilllv, BF_WEAPON,
+ 0, skillid, skilllv,
+ skill_timerskill::sktst::from_bf(BF_WEAPON),
flag);
sd->canmove_tick = tick + (sd->spiritball_old - 1) * 200;
}
@@ -2999,20 +3017,22 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
case NPC_SPLASHATTACK: /* スプラッシュアタック */
case ASC_METEORASSAULT: /* メテオアサルト */
case AS_SPLASHER: /* [Valaris] */
- if (flag & 1)
+ {
+ if (flag & BCT_lo_x01)
{
/* 個別にダメージを与える */
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
{
- int dist = 0;
+ BCT dist = BCT_ZERO;
if (skillid == SM_MAGNUM)
- { /* マグナムブレイクなら中心からの距離を計算 */
- int dx = abs(bl->x - skill_area_temp[2]);
- int dy = abs(bl->y - skill_area_temp[3]);
- dist = ((dx > dy) ? dx : dy);
+ {
+ /* マグナムブレイクなら中心からの距離を計算 */
+ int dx = abs(bl->x - skill_area_temp_x);
+ int dy = abs(bl->y - skill_area_temp_y);
+ dist.lo = ((dx > dy) ? dx : dy);
}
skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0x0500 | dist);
+ tick, BCT_mid_x05 | dist);
}
}
else
@@ -3030,26 +3050,28 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
ar = 1;
else if (skillid == NPC_SPLASHATTACK) /* スプラッシュアタックは範囲7*7 */
ar = 3;
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
+ skill_area_temp_id = bl->id;
+ skill_area_temp_x = x;
+ skill_area_temp_y = y;
/* まずターゲットに攻撃を加える */
skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv, tick,
- 0);
+ BCT_ZERO);
/* その後ターゲット以外の範囲内の敵全体に処理を行う */
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ // the BCT_lo_x01 is the important thing
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, x - ar, y - ar,
- x + ar, y + ar, 0);
+ x + ar, y + ar, BL_NUL);
}
+ }
break;
case KN_BOWLINGBASH: /* ボウリングバッシュ */
if (flag & 1)
{
/* 個別にダメージを与える */
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0x0500);
+ tick, BCT_mid_x05);
}
else
{
@@ -3057,7 +3079,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
map_freeblock_lock();
damage =
skill_attack(BF_WEAPON, src, src, bl, skillid, skilllv,
- tick, 0);
+ tick, BCT_ZERO);
if (damage > 0)
{
int i, c; /* 他人から聞いた動きなので間違ってる可能性大&効率が悪いっす>< */
@@ -3069,20 +3091,20 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
clif_fixmobpos((struct mob_data *) bl);
else
clif_fixpos(bl);
- skill_area_temp[0] = 0;
+ skill_area_temp_counter = BCT_ZERO;
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY, skill_area_sub_count),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
- if (skill_area_temp[0] > 1)
+ bl->x + 1, bl->y + 1, BL_NUL);
+ if (skill_area_temp_counter > 1)
break;
}
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
+ skill_area_temp_id = bl->id;
+ skill_area_temp_x = bl->x;
+ skill_area_temp_y = bl->y;
/* その後ターゲット以外の範囲内の敵全体に処理を行う */
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
+ bl->x + 1, bl->y + 1, BL_NUL);
battle_damage(src, bl, damage, 1);
if (rdamage > 0)
battle_damage(bl, src, rdamage, 0);
@@ -3141,87 +3163,90 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
if (flag & 1)
{
/* 個別にダメージを与える */
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
{
+ BCT dist = BCT_ZERO;
if (skillid == MG_FIREBALL)
{ /* ファイヤーボールなら中心からの距離を計算 */
- int dx = abs(bl->x - skill_area_temp[2]);
- int dy = abs(bl->y - skill_area_temp[3]);
- skill_area_temp[0] = ((dx > dy) ? dx : dy);
+ int dx = abs(bl->x - skill_area_temp_x);
+ int dy = abs(bl->y - skill_area_temp_y);
+ dist.lo = ((dx > dy) ? dx : dy);
}
skill_attack(BF_MAGIC, src, src, bl, skillid, skilllv,
- tick, skill_area_temp[0] | 0x0500);
+ tick, dist | BCT_mid_x05);
}
}
else
{
int ar = (skillid == MG_NAPALMBEAT) ? 1 : 2;
- skill_area_temp[1] = bl->id;
+ skill_area_temp_id = bl->id;
+ skill_area_temp_counter = BCT_ZERO;
if (skillid == MG_NAPALMBEAT)
- { /* ナパームでは先に数える */
- skill_area_temp[0] = 0;
+ {
+ /* ナパームでは先に数える */
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY, skill_area_sub_count),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
+ bl->x + 1, bl->y + 1, BL_NUL);
}
else
{
- skill_area_temp[0] = 0;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
+ skill_area_temp_x = bl->x;
+ skill_area_temp_y = bl->y;
}
+ BCT counter = BCT_ZERO;
+ counter.lo = skill_area_temp_counter;
+ counter.mid = skill_area_temp_counter >> 8;
/* まずターゲットに攻撃を加える */
skill_attack(BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0]);
+ counter);
/* その後ターゲット以外の範囲内の敵全体に処理を行う */
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - ar, bl->y - ar,
- bl->x + ar, bl->y + ar, 0);
+ bl->x + ar, bl->y + ar, BL_NUL);
}
break;
case HW_NAPALMVULCAN: // Fixed By SteelViruZ
if (flag & 1)
{
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
{
skill_attack(BF_MAGIC, src, src, bl, skillid, skilllv,
- tick, skill_area_temp[0]);
+ tick, skill_area_temp_counter/* wtf */);
}
}
else
{
int ar = (skillid == HW_NAPALMVULCAN) ? 1 : 2;
- skill_area_temp[1] = bl->id;
+ skill_area_temp_id = bl->id;
+ skill_area_temp_counter = BCT_ZERO;
if (skillid == HW_NAPALMVULCAN)
{
- skill_area_temp[0] = 0;
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY, skill_area_sub_count),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
+ bl->x + 1, bl->y + 1, BL_NUL);
}
else
{
- skill_area_temp[0] = 0;
- skill_area_temp[2] = bl->x;
- skill_area_temp[3] = bl->y;
+ skill_area_temp_x = bl->x;
+ skill_area_temp_y = bl->y;
}
skill_attack(BF_MAGIC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0]);
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ skill_area_temp_counter);
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - ar, bl->y - ar,
- bl->x + ar, bl->y + ar, 0);
+ bl->x + ar, bl->y + ar, BL_NUL);
}
break;
case WZ_FROSTNOVA: /* フロストノヴァ */
- skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, 0);
+ skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, BCT_ZERO);
skill_attack(BF_MAGIC, src, src, bl, skillid, skilllv, tick,
flag);
break;
case WZ_SIGHTRASHER:
- skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, 0);
+ skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, BCT_ZERO);
skill_status_change_end(src, SC_SIGHT, -1);
break;
@@ -3230,32 +3255,32 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
if (flag & 1)
{
/* 個別にダメージを与える */
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
skill_attack(BF_MISC, src, src, bl, skillid, skilllv,
tick,
- skill_area_temp[0] | (flag & 0xf00000));
+ skill_area_temp_counter | (flag & BCT_highnib));
}
else
{
- skill_area_temp[0] = 0;
- skill_area_temp[1] = bl->id;
- if (flag & 0xf00000)
+ skill_area_temp_counter = BCT_ZERO;
+ skill_area_temp_id = bl->id;
+ if (flag & BCT_highnib)
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY, skill_area_sub_count),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
+ bl->x + 1, bl->y + 1, BL_NUL);
/* まずターゲットに攻撃を加える */
skill_attack(BF_MISC, src, src, bl, skillid, skilllv, tick,
- skill_area_temp[0] | (flag & 0xf00000));
+ skill_area_temp_counter | (flag & BCT_highnib));
/* その後ターゲット以外の範囲内の敵全体に処理を行う */
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - 1, bl->y - 1,
- bl->x + 1, bl->y + 1, 0);
+ bl->x + 1, bl->y + 1, BL_NUL);
}
break;
case CR_GRANDCROSS: /* グランドクロス */
/* スキルユニット配置 */
- skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, 0);
+ skill_castend_pos2(src, bl->x, bl->y, skillid, skilllv, tick, BCT_ZERO);
if (sd)
sd->canmove_tick = tick + 1000;
else if (src->type == BL_MOB)
@@ -3264,7 +3289,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
case TF_THROWSTONE: /* 石投げ */
case NPC_SMOKING: /* スモーキング */
- skill_attack(BF_MISC, src, src, bl, skillid, skilllv, tick, 0);
+ skill_attack(BF_MISC, src, src, bl, skillid, skilllv, tick, BCT_ZERO);
break;
case NPC_SELFDESTRUCTION: /* 自爆 */
@@ -3276,8 +3301,8 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
{
struct mob_data *mb = (struct mob_data *) src;
nullpo_retr(1, mb);
- mb->hp = skill_area_temp[2];
- if (bl->id != skill_area_temp[1])
+ mb->hp = skill_area_temp_hp;
+ if (bl->id != skill_area_temp_id)
skill_attack(BF_MISC, src, src, bl,
NPC_SELFDESTRUCTION, skilllv, tick,
flag);
@@ -3289,11 +3314,11 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
struct mob_data *md;
if ((md = (struct mob_data *) src))
{
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = battle_get_hp(src);
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ skill_area_temp_id = bl->id;
+ skill_area_temp_hp = battle_get_hp(src);
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - 5, bl->y - 5,
- bl->x + 5, bl->y + 5, 0);
+ bl->x + 5, bl->y + 5, BL_NUL);
battle_damage(src, src, md->hp, 0);
}
}
@@ -3317,17 +3342,17 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
{
if (flag & 3)
{
- if (bl->id != skill_area_temp[1])
+ if (bl->id != skill_area_temp_id)
skill_attack(BF_WEAPON, src, src, bl, skillid,
- skilllv, tick, 0x0500);
+ skilllv, tick, BCT_mid_x05);
}
else
{
int ar = sd->splash_range;
- skill_area_temp[1] = bl->id;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ skill_area_temp_id = bl->id;
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - ar, bl->y - ar,
- bl->x + ar, bl->y + ar, 0);
+ bl->x + ar, bl->y + ar, BL_NUL);
}
}
break;
@@ -3346,8 +3371,8 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
*------------------------------------------
*/
int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv,
- unsigned int tick, int flag)
+ SkillID skillid, int skilllv,
+ unsigned int tick, BCT flag)
{
struct map_session_data *sd = NULL;
struct map_session_data *dstsd = NULL;
@@ -3553,9 +3578,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
else
{
int range = 15;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_nodamage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_nodamage_id),
src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0);
+ src->x + range, src->y + range, BL_NUL);
}
break;
@@ -3799,7 +3824,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
skill_get_time(skillid, skilllv), 0);
map_foreachinarea(std::bind(skill_status_change_timer_sub, ph::_1, src, SkillStatusChangeTable[skillid], tick),
src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0);
+ src->x + range, src->y + range, BL_NUL);
}
break;
case SM_PROVOKE: /* プロボック */
@@ -3967,19 +3992,21 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
case RG_RAID: /* サプライズアタック */
{
int x = bl->x, y = bl->y;
- skill_area_temp[1] = bl->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ skill_area_temp_id = bl->id;
+ skill_area_temp_x = x;
+ skill_area_temp_y = y;
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, x - 1, y - 1,
- x + 1, y + 1, 0);
+ x + 1, y + 1, BL_NUL);
}
skill_status_change_end(src, SC_HIDING, -1); // ハイディング解除
break;
case KN_BRANDISHSPEAR: /*ブランディッシュスピア */
{
- int c, n = 4;
+ int c;
+ BCT n = BCT_ZERO;
+ n.lo = 4;
int dir = map_calc_dir(src, bl->x, bl->y);
struct square tc;
int x = bl->x, y = bl->y;
@@ -3992,19 +4019,19 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | n, skill_castend_damage_id),
bl->m, tc.val1[c], tc.val2[c],
- tc.val1[c], tc.val2[c], 0);
+ tc.val1[c], tc.val2[c], BL_NUL);
}
}
/* 範囲BA */
if (skilllv > 6)
{
skill_brandishspear_dir(&tc, dir, -1);
- n--;
+ n.lo--;
}
else
{
skill_brandishspear_dir(&tc, dir, -2);
- n -= 2;
+ n.lo -= 2;
}
if (skilllv > 3)
@@ -4013,11 +4040,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | n, skill_castend_damage_id),
bl->m, tc.val1[c], tc.val2[c],
- tc.val1[c], tc.val2[c], 0);
- if (skilllv > 6 && n == 3 && c == 4)
+ tc.val1[c], tc.val2[c], BL_NUL);
+ if (skilllv > 6 && n.lo == 3 && c == 4)
{
skill_brandishspear_dir(&tc, dir, -1);
- n--;
+ n.lo--;
c = -1;
}
}
@@ -4027,9 +4054,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
if (c == 0 || c == 5)
skill_brandishspear_dir(&tc, dir, -1);
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, tc.val1[c % 5], tc.val2[c % 5],
- tc.val1[c % 5], tc.val2[c % 5], 0);
+ tc.val1[c % 5], tc.val2[c % 5], BL_NUL);
}
}
break;
@@ -4054,7 +4081,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
else
{
/* パーティ全体への処理 */
- party_foreachsamemap(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_PARTY | 1, skill_castend_nodamage_id),
+ party_foreachsamemap(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_PARTY | BCT_lo_x01, skill_castend_nodamage_id),
sd, 1);
}
break;
@@ -4072,7 +4099,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
else
{
/* パーティ全体への処理 */
- party_foreachsamemap(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_PARTY | 1, skill_castend_nodamage_id),
+ party_foreachsamemap(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_PARTY | BCT_lo_x01, skill_castend_nodamage_id),
sd, 1);
}
break;
@@ -4195,7 +4222,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
case BA_FROSTJOKE: /* 寒いジョーク */
case DC_SCREAM: /* スクリーム */
skill_addtimerskill(src, tick + 3000, bl->id, 0, 0, skillid,
- skilllv, 0, flag);
+ skilllv, skill_timerskill::sktst::from_n(0), flag);
break;
case TF_STEAL: // スティール
@@ -4286,7 +4313,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
dstmd->attacked_id = 0;
dstmd->target_id = 0;
- dstmd->state.targettype = NONE_ATTACKABLE;
+ dstmd->state.attackable = false;
dstmd->state.skillstate = MSS_IDLE;
dstmd->next_walktime = tick + MRAND(3000) + 3000;
}
@@ -4310,7 +4337,6 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
case AL_HOLYWATER: /* アクアベネディクタ */
if (sd)
{
- int eflag;
struct item item_tmp;
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = 523;
@@ -4321,8 +4347,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
item_tmp.card[1] = 0;
*((unsigned long *) (&item_tmp.card[2])) = sd->char_id; /* キャラID */
}
- eflag = pc_additem(sd, &item_tmp, 1);
- if (eflag)
+ PickupFail eflag = pc_additem(sd, &item_tmp, 1);
+ if (eflag != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, eflag);
map_addflooritem(&item_tmp, 1, sd->bl.m, sd->bl.x,
@@ -4333,7 +4359,6 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
case TF_PICKSTONE:
if (sd)
{
- int eflag;
struct item item_tmp;
struct block_list tbl;
memset(&item_tmp, 0, sizeof(item_tmp));
@@ -4342,8 +4367,8 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
item_tmp.identify = 1;
tbl.id = 0;
clif_takeitem(&sd->bl, &tbl);
- eflag = pc_additem(sd, &item_tmp, 1);
- if (eflag)
+ PickupFail eflag = pc_additem(sd, &item_tmp, 1);
+ if (eflag != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, eflag);
map_addflooritem(&item_tmp, 1, sd->bl.m, sd->bl.x,
@@ -4369,10 +4394,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
for (int i = 0; i < MAX_INVENTORY; i++)
{
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0002)
+ if (bool(dstsd->status.inventory[i].equip)
+ && bool(dstsd->status.inventory[i].equip & EPOS::WEAPON))
{
- pc_unequipitem(dstsd, i, 0);
+ pc_unequipitem(dstsd, i, CalcStatus::NOW);
break;
}
}
@@ -4398,10 +4423,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
for (int i = 0; i < MAX_INVENTORY; i++)
{
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0020)
+ if (bool(dstsd->status.inventory[i].equip)
+ && bool(dstsd->status.inventory[i].equip & EPOS::SHIELD))
{
- pc_unequipitem(dstsd, i, 0);
+ pc_unequipitem(dstsd, i, CalcStatus::NOW);
break;
}
}
@@ -4427,10 +4452,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
for (int i = 0; i < MAX_INVENTORY; i++)
{
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0010)
+ if (bool(dstsd->status.inventory[i].equip)
+ && bool(dstsd->status.inventory[i].equip & EPOS::MISC1))
{
- pc_unequipitem(dstsd, i, 0);
+ pc_unequipitem(dstsd, i, CalcStatus::NOW);
break;
}
}
@@ -4455,10 +4480,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
{
for (int i = 0; i < MAX_INVENTORY; i++)
{
- if (dstsd->status.inventory[i].equip
- && dstsd->status.inventory[i].equip & 0x0100)
+ if (bool(dstsd->status.inventory[i].equip)
+ && bool(dstsd->status.inventory[i].equip & EPOS::HAT))
{
- pc_unequipitem(dstsd, i, 0);
+ pc_unequipitem(dstsd, i, CalcStatus::NOW);
break;
}
}
@@ -4635,7 +4660,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
else if (src->type == BL_PC)
clif_fixpos(src);
skill_addtimerskill(src, tick + 200, src->id, 0, 0, skillid,
- skilllv, 0, flag);
+ skilllv, skill_timerskill::sktst::from_n(0), flag);
break;
case SA_CASTCANCEL:
@@ -4975,13 +5000,12 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
skill_db[su->group->
skill_id].itemid[i];
item_tmp.identify = 1;
- int item_flag;
+ PickupFail item_flag;
if (item_tmp.nameid
&& (item_flag =
pc_additem(sd, &item_tmp,
- skill_db[su->
- group->skill_id].amount
- [i])))
+ skill_db[su->group->skill_id].amount[i]))
+ != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, item_flag);
map_addflooritem(&item_tmp,
@@ -5000,9 +5024,10 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
memset(&item_tmp, 0, sizeof(item_tmp));
item_tmp.nameid = 1065;
item_tmp.identify = 1;
- int item_flag;
+ PickupFail item_flag;
if (item_tmp.nameid
- && (item_flag = pc_additem(sd, &item_tmp, 1)))
+ && (item_flag = pc_additem(sd, &item_tmp, 1))
+ != PickupFail::OKAY)
{
clif_additem(sd, 0, 0, item_flag);
map_addflooritem(&item_tmp, 1, sd->bl.m,
@@ -5293,7 +5318,7 @@ void skill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
case 0:
case 2:
skill_castend_damage_id(&sd->bl, bl, sd->skillid, sd->skilllv,
- tick, 0);
+ tick, BCT_ZERO);
break;
case 1: /* 支援系 */
if ((sd->skillid == AL_HEAL
@@ -5302,10 +5327,10 @@ void skill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
&& battle_check_undead(battle_get_race(bl),
battle_get_elem_type(bl)))
skill_castend_damage_id(&sd->bl, bl, sd->skillid,
- sd->skilllv, tick, 0);
+ sd->skilllv, tick, BCT_ZERO);
else
skill_castend_nodamage_id(&sd->bl, bl, sd->skillid,
- sd->skilllv, tick, 0);
+ sd->skilllv, tick, BCT_ZERO);
break;
}
}
@@ -5315,7 +5340,7 @@ void skill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
*------------------------------------------
*/
int skill_castend_pos2(struct block_list *src, int x, int y,
- SkillID skillid, int skilllv, unsigned int tick, int flag)
+ SkillID skillid, int skilllv, unsigned int tick, BCT flag)
{
struct map_session_data *sd = NULL;
int i, tmpx = 0, tmpy = 0, x1 = 0, y1 = 0;
@@ -5333,20 +5358,20 @@ int skill_castend_pos2(struct block_list *src, int x, int y,
switch (skillid)
{
case PR_BENEDICTIO: /* 聖体降福 */
- skill_area_temp[1] = src->id;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_NOENEMY | 1, skill_castend_nodamage_id),
- src->m, x - 1, y - 1, x + 1, y + 1, 0);
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 1, skill_castend_damage_id),
+ skill_area_temp_id = src->id;
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_NOENEMY | BCT_lo_x01, skill_castend_nodamage_id),
+ src->m, x - 1, y - 1, x + 1, y + 1, BL_NUL);
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
src->m, x - 1, y - 1,
- x + 1, y + 1, 0);
+ x + 1, y + 1, BL_NUL);
break;
case BS_HAMMERFALL: /* ハンマーフォール */
- skill_area_temp[1] = src->id;
- skill_area_temp[2] = x;
- skill_area_temp[3] = y;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | 2, skill_castend_nodamage_id),
- src->m, x - 2, y - 2, x + 2, y + 2, 0);
+ skill_area_temp_id = src->id;
+ skill_area_temp_x = x;
+ skill_area_temp_y = y;
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x02, skill_castend_nodamage_id),
+ src->m, x - 2, y - 2, x + 2, y + 2, BL_NUL);
break;
case HT_DETECTING: /* ディテクティング */
@@ -5354,7 +5379,7 @@ int skill_castend_pos2(struct block_list *src, int x, int y,
const int range = 7;
map_foreachinarea(std::bind(skill_status_change_timer_sub, ph::_1, src, SC_SIGHT, tick),
src->m, src->x - range, src->y - range,
- src->x + range, src->y + range, 0);
+ src->x + range, src->y + range, BL_NUL);
}
break;
@@ -5405,7 +5430,7 @@ int skill_castend_pos2(struct block_list *src, int x, int y,
case WZ_METEOR: //メテオストーム
{
- int flag_ = 0;
+ BCT flag_ = BCT_ZERO;
for (i = 0; i < 2 + (skilllv >> 1); i++)
{
int j = 0, c;
@@ -5427,17 +5452,17 @@ int skill_castend_pos2(struct block_list *src, int x, int y,
&& j < 100);
if (j >= 100)
continue;
- if (flag_ == 0)
- flag_ = 1;
+ if (flag_ == BCT_ZERO)
+ flag_ = BCT_lo_x01;
if (i > 0)
skill_addtimerskill(src, tick + i * 1000, 0, tmpx, tmpy,
- skillid, skilllv, (x1 << 16) | y1,
+ skillid, skilllv, skill_timerskill::sktst::from_xy(uint16_t(x1), uint16_t(y1)),
flag_);
x1 = tmpx;
y1 = tmpy;
}
skill_addtimerskill(src, tick + i * 1000, 0, tmpx, tmpy, skillid,
- skilllv, -1, flag_);
+ skilllv, skill_timerskill::sktst::from_n(-1), flag_);
}
break;
@@ -5617,7 +5642,8 @@ struct skill_unit_group *skill_unitsetting(struct block_list *src,
{
struct skill_unit_group *group;
int i, count = 1, limit_ = 10000, val1_ = 0, val2_ = 0;
- int target = BCT_ENEMY, interval = 1000, range_ = 0;
+ BCT target = BCT_ENEMY;
+ int interval = 1000, range_ = 0;
int dir = 0, aoe_diameter = 0; // -- aoe_diameter (moonsoul) added for sage Area Of Effect skills
nullpo_ret(src);
@@ -6294,7 +6320,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
}
else
skill_attack(BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
}
break;
@@ -6308,7 +6334,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
if (!damage_flag)
return 0;
skill_attack(BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
}
break;
@@ -6351,13 +6377,13 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
case 0x86: /* ロードオブヴァーミリオン(&ストームガスト &グランドクロス) */
skill_attack(BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
break;
case 0x7f: /* ファイヤーウォール */
if ((src->val2--) > 0)
skill_attack(BF_MAGIC, ss, &src->bl, bl,
- sg->skill_id, sg->skill_lv, tick, 0);
+ sg->skill_id, sg->skill_lv, tick, BCT_ZERO);
if (src->val2 <= 0)
skill_delunit(src);
break;
@@ -6371,7 +6397,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
case 0x88: /* ファイアーピラー(発動後) */
if (DIFF_TICK(tick, sg->tick) < 150)
skill_attack(BF_MAGIC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
break;
case 0x90: /* スキッドトラップ */
@@ -6387,7 +6413,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
case 0x93: /* ランドマイン */
skill_attack(BF_MISC, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
sg->unit_id = 0x8c;
clif_changelook(&src->bl, LOOK_BASE, 0x88);
sg->limit = DIFF_TICK(tick, sg->tick) + 1500;
@@ -6401,10 +6427,10 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
case 0x98: /* クレイモアートラップ */
map_foreachinarea(std::bind(skill_count_target, ph::_1, &src->bl, &splash_count),
src->bl.m, src->bl.x - src->range, src->bl.y - src->range,
- src->bl.x + src->range, src->bl.y + src->range, 0);
+ src->bl.x + src->range, src->bl.y + src->range, BL_NUL);
map_foreachinarea(std::bind(skill_trap_splash, ph::_1, &src->bl, tick, splash_count),
src->bl.m, src->bl.x - src->range, src->bl.y - src->range,
- src->bl.x + src->range, src->bl.y + src->range, 0);
+ src->bl.x + src->range, src->bl.y + src->range, BL_NUL);
sg->unit_id = 0x8c;
clif_changelook(&src->bl, LOOK_BASE, sg->unit_id);
sg->limit = DIFF_TICK(tick, sg->tick) + 1500;
@@ -6598,7 +6624,7 @@ int skill_unit_onplace(struct skill_unit *src, struct block_list *bl,
case 0xb1: /* デモンストレーション */
skill_attack(BF_WEAPON, ss, &src->bl, bl, sg->skill_id,
- sg->skill_lv, tick, 0);
+ sg->skill_lv, tick, BCT_ZERO);
if (bl->type == BL_PC && MRAND(100) < sg->skill_lv
&& battle_config.equipment_breaking)
pc_breakweapon((struct map_session_data *) bl);
@@ -7112,7 +7138,7 @@ void skill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
pc_stop_walking(sd, 0);
skill_castend_pos2(&sd->bl, sd->skillx, sd->skilly, sd->skillid,
- sd->skilllv, tick, 0);
+ sd->skilllv, tick, BCT_ZERO);
}
/*==========================================
@@ -8166,7 +8192,7 @@ int skill_use_id(struct map_session_data *sd, int target_id,
&& sd->invincible_timer == -1)
{
md->target_id = sd->bl.id;
- md->state.targettype = ATTACKABLE;
+ md->state.attackable = true;
md->min_chase = 13;
}
}
@@ -8868,11 +8894,11 @@ void skill_trap_splash(struct block_list *bl,
{
skill_attack(BF_MISC, ss, src, bl, sg->skill_id,
sg->skill_lv, tick,
- (sg->val2) ? 0x0500 : 0);
+ (sg->val2) ? BCT_mid_x05 : BCT_ZERO);
}
case 0x97: /* フリージングトラップ */
skill_attack(BF_WEAPON, ss, src, bl, sg->skill_id,
- sg->skill_lv, tick, (sg->val2) ? 0x0500 : 0);
+ sg->skill_lv, tick, (sg->val2) ? BCT_mid_x05 : BCT_ZERO);
break;
default:
break;
@@ -8917,7 +8943,7 @@ void skill_status_change_timer_sub(struct block_list *bl,
{
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
skill_attack(BF_MAGIC, src, src, bl, AL_RUWACH,
- sc_data[type].val1, tick, 0);
+ sc_data[type].val1, tick, BCT_ZERO);
}
}
break;
@@ -9100,7 +9126,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
//自分にダメージ&周囲3*3にダメージ
skill_castend_damage_id(src, bl,
SkillID(sc_data[type].val2), sc_data[type].val1,
- gettick(), 0);
+ gettick(), BCT_ZERO);
}
}
break;
@@ -9111,7 +9137,7 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
if (bl->type == BL_MOB && (md = (struct mob_data *) bl))
skill_castend_damage_id(bl, bl,
SkillID( sc_data[type].val2), sc_data[type].val1,
- gettick(), 0);
+ gettick(), BCT_ZERO);
}
break;
/* option1 */
@@ -9362,7 +9388,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
const int range = 7;
map_foreachinarea(std::bind(skill_status_change_timer_sub, ph::_1, bl, type, tick),
bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0);
+ bl->x + range, bl->y + range, BL_NUL);
if ((--sc_data[type].val2) > 0)
{
@@ -9379,7 +9405,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
const int range = 5;
map_foreachinarea(std::bind(skill_status_change_timer_sub, ph::_1, bl, type, tick),
bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0);
+ bl->x + range, bl->y + range, BL_NUL);
if ((--sc_data[type].val2) > 0)
{
@@ -9424,7 +9450,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
if (target == NULL || target->prev == NULL)
break;
skill_attack(BF_MAGIC, bl, bl, target, WZ_WATERBALL,
- sc_data[type].val1, tick, 0);
+ sc_data[type].val1, tick, BCT_ZERO);
if ((--sc_data[type].val3) > 0)
{
sc_data[type].timer =
@@ -9460,7 +9486,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
break;
skill_attack(BF_MISC, src, &unit->bl, bl,
unit->group->skill_id, sc_data[type].val1, tick,
- 0);
+ BCT_ZERO);
sc_data[type].timer =
add_timer(skill_get_time2(unit->group->skill_id,
unit->group->skill_lv) + tick,
@@ -9784,8 +9810,9 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
Opt1 *opt1;
Opt2 *opt2;
Opt3 *opt3;
- int opt_flag = 0, calc_flag = 0, updateflag =
- 0, race, mode, elem, undead_flag;
+ int opt_flag = 0, calc_flag = 0;
+ int race, mode, elem, undead_flag;
+ SP updateflag;
int scdef = 0;
nullpo_ret(bl);
@@ -10629,7 +10656,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
if (bl->type == BL_PC && calc_flag)
pc_calcstatus(sd, 0); /* ステータス再計算 */
- if (bl->type == BL_PC && updateflag)
+ if (bl->type == BL_PC && updateflag != SP::ZERO)
clif_updatestatus(sd, updateflag); /* ステータスをクライアントに送る */
return 0;
@@ -10681,10 +10708,10 @@ int skill_status_change_clear(struct block_list *bl, int type)
*opt3 = Opt3::ZERO;
*option &= Option::MASK;
- if (night_flag == 1 && type == BL_PC) // by [Yor]
+ if (night_flag == 1 && type == 1) // by [Yor]
*opt2 |= Opt2::BLIND;
- if (!type || type & 2)
+ if (type == 0 || type & 2)
clif_changeoption(bl);
return 0;
@@ -10882,7 +10909,7 @@ int skill_delunit(struct skill_unit *unit)
range = group->range;
map_foreachinarea(std::bind(skill_unit_timer_sub_ondelete, ph::_1, &unit->bl, gettick()),
unit->bl.m, unit->bl.x - range, unit->bl.y - range,
- unit->bl.x + range, unit->bl.y + range, 0);
+ unit->bl.x + range, unit->bl.y + range, BL_NUL);
unit->group = NULL;
unit->alive = 0;
@@ -11211,13 +11238,13 @@ void skill_unit_timer_sub(struct block_list *bl, unsigned int tick)
{
map_foreachinarea(std::bind(skill_unit_timer_sub_onplace, ph::_1, bl, tick),
bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0);
+ bl->x + range, bl->y + range, BL_NUL);
if (group->unit_id == 0xaa
&& DIFF_TICK(tick, group->tick) >= 6000 * group->val2)
{
map_foreachinarea(std::bind(skill_idun_heal, ph::_1, unit),
bl->m, bl->x - range, bl->y - range,
- bl->x + range, bl->y + range, 0);
+ bl->x + range, bl->y + range, BL_NUL);
group->val2++;
}
}
@@ -11455,7 +11482,7 @@ int skill_unit_move_unit_group(struct skill_unit_group *group, int m, int dx,
range = 7;
map_foreachinarea(std::bind(skill_unit_move_unit_group_sub, ph::_1, &unit->bl, gettick()),
unit->bl.m, unit->bl.x - range, unit->bl.y - range,
- unit->bl.x + range, unit->bl.y + range, 0);
+ unit->bl.x + range, unit->bl.y + range, BL_NUL);
}
}
}
@@ -11516,7 +11543,7 @@ int skill_unit_move_unit_group(struct skill_unit_group *group, int m, int dx,
map_foreachinarea(std::bind(skill_unit_move_unit_group_sub, ph::_1, &unit1->bl, gettick()),
unit1->bl.m, unit1->bl.x - range, unit1->bl.y - range,
- unit1->bl.x + range, unit1->bl.y + range, 0);
+ unit1->bl.x + range, unit1->bl.y + range, BL_NUL);
}
}
else
@@ -11542,7 +11569,7 @@ int skill_unit_move_unit_group(struct skill_unit_group *group, int m, int dx,
map_foreachinarea(std::bind(skill_unit_move_unit_group_sub, ph::_1, &unit2->bl, gettick()),
unit2->bl.m, unit2->bl.x - range, unit2->bl.y - range,
- unit2->bl.x + range, unit2->bl.y + range, 0);
+ unit2->bl.x + range, unit2->bl.y + range, BL_NUL);
}
s_flag[j] = 0; // 継承完了したのでoff
break;
@@ -11569,7 +11596,7 @@ int skill_unit_move_unit_group(struct skill_unit_group *group, int m, int dx,
*/
static
-int scan_stat(char *statname)
+SP scan_stat(char *statname)
{
if (!strcasecmp(statname, "str"))
return SP_STR;
@@ -11584,11 +11611,10 @@ int scan_stat(char *statname)
if (!strcasecmp(statname, "luk"))
return SP_LUK;
if (!strcasecmp(statname, "none"))
- return 0;
+ return SP::ZERO;
- else
- fprintf(stderr, "Unknown stat `%s'\n", statname);
- return 0;
+ fprintf(stderr, "Unknown stat `%s'\n", statname);
+ return SP::ZERO;
}
/*==========================================
@@ -11681,7 +11707,7 @@ int skill_readdb(void)
else if (strcasecmp(split[12], "misc") == 0)
skill_db[i].skill_type = BF_MISC;
else
- skill_db[i].skill_type = 0;
+ skill_db[i].skill_type = BF::ZERO;
memset(split2, 0, sizeof(split2));
for (j = 0, p = split[14]; j < MAX_SKILL_LEVEL && p; j++)
{
@@ -11705,7 +11731,7 @@ int skill_readdb(void)
skill_db[i].poolflags = SKILL_POOL_FLAG | SKILL_POOL_ACTIVE;
}
else
- skill_db[i].poolflags = 0;
+ skill_db[i].poolflags = SkillFlags::ZERO;
skill_db[i].stat = scan_stat(split[16]);
diff --git a/src/map/skill.hpp b/src/map/skill.hpp
index 8b23d64..086b9cb 100644
--- a/src/map/skill.hpp
+++ b/src/map/skill.hpp
@@ -12,19 +12,19 @@
#define MAX_SKILL_ARROW_DB 150
#define MAX_SKILL_ABRA_DB 350
-#define SKILL_POOL_FLAG 0x1 // is a pool skill
-#define SKILL_POOL_ACTIVE 0x2 // is an active pool skill
-#define SKILL_POOL_ACTIVATED 0x4 // pool skill has been activated (used for clif)
-
// スキルデータベース
struct skill_db
{
- int range[MAX_SKILL_LEVEL], hit, inf, pl, nk, max, stat, poolflags, max_raise; // `max' is the global max, `max_raise' is the maximum attainable via skill-ups
+ int range[MAX_SKILL_LEVEL], hit, inf, pl, nk, max;
+ SP stat;
+ SkillFlags poolflags;
+ int max_raise; // `max' is the global max, `max_raise' is the maximum attainable via skill-ups
int num[MAX_SKILL_LEVEL];
int cast[MAX_SKILL_LEVEL], delay[MAX_SKILL_LEVEL];
int upkeep_time[MAX_SKILL_LEVEL], upkeep_time2[MAX_SKILL_LEVEL];
int castcancel, cast_def_rate;
- int inf2, maxcount, skill_type;
+ int inf2, maxcount;
+ BF skill_type;
int blewcount[MAX_SKILL_LEVEL];
int hp[MAX_SKILL_LEVEL], sp[MAX_SKILL_LEVEL], mhp[MAX_SKILL_LEVEL],
hp_rate[MAX_SKILL_LEVEL], sp_rate[MAX_SKILL_LEVEL],
@@ -90,7 +90,7 @@ int skill_cleartimerskill(struct block_list *src);
// 追加効果
int skill_additional_effect(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, int attack_type,
+ SkillID skillid, int skilllv, BF attack_type,
unsigned int tick);
int skill_delunit(struct skill_unit *unit);
@@ -136,13 +136,14 @@ int skill_status_change_clear(struct block_list *bl, int type);
// mobスキルのため
int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick,
- int flag);
+ SkillID skillid, int skilllv, unsigned int tick,
+ BCT flag);
int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick,
- int flag);
-int skill_castend_pos2(struct block_list *src, int x, int y, SkillID skillid,
- int skilllv, unsigned int tick, int flag);
+ SkillID skillid, int skilllv, unsigned int tick,
+ BCT flag);
+int skill_castend_pos2(struct block_list *src, int x, int y,
+ SkillID skillid, int skilllv, unsigned int tick,
+ BCT flag);
int skill_update_heal_animation(struct map_session_data *sd); // [Fate] Check whether the healing flag must be updated, do so if needed
@@ -167,7 +168,7 @@ int skill_pool_max(struct map_session_data *sd); // Max. number of pool skills
// Skill into skill pool. Return is zero iff okay.
int skill_pool_activate(struct map_session_data *sd, SkillID skill);
// Skill into skill pool. Return is zero when activated.
-int skill_pool_is_activated(struct map_session_data *sd, SkillID skill);
+bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill);
// Skill out of skill pool. Return is zero iff okay.
int skill_pool_deactivate(struct map_session_data *sd, SkillID skill);
// Yield configurable skill name
diff --git a/src/map/skill.t.hpp b/src/map/skill.t.hpp
index fe10699..e286831 100644
--- a/src/map/skill.t.hpp
+++ b/src/map/skill.t.hpp
@@ -3,6 +3,8 @@
#include <cstdint>
+#include "../common/utils.hpp"
+
// only ST_NONE is actually used - TODO remove
enum class SkillState
{
@@ -1417,4 +1419,23 @@ enum class SkillID : uint16_t
#define MAX_SKILL_DB SkillID::MAX_SKILL_DB
};
+namespace e
+{
+enum class SkillFlags : uint16_t
+{
+ ZERO = 0x00,
+ // is a pool skill
+ FLAG = 0x01,
+#define SKILL_POOL_FLAG SkillFlags::FLAG
+ // is an active pool skill
+ ACTIVE = 0x02,
+#define SKILL_POOL_ACTIVE SkillFlags::ACTIVE
+ // pool skill has been activated (used for clif)
+ ACTIVATED = 0x04,
+#define SKILL_POOL_ACTIVATED SkillFlags::ACTIVATED
+};
+ENUM_BITWISE_OPERATORS(SkillFlags)
+}
+using e::SkillFlags;
+
#endif // SKILL_T_HPP
diff --git a/src/map/storage.cpp b/src/map/storage.cpp
index 041a735..39510bc 100644
--- a/src/map/storage.cpp
+++ b/src/map/storage.cpp
@@ -232,7 +232,7 @@ int storage_storageadd(struct map_session_data *sd, int index, int amount)
if (storage_additem(sd, stor, &sd->status.inventory[index], amount) == 0)
{
// remove item from inventory
- pc_unequipinvyitem(sd, index, 0);
+ pc_unequipinvyitem(sd, index, CalcStatus::NOW);
pc_delitem(sd, index, amount, 0);
}
@@ -246,7 +246,7 @@ int storage_storageadd(struct map_session_data *sd, int index, int amount)
int storage_storageget(struct map_session_data *sd, int index, int amount)
{
struct storage *stor;
- int flag;
+ PickupFail flag;
nullpo_ret(sd);
nullpo_ret(stor = account2storage2(sd->status.account_id));
@@ -260,7 +260,7 @@ int storage_storageget(struct map_session_data *sd, int index, int amount)
if (amount < 1 || amount > stor->storage_[index].amount)
return 0;
- if ((flag = pc_additem(sd, &stor->storage_[index], amount)) == 0)
+ if ((flag = pc_additem(sd, &stor->storage_[index], amount)) == PickupFail::OKAY)
storage_delitem(sd, stor, index, amount);
else
clif_additem(sd, 0, 0, flag);
diff --git a/src/map/trade.cpp b/src/map/trade.cpp
index 4c0ad99..d5be2ad 100644
--- a/src/map/trade.cpp
+++ b/src/map/trade.cpp
@@ -151,8 +151,10 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
&& target_sd->inventory_data[i] != NULL)
{
id = target_sd->inventory_data[i];
- if (id->type != 4 && id->type != 5
- && id->type != 7 && id->type != 8)
+ if (id->type != ItemType::WEAPON
+ && id->type != ItemType::ARMOR
+ && id->type != ItemType::_7
+ && id->type != ItemType::_8)
{
free++;
break;
@@ -181,7 +183,7 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
return;
}
}
- pc_unequipinvyitem(sd, index - 2, 0);
+ pc_unequipinvyitem(sd, index - 2, CalcStatus::NOW);
sd->deal_item_index[trade_i] = index;
sd->deal_item_amount[trade_i] += amount;
clif_tradeitemok(sd, index, amount, 0); //success to add item
@@ -205,8 +207,10 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount)
&& target_sd->inventory_data[i] != NULL)
{
id = target_sd->inventory_data[i];
- if (id->type != 4 && id->type != 5
- && id->type != 7 && id->type != 8)
+ if (id->type != ItemType::WEAPON
+ && id->type != ItemType::ARMOR
+ && id->type != ItemType::_7
+ && id->type != ItemType::_8)
{
free++;
break;
@@ -270,16 +274,19 @@ void trade_tradecancel(struct map_session_data *sd)
{ //give items back (only virtual)
if (sd->deal_item_amount[trade_i] != 0)
{
- clif_additem(sd, sd->deal_item_index[trade_i] - 2,
- sd->deal_item_amount[trade_i], 0);
+ clif_additem(sd,
+ sd->deal_item_index[trade_i] - 2,
+ sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
sd->deal_item_index[trade_i] = 0;
sd->deal_item_amount[trade_i] = 0;
}
if (target_sd->deal_item_amount[trade_i] != 0)
{
clif_additem(target_sd,
- target_sd->deal_item_index[trade_i] - 2,
- target_sd->deal_item_amount[trade_i], 0);
+ target_sd->deal_item_index[trade_i] - 2,
+ target_sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
target_sd->deal_item_index[trade_i] = 0;
target_sd->deal_item_amount[trade_i] = 0;
}
@@ -350,34 +357,34 @@ void trade_tradecommit(struct map_session_data *sd)
if (sd->deal_item_amount[trade_i] != 0)
{
int n = sd->deal_item_index[trade_i] - 2;
- int flag;
- flag =
- pc_additem(target_sd, &sd->status.inventory[n],
- sd->deal_item_amount[trade_i]);
- if (flag == 0)
+ PickupFail flag = pc_additem(target_sd,
+ &sd->status.inventory[n],
+ sd->deal_item_amount[trade_i]);
+ if (flag == PickupFail::OKAY)
pc_delitem(sd, n, sd->deal_item_amount[trade_i],
1);
else
clif_additem(sd, n,
- sd->deal_item_amount[trade_i], 0);
+ sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
sd->deal_item_index[trade_i] = 0;
sd->deal_item_amount[trade_i] = 0;
}
if (target_sd->deal_item_amount[trade_i] != 0)
{
int n = target_sd->deal_item_index[trade_i] - 2;
- int flag;
- flag =
- pc_additem(sd, &target_sd->status.inventory[n],
- target_sd->deal_item_amount[trade_i]);
- if (flag == 0)
+ PickupFail flag = pc_additem(sd,
+ &target_sd->status.inventory[n],
+ target_sd->deal_item_amount[trade_i]);
+ if (flag == PickupFail::OKAY)
pc_delitem(target_sd, n,
target_sd->deal_item_amount[trade_i],
1);
else
clif_additem(target_sd, n,
- target_sd->deal_item_amount
- [trade_i], 0);
+
+ target_sd->deal_item_amount[trade_i],
+ PickupFail::OKAY);
target_sd->deal_item_index[trade_i] = 0;
target_sd->deal_item_amount[trade_i] = 0;
}