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): split attack-circle shots across the selection
Olcay Seygane62d0c6bd006
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3a08ff5c4..b5a9be01c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -82,7 +82,7 @@ found and fixed — EA's own, not port damage.**- It no longer sits on a pile of cash. Past a level that depends on the difficulty, the more money it has the faster it builds - twice the pile, half the wait, and it stops at four times. It is spending sooner, not building faster: the rate itself is untouched.- A full bank buys a bigger army. Late in a match the computer's plan allows one of each attack group, so once they were all on the map it only replaced its losses and banked the rest: a Hard USA sat on 117,000 on Twilight Flame. Now every 8,000 in the bank on Hard allows one more copy of each attack group, up to four of them.-- Hard builds past its plan. When every war factory, barracks or airfield it owns is busy it puts down another, beside its newest expansion so the army comes out nearer the fighting. Buildings that pay out on a timer, supply drop zones and black markets, go up one after another as soon as the bank is past a small cushion, whatever else it is buying; they used to wait until production had nothing to ask for, which on a busy map was never, and over twelve four-player matches the count went from 5 to 95. China trains a hacker from every barracks that has room in its queue, not one barracks at a time: 120 hackers across those matches became 375. A hacker left standing still is put to work. It stops at six, an internet center's four plus a couple, because nothing counted them before: a Hard Tank General trained 67 over twenty thousand frames, about two thirds of everything it spent, and every one of them went through the barracks queue its army was waiting in. A player watching it from the other side of the map said China's tank general builds nothing but infantry, and he was right. Seven now, and the teams at the top of its build list are tanks. The limit grows with the match: one hacker for every four fighting units, never more than its Internet Centers have seats for plus four working outside, and never fewer than four. A computer that has not built an army does not buy an economy instead, and one with a full Internet Center and ninety units behind it keeps eight.+- Hard builds past its plan. A tank factory or a barracks gets another copy when units are waiting in its queue, and a factory that was destroyed is put back. Airfields keep going up for as long as the money is there. Supply drop zones and black markets go up one after another as soon as the bank is past a small cushion, whatever else it is buying; they used to wait until production had nothing to ask for, which on a busy map was never, and over twelve four-player matches the count went from 5 to 95. Internet centers follow that same rule. The spot search used to give up two rings outside the opening base, so a full base simply stopped. It now keeps looking further out until the map ends. Strategy centers, propaganda centers and palaces stop at three, so one of them blowing up leaves the tech tree standing. Extra factories still go beside the newest expansion it holds, nearer the fighting. China trains a hacker from every barracks that has room in its queue, not one barracks at a time: 120 hackers across those matches became 375. A hacker left standing still is put to work. It stops at six, an internet center's four plus a couple, because nothing counted them before: a Hard Tank General trained 67 over twenty thousand frames, about two thirds of everything it spent, and every one of them went through the barracks queue its army was waiting in. A player watching it from the other side of the map said China's tank general builds nothing but infantry, and he was right. Seven now, and the teams at the top of its build list are tanks. The limit grows with the match: one hacker for every four fighting units, never more than its Internet Centers have seats for plus four working outside, and never fewer than four. A computer that has not built an army does not buy an economy instead, and one with a full Internet Center and ninety units behind it keeps eight. Replays recorded before this change play out differently.- Hard picks its road into your base. Of the three approaches it takes the one with the fewest guns it has seen along it, and keeps to the one its plan named until it has scouted something. Aiming at your money instead was tried first and walked it straight past your army.- Hard sends its attack groups out together. A group too small to be a wave on its own waits on the near side of its base until about seven tanks' worth has gathered, or a minute and a half has passed, and then everything waiting leaves on one road at the pace of its slowest unit. A lone artillery piece or a single bomb truck used to drive across the map by itself, and nearly a third of Hard's units died with barely anyone of their own nearby.- Hard stops piling its army up at home. Its plan only sends an attack group while the signal for the next wave is up, and only a group standing in the base at that moment. A group finished a minute later guarded the base until the signal came round again, and one that fell back from a lost fight guarded it for good: one GLA stood 38 of its Angry Mob by its own buildings with 70,000 in the bank. China's Dragon Tank group never left at all, because the attack order its plan names for it is missing from EA's file. Now any attack group standing idle at home joins the next wave. Rich computers also stopped building extra copies of the groups that only ever guard, four sets of tunnel guards where the plan asked for one. Over eight Hard matches on Twilight Flame, the units standing idle at home late in the match went from 43 to 17, the waves sent went from 134 to 319, and kills went up by a tenth. Replays recorded before this change play out differently.@@ -183,7 +183,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 D 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. 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.+- With A armed, hold the left button and drag a circle instead: the enemies you can see inside it are split across the units that can shoot, as evenly as the numbers allow, in the order both sides stand around the circle. The tank on the left of your group takes the enemy on the left of theirs. Ten of yours against three of theirs put four guns on one and three on each of the others. Three of yours against ten of theirs each take a run of three or four and work down that run. One enemy, and every selected gun takes it. When a unit's target dies the next of its own 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/Common/DrawnPath.h b/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.hindex 043eb2e79..e1e3c3c42 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/DrawnPath.h@@ -55,4 +55,36 @@ extern void pointAlongPath( const std::vector<Coord3D>& path, const std::vector<extern void orderAlongPath( std::vector<Object *>& movers, const std::vector<Coord3D>& path,const std::vector<Real>& arc );+/**+ * One man or one target standing somewhere, named, so the attack circle can line both sides up+ * without the sort having to know what an object is. The id is the last tie, which makes the+ * order a total one.+ */+struct AttackAssignSlot+{+ ObjectID id;+ Real x;+ Real y;+};++/// Who shoots, and which target in the sorted target list. Both indexes are into lists that+/// orderAroundPoint has already sorted.+struct AttackAssignPair+{+ Int attacker;+ Int target;+};++/// Stand these in the order they sit around (centerX, centerY), counter-clockwise from the +x+/// ray. No angle is computed: the half-plane, then the cross product, then the distance from the+/// centre, then the id. A man on the centre itself is the nearest thing on the +x ray.+extern void orderAroundPoint( std::vector<AttackAssignSlot>& slots, Real centerX, Real centerY );++/// Pair attackers with targets so the counts differ by one at most. Both counts are the lengths+/// of lists already stood around the same centre. With at least as many attackers as targets,+/// each attacker takes one target and the extras share, in contiguous blocks. With more targets+/// than attackers, every target is still shot and each attacker queues a contiguous run of them.+/// Either side empty writes nothing.+extern void assignAttacks( Int attackerCount, Int targetCount, std::vector<AttackAssignPair>& pairs );+#endif // _H_DrawnPathdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 9abecea8c..23a47a689 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -557,9 +557,9 @@ public: // ********************************************************************const AllyCursor& getAllyCursor( Int playerIndex ) const { return m_allyCursors[ playerIndex ]; }Real getAllyCursorFade( Int playerIndex ) const; ///< 0 when there is nothing to draw, 1 for a live cursor- // A circle dragged out with the left button while the attack key is armed. Everything hostile- // 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.+ // A circle dragged out with the left button while the attack key is armed. The enemies inside+ // it are shared across the units that can shoot, in the order both sides stand around the+ // circle, and each unit works down its own share.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 clickdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cpp b/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cppindex 163e49c84..78e702099 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/DrawnPath.cpp@@ -128,3 +128,111 @@ void orderAlongPath( std::vector<Object *>& movers, const std::vector<Coord3D>&keys[ j + 1 ] = heldKey;}}++//-------------------------------------------------------------------------------------------------+/** Upper half, +x ray included, is 0. Lower half, -x ray included, is 1. The origin counts as+ * the +x ray so a man standing on the centre sorts with the start of the sweep. */+//-------------------------------------------------------------------------------------------------+static Int attackHalfPlane( Real vx, Real vy )+{+ if( vy > 0.0f )+ return 0;+ if( vy < 0.0f )+ return 1;+ return (vx >= 0.0f) ? 0 : 1;+}++//-------------------------------------------------------------------------------------------------+/** Strict order around the origin the vectors were measured from. Cross product, not an angle,+ * so nothing transcendental is in it and the same coordinates always sort the same way. */+//-------------------------------------------------------------------------------------------------+static Bool attackStandsBefore( Real ax, Real ay, ObjectID aId, Real bx, Real by, ObjectID bId )+{+ const Int halfA = attackHalfPlane( ax, ay );+ const Int halfB = attackHalfPlane( bx, by );+ if( halfA != halfB )+ return halfA < halfB;++ const Real cross = ax * by - ay * bx;+ if( cross > 0.0f )+ return TRUE;+ if( cross < 0.0f )+ return FALSE;++ const Real distA = ax * ax + ay * ay;+ const Real distB = bx * bx + by * by;+ if( distA < distB )+ return TRUE;+ if( distA > distB )+ return FALSE;++ return aId < bId;+}++//-------------------------------------------------------------------------------------------------+void orderAroundPoint( std::vector<AttackAssignSlot>& slots, Real centerX, Real centerY )+{+ const Int count = (Int)slots.size();++ // Insertion sort. A selection is a few dozen, a circle's targets a few hundred, and the+ // comparator is a total order, so the answer does not depend on the order they were found in.+ for( Int i = 1; i < count; i++ )+ {+ AttackAssignSlot held = slots[ i ];+ const Real heldX = held.x - centerX;+ const Real heldY = held.y - centerY;++ Int j = i - 1;+ while( j >= 0 )+ {+ const Real sx = slots[ j ].x - centerX;+ const Real sy = slots[ j ].y - centerY;+ if( !attackStandsBefore( heldX, heldY, held.id, sx, sy, slots[ j ].id ) )+ break;+ slots[ j + 1 ] = slots[ j ];+ j--;+ }++ slots[ j + 1 ] = held;+ }+}++//-------------------------------------------------------------------------------------------------+void assignAttacks( Int attackerCount, Int targetCount, std::vector<AttackAssignPair>& pairs )+{+ pairs.clear();+ if( attackerCount < 1 || targetCount < 1 )+ return;++ pairs.reserve( (attackerCount > targetCount) ? attackerCount : targetCount );++ // Enough guns that nobody needs a second target. Attacker i takes target+ // (i * M + M/2) / N, which lays the shares in contiguous blocks and puts a leftover+ // share in the middle block. 10 guns on 3 targets is 3, 4, 3.+ if( attackerCount >= targetCount )+ {+ for( Int i = 0; i < attackerCount; i++ )+ {+ AttackAssignPair pair;+ pair.attacker = i;+ pair.target = (i * targetCount + targetCount / 2) / attackerCount;+ pairs.push_back( pair );+ }+ return;+ }++ // More targets than guns. Attacker a's run is the targets from start(a) up to start(a+1),+ // start(a) = (a * M + N/2) / N. 3 guns on 10 targets queue 3, 4 and 3, in that spatial order.+ for( Int attacker = 0; attacker < attackerCount; attacker++ )+ {+ const Int begin = (attacker * targetCount + attackerCount / 2) / attackerCount;+ const Int end = ((attacker + 1) * targetCount + attackerCount / 2) / attackerCount;+ for( Int target = begin; target < end; target++ )+ {+ AttackAssignPair pair;+ pair.attacker = attacker;+ pair.target = target;+ pairs.push_back( pair );+ }+ }+}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 3f368c74f..e73c85ba5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -5624,13 +5624,14 @@ Bool InGameUI::getAttackCircleGround( Coord3D& center, Real& radius ) const}//--------------------------------------------------------------------------------------------------/** Everything hostile standing in the circle becomes a list of attacks, nearest first, and the group- * is put on the head of it. Without shift the list replaces whatever the group was doing; with it,- * the list goes on the end of the group's shift queue. 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. */+/** The enemies standing in the circle are shared across the units that can shoot. Both sides are+ * stood in the order they sit around the centre the player drew, the same order a move line uses+ * along its curve, and the shots are then dealt so the counts differ by one at most. With enough+ * guns each takes one target. With more targets than guns, each gun queues its own run of them+ * instead of the whole selection walking one list. The pair is two ids on the attack message, the+ * target first, so every other machine fires what this one decided and nobody recomputes the+ * circle. Without shift, a unit's first shot replaces whatever it was doing; with shift, the run+ * goes on the end of that unit's own queue. Shroud decides which enemies count. *///-------------------------------------------------------------------------------------------------Bool InGameUI::issueAttackCircle( void ){@@ -5647,25 +5648,91 @@ Bool InGameUI::issueAttackCircle( void )const Player *local = ThePlayerList->getLocalPlayer();- ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( ¢er, radius,- FROM_CENTER_2D, NULL,- ITER_SORTED_NEAR_TO_FAR );+ // who can actually shoot. a dozer standing in the selection is not given somebody else's target.+ // a passenger whose transport is also selected is left out too: the transport's own order already+ // tells everyone inside it to fire.+ const DrawableList *selected = getAllSelectedLocalDrawables();+ std::vector<const Object *> shooters;+ shooters.reserve( selected->size() );+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )+ {+ const Object *obj = (*it) ? (*it)->getObject() : NULL;+ if( obj == NULL || obj->isEffectivelyDead() || !obj->isAbleToAttack() )+ continue;+ shooters.push_back( obj );+ }++ std::vector<AttackAssignSlot> attackers;+ attackers.reserve( shooters.size() );+ for( std::vector<const Object *>::const_iterator it = shooters.begin(); it != shooters.end(); ++it )+ {+ const Object *obj = *it;+ const Object *holder = obj->getContainedBy();+ if( holder != NULL )+ {+ Bool holderSelected = FALSE;+ for( std::vector<const Object *>::const_iterator other = shooters.begin(); other != shooters.end(); ++other )+ {+ if( *other == holder )+ {+ holderSelected = TRUE;+ break;+ }+ }+ if( holderSelected )+ continue;+ }++ AttackAssignSlot slot;+ slot.id = obj->getID();+ slot.x = obj->getPosition()->x;+ slot.y = obj->getPosition()->y;+ attackers.push_back( slot );+ }++ std::vector<AttackAssignSlot> targets;+ ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( ¢er, radius, FROM_CENTER_2D, NULL );MemoryPoolObjectHolder holder( iter );- Int targetCount = 0;for( Object *obj = iter->first(); obj; obj = iter->next() ){if( !isAttackListTarget( obj, local ) )continue;- const Bool startsList = targetCount == 0 && !isInWaypointMode();+ AttackAssignSlot slot;+ slot.id = obj->getID();+ slot.x = obj->getPosition()->x;+ slot.y = obj->getPosition()->y;+ targets.push_back( slot );+ }++ orderAroundPoint( attackers, center.x, center.y );+ orderAroundPoint( targets, center.x, center.y );++ std::vector<AttackAssignPair> pairs;+ assignAttacks( (Int)attackers.size(), (Int)targets.size(), pairs );++ ObjectID previousAttacker = INVALID_ID;+ for( std::vector<AttackAssignPair>::const_iterator pair = pairs.begin(); pair != pairs.end(); ++pair )+ {+ const AttackAssignSlot& attacker = attackers[ pair->attacker ];+ const AttackAssignSlot& target = targets[ pair->target ];+ if( attacker.id == target.id )+ continue;++ const Bool firstForThisAttacker = attacker.id != previousAttacker;+ previousAttacker = attacker.id;++ // each unit's first shot starts that unit's list. the rest of its run is queued behind it.+ // shift appends the whole run onto whatever that one unit was already doing.+ const Bool startsList = firstForThisAttacker && !isInWaypointMode();markNextOrderQueued( startsList ? ORDER_QUEUE_FRESH : ORDER_QUEUE_APPEND );GameMessage *attack = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACK_OBJECT );- attack->appendObjectIDArgument( obj->getID() );- targetCount++;+ attack->appendObjectIDArgument( target.id );+ attack->appendObjectIDArgument( attacker.id );}- DEBUG_LOG(("attack circle: radius %.0f, %d targets, %d selected\n", radius, targetCount,- getSelectCount()));+ DEBUG_LOG(("attack circle: radius %.0f, %d targets, %d attackers, %d shots\n", radius,+ (Int)targets.size(), (Int)attackers.size(), (Int)pairs.size()));return TRUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cppindex 7436a9e49..9394933b0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp@@ -472,8 +472,33 @@ Bool OrderQueue::takeMessage( GameMessage *msg, AIGroup *selected, Player *ownerif( selected == NULL || !isOrder( msg->getType() ) || OrderQueue_namesItsOwnSource( msg ) )return FALSE;- std::vector<ObjectID> ids = selected->getAllIDs();- std::sort( ids.begin(), ids.end() );+ // An attack circle names the one unit a shot is for, as the argument after the target. The chain+ // is that unit's alone, or the whole selection would still share every target. A one-argument+ // attack is the click it always was, and it still goes to everyone selected. A named unit that+ // has already died, or that this player does not own, is not a reason to fire the rest of the+ // selection at that target either.+ std::vector<ObjectID> ids;+ if( msg->getType() == GameMessage::MSG_DO_ATTACK_OBJECT && msg->getArgumentCount() >= 2 )+ {+ const ObjectID attackerID = msg->getArgument( 1 )->objectID;+ const Object *attacker = TheGameLogic->findObjectByID( attackerID );+ if( attacker != NULL && attacker->getControllingPlayer() != owner )+ {+ DEBUG_CRASH(( "MSG_DO_ATTACK_OBJECT: player %d named object %d, which it does not control",+ owner->getPlayerIndex(), (Int)attackerID ));+ }+ if( attacker == NULL || attacker->getControllingPlayer() != owner )+ {+ TheAI->destroyGroup( selected );+ return TRUE;+ }+ ids.push_back( attackerID );+ }+ else+ {+ ids = selected->getAllIDs();+ std::sort( ids.begin(), ids.end() );+ }if( mode == ORDER_QUEUE_NONE || !isQueueable( msg->getType() ) ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex b1ed47712..702b8dc53 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -1516,20 +1516,52 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup// Check enemy, as it is possible that he died this frame.if (enemy){- if (currentlySelectedGroup)+ AIGroup *attackers = currentlySelectedGroup;+ AIGroup *named = NULL;++ // The second id is the one unit this shot is for, written by the attack circle. A+ // message with only the target still means the whole selection. The queue re-enters+ // here with a group that is already that one unit; a message that arrives on the full+ // selection has to be narrowed here or it focus-fires.+ if( msg->getArgumentCount() >= 2 )+ {+ const ObjectID attackerID = msg->getArgument( 1 )->objectID;+ Object *attacker = TheGameLogic->findObjectByID( attackerID );+ if( attacker == NULL || !isPlayerCommandingOwnObject( thisPlayer, attacker->getControllingPlayer() ) )+ {+ if( attacker != NULL )+ {+ DEBUG_CRASH( ("MSG_DO_ATTACK_OBJECT: a command from player %d named object %d, which it does not control",+ msg->getPlayerIndex(), (Int)attackerID) );+ }+ break;+ }++ if( attackers == NULL || attackers->getCount() != 1 || !attackers->isMember( attacker ) )+ {+ named = TheAI->createGroup();+ named->add( attacker );+ attackers = named;+ }+ }++ if (attackers){// 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(),+ DEBUG_LOG(("attack order: %d units on %s\n", attackers->getCount(),enemy->getTemplate()->getName().str()));- currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.- currentlySelectedGroup->groupAttackObject( enemy, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );+ attackers->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.+ attackers->groupAttackObject( enemy, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );}+ if( named )+ TheAI->destroyGroup( named );+}break;diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 595d39ea0..93e1af79d 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -1245,6 +1245,123 @@ TEST(drawn_path_orders_units_by_where_they_already_stand)CHECK_NEAR( 200.0f, distanceAlongPath( path, arc, 100.0f, 400.0f ), 0.001f );}+/* DrawnPath.cpp: the attack circle stands both sides around its centre and deals the shots so the+ counts differ by one at most. 10 guns on 3 targets is 3, 4, 3. 3 guns on 10 targets queue+ 3, 4, 3. */+#include <algorithm>++static AttackAssignSlot attackSlot( Int id, Real x, Real y )+{+ AttackAssignSlot slot;+ slot.id = (ObjectID)id;+ slot.x = x;+ slot.y = y;+ return slot;+}++TEST(attack_circle_splits_shots_as_evenly_as_the_counts_allow)+{+ std::vector<AttackAssignPair> pairs;++ /* ten guns, three targets: each gun one shot, the shares 3, 4 and 3, middle block the long one. */+ assignAttacks( 10, 3, pairs );+ CHECK_EQ( 10, (int)pairs.size() );+ int onTarget[3] = { 0, 0, 0 };+ for( int i = 0; i < 10; i++ )+ {+ CHECK_EQ( i, pairs[i].attacker );+ CHECK( pairs[i].target >= 0 && pairs[i].target < 3 );+ onTarget[ pairs[i].target ]++;+ }+ CHECK_EQ( 3, onTarget[0] );+ CHECK_EQ( 4, onTarget[1] );+ CHECK_EQ( 3, onTarget[2] );++ /* three guns, ten targets: every target is shot once, and the queues are 3, 4, 3 in order. */+ assignAttacks( 3, 10, pairs );+ CHECK_EQ( 10, (int)pairs.size() );+ int perAttacker[3] = { 0, 0, 0 };+ for( int i = 0; i < 10; i++ )+ {+ CHECK_EQ( i, pairs[i].target );+ CHECK( pairs[i].attacker >= 0 && pairs[i].attacker < 3 );+ if( i > 0 )+ CHECK( pairs[i].attacker >= pairs[i - 1].attacker );+ perAttacker[ pairs[i].attacker ]++;+ }+ CHECK_EQ( 3, perAttacker[0] );+ CHECK_EQ( 4, perAttacker[1] );+ CHECK_EQ( 3, perAttacker[2] );++ /* one each, in the order they stand. */+ assignAttacks( 5, 5, pairs );+ CHECK_EQ( 5, (int)pairs.size() );+ for( int i = 0; i < 5; i++ )+ {+ CHECK_EQ( i, pairs[i].attacker );+ CHECK_EQ( i, pairs[i].target );+ }++ /* one target: everybody shoots it. one attacker: that one queues the lot. */+ assignAttacks( 6, 1, pairs );+ CHECK_EQ( 6, (int)pairs.size() );+ for( int i = 0; i < 6; i++ )+ CHECK_EQ( 0, pairs[i].target );++ assignAttacks( 1, 4, pairs );+ CHECK_EQ( 4, (int)pairs.size() );+ for( int i = 0; i < 4; i++ )+ {+ CHECK_EQ( 0, pairs[i].attacker );+ CHECK_EQ( i, pairs[i].target );+ }++ /* nothing to shoot, or nobody to shoot it. */+ assignAttacks( 0, 4, pairs );+ CHECK_EQ( 0, (int)pairs.size() );+ assignAttacks( 4, 0, pairs );+ CHECK_EQ( 0, (int)pairs.size() );++ /* seven and three still differ by one, and every index is used. */+ assignAttacks( 7, 3, pairs );+ CHECK_EQ( 7, (int)pairs.size() );+ int seven[3] = { 0, 0, 0 };+ for( int i = 0; i < 7; i++ )+ seven[ pairs[i].target ]++;+ CHECK_EQ( 2, seven[0] );+ CHECK_EQ( 3, seven[1] );+ CHECK_EQ( 2, seven[2] );+}++TEST(attack_circle_stands_both_sides_around_the_centre)+{+ /* shuffled on purpose. counter-clockwise from +x, nearer first on the same ray, id after that,+ and a man standing on the centre itself leads. */+ std::vector<AttackAssignSlot> slots;+ slots.push_back( attackSlot( 4, 0.0f, -10.0f ) ); /* -y */+ slots.push_back( attackSlot( 1, 10.0f, 0.0f ) ); /* +x, far */+ slots.push_back( attackSlot( 8, 10.0f, 0.0f ) ); /* +x, far, higher id */+ slots.push_back( attackSlot( 2, 0.0f, 10.0f ) ); /* +y */+ slots.push_back( attackSlot( 5, 0.0f, 0.0f ) ); /* centre */+ slots.push_back( attackSlot( 6, 5.0f, 0.0f ) ); /* +x, near */+ slots.push_back( attackSlot( 3, -10.0f, 0.0f ) ); /* -x */+ slots.push_back( attackSlot( 9, 10.0f, 10.0f ) ); /* diagonal, between +x and +y */++ std::vector<AttackAssignSlot> reversed = slots;+ std::reverse( reversed.begin(), reversed.end() );++ orderAroundPoint( slots, 0.0f, 0.0f );+ orderAroundPoint( reversed, 0.0f, 0.0f );++ const int expect[] = { 5, 6, 1, 8, 9, 2, 3, 4 };+ CHECK_EQ( 8, (int)slots.size() );+ for( int i = 0; i < 8; i++ )+ {+ CHECK_EQ( expect[i], (int)slots[i].id );+ CHECK_EQ( expect[i], (int)reversed[i].id );+ }+}+/* AssaultTransportAIUpdate.cpp: the troop crawler deploys its passengers at a target and used toleave them walking behind it for the rest of the attack move once that target died - and on aplain attack order it re-boarded them the instant the target died, once per dead enemy. Both@@ -9963,6 +10080,43 @@ TEST(massing_waits_for_a_force_but_never_waits_for_ever)}+/** Another factory when the queue is backing up, and another tech building until three are standing.+ Easy and Normal never reach the caller: economy buildings stay off below Brutal. */+TEST(extra_factory_follows_the_queue_and_tech_stops_at_three)+{+ // nothing left standing: put one back+ CHECK( aiWantsAnotherFactory( 0, 0, 0, 0, FALSE ) );++ // one already going up is the building this would ask for+ CHECK( !aiWantsAnotherFactory( 0, 1, 0, 0, FALSE ) );+ CHECK( !aiWantsAnotherFactory( 2, 1, 0, 4, FALSE ) );++ // a factory with an empty queue is the spare+ CHECK( !aiWantsAnotherFactory( 2, 0, 1, 3, FALSE ) );++ // every finished factory is busy, and a unit is waiting behind the one being built+ CHECK( aiWantsAnotherFactory( 2, 0, 0, 2, FALSE ) );++ // busy, but the queue is only the unit under construction+ CHECK( !aiWantsAnotherFactory( 1, 0, 0, 1, FALSE ) );++ // airfields and the income buildings: another whenever one is not already going up,+ // even while a finished one sits idle+ CHECK( aiWantsAnotherFactory( 3, 0, 2, 0, TRUE ) );+ CHECK( !aiWantsAnotherFactory( 3, 1, 0, 5, TRUE ) );++ CHECK( aiWantsAnotherTechBuilding( 0, 0 ) );+ CHECK( aiWantsAnotherTechBuilding( AI_TECH_BUILDING_COPIES - 1, 0 ) );+ CHECK( !aiWantsAnotherTechBuilding( 2, 1 ) );+ CHECK( !aiWantsAnotherTechBuilding( AI_TECH_BUILDING_COPIES, 0 ) );++ TAiData ladder;+ CHECK( !ladder.m_skill[ AISKILL_EASY ].m_economyBuildings );+ CHECK( !ladder.m_skill[ AISKILL_MEDIUM ].m_economyBuildings );+ CHECK( ladder.m_skill[ AISKILL_BRUTAL ].m_economyBuildings );+}++/** B2: which enemy to go after. EA's answer was the nearest one, plus a rule with the sign thewrong way round - an enemy who had lost his units or his production had his distance set to halfthe map, which is "ignore the one you are about to beat" and is what drags matches out. */