|
| 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