Added support for returning integer values to abs math function.

Minor code refactoring in Skills.cpp.
This commit is contained in:
NovaRain
2019-01-16 11:38:49 +08:00
parent ba3ad33587
commit e509932add
3 changed files with 23 additions and 44 deletions
+1 -1
View File
@@ -278,7 +278,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)
+12 -37
View File
@@ -67,45 +67,20 @@ end:
retn;
}
}
static void __declspec(naked) funcAbs() {
__asm {
pushad;
sub esp, 4;
mov ecx, eax;
call interpretPopShort_;
mov ebx, eax;
mov eax, ecx;
call interpretPopLong_;
cmp bx, VAR_TYPE_INT;
jnz arg1l2;
mov [esp], eax;
fild [esp];
jmp calc;
arg1l2:
cmp bx, VAR_TYPE_FLOAT;
jnz fail;
mov [esp], eax;
fld [esp];
calc:
fabs;
fstp [esp];
mov edx, [esp];
jmp end;
fail:
fldz;
fstp [esp];
mov edx, [esp];
end:
mov eax, ecx;
call interpretPushLong_;
mov edx, VAR_TYPE_FLOAT;
mov eax, ecx;
call interpretPushShort_;
add esp, 4;
popad;
retn;
static void funcAbs2() {
const ScriptValue &value = opHandler.arg(0);
if (value.isInt()) {
opHandler.setReturn(abs(value.asInt()));
} else {
opHandler.setReturn(abs(value.asFloat()));
}
}
static void __declspec(naked) funcAbs() {
_WRAP_OPCODE(funcAbs2, 1, 1)
}
static void __declspec(naked) funcSin() {
__asm {
pushad;
+10 -6
View File
@@ -26,6 +26,9 @@
#include "FalloutEngine.h"
#include "Knockback.h"
#include "ScriptExtender.h"
#if (_MSC_VER < 1600)
#include "Cpp11_emu.h"
#endif
struct SkillInfo {
const char* name;
@@ -53,7 +56,7 @@ static std::vector<SkillModifier> SkillMaxMods;
static SkillModifier BaseSkillMax;
static BYTE skillCosts[512 * SKILL_count];
static DWORD basedOnPoints;
static double* multipliers;
static double* multipliers = nullptr;
static int __fastcall CheckSkillMax(TGameObj* critter, int base) {
for (DWORD i = 0; i < SkillMaxMods.size(); i++) {
@@ -108,7 +111,7 @@ static int __fastcall GetStatBonus(TGameObj* critter, const SkillInfo* info, int
}
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
@@ -117,9 +120,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;
@@ -228,7 +231,8 @@ void SkillsInit() {
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, "|");