tentbase.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. class TentBase extends ItemBase
  2. {
  3. const int OPENING_0 = 1;
  4. const int OPENING_1 = 2;
  5. const int OPENING_2 = 4;
  6. const int OPENING_3 = 8;
  7. const int OPENING_4 = 16;
  8. const int OPENING_5 = 32;
  9. const int OPENING_6 = 64;
  10. const int OPENING_7 = 128;
  11. const int OPENING_8 = 256;
  12. const int OPENING_9 = 512;
  13. const int OPENING_10 = 1024;
  14. const int OPENING_11 = 2048;
  15. const int OPENING_12 = 4096;
  16. const int OPENING_13 = 8192;
  17. const int OPENING_14 = 16384;
  18. const int OPENING_15 = 32768;
  19. static const int PACKED = 0;
  20. static const int PITCHED = 1;
  21. const float MAX_PLACEMENT_HEIGHT_DIFF = 1.5;
  22. protected int m_State;
  23. protected int m_StateLocal = -1;
  24. protected bool m_IsEntrance;
  25. protected bool m_IsWindow;
  26. protected bool m_IsToggle;
  27. protected bool m_IsBeingPacked = false;
  28. protected int m_OpeningMask = 0;
  29. protected int m_OpeningMaskLocal = -1;
  30. protected ref map< ref ToggleAnimations, bool> m_ToggleAnimations;
  31. protected ref array<string> m_ShowAnimationsWhenPitched;
  32. protected ref array<string> m_ShowAnimationsWhenPacked;
  33. protected Object m_ClutterCutter;
  34. protected CamoNet m_CamoNet;
  35. protected vector m_HalfExtents; // The Y value contains a heightoffset and not the halfextent !!!
  36. void TentBase()
  37. {
  38. m_ToggleAnimations = new map<ref ToggleAnimations, bool>;
  39. m_ShowAnimationsWhenPitched = new array<string>;
  40. m_ShowAnimationsWhenPacked = new array<string>;
  41. m_HalfExtents = vector.Zero;
  42. RegisterNetSyncVariableInt("m_State");
  43. RegisterNetSyncVariableBool("m_IsSoundSynchRemote");
  44. RegisterNetSyncVariableBool("m_IsEntrance");
  45. RegisterNetSyncVariableBool("m_IsWindow");
  46. RegisterNetSyncVariableBool("m_IsToggle");
  47. RegisterNetSyncVariableBool("m_IsDeploySound");
  48. RegisterNetSyncVariableInt("m_OpeningMask");
  49. RegisterNetSyncVariableBool("m_IsBeingPacked");
  50. ProcessInvulnerabilityCheck(GetInvulnerabilityTypeString());
  51. }
  52. void ~TentBase()
  53. {
  54. if (GetGame())
  55. {
  56. DestroyClutterCutter();
  57. }
  58. }
  59. override string GetInvulnerabilityTypeString()
  60. {
  61. return "disableContainerDamage";
  62. }
  63. override bool HasProxyParts()
  64. {
  65. return true;
  66. }
  67. //! prevents showing cargo when outside the tent geometry
  68. override bool CanProxyObstructSelf()
  69. {
  70. return true;
  71. }
  72. override bool IsItemTent()
  73. {
  74. return true;
  75. }
  76. override bool CanBeRepairedByCrafting()
  77. {
  78. return false;
  79. }
  80. override int GetMeleeTargetType()
  81. {
  82. return EMeleeTargetType.NONALIGNABLE;
  83. }
  84. override void OnStoreSave(ParamsWriteContext ctx)
  85. {
  86. super.OnStoreSave(ctx);
  87. ctx.Write(m_State);
  88. ctx.Write(m_OpeningMask);
  89. }
  90. override bool OnStoreLoad(ParamsReadContext ctx, int version)
  91. {
  92. if (!super.OnStoreLoad(ctx, version))
  93. return false;
  94. ctx.Read(m_State);
  95. if (version >= 110)
  96. {
  97. if (!ctx.Read(m_OpeningMask))
  98. Print("ERROR: no opening mask found! Default openinng settings initialized.");
  99. }
  100. if (m_State == PITCHED)
  101. {
  102. TryPitch(true);
  103. if (GetGame().IsServer())
  104. {
  105. if (!m_ClutterCutter && HasClutterCutter())
  106. {
  107. m_ClutterCutter = GetGame().CreateObjectEx(GetClutterCutter(), GetPosition(), ECE_PLACE_ON_SURFACE);
  108. m_ClutterCutter.SetOrientation(GetOrientation());
  109. }
  110. RefreshAttachements();
  111. }
  112. }
  113. else
  114. {
  115. Pack(true);
  116. }
  117. return true;
  118. }
  119. override void RefreshPhysics()
  120. {
  121. super.RefreshPhysics();
  122. if (m_State == PITCHED)
  123. {
  124. TryPitch(false, true);
  125. }
  126. else
  127. {
  128. Pack(false, true);
  129. }
  130. }
  131. override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
  132. {
  133. super.OnItemLocationChanged(old_owner, new_owner);
  134. if (new_owner || old_owner)
  135. {
  136. if (GetInventory().CountInventory() == 1) // refuse to pack tent with anything inside
  137. Pack(false);
  138. }
  139. }
  140. override void OnVariablesSynchronized()
  141. {
  142. super.OnVariablesSynchronized();
  143. if (IsDeploySound())
  144. {
  145. PlayDeploySound();
  146. }
  147. else
  148. {
  149. if (m_State == PITCHED)
  150. {
  151. if (IsManipulatedEntrance() && IsSoundSynchRemote())
  152. {
  153. if (m_IsToggle)
  154. {
  155. SoundTentOpenPlay();
  156. }
  157. else
  158. {
  159. SoundTentClosePlay();
  160. }
  161. }
  162. else if (IsManipulatedWindow() && IsSoundSynchRemote())
  163. {
  164. if (m_IsToggle)
  165. {
  166. SoundTentOpenWindowPlay();
  167. }
  168. else
  169. {
  170. SoundTentCloseWindowPlay();
  171. }
  172. }
  173. }
  174. }
  175. if (m_State != m_StateLocal)
  176. {
  177. if (m_State == PACKED)
  178. Pack(false);
  179. else
  180. TryPitch(false);
  181. m_StateLocal = m_State;
  182. }
  183. if ((m_OpeningMaskLocal != m_OpeningMask)) //opening synchronization for physics recalculation
  184. {
  185. HandleOpeningsPhysics();
  186. m_OpeningMaskLocal = m_OpeningMask;
  187. if (m_State == PACKED)
  188. {
  189. Pack(false); //intentional
  190. }
  191. }
  192. }
  193. override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
  194. {
  195. super.EEHealthLevelChanged(oldLevel,newLevel,zone);
  196. if (m_FixDamageSystemInit)
  197. return;
  198. if (zone == "" && GetState() == PITCHED && newLevel == GameConstants.STATE_RUINED && GetGame().IsServer())
  199. MiscGameplayFunctions.DropAllItemsInInventoryInBounds(this, m_HalfExtents);
  200. if (zone != "Body" && zone != "Inventory" && zone != "")
  201. {
  202. if (newLevel == GameConstants.STATE_RUINED)
  203. {
  204. array<string> selections = new array<string>;
  205. DamageSystem.GetComponentNamesFromDamageZone(this,zone,selections);
  206. for (int j = 0; j < selections.Count(); j++)
  207. {
  208. if (selections.Get(j) != "")
  209. {
  210. RemoveProxyPhysics(selections.Get(j)); //To keep
  211. //HideSelection(selections.Get(j)); //To change
  212. AnimateCamonetByOpeningSelection(selections.Get(j)); //To keep
  213. }
  214. }
  215. }
  216. else if (oldLevel == GameConstants.STATE_RUINED)
  217. {
  218. if (GetState() == PITCHED)
  219. {
  220. TryPitch(true);
  221. }
  222. }
  223. }
  224. }
  225. void HideAllAnimationsAndProxyPhysics(bool hide_animations = true, bool hide_physics = true)
  226. {
  227. string cfg_path = "cfgVehicles " + GetType() + " AnimationSources";
  228. if (GetGame().ConfigIsExisting(cfg_path))
  229. {
  230. int selections = GetGame().ConfigGetChildrenCount(cfg_path);
  231. string proxy_selection_name;
  232. for (int i = 0; i < selections; i++)
  233. {
  234. string selection_name;
  235. GetGame().ConfigGetChildName(cfg_path, i, selection_name);
  236. if (hide_animations)
  237. {
  238. SetAnimationPhase(selection_name, 1);
  239. }
  240. proxy_selection_name = selection_name;
  241. proxy_selection_name.ToLower();
  242. if (hide_physics)
  243. {
  244. RemoveProxyPhysics(proxy_selection_name);
  245. }
  246. }
  247. }
  248. }
  249. bool ConditionIntoInventory(EntityAI player)
  250. {
  251. return CanBeManipulated();
  252. }
  253. override bool CanPutIntoHands(EntityAI parent)
  254. {
  255. if (!super.CanPutIntoHands(parent))
  256. {
  257. return false;
  258. }
  259. return CanBeManipulated();
  260. }
  261. override bool CanPutInCargo(EntityAI parent)
  262. {
  263. if (!super.CanPutInCargo(parent))
  264. {
  265. return false;
  266. }
  267. return CanBeManipulated();
  268. }
  269. bool ConditionOutOfHands(EntityAI player)
  270. {
  271. return CanBeManipulated();
  272. }
  273. override bool CanBeRepairedToPristine()
  274. {
  275. return true;
  276. }
  277. void RefreshAttachements()
  278. {
  279. int slot_id_camo;
  280. int slot_id_xlights;
  281. EntityAI eai_xlights;
  282. slot_id_camo = InventorySlots.GetSlotIdFromString("CamoNet");
  283. m_CamoNet = CamoNet.Cast(GetInventory().FindAttachment(slot_id_camo));
  284. slot_id_xlights = InventorySlots.GetSlotIdFromString("Lights");
  285. eai_xlights = GetInventory().FindAttachment(slot_id_xlights);
  286. if (m_CamoNet)
  287. {
  288. HandleCamoNetAttachment(false);
  289. //SetAnimationPhase("Camonet", 0);
  290. if (!IsKindOf("MediumTent"))
  291. {
  292. AddProxyPhysics("camonet");
  293. }
  294. }
  295. if (eai_xlights)
  296. {
  297. SetAnimationPhase("Xlights", 0);
  298. SetAnimationPhase("Xlights_glass_r", 0);
  299. SetAnimationPhase("Xlights_glass_g", 0);
  300. SetAnimationPhase("Xlights_glass_b", 0);
  301. SetAnimationPhase("Xlights_glass_y", 0);
  302. }
  303. }
  304. override void EEItemAttached(EntityAI item, string slot_name)
  305. {
  306. super.EEItemAttached(item, slot_name);
  307. if (item.IsKindOf ("CamoNet"))
  308. {
  309. m_CamoNet = CamoNet.Cast(item);
  310. HandleCamoNetAttachment(false);
  311. //SetAnimationPhase("Camonet", 0);
  312. if (!IsKindOf ("MediumTent"))
  313. {
  314. AddProxyPhysics("camonet");
  315. }
  316. }
  317. if (item.IsKindOf ("XmasLights"))
  318. {
  319. SetAnimationPhase("Xlights", 0);
  320. SetAnimationPhase("Xlights_glass_r", 0);
  321. SetAnimationPhase("Xlights_glass_g", 0);
  322. SetAnimationPhase("Xlights_glass_b", 0);
  323. SetAnimationPhase("Xlights_glass_y", 0);
  324. XmasLights xlights = XmasLights.Cast(item);
  325. xlights.AttachToObject(this);
  326. }
  327. }
  328. override void EEItemDetached(EntityAI item, string slot_name)
  329. {
  330. super.EEItemDetached(item, slot_name);
  331. if (item.IsKindOf ("CamoNet"))
  332. {
  333. m_CamoNet = null;
  334. HandleCamoNetAttachment(true);
  335. //SetAnimationPhase("Camonet", 1);
  336. if (!IsKindOf ("MediumTent"))
  337. {
  338. RemoveProxyPhysics("camonet");
  339. }
  340. }
  341. if (item.IsKindOf ("XmasLights"))
  342. {
  343. SetAnimationPhase("Xlights", 1);
  344. SetAnimationPhase("Xlights_glass_r", 1);
  345. SetAnimationPhase("Xlights_glass_g", 1);
  346. SetAnimationPhase("Xlights_glass_b", 1);
  347. SetAnimationPhase("Xlights_glass_y", 1);
  348. XmasLights xlights = XmasLights.Cast(item);
  349. xlights.DetachFromObject(this);
  350. }
  351. }
  352. override int GetViewIndex()
  353. {
  354. if (MemoryPointExists("invView2"))
  355. {
  356. InventoryLocation il = new InventoryLocation();
  357. GetInventory().GetCurrentInventoryLocation(il);
  358. InventoryLocationType type = il.GetType();
  359. if (GetState() == PACKED)
  360. {
  361. switch (type)
  362. {
  363. case InventoryLocationType.ATTACHMENT:
  364. return 1;
  365. default:
  366. return 0;
  367. }
  368. }
  369. else
  370. {
  371. switch (type)
  372. {
  373. case InventoryLocationType.ATTACHMENT:
  374. case InventoryLocationType.GROUND:
  375. return 1;
  376. default:
  377. return 0;
  378. }
  379. }
  380. }
  381. return 0;
  382. }
  383. int GetState()
  384. {
  385. return m_State;
  386. }
  387. int GetStateLocal()
  388. {
  389. return m_StateLocal;
  390. }
  391. bool CanBePacked()
  392. {
  393. if (GetState() == PITCHED)
  394. {
  395. if (GetInventory().GetCargo().GetItemCount() == 0 && GetInventory().AttachmentCount() == 0)
  396. {
  397. return true;
  398. }
  399. }
  400. return false;
  401. }
  402. bool CanBeManipulated()
  403. {
  404. if (GetState() == PACKED)
  405. {
  406. return true;
  407. }
  408. else
  409. {
  410. return false;
  411. }
  412. }
  413. bool CanAttach(ItemBase item)
  414. {
  415. if (item.IsKindOf ("CamoNet") && GetState() == PITCHED)
  416. {
  417. return true;
  418. }
  419. return false;
  420. }
  421. override bool IsIgnoredByConstruction()
  422. {
  423. return false;
  424. }
  425. void Pack(bool update_navmesh, bool init = false)
  426. {
  427. HideAllAnimationsAndProxyPhysics();
  428. m_State = PACKED;
  429. m_IsEntrance = PACKED;
  430. m_IsWindow = PACKED;
  431. m_IsToggle = PACKED;
  432. Refresh();
  433. GetInventory().LockInventory(HIDE_INV_FROM_SCRIPT);
  434. if (update_navmesh)
  435. {
  436. RegenerateNavmesh();
  437. }
  438. DestroyClutterCutter();
  439. if (GetGame().IsServer() && !IsHologram())
  440. MiscGameplayFunctions.DropAllItemsInInventoryInBounds(this, m_HalfExtents);
  441. SetSynchDirty();
  442. if ((!GetGame().IsDedicatedServer()) && !init)
  443. {
  444. GetOnViewIndexChanged().Invoke();
  445. }
  446. }
  447. void Pitch(bool update_navmesh, bool init = false)
  448. {
  449. HideAllAnimationsAndProxyPhysics();
  450. m_State = PITCHED;
  451. m_IsEntrance = PITCHED;
  452. m_IsWindow = PITCHED;
  453. m_IsToggle = PITCHED;
  454. Refresh();
  455. GetInventory().UnlockInventory(HIDE_INV_FROM_SCRIPT);
  456. if (update_navmesh)
  457. {
  458. RegenerateNavmesh();
  459. }
  460. SetSynchDirty();
  461. if ((!GetGame().IsDedicatedServer()) && !init)
  462. {
  463. GetOnViewIndexChanged().Invoke();
  464. }
  465. }
  466. protected void TryPitch(bool update_navmesh, bool init = false)
  467. {
  468. if (GetHierarchyRootPlayer())
  469. {
  470. if (GetGame().IsDedicatedServer())
  471. {
  472. Pack(update_navmesh,init);
  473. }
  474. return;
  475. }
  476. Pitch(update_navmesh,init);
  477. }
  478. void UpdateVisuals()
  479. {
  480. string proxy_selection_name;
  481. string animation_name;
  482. if (GetState() == PITCHED)
  483. {
  484. for (int i = 0; i < m_ShowAnimationsWhenPitched.Count(); i++)
  485. {
  486. animation_name = m_ShowAnimationsWhenPitched.Get(i);
  487. SetAnimationPhase(animation_name, 0);
  488. }
  489. HandleOpeningsVisuals();
  490. }
  491. else
  492. {
  493. for (int j = 0; j < m_ShowAnimationsWhenPacked.Count(); j++)
  494. {
  495. animation_name = m_ShowAnimationsWhenPacked.Get(j);
  496. SetAnimationPhase(animation_name, 0);
  497. }
  498. }
  499. }
  500. void UpdatePhysics()
  501. {
  502. string proxy_selection_name;
  503. string animation_name;
  504. if (GetState() == PITCHED)
  505. {
  506. for (int i = 0; i < m_ShowAnimationsWhenPitched.Count(); i++)
  507. {
  508. animation_name = m_ShowAnimationsWhenPitched.Get(i);
  509. proxy_selection_name = animation_name;
  510. proxy_selection_name.ToLower();
  511. AddProxyPhysics(proxy_selection_name);
  512. }
  513. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(HandleOpeningsPhysics);
  514. }
  515. else
  516. {
  517. for (int j = 0; j < m_ShowAnimationsWhenPacked.Count(); j++)
  518. {
  519. animation_name = m_ShowAnimationsWhenPacked.Get(j);
  520. proxy_selection_name = animation_name;
  521. proxy_selection_name.ToLower();
  522. AddProxyPhysics(proxy_selection_name);
  523. }
  524. }
  525. }
  526. //refresh visual/physics state
  527. void Refresh()
  528. {
  529. GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).Call(UpdateVisuals);
  530. UpdatePhysics();
  531. }
  532. bool CanToggleAnimations(string selection)
  533. {
  534. for (int i = 0; i < m_ToggleAnimations.Count(); i++)
  535. {
  536. ToggleAnimations toggle = m_ToggleAnimations.GetKey(i);
  537. string toggle_off = toggle.GetToggleOff();
  538. toggle_off.ToLower();
  539. string toggle_on = toggle.GetToggleOn();
  540. toggle_on.ToLower();
  541. if (toggle_off == selection || toggle_on == selection)
  542. {
  543. string zone;
  544. DamageSystem.GetDamageZoneFromComponentName(this,selection,zone);
  545. return GetHealthLevel(zone) < GameConstants.STATE_RUINED;
  546. }
  547. }
  548. return false;
  549. }
  550. void ResetToggle()
  551. {
  552. m_IsEntrance = false;
  553. m_IsWindow = false;
  554. m_IsToggle = false;
  555. }
  556. void ManipulateEntrance()
  557. {
  558. m_IsEntrance = true;
  559. }
  560. void ManipulateWindow()
  561. {
  562. m_IsWindow = true;
  563. }
  564. bool IsManipulatedEntrance()
  565. {
  566. return m_IsEntrance;
  567. }
  568. bool IsManipulatedWindow()
  569. {
  570. return m_IsWindow;
  571. }
  572. //used by user action
  573. void ToggleAnimation(string selection)
  574. {
  575. if (m_State == PACKED)
  576. {
  577. return;
  578. }
  579. bool is_closed;
  580. ResetToggle();
  581. for (int i = 0; i < m_ToggleAnimations.Count(); i++)
  582. {
  583. ToggleAnimations toggle = m_ToggleAnimations.GetKey(i);
  584. string toggle_off = toggle.GetToggleOff();
  585. toggle_off.ToLower();
  586. string toggle_on = toggle.GetToggleOn();
  587. toggle_on.ToLower();
  588. if (toggle_off == selection || toggle_on == selection)
  589. {
  590. is_closed = m_OpeningMask & toggle.GetOpeningBit();
  591. if (is_closed)
  592. {
  593. SetAnimationPhase(toggle.GetToggleOff(), 0);
  594. AddProxyPhysics(toggle.GetToggleOff());
  595. SetAnimationPhase(toggle.GetToggleOn(), 1);
  596. RemoveProxyPhysics(toggle.GetToggleOn());
  597. m_ToggleAnimations.Set(toggle, false);
  598. m_IsToggle = true;
  599. m_OpeningMask &= ~toggle.GetOpeningBit();
  600. if (selection.Contains("window"))
  601. {
  602. ManipulateWindow();
  603. }
  604. if (selection.Contains("entrance") || selection.Contains("door"))
  605. {
  606. ManipulateEntrance();
  607. }
  608. AnimateCamonetToggle(toggle);
  609. }
  610. else
  611. {
  612. SetAnimationPhase(toggle.GetToggleOff(), 1);
  613. RemoveProxyPhysics(toggle.GetToggleOff());
  614. SetAnimationPhase(toggle.GetToggleOn(), 0);
  615. AddProxyPhysics(toggle.GetToggleOn());
  616. m_ToggleAnimations.Set(toggle, true);
  617. m_IsToggle = false;
  618. m_OpeningMask |= toggle.GetOpeningBit();
  619. if (selection.Contains("window"))
  620. {
  621. ManipulateWindow();
  622. }
  623. if (selection.Contains("entrance") || selection.Contains("door"))
  624. {
  625. ManipulateEntrance();
  626. }
  627. AnimateCamonetToggle(toggle);
  628. }
  629. }
  630. }
  631. SetSynchDirty();
  632. SoundSynchRemote();
  633. }
  634. void HandleCamoNetAttachment(bool hide)
  635. {
  636. SetAnimationPhase("CamoNet", hide);
  637. }
  638. void AnimateCamonetToggle(ToggleAnimations toggle) {};
  639. void AnimateCamonetByOpeningSelection(string opening_selection) {};
  640. string GetSoundOpen() {};
  641. string GetSoundClose() {};
  642. string GetSoundOpenWindow() {};
  643. string GetSoundCloseWindow() {};
  644. void SoundTentOpenPlay()
  645. {
  646. EffectSound sound = SEffectManager.PlaySound(GetSoundOpen(), GetPosition());
  647. sound.SetAutodestroy(true);
  648. }
  649. void SoundTentClosePlay()
  650. {
  651. EffectSound sound = SEffectManager.PlaySound(GetSoundClose(), GetPosition());
  652. sound.SetAutodestroy(true);
  653. }
  654. void SoundTentOpenWindowPlay()
  655. {
  656. EffectSound sound = SEffectManager.PlaySound(GetSoundOpenWindow(), GetPosition());
  657. sound.SetAutodestroy(true);
  658. }
  659. void SoundTentCloseWindowPlay()
  660. {
  661. EffectSound sound = SEffectManager.PlaySound(GetSoundCloseWindow(), GetPosition());
  662. sound.SetAutodestroy(true);
  663. }
  664. void RegenerateNavmesh()
  665. {
  666. SetAffectPathgraph(true, false);
  667. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(GetGame().UpdatePathgraphRegionByObject, 100, false, this);
  668. }
  669. bool HasClutterCutter() {};
  670. string GetClutterCutter() {};
  671. void DestroyClutterCutter()
  672. {
  673. if (GetGame().IsMultiplayer() || GetGame().IsServer())
  674. {
  675. if (m_ClutterCutter)
  676. {
  677. GetGame().ObjectDelete(m_ClutterCutter);
  678. }
  679. }
  680. }
  681. //================================================================
  682. // ADVANCED PLACEMENT
  683. //================================================================
  684. override bool IsDeployable()
  685. {
  686. return true;
  687. }
  688. override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
  689. {
  690. super.OnPlacementComplete(player, position, orientation);
  691. if (GetGame().IsServer())
  692. {
  693. TryPitch(true);
  694. SetIsDeploySound(true);
  695. }
  696. }
  697. override void SetActions()
  698. {
  699. super.SetActions();
  700. AddAction(ActionTogglePlaceObject);
  701. AddAction(ActionToggleTentOpen);
  702. AddAction(ActionPackTent);
  703. AddAction(ActionDeployObject);
  704. }
  705. void HandleOpeningsVisuals()
  706. {
  707. bool is_closed;
  708. bool is_ruined;
  709. string zone;
  710. string component;
  711. ToggleAnimations toggle;
  712. for (int i = 0; i < m_ToggleAnimations.Count(); i++)
  713. {
  714. toggle = m_ToggleAnimations.GetKey(i);
  715. is_closed = m_OpeningMask & toggle.GetOpeningBit();
  716. component = toggle.GetToggleOff(); //either one works
  717. component.ToLower();
  718. DamageSystem.GetDamageZoneFromComponentName(this,component,zone);
  719. //is_ruined = (GetHealthLevel(zone) == GameConstants.STATE_RUINED);
  720. if (is_closed)
  721. {
  722. SetAnimationPhase(toggle.GetToggleOff(),1);
  723. SetAnimationPhase(toggle.GetToggleOn(),is_ruined);
  724. m_ToggleAnimations.Set(toggle, false);
  725. }
  726. else
  727. {
  728. SetAnimationPhase(toggle.GetToggleOn(),1);
  729. SetAnimationPhase(toggle.GetToggleOff(),is_ruined);
  730. m_ToggleAnimations.Set(toggle, true);
  731. }
  732. //AnimateCamonetToggle(toggle);
  733. }
  734. }
  735. void HandleOpeningsPhysics()
  736. {
  737. bool is_closed;
  738. bool is_ruined;
  739. int hplevel;
  740. string zone;
  741. string component;
  742. ToggleAnimations toggle;
  743. for (int i = 0; i < m_ToggleAnimations.Count(); i++)
  744. {
  745. toggle = m_ToggleAnimations.GetKey(i);
  746. is_closed = m_OpeningMask & toggle.GetOpeningBit();
  747. component = toggle.GetToggleOff(); //either one works
  748. component.ToLower();
  749. DamageSystem.GetDamageZoneFromComponentName(this,component,zone);
  750. is_ruined = (GetHealthLevel(zone) == GameConstants.STATE_RUINED);
  751. //re-adding physics to avoid proxy physics stacking
  752. RemoveProxyPhysics(toggle.GetToggleOff());
  753. RemoveProxyPhysics(toggle.GetToggleOn());
  754. if (!is_ruined && GetState() == PITCHED)
  755. {
  756. if (is_closed)
  757. {
  758. AddProxyPhysics(toggle.GetToggleOn());
  759. }
  760. else
  761. {
  762. AddProxyPhysics(toggle.GetToggleOff());
  763. }
  764. }
  765. }
  766. }
  767. override int GetDamageSystemVersionChange()
  768. {
  769. return 110;
  770. }
  771. override bool CanReceiveItemIntoCargo(EntityAI item)
  772. {
  773. if (GetHealthLevel() == GameConstants.STATE_RUINED || m_IsBeingPacked)
  774. return false;
  775. return super.CanReceiveItemIntoCargo(item);
  776. }
  777. override bool CanLoadItemIntoCargo(EntityAI item)
  778. {
  779. if (!super.CanLoadItemIntoCargo(item))
  780. return false;
  781. if (GetHealthLevel() == GameConstants.STATE_RUINED)
  782. return false;
  783. return true;
  784. }
  785. override bool CanReceiveAttachment(EntityAI attachment, int slotId)
  786. {
  787. if (GetHealthLevel() == GameConstants.STATE_RUINED)
  788. return false;
  789. return super.CanReceiveAttachment(attachment, slotId);
  790. }
  791. override bool CanLoadAttachment(EntityAI attachment)
  792. {
  793. if (GetHealthLevel() == GameConstants.STATE_RUINED)
  794. return false;
  795. return super.CanLoadAttachment(attachment);
  796. }
  797. override bool CanBePlaced(Man player, vector position)
  798. {
  799. vector playerpos = player.GetPosition();
  800. float delta1 = playerpos[1] - position[1];
  801. if (delta1 > MAX_PLACEMENT_HEIGHT_DIFF || delta1 < -MAX_PLACEMENT_HEIGHT_DIFF)
  802. return false;
  803. return true;
  804. }
  805. void SetIsBeingPacked(bool isBeingPacked)
  806. {
  807. m_IsBeingPacked = isBeingPacked;
  808. SetSynchDirty();
  809. }
  810. //!DEPRECATED
  811. protected ref EffectSound m_DeployLoopSound; //DEPRECATED in favor of m_DeployLoopSoundEx
  812. void PlayDeployLoopSound(); //!DEPRECATED
  813. void StopDeployLoopSound(); //!DEPRECATED
  814. };