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): log each superweapon build and what each strike holds

Olcay Seygan431a06fa63d4
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 6c86f711b..bb7563ed7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -1795,6 +1795,8 @@ void Player::onStructureCreated( Object *builder, Object *structure )
{
} // end onStructureCreated
+static void logSuperweaponRation( Player *player, const Object *structure );
+
//-------------------------------------------------------------------------------------------------
/// a structure that was under construction has become completed
//-------------------------------------------------------------------------------------------------
@@ -1821,6 +1823,8 @@ void Player::onStructureConstructionComplete( Object *builder, Object *structure
// ai notification callback
if( m_ai )
m_ai->onStructureProduced( builder, structure );
+ if( m_ai && ( structure->isKindOf( KINDOF_FS_SUPERWEAPON ) || structure->isKindOf( KINDOF_FS_BASE_DEFENSE ) ) )
+ logSuperweaponRation( this, structure );
// the GUI needs to re-evaluate the information being displayed to the user now
if( TheControlBar )
@@ -3430,6 +3434,17 @@ static void countSuperweaponDefenses( Object *obj, void *userData )
}
}
+/* What the superweapon ration stands on, each time a computer player finishes a gun or a
+ superweapon: the batch reads the first superweapon's frame and the defences behind it from here. */
+static void logSuperweaponRation( Player *player, const Object *structure )
+{
+ SuperweaponDefenseCount count = { 0, 0 };
+ player->iterateObjects( countSuperweaponDefenses, &count );
+ DEBUG_LOG(( "AI RATION frame %d player %d skill %d built '%s', defences %d superweapons %d\n",
+ TheGameLogic->getFrame(), player->getPlayerIndex(), (Int)player->getAISkillLevel(),
+ structure->getTemplate()->getName().str(), count.defenses, count.superweapons ));
+}
+
Bool RebuildHoleHoldsSuperweapon( Bool rebuildsSuperweapon, Bool rebuildStanding )
{
return rebuildsSuperweapon && !rebuildStanding;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index 031079257..9c1d8ea25 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -2007,6 +2007,51 @@ void AIPlayer::onUnitProduced( Object *factory, Object *unit )
* again, and the fade recovering the whole way is what allows it. */
enum { SUPERWEAPON_REAIM_FRAMES = 600 * LOGICFRAMES_PER_SECOND };
+/** What a strike's blast holds, by plain price, for the AI SUPERWEAPON line only: buildings against
+ * units, and the dearest building. */
+struct StrikeSummary
+{
+ Int structures;
+ Int units;
+ const Object *top;
+};
+
+static void summarizeStrike( const Coord3D *at, Int playerNdx, Real radius, Int observerNdx, StrikeSummary *summary )
+{
+ summary->structures = 0;
+ summary->units = 0;
+ summary->top = NULL;
+ Int topCost = 0;
+ Player *enemy = ThePlayerList->getNthPlayer( playerNdx );
+ Player::PlayerTeamList::const_iterator teamIt;
+ for( teamIt = enemy->getPlayerTeams()->begin(); teamIt != enemy->getPlayerTeams()->end(); ++teamIt )
+ {
+ for( DLINK_ITERATOR<Team> instanceIt = (*teamIt)->iterate_TeamInstanceList(); !instanceIt.done(); instanceIt.advance() )
+ {
+ for( DLINK_ITERATOR<Object> memberIt = instanceIt.cur()->iterate_TeamMemberList(); !memberIt.done(); memberIt.advance() )
+ {
+ const Object *obj = memberIt.cur();
+ const Real dx = at->x - obj->getPosition()->x;
+ const Real dy = at->y - obj->getPosition()->y;
+ if( dx*dx + dy*dy >= radius*radius || obj->isEffectivelyDead() || !observerKnowsAbout( obj, observerNdx ) )
+ continue;
+ const Int cost = obj->getTemplate()->calcCostToBuild( enemy );
+ if( !obj->isKindOf( KINDOF_STRUCTURE ) )
+ {
+ summary->units += cost;
+ continue;
+ }
+ summary->structures += cost;
+ if( cost > topCost )
+ {
+ topCost = cost;
+ summary->top = obj;
+ }
+ }
+ }
+ }
+}
+
//----------------------------------------------------------------------------------------------------------
/** What a superweapon aimed at this spot is worth to this player right now.
*
@@ -2260,8 +2305,11 @@ Bool AIPlayer::computeSuperweaponTarget(const SpecialPowerTemplate *power, Coord
if( success )
{
- DEBUG_LOG(("AI SUPERWEAPON frame %d player %d aims '%s' at (%.0f,%.0f), worth %d\n", TheGameLogic->getFrame(),
- m_player->getPlayerIndex(), power->getName().str(), veryBestPos.x, veryBestPos.y, cash));
+ StrikeSummary summary;
+ summarizeStrike( &veryBestPos, playerNdx, weaponRadius, m_player->getPlayerIndex(), &summary );
+ DEBUG_LOG(("AI SUPERWEAPON frame %d player %d skill %d aims '%s' at (%.0f,%.0f), worth %d: structures %d units %d, top '%s'\n",
+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), (Int)m_skillLevel, power->getName().str(), veryBestPos.x,
+ veryBestPos.y, cash, summary.structures, summary.units, summary.top ? summary.top->getTemplate()->getName().str() : "none"));
noteSuperweaponAim( &veryBestPos );
}