Changed the fix for AI target selection in commit f731de7

* NPCs will reload the weapon in the same turn (and attack if have
enough AP left) if weapon is empty while selecting targets.

Misc code edits.
This commit is contained in:
NovaRain
2020-04-27 14:25:40 +08:00
parent d6f4a23527
commit ece76ee726
11 changed files with 108 additions and 90 deletions
+1 -1
View File
@@ -411,7 +411,7 @@ CorpseDeleteTime=6
;Set a number of milliseconds to idle each input loop
;Set to -1 to disable
;Set to 0 to idle only if other processes are waiting for processor time (WinXP/2000: if processes have equal priority)
;Set to 1 (or some higher number if needed, the maximum is 127) to prevent 100% CPU use
;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 127
ProcessorIdle=-1
;Set to 1 if using the hero appearance mod
+15 -6
View File
@@ -90,6 +90,15 @@ enum Animation : long
ANIM_called_shot_pic = 64,
};
enum AnimCommand : long
{
RB_UNRESERVED = 0x1,
RB_RESERVED = 0x2,
RB_DONTSTAND = 0x4,
RB_UNKNOWN = 0x100,
RB_END_ANIM = 0x200
};
enum CritterFlags : long
{
Sneak = 0x01, // Can sneak ?
@@ -244,7 +253,7 @@ enum ArtType : char
// Some FO2 PIDs possibly used by engine
enum ProtoId : long
{
PID_ROCK = 19,
// PID_ROCK = 19,
PID_SMALL_ENERGY_CELL = 38,
PID_MICRO_FUSION_CELL = 39,
PID_STIMPAK = 40,
@@ -256,8 +265,8 @@ enum ProtoId : long
PID_GEIGER_COUNTER = 52,
PID_MENTATS = 53,
PID_STEALTH_BOY = 54,
PID_WATER_CHIP = 55,
PID_HOLODISK = 58,
// PID_WATER_CHIP = 55,
// PID_HOLODISK = 58,
PID_MOTION_SENSOR = 59,
PID_MUTATED_FRUIT = 71,
PID_BIG_BOOK_OF_SCIENCE = 73,
@@ -268,7 +277,7 @@ enum ProtoId : long
PID_SCOUT_HANDBOOK = 86,
PID_BUFFOUT = 87,
PID_DOCTORS_BAG = 91,
PID_PUMP_PARTS = 98,
// PID_PUMP_PARTS = 98,
PID_GUNS_AND_BULLETS = 102,
PID_NUKA_COLA = 106,
PID_RAD_X = 109,
@@ -287,7 +296,7 @@ enum ProtoId : long
PID_JET = 259,
PID_JET_ANTIDOTE = 260,
PID_DECK_OF_TRAGIC_CARDS = 306,
PID_GECK = 366,
// PID_GECK = 366,
PID_SOLAR_SCORCHER = 390,
PID_CAR_TRUNK = 455,
PID_JESSE_CONTAINER = 467,
@@ -560,7 +569,7 @@ namespace Scripts {
}
#define STAT_max_derived STAT_poison_resist
#define STAT_max_stat STAT_current_hp
#define STAT_max_stat STAT_current_hp
// Script data types
#define VAR_TYPE_INT (0xC001)
+3
View File
@@ -19,6 +19,7 @@
WRAP_WATCOM_FFUNC4(long, _word_wrap, const char*, text, int, maxWidth, DWORD*, buf, BYTE*, count)
WRAP_WATCOM_FFUNC3(void, correctFidForRemovedItem, GameObject*, critter, GameObject*, item, long, slotFlag)
WRAP_WATCOM_FFUNC7(long, createWindow, const char*, winName, DWORD, x, DWORD, y, DWORD, width, DWORD, height, long, color, long, flags)
WRAP_WATCOM_FFUNC4(long, determine_to_hit, GameObject*, source, GameObject*, target, long, bodyPart, long, hitMode)
WRAP_WATCOM_FFUNC3(void, display_inventory, long, inventoryOffset, long, visibleOffset, long, mode)
WRAP_WATCOM_FFUNC4(void, display_target_inventory, long, inventoryOffset, long, visibleOffset, DWORD*, targetInventory, long, mode)
WRAP_WATCOM_FFUNC3(FrmFrameData*, frame_ptr, FrmHeaderData*, frm, long, frame, long, direction)
@@ -98,6 +99,7 @@ WRAP_WATCOM_FUNC1(long, item_w_dam_div, GameObject*, item)
WRAP_WATCOM_FUNC1(long, item_w_dam_mult, GameObject*, item)
WRAP_WATCOM_FUNC1(long, item_w_dr_adjust, GameObject*, item)
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_FUNC1(long, item_weight, GameObject*, item)
@@ -114,6 +116,7 @@ WRAP_WATCOM_FUNC0(long, new_obj_id)
// calculates bounding box (rectangle) for a given object
WRAP_WATCOM_FUNC2(void, obj_bound, GameObject*, object, BoundRect*, boundRect)
WRAP_WATCOM_FUNC1(long, obj_destroy, GameObject*, object)
WRAP_WATCOM_FUNC2(long, obj_dist, GameObject*, source, GameObject*, target)
WRAP_WATCOM_FUNC2(long, obj_erase_object, GameObject*, object, BoundRect*, boundRect)
WRAP_WATCOM_FUNC0(GameObject*, obj_find_first)
WRAP_WATCOM_FUNC0(GameObject*, obj_find_next)
+13 -9
View File
@@ -152,7 +152,7 @@ skip:
}
}
static DWORD RetryCombatMinAP;
static long RetryCombatMinAP;
static void __declspec(naked) RetryCombatHook() {
static DWORD RetryCombatLastAP = 0;
@@ -238,7 +238,7 @@ static void __declspec(naked) ai_danger_source_hook() {
je fix;
retn;
fix: // check result
cmp eax, 2; // exception: 2 - out of range, 1 - no ammo
cmp eax, 1; // exception: 1 - no ammo
setg al; // set 0 for result OK
retn;
}
@@ -286,6 +286,15 @@ void AI::init() {
/////////////////////// Combat AI behavior fixes ///////////////////////
// Fix for duplicate critters being added to the list of potential targets for AI
MakeCall(0x428E75, ai_find_attackers_hack_target2, 2);
MakeCall(0x428EB5, ai_find_attackers_hack_target3);
MakeCall(0x428EE5, ai_find_attackers_hack_target4, 1);
#ifndef NDEBUG
if (iniGetInt("Debugging", "AIBugFixes", 1, ::sfall::ddrawIni) == 0) return;
#endif
// Fix to allow fleeing NPC to use drugs
MakeCall(0x42B1DC, combat_ai_hack);
// Fix for AI not checking minimum hp properly for using stimpaks (prevents premature fleeing)
@@ -297,13 +306,8 @@ void AI::init() {
// Disable fleeing when NPC cannot move closer to target
BlockCall(0x42ADF6); // ai_try_attack_
// Fix for duplicate critters being added to the list of potential targets for AI
MakeCall(0x428E75, ai_find_attackers_hack_target2, 2);
MakeCall(0x428EB5, ai_find_attackers_hack_target3);
MakeCall(0x428EE5, ai_find_attackers_hack_target4, 1);
// Fix AI target selection for combat_check_bad_shot_ function returning a no_ammo or out_of_range result
HookCall(0x42918A, ai_danger_source_hook);
// Fix AI target selection for combat_check_bad_shot_ function returning a no_ammo result
HookCalls(ai_danger_source_hook, {0x42903A, 0x42918A});
}
fo::GameObject* __stdcall AI::AIGetLastAttacker(fo::GameObject* target) {
+2 -2
View File
@@ -2664,8 +2664,8 @@ checkTiles:
void BugFixes::init()
{
#ifndef NDEBUG
LoadGameHook::OnBeforeGameClose() += PrintAddrList;
if (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0) return;
LoadGameHook::OnBeforeGameClose() += PrintAddrList;
if (iniGetInt("Debugging", "BugFixes", 1, ::sfall::ddrawIni) == 0) return;
#endif
// Missing game initialization
+2 -2
View File
@@ -97,7 +97,7 @@ static void __declspec(naked) GetNumButtonsHook3() {
}
}
void ResetElevators() {
static void ResetElevators() {
//memset(&elevatorExits[vanillaElevatorCount], 0, sizeof(fo::ElevatorExit) * (elevatorCount - vanillaElevatorCount) * exitsPerElevator);
//memset(&elevatorsFrms[vanillaElevatorCount], 0, sizeof(fo::ElevatorFrms) * (elevatorCount - vanillaElevatorCount));
//for (int i = vanillaElevatorCount; i < elevatorCount; i++) elevatorType[i] = 0;
@@ -138,7 +138,7 @@ static void LoadElevators(const char* elevFile) {
}
}
void ElevatorsInit() {
static void ElevatorsInit() {
HookCall(0x43EF83, GetMenuHook);
HookCall(0x43F141, CheckHotKeysHook);
//HookCall(0x43F2D2, UnknownHook2); // unused
+16 -16
View File
@@ -1,20 +1,20 @@
/*
* sfall
* Copyright (C) 2008-2016 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* sfall
* Copyright (C) 2008-2016 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
#include "..\FalloutEngine\Fallout2.h"
+17 -16
View File
@@ -1,20 +1,21 @@
/*
* sfall
* Copyright (C) 2008-2016 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* sfall
* Copyright (C) 2008-2016 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Module.h"
+16 -16
View File
@@ -1,20 +1,20 @@
/*
* sfall
* Copyright (C) 2008-2017 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* sfall
* Copyright (C) 2008-2017 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "..\main.h"
+17 -16
View File
@@ -1,20 +1,21 @@
/*
* sfall
* Copyright (C) 2008-2017 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
* sfall
* Copyright (C) 2008-2017 The sfall team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "Module.h"
+6 -6
View File
@@ -345,7 +345,7 @@ static void RestRestore() {
SafeWrite16(0x499E93, 0x0574);
}
void WorldLimitsPatches() {
static void WorldLimitsPatches() {
DWORD data = GetConfigInt("Misc", "LocalMapXLimit", 0);
if (data) {
dlog("Applying local map x limit patch.", DL_INIT);
@@ -368,7 +368,7 @@ void WorldLimitsPatches() {
//}
}
void TimeLimitPatch() {
static void TimeLimitPatch() {
int limit = GetConfigInt("Misc", "TimeLimit", 13);
if (limit == -2 || limit == -3) {
addYear = true;
@@ -394,7 +394,7 @@ void TimeLimitPatch() {
}
}
void WorldmapFpsPatch() {
static void WorldmapFpsPatch() {
bool fpsPatchOK = (*(DWORD*)0x4BFE5E == 0x8D16);
if (GetConfigInt("Misc", "WorldMapFPSPatch", 0)) {
dlog("Applying world map fps patch.", DL_INIT);
@@ -429,7 +429,7 @@ void WorldmapFpsPatch() {
}
}
void PathfinderFixInit() {
static void PathfinderFixInit() {
//if (GetConfigInt("Misc", "PathfinderFix", 0)) {
dlog("Applying Pathfinder patch.", DL_INIT);
SafeWrite16(0x4C1FF6, 0x9090); // wmPartyWalkingStep_
@@ -439,7 +439,7 @@ void PathfinderFixInit() {
//}
}
void StartingStatePatches() {
static void StartingStatePatches() {
int date = GetConfigInt("Misc", "StartYear", -1);
if (date >= 0) {
dlog("Applying starting year patch.", DL_INIT);
@@ -495,7 +495,7 @@ void StartingStatePatches() {
if (ViewportX != -1 || ViewportY != -1) HookCall(0x4BCF07, ViewportHook); // game_reset_
}
void PipBoyAutomapsPatch() {
static void PipBoyAutomapsPatch() {
dlog("Applying Pip-Boy automaps patch.", DL_INIT);
MakeCall(0x4BF931, wmMapInit_hack, 2);
SafeWrite32(0x41B8B7, (DWORD)AutomapPipboyList);