Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ set(GAMEENGINE_SRC
Include/GameLogic/Module/RebuildHoleExposeDie.h
Include/GameLogic/Module/RepairDockUpdate.h
Include/GameLogic/Module/ReplaceObjectUpgrade.h
Include/GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h
Include/GameLogic/Module/RiderChangeContain.h
Include/GameLogic/Module/SabotageCommandCenterCrateCollide.h
Include/GameLogic/Module/SabotageFakeBuildingCrateCollide.h
Expand Down Expand Up @@ -1055,6 +1056,7 @@ set(GAMEENGINE_SRC
Source/GameLogic/Object/Update/RadarUpdate.cpp
Source/GameLogic/Object/Update/RadiusDecalUpdate.cpp
Source/GameLogic/Object/Update/RadiusDecalBehavior.cpp
Source/GameLogic/Object/Update/ResetSpecialPowerTimerWhileAliveUpdate.cpp
Source/GameLogic/Object/Update/ScatterShotUpdate.cpp
Source/GameLogic/Object/Update/SlavedUpdate.cpp
Source/GameLogic/Object/Update/SmartBombTargetHomingUpdate.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// FILE: ResetSpecialPowerTimerWhileAliveUpdate.h //////////////////////////////////////////////////////////////////////////
// Author: pWn3d, 2025
// Desc: Update module to reset a player global special power timer while this object is alive
// Example use: airdrop special power that starts with the cooldown when the dropped unit is dead, add this module to the
// dropped unit
///////////////////////////////////////////////////////////////////////////////////////////////////


#pragma once

#ifndef __RESET_SPECIAL_POWER_TIMER_WHILE_ALIVE_UPDATE_H_
#define __RESET_SPECIAL_POWER_TIMER_WHILE_ALIVE_UPDATE_H_

// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "Common/KindOf.h"
#include "GameLogic/Module/UpdateModule.h"

// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class ThingTemplate;
class SpecialPowerTemplate;


//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class ResetSpecialPowerTimerWhileAliveUpdateModuleData : public ModuleData
{
public:
SpecialPowerTemplate* m_specialPowerTemplate;

ResetSpecialPowerTimerWhileAliveUpdateModuleData();
static void buildFieldParse(MultiIniFieldParse& p);

private:

};

//-------------------------------------------------------------------------------------------------
/** The default update module */
//-------------------------------------------------------------------------------------------------
class ResetSpecialPowerTimerWhileAliveUpdate : public UpdateModule
{

MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(ResetSpecialPowerTimerWhileAliveUpdate, "ResetSpecialPowerTimerWhileAliveUpdate")
MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA(ResetSpecialPowerTimerWhileAliveUpdate, ResetSpecialPowerTimerWhileAliveUpdateModuleData);

public:

ResetSpecialPowerTimerWhileAliveUpdate(Thing* thing, const ModuleData* moduleData);
// virtual destructor prototype provided by memory pool declaration

virtual void onObjectCreated();
virtual UpdateSleepTime update();

protected:
// no members needed
};


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ static PoolSizeRec sizes[] =
{ "ThumbnailManagerClass", 32, 32},
{ "SmudgeSet", 32, 32},
{ "Smudge", 128, 32},
{ "ResetSpecialPowerTimerWhileAliveUpdate", 8, 8 },
{ 0, 0, 0 }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
#include "GameLogic/Module/PowerPlantUpdate.h"
#include "GameLogic/Module/CheckpointUpdate.h"
#include "GameLogic/Module/EMPUpdate.h"
#include "GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h"

// upgrade includes
#include "GameLogic/Module/ActiveShroudUpgrade.h"
Expand Down Expand Up @@ -486,6 +487,7 @@ void ModuleFactory::init( void )
addModule( WorkerAIUpdate );
addModule( PowerPlantUpdate );
addModule( CheckpointUpdate );
addModule( ResetSpecialPowerTimerWhileAliveUpdate );

// upgrade modules
addModule( CostModifierUpgrade );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine

#include "Common/BitFlagsIO.h"
#include "Common/RandomValue.h"
#include "Common/ThingTemplate.h"
#include "Common/Xfer.h"
#include "Common/SpecialPower.h"
#include "Common/Player.h"

#include "GameClient/Drawable.h"

#include "GameLogic/GameLogic.h"
#include "GameLogic/PartitionManager.h"
#include "GameLogic/Object.h"
#include "GameLogic/ObjectIter.h"
#include "GameLogic/Module/ResetSpecialPowerTimerWhileAliveUpdate.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "GameLogic/Weapon.h"



//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
ResetSpecialPowerTimerWhileAliveUpdateModuleData::ResetSpecialPowerTimerWhileAliveUpdateModuleData()
{
m_specialPowerTemplate = NULL;
}

//-------------------------------------------------------------------------------------------------
/*static*/ void ResetSpecialPowerTimerWhileAliveUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
{
ModuleData::buildFieldParse(p);

static const FieldParse dataFieldParse[] =
{
{ "SpecialPowerTemplate", INI::parseSpecialPowerTemplate, NULL, offsetof(ResetSpecialPowerTimerWhileAliveUpdateModuleData, m_specialPowerTemplate ) },
{ 0, 0, 0, 0 }
};
p.add(dataFieldParse);
}

//-------------------------------------------------------------------------------------------------
ResetSpecialPowerTimerWhileAliveUpdate::ResetSpecialPowerTimerWhileAliveUpdate( Thing *thing, const ModuleData* moduleData ) : UpdateModule( thing, moduleData )
{
setWakeFrame(getObject(), UPDATE_SLEEP_NONE);// No starting sleep, but we want to sleep later.
}

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
ResetSpecialPowerTimerWhileAliveUpdate::~ResetSpecialPowerTimerWhileAliveUpdate( void )
{

}


//-------------------------------------------------------------------------------------------------
void ResetSpecialPowerTimerWhileAliveUpdate::onObjectCreated()
{
const ResetSpecialPowerTimerWhileAliveUpdateModuleData *data = getResetSpecialPowerTimerWhileAliveUpdateModuleData();

//Make sure we have a weapon template
if( !data->m_specialPowerTemplate )
{
DEBUG_CRASH( ("ResetSpecialPowerTimerWhileAliveUpdateModuleData for %s doesn't have a valid Special Power Template",
getObject()->getTemplate()->getName().str() ) );
return;
}

//Make sure the special power template
if (!data->m_specialPowerTemplate->isSharedNSync()) {
DEBUG_CRASH(("ResetSpecialPowerTimerWhileAliveUpdateModuleData for %s only supports SpecialPowerTemplates with shared sync timers!",
getObject()->getTemplate()->getName().str()));
return;
}
}

//-------------------------------------------------------------------------------------------------
/** The update callback. */
//-------------------------------------------------------------------------------------------------
UpdateSleepTime ResetSpecialPowerTimerWhileAliveUpdate::update()
{
Object *me = getObject();
if( me->isEffectivelyDead() )
return UPDATE_SLEEP_FOREVER; //No more resetting when dead

const ResetSpecialPowerTimerWhileAliveUpdateModuleData *data = getResetSpecialPowerTimerWhileAliveUpdateModuleData();

Player* owner = me->getControllingPlayer();
if (owner != nullptr) {
owner->resetOrStartSpecialPowerReadyFrame(data->m_specialPowerTemplate);
}

return UPDATE_SLEEP_NONE;
}

// ------------------------------------------------------------------------------------------------
/** CRC */
// ------------------------------------------------------------------------------------------------
void ResetSpecialPowerTimerWhileAliveUpdate::crc( Xfer *xfer )
{
// extend base class
UpdateModule::crc( xfer );
} // end crc

// ------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
* 1: Initial version */
// ------------------------------------------------------------------------------------------------
void ResetSpecialPowerTimerWhileAliveUpdate::xfer( Xfer *xfer )
{
// version
XferVersion currentVersion = 1;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );

// extend base class
UpdateModule::xfer( xfer );

} // end xfer

// ------------------------------------------------------------------------------------------------
/** Load post process */
// ------------------------------------------------------------------------------------------------
void ResetSpecialPowerTimerWhileAliveUpdate::loadPostProcess( void )
{
// extend base class
UpdateModule::loadPostProcess();

} // end loadPostProcess
Loading