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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(ai): easy and normal attack on random maps; normal retreats
Olcay Seygan3fc53b93eeb3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 585c49770..231706811 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -105,7 +105,7 @@ found and fixed — EA's own, not port damage.**- It weighs a fight by what is in it, not by who is nearby: only things that can shoot count, and buildings do not. Its own base is not a reason to feel safe and yours is not a reason to run.- Its aircraft are left out of it. A retreat order was what took a parked jet off the runway, so while a fight raged near the airfield the whole wing took off, flew at the base, landed, and did it again every few seconds instead of ever reaching you. Aircraft already fly home on their own when the load is spent.- Matches finish. Two of these opponents used to fail to settle 65% of their games inside sixteen minutes; it is half that now, and they end in under seven minutes on average instead of ten.-- On Hard the retreat actually happens now. The order home was handed to units that were already fighting, and the game laid it over their attack instead of replacing it, so a team told to break off carried on driving at what it was shooting, and its aggressive mood turned any walk that did start into a fight on the way. Medium still retreats the old way.+- The retreat actually happens now, on Normal as well as Hard. The order home was handed to units that were already fighting, and the game laid it over their attack instead of replacing it, so a team told to break off carried on driving at what it was shooting, and its aggressive mood turned any walk that did start into a fight on the way. A unit that makes it home gets its mood back when it stops walking.## Hard fights each unit from where it is strongest@@ -1419,6 +1419,13 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the sameinstall and nothing to download, and the map shows up in the list with a picture like any other.The bigger the game, the bigger the map: every player who joins brings ground with them, so aneight-way fight is not eight bases crammed onto a duel map.+- Easy and Normal computer opponents attack on them. They only ever set off from inside the base+ area a map marks round each start, and only down the roads it marks out between the bases. A+ random map marked neither, so they built their armies and kept them at home all match: 128 games+ of Normal against Normal lost 159 units between them. Every base now has its areas, and three+ marked roads to every other base, a middle road along the ground a tank would drive and two that+ swing out wide to either side. Random maps made by an older version are different maps from the+ same number.- No two of them are the same shape. Nothing is mirrored, rotated or laid out on a ring. The wholemap is one field of noise, and the bases are found in it: the flattest ground first, thenwhichever good ground is furthest from everything already taken. Some seeds give you four cornersdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h b/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.hindex 9196463c5..ef173757b 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/RandomMapGenerator.h@@ -34,7 +34,7 @@rather than desyncing partway through it. The fingerprint test intest_gameengine.cpp fails until the version and the recorded CRCs agree, sothe bump cannot be forgotten. */-#define RANDOM_MAP_GENERATOR_VERSION 10+#define RANDOM_MAP_GENERATOR_VERSION 11/// How much ground the map gives everybody, before the per-player share.enum RandomMapSizediff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 1ea51c6b3..52810bcda 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -185,8 +185,8 @@ struct AIDifficultyProfile// Perception. Never fog: only how diligently it looks and how fast it acts on what it saw.Real m_scoutIntervalSeconds; ///< how often the scout is re-tasked; every rung scoutsInt m_maxScouts;- Real m_reactionDelaySeconds; ///< lag between "something happened" and answering it- Real m_decisionIntervalSeconds; ///< how often it re-evaluates - the AI's APM+ Real m_decisionIntervalSeconds; ///< how often it re-evaluates - the AI's APM, and so how late it answers+ ///< what it saw: a separate reaction delay stood here, read by nothing// Decision qualityReal m_counterCompositionWeight; ///< 0 = ignore what the enemy fields (EA's behaviour)diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex cfa779d2f..6e4d03bdb 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -509,6 +509,7 @@ protected:/** Hard's fighting units, one at a time: step back from what they outrange, climb onto ground* that lengthens their guns, and take a hurt unit out of ground it cannot win on. */virtual void doTactics(void);+ Bool measuringWithoutTactics(void) const; ///< -notactics has this slot fight the old wayvoid tacticsFor(Object *obj);struct TacticalStep{diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cppindex 7d1d9e33d..0b856499f 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RandomMapGenerator.cpp@@ -483,6 +483,7 @@ struct RMGObjectReal m_angle;Int m_waypointID; ///< 0 for anything that is not a waypointInt m_flags; ///< MapObject's own flags; the road ones are the only ones used here+ AsciiString m_pathLabel; ///< a waypoint on a skirmish approach path: "Center3", "Flank1" ...};/** A road is two objects in a row carrying MapObject's road flags, which W3DRoadBuffer pairs up as@@ -639,6 +640,7 @@ public:std::vector<char> m_passable;std::vector<RMGLake> m_lakes;std::vector<RMGObject> m_objects;+ std::vector< std::pair<Int, Int> > m_waypointLinks; ///< waypointID to waypointID, for WaypointsList/// The blend table the BlendTileData chunk carries; entry 0 is the "no blend" default.struct RMGBlend@@ -683,6 +685,9 @@ private:void buildTerrainClasses( const UnsignedByte perm[512] );void buildBlends( void );void buildObjects( const UnsignedByte perm[512] );+ void addApproachPaths( Int *waypointID );+ void addApproachWaypoint( const char *lane, Int targetStart, Int fromStart, Int step, Real cellX, Real cellY,+ Int *waypointID, Int *previous );void placeSupplyAndDerricks( void );void placeTowns( void );void placeBunkers( void );@@ -4009,6 +4014,136 @@ void RMGLayout::placeScenery( const UnsignedByte perm[512] )}}+/** One waypoint every this many cells along an approach path. */+static const Int RMG_APPROACH_SPACING_CELLS = 12;+/** How far a flank or back-door path bows out from the straight line, as a share of its length. */+static const Real RMG_APPROACH_BULGE = 0.3f;+/** How far a bowed point may be moved to find ground a unit can reach. */+static const Int RMG_APPROACH_SNAP_CELLS = 10;++void RMGLayout::addApproachWaypoint( const char *lane, Int targetStart, Int fromStart, Int step, Real cellX, Real cellY,+ Int *waypointID, Int *previous )+{+ RMGObject waypoint;+ waypoint.m_templateName = "*Waypoints/Waypoint";+ waypoint.m_uniqueID.format( "%s%d_from%d_%d", lane, targetStart + 1, fromStart + 1, step );+ waypoint.m_pathLabel.format( "%s%d", lane, targetStart + 1 );+ waypoint.m_worldX = cellX * MAP_XY_FACTOR;+ waypoint.m_worldY = cellY * MAP_XY_FACTOR;+ waypoint.m_angle = 0.0f;+ waypoint.m_waypointID = (*waypointID)++;+ waypoint.m_flags = 0;+ m_objects.push_back( waypoint );+ if( *previous > 0 )+ m_waypointLinks.push_back( std::make_pair( *previous, waypoint.m_waypointID ) );+ *previous = waypoint.m_waypointID;+}++/** The skirmish scripts send a wave down "Center", "Flank" or "Backdoor" followed by the target's start+ number, starting from the waypoint of that path nearest the wave. A generated map carried none of+ them, nor the base areas the launch waits on (writePolygonTriggers), so Easy and Medium, whose+ attacks are nothing but those paths, built their waves and never sent one: 128 Medium-against-Medium+ matches lost 159 units between them. Every start gets all three+ paths from every other start. The centre one walks the ground route the flood fill finds; the other+ two bow out to either side of the straight line, each point moved onto the nearest ground a unit+ can reach from the target. */+void RMGLayout::addApproachPaths( Int *waypointID )+{+ m_waypointLinks.clear();+ static const char *LANES[3] = { "Center", "Flank", "Backdoor" };+ static const Real BULGE[3] = { 0.0f, RMG_APPROACH_BULGE, -RMG_APPROACH_BULGE };+ static const Int STEP_X[4] = { 1, -1, 0, 0 };+ static const Int STEP_Y[4] = { 0, 0, 1, -1 };++ std::vector<Int> dist;+ for( UnsignedInt target = 0; target < m_starts.size(); target++ )+ {+ const Int targetX = (Int)m_starts[target].m_cellX;+ const Int targetY = (Int)m_starts[target].m_cellY;+ floodDistancesFromCell( targetX, targetY, dist );++ for( UnsignedInt from = 0; from < m_starts.size(); from++ )+ {+ if( from == target )+ continue;+ const Real fromX = m_starts[from].m_cellX;+ const Real fromY = m_starts[from].m_cellY;+ const Real dx = m_starts[target].m_cellX - fromX;+ const Real dy = m_starts[target].m_cellY - fromY;+ const Real length = sqrtf( dx * dx + dy * dy );+ if( length < 1.0f )+ continue;++ for( Int lane = 0; lane < 3; lane++ )+ {+ Int previous = 0;+ Int step = 0;+ Int x = (Int)fromX;+ Int y = (Int)fromY;+ if( lane == 0 && dist[cellIndex( x, y )] > 0 )+ {+ // downhill on the flood from the target: the route a unit would drive+ Int walked = 0;+ while( dist[cellIndex( x, y )] > 0 )+ {+ const Int here = dist[cellIndex( x, y )];+ Bool stepped = FALSE;+ for( Int n = 0; n < 4 && !stepped; n++ )+ {+ const Int nx = x + STEP_X[n];+ const Int ny = y + STEP_Y[n];+ if( nx < 0 || ny < 0 || nx >= m_width - 1 || ny >= m_height - 1 )+ continue;+ if( dist[cellIndex( nx, ny )] == here - 1 )+ {+ x = nx;+ y = ny;+ stepped = TRUE;+ }+ }+ if( !stepped )+ break; // a breadth-first flood always leaves one; this only guards the loop+ if( ++walked % RMG_APPROACH_SPACING_CELLS == 0 )+ addApproachWaypoint( LANES[lane], (Int)target, (Int)from, step++, (Real)x, (Real)y, waypointID, &previous );+ }+ }+ else+ {+ const Int points = max( 2, (Int)(length / RMG_APPROACH_SPACING_CELLS) );+ for( Int k = 1; k < points; k++ )+ {+ const Real t = (Real)k / (Real)points;+ const Real bow = BULGE[lane] * length * 4.0f * t * (1.0f - t);+ const Real px = fromX + dx * t - dy / length * bow;+ const Real py = fromY + dy * t + dx / length * bow;+ // the nearest cell a unit can reach, ring by ring+ Bool found = FALSE;+ for( Int ring = 0; ring <= RMG_APPROACH_SNAP_CELLS && !found; ring++ )+ {+ for( Int oy = -ring; oy <= ring && !found; oy++ )+ {+ for( Int ox = -ring; ox <= ring && !found; ox++ )+ {+ if( abs( ox ) != ring && abs( oy ) != ring )+ continue;+ const Int cx = (Int)px + ox;+ const Int cy = (Int)py + oy;+ if( cx < 0 || cy < 0 || cx >= m_width - 1 || cy >= m_height - 1 || dist[cellIndex( cx, cy )] < 0 )+ continue;+ addApproachWaypoint( LANES[lane], (Int)target, (Int)from, step++, (Real)cx, (Real)cy, waypointID, &previous );+ found = TRUE;+ }+ }+ }+ }+ }+ addApproachWaypoint( LANES[lane], (Int)target, (Int)from, step++, m_starts[target].m_cellX, m_starts[target].m_cellY,+ waypointID, &previous );+ }+ }+ }+}+void RMGLayout::buildObjects( const UnsignedByte perm[512] ){m_objects.clear();@@ -4029,6 +4164,7 @@ void RMGLayout::buildObjects( const UnsignedByte perm[512] )reserveSite( m_starts[i].m_cellX, m_starts[i].m_cellY, RMG_FLAT_RADIUS );}+ addApproachPaths( &waypointID );placeSupplyAndDerricks();placeTowns();@@ -4104,7 +4240,8 @@ static void writeWaypoint( MapChunkWriter& w, const RMGObject& object )w.writeInt( 0 );w.writeAsciiString( object.m_templateName.str() );- w.beginDict( 12 );+ const Bool onPath = !object.m_pathLabel.isEmpty();+ w.beginDict( onPath ? 13 : 12 );w.dictInt( "objectInitialHealth", 100 );w.dictBool( "objectEnabled", TRUE );w.dictBool( "objectPowered", TRUE );@@ -4117,6 +4254,8 @@ static void writeWaypoint( MapChunkWriter& w, const RMGObject& object )w.dictBool( "objectSellable", TRUE );w.dictBool( "objectRepairable", TRUE );w.dictAsciiString( "waypointName", object.m_uniqueID.str() );+ if( onPath )+ w.dictAsciiString( "waypointPathLabel1", object.m_pathLabel.str() );w.closeChunk();}@@ -4245,9 +4384,21 @@ static void writeSides( MapChunkWriter& w )w.closeChunk();}-/** One water area per basin. Point zero carries the water height for the whole- area, which is what isUnderwater compares the ground against. */-static void writeWaterAreas( MapChunkWriter& w, const RMGLayout& layout )+/** The skirmish scripts' base areas, in cells: InnerPerimeterN round start N is "my base", and a+ wave only leaves while it stands inside OuterPerimeterN. Neither is ever bigger than a share of the+ way to the nearest other start, so two bases' areas never overlap. */+static const Real RMG_INNER_PERIMETER_CELLS = 30.0f;+static const Real RMG_OUTER_PERIMETER_CELLS = 55.0f;+static const Real RMG_OUTER_PERIMETER_SHARE = 0.45f;+static const Real RMG_INNER_OF_OUTER = 0.6f;+static const Int RMG_PERIMETER_SIDES = 16;++/** Every trigger area the map has: one water area per basin, and the two base areas round every+ start. Point zero of a water area carries the water height for the whole area, which is what+ isUnderwater compares the ground against. The base areas are what an Easy or Medium attack+ waits on: "[Skirmish]MyOuterPerimeter" resolves to OuterPerimeterN, a generated map had none,+ and the scripts' launch condition was never true. */+static void writePolygonTriggers( MapChunkWriter& w, const RMGLayout& layout ){// The polygon is the contour of the basin that was carved, so the engine floods the same// shape the height field holds.@@ -4257,6 +4408,7 @@ static void writeWaterAreas( MapChunkWriter& w, const RMGLayout& layout )if( (Int)layout.m_lakes[i].m_polygon.size() >= 3 )written++;}+ written += 2 * (Int)layout.m_starts.size();w.openChunk( "PolygonTriggers", K_TRIGGERS_VERSION_4 );w.writeInt( written );@@ -4291,6 +4443,43 @@ static void writeWaterAreas( MapChunkWriter& w, const RMGLayout& layout )id++;}++ for( UnsignedInt start = 0; start < layout.m_starts.size(); start++ )+ {+ const RMGPoint& centre = layout.m_starts[start];+ Real nearest = FLT_MAX;+ for( UnsignedInt other = 0; other < layout.m_starts.size(); other++ )+ {+ if( other == start )+ continue;+ const Real dx = layout.m_starts[other].m_cellX - centre.m_cellX;+ const Real dy = layout.m_starts[other].m_cellY - centre.m_cellY;+ nearest = min( nearest, (Real)sqrt( dx * dx + dy * dy ) );+ }+ const Real outer = min( RMG_OUTER_PERIMETER_CELLS, nearest * RMG_OUTER_PERIMETER_SHARE );+ const Real inner = min( RMG_INNER_PERIMETER_CELLS, outer * RMG_INNER_OF_OUTER );+ for( Int ring = 0; ring < 2; ring++ )+ {+ AsciiString name;+ name.format( "%s%d", ring == 0 ? "InnerPerimeter" : "OuterPerimeter", start + 1 );+ const Real radius = (ring == 0) ? inner : outer;++ w.writeAsciiString( name.str() );+ w.writeAsciiString( "" ); // layer+ w.writeInt( id++ ); // trigger id+ w.writeByte( 0 ); // not water+ w.writeByte( 0 ); // not a river+ w.writeInt( 0 ); // river start+ w.writeInt( RMG_PERIMETER_SIDES );+ for( Int point = 0; point < RMG_PERIMETER_SIDES; point++ )+ {+ const Real angle = 2.0f * PI * point / RMG_PERIMETER_SIDES;+ w.writeInt( (Int)((centre.m_cellX + radius * Cos( angle )) * MAP_XY_FACTOR + 0.5f) );+ w.writeInt( (Int)((centre.m_cellY + radius * Sin( angle )) * MAP_XY_FACTOR + 0.5f) );+ w.writeInt( 0 );+ }+ }+ }w.closeChunk();}@@ -4496,13 +4685,23 @@ void RandomMapGenerator::generate( const RandomMapSettings& settings, std::vecto}w.closeChunk();- /***************WATER ***************/- if( !layout.m_lakes.empty() )- writeWaterAreas( w, layout );+ /***************WATER AND BASE AREAS ***************/+ writePolygonTriggers( w, layout );/***************GLOBAL LIGHTING DATA ***************/writeGlobalLighting( w );+ /***************WAYPOINT LINKS ***************/+ // read after every waypoint exists (TerrainLogic::loadMap), so its place in the file is free+ w.openChunk( "WaypointsList", K_WAYPOINTS_VERSION_1 );+ w.writeInt( (Int)layout.m_waypointLinks.size() );+ for( UnsignedInt i = 0; i < layout.m_waypointLinks.size(); i++ )+ {+ w.writeInt( layout.m_waypointLinks[i].first );+ w.writeInt( layout.m_waypointLinks[i].second );+ }+ w.closeChunk();+w.finish( mapBytes );}@@ -4786,8 +4985,14 @@ Bool generatedMapBytes( const AsciiString& path, const char **bytesOut, Int *sizAsciiString lower = path;lower.toLower();- const std::vector<char>& bytes = lower.endsWith( ".tga" ) ? slot->m_previewBytes- : slot->m_mapBytes;+ // the map and its preview, nothing else: the terrain loader asks for "<map>.wak" beside every map,+ // and handing it the map read the map's last four bytes as a count of shore waves. It came out+ // harmless while the map ended in the lighting chunk and crashed every load once it ended in the+ // waypoint links.+ const Bool preview = lower.endsWith( ".tga" );+ if( !preview && !lower.endsWith( ".map" ) )+ return FALSE;+ const std::vector<char>& bytes = preview ? slot->m_previewBytes : slot->m_mapBytes;if( bytes.empty() )return FALSE;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 168be2c7a..b84e05398 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1082,9 +1082,9 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* scoutS maxSc react decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ */static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] ={- /* Easy */ { 90.0f, 1, 15.0f, 10.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0, FALSE, FALSE },- /* Medium */ { 60.0f, 1, 6.0f, 5.0f, 0.25f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 10000, FALSE, FALSE },- /* Brutal */ { 25.0f, 2, 0.0f, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE }+ /* Easy */ { 90.0f, 1, 10.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0, FALSE, FALSE },+ /* Medium */ { 60.0f, 1, 5.0f, 0.25f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 10000, FALSE, FALSE },+ /* Brutal */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE }};//-------------------------------------------------------------------------------------------------@@ -1373,7 +1373,6 @@ void AI::parseSkillLevel(INI *ini, void *instance, void* /*store*/, const void*{{ "ScoutIntervalSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_scoutIntervalSeconds ) },{ "MaxScouts", INI::parseInt, NULL, offsetof( AIDifficultyProfile, m_maxScouts ) },- { "ReactionDelaySeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_reactionDelaySeconds ) },{ "DecisionIntervalSeconds", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_decisionIntervalSeconds ) },{ "CounterCompositionWeight", INI::parseReal, NULL, offsetof( AIDifficultyProfile, m_counterCompositionWeight ) },{ "MassBeforeAttacking", INI::parseBool, NULL, offsetof( AIDifficultyProfile, m_massBeforeAttacking ) },diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex cabc22b59..abd2203a7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -6144,14 +6144,16 @@ void AIPlayer::doRetreats( void )continue;if( homeTunnel != NULL && obj->getAI()->takeTunnelTrip( homeTunnel, &m_baseCenter, TUNNEL_TRIP_MOVE, CMD_FROM_AI ) )leaveTacticsAlone( obj->getID() );- else if( m_influence.isBuilt() )+ else if( measuringWithoutTactics() )+ obj->getAI()->aiMoveToPosition( &m_baseCenter, CMD_FROM_AI );+ else{- // the walk home taken calm, or its mood turns it into an attack move back into the fight+ // the walk home taken calm and as an order, on every rung: a CMD_FROM_AI move to a unit+ // that is fighting is laid under its attack, and an aggressive mood turns the walk back+ // into a fight, so the retreat never happenedleaveTacticsAlone( obj->getID() );stepCalmly( obj, tacticalStepFor( obj->getID() ), &m_baseCenter );}- else- obj->getAI()->aiMoveToPosition( &m_baseCenter, CMD_FROM_AI );}}}@@ -6194,6 +6196,8 @@ static const Real HURT_HEALTH_SHARE = 0.35f;static const UnsignedInt TACTICAL_ROW_EXPIRY_FRAMES = 10 * LOGICFRAMES_PER_SECOND;/** A unit the retreat sent home is not turned round by a kite. */static const UnsignedInt LEAVE_ALONE_FRAMES = 10 * LOGICFRAMES_PER_SECOND;+/** ... and gets its mood back when it stops walking, or this long after that at the latest. */+static const UnsignedInt WALK_HOME_MAX_FRAMES = 30 * LOGICFRAMES_PER_SECOND;static void collectObject( Object *obj, void *userData ){@@ -6308,8 +6312,6 @@ AIPlayer::TacticalStep *AIPlayer::tacticalStepFor( ObjectID unit )void AIPlayer::leaveTacticsAlone( ObjectID unit ){- if( !m_influence.isBuilt() )- return; // no tactics running for this playerTacticalStep *step = tacticalStepFor( unit );step->resumeFrame = 0;step->leaveAloneUntil = TheGameLogic->getFrame() + LEAVE_ALONE_FRAMES;@@ -6415,37 +6417,50 @@ Bool AIPlayer::pickTacticalSpot( const Object *obj, const Coord3D *from, const C* unit's own AI still aims, picks targets and drives; this only decides where it stands, on the* rung's own clock. *///----------------------------------------------------------------------------------------------------------+/** -notactics, the measuring half of a batch: this player fights the way it did before the tactics,+ * the retreat and the approaches included. */+Bool AIPlayer::measuringWithoutTactics( void ) const+{+ return TheGlobalData->m_noTacticsSlotParity >= 0 && TheGameLogic->isInSkirmishGame() &&+ (ThePlayerList->getSlotIndex( m_player->getPlayerIndex() ) & 1) == TheGlobalData->m_noTacticsSlotParity;+}+void AIPlayer::doTactics( void ){- if( !getSkillProfile()->m_tacticalMicro )+ if( measuringWithoutTactics() )return;const UnsignedInt now = TheGameLogic->getFrame();const Int me = m_player->getPlayerIndex();- if( TheGlobalData->m_noTacticsSlotParity >= 0 && TheGameLogic->isInSkirmishGame() &&- (ThePlayerList->getSlotIndex( me ) & 1) == TheGlobalData->m_noTacticsSlotParity )- return; // -notactics, the measuring half of a batch; the approaches then count the old way too+ const Bool tactics = getSkillProfile()->m_tacticalMicro;- if( !m_influence.isBuilt() || (now + computeUpdatePhase( me, INFLUENCE_REBUILD_RATE )) % INFLUENCE_REBUILD_RATE == 0 )+ if( tactics && (!m_influence.isBuilt() || (now + computeUpdatePhase( me, INFLUENCE_REBUILD_RATE )) % INFLUENCE_REBUILD_RATE == 0) )rebuildInfluence();- if( !m_baseCenterSet )- return;if( (now + computeUpdatePhase( me, TACTICS_RATE )) % TACTICS_RATE != 0 )return;- std::vector<Object *> units;- m_player->iterateObjects( collectObject, &units );- for( size_t i = 0; i < units.size(); ++i )- tacticsFor( units[ i ] );+ if( tactics && m_baseCenterSet )+ {+ std::vector<Object *> units;+ m_player->iterateObjects( collectObject, &units );+ for( size_t i = 0; i < units.size(); ++i )+ tacticsFor( units[ i ] );+ }// ponytail: a linear list searched per unit, a few hundred rows at most; a map keyed on the ID if// armies ever grow past thatfor( size_t i = 0; i < m_tactics.size(); ){- if( now - m_tactics[ i ].lastSeenFrame > TACTICAL_ROW_EXPIRY_FRAMES )+ Object *unit = TheGameLogic->findObjectByID( m_tactics[ i ].unit );+ const TacticalStep &row = m_tactics[ i ];+ // with the tactics running a row goes when the unit has not been looked at for a while; without+ // them the only rows are walks home from a retreat, which end when the walk does+ const Bool done = (unit == NULL || unit->isEffectivelyDead()) ? TRUE :+ tactics ? now - row.lastSeenFrame > TACTICAL_ROW_EXPIRY_FRAMES :+ now >= row.leaveAloneUntil && (unit->getAI() == NULL || !unit->getAI()->isMoving() || now >= row.leaveAloneUntil + WALK_HOME_MAX_FRAMES);+ if( done ){- // one that is still alive (in a tunnel, garrisoned) keeps the mood its team gave it- Object *unit = TheGameLogic->findObjectByID( m_tactics[ i ].unit );+ // one that is still alive (home, in a tunnel, garrisoned) gets the mood its team gave it backif( unit && unit->getAI() )restoreMood( unit, &m_tactics[ i ] );m_tactics[ i ] = m_tactics.back();@@ -6497,8 +6512,10 @@ void AIPlayer::tacticsFor( Object *obj )step->lastSeenFrame = now;if( now < step->leaveAloneUntil )return;- if( step->resumeFrame == 0 )- restoreMood( obj, step ); // home from a lost fight: its own mood again+ // home from a lost fight: its own mood again once the walk is over, and not before, or the mood turns+ // what is left of the walk into an attack move+ if( step->resumeFrame == 0 && (!ai->isMoving() || now >= step->leaveAloneUntil + WALK_HOME_MAX_FRAMES) )+ restoreMood( obj, step );// a step under way ends when it gets there or runs out of time, and the unit goes back to work:// the thing it was shooting if that still stands, otherwise back up the road it stepped offdiff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 1859a4f3a..a4be7070c 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6879,15 +6879,18 @@ static Bool RMGParseLighting( DataChunkInput &file, DataChunkInfo *info, void *static Bool RMGParseWaterAreas( DataChunkInput &file, DataChunkInfo *info, void * ){- theRMGParse.m_numWaterAreas = file.readInt();+ const Int numAreas = file.readInt();+ theRMGParse.m_numWaterAreas = 0;- for( Int area = 0; area < theRMGParse.m_numWaterAreas; area++ )+ for( Int area = 0; area < numAreas; area++ ){- file.readAsciiString(); // trigger name+ const AsciiString name = file.readAsciiString(); // trigger namefile.readAsciiString(); // layerfile.readInt(); // trigger id- CHECK( file.readByte() == 1 ); // every one of ours is water+ // the lakes are water; the skirmish base areas round every start are not+ const Bool water = file.readByte() == 1;+ CHECK( water || name.startsWith( "InnerPerimeter" ) || name.startsWith( "OuterPerimeter" ) );file.readByte(); // not a riverfile.readInt(); // river start@@ -6903,11 +6906,15 @@ static Bool RMGParseWaterAreas( DataChunkInput &file, DataChunkInfo *info, voidloc.z = (Real)file.readInt();polygon.push_back( loc );- if( point == 0 )+ if( water && point == 0 )theRMGParse.m_waterPoints.push_back( loc );}- theRMGParse.m_waterPolygons.push_back( polygon );+ if( water )+ {+ theRMGParse.m_numWaterAreas++;+ theRMGParse.m_waterPolygons.push_back( polygon );+ }}return TRUE;}@@ -6955,7 +6962,8 @@ static Bool RMGParseObject( DataChunkInput &file, DataChunkInfo *info, void * )theRMGParse.m_objectAngles.push_back( angle );theRMGParse.m_objectFlags.push_back( flags );- if( d.getType( NAMEKEY( "waypointID" ) ) == Dict::DICT_INT )+ // the start waypoints; the approach paths' waypoints carry a path label and are not starts+ if( d.getType( NAMEKEY( "waypointID" ) ) == Dict::DICT_INT && d.getType( NAMEKEY( "waypointPathLabel1" ) ) != Dict::DICT_ASCIISTRING ){theRMGParse.m_waypointNames.push_back( d.getAsciiString( NAMEKEY( "waypointName" ) ) );theRMGParse.m_waypointPositions.push_back( loc );@@ -8358,6 +8366,48 @@ TEST(every_start_reaches_its_money_and_has_two_ways_out)printf( "PASS every_start_reaches_its_money_and_has_two_ways_out (%d maps)\n", maps );}+//-------------------------------------------------------------------------------------------------+/** Easy and Medium attack only down the map's Center, Flank and Backdoor paths, named for the start+ they lead to, and only while the wave stands inside its own OuterPerimeter area. A generated map had+ neither, and their waves stayed at home: 128 Medium-against-Medium matches lost 159 units between+ them. Every start needs all three paths, the links that make them paths rather than loose points,+ and both base areas. */+//-------------------------------------------------------------------------------------------------+TEST(a_generated_map_carries_an_attack_path_to_every_start)+{+ CHECK( bootOnce() );++ RandomMapSettings settings;+ settings.m_seed = 12345;+ settings.m_numPlayers = 4;+ settings.m_playableCells = 96;+ std::vector<char> bytes;+ RandomMapGenerator::generate( settings, bytes );+ const std::string map( bytes.begin(), bytes.end() );++ CHECK( map.find( "WaypointsList" ) != std::string::npos );+ CHECK( map.find( "waypointPathLabel1" ) != std::string::npos );+ // ... and the base areas their launch condition asks about+ for( Int start = 1; start <= settings.m_numPlayers; ++start )+ {+ char area[32];+ sprintf( area, "InnerPerimeter%d", start );+ CHECK( map.find( area ) != std::string::npos );+ sprintf( area, "OuterPerimeter%d", start );+ CHECK( map.find( area ) != std::string::npos );+ }+ static const char *LANES[3] = { "Center", "Flank", "Backdoor" };+ for( Int lane = 0; lane < 3; ++lane )+ {+ for( Int start = 1; start <= settings.m_numPlayers; ++start )+ {+ char label[32];+ sprintf( label, "%s%d", LANES[lane], start );+ CHECK( map.find( label ) != std::string::npos );+ }+ }+}+//-------------------------------------------------------------------------------------------------/** The seed is worthless across two builds unless both builds turn it into the same bytes, andnothing warns anybody when they stop doing so. These numbers are that warning: change the@@ -8368,14 +8418,14 @@ TEST(the_generator_still_turns_a_seed_into_the_bytes_it_used_to){CHECK( bootOnce() );- CHECK_EQ( RANDOM_MAP_GENERATOR_VERSION, 10 );+ CHECK_EQ( RANDOM_MAP_GENERATOR_VERSION, 11 );struct RMGFingerprint { Int m_seed, m_players, m_cells; UnsignedInt m_crc; };static const RMGFingerprint theFingerprints[] ={- { 0, 2, 64, 0x6FE5FB90 },- { 12345, 4, 96, 0x71D5E795 },- { 7, 8, 128, 0x9C0240F4 },+ { 0, 2, 64, 0x2D2AF5EF },+ { 12345, 4, 96, 0xD1B4AB2D },+ { 7, 8, 128, 0x5A40EFA4 },};const Int numFingerprints = sizeof(theFingerprints) / sizeof(theFingerprints[0]);@@ -8969,7 +9019,6 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)// perception: looks more often, acts sooner, thinks more often - never sees moreCHECK( upper.m_scoutIntervalSeconds <= lower.m_scoutIntervalSeconds );- CHECK( upper.m_reactionDelaySeconds <= lower.m_reactionDelaySeconds );CHECK( upper.m_decisionIntervalSeconds <= lower.m_decisionIntervalSeconds );CHECK( upper.m_maxScouts >= lower.m_maxScouts );@@ -8992,10 +9041,9 @@ TEST(the_difficulty_ladder_climbs_in_every_direction_it_should)}// the ends of the ladder are what they say they are: Easy ignores what it is facing and Brutal- // is the baseline, which means it counters fully and answers the moment it sees something+ // is the baseline, which means it counters fullyCHECK_EQ( 0.0f, data.m_skill[ AISKILL_EASY ].m_counterCompositionWeight );CHECK_EQ( 1.0f, data.m_skill[ AISKILL_BRUTAL ].m_counterCompositionWeight );- CHECK_EQ( 0.0f, data.m_skill[ AISKILL_BRUTAL ].m_reactionDelaySeconds );// every rung scouts. An AI that never looks reads as broken, not as easy.for( Int i = 0; i < AISKILL_COUNT; ++i )