From 352a344308b13d4b428f88a57c7e40fed9c871d3 Mon Sep 17 00:00:00 2001 From: Sevenfm Date: Fri, 24 Jan 2020 09:14:38 +0000 Subject: [PATCH] Added new option AI_PATH_TWEAKS which controls various experimental path tweaks for AI: avoid gas, deep water, light at night. Added experimental path tweak: AI tanks prefer moving in straight directions to avoid sliding effect. Set default value for options AI_EXTRA_SUPPRESSION, AI_NEW_MORALE, AI_BETTER_COVER, AI_MOVEMENT_MODE to TRUE. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8737 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- GameSettings.cpp | 9 +++++---- GameSettings.h | 1 + Tactical/PATHAI.cpp | 32 +++++++++++--------------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/GameSettings.cpp b/GameSettings.cpp index eef7b4f4..645fc9ff 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -2276,11 +2276,12 @@ void LoadGameExternalOptions() // sevenfm: tactical AI gGameExternalOptions.fAIYellowFlanking = iniReader.ReadBoolean("Tactical AI Settings", "AI_YELLOW_FLANKING", FALSE); - gGameExternalOptions.fAIExtraSuppression = iniReader.ReadBoolean("Tactical AI Settings", "AI_EXTRA_SUPPRESSION", FALSE); - gGameExternalOptions.fAINewMorale = iniReader.ReadBoolean("Tactical AI Settings", "AI_NEW_MORALE", FALSE); - gGameExternalOptions.fAIBetterCover = iniReader.ReadBoolean("Tactical AI Settings", "AI_BETTER_COVER", FALSE); + gGameExternalOptions.fAIExtraSuppression = iniReader.ReadBoolean("Tactical AI Settings", "AI_EXTRA_SUPPRESSION", TRUE); + gGameExternalOptions.fAINewMorale = iniReader.ReadBoolean("Tactical AI Settings", "AI_NEW_MORALE", TRUE); + gGameExternalOptions.fAIBetterCover = iniReader.ReadBoolean("Tactical AI Settings", "AI_BETTER_COVER", TRUE); gGameExternalOptions.fAITacticalRetreat = iniReader.ReadBoolean("Tactical AI Settings", "AI_TACTICAL_RETREAT", FALSE); - gGameExternalOptions.fAIMovementMode = iniReader.ReadBoolean("Tactical AI Settings", "AI_MOVEMENT_MODE", FALSE); + gGameExternalOptions.fAIMovementMode = iniReader.ReadBoolean("Tactical AI Settings", "AI_MOVEMENT_MODE", TRUE); + gGameExternalOptions.fAIPathTweaks = iniReader.ReadBoolean("Tactical AI Settings", "AI_PATH_TWEAKS", TRUE); } diff --git a/GameSettings.h b/GameSettings.h index 712ecbb9..ad71dacf 100644 --- a/GameSettings.h +++ b/GameSettings.h @@ -1543,6 +1543,7 @@ typedef struct BOOLEAN fAIBetterCover; BOOLEAN fAITacticalRetreat; BOOLEAN fAIMovementMode; + BOOLEAN fAIPathTweaks; } GAME_EXTERNAL_OPTIONS; diff --git a/Tactical/PATHAI.cpp b/Tactical/PATHAI.cpp index 82a18d0a..0ebaf385 100644 --- a/Tactical/PATHAI.cpp +++ b/Tactical/PATHAI.cpp @@ -3832,18 +3832,25 @@ if(!GridNoOnVisibleWorldTile(iDestination)) //nextCost = gubDiagCost[nextCost]; nextCost = nextCost * 14 / 10; //nextCost++; - } + } if ( bLoopState == LOOPING_REVERSE) { // penalize moving backwards to encourage turning sooner nextCost += 50; + } + + // sevenfm: tanks prefer moving in straight directions to avoid sliding effect + if (gGameExternalOptions.fAIPathTweaks && + TANK(s) && + (iCnt & 1)) + { + nextCost += 50; } - newTotCost = curCost + nextCost; - // sevenfm: experimental path tweaks for AI - if (s->bTeam != gbPlayerNum && + if (gGameExternalOptions.fAIPathTweaks && + s->bTeam != gbPlayerNum && !(s->flags.uiStatusFlags & SOLDIER_BOXER) && !AreInMeanwhile() && IS_MERC_BODY_TYPE(s)) @@ -3867,25 +3874,8 @@ if(!GridNoOnVisibleWorldTile(iDestination)) } } -/* -// no diagonal bias - straightforward costing regardless of direction newTotCost = curCost + nextCost; - -// NOTE: ON JAN 6TH, 1995, IAN COMMENTED OUT THE DIAGONAL BIAS AND -// UNCOMMENTED THE "NO DIAGONAL BIAS" -//diagonal bias - this makes diagonal moves cost more - - - if (iCnt & 1) - // diagonal move costs 70 percent - //newTotCost += (nextCost/PATHFACTOR); - newTotCost += 1; -// newTotCost = curCost + ((prevCost+nextCost)*7)/10; -// else // non-diagonal costs only 50% -// newTotCost = curCost + (prevCost+nextCost)/2; -*/ - // have we found a path to the current location that // costs less than the best so far to the same location? if (trailCostUsed[newLoc] != gubGlobalPathCount || newTotCost < trailCost[newLoc])