Skip to content

Commit c13e363

Browse files
authored
unify(controlbar): Merge ControlBar and related code from Zero Hour (TheSuperHackers#2655)
1 parent dffdab9 commit c13e363

20 files changed

Lines changed: 1247 additions & 220 deletions

File tree

Generals/Code/GameEngine/Include/Common/DisabledTypes.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
3333
#include "Lib/BaseType.h"
3434
#include "Common/BitFlags.h"
35+
#include "Common/BitFlagsIO.h"
3536

3637
//-------------------------------------------------------------------------------------------------
3738
/** Kind of flags for determining groups of things that belong together
@@ -48,11 +49,16 @@ enum DisabledType CPP_11(: Int)
4849
DISABLED_UNDERPOWERED,//Separate from ScriptUnderpowered, the owning player has insufficient power. Energy status controls this
4950
DISABLED_FREEFALL, //This unit has been disabled via being in free fall
5051

52+
DISABLED_AWESTRUCK,
53+
DISABLED_BRAINWASHED,
54+
DISABLED_SUBDUED, ///< Temporarily shut down by Subdual damage
5155
//These ones are specifically for scripts to enable/reenable!
5256
DISABLED_SCRIPT_DISABLED,
5357
DISABLED_SCRIPT_UNDERPOWERED,
5458

5559
DISABLED_COUNT,
60+
61+
DISABLED_ANY = 65535 ///< Do not use this value for setting disabled types (read-only)
5662
};
5763

5864
typedef BitFlags<DISABLED_COUNT> DisabledMaskType;
@@ -102,6 +108,5 @@ inline void FLIP_DISABLEDMASK(DisabledMaskType& m)
102108

103109

104110
// defined in Common/System/DisabledTypes.cpp
105-
extern const char *TheDisabledNames[];
106111
extern DisabledMaskType DISABLEDMASK_NONE; // inits to all zeroes
107112
extern DisabledMaskType DISABLEDMASK_ALL; // inits to all bits set.

Generals/Code/GameEngine/Include/Common/Player.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,22 @@ class Player : public Snapshot
276276
if he has multiple, return one arbitrarily. */
277277
Object* findNaturalCommandCenter();
278278

279+
Object* findAnyExistingObjectWithThingTemplate( const ThingTemplate *thing );
280+
281+
// Finds a short-cut firing special power of specified type returning the first ready power or
282+
// the most ready if none ready.
283+
Object* findMostReadyShortcutSpecialPowerOfType( SpecialPowerType spType );
284+
285+
//Find specified thing template's most ready weapon.
286+
Object* findMostReadyShortcutWeaponForThing( const ThingTemplate *thing, UnsignedInt &mostReadyPercentage );
287+
Object* findMostReadyShortcutSpecialPowerForThing( const ThingTemplate *thing, UnsignedInt &mostReadyPercentage );
288+
289+
// Finds a short-cut firing special power of any type arbitrarily.
290+
Bool hasAnyShortcutSpecialPower();
291+
292+
// Counts available shortcut special power of specified type that can fire now.
293+
Int countReadyShortcutSpecialPowersOfType( SpecialPowerType spType );
294+
279295
/// return t if the player has the given science, either intrinsically, via specialization, or via capture.
280296
Bool hasScience(ScienceType t) const;
281297
Bool isScienceDisabled( ScienceType t ) const; ///< Can't purchase this science because of script reasons.

Generals/Code/GameEngine/Include/GameClient/ControlBar.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ControlBarSchemeManager;
5656
class UpgradeTemplate;
5757
class ControlBarResizer;
5858
class GameWindowTransitionsHandler;
59+
class DisplayString;
5960

6061
enum ProductionID CPP_11(: Int);
6162

@@ -96,6 +97,8 @@ enum CommandOption CPP_11(: Int)
9697
SCRIPT_ONLY = 0x00080000, // Only a script can use this command (not by users)
9798
IGNORES_UNDERPOWERED = 0x00100000, // this button isn't disabled if its object is merely underpowered
9899
USES_MINE_CLEARING_WEAPONSET= 0x00200000, // uses the special mine-clearing weaponset, even if not current
100+
CAN_USE_WAYPOINTS = 0x00400000, // button has option to use a waypoint path
101+
MUST_BE_STOPPED = 0x00800000, // Unit must be stopped in order to be able to use button.
99102
};
100103

