Skip to content

Commit 3ba0d09

Browse files
authored
Merge pull request #35 from Andreas-W/unique_unit_deploy_genpower
add ResetSpecialPowerTimerWhileAliveUpdate
2 parents aa3c558 + 18272d6 commit 3ba0d09

File tree

5 files changed

+196
-0
lines changed

5 files changed

+196
-0
lines changed

GeneralsMD/Code/GameEngine/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ set(GAMEENGINE_SRC
415415
Include/GameLogic/Module/RebuildHoleExposeDie.h
416416
Include/GameLogic/Module/RepairDockUpdate.h
417417
Include/GameLogic/Module/ReplaceObjectUpgrade.h
418+
Include/GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h
418419
Include/GameLogic/Module/RiderChangeContain.h
419420
Include/GameLogic/Module/SabotageCommandCenterCrateCollide.h
420421
Include/GameLogic/Module/SabotageFakeBuildingCrateCollide.h
@@ -1055,6 +1056,7 @@ set(GAMEENGINE_SRC
10551056
Source/GameLogic/Object/Update/RadarUpdate.cpp
10561057
Source/GameLogic/Object/Update/RadiusDecalUpdate.cpp
10571058
Source/GameLogic/Object/Update/RadiusDecalBehavior.cpp
1059+
Source/GameLogic/Object/Update/ResetSpecialPowerTimerWhileAliveUpdate.cpp
10581060
Source/GameLogic/Object/Update/ScatterShotUpdate.cpp
10591061
Source/GameLogic/Object/Update/SlavedUpdate.cpp
10601062
Source/GameLogic/Object/Update/SmartBombTargetHomingUpdate.cpp
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// FILE: ResetSpecialPowerTimerWhileAliveUpdate.h //////////////////////////////////////////////////////////////////////////
2+
// Author: pWn3d, 2025
3+
// Desc: Update module to reset a player global special power timer while this object is alive
4+
// Example use: airdrop special power that starts with the cooldown when the dropped unit is dead, add this module to the
5+
// dropped unit
6+
///////////////////////////////////////////////////////////////////////////////////////////////////
7+
8+
9+
#pragma once
10+
11+
#ifndef __RESET_SPECIAL_POWER_TIMER_WHILE_ALIVE_UPDATE_H_
12+
#define __RESET_SPECIAL_POWER_TIMER_WHILE_ALIVE_UPDATE_H_
13+
14+
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
15+
#include "Common/KindOf.h"
16+
#include "GameLogic/Module/UpdateModule.h"
17+
18+
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
19+
class ThingTemplate;
20+
class SpecialPowerTemplate;
21+
22+
23+
//-------------------------------------------------------------------------------------------------
24+
//-------------------------------------------------------------------------------------------------
25+
class ResetSpecialPowerTimerWhileAliveUpdateModuleData : public ModuleData
26+
{
27+
public:
28+
SpecialPowerTemplate* m_specialPowerTemplate;
29+
30+
ResetSpecialPowerTimerWhileAliveUpdateModuleData();
31+
static void buildFieldParse(MultiIniFieldParse& p);
32+
33+
private:
34+
35+
};
36+
37+
//-------------------------------------------------------------------------------------------------
38+
/** The default update module */
39+
//-------------------------------------------------------------------------------------------------
40+
class ResetSpecialPowerTimerWhileAliveUpdate : public UpdateModule
41+
{
42+
43+
MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(ResetSpecialPowerTimerWhileAliveUpdate, "ResetSpecialPowerTimerWhileAliveUpdate")
44+
MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA(ResetSpecialPowerTimerWhileAliveUpdate, ResetSpecialPowerTimerWhileAliveUpdateModuleData);
45+
46+
public:
47+
48+
ResetSpecialPowerTimerWhileAliveUpdate(Thing* thing, const ModuleData* moduleData);
49+
// virtual destructor prototype provided by memory pool declaration
50+
51+
virtual void onObjectCreated();
52+
virtual UpdateSleepTime update();
53+
54+
protected:
55+
// no members needed
56+
};
57+
58+
59+
#endif

GeneralsMD/Code/GameEngine/Source/Common/System/MemoryInit.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ static PoolSizeRec sizes[] =
729729
{ "ThumbnailManagerClass", 32, 32},
730730
{ "SmudgeSet", 32, 32},
731731
{ "Smudge", 128, 32},
732+
{ "ResetSpecialPowerTimerWhileAliveUpdate", 8, 8 },
732733
{ 0, 0, 0 }
733734
};
734735

GeneralsMD/Code/GameEngine/Source/Common/Thing/ModuleFactory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
#include "GameLogic/Module/PowerPlantUpdate.h"
198198
#include "GameLogic/Module/CheckpointUpdate.h"
199199
#include "GameLogic/Module/EMPUpdate.h"
200+
#include "GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h"
200201

201202
// upgrade includes
202203
#include "GameLogic/Module/ActiveShroudUpgrade.h"
@@ -486,6 +487,7 @@ void ModuleFactory::init( void )
486487
addModule( WorkerAIUpdate );
487488
addModule( PowerPlantUpdate );
488489
addModule( CheckpointUpdate );
490+
addModule( ResetSpecialPowerTimerWhileAliveUpdate );
489491

490492
// upgrade modules
491493
addModule( CostModifierUpgrade );
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
3+
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
4+
5+
#include "Common/BitFlagsIO.h"
6+
#include "Common/RandomValue.h"
7+
#include "Common/ThingTemplate.h"
8+
#include "Common/Xfer.h"
9+
#include "Common/SpecialPower.h"
10+
#include "Common/Player.h"
11+
12+
#include "GameClient/Drawable.h"
13+
14+
#include "GameLogic/GameLogic.h"
15+
#include "GameLogic/PartitionManager.h"
16+
#include "GameLogic/Object.h"
17+
#include "GameLogic/ObjectIter.h"
18+
#include "GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h"
19+
#include "GameLogic/Module/PhysicsUpdate.h"
20+
#include "GameLogic/Weapon.h"
21+
22+
23+
24+
//-------------------------------------------------------------------------------------------------
25+
//-------------------------------------------------------------------------------------------------
26+
ResetSpecialPowerTimerWhileAliveUpdateModuleData::ResetSpecialPowerTimerWhileAliveUpdateModuleData()
27+
{
28+
m_specialPowerTemplate = NULL;
29+
}
30+
31+
//-------------------------------------------------------------------------------------------------
32+
/*static*/ void ResetSpecialPowerTimerWhileAliveUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
33+
{
34+
ModuleData::buildFieldParse(p);
35+
36+
static const FieldParse dataFieldParse[] =
37+
{
38+
{ "SpecialPowerTemplate", INI::parseSpecialPowerTemplate, NULL, offsetof(ResetSpecialPowerTimerWhileAliveUpdateModuleData, m_specialPowerTemplate ) },
39+
{ 0, 0, 0, 0 }
40+
};
41+
p.add(dataFieldParse);
42+
}
43+
44+
//-------------------------------------------------------------------------------------------------
45+
ResetSpecialPowerTimerWhileAliveUpdate::ResetSpecialPowerTimerWhileAliveUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
46+
{
47+
setWakeFrame(getObject(), UPDATE_SLEEP_NONE);// No starting sleep, but we want to sleep later.
48+
}
49+
50+
//-------------------------------------------------------------------------------------------------
51+
//-------------------------------------------------------------------------------------------------
52+
ResetSpecialPowerTimerWhileAliveUpdate::~ResetSpecialPowerTimerWhileAliveUpdate( void )
53+
{
54+
55+
}
56+
57+
58+
//-------------------------------------------------------------------------------------------------
59+
void ResetSpecialPowerTimerWhileAliveUpdate::onObjectCreated()
60+
{
61+
const ResetSpecialPowerTimerWhileAliveUpdateModuleData *data = getResetSpecialPowerTimerWhileAliveUpdateModuleData();
62+
63+
//Make sure we have a weapon template
64+
if( !data->m_specialPowerTemplate )
65+
{
66+
DEBUG_CRASH( ("ResetSpecialPowerTimerWhileAliveUpdateModuleData for %s doesn't have a valid Special Power Template",
67+
getObject()->getTemplate()->getName().str() ) );
68+
return;
69+
}
70+
71+
//Make sure the special power template
72+
if (!data->m_specialPowerTemplate->isSharedNSync()) {
73+
DEBUG_CRASH(("ResetSpecialPowerTimerWhileAliveUpdateModuleData for %s only supports SpecialPowerTemplates with shared sync timers!",
74+
getObject()->getTemplate()->getName().str()));
75+
return;
76+
}
77+
}
78+
79+
//-------------------------------------------------------------------------------------------------
80+
/** The update callback. */
81+
//-------------------------------------------------------------------------------------------------
82+
UpdateSleepTime ResetSpecialPowerTimerWhileAliveUpdate::update()
83+
{
84+
Object *me = getObject();
85+
if( me->isEffectivelyDead() )
86+
return UPDATE_SLEEP_FOREVER; //No more resetting when dead
87+
88+
const ResetSpecialPowerTimerWhileAliveUpdateModuleData *data = getResetSpecialPowerTimerWhileAliveUpdateModuleData();
89+
90+
Player* owner = me->getControllingPlayer();
91+
if (owner != nullptr) {
92+
owner->resetOrStartSpecialPowerReadyFrame(data->m_specialPowerTemplate);
93+
}
94+
95+
return UPDATE_SLEEP_NONE;
96+
}
97+
98+
// ------------------------------------------------------------------------------------------------
99+
/** CRC */
100+
// ------------------------------------------------------------------------------------------------
101+
void ResetSpecialPowerTimerWhileAliveUpdate::crc( Xfer *xfer )
102+
{
103+
// extend base class
104+
UpdateModule::crc( xfer );
105+
} // end crc
106+
107+
// ------------------------------------------------------------------------------------------------
108+
/** Xfer method
109+
* Version Info:
110+
* 1: Initial version */
111+
// ------------------------------------------------------------------------------------------------
112+
void ResetSpecialPowerTimerWhileAliveUpdate::xfer( Xfer *xfer )
113+
{
114+
// version
115+
XferVersion currentVersion = 1;
116+
XferVersion version = currentVersion;
117+
xfer->xferVersion( &version, currentVersion );
118+
119+
// extend base class
120+
UpdateModule::xfer( xfer );
121+
122+
} // end xfer
123+
124+
// ------------------------------------------------------------------------------------------------
125+
/** Load post process */
126+
// ------------------------------------------------------------------------------------------------
127+
void ResetSpecialPowerTimerWhileAliveUpdate::loadPostProcess( void )
128+
{
129+
// extend base class
130+
UpdateModule::loadPostProcess();
131+
132+
} // end loadPostProcess

0 commit comments

Comments
 (0)