ParticleUplinkCannonUpdate.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ParticleUplinkCannonUpdate.cpp //////////////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, September 2002
  25. // Desc: Update module to handle building states and weapon firing of the particle uplink cannon.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #define DEFINE_DEATH_NAMES
  29. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  30. #include "Common\ThingTemplate.h"
  31. #include "Common\ThingFactory.h"
  32. #include "Common\Player.h"
  33. #include "Common\PlayerList.h"
  34. #include "Common\Xfer.h"
  35. #include "Common\ClientUpdateModule.h"
  36. #include "GameClient\ControlBar.h"
  37. #include "GameClient\GameClient.h"
  38. #include "GameClient\Drawable.h"
  39. #include "GameClient\ParticleSys.h"
  40. #include "GameClient\FXList.h"
  41. #include "GameLogic\GameLogic.h"
  42. #include "GameLogic\PartitionManager.h"
  43. #include "GameLogic\Object.h"
  44. #include "GameLogic\ObjectIter.h"
  45. #include "GameLogic\Weaponset.h"
  46. #include "GameLogic\Weapon.h"
  47. #include "GameLogic\TerrainLogic.h"
  48. #include "GameLogic\Module\SpecialPowerModule.h"
  49. #include "GameLogic\Module\ParticleUplinkCannonUpdate.h"
  50. #include "GameLogic\Module\PhysicsUpdate.h"
  51. #include "GameLogic\Module\LaserUpdate.h"
  52. #include "GameLogic\Module\ActiveBody.h"
  53. #ifdef _INTERNAL
  54. // for occasional debugging...
  55. //#pragma optimize("", off)
  56. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  57. #endif
  58. //-------------------------------------------------------------------------------------------------
  59. //-------------------------------------------------------------------------------------------------
  60. ParticleUplinkCannonUpdateModuleData::ParticleUplinkCannonUpdateModuleData()
  61. {
  62. m_specialPowerTemplate = NULL;
  63. m_beginChargeFrames = 0;
  64. m_raiseAntennaFrames = 0;
  65. m_readyDelayFrames = 0;
  66. m_outerEffectNumBones = 0;
  67. m_beamTravelFrames = 0;
  68. m_widthGrowFrames = 0;
  69. m_totalFiringFrames = 0;
  70. m_totalScorchMarks = 0;
  71. m_scorchMarkScalar = 1.0f;
  72. m_damageRadiusScalar = 1.0f;
  73. m_groundHitFX = NULL;
  74. m_beamLaunchFX = NULL;
  75. m_framesBetweenLaunchFXRefresh = 30;
  76. m_totalDamagePulses = 0;
  77. m_damagePerSecond = 0.0f;
  78. m_damageType = DAMAGE_LASER;
  79. m_deathType = DEATH_LASERED;
  80. m_revealRange = 0.0f;
  81. m_manualDrivingSpeed = 0.0f;
  82. m_manualFastDrivingSpeed = 0.0f;
  83. m_doubleClickToFastDriveDelay = 500;
  84. //Added by Sadullah Nader
  85. //Initializations inserted
  86. m_swathOfDeathAmplitude = 0.0f;
  87. m_swathOfDeathDistance = 0.0f;
  88. //
  89. }
  90. //-------------------------------------------------------------------------------------------------
  91. /*static*/ void ParticleUplinkCannonUpdateModuleData::buildFieldParse(MultiIniFieldParse& p)
  92. {
  93. ModuleData::buildFieldParse(p);
  94. static const FieldParse dataFieldParse[] =
  95. {
  96. { "SpecialPowerTemplate", INI::parseSpecialPowerTemplate, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_specialPowerTemplate ) },
  97. { "BeginChargeTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_beginChargeFrames ) },
  98. { "RaiseAntennaTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_raiseAntennaFrames ) },
  99. { "ReadyDelayTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_readyDelayFrames ) },
  100. { "WidthGrowTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_widthGrowFrames ) },
  101. { "BeamTravelTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_beamTravelFrames ) },
  102. { "TotalFiringTime", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_totalFiringFrames ) },
  103. { "RevealRange", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_revealRange ) },
  104. { "OuterEffectBoneName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_outerEffectBaseBoneName ) },
  105. { "OuterEffectNumBones", INI::parseUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_outerEffectNumBones ) },
  106. { "OuterNodesLightFlareParticleSystem", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_outerNodesLightFlareParticleSystemName ) },
  107. { "OuterNodesMediumFlareParticleSystem", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_outerNodesMediumFlareParticleSystemName ) },
  108. { "OuterNodesIntenseFlareParticleSystem", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_outerNodesIntenseFlareParticleSystemName ) },
  109. { "ConnectorBoneName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_connectorBoneName ) },
  110. { "ConnectorMediumLaserName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_connectorMediumLaserNameName ) },
  111. { "ConnectorIntenseLaserName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_connectorIntenseLaserNameName ) },
  112. { "ConnectorMediumFlare", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_connectorMediumFlareParticleSystemName ) },
  113. { "ConnectorIntenseFlare", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_connectorIntenseFlareParticleSystemName ) },
  114. { "FireBoneName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_fireBoneName ) },
  115. { "LaserBaseLightFlareParticleSystemName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_laserBaseLightFlareParticleSystemName ) },
  116. { "LaserBaseMediumFlareParticleSystemName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_laserBaseMediumFlareParticleSystemName ) },
  117. { "LaserBaseIntenseFlareParticleSystemName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_laserBaseIntenseFlareParticleSystemName ) },
  118. { "ParticleBeamLaserName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_particleBeamLaserName ) },
  119. { "SwathOfDeathDistance", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_swathOfDeathDistance ) },
  120. { "SwathOfDeathAmplitude", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_swathOfDeathAmplitude ) },
  121. { "TotalScorchMarks", INI::parseUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_totalScorchMarks ) },
  122. { "ScorchMarkScalar", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_scorchMarkScalar ) },
  123. { "BeamLaunchFX", INI::parseFXList, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_beamLaunchFX ) },
  124. { "DelayBetweenLaunchFX", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_framesBetweenLaunchFXRefresh ) },
  125. { "GroundHitFX", INI::parseFXList, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_groundHitFX ) },
  126. { "DamagePerSecond", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_damagePerSecond ) },
  127. { "TotalDamagePulses", INI::parseUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_totalDamagePulses ) },
  128. { "DamageType", DamageTypeFlags::parseSingleBitFromINI, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_damageType ) },
  129. { "DeathType", INI::parseIndexList, TheDeathNames, offsetof( ParticleUplinkCannonUpdateModuleData, m_deathType ) },
  130. { "DamageRadiusScalar", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_damageRadiusScalar ) },
  131. { "PoweringUpSoundLoop", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_powerupSoundName ) },
  132. { "UnpackToIdleSoundLoop", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_unpackToReadySoundName ) },
  133. { "FiringToPackSoundLoop", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_firingToIdleSoundName ) },
  134. { "GroundAnnihilationSoundLoop", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_annihilationSoundName ) },
  135. { "DamagePulseRemnantObjectName", INI::parseAsciiString, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_damagePulseRemnantObjectName ) },
  136. { "ManualDrivingSpeed", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_manualDrivingSpeed ) },
  137. { "ManualFastDrivingSpeed", INI::parseReal, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_manualFastDrivingSpeed ) },
  138. { "DoubleClickToFastDriveDelay", INI::parseDurationUnsignedInt, NULL, offsetof( ParticleUplinkCannonUpdateModuleData, m_doubleClickToFastDriveDelay ) },
  139. { 0, 0, 0, 0 }
  140. };
  141. p.add(dataFieldParse);
  142. }
  143. //-------------------------------------------------------------------------------------------------
  144. ParticleUplinkCannonUpdate::ParticleUplinkCannonUpdate( Thing *thing, const ModuleData* moduleData ) : SpecialPowerUpdateModule( thing, moduleData )
  145. {
  146. m_status = STATUS_IDLE;
  147. m_laserStatus = LASERSTATUS_NONE;
  148. m_frames = 0;
  149. m_specialPowerModule = NULL;
  150. m_groundToOrbitBeamID = INVALID_DRAWABLE_ID;
  151. m_orbitToTargetBeamID = INVALID_DRAWABLE_ID;
  152. m_connectorSystemID = INVALID_PARTICLE_SYSTEM_ID;
  153. m_laserBaseSystemID = INVALID_PARTICLE_SYSTEM_ID;
  154. m_connectorNodePosition.zero();
  155. m_laserOriginPosition.zero();
  156. m_upBonesCached = FALSE;
  157. m_defaultInfoCached = FALSE;
  158. m_invalidSettings = FALSE;
  159. m_manualTargetMode = FALSE;
  160. m_scriptedWaypointMode = FALSE;
  161. m_nextDestWaypointID = 0;
  162. m_initialTargetPosition.zero();
  163. m_currentTargetPosition.zero();
  164. m_overrideTargetDestination.zero();
  165. m_scorchMarksMade= 0;
  166. m_nextScorchMarkFrame = 0;
  167. m_nextLaunchFXFrame = 0;
  168. m_damagePulsesMade = 0;
  169. m_nextDamagePulseFrame = 0;
  170. m_startAttackFrame = 0;
  171. m_startDecayFrame = 0;
  172. m_lastDrivingClickFrame = 0;
  173. m_2ndLastDrivingClickFrame = 0;
  174. m_clientShroudedLastFrame = FALSE;
  175. for( Int i = 0; i < MAX_OUTER_NODES; i++ )
  176. {
  177. m_outerSystemIDs[ i ] = INVALID_PARTICLE_SYSTEM_ID;
  178. m_laserBeamIDs[ i ] = INVALID_DRAWABLE_ID;
  179. //Initializing (even though they will get cached properly).
  180. m_outerNodePositions[ i ].zero();
  181. m_outerNodeOrientations[ i ].Make_Identity();
  182. }
  183. }
  184. //-------------------------------------------------------------------------------------------------
  185. //-------------------------------------------------------------------------------------------------
  186. void ParticleUplinkCannonUpdate::killEverything()
  187. {
  188. removeAllEffects();
  189. //This laser is independent from the other effects and needs to be specially handled.
  190. if( m_orbitToTargetBeamID )
  191. {
  192. Drawable *beam = TheGameClient->findDrawableByID( m_orbitToTargetBeamID );
  193. if( beam )
  194. {
  195. TheGameClient->destroyDrawable( beam );
  196. }
  197. m_orbitToTargetBeamID = INVALID_DRAWABLE_ID;
  198. }
  199. TheAudio->removeAudioEvent( m_powerupSound.getPlayingHandle() );
  200. TheAudio->removeAudioEvent( m_unpackToReadySound.getPlayingHandle() );
  201. TheAudio->removeAudioEvent( m_firingToIdleSound.getPlayingHandle() );
  202. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  203. }
  204. //-------------------------------------------------------------------------------------------------
  205. //-------------------------------------------------------------------------------------------------
  206. ParticleUplinkCannonUpdate::~ParticleUplinkCannonUpdate( void )
  207. {
  208. killEverything();
  209. }
  210. //-------------------------------------------------------------------------------------------------
  211. // Validate that we have the necessary data from the ini file.
  212. //-------------------------------------------------------------------------------------------------
  213. void ParticleUplinkCannonUpdate::onObjectCreated()
  214. {
  215. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  216. Object *obj = getObject();
  217. if( !data->m_specialPowerTemplate )
  218. {
  219. DEBUG_CRASH( ("%s object's ParticleUplinkCannonUpdate lacks access to the SpecialPowerTemplate. Needs to be specified in ini.", obj->getTemplate()->getName().str() ) );
  220. m_invalidSettings = TRUE;
  221. return;
  222. }
  223. m_specialPowerModule = obj->getSpecialPowerModule( data->m_specialPowerTemplate );
  224. m_connectorNodePosition.set( obj->getPosition() );
  225. m_laserOriginPosition.set( obj->getPosition() );
  226. //Create instances of the sounds required.
  227. m_powerupSound.setEventName( data->m_powerupSoundName );
  228. m_unpackToReadySound.setEventName( data->m_unpackToReadySoundName );
  229. m_firingToIdleSound.setEventName( data->m_firingToIdleSoundName );
  230. m_annihilationSound.setEventName( data->m_annihilationSoundName );
  231. TheAudio->getInfoForAudioEvent( &m_powerupSound );
  232. TheAudio->getInfoForAudioEvent( &m_unpackToReadySound );
  233. TheAudio->getInfoForAudioEvent( &m_firingToIdleSound );
  234. TheAudio->getInfoForAudioEvent( &m_annihilationSound );
  235. }
  236. //-------------------------------------------------------------------------------------------------
  237. Bool ParticleUplinkCannonUpdate::initiateIntentToDoSpecialPower(const SpecialPowerTemplate *specialPowerTemplate, const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions )
  238. {
  239. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  240. if( m_specialPowerModule->getSpecialPowerTemplate() != specialPowerTemplate )
  241. {
  242. //Check to make sure our modules are connected.
  243. return FALSE;
  244. }
  245. // getObject()->getControllingPlayer()->getAcademyStats()->recordSpecialPowerUsed( specialPowerTemplate );
  246. if( !BitTest( commandOptions, COMMAND_FIRED_BY_SCRIPT ) )
  247. {
  248. //All human players have manual control and must "drive" the beam around!
  249. m_startAttackFrame = TheGameLogic->getFrame();
  250. m_laserStatus = LASERSTATUS_NONE;
  251. m_manualTargetMode = TRUE;
  252. m_initialTargetPosition.set( targetPos );
  253. m_overrideTargetDestination.set( targetPos );
  254. m_currentTargetPosition.set( targetPos );
  255. }
  256. else if( way )
  257. {
  258. //Script fired with a specific waypoint path, so set things up to follow the waypoint!
  259. UnsignedInt now = TheGameLogic->getFrame();
  260. Coord3D pos;
  261. if( way )
  262. {
  263. pos.set( way->getLocation() );
  264. }
  265. else if( targetObj )
  266. {
  267. pos.set( targetObj->getPosition() );
  268. }
  269. m_startAttackFrame = max( now, (UnsignedInt)1 );
  270. m_scriptedWaypointMode = TRUE;
  271. m_laserStatus = LASERSTATUS_NONE;
  272. setLogicalStatus( STATUS_READY_TO_FIRE );
  273. m_specialPowerModule->setReadyFrame( now );
  274. m_initialTargetPosition.set( &pos );
  275. m_currentTargetPosition.set( &pos );
  276. m_nextDestWaypointID = way->getID();
  277. Int linkCount = way->getNumLinks();
  278. Int which = GameLogicRandomValue( 0, linkCount-1 );
  279. Waypoint *next = way->getLink( which );
  280. if( next )
  281. {
  282. m_nextDestWaypointID = next->getID();
  283. m_overrideTargetDestination.set( next->getLocation() );
  284. }
  285. }
  286. else
  287. {
  288. //All computer controlled players have automatic control -- the "S" curve.
  289. UnsignedInt now = TheGameLogic->getFrame();
  290. Coord3D pos;
  291. if( targetPos )
  292. {
  293. pos.set( targetPos );
  294. }
  295. else if( targetObj )
  296. {
  297. pos.set( targetObj->getPosition() );
  298. }
  299. m_initialTargetPosition.set( &pos );
  300. m_startAttackFrame = max( now, (UnsignedInt)1 );
  301. m_laserStatus = LASERSTATUS_NONE;
  302. setLogicalStatus( STATUS_READY_TO_FIRE );
  303. m_specialPowerModule->setReadyFrame( now );
  304. }
  305. m_startDecayFrame = m_startAttackFrame + data->m_totalFiringFrames;
  306. SpecialPowerModuleInterface *spmInterface = getObject()->getSpecialPowerModule( specialPowerTemplate );
  307. if( spmInterface )
  308. {
  309. SpecialPowerModule *spModule = (SpecialPowerModule*)spmInterface;
  310. spModule->markSpecialPowerTriggered( &m_initialTargetPosition );
  311. }
  312. return TRUE;
  313. }
  314. //-------------------------------------------------------------------------------------------------
  315. Bool ParticleUplinkCannonUpdate::isPowerCurrentlyInUse( const CommandButton *command ) const
  316. {
  317. if( m_startAttackFrame != 0 && m_startAttackFrame <= TheGameLogic->getFrame() )
  318. {
  319. return TRUE;
  320. }
  321. return FALSE;
  322. }
  323. //-------------------------------------------------------------------------------------------------
  324. void ParticleUplinkCannonUpdate::setSpecialPowerOverridableDestination( const Coord3D *loc )
  325. {
  326. if( !getObject()->isDisabled() )
  327. {
  328. m_overrideTargetDestination = *loc;
  329. m_manualTargetMode = TRUE;
  330. m_2ndLastDrivingClickFrame = m_lastDrivingClickFrame;
  331. m_lastDrivingClickFrame = TheGameLogic->getFrame();
  332. }
  333. }
  334. //-------------------------------------------------------------------------------------------------
  335. /** The update callback. */
  336. //-------------------------------------------------------------------------------------------------
  337. UpdateSleepTime ParticleUplinkCannonUpdate::update()
  338. {
  339. if( m_invalidSettings )
  340. {
  341. // can't return UPDATE_SLEEP_FOREVER unless we are sleepy...
  342. return UPDATE_SLEEP_NONE;
  343. ///return UPDATE_SLEEP_FOREVER;
  344. }
  345. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  346. Object *me = getObject();
  347. // must test SOLD *before* the others.
  348. if( me->testStatus(OBJECT_STATUS_SOLD))
  349. {
  350. if (m_status != STATUS_IDLE)
  351. {
  352. setLogicalStatus( STATUS_IDLE );
  353. killEverything();
  354. }
  355. return UPDATE_SLEEP_NONE;
  356. }
  357. if( me->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION) )
  358. {
  359. return UPDATE_SLEEP_NONE;
  360. }
  361. if( me->isEffectivelyDead() )
  362. {
  363. return UPDATE_SLEEP_NONE;
  364. }
  365. //Check to see what our status is -- there are a couple:
  366. //1) Idle while waiting to get near the time when we should be preparing to be ready.
  367. //2) If superweapon delay is nuked (cheat) then we need to make the building ready now.
  368. UnsignedInt now = TheGameLogic->getFrame();
  369. UnsignedInt readyToFireFrame = m_specialPowerModule->isReady() ? now : m_specialPowerModule->getReadyFrame();
  370. UnsignedInt almostReadyFrame = readyToFireFrame - data->m_readyDelayFrames;
  371. UnsignedInt raiseAntennaFrame = almostReadyFrame - data->m_raiseAntennaFrames;
  372. UnsignedInt beginChargeFrame = raiseAntennaFrame - data->m_beginChargeFrames;
  373. if( m_startAttackFrame != 0 && m_startAttackFrame <= now )
  374. {
  375. if( m_startDecayFrame > now )
  376. {
  377. if( me->isDisabledByType( DISABLED_UNDERPOWERED ) ||
  378. me->isDisabledByType( DISABLED_EMP ) ||
  379. me->isDisabledByType( DISABLED_SUBDUED ) ||
  380. me->isDisabledByType( DISABLED_HACKED ) )
  381. {
  382. //We must end the special power early! ABORT! ABORT!
  383. m_startDecayFrame = now;
  384. }
  385. }
  386. UnsignedInt endDecayFrame = m_startDecayFrame + data->m_widthGrowFrames;
  387. UnsignedInt orbitalBirthFrame = m_startAttackFrame + data->m_beamTravelFrames;
  388. UnsignedInt orbitalDecayStart = m_startDecayFrame + data->m_beamTravelFrames;
  389. UnsignedInt orbitalDeathFrame = orbitalDecayStart + data->m_widthGrowFrames;
  390. switch( m_laserStatus )
  391. {
  392. case LASERSTATUS_NONE:
  393. //Means we are eligible to fire!
  394. if( orbitalBirthFrame <= now )
  395. {
  396. createOrbitToTargetLaser( data->m_widthGrowFrames );
  397. m_laserStatus = LASERSTATUS_BORN;
  398. m_scorchMarksMade = 0;
  399. m_nextScorchMarkFrame = now;
  400. m_damagePulsesMade = 0;
  401. m_nextDamagePulseFrame = now;
  402. }
  403. break;
  404. case LASERSTATUS_BORN:
  405. {
  406. Drawable *beam = TheGameClient->findDrawableByID( m_orbitToTargetBeamID );
  407. if( beam )
  408. {
  409. //m_annihilationSound.setPosition( beam->getPosition() );
  410. if( orbitalDecayStart <= now )
  411. {
  412. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  413. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  414. if( update )
  415. {
  416. update->setDecayFrames( data->m_widthGrowFrames );
  417. }
  418. m_laserStatus = LASERSTATUS_DECAYING;
  419. }
  420. }
  421. break;
  422. }
  423. case LASERSTATUS_DECAYING:
  424. {
  425. Drawable *beam = TheGameClient->findDrawableByID( m_orbitToTargetBeamID );
  426. if( beam )
  427. {
  428. //m_annihilationSound.setPosition( beam->getPosition() );
  429. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  430. if( orbitalDeathFrame <= now )
  431. {
  432. TheGameClient->destroyDrawable( beam );
  433. m_orbitToTargetBeamID = INVALID_DRAWABLE_ID;
  434. m_laserStatus = LASERSTATUS_DEAD;
  435. m_startAttackFrame = 0;
  436. setLogicalStatus( STATUS_IDLE );
  437. }
  438. }
  439. break;
  440. }
  441. case LASERSTATUS_DEAD:
  442. //Nothing... this is just a wait state.
  443. break;
  444. }
  445. Drawable *beam = TheGameClient->findDrawableByID( m_orbitToTargetBeamID );
  446. if( beam && orbitalBirthFrame <= now && now <= orbitalDeathFrame )
  447. {
  448. if( !m_manualTargetMode && !m_scriptedWaypointMode )
  449. {
  450. //Calculate the position of the beam because it swaths -- a nice S curve centering at the target location!
  451. //First determine the factor of time completed (ranges between 0.0 and 1.0)
  452. Real factor = (Real)(now - orbitalBirthFrame) / (Real)(orbitalDeathFrame - orbitalBirthFrame);
  453. //We're generating a swath that travels the points between sin( -1PI ) and sin( 1PI )
  454. Real radians = (factor * TWO_PI) - PI;
  455. Real cxDistance = (factor * data->m_swathOfDeathDistance ) - (data->m_swathOfDeathDistance * 0.5f); //cx is cartesian x
  456. //Now calculate the amplitude value.
  457. Real height = sin( radians );
  458. Real cxHeight = height * data->m_swathOfDeathAmplitude;
  459. Coord3D buildingToInitialTargetVector;
  460. buildingToInitialTargetVector.set( &m_initialTargetPosition );
  461. buildingToInitialTargetVector.sub( me->getPosition() );
  462. Real targetDistance = buildingToInitialTargetVector.length();
  463. //Calculate the point position assuming the target position is on the x axis relative to the building.
  464. m_currentTargetPosition.x = cxDistance + targetDistance;
  465. m_currentTargetPosition.y = cxHeight;
  466. m_currentTargetPosition.z = 0.0f;
  467. targetDistance = m_currentTargetPosition.length();
  468. //Now that we have our cartesian offset relative to the target coordinate, we need to rotate that offset
  469. //so it's aligned to along the building -> target vector.
  470. Vector2 buildingToTargetVector( m_initialTargetPosition.x - me->getPosition()->x, m_initialTargetPosition.y - me->getPosition()->y );
  471. buildingToTargetVector.Normalize();
  472. Vector2 cartesianTargetVector( m_currentTargetPosition.x, m_currentTargetPosition.y );
  473. cartesianTargetVector.Normalize();
  474. Real dotProduct = Vector2::Dot_Product( buildingToTargetVector, cartesianTargetVector );
  475. dotProduct = __min( 0.99999f, __max( -0.99999f, dotProduct ) ); //Account for numerical errors. Also, acos(-1.00000) is coming out QNAN on the superweapon general map. Heh.
  476. Real angle = (Real)ACos( dotProduct );
  477. if( buildingToTargetVector.Y >= 0 )
  478. {
  479. angle = -angle;
  480. }
  481. Matrix3D mtx( Vector3( 1.0f, 0.0f, 0.0f ) );
  482. mtx.Scale( targetDistance );
  483. mtx.Rotate_Z( -angle );
  484. Vector3 v = mtx.Get_X_Vector();
  485. m_currentTargetPosition.x = me->getPosition()->x + v.X;
  486. m_currentTargetPosition.y = me->getPosition()->y + v.Y;
  487. }
  488. else
  489. {
  490. Real speed = data->m_manualDrivingSpeed;
  491. if( m_scriptedWaypointMode || m_lastDrivingClickFrame - m_2ndLastDrivingClickFrame < data->m_doubleClickToFastDriveDelay )
  492. {
  493. //Because we double clicked, use the faster driving speed.
  494. speed = data->m_manualFastDrivingSpeed;
  495. }
  496. //Convert speed to speed per frame.
  497. speed /= LOGICFRAMES_PER_SECOND;
  498. //Calculate the distance from our current position to our target dest.
  499. Coord3D vector = m_overrideTargetDestination;
  500. vector.sub( &m_currentTargetPosition );
  501. Real distance = vector.length();
  502. if( distance < speed )
  503. {
  504. //Don't allow the speed to overshoot the target point if close.
  505. speed = distance;
  506. //If we're in scripted waypoint mode, go to the next waypoint!
  507. if( m_scriptedWaypointMode )
  508. {
  509. Waypoint *way = TheTerrainLogic->getWaypointByID( m_nextDestWaypointID );
  510. if( way )
  511. {
  512. //Advance to the next waypoint.
  513. Int linkCount = way->getNumLinks();
  514. Int which = GameLogicRandomValue( 0, linkCount-1 );
  515. way = way->getLink( which );
  516. m_nextDestWaypointID = way->getID();
  517. m_overrideTargetDestination.set( way->getLocation() );
  518. }
  519. }
  520. }
  521. //Unitize the vector then apply the distance we will move.
  522. vector.normalize();
  523. vector.scale( speed );
  524. //Move the current target position in the desired direction and speed.
  525. m_currentTargetPosition.x += vector.x;
  526. m_currentTargetPosition.y += vector.y;
  527. }
  528. //Regardless of which method we used to set the target position, make sure the z position is at the terrain.
  529. m_currentTargetPosition.z = TheTerrainLogic->getGroundHeight( m_currentTargetPosition.x, m_currentTargetPosition.y );
  530. Coord3D orbitPosition;
  531. orbitPosition.set( &m_currentTargetPosition );
  532. orbitPosition.z += 500.0f;
  533. Real scorchRadius = 0.0f;
  534. Real damageRadius = 0.0f;
  535. //Reset the laser position
  536. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  537. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  538. if( update )
  539. {
  540. update->initLaser( NULL, NULL, &orbitPosition, &m_currentTargetPosition, "" );
  541. scorchRadius = update->getCurrentLaserRadius() * data->m_scorchMarkScalar;
  542. damageRadius = update->getCurrentLaserRadius() * data->m_damageRadiusScalar;
  543. }
  544. //Create scorch marks periodically
  545. if( m_nextScorchMarkFrame <= now )
  546. {
  547. m_scorchMarksMade++;
  548. //Create the scorch mark now!
  549. Scorches scorchID = (Scorches)GameClientRandomValue( SCORCH_1, SCORCH_4 ); //Yes, this is just client fluff!
  550. TheGameClient->addScorch( &m_currentTargetPosition, scorchRadius, scorchID );
  551. //Calculate next scorch mark frame.
  552. Real nextFactor = (Real)m_scorchMarksMade / (Real)data->m_totalScorchMarks;
  553. m_nextScorchMarkFrame = orbitalBirthFrame + nextFactor * (orbitalDeathFrame - orbitalBirthFrame);
  554. //Generate iteration of fxlist for beam hitting ground.
  555. if( data->m_groundHitFX )
  556. {
  557. FXList::doFXPos( data->m_groundHitFX, &m_currentTargetPosition, NULL );
  558. }
  559. //Also reveal vision because the owning player has full rights to watch the carnage he created!
  560. ThePartitionManager->doShroudReveal( m_currentTargetPosition.x, m_currentTargetPosition.y, data->m_revealRange, me->getControllingPlayer()->getPlayerMask() );
  561. ThePartitionManager->undoShroudReveal( m_currentTargetPosition.x, m_currentTargetPosition.y, data->m_revealRange, me->getControllingPlayer()->getPlayerMask() );
  562. }
  563. //Handle damage pulses
  564. if( m_nextDamagePulseFrame <= now )
  565. {
  566. m_damagePulsesMade++;
  567. DamageInfo damageInfo;
  568. Real totalFiringSeconds = data->m_totalFiringFrames / LOGICFRAMES_PER_SECOND;
  569. Real damagePerPulse = (Real)(totalFiringSeconds * data->m_damagePerSecond) / (Real)data->m_totalDamagePulses;
  570. damageInfo.in.m_amount = damagePerPulse;
  571. damageInfo.in.m_sourceID = me->getID();
  572. damageInfo.in.m_damageType = data->m_damageType;
  573. damageInfo.in.m_deathType = data->m_deathType;
  574. PartitionFilterAlive filterAlive;
  575. PartitionFilter *filters[] = { &filterAlive, NULL };
  576. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange( &m_currentTargetPosition, damageRadius, FROM_CENTER_2D, filters );
  577. MemoryPoolObjectHolder hold( iter );
  578. for( Object *obj = iter->first(); obj; obj = iter->next() )
  579. {
  580. BodyModuleInterface *body = obj->getBodyModule();
  581. if( body )
  582. {
  583. body->attemptDamage( &damageInfo );
  584. }
  585. }
  586. if( data->m_damagePulseRemnantObjectName.isNotEmpty() )
  587. {
  588. //Create a remnant damaging object that will fade over time to represent the burning trail.
  589. const ThingTemplate *thing = TheThingFactory->findTemplate( data->m_damagePulseRemnantObjectName );
  590. if( thing )
  591. {
  592. //Fire and forget
  593. Object *remnant = TheThingFactory->newObject( thing, me->getTeam() );
  594. if( remnant )
  595. {
  596. remnant->setPosition( &m_currentTargetPosition );
  597. }
  598. }
  599. }
  600. //Calculate next damage pulse frame.
  601. Real nextFactor = (Real)m_damagePulsesMade / (Real)data->m_totalDamagePulses;
  602. m_nextDamagePulseFrame = orbitalBirthFrame + nextFactor * (orbitalDeathFrame - orbitalBirthFrame);
  603. }
  604. }
  605. if( endDecayFrame <= now )
  606. {
  607. setLogicalStatus( STATUS_PACKING );
  608. }
  609. else if( m_startDecayFrame <= now )
  610. {
  611. setLogicalStatus( STATUS_POSTFIRE );
  612. }
  613. else
  614. {
  615. setLogicalStatus( STATUS_FIRING );
  616. }
  617. }
  618. else if( readyToFireFrame <= now )
  619. {
  620. setLogicalStatus( STATUS_READY_TO_FIRE );
  621. }
  622. else if( almostReadyFrame <= now )
  623. {
  624. setLogicalStatus( STATUS_ALMOST_READY );
  625. }
  626. else if( raiseAntennaFrame <= now )
  627. {
  628. setLogicalStatus( STATUS_PREPARING );
  629. }
  630. else if( beginChargeFrame <= now )
  631. {
  632. setLogicalStatus( STATUS_CHARGING );
  633. }
  634. else if( m_status == STATUS_ALMOST_READY )
  635. {
  636. }
  637. else if( m_status == STATUS_READY_TO_FIRE )
  638. {
  639. //The particle cannon timer has been reset (sabotaged?)
  640. //If so, when ready, pack it up again.
  641. setLogicalStatus( STATUS_PACKING );
  642. }
  643. if( m_status == STATUS_FIRING )
  644. {
  645. if( m_nextLaunchFXFrame <= now )
  646. {
  647. //Generate iteration of fxlist for beam launching
  648. if( data->m_beamLaunchFX )
  649. {
  650. FXList::doFXPos( data->m_beamLaunchFX, &m_laserOriginPosition, NULL );
  651. }
  652. m_nextLaunchFXFrame = now + data->m_framesBetweenLaunchFXRefresh;
  653. }
  654. }
  655. //Handle shrouded status changes for the client player.
  656. Player *localPlayer = ThePlayerList->getLocalPlayer();
  657. if( localPlayer )
  658. {
  659. Bool shrouded = me->getShroudedStatus( localPlayer->getPlayerIndex() ) != OBJECTSHROUD_CLEAR;
  660. if( shrouded )
  661. {
  662. //We can't see it so any client effects that have been added logically needs to be removed!
  663. removeAllEffects();
  664. }
  665. else
  666. {
  667. //We can see it -- we only want to do anything if we just started seeing it, which means
  668. //we want to add client effects again.
  669. Bool revealThisFrame = m_clientShroudedLastFrame != shrouded;
  670. if( revealThisFrame )
  671. {
  672. //Only if we reveal this frame, will we add client effects. The logic can take it from
  673. //here on... unless of course we lose sight again.
  674. setClientStatus( m_status, revealThisFrame );
  675. }
  676. }
  677. m_clientShroudedLastFrame = shrouded;
  678. }
  679. return UPDATE_SLEEP_NONE;
  680. }
  681. //-------------------------------------------------------------------------------------------------
  682. void ParticleUplinkCannonUpdate::createOuterNodeParticleSystems( IntensityTypes intensity )
  683. {
  684. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  685. AsciiString str;
  686. switch( intensity )
  687. {
  688. case IT_LIGHT:
  689. str = data->m_outerNodesLightFlareParticleSystemName;
  690. break;
  691. case IT_MEDIUM:
  692. str = data->m_outerNodesMediumFlareParticleSystemName;
  693. break;
  694. case IT_INTENSE:
  695. str = data->m_outerNodesIntenseFlareParticleSystemName;
  696. break;
  697. case IT_FINISH:
  698. break;
  699. }
  700. if( str.isNotEmpty() )
  701. {
  702. const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( str );
  703. if( tmp )
  704. {
  705. ParticleSystem *system;
  706. for( int i = 0; i < data->m_outerEffectNumBones; i++ )
  707. {
  708. system = TheParticleSystemManager->createParticleSystem( tmp );
  709. if( system )
  710. {
  711. m_outerSystemIDs[ i ] = system->getSystemID();
  712. system->setPosition( &m_outerNodePositions[ i ] );
  713. system->setLocalTransform( &m_outerNodeOrientations[ i ] );
  714. }
  715. }
  716. }
  717. }
  718. }
  719. //-------------------------------------------------------------------------------------------------
  720. void ParticleUplinkCannonUpdate::createConnectorLasers( IntensityTypes intensity )
  721. {
  722. //Cache bone positions for the laser when it is ready to fire
  723. if( !m_upBonesCached )
  724. {
  725. calculateUpBonePositions();
  726. m_upBonesCached = TRUE;
  727. }
  728. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  729. AsciiString str;
  730. switch( intensity )
  731. {
  732. case IT_LIGHT:
  733. break;
  734. case IT_MEDIUM:
  735. str = data->m_connectorMediumLaserNameName;;
  736. break;
  737. case IT_INTENSE:
  738. str = data->m_connectorIntenseLaserNameName;
  739. break;
  740. case IT_FINISH:
  741. break;
  742. }
  743. if( str.isNotEmpty() )
  744. {
  745. const ThingTemplate *thingTemplate = TheThingFactory->findTemplate( str );
  746. if( thingTemplate )
  747. {
  748. for( int i = 0; i < data->m_outerEffectNumBones; i++ )
  749. {
  750. Drawable *beam = TheThingFactory->newDrawable( thingTemplate );
  751. if( beam )
  752. {
  753. m_laserBeamIDs[ i ] = beam->getID();
  754. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  755. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  756. if( update )
  757. {
  758. update->initLaser( NULL, NULL, &m_outerNodePositions[ i ], &m_connectorNodePosition, "" );
  759. }
  760. }
  761. }
  762. }
  763. }
  764. }
  765. //-------------------------------------------------------------------------------------------------
  766. void ParticleUplinkCannonUpdate::createConnectorFlare( IntensityTypes intensity )
  767. {
  768. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  769. AsciiString str;
  770. switch( intensity )
  771. {
  772. case IT_LIGHT:
  773. break;
  774. case IT_MEDIUM:
  775. str = data->m_connectorMediumFlareParticleSystemName;
  776. break;
  777. case IT_INTENSE:
  778. str = data->m_connectorIntenseFlareParticleSystemName;
  779. break;
  780. case IT_FINISH:
  781. break;
  782. }
  783. if( str.isNotEmpty() )
  784. {
  785. const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( str );
  786. ParticleSystem *system;
  787. if( tmp )
  788. {
  789. system = TheParticleSystemManager->createParticleSystem( tmp );
  790. if( system )
  791. {
  792. m_connectorSystemID = system->getSystemID();
  793. system->setPosition( &m_connectorNodePosition );
  794. }
  795. }
  796. }
  797. }
  798. //-------------------------------------------------------------------------------------------------
  799. void ParticleUplinkCannonUpdate::createLaserBaseFlare( IntensityTypes intensity )
  800. {
  801. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  802. AsciiString str;
  803. switch( intensity )
  804. {
  805. case IT_LIGHT:
  806. str = data->m_laserBaseLightFlareParticleSystemName;
  807. break;
  808. case IT_MEDIUM:
  809. str = data->m_laserBaseMediumFlareParticleSystemName;
  810. break;
  811. case IT_INTENSE:
  812. str = data->m_laserBaseIntenseFlareParticleSystemName;
  813. break;
  814. case IT_FINISH:
  815. break;
  816. }
  817. if( str.isNotEmpty() )
  818. {
  819. const ParticleSystemTemplate *tmp = TheParticleSystemManager->findTemplate( str );
  820. if( tmp )
  821. {
  822. ParticleSystem *system = TheParticleSystemManager->createParticleSystem( tmp );
  823. if( system )
  824. {
  825. m_laserBaseSystemID = system->getSystemID();
  826. system->setPosition( &m_laserOriginPosition );
  827. }
  828. }
  829. }
  830. }
  831. //-------------------------------------------------------------------------------------------------
  832. void ParticleUplinkCannonUpdate::createGroundToOrbitLaser( UnsignedInt growthFrames )
  833. {
  834. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  835. Drawable *beam = TheGameClient->findDrawableByID( m_groundToOrbitBeamID );
  836. if( beam )
  837. {
  838. TheGameClient->destroyDrawable( beam );
  839. m_orbitToTargetBeamID = INVALID_DRAWABLE_ID;
  840. }
  841. if( data->m_particleBeamLaserName.isNotEmpty() )
  842. {
  843. const ThingTemplate *thingTemplate = TheThingFactory->findTemplate( data->m_particleBeamLaserName );
  844. if( thingTemplate )
  845. {
  846. Drawable *beam = TheThingFactory->newDrawable( thingTemplate );
  847. if( beam )
  848. {
  849. m_groundToOrbitBeamID = beam->getID();
  850. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  851. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  852. if( update )
  853. {
  854. Coord3D orbitPosition;
  855. orbitPosition.set( &m_laserOriginPosition );
  856. orbitPosition.z += 500.0f;
  857. update->initLaser( NULL, NULL, &m_laserOriginPosition, &orbitPosition, "", growthFrames );
  858. }
  859. }
  860. }
  861. }
  862. }
  863. //-------------------------------------------------------------------------------------------------
  864. void ParticleUplinkCannonUpdate::createOrbitToTargetLaser( UnsignedInt growthFrames )
  865. {
  866. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  867. Drawable *beam = TheGameClient->findDrawableByID( m_orbitToTargetBeamID );
  868. if( beam )
  869. {
  870. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  871. TheGameClient->destroyDrawable( beam );
  872. m_orbitToTargetBeamID = INVALID_DRAWABLE_ID;
  873. }
  874. if( data->m_particleBeamLaserName.isNotEmpty() )
  875. {
  876. const ThingTemplate *thingTemplate = TheThingFactory->findTemplate( data->m_particleBeamLaserName );
  877. if( thingTemplate )
  878. {
  879. Drawable *beam = TheThingFactory->newDrawable( thingTemplate );
  880. if( beam )
  881. {
  882. m_orbitToTargetBeamID = beam->getID();
  883. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  884. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  885. if( update )
  886. {
  887. Coord3D orbitPosition;
  888. orbitPosition.set( &m_initialTargetPosition );
  889. orbitPosition.z += 500.0f;
  890. update->initLaser( NULL, NULL, &orbitPosition, &m_initialTargetPosition, "", growthFrames );
  891. }
  892. }
  893. }
  894. if( m_annihilationSound.getEventName().isNotEmpty() )
  895. {
  896. m_annihilationSound.setDrawableID( m_orbitToTargetBeamID );
  897. //m_annihilationSound.setPosition( &m_initialTargetPosition );
  898. m_annihilationSound.setPlayingHandle( TheAudio->addAudioEvent( &m_annihilationSound ) );
  899. }
  900. }
  901. }
  902. //-------------------------------------------------------------------------------------------------
  903. void ParticleUplinkCannonUpdate::createGroundHitParticleSystem( IntensityTypes intensity )
  904. {
  905. }
  906. //-------------------------------------------------------------------------------------------------
  907. void ParticleUplinkCannonUpdate::removeAllEffects()
  908. {
  909. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  910. for( int i = 0; i < data->m_outerEffectNumBones; i++ )
  911. {
  912. if( m_outerSystemIDs && m_outerSystemIDs[ i ] )
  913. {
  914. TheParticleSystemManager->destroyParticleSystemByID( m_outerSystemIDs[ i ] );
  915. m_outerSystemIDs[ i ] = INVALID_PARTICLE_SYSTEM_ID;
  916. }
  917. Drawable *beam = TheGameClient->findDrawableByID( m_laserBeamIDs[ i ] );
  918. if( beam )
  919. {
  920. TheGameClient->destroyDrawable( beam );
  921. m_laserBeamIDs[ i ] = INVALID_DRAWABLE_ID;
  922. }
  923. }
  924. if( m_connectorSystemID )
  925. {
  926. TheParticleSystemManager->destroyParticleSystemByID( m_connectorSystemID );
  927. m_connectorSystemID = INVALID_PARTICLE_SYSTEM_ID;
  928. }
  929. if( m_laserBaseSystemID )
  930. {
  931. TheParticleSystemManager->destroyParticleSystemByID( m_laserBaseSystemID );
  932. m_laserBaseSystemID = INVALID_PARTICLE_SYSTEM_ID;
  933. }
  934. Drawable *beam = TheGameClient->findDrawableByID( m_groundToOrbitBeamID );
  935. if( beam )
  936. {
  937. TheGameClient->destroyDrawable( beam );
  938. m_groundToOrbitBeamID = INVALID_DRAWABLE_ID;
  939. }
  940. //Remove all sound hooks
  941. }
  942. //-------------------------------------------------------------------------------------------------
  943. Bool ParticleUplinkCannonUpdate::calculateDefaultInformation()
  944. {
  945. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  946. Object *obj = getObject();
  947. //Get the local bone positions for each of the outer nodes.
  948. Coord3D bonePositions[ MAX_OUTER_NODES ];
  949. Matrix3D boneMatrices[ MAX_OUTER_NODES ];
  950. int numBones = obj->getMultiLogicalBonePosition( data->m_outerEffectBaseBoneName.str(), data->m_outerEffectNumBones, bonePositions, boneMatrices, FALSE );
  951. if( numBones != data->m_outerEffectNumBones )
  952. {
  953. DEBUG_CRASH( ("Particle cannon requires %d outer node bones, but can only find %d bones.", data->m_outerEffectNumBones, numBones ) );
  954. m_invalidSettings = TRUE;
  955. return FALSE;
  956. }
  957. for( int i = 0; i < data->m_outerEffectNumBones; i++ )
  958. {
  959. m_laserBeamIDs[ i ] = INVALID_DRAWABLE_ID;
  960. m_outerSystemIDs[ i ] = INVALID_PARTICLE_SYSTEM_ID;
  961. //Convert the local bone position into world space.
  962. Matrix3D nodeMatrix;
  963. getObject()->convertBonePosToWorldPos( &bonePositions[i], &boneMatrices[i], &m_outerNodePositions[ i ], &m_outerNodeOrientations[ i ] );
  964. }
  965. return TRUE;
  966. }
  967. //-------------------------------------------------------------------------------------------------
  968. Bool ParticleUplinkCannonUpdate::calculateUpBonePositions()
  969. {
  970. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  971. Object *obj = getObject();
  972. //Due to instant special weapons (or scripting)... it's possible to be in many states that are ready to fire (or firing)
  973. Drawable *draw = obj->getDrawable();
  974. Matrix3D mtx;
  975. Coord3D pos;
  976. if( draw )
  977. {
  978. if( data->m_connectorBoneName.isNotEmpty() && draw->getCurrentClientBonePositions( data->m_connectorBoneName.str(), 0, &pos, &mtx, 1 ) )
  979. {
  980. obj->convertBonePosToWorldPos( &pos, &mtx, &m_connectorNodePosition, &mtx );
  981. }
  982. if( data->m_connectorBoneName.isNotEmpty() && draw->getCurrentClientBonePositions( data->m_fireBoneName.str(), 0, &pos, &mtx, 1 ) )
  983. {
  984. obj->convertBonePosToWorldPos( &pos, &mtx, &m_laserOriginPosition, &mtx );
  985. }
  986. }
  987. return TRUE;
  988. }
  989. //-------------------------------------------------------------------------------------------------
  990. void ParticleUplinkCannonUpdate::setLogicalStatus( PUCStatus newStatus )
  991. {
  992. Object *obj = getObject();
  993. if( m_status == newStatus )
  994. {
  995. return;
  996. }
  997. //Handle entering new status
  998. switch( newStatus )
  999. {
  1000. case STATUS_IDLE:
  1001. {
  1002. //Set unpacked animation
  1003. obj->clearModelConditionFlags( MAKE_MODELCONDITION_MASK3( MODELCONDITION_PACKING, MODELCONDITION_UNPACKING, MODELCONDITION_DEPLOYED ) );
  1004. TheAudio->removeAudioEvent( m_powerupSound.getPlayingHandle() );
  1005. TheAudio->removeAudioEvent( m_unpackToReadySound.getPlayingHandle() );
  1006. TheAudio->removeAudioEvent( m_firingToIdleSound.getPlayingHandle() );
  1007. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  1008. break;
  1009. }
  1010. case STATUS_CHARGING:
  1011. {
  1012. m_laserStatus = LASERSTATUS_NONE;
  1013. m_powerupSound.setObjectID( obj->getID() );
  1014. m_powerupSound.setPlayingHandle( TheAudio->addAudioEvent( &m_powerupSound ) );
  1015. TheAudio->removeAudioEvent( m_unpackToReadySound.getPlayingHandle() );
  1016. TheAudio->removeAudioEvent( m_firingToIdleSound.getPlayingHandle() );
  1017. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  1018. break;
  1019. }
  1020. case STATUS_PREPARING:
  1021. {
  1022. //Set unpacking animation
  1023. obj->clearAndSetModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_PACKING, MODELCONDITION_DEPLOYED ),
  1024. MAKE_MODELCONDITION_MASK( MODELCONDITION_UNPACKING ) );
  1025. if( m_unpackToReadySound.getEventName().isNotEmpty() )
  1026. {
  1027. m_unpackToReadySound.setObjectID( obj->getID() );
  1028. m_unpackToReadySound.setPlayingHandle( TheAudio->addAudioEvent( &m_unpackToReadySound ) );
  1029. }
  1030. TheAudio->removeAudioEvent( m_firingToIdleSound.getPlayingHandle() );
  1031. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  1032. m_laserStatus = LASERSTATUS_NONE;
  1033. break;
  1034. }
  1035. case STATUS_ALMOST_READY:
  1036. {
  1037. //Set deployed animation
  1038. obj->clearAndSetModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_PACKING, MODELCONDITION_UNPACKING ),
  1039. MAKE_MODELCONDITION_MASK( MODELCONDITION_DEPLOYED ) );
  1040. m_laserStatus = LASERSTATUS_NONE;
  1041. break;
  1042. }
  1043. case STATUS_READY_TO_FIRE:
  1044. {
  1045. obj->clearAndSetModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_PACKING, MODELCONDITION_UNPACKING ),
  1046. MAKE_MODELCONDITION_MASK( MODELCONDITION_DEPLOYED ) );
  1047. TheAudio->removeAudioEvent( m_powerupSound.getPlayingHandle() );
  1048. TheAudio->removeAudioEvent( m_firingToIdleSound.getPlayingHandle() );
  1049. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  1050. m_laserStatus = LASERSTATUS_NONE;
  1051. break;
  1052. }
  1053. case STATUS_PREFIRE:
  1054. {
  1055. break;
  1056. }
  1057. case STATUS_FIRING:
  1058. {
  1059. obj->clearAndSetModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_PACKING, MODELCONDITION_UNPACKING ),
  1060. MAKE_MODELCONDITION_MASK( MODELCONDITION_DEPLOYED ) );
  1061. if( m_firingToIdleSound.getEventName().isNotEmpty() )
  1062. {
  1063. m_firingToIdleSound.setObjectID( obj->getID() );
  1064. m_firingToIdleSound.setPlayingHandle( TheAudio->addAudioEvent( &m_firingToIdleSound ) );
  1065. }
  1066. TheAudio->removeAudioEvent( m_powerupSound.getPlayingHandle() );
  1067. TheAudio->removeAudioEvent( m_unpackToReadySound.getPlayingHandle() );
  1068. TheAudio->removeAudioEvent( m_annihilationSound.getPlayingHandle() );
  1069. m_nextLaunchFXFrame = 0;
  1070. break;
  1071. }
  1072. case STATUS_POSTFIRE:
  1073. {
  1074. break;
  1075. }
  1076. case STATUS_PACKING:
  1077. {
  1078. //Set packing animation
  1079. obj->clearAndSetModelConditionFlags( MAKE_MODELCONDITION_MASK2( MODELCONDITION_UNPACKING, MODELCONDITION_DEPLOYED ),
  1080. MAKE_MODELCONDITION_MASK( MODELCONDITION_PACKING ) );
  1081. break;
  1082. }
  1083. }
  1084. //Set new status.
  1085. m_status = newStatus;
  1086. setClientStatus( m_status, FALSE );
  1087. }
  1088. //-------------------------------------------------------------------------------------------------
  1089. void ParticleUplinkCannonUpdate::setClientStatus( PUCStatus newStatus, Bool revealThisFrame )
  1090. {
  1091. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  1092. //Caches bone positions for positioning the client beams.
  1093. if( !m_defaultInfoCached )
  1094. {
  1095. if( !calculateDefaultInformation() )
  1096. {
  1097. m_invalidSettings = TRUE;
  1098. return;
  1099. }
  1100. m_defaultInfoCached = TRUE;
  1101. }
  1102. //This isn't the most efficient way to do this. Various effects can live in more than
  1103. //one status state, but keeping track of them properly is error-prone and hard to read.
  1104. //Therefore, the new philosophy is to delete EVERYTHING between status changes and
  1105. //create the ones we want!
  1106. removeAllEffects();
  1107. //Handle entering new status
  1108. switch( newStatus )
  1109. {
  1110. case STATUS_IDLE:
  1111. {
  1112. break;
  1113. }
  1114. case STATUS_CHARGING:
  1115. {
  1116. createOuterNodeParticleSystems( IT_LIGHT );
  1117. break;
  1118. }
  1119. case STATUS_PREPARING:
  1120. {
  1121. createOuterNodeParticleSystems( IT_MEDIUM );
  1122. break;
  1123. }
  1124. case STATUS_ALMOST_READY:
  1125. {
  1126. createOuterNodeParticleSystems( IT_MEDIUM );
  1127. createConnectorLasers( IT_MEDIUM );
  1128. createConnectorFlare( IT_MEDIUM );
  1129. break;
  1130. }
  1131. case STATUS_READY_TO_FIRE:
  1132. {
  1133. createOuterNodeParticleSystems( IT_MEDIUM );
  1134. createConnectorLasers( IT_MEDIUM );
  1135. createConnectorFlare( IT_MEDIUM );
  1136. createLaserBaseFlare( IT_LIGHT );
  1137. break;
  1138. }
  1139. case STATUS_PREFIRE:
  1140. {
  1141. break;
  1142. }
  1143. case STATUS_FIRING:
  1144. {
  1145. if( revealThisFrame )
  1146. {
  1147. createGroundToOrbitLaser( 0 );
  1148. }
  1149. else
  1150. {
  1151. createGroundToOrbitLaser( data->m_widthGrowFrames );
  1152. }
  1153. createOuterNodeParticleSystems( IT_INTENSE );
  1154. createConnectorLasers( IT_INTENSE );
  1155. createConnectorFlare( IT_INTENSE );
  1156. createLaserBaseFlare( IT_INTENSE );
  1157. break;
  1158. }
  1159. case STATUS_POSTFIRE:
  1160. {
  1161. createOuterNodeParticleSystems( IT_MEDIUM );
  1162. createConnectorLasers( IT_MEDIUM );
  1163. createConnectorFlare( IT_MEDIUM );
  1164. createLaserBaseFlare( IT_MEDIUM );
  1165. createGroundToOrbitLaser( 0 );
  1166. Drawable *beam = TheGameClient->findDrawableByID( m_groundToOrbitBeamID );
  1167. if( beam )
  1168. {
  1169. static NameKeyType nameKeyClientUpdate = NAMEKEY( "LaserUpdate" );
  1170. LaserUpdate *update = (LaserUpdate*)beam->findClientUpdateModule( nameKeyClientUpdate );
  1171. if( update )
  1172. {
  1173. if( revealThisFrame )
  1174. {
  1175. update->setDecayFrames( 0 );
  1176. }
  1177. else
  1178. {
  1179. update->setDecayFrames( data->m_widthGrowFrames );
  1180. }
  1181. }
  1182. }
  1183. break;
  1184. }
  1185. case STATUS_PACKING:
  1186. {
  1187. break;
  1188. }
  1189. }
  1190. }
  1191. //-------------------------------------------------------------------------------------------------
  1192. Bool ParticleUplinkCannonUpdate::doesSpecialPowerHaveOverridableDestinationActive() const
  1193. {
  1194. return m_status == STATUS_PREFIRE || m_status == STATUS_FIRING || m_status == STATUS_POSTFIRE;
  1195. }
  1196. // ------------------------------------------------------------------------------------------------
  1197. /** CRC */
  1198. // ------------------------------------------------------------------------------------------------
  1199. void ParticleUplinkCannonUpdate::crc( Xfer *xfer )
  1200. {
  1201. // extend base class
  1202. UpdateModule::crc( xfer );
  1203. } // end crc
  1204. // ------------------------------------------------------------------------------------------------
  1205. /** Xfer method
  1206. * Version Info:
  1207. * 1: Initial version */
  1208. // ------------------------------------------------------------------------------------------------
  1209. void ParticleUplinkCannonUpdate::xfer( Xfer *xfer )
  1210. {
  1211. const ParticleUplinkCannonUpdateModuleData *data = getParticleUplinkCannonUpdateModuleData();
  1212. // version
  1213. XferVersion currentVersion = 3;
  1214. XferVersion version = currentVersion;
  1215. xfer->xferVersion( &version, currentVersion );
  1216. // extend base class
  1217. UpdateModule::xfer( xfer );
  1218. // status
  1219. xfer->xferUser( &m_status, sizeof( PUCStatus ) );
  1220. // laser status
  1221. xfer->xferUser( &m_laserStatus, sizeof( LaserStatus ) );
  1222. // frames
  1223. xfer->xferUnsignedInt( &m_frames );
  1224. // we do not need to tie up the special power module pointer, it is done on object creation
  1225. // SpecialPowerModuleInterface *m_specialPowerModule;
  1226. // outer system ids
  1227. xfer->xferUser( m_outerSystemIDs, sizeof( ParticleSystemID ) * MAX_OUTER_NODES );
  1228. // laser beam ids
  1229. xfer->xferUser( m_laserBeamIDs, sizeof( DrawableID ) * MAX_OUTER_NODES );
  1230. // ground to orbit beam id
  1231. xfer->xferDrawableID( &m_groundToOrbitBeamID );
  1232. // orbit to target beam
  1233. xfer->xferDrawableID( &m_orbitToTargetBeamID );
  1234. // connector system ID
  1235. xfer->xferUser( &m_connectorSystemID, sizeof( ParticleSystemID ) );
  1236. // laser base system id
  1237. xfer->xferUser( &m_laserBaseSystemID, sizeof( ParticleSystemID ) );
  1238. // outer node positions
  1239. xfer->xferUser( m_outerNodePositions, sizeof( Coord3D ) * MAX_OUTER_NODES );
  1240. // outer node orientations
  1241. xfer->xferUser( m_outerNodeOrientations, sizeof( Matrix3D ) * MAX_OUTER_NODES );
  1242. // connector node position
  1243. xfer->xferCoord3D( &m_connectorNodePosition );
  1244. // laser origin position
  1245. xfer->xferCoord3D( &m_laserOriginPosition );
  1246. // The manual override target destination.
  1247. xfer->xferCoord3D( &m_overrideTargetDestination );
  1248. // up bones cached
  1249. xfer->xferBool( &m_upBonesCached );
  1250. // default info cached
  1251. xfer->xferBool( &m_defaultInfoCached );
  1252. // invalid settings
  1253. xfer->xferBool( &m_invalidSettings );
  1254. // initial target position
  1255. xfer->xferCoord3D( &m_initialTargetPosition );
  1256. // current target position
  1257. xfer->xferCoord3D( &m_currentTargetPosition );
  1258. // scorch marks make
  1259. xfer->xferUnsignedInt( &m_scorchMarksMade );
  1260. // next scorch mark frame
  1261. xfer->xferUnsignedInt( &m_nextScorchMarkFrame );
  1262. // next launch FX frame
  1263. xfer->xferUnsignedInt( &m_nextLaunchFXFrame );
  1264. // damage pluses made
  1265. xfer->xferUnsignedInt( &m_damagePulsesMade );
  1266. // next damage pulse frame
  1267. xfer->xferUnsignedInt( &m_nextDamagePulseFrame );
  1268. // start attack frame
  1269. xfer->xferUnsignedInt( &m_startAttackFrame );
  1270. // start attack frame
  1271. if( xfer->getXferMode() == XFER_SAVE || version >= 2 )
  1272. {
  1273. xfer->xferUnsignedInt( &m_startDecayFrame );
  1274. }
  1275. else
  1276. {
  1277. m_startDecayFrame = m_startAttackFrame + data->m_totalFiringFrames;
  1278. }
  1279. // the time of last manual target click
  1280. xfer->xferUnsignedInt( & m_lastDrivingClickFrame );
  1281. // the time of the 2nd last manual target click
  1282. xfer->xferUnsignedInt( &m_2ndLastDrivingClickFrame );
  1283. if( version >= 3 )
  1284. {
  1285. xfer->xferBool( &m_manualTargetMode );
  1286. xfer->xferBool( &m_scriptedWaypointMode );
  1287. xfer->xferUnsignedInt( &m_nextDestWaypointID );
  1288. }
  1289. } // end xfer
  1290. // ------------------------------------------------------------------------------------------------
  1291. /** Load post process */
  1292. // ------------------------------------------------------------------------------------------------
  1293. void ParticleUplinkCannonUpdate::loadPostProcess( void )
  1294. {
  1295. // extend base class
  1296. UpdateModule::loadPostProcess();
  1297. } // end loadPostProcess