mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Tweaked set_pc/critter_base/extra_stat script functions
* before they didn't update derived stats when setting SPECIAL, for the player it requires accessing the char screen to update. Replaced some proto_ptr() usages with GetProto().
This commit is contained in:
@@ -215,6 +215,7 @@ WRAP_WATCOM_FUNC2(long, skill_level, fo::GameObject*, critter, long, statID)
|
|||||||
WRAP_WATCOM_FUNC2(long, stat_get_base, fo::GameObject*, critter, long, statID)
|
WRAP_WATCOM_FUNC2(long, stat_get_base, fo::GameObject*, critter, long, statID)
|
||||||
WRAP_WATCOM_FUNC2(long, stat_get_base_direct, fo::GameObject*, critter, long, statID)
|
WRAP_WATCOM_FUNC2(long, stat_get_base_direct, fo::GameObject*, critter, long, statID)
|
||||||
WRAP_WATCOM_FUNC2(long, stat_get_bonus, fo::GameObject*, critter, long, statID)
|
WRAP_WATCOM_FUNC2(long, stat_get_bonus, fo::GameObject*, critter, long, statID)
|
||||||
|
WRAP_WATCOM_FUNC1(void, stat_recalc_derived, fo::GameObject*, critter)
|
||||||
WRAP_WATCOM_FUNC3(long, stat_set_bonus, fo::GameObject*, critter, long, statID, long, amount)
|
WRAP_WATCOM_FUNC3(long, stat_set_bonus, fo::GameObject*, critter, long, statID, long, amount)
|
||||||
WRAP_WATCOM_FUNC2(void, skill_get_tags, long*, tags, long, num)
|
WRAP_WATCOM_FUNC2(void, skill_get_tags, long*, tags, long, num)
|
||||||
WRAP_WATCOM_FUNC2(void, skill_set_tags, long*, tags, long, num)
|
WRAP_WATCOM_FUNC2(void, skill_set_tags, long*, tags, long, num)
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ void op_get_proto_data(OpcodeContext& ctx) {
|
|||||||
long result = -1;
|
long result = -1;
|
||||||
fo::Proto* protoPtr;
|
fo::Proto* protoPtr;
|
||||||
int pid = ctx.arg(0).rawValue();
|
int pid = ctx.arg(0).rawValue();
|
||||||
if (fo::util::CheckProtoID(pid) && fo::func::proto_ptr(pid, &protoPtr) != result) {
|
if (fo::util::CheckProtoID(pid) && fo::util::GetProto(pid, &protoPtr)) {
|
||||||
result = *(long*)((BYTE*)protoPtr + ctx.arg(1).rawValue());
|
result = *(long*)((BYTE*)protoPtr + ctx.arg(1).rawValue());
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(protoFailedLoad, ctx.getOpcodeName(), pid);
|
ctx.printOpcodeError(protoFailedLoad, ctx.getOpcodeName(), pid);
|
||||||
@@ -448,7 +448,7 @@ void op_get_proto_data(OpcodeContext& ctx) {
|
|||||||
void op_set_proto_data(OpcodeContext& ctx) {
|
void op_set_proto_data(OpcodeContext& ctx) {
|
||||||
fo::Proto* protoPtr;
|
fo::Proto* protoPtr;
|
||||||
int pid = ctx.arg(0).rawValue();
|
int pid = ctx.arg(0).rawValue();
|
||||||
if (fo::util::CheckProtoID(pid) && fo::func::proto_ptr(pid, &protoPtr) != -1) {
|
if (fo::util::CheckProtoID(pid) && fo::util::GetProto(pid, &protoPtr)) {
|
||||||
*(long*)((BYTE*)protoPtr + ctx.arg(1).rawValue()) = ctx.arg(2).rawValue();
|
*(long*)((BYTE*)protoPtr + ctx.arg(1).rawValue()) = ctx.arg(2).rawValue();
|
||||||
if (!protoMaxLimitPatch) {
|
if (!protoMaxLimitPatch) {
|
||||||
Objects::LoadProtoAutoMaxLimit();
|
Objects::LoadProtoAutoMaxLimit();
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ void op_set_pc_base_stat(OpcodeContext& ctx) {
|
|||||||
int stat = ctx.arg(0).rawValue();
|
int stat = ctx.arg(0).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
((long*)FO_VAR_pc_proto)[9 + stat] = ctx.arg(1).rawValue();
|
((long*)FO_VAR_pc_proto)[9 + stat] = ctx.arg(1).rawValue();
|
||||||
|
if (stat <= fo::STAT_lu) fo::func::stat_recalc_derived(*fo::ptr::obj_dude);
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
@@ -62,6 +63,7 @@ void op_set_pc_extra_stat(OpcodeContext& ctx) {
|
|||||||
int stat = ctx.arg(0).rawValue();
|
int stat = ctx.arg(0).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
((long*)FO_VAR_pc_proto)[44 + stat] = ctx.arg(1).rawValue();
|
((long*)FO_VAR_pc_proto)[44 + stat] = ctx.arg(1).rawValue();
|
||||||
|
if (stat <= fo::STAT_lu) fo::func::stat_recalc_derived(*fo::ptr::obj_dude);
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
@@ -94,8 +96,11 @@ void op_set_critter_base_stat(OpcodeContext& ctx) {
|
|||||||
if (obj && obj->IsCritter()) {
|
if (obj && obj->IsCritter()) {
|
||||||
int stat = ctx.arg(1).rawValue();
|
int stat = ctx.arg(1).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
fo::Proto* proto = fo::util::GetProto(obj->protoId);
|
fo::Proto* proto;
|
||||||
if (proto != nullptr) ((long*)proto)[9 + stat] = ctx.arg(2).rawValue();
|
if (fo::util::GetProto(obj->protoId, &proto)) {
|
||||||
|
((long*)proto)[9 + stat] = ctx.arg(2).rawValue();
|
||||||
|
if (stat <= fo::STAT_lu) fo::func::stat_recalc_derived(obj);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
@@ -109,8 +114,11 @@ void op_set_critter_extra_stat(OpcodeContext& ctx) {
|
|||||||
if (obj && obj->IsCritter()) {
|
if (obj && obj->IsCritter()) {
|
||||||
int stat = ctx.arg(1).rawValue();
|
int stat = ctx.arg(1).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
fo::Proto* proto = fo::util::GetProto(obj->protoId);
|
fo::Proto* proto;
|
||||||
if (proto != nullptr) ((long*)proto)[44 + stat] = ctx.arg(2).rawValue();
|
if (fo::util::GetProto(obj->protoId, &proto)) {
|
||||||
|
((long*)proto)[44 + stat] = ctx.arg(2).rawValue();
|
||||||
|
if (stat <= fo::STAT_lu) fo::func::stat_recalc_derived(obj);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
@@ -125,8 +133,10 @@ void op_get_critter_base_stat(OpcodeContext& ctx) {
|
|||||||
if (obj && obj->IsCritter()) {
|
if (obj && obj->IsCritter()) {
|
||||||
int stat = ctx.arg(1).rawValue();
|
int stat = ctx.arg(1).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
fo::Proto* proto = fo::util::GetProto(obj->protoId);
|
fo::Proto* proto;
|
||||||
if (proto != nullptr) result = ((long*)proto)[9 + stat];
|
if (fo::util::GetProto(obj->protoId, &proto)) {
|
||||||
|
result = ((long*)proto)[9 + stat];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
@@ -142,8 +152,10 @@ void op_get_critter_extra_stat(OpcodeContext& ctx) {
|
|||||||
if (obj && obj->IsCritter()) {
|
if (obj && obj->IsCritter()) {
|
||||||
int stat = ctx.arg(1).rawValue();
|
int stat = ctx.arg(1).rawValue();
|
||||||
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
if (stat >= 0 && stat < fo::STAT_max_stat) {
|
||||||
fo::Proto* proto = fo::util::GetProto(obj->protoId);
|
fo::Proto* proto;
|
||||||
if (proto != nullptr) result = ((long*)proto)[44 + stat];
|
if (fo::util::GetProto(obj->protoId, &proto)) {
|
||||||
|
result = ((long*)proto)[44 + stat];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
ctx.printOpcodeError(invalidStat, ctx.getOpcodeName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ static long RecalcStat(int stat, int statsValue[]) {
|
|||||||
|
|
||||||
static void __stdcall StatRecalcDerived(fo::GameObject* critter) {
|
static void __stdcall StatRecalcDerived(fo::GameObject* critter) {
|
||||||
long* proto;
|
long* proto;
|
||||||
if (fo::func::proto_ptr(critter->protoId, (fo::Proto**)&proto) == -1) return;
|
if (!fo::util::GetProto(critter->protoId, (fo::Proto**)&proto)) return;
|
||||||
|
|
||||||
int baseStats[7], levelStats[7];
|
int baseStats[7], levelStats[7];
|
||||||
for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) {
|
for (int stat = fo::Stat::STAT_st; stat <= fo::Stat::STAT_lu; stat++) {
|
||||||
@@ -188,7 +188,7 @@ static void __declspec(naked) stat_recalc_derived_hack() {
|
|||||||
|
|
||||||
void Stats::UpdateHPStat(fo::GameObject* critter) {
|
void Stats::UpdateHPStat(fo::GameObject* critter) {
|
||||||
fo::Proto* proto;
|
fo::Proto* proto;
|
||||||
if (fo::func::proto_ptr(critter->protoId, &proto) == -1) return;
|
if (!fo::util::GetProto(critter->protoId, &proto)) return;
|
||||||
|
|
||||||
if (!engineDerivedStats) {
|
if (!engineDerivedStats) {
|
||||||
auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base;
|
auto getStatFunc = (derivedHPwBonus) ? fo::func::stat_level : fo::func::stat_get_base;
|
||||||
|
|||||||
Reference in New Issue
Block a user