Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameengine): a line drawn with the attack key targets what it crosses
Olcay Seygan8d578be965ae
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ac2fa8b35..1ba06a31f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -175,7 +175,7 @@ found and fixed — EA's own, not port damage.**- A unit standing guard draws its marker on the ground it is guarding. A guard order clears the unit's goal on the way in, so every guard marker used to sit in the bottom left corner of the map with a thread running the whole way across it, whatever the unit was actually watching.- 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. The click keeps your group, too: an attack click that was not a drag used to run the same deselect an ordinary left click runs, so the order arrived a moment after the units it was meant for had been dropped. Both orders are aimed with the left button, the way a special power is, and a right click puts the key down again without giving any order. Holding ctrl no longer forces fire: A is the one way to shoot the ground, and ctrl on a move is only the shared pace. The two keys turn each other off, and the letters they took were sitting on grid commands that moved.- G is guard, armed the same way and aimed with the same left button. A left click posts the selection on that spot: they hold it, shoot what walks into range and do not chase it off the post you put them on. The cursor turns into the targeting cross while G is armed, so you can see the key is down before you click, and a right click puts it down again. Drag the left button with G armed (the right one draws nothing while G is down) and they post along the line you draw, one unit per station, which is how a hill or a bridge approach gets covered in one gesture instead of a click per tank. Guard has its own colour, blue, on the line while you draw it and on the thread and marker afterwards, so a group told to hold ground reads apart from one told to walk there. Hold position, which posts every unit on the spot it is already standing on, has moved to H.-- 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. What the circle picks up is what you can shoot: a shell or a missile crossing it is on the enemy's side like everything else and used to go on the list as a target, costing the group a two second stall on something that was about to stop existing. A target that has driven into the shroud since you picked it keeps its place in the list but stops drawing its thread, so the line cannot be used to trace it through the fog. An attack-move queued behind other orders keeps the force fire it was given rather than losing it when the attack key drops.+- 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. What the circle picks up is what you can shoot: a shell or a missile crossing it is on the enemy's side like everything else and used to go on the list as a target, costing the group a two second stall on something that was about to stop existing. A target that has driven into the shroud since you picked it keeps its place in the list but stops drawing its thread, so the line cannot be used to trace it through the fog. An attack-move queued behind other orders keeps the force fire it was given rather than losing it when the attack key drops. A line drawn with A works the same way now: every enemy the line is drawn across goes on the list, in the order the line crosses them, so the way you draw it is the way the group fights along it. It used to pour fire into the ground under the line and hit whatever happened to be standing there. A line that crosses nobody still fires on the ground along it.- Shift queues a guard as well, and it is where the line of orders stops. Hold shift with G armed and click, and the group takes up its post once it has finished everything queued in front of it: clear that ridge, then sit on it, in one set of clicks instead of standing over the fight waiting to give the last order. Nothing goes behind a guard, because a posted unit has no next place to be. The thread to the post is drawn in the guard colour like any other guard.- 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.- The shift queue takes any mix of orders now and stays with the units you gave it to. Move, attack-move, attack a target, draw a formation line, then guard: hold shift, click them in whatever order you like, and the group works down the list by itself. Queue an army's whole route, select something else, go back to your base, and the army keeps going. Before, clicking anything else threw the list away. Each step also starts the moment the one before it is done. It used to wait for the order to travel to the other players and back, which on a 250ms connection was a quarter of a second standing still at every corner. The group keeps together: nobody starts the next order until everyone still alive has finished this one, so a column does not string out behind its fastest tank. Select part of a group and shift-click, and that part takes its own copy of the list with the new order on the end while the others carry on with theirs. Shift-click a group that is already on an ordinary move and the new point goes behind the move instead of replacing it.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex f8fb4265c..2c67ed78f 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -542,6 +542,8 @@ public: // ********************************************************************void beginAttackCircle( const ICoord2D& pt );void updateAttackCircle( const ICoord2D& pt );Bool issueAttackCircle( void ); ///< FALSE when the press never became a drag, so it was an ordinary attack click+ Int issueAttackLine( const std::vector<Coord3D>& line ); ///< every enemy a line drawn with the attack key runs across, as a target list in line order+ Bool isAttackListTarget( const Object *obj, const Player *local ) const; ///< would the circle or the attack line take thisvoid cancelAttackCircle( void ) { m_isAttackCircling = FALSE; }Bool isAttackCircling( void ) const { return m_isAttackCircling; }const ICoord2D& getAttackCircleAnchor( void ) const { return m_attackCircleAnchor; }diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 250847c20..cac69849e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -5343,7 +5343,7 @@ Bool InGameUI::issueAttackCircle( void )if( !wasDragged )return FALSE;- Player *local = ThePlayerList->getLocalPlayer();+ const Player *local = ThePlayerList->getLocalPlayer();ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( ¢er, radius,FROM_CENTER_2D, NULL,@@ -5352,30 +5352,7 @@ Bool InGameUI::issueAttackCircle( void )Int targetCount = 0;for( Object *obj = iter->first(); obj; obj = iter->next() ){- if( obj->isEffectivelyDead() )- continue;- if( local->getRelationship( obj->getTeam() ) != ENEMIES )- continue;- if( isHiddenByShroud( obj ) )- continue;-- //- // Shroud is only half of invisible. A stealthed tank sitting in ground the player has- // cleared passes the test above, so a circle swept over open country used to pick out every- // hidden unit in it and open fire: a detector nobody built, and a way to read the map for- // stealth by dragging a circle over it. Undetected means not in the circle.- //- if( obj->testStatus( OBJECT_STATUS_STEALTHED ) && !obj->testStatus( OBJECT_STATUS_DETECTED ) )- continue;-- //- // Not everything hostile standing in the circle is something to shoot at. A shell or a- // missile in flight is an object on the enemy's team like any other, and the range query hands- // them over the same way it hands over tanks; the rest of the engine drops them by kind- // wherever it scans. Each one that reached the list cost the group a two second stall on a- // target that was about to stop existing.- //- if( obj->isKindOf( KINDOF_PROJECTILE ) || obj->isKindOf( KINDOF_UNATTACKABLE ) )+ if( !isAttackListTarget( obj, local ) )continue;const Bool startsList = targetCount == 0 && !isInWaypointMode();@@ -5390,6 +5367,130 @@ Bool InGameUI::issueAttackCircle( void )return TRUE;}+//-------------------------------------------------------------------------------------------------+/** Would the circle or the attack line put this on the target list? */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::isAttackListTarget( const Object *obj, const Player *local ) const+{+ if( obj->isEffectivelyDead() )+ return FALSE;+ if( local->getRelationship( obj->getTeam() ) != ENEMIES )+ return FALSE;+ if( isHiddenByShroud( obj ) )+ return FALSE;++ //+ // Shroud is only half of invisible. A stealthed tank sitting in ground the player has+ // cleared passes the test above, so a circle swept over open country used to pick out every+ // hidden unit in it and open fire: a detector nobody built, and a way to read the map for+ // stealth by dragging a circle over it. Undetected means not in the circle.+ //+ if( obj->testStatus( OBJECT_STATUS_STEALTHED ) && !obj->testStatus( OBJECT_STATUS_DETECTED ) )+ return FALSE;++ //+ // Not everything hostile standing in the circle is something to shoot at. A shell or a+ // missile in flight is an object on the enemy's team like any other, and the range query hands+ // them over the same way it hands over tanks; the rest of the engine drops them by kind+ // wherever it scans. Each one that reached the list cost the group a two second stall on a+ // target that was about to stop existing.+ //+ return !obj->isKindOf( KINDOF_PROJECTILE ) && !obj->isKindOf( KINDOF_UNATTACKABLE );+}++//-------------------------------------------------------------------------------------------------+/** The line drawn with the attack key: every enemy it runs across goes on the target list, in the+ * order the line reaches it, so the direction it was drawn in is the direction the group fights+ * along. "Across" is the line passing over the object's own footprint, give or take a few feet for+ * a hand that is not steady. Returns how many targets went out; with none, the caller fires on+ * the ground along the line instead. */+//-------------------------------------------------------------------------------------------------+Int InGameUI::issueAttackLine( const std::vector<Coord3D>& line )+{+ // how far off the line a unit's edge may be and still count as under it+ const Real LINE_TOLERANCE = 10.0f;++ // the range query measures to centres, so it reaches this much further for a building whose+ // centre is off the line and whose walls are under it+ const Real LARGEST_FOOTPRINT = 150.0f;++ if( line.size() < 2 )+ return 0;++ // one query over the circle round the whole line, then each object is measured against it+ Region2D box;+ box.lo.x = box.hi.x = line[ 0 ].x;+ box.lo.y = box.hi.y = line[ 0 ].y;+ for( std::vector<Coord3D>::const_iterator point = line.begin(); point != line.end(); ++point )+ {+ box.lo.x = min( box.lo.x, point->x );+ box.lo.y = min( box.lo.y, point->y );+ box.hi.x = max( box.hi.x, point->x );+ box.hi.y = max( box.hi.y, point->y );+ }+ Coord3D center;+ center.x = ( box.lo.x + box.hi.x ) * 0.5f;+ center.y = ( box.lo.y + box.hi.y ) * 0.5f;+ center.z = 0.0f;+ const Real halfWidth = ( box.hi.x - box.lo.x ) * 0.5f;+ const Real halfHeight = ( box.hi.y - box.lo.y ) * 0.5f;+ const Real reach = sqrt( halfWidth * halfWidth + halfHeight * halfHeight ) + LINE_TOLERANCE + LARGEST_FOOTPRINT;++ const Player *local = ThePlayerList->getLocalPlayer();+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( ¢er, reach, FROM_CENTER_2D, NULL );+ MemoryPoolObjectHolder holder( iter );++ // how far along the line each target is, so they can go out in the order the line meets them+ std::vector< std::pair<Real, ObjectID> > targets;+ for( Object *obj = iter->first(); obj; obj = iter->next() )+ {+ if( !isAttackListTarget( obj, local ) )+ continue;++ const Coord3D *pos = obj->getPosition();+ const Real allowed = obj->getGeometryInfo().getBoundingCircleRadius() + LINE_TOLERANCE;+ Real bestDistanceSqr = allowed * allowed;+ Real along = -1.0f;+ Real walked = 0.0f;+ for( size_t i = 1; i < line.size(); ++i )+ {+ const Real dx = line[ i ].x - line[ i - 1 ].x;+ const Real dy = line[ i ].y - line[ i - 1 ].y;+ const Real lengthSqr = dx * dx + dy * dy;+ const Real length = sqrt( lengthSqr );+ Real t = 0.0f;+ if( lengthSqr > 0.0f )+ t = clamp( 0.0f, ( ( pos->x - line[ i - 1 ].x ) * dx + ( pos->y - line[ i - 1 ].y ) * dy ) / lengthSqr, 1.0f );+ const Real offX = line[ i - 1 ].x + dx * t - pos->x;+ const Real offY = line[ i - 1 ].y + dy * t - pos->y;+ const Real distanceSqr = offX * offX + offY * offY;+ if( distanceSqr <= bestDistanceSqr )+ {+ bestDistanceSqr = distanceSqr;+ along = walked + length * t;+ }+ walked += length;+ }++ if( along >= 0.0f )+ targets.push_back( std::make_pair( along, obj->getID() ) );+ }++ std::sort( targets.begin(), targets.end() );++ for( size_t i = 0; i < targets.size(); ++i )+ {+ const Bool startsList = i == 0 && !isInWaypointMode();+ markNextOrderQueued( startsList ? ORDER_QUEUE_FRESH : ORDER_QUEUE_APPEND );+ GameMessage *attack = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );+ attack->appendObjectIDArgument( targets[ i ].second );+ }++ DEBUG_LOG(("attack line: %d points, %d targets, %d selected\n", (Int)line.size(), (Int)targets.size(),+ getSelectCount()));+ return (Int)targets.size();+}+//-------------------------------------------------------------------------------------------------/** Whether the shroud is over this object as far as the player at this machine is concerned, or the* player a watcher with fog on is looking through. */diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 08fdb596b..204568434 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -1469,18 +1469,30 @@ void CommandTranslator::finishFormationDrag( const ICoord2D& lift )TheInGameUI->isForceAttackArmed(),TheInGameUI->isGuardArmed() );- // a line drawn with shift is the next order on the units' list- if( TheInGameUI->isInWaypointMode() )- TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );-// the traced curve becomes world points; who stands where along it is decided on// the logic side, where every machine decides it the same way- GameMessage *newMsg = TheMessageStream->appendMessage( formationType );+ std::vector<Coord3D> line;for( std::vector<ICoord2D>::const_iterator it = curve.begin(); it != curve.end(); ++it ){Coord3D world;TheTacticalView->screenToTerrain( &(*it), &world );- newMsg->appendLocationArgument( world );+ line.push_back( world );+ }++ // a line drawn with the attack key across enemies is aimed at them: each one it crosses goes on+ // the target list, in the order the line meets them, and the ground under the line is not shot+ // at. Only a line that crosses nobody fires on the ground along it+ const Bool aimedAtTargets = formationType == GameMessage::MSG_DO_FORMATION_FORCEATTACK+ && TheInGameUI->issueAttackLine( line ) > 0;+ if( !aimedAtTargets )+ {+ // a line drawn with shift is the next order on the units' list+ if( TheInGameUI->isInWaypointMode() )+ TheInGameUI->markNextOrderQueued( ORDER_QUEUE_APPEND );++ GameMessage *newMsg = TheMessageStream->appendMessage( formationType );+ for( std::vector<Coord3D>::const_iterator it = line.begin(); it != line.end(); ++it )+ newMsg->appendLocationArgument( *it );}TheInGameUI->spendOrderKey();