From 6be3de2149b02ebf0ab24677ed2648434248447e Mon Sep 17 00:00:00 2001 From: ChrisL Date: Mon, 9 Mar 2009 23:14:43 +0000 Subject: [PATCH] Fix movement cost problems in 100AP. Externalized the movement cost modifiers and changed the run modifier from a divisor to a flat modifier like other forms of movement use. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2618 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- GameSettings.cpp | 5 ++ Init.h | 5 ++ Tactical/PATHAI.cpp | 108 +++++++++++++++++++---------------------- Tactical/Points.cpp | 40 ++++++--------- TacticalAI/AIUtils.cpp | 8 +-- ja2_2005Express.vcproj | 4 +- 6 files changed, 83 insertions(+), 87 deletions(-) diff --git a/GameSettings.cpp b/GameSettings.cpp index 52cc0103..4148cc1a 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -868,6 +868,11 @@ void LoadGameAPBPConstants() APBPConstants[AP_MOVEMENT_SHORE] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MOVEMENT_SHORE",28),28); APBPConstants[AP_MOVEMENT_LAKE] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MOVEMENT_LAKE",36),36); APBPConstants[AP_MOVEMENT_OCEAN] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MOVEMENT_OCEAN",32),32); + APBPConstants[AP_MODIFIER_RUN] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MODIFIER_RUN",-8),-8); + APBPConstants[AP_MODIFIER_WALK] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MODIFIER_WALK",-4),-4); + APBPConstants[AP_MODIFIER_SWAT] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MODIFIER_SWAT",0),0); + APBPConstants[AP_MODIFIER_CRAWL] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MODIFIER_CRAWL",4),4); + APBPConstants[AP_MODIFIER_PACK] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_MODIFIER_PACK",4),4); APBPConstants[AP_CHANGE_FACING] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_CHANGE_FACING",4),4); APBPConstants[AP_CHANGE_TARGET] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_CHANGE_TARGET",2),2); APBPConstants[AP_TOSS_ITEM] = DynamicAdjustAPConstants(iniReader.ReadInteger("APConstants","AP_TOSS_ITEM",32),32); diff --git a/Init.h b/Init.h index 9130f503..929bf674 100644 --- a/Init.h +++ b/Init.h @@ -32,6 +32,11 @@ AP_MOVEMENT_RUBBLE, AP_MOVEMENT_SHORE, AP_MOVEMENT_LAKE, AP_MOVEMENT_OCEAN, +AP_MODIFIER_RUN, +AP_MODIFIER_WALK, +AP_MODIFIER_SWAT, +AP_MODIFIER_CRAWL, +AP_MODIFIER_PACK, AP_CHANGE_FACING, AP_CHANGE_TARGET, AP_TOSS_ITEM, diff --git a/Tactical/PATHAI.cpp b/Tactical/PATHAI.cpp index e2eeae32..506011b8 100644 --- a/Tactical/PATHAI.cpp +++ b/Tactical/PATHAI.cpp @@ -1326,18 +1326,19 @@ INT16 AStarPathfinder::CalcAP(int const terrainCost, UINT8 const direction) case RUNNING: case ADULTMONSTER_WALKING: // save on casting - movementAPCost = (INT16) (movementAPCost * 100 / ( (UINT8) (RUNDIVISOR * 100))); + //movementAPCost = (INT16) (movementAPCost * 100 / ( (UINT8) (RUNDIVISOR * 100))); + movementAPCost = (INT16) movementAPCost + APBPConstants[AP_MODIFIER_RUN]; //movementAPCost = (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ); break; break; case WALKING: case ROBOT_WALK: - movementAPCost = (movementAPCost + WALKCOST); + movementAPCost = (movementAPCost + APBPConstants[AP_MODIFIER_WALK]); //WALKCOST); break; case SWATTING: - movementAPCost = (movementAPCost + SWATCOST); + movementAPCost = (movementAPCost + APBPConstants[AP_MODIFIER_SWAT]); //SWATCOST); break; case CRAWLING: - movementAPCost = (movementAPCost + CRAWLCOST); + movementAPCost = (movementAPCost + APBPConstants[AP_MODIFIER_CRAWL]); //CRAWLCOST); break; } @@ -3354,29 +3355,31 @@ INT32 FindBestPath(SOLDIERTYPE *s , INT16 sDestination, INT8 ubLevel, INT16 usMo case ADULTMONSTER_WALKING: // save on casting if((UsingNewInventorySystem() == true) && s->inv[BPACKPOCKPOS].exists() == true) - ubAPCost = ubAPCost * 10 / ( (UINT8) (RUNDIVISORBPACK * 10)); + //ubAPCost = ubAPCost * 10 / ( (UINT8) (RUNDIVISORBPACK * 10)); + ubAPCost = ubAPCost + APBPConstants[AP_MODIFIER_RUN] + APBPConstants[AP_MODIFIER_PACK]; else - ubAPCost = (UINT8)(ubAPCost * 10 / ( (UINT8) (RUNDIVISOR * 10))); + //ubAPCost = (UINT8)(ubAPCost * 10 / ( (UINT8) (RUNDIVISOR * 10))); + ubAPCost = (UINT8)ubAPCost + APBPConstants[AP_MODIFIER_RUN]; //ubAPCost = (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ); break; break; case WALKING: case ROBOT_WALK: if((UsingNewInventorySystem() == true) && s->inv[BPACKPOCKPOS].exists() == true) - ubAPCost = (ubAPCost + WALKCOSTBPACK); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_WALK] + APBPConstants[AP_MODIFIER_PACK]); //WALKCOSTBPACK); else - ubAPCost = (ubAPCost + WALKCOST); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_WALK]); //WALKCOST); break; case SWATTING: if((UsingNewInventorySystem() == true) && s->inv[BPACKPOCKPOS].exists() == true) - ubAPCost = (ubAPCost + SWATCOSTBPACK); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_SWAT] + APBPConstants[AP_MODIFIER_PACK]); //SWATCOSTBPACK); else - ubAPCost = (ubAPCost + SWATCOST); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_SWAT]); //SWATCOST); break; case CRAWLING: if((UsingNewInventorySystem() == true) && s->inv[BPACKPOCKPOS].exists() == true) - ubAPCost = (ubAPCost + CRAWLCOSTBPACK); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_CRAWL] + APBPConstants[AP_MODIFIER_PACK]); //CRAWLCOSTBPACK); else - ubAPCost = (ubAPCost + CRAWLCOST); + ubAPCost = (ubAPCost + APBPConstants[AP_MODIFIER_CRAWL]); //CRAWLCOST); break; } @@ -4297,39 +4300,34 @@ INT16 PlotPath( SOLDIERTYPE *pSold, INT16 sDestGridno, INT8 bCopyRoute, INT8 bPl // so, then we must modify it for other movement styles and accumulate // CHRISL: Force display path to calculate AP cost differently if we're wearing a backpack - switch( usMovementModeToUseForAPs ) - { - case RUNNING: - if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPoints += (INT16)(DOUBLE)( (sTileCost / RUNDIVISORBPACK) ) + sExtraCostStand; - else - sPoints += (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ) + sExtraCostStand; - break; - case WALKING : - if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPoints += (sTileCost + WALKCOSTBPACK) + sExtraCostStand; - else - sPoints += (sTileCost + WALKCOST) + sExtraCostStand; - break; - case SWATTING: - if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPoints += (sTileCost + SWATCOSTBPACK) + sExtraCostSwat; - else - sPoints += (sTileCost + SWATCOST) + sExtraCostSwat; - break; - case CRAWLING: - if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPoints += (sTileCost + CRAWLCOSTBPACK) + sExtraCostCrawl; - else - sPoints += (sTileCost + CRAWLCOST) + sExtraCostCrawl; - break; - default : - if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPoints = sPoints + sTileCost; - else - sPoints = sPoints + sTileCost; - break; - } + switch( usMovementModeToUseForAPs ) + { + case RUNNING: + sPoints += sTileCost + sExtraCostStand + APBPConstants[AP_MODIFIER_RUN]; + if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) + sPoints += APBPConstants[AP_MODIFIER_PACK]; + break; + case WALKING : + sPoints += sTileCost + sExtraCostStand + APBPConstants[AP_MODIFIER_WALK]; + if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) + sPoints += APBPConstants[AP_MODIFIER_PACK]; + break; + case SWATTING: + sPoints += sTileCost + sExtraCostStand + APBPConstants[AP_MODIFIER_SWAT]; + if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) + sPoints += APBPConstants[AP_MODIFIER_PACK]; + break; + case CRAWLING: + sPoints += sTileCost + sExtraCostStand + APBPConstants[AP_MODIFIER_CRAWL]; + if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) + sPoints += APBPConstants[AP_MODIFIER_PACK]; + break; + default : + sPoints += sPoints + sTileCost; + if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) + sPoints += APBPConstants[AP_MODIFIER_PACK]; + break; + } } } @@ -4341,28 +4339,24 @@ INT16 PlotPath( SOLDIERTYPE *pSold, INT16 sDestGridno, INT8 bCopyRoute, INT8 bPl // CHRISL: Adjusted system to use different move costs while wearing a backpack // store WALK cost + sPointsWalk += sTileCost + APBPConstants[AP_MODIFIER_WALK] + sExtraCostStand; if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPointsWalk += (sTileCost + WALKCOSTBPACK) + sExtraCostStand; - else - sPointsWalk += (sTileCost + WALKCOST) + sExtraCostStand; + sPointsWalk += APBPConstants[AP_MODIFIER_PACK]; // now get cost as if CRAWLING + sPointsCrawl += sTileCost + APBPConstants[AP_MODIFIER_CRAWL] + sExtraCostCrawl; if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPointsCrawl += (sTileCost + CRAWLCOSTBPACK) + sExtraCostCrawl; - else - sPointsCrawl += (sTileCost + CRAWLCOST) + sExtraCostCrawl; + sPointsCrawl += APBPConstants[AP_MODIFIER_PACK]; // now get cost as if SWATTING + sPointsSwat += sTileCost + APBPConstants[AP_MODIFIER_SWAT] + sExtraCostSwat; if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPointsSwat += (sTileCost + SWATCOSTBPACK) + sExtraCostSwat; - else - sPointsSwat += (sTileCost + SWATCOST) + sExtraCostSwat; + sPointsSwat += APBPConstants[AP_MODIFIER_PACK]; // now get cost as if RUNNING + sPointsRun += sTileCost + APBPConstants[AP_MODIFIER_RUN] + sExtraCostStand; if((UsingNewInventorySystem() == true) && pSold->inv[BPACKPOCKPOS].exists() == true) - sPointsRun += (INT16)(DOUBLE)( (sTileCost / RUNDIVISORBPACK) ) + sExtraCostStand; - else - sPointsRun += (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ) + sExtraCostStand; + sPointsRun += APBPConstants[AP_MODIFIER_PACK]; } if ( iCnt == 0 && bPlot ) diff --git a/Tactical/Points.cpp b/Tactical/Points.cpp index 63ca4d25..053ebe1d 100644 --- a/Tactical/Points.cpp +++ b/Tactical/Points.cpp @@ -336,10 +336,9 @@ INT16 ActionPointCost( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT8 bDir, UINT16 u case ADULTMONSTER_WALKING: case BLOODCAT_RUN: // CHRISL + sPoints = sTileCost + APBPConstants[AP_MODIFIER_RUN]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (INT16)(DOUBLE)( (sTileCost / RUNDIVISORBPACK) ); - else - sPoints = (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case CROW_FLY: @@ -351,26 +350,23 @@ INT16 ActionPointCost( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT8 bDir, UINT16 u case LARVAE_WALK: case WALKING : // CHRISL + sPoints = sTileCost + APBPConstants[AP_MODIFIER_WALK]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + WALKCOSTBPACK); - else - sPoints = (sTileCost + WALKCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case START_SWAT: case SWAT_BACKWARDS: // CHRISL case SWATTING: + sPoints = sTileCost + APBPConstants[AP_MODIFIER_SWAT]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + SWATCOSTBPACK); - else - sPoints = (sTileCost + SWATCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case CRAWLING: + sPoints = sTileCost + APBPConstants[AP_MODIFIER_CRAWL]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + CRAWLCOSTBPACK); - else - sPoints = (sTileCost + CRAWLCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; default: @@ -426,10 +422,9 @@ INT16 EstimateActionPointCost( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT8 bDir, case ADULTMONSTER_WALKING: case BLOODCAT_RUN: // CHRISL + sPoints = sTileCost + APBPConstants[AP_MODIFIER_RUN]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (INT16)(DOUBLE)( (sTileCost / RUNDIVISORBPACK) ); - else - sPoints = (INT16)(DOUBLE)( (sTileCost / RUNDIVISOR) ); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case CROW_FLY: @@ -441,26 +436,23 @@ INT16 EstimateActionPointCost( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT8 bDir, case LARVAE_WALK: // CHRISL case WALKING : + sPoints = sTileCost + APBPConstants[AP_MODIFIER_WALK]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + WALKCOSTBPACK); - else - sPoints = (sTileCost + WALKCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case START_SWAT: case SWAT_BACKWARDS: // CHRISL case SWATTING: + sPoints = sTileCost + APBPConstants[AP_MODIFIER_SWAT]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + SWATCOSTBPACK); - else - sPoints = (sTileCost + SWATCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; case CRAWLING: + sPoints = sTileCost + APBPConstants[AP_MODIFIER_CRAWL]; if((UsingNewInventorySystem() == true) && pSoldier->inv[BPACKPOCKPOS].exists() == true) - sPoints = (sTileCost + CRAWLCOSTBPACK); - else - sPoints = (sTileCost + CRAWLCOST); + sPoints += APBPConstants[AP_MODIFIER_PACK]; break; default: diff --git a/TacticalAI/AIUtils.cpp b/TacticalAI/AIUtils.cpp index 922e39a2..889c9d4d 100644 --- a/TacticalAI/AIUtils.cpp +++ b/TacticalAI/AIUtils.cpp @@ -1459,13 +1459,13 @@ INT16 EstimatePathCostToLocation( SOLDIERTYPE * pSoldier, INT16 sDestGridNo, INT // add in cost of later climbing up, too sPathCost += APBPConstants[AP_CLIMBOFFROOF] + APBPConstants[AP_CLIMBROOF]; // add in an estimate of getting there after climbing down - sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + WALKCOST) * PythSpacesAway( sClimbGridNo, sDestGridNo ); + sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + APBPConstants[AP_MODIFIER_WALK]) * PythSpacesAway( sClimbGridNo, sDestGridNo ); } else { sPathCost += APBPConstants[AP_CLIMBOFFROOF]; // add in an estimate of getting there after climbing down, *but not on top of roof* - sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + WALKCOST) * PythSpacesAway( sClimbGridNo, sDestGridNo ) / 2; + sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + APBPConstants[AP_MODIFIER_WALK]) * PythSpacesAway( sClimbGridNo, sDestGridNo ) / 2; } *pfClimbingNecessary = TRUE; *psClimbGridNo = sClimbGridNo; @@ -1505,7 +1505,7 @@ INT16 EstimatePathCostToLocation( SOLDIERTYPE * pSoldier, INT16 sDestGridNo, INT { // add to path a rough estimate of how far to go from the climb gridno to the friend // estimate walk cost - sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + WALKCOST) * PythSpacesAway( sClimbGridNo, sDestGridNo ); + sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + APBPConstants[AP_MODIFIER_WALK]) * PythSpacesAway( sClimbGridNo, sDestGridNo ); } } else @@ -1514,7 +1514,7 @@ INT16 EstimatePathCostToLocation( SOLDIERTYPE * pSoldier, INT16 sDestGridNo, INT sPathCost += APBPConstants[AP_CLIMBOFFROOF]; // add to path a rough estimate of how far to go from the climb gridno to the friend // estimate walk cost - sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + WALKCOST) * PythSpacesAway( sClimbGridNo, sDestGridNo ); + sPathCost += (APBPConstants[AP_MOVEMENT_FLAT] + APBPConstants[AP_MODIFIER_WALK]) * PythSpacesAway( sClimbGridNo, sDestGridNo ); } *pfClimbingNecessary = TRUE; *psClimbGridNo = sClimbGridNo; diff --git a/ja2_2005Express.vcproj b/ja2_2005Express.vcproj index 4902aa9d..d444f1e2 100644 --- a/ja2_2005Express.vcproj +++ b/ja2_2005Express.vcproj @@ -1,7 +1,7 @@