101104
#ifdef DEFINE_COMMAND_OPTION_NAMES
@@ -127,6 +130,8 @@ static const char *const TheCommandOptionNames[] =
127130
"SCRIPT_ONLY",
128131
"IGNORES_UNDERPOWERED",
129132
"USES_MINE_CLEARING_WEAPONSET",
133+
"CAN_USE_WAYPOINTS",
134+
"MUST_BE_STOPPED",
130135

131136
nullptr
132137
};
@@ -181,25 +186,33 @@ enum GUICommandType CPP_11(: Int)
181186
GUI_COMMAND_FIRE_WEAPON, ///< fire a weapon
182187
GUI_COMMAND_SPECIAL_POWER, ///< do a special power
183188
GUI_COMMAND_PURCHASE_SCIENCE, ///< purchase science
184-
GUI_COMMAND_HACK_INTERNET, ///< Hey author, write me!
189+
GUI_COMMAND_HACK_INTERNET, ///< gain income from the ether (by hacking the internet)
185190
GUI_COMMAND_TOGGLE_OVERCHARGE, ///< Overcharge command for power plants
186191
#ifdef ALLOW_SURRENDER
187192
GUI_COMMAND_POW_RETURN_TO_PRISON, ///< POW Truck, return to prison
188193
#endif
189194
GUI_COMMAND_COMBATDROP, ///< rappel contents to ground or bldg
190195
GUI_COMMAND_SWITCH_WEAPON, ///< switch weapon use
191196

192-
//Context senstive command modes
197+
//Context sensitive command modes
193198
GUICOMMANDMODE_HIJACK_VEHICLE,
194199
GUICOMMANDMODE_CONVERT_TO_CARBOMB,
200+
GUICOMMANDMODE_SABOTAGE_BUILDING,
195201
#ifdef ALLOW_SURRENDER
196202
GUICOMMANDMODE_PICK_UP_PRISONER, ///< POW Truck assigned to pick up a specific prisoner
197203
#endif
198204

199205
// context-insensitive command mode(s)
200206
GUICOMMANDMODE_PLACE_BEACON,
201207

202-
GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER, ///< do a special power from localPlayer's command center, regardless of selection
208+
GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT, ///< do a special power from localPlayer's command center, regardless of selection
209+
#if RTS_GENERALS
210+
GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER = GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT, ///< Legacy name
211+
#endif
212+
GUI_COMMAND_SPECIAL_POWER_CONSTRUCT, ///< do a special power using the construct building interface
213+
GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT, ///< do a shortcut special power using the construct building interface
214+
215+
GUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE,
203216

204217
// add more commands here, don't forget to update the string command list below too ...
205218

@@ -241,11 +254,19 @@ static const char *const TheGuiCommandNames[] =
241254
"SWITCH_WEAPON",
242255
"HIJACK_VEHICLE",
243256
"CONVERT_TO_CARBOMB",
257+
"SABOTAGE_BUILDING",
244258
#ifdef ALLOW_SURRENDER
245259
"PICK_UP_PRISONER",
246260
#endif
247261
"PLACE_BEACON",
248-
"SPECIAL_POWER_FROM_COMMAND_CENTER",
262+
#if RTS_GENERALS
263+
"SPECIAL_POWER_FROM_COMMAND_CENTER", ///< Legacy name
264+
#else
265+
"SPECIAL_POWER_FROM_SHORTCUT",
266+
#endif
267+
"SPECIAL_POWER_CONSTRUCT",
268+
"SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT",
269+
"SELECT_ALL_UNITS_OF_TYPE",
249270

