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
refactor(gameengine): drop the shot claim ledger
Olcay Seygan2193ea3c50d5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 42560b3c6..605b2ad69 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -208,14 +208,8 @@ found and fixed — EA's own, not port damage.**- A Crawler that has lost its whole squad carries on with your order instead of idling.- Attack-move state is saved now, instead of coming back as random memory.-## 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.-- Soldiers in a heavy fight no longer stand there like statues. One whose target was already covered by somebody else's shot held his fire and kept the target, waiting for the others to finish it, while enemies nobody had called stood within reach. Thirty Red Guards on one burning Crusader meant a handful shooting and the rest watching. He lets that target go now and turns on the next enemy he can hit. Over five 280-unit clashes, soldiers who stood three seconds or more with an enemy in range and never fired went from 146 to 21. Replays recorded before this play out differently.-- 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.+## Selecting and ordering with the mouse+- 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.- A box dragged over your army and your economy together takes the army. The dozers, workers, supply trucks and hackers standing among the tanks stay where they are, and ambulances and troop carriers go with the soldiers they look after. A box with nobody military in it takes the workers the way it always did.@@ -227,7 +221,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: 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 stroke drawn across enemies splits them across the units that can shoot, as evenly as the numbers allow, in the order both sides stand along the stroke. The unit nearest the start takes the enemy nearest the start. Ten guns on three enemies put four on one and three on each of the others. Three guns on ten each work down a run of three or four. The whole group used to walk one list and pour every gun into each enemy in turn. Before that the line poured fire into the ground under it and hit whatever happened to be standing there. A stroke 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. 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 stroke drawn across enemies splits them across the units that can shoot, as evenly as the numbers allow, in the order both sides stand along the stroke. The unit nearest the start takes the enemy nearest the start. Ten guns on three enemies put four on one and three on each of the others. Three guns on ten each work down a run of three or four. The whole group used to walk one list and pour every gun into each enemy in turn. Before that the line poured fire into the ground under it and hit whatever happened to be standing there. A stroke 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.@@ -796,7 +790,6 @@ A third pass went through the generals' powers, promotions and unit abilities.- An EMPed or unpowered defence stops acting as if it were fighting. A Gattling Cannon hit mid-burst spun its barrels for the whole blackout, and one ordered to attack while it had no power spun up without firing a shot. It drops its target now, can't be given a new one until it is back, and picks one again when it is.- A vehicle knocked out by an EMP while its turret was turning goes quiet. The turret's motor sound only ever stopped when the turret next moved, so it looped for the whole time the vehicle sat dead.- A Fire Base can be ordered to attack what only the soldiers inside it can hit. The base's own howitzer answered first, and a howitzer hits nothing in the air and nothing within 50 of the base, so Missile Defenders inside got no attack cursor on a Comanche.-- A defence that picked its own target moves on once that target is as good as dead. When the shots already in the air were enough to finish it, a Gattling Cannon held its fire and kept aiming at it, for up to three and a half seconds, while the next tank drove up. It lets go and takes the next one.- The green beam between Patriot batteries means a battery is really joining in. A shot called every idle battery within 200 to fire a volley at the same target, and the beams went out to batteries that could not: one without power, one knocked out by an EMP, one already busy with its own target, one the target was too far from. None of them fired. A battery shooting down a missile called the rest in too, with a weapon that cannot hit missiles. Only a battery able to hit the target from where it stands is called now. A battery whose target died after one missile of its volley also kept the longer assist range for its own shots until it next emptied a volley; it drops it when the target goes.- Killing something with poison or toxin credited nobody with experience or score.- Healing a unit counted as attacking it, so guards chased the wrong target.@@ -1652,6 +1645,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the samemost games are played at, so it came out again: every soldier on screen keeps his shadow.- The six-rung difficulty ladder is back down to three. The three extra rungs were built, played and taken out again: a player picks a level once and wants to know what it means, and six names that each moved one switch was a worse answer to that than three that each describe an opponent. The machinery underneath is the same, so the levels are still tunable in the data files, and Hard kept the top rung's numbers rather than its old ones.- The three-piece command bar was reverted once, for having nowhere to put the painting of the bar, and is back now that the painting has been cut into three to match. Each piece is fitted by matching it against the artwork it was cut from rather than by eye: the eyeballed fit was four percent out, which nobody sees on the metal and everybody sees on the money readout.+- Units no longer call their shots. For a while a unit put the shot it was lining up on a shared list, and the rest of its group passed over any enemy that list said was already dead, so a squad would spread its fire instead of emptying it into one tank. In play it cost more than it saved: soldiers held their fire on a target somebody else had called while enemies stood in reach, and each patch for that was one more exception. It is gone, and units pick and fire at their targets the way the 2003 game does. Over five 280-unit clashes, stops of three seconds or more with an enemy in range and no shot came to 33, where the last version of the list left 34 and the one before it 167. Replays recorded with it play out differently.- The opponent's decisions are argued with a number: 20 headless matches per change, same seeds, win rate and match length before and after.- That caught two changes that looked right and measured catastrophic - a wave that waited jammed the whole production line, and a retreat rule that counted buildings as gunfire sent every attack home. Both showed up as twenty matches with zero kills.- The same habit caught a speed fix that measured beautifully for the wrong reason. Capping the search for room beside a supply dock cut a once-a-minute stall and dropped the average eight-player frame below a millisecond, which was the giveaway: the first supply centre of every match went down on a blocked spot and never went up, so no computer player had an economy and nothing was happening. Counting supply trucks and attack waves next to the frame times showed it at once. The cap came out, and the stall was cured instead by not ordering the same supply centre twice.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 79c4a1123..44efc1057 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -401,7 +401,6 @@ GameEngine/Include/GameLogic/FPUControl.hGameEngine/Include/GameLogic/FiringTracker.hGameEngine/Include/GameLogic/GameLogic.hGameEngine/Include/GameLogic/GhostObject.h-GameEngine/Include/GameLogic/IncomingDamage.hGameEngine/Include/GameLogic/Locomotor.hGameEngine/Include/GameLogic/LocomotorSet.hGameEngine/Include/GameLogic/LogicRandomValue.h@@ -1142,7 +1141,6 @@ GameEngine/Source/GameLogic/Object/Helper/ObjectWeaponStatusHelper.cppGameEngine/Source/GameLogic/Object/Helper/StatusDamageHelper.cppGameEngine/Source/GameLogic/Object/Helper/SubdualDamageHelper.cppGameEngine/Source/GameLogic/Object/Helper/TempWeaponBonusHelper.cpp-GameEngine/Source/GameLogic/Object/IncomingDamage.cppGameEngine/Source/GameLogic/Object/Locomotor.cppGameEngine/Source/GameLogic/Object/Object.cppGameEngine/Source/GameLogic/Object/ObjectCreationList.cppdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.hdeleted file mode 100644index 2efad69f8..000000000--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/IncomingDamage.h+++ /dev/null@@ -1,106 +0,0 @@-/*-** Command & Conquer Generals Zero Hour(tm)-** Copyright 2025 Electronic Arts Inc.-**-** This program is free software: you can redistribute it and/or modify-** it under the terms of the GNU General Public License as published by-** the Free Software Foundation, either version 3 of the License, or-** (at your option) any later version.-**-** This program is distributed in the hope that it will be useful,-** but WITHOUT ANY WARRANTY; without even the implied warranty of-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-** GNU General Public License for more details.-**-** You should have received a copy of the GNU General Public License-** along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--// IncomingDamage.h ///////////////////////////////////////////////////////////////////////////////-// The ledger of damage that is already on its way to a target but has not landed yet.-//-// A shot whose damage is delayed - a projectile in flight, or a hitscan weapon far enough away that-// the damage is scheduled for a later frame - leaves the shooter's barrel with nothing anywhere-// recording that the victim is, for practical purposes, already dead. Every other unit still sees-// full health and keeps firing, so a squad routinely spends a whole volley on a target the first-// two shots had already killed.-//-// Every delayed shot is booked here against its victim, with the frame its damage is expected to-// land. Auto-targeting reads the ledger back: a target whose booked damage already covers its-// remaining health is skipped when acquiring, and a unit that is auto-attacking one stops firing-// and looks for something else. Nothing here touches an explicit player attack order.-//-// Entries expire on their own. A booking is dropped when its damage lands, and otherwise a few-// frames after the impact was due, so a missile that is shot down or diverted by countermeasures-// costs at most that long a pause rather than a permanent reservation.-//-// The ledger is logic-side and iterated in ObjectID order, so it stays deterministic across clients-// and replays. It is deliberately not saved: bookings live under a second of game time, and a-// loaded game simply re-books as its units fire again.-///////////////////////////////////////////////////////////////////////////////////////////////////--#pragma once-#ifndef __INCOMINGDAMAGE_H__-#define __INCOMINGDAMAGE_H__--#include "Lib/BaseType.h"-#include "Common/GameCommon.h"--class Object;--//--------------------------------------------------------------------------------------------------class IncomingDamageTracker-{-public:-- /// Drop every booking. Called when the game logic resets.- static void reset();-- /// Drop the bookings whose impact frame has come and gone. Called once per logic frame.- static void update(UnsignedInt currentFrame);-- /**- Book a shot's damage against its victim, expected to land on impactFrame. The amount is what- the shot is estimated to actually take off the victim, i.e. after armor.- */- static void bookShot(ObjectID victim, ObjectID shooter, Real amount,- UnsignedInt currentFrame, UnsignedInt impactFrame);-- /// A shot from this shooter has landed on this victim: release the oldest booking of the pair.- static void shotLanded(ObjectID victim, ObjectID shooter);-- /// Total damage booked against this victim that has not landed yet.- static Real getBookedDamage(ObjectID victim);-- /**- TRUE if the damage already on its way to this victim covers remainingHealth, i.e. shooting it- again would be wasted. Always FALSE for an object nothing has booked damage against, so the- common case costs one lookup in an almost always tiny table.- */- static Bool isAlreadyDoomed(ObjectID victim, Real remainingHealth);-- /// 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/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cppindex a1c951057..a9ec363ec 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp@@ -57,7 +57,6 @@#include "GameLogic/AITNGuard.h"#include "GameLogic/AIStateMachine.h"#include "GameLogic/AIPathfind.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Locomotor.h"#include "GameLogic/PartitionManager.h"#include "GameLogic/PolygonTrigger.h"@@ -5539,22 +5538,6 @@ 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());-}-//----------------------------------------------------------------------------------------------------------/*** Would a plane that turns toward its target as hard as it can get the target inside its aim cone while it@@ -5664,23 +5647,6 @@ StateReturnType AIAttackAimAtTargetState::update(){if (!victim || victim->isEffectivelyDead())return STATE_FAILURE; // can't aim at dead things-- // The fire state holds the round when the victim is already paid for and falls back to aiming,- // and aiming hands it straight back to the fire state, so a unit that keeps this victim keeps- // holding its fire for as long as somebody else's claim covers it. In a crowd that is most of- // a squad standing silent beside enemies nobody has claimed while a few of them whittle down- // one target. Let go of a target we chose ourselves: the scan that chose it passes over- // doomed ones and finds the next. An order is kept, as the fire state promises.- if (sourceAI->getLastCommandSource() == CMD_FROM_AI &&- IncomingDamageTracker::isSpokenFor(victim, source->getID()))- {- return STATE_FAILURE;- }-- // 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();@@ -5915,31 +5881,6 @@ StateReturnType AIAttackFireWeaponState::update()// if our target is dead, go ahead and stop.if (!victim || victim->isEffectivelyDead())return STATE_FAILURE;-- //- // 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.- //- // 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()))- 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/AI/OrderQueue.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cppindex 9394933b0..112595223 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/OrderQueue.cpp@@ -29,7 +29,6 @@#include "GameLogic/AI.h"#include "GameLogic/AIStateMachine.h"#include "GameLogic/GameLogic.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Object.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/JetAIUpdate.h"@@ -254,12 +253,6 @@ static Bool OrderQueue_isWalking( const AIUpdateInterface *ai )}}-//--------------------------------------------------------------------------------------------------static Bool OrderQueue_isAttack( GameMessage::Type type )-{- return type == GameMessage::MSG_DO_ATTACK_OBJECT || type == GameMessage::MSG_DO_FORCE_ATTACK_OBJECT;-}-//-------------------------------------------------------------------------------------------------/** A special power that names the object firing it - a superweapon off the shortcut bar - goes to* that object whatever is selected, so it is no order to the selection at all. */@@ -754,11 +747,6 @@ Bool OrderQueue::isStepOver( OrderChain& chain, Player *owner )const Object *target = TheGameLogic->findObjectByID( targetID );if( target == NULL || target->isEffectivelyDead() )return TRUE;-- // a flight fires from range and its missiles take seconds to arrive, so a target with enough- // already in the air to kill it is finished as far as the list is concerned- if( OrderQueue_isAttack( chain.m_active.getType() ) && IncomingDamageTracker::isAlreadyDoomed( target ) )- return TRUE;}// a post never ends by itself; the object it guards dying is the one way off it, above@@ -844,8 +832,7 @@ Bool OrderQueue::advance( OrderChain& chain, Player *owner )if( targetID != INVALID_ID ){const Object *target = TheGameLogic->findObjectByID( targetID );- if( target == NULL || target->isEffectivelyDead()- || ( OrderQueue_isAttack( next.getType() ) && IncomingDamageTracker::isAlreadyDoomed( target ) ) )+ if( target == NULL || target->isEffectivelyDead() )continue;// the list was copied when the chain split, and the upgrade belongs to whichever half has the unitdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cppindex e8e970c5c..7bf610444 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/TurretAI.cpp@@ -38,7 +38,6 @@#include "Common/Xfer.h"#include "GameLogic/GameLogic.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Object.h"#include "GameLogic/PartitionManager.h"@@ -1051,15 +1050,6 @@ StateReturnType TurretAIAimTurretState::update()return STATE_FAILURE;}- // The fire state holds the round on a victim already paid for and hands back to this state, which- // never looks for another target, so a turret that had picked the target on its own sat silent- // until the booking lapsed. Drop it; hold scans again, and its scan passes over doomed targets.- if (turret->friend_getTargetWasSetByIdleMood() && IncomingDamageTracker::isSpokenFor(enemy, obj->getID()))- {- turret->setTurretTargetObject(NULL, FALSE);- return STATE_FAILURE;- }-// aim turret towards enemy (turret angle is relative to its parent object)if (enemy->isKindOf(KINDOF_BRIDGE)){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cppdeleted file mode 100644index 60c6781e6..000000000--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/IncomingDamage.cpp+++ /dev/null@@ -1,301 +0,0 @@-/*-** Command & Conquer Generals Zero Hour(tm)-** Copyright 2025 Electronic Arts Inc.-**-** This program is free software: you can redistribute it and/or modify-** it under the terms of the GNU General Public License as published by-** the Free Software Foundation, either version 3 of the License, or-** (at your option) any later version.-**-** This program is distributed in the hope that it will be useful,-** but WITHOUT ANY WARRANTY; without even the implied warranty of-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-** GNU General Public License for more details.-**-** You should have received a copy of the GNU General Public License-** along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--// IncomingDamage.cpp /////////////////////////////////////////////////////////////////////////////-// The ledger of damage in flight. See IncomingDamage.h for what it is for.-///////////////////////////////////////////////////////////////////////////////////////////////////--#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine--#include "GameLogic/IncomingDamage.h"--#include "GameLogic/Object.h"-#include "GameLogic/Module/BodyModule.h"--#include <map>-#include <vector>--//--------------------------------------------------------------------------------------------------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;--// std::map, keyed by ObjectID: the sweep below walks it in ID order on every client.-typedef std::map<ObjectID, BookedShotVec> BookedShotMap;--static BookedShotMap theBookings;--//-// How long past the expected impact a booking is honored before it lapses. A missile that is shot-// down or lured away by countermeasures never lands, and this is how long the target stays wrongly-// reserved: long enough to absorb the slop in the flight-time estimate below, short enough that the-// squad's pause is not noticeable.-//-static const UnsignedInt BOOKING_SLACK_FRAMES = 15;--// Flight time is estimated from the weapon speed, which for a guided projectile is only a hint ---// the projectile flies on its own locomotor. Clamp the estimate rather than trust it outright.-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()-{- theBookings.clear();-}--//--------------------------------------------------------------------------------------------------void IncomingDamageTracker::update(UnsignedInt currentFrame)-{- for (BookedShotMap::iterator vic = theBookings.begin(); vic != theBookings.end(); )- {- BookedShotVec& shots = vic->second;- for (BookedShotVec::iterator s = shots.begin(); s != shots.end(); )- {- if (currentFrame >= s->m_expireFrame)- s = shots.erase(s);- else- ++s;- }-- if (shots.empty())- {- // ObjectIDs are never reused, so an emptied entry is gone for good.- BookedShotMap::iterator dead = vic;- ++vic;- theBookings.erase(dead);- }- else- {- ++vic;- }- }-}--//--------------------------------------------------------------------------------------------------void IncomingDamageTracker::bookShot(ObjectID victim, ObjectID shooter, Real amount,- UnsignedInt currentFrame, UnsignedInt impactFrame)-{- if (victim == INVALID_ID || amount <= 0.0f)- return;-- UnsignedInt flight = (impactFrame > currentFrame) ? (impactFrame - currentFrame) : MIN_FLIGHT_FRAMES;- if (flight < MIN_FLIGHT_FRAMES)- flight = MIN_FLIGHT_FRAMES;- 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)-{- 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_shooter == shooter && !s->m_isClaim)- {- // oldest first: a shooter's shots land in the order they were fired- shots.erase(s);- break;- }- }-- if (shots.empty())- theBookings.erase(vic);-}--//--------------------------------------------------------------------------------------------------Real IncomingDamageTracker::getBookedDamage(ObjectID victim)-{- return sumShotsInFlight(victim);-}--//--------------------------------------------------------------------------------------------------Bool IncomingDamageTracker::isAlreadyDoomed(ObjectID victim, Real remainingHealth)-{- const Real booked = getBookedDamage(victim);- if (booked <= 0.0f)- return FALSE;-- return booked >= remainingHealth;-}--//--------------------------------------------------------------------------------------------------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.cppindex ca3c42491..370a466f1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp@@ -67,7 +67,6 @@#include "GameLogic/AIPathfind.h"#include "GameLogic/GameLogic.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Object.h"#include "GameLogic/Module/AIUpdate.h"#include "GameLogic/Module/BodyModule.h"@@ -5838,18 +5837,6 @@ Bool PartitionFilterPossibleToAttack::allow(Object *objOther)// disable this assert for INTERNAL builds (srj)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, 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::isSpokenFor(objOther, m_obj->getID()))- return FALSE;-//// A capturable tech building is income, not a target. The computer razed the enemy's oil derricks// on sight - the one thing you can do with a derrick that earns nobody anything - when it coulddiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex abaeb14a2..a9ebafc19 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -59,7 +59,6 @@#include "GameLogic/Damage.h"#include "GameLogic/ExperienceTracker.h"#include "GameLogic/GameLogic.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/AIPathfind.h"#include "GameLogic/Module/BehaviorModule.h"#include "GameLogic/Module/BodyModule.h"@@ -1131,15 +1130,6 @@ UnsignedInt WeaponTemplate::fireWeaponTemplatewhen = TheGameLogic->getFrame() + delayInWholeFrames;//DEBUG_LOG(("WeaponTemplate::fireWeaponTemplate: firing weapon in %d frames (= %d)!\n", delayInWholeFrames,when));TheWeaponStore->setDelayedDamage(this, damagePos, when, sourceID, damageID, bonus);-- // This damage is already spoken for: book it so nothing else spends a shot on a target- // that is dead as soon as this lands.- if (damageID != INVALID_ID && victimObj != NULL)- {- IncomingDamageTracker::bookShot(damageID, sourceID,- estimateWeaponTemplateDamage(sourceObj, victimObj, NULL, bonus),- TheGameLogic->getFrame(), when);- }}//-extraLogging@@ -1194,19 +1184,6 @@ UnsignedInt WeaponTemplate::fireWeaponTemplatefiringWeapon->newProjectileFired( sourceObj, projectile, victimObj, victimPos );//The actual logic weapon needs to know this was created.- // Book the projectile's damage against its victim for the length of its flight, so the rest of- // the squad can see that this target is already accounted for. The flight time is only an- // estimate - a guided projectile flies on its own locomotor - and the booking lapses on its own.- if (inflictDamage && victimObj != NULL && victimID != INVALID_ID)- {- const Real flightFrames = sqrtf(distSqr) / getWeaponSpeed();- const UnsignedInt now = TheGameLogic->getFrame();- IncomingDamageTracker::bookShot(victimID, sourceID,- estimateWeaponTemplateDamage(sourceObj, victimObj, NULL, bonus),- now, now + REAL_TO_INT_CEIL(flightFrames));- }--ProjectileUpdateInterface* pui = NULL;for (BehaviorModule** u = projectile->getBehaviorModules(); *u; ++u){@@ -1588,9 +1565,6 @@ void WeaponTemplate::dealDamageInternal(ObjectID sourceID, ObjectID victimID, co}curVictim->attemptDamage(&damageInfo);-- // whatever was booked for this shot has now been spent- IncomingDamageTracker::shotLanded(curVictim->getID(), damageInfo.in.m_sourceID);//DEBUG_ASSERTLOG(damageInfo.out.m_noEffect, ("WeaponTemplate::dealDamageInternal: dealt to %s %08lx: attempted %f, actual %f (%f)\n",// curVictim->getTemplate()->getName().str(),curVictim,// damageInfo.in.m_amount, damageInfo.out.m_actualDamageDealt, damageInfo.out.m_actualDamageClipped));@@ -1742,8 +1716,6 @@ void WeaponStore::update()++ddi;}}-- IncomingDamageTracker::update(TheGameLogic->getFrame());}//-------------------------------------------------------------------------------------------------@@ -1792,7 +1764,6 @@ void WeaponStore::reset()deleteAllDelayedDamage();deleteWeaponsNow();- IncomingDamageTracker::reset();resetWeaponTemplates();}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cppindex 27bc8cd53..5295054c6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp@@ -50,7 +50,6 @@#include "GameClient/ControlBar.h" // COMMAND_FIRED_BY_SCRIPT, the flag every script-fired power carries#include "GameClient/ParticleSys.h"#include "GameLogic/PartitionManager.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/Module/BodyModule.h"#include "GameLogic/Weapon.h"@@ -965,16 +964,14 @@ static void updateStatues( UnsignedInt now )else++theStatueVictimOutOfRange;- // "spoken for" is somebody else's shot, in the air or announced, covering what the victim has leftif (theStatueStops <= STATUE_DETAIL_LINES){- DEBUG_LOG(("STATUE: frame %d id %d '%s' state %d idle %d waiting %d blocked %d victim %d '%s' at %.0f health %.0f spoken for %d, enemy %d '%s' at %.0f, range %.0f, weapon '%s' status %d\n",+ DEBUG_LOG(("STATUE: frame %d id %d '%s' state %d idle %d waiting %d blocked %d victim %d '%s' at %.0f health %.0f, enemy %d '%s' at %.0f, range %.0f, weapon '%s' status %d\n",now, obj->getID(), obj->getTemplate()->getName().str(), (Int)state, ai->isIdle(),ai->isWaitingForPath(), ai->getNumFramesBlocked(),victim ? victim->getID() : 0, victim ? victim->getTemplate()->getName().str() : "",victim ? sqrt( ThePartitionManager->getDistanceSquared( obj, victim, FROM_BOUNDINGSPHERE_2D ) ) : 0.0f,victim ? victim->getBodyModule()->getHealth() : 0.0f,- victim ? IncomingDamageTracker::isSpokenFor( victim, obj->getID() ) : 0,enemy->getID(), enemy->getTemplate()->getName().str(), enemyDist,weapon->getAttackRange( obj ), weapon->getName().str(), (Int)weapon->getStatus()));}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex a265d12ef..a01e98714 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -151,7 +151,6 @@ static int GetSystemMetrics( int which )#include "GameClient/InGameUI.h"#include "GameClient/GlobalLanguage.h"#include "GameClient/View.h"-#include "GameLogic/IncomingDamage.h"#include "GameLogic/AIPlayer.h"#include "GameLogic/AIPathfind.h"#include "GameLogic/CrowdModel.h"@@ -2292,145 +2291,6 @@ TEST(smoke_cap_grows_with_the_thickness_and_stops_at_the_ceiling)CHECK_EQ(particleSmokeParticleCap(20000, 8.0f), 20000);}-//////////////////////////////////////////////////////////////////////////////-// The in-flight damage ledger-//////////////////////////////////////////////////////////////////////////////--/*- * A delayed shot - a projectile in flight, or a hitscan weapon far enough away that its- * damage is scheduled for a later frame - used to leave no trace anywhere between the- * muzzle and the impact. Every other unit went on reading full health off the victim and- * kept firing, so a squad routinely spent a whole volley killing something the first two- * shots had already killed. IncomingDamageTracker books each such shot against its victim- * and auto-targeting reads it back.- *- * These drive the ledger with hand-picked frame numbers, which is why the frame is a- * parameter rather than a read of TheGameLogic - there is no game logic in this binary.- */--static const ObjectID VICTIM_A = (ObjectID)101;-static const ObjectID VICTIM_B = (ObjectID)102;-static const ObjectID SHOOTER_1 = (ObjectID)201;-static const ObjectID SHOOTER_2 = (ObjectID)202;--TEST(incomingdamage_books_and_sums_per_victim)-{- IncomingDamageTracker::reset();- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 100, 110);- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_2, 25.0f, 100, 112);- IncomingDamageTracker::bookShot(VICTIM_B, SHOOTER_1, 10.0f, 100, 110);-- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 65.0f, 0.001f);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_B), 10.0f, 0.001f);-- IncomingDamageTracker::reset();- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);-}--TEST(incomingdamage_doomed_only_once_the_booking_covers_the_health)-{- IncomingDamageTracker::reset();-- // nothing booked: never doomed, however little health is left- CHECK(!IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 1.0f));-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 100, 110);- CHECK(!IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 100.0f));- CHECK(IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 40.0f)); // exactly lethal counts-- // a second shooter's shell tips it over: this is the overkill the ledger exists to stop- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_2, 70.0f, 100, 112);- CHECK(IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 100.0f));-- // and the victim next to it is unaffected- CHECK(!IncomingDamageTracker::isAlreadyDoomed(VICTIM_B, 1.0f));-- IncomingDamageTracker::reset();-}--TEST(incomingdamage_landing_releases_one_booking_from_that_shooter)-{- IncomingDamageTracker::reset();-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 100, 110);- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 101, 111);- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_2, 25.0f, 100, 112);-- // one landing releases one shot, not the shooter's whole account- IncomingDamageTracker::shotLanded(VICTIM_A, SHOOTER_1);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 65.0f, 0.001f);-- IncomingDamageTracker::shotLanded(VICTIM_A, SHOOTER_1);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 25.0f, 0.001f);-- // a landing nobody booked is not an error, and takes nothing with it- IncomingDamageTracker::shotLanded(VICTIM_A, SHOOTER_1);- IncomingDamageTracker::shotLanded(VICTIM_B, SHOOTER_1);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 25.0f, 0.001f);-- IncomingDamageTracker::shotLanded(VICTIM_A, SHOOTER_2);- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);-- IncomingDamageTracker::reset();-}--/*- * The reservation has to lapse on its own, or a missile shot down by a point defence - or- * lured away by countermeasures - would reserve its target forever and the squad would- * stand there holding its fire.- */-TEST(incomingdamage_booking_lapses_after_the_impact_it_predicted)-{- IncomingDamageTracker::reset();-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 100, 110);-- // still honored while the shot is plausibly in the air- IncomingDamageTracker::update(110);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 40.0f, 0.001f);-- // ...and released once the impact is well past and nothing landed- IncomingDamageTracker::update(200);- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);- CHECK(!IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 1.0f));-- IncomingDamageTracker::reset();-}--/*- * An impact frame that has already gone by (or is this very frame) must not wrap the- * unsigned subtraction into a four-billion-frame reservation.- */-TEST(incomingdamage_impact_in_the_past_still_expires)-{- IncomingDamageTracker::reset();-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 40.0f, 500, 400);- CHECK_NEAR(IncomingDamageTracker::getBookedDamage(VICTIM_A), 40.0f, 0.001f);-- IncomingDamageTracker::update(600);- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);-- IncomingDamageTracker::reset();-}--/* A shot that would do nothing is not worth reserving a target over. */-TEST(incomingdamage_ignores_harmless_shots)-{- IncomingDamageTracker::reset();-- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, 0.0f, 100, 110);- IncomingDamageTracker::bookShot(VICTIM_A, SHOOTER_1, -5.0f, 100, 110);- IncomingDamageTracker::bookShot(INVALID_ID, SHOOTER_1, 40.0f, 100, 110);-- CHECK_EQ(IncomingDamageTracker::getBookedDamage(VICTIM_A), 0.0f);- CHECK(!IncomingDamageTracker::isAlreadyDoomed(VICTIM_A, 1.0f));-- IncomingDamageTracker::reset();-}-//////////////////////////////////////////////////////////////////////////////// Drag-to-aim building placement//////////////////////////////////////////////////////////////////////////////