Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): order threads, attack circle queue, shot claims

Olcay Seyganfec052cc1d58
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d5604f80..b9875c3f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -110,16 +110,17 @@ found and fixed — EA's own, not port damage.**
## Your units stop shooting corpses
- Damage counts the moment a shot leaves the barrel, not when it lands.
+- A unit says what it is about to do before it does it. Lining up a shot takes time, and a wind-up can run a second on some weapons, and for all of that time there was nothing anywhere saying the target was already being dealt with, so the second and third unit committed to it too and only found out when the first one fired. The shot is now on the books while it is still being aimed. Whoever called it first keeps the target and everyone else looks elsewhere before making the trip, not after arriving.
- Once an enemy is accounted for, the rest of the group retargets.
-- Your own right-click orders always win, however much fire is already inbound.
+- An order you gave by hand is held to rather than thrown away, but it holds its fire too. The unit keeps the target and keeps its aim and simply does not spend the round, so the volley is still in the tubes when you point the group at something else. Ordered attacks used to fire regardless, which is why a flight of four planes put all four loads into the first tank it reached.
- A reservation lapses within half a second if the shot never arrives.
- Ctrl+Q now takes infantry only, not every armed thing you own.
- A box drawn with Ctrl held takes those units back out of your selection instead of replacing it, so a group is trimmed by dragging over the corner of it rather than picked again from scratch. Held with Alt the box keeps only what can shoot: drag across your base and you get the tanks, not the dozers and supply trucks standing among them. Both are drag-only, and a single click still means exactly what it always did.
- The three buttons each do one thing now. Left selects, and only selects. Right gives orders, and nothing it does moves the camera. The camera is on the middle button, and it scrolls the way the right button used to: the spot you pressed on stays put, and the further you pull away from it the faster the map runs. Hold Ctrl and the same drag turns the view instead. The wheel zooms toward whatever the cursor is over and the screen edges still scroll. The classic scheme, where left both selected and commanded and right scrolled and deselected, is gone rather than switched off, and the two checkboxes that used to choose between them are out of the options screen.
- Drag the right button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, however far you keep drawing it: a long sweep used to give up partway through and finish as one straight run to the cursor, and now it holds its shape to the end. Letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. Draw the same line with attack move armed and the whole line is an attack move: artillery spread across a front, each gun firing on what walks into it, instead of one clump on one spot. Armed with attack instead, every unit fires on its own station along the line, which is a barrage laid across a ridge in one drag. This is what the right button freed up. `FormationDrag = no` in Options.ini turns it off if you would rather a slipped click did nothing.
-- Selected units draw a thread to wherever they are going, and the marker on the spot is the game's own cursor. Every order that has a cursor gets that cursor: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed.
+- Selected units draw a thread to wherever they are going, and the marker on the spot is the game's own cursor. Every order that has a cursor gets that cursor: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed. The animated ring the ground used to sprout wherever you clicked is gone: it flashed for a second and told you nothing the marker sitting on the destination does not, and that marker stays for as long as the order does. A marker that has just appeared slides the last few pixels up out of the bottom right and fades in as it lands, over about an eighth of a second, so a fresh order catches your eye without anything flashing. Aircraft draw their thread from the click, not from the moment they leave the runway. A plane parked on its airfield answers an order by starting its takeoff and puts the order itself aside until the wheels are up, so the taxi and the climb, which is exactly the stretch where you are wondering whether the strike went out at all, used to show nothing.
- A is attack and F is attack move, each arming the next order click. A click on the ground with A held down is a shot at that ground, on your own tank a shot at your own tank, and the mode drops again the moment the order goes out, so nothing stays armed behind your back. Ctrl still forces fire while you hold it. The two keys turn each other off, and the letters they took were sitting on grid commands that moved.
-- With A armed, hold the left button and drag a circle instead: everything hostile you can see inside it becomes a target list, nearest first, and the selection works down that list on its own. When the current target dies the next order goes out the same frame, so a strike group clears a circle without you clicking once per tank. Any order you give by hand ends the list, and so does changing what is selected.
+- With A armed, hold the left button and drag a circle instead: everything hostile you can see inside it becomes a target list, nearest first, and the selection works down that list on its own. When the current target dies the next order goes out the same frame, so a strike group clears a circle without you clicking once per tank. It moves on from a target the group has stopped working on, too, rather than only from a dead one: something none of them can reach or hurt used to sit at the head of the list and hold every other target behind it for the rest of the match. That list is the same queue a shift-clicked attack builds, so you can see it: every target still owed has its own thread and marker, in the order they will be taken, instead of one line to whatever is being shot at this second. Hold shift while you draw the circle and its targets go on the end of what the group is already working through; draw it without shift and the circle replaces the lot. The ground inside the circle is washed the same red while you drag it, painted on the map rather than over it, so it runs up the hills inside the circle and your own tanks stand on top of it. Any order you give by hand ends the list. Losing a unit does not: the list belongs to the group that was told and carries on with whoever is left, which is worth saying because for a while it did not, and one tank dying threw away every target still owed. A target with enough of your fire already in the air to kill it counts as done, so the rest of the group takes the next thing on the list rather than emptying itself into something that is dead and has not fallen over yet. Aircraft are what this is for: a flight fires from range and the missiles are seconds behind, and four planes used to spend all four loads on the first tank in the circle. Running out of ammo does not cost you the list either. A flight that empties its racks flies home, lands, rearms and comes back to the target it left, and the queue waits for it instead of counting the trip as the group giving up: a circle drawn for four planes used to be empty by the time they were back in the air, one entry lost every two seconds they were away. The threads stay on the ground for the whole trip, too. A plane flying home has no target and no order to read, so the list it was still holding used to vanish off the map the moment it turned for base and reappear only when it was shooting again, which looks exactly like the list being thrown away.
- Shift queues an attack now, not only a move. A or F held down while you shift-click adds a force-attack or an attack-move to the line of orders a group is already holding, and it fires the moment the order in front of it is finished - a target dead, or nobody left chasing an attack-move point. The coloured thread that shows a queued order covers it too, so a queue of "go here, then attack that, then attack-move over there" reads as one continuous line in three colours. The game's own white waypoint markings, which used to draw over the same ground the moment shift went down, are gone - they only ever duplicated what the coloured thread already showed, and doing both left a queued attack sitting under two different pictures of itself.
- Ctrl+D takes every unit of the kinds you have selected that is on the screen, and pressed twice inside half a second takes them across the whole map. One tank selected and two keystrokes is your whole armour, wherever it is standing. It was on Shift+Ctrl+E, which is three fingers for something you do in every fight, and it only ever reached across the map when the screen had nothing left to give - so the wide selection happened to you instead of being asked for.
@@ -331,6 +332,7 @@ found and fixed — EA's own, not port damage.**
- The pointer keeps its build cursor while you place, even passing over your own buildings.
- GLA defences get a range ring while you site them.
- Two buildings can no longer be put down on the same spot online. A build order travels to the other players before anything appears on the ground, and every click made while it was in flight was answered by a map that still showed the square as empty - so a shift-held row on a bad connection came out as buildings standing inside each other. The ghost now knows about the orders you have already spent, and turns red over them or slides to the square beside; and the order itself is checked again where it lands, on every machine, after the first building is standing. A second one aimed at the same ground is refused there and costs you nothing.
+- The right button drops the building on your cursor whether the click travelled or not. Sending a dozer off somewhere in the middle of a shift-held row moved it and left the ghost riding the cursor, because the cancel only counted a press that had not moved a pixel and a hand on the way to a destination always moves a few.
- A click clears a half-typed building shortcut.
- The two-key building shortcut survives the command bar's redraw now.
- Every structure is those two keys and nothing else. The letter written on a cell is the second half of its pair, and pressed on its own it used to build whatever sat in the slot that letter names - so the same barracks went up either by the shortcut painted on it or by one bare key nobody had written anywhere, and a key pressed after a shortcut you had thought better of put a building on your cursor. And the pairs are read off the key bindings now instead of a list written out beside them: the second letters had been left behind when the bottom row of the command bar moved to Z X C V B N M, so half the cells answered a letter that was not on them.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 314834e2c..b86e12262 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -406,7 +406,11 @@ public: // ********************************************************************
FORMATION_DRAG_MIN_SPACING = 12 ///< pixels between kept points, doubled when the curve fills up
};
void addFormationDragPoint( const ICoord2D& pt );
- void clearFormationDrag( void ) { m_isFormationDragging = FALSE; m_formationDragPoints.clear(); m_orderHints.clear(); }
+ // The markers are not thrown away with the drag. They are rebuilt from the units every frame
+ // anyway, before anything is drawn, and emptying the list here cost every marker on the screen
+ // its age: a right click is what ends a drag, so every order the player gave made the whole
+ // screen slide in again instead of only the marker that was new.
+ void clearFormationDrag( void ) { m_isFormationDragging = FALSE; m_formationDragPoints.clear(); }
Bool isFormationDragging( void ) const { return m_isFormationDragging; }
const std::vector<ICoord2D>& getFormationDragPoints( void ) const { return m_formationDragPoints; }
@@ -438,25 +442,27 @@ public: // ********************************************************************
Coord3D from; ///< where the unit is now
Coord3D to; ///< where it is going
OrderHintKind kind;
+ ObjectID owner; ///< the selected unit this one belongs to
+ UnsignedInt bornMs; ///< when the marker first appeared, so it can be slid in
};
const std::vector<OrderHint>& getOrderHints( void ) const { return m_orderHints; }
// A circle dragged out with the left button while the attack key is armed. Everything hostile
- // and visible inside it becomes a list, and the selection works down that list one target at a
- // time: the next one is ordered the moment the current one stops existing.
+ // and visible inside it joins the shift queue below, and the selection works down that list one
+ // target at a time: the next one is ordered the moment the current one stops existing.
void beginAttackCircle( const ICoord2D& pt );
void updateAttackCircle( const ICoord2D& pt );
- void issueAttackCircle( void );
+ Bool issueAttackCircle( void ); ///< FALSE when the press never became a drag, so it was an ordinary attack click
void cancelAttackCircle( void ) { m_isAttackCircling = FALSE; }
Bool isAttackCircling( void ) const { return m_isAttackCircling; }
const ICoord2D& getAttackCircleAnchor( void ) const { return m_attackCircleAnchor; }
const ICoord2D& getAttackCircleCursor( void ) const { return m_attackCircleCursor; }
- void clearAttackQueue( void );
+ Bool getAttackCircleGround( Coord3D& center, Real& radius ) const; ///< the circle in world terms, FALSE while it is still a dot
// An attack order (force-attack or attack-move) added to the shift queue. The goal path the
- // plain move queue rides on carries no order type, so this is a second queue, driven the same
- // way the attack circle's is: an ordinary message the client sends again once the order before
- // it is over, nothing new for the logic to learn.
+ // plain move queue rides on carries no order type, so this is a second queue: an ordinary
+ // message the client sends again once the order before it is over, nothing new for the logic
+ // to learn.
struct AttackWaypoint
{
Coord3D pos; ///< where to attack-move to, or the last known spot of targetID
@@ -467,7 +473,6 @@ public: // ********************************************************************
Bool isShiftAttackQueueActive( void ) const { return !m_shiftAttackQueue.empty() || m_shiftAttackQueueRunning; }
const std::vector<AttackWaypoint>& getShiftAttackQueue( void ) const { return m_shiftAttackQueue; }
- virtual void createMoveHint( const GameMessage *msg ); ///< A move command has occurred, start graphical "hint"
virtual void createAttackHint( const GameMessage *msg ); ///< An attack command has occurred, start graphical "hint"
virtual void createForceAttackHint( const GameMessage *msg ); ///< A force attack command has occurred, start graphical "hint"
@@ -920,16 +925,6 @@ protected:
// Protected Types ------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------
- enum HintType
- {
- MOVE_HINT = 0,
- ATTACK_HINT,
-#ifdef _DEBUG
- DEBUG_HINT,
-#endif
- NUM_HINT_TYPES // keep this one last
- };
-
// mouse mode interface
enum MouseMode
{
@@ -939,14 +934,6 @@ protected:
MOUSEMODE_MAX
};
- enum { MAX_MOVE_HINTS = 256 };
- struct MoveHintStruct
- {
- Coord3D pos; ///< World coords of destination point
- UnsignedInt sourceID; ///< id of who will move to this point
- UnsignedInt frame; ///< frame the command was issued on
- };
-
struct UIMessage
{
UnicodeString fullText; ///< the whole text message
@@ -987,9 +974,6 @@ protected:
virtual View *createView( void ) = 0; ///< Factory for Views
void evaluateSoloNexus( Drawable *newlyAddedDrawable = NULL );
- /// expire a hint from of the specified type at the hint index
- void expireHint( HintType type, UnsignedInt hintIndex );
-
void createControlBar( void ); ///< create the control bar user interface
void createReplayControl( void ); ///< create the replay control window
@@ -1008,6 +992,10 @@ public:
* renderer rather than from preDraw: it is geometry lying on the ground, and it has to go down
* with the terrain so that everything drawn after the terrain covers it. */
virtual void drawBuildGrid( void ) { }
+
+ /** The wash inside the attack circle, on the ground for the same reason: the units being swept
+ * up stand on top of it instead of being painted over. */
+ virtual void drawAttackCircleFill( void ) { }
protected:
void clearWorldAnimations( void ); ///< delete all world animations
@@ -1040,22 +1028,26 @@ protected:
Bool m_isAttackCircling; ///< TRUE while an attack circle is being dragged (fork)
ICoord2D m_attackCircleAnchor; ///< where the circle was started, in pixels
ICoord2D m_attackCircleCursor; ///< where the cursor is now, which is the rim
- std::vector<ObjectID> m_attackQueue; ///< targets still owed, nearest first
- ObjectID m_attackQueueTarget; ///< the one the group is on now
- std::vector<ObjectID> m_attackQueueUnits; ///< who was told, so a changed selection drops the queue
std::vector<AttackWaypoint> m_shiftAttackQueue; ///< attack points still owed, in click order (fork)
Bool m_shiftAttackQueueRunning; ///< TRUE once the first order of the queue has been sent
AttackWaypoint m_shiftAttackQueueActive; ///< the order that was sent, so its completion can be noticed
+ UnsignedInt m_shiftAttackQueueEngagedFrame; ///< the last logic frame somebody was still working on the order in flight
std::vector<ObjectID> m_shiftAttackQueueUnits; ///< who was told, so a changed selection drops the queue
+ Bool m_shiftAttackQueueWaitingForRearm; ///< the order stands but its aircraft went home for ammo
+ Bool m_shiftAttackQueueWaitingForSelection; ///< the order stands but nothing that was told is in hand
void updateFormationHints( void ); ///< recompute who goes where from the curve being drawn
void updateOrderHints( void ); ///< read the selection's own goals, once a frame
- void updateAttackQueue( void ); ///< order the next target when the current one is gone
void updateShiftAttackQueue( void ); ///< send the next queued attack once the current one is over
+ void addOrderHint( OrderHint& hint, const std::vector<OrderHint>& previous ); ///< keep a marker's age across the frame the list is rebuilt on
+ Bool getHeldAircraftOrder( const Object *obj, OrderHintKind& kind, Coord3D& to ) const; ///< the order an aircraft is sitting on until it is airborne
+ void sendShiftAttackOrder( const AttackWaypoint& waypoint ); ///< put one queue entry on the message stream
+ void logShiftAttackQueue( const char *why ) const; ///< one line saying what the queue did and what its group was doing
+ void addShiftAttackQueueTail( OrderHint& hint, const std::vector<OrderHint>& previous ); ///< every target still owed, drawn on from where the hint leaves off
+ void collectSelectedObjectIDs( std::vector<ObjectID>& ids ) const; ///< the selection by id, sorted
+ Bool selectionOwnsShiftAttackQueue( const std::vector<ObjectID>& selected ) const; ///< is this still the group the queue was given to
Bool m_displayedMaxWarning; ///< keeps the warning from being shown over and over
- MoveHintStruct m_moveHint[ MAX_MOVE_HINTS ];
- Int m_nextMoveHint;
const CommandButton * m_pendingGUICommand; ///< GUI command that needs additional interaction from the user
BuildProgress m_buildProgress[ MAX_BUILD_PROGRESS ]; ///< progress for building units
const ThingTemplate * m_pendingPlaceType; ///< type of built thing we're trying to place
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h
index 889e3f980..28daa3d58 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/SelectionXlat.h
@@ -51,14 +51,10 @@ private:
UnsignedInt m_lastGroupSelTime;
Int m_lastGroupSelGroup;
ICoord2D m_selectFeedbackAnchor; // Note: Used for drawing feedback only.
- ICoord2D m_deselectFeedbackAnchor; // Note: Used for drawing feedback only.
Bool m_displayedMaxWarning; // did we already display a warning about selecting too many units?
- UnsignedInt m_lastClick; ///< timer used for checking double click for type selection
SelectCountMap m_selectCountMap;
- Coord3D m_deselectDownCameraPosition;
-
Bool selectFriends( Drawable *draw, GameMessage *createTeamMsg, Bool dragSelecting );
Bool killThemKillThemAll( Drawable *draw, GameMessage *killThemAllMsg );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 73544d64d..8330df188 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -660,6 +660,8 @@ public:
void reconstitute(AICommandParms& parms) const;
void doXfer(Xfer *xfer);
AICommandType getCommandType() const { return m_cmd; }
+ ObjectID getTargetObjectID() const { return m_obj; }
+ const Coord3D& getTargetPosition() const { return m_pos; }
};
/**
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h
index 014d6032f..70ddaaccd 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h
@@ -979,9 +979,10 @@ class AIAttackFireWeaponState : public State
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(AIAttackFireWeaponState, "AIAttackFireWeaponState")
public:
AIAttackFireWeaponState( StateMachine *machine, NotifyWeaponFiredInterface* att ) :
- State( machine, "AIAttackFireWeaponState" ),
- m_att(att)
- {
+ State( machine, "AIAttackFireWeaponState" ),
+ m_att(att),
+ m_saidHeldFire(FALSE)
+ {
}
virtual Bool isAttack() const { return TRUE; }
virtual StateReturnType update();
@@ -994,6 +995,7 @@ protected:
virtual void loadPostProcess(){};
private:
NotifyWeaponFiredInterface *const m_att; // this is NOT owned by us and should not be freed
+ Bool m_saidHeldFire; // one log line per held shot, not one per frame of holding it
};
EMPTY_DTOR(AIAttackFireWeaponState)
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h
index 2c5ab4f3f..2efad69f8 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h
@@ -82,6 +82,25 @@ public:
/// The same question asked about a live object, whose health it reads for you.
static Bool isAlreadyDoomed(const Object *victim);
+ /**
+ Say, before the round leaves the barrel, that this shooter means to put this much damage into
+ this victim. A shot that is still being aimed or is inside its wind-up is worth announcing:
+ until it is fired there is nothing in the ledger, so a whole flight commits to the same target
+ and only finds out on the frame the first missile launches. Re-announcing refreshes the claim
+ and it lapses within a few frames of the last one, so a unit that changes its mind releases it
+ by falling silent.
+ */
+ static void claimShot(ObjectID victim, ObjectID shooter, Real amount, UnsignedInt currentFrame);
+
+ /**
+ TRUE if somebody else has this victim covered: damage in flight plus the shots other units
+ have announced already exceed its health. The asker's own claim is left out, so a unit is
+ never talked out of the shot it is lining up. This is the question a unit asks before
+ committing; isAlreadyDoomed, which counts only fire that is genuinely in the air, is the
+ question to ask when an announcement is not good enough.
+ */
+ static Bool isSpokenFor(const Object *victim, ObjectID asker);
+
};
#endif // __INCOMINGDAMAGE_H__
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
index 027187275..e23f4a391 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h
@@ -133,6 +133,8 @@ public:
}
void friend_addWaypointToGoalPath( const Coord3D &pos );
AICommandType friend_getPendingCommandType() const;
+ AICommandType friend_getHeldOrder( ObjectID& targetID, Coord3D& targetPos ) const;
+ Bool friend_isRearming() const;
void friend_purgePendingCommand();
protected:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 1fe261d17..2d8096f8e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -82,6 +82,8 @@
#include "GameLogic/AIGuard.h"
#include "GameLogic/AIStateMachine.h"
#include "GameLogic/Module/AIUpdate.h"
+#include "GameLogic/Module/JetAIUpdate.h"
+#include "GameLogic/IncomingDamage.h"
#include "GameLogic/Weapon.h"
#include "GameLogic/Object.h"
#include "GameLogic/GameLogic.h"
@@ -1010,7 +1012,6 @@ InGameUI::InGameUI()
m_isDragSelecting = false;
m_isFormationDragging = FALSE;
m_formationDragSpacing = FORMATION_DRAG_MIN_SPACING;
- m_nextMoveHint = 0;
m_selectCount = 0;
m_frameSelectionChanged = 0;
m_duringDoubleClickAttackMoveGuardHintTimer = 0;
@@ -1060,16 +1061,6 @@ InGameUI::InGameUI()
m_tooltipsDisabledUntil = 0;
- // init hint lists
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- {
-
- m_moveHint[ i ].pos.zero();
- m_moveHint[ i ].sourceID = 0;
- m_moveHint[ i ].frame = 0;
-
- } // end for i
-
for( i = 0; i < MAX_BUILD_PROGRESS; i++ )
{
@@ -1216,8 +1207,10 @@ InGameUI::InGameUI()
m_forceAttackArmed = false;
m_preferSelection = false;
m_isAttackCircling = FALSE;
- m_attackQueueTarget = INVALID_ID;
m_shiftAttackQueueRunning = FALSE;
+ m_shiftAttackQueueEngagedFrame = 0;
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ m_shiftAttackQueueWaitingForSelection = FALSE;
m_curRcType = RADIUSCURSOR_NONE;
@@ -1930,10 +1923,8 @@ void InGameUI::preDraw( void )
// where the selection is headed, read fresh from the units themselves
updateOrderHints();
- // and the next target of an attack circle, if the current one has stopped existing
- updateAttackQueue();
-
- // and the next point of a shift-queued attack, if the current one is over
+ // and the next queued attack, hand-clicked or swept out of a circle, once the one in front of
+ // it is over
updateShiftAttackQueue();
// the build grid under a structure waiting to be placed is not drawn here: it is terrain
@@ -2396,15 +2387,6 @@ void InGameUI::reset( void )
clearFloatingText();
clearWorldAnimations();
resetIdleWorker();
- // clear hint lists
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- {
-
- m_moveHint[ i ].pos.zero();
- m_moveHint[ i ].sourceID = 0;
- m_moveHint[ i ].frame = 0;
-
- } // end for i
m_waypointMode = false;
m_forceAttackMode = false;
@@ -2413,12 +2395,12 @@ void InGameUI::reset( void )
m_forceAttackArmed = false;
m_preferSelection = false;
m_isAttackCircling = FALSE;
- m_attackQueueTarget = INVALID_ID;
- m_attackQueue.clear();
- m_attackQueueUnits.clear();
m_shiftAttackQueue.clear();
m_shiftAttackQueueUnits.clear();
m_shiftAttackQueueRunning = FALSE;
+ m_shiftAttackQueueEngagedFrame = 0;
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ m_shiftAttackQueueWaitingForSelection = FALSE;
m_clientQuiet = false;
m_windowLayouts.clear();
@@ -2673,7 +2655,9 @@ void InGameUI::addFormationDragPoint( const ICoord2D& pt )
//-------------------------------------------------------------------------------------------------
void InGameUI::updateFormationHints( void )
{
- m_orderHints.clear();
+ // last frame's markers, kept only so this frame's can inherit their age (see addOrderHint)
+ std::vector<OrderHint> previous;
+ previous.swap( m_orderHints );
if( m_formationDragPoints.size() < 2 )
return;
@@ -2718,14 +2702,83 @@ void InGameUI::updateFormationHints( void )
hint.kind = isInAttackMoveToMode() ? ORDER_HINT_ATTACK_MOVE
: isForceAttackArmed() ? ORDER_HINT_ATTACK
: ORDER_HINT_MOVE;
+ hint.owner = movers[ i ]->getID();
hint.from = *movers[ i ]->getPosition();
pointAlongPath( path, arc, span * ((count == 1) ? 1.0f : ((Real)i / (Real)(count - 1))),
&hint.to );
hint.to.z = TheTerrainLogic->getGroundHeight( hint.to.x, hint.to.y );
- m_orderHints.push_back( hint );
+ addOrderHint( hint, previous );
}
}
+//-------------------------------------------------------------------------------------------------
+/** The order an aircraft has taken but not started. A plane on the ground answers a move or an
+ * attack by handing its state machine to the takeoff sequence and putting the order aside, so
+ * neither the state id nor the goal names the thing the player pointed at until it is flying. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::getHeldAircraftOrder( const Object *obj, OrderHintKind& kind, Coord3D& to ) const
+{
+ const AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ const JetAIUpdate *jet = ai->getJetAIUpdate();
+ if( jet == NULL )
+ return FALSE;
+
+ ObjectID targetID = INVALID_ID;
+ Coord3D targetPos;
+ targetPos.zero();
+
+ switch( jet->friend_getHeldOrder( targetID, targetPos ) )
+ {
+ case AICMD_ATTACK_OBJECT:
+ kind = ORDER_HINT_ATTACK;
+ break;
+
+ case AICMD_FORCE_ATTACK_OBJECT:
+ kind = ORDER_HINT_FORCE_ATTACK;
+ break;
+
+ case AICMD_ATTACK_POSITION:
+ case AICMD_ATTACK_AREA:
+ kind = ORDER_HINT_ATTACK_GROUND;
+ break;
+
+ case AICMD_ATTACKMOVE_TO_POSITION:
+ kind = ORDER_HINT_ATTACK_MOVE;
+ break;
+
+ case AICMD_ENTER:
+ case AICMD_GET_REPAIRED:
+ kind = ORDER_HINT_ENTER;
+ break;
+
+ // a queued path is held as a coordinate list the storage does not hand back, so a shift move
+ // given to a parked plane stays invisible until it flies. Single-point orders are the ones
+ // worth drawing here
+ case AICMD_MOVE_TO_POSITION:
+ case AICMD_MOVE_TO_OBJECT:
+ kind = ORDER_HINT_MOVE;
+ break;
+
+ default:
+ // everything else the aircraft holds is its own housekeeping, not a player order
+ return FALSE;
+ }
+
+ if( targetID != INVALID_ID )
+ {
+ const Object *target = TheGameLogic->findObjectByID( targetID );
+ if( target == NULL )
+ return FALSE;
+ to = *target->getPosition();
+ }
+ else
+ {
+ to = targetPos;
+ }
+
+ return TRUE;
+}
+
//-------------------------------------------------------------------------------------------------
/** Where each selected unit is going, asked of the unit rather than remembered from the order. A
* line therefore lives exactly as long as the order behind it: it appears the frame the unit
@@ -2739,7 +2792,9 @@ void InGameUI::updateOrderHints( void )
return;
}
- m_orderHints.clear();
+ // last frame's markers, kept only so this frame's can inherit their age (see addOrderHint)
+ std::vector<OrderHint> previous;
+ previous.swap( m_orderHints );
Player *local = ThePlayerList->getLocalPlayer();
for( DrawableList::const_iterator it = m_selectedDrawables.begin();
@@ -2754,6 +2809,9 @@ void InGameUI::updateOrderHints( void )
continue;
OrderHint hint;
+ hint.owner = obj->getID();
+ Coord3D heldOrderGoal;
+ Bool isHoldingOrder = FALSE;
switch( ai->getCurrentStateID() )
{
case AI_MOVE_TO:
@@ -2821,55 +2879,188 @@ void InGameUI::updateOrderHints( void )
break;
default:
- continue;
+ // a parked aircraft is running its own takeoff state machine, not the order the player
+ // gave it, and that order is held out of reach of the goal until the wheels are up.
+ // Ask for it, or an air strike shows nothing at all during the seconds the plane spends
+ // taxiing, which is exactly when the player wants to see where it is going
+ if( !getHeldAircraftOrder( obj, hint.kind, heldOrderGoal ) )
+ continue;
+ isHoldingOrder = TRUE;
+ break;
}
hint.from = *obj->getPosition();
- // a queued path is shown point by point: one thread from the unit to its next point and one
- // from each point to the one after it, so the whole shift queue is on the ground at once and
- // stays there after the key is let go
- const Int pathSize = ai->friend_getWaypointGoalPathSize();
- const Int pathIndex = ai->friend_getCurrentGoalPathIndex();
- if( pathSize > 0 && pathIndex >= 0 && pathIndex < pathSize )
+ if( isHoldingOrder )
+ {
+ hint.to = heldOrderGoal;
+ }
+ else
{
- for( Int i = pathIndex; i < pathSize; i++ )
+ // a queued path is shown point by point: one thread from the unit to its next point and one
+ // from each point to the one after it, so the whole shift queue is on the ground at once and
+ // stays there after the key is let go
+ const Int pathSize = ai->friend_getWaypointGoalPathSize();
+ const Int pathIndex = ai->friend_getCurrentGoalPathIndex();
+ if( pathSize > 0 && pathIndex >= 0 && pathIndex < pathSize )
{
- hint.to = *ai->friend_getGoalPathPosition( i );
- m_orderHints.push_back( hint );
- hint.from = hint.to;
+ for( Int i = pathIndex; i < pathSize; i++ )
+ {
+ hint.to = *ai->friend_getGoalPathPosition( i );
+ addOrderHint( hint, previous );
+ hint.from = hint.to;
+ }
+ continue;
}
- continue;
- }
- // a goal object outranks the goal position: a unit chasing something is headed wherever that
- // thing is standing now, not where it stood when the order was given
- Object *goalObj = ai->getGoalObject();
- if( goalObj )
- hint.to = *goalObj->getPosition();
- else
- hint.to = *ai->getGoalPosition();
+ // a goal object outranks the goal position: a unit chasing something is headed wherever that
+ // thing is standing now, not where it stood when the order was given
+ Object *goalObj = ai->getGoalObject();
+ if( goalObj )
+ hint.to = *goalObj->getPosition();
+ else
+ hint.to = *ai->getGoalPosition();
+ }
- m_orderHints.push_back( hint );
+ addOrderHint( hint, previous );
// the rest of a shift-queued attack: every point still owed after this one, drawn the same
// way a queued move is. The queue is shared by the whole group rather than kept per unit,
// so each member's tail starts wherever that unit's own current order leaves off
- if( !m_shiftAttackQueue.empty() &&
- std::find( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(), obj->getID() ) != m_shiftAttackQueueUnits.end() )
+ if( std::find( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(), obj->getID() )
+ != m_shiftAttackQueueUnits.end() )
{
hint.from = hint.to;
- for( std::vector<AttackWaypoint>::const_iterator qit = m_shiftAttackQueue.begin();
- qit != m_shiftAttackQueue.end(); ++qit )
+ addShiftAttackQueueTail( hint, previous );
+ }
+ }
+
+ //
+ // A unit holding the list that drew nothing above has to draw it anyway. An aircraft on its way
+ // home for ammo has no goal and no state the switch recognises, and one sitting on its airfield
+ // is not even in the selection, so the whole list went blank the moment the planes turned for
+ // home and came back only when they were shooting again - which looked exactly like the list had
+ // been thrown away. Here it stays on the ground for the length of the trip.
+ //
+ if( !m_shiftAttackQueueRunning )
+ return;
+
+ for( std::vector<ObjectID>::const_iterator id = m_shiftAttackQueueUnits.begin();
+ id != m_shiftAttackQueueUnits.end(); ++id )
+ {
+ Bool alreadyDrawn = FALSE;
+ for( std::vector<OrderHint>::const_iterator drawn = m_orderHints.begin();
+ drawn != m_orderHints.end(); ++drawn )
+ {
+ if( drawn->owner == *id )
{
- hint.to = qit->pos;
- m_orderHints.push_back( hint );
- hint.from = hint.to;
+ alreadyDrawn = TRUE;
+ break;
}
}
+
+ if( alreadyDrawn )
+ continue;
+
+ Object *owner = TheGameLogic->findObjectByID( *id );
+ if( owner == NULL || owner->isEffectivelyDead() )
+ continue;
+
+ OrderHint hint;
+ hint.owner = *id;
+ hint.from = *owner->getPosition();
+
+ // the order the group is on right now is no longer in the list, so it is drawn from here
+ const Object *active = m_shiftAttackQueueActive.targetID != INVALID_ID
+ ? TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID ) : NULL;
+ if( active && !active->isEffectivelyDead() )
+ {
+ hint.kind = ORDER_HINT_ATTACK;
+ hint.to = *active->getPosition();
+ addOrderHint( hint, previous );
+ hint.from = hint.to;
+ }
+ else if( m_shiftAttackQueueActive.targetID == INVALID_ID )
+ {
+ hint.kind = ORDER_HINT_ATTACK_MOVE;
+ hint.to = m_shiftAttackQueueActive.pos;
+ addOrderHint( hint, previous );
+ hint.from = hint.to;
+ }
+
+ addShiftAttackQueueTail( hint, previous );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Every target still owed, one thread from the last point to the next, starting wherever the hint
+ * handed in leaves off. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::addShiftAttackQueueTail( OrderHint& hint, const std::vector<OrderHint>& previous )
+{
+ for( std::vector<AttackWaypoint>::const_iterator qit = m_shiftAttackQueue.begin();
+ qit != m_shiftAttackQueue.end(); ++qit )
+ {
+ if( qit->targetID != INVALID_ID )
+ {
+ // a queued victim is drawn where it stands now rather than where it stood when the player
+ // picked it, so the thread follows a target that is driving away. One that died while it
+ // waited its turn is drawn nowhere: the order will be skipped
+ const Object *victim = TheGameLogic->findObjectByID( qit->targetID );
+ if( victim == NULL || victim->isEffectivelyDead() )
+ continue;
+
+ hint.kind = ORDER_HINT_ATTACK;
+ hint.to = *victim->getPosition();
+ }
+ else
+ {
+ hint.kind = ORDER_HINT_ATTACK_MOVE;
+ hint.to = qit->pos;
+ }
+
+ addOrderHint( hint, previous );
+ hint.from = hint.to;
}
}
+//-------------------------------------------------------------------------------------------------
+/** Add a marker to this frame's list, carrying over when it first appeared. The list is thrown
+ * away and rebuilt from the units every frame, so without this every marker would be newborn on
+ * every frame and none of them would ever finish sliding in.
+ *
+ * A marker is last frame's marker when it is the n-th one belonging to the same unit. Matching
+ * on the destination instead would restart the slide on every frame of a chase, and matching on
+ * the unit alone would give a whole queue one age. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::addOrderHint( OrderHint& hint, const std::vector<OrderHint>& previous )
+{
+ Int ordinal = 0;
+ for( std::vector<OrderHint>::const_iterator it = m_orderHints.begin();
+ it != m_orderHints.end(); ++it )
+ {
+ if( it->owner == hint.owner )
+ ordinal++;
+ }
+
+ hint.bornMs = timeGetTime();
+
+ Int seen = 0;
+ for( std::vector<OrderHint>::const_iterator it = previous.begin();
+ it != previous.end(); ++it )
+ {
+ if( it->owner != hint.owner )
+ continue;
+ if( seen++ == ordinal )
+ {
+ hint.bornMs = it->bornMs;
+ break;
+ }
+ }
+
+ m_orderHints.push_back( hint );
+}
+
//-------------------------------------------------------------------------------------------------
/** The attack key is armed and the player has pressed the left button: from here a drag draws a
* circle rather than a selection box. */
@@ -2889,24 +3080,46 @@ void InGameUI::updateAttackCircle( const ICoord2D& pt )
}
//-------------------------------------------------------------------------------------------------
-/** Everything hostile standing in the circle becomes a queue, nearest first, and the group is put
- * on the head of it. Shroud decides membership: a target the player cannot see is not in the
- * circle, whatever the partition manager knows about it. */
+/** The circle the player is dragging, in world terms: the anchor is its centre and the cursor sits
+ * on its rim. Both the rim drawn on the screen and the wash laid on the ground ask this, so they
+ * cannot disagree about where the circle is. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::issueAttackCircle( void )
+Bool InGameUI::getAttackCircleGround( Coord3D& center, Real& radius ) const
{
- m_isAttackCircling = FALSE;
- clearAttackQueue();
+ if( !m_isAttackCircling )
+ return FALSE;
- Coord3D center, rim;
+ Coord3D rim;
TheTacticalView->screenToTerrain( &m_attackCircleAnchor, &center );
TheTacticalView->screenToTerrain( &m_attackCircleCursor, &rim );
const Real dx = rim.x - center.x;
const Real dy = rim.y - center.y;
- const Real radius = sqrtf( dx * dx + dy * dy );
- if( radius < 1.0f )
- return;
+ radius = (Real)sqrt( dx * dx + dy * dy );
+
+ // a press that has not been dragged anywhere is a click, not a circle
+ return radius >= 1.0f;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Everything hostile standing in the circle joins the shift queue, nearest first, and the group is
+ * put on the head of it. Shroud decides membership: a target the player cannot see is not in the
+ * circle, whatever the partition manager knows about it. The targets go through the same queue a
+ * shift-clicked attack uses, so the whole list is drawn on the ground as threads and markers
+ * instead of only the one target the group happens to be shooting at. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::issueAttackCircle( void )
+{
+ Coord3D center;
+ Real radius;
+ const Bool wasDragged = getAttackCircleGround( center, radius );
+
+ m_isAttackCircling = FALSE;
+
+ // the button went down and came back up without going anywhere, so this was a plain attack
+ // click and the order belongs to the command translator, not here
+ if( !wasDragged )
+ return FALSE;
Player *local = ThePlayerList->getLocalPlayer();
const Int localIndex = local->getPlayerIndex();
@@ -2915,6 +3128,7 @@ void InGameUI::issueAttackCircle( void )
FROM_CENTER_2D, NULL,
ITER_SORTED_NEAR_TO_FAR );
MemoryPoolObjectHolder holder( iter );
+ Int targetCount = 0;
for( Object *obj = iter->first(); obj; obj = iter->next() )
{
if( obj->isEffectivelyDead() )
@@ -2924,82 +3138,44 @@ void InGameUI::issueAttackCircle( void )
if( obj->getShroudedStatus( localIndex ) > OBJECTSHROUD_PARTIAL_CLEAR )
continue;
- m_attackQueue.push_back( obj->getID() );
+ queueAttackWaypoint( obj->getPosition(), obj );
+ targetCount++;
}
- DEBUG_LOG(("attack circle: radius %.0f, %d targets\n", radius, (Int)m_attackQueue.size()));
- if( m_attackQueue.empty() )
- return;
-
- // who the queue belongs to. The orders go to whatever is selected when each one is sent, so a
- // changed selection has to end the queue rather than quietly redirect it
- for( DrawableList::const_iterator it = m_selectedDrawables.begin();
- it != m_selectedDrawables.end(); ++it )
- {
- Object *obj = (*it)->getObject();
- if( obj )
- m_attackQueueUnits.push_back( obj->getID() );
- }
- std::sort( m_attackQueueUnits.begin(), m_attackQueueUnits.end() );
-
- updateAttackQueue();
-}
-
-//-------------------------------------------------------------------------------------------------
-void InGameUI::clearAttackQueue( void )
-{
- m_attackQueue.clear();
- m_attackQueueUnits.clear();
- m_attackQueueTarget = INVALID_ID;
+ DEBUG_LOG(("attack circle: radius %.0f, %d targets, %d selected\n", radius, targetCount,
+ getSelectCount()));
+ return TRUE;
}
//-------------------------------------------------------------------------------------------------
-/** One order per target, sent when the target before it stops existing. This is the player's own
- * click repeated by the client, so it is an ordinary message on the stream and the logic learns
- * nothing new: no queue lives in the simulation. */
+/** Every selected object by id, sorted, which is how the shift queue recognises the group it was
+ * given to. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::updateAttackQueue( void )
+void InGameUI::collectSelectedObjectIDs( std::vector<ObjectID>& ids ) const
{
- if( m_attackQueue.empty() && m_attackQueueTarget == INVALID_ID )
- return;
-
- // the selection is the queue's owner, so a different selection means the queue is over
- std::vector<ObjectID> current;
+ ids.clear();
for( DrawableList::const_iterator it = m_selectedDrawables.begin();
it != m_selectedDrawables.end(); ++it )
{
Object *obj = (*it)->getObject();
if( obj )
- current.push_back( obj->getID() );
- }
- std::sort( current.begin(), current.end() );
-
- if( current != m_attackQueueUnits )
- {
- clearAttackQueue();
- return;
- }
-
- Object *target = TheGameLogic->findObjectByID( m_attackQueueTarget );
- if( target && !target->isEffectivelyDead() )
- return;
-
- while( !m_attackQueue.empty() )
- {
- const ObjectID next = m_attackQueue.front();
- m_attackQueue.erase( m_attackQueue.begin() );
-
- Object *obj = TheGameLogic->findObjectByID( next );
- if( obj == NULL || obj->isEffectivelyDead() )
- continue;
-
- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );
- msg->appendObjectIDArgument( next );
- m_attackQueueTarget = next;
- return;
+ ids.push_back( obj->getID() );
}
+ std::sort( ids.begin(), ids.end() );
+}
- clearAttackQueue();
+//-------------------------------------------------------------------------------------------------
+/** The queue belongs to the group that was told, and it has to survive that group being shot at:
+ * whatever is left of it carries on down the list. Comparing the two lists for equality instead
+ * meant one tank dying threw away every target still owed, which is what the group stopping dead
+ * after its first kill was. Selecting anything that was not told ends the queue, because those
+ * units never agreed to the list and the next order would land on them. */
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::selectionOwnsShiftAttackQueue( const std::vector<ObjectID>& selected ) const
+{
+ return !selected.empty() &&
+ std::includes( m_shiftAttackQueueUnits.begin(), m_shiftAttackQueueUnits.end(),
+ selected.begin(), selected.end() );
}
//-------------------------------------------------------------------------------------------------
@@ -3015,24 +3191,18 @@ void InGameUI::queueAttackWaypoint( const Coord3D *pos, Object *targetObj )
order.pos = *pos;
order.targetID = targetObj ? targetObj->getID() : INVALID_ID;
- // who the queue belongs to. A changed selection starts a fresh queue rather than adding to
- // whatever the old selection was doing
+ // who the queue belongs to. A selection that is not part of the group holding the queue starts
+ // a fresh one rather than adding to whatever the old selection was doing
std::vector<ObjectID> current;
- for( DrawableList::const_iterator it = m_selectedDrawables.begin();
- it != m_selectedDrawables.end(); ++it )
- {
- Object *obj = (*it)->getObject();
- if( obj )
- current.push_back( obj->getID() );
- }
- std::sort( current.begin(), current.end() );
+ collectSelectedObjectIDs( current );
- if( !m_shiftAttackQueueRunning || current != m_shiftAttackQueueUnits )
+ if( !m_shiftAttackQueueRunning || !selectionOwnsShiftAttackQueue( current ) )
{
clearShiftAttackQueue();
m_shiftAttackQueueUnits = current;
m_shiftAttackQueueRunning = TRUE;
m_shiftAttackQueueActive = order;
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
if( order.targetID != INVALID_ID )
{
@@ -3059,51 +3229,238 @@ void InGameUI::clearShiftAttackQueue( void )
m_shiftAttackQueueRunning = FALSE;
m_shiftAttackQueueActive.targetID = INVALID_ID;
m_shiftAttackQueueActive.pos.zero();
+ m_shiftAttackQueueEngagedFrame = 0;
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ m_shiftAttackQueueWaitingForSelection = FALSE;
}
//-------------------------------------------------------------------------------------------------
-/** The order in flight ends when its target dies (an object target) or nobody selected is still
- * chasing it down (an attack-move point); either way, the next queued order goes out then, same
- * as updateAttackQueue(). */
+/** What the queue just did, and what every unit holding it was doing at that moment. The queue is
+ * driven by the player, so no unattended run can reproduce a fault in it; this line is the whole
+ * instrument. One per event, never one per frame. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::logShiftAttackQueue( const char *why ) const
+{
+ AsciiString census;
+ for( DrawableList::const_iterator it = m_selectedDrawables.begin();
+ it != m_selectedDrawables.end(); ++it )
+ {
+ Object *obj = (*it)->getObject();
+ if( obj == NULL )
+ continue;
+
+ AIUpdateInterface *ai = obj->getAIUpdateInterface();
+ const JetAIUpdate *jet = ai ? ai->getJetAIUpdate() : NULL;
+
+ AsciiString one;
+ one.format( " [%d %s state %d goal %d%s%s%s]",
+ (Int)obj->getID(),
+ obj->getTemplate()->getName().str(),
+ ai ? (Int)ai->getCurrentStateID() : -1,
+ ( ai && ai->getGoalObject() ) ? (Int)ai->getGoalObject()->getID() : 0,
+ obj->isOutOfAmmo() ? " dry" : "",
+ ( jet && jet->friend_isRearming() ) ? " rearming" : "",
+ ( ai && ai->isIdle() ) ? " idle" : "" );
+ census.concat( one );
+ }
+
+ DEBUG_LOG(("shift attack queue: frame %d, %s, active %d, %d owed, told %d:%s\n",
+ TheGameLogic->getFrame(), why,
+ (Int)m_shiftAttackQueueActive.targetID,
+ (Int)m_shiftAttackQueue.size(),
+ (Int)m_shiftAttackQueueUnits.size(),
+ census.str()));
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Put one entry of the queue on the message stream, as the ordinary order it would have been if the
+ * player had clicked it by hand. Sent again rather than remembered, so a flight that had to go
+ * home for ammo picks the same order back up. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::sendShiftAttackOrder( const AttackWaypoint& waypoint )
+{
+ if( waypoint.targetID != INVALID_ID )
+ {
+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );
+ msg->appendObjectIDArgument( waypoint.targetID );
+ }
+ else
+ {
+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );
+ msg->appendLocationArgument( waypoint.pos );
+ msg->appendBooleanArgument( isInForceAttackMode() );
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The order in flight is over when the target is dead, or when the group has genuinely given up on
+ * it. Dead was the only way the queue knew, and a target nobody selected could reach or hurt held
+ * the whole list behind it for the rest of the match - which is what "they only attacked the first
+ * one" was.
+ *
+ * Giving up is measured over time rather than on one frame. A unit chasing something that is
+ * driving away drops its goal for a frame here and there while it repaths, and a target that runs
+ * must not fall out of the list because of it; the order is only abandoned after nobody has been
+ * on it for a couple of seconds, which is long enough that the target really is out of reach. */
//-------------------------------------------------------------------------------------------------
void InGameUI::updateShiftAttackQueue( void )
{
+ // two seconds at the logic's own rate: longer than any repath, shorter than a stalled list
+ const UnsignedInt ABANDON_ORDER_FRAMES = 60;
+
if( !m_shiftAttackQueueRunning )
return;
- // the selection is the queue's owner, so a different selection means the queue is over
std::vector<ObjectID> current;
- for( DrawableList::const_iterator it = m_selectedDrawables.begin();
- it != m_selectedDrawables.end(); ++it )
+ collectSelectedObjectIDs( current );
+
+ //
+ // Nothing in hand does not mean the list is over. An aircraft leaves the selection while it is
+ // on the ground at its airfield, and a flight that went home for ammo therefore stops being a
+ // group at all for a while - which used to throw the whole list away a second after the first
+ // target died, with the planes still in the air on their way back. So an empty selection holds
+ // the list instead of ending it, and it only really ends when every unit that was told is gone.
+ //
+ if( current.empty() )
{
- Object *obj = (*it)->getObject();
- if( obj )
- current.push_back( obj->getID() );
+ Int stillAlive = 0;
+ for( std::vector<ObjectID>::const_iterator id = m_shiftAttackQueueUnits.begin();
+ id != m_shiftAttackQueueUnits.end(); ++id )
+ {
+ const Object *told = TheGameLogic->findObjectByID( *id );
+ if( told && !told->isEffectivelyDead() )
+ stillAlive++;
+ }
+
+ if( stillAlive == 0 )
+ {
+ logShiftAttackQueue( "over, every unit that was told is gone" );
+ clearShiftAttackQueue();
+ return;
+ }
+
+ if( !m_shiftAttackQueueWaitingForSelection )
+ {
+ m_shiftAttackQueueWaitingForSelection = TRUE;
+ DEBUG_LOG(("shift attack queue: frame %d, holding, nothing in hand but %d of the group is alive\n",
+ TheGameLogic->getFrame(), stillAlive));
+ }
+
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ return;
}
- std::sort( current.begin(), current.end() );
- if( current != m_shiftAttackQueueUnits )
+ m_shiftAttackQueueWaitingForSelection = FALSE;
+
+ if( !selectionOwnsShiftAttackQueue( current ) )
{
+ logShiftAttackQueue( "dropped, the selection is not the group it was given to" );
clearShiftAttackQueue();
return;
}
- if( m_shiftAttackQueueActive.targetID != INVALID_ID )
- {
- Object *target = TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID );
- if( target && !target->isEffectivelyDead() )
- return;
- }
- else
+ Object *target = m_shiftAttackQueueActive.targetID != INVALID_ID
+ ? TheGameLogic->findObjectByID( m_shiftAttackQueueActive.targetID ) : NULL;
+
+ // a target with enough shots already in the air to kill it is finished as far as the queue is
+ // concerned. Aircraft are the reason: a flight fires from range and the missiles take seconds to
+ // arrive, and without this every plane in the group keeps circling a corpse that has not fallen
+ // over yet instead of taking the next target on the list
+ if( target && ( target->isEffectivelyDead() || IncomingDamageTracker::isAlreadyDoomed( target ) ) )
+ target = NULL;
+
+ if( target || m_shiftAttackQueueActive.targetID == INVALID_ID )
{
+ Bool anyEngaged = FALSE;
+ Bool anyRearming = FALSE;
+ Bool anyReadyToGoAgain = FALSE;
+
for( DrawableList::const_iterator it = m_selectedDrawables.begin();
it != m_selectedDrawables.end(); ++it )
{
Object *obj = (*it)->getObject();
AIUpdateInterface *ai = obj ? obj->getAIUpdateInterface() : NULL;
- if( ai && ai->getAIStateType() == AI_ATTACK_MOVE_TO )
- return;
+ if( ai == NULL )
+ continue;
+
+ const JetAIUpdate *jet = ai->getJetAIUpdate();
+
+ // on the victim it was given, or walking the attack-move point it was given
+ Bool onOrder = target ? ( ai->getGoalObject() == target )
+ : ( ai->getAIStateType() == AI_ATTACK_MOVE_TO );
+
+ //
+ // An aircraft that is taxiing or climbing is carrying the order in its pocket rather than
+ // in its goal - taking off clears the state machine - so for the length of every takeoff it
+ // read here as nobody being on the order at all. Two seconds of that and the list moved on
+ // without it, which is how a flight that went home for ammo came back to an empty queue.
+ //
+ if( !onOrder && jet != NULL )
+ {
+ ObjectID heldTarget = INVALID_ID;
+ Coord3D heldPos;
+ if( jet->friend_getHeldOrder( heldTarget, heldPos ) != AICMD_NO_COMMAND )
+ onOrder = target ? ( heldTarget == target->getID() ) : TRUE;
+ }
+
+ if( onOrder )
+ {
+ anyEngaged = TRUE;
+ break;
+ }
+
+ if( jet == NULL )
+ continue;
+
+ if( jet->friend_isRearming() || obj->isOutOfAmmo() )
+ anyRearming = TRUE;
+ else if( ai->isIdle() )
+ anyReadyToGoAgain = TRUE;
+ }
+
+ if( anyEngaged )
+ {
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ return;
+ }
+
+ //
+ // An aircraft that has run dry leaves the target, lands, fills its racks and comes back, and
+ // none of that is giving up on the order - but it looks exactly like it from here, and the
+ // whole list used to drain one entry every two seconds while the flight was away. So the
+ // clock stops for the trip, and the order that was interrupted is sent again when a plane is
+ // back in the air with a full load. A jet is not told to resume by itself: only hunting and
+ // attack moving survive a reload, an ordered attack on a particular target does not.
+ //
+ if( anyRearming )
+ {
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ if( !m_shiftAttackQueueWaitingForRearm )
+ {
+ m_shiftAttackQueueWaitingForRearm = TRUE;
+ logShiftAttackQueue( "holding, the group has gone home for ammo" );
+ }
+ return;
+ }
+
+ if( m_shiftAttackQueueWaitingForRearm && anyReadyToGoAgain )
+ {
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ logShiftAttackQueue( "rearmed, sending the order again" );
+ sendShiftAttackOrder( m_shiftAttackQueueActive );
+ return;
}
+
+ if( TheGameLogic->getFrame() - m_shiftAttackQueueEngagedFrame < ABANDON_ORDER_FRAMES )
+ return;
+
+ logShiftAttackQueue( "nobody on this order for two seconds, moving on" );
+ }
+ else
+ {
+ logShiftAttackQueue( "the order in flight is finished, moving on" );
}
while( !m_shiftAttackQueue.empty() )
@@ -3114,61 +3471,28 @@ void InGameUI::updateShiftAttackQueue( void )
if( next.targetID != INVALID_ID )
{
Object *obj = TheGameLogic->findObjectByID( next.targetID );
- if( obj == NULL || obj->isEffectivelyDead() )
+ if( obj == NULL || obj->isEffectivelyDead() || IncomingDamageTracker::isAlreadyDoomed( obj ) )
+ {
+ DEBUG_LOG(("shift attack queue: frame %d, skipping target %d, %s\n",
+ TheGameLogic->getFrame(), (Int)next.targetID,
+ obj == NULL ? "gone" : ( obj->isEffectivelyDead() ? "dead" : "already covered" )));
continue;
-
- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );
- msg->appendObjectIDArgument( next.targetID );
- }
- else
- {
- GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );
- msg->appendLocationArgument( next.pos );
- msg->appendBooleanArgument( isInForceAttackMode() );
+ }
}
+ sendShiftAttackOrder( next );
+
m_shiftAttackQueueActive = next;
+ m_shiftAttackQueueEngagedFrame = TheGameLogic->getFrame();
+ m_shiftAttackQueueWaitingForRearm = FALSE;
+ logShiftAttackQueue( "next order out" );
return;
}
+ logShiftAttackQueue( "list is empty, done" );
clearShiftAttackQueue();
}
-//-------------------------------------------------------------------------------------------------
-/** A move command has occurred, start graphical "hint". */
-//-------------------------------------------------------------------------------------------------
-void InGameUI::createMoveHint( const GameMessage *msg )
-{
- Int i;
-
- // first, remove any existing move hint for this source if present
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- if( m_moveHint[ i ].sourceID == msg->getArgument( 0 )->objectID &&
- m_moveHint[ i ].frame != 0 )
- expireHint( MOVE_HINT, i );
-
-
- if( getSelectCount() == 1 )
- {
- Drawable *draw = getFirstSelectedDrawable();
- Object *obj = draw ? draw->getObject() : NULL;
- if( obj && obj->isKindOf( KINDOF_IMMOBILE ) )
- {
- //Don't allow move hints to be created if our selected object can't move!
- return;
- }
- }
-
- m_moveHint[ m_nextMoveHint ].frame = TheGameClient->getFrame();
- m_moveHint[ m_nextMoveHint ].pos = msg->getArgument( 0 )->location;
-
- m_nextMoveHint++;
-
- // wrap around
- if (m_nextMoveHint == InGameUI::MAX_MOVE_HINTS)
- m_nextMoveHint = 0;
-}
-
//-------------------------------------------------------------------------------------------------
/** An attack command has occurred, start graphical "hint". */
//-------------------------------------------------------------------------------------------------
@@ -4535,6 +4859,12 @@ void InGameUI::deselectDrawable( Drawable *draw )
if( draw->isSelected() )
{
+ if( m_shiftAttackQueueRunning )
+ {
+ DEBUG_LOG(("shift attack queue: frame %d, %s is leaving the selection\n",
+ TheGameLogic->getFrame(),
+ draw->getObject() ? draw->getObject()->getTemplate()->getName().str() : "a drawable"));
+ }
m_frameSelectionChanged = TheGameLogic->getFrame();
// clear the selected bit out of the drawable
@@ -4571,6 +4901,12 @@ void InGameUI::deselectDrawable( Drawable *draw )
//-------------------------------------------------------------------------------------------------
void InGameUI::deselectAllDrawables( Bool postMsg )
{
+ if( m_shiftAttackQueueRunning && !m_selectedDrawables.empty() )
+ {
+ DEBUG_LOG(("shift attack queue: frame %d, the whole selection is being cleared at once\n",
+ TheGameLogic->getFrame()));
+ }
+
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
// loop through all the selected drawables
@@ -5094,34 +5430,6 @@ void InGameUI::postDraw( void )
} // end postDraw
-//-------------------------------------------------------------------------------------------------
-/** Expire a hint of the specified type with the corresponding hint index */
-//-------------------------------------------------------------------------------------------------
-void InGameUI::expireHint( HintType type, UnsignedInt hintIndex )
-{
-
- if( type == MOVE_HINT )
- {
-
- // sanity
- if( hintIndex < 0 || hintIndex >= MAX_MOVE_HINTS )
- return;
-
- m_moveHint[ hintIndex ].sourceID = 0;
- m_moveHint[ hintIndex ].frame = 0;
-
- } // end if
- else
- {
-
- // undefined hint type
- DEBUG_CRASH(("undefined hint type"));
- return;
-
- } // end else
-
-} // end expireHint
-
//-------------------------------------------------------------------------------------------------
/** Create the control user interface GUI */
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 42622dfb1..79cd3801b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -3972,7 +3972,11 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
}
TheInGameUI->clearAttackMoveToMode();
- TheInGameUI->clearAttackQueue();
+
+ // a hand-given order ends whatever list the group was working through, unless shift
+ // says the player is adding to it
+ if( !TheInGameUI->isInWaypointMode() )
+ TheInGameUI->clearShiftAttackQueue();
const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
if( selected && !selected->empty() )
@@ -3982,14 +3986,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
}
}
- //Kris: July 7, 2003. Added this code to deselect build placement mode when right clicked. This fixes
- //a bug where you couldn't cancel the sneak attack mode via right click. This only happened when you
- //didn't have anything selected which is possible via the shortcut bar. Normally, it would get deselected
- //via the deselect drawable code.
- if( TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift, m_mouseRightDown, m_mouseRightUp) )
- {
- TheInGameUI->placeBuildAvailable( NULL, NULL );
- }
+ // a structure waiting to be placed is dropped by the same release, over in
+ // SelectionXlat, which sees it whether this was a click or a drag
break;
}
@@ -4052,8 +4050,12 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
disp = DESTROY_MESSAGE;
TheInGameUI->clearAttackMoveToMode();
- // a hand-given order ends whatever list the circle was working through
- TheInGameUI->clearAttackQueue();
+
+ // a hand-given order ends whatever list the group was working through, unless shift
+ // says the player is adding to it - in which case the order just given is itself the
+ // newest entry in that list
+ if( !TheInGameUI->isInWaypointMode() )
+ TheInGameUI->clearShiftAttackQueue();
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HintSpy.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HintSpy.cpp
index 331fdfa6b..31ea8fa76 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HintSpy.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HintSpy.cpp
@@ -111,14 +111,6 @@ GameMessageDisposition HintSpyTranslator::translateGameMessage(const GameMessage
TheInGameUI->endAreaSelectHint( msg );
break;
- //-----------------------------------------------------------------------------
- case GameMessage::MSG_DO_MOVETO:
- case GameMessage::MSG_DO_ATTACKMOVETO:
- case GameMessage::MSG_DO_FORCEMOVETO:
- case GameMessage::MSG_ADD_WAYPOINT:
- TheInGameUI->createMoveHint( msg );
- break;
-
//-----------------------------------------------------------------------------
case GameMessage::MSG_DO_ATTACK_OBJECT:
TheInGameUI->createAttackHint( msg );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
index 9a35876da..1ffdb4fce 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
@@ -273,14 +273,7 @@ SelectionTranslator::SelectionTranslator()
m_lastGroupSelGroup = -1;
m_selectFeedbackAnchor.x = 0;
m_selectFeedbackAnchor.y = 0;
- m_deselectFeedbackAnchor.x = 0;
- m_deselectFeedbackAnchor.y = 0;
- m_lastClick = 0;
- //Added By Sadullah Nader
- //Initializtion(s) inserted
- m_deselectDownCameraPosition.zero();
m_displayedMaxWarning = FALSE;
- //
m_selectCountMap.clear();
TheSelectionTranslator = this;
@@ -494,8 +487,18 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
case GameMessage::MSG_MOUSE_LEFT_DOUBLE_CLICK:
{
Int modifiers = msg->getArgument(1)->integer;
-
- // Pressing ctrl is disallowed for double clicking
+
+ // the release that ended a circle arrives as a double click when the circle was the
+ // second of a quick pair. Letting it through would select everything of one kind on the
+ // screen, and that new selection is exactly what drops the orders just given
+ if( m_attackCircleJustIssued )
+ {
+ m_attackCircleJustIssued = FALSE;
+ disp = DESTROY_MESSAGE;
+ break;
+ }
+
+ // Pressing ctrl is disallowed for double clicking
if (TheInGameUI->isInForceAttackMode())
break;
@@ -1014,7 +1017,14 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
// Note that the raw left messages are only used to draw feedback now when
// appropriate. All actual selection code takes place in
// MSG_MOUSE_LEFT_CLICK & MSG_MOUSE_LEFT_DOUBLE_CLICK
+ //
+ // Windows sends the second press of a quick pair as WM_LBUTTONDBLCLK rather than
+ // WM_LBUTTONDOWN, so it arrives here as a double click. Sweeping a second circle straight
+ // after the first is exactly that pair: without this label no circle began, the drag grew a
+ // selection box instead, and the box swapped the group out from under the order.
+ //
case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
+ case GameMessage::MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK:
{
// cannot actually start area selection yet - have to wait for cursor to move a bit
m_leftMouseButtonIsDown = true;
@@ -1039,10 +1049,19 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
// click that follows this release has to be eaten or it would reselect under the anchor
if( TheInGameUI->isAttackCircling() )
{
- TheInGameUI->issueAttackCircle();
- TheInGameUI->clearAttackMoveToMode();
- m_attackCircleJustIssued = TRUE;
- break;
+ // a circle drawn with shift adds its targets to the end of the list the group is
+ // already working through; without shift it replaces that list
+ if( !TheInGameUI->isInWaypointMode() )
+ TheInGameUI->clearShiftAttackQueue();
+
+ // a press with the attack key that never became a drag is an ordinary attack click,
+ // and the click that follows this release is the order. Only a real circle eats it
+ if( TheInGameUI->issueAttackCircle() )
+ {
+ TheInGameUI->clearAttackMoveToMode();
+ m_attackCircleJustIssued = TRUE;
+ break;
+ }
}
if (m_dragSelecting) {
@@ -1088,82 +1107,35 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
break;
}
- //-----------------------------------------------------------------------------
- case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
- {
- // There are three ways in which we can ignore this as a deselect:
- // 1) 2-D position on screen
- // 2) Time has exceeded the time which we allow for this to be a click.
- // 3) 3-D camera position has changed
- 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:
{
- ICoord2D delta, pixel;
- UnsignedInt currentTime;
- Coord3D cameraPos;
-
- TheTacticalView->getPosition(&cameraPos);
- cameraPos.sub(&m_deselectDownCameraPosition);
-
- pixel = msg->getArgument( 0 )->pixel;
- currentTime = (UnsignedInt) msg->getArgument( 2 )->integer;
-
- delta.x = m_deselectFeedbackAnchor.x - pixel.x;
- delta.y = m_deselectFeedbackAnchor.y - pixel.y;
-
- Bool isClick = TRUE;
- if (isClick &&
- abs(delta.x) > TheMouse->m_dragTolerance ||
- abs(delta.y) > TheMouse->m_dragTolerance)
- {
- isClick = FALSE;
- }
-
- if (isClick &&
- currentTime - m_lastClick > TheMouse->m_dragToleranceMS)
+ //
+ // The right button drops whatever is armed, and it does so on a drag as well as on a
+ // click. A dozer placing a row of structures with shift held is the case that made this
+ // matter: the player right-clicks to send it somewhere, the cursor travels a few pixels
+ // while the button is down, the order goes out as a formation move - and the ghost used
+ // to stay riding the cursor because the cancel only ran on a strict click.
+ //
+ // Nothing here eats the message. The order itself arrives as the separate
+ // MSG_MOUSE_RIGHT_CLICK the meta translator inserts, and CommandXlat still needs this
+ // release to close off a formation drag it started.
+ //
+ if( TheInGameUI->getGUICommand() )
{
- isClick = FALSE;
+ //Cancel GUI command mode... don't deselect units.
+ TheInGameUI->setGUICommand( NULL );
+ TheInGameUI->setScrolling( FALSE );
}
-
- if (isClick &&
- cameraPos.length() > TheMouse->m_dragTolerance3D)
+ else if( TheInGameUI->getPendingPlaceType() != NULL )
{
- isClick = FALSE;
- }
-
- // right click behavior (not right drag)
- if (isClick)
- {
- //Added support to cancel the GUI command without deselecting the unit(s) involved
- //when you right click.
- if( TheInGameUI->getGUICommand() )
- {
- //Cancel GUI command mode... don't deselect units.
- TheInGameUI->setGUICommand( NULL );
-
- //With a GUI command cancel, we want no other behavior.
- disp = DESTROY_MESSAGE;
- TheInGameUI->setScrolling( FALSE );
- }
- else if( TheInGameUI->getPendingPlaceSourceObjectID() != INVALID_ID )
- {
- //Cancel the building placement, and keep the builder selected: you almost always
- //want to place something else with it, and reselecting it costs a click.
- TheInGameUI->placeBuildAvailable( NULL, NULL );
-
- disp = DESTROY_MESSAGE;
- TheInGameUI->setScrolling( FALSE );
- }
- // The right button used to deselect here in the classic mouse mode. It does not any
- // more: it is the order button, and an order that hits nothing is simply no order.
+ //Cancel the building placement, and keep the builder selected: you almost always
+ //want to place something else with it, and reselecting it costs a click.
+ TheInGameUI->placeBuildAvailable( NULL, NULL );
+ TheInGameUI->setScrolling( FALSE );
}
+ // The right button used to deselect here in the classic mouse mode. It does not any
+ // more: it is the order button, and an order that hits nothing is simply no order.
break;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
index 1c1efc6bd..418065a5b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
@@ -5386,6 +5386,22 @@ StateReturnType AIAttackAimAtTargetState::onEnter()
return STATE_CONTINUE;
}
+//----------------------------------------------------------------------------------------------------------
+/**
+ * Put this unit's intended shot on the ledger before it is fired. Said again every frame the unit is
+ * still lining the shot up, and forgotten a few frames after it stops saying it.
+ */
+static void announceIntendedShot(Object *shooter, Object *victim)
+{
+ Weapon *weapon = shooter->getCurrentWeapon();
+ if (weapon == NULL)
+ return;
+
+ IncomingDamageTracker::claimShot(victim->getID(), shooter->getID(),
+ weapon->estimateWeaponDamage(shooter, victim),
+ TheGameLogic->getFrame());
+}
+
//----------------------------------------------------------------------------------------------------------
/**
* Orient the machine's owner to face towards the given target
@@ -5405,6 +5421,11 @@ StateReturnType AIAttackAimAtTargetState::update()
{
if (!victim || victim->isEffectivelyDead())
return STATE_FAILURE; // can't aim at dead things
+
+ // tell everyone else what this shot is going to take off the victim while it is still being
+ // aimed, so a second unit lining up the same target can see the kill is covered before it
+ // commits to the trip rather than on the frame the first round launches
+ announceIntendedShot(source, victim);
}
WhichTurretType tur = sourceAI->getWhichTurretForCurWeapon();
@@ -5568,9 +5589,11 @@ StateReturnType AIAttackFireWeaponState::onEnter()
}
}
+ m_saidHeldFire = FALSE;
+
obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_IS_FIRING_WEAPON ) );
obj->preFireCurrentWeapon( getMachineGoalObject() );
- return STATE_CONTINUE;
+ return STATE_CONTINUE;
}
//----------------------------------------------------------------------------------------------------------
@@ -5592,16 +5615,40 @@ StateReturnType AIAttackFireWeaponState::update()
return STATE_FAILURE;
//
- // The shots already in the air add up to more than the victim has left, so this one would be
- // spent on something that is dead the moment they land. Drop the attack: whatever put us on
- // this target on our own initiative - guarding, attack moving, the idle scan - runs again on
- // its own clock, and the acquisition filter now passes over this victim and hands us the next
- // one, or nothing, in which case we simply hold. Only our own initiative is second-guessed
- // here; an explicit order from the player is carried out as given.
+ // What is in the air, plus what other units have announced they are about to fire, adds up to
+ // more than the victim has left: this round would be spent on something that is dead the
+ // moment the rest of it lands.
+ //
+ // Hold the shot. Failing out of the fire state goes back to aiming rather than out of the
+ // attack, so nothing is given up: the unit keeps the victim and keeps its aim, it just does
+ // not spend the round. A unit that picked this target itself gets a fresh scan out of the
+ // thing that put it here - guarding, attack moving, the idle scan - and that scan passes over
+ // a doomed victim, so it moves on. One under orders waits for whoever re-aims it, which is
+ // what an attack circle working down its target list does, and arrives at the next victim
+ // with a full load instead of an empty one.
//
- AIUpdateInterface* ai = obj->getAI();
- if (ai && ai->getLastCommandSource() == CMD_FROM_AI && IncomingDamageTracker::isAlreadyDoomed(victim))
+ // A player order used to be exempt from this and fire regardless, which is what put all four
+ // loads of a four plane flight into the first tank they reached: missiles are seconds in the
+ // air, and the other three planes could not see that the kill was already paid for. Booked
+ // damage lapses on its own if the shot never lands, so nothing holds fire forever.
+ //
+ if (IncomingDamageTracker::isSpokenFor(victim, obj->getID()))
+ {
+ if (!m_saidHeldFire)
+ {
+ m_saidHeldFire = TRUE;
+ DEBUG_LOG(("held fire: %s holds, %s has %.0f left and %.0f is already in the air\n",
+ obj->getTemplate()->getName().str(),
+ victim->getTemplate()->getName().str(),
+ victim->getBodyModule()->getHealth(),
+ IncomingDamageTracker::getBookedDamage(victim->getID())));
+ }
return STATE_FAILURE;
+ }
+
+ // still ours to take, so keep saying so: the wind-up before a shot can run for a second and
+ // nothing is in the air during it
+ announceIntendedShot(obj, victim);
}
WeaponSlotType wslot;
Weapon* weapon = obj->getCurrentWeapon(&wslot);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp
index 7517c9c13..60c6781e6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp
@@ -36,6 +36,8 @@ struct BookedShot
ObjectID m_shooter; ///< who fired it, so the landing damage can release its own booking
Real m_amount; ///< damage it is expected to take off the victim, after armor
UnsignedInt m_expireFrame; ///< when the booking lapses even though nothing landed
+ Bool m_isClaim; ///< an announced shot rather than one in the air: invisible to its own shooter
+ UnsignedInt m_claimFrame; ///< when the claim was first made, which is what decides who gets the target
};
typedef std::vector<BookedShot> BookedShotVec;
@@ -58,6 +60,57 @@ static const UnsignedInt BOOKING_SLACK_FRAMES = 15;
static const UnsignedInt MIN_FLIGHT_FRAMES = 1;
static const UnsignedInt MAX_FLIGHT_FRAMES = 90;
+//
+// How long an announced shot stands without being repeated. A unit that is still lining the shot up
+// says so again every frame, so this only has to outlast one frame; the margin is there so a unit
+// whose update is skipped for a frame does not have to start over, and it is short enough that a
+// unit which gives up on the target frees it again within a fifth of a second.
+//
+static const UnsignedInt CLAIM_HOLD_FRAMES = 6;
+
+//-------------------------------------------------------------------------------------------------
+/** Damage genuinely in the air against a victim. Announcements are not counted. */
+//-------------------------------------------------------------------------------------------------
+static Real sumShotsInFlight(ObjectID victim)
+{
+ BookedShotMap::const_iterator vic = theBookings.find(victim);
+ if (vic == theBookings.end())
+ return 0.0f;
+
+ Real total = 0.0f;
+ const BookedShotVec& shots = vic->second;
+ for (BookedShotVec::const_iterator s = shots.begin(); s != shots.end(); ++s)
+ {
+ if (!s->m_isClaim)
+ total += s->m_amount;
+ }
+
+ return total;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** Take back this shooter's announcement against this victim, if it has one standing. */
+//-------------------------------------------------------------------------------------------------
+static void releaseClaim(ObjectID victim, ObjectID shooter)
+{
+ BookedShotMap::iterator vic = theBookings.find(victim);
+ if (vic == theBookings.end())
+ return;
+
+ BookedShotVec& shots = vic->second;
+ for (BookedShotVec::iterator s = shots.begin(); s != shots.end(); ++s)
+ {
+ if (s->m_isClaim && s->m_shooter == shooter)
+ {
+ shots.erase(s);
+ break;
+ }
+ }
+
+ if (shots.empty())
+ theBookings.erase(vic);
+}
+
//-------------------------------------------------------------------------------------------------
void IncomingDamageTracker::reset()
{
@@ -105,14 +158,51 @@ void IncomingDamageTracker::bookShot(ObjectID victim, ObjectID shooter, Real amo
else if (flight > MAX_FLIGHT_FRAMES)
flight = MAX_FLIGHT_FRAMES;
+ // the round is away, so the announcement that preceded it has done its job
+ releaseClaim(victim, shooter);
+
BookedShot shot;
shot.m_shooter = shooter;
shot.m_amount = amount;
shot.m_expireFrame = currentFrame + flight + BOOKING_SLACK_FRAMES;
+ shot.m_isClaim = FALSE;
+ shot.m_claimFrame = 0;
theBookings[victim].push_back(shot);
}
+//-------------------------------------------------------------------------------------------------
+void IncomingDamageTracker::claimShot(ObjectID victim, ObjectID shooter, Real amount,
+ UnsignedInt currentFrame)
+{
+ if (victim == INVALID_ID || shooter == INVALID_ID || amount <= 0.0f)
+ return;
+
+ const UnsignedInt expire = currentFrame + CLAIM_HOLD_FRAMES;
+
+ BookedShotVec& shots = theBookings[victim];
+ for (BookedShotVec::iterator s = shots.begin(); s != shots.end(); ++s)
+ {
+ if (s->m_isClaim && s->m_shooter == shooter)
+ {
+ // saying it again only stands the same claim up for longer: the frame it was first made on
+ // is what holds this unit's place in the queue for the target, so it is left alone
+ s->m_amount = amount;
+ s->m_expireFrame = expire;
+ return;
+ }
+ }
+
+ BookedShot claim;
+ claim.m_shooter = shooter;
+ claim.m_amount = amount;
+ claim.m_expireFrame = expire;
+ claim.m_isClaim = TRUE;
+ claim.m_claimFrame = currentFrame;
+
+ shots.push_back(claim);
+}
+
//-------------------------------------------------------------------------------------------------
void IncomingDamageTracker::shotLanded(ObjectID victim, ObjectID shooter)
{
@@ -123,7 +213,7 @@ void IncomingDamageTracker::shotLanded(ObjectID victim, ObjectID shooter)
BookedShotVec& shots = vic->second;
for (BookedShotVec::iterator s = shots.begin(); s != shots.end(); ++s)
{
- if (s->m_shooter == shooter)
+ if (s->m_shooter == shooter && !s->m_isClaim)
{
// oldest first: a shooter's shots land in the order they were fired
shots.erase(s);
@@ -138,16 +228,7 @@ void IncomingDamageTracker::shotLanded(ObjectID victim, ObjectID shooter)
//-------------------------------------------------------------------------------------------------
Real IncomingDamageTracker::getBookedDamage(ObjectID victim)
{
- BookedShotMap::const_iterator vic = theBookings.find(victim);
- if (vic == theBookings.end())
- return 0.0f;
-
- Real total = 0.0f;
- const BookedShotVec& shots = vic->second;
- for (BookedShotVec::const_iterator s = shots.begin(); s != shots.end(); ++s)
- total += s->m_amount;
-
- return total;
+ return sumShotsInFlight(victim);
}
//-------------------------------------------------------------------------------------------------
@@ -165,3 +246,56 @@ Bool IncomingDamageTracker::isAlreadyDoomed(const Object *victim)
{
return isAlreadyDoomed(victim->getID(), victim->getBodyModule()->getHealth());
}
+
+//-------------------------------------------------------------------------------------------------
+Bool IncomingDamageTracker::isSpokenFor(const Object *victim, ObjectID asker)
+{
+ BookedShotMap::const_iterator vic = theBookings.find(victim->getID());
+ if (vic == theBookings.end())
+ return FALSE;
+
+ const BookedShotVec& shots = vic->second;
+
+ // where the asker stands in the queue for this victim, if it has announced anything at all
+ Bool askerHasClaim = FALSE;
+ UnsignedInt askerClaimFrame = 0;
+ for (BookedShotVec::const_iterator s = shots.begin(); s != shots.end(); ++s)
+ {
+ if (s->m_isClaim && s->m_shooter == asker)
+ {
+ askerHasClaim = TRUE;
+ askerClaimFrame = s->m_claimFrame;
+ break;
+ }
+ }
+
+ Real covered = 0.0f;
+ for (BookedShotVec::const_iterator s = shots.begin(); s != shots.end(); ++s)
+ {
+ if (s->m_isClaim)
+ {
+ if (s->m_shooter == asker)
+ continue;
+
+ //
+ // Only an announcement that got in ahead of ours stops us. Two units that each defer to
+ // the other both hold fire and the target is never shot at all, so the claims are ordered:
+ // whoever spoke first keeps the target, and two that spoke on the same frame are settled by
+ // object id, which every machine in a network game agrees on. A unit that has announced
+ // nothing - one scanning for something to acquire - is behind all of them.
+ //
+ const Bool spokeFirst = !askerHasClaim
+ || s->m_claimFrame < askerClaimFrame
+ || (s->m_claimFrame == askerClaimFrame && s->m_shooter < asker);
+ if (!spokeFirst)
+ continue;
+ }
+
+ covered += s->m_amount;
+ }
+
+ if (covered <= 0.0f)
+ return FALSE;
+
+ return covered >= victim->getBodyModule()->getHealth();
+}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
index 9ab279c00..c7094c9e2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
@@ -5496,13 +5496,15 @@ Bool PartitionFilterPossibleToAttack::allow(Object *objOther)
DEBUG_ASSERTCRASH(m_obj && m_obj->isAbleToAttack(), ("if the object is unable to attack at all, you should filter that out ahead of time!"));
#endif
//
- // Someone else's shots are already in the air and already add up to more than this thing has
- // left, so acquiring it would spend a volley on a corpse. Skipping it here is what spreads a
+ // Someone else's shots, in the air or announced and about to be fired, already add up to more
+ // than this thing has left, so acquiring it would spend a volley on a corpse. Our own
+ // announcement does not count against us, or a unit re-scanning would refuse the target it is
+ // currently lining up. Skipping it here is what spreads a
// group's fire over several targets instead of piling all of it onto the nearest one. This
// filter is only ever used to acquire a target on the unit's own initiative - guarding, attack
// moving, idle scanning - so an explicit attack order is never touched by it.
//
- if (IncomingDamageTracker::isAlreadyDoomed(objOther))
+ if (IncomingDamageTracker::isSpokenFor(objOther, m_obj->getID()))
return FALSE;
//
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
index b1a72b4e5..7b1ea57c5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp
@@ -2583,6 +2583,44 @@ AICommandType JetAIUpdate::friend_getPendingCommandType() const
return AICMD_NO_COMMAND;
}
+//-------------------------------------------------------------------------------------------------
+/** The order this aircraft accepted but has not started yet. Taking off clears the state machine
+ * and parks the command here, so between the player's click and the wheels leaving the ground the
+ * order exists nowhere else. */
+//-------------------------------------------------------------------------------------------------
+AICommandType JetAIUpdate::friend_getHeldOrder( ObjectID& targetID, Coord3D& targetPos ) const
+{
+ if( !getFlag( HAS_PENDING_COMMAND ) )
+ return AICMD_NO_COMMAND;
+
+ targetID = m_mostRecentCommand.getTargetObjectID();
+ targetPos = m_mostRecentCommand.getTargetPosition();
+ return m_mostRecentCommand.getCommandType();
+}
+
+//-------------------------------------------------------------------------------------------------
+/** On its way home, on the ground, or filling its racks: everything between running dry and being
+ * ready to fly out again. An aircraft in here is not refusing the order it was given, it is in the
+ * middle of the trip that lets it carry the order out. */
+//-------------------------------------------------------------------------------------------------
+Bool JetAIUpdate::friend_isRearming() const
+{
+ switch( getStateMachine()->getCurrentStateID() )
+ {
+ case RETURNING_FOR_LANDING:
+ case RETURN_TO_DEAD_AIRFIELD:
+ case CIRCLING_DEAD_AIRFIELD:
+ case LANDING_AWAIT_CLEARANCE:
+ case LANDING:
+ case TAXI_FROM_LANDING:
+ case ORIENT_FOR_PARKING_PLACE:
+ case RELOAD_AMMO:
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
//-------------------------------------------------------------------------------------------------
void JetAIUpdate::friend_purgePendingCommand()
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 1177dc6b6..8d9efe69e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -1426,11 +1426,17 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
Object *enemy = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
// Check enemy, as it is possible that he died this frame.
- if (enemy)
+ if (enemy)
{
if (currentlySelectedGroup)
{
+ // how many units the order actually reached, against how many the player had
+ // selected on their own screen: the two disagreeing is what "only one of them
+ // went" looks like from the outside
+ DEBUG_LOG(("attack order: %d units on %s\n", currentlySelectedGroup->getCount(),
+ enemy->getTemplate()->getName().str()));
+
currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
currentlySelectedGroup->groupAttackObject( enemy, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
index 95ad9f727..2d00b39bb 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
@@ -75,16 +75,14 @@ protected:
virtual View *createView( void ) { return NEW W3DView; }
virtual void drawSelectionRegion( void ); ///< draw the selection region on screen
- virtual void drawMoveHints( View *view ); ///< draw move hint visual feedback
virtual void drawAttackHints( View *view ); ///< draw attack hint visual feedback
virtual void drawPlaceAngle( View *view ); ///< draw place building angle if needed
virtual void drawBuildGrid( void ); ///< the pathfinder's build grid under a pending structure
+ virtual void drawAttackCircleFill( void ); ///< the wash on the ground inside an attack circle
virtual void drawFormationLine( void ); ///< the line a right drag is spreading the selection along
virtual void drawOrderHints( void ); ///< a line from each selected unit to where its order sends it
virtual void drawAttackCircle( void ); ///< the circle a left drag is sweeping targets out of
- RenderObjClass *m_moveHintRenderObj[ MAX_MOVE_HINTS ];
- HAnimClass *m_moveHintAnim[ MAX_MOVE_HINTS ];
RenderObjClass *m_buildingPlacementAnchor;
RenderObjClass *m_buildingPlacementArrow;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
index 7d117c767..2fe591786 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/HeightMap.cpp
@@ -2203,8 +2203,14 @@ void HeightMapRenderObjClass::Render(RenderInfoClass & rinfo)
// the terrain and covered by everything drawn after it, so it reads as paint on the map rather
// than as a wireframe floating over the scene
if( TheInGameUI )
+ {
TheInGameUI->drawBuildGrid();
+ // and the wash inside an attack circle, for the same reason: the units it is sweeping up
+ // have to stand on top of it
+ TheInGameUI->drawAttackCircleFill();
+ }
+
// We do some custom blending, so tell the shader class to reset everything.
DX8Wrapper::Set_Texture(0,NULL);
DX8Wrapper::Set_Texture(1,NULL);
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index 69f4afea0..aea85f93d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -280,16 +280,6 @@ void DebugHintObject::Render(RenderInfoClass & rinfo)
//-------------------------------------------------------------------------------------------------
W3DInGameUI::W3DInGameUI()
{
- Int i;
-
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- {
-
- m_moveHintRenderObj[ i ] = NULL;
- m_moveHintAnim[ i ] = NULL;
-
- } // end for i
-
m_buildingPlacementAnchor = NULL;
m_buildingPlacementArrow = NULL;
@@ -299,17 +289,6 @@ W3DInGameUI::W3DInGameUI()
//-------------------------------------------------------------------------------------------------
W3DInGameUI::~W3DInGameUI()
{
- Int i;
-
- // remove render objects for hints
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- {
-
- REF_PTR_RELEASE( m_moveHintRenderObj[ i ] );
- REF_PTR_RELEASE( m_moveHintAnim[ i ] );
-
- } // end for i
-
REF_PTR_RELEASE( m_buildingPlacementAnchor );
REF_PTR_RELEASE( m_buildingPlacementArrow );
@@ -430,9 +409,6 @@ void W3DInGameUI::draw( void )
view = TheDisplay->getNextView( view ) )
{
- // draw move hints
- drawMoveHints( view );
-
// draw attack hints
drawAttackHints( view );
@@ -499,20 +475,21 @@ void W3DInGameUI::draw( void )
} // end draw
//-------------------------------------------------------------------------------------------------
-// The build grid's own render state. Alpha blended, untextured, depth tested but never depth
-// written, and PASS_ALWAYS: the grid is a sheet lying exactly on the terrain, so anything that
-// compared depth against the terrain would z-fight with it. Drawing it in the terrain pass and
-// never writing depth means everything drawn after the terrain - buildings, units, trees, the
-// placement ghost itself - covers it, which is what makes it read as paint on the ground.
+// The render state every sheet painted on the ground is drawn with: the build grid, and the wash
+// inside an attack circle. Alpha blended, untextured, depth tested but never depth written, and
+// PASS_ALWAYS: the sheet lies exactly on the terrain, so anything that compared depth against the
+// terrain would z-fight with it. Drawing it in the terrain pass and never writing depth means
+// everything drawn after the terrain - buildings, units, trees, the placement ghost itself - covers
+// it, which is what makes it read as paint on the ground.
// This is the bibs' shader with texturing off (see W3DBibBuffer).
-#define SC_BUILD_GRID ( SHADE_CNST(ShaderClass::PASS_ALWAYS, ShaderClass::DEPTH_WRITE_DISABLE, ShaderClass::COLOR_WRITE_ENABLE, ShaderClass::SRCBLEND_SRC_ALPHA, \
+#define SC_GROUND_OVERLAY ( SHADE_CNST(ShaderClass::PASS_ALWAYS, ShaderClass::DEPTH_WRITE_DISABLE, ShaderClass::COLOR_WRITE_ENABLE, ShaderClass::SRCBLEND_SRC_ALPHA, \
ShaderClass::DSTBLEND_ONE_MINUS_SRC_ALPHA, ShaderClass::FOG_DISABLE, ShaderClass::GRADIENT_MODULATE, ShaderClass::SECONDARY_GRADIENT_DISABLE, ShaderClass::TEXTURING_DISABLE, \
ShaderClass::ALPHATEST_DISABLE, ShaderClass::CULL_MODE_DISABLE, \
ShaderClass::DETAILCOLOR_DISABLE, ShaderClass::DETAILALPHA_DISABLE) )
-/** rgb plus an alpha given as a float 0..255, clamped - the grid's colours are all one colour at
+/** rgb plus an alpha given as a float 0..255, clamped - these sheets are all one colour at
* a per-vertex strength. */
-static UnsignedInt gridColor( UnsignedInt rgb, Real alpha )
+static UnsignedInt overlayColor( UnsignedInt rgb, Real alpha )
{
Int a = REAL_TO_INT( alpha );
if( a < 0 )
@@ -522,13 +499,14 @@ static UnsignedInt gridColor( UnsignedInt rgb, Real alpha )
return rgb | ((UnsignedInt)a << 24);
}
-/** Batches the grid's quads through the dynamic vertex buffer. The patch is ~1700 line quads plus
- * a fill for each blocked cell, which is more than one dynamic lock wants to hold, so it flushes
- * in fixed chunks - the draw state is set once by the caller and holds across the flushes. */
-class BuildGridQuads
+/** Batches a ground sheet's quads through the dynamic vertex buffer. The build grid alone is ~1700
+ * line quads plus a fill for each blocked cell, which is more than one dynamic lock wants to hold,
+ * so it flushes in fixed chunks - the draw state is set once by the caller and holds across the
+ * flushes. */
+class GroundOverlayQuads
{
public:
- BuildGridQuads( void ) : m_quads( 0 ) { }
+ GroundOverlayQuads( void ) : m_quads( 0 ) { }
void add( const Vector3 &p0, const Vector3 &p1, const Vector3 &p2, const Vector3 &p3,
UnsignedInt c0, UnsignedInt c1, UnsignedInt c2, UnsignedInt c3 )
@@ -557,7 +535,7 @@ private:
Int m_quads;
};
-void BuildGridQuads::flush( void )
+void GroundOverlayQuads::flush( void )
{
if( m_quads == 0 )
return;
@@ -607,6 +585,23 @@ void BuildGridQuads::flush( void )
DX8Wrapper::Draw_Triangles( 0, quads * 2, 0, quads * 4 );
}
+// 32k of vertices, shared by every sheet drawn on the ground. They all run on the render thread
+// and each one flushes before it returns, so there is only ever one batch in flight.
+static GroundOverlayQuads theGroundOverlayQuads;
+
+/** The prelit, untextured, alpha blended state a ground sheet is drawn with. Set once per sheet,
+ * before any quad is added. */
+static void setGroundOverlayState( void )
+{
+ static ShaderClass overlayShader( SC_GROUND_OVERLAY );
+ VertexMaterialClass *material = VertexMaterialClass::Get_Preset( VertexMaterialClass::PRELIT_DIFFUSE );
+ DX8Wrapper::Set_Material( material );
+ REF_PTR_RELEASE( material );
+ DX8Wrapper::Set_Texture( 0, NULL );
+ DX8Wrapper::Set_Shader( overlayShader );
+ DX8Wrapper::Apply_Render_State_Changes();
+}
+
//-------------------------------------------------------------------------------------------------
/** Draw the pathfinder's own cell grid under the structure sitting on the cursor, and cross out
* the cells it cannot go on. GridBuildPlacement snaps a footprint's edges to these very lines
@@ -692,19 +687,9 @@ void W3DInGameUI::drawBuildGrid( void )
}
}
- // the state the quads are drawn with: prelit (the colour is all in the vertices), untextured,
- // alpha blended, depth tested but never depth written, and PASS_ALWAYS so a sheet lying on the
- // terrain cannot z-fight with the terrain triangles underneath it. This is the bibs' own
- // shader, and the bibs are the proof it reads as paint rather than as decal geometry.
- static ShaderClass gridShader( SC_BUILD_GRID );
- VertexMaterialClass *material = VertexMaterialClass::Get_Preset( VertexMaterialClass::PRELIT_DIFFUSE );
- DX8Wrapper::Set_Material( material );
- REF_PTR_RELEASE( material );
- DX8Wrapper::Set_Texture( 0, NULL );
- DX8Wrapper::Set_Shader( gridShader );
- DX8Wrapper::Apply_Render_State_Changes();
+ setGroundOverlayState();
- static BuildGridQuads quads; // 32k of vertices; static so it is not a stack frame
+ GroundOverlayQuads &quads = theGroundOverlayQuads;
// the lines themselves, one quad per cell edge so they follow the ground over every bump
const Real LINE_ALPHA = 0x58;
@@ -714,8 +699,8 @@ void W3DInGameUI::drawBuildGrid( void )
{
if( ix + 1 < GRID_POINTS && ( fade[ iy ][ ix ] > 0.0f || fade[ iy ][ ix + 1 ] > 0.0f ) )
{
- const UnsignedInt c0 = gridColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix ] );
- const UnsignedInt c1 = gridColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix + 1 ] );
+ const UnsignedInt c0 = overlayColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix ] );
+ const UnsignedInt c1 = overlayColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix + 1 ] );
quads.add( Vector3( gx[ ix ], gy[ iy ] - LINE_HALF_WIDTH, gz[ iy ][ ix ] ),
Vector3( gx[ ix + 1 ], gy[ iy ] - LINE_HALF_WIDTH, gz[ iy ][ ix + 1 ] ),
Vector3( gx[ ix + 1 ], gy[ iy ] + LINE_HALF_WIDTH, gz[ iy ][ ix + 1 ] ),
@@ -725,8 +710,8 @@ void W3DInGameUI::drawBuildGrid( void )
if( iy + 1 < GRID_POINTS && ( fade[ iy ][ ix ] > 0.0f || fade[ iy + 1 ][ ix ] > 0.0f ) )
{
- const UnsignedInt c0 = gridColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix ] );
- const UnsignedInt c1 = gridColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy + 1 ][ ix ] );
+ const UnsignedInt c0 = overlayColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy ][ ix ] );
+ const UnsignedInt c1 = overlayColor( 0x00FFFFFF, LINE_ALPHA * fade[ iy + 1 ][ ix ] );
quads.add( Vector3( gx[ ix ] - LINE_HALF_WIDTH, gy[ iy ], gz[ iy ][ ix ] ),
Vector3( gx[ ix ] + LINE_HALF_WIDTH, gy[ iy ], gz[ iy ][ ix ] ),
Vector3( gx[ ix ] + LINE_HALF_WIDTH, gy[ iy + 1 ], gz[ iy + 1 ][ ix ] ),
@@ -754,10 +739,10 @@ void W3DInGameUI::drawBuildGrid( void )
Vector3( gx[ ix + 1 ], gy[ iy ], gz[ iy ][ ix + 1 ] ),
Vector3( gx[ ix + 1 ], gy[ iy + 1 ], gz[ iy + 1 ][ ix + 1 ] ),
Vector3( gx[ ix ], gy[ iy + 1 ], gz[ iy + 1 ][ ix ] ),
- gridColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy ][ ix ] ),
- gridColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy ][ ix + 1 ] ),
- gridColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy + 1 ][ ix + 1 ] ),
- gridColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy + 1 ][ ix ] ) );
+ overlayColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy ][ ix ] ),
+ overlayColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy ][ ix + 1 ] ),
+ overlayColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy + 1 ][ ix + 1 ] ),
+ overlayColor( 0x00FF3030, BLOCKED_ALPHA * fade[ iy + 1 ][ ix ] ) );
}
}
@@ -765,6 +750,62 @@ void W3DInGameUI::drawBuildGrid( void )
} // end drawBuildGrid
+//-------------------------------------------------------------------------------------------------
+/** The wash inside the circle a left drag is sweeping targets out of. The rim is a screen space
+ * line drawn with everything else; this is the ground it encloses, laid down in the terrain pass
+ * so it bends over every slope inside it and so the tanks standing in the circle are drawn on top
+ * of the wash instead of under it.
+ *
+ * Rings rather than one fan from the centre: a fan spans a valley with a single flat triangle,
+ * and the circles worth drawing are big enough to cross one. */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::drawAttackCircleFill( void )
+{
+ Coord3D center;
+ Real radius;
+ if( !getAttackCircleGround( center, radius ) )
+ return;
+
+ enum { FILL_SEGMENTS = 48, FILL_RINGS = 6 };
+
+ // the ground is sampled at the vertex, so a sheet across a slope would sink into the hill
+ // between two samples; lifting it a hair keeps it out of the dirt without floating
+ const Real FILL_LIFT = 0.35f;
+ // faint on purpose. It says which ground is inside the circle, it does not hide what is on it
+ const Real FILL_ALPHA = 0x2C;
+ const UnsignedInt FILL_RGB = 0x00FF5555; // the attack red the rim and the hints use
+
+ Vector3 ring[ FILL_RINGS + 1 ][ FILL_SEGMENTS + 1 ];
+ Int r, s;
+ for( r = 0; r <= FILL_RINGS; ++r )
+ {
+ const Real ringRadius = radius * (Real)r / (Real)FILL_RINGS;
+ for( s = 0; s <= FILL_SEGMENTS; ++s )
+ {
+ const Real angle = 2.0f * PI * (Real)s / (Real)FILL_SEGMENTS;
+ const Real x = center.x + ringRadius * (Real)cos( angle );
+ const Real y = center.y + ringRadius * (Real)sin( angle );
+ ring[ r ][ s ].Set( x, y, TheTerrainLogic->getGroundHeight( x, y ) + FILL_LIFT );
+ }
+ }
+
+ setGroundOverlayState();
+
+ GroundOverlayQuads &quads = theGroundOverlayQuads;
+ const UnsignedInt fill = overlayColor( FILL_RGB, FILL_ALPHA );
+ for( r = 0; r < FILL_RINGS; ++r )
+ {
+ for( s = 0; s < FILL_SEGMENTS; ++s )
+ {
+ quads.add( ring[ r ][ s ], ring[ r + 1 ][ s ], ring[ r + 1 ][ s + 1 ], ring[ r ][ s + 1 ],
+ fill, fill, fill, fill );
+ }
+ }
+
+ quads.flush();
+
+} // end drawAttackCircleFill
+
//-------------------------------------------------------------------------------------------------
/** draw 2d selection region on screen */
//-------------------------------------------------------------------------------------------------
@@ -814,14 +855,9 @@ void W3DInGameUI::drawFormationLine( void )
//-------------------------------------------------------------------------------------------------
void W3DInGameUI::drawAttackCircle( void )
{
- Coord3D center, rim;
- TheTacticalView->screenToTerrain( &getAttackCircleAnchor(), &center );
- TheTacticalView->screenToTerrain( &getAttackCircleCursor(), &rim );
-
- const Real dx = rim.x - center.x;
- const Real dy = rim.y - center.y;
- const Real radius = (Real)sqrt( dx * dx + dy * dy );
- if( radius < 1.0f )
+ Coord3D center;
+ Real radius;
+ if( !getAttackCircleGround( center, radius ) )
return;
const Int segments = 48;
@@ -1040,10 +1076,27 @@ void W3DInGameUI::drawOrderHints( void )
const Real width = 1.0f;
+ // A new marker slides up out of the bottom right and fades in over this long, so an order that
+ // has just been given announces itself instead of appearing fully formed. Wall clock rather
+ // than frames: the picture is uncapped, so a frame count would run at the frame rate.
+ const UnsignedInt MARKER_SLIDE_MS = 130;
+ const Real MARKER_SLIDE_PIXELS = 13.0f;
+
+ const UnsignedInt nowMs = timeGetTime();
+
for( std::vector<OrderHint>::const_iterator it = hints.begin(); it != hints.end(); ++it )
{
const UnsignedInt lineColor = orderHintLineColor( it->kind );
+ const UnsignedInt ageMs = nowMs - it->bornMs;
+ Real arrival = 1.0f;
+ if( ageMs < MARKER_SLIDE_MS )
+ arrival = (Real)ageMs / (Real)MARKER_SLIDE_MS;
+
+ // eased out, so it comes in fast and settles rather than sliding at one speed and stopping
+ const Real remaining = 1.0f - arrival;
+ const Real eased = 1.0f - remaining * remaining * remaining;
+
// a unit off the edge of the screen still has a destination worth seeing, and the line to it
// says which way it went. WTS_OUTSIDE_FRUSTUM still gives usable pixels, so only points
// behind the camera are dropped
@@ -1065,137 +1118,19 @@ void W3DInGameUI::drawOrderHints( void )
{
const Int w = image->getImageWidth();
const Int h = image->getImageHeight();
- const Int x = to.x - hotSpot.x;
- const Int y = to.y - hotSpot.y;
- TheDisplay->drawImage( image, x, y, x + w, y + h, orderHintMarkerColor( it->kind ) );
+ const Int slide = REAL_TO_INT_FLOOR( ( 1.0f - eased ) * MARKER_SLIDE_PIXELS );
+ const Int x = to.x - hotSpot.x + slide;
+ const Int y = to.y - hotSpot.y + slide;
+
+ // the tint carries the fade as well as the order's colour
+ const UnsignedInt markerColor = ( orderHintMarkerColor( it->kind ) & 0x00FFFFFF )
+ | ( (UnsignedInt)REAL_TO_INT( 255.0f * eased ) << 24 );
+ TheDisplay->drawImage( image, x, y, x + w, y + h, markerColor );
}
}
} // end drawOrderHints
-//-------------------------------------------------------------------------------------------------
-/** Draw the visual feedback for clicking in the world and telling units
- * to move there */
-//-------------------------------------------------------------------------------------------------
-void W3DInGameUI::drawMoveHints( View *view )
-{
- Int i;
-// Real width = 1.0f;
-// UnsignedInt color = 0x9933FF33; //0xAARRGGBB
-
- for( i = 0; i < MAX_MOVE_HINTS; i++ )
- {
- Int elapsed = TheGameClient->getFrame() - m_moveHint[i].frame;
-
- if( elapsed <= 40 )
- {
- RectClass rect;
-
- // if this hint is not in this view ignore it
- /// @todo write this to check if point is visible in view
-// if( view->pointInView( &m_moveHint[ i ].pos == FALSE )
-// continue;
-
- // create render object and add to scene of needed
- if( m_moveHintRenderObj[ i ] == NULL )
- {
- RenderObjClass *hint;
- HAnimClass *anim;
-
- // create hint object
- hint = W3DDisplay::m_assetManager->Create_Render_Obj(TheGlobalData->m_moveHintName.str());
-
- AsciiString animName;
- animName.format("%s.%s", TheGlobalData->m_moveHintName.str(), TheGlobalData->m_moveHintName.str());
- anim = W3DDisplay::m_assetManager->Get_HAnim(animName.str());
-
- // sanity
- if( hint == NULL )
- {
-
- DEBUG_CRASH(("unable to create hint"));
- return;
-
- } // end if
-
- // asign render objects to GUI data
- m_moveHintRenderObj[ i ] = hint;
-
- // note that 'anim' is returned from Get_HAnim with an AddRef, so we don't need to addref it again.
- // however, we do need to release the contents of moveHintAnim (if any)
- REF_PTR_RELEASE(m_moveHintAnim[i]);
- m_moveHintAnim[i] = anim;
-
- } // end if, create render objects
-
- // show the render object if hidden
- if( m_moveHintRenderObj[ i ]->Is_Hidden() == 1 ) {
- m_moveHintRenderObj[ i ]->Set_Hidden( 0 );
- // add to scene
- W3DDisplay::m_3DScene->Add_Render_Object( m_moveHintRenderObj[ i ] );
- if (m_moveHintAnim[i])
- m_moveHintRenderObj[i]->Set_Animation(m_moveHintAnim[i], 0, RenderObjClass::ANIM_MODE_ONCE);
- }
-
- // move this hint render object to the position and align with terrain
- Matrix3D transform;
- PathfindLayerEnum layer = TheTerrainLogic->alignOnTerrain( 0, m_moveHint[ i ].pos, true, transform );
-
- Real waterZ;
- if (layer == LAYER_GROUND && TheTerrainLogic->isUnderwater(m_moveHint[ i ].pos.x, m_moveHint[ i ].pos.y, &waterZ))
- {
- Coord3D tmp = m_moveHint[ i ].pos;
- tmp.z = waterZ;
- Coord3D normal;
- normal.x = 0;
- normal.y = 0;
- normal.z = 1;
- makeAlignToNormalMatrix(0, tmp, normal, transform);
- }
-
- m_moveHintRenderObj[ i ]->Set_Transform( transform );
-
-#if 0
- // if there is a source then draw line from source to destination
- Object *obj = TheGameLogic->getObject( m_moveHint[ i ].sourceID );
- if( obj )
- {
- Drawable *source = obj->getDrawable();
-
- if( source )
- {
- Coord3D pos;
- ICoord2D start, end;
-
- // project start and end point to screen point
- source->getPosition( &pos );
- view->worldToScreen( &pos, &start );
- view->worldToScreen( &hintPos, &end );
-
- // draw the line
- TheDisplay->drawLine( start.x, start.y, end.x, end.y, width, color );
-
- } // end if
- } // end if
-#endif
-
- }
- else
- {
-
- // hide hint marker
- if( m_moveHintRenderObj[ i ] )
- if( m_moveHintRenderObj[ i ]->Is_Hidden() == 0 ) {
- m_moveHintRenderObj[ i ]->Set_Hidden( 1 );
- W3DDisplay::m_3DScene->Remove_Render_Object( m_moveHintRenderObj[ i ] );
- }
-
- } // end else
-
- } // end for i
-
-} // end drawMoveHints
-
//-------------------------------------------------------------------------------------------------
/** Draw visual back for clicking to attack a unit in the world */
//-------------------------------------------------------------------------------------------------