transport.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*!
  2. Base native class of all vehicles in game.
  3. */
  4. #ifdef FEATURE_NETWORK_RECONCILIATION
  5. class TransportOwnerState : PawnOwnerState
  6. {
  7. proto native void SetWorldTransform(vector transform[4]);
  8. proto native void GetWorldTransform(out vector transform[4]);
  9. proto native void SetLinearVelocity(vector value);
  10. proto native void GetLinearVelocity(out vector value);
  11. proto native void SetAngularVelocity(vector value);
  12. proto native void GetAngularVelocity(out vector value);
  13. proto native void SetPhysicsTimeStamp(int value);
  14. proto native int GetPhysicsTimeStamp();
  15. proto native void SetWaterTime(float value);
  16. proto native float GetWaterTime();
  17. proto native void SetBuoyancySubmerged(float value);
  18. proto native float GetBuoyancySubmerged();
  19. #ifdef DIAG_DEVELOPER
  20. override event void GetTransform(inout vector transform[4])
  21. {
  22. GetWorldTransform(transform);
  23. }
  24. #endif
  25. };
  26. class TransportMove : PawnMove
  27. {
  28. proto native void SetWorldTransform(vector transform[4]);
  29. proto native void GetWorldTransform(out vector transform[4]);
  30. proto native void SetLinearVelocity(vector value);
  31. proto native void GetLinearVelocity(out vector value);
  32. proto native void SetAngularVelocity(vector value);
  33. proto native void GetAngularVelocity(out vector value);
  34. #ifdef DIAG_DEVELOPER
  35. override event void GetTransform(inout vector transform[4])
  36. {
  37. GetWorldTransform(transform);
  38. }
  39. #endif
  40. };
  41. //! Uses NetworkMoveStrategy.NONE
  42. class Transport extends Pawn
  43. #else
  44. class Transport extends EntityAI
  45. #endif
  46. {
  47. ref TIntArray m_SingleUseActions;
  48. ref TIntArray m_ContinuousActions;
  49. ref TIntArray m_InteractActions;
  50. protected bool m_EngineZoneReceivedHit;
  51. protected vector m_fuelPos;
  52. protected ref set<int> m_UnconsciousCrewMemberIndices;
  53. protected ref set<int> m_DeadCrewMemberIndices;
  54. void Transport()
  55. {
  56. RegisterNetSyncVariableBool("m_EngineZoneReceivedHit");
  57. if ( MemoryPointExists("refill") )
  58. m_fuelPos = GetMemoryPointPos("refill");
  59. else
  60. m_fuelPos = "0 0 0";
  61. m_UnconsciousCrewMemberIndices = new set<int>();
  62. m_DeadCrewMemberIndices = new set<int>();
  63. }
  64. override void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
  65. {
  66. super.EEHitBy(damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
  67. SetEngineZoneReceivedHit(dmgZone == "Engine");
  68. }
  69. override int GetMeleeTargetType()
  70. {
  71. return EMeleeTargetType.NONALIGNABLE;
  72. }
  73. //!
  74. protected override event typename GetOwnerStateType()
  75. {
  76. return TransportOwnerState;
  77. }
  78. //!
  79. protected override event typename GetMoveType()
  80. {
  81. return TransportMove;
  82. }
  83. //! Synchronizes car's state in case the simulation is not running.
  84. proto native void Synchronize();
  85. //! Returns crew capacity of this vehicle.
  86. proto native int CrewSize();
  87. //! Returns crew member index based on action component index.
  88. //! -1 is returned when no crew position corresponds to given component index.
  89. proto native int CrewPositionIndex( int componentIdx );
  90. //! Returns crew member index based on player's instance.
  91. //! -1 is returned when the player is not isnide.
  92. proto native int CrewMemberIndex( Human player );
  93. //! Returns crew member based on position index.
  94. //! Null can be returned if no Human is present on the given position.
  95. proto native Human CrewMember( int posIdx );
  96. //! Returns the driver
  97. //! Null can be returned if no Human is present.
  98. proto native Human CrewDriver();
  99. //! Reads entry point and direction into vehicle on given position in model space.
  100. proto void CrewEntry( int posIdx, out vector pos, out vector dir );
  101. //! Reads entry point and direction into vehicle on given position in world space.
  102. proto void CrewEntryWS( int posIdx, out vector pos, out vector dir );
  103. //! Returns crew transformation indside vehicle in model space
  104. proto void CrewTransform( int posIdx, out vector mat[4] );
  105. //! Returns crew transformation indside vehicle in world space
  106. proto void CrewTransformWS( int posIdx, out vector mat[4] );
  107. //! Performs transfer of player from world into vehicle on given position.
  108. proto native void CrewGetIn( Human player, int posIdx );
  109. //! Performs transfer of player from vehicle into world from given position.
  110. proto native Human CrewGetOut( int posIdx );
  111. //! Handles death of player in vehicle and awakes its physics if needed
  112. proto native void CrewDeath( int posIdx );
  113. override bool IsTransport()
  114. {
  115. return true;
  116. }
  117. override bool IsIgnoredByConstruction()
  118. {
  119. return false;
  120. }
  121. override bool IsHealthVisible()
  122. {
  123. return true;
  124. }
  125. override bool ShowZonesHealth()
  126. {
  127. return true;
  128. }
  129. override int GetHideIconMask()
  130. {
  131. return EInventoryIconVisibility.HIDE_VICINITY;
  132. }
  133. float GetMomentum()
  134. {
  135. return GetVelocity(this).Length() * dBodyGetMass(this);
  136. }
  137. bool IsVitalSparkPlug()
  138. {
  139. return true;
  140. }
  141. string GetVehicleType()
  142. {
  143. return "VehicleTypeUndefined";
  144. }
  145. string GetActionCompNameFuel()
  146. {
  147. return "refill";
  148. }
  149. float GetActionDistanceFuel()
  150. {
  151. return 1.5;
  152. }
  153. vector GetRefillPointPosWS()
  154. {
  155. return ModelToWorld( m_fuelPos );
  156. }
  157. bool IsAnyCrewPresent()
  158. {
  159. for (int index = 0; index < CrewSize(); ++index)
  160. {
  161. if (CrewMember(index) != null)
  162. return true;
  163. }
  164. return false;
  165. }
  166. float GetTransportCameraDistance()
  167. {
  168. return 4.0;
  169. }
  170. void MarkCrewMemberUnconscious(int crewMemberIndex)
  171. {
  172. set<int> crewMemberIndicesCopy = new set<int>();
  173. crewMemberIndicesCopy.Copy(m_UnconsciousCrewMemberIndices);
  174. crewMemberIndicesCopy.Insert(crewMemberIndex);
  175. m_UnconsciousCrewMemberIndices = crewMemberIndicesCopy;
  176. }
  177. void MarkCrewMemberDead(int crewMemberIndex)
  178. {
  179. set<int> crewMemberIndicesCopy = new set<int>();
  180. crewMemberIndicesCopy.Copy(m_DeadCrewMemberIndices);
  181. crewMemberIndicesCopy.Insert(crewMemberIndex);
  182. m_DeadCrewMemberIndices = crewMemberIndicesCopy;
  183. }
  184. protected void HandleByCrewMemberState(ECrewMemberState state);
  185. vector GetTransportCameraOffset()
  186. {
  187. return "0 1.3 0";
  188. }
  189. int GetAnimInstance()
  190. {
  191. #ifndef CFGMODS_DEFINE_TEST
  192. Error("GetAnimInstance() not implemented");
  193. return 0;
  194. #else
  195. return 2;
  196. #endif
  197. }
  198. int GetSeatAnimationType( int posIdx )
  199. {
  200. #ifndef CFGMODS_DEFINE_TEST
  201. Error("GetSeatAnimationType() not implemented");
  202. #endif
  203. return 0;
  204. }
  205. int Get3rdPersonCameraType()
  206. {
  207. #ifndef CFGMODS_DEFINE_TEST
  208. Error("Get3rdPersonCameraType() not implemented");
  209. return 0;
  210. #else
  211. return 31;
  212. #endif
  213. }
  214. bool CrewCanGetThrough( int posIdx )
  215. {
  216. #ifndef CFGMODS_DEFINE_TEST
  217. return false;
  218. #else
  219. return true;
  220. #endif
  221. }
  222. bool CanReachSeatFromSeat( int currentSeat, int nextSeat )
  223. {
  224. #ifndef CFGMODS_DEFINE_TEST
  225. return false;
  226. #else
  227. return true;
  228. #endif
  229. }
  230. bool CanReachSeatFromDoors( string pSeatSelection, vector pFromPos, float pDistance = 1.0 )
  231. {
  232. #ifndef CFGMODS_DEFINE_TEST
  233. return false;
  234. #else
  235. return true;
  236. #endif
  237. }
  238. bool CanReachDoorsFromSeat( string pDoorsSelection, int pCurrentSeat )
  239. {
  240. #ifndef CFGMODS_DEFINE_TEST
  241. return false;
  242. #else
  243. return true;
  244. #endif
  245. }
  246. int GetSeatIndexFromDoor( string pDoorSelection )
  247. {
  248. //Potientially could be fixed some other way, currently follows the unfortunate pattern that CanReachDoorsFromSeat has created
  249. switch (pDoorSelection)
  250. {
  251. case "DoorsDriver":
  252. return 0;
  253. break;
  254. case "DoorsCoDriver":
  255. return 1;
  256. break;
  257. case "DoorsCargo1":
  258. return 2;
  259. break;
  260. case "DoorsCargo2":
  261. return 3;
  262. break;
  263. }
  264. return -1;
  265. }
  266. bool IsIgnoredObject( Object o )
  267. {
  268. if (!o)
  269. return false;
  270. //! If the player can't interact (hint: collide) with the object, then it is ignored
  271. int layer = dBodyGetInteractionLayer(o);
  272. bool interacts = dGetInteractionLayer(this, PhxInteractionLayers.CHARACTER, layer);
  273. if (!interacts)
  274. {
  275. return true;
  276. }
  277. DayZPlayer player;
  278. if (Class.CastTo(player, o))
  279. {
  280. //! Ignore any player that is currently in this vehicle
  281. HumanCommandVehicle hcv = player.GetCommand_Vehicle();
  282. if (hcv && hcv.GetTransport() == this)
  283. {
  284. return true;
  285. }
  286. }
  287. EntityAI e = EntityAI.Cast(o);
  288. // CanBeSkinned means it is a dead entity which should not block the door
  289. return ( ( e && (e.IsZombie() || e.IsHologram()) ) || o.CanBeSkinned() || o.IsBush() || o.IsTree() );
  290. }
  291. void SetEngineZoneReceivedHit(bool pState)
  292. {
  293. m_EngineZoneReceivedHit = pState;
  294. SetSynchDirty();
  295. }
  296. bool HasEngineZoneReceivedHit()
  297. {
  298. return m_EngineZoneReceivedHit;
  299. }
  300. bool IsAreaAtDoorFree( int currentSeat, float maxAllowedObjHeight, inout vector extents, out vector transform[4] )
  301. {
  302. GetTransform(transform);
  303. vector crewPos;
  304. vector crewDir;
  305. CrewEntry( currentSeat, crewPos, crewDir );
  306. vector entry[4];
  307. entry[2] = crewDir;
  308. entry[0] = vector.Up * crewDir;
  309. entry[1] = entry[2] * entry[0];
  310. entry[3] = crewPos;
  311. Math3D.MatrixMultiply4( transform, entry, transform );
  312. vector position = transform[3];
  313. vector orientation = Math3D.MatrixToAngles(transform);
  314. position[1] = position[1] + maxAllowedObjHeight + (extents[1] * 0.5);
  315. array<Object> excluded = new array<Object>;
  316. array<Object> collided = new array<Object>;
  317. excluded.Insert(this);
  318. GetGame().IsBoxColliding(position, orientation, extents, excluded, collided);
  319. orientation.RotationMatrixFromAngles(transform);
  320. transform[3] = position;
  321. foreach (Object o : collided)
  322. {
  323. EntityAI e = EntityAI.Cast(o);
  324. if (IsIgnoredObject(o))
  325. continue;
  326. vector minmax[2];
  327. if (o.GetCollisionBox(minmax))
  328. return false;
  329. }
  330. return true;
  331. }
  332. bool IsAreaAtDoorFree( int currentSeat, float maxAllowedObjHeight = 0.5, float horizontalExtents = 0.5, float playerHeight = 1.7 )
  333. {
  334. vector transform[4];
  335. vector extents;
  336. extents[0] = horizontalExtents;
  337. extents[1] = playerHeight;
  338. extents[2] = horizontalExtents;
  339. return IsAreaAtDoorFree( currentSeat, maxAllowedObjHeight, extents, transform );
  340. }
  341. Shape DebugFreeAreaAtDoor( int currentSeat, float maxAllowedObjHeight = 0.5, float horizontalExtents = 0.5, float playerHeight = 1.7 )
  342. {
  343. int color = ARGB(20, 0, 255, 0);
  344. vector transform[4];
  345. vector extents;
  346. extents[0] = horizontalExtents;
  347. extents[1] = playerHeight;
  348. extents[2] = horizontalExtents;
  349. if (!IsAreaAtDoorFree( currentSeat, maxAllowedObjHeight, extents, transform ))
  350. {
  351. color = ARGB(20, 255, 0, 0);
  352. }
  353. Shape shape = Debug.DrawBox(-extents * 0.5, extents * 0.5, color);
  354. shape.SetMatrix(transform);
  355. return shape;
  356. }
  357. };
  358. class VehicleContactData
  359. {
  360. vector m_LocalPos;
  361. IEntity m_Other;
  362. float m_Impulse;
  363. void SetData(vector localPos, IEntity other, float impulse)
  364. {
  365. m_LocalPos = localPos;
  366. m_Other = other;
  367. m_Impulse = impulse;
  368. }
  369. }