Minor code edits to Combat.cpp

Added some function defines.
This commit is contained in:
NovaRain
2020-05-07 12:13:28 +08:00
parent a9c74501df
commit e28b3a5796
3 changed files with 36 additions and 31 deletions
+5 -2
View File
@@ -35,6 +35,8 @@ WRAP_WATCOM_FFUNC4(long, obj_move_to_tile, GameObject*, object, long, tile, long
WRAP_WATCOM_FFUNC3(long, obj_new_sid_inst, GameObject*, object, long, sType, long, scriptIndex)
WRAP_WATCOM_FFUNC3(long, object_under_mouse, long, crSwitch, long, inclDude, long, elevation)
WRAP_WATCOM_FFUNC4(void, register_object_call, long*, target, long*, source, void*, func, long, delay)
WRAP_WATCOM_FFUNC4(long, register_object_move_to_object, GameObject*, source, GameObject*, target, long, distance, long, delay)
WRAP_WATCOM_FFUNC4(long, register_object_run_to_object, GameObject*, source, GameObject*, target, long, distance, long, delay)
WRAP_WATCOM_FFUNC3(long, scr_get_local_var, long, sid, long, varId, long*, value)
WRAP_WATCOM_FFUNC3(long, scr_set_local_var, long, sid, long, varId, long, value)
WRAP_WATCOM_FFUNC3(long, tile_num_in_direction, long, tile, long, rotation,long, distance)
@@ -104,6 +106,7 @@ WRAP_WATCOM_FUNC1(long, item_w_max_ammo, GameObject*, item)
WRAP_WATCOM_FUNC2(long, item_w_range, GameObject*, critter, long, hitMode)
WRAP_WATCOM_FUNC2(long, item_w_reload, GameObject*, weapon, GameObject*, ammo)
WRAP_WATCOM_FUNC1(long, item_w_rounds, GameObject*, item)
WRAP_WATCOM_FUNC2(long, item_w_subtype, GameObject*, item, long, hitMode)
WRAP_WATCOM_FUNC1(long, item_weight, GameObject*, item)
// returns light level at given tile
WRAP_WATCOM_FUNC2(long, light_get_tile, long, elevation, long, tileNum)
@@ -135,6 +138,8 @@ WRAP_WATCOM_FUNC0(void, process_bk)
WRAP_WATCOM_FUNC0(void, proto_dude_update_gender)
WRAP_WATCOM_FUNC2(long*, queue_find_first, GameObject*, object, long, qType)
WRAP_WATCOM_FUNC2(long*, queue_find_next, GameObject*, object, long, qType)
WRAP_WATCOM_FUNC1(long, register_begin, long, regType)
WRAP_WATCOM_FUNC0(long, register_end)
WRAP_WATCOM_FUNC3(long, register_object_animate, GameObject*, object, long, anim, long, delay)
WRAP_WATCOM_FUNC3(long, register_object_animate_and_hide, GameObject*, object, long, anim, long, delay)
// WRAP_WATCOM_FUNC3(long, register_object_animate_and_move_straight_, GameObject*, object;
@@ -149,13 +154,11 @@ WRAP_WATCOM_FUNC1(long, register_object_inc_rotation, GameObject*, object)
WRAP_WATCOM_FUNC3(long, register_object_light, GameObject*, object, long, lightRadius, long, delay)
// WRAP_WATCOM_FUNC3(long, register_object_move_on_stairs_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_move_straight_to_tile_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_move_to_object_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_move_to_tile_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_must_call_, GameObject*, object;
WRAP_WATCOM_FUNC1(long, register_object_must_erase, GameObject*, object)
// WRAP_WATCOM_FUNC3(long, register_object_outline_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_play_sfx_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_run_to_object_, GameObject*, object;
// WRAP_WATCOM_FUNC3(long, register_object_run_to_tile_, GameObject*, object;
WRAP_WATCOM_FUNC3(long, register_object_take_out, GameObject*, object, long, holdFrameId, long, nothing)
WRAP_WATCOM_FUNC3(long, register_object_turn_towards, GameObject*, object, long, tileNum, long, nothing)
+23 -23
View File
@@ -83,10 +83,10 @@ static bool hookedAimedShot;
static std::vector<DWORD> disabledAS;
static std::vector<DWORD> forcedAS;
static DWORD __fastcall add_check_for_item_ammo_cost(register fo::GameObject* weapon, DWORD hitMode) {
DWORD __fastcall Combat::check_item_ammo_cost(fo::GameObject* weapon, DWORD hitMode) {
DWORD rounds = 1;
DWORD anim = fo::func::item_w_anim_weap(weapon, hitMode);
long anim = fo::func::item_w_anim_weap(weapon, hitMode);
if (anim == fo::Animation::ANIM_fire_burst || anim == fo::Animation::ANIM_fire_continuous) {
rounds = fo::func::item_w_rounds(weapon); // ammo in burst
}
@@ -95,9 +95,9 @@ static DWORD __fastcall add_check_for_item_ammo_cost(register fo::GameObject* we
} else if (rounds == 1) {
fo::func::item_w_compute_ammo_cost(weapon, &rounds);
}
DWORD currAmmo = fo::func::item_w_curr_ammo(weapon);
long currAmmo = fo::func::item_w_curr_ammo(weapon);
DWORD cost = 1; // default cost
long cost = 1; // default cost
if (currAmmo > 0) {
cost = rounds / currAmmo;
if (rounds % currAmmo) cost++; // round up
@@ -111,7 +111,7 @@ static void __declspec(naked) combat_check_bad_shot_hook() {
push edx;
push ecx; // weapon
mov edx, edi; // hitMode
call add_check_for_item_ammo_cost;
call Combat::check_item_ammo_cost;
pop ecx;
pop edx;
retn;
@@ -125,7 +125,7 @@ static void __declspec(naked) ai_search_inven_weap_hook() {
push ecx;
mov ecx, eax; // weapon
mov edx, ATKTYPE_RWEAPON_PRIMARY; // hitMode
call add_check_for_item_ammo_cost; // enough ammo?
call Combat::check_item_ammo_cost; // enough ammo?
pop ecx;
retn;
}
@@ -183,7 +183,7 @@ static void __declspec(naked) compute_spray_hack() {
}
static double ApplyModifiers(std::vector<KnockbackModifier>* mods, fo::GameObject* object, double val) {
for (DWORD i = 0; i < mods->size(); i++) {
for (size_t i = 0; i < mods->size(); i++) {
KnockbackModifier* mod = &(*mods)[i];
if (mod->id == object->id) {
switch (mod->type) {
@@ -238,7 +238,7 @@ static void __declspec(naked) compute_dmg_damage_hack() {
}
static int __fastcall HitChanceMod(int base, fo::GameObject* critter) {
for (DWORD i = 0; i < hitChanceMods.size(); i++) {
for (size_t i = 0; i < hitChanceMods.size(); i++) {
if (critter->id == hitChanceMods[i].id) {
return min(base + hitChanceMods[i].mod, hitChanceMods[i].maximum);
}
@@ -280,7 +280,7 @@ static void __declspec(naked) ai_pick_hit_mode_hack_noSecondary() {
}
}
void _stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode) {
void __stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode) {
std::vector<KnockbackModifier>* mods;
switch (mode) {
case 0:
@@ -301,7 +301,7 @@ void _stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWO
: Objects::SetObjectUniqueID(object);
KnockbackModifier mod = { id, type, (double)val };
for (DWORD i = 0; i < mods->size(); i++) {
for (size_t i = 0; i < mods->size(); i++) {
if ((*mods)[i].id == id) {
(*mods)[i] = mod;
return;
@@ -310,7 +310,7 @@ void _stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWO
mods->push_back(mod);
}
void _stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode) {
void __stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode) {
std::vector<KnockbackModifier>* mods;
switch (mode) {
case 0:
@@ -325,7 +325,7 @@ void _stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode) {
default:
return;
}
for (DWORD i = 0; i < mods->size(); i++) {
for (size_t i = 0; i < mods->size(); i++) {
if ((*mods)[i].id == object->id) {
mods->erase(mods->begin() + i);
if (mode == 0) Objects::SetNewEngineID(object); // revert to engine range id
@@ -334,7 +334,7 @@ void _stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode) {
}
}
void _stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod) {
void __stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod) {
if ((DWORD)critter == -1) {
baseHitChance.maximum = maximum;
baseHitChance.mod = mod;
@@ -342,7 +342,7 @@ void _stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod)
}
if (critter->Type() != fo::OBJ_TYPE_CRITTER) return;
long id = Objects::SetObjectUniqueID(critter);
for (DWORD i = 0; i < hitChanceMods.size(); i++) {
for (size_t i = 0; i < hitChanceMods.size(); i++) {
if (id == hitChanceMods[i].id) {
hitChanceMods[i].maximum = maximum;
hitChanceMods[i].mod = mod;
@@ -352,7 +352,7 @@ void _stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod)
hitChanceMods.emplace_back(id, maximum, mod);
}
void _stdcall SetNoBurstMode(fo::GameObject* critter, bool on) {
void __stdcall SetNoBurstMode(fo::GameObject* critter, bool on) {
if (critter == fo::var::obj_dude || critter->Type() != fo::OBJ_TYPE_CRITTER) return;
long id = Objects::SetObjectUniqueID(critter);
@@ -367,10 +367,10 @@ void _stdcall SetNoBurstMode(fo::GameObject* critter, bool on) {
static int __fastcall AimedShotTest(DWORD pid) {
if (pid) pid = ((fo::GameObject*)pid)->protoId;
for (DWORD i = 0; i < disabledAS.size(); i++) {
for (size_t i = 0; i < disabledAS.size(); i++) {
if (disabledAS[i] == pid) return -1;
}
for (DWORD i = 0; i < forcedAS.size(); i++) {
for (size_t i = 0; i < forcedAS.size(); i++) {
if (forcedAS[i] == pid) return 1;
}
return 0;
@@ -403,23 +403,23 @@ static void HookAimedShots() {
hookedAimedShot = true;
}
void _stdcall DisableAimedShots(DWORD pid) {
void __stdcall DisableAimedShots(DWORD pid) {
if (!hookedAimedShot) HookAimedShots();
for (DWORD i = 0; i < forcedAS.size(); i++) {
for (size_t i = 0; i < forcedAS.size(); i++) {
if (forcedAS[i] == pid) forcedAS.erase(forcedAS.begin() + (i--));
}
for (DWORD i = 0; i < disabledAS.size(); i++) {
for (size_t i = 0; i < disabledAS.size(); i++) {
if (disabledAS[i] == pid) return;
}
disabledAS.push_back(pid);
}
void _stdcall ForceAimedShots(DWORD pid) {
void __stdcall ForceAimedShots(DWORD pid) {
if (!hookedAimedShot) HookAimedShots();
for (DWORD i = 0; i < disabledAS.size(); i++) {
for (size_t i = 0; i < disabledAS.size(); i++) {
if (disabledAS[i] == pid) disabledAS.erase(disabledAS.begin() + (i--));
}
for (DWORD i = 0; i < forcedAS.size(); i++) {
for (size_t i = 0; i < forcedAS.size(); i++) {
if (forcedAS[i] == pid) return;
}
forcedAS.push_back(pid);
+8 -6
View File
@@ -27,6 +27,8 @@ class Combat : public Module {
public:
const char* name() { return "Combat"; }
void init();
static DWORD __fastcall check_item_ammo_cost(fo::GameObject* weapon, DWORD hitMode);
};
struct ChanceModifier {
@@ -48,12 +50,12 @@ struct ChanceModifier {
}
};
void _stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod);
void _stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode);
void _stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode);
void __stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod);
void __stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode);
void __stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode);
void _stdcall SetNoBurstMode(fo::GameObject* critter, bool on);
void _stdcall DisableAimedShots(DWORD pid);
void _stdcall ForceAimedShots(DWORD pid);
void __stdcall SetNoBurstMode(fo::GameObject* critter, bool on);
void __stdcall DisableAimedShots(DWORD pid);
void __stdcall ForceAimedShots(DWORD pid);
}