Skip to content

Commit a3a1fc4

Browse files
committed
Add Trigger Chance to StickyBombCrateCollide
cleanup
1 parent b33d2ab commit a3a1fc4

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/StickyBombCrateCollide.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ class StickyBombCrateCollideModuleData : public CrateCollideModuleData
5151
Bool m_allowMultiCollide; ///< if we are a crate, allow spawning multiple sticky bombs, or just single use
5252
Bool m_showInfiltrationEvent; ///< show an infiltration map event for the target player
5353
AsciiString m_stickyBombObjectName; ///< the object to create
54+
Real m_triggerChance; ///< chance to create the bomb when triggering the module
5455

5556
StickyBombCrateCollideModuleData()
5657
{
5758
m_needsTarget = FALSE;
5859
m_allowMultiCollide = FALSE;
5960
m_showInfiltrationEvent = FALSE;
6061
m_stickyBombObjectName = AsciiString::TheEmptyString;
62+
m_triggerChance = 1.0;
6163
}
6264

6365
static void buildFieldParse(MultiIniFieldParse& p)
@@ -70,6 +72,7 @@ class StickyBombCrateCollideModuleData : public CrateCollideModuleData
7072
{ "AllowMultiCollide", INI::parseBool, NULL, offsetof(StickyBombCrateCollideModuleData, m_allowMultiCollide) },
7173
{ "ShowInfiltrationEvent", INI::parseBool, NULL, offsetof(StickyBombCrateCollideModuleData, m_showInfiltrationEvent) },
7274
{ "StickyBombObject", INI::parseAsciiString, NULL, offsetof(StickyBombCrateCollideModuleData, m_stickyBombObjectName) },
75+
{ "ChanceToTriggerPercent", INI::parsePercentToReal, NULL, offsetof(StickyBombCrateCollideModuleData, m_triggerChance) },
7376
{ 0, 0, 0, 0 }
7477
};
7578
p.add( dataFieldParse );
@@ -92,7 +95,7 @@ class StickyBombCrateCollide : public CrateCollide
9295
protected:
9396

9497
/// This allows specific vetoes to certain types of crates and their data
95-
virtual Bool isValidToExecute( const Object *other ) const;
98+
// virtual Bool isValidToExecute( const Object *other ) const;
9699

97100
/// This is the game logic execution function that all real CrateCollides will implement
98101
virtual Bool executeCrateBehavior( Object *other );

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Collide/CrateCollide/StickyBombCrateCollide.cpp

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,28 @@
2525
///////////////////////////////////////////////////////////////////////////////////////////////////
2626
//
2727
// FILE: StickyBombCrateCollide.cpp
28-
// Author: Kris Morness, June 2003
29-
// Desc: A crate (actually a saboteur - mobile crate) that resets the timer on the target supply dropzone.
28+
// Author: Andi W - Sept 2025
29+
// Desc: Creates a Sticks Bomb on the object we collide with
3030
//
3131
///////////////////////////////////////////////////////////////////////////////////////////////////
3232

3333

34-
3534
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
3635
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
3736

38-
// #include "Common/GameAudio.h"
39-
// #include "Common/MiscAudio.h"
4037
#include "Common/Player.h"
41-
// #include "Common/PlayerList.h"
4238
#include "Common/Radar.h"
43-
// #include "Common/SpecialPower.h"
4439
#include "Common/ThingFactory.h"
4540
#include "Common/ThingTemplate.h"
4641
#include "Common/Xfer.h"
4742

48-
// #include "GameClient/Drawable.h"
4943
#include "GameClient/Eva.h"
50-
// #include "GameClient/InGameUI.h" // useful for printing quick debug strings when we need to
5144

52-
//#include "GameLogic/ExperienceTracker.h"
5345
#include "GameLogic/Object.h"
54-
//#include "GameLogic/PartitionManager.h"
55-
//#include "GameLogic/ScriptEngine.h"
5646

5747
#include "GameLogic/Module/AIUpdate.h"
58-
//#include "GameLogic/Module/ContainModule.h"
59-
//#include "GameLogic/Module/DozerAIUpdate.h"
60-
//#include "GameLogic/Module/HijackerUpdate.h"
61-
//#include "GameLogic/Module/OCLUpdate.h"
6248
#include "GameLogic/Module/StickyBombCrateCollide.h"
6349
#include "GameLogic/Module/StickyBombUpdate.h"
64-
//#include "GameLogic/Module/SpecialPowerModule.h"
6550

6651

6752

@@ -79,29 +64,29 @@ StickyBombCrateCollide::~StickyBombCrateCollide( void )
7964

8065
//-------------------------------------------------------------------------------------------------
8166
//-------------------------------------------------------------------------------------------------
82-
Bool StickyBombCrateCollide::isValidToExecute( const Object *other ) const
83-
{
84-
if( !CrateCollide::isValidToExecute(other) )
85-
{
86-
if (other != NULL)
87-
DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> target '%s' Not Valid.", other->getTemplate()->getName().str()));
88-
else
89-
DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> collide with ground!"));
90-
//Extend functionality.
91-
return FALSE;
92-
}
93-
94-
// Do we need anything here?
95-
DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> target '%s' Valid!", other->getTemplate()->getName().str()));
96-
return TRUE;
97-
}
67+
//Bool StickyBombCrateCollide::isValidToExecute( const Object *other ) const
68+
//{
69+
// if( !CrateCollide::isValidToExecute(other) )
70+
// {
71+
// if (other != NULL)
72+
// DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> target '%s' Not Valid.", other->getTemplate()->getName().str()));
73+
// else
74+
// DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> collide with ground!"));
75+
// //Extend functionality.
76+
// return FALSE;
77+
// }
78+
//
79+
// // Do we need anything here?
80+
// DEBUG_LOG(("StickyBombCrateCollide::isValidToExecute >>> target '%s' Valid!", other->getTemplate()->getName().str()));
81+
// return TRUE;
82+
//}
9883

9984
//-------------------------------------------------------------------------------------------------
10085
//-------------------------------------------------------------------------------------------------
10186
Bool StickyBombCrateCollide::executeCrateBehavior( Object *other )
10287
{
10388

104-
DEBUG_LOG(("StickyBombCrateCollide::executeCrateBehavior 0"));
89+
//DEBUG_LOG(("StickyBombCrateCollide::executeCrateBehavior 0"));
10590
const StickyBombCrateCollideModuleData* md = getStickyBombCrateCollideModuleData();
10691

10792
if (m_hasCollided && !md->m_allowMultiCollide)
@@ -131,6 +116,12 @@ Bool StickyBombCrateCollide::executeCrateBehavior( Object *other )
131116

132117
}
133118

119+
Real randomNumber = GameLogicRandomValueReal(0, 1);
120+
if (randomNumber > md->m_triggerChance) {
121+
m_hasCollided = TRUE;
122+
return false;
123+
}
124+
134125
if (md->m_showInfiltrationEvent)
135126
TheRadar->tryInfiltrationEvent( other );
136127

0 commit comments

Comments
 (0)