tentbase.c 21 KB

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