Skip to content

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

fix(gameclient): show the attack key cannot fire when nothing can shoot

Olcay Seygan9139081cd205
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92c63e8b1..42869257e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -267,7 +267,7 @@ found and fixed — EA's own, not port damage.**
- Press V, or the move button, then drag the left button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, however far you keep drawing it: a long sweep used to give up partway through and finish as one straight run to the cursor, and now it holds its shape to the end. Letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. Draw the line with the left button while attack move is armed and the whole line is an attack move: artillery spread across a front, each gun firing on what walks into it, instead of one clump on one spot. Guard draws the same way. Every line is drawn with the left button, the one armed orders are aimed with, and the right button never draws one: its drag is the camera. Without an order armed a left drag is the selection box it always was. Armed with attack instead, every unit fires on its own station along the line, which is a barrage laid across a ridge in one drag. `FormationDrag = no` in Options.ini turns the line off if you would rather an armed drag did nothing.
- Selected units draw a thread to wherever they are going, with the pointer, tinted, sitting on the spot. Every order draws one: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. Units standing together and headed the same way share one thread, from the middle of the knot to the middle of where they are going, so twenty tanks sent across the map draw one line instead of twenty laid on top of each other; a selection spread over the map draws one per knot, and a flank sent on its own still shows. An angry mob draws one thread for the whole mob, not one per rioter. An attack move and a shot at the ground both point at the spot you clicked: the attack move's thread used to wander off to whichever free ground each unit was steering for, and ground fire pointed at the middle of the nearest map cell. An attack move stays pink from start to finish, too. A unit that stopped to fight used to swing its thread onto the enemy it was fighting, and only swung it back to your destination once the enemy was dead. A dot and a ring stood in for the pointer for a while, and players asked for the pointer back. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed. The animated ring the ground used to sprout wherever you clicked is gone: it flashed for a second and told you nothing the marker sitting on the destination does not, and that marker stays for as long as the order does. A marker that has just appeared slides the last few pixels up out of the bottom right and fades in as it lands, over about an eighth of a second, so a fresh order catches your eye without anything flashing. Aircraft draw their thread from the click, not from the moment they leave the runway. A plane parked on its airfield answers an order by starting its takeoff and puts the order itself aside until the wheels are up, so the taxi and the climb, which is exactly the stretch where you are wondering whether the strike went out at all, used to show nothing.
- A 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.
+- 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. With A armed, pointing at something nothing in your selection can shoot shows the game's can't-do-that pointer: a Sentry Drone before its gun is researched has no weapon at all, and the pointer used to look ready while the click did nothing.
- 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. 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.
diff --git a/GeneralsMD/Code/Data/Scenarios/sentryattack.txt b/GeneralsMD/Code/Data/Scenarios/sentryattack.txt
new file mode 100644
index 000000000..b03c05692
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/sentryattack.txt
@@ -0,0 +1,22 @@
+# The attack key's click (A, then a left click on the target) for a Sentry Drone with no gun, on a
+# Technical 120 away, inside the drone gun's 150, and for a Humvee on a Rocket Buggy 400 away.
+#
+# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 1900
+# -scenario sentryattack -logPrefix sentryattack_
+#
+# Measured 2026-10-05. The drone has no weapon until the war factory researches the Sentry Drone Gun,
+# so its click sends nothing ("none of ... can shoot" in the log) and the Technical is untouched at
+# frame 1890; the Humvee's Buggy is dead. With the gun researched (add a power plant, a war factory
+# and "20 shiftupgrade 0 AmericaWarFactory Upgrade_AmericaSentryDroneGun") the drone kills a
+# Technical at 120 and at 400 alike, on forceattack, shiftattack and a script attack.
+
+30 spawn 0 AmericaVehicleSentryDrone 1 1000 3700
+30 spawn 0 AmericaVehicleHumvee 1 1000 3300
+1000 spawn 1 GLAVehicleTechnical 1 1120 3700
+1000 spawn 1 GLAVehicleRocketBuggy 1 1400 3300
+1010 forceattack 0 AmericaVehicleSentryDrone 1 GLAVehicleTechnical*
+1010 forceattack 0 AmericaVehicleHumvee 1 GLAVehicleRocketBuggy
+1890 tally 1 GLAVehicleTechnical*
+1890 tally 1 GLAVehicleRocketBuggy
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index f394e85cc..0c38342f6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -84,7 +84,8 @@ enum ScenarioActionType
SCENARIO_ACTION_DOCK, ///< dock <slot> <selector> <targetSlot> <targetSelector>; a right click on a supply point or a dock
SCENARIO_ACTION_CONSTRUCT, ///< construct <slot> <template> <position>; the local player's placement click, whatever is selected, as a message that is recorded and crosses the network
SCENARIO_ACTION_STANCE, ///< stance <slot> <selector> aggressive|defensive; the stance key, as MSG_SET_STANCE
- SCENARIO_ACTION_HUNT ///< hunt <slot> <selector> <position> [radius]; the search and destroy key's sweep, through the order queue as its messages arrive
+ SCENARIO_ACTION_HUNT, ///< hunt <slot> <selector> <position> [radius]; the search and destroy key's sweep, through the order queue as its messages arrive
+ SCENARIO_ACTION_FORCEATTACK ///< forceattack <slot> <selector> <targetSlot> <targetSelector>; the attack key's click on one unit, as MSG_DO_FORCE_ATTACK_OBJECT
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 6010a73da..d5fff9143 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -1559,13 +1559,16 @@ GameMessage::Type CommandTranslator::evaluateForceAttack( Drawable *draw, const
TheMessageStream->appendMessage( retVal );
}
}
- else if( result == ATTACKRESULT_INVALID_SHOT && type == DO_HINT )
+ // Nobody selected can shoot this at all: a Sentry Drone before its gun is researched has no weapon.
+ // With no hint the attack key's cursor stayed as it was over the target, and the click did nothing
+ // without a word, so it read as a broken key rather than as an unarmed unit.
+ else if( ( result == ATTACKRESULT_INVALID_SHOT || result == ATTACKRESULT_NOT_POSSIBLE ) && type == DO_HINT )
{
retVal = GameMessage::MSG_IMPOSSIBLE_ATTACK_HINT;
TheMessageStream->appendMessage( retVal );
}
- }
- else if( pos )
+ }
+ else if( pos )
{
CanAttackResult result = canAnyForceAttack( allSelected, NULL, pos );
@@ -1588,7 +1591,7 @@ GameMessage::Type CommandTranslator::evaluateForceAttack( Drawable *draw, const
TheMessageStream->appendMessage( retVal );
}
}
- else if( result == ATTACKRESULT_INVALID_SHOT && type == DO_HINT )
+ else if( ( result == ATTACKRESULT_INVALID_SHOT || result == ATTACKRESULT_NOT_POSSIBLE ) && type == DO_HINT )
{
retVal = GameMessage::MSG_IMPOSSIBLE_ATTACK_HINT;
TheMessageStream->appendMessage( retVal );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 6cbcb3f3f..853042319 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -219,6 +219,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_STANCE;
else if (token == "hunt")
*action = SCENARIO_ACTION_HUNT;
+ else if (token == "forceattack")
+ *action = SCENARIO_ACTION_FORCEATTACK;
else
return FALSE;
@@ -304,6 +306,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_HUNT: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_STANCE: return SCENARIO_TOKENS_STANCE;
case SCENARIO_ACTION_SHIFTATTACK: return SCENARIO_TOKENS_ATTACK;
+ case SCENARIO_ACTION_FORCEATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_SHIFTPOWER: return SCENARIO_TOKENS_SHIFTPOWER;
case SCENARIO_ACTION_SHIFTUPGRADE: return SCENARIO_TOKENS_SHIFTUPGRADE;
case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;
@@ -404,6 +407,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_ENTER:
case SCENARIO_ACTION_DOCK:
case SCENARIO_ACTION_SHIFTATTACK:
+ case SCENARIO_ACTION_FORCEATTACK:
case SCENARIO_ACTION_SHIFTPOWER:
{
if (!parseWholeNumber( tokens[ 4 ], &action->targetSlot ))
@@ -1322,6 +1326,42 @@ static Bool executeStance( const ScenarioAction &action, Player *player, AIGroup
return TRUE;
}
+/** The attack key armed and a left click on one enemy: MSG_DO_FORCE_ATTACK_OBJECT handed to the
+ dispatcher with the matching units as the selection. The client only sends it when one of them can
+ shoot the target, so a seat that could not is refused here the same way rather than ordered. */
+static Bool executeForceAttack( const ScenarioAction &action, Player *player, AIGroup *group, Int taken )
+{
+ Player *targetPlayer = findPlayerForSlot( action.targetSlot );
+ Object *target = (targetPlayer != NULL) ? findFirstMatching( targetPlayer, action.targetSelector ) : NULL;
+ Bool canShoot = FALSE;
+ const VecObjectID ids = group->getAllIDs();
+ for( VecObjectID::const_iterator it = ids.begin(); target != NULL && it != ids.end(); ++it )
+ {
+ const Object *obj = TheGameLogic->findObjectByID( *it );
+ const CanAttackResult result = obj->isAbleToAttack()
+ ? obj->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET_FORCED, target, CMD_FROM_PLAYER )
+ : ATTACKRESULT_NOT_POSSIBLE;
+ canShoot = canShoot || result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING;
+ }
+ if (!canShoot)
+ {
+ DEBUG_LOG(("SCENARIO: frame %d forceattack: none of slot %d '%s' x%d can shoot slot %d '%s'; the click sends nothing\n",
+ action.frame, action.slot, action.selector.str(), taken, action.targetSlot, action.targetSelector.str()));
+ TheAI->destroyGroup( group );
+ return FALSE;
+ }
+
+ GameMessage *msg = newInstance( GameMessage )( GameMessage::MSG_DO_FORCE_ATTACK_OBJECT );
+ msg->friend_setPlayerIndex( player->getPlayerIndex() );
+ msg->appendObjectIDArgument( target->getID() );
+ TheGameLogic->logicMessageDispatcher( msg, group );
+ msg->deleteInstance();
+
+ DEBUG_LOG(("SCENARIO: frame %d forceattack slot %d '%s' x%d -> slot %d '%s'\n",
+ action.frame, action.slot, action.selector.str(), taken, action.targetSlot, action.targetSelector.str()));
+ return TRUE;
+}
+
/** The search and destroy key: the ring sweepRoute gives this seat round the point, from where the
units stand, each point handed to the order queue the way the key's messages arrive - the first
fresh, the rest behind it - and then a guard of the whole circle. Each message gets a group of
@@ -1457,6 +1497,9 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_STANCE:
return executeStance( action, player, group, taken ); // the dispatcher destroys the group
+ case SCENARIO_ACTION_FORCEATTACK:
+ return executeForceAttack( action, player, group, taken ); // so does this, or it does itself
+
case SCENARIO_ACTION_HUNT:
return executeSweep( action, player, dest, group, taken ); // and so does this
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 00ef3fd81..0293d7152 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -14890,6 +14890,11 @@ TEST(scenario_parses_the_order_lines)
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_SHIFTATTACK );
CHECK_STR( action.targetSelector.str(), "AmericaCommandCenter" );
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftattack 0 * 1", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 forceattack 0 AmericaVehicleSentryDrone 1 GLAVehicleTechnical*", &action ), (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_FORCEATTACK );
+ CHECK_EQ( action.targetSlot, 1 );
+ CHECK_STR( action.targetSelector.str(), "GLAVehicleTechnical*" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 forceattack 0 * 1", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
CHECK_EQ( (Int)ScenarioDrill_parseLine( "200 shiftpower 0 * 1 AmericaSupplyCenter SpecialAbilityBlackLotusCaptureBuilding",
&action ), (Int)SCENARIO_PARSE_OK );