Skip to content

Commit a42cd64

Browse files
authored
chore(controlbar): Add asserts to verify special power templates and buttons (TheSuperHackers#2657)
1 parent c13e363 commit a42cd64

6 files changed

Lines changed: 44 additions & 4 deletions

File tree

Generals/Code/GameEngine/Source/Common/INI/INICommandButton.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,24 @@ void ControlBar::parseCommandButtonDefinition( INI *ini )
7474
// parse the ini definition
7575
ini->initFromINI( button, button->getFieldParse() );
7676

77+
const SpecialPowerTemplate *spTemplate = button->getSpecialPowerTemplate();
78+
79+
// TheSuperHackers @tweak Make sure Special Power buttons have a Special Power template.
80+
switch (button->getCommandType())
81+
{
82+
case GUI_COMMAND_SPECIAL_POWER:
83+
case GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT:
84+
case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT:
85+
case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT:
86+
{
87+
DEBUG_ASSERTCRASH(spTemplate != nullptr,
88+
("[LINE: %d in '%s'] CommandButton %s is a SPECIAL_POWER but is missing a SpecialPower field",
89+
ini->getLineNum(), ini->getFilename().str(), name.str()));
90+
break;
91+
}
92+
}
7793

7894
//Make sure buttons with special power templates also have the appropriate option set.
79-
const SpecialPowerTemplate *spTemplate = button->getSpecialPowerTemplate();
8095
Bool needsTemplate = BitIsSet( button->getOptions(), NEED_SPECIAL_POWER_SCIENCE );
8196
if( spTemplate && !needsTemplate )
8297
{

Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,9 @@ void ControlBar::populateSpecialPowerShortcut( Player *player)
35023502
}
35033503
}
35043504

3505+
DEBUG_ASSERTCRASH(m_specialPowerShortcutButtons[ currentButton ] != nullptr, ("m_specialPowerShortcutButtons[%d] is null", currentButton));
3506+
DEBUG_ASSERTCRASH(m_specialPowerShortcutButtonParents[ currentButton ] != nullptr, ("m_specialPowerShortcutButtonParents[%d] is null", currentButton));
3507+
35053508
// make sure the window is not hidden
35063509
m_specialPowerShortcutButtons[ currentButton ]->winHide( FALSE );
35073510
m_specialPowerShortcutButtonParents[ currentButton ]->winHide( FALSE );

Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct SelectObjectsInfo
6868

6969
//-------------------------------------------------------------------------------------------------
7070

71-
void selectObjectOfType( Object* obj, void* selectObjectsInfo )
71+
static void selectObjectOfType( Object* obj, void* selectObjectsInfo )
7272
{
7373
SelectObjectsInfo *soInfo = (SelectObjectsInfo*)selectObjectsInfo;
7474
if( !obj || !soInfo )
@@ -277,6 +277,8 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
277277
{
278278
//Determine the object that would construct it.
279279
const SpecialPowerTemplate *spTemplate = commandButton->getSpecialPowerTemplate();
280+
DEBUG_ASSERTCRASH(spTemplate != nullptr, ("Special Power Button is missing Special Power template"));
281+
280282
SpecialPowerType spType = spTemplate->getSpecialPowerType();
281283
Object* obj = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( spType );
282284
if( !obj )

GeneralsMD/Code/GameEngine/Source/Common/INI/INICommandButton.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,24 @@ void ControlBar::parseCommandButtonDefinition( INI *ini )
7474
// parse the ini definition
7575
ini->initFromINI( button, button->getFieldParse() );
7676

77+
const SpecialPowerTemplate *spTemplate = button->getSpecialPowerTemplate();
78+
79+
// TheSuperHackers @tweak Make sure Special Power buttons have a Special Power template.
80+
switch (button->getCommandType())
81+
{
82+
case GUI_COMMAND_SPECIAL_POWER:
83+
case GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT:
84+
case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT:
85+
case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT:
86+
{
87+
DEBUG_ASSERTCRASH(spTemplate != nullptr,
88+
("[LINE: %d in '%s'] CommandButton %s is a SPECIAL_POWER but is missing a SpecialPower field",
89+
ini->getLineNum(), ini->getFilename().str(), name.str()));
90+
break;
91+
}
92+
}
7793

7894
//Make sure buttons with special power templates also have the appropriate option set.
79-
const SpecialPowerTemplate *spTemplate = button->getSpecialPowerTemplate();
8095
Bool needsTemplate = BitIsSet( button->getOptions(), NEED_SPECIAL_POWER_SCIENCE );
8196
if( spTemplate && !needsTemplate )
8297
{

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,9 @@ void ControlBar::populateSpecialPowerShortcut( Player *player)
35023502
}
35033503
}
35043504

3505+
DEBUG_ASSERTCRASH(m_specialPowerShortcutButtons[ currentButton ] != nullptr, ("m_specialPowerShortcutButtons[%d] is null", currentButton));
3506+
DEBUG_ASSERTCRASH(m_specialPowerShortcutButtonParents[ currentButton ] != nullptr, ("m_specialPowerShortcutButtonParents[%d] is null", currentButton));
3507+
35053508
// make sure the window is not hidden
35063509
m_specialPowerShortcutButtons[ currentButton ]->winHide( FALSE );
35073510
m_specialPowerShortcutButtonParents[ currentButton ]->winHide( FALSE );

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct SelectObjectsInfo
6868

6969
//-------------------------------------------------------------------------------------------------
7070

71-
void selectObjectOfType( Object* obj, void* selectObjectsInfo )
71+
static void selectObjectOfType( Object* obj, void* selectObjectsInfo )
7272
{
7373
SelectObjectsInfo *soInfo = (SelectObjectsInfo*)selectObjectsInfo;
7474
if( !obj || !soInfo )
@@ -277,6 +277,8 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
277277
{
278278
//Determine the object that would construct it.
279279
const SpecialPowerTemplate *spTemplate = commandButton->getSpecialPowerTemplate();
280+
DEBUG_ASSERTCRASH(spTemplate != nullptr, ("Special Power Button is missing Special Power template"));
281+
280282
SpecialPowerType spType = spTemplate->getSpecialPowerType();
281283
Object* obj = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( spType );
282284
if( !obj )

0 commit comments

Comments
 (0)