250271
nullptr
251272
};
@@ -386,16 +407,16 @@ class CommandButton : public Overridable
386407
/** Command sets are collections of configurable command buttons. They are used in the
387408
* command context sensitive window in the battle user interface */
388409
//-------------------------------------------------------------------------------------------------
389-
enum { MAX_COMMANDS_PER_SET = 12 }; // user interface max button limit for commands
410+
enum { MAX_COMMANDS_PER_SET = 18 }; // user interface max is 14 (but internally it's 18 for script only buttons!)
390411
enum { MAX_RIGHT_HUD_UPGRADE_CAMEOS = 5};
391412
enum {
392-
MAX_PURCHASE_SCIENCE_RANK_1 = 3,
393-
MAX_PURCHASE_SCIENCE_RANK_3 = 12,
394-
MAX_PURCHASE_SCIENCE_RANK_8 = 1,
413+
MAX_PURCHASE_SCIENCE_RANK_1 = 4,
414+
MAX_PURCHASE_SCIENCE_RANK_3 = 15,
415+
MAX_PURCHASE_SCIENCE_RANK_8 = 4,
395416
};
396417
enum { MAX_STRUCTURE_INVENTORY_BUTTONS = 10 }; // there are this many physical buttons in "inventory" windows for structures
397418
enum { MAX_BUILD_QUEUE_BUTTONS = 9 };// physical button count for the build queue
398-
enum { MAX_SPECIAL_POWER_SHORTCUTS = 5};
419+
enum { MAX_SPECIAL_POWER_SHORTCUTS = 11};
399420
class CommandSet : public Overridable
400421
{
401422

@@ -760,6 +781,11 @@ class ControlBar : public SubsystemInterface
760781
void initSpecialPowershortcutBar( Player *player);
761782

762783
void triggerRadarAttackGlow();
784+
785+
void drawSpecialPowerShortcutMultiplierText();
786+
787+
Bool hasAnyShortcutSelection() const;
788+
763789
protected:
764790
void updateRadarAttackGlow ();
765791

@@ -824,7 +850,7 @@ class ControlBar : public SubsystemInterface
824850
static void populateInvDataCallback( Object *obj, void *userData );
825851

826852
// the following methods are for updating the currently showing context
827-
CommandAvailability getCommandAvailability( const CommandButton *command, Object *obj, GameWindow *win, Bool forceDisabledEvaluation = FALSE ) const;
853+
CommandAvailability getCommandAvailability( const CommandButton *command, Object *obj, GameWindow *win, GameWindow *applyToWin = nullptr, Bool forceDisabledEvaluation = FALSE ) const;
828854
void updateContextMultiSelect();
829855
void updateContextPurchaseScience();
830856
void updateContextCommand();
@@ -893,6 +919,7 @@ class ControlBar : public SubsystemInterface
893919
GameWindow *m_sciencePurchaseWindowsRank8[ MAX_PURCHASE_SCIENCE_RANK_8 ]; ///< command window controls for easy access
894920
GameWindow *m_specialPowerShortcutButtons[ MAX_SPECIAL_POWER_SHORTCUTS ];
895921
GameWindow *m_specialPowerShortcutButtonParents[ MAX_SPECIAL_POWER_SHORTCUTS ];
922+
DisplayString *m_shortcutDisplayStrings[ MAX_SPECIAL_POWER_SHORTCUTS ];
896923
Int m_currentlyUsedSpecialPowersButtons; ///< Value will be <= MAX_SPECIAL_POWER_SHORTCUTS;
897924

898925

Generals/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ class ProductionUpdateInterface
170170

171171
virtual void setHoldDoorOpen(ExitDoorType exitDoor, Bool holdIt) = 0;
172172

173+
//These functions keep track of the special power construction of a new building via a special power instead of standard production interface.
174+
//This was added for the sneak attack building functionality.
175+
virtual const CommandButton* getSpecialPowerConstructionCommandButton() const = 0;
176+
virtual void setSpecialPowerConstructionCommandButton( const CommandButton *commandButton ) = 0;
177+
173178
};
174179

175180
//-------------------------------------------------------------------------------------------------
@@ -224,6 +229,11 @@ class ProductionUpdate : public UpdateModule, public ProductionUpdateInterface,
224229

225230
virtual UpdateSleepTime update() override; ///< the update
226231

232+
//These functions keep track of the special power construction of a new building via a special power instead of standard production interface.
233+
//This was added for the sneak attack building functionality.
234+
virtual const CommandButton* getSpecialPowerConstructionCommandButton() const override { return m_specialPowerConstructionCommandButton; }
235+
virtual void setSpecialPowerConstructionCommandButton( const CommandButton *commandButton ) override { m_specialPowerConstructionCommandButton = commandButton; }
236+
227237
// DieModuleInterface
228238
virtual void onDie( const DamageInfo *damageInfo ) override;
229239

