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
feat(ai): allied computer players answer the team board
Olcay Seygan868954d89e3c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex da59e63e6..2160bfb8b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,6 +26,9 @@ found and fixed — EA's own, not port damage.**- **Supporter** attacks what its ally attacks and sends its army home to its ally when the ally's base is hit.- **Counter** studies what you field and builds the answer to it.- **Random** picks one of the above when the match starts and does not tell you which.+- Computer allies with a personality answer their team. When an ally's base is hit, an Air Force strikes the attacker, a Supporter comes home to defend, an Attacker or Rusher hits back at the attacker's base and a Tech turns its powers on him. An Economist sends money to an ally who runs dry.+- Allied computer players join the attack a teammate has started, so a team hits one enemy together.+- You can call them too. A beacon you place asks your computer allies to attack there, and typing `help`, `attack` or `money` in chat (`yardim`, `saldir`, `para` in Turkish) asks for help where you are looking, an attack there, or cash.- A personality is a preference, never a bonus: no personality gets extra money, faster building or tougher units.- Computer players with a personality now and then say something in chat, in their own voice, at most once every two and a half minutes. Normal ones stay quiet.- The choice travels with the game to every player in a LAN or online match and into the replay. Replays and saves from earlier versions load with every computer player on Normal; a save made with this version does not load in an earlier one.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex 187ec77b1..a250c130d 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1935,6 +1935,19 @@ GUI:AIChatCounterWin1"Countered."END+// A computer ally answering the team board (AIPlayer::coopChat)+GUI:AICoopHelp+"Hold on, I am coming."+END++GUI:AICoopMoney+"Here, take some money."+END++GUI:AICoopJoin+"I am with you on that attack."+END+GUI:MoneyTransferTitle"Send money"ENDdiff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex a1fb297bb..1b4672d34 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -16332,6 +16332,19 @@ GUI:AIChatCounterWin1"Karşılık verildi."END+// Takım panosuna cevap veren bilgisayar müttefiki (AIPlayer::coopChat)+GUI:AICoopHelp+"Dayan, geliyorum."+END++GUI:AICoopMoney+"Al, biraz para gönderiyorum."+END++GUI:AICoopJoin+"Bu saldırıda seninleyim."+END+GUI:MoneyTransferTitle"Para gönder"ENDdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex 7aeabc60a..46bdd7d3e 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -669,6 +669,7 @@ public:MSG_VOTE_KICK, ///< (Int player index, Bool yes) a vote kick: opens one, or answers the open one (fork)MSG_SET_REPEAT_UNIT, ///< (Int template ID, objectID producer, Bool on) the factory builds that unit on repeat, or stops (fork)MSG_TRANSFER_MONEY, ///< (Int player index, Int amount) the sender hands that much of his money to another player (fork)+ MSG_TEAM_REQUEST, ///< (Int AITeamRequestKind, Location) the sender asks his computer allies for help, money or to join his attack (fork)MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.hindex 8f91c472c..abe050d5a 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h@@ -611,6 +611,7 @@ public:/// Get the enemy an ai player is currently focused on. NOTE - Can be NULL.Player *getCurrentEnemy( void );+ void noteTeamRequest( Int kind, Int from, Int enemy, const Coord3D *pos ); ///< an ally's request, for this player's AI if it has one (aiPostTeamRequest)/// Is this player a skirmish ai player?Bool isSkirmishAIPlayer( void );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.hindex 02aad2d07..62df80bcc 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h@@ -638,6 +638,35 @@ Int aiPersonaShareAmount( Int bank, Int target, Int cap );static const UnsignedInt AI_CHAT_GAP_FRAMES = 150 * LOGICFRAMES_PER_SECOND;Bool aiPersonaChatAllowed( UnsignedInt now, UnsignedInt lastChat );+/** What a player asks of his allies: his base is under attack, by aircraft, he is short of money, or+ * he goes after an enemy. A computer player posts these itself; a person by beacon or chat command+ * (MSG_TEAM_REQUEST). Only a personality answers: Normal reads nothing off the board. */+enum AITeamRequestKind+{+ AIREQ_HELP = 0,+ AIREQ_AA,+ AIREQ_MONEY,+ AIREQ_ATTACK,+ AIREQ_COUNT+};++struct AITeamRequest+{+ Int from; ///< the asking player's index+ Int enemy; ///< the player he is fighting, -1 for none known+ Coord3D pos; ///< where: the attacker, or the attack's target+ UnsignedInt frame; ///< when it was posted, 0 for never+};++/** How long a call for help stands, and a personality keeps to an ally's attack after he posted it. */+static const UnsignedInt AI_COOP_HELP_FRAMES = 15 * LOGICFRAMES_PER_SECOND;+static const UnsignedInt AI_COOP_JOIN_FRAMES = 120 * LOGICFRAMES_PER_SECOND;++/** Post a request from this player to every computer ally of his (allied both ways). */+void aiPostTeamRequest( Player *from, AITeamRequestKind kind, Int enemy, const Coord3D *pos );+/** The enemy of this player's who owns what stands nearest pos, -1 for none within reach. */+Int aiEnemyNear( const Player *of, const Coord3D *pos );+/** A skirmish AI's purchase queue, on every rung with a bank target. Every spender asks it before it pays, with a stable key (a* template id), the price, its score and whether the thing could start right now (an idle factory,* a dozer). It remembers one request: the best one it could not afford. That one has the moneydiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex 7c5098d75..a7f494d7b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -263,6 +263,7 @@ public:void setAIPersonality(AIPersonality persona);AIPersonality getAIPersonality(void) const {return m_persona;}Bool superweaponIsPlan(void) const; ///< a Tech AI, or a GLA Air AI whose SCUD Storm stands in for the air force: its first superweapon is rushed+ void noteTeamRequest(AITeamRequestKind kind, Int from, Int enemy, const Coord3D *pos); ///< an ally asks (aiPostTeamRequest)/// HEADLESS PERSONA: one line of what this seat's personality did over the match, for ai-batchvoid logPersonaSummary(void);@@ -564,6 +565,12 @@ protected:void huntGatherers(void); ///< raiders out of the base turn on the nearest known gatherer near themvoid personaSortie(void); ///< Attacker and Rusher on a rung that does not mass: the rush and the regular sorties of what idles at homevoid defendAlly(void); ///< Supporter: idle units at home go to an ally's base when it is hit+ void postTeamRequests(void); ///< what this AI asks of its allies, every wave tick+ void answerTeamRequests(void); ///< Air, Attacker and Rusher answer an ally's call for help+ const AITeamRequest *freshRequest(AITeamRequestKind kind, UnsignedInt within) const; ///< the request of that kind posted inside within frames, NULL for none+ void coopChat(const char *trigger); ///< one line to the team when answering, GUI:AICoop<trigger>+ AITeamRequest m_inbox[ AIREQ_COUNT ]; ///< the latest request of each kind from an ally; not saved+ UnsignedInt m_answeredFrame; ///< the frame of the last call answerTeamRequests answeredvoid shareSurplusWithAllies(Int bank, Int target); ///< Economist: who gets what out of the bank (the hook only)AsciiString sneakyLane(const Coord3D *from, const AsciiString &requested, Int pathSuffix); ///< Sneaky: the back door or the flankdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex 9efbf436f..cc016aef1 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -675,6 +675,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_VOTE_KICK)CHECK_IF(MSG_SET_REPEAT_UNIT)CHECK_IF(MSG_TRANSFER_MONEY)+ CHECK_IF(MSG_TEAM_REQUEST)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cppindex 86c6c46fc..43594f722 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp@@ -1302,7 +1302,13 @@ Bool Player::computeSuperweaponTarget(const SpecialPowerTemplate *power, Coord3D//-------------------------------------------------------------------------------------------------Player *Player::getCurrentEnemy( void ){- return m_ai?m_ai->getAiEnemy():NULL;+ return m_ai?m_ai->getAiEnemy():NULL;+}++void Player::noteTeamRequest( Int kind, Int from, Int enemy, const Coord3D *pos )+{+ if( m_ai )+ m_ai->noteTeamRequest( (AITeamRequestKind)kind, from, enemy, pos );}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cppindex aef9cceca..4c648760e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/InGameChat.cpp@@ -46,6 +46,8 @@#include "GameClient/GUICallbacks.h"#include "GameClient/InGameUI.h"#include "GameClient/LanguageFilter.h"+#include "GameClient/View.h"+#include "GameLogic/AI.h"#include "GameLogic/GameLogic.h"#include "GameNetwork/GameInfo.h"#include "GameNetwork/NetworkInterface.h"@@ -247,6 +249,29 @@ Bool handleInGameSlashCommands(UnicodeString uText)return FALSE; // not a slash command}+// ------------------------------------------------------------------------------------------------+/** help / attack / money, or yardim / saldir / para, as the whole line: a request to the computer+ * allies (MSG_TEAM_REQUEST) at where the camera looks. The line still goes out as chat. */+// ------------------------------------------------------------------------------------------------+static void sendTeamRequest( const UnicodeString &line )+{+ static const struct { const WideChar *word; Int kind; } COMMANDS[] = {+ { u"help", AIREQ_HELP }, { u"yardim", AIREQ_HELP }, { u"yardım", AIREQ_HELP },+ { u"attack", AIREQ_ATTACK }, { u"saldir", AIREQ_ATTACK }, { u"saldır", AIREQ_ATTACK },+ { u"money", AIREQ_MONEY }, { u"para", AIREQ_MONEY } };+ for( Int c = 0; c < (Int)( sizeof( COMMANDS ) / sizeof( COMMANDS[ 0 ] ) ); ++c )+ {+ if( line.compareNoCase( COMMANDS[ c ].word ) != 0 )+ continue;+ Coord3D pos;+ TheTacticalView->getPosition( &pos );+ GameMessage *request = TheMessageStream->appendMessage( GameMessage::MSG_TEAM_REQUEST );+ request->appendIntegerArgument( COMMANDS[ c ].kind );+ request->appendLocationArgument( pos );+ return;+ }+}+// ------------------------------------------------------------------------------------------------// ------------------------------------------------------------------------------------------------void ToggleInGameChat( Bool immediate )@@ -278,6 +303,8 @@ void ToggleInGameChat( Bool immediate )// Send what is there, clear it out, and hide the windowUnicodeString msg = GadgetTextEntryGetText( chatTextEntry );msg.trim();+ if (!msg.isEmpty())+ sendTeamRequest(msg);if (!msg.isEmpty() && !handleInGameSlashCommands(msg)){const Player *localPlayer = ThePlayerList->getLocalPlayer();diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex 9169a0fb6..0e825b3f8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -406,6 +406,14 @@ m_role(AIROLE_AGGRESSIVE)for( Int r = 0; r < MAX_PERSONA_RAIDERS; ++r )m_raider[ r ] = INVALID_ID;m_shareFrame = 0;+ for( Int k = 0; k < AIREQ_COUNT; ++k )+ {+ m_inbox[ k ].from = -1;+ m_inbox[ k ].enemy = -1;+ m_inbox[ k ].pos.zero();+ m_inbox[ k ].frame = 0;+ }+ m_answeredFrame = 0;m_chatFrame = 0;m_beatenMask = 0;m_personaWaves = 0;@@ -2061,6 +2069,14 @@ void AIPlayer::noteSuperweaponAim( const Coord3D *pos )*/Bool AIPlayer::computeSuperweaponTarget(const SpecialPowerTemplate *power, Coord3D *retPos, Int playerNdx, Real weaponRadius){+ // a Tech AI turns its powers on whoever is hitting an ally (the team board)+ const AITeamRequest *call = m_persona == AIPERSONA_TECH ? freshRequest( AIREQ_HELP, AI_COOP_HELP_FRAMES ) : NULL;+ if( call && call->enemy >= 0 && call->enemy != playerNdx )+ {+ DEBUG_LOG(("AI COOP frame %d player %d turns '%s' on player %d, who hits player %d\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), power->getName().str(), call->enemy, call->from));+ playerNdx = call->enemy;+ }Bool success = FALSE;@@ -9779,6 +9795,9 @@ void AIPlayer::doWaves( void )updatePressure();defendHome();notePersonaProgress();+ postTeamRequests();+ if( m_persona != AIPERSONA_NORMAL )+ answerTeamRequests();if( m_persona == AIPERSONA_SUPPORTER )defendAlly();if( m_persona == AIPERSONA_RAIDER )@@ -10703,6 +10722,18 @@ void AIPlayer::sendWave( AIGroup *wave, const AsciiString &approach, Int pathSuflogEngage( cause, units );computeShuttleFront( way, wave );+ // the team board: this attack, for an ally to join (acquireEnemy)+ Player *target = getAiEnemy();+ if( target )+ {+ Region2D bounds;+ getPlayerStructureBounds( &bounds, target->getPlayerIndex(), FALSE, m_player->getPlayerIndex() );+ Coord3D aim;+ aim.x = bounds.lo.x + bounds.width() / 2;+ aim.y = bounds.lo.y + bounds.height() / 2;+ aim.z = 0.0f;+ aiPostTeamRequest( m_player, AIREQ_ATTACK, target->getPlayerIndex(), &aim );+ }if( m_persona == AIPERSONA_INFANTRY )sendPersonaTransports( wave );wave->groupFollowWaypointPathAsTeam( way, CMD_FROM_AI );@@ -16095,14 +16126,171 @@ void AIPlayer::shareSurplusWithAllies( Int bank, Int target )if( poorest == NULL || ally->getMoney()->countMoney() < poorest->getMoney()->countMoney() )poorest = ally;}+ // an ally who asked for money (the board) goes before the poorest+ const AITeamRequest *asked = freshRequest( AIREQ_MONEY, SHARE_EVERY_FRAMES );+ if( asked )+ {+ Player *asker = ThePlayerList->getNthPlayer( asked->from );+ if( asker->isPlayableSide() && asker->hasAnyObjects() && m_player->getRelationship( asker->getDefaultTeam() ) == ALLIES &&+ asker->getRelationship( m_player->getDefaultTeam() ) == ALLIES )+ poorest = asker;+ }if( poorest == NULL )return;m_shareFrame = now;m_personaShared += amount;- // HOOK(ai-money-transfer): the transfer of amount from m_player to poorest goes here. This decides- // who and how much, deterministically, and moves nothing yet.- DEBUG_LOG(("AI SHARE frame %d player %d would give %d to player %d (%d in its bank), %d in ours, bank target %d\n", now,- m_player->getPlayerIndex(), amount, poorest->getPlayerIndex(), poorest->getMoney()->countMoney(), bank, target));+ // straight from bank to bank inside the logic, as MSG_TRANSFER_MONEY does: every machine runs this+ // same decision, so nothing goes through the message stream+ const UnsignedInt moved = m_player->getMoney()->withdraw( (UnsignedInt)amount );+ poorest->getMoney()->deposit( moved );+ if( asked && poorest->getPlayerIndex() == asked->from )+ coopChat( "Money" );+ DEBUG_LOG(("AI SHARE frame %d player %d gives %u to player %d (%d in its bank now)%s, %d in ours, bank target %d\n", now,+ m_player->getPlayerIndex(), moved, poorest->getPlayerIndex(), poorest->getMoney()->countMoney(),+ asked && poorest->getPlayerIndex() == asked->from ? ", asked for" : "", m_player->getMoney()->countMoney(), target));+}++//-------------------------------------------------------------------------------------------------+/** The team board. A request lands in every computer ally's inbox, the latest of each kind kept; a+ * personality answers, Normal never reads it, so Normal teams play as before. */+//-------------------------------------------------------------------------------------------------+static const Real COOP_ENEMY_REACH = 1000.0f;+/** A computer player short of this much, three minutes in, asks its allies for money. */+static const Int COOP_POOR_BANK = 300;+static const UnsignedInt COOP_POOR_AFTER_FRAMES = 180 * LOGICFRAMES_PER_SECOND;++void aiPostTeamRequest( Player *from, AITeamRequestKind kind, Int enemy, const Coord3D *pos )+{+ for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )+ {+ Player *ally = ThePlayerList->getNthPlayer( i );+ if( ally != from && ally->getRelationship( from->getDefaultTeam() ) == ALLIES && from->getRelationship( ally->getDefaultTeam() ) == ALLIES )+ ally->noteTeamRequest( kind, from->getPlayerIndex(), enemy, pos );+ }+}++Int aiEnemyNear( const Player *of, const Coord3D *pos )+{+ PartitionFilterAlive filterAlive;+ PartitionFilterOnMap filterOnMap;+ PartitionFilter *filters[] = { &filterAlive, &filterOnMap, NULL };+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( pos, COOP_ENEMY_REACH, FROM_CENTER_2D, filters, ITER_SORTED_NEAR_TO_FAR );+ MemoryPoolObjectHolder hold( iter );+ for( Object *obj = iter->first(); obj; obj = iter->next() )+ {+ const Player *owner = obj->getControllingPlayer();+ if( owner && owner->isPlayableSide() && of->getRelationship( obj->getTeam() ) == ENEMIES )+ return owner->getPlayerIndex();+ }+ return -1;+}++void AIPlayer::noteTeamRequest( AITeamRequestKind kind, Int from, Int enemy, const Coord3D *pos )+{+ AITeamRequest &slot = m_inbox[ kind ];+ slot.from = from;+ slot.enemy = enemy;+ slot.pos = *pos;+ slot.frame = TheGameLogic->getFrame();+}++const AITeamRequest *AIPlayer::freshRequest( AITeamRequestKind kind, UnsignedInt within ) const+{+ const AITeamRequest &slot = m_inbox[ kind ];+ return slot.frame != 0 && TheGameLogic->getFrame() - slot.frame < within ? &slot : NULL;+}++void AIPlayer::coopChat( const char *trigger )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ if( !aiPersonaChatAllowed( now, m_chatFrame ) )+ return;+ AsciiString label;+ label.format( "GUI:AICoop%s", trigger );+ m_chatFrame = now;+ DEBUG_LOG(("AI CHAT frame %d player %d %s\n", now, m_player->getPlayerIndex(), label.str()));+ TheInGameUI->chatMessage( m_player, TheGameText->fetch( label ) );+}++/** A computer player's own requests: the armed enemy nearest the middle of its base while it is hit,+ * by air or not, and its empty bank. Its attacks are posted where they are sent (sendWave). */+void AIPlayer::postTeamRequests( void )+{+ if( !m_baseCenterSet )+ return;+ const UnsignedInt now = TheGameLogic->getFrame();+ if( isBaseUnderAttack() )+ {+ PartitionFilterAlive filterAlive;+ PartitionFilterOnMap filterOnMap;+ PartitionFilter *filters[] = { &filterAlive, &filterOnMap, NULL };+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( &m_baseCenter, 1.5f * m_baseRadius, FROM_CENTER_2D, filters, ITER_SORTED_NEAR_TO_FAR );+ MemoryPoolObjectHolder hold( iter );+ for( Object *obj = iter->first(); obj; obj = iter->next() )+ {+ if( obj->isKindOf( KINDOF_PROJECTILE ) || !obj->isAbleToAttack() || m_player->getRelationship( obj->getTeam() ) != ENEMIES )+ continue;+ const Int enemy = obj->getControllingPlayer()->getPlayerIndex();+ aiPostTeamRequest( m_player, obj->isKindOf( KINDOF_AIRCRAFT ) ? AIREQ_AA : AIREQ_HELP, enemy, obj->getPosition() );+ break;+ }+ }+ if( now > COOP_POOR_AFTER_FRAMES && (Int)m_player->getMoney()->countMoney() < COOP_POOR_BANK )+ aiPostTeamRequest( m_player, AIREQ_MONEY, -1, &m_baseCenter );+}++/** An ally's call for help, answered by the Air AI with its idle aircraft at the attacker (an air raid+ * too) and by the Attacker and Rusher with a counter-attack of what idles at home on the attacker's+ * own base. The Supporter has defendAlly, the Tech AI its powers (computeSuperweaponTarget), the+ * Economist the money (shareSurplusWithAllies). Once a request: what went is not sent again. */+void AIPlayer::answerTeamRequests( void )+{+ if( !m_baseCenterSet || isBaseUnderAttack() )+ return;+ const Bool air = m_persona == AIPERSONA_AIR;+ const Bool counter = m_persona == AIPERSONA_ATTACKER || m_persona == AIPERSONA_RUSHER;+ if( !air && !counter )+ return;+ const AITeamRequest *call = freshRequest( AIREQ_AA, AI_COOP_HELP_FRAMES );+ if( call == NULL || !air )+ call = freshRequest( AIREQ_HELP, AI_COOP_HELP_FRAMES );+ if( call == NULL || call->frame == m_answeredFrame )+ return;+ m_answeredFrame = call->frame;++ Coord3D goal = call->pos;+ if( counter )+ {+ if( call->enemy < 0 )+ return;+ Region2D bounds;+ getPlayerStructureBounds( &bounds, call->enemy, FALSE, m_player->getPlayerIndex() );+ goal.x = bounds.lo.x + bounds.width() / 2;+ goal.y = bounds.lo.y + bounds.height() / 2;+ goal.z = TheTerrainLogic->getGroundHeight( goal.x, goal.y );+ }+ std::vector<Object *> owned;+ m_player->iterateObjects( collectOwned, &owned );+ Int sent = 0;+ for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )+ {+ Object *obj = *o;+ if( obj->isEffectivelyDead() || obj->isContained() || obj->getAI() == NULL || obj->isKindOf( KINDOF_IMMOBILE ) ||+ obj->isKindOf( KINDOF_STRUCTURE ) || !obj->isAbleToAttack() || ( !air && obj->isKindOf( KINDOF_AIRCRAFT ) ) ||+ !isAtHome( obj->getPosition() ) || !leavesToFinish( obj ) || isOutOnOrders( obj ) )+ continue;+ const StateID state = obj->getAI()->getCurrentStateID();+ if( state != AI_IDLE && state != AI_GUARD && state != AI_GUARD_RETALIATE )+ continue;+ obj->getAI()->aiAttackMoveToPosition( &goal, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );+ ++sent;+ }+ if( sent == 0 )+ return;+ coopChat( "Help" );+ DEBUG_LOG(("AI COOP frame %d player %d answers player %d's call (%s) with %d %s at (%.0f,%.0f)\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), call->from, call == &m_inbox[ AIREQ_AA ] ? "aircraft" : "base", sent,+ air ? "aircraft" : "units on his attacker's base", goal.x, goal.y));}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cppindex a651646e1..679587b07 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AISkirmishPlayer.cpp@@ -609,6 +609,20 @@ void AISkirmishPlayer::acquireEnemy(void)Player *bestEnemy = NULL;Real bestDistanceSqr = HUGE_DIST*HUGE_DIST;+ // a personality joins an ally's attack (the team board): his target is ours while it stands+ if (m_persona != AIPERSONA_NORMAL && m_persona != AIPERSONA_OPPORTUNIST) {+ const AITeamRequest *attack = freshRequest(AIREQ_ATTACK, AI_COOP_JOIN_FRAMES);+ Player *target = attack && attack->enemy >= 0 ? ThePlayerList->getNthPlayer(attack->enemy) : NULL;+ if (target && target != m_currentEnemy && m_player->getRelationship(target->getDefaultTeam()) == ENEMIES &&+ target->hasAnyObjects()) {+ DEBUG_LOG(("AI COOP frame %d player %d joins player %d's attack on player %d\n", TheGameLogic->getFrame(),+ m_player->getPlayerIndex(), attack->from, attack->enemy));+ m_currentEnemy = target;+ coopChat("Join");+ return;+ }+ }+// an Opportunist keeps looking for the weaker, busier enemy, and changes when one is clearly cheaperconst Bool opportunist = m_persona == AIPERSONA_OPPORTUNIST;Real currentCost = HUGE_DIST*HUGE_DIST;diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex bd88ef400..a172eff9e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -821,6 +821,26 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroupbreak;}+ //---------------------------------------------------------------------------------------------+ // A chat command to the computer allies (fork): (Int AITeamRequestKind, Location) from help /+ // attack / money typed in chat. It goes on the team board (aiPostTeamRequest); only a computer+ // personality reads it. The kind came over the network, so it is checked here.+ case GameMessage::MSG_TEAM_REQUEST:+ {+ if( msg->getArgumentCount() < 2 || msg->getArgumentDataType( 0 ) != ARGUMENTDATATYPE_INTEGER+ || msg->getArgumentDataType( 1 ) != ARGUMENTDATATYPE_LOCATION )+ break;+ const Int kind = msg->getArgument( 0 )->integer;+ if( kind < 0 || kind >= AIREQ_COUNT || !thisPlayer->isPlayableSide() || !thisPlayer->isPlayerActive() )+ break;+ const Coord3D pos = msg->getArgument( 1 )->location;+ const Int enemy = aiEnemyNear( thisPlayer, &pos );+ DEBUG_LOG(( "TEAM REQUEST: frame %d player %d asks %d, enemy %d at (%.0f,%.0f)\n", getFrame(),+ thisPlayer->getPlayerIndex(), kind, enemy, pos.x, pos.y ));+ aiPostTeamRequest( thisPlayer, (AITeamRequestKind)kind, enemy, &pos );+ break;+ }+//---------------------------------------------------------------------------------------------// The stance key (fork): every selected unit of the sender's takes the stance. The number came// over the network, so only 0 and 1 mean anything@@ -2301,6 +2321,8 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroupObject *object = TheThingFactory->newObject( thing, thisPlayer->getDefaultTeam() );object->setPosition( &pos );object->setProducer(NULL);+ // a beacon is an attack request to the computer allies (the team board, fork)+ aiPostTeamRequest( thisPlayer, AIREQ_ATTACK, aiEnemyNear( thisPlayer, &pos ), &pos );if (thisPlayer->getRelationship( ThePlayerList->getLocalPlayer()->getDefaultTeam() ) == ALLIES || ThePlayerList->getLocalPlayer()->isPlayerObserver()){