boatscript.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. enum EBoatEffects
  2. {
  3. PTC_FRONT = 0,
  4. PTC_BACK,
  5. PTC_SIDE_L,
  6. PTC_SIDE_R
  7. }
  8. enum EBoatEngineSoundState
  9. {
  10. NONE,
  11. START_OK,
  12. START_NO_FUEL,
  13. STOP_OK,
  14. STOP_NO_FUEL
  15. }
  16. class BoatScriptOwnerState : BoatOwnerState
  17. {
  18. };
  19. class BoatScriptMove : BoatMove
  20. {
  21. };
  22. #ifdef DIAG_DEVELOPER
  23. BoatScript _boat;
  24. #endif
  25. class BoatScript : Boat
  26. {
  27. protected const int DECAY_PLAYER_RANGE = 300; // when a player is found within this range, decay is deactivated
  28. protected const int DECAY_FLAG_RANGE = 100; // when a boat is parked around a territoryflag, decay is deactivated
  29. protected const float DECAY_TICK_FREQUENCY = 10; // seconds
  30. protected const float DECAY_DAMAGE = 0.017;
  31. protected const float DECAY_FLIPPED_MULT = 4;
  32. protected const float SOUND_ENGINE_FADE = 0.2;
  33. protected const float SPLASH_THRESHOLD_CONDITION = 0.08; // diff between sea surface and propeller pos which determines if the splash should happen
  34. protected const float SPLASH_THRESHOLD = 0.18; // diff between sea surface and propeller pos which determines when the splash happens
  35. private static ref map<typename, ref TInputActionMap> m_BoatTypeActionsMap = new map<typename, ref TInputActionMap>();
  36. private TInputActionMap m_InputActionMap;
  37. private bool m_ActionsInitialized;
  38. protected vector m_VelocityPrevTick;
  39. protected float m_MomentumPrevTick;
  40. protected ref VehicleContactData m_ContactData;
  41. protected ref Timer m_DecayTimer;
  42. // particles
  43. protected bool m_UpdateParticles;
  44. protected ref EffectBoatWaterBase m_WaterEffects[4];
  45. // sounds
  46. protected bool m_SplashIncoming; // boat is high enough for the splash to trigger when it falls back down to sea level
  47. protected bool m_PlaySoundEngineStopNoFuel;
  48. protected bool m_PlaySoundImpactLight;
  49. protected bool m_PlaySoundImpactHeavy;
  50. protected bool m_PlaySoundPushBoat;
  51. protected bool m_IsEngineSoundFading;
  52. protected bool m_EngineFadeDirection; // true>in | false>out
  53. protected float m_EngineFadeTime;
  54. protected string m_SoundImpactLight;
  55. protected string m_SoundImpactHeavy;
  56. protected string m_SoundPushBoat;
  57. protected string m_SoundWaterSplash;
  58. protected string m_SoundEngineStart;
  59. protected string m_SoundEngineStop;
  60. protected string m_SoundEngineStartNoFuel;
  61. protected string m_SoundEngineStopNoFuel;
  62. // caches to avoid multiple triggers
  63. protected ref EffectSound m_SoundPushBoatEffect;
  64. protected ref EffectSound m_SoundWaterSplashEffect;
  65. protected ref EffectSound m_SoundEngineEffect;
  66. protected ref EffectSound m_SoundEngineEffectDeletion; // hold engine sound which is being stopped & deleted while another is starting
  67. void BoatScript()
  68. {
  69. #ifdef DIAG_DEVELOPER
  70. _boat = this;
  71. #endif
  72. SetEventMask(EntityEvent.POSTSIMULATE);
  73. SetEventMask(EntityEvent.FRAME);
  74. m_PlaySoundImpactLight = false;
  75. m_PlaySoundImpactHeavy = false;
  76. RegisterNetSyncVariableBool("m_PlaySoundEngineStopNoFuel");
  77. RegisterNetSyncVariableBool("m_PlaySoundPushBoat");
  78. RegisterNetSyncVariableBoolSignal("m_PlaySoundImpactLight");
  79. RegisterNetSyncVariableBoolSignal("m_PlaySoundImpactHeavy");
  80. m_SoundImpactHeavy = "boat_01_hit_light_SoundSet";
  81. m_SoundImpactLight = "boat_01_hit_heavy_SoundSet";
  82. m_SoundPushBoat = "boat_01_push_SoundSet";
  83. m_SoundWaterSplash = "boat_01_splash_SoundSet";
  84. m_SoundEngineStart = "boat_01_engine_start_SoundSet";
  85. m_SoundEngineStop = "boat_01_engine_stop_SoundSet";
  86. m_SoundEngineStartNoFuel = "boat_01_engine_start_no_fuel_SoundSet";
  87. m_SoundEngineStopNoFuel = "boat_01_engine_stop_no_fuel_SoundSet";
  88. if (GetGame().IsServer())
  89. {
  90. m_DecayTimer = new Timer( CALL_CATEGORY_SYSTEM );
  91. m_DecayTimer.Run(DECAY_TICK_FREQUENCY, this, "DecayHealthTick", NULL, true);
  92. }
  93. if (GetGame().IsDedicatedServer())
  94. return;
  95. m_WaterEffects[EBoatEffects.PTC_FRONT] = new EffectBoatWaterFront();
  96. m_WaterEffects[EBoatEffects.PTC_BACK] = new EffectBoatWaterBack();
  97. m_WaterEffects[EBoatEffects.PTC_SIDE_L] = new EffectBoatWaterSide();
  98. m_WaterEffects[EBoatEffects.PTC_SIDE_R] = new EffectBoatWaterSide();
  99. if (MemoryPointExists("ptcFxFront"))
  100. m_WaterEffects[EBoatEffects.PTC_FRONT].AttachTo(this, GetMemoryPointPos("ptcFxFront"));
  101. if (MemoryPointExists("ptcFxBack"))
  102. m_WaterEffects[EBoatEffects.PTC_BACK].AttachTo(this, GetMemoryPointPos("ptcFxBack"));
  103. if (MemoryPointExists("ptcFxSide1"))
  104. m_WaterEffects[EBoatEffects.PTC_SIDE_L].AttachTo(this, GetMemoryPointPos("ptcFxSide1"));
  105. if (MemoryPointExists("ptcFxSide2"))
  106. m_WaterEffects[EBoatEffects.PTC_SIDE_R].AttachTo(this, GetMemoryPointPos("ptcFxSide2"));
  107. }
  108. void ~BoatScript()
  109. {
  110. if (m_DecayTimer)
  111. m_DecayTimer.Stop();
  112. #ifndef SERVER
  113. CleanupEffects();
  114. #endif
  115. }
  116. override void EEDelete(EntityAI parent)
  117. {
  118. if (!GetGame().IsDedicatedServer())
  119. CleanupEffects();
  120. }
  121. void InitializeActions()
  122. {
  123. m_InputActionMap = m_BoatTypeActionsMap.Get(this.Type());
  124. if (!m_InputActionMap)
  125. {
  126. TInputActionMap iam = new TInputActionMap();
  127. m_InputActionMap = iam;
  128. SetActions();
  129. m_BoatTypeActionsMap.Insert(this.Type(), m_InputActionMap);
  130. }
  131. }
  132. override void GetActions(typename action_input_type, out array<ActionBase_Basic> actions)
  133. {
  134. if (!m_ActionsInitialized)
  135. {
  136. m_ActionsInitialized = true;
  137. InitializeActions();
  138. }
  139. actions = m_InputActionMap.Get(action_input_type);
  140. }
  141. override bool DisableVicinityIcon()
  142. {
  143. return true;
  144. }
  145. override string GetVehicleType()
  146. {
  147. return "VehicleTypeBoat";
  148. }
  149. override bool IsInventoryVisible()
  150. {
  151. return (GetGame().GetPlayer() && (!GetGame().GetPlayer().GetCommand_Vehicle() || GetGame().GetPlayer().GetCommand_Vehicle().GetTransport() == this));
  152. }
  153. override float GetTransportCameraDistance()
  154. {
  155. return 4.5;
  156. }
  157. override vector GetTransportCameraOffset()
  158. {
  159. return "0 1.4 0";
  160. }
  161. override int GetAnimInstance()
  162. {
  163. return VehicleAnimInstances.ZODIAC;
  164. }
  165. override int Get3rdPersonCameraType()
  166. {
  167. return DayZPlayerCameras.DAYZCAMERA_3RD_VEHICLE;
  168. }
  169. override bool CrewCanGetThrough(int posIdx)
  170. {
  171. return true;
  172. }
  173. override bool CanReachSeatFromSeat(int currentSeat, int nextSeat)
  174. {
  175. return true;
  176. }
  177. override bool CanReachSeatFromDoors(string pSeatSelection, vector pFromPos, float pDistance = 1.0)
  178. {
  179. return true;
  180. }
  181. override bool CanReachDoorsFromSeat(string pDoorsSelection, int pCurrentSeat)
  182. {
  183. return true;
  184. }
  185. override bool IsAreaAtDoorFree(int currentSeat, float maxAllowedObjHeight, inout vector extents, out vector transform[4])
  186. {
  187. return super.IsAreaAtDoorFree(currentSeat, maxAllowedObjHeight, extents, transform);
  188. }
  189. override bool OnBeforeEngineStart()
  190. {
  191. if (IsVitalSparkPlug())
  192. {
  193. EntityAI item = FindAttachmentBySlotName("SparkPlug");
  194. if (!item || (item && item.IsRuined()))
  195. {
  196. HandleEngineSound(EBoatEngineSoundState.START_NO_FUEL);
  197. return false;
  198. }
  199. }
  200. if (GetFluidFraction(BoatFluid.FUEL) <= 0)
  201. {
  202. HandleEngineSound(EBoatEngineSoundState.START_NO_FUEL);
  203. return false;
  204. }
  205. return true;
  206. }
  207. override void OnEngineStart()
  208. {
  209. super.OnEngineStart();
  210. if (GetGame().IsDedicatedServer())
  211. return;
  212. FadeEngineSound(true);
  213. HandleEngineSound(EBoatEngineSoundState.START_OK);
  214. ClearWaterEffects(); // in case they are still active
  215. }
  216. override void OnEngineStop()
  217. {
  218. super.OnEngineStop();
  219. if (GetGame().IsDedicatedServer())
  220. return;
  221. FadeEngineSound(false);
  222. HandleEngineSound(EBoatEngineSoundState.STOP_OK);
  223. vector mat[4];
  224. dBodyGetWorldTransform(this, mat);
  225. vector pos = mat[3] + VectorToParent(PropellerGetPosition());
  226. if (GetGame().GetWaterDepth(pos) < 0) // stop instantly
  227. StopParticleUpdate();
  228. else
  229. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(StopParticleUpdate, 3000);
  230. }
  231. override void EEOnCECreate()
  232. {
  233. float maxVolume = GetFluidCapacity(BoatFluid.FUEL);
  234. float amount = Math.RandomFloat(0.0, maxVolume * 0.35);
  235. Fill(BoatFluid.FUEL, amount);
  236. }
  237. override void EOnPostSimulate(IEntity other, float timeSlice)
  238. {
  239. if (!IsProxy())
  240. {
  241. HandleByCrewMemberState(ECrewMemberState.UNCONSCIOUS);
  242. HandleByCrewMemberState(ECrewMemberState.DEAD);
  243. if (EngineIsOn())
  244. {
  245. if (GetFluidFraction(BoatFluid.FUEL) <= 0)
  246. {
  247. if (GetGame().IsServer())
  248. {
  249. m_PlaySoundEngineStopNoFuel = true;
  250. SetSynchDirty();
  251. m_PlaySoundEngineStopNoFuel = false;
  252. }
  253. EngineStop();
  254. }
  255. }
  256. }
  257. if (GetGame().IsServer())
  258. {
  259. CheckContactCache();
  260. m_VelocityPrevTick = GetVelocity(this);
  261. m_MomentumPrevTick = GetMomentum();
  262. }
  263. if (!GetGame().IsDedicatedServer())
  264. {
  265. if (EngineIsOn())
  266. m_UpdateParticles = true;
  267. if (m_UpdateParticles)
  268. HandleBoatSplashSound();
  269. }
  270. }
  271. override void EOnSimulate(IEntity other, float dt)
  272. {
  273. if (!IsProxy())
  274. {
  275. if (EngineIsOn())
  276. {
  277. vector mat[4];
  278. dBodyGetWorldTransform(this, mat);
  279. vector pos = mat[3] + VectorToParent(PropellerGetPosition());
  280. if (GetGame().GetWaterDepth(pos) < -0.2)
  281. EngineStop();
  282. }
  283. }
  284. }
  285. override void EOnFrame(IEntity other, float timeSlice)
  286. {
  287. if (!GetGame().IsDedicatedServer())
  288. {
  289. if (m_UpdateParticles)
  290. UpdateParticles(timeSlice);
  291. if (m_IsEngineSoundFading)
  292. {
  293. m_EngineFadeTime -= timeSlice;
  294. if (m_EngineFadeTime < 0)
  295. m_IsEngineSoundFading = false;
  296. }
  297. }
  298. }
  299. override void EOnContact(IEntity other, Contact extra)
  300. {
  301. if (GetGame().IsServer())
  302. {
  303. if (m_ContactData)
  304. return;
  305. float momentumDelta = GetMomentum() - m_MomentumPrevTick;
  306. float dot = vector.Dot(m_VelocityPrevTick.Normalized(), GetVelocity(this).Normalized());
  307. if (dot < 0)
  308. momentumDelta = m_MomentumPrevTick;
  309. m_ContactData = new VehicleContactData();
  310. m_ContactData.SetData(extra.Position, other, momentumDelta); // change to local pos
  311. }
  312. if (!IsProxy())
  313. {
  314. if (EngineIsOn() && !CheckOperationalState())
  315. EngineStop();
  316. }
  317. }
  318. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  319. {
  320. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  321. if (!IsProxy())
  322. {
  323. if (EngineIsOn() && !CheckOperationalState())
  324. EngineStop();
  325. }
  326. }
  327. override void OnVariablesSynchronized()
  328. {
  329. super.OnVariablesSynchronized();
  330. if (m_PlaySoundImpactHeavy)
  331. {
  332. EffectSound impactHeavy;
  333. PlaySound(m_SoundImpactHeavy, impactHeavy, GetPosition());
  334. m_PlaySoundImpactHeavy = false;
  335. }
  336. if (m_PlaySoundImpactLight)
  337. {
  338. EffectSound impactLight;
  339. PlaySound(m_SoundImpactLight, impactLight, GetPosition());
  340. m_PlaySoundImpactLight = false;
  341. }
  342. if (m_PlaySoundPushBoat)
  343. PlaySound(m_SoundPushBoat, m_SoundPushBoatEffect, GetPosition());
  344. else if (m_SoundPushBoatEffect && m_SoundPushBoatEffect.IsPlaying())
  345. m_SoundPushBoatEffect.Stop();
  346. if (m_PlaySoundEngineStopNoFuel)
  347. {
  348. HandleEngineSound(EBoatEngineSoundState.STOP_NO_FUEL);
  349. m_PlaySoundEngineStopNoFuel = false;
  350. }
  351. }
  352. protected override bool DetectFlipped(VehicleFlippedContext ctx)
  353. {
  354. if (!DetectFlippedUsingSurface(ctx, GameConstants.VEHICLE_FLIP_ANGLE_TOLERANCE))
  355. return false;
  356. return true;
  357. }
  358. override float OnSound(BoatSoundCtrl ctrl, float oldValue)
  359. {
  360. if (m_IsEngineSoundFading)
  361. {
  362. if (m_EngineFadeDirection)
  363. oldValue = Math.InverseLerp(SOUND_ENGINE_FADE, 0, m_EngineFadeTime);
  364. else
  365. oldValue = Math.InverseLerp(0, SOUND_ENGINE_FADE, m_EngineFadeTime);
  366. return oldValue;
  367. }
  368. return super.OnSound(ctrl, oldValue);
  369. }
  370. override void HandleByCrewMemberState(ECrewMemberState state)
  371. {
  372. switch (state)
  373. {
  374. case ECrewMemberState.UNCONSCIOUS:
  375. foreach (int unconsciousCrewMemberIndex : m_UnconsciousCrewMemberIndices)
  376. {
  377. if (unconsciousCrewMemberIndex == DayZPlayerConstants.VEHICLESEAT_DRIVER)
  378. EngineStop();
  379. m_UnconsciousCrewMemberIndices.RemoveItem(unconsciousCrewMemberIndex);
  380. }
  381. break;
  382. case ECrewMemberState.DEAD:
  383. foreach (int deadCrewMemberIndex : m_DeadCrewMemberIndices)
  384. {
  385. if (deadCrewMemberIndex == DayZPlayerConstants.VEHICLESEAT_DRIVER)
  386. EngineStop();
  387. m_DeadCrewMemberIndices.RemoveItem(deadCrewMemberIndex);
  388. }
  389. break;
  390. }
  391. }
  392. protected void DecayHealthTick()
  393. {
  394. if ( (GetCEApi() && !GetCEApi().AvoidPlayer(GetPosition(), DECAY_PLAYER_RANGE)) || CfgGameplayHandler.GetBoatDecayMultiplier() <= 0 )
  395. return;
  396. float damage = DECAY_DAMAGE * CfgGameplayHandler.GetBoatDecayMultiplier();
  397. if (IsFlipped())
  398. damage *= DECAY_FLIPPED_MULT;
  399. if (IsInFlagRange())
  400. damage *= 0.3;
  401. AddHealth("Engine","Health", -damage);
  402. }
  403. protected bool IsInFlagRange()
  404. {
  405. array<vector> locations = GetGame().GetMission().GetActiveRefresherLocations();
  406. if (!locations)
  407. return false;
  408. int count = locations.Count();
  409. if (count > 0)
  410. {
  411. vector pos = GetWorldPosition();
  412. for (int i = 0; i < count; i++)
  413. {
  414. if (vector.Distance(pos, locations.Get(i)) < DECAY_FLAG_RANGE)
  415. return true;
  416. }
  417. return false;
  418. }
  419. else
  420. return false;
  421. }
  422. bool CheckOperationalState()
  423. {
  424. if (GetHealthLevel("") >= GameConstants.STATE_RUINED || GetHealthLevel("Engine") >= GameConstants.STATE_RUINED)
  425. return false;
  426. if (IsVitalSparkPlug())
  427. {
  428. EntityAI item = FindAttachmentBySlotName("SparkPlug");
  429. if (!item || (item && item.IsRuined()))
  430. return false;
  431. }
  432. return true;
  433. }
  434. // Server side event for jump out processing
  435. void OnVehicleJumpOutServer(GetOutTransportActionData data)
  436. {
  437. vector posMS = data.m_Player.WorldToModel(data.m_Player.GetPosition());
  438. float healthCoef = Math.InverseLerp(ActionGetOutTransport.HEALTH_LOW_SPEED_VALUE, ActionGetOutTransport.HEALTH_HIGH_SPEED_VALUE, data.m_Speed) * 0.5;
  439. healthCoef = Math.Clamp(healthCoef, 0.0, 1.0);
  440. data.m_Player.ProcessDirectDamage(DamageType.CUSTOM, data.m_Player, "", "FallDamageHealth", posMS, healthCoef);
  441. }
  442. protected void HandleEngineSound(EBoatEngineSoundState state)
  443. {
  444. if (GetGame().IsDedicatedServer())
  445. return;
  446. string soundset;
  447. switch (state)
  448. {
  449. case EBoatEngineSoundState.START_OK:
  450. soundset = m_SoundEngineStart;
  451. break;
  452. case EBoatEngineSoundState.STOP_OK:
  453. soundset = m_SoundEngineStop;
  454. break;
  455. case EBoatEngineSoundState.START_NO_FUEL:
  456. soundset = m_SoundEngineStartNoFuel;
  457. break;
  458. case EBoatEngineSoundState.STOP_NO_FUEL:
  459. soundset = m_SoundEngineStopNoFuel;
  460. break;
  461. }
  462. // already playing same type of sound
  463. if (m_SoundEngineEffect)
  464. {
  465. if (m_SoundEngineEffect.GetSoundSet() == soundset) // already playing same type of sound
  466. return;
  467. else
  468. {
  469. m_SoundEngineEffectDeletion = m_SoundEngineEffect;
  470. m_SoundEngineEffectDeletion.SoundStop(); // stop the existing sound
  471. m_SoundEngineEffect = null;
  472. }
  473. }
  474. PlaySound(soundset, m_SoundEngineEffect, ModelToWorld(PropellerGetPosition()));
  475. }
  476. protected void PlaySound(string soundset, inout EffectSound sound, vector position = vector.Zero)
  477. {
  478. #ifndef SERVER
  479. if (position == vector.Zero)
  480. position = GetPosition();
  481. if (!sound)
  482. {
  483. sound = SEffectManager.PlaySoundCachedParams(soundset, position);
  484. sound.SetAttachmentParent(this);
  485. sound.SetAutodestroy(true); // SoundWaveObjects tend to null themselves for unknown reasons, breaking the effect in the process
  486. }
  487. else
  488. {
  489. if (!sound.IsSoundPlaying())
  490. {
  491. sound.SetCurrentPosition(position);
  492. sound.SoundPlay();
  493. }
  494. }
  495. #endif
  496. }
  497. protected void HandleBoatSplashSound()
  498. {
  499. float propPosRelative = GetGame().SurfaceGetSeaLevel() - CoordToParent(PropellerGetPosition())[1];
  500. if (propPosRelative < SPLASH_THRESHOLD_CONDITION)
  501. m_SplashIncoming = true;
  502. if (m_SplashIncoming && propPosRelative > SPLASH_THRESHOLD)
  503. {
  504. m_SoundWaterSplashEffect = SEffectManager.CreateSound(m_SoundWaterSplash, GetPosition());
  505. m_SoundWaterSplashEffect.SetAttachmentParent(this);
  506. m_SoundWaterSplashEffect.SetLocalPosition(PropellerGetPosition());
  507. m_SoundWaterSplashEffect.SetAutodestroy(true);
  508. vector velocity = dBodyGetVelocityAt(this, CoordToParent(PropellerGetPosition()));
  509. float speed = velocity.Normalize() * 3.6; // to km/h
  510. float lerp = Math.InverseLerp(0, 30, speed);
  511. m_SoundWaterSplashEffect.SetSoundVolume(lerp);
  512. m_SoundWaterSplashEffect.Start();
  513. m_SplashIncoming = false;
  514. }
  515. }
  516. protected void SyncSoundImpactLight()
  517. {
  518. if (!m_PlaySoundImpactLight)
  519. {
  520. m_PlaySoundImpactLight = true;
  521. SetSynchDirty();
  522. }
  523. }
  524. protected void SyncSoundImpactHeavy()
  525. {
  526. if (!m_PlaySoundImpactHeavy)
  527. {
  528. m_PlaySoundImpactHeavy = true;
  529. SetSynchDirty();
  530. }
  531. }
  532. void SyncSoundPushBoat(bool play)
  533. {
  534. if (m_PlaySoundPushBoat != play)
  535. {
  536. m_PlaySoundPushBoat = play;
  537. SetSynchDirty();
  538. }
  539. }
  540. // Set engine sound to fade on start/stop
  541. protected void FadeEngineSound(bool fadeIn)
  542. {
  543. m_IsEngineSoundFading = true;
  544. m_EngineFadeDirection = fadeIn;
  545. m_EngineFadeTime = SOUND_ENGINE_FADE;
  546. }
  547. protected void FlipVehicle()
  548. {
  549. vector orient = GetOrientation();
  550. orient[2] = orient[2] + 180;
  551. SetOrientation(orient);
  552. vector pos = GetPosition();
  553. pos[1] = pos[1] + 0.5;
  554. SetPosition(pos);
  555. }
  556. protected void CheckContactCache()
  557. {
  558. if (!m_ContactData)
  559. return;
  560. float impulse = Math.AbsInt(m_ContactData.m_Impulse);
  561. m_ContactData = null;
  562. if (impulse < GameConstants.CARS_CONTACT_DMG_MIN)
  563. return;
  564. else if (impulse < GameConstants.CARS_CONTACT_DMG_THRESHOLD)
  565. SyncSoundImpactLight();
  566. else
  567. SyncSoundImpactHeavy();
  568. }
  569. protected void SetActions()
  570. {
  571. AddAction(ActionGetInTransport);
  572. AddAction(ActionPushBoat);
  573. }
  574. void AddAction(typename actionName)
  575. {
  576. ActionBase action = ActionManagerBase.GetAction(actionName);
  577. if (!action)
  578. {
  579. Debug.LogError("Action " + actionName + " dosn't exist!");
  580. return;
  581. }
  582. typename ai = action.GetInputType();
  583. if (!ai)
  584. {
  585. m_ActionsInitialized = false;
  586. return;
  587. }
  588. array<ActionBase_Basic> actionArray = m_InputActionMap.Get(ai);
  589. if (!actionArray)
  590. {
  591. actionArray = new array<ActionBase_Basic>;
  592. m_InputActionMap.Insert(ai, actionArray);
  593. }
  594. if (LogManager.IsActionLogEnable())
  595. {
  596. Debug.ActionLog(action.ToString() + " -> " + ai, this.ToString() , "n/a", "Add action" );
  597. }
  598. actionArray.Insert(action);
  599. }
  600. void RemoveAction(typename actionName)
  601. {
  602. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  603. ActionBase action = player.GetActionManager().GetAction(actionName);
  604. typename ai = action.GetInputType();
  605. array<ActionBase_Basic> actionArray = m_InputActionMap.Get(ai);
  606. if (actionArray)
  607. {
  608. actionArray.RemoveItem(action);
  609. }
  610. }
  611. protected void UpdateParticles(float timeSlice = 0)
  612. {
  613. for (int i; i < 4; i++)
  614. {
  615. m_WaterEffects[i].Update(timeSlice);
  616. }
  617. }
  618. protected void StopParticleUpdate()
  619. {
  620. m_UpdateParticles = false;
  621. ClearWaterEffects();
  622. }
  623. protected void ClearWaterEffects()
  624. {
  625. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(StopParticleUpdate);
  626. for (int i; i < 4; i++)
  627. {
  628. if (m_WaterEffects[i].IsPlaying())
  629. {
  630. if (m_WaterEffects[i].GetParticle())
  631. {
  632. m_WaterEffects[i].GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE, 0);
  633. m_WaterEffects[i].GetParticle().SetParticleParam(EmitorParam.BIRTH_RATE_RND, 0);
  634. }
  635. m_WaterEffects[i].Stop();
  636. }
  637. }
  638. }
  639. // Called on destroy/stream out
  640. protected void CleanupEffects()
  641. {
  642. for (int i; i < 4; i++)
  643. {
  644. if (m_WaterEffects[i].IsRegistered())
  645. {
  646. m_WaterEffects[i].Stop();
  647. SEffectManager.EffectUnregisterEx(m_WaterEffects[i]);
  648. }
  649. }
  650. SEffectManager.DestroyEffect(m_SoundPushBoatEffect);
  651. SEffectManager.DestroyEffect(m_SoundWaterSplashEffect);
  652. }
  653. override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
  654. {
  655. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FLIP_ENTITY, "Flip vehicle", FadeColors.LIGHT_GREY));
  656. super.GetDebugActions(outputList);
  657. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.SEPARATOR, "___________________________", FadeColors.RED));
  658. outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.DELETE, "Delete", FadeColors.RED));
  659. }
  660. override bool OnAction(int action_id, Man player, ParamsReadContext ctx)
  661. {
  662. if (super.OnAction(action_id, player, ctx))
  663. return true;
  664. if (!GetGame().IsServer())
  665. {
  666. return false;
  667. }
  668. switch (action_id)
  669. {
  670. case EActions.DELETE:
  671. Delete();
  672. return true;
  673. case EActions.FLIP_ENTITY:
  674. FlipVehicle();
  675. return true;
  676. }
  677. return false;
  678. }
  679. protected override event typename GetOwnerStateType()
  680. {
  681. return BoatScriptOwnerState;
  682. }
  683. protected override event typename GetMoveType()
  684. {
  685. return BoatScriptMove;
  686. }
  687. #ifdef DIAG_DEVELOPER
  688. override void FixEntity()
  689. {
  690. super.FixEntity();
  691. if (GetGame().IsServer())
  692. Fill(BoatFluid.FUEL, GetFluidCapacity(BoatFluid.FUEL));
  693. }
  694. #endif
  695. }