Skip to content

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

feat(gameengine): plan a building as a silhouette you can place into fog

Olcay Seygan0ae62e168433
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 950b6a351..7deb9b79a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -446,6 +446,19 @@ around with the building as you wheel it. Siting a war factory is a decision abo
tanks face when they roll off the line, and until now you could not see that decision until the
building was finished and selected.
+A building you order now lands on the map as a see-through silhouette of the finished thing - not a
+foundation, the building itself - and it stays that way until a worker walks over and puts the first
+spade in. One dozer and four orders gives you the whole base drawn out on the ground before a penny
+of it is spent, and if the third one was a mistake, click it and take the money back. Stop cancels
+it too, so the same key you use to call off a unit calls off a building.
+
+Ground your units have already walked stays buildable after they leave it: a forward base can be
+planned out into the dark and a worker sent to walk there, instead of parking a scout on the spot
+first to hold the lights on. The plan sees nothing while it stands there - it opens no fog of its
+own, so drawing buildings across the map tells you nothing about what is sitting in it. You can see
+your own plan through the fog, click it, and send a builder to it whenever you like; your opponent
+sees nothing. Land nobody of yours has ever seen is still off limits.
+
## Bonuses that come and go when they should
A squad of infantry standing over its own dead used to keep the horde bonus the dead were paying
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h b/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h
index c33a17c14..5f7237ee7 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h
@@ -58,6 +58,12 @@ enum CanEnterType
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+/** Does what the asking player can see of a target stop them ordering something done to it? */
+//-------------------------------------------------------------------------------------------------
+extern Bool ActionManager_shroudHidesTarget( Bool humanSource, Bool fromScript, Bool targetFoggedOrWorse,
+ Bool ownPlacementSilhouette );
+
class ActionManager : public SubsystemInterface
{
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
index 22c5eadc7..74f4e68f3 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
@@ -98,6 +98,11 @@ enum LegalBuildCode
LBC_GENERIC_FAILURE,
};
+//-------------------------------------------------------------------------------------------------
+/** Does what the local player can see of a cell stop them putting a structure on it? */
+//-------------------------------------------------------------------------------------------------
+extern Bool BuildAssistant_shroudBlocksBuilding( CellShroudStatus status );
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class BuildAssistant : public SubsystemInterface
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
index 1a887c5af..8d43ad1f2 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
@@ -126,4 +126,7 @@ public:
extern void pickAndPlayUnitVoiceResponse( const DrawableList *list, GameMessage::Type msgType, PickAndPlayInfo *info = NULL );
+///< does the stop key cancel a building that is going up, rather than stopping a unit?
+extern Bool Command_stopMeansCancelConstruction( Int selectionCount, Bool locallyControlled, Bool underConstruction );
+
#endif
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 444f1ad29..364c5c54f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -68,6 +68,16 @@ enum BodyDamageType;
#define DEF_DECAY_FRAMES (4)
#define SUSTAIN_INDEFINITELY (0xfffffffe) // forever and ever, amen.
+//
+// A structure that has been placed but whose builder has not walked over yet is drawn as a
+// translucent silhouette at this opacity - the same value the placement preview uses, so what
+// you see under the cursor is exactly what lands on the map until the build actually starts.
+//
+const Real PLACEMENT_SILHOUETTE_OPACITY = 0.45f;
+
+///< the opacity a drawable is actually drawn at, given what it is doing
+extern Real Drawable_effectiveOpacity( Real explicitOpacity, Real stealthOpacity, Bool awaitingBuilder );
+
//-----------------------------------------------------------------------------
//@TODO -- The drawable icon system needs to be implemented in a proper manner -- KM
// Fact 1: Every drawable in the world shouldn't have to have a pointer
@@ -529,7 +539,7 @@ public:
inline void setDrawableOpacity( Real value ) { m_explicitOpacity = value; } ///< set alpha/opacity value used to override defaults when drawing.
// note that this is not the 'get' inverse of setDrawableOpacity, since stealthing can also affect the effective opacity!
- inline Real getEffectiveOpacity() const { return m_explicitOpacity * m_effectiveStealthOpacity; } ///< get alpha/opacity value used to override defaults when drawing.
+ Real getEffectiveOpacity() const; ///< get alpha/opacity value used to override defaults when drawing.
void setEffectiveOpacity( Real pulseFactor, Real explicitOpacity = -1.0f );
// this is for the add'l pass fx which operates completely independently of the stealth opacity effects. Draw() does the fading every frame.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
index eb48dae4c..19af0c659 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h
@@ -257,6 +257,9 @@ inline Drawable* GameClient::findDrawableByID( const DrawableID id )
// the singleton
+///< does the shroud hide this drawable from the local player?
+extern Bool GameClient_hiddenByShroud( ObjectShroudStatus status, Bool ownPlacementSilhouette );
+
extern GameClient *TheGameClient;
#endif // _GAME_INTERFACE_H_
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
index ccd34d6b7..45b91ef43 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
@@ -160,6 +160,16 @@ enum CrushSquishTestType
* Object definition. Objects are manipulated via TheGameLogic singleton.
* @todo Create an ObjectInterface class.
*/
+//-------------------------------------------------------------------------------------------------
+/** Has a structure been planned but not started? It is on the map, at zero percent, waiting for a
+ * builder to walk over to it. */
+//-------------------------------------------------------------------------------------------------
+extern Bool Object_isAwaitingBuilder( Bool underConstruction, Real constructionPercent );
+
+///< how far a structure clears shroud, given where it is in its construction
+extern Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real constructionPercent,
+ Real boundingCircleRadius );
+
class Object : public Thing, public Snapshot
{
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
index 35aa2dccd..6d3295347 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
@@ -113,18 +113,36 @@ static Bool isObjectShroudedForAction ( const Object *source, const Object *targ
if( source && target && source->getControllingPlayer() )
{
- if( source->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN
- && commandSource != CMD_FROM_SCRIPT
- && target->getShroudedStatus( source->getControllingPlayer()->getPlayerIndex() ) >= OBJECTSHROUD_FOGGED
- )
- {
- return TRUE;
- }
+ //
+ // ...with one exception: a structure the asking player has planned but not started clears no
+ // shroud of its own (Object_shroudClearingRange), so it sits in fog on its owner's screen by
+ // design. It is still their own plan, drawn for them and selectable, and the fog must not be
+ // what stops them sending a builder back to it.
+ //
+ Bool ownPlacementSilhouette = source->getControllingPlayer() == target->getControllingPlayer()
+ && Object_isAwaitingBuilder( target->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ),
+ target->getConstructionPercent() );
+
+ return ActionManager_shroudHidesTarget( source->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN,
+ commandSource == CMD_FROM_SCRIPT,
+ target->getShroudedStatus( source->getControllingPlayer()->getPlayerIndex() ) >= OBJECTSHROUD_FOGGED,
+ ownPlacementSilhouette );
}
return FALSE;
}
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+Bool ActionManager_shroudHidesTarget( Bool humanSource, Bool fromScript, Bool targetFoggedOrWorse,
+ Bool ownPlacementSilhouette )
+{
+ if( ownPlacementSilhouette )
+ return FALSE;
+
+ return humanSource && !fromScript && targetFoggedOrWorse;
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
index 505aac325..16c51f055 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
@@ -911,6 +911,16 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos
return LBC_OK;
}
+//-------------------------------------------------------------------------------------------------
+/** Fog is fair game: ground you have already scouted stays buildable after your units leave it, so
+ * a base can be planned out into the dark half of the map and the builder sent to walk there.
+ * Shroud - terrain nobody of yours has ever laid eyes on - is still off limits. */
+//-------------------------------------------------------------------------------------------------
+Bool BuildAssistant_shroudBlocksBuilding( CellShroudStatus status )
+{
+ return status == CELLSHROUD_SHROUDED;
+}
+
//-------------------------------------------------------------------------------------------------
/** Query if we can build at this location. Note that 'build' may be null and is NOT required
* to be valid to know if a location is legal to build at. 'builderObject' is used
@@ -942,7 +952,7 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
if (builderObject && builderObject->getControllingPlayer())
playerIndex = builderObject->getControllingPlayer()->getPlayerIndex();
DEBUG_ASSERTCRASH(playerIndex >= 0, ("isLocationLegalToBuild() needs a builderObject with a team to check for shroud"));
- if( ThePartitionManager->getShroudStatusForPlayer(playerIndex, x, y) != CELLSHROUD_CLEAR )
+ if( BuildAssistant_shroudBlocksBuilding( ThePartitionManager->getShroudStatusForPlayer(playerIndex, x, y) ) )
{
return LBC_SHROUD;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index dbcb1cb5a..116baacc1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -346,6 +346,37 @@ void Drawable::saturateRGB(RGBColor& color, Real factor)
#define CLAMP_ICON_ZOOM_FACTOR(n) (n)//nothing
+//-------------------------------------------------------------------------------------------------
+/** Opacity a drawable is drawn at. Stealth scales whatever the drawable asked for, and a structure
+ * that has been placed but not started - its builder is still walking over - is drawn as the same
+ * translucent silhouette the placement preview used, so a plan on the map never reads as a
+ * building that is already standing there. */
+//-------------------------------------------------------------------------------------------------
+Real Drawable_effectiveOpacity( Real explicitOpacity, Real stealthOpacity, Bool awaitingBuilder )
+{
+ Real opacity = explicitOpacity * stealthOpacity;
+
+ if( awaitingBuilder )
+ opacity *= PLACEMENT_SILHOUETTE_OPACITY;
+
+ return opacity;
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The silhouette is the finished building, not a foundation: the construction model conditions are
+ * left alone until the builder arrives, so what stands on the map is the shape that was under the
+ * cursor. A drawable with no object behind it is the placement preview itself, which carries the
+ * same opacity explicitly. */
+//-------------------------------------------------------------------------------------------------
+Real Drawable::getEffectiveOpacity() const
+{
+ const Object *obj = getObject();
+ Bool awaitingBuilder = obj && Object_isAwaitingBuilder( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ),
+ obj->getConstructionPercent() );
+
+ return Drawable_effectiveOpacity( m_explicitOpacity, m_effectiveStealthOpacity, awaitingBuilder );
+}
+
//-------------------------------------------------------------------------------------------------
/** Drawables are lightweight, graphical entities which live on the GameClient,
* and are usually bound to GameLogic objects. In other words, they are the
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
index 02ec0c69c..66d33780b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp
@@ -94,6 +94,20 @@
/// The GameClient singleton instance
GameClient *TheGameClient = NULL;
+//-------------------------------------------------------------------------------------------------
+/** Fog and shroud hide a drawable from the local player, with one exception: a structure the player
+ * has just planned. It clears no shroud of its own, so a base planned out into fog would otherwise
+ * disappear the moment it was placed - it stays drawn, as the silhouette of the finished building,
+ * until the builder walks over and the work starts for real. */
+//-------------------------------------------------------------------------------------------------
+Bool GameClient_hiddenByShroud( ObjectShroudStatus status, Bool ownPlacementSilhouette )
+{
+ if( ownPlacementSilhouette )
+ return FALSE;
+
+ return status >= OBJECTSHROUD_FOGGED;
+}
+
//-------------------------------------------------------------------------------------------------
GameClient::GameClient()
{
@@ -715,7 +729,17 @@ void GameClient::update( void )
ss = OBJECTSHROUD_CLEAR;
}
}
- draw->setFullyObscuredByShroud(ss >= OBJECTSHROUD_FOGGED);
+ //
+ // a structure the local player has planned but not started is drawn wherever it was
+ // put, fog or no fog: it reveals nothing (Object_shroudClearingRange gives it no
+ // sight at all), so without this it would be invisible to the player who placed it
+ // and there would be nothing to click on to cancel it.
+ //
+ Bool ownPlacementSilhouette = object->isLocallyControlled()
+ && Object_isAwaitingBuilder( object->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ),
+ object->getConstructionPercent() );
+
+ draw->setFullyObscuredByShroud( GameClient_hiddenByShroud( ss, ownPlacementSilhouette ) );
}
}
draw->updateDrawable();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index cdc4f41a6..fa07e3506 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -101,7 +101,7 @@
// ------------------------------------------------------------------------------------------------
-static const Real placementOpacity = 0.45f;
+static const Real placementOpacity = PLACEMENT_SILHOUETTE_OPACITY;
static const RGBColor illegalBuildColor = { 1.0, 0.0, 0.0 };
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 62a5bc86d..b0894d245 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -114,6 +114,17 @@ static Bool isForceAttackTargeting( void )
TheInGameUI->isInAttackMoveToMode() );
}
+//-------------------------------------------------------------------------------------------------
+/**
+ * Does the stop key mean "cancel this building"?
+ * Only for a single structure of your own that is still under construction - a mixed selection, an
+ * enemy structure or anything already finished still means stop.
+ */
+Bool Command_stopMeansCancelConstruction( Int selectionCount, Bool locallyControlled, Bool underConstruction )
+{
+ return selectionCount == 1 && locallyControlled && underConstruction;
+}
+
#if defined(_DEBUG) || defined(_INTERNAL)
/*non-static*/ Real TheSkateDistOverride = 0.0f;
@@ -3036,11 +3047,28 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
//-----------------------------------------------------------------------------------------
case GameMessage::MSG_META_STOP:
- // This message always works on the currently selected team
- TheMessageStream->appendMessage(GameMessage::MSG_DO_STOP);
+ {
+ //
+ // stop one structure of your own that is still going up and there is nothing to stop yet -
+ // what you mean is call the whole thing off, which is what the command bar's cancel button
+ // on that same structure does, refund and all.
+ //
+ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
+ Int selectionCount = selected ? selected->size() : 0;
+ const Drawable *onlyDrawable = ( selectionCount == 1 ) ? selected->front() : NULL;
+ const Object *onlyObject = onlyDrawable ? onlyDrawable->getObject() : NULL;
+
+ if( Command_stopMeansCancelConstruction( selectionCount,
+ onlyObject && onlyObject->isLocallyControlled(),
+ onlyObject && onlyObject->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) ) )
+ TheMessageStream->appendMessage(GameMessage::MSG_DOZER_CANCEL_CONSTRUCT);
+ else
+ // This message always works on the currently selected team
+ TheMessageStream->appendMessage(GameMessage::MSG_DO_STOP);
disp = DESTROY_MESSAGE;
break;
+ }
//-----------------------------------------------------------------------------------------
case GameMessage::MSG_META_CREATE_FORMATION:
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 9a18acf80..a3288eba3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -5214,16 +5214,37 @@ void Object::setVisionRange( Real newVisionRange )
}
//-------------------------------------------------------------------------------------------------
-Real Object::getShroudClearingRange() const
+/** A structure that has only been planned - it stands on the map at zero percent and its builder is
+ * still walking over - is not there yet as far as sight is concerned, so it opens no shroud: a base
+ * can be laid out into fog without the plan itself scouting the ground it sits on. Once the
+ * builder arrives and the first percent goes in, EA's rule takes over and the structure sees
+ * itself and no further. */
+//-------------------------------------------------------------------------------------------------
+Bool Object_isAwaitingBuilder( Bool underConstruction, Real constructionPercent )
{
- Real shroudClearingRange=m_shroudClearingRange;
+ return underConstruction && constructionPercent <= 0.0f;
+}
- if( getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
- {
- //structures under construction have limited vision range. For now, base it
- //on the geometry extents so the structure can only see itself.
- shroudClearingRange = getGeometryInfo().getBoundingCircleRadius();
- }
+//-------------------------------------------------------------------------------------------------
+Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real constructionPercent,
+ Real boundingCircleRadius )
+{
+ if( Object_isAwaitingBuilder( underConstruction, constructionPercent ) )
+ return 0.0f;
+
+ if( underConstruction )
+ return boundingCircleRadius;
+
+ return ownRange;
+}
+
+//-------------------------------------------------------------------------------------------------
+Real Object::getShroudClearingRange() const
+{
+ Real shroudClearingRange = Object_shroudClearingRange( m_shroudClearingRange,
+ getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ),
+ m_constructionPercent,
+ getGeometryInfo().getBoundingCircleRadius() );
#if defined(_DEBUG) || defined(_INTERNAL)
if (TheGlobalData->m_debugVisibility)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
index a58141192..662a4dd9e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
@@ -1806,10 +1806,15 @@ Object *DozerAIUpdate::construct( const ThingTemplate *what,
BodyModuleInterface *body = obj->getBodyModule();
body->internalChangeHealth( -body->getHealth() + 1.0f );
- // set the model action state to awaiting construction
- obj->clearAndSetModelConditionFlags(
- MAKE_MODELCONDITION_MASK2(MODELCONDITION_PARTIALLY_CONSTRUCTED, MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED),
- MAKE_MODELCONDITION_MASK(MODELCONDITION_AWAITING_CONSTRUCTION)
+ //
+ // leave every construction model condition off. The art's AWAITING_CONSTRUCTION state is a
+ // foundation, and a plan standing on the map has to show the finished building - it is drawn as a
+ // translucent silhouette of it instead (Drawable::getEffectiveOpacity). The two "work under way"
+ // states go on when the builder arrives, in DozerActionMoveToState::update.
+ //
+ obj->clearModelConditionFlags(
+ MAKE_MODELCONDITION_MASK3(MODELCONDITION_AWAITING_CONSTRUCTION, MODELCONDITION_PARTIALLY_CONSTRUCTED,
+ MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED)
);
// we have a construction pending - unless a human player's dozer is already building
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
index 20c602b83..549c43f83 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp
@@ -447,10 +447,15 @@ Object *WorkerAIUpdate::construct( const ThingTemplate *what,
BodyModuleInterface *body = obj->getBodyModule();
body->internalChangeHealth( -body->getHealth() + 1.0f );
- // set the model action state to awaiting construction
- obj->clearAndSetModelConditionFlags(
- MAKE_MODELCONDITION_MASK2(MODELCONDITION_PARTIALLY_CONSTRUCTED, MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED),
- MAKE_MODELCONDITION_MASK(MODELCONDITION_AWAITING_CONSTRUCTION)
+ //
+ // leave every construction model condition off. The art's AWAITING_CONSTRUCTION state is a
+ // foundation, and a plan standing on the map has to show the finished building - it is drawn as a
+ // translucent silhouette of it instead (Drawable::getEffectiveOpacity). The two "work under way"
+ // states go on when the builder arrives, in DozerActionMoveToState::update.
+ //
+ obj->clearModelConditionFlags(
+ MAKE_MODELCONDITION_MASK3(MODELCONDITION_AWAITING_CONSTRUCTION, MODELCONDITION_PARTIALLY_CONSTRUCTED,
+ MODELCONDITION_ACTIVELY_BEING_CONSTRUCTED)
);
// we have a construction pending - unless a human player's worker is already building
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index c8a7a352f..b706aae18 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -75,6 +75,11 @@
#include "GameLogic/Module/QueueProductionExitUpdate.h"
#include "GameLogic/Module/SupplyCenterProductionExitUpdate.h"
#include "WWMath/matrix3d.h"
+#include "GameClient/Drawable.h"
+#include "Common/BuildAssistant.h"
+#include "GameLogic/Object.h"
+#include "GameClient/CommandXlat.h"
+#include "Common/ActionManager.h"
#include <stdio.h>
#include <string.h>
@@ -4697,3 +4702,120 @@ TEST(a_rotate_key_press_moves_the_camera_exactly_one_eighth)
CHECK_NEAR( View_stepAngleByEighths( -0.1f, -1 ), -step, 0.0001f );
CHECK_NEAR( View_stepAngleByEighths( 0.0f, 0 ), 0.0f, 0.0001f );
}
+
+/** Placing a structure buys a plan, not a building. The object does go down at once - it is paid
+ for, it holds the ground, and it can be clicked and cancelled - but nothing is built until a
+ builder walks over to it, so it is drawn as the same translucent silhouette that was following
+ the cursor a moment earlier. A plan on the map must never read as a building already standing
+ there. */
+TEST(a_structure_waiting_for_its_builder_is_drawn_as_a_silhouette)
+{
+ CHECK( Object_isAwaitingBuilder( TRUE, 0.0f ) == TRUE );
+
+ CHECK_NEAR( Drawable_effectiveOpacity( 1.0f, 1.0f, TRUE ), PLACEMENT_SILHOUETTE_OPACITY, 0.0001f );
+
+ // what followed the cursor and what landed on the map are drawn at the same opacity
+ CHECK_NEAR( Drawable_effectiveOpacity( PLACEMENT_SILHOUETTE_OPACITY, 1.0f, FALSE ),
+ Drawable_effectiveOpacity( 1.0f, 1.0f, TRUE ), 0.0001f );
+
+ // and it is see-through, which is the whole reason the renderer puts it in the translucent pass
+ CHECK( Drawable_effectiveOpacity( 1.0f, 1.0f, TRUE ) != 1.0f );
+}
+
+/** The first percent of work is what ends the plan, so the moment the builder arrives and starts
+ the structure turns solid and stays solid for the rest of its life. A finished building carries
+ CONSTRUCTION_COMPLETE (-1) and must not be mistaken for one sitting at zero. */
+TEST(a_structure_the_builder_has_reached_is_drawn_solid)
+{
+ CHECK( Object_isAwaitingBuilder( TRUE, 0.1f ) == FALSE );
+ CHECK( Object_isAwaitingBuilder( TRUE, 99.9f ) == FALSE );
+ CHECK( Object_isAwaitingBuilder( FALSE, 0.0f ) == FALSE );
+ CHECK( Object_isAwaitingBuilder( FALSE, CONSTRUCTION_COMPLETE ) == FALSE );
+
+ CHECK_NEAR( Drawable_effectiveOpacity( 1.0f, 1.0f, FALSE ), 1.0f, 0.0001f );
+}
+
+/** The silhouette scales whatever opacity the drawable already asked for instead of replacing it,
+ so a stealthed or half-faded drawable is not dragged back up to 45% by being a plan, and one
+ that has been faded all the way out stays out. */
+TEST(the_placement_silhouette_scales_the_opacity_it_is_given)
+{
+ CHECK_NEAR( Drawable_effectiveOpacity( 0.5f, 1.0f, TRUE ), 0.5f * PLACEMENT_SILHOUETTE_OPACITY, 0.0001f );
+ CHECK_NEAR( Drawable_effectiveOpacity( 1.0f, 0.5f, TRUE ), 0.5f * PLACEMENT_SILHOUETTE_OPACITY, 0.0001f );
+ CHECK_NEAR( Drawable_effectiveOpacity( 0.0f, 1.0f, TRUE ), 0.0f, 0.0001f );
+}
+
+/** Ground you have already scouted stays buildable after your units leave it, so a base can be
+ planned out into the fog and the builder sent to walk there. Shroud - terrain nobody of yours
+ has ever laid eyes on - is still off limits, which is what stops the map being read through a
+ placement cursor. */
+TEST(a_base_can_be_planned_into_fog_but_not_into_shroud)
+{
+ CHECK( BuildAssistant_shroudBlocksBuilding( CELLSHROUD_CLEAR ) == FALSE );
+ CHECK( BuildAssistant_shroudBlocksBuilding( CELLSHROUD_FOGGED ) == FALSE );
+ CHECK( BuildAssistant_shroudBlocksBuilding( CELLSHROUD_SHROUDED ) == TRUE );
+}
+
+/** A plan is not a scout. A structure that has been placed but not started opens no shroud at all,
+ so drawing a base out into the fog cannot be used to see what is standing there. Once the
+ builder arrives EA's own rule takes over - the structure sees itself and no further - and a
+ finished building goes back to the sight its template gives it. */
+TEST(a_planned_structure_opens_no_shroud_until_the_work_starts)
+{
+ const Real templateRange = 300.0f;
+ const Real boundingRadius = 40.0f;
+
+ CHECK_NEAR( Object_shroudClearingRange( templateRange, TRUE, 0.0f, boundingRadius ), 0.0f, 0.0001f );
+ CHECK_NEAR( Object_shroudClearingRange( templateRange, TRUE, 0.1f, boundingRadius ), boundingRadius, 0.0001f );
+ CHECK_NEAR( Object_shroudClearingRange( templateRange, TRUE, 99.9f, boundingRadius ), boundingRadius, 0.0001f );
+ CHECK_NEAR( Object_shroudClearingRange( templateRange, FALSE, CONSTRUCTION_COMPLETE, boundingRadius ),
+ templateRange, 0.0001f );
+
+ // a structure that clears no shroud at all is not the same as one with no vision by template
+ CHECK_NEAR( Object_shroudClearingRange( 0.0f, FALSE, CONSTRUCTION_COMPLETE, boundingRadius ), 0.0f, 0.0001f );
+}
+
+/** Since the plan reveals nothing, the fog it was placed in would swallow it - and there would be
+ nothing left on screen to click on and cancel. Your own plan is drawn through the fog; anything
+ else fogged, including an enemy's, is still hidden. */
+TEST(your_own_plan_is_drawn_through_the_fog_that_hides_everything_else)
+{
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_FOGGED, TRUE ) == FALSE );
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_SHROUDED, TRUE ) == FALSE );
+
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_FOGGED, FALSE ) == TRUE );
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_SHROUDED, FALSE ) == TRUE );
+
+ // nothing changes for what the player can see anyway
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_CLEAR, FALSE ) == FALSE );
+ CHECK( GameClient_hiddenByShroud( OBJECTSHROUD_PARTIAL_CLEAR, FALSE ) == FALSE );
+}
+
+/** There is nothing to stop about a building that is still going up, so the stop key calls it off
+ instead - the same cancel, refund and all, that the command bar button on that structure does.
+ One structure of your own only: a mixed selection or anything already finished still means
+ stop. */
+TEST(the_stop_key_cancels_a_building_that_is_still_going_up)
+{
+ CHECK( Command_stopMeansCancelConstruction( 1, TRUE, TRUE ) == TRUE );
+
+ CHECK( Command_stopMeansCancelConstruction( 1, TRUE, FALSE ) == FALSE ); // finished building
+ CHECK( Command_stopMeansCancelConstruction( 1, FALSE, TRUE ) == FALSE ); // not yours
+ CHECK( Command_stopMeansCancelConstruction( 2, TRUE, TRUE ) == FALSE ); // more than one thing
+ CHECK( Command_stopMeansCancelConstruction( 0, FALSE, FALSE ) == FALSE ); // nothing selected
+}
+
+/** The plan sits in fog on its owner's screen on purpose, and the fog gate on orders would then
+ refuse every click on it: no build cursor, no resume, nothing but selection. A player's own
+ plan is never hidden from that player's own builders. Everything else the gate does is
+ untouched - an enemy in fog is still out of reach, the AI and scripts still ignore the gate
+ entirely. */
+TEST(the_fog_never_hides_your_own_plan_from_your_own_builder)
+{
+ CHECK( ActionManager_shroudHidesTarget( TRUE, FALSE, TRUE, TRUE ) == FALSE ); // your own plan
+ CHECK( ActionManager_shroudHidesTarget( TRUE, FALSE, TRUE, FALSE ) == TRUE ); // anything else fogged
+
+ CHECK( ActionManager_shroudHidesTarget( TRUE, TRUE, TRUE, FALSE ) == FALSE ); // from a script
+ CHECK( ActionManager_shroudHidesTarget( FALSE, FALSE, TRUE, FALSE ) == FALSE ); // asked by the AI
+ CHECK( ActionManager_shroudHidesTarget( TRUE, FALSE, FALSE, FALSE ) == FALSE ); // in plain sight
+}