Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): five AI roles, and every rung's knob wired to something

Olcay Seyganfcaa5b1d1144
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index 2371f17c8..8ab11324f 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -56,6 +56,7 @@
#include "Common/MissionStats.h"
#include "Common/Money.h"
#include "Common/Science.h"
+#include "GameLogic/AI.h" // AISkillLevel and AIRole, asked of a player from outside the AI
#include "Common/UnicodeString.h"
#include "Common/NameKeyGenerator.h"
#include "Common/Thing.h"
@@ -745,6 +746,11 @@ public:
/** return true attemptToPurchaseScience() would succeed for this science. */
Bool isCapableOfPurchasingScience(ScienceType science) const;
+ /** What kind of AI is behind this player, for the handful of places outside GameLogic/AI/ that
+ * have to ask. Both answer their neutral value for a human seat. */
+ AISkillLevel getAISkillLevel(void) const;
+ AIRole getAIRole(void) const;
+
protected:
// snapshot methods
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 4acd6bd52..adb693c21 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -159,12 +159,19 @@ enum AISkillLevel
//-------------------------------------------------------------------------------------------------
enum AIRole
{
- AIROLE_AGGRESSIVE = 0,
- AIROLE_DEFENSIVE,
+ AIROLE_AGGRESSIVE = 0, ///< cheap early units, few defences, commits with less
+ AIROLE_DEFENSIVE, ///< base defences first, waits for more, counter-attacks
+ AIROLE_SUPPORTIVE, ///< converges on an ally's target, answers calls for help, shares the map
+ AIROLE_ECONOMIST, ///< expands early and often, fights only with an advantage
+ AIROLE_STEAMROLLER, ///< heavy units, one large well-timed push
AIROLE_COUNT
};
+/** How much of the enemy army a role wants in hand before it commits. The role's knob, not the
+ * rung's: both spend the same money, they spend it at different moments. */
+Real aiRoleMassFraction( AIRole role );
+
//-------------------------------------------------------------------------------------------------
/** One rung of the ladder. Every new AI behaviour adds a field here rather than a
* switch(difficulty) somewhere, so the whole ladder can be read, tuned and measured in one place.
@@ -267,7 +274,7 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractio
* ill-defended planet 25 map units away". Two independently written RTS AIs converging on the
* same mistake is decent evidence that distance-dominated target selection is the wrong default. */
Real aiEnemyCost( Real distSqr, Bool crippled, Bool alreadyTargetedByAnotherAI,
- Bool isAttackingMe, Real economyShare );
+ Bool isAttackingMe, Real economyShare, Bool joinAllysTarget = FALSE );
/** Shorten a build delay when the money is piling up. The classic AI disease is sitting on twenty
* thousand cash while trickling one unit out at a time; the delays already move with wealth
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
index dbd815465..f48d0d5dd 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h
@@ -259,10 +259,10 @@ protected:
Bool shouldHoldForMassing( TeamInQueue *team );
virtual void doScouting(void);
- Object *findScout(void); ///< a spare unit of ours that can do the touring
+ Object *findScout(void); ///< a spare unit of ours that can do the touring, not already scouting
void queueScout(void); ///< ... or build the cheapest one that can
Bool scoutInQueue(void); ///< one is already on order
- Bool nextScoutTarget(Coord3D *pos); ///< the next enemy start position to go and look at
+ Bool nextScoutTarget(Int slot, Coord3D *pos); ///< the next enemy start position for this scout
virtual void doBaseBuilding(void);
virtual void checkReadyTeams(void);
@@ -337,9 +337,10 @@ protected:
AISkillLevel m_skillLevel; ///< rung of the ladder: how well this AI plays
AIRole m_role; ///< what it is trying to do; rolled once, kept for the match
- ObjectID m_scoutID; ///< the unit currently touring the map for us
+ enum { MAX_AI_SCOUTS = 2 }; ///< the ladder's maxScouts never asks for more than this
+ ObjectID m_scoutID[ MAX_AI_SCOUTS ]; ///< the units currently touring the map for us
+ Int m_scoutTargetFor[ MAX_AI_SCOUTS ]; ///< which start position each one is walking to
Int m_scoutTimer; ///< frames until the next scouting check
- Int m_scoutTarget; ///< which player's start position the scout is walking to
Int m_retreatTimer; ///< frames until the next look at how the fights are going
Int m_expandTimer; ///< frames until the next look for somewhere to expand to
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 7c2ee52fc..fdb20b40b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -2654,6 +2654,16 @@ Bool Player::grantScience(ScienceType science)
}
//=============================================================================
+AISkillLevel Player::getAISkillLevel(void) const
+{
+ return m_ai ? m_ai->getAISkillLevel() : AISKILL_MERCILESS;
+}
+
+AIRole Player::getAIRole(void) const
+{
+ return m_ai ? m_ai->getAIRole() : AIROLE_AGGRESSIVE;
+}
+
Bool Player::isCapableOfPurchasingScience(ScienceType science) const
{
if (science == SCIENCE_INVALID)
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
index 0f2a303b8..b5a5885aa 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Team.cpp
@@ -43,6 +43,7 @@
#include "GameLogic/SidesList.h"
#include "GameLogic/Object.h"
+#include "GameLogic/AI.h" // the rung decides whether a team fires together
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/ContainModule.h"
#include "GameLogic/PolygonTrigger.h"
@@ -1507,8 +1508,14 @@ void Team::setTeamTargetObject(const Object *target)
}
// Only ai players do common attack.
if (getControllingPlayer()->getPlayerType() == PLAYER_COMPUTER) {
- if (getControllingPlayer()->getPlayerDifficulty() == DIFFICULTY_EASY) {
- return; // we don't do this for easy. jba.
+ //
+ // Whether a team fires together is a rung of the ladder now, not one of the three script
+ // tiers: the ladder has six steps and this is one of the capabilities that separates them
+ // (AI-ROADMAP.md D6). The bottom two rungs still do not do it, which is what the old
+ // DIFFICULTY_EASY test said.
+ //
+ if (!TheAI->getDifficultyProfile(getControllingPlayer()->getAISkillLevel())->m_focusFire) {
+ return;
}
m_commonAttackTarget = target->getID();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
index c708c36d8..bfcc1e72c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
@@ -1076,9 +1076,23 @@ Bool aiShouldMass( Real waitingThreat, Real enemyVisibleThreat, Real massFractio
return waitingThreat < massFraction * enemyVisibleThreat;
}
+//-------------------------------------------------------------------------------------------------
+Real aiRoleMassFraction( AIRole role )
+{
+ switch( role )
+ {
+ case AIROLE_AGGRESSIVE: return 0.8f; // presses, with less
+ case AIROLE_DEFENSIVE: return 1.3f; // would rather absorb a hit and counter-attack
+ case AIROLE_SUPPORTIVE: return 1.0f; // goes when the ally goes
+ case AIROLE_ECONOMIST: return 1.5f; // fights only with a clear advantage
+ case AIROLE_STEAMROLLER: return 1.8f; // one push, and it had better land
+ default: return 1.0f;
+ }
+}
+
//-------------------------------------------------------------------------------------------------
Real aiEnemyCost( Real distSqr, Bool crippled, Bool alreadyTargetedByAnotherAI,
- Bool isAttackingMe, Real economyShare )
+ Bool isAttackingMe, Real economyShare, Bool joinAllysTarget )
{
Real cost = distSqr;
@@ -1092,9 +1106,14 @@ Real aiEnemyCost( Real distSqr, Bool crippled, Bool alreadyTargetedByAnotherAI,
if( economyShare > 1.0f ) economyShare = 1.0f;
cost *= (1.0f - 0.3f * economyShare);
+ //
// EA's two flat terms, kept: do not gang up, and gently prefer whoever is already on me.
+ //
+ // The first one is exactly backwards for a supportive AI - converging on the ally's chosen
+ // enemy is the entire point of allied play - so that role flips its sign rather than paying it.
+ //
if( alreadyTargetedByAnotherAI )
- cost += 500.0f * 500.0f;
+ cost += joinAllysTarget ? -(250.0f * 250.0f) : (500.0f * 500.0f);
if( isAttackingMe )
cost -= 25.0f * 25.0f;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 4d7106ee5..7768a7173 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -1,4 +1,4 @@
-/*
+/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
@@ -168,14 +168,18 @@ m_supplySourceAttackCheckFrame(0),
m_attackedSupplyCenter(INVALID_ID),
m_teamSeconds(10),
m_curWarehouseID(INVALID_ID),
-m_scoutID(INVALID_ID),
m_scoutTimer(1),
-m_scoutTarget(0),
m_retreatTimer(1),
m_expandTimer(1),
m_skillLevel(AISKILL_MERCILESS),
m_role(AIROLE_AGGRESSIVE)
{
+ for (Int scoutSlot = 0; scoutSlot < MAX_AI_SCOUTS; ++scoutSlot) {
+ m_scoutID[scoutSlot] = INVALID_ID;
+ // a different start position each, so two scouts do not walk the same lap together
+ m_scoutTargetFor[scoutSlot] = scoutSlot;
+ }
+
m_frameLastBuildingBuilt = TheGameLogic->getFrame();
p->setCanBuildUnits(false); // turn off ai production by default.
@@ -2566,11 +2570,18 @@ Object *AIPlayer::findSupplyCenter(Int minimumCash)
Real radius = SUPPLY_CENTER_CLOSE_DIST + obj->getGeometryInfo().getBoundingCircleRadius();
PartitionFilterAcceptByKindOf f1(MAKE_KINDOF_MASK(KINDOF_CASH_GENERATOR), KINDOFMASK_NONE);
+ //
+ // "Do I already have a centre here" - and, for a supportive AI, "does my ally". Two
+ // allied AIs racing each other to the same warehouse is one of the most visibly
+ // stupid things AI teammates do, and this filter is the whole of the fix.
+ //
PartitionFilterPlayer f2(m_player, true); // Only find your own units.
+ PartitionFilterPlayerAffiliation f2Ally(m_player, ALLOW_SAME_PLAYER | ALLOW_ALLIES, true);
PartitionFilterOnMap filterMapStatus;
-
- PartitionFilter *filters[] = { &f1, &f2, &filterMapStatus, 0 };
+ PartitionFilter *mine[] = { &f1, &f2, &filterMapStatus, 0 };
+ PartitionFilter *ours[] = { &f1, &f2Ally, &filterMapStatus, 0 };
+ PartitionFilter **filters = (m_role == AIROLE_SUPPORTIVE) ? ours : mine;
Object *supplyCenter = ThePartitionManager->getClosestObject(&center, radius, FROM_BOUNDINGSPHERE_2D, filters);
if (supplyCenter) {
@@ -3998,6 +4009,14 @@ Object *AIPlayer::findScout( void )
continue;
if( obj->getAI() == NULL )
continue;
+
+ Bool alreadyScouting = FALSE;
+ for( Int slot = 0; slot < MAX_AI_SCOUTS; ++slot )
+ if( m_scoutID[ slot ] == obj->getID() )
+ alreadyScouting = TRUE;
+ if( alreadyScouting )
+ continue;
+
return obj;
}
return NULL;
@@ -4075,19 +4094,22 @@ void AIPlayer::queueScout( void )
* what is on them is what has to be found out. The list is walked round and round, so the same one
* unit that opens the map keeps it up to date for the rest of the match.
*/
-Bool AIPlayer::nextScoutTarget( Coord3D *pos )
+Bool AIPlayer::nextScoutTarget( Int slot, Coord3D *pos )
{
+ if( slot < 0 || slot >= MAX_AI_SCOUTS )
+ return FALSE;
+
const Int count = ThePlayerList->getPlayerCount();
for( Int tries = 0; tries < count; ++tries )
{
- m_scoutTarget = (m_scoutTarget + 1) % count;
+ m_scoutTargetFor[ slot ] = (m_scoutTargetFor[ slot ] + 1) % count;
- Player *p = ThePlayerList->getNthPlayer( m_scoutTarget );
+ Player *p = ThePlayerList->getNthPlayer( m_scoutTargetFor[ slot ] );
if( p == NULL || p == m_player )
continue;
if( m_player->getRelationship( p->getDefaultTeam() ) != ENEMIES )
continue;
- if( playerStartPosition( m_scoutTarget, pos ) )
+ if( playerStartPosition( m_scoutTargetFor[ slot ], pos ) )
return TRUE;
}
return FALSE;
@@ -4106,45 +4128,63 @@ void AIPlayer::doScouting( void )
return;
m_scoutTimer = SCOUT_CHECK_RATE;
- Object *scout = TheGameLogic->findObjectByID( m_scoutID );
- if( scout && (scout->isEffectivelyDead() || scout->getControllingPlayer() != m_player) )
- scout = NULL;
+ const AIDifficultyProfile *profile = getSkillProfile();
+ Int wanted = profile->m_maxScouts;
+ if( wanted < 1 ) wanted = 1;
+ if( wanted > MAX_AI_SCOUTS ) wanted = MAX_AI_SCOUTS;
+
+ Bool ordered = FALSE;
+ Bool short_ = FALSE;
- if( scout == NULL )
+ for( Int slot = 0; slot < wanted; ++slot )
{
- m_scoutID = INVALID_ID;
- scout = findScout();
- if( scout )
+ Object *scout = TheGameLogic->findObjectByID( m_scoutID[ slot ] );
+ if( scout && (scout->isEffectivelyDead() || scout->getControllingPlayer() != m_player) )
+ scout = NULL;
+
+ if( scout == NULL )
{
- m_scoutID = scout->getID();
- // once per scout, so the log says whether this is working at all without saying it twice
- DEBUG_LOG(("AI player %d scouting with a '%s'\n", m_player->getPlayerIndex(),
- scout->getTemplate()->getName().str()));
+ m_scoutID[ slot ] = INVALID_ID;
+ scout = findScout();
+ if( scout )
+ {
+ m_scoutID[ slot ] = scout->getID();
+ // once per scout, so the log says whether this works at all without saying it twice
+ DEBUG_LOG(("AI player %d scouting with a '%s'\n", m_player->getPlayerIndex(),
+ scout->getTemplate()->getName().str()));
+ }
}
- }
- if( scout == NULL )
- {
- queueScout();
- return;
+ if( scout == NULL )
+ {
+ short_ = TRUE;
+ continue;
+ }
+
+ AIUpdateInterface *ai = scout->getAI();
+ if( ai == NULL || !ai->isIdle() )
+ continue; // still on its way
+
+ Coord3D goal;
+ if( nextScoutTarget( slot, &goal ) )
+ {
+ ai->aiMoveToPosition( &goal, CMD_FROM_AI );
+ ordered = TRUE;
+ }
}
- AIUpdateInterface *ai = scout->getAI();
- if( ai == NULL || !ai->isIdle() )
- return; // still on its way
+ // one short of what this rung wants: put one on order, out of spare change
+ if( short_ )
+ queueScout();
- Coord3D goal;
- if( nextScoutTarget( &goal ) )
+ //
+ // A scout that has just been sent somewhere is left alone for this rung's scouting interval.
+ // This is the ladder's honest perception knob: every rung scouts, they differ in how diligently.
+ // Ninety seconds between legs on Easy is a scout that wanders; twenty-five on Merciless is one
+ // that keeps the map current.
+ //
+ if( ordered )
{
- ai->aiMoveToPosition( &goal, CMD_FROM_AI );
-
- //
- // ... and then leave it alone for this rung's scouting interval before the next leg. This
- // is the ladder's honest perception knob: every rung scouts, they differ in how diligently.
- // Ninety seconds between legs on Easy is a scout that wanders; twenty-five on Merciless is
- // one that keeps the map current.
- //
- const AIDifficultyProfile *profile = getSkillProfile();
Int interval = REAL_TO_INT_CEIL( profile->m_scoutIntervalSeconds * LOGICFRAMES_PER_SECOND );
if( interval > m_scoutTimer )
m_scoutTimer = interval;
@@ -4486,9 +4526,12 @@ void AIPlayer::xfer( Xfer *xfer )
// the scout, so a loaded game does not go blind or start a second one
if( version >= 2 )
{
- xfer->xferObjectID( &m_scoutID );
xfer->xferInt( &m_scoutTimer );
- xfer->xferInt( &m_scoutTarget );
+ for( Int scoutSlot = 0; scoutSlot < MAX_AI_SCOUTS; ++scoutSlot )
+ {
+ xfer->xferObjectID( &m_scoutID[ scoutSlot ] );
+ xfer->xferInt( &m_scoutTargetFor[ scoutSlot ] );
+ }
}
if( version >= 3 )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
index 2a63224fb..6c6610803 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp
@@ -567,7 +567,8 @@ void AISkirmishPlayer::acquireEnemy(void)
}
const Real share = (estateTotal > 0.0f && i < MAX_PLAYER_COUNT) ? (estate[i] / estateTotal) : 0.0f;
- curDistSqr = aiEnemyCost( curDistSqr, inBadShape, alreadyTargeted, attackingMe, share );
+ curDistSqr = aiEnemyCost( curDistSqr, inBadShape, alreadyTargeted, attackingMe, share,
+ getAIRole() == AIROLE_SUPPORTIVE );
// Ai enemy - will take if we don't get a better offer.
if (curDistSqr<bestDistanceSqr) {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
index a4399a056..53dc89c50 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Body/ActiveBody.cpp
@@ -709,7 +709,20 @@ void ActiveBody::attemptDamage( DamageInfo *damageInfo )
//Also only retaliate if we're controlled by a human player and the thing that attacked me
//is an enemy.
Player *controllingPlayer = obj->getControllingPlayer();
- if( controllingPlayer && controllingPlayer->isLogicalRetaliationModeEnabled() && controllingPlayer->getPlayerType() == PLAYER_HUMAN )
+ //
+ // "Friends come to your aid" already sweeps a radius and pulls in an *allied player's* units,
+ // not only your own - and EA switched the whole mechanism off for computer players with a
+ // player-type test, twice (here, and again in shouldRetaliateAgainstAggressor). That is the
+ // same shape as the fog exemption in A1.
+ //
+ // It is unlocked for the supportive role and no other: turning up when your partner is hit is
+ // the whole of what that role is for, and switching it on for every AI would be a flat combat
+ // buff rather than a difference in what an opponent is trying to do (D8, D10).
+ //
+ const Bool retaliates = obj->getControllingPlayer() &&
+ (obj->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN ||
+ obj->getControllingPlayer()->getAIRole() == AIROLE_SUPPORTIVE);
+ if( controllingPlayer && controllingPlayer->isLogicalRetaliationModeEnabled() && retaliates )
{
if( shouldRetaliateAgainstAggressor(obj, damager))
{
@@ -765,8 +778,9 @@ Bool ActiveBody::shouldRetaliateAgainstAggressor(Object *obj, Object *damager)
if (distSqr > sqr(TheAI->getAiData()->m_maxRetaliateDistance)) {
return false;
}
- // Only human players retaliate. [8/25/2003]
- if (obj->getControllingPlayer()->getPlayerType() != PLAYER_HUMAN) {
+ // Only human players retaliate. [8/25/2003] ... and supportive AIs; see doDamage above.
+ if (obj->getControllingPlayer()->getPlayerType() != PLAYER_HUMAN &&
+ obj->getControllingPlayer()->getAIRole() != AIROLE_SUPPORTIVE) {
return false;
}
// Drones never retaliate. [8/25/2003]
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index df6791eaa..c4d33e96b 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -6048,3 +6048,40 @@ TEST(a_cash_hoard_shortens_the_wait_but_only_so_far)
CHECK( data.m_skill[ AISKILL_MERCILESS ].m_cashHoardThreshold <
data.m_skill[ AISKILL_MEDIUM ].m_cashHoardThreshold );
}
+
+
+/** D8: role is the second axis - difficulty says how well the AI plays, role says what it is
+ trying to do. The property that has to hold is that a role is a *preference*, not a bonus: they
+ all spend the same money, they spend it at different moments and on different things. If one
+ role were simply stronger the axis would have quietly become a second difficulty setting. */
+TEST(every_role_commits_at_its_own_moment_and_none_of_them_is_a_bonus)
+{
+ // every role has a threshold, and every threshold is a real fraction of an enemy army
+ for( Int r = 0; r < AIROLE_COUNT; ++r )
+ {
+ CHECK( aiRoleMassFraction( (AIRole)r ) > 0.0f );
+ CHECK( aiRoleMassFraction( (AIRole)r ) < 5.0f );
+ }
+
+ // the spread is the whole point: the aggressive one goes in with the least in hand and the
+ // steamroller with the most
+ CHECK( aiRoleMassFraction( AIROLE_AGGRESSIVE ) < aiRoleMassFraction( AIROLE_DEFENSIVE ) );
+ CHECK( aiRoleMassFraction( AIROLE_DEFENSIVE ) < aiRoleMassFraction( AIROLE_ECONOMIST ) );
+ CHECK( aiRoleMassFraction( AIROLE_ECONOMIST ) < aiRoleMassFraction( AIROLE_STEAMROLLER ) );
+
+ // at parity with the enemy, the aggressive one has already gone and the steamroller has not
+ CHECK( !aiShouldMass( 1000.0f, 1000.0f, aiRoleMassFraction( AIROLE_AGGRESSIVE ), FALSE, FALSE ) );
+ CHECK( aiShouldMass( 1000.0f, 1000.0f, aiRoleMassFraction( AIROLE_STEAMROLLER ), FALSE, FALSE ) );
+
+ // the supportive role converges on an ally's target instead of paying EA's gang-up penalty -
+ // which is the single sign flip that makes allied play work
+ const Real dist = 200.0f * 200.0f;
+ CHECK( aiEnemyCost( dist, FALSE, TRUE, FALSE, 0.0f, FALSE ) >
+ aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.0f, FALSE ) );
+ CHECK( aiEnemyCost( dist, FALSE, TRUE, FALSE, 0.0f, TRUE ) <
+ aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.0f, TRUE ) );
+
+ // and it only flips the term it is about: an untargeted enemy is scored the same either way
+ CHECK_NEAR( aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.5f, FALSE ),
+ aiEnemyCost( dist, FALSE, FALSE, FALSE, 0.5f, TRUE ), 0.001f );
+}