@@ -243,6 +253,7 @@ class ProductionUpdate : public UpdateModule, public ProductionUpdateInterface,
243253
Bool m_holdOpen; ///< if T, don't allow door to close
244254
};
245255

256+
const CommandButton *m_specialPowerConstructionCommandButton; ///< In a mode to construct a specific building via a special power. (NO NEED TO SAVE DATA ON THIS FIELD)
246257
ProductionEntry* m_productionQueue; ///< queue of things we want to build
247258
ProductionEntry* m_productionQueueTail; ///< tail pointer for m_productionQueue
248259
ProductionID m_uniqueID; ///< unique ID counter for producing units

Generals/Code/GameEngine/Include/GameLogic/Module/SpecialPowerModule.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SpecialPowerModuleInterface
6666
virtual void markSpecialPowerTriggered( const Coord3D *location ) = 0;
6767
virtual void startPowerRecharge() = 0;
6868
virtual const AudioEventRTS& getInitiateSound() const = 0;
69+
virtual Bool isScriptOnly() const = 0;
6970
};
7071

7172
//-------------------------------------------------------------------------------------------------
@@ -79,9 +80,10 @@ class SpecialPowerModuleData : public BehaviorModuleData
7980
static void buildFieldParse(MultiIniFieldParse& p);
8081

8182
const SpecialPowerTemplate *m_specialPowerTemplate; ///< pointer to the special power template
82-
Bool m_updateModuleStartsAttack; ///< update module determines when the special power actually starts! If true, update module is required.
83-
Bool m_startsPaused; ///< Paused on creation, someone else will have to unpause (like upgrade module, or script)
84-
AudioEventRTS m_initiateSound;
83+
AudioEventRTS m_initiateSound;
84+
Bool m_updateModuleStartsAttack; ///< update module determines when the special power actually starts! If true, update module is required.
85+
Bool m_startsPaused; ///< Paused on creation, someone else will have to unpause (like upgrade module, or script)
86+
Bool m_scriptedSpecialPowerOnly;
8587
};
8688

8789
//-------------------------------------------------------------------------------------------------
@@ -152,6 +154,8 @@ class SpecialPowerModule : public BehaviorModule,
152154
virtual void startPowerRecharge() override;
153155
virtual const AudioEventRTS& getInitiateSound() const override;
154156

157+
virtual Bool isScriptOnly() const override;
158+
155159
protected:
156160

157161
Bool initiateIntentToDoSpecialPower( const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions );

Generals/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ class Object : public Thing, public Snapshot
455455
Bool hasAnyDamageWeapon() const; //Kris: a should be used for real weapons that directly inflict damage... not deploy, hack, etc.
456456
Bool hasWeaponToDealDamageType(DamageType typeToDeal) const;
457457
Real getLargestWeaponRange() const;
458+
UnsignedInt getMostPercentReadyToFireAnyWeapon() const;
458459

459460
Weapon* getWeaponInWeaponSlot(WeaponSlotType wslot) const { return m_weaponSet.getWeaponInWeaponSlot(wslot); }
460461

@@ -525,6 +526,7 @@ class Object : public Thing, public Snapshot
525526
/// return true if the template has the specified special power flag set
526527
// @todo: inline
527528
Bool hasSpecialPower( SpecialPowerType type ) const;
529+
Bool hasAnySpecialPower() const;
528530

529531
void setWeaponBonusCondition(WeaponBonusConditionType wst) { m_weaponBonusCondition |= (1 << wst); }
530532
void clearWeaponBonusCondition(WeaponBonusConditionType wst) { m_weaponBonusCondition &= ~(1 << wst); }

Generals/Code/GameEngine/Include/GameLogic/WeaponSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class WeaponSet : public Snapshot
211211
WeaponSlotType getCurWeaponSlot() const { return m_curWeapon; }
212212
Weapon* findWaypointFollowingCapableWeapon();
213213
const Weapon* findAmmoPipShowingWeapon() const;
214+
UnsignedInt getMostPercentReadyToFireAnyWeapon() const;
214215

215216
Bool setWeaponLock( WeaponSlotType weaponSlot, WeaponLockType lockType );
216217
void releaseWeaponLock(WeaponLockType lockType);

0 commit comments

Comments
 (0)