Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): Classic's two mouse setups answer as 1.04 did
Olcay Seyganfccc7e576c9b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 23cc4d2c7..3cca15b57 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -204,6 +204,8 @@ found and fixed — EA's own, not port damage.**- It still refuses to gang up with another computer opponent on one victim, and still gently prefers whoever is already shooting at it.- An aggressive computer team is supposed to fight its way to where it is sent rather than walk there. It never did. The order to fight was being reissued every frame, and each reissue pushed the moment that unit next looks for a target one step further into the future, so the look never came at all and the team crossed the map through the enemy without firing. Over four and a half minutes of one test match that order was restarted 2,240 times. It is restarted 15 times now.- And when that switch does happen, the old order stops there. It used to finish its own turn afterwards, steering one last time toward the place the unit was going before the order changed, which is a visible flinch at the head of a column.+- It no longer chases what it cannot see. A stealthed Colonel Burton nobody had detected still counted as seen to the computer, so walking him into its base drew the whole guard after him while not one of their guns was allowed to fire at him. A hidden unit is now hidden from the computer the way it is from you, until a detector or a shot of his own gives him away, and a GLA bomb truck dressed as one of the computer's own units fools it as well. In four staged runs a Burton pacing inside a USA base had the guard sent at him about 70 seconds in every time; now nothing goes for him until the base's first Patriot Battery, which can see him, is up.+- Hard stops feeding you units. Before a group leaves, or a lone reinforcement sets off to join one out on the map, it weighs what it is sending against everything of yours it has seen in the last three minutes, unit type against unit type, and holds back what would only die. A reinforcement waits at home for the next wave instead of crossing the map alone. When you mass one unit it trains the answer between attacks too, Comanches and Helixes included, and stops buying what your biggest group beats. Against waves of Overlords rolling at its base, the share of its groups sent into a fight their units lose fell from 48% to 40%, and units dying alone from 17% to 14% of its losses. Against itself it changed nothing measurable: in 48 matches where only one side had it, that side won 5 and the other 4. Replays recorded before this change play out differently.## The computer knows when to quit- Its teams fought to the last man. The word "retreat" appeared nowhere in the opponent's code - the single most visible thing that made it look stupid.@@ -1134,6 +1136,7 @@ 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/GameEngine/Include/GameClient/SelectionXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.hindex 6f97d0d87..94e21f833 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h@@ -53,6 +53,9 @@ 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/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cppindex 0128af7bf..cc4bcd17a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp@@ -343,11 +343,13 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,TheAudio->addAudioEvent( &sound );}- if( commandButton->getCommandType() == GUI_COMMAND_ATTACK_MOVE )+ if( commandButton->getCommandType() == GUI_COMMAND_ATTACK_MOVE && !TheGlobalData->isClassicUI() ){// 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 4514f04af..2e1fe45b4 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())+ if (TheInGameUI->isInAttackMoveToMode() || (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE)){cur = Mouse::ATTACKMOVETO;}@@ -247,7 +247,7 @@ WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,if (!(drawableList->empty() || msg == GWM_MOUSE_LEAVING)){- if (TheInGameUI->isInAttackMoveToMode())+ if (TheInGameUI->isInAttackMoveToMode() || (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE)){cur = Mouse::ATTACKMOVETO;}@@ -340,10 +340,38 @@ 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 );- s_radarLookDrag = (msg == GWM_LEFT_DOWN) ? GWM_LEFT_DRAG : GWM_RIGHT_DRAG;+ 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 );+ }break;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 983800662..0150cf3e5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -4161,7 +4161,11 @@ 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+ // 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 );break;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cppindex 6fa02cf2e..3028576e8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/GUICommandTranslator.cpp@@ -266,6 +266,37 @@ 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 *///-------------------------------------------------------------------------------------------------@@ -440,6 +471,12 @@ 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 850bb0b01..65893dfd8 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp@@ -328,6 +328,20 @@ 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 8aef6cbdf..30715e455 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -287,6 +287,10 @@ 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();@@ -575,8 +579,11 @@ 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- if (draw && draw->isMassSelectable() && draw->isKindOf( KINDOF_STRUCTURE ) == picked->isKindOf( KINDOF_STRUCTURE )) {+ // 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) {TheInGameUI->selectDrawable(draw);selectMore->appendObjectIDArgument(draw->getObject()->getID());}@@ -1204,9 +1211,49 @@ 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() )@@ -1219,18 +1266,6 @@ 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/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.incindex 09b919839..2f5ca4c35 100644--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc@@ -483,9 +483,11 @@ 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+ // Classic's right drag is the same retail scroll, started by the press itself as 1.04 started itf.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 ed67d520e..29c132fbb 100644--- a/GeneralsMD/Code/Tests/test_minimap_input.inc+++ b/GeneralsMD/Code/Tests/test_minimap_input.inc@@ -6,6 +6,8 @@#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"@@ -221,7 +223,9 @@ class MinimapTestUI : public MinimapInputUI{public:DrawableList selected;+ const CommandButton *command = NULL;const DrawableList *getAllSelectedLocalDrawables() { return &selected; }+ const CommandButton *getGUICommand() const { return command; }};struct MinimapInputFixture@@ -243,6 +247,7 @@ 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;@@ -267,7 +272,7 @@ struct MinimapInputFixtureGameMessage *message = messages.stream.appendMessage(type);ICoord2D pixel = {x, y};message->appendPixelArgument(pixel);- if(type == GameMessage::MSG_RAW_MOUSE_LEFT_DRAG)+ if(type == GameMessage::MSG_RAW_MOUSE_LEFT_DRAG || type == GameMessage::MSG_RAW_MOUSE_RIGHT_DRAG){ICoord2D delta = {1, 1};message->appendPixelArgument(delta);@@ -385,3 +390,135 @@ 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;+}