summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-03-01 11:45:15 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-03-01 13:56:33 -0800
commit30335063bff54c2b4782689eebdb3b2717e878fa (patch)
tree8cf4af06a0915e8741b51bbdcb19491d954b5c7f
parent777c013fe163348d1489fb9ca2e41cb135eec0d1 (diff)
downloadtmwa-30335063bff54c2b4782689eebdb3b2717e878fa.tar.gz
tmwa-30335063bff54c2b4782689eebdb3b2717e878fa.tar.bz2
tmwa-30335063bff54c2b4782689eebdb3b2717e878fa.tar.xz
tmwa-30335063bff54c2b4782689eebdb3b2717e878fa.zip
Convince skills to work
-rw-r--r--src/char/char.cpp28
-rw-r--r--src/common/mmo.hpp5
-rw-r--r--src/map/atcommand.cpp3
-rw-r--r--src/map/clif.cpp34
-rw-r--r--src/map/magic-expr.cpp12
-rw-r--r--src/map/pc.cpp39
-rw-r--r--src/map/script.cpp24
-rw-r--r--src/map/skill-pools.cpp6
8 files changed, 67 insertions, 84 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 7954655..9749c23 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -327,10 +327,10 @@ std::string mmo_char_tostr(struct mmo_charstatus *p)
str_p += '\t';
for (SkillID i : erange(SkillID(), MAX_SKILL))
- if (p->skill[i].id != SkillID()/*SkillID::ZERO*/)
+ if (p->skill[i].lv)
{
str_p += STRPRINTF("%d,%d ",
- p->skill[i].id,
+ i,
p->skill[i].lv | (uint16_t(p->skill[i].flags) << 16));
}
str_p += '\t';
@@ -351,14 +351,21 @@ bool extract(const_string str, struct point *p)
return extract(str, record<','>(&p->map, &p->x, &p->y));
}
+struct skill_loader
+{
+ SkillID id;
+ uint16_t level;
+ SkillFlags flags;
+};
+
static
-bool extract(const_string str, struct skill *s)
+bool extract(const_string str, struct skill_loader *s)
{
uint32_t flags_and_level;
if (!extract(str,
record<','>(&s->id, &flags_and_level)))
return false;
- s->lv = flags_and_level & 0xffff;
+ s->level = flags_and_level & 0xffff;
s->flags = SkillFlags(flags_and_level >> 16);
return true;
}
@@ -375,7 +382,7 @@ bool extract(const_string str, struct mmo_charstatus *p)
uint32_t unused_guild_id, unused_pet_id;
std::vector<struct point> memos;
std::vector<struct item> inventory, cart;
- std::vector<struct skill> skills;
+ std::vector<struct skill_loader> skills;
std::vector<struct global_reg> vars;
if (!extract(str,
record<'\t'>(
@@ -429,10 +436,13 @@ bool extract(const_string str, struct mmo_charstatus *p)
std::copy(cart.begin(), cart.end(), p->cart);
// number of cart items is not saved - it just detects nameid 0
- if (skills.size() > uint16_t(MAX_SKILL))
- return false;
- std::copy(skills.begin(), skills.end(), &p->skill[SkillID()]);
- // number of skills is not saved - it just detects skill.id 0
+ for (struct skill_loader& sk : skills)
+ {
+ if (sk.id > MAX_SKILL)
+ return false;
+ p->skill[sk.id].lv = sk.level;
+ p->skill[sk.id].flags = sk.flags;
+ }
if (vars.size() > GLOBAL_REG_NUM)
return false;
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index f35064b..34f3047 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -88,9 +88,8 @@ enum class SkillFlags : uint16_t;
}
using e::SkillFlags;
-struct skill
+struct skill_value
{
- SkillID id;
unsigned short lv;
SkillFlags flags;
};
@@ -161,7 +160,7 @@ struct mmo_charstatus
struct point last_point, save_point, memo_point[10];
struct item inventory[MAX_INVENTORY], cart[MAX_CART];
- earray<struct skill, SkillID, MAX_SKILL> skill;
+ earray<skill_value, SkillID, MAX_SKILL> skill;
int global_reg_num;
struct global_reg global_reg[GLOBAL_REG_NUM];
int account_reg_num;
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 479b7c3..27245b2 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -6230,7 +6230,7 @@ int atcommand_magic_info(const int fd, struct map_session_data *,
"%d in %s",
pl_sd->status.skill[sk].lv,
magic_skill_names[i]);
- if (pl_sd->status.skill[sk].id == sk)
+ if (pl_sd->status.skill[sk].lv)
clif_displaymessage(fd, buf);
}
@@ -6245,7 +6245,6 @@ int atcommand_magic_info(const int fd, struct map_session_data *,
static
void set_skill(struct map_session_data *sd, SkillID i, int level)
{
- sd->status.skill[i].id = level ? i : SkillID();
sd->status.skill[i].lv = level;
}
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index 2da8a14..24060a4 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -2997,21 +2997,20 @@ int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type,
nullpo_ret(sd);
fd = sd->fd;
- SkillID id = sd->status.skill[skillid].id;
- if (id == SkillID::ZERO || id == SkillID::NEGATIVE)
+ if (!sd->status.skill[skillid].lv)
return 0;
WFIFOW(fd, 0) = 0x147;
- WFIFOW(fd, 2) = uint16_t(id);
+ WFIFOW(fd, 2) = static_cast<uint16_t>(skillid);
if (type < 0)
- WFIFOW(fd, 4) = skill_get_inf(id);
+ WFIFOW(fd, 4) = skill_get_inf(skillid);
else
WFIFOW(fd, 4) = type;
WFIFOW(fd, 6) = 0;
WFIFOW(fd, 8) = sd->status.skill[skillid].lv;
- WFIFOW(fd, 10) = skill_get_sp(id, sd->status.skill[skillid].lv);
+ WFIFOW(fd, 10) = skill_get_sp(skillid, sd->status.skill[skillid].lv);
if (range < 0)
{
- range = skill_get_range(id, sd->status.skill[skillid].lv);
+ range = skill_get_range(skillid, sd->status.skill[skillid].lv);
if (range < 0)
range = battle_get_range(&sd->bl) - (range + 1);
WFIFOW(fd, 12) = range;
@@ -3019,8 +3018,7 @@ int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type,
else
WFIFOW(fd, 12) = range;
memset(WFIFOP(fd, 14), 0, 24);
- WFIFOB(fd, 38) =
- (sd->status.skill[skillid].lv < skill_get_max_raise(id)) ? 1 : 0;
+ WFIFOB(fd, 38) = bool(sd->status.skill[skillid].lv < skill_get_max_raise(skillid));
WFIFOSET(fd, clif_parse_func_table[0x147].len);
return 0;
@@ -3041,24 +3039,22 @@ int clif_skillinfoblock(struct map_session_data *sd)
WFIFOW(fd, 0) = 0x10f;
for (SkillID i : erange(SkillID(), MAX_SKILL))
{
- SkillID id = sd->status.skill[i].id;
- if (id != SkillID::ZERO && sd->tmw_version >= 1)
+ if (sd->status.skill[i].lv && sd->tmw_version >= 1)
{
// [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) = uint16_t(
+ WFIFOW(fd, len) = static_cast<uint16_t>(i);
+ WFIFOW(fd, len + 2) = skill_get_inf(i);
+ WFIFOW(fd, len + 4) = static_cast<uint16_t>(
skill_db[i].poolflags
| (sd->status.skill[i].flags & SkillFlags::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);
+ WFIFOW(fd, len + 8) = skill_get_sp(i, sd->status.skill[i].lv);
+ range = skill_get_range(i, sd->status.skill[i].lv);
if (range < 0)
range = battle_get_range(&sd->bl) - (range + 1);
WFIFOW(fd, len + 10) = range;
memset(WFIFOP(fd, len + 12), 0, 24);
- WFIFOB(fd, len + 36) =
- (sd->status.skill[i].lv < skill_get_max_raise(id)) ? 1 : 0;
+ WFIFOB(fd, len + 36) = bool(sd->status.skill[i].lv < skill_get_max_raise(i));
len += 37;
}
}
@@ -3087,9 +3083,7 @@ int clif_skillup(struct map_session_data *sd, SkillID skill_num)
if (range < 0)
range = battle_get_range(&sd->bl) - (range + 1);
WFIFOW(fd, 8) = range;
- WFIFOB(fd, 10) =
- (sd->status.skill[skill_num].lv <
- skill_get_max_raise(sd->status.skill[skill_num].id)) ? 1 : 0;
+ WFIFOB(fd, 10) = bool(sd->status.skill[skill_num].lv < skill_get_max_raise(skill_num));
WFIFOSET(fd, clif_parse_func_table[0x10e].len);
return 0;
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index a366cc0..0acc50a 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -582,13 +582,17 @@ static
int fun_skill(env_t *, int, val_t *result, val_t *args)
{
if (ENTITY_TYPE(0) != BL::PC
- // don't convert to enum until after the range check
+ // don't convert to enum until after the range check
|| ARGINT(1) < 0
- || ARGINT(1) >= uint16_t(MAX_SKILL)
- || ARGPC(0)->status.skill[SkillID(ARGINT(1))].id != SkillID(ARGINT(1)))
+ || ARGINT(1) >= uint16_t(MAX_SKILL))
+ {
RESULTINT = 0;
+ }
else
- RESULTINT = ARGPC(0)->status.skill[SkillID(ARGINT(1))].lv;
+ {
+ SkillID id = static_cast<SkillID>(ARGINT(1));
+ RESULTINT = ARGPC(0)->status.skill[id].lv;
+ }
return 0;
}
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index b192aae..883d9bb 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -845,21 +845,6 @@ int pc_calc_skillpoint(struct map_session_data *sd)
}
/*==========================================
- * 覚えられるスキルの計算
- *------------------------------------------
- */
-static
-void pc_calc_skilltree(struct map_session_data *sd)
-{
- nullpo_retv(sd);
-
- // TODO - I *think* this can be removed
- // since the skill is worthless without a level
- if (sd->status.skill[SkillID::NV_EMOTE].id == SkillID::ZERO)
- sd->status.skill[SkillID::NV_EMOTE].id = SkillID::NV_EMOTE;
-}
-
-/*==========================================
* 重量アイコンの確認
*------------------------------------------
*/
@@ -920,7 +905,6 @@ int pc_calcstatus(struct map_session_data *sd, int first)
int b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2;
int b_base_atk;
- earray<struct skill, SkillID, MAX_SKILL> b_skill;
int bl, index;
int aspd_rate, refinedef = 0;
int str, dstr, dex;
@@ -936,7 +920,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
b_max_weight = sd->max_weight;
earray<int, ATTR, ATTR::COUNT> b_paramb = sd->paramb;
earray<int, ATTR, ATTR::COUNT> b_parame = sd->paramc;
- b_skill = sd->status.skill;
+ earray<skill_value, SkillID, MAX_SKILL> b_skill = sd->status.skill;
b_hit = sd->hit;
b_flee = sd->flee;
interval_t b_aspd = sd->aspd;
@@ -953,8 +937,6 @@ int pc_calcstatus(struct map_session_data *sd, int first)
b_mdef2 = sd->mdef2;
b_base_atk = sd->base_atk;
- pc_calc_skilltree(sd); // スキルツリーの計算
-
sd->max_weight = max_weight_base_0 + sd->status.attrs[ATTR::STR] * 300;
if (first & 1)
@@ -1868,15 +1850,14 @@ int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag)
PRINTF("support card skill only!\n");
return 0;
}
- if (!flag && (sd->status.skill[id].id == id || level == 0))
- { // クエスト所得ならここで条件を確認して送信する
+ if (!flag && (sd->status.skill[id].lv || level == 0))
+ {
sd->status.skill[id].lv = level;
pc_calcstatus(sd, 0);
clif_skillinfoblock(sd);
}
else if (sd->status.skill[id].lv < level)
- { // 覚えられるがlvが小さいなら
- sd->status.skill[id].id = id;
+ {
sd->status.skill[id].lv = level;
}
@@ -2840,10 +2821,7 @@ int pc_checkskill(struct map_session_data *sd, SkillID skill_id)
if (sd == NULL)
return 0;
- if (sd->status.skill[skill_id].id == skill_id)
- return (sd->status.skill[skill_id].lv);
-
- return 0;
+ return sd->status.skill[skill_id].lv;
}
/*==========================================
@@ -3085,7 +3063,7 @@ int pc_skillpt_potential(struct map_session_data *sd)
for (SkillID skill_id = SkillID(); skill_id < MAX_SKILL;
skill_id = SkillID(uint16_t(skill_id) + 1))
- if (sd->status.skill[skill_id].id != SkillID::ZERO
+ if (sd->status.skill[skill_id].lv
&& sd->status.skill[skill_id].lv < skill_db[skill_id].max_raise)
potential += RAISE_COST(skill_db[skill_id].max_raise)
- RAISE_COST(sd->status.skill[skill_id].lv);
@@ -3376,7 +3354,7 @@ int pc_skillup(struct map_session_data *sd, SkillID skill_num)
{
nullpo_ret(sd);
- if (sd->status.skill[skill_num].id != SkillID::ZERO
+ if (sd->status.skill[skill_num].lv
&& sd->status.skill_point >= sd->status.skill[skill_num].lv
&& sd->status.skill[skill_num].lv < skill_db[skill_num].max_raise)
{
@@ -3388,7 +3366,8 @@ int pc_skillup(struct map_session_data *sd, SkillID skill_num)
clif_updatestatus(sd, SP::SKILLPOINT);
clif_skillinfoblock(sd);
MAP_LOG_PC(sd, "SKILLUP %d %d %d",
- uint16_t(skill_num), sd->status.skill[skill_num].lv, skill_power(sd, skill_num));
+ skill_num, sd->status.skill[skill_num].lv,
+ skill_power(sd, skill_num));
}
return 0;
diff --git a/src/map/script.cpp b/src/map/script.cpp
index a39186e..f56cabb 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -2494,11 +2494,10 @@ void builtin_setskill(ScriptState *st)
int level;
struct map_session_data *sd;
- SkillID id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ SkillID id = static_cast<SkillID>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
level = conv_num(st, &(st->stack->stack_data[st->start + 3]));
sd = script_rid2sd(st);
- sd->status.skill[id].id = level ? id : SkillID();
sd->status.skill[id].lv = level;
clif_skillinfoblock(sd);
}
@@ -3809,16 +3808,16 @@ void builtin_getactivatedpoolskilllist(ScriptState *st)
{
SkillID skill_id = pool_skills[i];
- if (sd->status.skill[skill_id].id == skill_id)
+ if (sd->status.skill[skill_id].lv)
{
pc_setreg(sd, add_str("@skilllist_id") + (count << 24),
- uint16_t(sd->status.skill[skill_id].id));
+ static_cast<uint16_t>(skill_id));
pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
- sd->status.skill[skill_id].lv);
+ sd->status.skill[skill_id].lv);
pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
- uint16_t(sd->status.skill[skill_id].flags));
+ static_cast<uint16_t>(sd->status.skill[skill_id].flags));
pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
- skill_name(skill_id));
+ skill_name(skill_id));
++count;
}
}
@@ -3839,22 +3838,21 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st)
{
SkillID skill_id = skill_pool_skills[i];
- if (sd->status.skill[skill_id].id == skill_id
+ if (sd->status.skill[skill_id].lv
&& !bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
{
pc_setreg(sd, add_str("@skilllist_id") + (count << 24),
- uint16_t(sd->status.skill[skill_id].id));
+ static_cast<uint16_t>(skill_id));
pc_setreg(sd, add_str("@skilllist_lv") + (count << 24),
- sd->status.skill[skill_id].lv);
+ sd->status.skill[skill_id].lv);
pc_setreg(sd, add_str("@skilllist_flag") + (count << 24),
- uint16_t(sd->status.skill[skill_id].flags));
+ static_cast<uint16_t>(sd->status.skill[skill_id].flags));
pc_setregstr(sd, add_str("@skilllist_name$") + (count << 24),
- skill_name(skill_id));
+ skill_name(skill_id));
++count;
}
}
pc_setreg(sd, add_str("@skilllist_count"), count);
-
}
static
diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp
index 9c0ea8b..c225ebe 100644
--- a/src/map/skill-pools.cpp
+++ b/src/map/skill-pools.cpp
@@ -54,13 +54,13 @@ int skill_pool_activate(struct map_session_data *sd, SkillID skill_id)
{
if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
return 0; // Already there
- else if (sd->status.skill[skill_id].id == skill_id // knows the skill
+ else if (sd->status.skill[skill_id].lv
&& (skill_pool_size(sd) < skill_pool_max(sd)))
{
sd->status.skill[skill_id].flags |= SkillFlags::POOL_ACTIVATED;
pc_calcstatus(sd, 0);
MAP_LOG_PC(sd, "SKILL-ACTIVATE %d %d %d",
- uint16_t(skill_id), sd->status.skill[skill_id].lv,
+ skill_id, sd->status.skill[skill_id].lv,
skill_power(sd, skill_id));
return 0;
}
@@ -78,7 +78,7 @@ int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id)
if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED))
{
sd->status.skill[skill_id].flags &= ~SkillFlags::POOL_ACTIVATED;
- MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", uint16_t(skill_id));
+ MAP_LOG_PC(sd, "SKILL-DEACTIVATE %d", skill_id);
pc_calcstatus(sd, 0);
return 0;
}