Added support for integer values to abs() math function.

Minor code refactoring in Skills.cpp.
This commit is contained in:
NovaRain
2019-01-16 11:07:56 +08:00
parent 34caa1cbbd
commit 68e8ce8d41
3 changed files with 19 additions and 13 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ Some utility/math functions are available:
> float sqrt(float x)
- square root of x
> float abs(float x)
> int/float abs(int/float x)
- absolute (positive) value of x
> float sin(float x)
@@ -38,8 +38,12 @@ void sf_sqrt(OpcodeContext& ctx) {
}
void sf_abs(OpcodeContext& ctx) {
if (ctx.arg(0).isInt()) {
ctx.setReturn(abs(ctx.arg(0).asInt()));
} else {
ctx.setReturn(abs(ctx.arg(0).asFloat()));
}
}
void sf_sin(OpcodeContext& ctx) {
ctx.setReturn(sin(ctx.arg(0).asFloat()));
+13 -11
View File
@@ -56,7 +56,7 @@ static SkillModifier baseSkillMax;
static BYTE skillCosts[512 * fo::SKILL_count];
static DWORD basedOnPoints;
static double* multipliers;
static double* multipliers = nullptr;
static std::vector<ChanceModifier> pickpocketMods;
static ChanceModifier basePickpocket;
@@ -136,7 +136,7 @@ static int __fastcall GetStatBonus(fo::GameObject* critter, const fo::SkillInfo*
}
result += points * info->skillPointMulti;
result += info->base;
return (int)result;
return static_cast<int>(result);
}
//On input, ebx/edx contains the skill id, ecx contains the critter, edi contains a SkillInfo*, ebp contains the number of skill points
@@ -145,9 +145,9 @@ static const DWORD StatBonusHookRet = 0x4AA5D6;
static void __declspec(naked) skill_level_hack_bonus() {
__asm {
push ecx;
push ebp;
push ebx;
mov edx, edi;
push ebp; // points
push ebx; // skill
mov edx, edi; // info
call GetStatBonus; // ecx - critter
mov esi, eax;
pop ecx;
@@ -253,13 +253,14 @@ void Skills::init() {
SafeWrite8(0x4ABC67, 0x89); // mov [esp + 0x54], eax
SafeWrite32(0x4ABC6B, 0x90909090);
char buf[512], key[16], file[64];
char buf[512], key[16];
auto skillsFile = GetConfigString("Misc", "SkillsFile", "");
if (skillsFile.size() > 0) {
if (!skillsFile.empty()) {
fo::SkillInfo *skills = fo::var::skill_data;
sprintf(file, ".\\%s", skillsFile.c_str());
multipliers = new double[7 * fo::SKILL_count];
memset(multipliers, 0, 7 * fo::SKILL_count * sizeof(double));
skillsFile = ".\\" + skillsFile;
const char* file = skillsFile.c_str();
multipliers = new double[7 * fo::SKILL_count]();
for (int i = 0; i < fo::SKILL_count; i++) {
sprintf(key, "Skill%d", i);
@@ -276,7 +277,8 @@ void Skills::init() {
case 'i': multipliers[i * 7 + 4] = m; break;
case 'a': multipliers[i * 7 + 5] = m; break;
case 'l': multipliers[i * 7 + 6] = m; break;
default: continue;
default:
dlogr("Warning : Invalid character for SPECIAL stats in the skills file.", DL_INIT);
}
}
tok = strtok(0, "|");