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(gameengine): weigh hard ai fights by matchup and hide stealth from it
Olcay Seygandd2780d982dc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3cca15b57..be147901a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1136,7 +1136,6 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- Classic's command bar lets the battlefield have the ground it shows. A click on the battlefield between its three pieces, or over the sloped shoulders of the build grid's plate, reaches the unit standing there; only the painted metal keeps it. Change the resolution with the bar minimised and the build tooltip used to come back 245 pixels too high at 1920x1080, as far as the bar had dropped; it stays over the radar now. The Chinese beacon button, the red one with the exclamation mark, no longer sits on a black card: EA's picture of it had no transparent corners, and the lit and pressed versions always did.- Classic's command bar empties when you let your worker go, as 1.04's did. Reforged's habit of showing a builder's buildings with nothing selected had leaked into Classic, so a dozer's build menu stayed on the bar after you dropped it, and was there from the first second of a match before you had picked anything. In Reforged that builder's menu now also comes back after a resolution change; it used to leave the bar empty until you clicked something.- Classic brings back 1.04's Alternate Mouse Setup, on its Controls page where EA had it and off until you tick it. Ticked, the right button gives the order and the left one only selects: a left click on open ground drops your selection, a right drag still scrolls the map, a double right click is the guard order when Double Click Guard is ticked, and the radar looks on the left button and sends units on the right. It is saved under the name 1.04 gave it, so a settings file 1.04 wrote keeps your choice. Reforged has one mouse, no box, and ignores the setting. The orders are 1.04's either way, so the box changes nothing about a match or its replay.-- Both of Classic's mouse setups now answer every click the way 1.04 did, checked against EA's code one case at a time. The attack move button waits for its click again, like guard: the left button aims it whichever setup you play, and a right click takes it back with your units still selected. Until now a right click there threw your whole selection away, and with the Alternate Mouse Setup ticked the left click did nothing while the right one fired it. A right click that takes back a waiting command gives no order behind it. With a dozer's building on the cursor a right click drops the building and lets go of the dozer, as it did in 2003. The right press starts the scroll at once and only a real click deselects, so a press held for a quarter of a second, or one the scroll carried the camera away from, keeps your selection. The radar sends a plain move, or an attack move when that button is waiting, and Alt held over it no longer makes a waypoint. Dragging on it leaves the camera where the press put it. Reforged's mouse is untouched.- Supply piles stop shouting their cash over the whole map. A small pile shows its amount only while your cursor is on it or close by, in a smaller font; a big supply dock keeps its label all the time. Classic has the same labels now, with the radar still leaving the piles off.- The Esc menu and the general's promotion screen close the way they open, in both interfaces. Both used to vanish in a single frame, and Classic's Esc menu had lost its opening flash as well. Classic plays 1.04's flash and fade, forwards to open and backwards to close; Reforged fades its pages out over a little more than a tenth of a second, as fast as they fade in.- Every graphics setting is on the Graphics and Effects pages. Shadows, clouds, ground lighting, soft water edges, trees, extra animations, heat haze, texture resolution and the particle limit used to hide in a popup that only opened if you picked Custom from the detail box on another page, so choosing High never showed you what High turns on. Pick a preset now and its settings change in front of you; touch any one of them and the box reads Custom. Texture filtering and the number of anisotropic samples, which needed a text editor, sit there too.diff --git a/GeneralsMD/Code/Data/Scenarios/stealthintruder.txt b/GeneralsMD/Code/Data/Scenarios/stealthintruder.txtnew file mode 100644index 000000000..d142a1fab--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/stealthintruder.txt@@ -0,0 +1,52 @@+# Issue #64: a stealthed Colonel Burton nobody has detected walks around inside the computer's+# base. The computer must not send its army at him until something detects him; then it should.+#+# Slot 0 is taken over by the file, slot 1 is a USA computer: China's Gattling Cannon detects+# stealth, so a China computer would find him by the game's own rules. Burton walks from his own+# base into the computer's and paces back and forth past a guard of four Crusaders, always under+# a move order, since an idle Burton shoots and a shot gives him away. The USA computer's first+# Patriot Battery, which does detect, goes up near frame 2550 on seeds 20-23, and from there on+# chasing him is fair. The Listening Outpost at 7000 is a second detector for a seed where no+# Patriot comes.+#+# Read the first "AI DEFEND ... sends N idle units at the intruder" against the first STATUE line+# naming Burton as a unit's enemy (the first moment the game itself lets anyone shoot him).+# On 2026-10-09: before the fix the computer sent its guard at him from frame 2029-2149 on all+# four seeds, before anything could see him; after it, nothing went at him before frame 2629, and+# no unit had him as a target before 2551. Seeds 0 and 1 end at frame 2400 with the computer+# marked defeated for a reason not found; 20 onward play.+#+# ai-batch.ps1 -Runs 4 -SeedStart 20 -Map 'Tournament Desert' -Scenario stealthintruder+# -Takeover 0 -Sides FactionAmerica,FactionAmerica -MaxFrames 9000 -Difficulty hard++30 spawn 0 AmericaInfantryColonelBurton 1 start0:0:200+30 spawn 1 AmericaTankCrusader 4 start1:0:-250 50+300 move 0 AmericaInfantryColonelBurton start1:-200:-400+300 arrive 0 AmericaInfantryColonelBurton start1:-200:-400 150++1000 move 0 AmericaInfantryColonelBurton start1:200:-400+1300 move 0 AmericaInfantryColonelBurton start1:-200:-400+1600 move 0 AmericaInfantryColonelBurton start1:200:-400+1900 move 0 AmericaInfantryColonelBurton start1:-200:-400+2200 move 0 AmericaInfantryColonelBurton start1:200:-400+2500 move 0 AmericaInfantryColonelBurton start1:-200:-400+2800 move 0 AmericaInfantryColonelBurton start1:200:-400+3100 move 0 AmericaInfantryColonelBurton start1:-200:-400+3400 move 0 AmericaInfantryColonelBurton start1:200:-400+3700 move 0 AmericaInfantryColonelBurton start1:-200:-400+4000 move 0 AmericaInfantryColonelBurton start1:200:-400+4300 move 0 AmericaInfantryColonelBurton start1:-200:-400+4600 move 0 AmericaInfantryColonelBurton start1:200:-400+4900 move 0 AmericaInfantryColonelBurton start1:-200:-400+5200 move 0 AmericaInfantryColonelBurton start1:200:-400+5500 move 0 AmericaInfantryColonelBurton start1:-200:-400+5800 move 0 AmericaInfantryColonelBurton start1:200:-400+6100 move 0 AmericaInfantryColonelBurton start1:-200:-400+6400 move 0 AmericaInfantryColonelBurton start1:200:-400+6700 move 0 AmericaInfantryColonelBurton start1:-200:-400++7000 tally 0 AmericaInfantryColonelBurton+7000 spawn 1 ChinaVehicleListeningOutpost 1 start1:0:-400+7000 move 0 AmericaInfantryColonelBurton start1:200:-400+7300 move 0 AmericaInfantryColonelBurton start1:-200:-400+8900 tally 0 AmericaInfantryColonelBurtondiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.hindex 94e21f833..6f97d0d87 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h@@ -53,9 +53,6 @@ private:UnsignedInt m_lastGroupSelTime;Int m_lastGroupSelGroup;ICoord2D m_selectFeedbackAnchor; // Note: Used for drawing feedback only.- ICoord2D m_deselectFeedbackAnchor; ///< where Classic's right press went down, for 1.04's click test on its release- UnsignedInt m_lastClick; ///< when it went down- Coord3D m_deselectDownCameraPosition; ///< and where the camera stood thenBool m_displayedMaxWarning; // did we already display a warning about selecting too many units?SelectCountMap m_selectCountMap;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.hindex d6c6961d0..e3f3f99a7 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIPlayer.h@@ -613,6 +613,17 @@ protected:Bool stealth; ///< it can go invisible};std::map<ObjectID, SeenEnemy> m_seenEnemies;+ void answerArmy(void); ///< train the answer to the biggest part of the remembered enemy army nothing of ours answers++ /** The fist: one unit picked because the army it remembers has no answer to it, built from the idle+ * factories, held together at the staging point and sent as one. */+ void doMass(void);+ const ThingTemplate *pickMassUnit(const std::vector<AIVisibleEnemy> &army, Real *efficiency) const;+ Bool isMassUnit(ObjectID id) const;+ const ThingTemplate *m_massTemplate; ///< NULL while no unit is picked+ UnsignedInt m_massPickFrame; ///< when it was picked, or dropped; 0 for never+ UnsignedInt m_massSince; ///< when the first of the fist now waiting joined it+ std::vector<ObjectID> m_massUnits; ///< the fist so far, in the order they came outAIPressure m_pressure;Real m_knownEnemyPower; ///< his army as this AI believes it: what is in sight at least, less for each look at his base that does not find it, more for each look not takenInt m_pressureEnemy; ///< the player index that figure is about, -1 for nobody yet@@ -656,7 +667,8 @@ protected:void leaveTacticsAlone(ObjectID unit);Bool isFallingBack(ObjectID unit); ///< holding at a safe spot after a lost fight, for doRetreats to send backvoid measureFight(const Coord3D *centre, Bool countHolders, Real *myHealth, Real *myPower,- Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns);+ Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns, Real *advantage = NULL);+ Real fightRatio(const Coord3D *centre, Bool countHolders, Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns); ///< the exchange around centre, by the units in it when the rung weighs themBool doFallback(Team *team); ///< TRUE when it sent the team's holders back or home on this passvoid stepCalmly(Object *obj, TacticalStep *step, const Coord3D *spot); ///< a move the unit's mood cannot turn into an attack movevoid restoreMood(Object *obj, TacticalStep *step);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cppindex cc4bcd17a..0128af7bf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp@@ -343,13 +343,11 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,TheAudio->addAudioEvent( &sound );}- if( commandButton->getCommandType() == GUI_COMMAND_ATTACK_MOVE && !TheGlobalData->isClassicUI() )+ if( commandButton->getCommandType() == GUI_COMMAND_ATTACK_MOVE ){// The attack move button arms the same key its hotkey does, rather than becoming a pending// GUI command that one click uses up: shift then keeps it armed for a row of points. It// takes the place of whatever command was waiting for a target, as any other button would.- // Classic's is 1.04's, a GUI command like guard: the left button aims it in either mouse- // setup and the right one takes it back.TheInGameUI->setGUICommand( NULL );TheMessageStream->appendMessage( GameMessage::MSG_META_TOGGLE_ATTACKMOVE );}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cppindex 2e1fe45b4..4514f04af 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp@@ -164,7 +164,7 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,if (!(drawableList->empty() || msg == GWM_MOUSE_LEAVING)){- if (TheInGameUI->isInAttackMoveToMode() || (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE))+ if (TheInGameUI->isInAttackMoveToMode()){cur = Mouse::ATTACKMOVETO;}@@ -247,7 +247,7 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,if (!(drawableList->empty() || msg == GWM_MOUSE_LEAVING)){- if (TheInGameUI->isInAttackMoveToMode() || (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE))+ if (TheInGameUI->isInAttackMoveToMode()){cur = Mouse::ATTACKMOVETO;}@@ -340,38 +340,10 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,// divides the world the other way round, and so did the radar in the game as shipped,// except under EA's Alternate Mouse Setup, which looked with the left.const UnsignedInt lookButton = TheGlobalData->leftButtonOrders() ? GWM_RIGHT_DOWN : GWM_LEFT_DOWN;- // Classic's look is 1.04's, the press alone: a drag on the radar left the camera where it wasif( drawableList->empty() || msg == lookButton ){radarLookAt( &world );- if( !TheGlobalData->isClassicUI() )- s_radarLookDrag = (msg == GWM_LEFT_DOWN) ? GWM_LEFT_DRAG : GWM_RIGHT_DRAG;- break;- }-- // Classic orders what 1.04's radar ordered: a targeted special power, the attack move- // command, and otherwise a move, whatever the keys held or the units selected- if( TheGlobalData->isClassicUI() )- {- const CommandButton *command = TheInGameUI->getGUICommand();- if( command- && (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)- && BitTest( command->getOptions(), NEED_TARGET_POS ) )- {- TheGameClient->evaluateContextCommand( NULL, &world, CommandTranslator::DO_COMMAND );- }- else if( command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE )- {- GameMessage *order = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );- order->appendLocationArgument( world );- pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_ATTACKMOVETO );- }- else- {- GameMessage *order = TheMessageStream->appendMessage( GameMessage::MSG_DO_MOVETO );- order->appendLocationArgument( world );- pickAndPlayUnitVoiceResponse( drawableList, GameMessage::MSG_DO_MOVETO );- }+ s_radarLookDrag = (msg == GWM_LEFT_DOWN) ? GWM_LEFT_DRAG : GWM_RIGHT_DRAG;break;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 0150cf3e5..983800662 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -4161,11 +4161,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessagem_mouseRightUp = (UnsignedInt) msg->getArgument( 2 )->integer;// a structure waiting to be placed is dropped by the same release, over in- // SelectionXlat, unless the release ended a pan. Classic drops it here on a click, as 1.04- // did, which is also what takes a shortcut bar's sneak attack off the cursor.- if( TheGlobalData->isClassicUI()- && TheMouse->isClick( &m_mouseRightDragAnchor, &m_mouseRightDragLift, NULL, NULL, m_mouseRightDown, m_mouseRightUp ) )- TheInGameUI->placeBuildAvailable( NULL, NULL );+ // SelectionXlat, unless the release ended a panbreak;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cppindex 3028576e8..6fa02cf2e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp@@ -266,37 +266,6 @@ static CommandStatus doGuardCommand( const CommandButton *command, GuardMode gua}-//--------------------------------------------------------------------------------------------------/** Do the attack move command: Classic's attack move button, a GUI command as in 1.04 */-//--------------------------------------------------------------------------------------------------static CommandStatus doAttackMoveCommand( const CommandButton *command, const ICoord2D *mouse )-{-- // sanity- if( command == NULL || mouse == NULL )- return COMMAND_COMPLETE;-- Drawable *draw = TheInGameUI->getFirstSelectedDrawable();- DEBUG_ASSERTCRASH( draw, ("doAttackMoveCommand: No selected object(s)\n") );-- // sanity- if( draw == NULL || draw->getObject() == NULL )- return COMMAND_COMPLETE;-- // convert mouse point to world coords- Coord3D world;- TheTacticalView->screenToTerrain( mouse, &world );-- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );- msg->appendLocationArgument( world );-- // Play the unit voice response- pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_ATTACKMOVETO);-- return COMMAND_COMPLETE;--}-//-------------------------------------------------------------------------------------------------/** Do the set rally point command *///-------------------------------------------------------------------------------------------------@@ -471,12 +440,6 @@ GameMessageDisposition GUICommandTranslator::translateGameMessage(const GameMess} // end special power- case GUI_COMMAND_ATTACK_MOVE:- {- commandStatus = doAttackMoveCommand( command, &mouse );- break;- }-//---------------------------------------------------------------------------------------case GUI_COMMAND_SET_RALLY_POINT:{diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cppindex 65893dfd8..850bb0b01 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -328,20 +328,6 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage{m_lastMouseMoveFrame = TheGameLogic->getFrame();m_anchor = msg->getArgument( 0 )->pixel;-- // Classic is 1.04's scroll, which starts on the press itself, so a click that wobbles- // nudges the camera. Its second press of a quick pair started nothing, as there.- if (TheGlobalData->isClassicUI())- {- if (msg->getType() == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN)- {- m_currentPos = m_anchor;- if (!TheInGameUI->isSelecting() && !m_isScrolling)- setScrolling(SCROLL_RMB);- }- break;- }-m_rightPanArmed = true;break;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex 30715e455..8aef6cbdf 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -287,10 +287,6 @@ SelectionTranslator::SelectionTranslator()m_lastGroupSelGroup = -1;m_selectFeedbackAnchor.x = 0;m_selectFeedbackAnchor.y = 0;- m_deselectFeedbackAnchor.x = 0;- m_deselectFeedbackAnchor.y = 0;- m_lastClick = 0;- m_deselectDownCameraPosition.zero();m_displayedMaxWarning = FALSE;m_selectCountMap.clear();forgetPendingSquads();@@ -579,11 +575,8 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessaDrawable *draw = *it;// buildings and units stay in separate selections, and a double click that// gathers everything of a kind may only gather what a box would - things- // you can click one at a time but never sweep up used to come along. Classic keeps- // 1.04's rule, which put back everything that was selected- const Bool keep = TheGlobalData->isClassicUI() ? (draw && draw->isSelectable())- : (draw && draw->isMassSelectable() && draw->isKindOf( KINDOF_STRUCTURE ) == picked->isKindOf( KINDOF_STRUCTURE ));- if (keep) {+ // you can click one at a time but never sweep up used to come along+ if (draw && draw->isMassSelectable() && draw->isKindOf( KINDOF_STRUCTURE ) == picked->isKindOf( KINDOF_STRUCTURE )) {TheInGameUI->selectDrawable(draw);selectMore->appendObjectIDArgument(draw->getObject()->getID());}@@ -1211,49 +1204,9 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessabreak;}- //------------------------------------------------------------------------------ // Classic measures a right click the way 1.04 did, from this press to the release below- case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:- {- m_deselectFeedbackAnchor = msg->getArgument( 0 )->pixel;- m_lastClick = (UnsignedInt) msg->getArgument( 2 )->integer;- TheTacticalView->getPosition( &m_deselectDownCameraPosition );- break;- }-//-----------------------------------------------------------------------------case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:{- // Classic is 1.04's right release. Only a click counts: the press is the scroll as well- // (LookAtXlat), so a release that travelled, was held, or rode the camera too far is not one.- // The click takes back a waiting GUI command and nothing else, and eats the release, which- // leaves CommandXlat measuring the alternate mouse's right click against the last release- // instead, so that click gives no order either. Otherwise it deselects everyone: always in- // the default mouse, where it is the cancel button, and under the Alternate Mouse Setup only- // with a dozer's structure on the cursor. The structure itself comes off in CommandXlat.- if( TheGlobalData->isClassicUI() )- {- Coord3D cameraAtRelease;- TheTacticalView->getPosition( &cameraAtRelease );- const ICoord2D release = msg->getArgument( 0 )->pixel;- if( !TheMouse->isClick( &m_deselectFeedbackAnchor, &release,- &m_deselectDownCameraPosition, &cameraAtRelease,- m_lastClick, (UnsignedInt) msg->getArgument( 2 )->integer ) )- break;-- if( TheInGameUI->getGUICommand() )- {- TheInGameUI->setGUICommand( NULL );- disp = DESTROY_MESSAGE;- TheInGameUI->setScrolling( FALSE );- }- else if( TheGlobalData->leftButtonOrders() || TheInGameUI->getPendingPlaceSourceObjectID() != INVALID_ID )- {- deselectAll();- }- break;- }-// a right drag panned the camera, and a pan takes nothing back: a player can look around// with a structure on the cursor or a GUI command waiting and still have it on releaseif( TheLookAtTranslator->isRightDragPanning() )@@ -1266,6 +1219,18 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessabreak;}+ // Classic is the game as shipped: a right click with nothing armed deselects everyone, and+ // with something armed it only takes that back, below. A right drag panned and is gone above.+ // Under EA's Alternate Mouse Setup that click is the order instead (CommandXlat) and+ // deselects nothing.+ if( TheGlobalData->isClassicUI() && TheInGameUI->getGUICommand() == NULL+ && TheInGameUI->getPendingPlaceType() == NULL )+ {+ if( TheGlobalData->leftButtonOrders() )+ deselectAll();+ break;+ }+//// The right button drops whatever is armed, and it does so on a release that wobbled as// well as on a strict click. A dozer placing a row of structures with shift held is thediff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cppindex 82208973d..1c88780ed 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp@@ -1101,12 +1101,19 @@ Real AI::getAdjustedVisionRangeForObject(const Object *object, Int factorsToCons* expansions, extra buildings and tactical fighting stay on Hard, and the two measured columns* above were left where the matches put them.*+ * gate, answer and massU came in on 2026-10-09 and none of them moved Hard against Hard: over 24+ * matches a condition on Twilight Flame, Winter Wolf and Tournament Desert, a side with all three+ * won 5 where the side without won 4, at the same value lost for value killed. Against the+ * overlordrush scenario gate and answer together cut the sends into a fight the matchup loses+ * from 48% to 40% and stragglers from 17% to 14% of deaths; massU on top shortened the matches+ * and lost more for what it killed (0.70 against 0.64), so it stays off until it earns its place.+ ** scoutS maxSc decis cntr mass ttk indiv team infl focus save harv expand guard hoard econ micro gate answer massU */static const AIDifficultyProfile s_defaultSkillLadder[ AISKILL_COUNT ] ={/* Easy */ { 75.0f, 1, 7.0f, 0.00f, FALSE, 0.00f, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE, FALSE },/* Medium */ { 45.0f, 1, 3.0f, 0.50f, FALSE, 0.35f, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, 6000, FALSE, FALSE, FALSE, FALSE, FALSE },- /* Brutal */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, FALSE, FALSE, FALSE }+ /* Brutal */ { 25.0f, 2, 1.5f, 1.00f, TRUE, 0.50f, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 4000, TRUE, TRUE, TRUE, TRUE, FALSE }};//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cppindex f49d58a0b..477ddad0c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp@@ -102,14 +102,32 @@* whichever code happens to ask while the building is in view: the drawing loop, run for every* player only on an observer's machine, so two machines could think different things.*- * observerNdx < 0 is the old omniscient answer, for callers that are not one player's thinking. */+ * observerNdx < 0 is the old omniscient answer, for callers that are not one player's thinking.+ *+ * A stealthed unit nobody has detected is unknown to anyone but its own side, wherever it stands:+ * a hidden Burton walking into the base drew the whole army after him (issue #64). The rule is the+ * one PartitionFilterStealthedAndUndetected applies to a unit choosing its target, bomb trucks+ * included: one disguised as the observer's enemy is seen, one dressed as his friend is not. */static Bool observerKnowsAbout( const Object *obj, Int observerNdx ){if( obj == NULL )return FALSE;if( observerNdx < 0 )return TRUE;- return !obj->isUnknownTo( observerNdx );+ if( obj->isUnknownTo( observerNdx ) )+ return FALSE;+ if( !obj->testStatus( OBJECT_STATUS_STEALTHED ) || obj->testStatus( OBJECT_STATUS_DETECTED ) )+ return TRUE;+ const Player *observer = ThePlayerList->getNthPlayer( observerNdx );+ if( observer->getRelationship( obj->getTeam() ) == ALLIES )+ return TRUE;+ if( !obj->isKindOf( KINDOF_DISGUISER ) )+ return FALSE;+ const StealthUpdate *stealth = obj->getStealth();+ if( !obj->testStatus( OBJECT_STATUS_DISGUISED ) || stealth == NULL || !stealth->isDisguised() )+ return TRUE;+ const Player *dressedAs = ThePlayerList->getNthPlayer( stealth->getDisguisedPlayerIndex() );+ return observer->getRelationship( dressedAs->getDefaultTeam() ) == ENEMIES;}/** What a unit is worth in a fight, for every decision here that has to weigh one force against@@ -362,6 +380,9 @@ m_role(AIROLE_AGGRESSIVE)m_pressure = AIPRESSURE_NORMAL;m_knownEnemyPower = 0.0f;m_pressureEnemy = -1;+ m_massTemplate = NULL;+ m_massPickFrame = 0;+ m_massSince = 0;for( Int strike = 0; strike < MAX_REMEMBERED_STRIKES; ++strike ){@@ -2631,6 +2652,14 @@ static Real armyAdvantage( const std::vector<AIVisibleEnemy> &mine, const std::vreturn aiArmyAdvantage( &myValue[ 0 ], (Int)myValue.size(), &theirValue[ 0 ], (Int)theirValue.size(), &score[ 0 ] );}+/** One unit into an army by kind, at its combat power, when an army is being kept. */+static void addToArmy( std::vector<AIVisibleEnemy> *army, const Object *obj )+{+ const Real power = aiCombatPower( obj );+ if( army && power > 0.0f && !obj->isEffectivelyDead() )+ addToVisibleArmy( army, obj->getTemplate(), obj->getControllingPlayer(), power );+}+/** How often the ledger of seen enemies is brought up to date, and how long a unit nobody has seen is* still believed in. Three minutes is long enough for an army that walked back into the fog to be* remembered when it walks out again, and short enough that one the AI never saw die is let go. */@@ -2813,7 +2842,32 @@ void AIPlayer::computeEnemyComposition( AIEnemyComposition *out, std::vector<AIVReal air = 0.0f, armour = 0.0f, infantry = 0.0f, stealth = 0.0f, total = 0.0f;const Int me = m_player->getPlayerIndex();- for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i )+ // AnswerArmy: the army it remembers, not the part of it in sight this second. Ten Overlords that+ // rolled back behind the fog are still ten Overlords, and the counter has to be on order before they+ // come back, not after+ if( getSkillProfile()->m_answerArmy )+ {+ for( std::map<ObjectID, SeenEnemy>::const_iterator it = m_seenEnemies.begin(); it != m_seenEnemies.end(); ++it )+ {+ const ThingTemplate *tmpl = it->second.tmpl;+ const Player *owner = ThePlayerList->getNthPlayer( it->second.owner );+ const Real threat = templateCombatPower( tmpl, owner );+ if( threat <= 0.0f )+ continue;+ total += threat;+ if( army != NULL )+ addToVisibleArmy( army, tmpl, owner, threat );+ if( tmpl->isKindOf( KINDOF_AIRCRAFT ) ) air += threat;+ if( tmpl->isKindOf( KINDOF_VEHICLE ) ) armour += threat;+ if( tmpl->isKindOf( KINDOF_INFANTRY ) ) infantry += threat;+ if( it->second.stealth ) stealth += threat;+ if( tmpl->isKindOf( KINDOF_INFANTRY ) )+ ++out->m_infantryCount;+ else if( tmpl->isKindOf( KINDOF_VEHICLE ) && !tmpl->isKindOf( KINDOF_AIRCRAFT ) )+ ++out->m_vehicleCount;+ }+ }+ else for( Int i = 0; i < ThePlayerList->getPlayerCount(); ++i ){Player *p = ThePlayerList->getNthPlayer( i );if( p == NULL || p == m_player )@@ -2967,6 +3021,22 @@ Bool AIPlayer::selectTeamToBuild( void )const Real COUNTER_SPAN = 20.0f;const Real ROLE_SPAN = 10.0f;+ // AnswerArmy: the one kind of unit that makes up a third or more of the army it remembers, which a+ // team that it hard-counters should not be built into. Crusaders went on coming off the line into+ // ten Overlords because the rest of the score still liked them+ const Real DOMINANT_SHARE = 0.3f;+ const Real HARD_COUNTERED = 0.25f;+ std::vector<AIVisibleEnemy> dominant;+ if( profile->m_answerArmy && enemy.m_totalThreat > 0.0f )+ {+ size_t top = 0;+ for( size_t k = 1; k < army.size(); ++k )+ if( army[ k ].m_weight > army[ top ].m_weight )+ top = k;+ if( !army.empty() && army[ top ].m_weight >= DOMINANT_SHARE * enemy.m_totalThreat )+ dominant.push_back( army[ top ] );+ }+Player::PlayerTeamList candidateList;Int count = 0;Real bestScore = 0.0f;@@ -2981,6 +3051,8 @@ Bool AIPlayer::selectTeamToBuild( void )aiCounterScore( enemy, teamCapability( *t, m_player, army ) );if( (m_role == AIROLE_DEFENSIVE) == (isDefenceTeam != FALSE) )score += ROLE_SPAN;+ if( !dominant.empty() && !isDefenceTeam && teamCapability( *t, m_player, dominant ).m_answer < HARD_COUNTERED )+ score -= COUNTER_SPAN;if( !haveBest || score > bestScore ){@@ -4687,6 +4759,8 @@ void AIPlayer::update( void )AI_PHASE( AIP_POWER, doPower() ); // Keep the lights on, and out of reach.AI_PHASE( AIP_ECONOMY, doSuperweapons() ); // The big guns, as soon as they can be bought.AI_PHASE( AIP_WAVE, rememberEnemies() ); // Write down the enemy army in sight.+ AI_PHASE( AIP_WAVE, answerArmy() ); // Train the answer to the part of it nothing answers.+ AI_PHASE( AIP_WAVE, doMass() ); // Build the fist, and send it when it is one.AI_PHASE( AIP_WAVE, doWaves() ); // Send the parked attack teams out together.AI_PHASE( AIP_TACTICS, doTactics() ); // Fight each unit from where it is strongest.AI_PHASE( AIP_TACTICS, doTransports() ); // Put the helicopters' riders down at the fight.@@ -6658,7 +6732,8 @@ static void findDefenseUnderConstruction( Object *obj, void *userData )/** The fighting unit off this factory's buttons that answers one kind of intruder best, money for* money, and the dearer of two that answer it equally. Not a worker, a gatherer, a hacker or an* aircraft: a jet flies its sortie and goes home, and the fight is at the door. */-static const ThingTemplate *bestDefender( Object *factory, const Player *owner, const AIVisibleEnemy &enemy )+static const ThingTemplate *bestDefender( Object *factory, const Player *owner, const AIVisibleEnemy &enemy,+ Bool allowHelicopters = FALSE, Real *outScore = NULL ){const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );if( commandSet == NULL )@@ -6673,8 +6748,10 @@ static const ThingTemplate *bestDefender( Object *factory, const Player *owner,if( button == NULL || button->getCommandType() != GUI_COMMAND_UNIT_BUILD )continue;const ThingTemplate *tmpl = button->getThingTemplate();+ // a helicopter fights where the army is and stays there, which a jet does not+ const Bool aircraftAllowed = allowHelicopters && tmpl && tmpl->isKindOf( KINDOF_PRODUCED_AT_HELIPAD );if( tmpl == NULL || !tmpl->canPossiblyHaveAnyWeapon() || tmpl->isKindOf( KINDOF_DOZER ) || tmpl->isKindOf( KINDOF_HARVESTER ) ||- tmpl->isKindOf( KINDOF_MONEY_HACKER ) || tmpl->isKindOf( KINDOF_AIRCRAFT ) ||+ tmpl->isKindOf( KINDOF_MONEY_HACKER ) || (tmpl->isKindOf( KINDOF_AIRCRAFT ) && !aircraftAllowed) ||TheBuildAssistant->canMakeUnit( factory, tmpl ) != CANMAKE_OK )continue;@@ -6688,6 +6765,8 @@ static const ThingTemplate *bestDefender( Object *factory, const Player *owner,bestCost = cost;}}+ if( outScore )+ *outScore = bestScore;return best;}@@ -6809,14 +6888,22 @@ void AIPlayer::defendHome( void )// it: a rushed China sent its Tank Hunters out by twos into sixteen rebels and lost them, where they// had stood by the Gattling Cannon and let it do the workReal homePower = 0.0f;+ std::vector<AIVisibleEnemy> home;for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o ){if( !(*o)->isEffectivelyDead() && !(*o)->isKindOf( KINDOF_STRUCTURE ) && isAtHome( (*o)->getPosition() ) && leavesToFinish( *o ) )+ {homePower += aiCombatPower( *o );+ addToArmy( &home, *o );+ }}Real intruderWorth = 0.0f;for( std::vector<AIVisibleEnemy>::const_iterator k = army.begin(); k != army.end(); ++k )intruderWorth += k->m_weight;+ // by unit against unit as well as price: four Tank Hunters are a match for two Overlords that cost as+ // much again, and four Crusaders are not. The advantage is the square law's, so its root scales power+ if( getSkillProfile()->m_engageGate )+ homePower *= (Real)sqrt( armyAdvantage( home, army ) );if( homePower < 0.5f * intruderWorth )return;@@ -6838,6 +6925,380 @@ void AIPlayer::defendHome( void )m_player->getPlayerIndex(), sent, intruder->getPosition()->x, intruder->getPosition()->y));}+/** How often the army is looked at for a part of the enemy's nothing answers, how big a part has to be+ * before a factory is turned over to it, what counts as an answer money for money, and what the bank+ * keeps back for the team plan. */+static const Int ANSWER_RATE = 10 * LOGICFRAMES_PER_SECOND;+static const Real ANSWER_MIN_GAP = 1500.0f;+static const Real ANSWER_SCORE = 0.6f;+static const Int ANSWER_RESERVE = 1000;++/** Count a unit of ours against the enemy kind it answers (ANSWER_SCORE) that has the most of its worth+ * still unanswered. Not the one it answers best: a Missile Defender answers a Battlemaster even better+ * than an Overlord, and counted that way, two Battlemasters at home soaked up every one trained against+ * twenty Overlords. */+static void creditWhereNeeded( const ThingTemplate *tmpl, const Player *owner, const std::vector<AIVisibleEnemy> &army, std::vector<Real> *answered )+{+ if( tmpl == NULL || !tmpl->canPossiblyHaveAnyWeapon() )+ return;+ const Real cost = INT_TO_REAL( tmpl->calcCostToBuild( owner ) );+ Int best = -1;+ for( size_t k = 0; k < army.size(); ++k )+ {+ if( aiMatchupScore( templateFramesToKill( tmpl, army[ k ].m_template ), templateFramesToKill( army[ k ].m_template, tmpl ),+ cost, army[ k ].m_cost ) < ANSWER_SCORE )+ continue;+ if( best < 0 || army[ k ].m_weight - (*answered)[ k ] > army[ best ].m_weight - (*answered)[ best ] )+ best = (Int)k;+ }+ if( best >= 0 )+ (*answered)[ best ] += cost;+}++//----------------------------------------------------------------------------------------------------------+/** B1/B3 outside an emergency. defendHome trained the right answer to whatever stood in the base; the+ * rest of the match the AI built from the script's team list, weighted by what it could see that+ * second, and the skirmish scripts' own counter teams wait for fifteen enemy tanks. A player with ten+ * Overlords was answered by Crusaders until they reached the base. So every ten seconds the enemy army+ * the AI remembers is set against its own: each of its units, and each one on order, counts against+ * the enemy kind it answers best, if it answers it at all (ANSWER_SCORE). The kind with the most of+ * its worth unanswered gets one of its best answer from every idle factory that has one, helicopters+ * included, while the bank holds the price and a reserve. */+//----------------------------------------------------------------------------------------------------------+void AIPlayer::answerArmy( void )+{+ if( !isSkirmishAI() || !m_baseCenterSet || !getSkillProfile()->m_answerArmy ||+ (TheGameLogic->getFrame() + computeUpdatePhase( m_player->getPlayerIndex(), ANSWER_RATE )) % ANSWER_RATE != 0 )+ return;+ if( isBaseUnderAttack() )+ return; // defendHome's+ std::vector<AIVisibleEnemy> army;+ rememberedArmy( &army );+ if( army.empty() )+ return;++ std::vector<Object *> owned;+ m_player->iterateObjects( collectOwned, &owned );+ std::vector<Object *> factories;+ m_player->iterateObjects( collectFactories, &factories );+ std::vector<Real> answered( army.size(), 0.0f );+ for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )+ if( !(*o)->isEffectivelyDead() && !(*o)->isKindOf( KINDOF_STRUCTURE ) && leavesToFinish( *o ) )+ creditWhereNeeded( (*o)->getTemplate(), m_player, army, &answered );+ for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end(); ++f )+ {+ const ProductionUpdateInterface *pu = (*f)->getProductionUpdateInterface();+ for( const ProductionEntry *entry = pu->firstProduction(); entry; entry = pu->nextProduction( entry ) )+ if( entry->getProductionType() == PRODUCTION_UNIT )+ creditWhereNeeded( entry->getProductionObject(), m_player, army, &answered );+ }++ size_t kind = 0;+ for( size_t k = 1; k < army.size(); ++k )+ if( army[ k ].m_weight - answered[ k ] > army[ kind ].m_weight - answered[ kind ] )+ kind = k;+ const Real gap = army[ kind ].m_weight - answered[ kind ];+ if( gap < ANSWER_MIN_GAP )+ return;++ for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end() && answered[ kind ] < army[ kind ].m_weight; ++f )+ {+ ProductionUpdateInterface *pu = (*f)->getProductionUpdateInterface();+ if( pu->getProductionCount() > 1 )+ continue; // one behind the unit in hand at most: the team plan keeps the rest of the queue, and its mix+ Real score = 0.0f;+ const ThingTemplate *unit = bestDefender( *f, m_player, army[ kind ], TRUE, &score );+ if( unit == NULL || score < ANSWER_SCORE )+ continue;+ const Int cost = unit->calcCostToBuild( m_player );+ if( m_player->getMoney()->countMoney() < (UnsignedInt)(cost + ANSWER_RESERVE) || !pu->queueCreateUnit( unit, pu->requestUniqueUnitID() ) )+ continue;+ answered[ kind ] += INT_TO_REAL( cost );+ DEBUG_LOG(("AI ANSWER frame %d player %d trains '%s' at '%s' against '%s', %.0f of %.0f unanswered, score %.2f, %d in the bank\n",+ TheGameLogic->getFrame(), m_player->getPlayerIndex(), unit->getName().str(), (*f)->getTemplate()->getName().str(),+ army[ kind ].m_template->getName().str(), gap, army[ kind ].m_weight, score, m_player->getMoney()->countMoney()));+ }+}++/** The fist. How often it is looked at; what the enemy army has to be worth before a unit is picked+ * against it, and how long a dropped pick waits before the next; how good an enemy kind has to be+ * against the unit to count as his answer, and how much of his army that answer has to be before the+ * unit is dropped; how good the unit has to be against his army to be picked; how big a fist goes,+ * and what the bank keeps back for the team plan. */+static const Int MASS_RATE = 5 * LOGICFRAMES_PER_SECOND;+static const Real MASS_MIN_ENEMY = 2000.0f;+static const UnsignedInt MASS_REPICK_FRAMES = 60 * LOGICFRAMES_PER_SECOND;+static const Real MASS_COUNTERED = 0.7f;+static const Real MASS_DROP_SHARE = 0.3f;+static const Real MASS_PICK_SHARE = 0.2f;+static const Real MASS_MIN_EFFICIENCY = 0.55f;+static const Real MASS_FIST_POWER = 6000.0f;+static const Real MASS_FIST_MAX_POWER = 18000.0f;+static const Int MASS_FIST_MAX_UNITS = 14;+static const UnsignedInt MASS_HOLD_FRAMES = 120 * LOGICFRAMES_PER_SECOND;+static const UnsignedInt MASS_MAX_HOLD_FRAMES = 180 * LOGICFRAMES_PER_SECOND;+static const Int MASS_RESERVE = 1500;++/** This factory has a button for that unit. */+static Bool factoryOffers( Object *factory, const ThingTemplate *tmpl )+{+ const CommandSet *commandSet = TheControlBar->findCommandSet( factory->getCommandSetString() );+ for( Int i = 0; commandSet && i < MAX_COMMANDS_PER_SET; ++i )+ {+ const CommandButton *button = commandSet->getCommandButton( i );+ if( button && button->getCommandType() == GUI_COMMAND_UNIT_BUILD && button->getThingTemplate() == tmpl )+ return TRUE;+ }+ return FALSE;+}++/** The unit for the fist: of everything the factories can train now, the one that does best, money for+ * money, against the army this AI remembers, and that nothing in that army is already good against+ * (MASS_COUNTERED). NULL when none does well enough. */+const ThingTemplate *AIPlayer::pickMassUnit( const std::vector<AIVisibleEnemy> &army, Real *efficiency ) const+{+ std::vector<Object *> factories;+ m_player->iterateObjects( collectFactories, &factories );+ const ThingTemplate *best = NULL;+ Real bestEfficiency = 0.0f;+ Int bestCost = 0;+ for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end(); ++f )+ {+ const CommandSet *commandSet = TheControlBar->findCommandSet( (*f)->getCommandSetString() );+ for( Int i = 0; commandSet && i < MAX_COMMANDS_PER_SET; ++i )+ {+ const CommandButton *button = commandSet->getCommandButton( i );+ if( button == NULL || button->getCommandType() != GUI_COMMAND_UNIT_BUILD )+ continue;+ const ThingTemplate *tmpl = button->getThingTemplate();+ if( tmpl == NULL || !tmpl->canPossiblyHaveAnyWeapon() || tmpl->isKindOf( KINDOF_DOZER ) || tmpl->isKindOf( KINDOF_HARVESTER ) ||+ tmpl->isKindOf( KINDOF_MONEY_HACKER ) || tmpl->isKindOf( KINDOF_HERO ) ||+ (tmpl->isKindOf( KINDOF_AIRCRAFT ) && !tmpl->isKindOf( KINDOF_PRODUCED_AT_HELIPAD )) ||+ TheBuildAssistant->canMakeUnit( *f, tmpl ) != CANMAKE_OK )+ continue;+ const Int cost = tmpl->calcCostToBuild( m_player );+ if( cost <= 0 )+ continue;+ Real weighed = 0.0f, scored = 0.0f, countered = 0.0f;+ for( std::vector<AIVisibleEnemy>::const_iterator k = army.begin(); k != army.end(); ++k )+ {+ const Real mineFrames = templateFramesToKill( tmpl, k->m_template );+ const Real theirFrames = templateFramesToKill( k->m_template, tmpl );+ scored += k->m_weight * aiMatchupScore( mineFrames, theirFrames, INT_TO_REAL( cost ), k->m_cost );+ weighed += k->m_weight;+ if( aiMatchupScore( theirFrames, mineFrames, k->m_cost, INT_TO_REAL( cost ) ) >= MASS_COUNTERED )+ countered += k->m_weight;+ }+ // an answer in his army is one that is a real part of it: a pair of Gattling tanks at home do not+ // make every rifle a bad idea against twenty Overlords. Below the share that drops a pick, so a+ // pick is not dropped on the next look+ if( weighed <= 0.0f || countered >= MASS_PICK_SHARE * weighed )+ continue;+ const Real e = scored / weighed;+ if( best == NULL || e > bestEfficiency || (e == bestEfficiency && cost > bestCost) )+ {+ best = tmpl;+ bestEfficiency = e;+ bestCost = cost;+ }+ }+ }+ *efficiency = bestEfficiency;+ return bestEfficiency >= MASS_MIN_EFFICIENCY ? best : NULL;+}++Bool AIPlayer::isMassUnit( ObjectID id ) const+{+ return std::find( m_massUnits.begin(), m_massUnits.end(), id ) != m_massUnits.end();+}++//----------------------------------------------------------------------------------------------------------+/** A player who finds a unit the other side has no answer to builds nothing else and hits with all of+ * it at once. The AI built the script's mix, every unit of it in some team's three or four. So it+ * picks one: the unit doing best, money for money, against the enemy army it remembers, that nothing+ * in that army is already good against. Every idle factory that can trains it while the bank holds+ * its price and a reserve (the team plan keeps the busy ones, and its mix: anti-air, repair, counters).+ * The ones that come out wait together at the staging point, out of the waves, until they are a fist:+ * a wave's worth, or three quarters of the enemy army, up to three waves or fourteen units. Then the+ * fist goes as one wave, with whatever is parked. When the enemy starts fielding its answer, a third+ * of his army that is good against it, the pick is dropped, what was held goes back to the waves, and a+ * new unit is picked a minute later. */+//----------------------------------------------------------------------------------------------------------+void AIPlayer::doMass( void )+{+ const UnsignedInt now = TheGameLogic->getFrame();+ if( !isSkirmishAI() || !m_baseCenterSet || !getSkillProfile()->m_massUnit ||+ (now + computeUpdatePhase( m_player->getPlayerIndex(), MASS_RATE )) % MASS_RATE != 0 )+ return;+ Player *enemy = getAiEnemy();+ if( enemy == NULL )+ return;++ // the fist so far: still alive and still ours+ for( std::vector<ObjectID>::iterator it = m_massUnits.begin(); it != m_massUnits.end(); )+ {+ const Object *obj = TheGameLogic->findObjectByID( *it );+ if( obj == NULL || obj->isEffectivelyDead() || obj->getControllingPlayer() != m_player )+ it = m_massUnits.erase( it );+ else+ ++it;+ }++ std::vector<AIVisibleEnemy> army;+ rememberedArmy( &army );+ Real armyPower = 0.0f;+ for( std::vector<AIVisibleEnemy>::const_iterator k = army.begin(); k != army.end(); ++k )+ armyPower += k->m_weight;++ if( m_massTemplate && armyPower > 0.0f )+ {+ const Real cost = INT_TO_REAL( m_massTemplate->calcCostToBuild( m_player ) );+ Real countered = 0.0f;+ for( std::vector<AIVisibleEnemy>::const_iterator k = army.begin(); k != army.end(); ++k )+ if( aiMatchupScore( templateFramesToKill( k->m_template, m_massTemplate ), templateFramesToKill( m_massTemplate, k->m_template ),+ k->m_cost, cost ) >= MASS_COUNTERED )+ countered += k->m_weight;+ if( countered >= MASS_DROP_SHARE * armyPower )+ {+ DEBUG_LOG(("AI MASS frame %d player %d drops '%s': %.0f of the %.0f army it remembers answers it, %d held go back to the waves\n",+ now, m_player->getPlayerIndex(), m_massTemplate->getName().str(), countered, armyPower, (Int)m_massUnits.size()));+ m_massTemplate = NULL;+ m_massPickFrame = now;+ m_massUnits.clear();+ return;+ }+ }+ if( m_massTemplate == NULL )+ {+ if( armyPower < MASS_MIN_ENEMY || (m_massPickFrame != 0 && now - m_massPickFrame < MASS_REPICK_FRAMES) )+ return;+ Real efficiency = 0.0f;+ m_massTemplate = pickMassUnit( army, &efficiency );+ m_massPickFrame = now;+ if( m_massTemplate == NULL )+ {+ DEBUG_LOG(("AI MASS frame %d player %d finds nothing to mass against the %.0f army it remembers, best %.2f\n",+ now, m_player->getPlayerIndex(), armyPower, efficiency));+ return;+ }+ DEBUG_LOG(("AI MASS frame %d player %d picks '%s', %.2f money for money against the %.0f army it remembers\n",+ now, m_player->getPlayerIndex(), m_massTemplate->getName().str(), efficiency, armyPower));+ }++ // new ones off the line join the fist+ for( DLINK_ITERATOR<Object> m = m_player->getDefaultTeam()->iterate_TeamMemberList(); !m.done(); m.advance() )+ {+ Object *obj = m.cur();+ if( obj->getTemplate() == m_massTemplate && !obj->isEffectivelyDead() && !obj->isContained() && obj->getAI() &&+ isAtHome( obj->getPosition() ) && !isMassUnit( obj->getID() ) )+ {+ if( m_massUnits.empty() )+ m_massSince = now;+ m_massUnits.push_back( obj->getID() );+ }+ }++ const Bool underAttack = isBaseUnderAttack();+ if( !underAttack )+ {+ std::vector<Object *> factories;+ m_player->iterateObjects( collectFactories, &factories );+ const Int cost = m_massTemplate->calcCostToBuild( m_player );+ for( std::vector<Object *>::const_iterator f = factories.begin(); f != factories.end(); ++f )+ {+ ProductionUpdateInterface *pu = (*f)->getProductionUpdateInterface();+ if( pu->getProductionCount() > 0 || !factoryOffers( *f, m_massTemplate ) ||+ TheBuildAssistant->canMakeUnit( *f, m_massTemplate ) != CANMAKE_OK ||+ m_player->getMoney()->countMoney() < (UnsignedInt)(cost + MASS_RESERVE) )+ continue;+ if( pu->queueCreateUnit( m_massTemplate, pu->requestUniqueUnitID() ) )+ DEBUG_LOG(("AI MASS frame %d player %d trains '%s' at '%s', %d in the fist, %d in the bank\n", now,+ m_player->getPlayerIndex(), m_massTemplate->getName().str(), (*f)->getTemplate()->getName().str(),+ (Int)m_massUnits.size(), m_player->getMoney()->countMoney()));+ }+ }++ Real power = 0.0f;+ for( std::vector<ObjectID>::const_iterator it = m_massUnits.begin(); it != m_massUnits.end(); ++it )+ power += aiCombatPower( TheGameLogic->findObjectByID( *it ) );+ Real target = 0.75f * armyPower;+ if( target < MASS_FIST_POWER ) target = MASS_FIST_POWER;+ if( target > MASS_FIST_MAX_POWER ) target = MASS_FIST_MAX_POWER;+ const Int pathSuffix = enemy->getMpStartIndex() + 1;++ // a fist the factories cannot finish goes anyway, half a wave after two minutes and whatever it is+ // after three: held for good, the units of the pick were missing from every wave for the whole match+ const UnsignedInt held = m_massUnits.empty() ? 0 : now - m_massSince;+ const Bool ready = power >= target || (Int)m_massUnits.size() >= MASS_FIST_MAX_UNITS ||+ (held >= MASS_HOLD_FRAMES && power >= 0.5f * MASS_FIST_POWER) || held >= MASS_MAX_HOLD_FRAMES;+ if( !underAttack && !m_massUnits.empty() && ready )+ {+ AIGroup *fist = TheAI->createGroup();+ for( std::vector<ObjectID>::const_iterator it = m_massUnits.begin(); it != m_massUnits.end(); ++it )+ {+ Object *obj = TheGameLogic->findObjectByID( *it );+ if( obj && !obj->isContained() )+ fist->add( obj );+ }+ Int teams = 0;+ Real total = power;+ for( Int i = 0; i < MAX_HELD_TEAMS; ++i )+ {+ if( !m_heldUsed[ i ] )+ continue;+ m_heldUsed[ i ] = FALSE;+ Team *team = TheTeamFactory->findTeamByID( m_heldTeam[ i ] );+ if( team )+ {+ total += waitingPower( team, fist );+ ++teams;+ }+ }+ total += addHomeStrays( fist ); // which leaves the fist's own to it+ m_massUnits.clear();+ if( fist->isEmpty() )+ {+ TheAI->destroyGroup( fist );+ return;+ }+ Coord3D center;+ fist->getCenter( ¢er );+ DEBUG_LOG(("AI MASS frame %d player %d sends the fist of '%s', %.0f power of %.0f wanted after %d s, with %d parked teams\n", now,+ m_player->getPlayerIndex(), m_massTemplate->getName().str(), power, target, held / LOGICFRAMES_PER_SECOND, teams));+ sendWave( fist, chooseApproachLabel( ¢er, AsciiString( "Center" ), pathSuffix ), pathSuffix, teams, total, 0, "fist" );+ return;+ }++ // the rest wait together where the waves gather, out of the way of the factories' doors+ Coord3D staging = m_baseCenter;+ Coord3D enemyPos;+ if( enemyStartGuess( enemy->getPlayerIndex(), &enemyPos ) )+ {+ Coord2D toward;+ toward.x = enemyPos.x - m_baseCenter.x;+ toward.y = enemyPos.y - m_baseCenter.y;+ if( toward.length() > 0.0f )+ {+ toward.normalize();+ staging.x += toward.x * m_baseRadius;+ staging.y += toward.y * m_baseRadius;+ }+ }+ AIGroup *waiting = NULL;+ for( std::vector<ObjectID>::const_iterator it = m_massUnits.begin(); it != m_massUnits.end(); ++it )+ {+ Object *obj = TheGameLogic->findObjectByID( *it );+ if( obj == NULL || obj->isContained() || !obj->getAI()->isIdle() ||+ sqr( obj->getPosition()->x - staging.x ) + sqr( obj->getPosition()->y - staging.y ) <= sqr( 0.5f * m_baseRadius ) )+ continue;+ if( waiting == NULL )+ waiting = TheAI->createGroup();+ waiting->add( obj );+ }+ if( waiting )+ waiting->groupTightenToPosition( &staging, FALSE, CMD_FROM_AI );+}+/** What a team has to put into a wave, and those members into the group when one is given. Not the* members already out on orders. A team is topped up at home while the rest of it fights, and the* wave code took the team whole: one Hard USA's 'Artillery F' had three new members idle at home, was@@ -7204,7 +7665,21 @@ void AIPlayer::updatePressure( void )if( his.power > m_knownEnemyPower )m_knownEnemyPower = his.power;- const Real chance = aiWinChance( mine.power, m_knownEnemyPower );+ // what the two armies are worth to each other, unit against unit, as well as by price: a Crusader+ // army against Overlords it has seen is worth less than its money says+ Real myPower = mine.power;+ if( getSkillProfile()->m_engageGate )+ {+ std::vector<Object *> owned;+ m_player->iterateObjects( collectOwned, &owned );+ std::vector<AIVisibleEnemy> myArmy, theirArmy;+ for( std::vector<Object *>::const_iterator o = owned.begin(); o != owned.end(); ++o )+ if( !(*o)->isKindOf( KINDOF_STRUCTURE ) && !(*o)->isKindOf( KINDOF_MONEY_HACKER ) && !(*o)->isKindOf( KINDOF_PROJECTILE ) )+ addToArmy( &myArmy, *o );+ rememberedArmy( &theirArmy );+ myPower *= (Real)sqrt( armyAdvantage( myArmy, theirArmy ) );+ }+ const Real chance = aiWinChance( myPower, m_knownEnemyPower );AIPressure level = aiPressureLevel( chance, baseInSight, m_pressure );// the guards stay while anybody else is still in the game to walk into the base they left@@ -7221,8 +7696,8 @@ void AIPlayer::updatePressure( void )if( level == m_pressure )return;static const char *const names[ AIPRESSURE_COUNT ] = { "defend", "normal", "press", "finish" };- DEBUG_LOG(("AI PRESSURE frame %d player %d chance %.2f level %s, %.0f power against %.0f believed\n", TheGameLogic->getFrame(),- me, chance, names[ level ], mine.power, m_knownEnemyPower));+ DEBUG_LOG(("AI PRESSURE frame %d player %d chance %.2f level %s, %.0f power (%.0f by the units) against %.0f believed\n", TheGameLogic->getFrame(),+ me, chance, names[ level ], mine.power, myPower, m_knownEnemyPower));m_pressure = level;}@@ -7447,7 +7922,7 @@ static void collectBoardingGoals( Object *obj, void *userData )Bool AIPlayer::isGunshipRider( const Object *obj ) const{return obj->isKindOf( KINDOF_INFANTRY ) && !obj->isKindOf( KINDOF_HERO ) && obj->isSelectable() && !obj->isContained() &&- !obj->isEffectivelyDead() && obj->getAI() && leavesToFinish( obj );+ !obj->isEffectivelyDead() && obj->getAI() && leavesToFinish( obj ) && !isMassUnit( obj->getID() );}/** An infantryman who rides out with the army, where loadGunships puts him. */@@ -7937,8 +8412,8 @@ Real AIPlayer::addHomeStrays( AIGroup *wave ) const{Object *obj = m.cur();if( obj->isEffectivelyDead() || obj->getAI() == NULL || obj->isContained() || obj->isKindOf( KINDOF_IMMOBILE ) ||- !isAtHome( obj->getPosition() ) || !leavesToFinish( obj ) )- continue;+ !isAtHome( obj->getPosition() ) || !leavesToFinish( obj ) || isMassUnit( obj->getID() ) )+ continue; // the fist goes as one, when it is one (doMass)const StateID state = obj->getAI()->getCurrentStateID();if( state != AI_IDLE && state != AI_GUARD && state != AI_GUARD_RETALIATE )continue;@@ -9515,15 +9990,13 @@ void AIPlayer::doRetreats( void )if( isAtHome( ¢re ) )continue;- Real myHealth = 0.0f, myPower = 0.0f;Real enemyHealth = 0.0f, enemyPower = 0.0f;std::vector<Real> enemyGuns;- measureFight( ¢re, FALSE, &myHealth, &myPower, &enemyHealth, &enemyPower, &enemyGuns );+ const Real ratio = fightRatio( ¢re, FALSE, &enemyHealth, &enemyPower, &enemyGuns );if( enemyPower <= 0.0f )continue; // not in a fight- const Real ratio = aiRetreatRatio( myHealth, myPower, enemyHealth, enemyPower );if( ratio >= profile->m_retreatTtkRatio )continue; // holding, or winning@@ -9639,8 +10112,11 @@ static Bool heldFrom( Bool fallingBack, const Coord3D *from, const Coord3D *cent}void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myHealth, Real *myPower,- Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns )+ Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns, Real *advantage ){+ std::vector<AIVisibleEnemy> mine, theirs;+ std::vector<AIVisibleEnemy> *myKinds = advantage ? &mine : NULL;+ std::vector<AIVisibleEnemy> *theirKinds = advantage ? &theirs : NULL;PartitionFilterAlive filterAlive;PartitionFilterOnMap filterOnMap;PartitionFilter *filters[] = { &filterAlive, &filterOnMap, 0 };@@ -9666,7 +10142,10 @@ void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myH// a holder counted below is not counted twiceconst TacticalStep *row = countHolders ? findTacticalStep( e->getID() ) : NULL;if( !fixed && (row == NULL || !heldFrom( row->fallingBack, &row->fallbackFrom, centre )) )+ {addToForce( e, myHealth, myPower );+ addToArmy( myKinds, e );+ }}else if( m_player->getRelationship( e->getTeam() ) == ENEMIES ){@@ -9675,7 +10154,10 @@ void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myHif( !observerKnowsAbout( e, m_player->getPlayerIndex() ) )continue;if( !fixed )+ {addToForce( e, enemyHealth, enemyPower );+ addToArmy( theirKinds, e );+ }const Real reach = enemyGuns ? groundAttackRange( e ) : 0.0f;if( reach > 0.0f ){@@ -9686,9 +10168,7 @@ void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myH}}- if( !countHolders )- return;- for( size_t i = 0; i < m_tactics.size(); ++i )+ for( size_t i = 0; countHolders && i < m_tactics.size(); ++i ){if( !heldFrom( m_tactics[ i ].fallingBack, &m_tactics[ i ].fallbackFrom, centre ) )continue;@@ -9696,8 +10176,30 @@ void AIPlayer::measureFight( const Coord3D *centre, Bool countHolders, Real *myH// and still ours: a holder taken by a Hijacker keeps its row until it expiresif( obj && !obj->isEffectivelyDead() && obj->getControllingPlayer() == m_player && !obj->isKindOf( KINDOF_PROJECTILE ) &&!obj->isKindOf( KINDOF_STRUCTURE ) && !obj->isKindOf( KINDOF_IMMOBILE ) )+ {addToForce( obj, myHealth, myPower );+ addToArmy( myKinds, obj );+ }}+ if( advantage )+ *advantage = armyAdvantage( mine, theirs );+}++//----------------------------------------------------------------------------------------------------------+/** How the fight around centre is going (aiRetreatRatio). With EngageGate the units in it are weighed+ * against each other as well as by price: twelve Crusaders and six Overlords cost the same, and the+ * Crusaders lose. The money ratio called that fight even and kept feeding tanks into it; one by unit+ * against unit breaks it off, and stays in one a cheaper army of the right units is winning. */+//----------------------------------------------------------------------------------------------------------+Real AIPlayer::fightRatio( const Coord3D *centre, Bool countHolders, Real *enemyHealth, Real *enemyPower, std::vector<Real> *enemyGuns )+{+ Real myHealth = 0.0f, myPower = 0.0f;+ Real advantage = 1.0f;+ *enemyHealth = 0.0f;+ *enemyPower = 0.0f;+ measureFight( centre, countHolders, &myHealth, &myPower, enemyHealth, enemyPower, enemyGuns,+ getSkillProfile()->m_engageGate ? &advantage : NULL );+ return aiRetreatRatio( myHealth, myPower, *enemyHealth, *enemyPower ) * advantage;}/** How long a team that fell back holds before it may go back, at the least and at the most; and how@@ -9749,10 +10251,8 @@ Bool AIPlayer::doFallback( Team *team )if( !holding )return FALSE;- Real myHealth = 0.0f, myPower = 0.0f;Real enemyHealth = 0.0f, enemyPower = 0.0f;- measureFight( &from, TRUE, &myHealth, &myPower, &enemyHealth, &enemyPower, NULL );- const Real ratio = aiRetreatRatio( myHealth, myPower, enemyHealth, enemyPower );+ const Real ratio = fightRatio( &from, TRUE, &enemyHealth, &enemyPower, NULL );// the shortest hold runs from the last to arrive, the longest from the firstconst UnsignedInt held = now - first >= FALLBACK_MAX_HOLD_FRAMES ? now - first : now - since;// one still moving this long after it was pulled out is on somebody else's errand (its script, a@@ -11923,7 +12423,7 @@ void AIPlayer::xfer( Xfer *xfer ){// version- XferVersion currentVersion = 17; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger+ XferVersion currentVersion = 18; // 2: scout 3: rung and role 4: scouting stamps 5: the capturer 6: parked waves 7: superweapon aims 8: the hijacker 9: tactical steps 10: the ferry and dropped riders 11: the outward placement ring 12: the pressure level 13: falling back 14: gunship Chinooks and the boarding wait 15: transport Chinooks and the lent one 16: healer and raider Helixes 17: the seen-enemy ledger 18: the fistXferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -12279,6 +12779,22 @@ void AIPlayer::xfer( Xfer *xfer )}}}+ // the fist: the unit picked, when, and what of it is waiting+ if( version >= 18 )+ {+ AsciiString massName = m_massTemplate ? m_massTemplate->getName() : AsciiString::TheEmptyString;+ xfer->xferAsciiString( &massName );+ if( xfer->getXferMode() == XFER_LOAD )+ m_massTemplate = massName.isEmpty() ? NULL : TheThingFactory->findTemplate( massName, FALSE );+ xfer->xferUnsignedInt( &m_massPickFrame );+ xfer->xferUnsignedInt( &m_massSince );+ UnsignedShort held = (UnsignedShort)m_massUnits.size();+ xfer->xferUnsignedShort( &held );+ if( xfer->getXferMode() == XFER_LOAD )+ m_massUnits.resize( held );+ for( UnsignedShort i = 0; i < held; ++i )+ xfer->xferObjectID( &m_massUnits[ i ] );+ }// the ladder rung and the role, which are rolled once and must come back the same wayif( version >= 3 )diff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.incindex 2f5ca4c35..09b919839 100644--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc@@ -483,11 +483,9 @@ TEST(right_drag_pans_past_the_drag_tolerance_and_middle_drag_turns)mouse(GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP, 350, 300);CHECK(!f.camera.isMovingCamera());- // Classic's right drag is the same retail scroll, started by the press itself as 1.04 started it+ // Classic's right drag is the same retail scrollf.global->m_interfaceStyle = INTERFACE_STYLE_CLASSIC;mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN, 300, 300);- CHECK(f.ui->scrolling);- CHECK(f.camera.isRightDragPanning());mouse(GameMessage::MSG_RAW_MOUSE_POSITION, 340, 300);CHECK(f.camera.isRightDragPanning());mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP, 340, 300);diff --git a/GeneralsMD/Code/Tests/test_minimap_input.inc b/GeneralsMD/Code/Tests/test_minimap_input.incindex 29c132fbb..ed67d520e 100644--- a/GeneralsMD/Code/Tests/test_minimap_input.inc+++ b/GeneralsMD/Code/Tests/test_minimap_input.inc@@ -6,8 +6,6 @@#include "GameClient/GameWindowManager.h"#include "GameClient/WindowXlat.h"#include "GameClient/GUICallbacks.h"-#include "GameClient/ControlBar.h"-#include "GameClient/SelectionXlat.h"#include "Common/Radar.h"#include "Common/StatsCollector.h"#include "Common/PlayerList.h"@@ -223,9 +221,7 @@ class MinimapTestUI : public MinimapInputUI{public:DrawableList selected;- const CommandButton *command = NULL;const DrawableList *getAllSelectedLocalDrawables() { return &selected; }- const CommandButton *getGUICommand() const { return command; }};struct MinimapInputFixture@@ -247,7 +243,6 @@ struct MinimapInputFixtureradar.configure(window);static MinimapTestUI *ui = NEW MinimapTestUI;ui->selected.clear();- ui->command = NULL;ui->scrolling = ui->selecting = FALSE;ui->enabled = TRUE;TheInGameUI = ui;@@ -272,7 +267,7 @@ struct MinimapInputFixtureGameMessage *message = messages.stream.appendMessage(type);ICoord2D pixel = {x, y};message->appendPixelArgument(pixel);- if(type == GameMessage::MSG_RAW_MOUSE_LEFT_DRAG || type == GameMessage::MSG_RAW_MOUSE_RIGHT_DRAG)+ if(type == GameMessage::MSG_RAW_MOUSE_LEFT_DRAG){ICoord2D delta = {1, 1};message->appendPixelArgument(delta);@@ -390,135 +385,3 @@ TEST(minimap_drag_works_during_keyboard_scroll_and_pins_to_a_letterboxed_picturef.event(messages, GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP, 300, 400);CHECK(f.windows.winGetGrabWindow() == NULL);}--/* 1.04's radar in both of its mouse setups: the look button moves the camera on the press and a drag- after it leaves the camera alone, and the other button with units selected gives 1.04's orders - the- attack move command when it is waiting, a plain move otherwise. */-TEST(minimap_classic_looks_on_the_press_and_orders_attack_move_in_both_mouse_setups)-{- CHECK(bootOnce());- CommandButton *attackMove = newInstance(CommandButton);- attackMove->friend_setCommandType(GUI_COMMAND_ATTACK_MOVE);- for (Int alternate = 0; alternate < 2; ++alternate)- {- MinimapInputFixture f;- MinimapMessages messages;- messages.stream.attachTranslator(NEW WindowTranslator, 10);- TheWritableGlobalData->m_interfaceStyle = INTERFACE_STYLE_CLASSIC;- TheWritableGlobalData->m_useAlternateMouse = alternate ? TRUE : FALSE;- MinimapTestUI *ui = (MinimapTestUI*)TheInGameUI;- ui->selected.push_back(NULL);-- const GameMessage::Type lookDown = alternate ? GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN : GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN;- const GameMessage::Type lookDrag = alternate ? GameMessage::MSG_RAW_MOUSE_LEFT_DRAG : GameMessage::MSG_RAW_MOUSE_RIGHT_DRAG;- const GameMessage::Type lookUp = alternate ? GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP : GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP;- const GameMessage::Type orderDown = alternate ? GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN : GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN;- const GameMessage::Type orderUp = alternate ? GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP : GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP;-- f.event(messages, lookDown, 120, 220);- CHECK(f.engine.view.lookAtCalls == 1);- f.event(messages, lookDrag, 150, 250);- CHECK(f.engine.view.lookAtCalls == 1);- f.event(messages, lookUp, 150, 250);- CHECK(messages.commands.getFirstMessage() == NULL);-- ui->command = attackMove;- f.event(messages, orderDown, 120, 220);- f.event(messages, orderUp, 120, 220);- CHECK(f.engine.view.lookAtCalls == 1);- const GameMessage *order = messages.commands.getFirstMessage();- CHECK(order != NULL && order->getType() == GameMessage::MSG_DO_ATTACKMOVETO);- }- attackMove->deleteInstance();-}--namespace-{-class ClassicRightClickUI : public MinimapInputUI-{-public:- const CommandButton *command = NULL;- ObjectID placeSource = INVALID_ID;- Int deselects = 0;- const CommandButton *getGUICommand() const { return command; }- void setGUICommand(const CommandButton *c) { command = c; }- const ObjectID getPendingPlaceSourceObjectID() { return placeSource; }- void deselectAllDrawables() { ++deselects; }-};-}--/* 1.04's right release in Classic: only a click counts, measured on screen, in time and by how far the- camera rode, since the press scrolls as well. A click takes back a waiting command and is eaten, so- the alternate mouse's order does not follow it; otherwise it deselects, which under the alternate- mouse it does only with a dozer's structure on the cursor. */-TEST(classic_right_click_deselects_or_takes_back_a_command_as_1_04_did)-{- CHECK(bootOnce());- MinimapEngineFixture f;- static ClassicRightClickUI *ui = NEW ClassicRightClickUI;- TheInGameUI = ui;- SelectionTranslator *savedSelection = TheSelectionTranslator;- f.mouse.m_dragTolerance = 25;- f.mouse.m_dragTolerance3D = 25;- f.mouse.m_dragToleranceMS = 250;- f.global->m_interfaceStyle = INTERFACE_STYLE_CLASSIC;- CommandButton *guard = newInstance(CommandButton);- guard->friend_setCommandType(GUI_COMMAND_GUARD);- {- SelectionTranslator selection;- const auto mouse = [&selection](GameMessage::Type type, Int x, Int y, Int time)- {- GameMessage *message = newInstance(GameMessage)(type);- const ICoord2D pixel = {x, y};- message->appendPixelArgument(pixel);- message->appendIntegerArgument(0);- message->appendIntegerArgument(time);- const GameMessageDisposition disp = selection.translateGameMessage(message);- message->deleteInstance();- return disp;- };- const auto click = [&mouse](Int dx, Int heldMs)- {- mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN, 300, 300, 1000);- return mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP, 300 + dx, 300, 1000 + heldMs);- };-- for (Int alternate = 0; alternate < 2; ++alternate)- {- f.global->m_useAlternateMouse = alternate ? TRUE : FALSE;- ui->deselects = 0;- ui->command = NULL;- ui->placeSource = INVALID_ID;-- // a click with nothing waiting deselects in the default mouse and not in the alternate one- CHECK(click(10, 100) == KEEP_MESSAGE);- CHECK_EQ(ui->deselects, alternate ? 0 : 1);-- // a drag or a held press is no click at all- click(60, 100);- click(0, 400);- CHECK_EQ(ui->deselects, alternate ? 0 : 1);-- // nor is a press the camera rode away from- mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN, 300, 300, 1000);- Coord3D moved = *f.view.getPosition();- moved.x += 100.0f;- f.view.setPosition(&moved);- mouse(GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP, 300, 300, 1100);- CHECK_EQ(ui->deselects, alternate ? 0 : 1);-- // a waiting command is taken back, the units stay, and the release is eaten- ui->command = guard;- CHECK(click(0, 100) == DESTROY_MESSAGE);- CHECK(ui->command == NULL);- CHECK_EQ(ui->deselects, alternate ? 0 : 1);-- // a dozer's structure on the cursor deselects the dozer in both- ui->placeSource = (ObjectID)7;- click(0, 100);- CHECK_EQ(ui->deselects, alternate ? 1 : 2);- }- }- guard->deleteInstance();- TheSelectionTranslator = savedSelection;-}