FlightDeckBehavior.cpp 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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: FlightDeckBehavior.cpp ///////////////////////////////////////////////////////////////////
  24. // Author: Kris Morness, May 2003
  25. // Desc: Handles aircraft movement and parking behavior for aircraft carriers.
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/CRCDebug.h"
  30. #include "Common/Player.h"
  31. #include "Common/Team.h"
  32. #include "Common/ThingFactory.h"
  33. #include "Common/ThingTemplate.h"
  34. #include "Common/Xfer.h"
  35. #include "GameClient/Drawable.h"
  36. #include "GameClient/ParticleSys.h"
  37. #include "GameLogic/AI.h"
  38. #include "GameLogic/AIPathfind.h"
  39. #include "GameLogic/GameLogic.h"
  40. #include "GameLogic/Object.h"
  41. #include "GameLogic/PartitionManager.h"
  42. #include "GameLogic/TerrainLogic.h"
  43. #include "GameLogic/Weapon.h"
  44. #include "GameLogic/Module/FlightDeckBehavior.h"
  45. #include "GameLogic/Module/JetAIUpdate.h"
  46. #include "GameLogic/Module/ProductionUpdate.h"
  47. #ifdef _INTERNAL
  48. // for occasional debugging...
  49. //#pragma optimize("", off)
  50. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  51. #endif
  52. FlightDeckBehaviorModuleData::FlightDeckBehaviorModuleData()
  53. {
  54. //m_framesForFullHeal = 0;
  55. m_healAmount = 0;
  56. m_numRows = 0;
  57. m_numCols = 0;
  58. m_approachHeight = 0.0f;
  59. m_landingDeckHeightOffset = 0.0f;
  60. m_dockAnimationFrames = 0;
  61. m_catapultFireFrames = 0;
  62. }
  63. //-------------------------------------------------------------------------------------------------
  64. void FlightDeckBehaviorModuleData::parseRunwayStrip( INI* ini, void *instance, void *store, const void* /*userData*/ )
  65. {
  66. AsciiString *runwayNames = (AsciiString*)store;
  67. const char *token = ini->getNextTokenOrNull();
  68. if( token )
  69. {
  70. runwayNames[ RUNWAY_START_BONE ].format( token );
  71. token = ini->getNextTokenOrNull();
  72. if( token )
  73. {
  74. runwayNames[ RUNWAY_END_BONE ].format( token );
  75. }
  76. }
  77. }
  78. //-------------------------------------------------------------------------------------------------
  79. void FlightDeckBehaviorModuleData::buildFieldParse(MultiIniFieldParse& p)
  80. {
  81. AIUpdateModuleData::buildFieldParse(p);
  82. static const FieldParse dataFieldParse[] =
  83. {
  84. { "NumRunways", INI::parseInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_numCols ) },
  85. { "NumSpacesPerRunway", INI::parseInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_numRows ) },
  86. { "Runway1Spaces", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_spacesBoneNames ) },
  87. { "Runway1Takeoff", parseRunwayStrip, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_takeoffBoneNames ) },
  88. { "Runway1Landing", parseRunwayStrip, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_landingBoneNames ) },
  89. { "Runway1Taxi", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_taxiBoneNames ) },
  90. { "Runway1Creation", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_creationBoneNames ) },
  91. { "Runway1CatapultSystem", INI::parseParticleSystemTemplate, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 0 ].m_catapultParticleSystem ) },
  92. { "Runway2Spaces", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_spacesBoneNames ) },
  93. { "Runway2Takeoff", parseRunwayStrip, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_takeoffBoneNames ) },
  94. { "Runway2Landing", parseRunwayStrip, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_landingBoneNames ) },
  95. { "Runway2Taxi", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_taxiBoneNames ) },
  96. { "Runway2Creation", INI::parseAsciiStringVector, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_creationBoneNames ) },
  97. { "Runway2CatapultSystem", INI::parseParticleSystemTemplate, NULL, offsetof( FlightDeckBehaviorModuleData, m_runwayInfo[ 1 ].m_catapultParticleSystem ) },
  98. { "ApproachHeight", INI::parseReal, NULL, offsetof( FlightDeckBehaviorModuleData, m_approachHeight ) },
  99. { "LandingDeckHeightOffset",INI::parseReal, NULL, offsetof( FlightDeckBehaviorModuleData, m_landingDeckHeightOffset ) },
  100. { "HealAmountPerSecond", INI::parseReal, NULL, offsetof( FlightDeckBehaviorModuleData, m_healAmount ) },
  101. { "ParkingCleanupPeriod", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_cleanupFrames ) },
  102. { "HumanFollowPeriod", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_humanFollowFrames ) },
  103. { "PayloadTemplate", INI::parseAsciiString, NULL, offsetof( FlightDeckBehaviorModuleData, m_thingTemplateName ) },
  104. { "ReplacementDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_replacementFrames ) },
  105. { "DockAnimationDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_dockAnimationFrames ) },
  106. { "LaunchWaveDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_launchWaveFrames ) },
  107. { "LaunchRampDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_launchRampFrames ) },
  108. { "LowerRampDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_lowerRampFrames ) },
  109. { "CatapultFireDelay", INI::parseDurationUnsignedInt, NULL, offsetof( FlightDeckBehaviorModuleData, m_catapultFireFrames ) },
  110. { 0, 0, 0, 0 }
  111. };
  112. p.add(dataFieldParse);
  113. }
  114. //-------------------------------------------------------------------------------------------------
  115. //-------------------------------------------------------------------------------------------------
  116. FlightDeckBehavior::FlightDeckBehavior( Thing *thing, const ModuleData* moduleData ) : AIUpdateInterface( thing, moduleData )
  117. {
  118. m_gotInfo = false;
  119. m_nextHealFrame = FOREVER;
  120. setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  121. m_nextCleanupFrame = 0;
  122. m_startedProductionFrame = FOREVER;
  123. m_nextAllowedProductionFrame = 0;
  124. m_designatedTarget = INVALID_ID;
  125. m_designatedCommand = AICMD_NO_COMMAND;
  126. m_designatedPosition.zero();
  127. for( int i = 0; i < MAX_RUNWAYS; i++ )
  128. {
  129. m_nextLaunchWaveFrame[ i ] = 0;
  130. m_rampUpFrame[ i ] = 0;
  131. m_catapultSystemFrame[ i ] = 0;
  132. m_lowerRampFrame[ i ] = 0;
  133. m_rampUp[ i ] = FALSE;
  134. }
  135. m_thingTemplate = NULL;
  136. }
  137. //-------------------------------------------------------------------------------------------------
  138. //-------------------------------------------------------------------------------------------------
  139. FlightDeckBehavior::~FlightDeckBehavior( void )
  140. {
  141. }
  142. //-------------------------------------------------------------------------------------------------
  143. //-------------------------------------------------------------------------------------------------
  144. void FlightDeckBehavior::buildInfo(Bool createUnits)
  145. {
  146. if (m_gotInfo)
  147. return;
  148. const FlightDeckBehaviorModuleData* data = getFlightDeckBehaviorModuleData();
  149. m_thingTemplate = TheThingFactory->findTemplate( data->m_thingTemplateName );
  150. if (getObject()->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION) ||
  151. getObject()->testStatus(OBJECT_STATUS_SOLD))
  152. return;
  153. //ProductionUpdateInterface* pu = getObject()->getProductionUpdateInterface();
  154. m_spaces.reserve( data->m_numRows * data->m_numCols );
  155. //Initialize the spaces that planes will eventually be assigned to for parking purposes
  156. FlightDeckInfo flightDeckInfo;
  157. //We want to sort the spaces so that we have runway 1 space 1, runway 2 space 1, R1S2, R2S2, R1S3...
  158. for( Int row = 0; row < data->m_numRows; row++ )
  159. {
  160. for( Int col = 0; col < data->m_numCols; col++ )
  161. {
  162. std::vector<AsciiString> spaces = data->m_runwayInfo[ col ].m_spacesBoneNames;
  163. std::vector<AsciiString>::const_iterator it;
  164. Int counter = 0;
  165. for( it = spaces.begin(); it != spaces.end(), counter < row; it++, counter++ )
  166. {
  167. //just iterate to the spaces.
  168. }
  169. AsciiString tmp;
  170. Matrix3D mtx;
  171. //Convert the module data bone names into coordinates that we can use
  172. getObject()->getSingleLogicalBonePosition( it->str(), &flightDeckInfo.m_prep, &mtx );
  173. flightDeckInfo.m_orientation = mtx.Get_Z_Rotation();
  174. //Init basic runway stuff
  175. flightDeckInfo.m_runway = col;
  176. flightDeckInfo.m_objectInSpace = INVALID_ID;
  177. //Create the payload
  178. Object *jet = NULL;
  179. if( m_thingTemplate && createUnits )
  180. {
  181. jet = TheThingFactory->newObject( m_thingTemplate, getObject()->getControllingPlayer()->getDefaultTeam() );
  182. if( jet )
  183. {
  184. jet->setProducer( getObject() );
  185. jet->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_DECK_HEIGHT_OFFSET ) );
  186. //Init positioning.
  187. jet->setPosition( &flightDeckInfo.m_prep );
  188. jet->setOrientation( flightDeckInfo.m_orientation );
  189. //Assign jet to space
  190. flightDeckInfo.m_objectInSpace = jet->getID();
  191. //validateAssignments();
  192. }
  193. }
  194. m_spaces.push_back( flightDeckInfo );
  195. }
  196. }
  197. //Now initialize the runway take-off and landing information.
  198. RunwayInfo info;
  199. m_runways.reserve(data->m_numCols);
  200. for( Int col = 0; col < data->m_numCols; ++col )
  201. {
  202. AsciiString tmp;
  203. getObject()->getSingleLogicalBonePosition( data->m_runwayInfo[ col ].m_takeoffBoneNames[ RUNWAY_START_BONE ].str(), &info.m_start, NULL);
  204. getObject()->getSingleLogicalBonePosition( data->m_runwayInfo[ col ].m_takeoffBoneNames[ RUNWAY_END_BONE ].str(), &info.m_end, NULL);
  205. getObject()->getSingleLogicalBonePosition( data->m_runwayInfo[ col ].m_landingBoneNames[ RUNWAY_START_BONE ].str(), &info.m_landingStart, NULL);
  206. getObject()->getSingleLogicalBonePosition( data->m_runwayInfo[ col ].m_landingBoneNames[ RUNWAY_END_BONE ].str(), &info.m_landingEnd, NULL);
  207. info.m_inUseByForTakeoff = INVALID_ID;
  208. info.m_inUseByForLanding = INVALID_ID;
  209. //Get the taxi bones and store them as well (possible to have none!)
  210. std::vector<AsciiString> locations = data->m_runwayInfo[ col ].m_taxiBoneNames;
  211. std::vector<AsciiString>::const_iterator it;
  212. info.m_taxi.clear();
  213. for( it = locations.begin(); it != locations.end(); it++ )
  214. {
  215. Coord3D taxiPos;
  216. Matrix3D mtx;
  217. //Get the position of the taxi bone.
  218. getObject()->getSingleLogicalBonePosition( it->str(), &taxiPos, &mtx );
  219. //Add it to the taxi vector
  220. info.m_taxi.push_back( taxiPos );
  221. }
  222. //Get the creation bones and store them as well
  223. locations = data->m_runwayInfo[ col ].m_creationBoneNames;
  224. info.m_creation.clear();
  225. Bool firstTime = TRUE;
  226. for( it = locations.begin(); it != locations.end(); it++ )
  227. {
  228. Coord3D pos;
  229. Matrix3D mtx;
  230. //Get the position of the creation bone.
  231. getObject()->getSingleLogicalBonePosition( it->str(), &pos, &mtx );
  232. if( firstTime )
  233. {
  234. firstTime = FALSE;
  235. info.m_startOrient = mtx.Get_Z_Rotation();
  236. info.m_startTransform = mtx;
  237. }
  238. //Add it to the taxi vector
  239. info.m_creation.push_back( pos );
  240. }
  241. m_runways.push_back(info);
  242. }
  243. m_gotInfo = true;
  244. }
  245. //-------------------------------------------------------------------------------------------------
  246. void FlightDeckBehavior::purgeDead()
  247. {
  248. buildInfo();
  249. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  250. {
  251. if (it->m_objectInSpace != INVALID_ID)
  252. {
  253. Object* obj = TheGameLogic->findObjectByID(it->m_objectInSpace);
  254. if (obj == NULL || obj->isEffectivelyDead())
  255. {
  256. it->m_objectInSpace = INVALID_ID;
  257. }
  258. }
  259. }
  260. {
  261. for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
  262. {
  263. if (it->m_inUseByForTakeoff != INVALID_ID)
  264. {
  265. Object* obj = TheGameLogic->findObjectByID(it->m_inUseByForTakeoff);
  266. if (obj == NULL || obj->isEffectivelyDead())
  267. {
  268. it->m_inUseByForTakeoff = INVALID_ID;
  269. }
  270. }
  271. if (it->m_inUseByForLanding != INVALID_ID)
  272. {
  273. Object* obj = TheGameLogic->findObjectByID(it->m_inUseByForLanding);
  274. if (obj == NULL || obj->isEffectivelyDead())
  275. {
  276. it->m_inUseByForLanding = INVALID_ID;
  277. }
  278. }
  279. }
  280. }
  281. {
  282. Bool anythingPurged = false;
  283. for (std::list<HealingInfo>::iterator it = m_healing.begin(); it != m_healing.end(); /*++it*/)
  284. {
  285. if (it->m_gettingHealedID != INVALID_ID)
  286. {
  287. Object* objToHeal = TheGameLogic->findObjectByID(it->m_gettingHealedID);
  288. if (objToHeal == NULL || objToHeal->isEffectivelyDead())
  289. {
  290. it = m_healing.erase(it);
  291. anythingPurged = true;
  292. }
  293. else
  294. {
  295. ++it;
  296. }
  297. }
  298. }
  299. if (anythingPurged)
  300. resetWakeFrame();
  301. }
  302. }
  303. //-------------------------------------------------------------------------------------------------
  304. // note: called from client, so MUST NOT modify self in any way, or desyncs will occur
  305. Bool FlightDeckBehavior::hasReservedSpace(ObjectID id) const
  306. {
  307. if (!m_gotInfo)
  308. return false;
  309. if (id == INVALID_ID) // shouldn't call this way, but Weapon mistakenly does sometimes, so check for it
  310. return false;
  311. for (std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  312. {
  313. if (it->m_objectInSpace == id)
  314. return true;
  315. }
  316. return false;
  317. }
  318. //-------------------------------------------------------------------------------------------------
  319. Int FlightDeckBehavior::getSpaceIndex( ObjectID id ) const
  320. {
  321. if( id == INVALID_ID )
  322. {
  323. return -1;
  324. }
  325. Int index = 0;
  326. for( std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); it++, index++ )
  327. {
  328. if (it->m_objectInSpace == id)
  329. {
  330. return index;
  331. }
  332. }
  333. return -1;
  334. }
  335. //-------------------------------------------------------------------------------------------------
  336. FlightDeckBehavior::FlightDeckInfo* FlightDeckBehavior::findPPI(ObjectID id)
  337. {
  338. DEBUG_ASSERTCRASH(id != INVALID_ID, ("call findEmptyPPI instead"));
  339. if (!m_gotInfo || id == INVALID_ID)
  340. return NULL;
  341. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  342. {
  343. if (it->m_objectInSpace == id)
  344. return it;
  345. }
  346. return NULL;
  347. }
  348. //-------------------------------------------------------------------------------------------------
  349. FlightDeckBehavior::FlightDeckInfo* FlightDeckBehavior::findEmptyPPI()
  350. {
  351. if (!m_gotInfo)
  352. return NULL;
  353. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  354. {
  355. if( it->m_objectInSpace == INVALID_ID )
  356. return it;
  357. }
  358. return NULL;
  359. }
  360. //-------------------------------------------------------------------------------------------------
  361. // note: called from client, so MUST NOT modify self in any way, or desyncs will occur
  362. Bool FlightDeckBehavior::shouldReserveDoorWhenQueued(const ThingTemplate* thing) const
  363. {
  364. return true;
  365. }
  366. //-------------------------------------------------------------------------------------------------
  367. // note: called from client, so MUST NOT modify self in any way, or desyncs will occur
  368. Bool FlightDeckBehavior::hasAvailableSpaceFor(const ThingTemplate* thing) const
  369. {
  370. if (!m_gotInfo) // degenerate case, shouldn't happen, but just in case...
  371. return false;
  372. for (std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  373. {
  374. ObjectID id = it->m_objectInSpace;
  375. // since this is const, and we can't purge the dead safely, just peek and see if we have a dead thing.
  376. if (id != INVALID_ID)
  377. {
  378. Object* obj = TheGameLogic->findObjectByID(id);
  379. if (obj == NULL || obj->isEffectivelyDead())
  380. {
  381. id = INVALID_ID;
  382. }
  383. }
  384. if( id == INVALID_ID )
  385. {
  386. return true;
  387. }
  388. }
  389. return false;
  390. }
  391. //-------------------------------------------------------------------------------------------------
  392. Bool FlightDeckBehavior::reserveSpace(ObjectID id, Real parkingOffset, ParkingPlaceBehaviorInterface::PPInfo* info)
  393. {
  394. buildInfo();
  395. purgeDead();
  396. const FlightDeckBehaviorModuleData* d = getFlightDeckBehaviorModuleData();
  397. FlightDeckInfo* ppi = findPPI(id);
  398. if (ppi == NULL)
  399. {
  400. ppi = findEmptyPPI();
  401. if (ppi == NULL)
  402. {
  403. DEBUG_CRASH(("No parking places!"));
  404. return false; // nothing available
  405. }
  406. }
  407. ppi->m_objectInSpace = id;
  408. //validateAssignments();
  409. if( d->m_landingDeckHeightOffset )
  410. {
  411. Object *obj = TheGameLogic->findObjectByID( id );
  412. if( obj )
  413. {
  414. obj->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_DECK_HEIGHT_OFFSET ) );
  415. }
  416. }
  417. if( info )
  418. {
  419. calcPPInfo( id, info );
  420. if (parkingOffset != 0.0f)
  421. {
  422. info->parkingSpace.x += parkingOffset * Cos(ppi->m_orientation);
  423. info->parkingSpace.y += parkingOffset * Sin(ppi->m_orientation);
  424. }
  425. }
  426. return true;
  427. }
  428. //-------------------------------------------------------------------------------------------------
  429. void FlightDeckBehavior::validateAssignments()
  430. {
  431. Int index = 0, index2 = 0;
  432. for( std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); it++, index++ )
  433. {
  434. ObjectID id = it->m_objectInSpace;
  435. if( id != INVALID_ID )
  436. {
  437. for( std::vector<FlightDeckInfo>::const_iterator it2 = it; it2 != m_spaces.end(); it2++, index2++ )
  438. {
  439. if( it == it2 )
  440. {
  441. continue;
  442. }
  443. ObjectID id2 = it2->m_objectInSpace;
  444. if( id == id2 )
  445. {
  446. DEBUG_CRASH( ("Aircraft %d assigned to multiple spaces %d and %d", id, index, index2 ) );
  447. }
  448. }
  449. }
  450. }
  451. }
  452. //-------------------------------------------------------------------------------------------------
  453. void FlightDeckBehavior::calcPPInfo( ObjectID id, PPInfo *info )
  454. {
  455. FlightDeckInfo *ppi = findPPI( id );
  456. if( !ppi )
  457. {
  458. //Utter failure.
  459. return;
  460. }
  461. const RunwayInfo& rr = m_runways[ ppi->m_runway ];
  462. if( info )
  463. {
  464. const FlightDeckBehaviorModuleData* d = getFlightDeckBehaviorModuleData();
  465. const Real APPROACH_DIST = 0.75f;
  466. info->parkingSpace = ppi->m_prep;
  467. info->runwayPrep = ppi->m_prep;
  468. info->parkingOrientation = ppi->m_orientation;
  469. info->runwayStart = rr.m_start;
  470. info->runwayEnd = rr.m_end;
  471. info->runwayExit = rr.m_end;
  472. info->runwayExit.x += (rr.m_end.x - rr.m_start.x) * APPROACH_DIST;
  473. info->runwayExit.y += (rr.m_end.y - rr.m_start.y) * APPROACH_DIST;
  474. info->runwayExit.z = rr.m_end.z + d->m_approachHeight + d->m_landingDeckHeightOffset;
  475. info->runwayLandingStart = rr.m_landingStart;
  476. info->runwayLandingEnd = rr.m_landingEnd;
  477. info->runwayApproach = rr.m_landingStart;
  478. info->runwayApproach.x += (rr.m_landingStart.x - rr.m_landingEnd.x) * APPROACH_DIST;
  479. info->runwayApproach.y += (rr.m_landingStart.y - rr.m_landingEnd.y) * APPROACH_DIST;
  480. info->runwayApproach.z = rr.m_landingStart.z + d->m_approachHeight + d->m_landingDeckHeightOffset;
  481. //Cache the runway's takeoff distance used by JetAIUpdate for calculating lift.
  482. Coord3D vector = info->runwayStart;
  483. vector.sub( &info->runwayEnd );
  484. info->runwayTakeoffDist = vector.length();
  485. for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
  486. {
  487. if (it->m_inUseByForTakeoff == id )
  488. {
  489. info->runwayStart = info->runwayPrep;
  490. }
  491. }
  492. }
  493. }
  494. //-------------------------------------------------------------------------------------------------
  495. void FlightDeckBehavior::releaseSpace(ObjectID id)
  496. {
  497. buildInfo();
  498. purgeDead();
  499. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  500. {
  501. if (it->m_objectInSpace == id)
  502. {
  503. it->m_objectInSpace = INVALID_ID;
  504. }
  505. }
  506. Object *obj = TheGameLogic->findObjectByID( id );
  507. if( obj )
  508. {
  509. obj->clearStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_DECK_HEIGHT_OFFSET ) );
  510. }
  511. }
  512. //-------------------------------------------------------------------------------------------------
  513. ObjectID FlightDeckBehavior::getRunwayReservation( Int runway, RunwayReservationType type )
  514. {
  515. buildInfo();
  516. purgeDead();
  517. switch( type )
  518. {
  519. case RESERVATION_TAKEOFF:
  520. return m_runways[runway].m_inUseByForTakeoff;
  521. case RESERVATION_LANDING:
  522. return m_runways[runway].m_inUseByForLanding;
  523. default:
  524. return INVALID_ID;
  525. }
  526. }
  527. //-------------------------------------------------------------------------------------------------
  528. void FlightDeckBehavior::transferRunwayReservationToNextInLineForTakeoff(ObjectID id)
  529. {
  530. //Aircraft carrier controls this functionality with an iron fist.
  531. }
  532. //-------------------------------------------------------------------------------------------------
  533. Bool FlightDeckBehavior::reserveRunway(ObjectID id, Bool forLanding)
  534. {
  535. buildInfo();
  536. purgeDead();
  537. Int runway = -1;
  538. if( !forLanding )
  539. {
  540. //Only look at the front spaces for takeoff. You can't take off from the back!
  541. const FlightDeckBehaviorModuleData *data = getFlightDeckBehaviorModuleData();
  542. for( Int i = 0; i < data->m_numCols; i++ )
  543. {
  544. if( m_spaces[ i ].m_objectInSpace == id )
  545. {
  546. runway = m_spaces[ i ].m_runway;
  547. break;
  548. }
  549. }
  550. }
  551. else
  552. {
  553. //Look at all spaces for landing.
  554. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  555. {
  556. if (it->m_objectInSpace == id)
  557. {
  558. runway = it->m_runway;
  559. break;
  560. }
  561. }
  562. }
  563. if (runway == -1)
  564. {
  565. if( forLanding )
  566. {
  567. DEBUG_CRASH(("only planes with reserved spaces can reserve runways"));
  568. }
  569. return false;
  570. }
  571. RunwayInfo& info = m_runways[runway];
  572. if( info.m_inUseByForTakeoff == id && !forLanding || info.m_inUseByForLanding == id && forLanding )
  573. {
  574. return true;
  575. }
  576. else if( info.m_inUseByForTakeoff == INVALID_ID && !forLanding || info.m_inUseByForLanding == INVALID_ID && forLanding )
  577. {
  578. if( forLanding )
  579. {
  580. info.m_inUseByForLanding = id;
  581. }
  582. else
  583. {
  584. info.m_inUseByForTakeoff = id;
  585. }
  586. return true;
  587. }
  588. return false;
  589. }
  590. //-------------------------------------------------------------------------------------------------
  591. void FlightDeckBehavior::releaseRunway(ObjectID id)
  592. {
  593. buildInfo();
  594. purgeDead();
  595. for (std::vector<RunwayInfo>::iterator it = m_runways.begin(); it != m_runways.end(); ++it)
  596. {
  597. if( it->m_inUseByForTakeoff == id )
  598. {
  599. it->m_inUseByForTakeoff = INVALID_ID;
  600. }
  601. if( it->m_inUseByForLanding == id )
  602. {
  603. it->m_inUseByForLanding = INVALID_ID;
  604. }
  605. }
  606. }
  607. //-------------------------------------------------------------------------------------------------
  608. const std::vector<Coord3D>* FlightDeckBehavior::getTaxiLocations( ObjectID id ) const
  609. {
  610. //Find the runway the object is assigned to.
  611. Int runway = -1;
  612. for( std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); it++ )
  613. {
  614. if( it->m_objectInSpace == id )
  615. {
  616. runway = it->m_runway;
  617. break;
  618. }
  619. }
  620. if( runway == -1 )
  621. {
  622. DEBUG_CRASH(("only planes with reserved spaces can reserve runways"));
  623. return NULL;
  624. }
  625. //Now get the runway we're assigned to and return it's taxi vector
  626. return &(m_runways[ runway ].m_taxi);
  627. }
  628. //-------------------------------------------------------------------------------------------------
  629. const std::vector<Coord3D>* FlightDeckBehavior::getCreationLocations( ObjectID id ) const
  630. {
  631. //Find the runway the object is assigned to.
  632. Int runway = -1;
  633. for( std::vector<FlightDeckInfo>::const_iterator it = m_spaces.begin(); it != m_spaces.end(); it++ )
  634. {
  635. if( it->m_objectInSpace == id )
  636. {
  637. runway = it->m_runway;
  638. break;
  639. }
  640. }
  641. if( runway == -1 )
  642. {
  643. DEBUG_CRASH(("only planes with reserved spaces can reserve runways"));
  644. return NULL;
  645. }
  646. //Now get the runway we're assigned to and return it's creation vector
  647. return &(m_runways[ runway ].m_creation);
  648. }
  649. //-------------------------------------------------------------------------------------------------
  650. Bool FlightDeckBehavior::isAbleToGiveUpParkingSpace( Object *jet )
  651. {
  652. //If we're airborne or non-existant, someone else can have my spot if they need it.
  653. if( !jet || jet->isAirborneTarget() )
  654. {
  655. return TRUE;
  656. }
  657. JetAIUpdate *ai = (JetAIUpdate*)jet->getAI();
  658. if( ai )
  659. {
  660. //If I'm not idle, I'm certainly not parked. But I could be on route to park in my space!
  661. if( !ai->isIdle() && !ai->isTaxiingToParking() )
  662. {
  663. //We're definitely not airborne, so if our pending command is to land at the carrier, nuke the pending
  664. //command.
  665. AICommandType command = ai->friend_getPendingCommandType();
  666. if( command == AICMD_ENTER || m_designatedCommand == AICMD_IDLE )
  667. {
  668. ai->friend_purgePendingCommand();
  669. return FALSE;
  670. }
  671. //But make sure we're not waiting to takeoff!
  672. std::vector< RunwayInfo >::const_iterator it;
  673. for( it = m_runways.begin(); it != m_runways.end(); it++ )
  674. {
  675. if( it->m_inUseByForTakeoff == jet->getID() )
  676. {
  677. return FALSE;
  678. }
  679. }
  680. return TRUE;
  681. }
  682. }
  683. return FALSE;
  684. }
  685. //-------------------------------------------------------------------------------------------------
  686. Bool FlightDeckBehavior::isInPositionToTakeoff( const Object &jet ) const
  687. {
  688. const AIUpdateInterface *ai = jet.getAI();
  689. const FlightDeckBehaviorModuleData *data = getFlightDeckBehaviorModuleData();
  690. if( ai )
  691. {
  692. for( int i = 0; i < data->m_numCols; i++ )
  693. {
  694. if( m_spaces[ i ].m_objectInSpace == jet.getID() )
  695. {
  696. //This code fixes a problem where there is a one frame lag between the
  697. //time a jet gets assigned to the front spot, and the time it's AI is able to
  698. //order it to taxi into the position. When this happens, the ramp triggers its
  699. //animation, and the jet drives through it. So to counter that, simply check
  700. //the distance between the jet and the space.
  701. Real distanceSqr = ThePartitionManager->getDistanceSquared( &jet, &m_spaces[ i ].m_prep, FROM_CENTER_2D );
  702. if( distanceSqr < 10.0f )
  703. {
  704. return TRUE;
  705. }
  706. return FALSE;
  707. }
  708. }
  709. }
  710. return FALSE;
  711. }
  712. //-------------------------------------------------------------------------------------------------
  713. Bool FlightDeckBehavior::isAbleToMoveForward( const Object &jet ) const
  714. {
  715. JetAIUpdate *jetAI = (JetAIUpdate*)jet.getAI();
  716. if( jetAI && !jet.isAirborneTarget() )
  717. {
  718. //We're not airborne.
  719. if( jetAI->isIdle() )
  720. {
  721. //We're idle (not moving)
  722. return TRUE;
  723. }
  724. //We might be rearming... if so, allow it.
  725. if( jetAI->isReloading() )
  726. {
  727. return TRUE;
  728. }
  729. }
  730. return FALSE;
  731. }
  732. //-------------------------------------------------------------------------------------------------
  733. Bool FlightDeckBehavior::calcBestParkingAssignment( ObjectID id, Coord3D *pos, Int *oldIndex, Int *newIndex )
  734. {
  735. //Find the runway the object is assigned to.
  736. Int runway = -1;
  737. Int myIndex = 0;
  738. for( std::vector<FlightDeckInfo>::iterator myIt = m_spaces.begin(); myIt != m_spaces.end(); myIt++, myIndex++ )
  739. {
  740. if( myIt->m_objectInSpace == id )
  741. {
  742. runway = myIt->m_runway;
  743. if( pos )
  744. {
  745. pos->set( &myIt->m_prep );
  746. }
  747. break;
  748. }
  749. }
  750. if( oldIndex )
  751. {
  752. *oldIndex = myIndex;
  753. }
  754. //Now iterate the runway again in search of an empty spot in front of it. If we reach the same
  755. //plane again, then we're done because there is no better spot!
  756. //Search for the front-most available space that doesn't have any planes blocking it. So start from
  757. //the back and keep looking at empty spaces until we find one with a plane blocking.
  758. Bool checkForPlaneInWay = FALSE;
  759. std::vector<FlightDeckInfo>::iterator bestIt = NULL;
  760. Object *bestJet = NULL;
  761. Int bestIndex = 0, index = 0;
  762. for( std::vector<FlightDeckInfo>::iterator thatIt = m_spaces.begin(); thatIt != m_spaces.end(); thatIt++, index++ )
  763. {
  764. Object *nonIdleJet = TheGameLogic->findObjectByID( thatIt->m_objectInSpace );
  765. if( myIt == thatIt )
  766. {
  767. //Done, don't look at my spot, nor spots behind me.
  768. if( bestIt )
  769. {
  770. myIt->m_objectInSpace = bestJet ? bestJet->getID() : INVALID_ID;
  771. bestIt->m_objectInSpace = id;
  772. //validateAssignments();
  773. /*if( bestJet )
  774. {
  775. JetAIUpdate *jetAI = (JetAIUpdate*)bestJet->getAI();
  776. reserveSpace( bestJet->getID(), jetAI->friend_getParkingOffset(), NULL );
  777. }
  778. if( nonIdleJet )
  779. {
  780. JetAIUpdate *jetAI = (JetAIUpdate*)nonIdleJet->getAI();
  781. reserveSpace( nonIdleJet->getID(), jetAI->friend_getParkingOffset(), NULL );
  782. }*/
  783. if( newIndex )
  784. {
  785. *newIndex = bestIndex;
  786. }
  787. //Promoted forward.
  788. return TRUE;
  789. }
  790. //Did not get promoted forward.
  791. return FALSE;
  792. }
  793. if( thatIt->m_runway == runway )
  794. {
  795. if( !nonIdleJet || isAbleToGiveUpParkingSpace( nonIdleJet ) )
  796. {
  797. if( !checkForPlaneInWay )
  798. {
  799. //We can take this spot! But first find the flight deck info entry for it.Now handle assignment swap.
  800. bestIt = thatIt;
  801. bestJet = nonIdleJet;
  802. bestIndex = index;
  803. checkForPlaneInWay = TRUE;
  804. if( pos )
  805. {
  806. pos->set( &thatIt->m_prep );
  807. }
  808. }
  809. }
  810. else if( checkForPlaneInWay )
  811. {
  812. //Ugh, there's a plane parked between us and the best spot!
  813. checkForPlaneInWay = FALSE;
  814. if( pos )
  815. {
  816. pos->set( &myIt->m_prep ); //reset the original position.
  817. bestIt = NULL;
  818. }
  819. }
  820. }
  821. }
  822. //Did not get promoted forward
  823. return FALSE;
  824. }
  825. //-------------------------------------------------------------------------------------------------
  826. // don't really need to autoheal every frame....
  827. const Int HEAL_RATE_FRAMES = LOGICFRAMES_PER_SECOND / 5;
  828. //-------------------------------------------------------------------------------------------------
  829. void FlightDeckBehavior::resetWakeFrame()
  830. {
  831. if (m_healing.empty())
  832. {
  833. m_nextHealFrame = FOREVER;
  834. }
  835. else
  836. {
  837. m_nextHealFrame = TheGameLogic->getFrame() + HEAL_RATE_FRAMES;
  838. }
  839. }
  840. //-------------------------------------------------------------------------------------------------
  841. void FlightDeckBehavior::setHealee(Object* healee, Bool add)
  842. {
  843. if (add)
  844. {
  845. for (std::list<HealingInfo>::const_iterator it = m_healing.begin(); it != m_healing.end(); ++it)
  846. {
  847. if (it->m_gettingHealedID == healee->getID())
  848. return;
  849. }
  850. HealingInfo info;
  851. info.m_gettingHealedID = healee->getID();
  852. info.m_healStartFrame = TheGameLogic->getFrame();
  853. m_healing.push_back(info);
  854. resetWakeFrame();
  855. }
  856. else
  857. {
  858. for (std::list<HealingInfo>::iterator it = m_healing.begin(); it != m_healing.end(); /*++it*/)
  859. {
  860. if (it->m_gettingHealedID == healee->getID())
  861. {
  862. it = m_healing.erase(it);
  863. resetWakeFrame();
  864. }
  865. else
  866. {
  867. ++it;
  868. }
  869. }
  870. }
  871. }
  872. //-------------------------------------------------------------------------------------------------
  873. void FlightDeckBehavior::defectAllParkedUnits(Team* newTeam, UnsignedInt detectionTime)
  874. {
  875. buildInfo();
  876. purgeDead();
  877. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  878. {
  879. if (it->m_objectInSpace != INVALID_ID)
  880. {
  881. Object* obj = TheGameLogic->findObjectByID(it->m_objectInSpace);
  882. if (obj == NULL || obj->isEffectivelyDead())
  883. continue;
  884. // srj sez: evil. fix better someday.
  885. static NameKeyType jetKey = TheNameKeyGenerator->nameToKey("JetAIUpdate");
  886. JetAIUpdate* ju = (JetAIUpdate *)obj->findUpdateModule(jetKey);
  887. Bool takeoffOrLanding = ju ? ju->friend_isTakeoffOrLandingInProgress() : false;
  888. if (obj->isAboveTerrain() && !takeoffOrLanding)
  889. {
  890. // if the new team is a different controlling player, this guys loses his space.
  891. if (newTeam->getControllingPlayer() != obj->getControllingPlayer())
  892. {
  893. releaseSpace(obj->getID());
  894. if (obj->getProducerID() == getObject()->getID())
  895. obj->setProducer(NULL);
  896. }
  897. }
  898. else
  899. {
  900. obj->defect(newTeam, detectionTime);
  901. }
  902. }
  903. }
  904. purgeDead();
  905. }
  906. //-------------------------------------------------------------------------------------------------
  907. void FlightDeckBehavior::killAllParkedUnits()
  908. {
  909. buildInfo();
  910. purgeDead();
  911. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  912. {
  913. if (it->m_objectInSpace != INVALID_ID)
  914. {
  915. Object* obj = TheGameLogic->findObjectByID(it->m_objectInSpace);
  916. if (obj == NULL || obj->isEffectivelyDead())
  917. continue;
  918. // srj sez: evil. fix better someday.
  919. static NameKeyType jetKey = TheNameKeyGenerator->nameToKey("JetAIUpdate");
  920. JetAIUpdate* ju = (JetAIUpdate *)obj->findUpdateModule(jetKey);
  921. Bool takeoffOrLanding = ju ? ju->friend_isTakeoffOrLandingInProgress() : false;
  922. if (obj->isAboveTerrain() && !takeoffOrLanding)
  923. continue;
  924. obj->kill();
  925. }
  926. }
  927. purgeDead();
  928. }
  929. //-------------------------------------------------------------------------------------------------
  930. void FlightDeckBehavior::onDie( const DamageInfo *damageInfo )
  931. {
  932. killAllParkedUnits();
  933. }
  934. //-------------------------------------------------------------------------------------------------
  935. UpdateSleepTime FlightDeckBehavior::update()
  936. {
  937. // alas, we need to keep the buildInfo and dead-purged stuff pretty much up to date, for
  938. // the client to be able to peek at. at this late date, the most expedient way is to ensure
  939. // our update is run every frame, and do this manually. the extra cost should be trivial, since
  940. // there are generally at most only a few airfields at any given time.
  941. buildInfo();
  942. purgeDead();
  943. const FlightDeckBehaviorModuleData* data = getFlightDeckBehaviorModuleData();
  944. UnsignedInt now = TheGameLogic->getFrame();
  945. if( now >= m_nextHealFrame )
  946. {
  947. m_nextHealFrame = now + HEAL_RATE_FRAMES;
  948. for (std::list<HealingInfo>::iterator it = m_healing.begin(); it != m_healing.end(); /*++it*/)
  949. {
  950. if (it->m_gettingHealedID != INVALID_ID)
  951. {
  952. Object* objToHeal = TheGameLogic->findObjectByID(it->m_gettingHealedID);
  953. if (objToHeal == NULL || objToHeal->isEffectivelyDead())
  954. {
  955. it = m_healing.erase(it);
  956. }
  957. else
  958. {
  959. DamageInfo healInfo;
  960. healInfo.in.m_damageType = DAMAGE_HEALING;
  961. healInfo.in.m_deathType = DEATH_NONE;
  962. healInfo.in.m_sourceID = getObject()->getID();
  963. healInfo.in.m_amount = HEAL_RATE_FRAMES * data->m_healAmount * SECONDS_PER_LOGICFRAME_REAL;
  964. BodyModuleInterface *body = objToHeal->getBodyModule();
  965. body->attemptHealing( &healInfo );
  966. ++it;
  967. }
  968. }
  969. }
  970. }
  971. //Periodically, we want to look at all the aircraft assignments and keep them near the front
  972. //of the carrier at all times. We do this with the following steps:
  973. // 1) Detect non-idle plane assigned to frontmost spaces (implying spot is empty)
  974. // 2) Promote next idle plane behind it to move up and take it's spot. The original plane will
  975. // get assigned to it's old spot (thus bubblesorted eventually to the rear).
  976. if( now >= m_nextCleanupFrame )
  977. {
  978. m_nextCleanupFrame = now + data->m_cleanupFrames;
  979. std::vector<FlightDeckInfo>::iterator tempIt;
  980. Int spaceID = 0;
  981. Bool complete[ MAX_RUNWAYS ] = { FALSE, FALSE };
  982. for( std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); it++, spaceID++ )
  983. {
  984. Object *nonIdleJet = TheGameLogic->findObjectByID( it->m_objectInSpace );
  985. if( !nonIdleJet || isAbleToGiveUpParkingSpace( nonIdleJet ) )
  986. {
  987. //Either we don't have a jet, or the jet is busy (meaning it's not parked there). When a jet
  988. //isn't in his spot, we will look for jets behind him to move up to take up his spot.
  989. Int runwayCount = data->m_numCols;
  990. Int tempID = spaceID;
  991. for( tempIt = it; tempIt != m_spaces.end(); tempIt++, tempID++ )
  992. {
  993. if( runwayCount > 0 )
  994. {
  995. //Because the spaces are sorted Runway 1 Space 1, R2S1, R1S2, R2S2 etc, we simply iterate
  996. //every other space. If there were 3 or 4 runways, then we would jump the number of runways
  997. //before each check so we don't get aircraft from a different runway getting moved up!
  998. runwayCount--;
  999. continue;
  1000. }
  1001. if( complete[ it->m_runway ] )
  1002. {
  1003. continue;
  1004. }
  1005. //Now we have the correct runway. Check if that spot has an idle plane in it!
  1006. Object *parkedJet = TheGameLogic->findObjectByID( tempIt->m_objectInSpace );
  1007. if( parkedJet && isAbleToMoveForward( *parkedJet ) )
  1008. {
  1009. //We have found the best candidate to replace our empty space. Now handle assignment swap.
  1010. it->m_objectInSpace = parkedJet->getID();
  1011. tempIt->m_objectInSpace = nonIdleJet ? nonIdleJet->getID() : INVALID_ID;
  1012. //validateAssignments();
  1013. //Give the parkedJet a move order to taxi over to the new spot.
  1014. //However, we need to set a status bit to tell the AI the difference between taxiing from
  1015. //a hangar and reassigning a parking space.
  1016. parkedJet->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_REASSIGN_PARKING ) );
  1017. //Doesn't matter what we push in now, the JetOrHeliTaxiState::onEnter() will nuke it
  1018. //and calculate the taxi point to move through.
  1019. std::vector<Coord3D> exitPath;
  1020. exitPath.push_back( it->m_prep );
  1021. parkedJet->getAI()->aiFollowExitProductionPath( &exitPath, getObject(), CMD_FROM_AI );
  1022. //Determine if the first plane in each row has completed a move. We want to lag the
  1023. //additional planes instead of moving them all simultaneously. So this is the exit
  1024. //condition if one plane per runway has been bumped.
  1025. complete[ it->m_runway ] = TRUE;
  1026. m_nextCleanupFrame = now + data->m_humanFollowFrames;
  1027. }
  1028. //Break through and advance to the next spot!
  1029. break;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. //Handle automatic production of lost aircraft.
  1035. //Reset timer if we just finished building an aircraft.
  1036. if( m_nextAllowedProductionFrame <= now )
  1037. {
  1038. m_startedProductionFrame = FOREVER;
  1039. }
  1040. for( std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); it++ )
  1041. {
  1042. //Unassigned space?... so we can build a replacement.
  1043. if( it->m_objectInSpace == INVALID_ID )
  1044. {
  1045. //But are we already building one?
  1046. ProductionUpdateInterface *pu = getObject()->getProductionUpdateInterface();
  1047. if( pu == NULL )
  1048. {
  1049. DEBUG_CRASH( ("MSG_QUEUE_UNIT_CREATE: Producer '%s' doesn't have a unit production interface\n", getObject()->getTemplate()->getName().str()) );
  1050. break;
  1051. } // end if
  1052. DEBUG_ASSERTCRASH( m_thingTemplate != NULL, ("flightdeck has a null thingtemplate... no jets for you!\n") );
  1053. if( !pu->getProductionCount() && now >= m_nextAllowedProductionFrame && m_thingTemplate != NULL )
  1054. {
  1055. //Queue the build
  1056. pu->queueCreateUnit( m_thingTemplate, pu->requestUniqueUnitID() );
  1057. m_startedProductionFrame = now;
  1058. m_nextAllowedProductionFrame = now + data->m_replacementFrames + data->m_dockAnimationFrames;
  1059. }
  1060. break;
  1061. }
  1062. }
  1063. //If the carrier has at least one aircraft, then allow it to attack.
  1064. Bool hasAircraft = FALSE;
  1065. for( it = m_spaces.begin(); it != m_spaces.end(); it++ )
  1066. {
  1067. if( it->m_objectInSpace != INVALID_ID )
  1068. {
  1069. hasAircraft = TRUE;
  1070. break;
  1071. }
  1072. }
  1073. getObject()->setStatus( MAKE_OBJECT_STATUS_MASK( OBJECT_STATUS_NO_ATTACK ), !hasAircraft );
  1074. Drawable *draw = getObject()->getDrawable();
  1075. //Check for timer expiry -- are we allowed to launch the next wave yet?
  1076. for( int i = 0; i < data->m_numCols; i++ )
  1077. {
  1078. Object *jet = TheGameLogic->findObjectByID( m_spaces[ i ].m_objectInSpace );
  1079. if( jet && !isAbleToGiveUpParkingSpace( jet ) && isInPositionToTakeoff( *jet ) && hasTakeoffOrders() )
  1080. {
  1081. if( m_nextLaunchWaveFrame[ i ] <= now )
  1082. {
  1083. //Handle making the ramp going up and holding the launch until it's completely up.
  1084. if( !m_rampUp[ i ] )
  1085. {
  1086. m_rampUp[ i ] = TRUE;
  1087. m_rampUpFrame[ i ] = now + data->m_launchRampFrames;
  1088. m_lowerRampFrame[ i ] = FOREVER;
  1089. //****MAX_RUNWAYS***** if defined beyond 3, then this code will need to be rewritten or more modelcondition flags will
  1090. // need to be added.
  1091. ModelConditionFlagType opening = (ModelConditionFlagType)(MODELCONDITION_DOOR_2_OPENING + i * NUM_MODELCONDITION_DOOR_STATES);
  1092. ModelConditionFlagType closing = (ModelConditionFlagType)(MODELCONDITION_DOOR_2_CLOSING + i * NUM_MODELCONDITION_DOOR_STATES);
  1093. draw->clearAndSetModelConditionState( closing, opening );
  1094. }
  1095. //Handle launching the wave of fighters.
  1096. if( m_rampUp[ i ] && m_rampUpFrame[ i ] <= now )
  1097. {
  1098. AIUpdateInterface *jetAI = jet->getAI();
  1099. if( jetAI )
  1100. {
  1101. propagateOrderToSpecificPlane( jet );
  1102. m_nextLaunchWaveFrame[ i ] = now + data->m_launchWaveFrames;
  1103. m_catapultSystemFrame[ i ] = now + data->m_catapultFireFrames;
  1104. m_lowerRampFrame[ i ] = now + data->m_lowerRampFrames;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. //Handle firing of the catapult steam effect upon launching planes.
  1110. if( m_catapultSystemFrame[ i ] <= now && data->m_runwayInfo[ i ].m_catapultParticleSystem )
  1111. {
  1112. ParticleSystem *ps = TheParticleSystemManager->createParticleSystem( data->m_runwayInfo[ i ].m_catapultParticleSystem );
  1113. m_catapultSystemFrame[ i ] = FOREVER;
  1114. if( ps )
  1115. {
  1116. ps->setLocalTransform( &m_runways[ i ].m_startTransform );
  1117. ps->setPosition( &m_runways[ i ].m_start );
  1118. }
  1119. }
  1120. //Handle lowering the ramp after the fighter has been launched.
  1121. if( m_rampUp[ i ] && m_lowerRampFrame[ i ] <= now )
  1122. {
  1123. m_rampUp[ i ] = FALSE;
  1124. //****MAX_RUNWAYS***** if defined beyond 3, then this code will need to be rewritten or more modelcondition flags will
  1125. // need to be added.
  1126. ModelConditionFlagType opening = (ModelConditionFlagType)(MODELCONDITION_DOOR_2_OPENING + i * NUM_MODELCONDITION_DOOR_STATES);
  1127. ModelConditionFlagType closing = (ModelConditionFlagType)(MODELCONDITION_DOOR_2_CLOSING + i * NUM_MODELCONDITION_DOOR_STATES);
  1128. draw->clearAndSetModelConditionState( opening, closing );
  1129. }
  1130. }
  1131. return UPDATE_SLEEP_NONE;
  1132. }
  1133. //-------------------------------------------------------------------------------------------------
  1134. ExitDoorType FlightDeckBehavior::reserveDoorForExit( const ThingTemplate* objType, Object *specificObject )
  1135. {
  1136. //Uses the same door for all production.
  1137. return DOOR_1;
  1138. }
  1139. //-------------------------------------------------------------------------------------------------
  1140. void FlightDeckBehavior::exitObjectViaDoor( Object *newObj, ExitDoorType exitDoor ) ///< Here is the thing I want you to exit
  1141. {
  1142. FlightDeckInfo* ppi = NULL;
  1143. if (exitDoor != DOOR_NONE_NEEDED)
  1144. {
  1145. for (std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); ++it)
  1146. {
  1147. if( it->m_objectInSpace == INVALID_ID )
  1148. {
  1149. ppi = &(*it);
  1150. break;
  1151. }
  1152. }
  1153. if (!ppi)
  1154. {
  1155. DEBUG_CRASH(("could not find the space. what?"));
  1156. return;
  1157. }
  1158. ppi->m_objectInSpace = newObj->getID();
  1159. //validateAssignments();
  1160. }
  1161. /// @todo srj -- this is evil. fix.
  1162. static NameKeyType jetKey = TheNameKeyGenerator->nameToKey( "JetAIUpdate" );
  1163. JetAIUpdate* ju = (JetAIUpdate *)newObj->findUpdateModule( jetKey );
  1164. Real parkingOffset = ju ? ju->friend_getParkingOffset() : 0.0f;
  1165. PPInfo ppinfo;
  1166. Matrix3D mtx;
  1167. DUMPMATRIX3D(getObject()->getTransformMatrix());
  1168. DUMPCOORD3D(getObject()->getPosition());
  1169. CRCDEBUG_LOG(("Produced at hangar (door = %d)\n", exitDoor));
  1170. DEBUG_ASSERTCRASH(exitDoor != DOOR_NONE_NEEDED, ("Hmm, unlikely"));
  1171. if (!reserveSpace(newObj->getID(), parkingOffset, &ppinfo)) //&loc, &orient, NULL, NULL, NULL, NULL, &hangarInternal, &hangOrient))
  1172. {
  1173. DEBUG_CRASH(("no spaces available, how did we get here?"));
  1174. ppinfo.parkingSpace = *getObject()->getPosition();
  1175. ppinfo.parkingOrientation = getObject()->getOrientation();
  1176. }
  1177. const std::vector<Coord3D> *pCreationLocations = getCreationLocations( newObj->getID() );
  1178. if( !pCreationLocations )
  1179. {
  1180. DEBUG_CRASH( ("No creation locations specified for runway for FlightDeckBehavior (Kris).") );
  1181. return;
  1182. }
  1183. newObj->setPosition( pCreationLocations->begin() );
  1184. newObj->setOrientation( m_runways[ ppi->m_runway ].m_startOrient );
  1185. TheAI->pathfinder()->addObjectToPathfindMap( newObj );
  1186. AIUpdateInterface *ai = newObj->getAIUpdateInterface();
  1187. if( ai )
  1188. {
  1189. std::vector<Coord3D> exitPath;
  1190. //Doesn't matter what we push in now, the JetOrHeliTaxiState::onEnter() will nuke it
  1191. //and calculate the taxi points to move through.
  1192. exitPath.push_back( ppi->m_prep );
  1193. ai->aiFollowExitProductionPath( &exitPath, getObject(), CMD_FROM_AI );
  1194. }
  1195. }
  1196. //-------------------------------------------------------------------------------------------------
  1197. void FlightDeckBehavior::unreserveDoorForExit( ExitDoorType exitDoor )
  1198. {
  1199. //Aircraft carrier doesn't use the door reservation system.
  1200. }
  1201. //-------------------------------------------------------------------------------------------------
  1202. void FlightDeckBehavior::aiDoCommand(const AICommandParms* parms)
  1203. {
  1204. //Inspect the command and reset everything when necessary.
  1205. if( parms->m_cmdSource != CMD_FROM_AI )
  1206. {
  1207. //Now the only time we care about anything is if we were ordered to attack something or attack move.
  1208. switch( parms->m_cmd )
  1209. {
  1210. case AICMD_GUARD_POSITION:
  1211. m_designatedTarget = INVALID_ID;
  1212. m_designatedPosition.set( &parms->m_pos );
  1213. m_designatedCommand = parms->m_cmd;
  1214. propagateOrdersToPlanes();
  1215. break;
  1216. case AICMD_ATTACK_POSITION:
  1217. m_designatedTarget = INVALID_ID;
  1218. m_designatedPosition.set( &parms->m_pos );
  1219. m_designatedCommand = parms->m_cmd;
  1220. propagateOrdersToPlanes();
  1221. break;
  1222. case AICMD_FORCE_ATTACK_OBJECT:
  1223. case AICMD_ATTACK_OBJECT:
  1224. m_designatedTarget = parms->m_obj ? parms->m_obj->getID() : INVALID_ID;
  1225. m_designatedPosition.zero();
  1226. m_designatedCommand = parms->m_cmd;
  1227. propagateOrdersToPlanes();
  1228. break;
  1229. case AICMD_ATTACKMOVE_TO_POSITION:
  1230. m_designatedTarget = INVALID_ID;
  1231. m_designatedPosition.set( &parms->m_pos );
  1232. m_designatedCommand = parms->m_cmd;
  1233. propagateOrdersToPlanes();
  1234. break;
  1235. case AICMD_IDLE:
  1236. m_designatedTarget = INVALID_ID;
  1237. m_designatedPosition.zero();
  1238. m_designatedCommand = parms->m_cmd;
  1239. propagateOrdersToPlanes();
  1240. break;
  1241. default:
  1242. m_designatedCommand = AICMD_NO_COMMAND;
  1243. break;
  1244. }
  1245. }
  1246. //Do NOT extend the base class AI. The carrier is a dumb stump that only propagates orders
  1247. //to it's aircraft.
  1248. //AIUpdateInterface::aiDoCommand( parms );
  1249. }
  1250. //-------------------------------------------------------------------------------------------------
  1251. void FlightDeckBehavior::propagateOrdersToPlanes()
  1252. {
  1253. //We just ordered the carrier to stop, so order all the planes that are out to return!
  1254. for( std::vector<FlightDeckInfo>::iterator it = m_spaces.begin(); it != m_spaces.end(); it++ )
  1255. {
  1256. if( it->m_objectInSpace != INVALID_ID )
  1257. {
  1258. Object *jet = TheGameLogic->findObjectByID( it->m_objectInSpace );
  1259. if( jet && isAbleToGiveUpParkingSpace( jet ) )
  1260. {
  1261. propagateOrderToSpecificPlane( jet );
  1262. }
  1263. }
  1264. }
  1265. }
  1266. //-------------------------------------------------------------------------------------------------
  1267. Bool FlightDeckBehavior::hasTakeoffOrders()
  1268. {
  1269. Object *target = TheGameLogic->findObjectByID( m_designatedTarget );
  1270. switch( m_designatedCommand )
  1271. {
  1272. case AICMD_GUARD_POSITION:
  1273. return TRUE;
  1274. case AICMD_ATTACK_POSITION:
  1275. return TRUE;
  1276. case AICMD_ATTACKMOVE_TO_POSITION:
  1277. return TRUE;
  1278. case AICMD_FORCE_ATTACK_OBJECT:
  1279. case AICMD_ATTACK_OBJECT:
  1280. if( target )
  1281. {
  1282. return TRUE;
  1283. }
  1284. m_designatedCommand = AICMD_NO_COMMAND;
  1285. m_designatedTarget = INVALID_ID;
  1286. return FALSE;
  1287. case AICMD_IDLE:
  1288. return FALSE;
  1289. default:
  1290. return FALSE;
  1291. }
  1292. }
  1293. //-------------------------------------------------------------------------------------------------
  1294. void FlightDeckBehavior::propagateOrderToSpecificPlane( Object *jet )
  1295. {
  1296. if( jet )
  1297. {
  1298. AIUpdateInterface *ai = jet->getAI();
  1299. if( ai )
  1300. {
  1301. Object *target = TheGameLogic->findObjectByID( m_designatedTarget );
  1302. switch( m_designatedCommand )
  1303. {
  1304. case AICMD_GUARD_POSITION:
  1305. ai->aiGuardPosition( &m_designatedPosition, GUARDMODE_NORMAL, CMD_FROM_AI );
  1306. break;
  1307. case AICMD_ATTACK_POSITION:
  1308. ai->aiAttackPosition( &m_designatedPosition, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
  1309. break;
  1310. case AICMD_FORCE_ATTACK_OBJECT:
  1311. case AICMD_ATTACK_OBJECT:
  1312. ai->aiForceAttackObject( target, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  1313. break;
  1314. case AICMD_ATTACKMOVE_TO_POSITION:
  1315. ai->aiAttackMoveToPosition( &m_designatedPosition, NO_MAX_SHOTS_LIMIT, CMD_FROM_AI );
  1316. break;
  1317. case AICMD_IDLE:
  1318. ai->aiEnter( getObject(), CMD_FROM_AI );
  1319. break;
  1320. }
  1321. }
  1322. }
  1323. }
  1324. // ------------------------------------------------------------------------------------------------
  1325. /** CRC */
  1326. // ------------------------------------------------------------------------------------------------
  1327. void FlightDeckBehavior::crc( Xfer *xfer )
  1328. {
  1329. // extend base class
  1330. AIUpdateInterface::crc( xfer );
  1331. } // end crc
  1332. // ------------------------------------------------------------------------------------------------
  1333. /** Xfer method
  1334. * Version Info:
  1335. * 1: Initial version */
  1336. // ------------------------------------------------------------------------------------------------
  1337. void FlightDeckBehavior::xfer( Xfer *xfer )
  1338. {
  1339. Int i;
  1340. // version
  1341. const XferVersion currentVersion = 1;
  1342. XferVersion version = currentVersion;
  1343. xfer->xferVersion( &version, currentVersion );
  1344. // extend base class
  1345. AIUpdateInterface::xfer( xfer );
  1346. if( xfer->getXferMode() == XFER_LOAD )
  1347. {
  1348. // first, build our info, so it won't be overwritten later.
  1349. buildInfo(FALSE); // False, because the planes are going to save themselves. We don't re-create them
  1350. }
  1351. // spaces info count and data
  1352. UnsignedByte spacesCount = m_spaces.size();
  1353. xfer->xferUnsignedByte( &spacesCount );
  1354. if( xfer->getXferMode() == XFER_SAVE )
  1355. {
  1356. // save all elements
  1357. std::vector< FlightDeckInfo >::iterator it;
  1358. for( it = m_spaces.begin(); it != m_spaces.end(); ++it )
  1359. {
  1360. // object in this space
  1361. xfer->xferObjectID( &((*it).m_objectInSpace) ); // This is the one thing not regenerated by buildInfo
  1362. } // end for, it
  1363. } // end if, save
  1364. else if( xfer->getXferMode() == XFER_LOAD )
  1365. {
  1366. ObjectID objectID;
  1367. // read all elements
  1368. std::vector< FlightDeckInfo >::iterator it;
  1369. it = m_spaces.begin();
  1370. for( i = 0; i < spacesCount; ++i )
  1371. {
  1372. // read object id
  1373. xfer->xferObjectID( &objectID );
  1374. // store in vector if the vector does indeed still have room for this entry
  1375. if( it != m_spaces.end() )
  1376. {
  1377. (*it).m_objectInSpace = objectID;
  1378. //validateAssignments();
  1379. ++it;
  1380. } // end if
  1381. } // end for, i
  1382. } // end else, load
  1383. // runways count and info
  1384. UnsignedByte runwaysCount = m_runways.size();
  1385. xfer->xferUnsignedByte( &runwaysCount );
  1386. if( xfer->getXferMode() == XFER_SAVE )
  1387. {
  1388. // save all elements
  1389. std::vector< RunwayInfo >::iterator it;
  1390. for( it = m_runways.begin(); it != m_runways.end(); ++it )
  1391. {
  1392. // save object ID
  1393. xfer->xferObjectID( &((*it).m_inUseByForTakeoff ) );
  1394. xfer->xferObjectID( &((*it).m_inUseByForLanding ) );
  1395. } // end for, it
  1396. } // end if, save
  1397. else if( xfer->getXferMode() == XFER_LOAD )
  1398. {
  1399. // read all elements
  1400. std::vector< RunwayInfo >::iterator it;
  1401. it = m_runways.begin();
  1402. for( i = 0; i < runwaysCount; ++i )
  1403. {
  1404. ObjectID inUseByForTakeoff, inUseByForLanding;
  1405. // Old? Bool wasInLine;
  1406. // read object ID
  1407. xfer->xferObjectID( &inUseByForTakeoff );
  1408. xfer->xferObjectID( &inUseByForLanding );
  1409. // Old? xfer->xferBool( &wasInLine );
  1410. // store in vector if the vector does indeed still have room for this entry
  1411. if( it != m_runways.end() )
  1412. {
  1413. (*it).m_inUseByForTakeoff = inUseByForTakeoff;
  1414. (*it).m_inUseByForLanding = inUseByForLanding;
  1415. ++it;
  1416. } // end if
  1417. } // end for, i
  1418. } // end else, load
  1419. // healees
  1420. UnsignedByte healCount = m_healing.size();
  1421. xfer->xferUnsignedByte( &healCount );
  1422. if( xfer->getXferMode() == XFER_SAVE )
  1423. {
  1424. // save all elements
  1425. std::list< HealingInfo >::iterator it;
  1426. for( it = m_healing.begin(); it != m_healing.end(); ++it )
  1427. {
  1428. // save object ID
  1429. xfer->xferObjectID( &((*it).m_gettingHealedID) );
  1430. xfer->xferUnsignedInt( &((*it).m_healStartFrame) );
  1431. } // end for, it
  1432. } // end if, save
  1433. else if( xfer->getXferMode() == XFER_LOAD )
  1434. {
  1435. // read all elements
  1436. m_healing.clear();
  1437. for( i = 0; i < healCount; ++i )
  1438. {
  1439. HealingInfo info;
  1440. // read object ID
  1441. xfer->xferObjectID( &info.m_gettingHealedID );
  1442. xfer->xferUnsignedInt( &info.m_healStartFrame );
  1443. m_healing.push_back(info);
  1444. } // end for, i
  1445. } // end else, load
  1446. xfer->xferUnsignedInt( &m_nextHealFrame );
  1447. xfer->xferUnsignedInt( &m_nextCleanupFrame );
  1448. xfer->xferUnsignedInt( &m_startedProductionFrame );
  1449. xfer->xferUnsignedInt( &m_nextAllowedProductionFrame );
  1450. xfer->xferObjectID( &m_designatedTarget );
  1451. Int commandType;
  1452. xfer->xferInt( &commandType );
  1453. m_designatedCommand = (AICommandType)commandType;
  1454. xfer->xferCoord3D( &m_designatedPosition );
  1455. UnsignedInt maxRunways = MAX_RUNWAYS;
  1456. xfer->xferUnsignedInt( &maxRunways ); //If we're loading, we'll overwrite it. If we're saving, we save it!
  1457. for( i = 0; i < MAX_RUNWAYS; i++ )
  1458. {
  1459. if( maxRunways <= MAX_RUNWAYS )
  1460. {
  1461. //Save and load everything.
  1462. xfer->xferUnsignedInt( &m_nextLaunchWaveFrame[ i ] );
  1463. xfer->xferUnsignedInt( &m_rampUpFrame[ i ] );
  1464. xfer->xferUnsignedInt( &m_catapultSystemFrame[ i ] );
  1465. xfer->xferUnsignedInt( &m_lowerRampFrame[ i ] );
  1466. xfer->xferBool( &m_rampUp[ MAX_RUNWAYS ] );
  1467. }
  1468. else
  1469. {
  1470. //We must be loading... so load filler but don't assign it.
  1471. UnsignedInt dummyInt;
  1472. Bool dummyBool;
  1473. xfer->xferUnsignedInt( &dummyInt );
  1474. xfer->xferUnsignedInt( &dummyInt );
  1475. xfer->xferUnsignedInt( &dummyInt );
  1476. xfer->xferUnsignedInt( &dummyInt );
  1477. xfer->xferBool( &dummyBool );
  1478. }
  1479. }
  1480. } // end xfer
  1481. // ------------------------------------------------------------------------------------------------
  1482. /** Load post process */
  1483. // ------------------------------------------------------------------------------------------------
  1484. void FlightDeckBehavior::loadPostProcess( void )
  1485. {
  1486. const FlightDeckBehaviorModuleData* data = getFlightDeckBehaviorModuleData();
  1487. m_thingTemplate = TheThingFactory->findTemplate( data->m_thingTemplateName );
  1488. // extend base class
  1489. AIUpdateInterface::loadPostProcess();
  1490. // no, this is bad.. it is NOT SAFE to call setWakeFrame from the xfer system. crap. (srj)
  1491. // make sure we are awake... old save games let us sleep
  1492. //setWakeFrame(getObject(), UPDATE_SLEEP_NONE);
  1493. } // end loadPostProcess