Skip to content

Commit

Permalink
Minor code fixes in AI.cpp:
Browse files Browse the repository at this point in the history
* Fixed NPCs being unable to select a burst attack mode if the line of
fire was blocked.

* Changed the return point of combat_ai_hook_FleeFix to run
ai_check_drugs_ first.

Changed the debug message about missing art file for critters to be
displayed in game only when in sfall debugging mode.
  • Loading branch information
NovaRain committed May 19, 2020
1 parent c89a185 commit 6bb56b0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion sfall/FalloutEngine/EngineUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void ToggleNpcFlag(fo::GameObject* npc, long flag, bool set) {
}
}

// Returns the number of party members in the existing table (begins from 1)
// Returns the position of party member in the existing table (begins from 1)
long IsPartyMemberByPid(long pid) {
size_t patryCount = fo::var::partyMemberMaxCount;
if (patryCount) {
Expand All @@ -178,6 +178,7 @@ long IsPartyMemberByPid(long pid) {
return 0;
}

// Returns True if the NPC belongs to the player's potential (set in party.txt) party members (analog of broken isPotentialPartyMember_)
bool IsPartyMember(fo::GameObject* critter) {
if (critter->id < PLAYER_ID) return false;
return (IsPartyMemberByPid(critter->protoId) > 0);
Expand Down
3 changes: 2 additions & 1 deletion sfall/FalloutEngine/EngineUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ long __fastcall IsRadInfluence();

void ToggleNpcFlag(fo::GameObject* npc, long flag, bool set);

// Returns the number of party members in the existing table (begins from 1)
// Returns the position of party member in the existing table (begins from 1)
long IsPartyMemberByPid(long pid);

// Returns True if the NPC belongs to the player's potential (set in party.txt) party members (analog of broken isPotentialPartyMember_)
bool IsPartyMember(fo::GameObject* critter);

// Returns the number of local variables of the object script
Expand Down
5 changes: 3 additions & 2 deletions sfall/Modules/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ fo::GameObject* AI::sf_check_critters_in_lof(fo::GameObject* object, DWORD check
fo::GameObject* AI::CheckFriendlyFire(fo::GameObject* target, fo::GameObject* attacker) {
fo::GameObject* object = nullptr;
fo::func::make_straight_path_func(attacker, attacker->tile, target->tile, 0, (DWORD*)&object, 32, (void*)fo::funcoffs::obj_shoot_blocking_at_);
return sf_check_critters_in_lof(object, target->tile, attacker->critter.teamNum); // 0 if there are no friendly critters
object = sf_check_critters_in_lof(object, target->tile, attacker->critter.teamNum);
return (!object || object->TypeFid() == fo::ObjType::OBJ_TYPE_CRITTER) ? object : nullptr; // 0 if there are no friendly critters
}

static void __declspec(naked) ai_try_attack_hook_FleeFix() {
Expand All @@ -59,7 +60,7 @@ static void __declspec(naked) ai_try_attack_hook_FleeFix() {
}

static void __declspec(naked) combat_ai_hook_FleeFix() {
static const DWORD combat_ai_hook_flee_Ret = 0x42B22F;
static const DWORD combat_ai_hook_flee_Ret = 0x42B206;
__asm {
test byte ptr [ebp], 8; // 'ReTarget' flag (critter.combat_state)
jnz reTarget;
Expand Down
7 changes: 6 additions & 1 deletion sfall/Modules/DebugEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ static void __declspec(naked) art_data_size_hook() {
push edx;
push artDbgMsg;
call fo::funcoffs::debug_printf_;
cmp isDebug, 0;
jne display;
add esp, 8;
retn;
display:
push edx; // filename
push artDbgMsg;
lea eax, [esp + 0x124 - 0x124 + 20]; // buf
Expand Down Expand Up @@ -379,7 +384,7 @@ static void DebugModePatch() {
if (iniGetInt("Debugging", "HideObjIsNullMsg", 0, ::sfall::ddrawIni)) {
MakeJump(0x453FD2, dbg_error_hack);
}
// prints a debug message about missing art file for critters to both debug.log and the message window
// prints a debug message about missing art file for critters to both debug.log and the message window in sfall debugging mode
HookCall(0x419B65, art_data_size_hook);

// Fix to prevent crashes when there is a '%' character in the printed message
Expand Down
4 changes: 2 additions & 2 deletions sfall/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#define VERSION_MAJOR 4
#define VERSION_MINOR 2
#define VERSION_BUILD 5
#define VERSION_REV 0
#define VERSION_REV 1

#define VERSION_STRING "4.2.5"
#define VERSION_STRING "4.2.5.1"

3 comments on commit 6bb56b0

@FakelsHub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make fix-release.

@NovaRain
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make fix-release.

Are you done with the minor bugs you mentioned on NC?
For official build there are probably only two lines in changelog. Should I write the change in CheckFriendlyFire() as:
Fixed a bug introduced in 4.2.5 that caused NPCs to be unable to select a burst attack mode if the line of fire was blocked

@FakelsHub
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you done with the minor bugs you mentioned on NC?

There were errors related to the Ext. version, I saw the bug in CheckFriendlyFire() by accident :)
you can write it that way.

Please sign in to comment.