man.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. #ifdef FEATURE_NETWORK_RECONCILIATION
  2. class Person extends Pawn
  3. {
  4. //! ???
  5. };
  6. #endif
  7. #ifdef FEATURE_NETWORK_RECONCILIATION
  8. class Man extends Person
  9. #else
  10. class Man extends EntityAI
  11. #endif
  12. {
  13. //! Returns player's input interface
  14. proto native UAInterface GetInputInterface();
  15. //! Returns player's identity
  16. proto native PlayerIdentity GetIdentity();
  17. //! Returns vehicle which this Man object is driving. If this Man object isn't as driver of any vehicle it will return NULL.
  18. proto native EntityAI GetDrivingVehicle();
  19. proto native owned string GetCurrentWeaponMode();
  20. //! Set speech restriction
  21. proto native void SetSpeechRestricted(bool state);
  22. //! Check if player has resctricted speech
  23. proto native bool IsSpeechRestricted();
  24. //! Texture that is used on the Man's face and hands
  25. proto native void SetFaceTexture(string texture_name);
  26. //! Material that is used on the Man's face and hands
  27. proto native void SetFaceMaterial(string material_name);
  28. proto native bool IsSoundInsideBuilding();
  29. proto native bool IsCameraInsideVehicle();
  30. proto native owned string GetMasterAttenuation();
  31. proto native void SetMasterAttenuation(string masterAttenuation);
  32. void Man()
  33. {
  34. SetFlags(EntityFlags.TOUCHTRIGGERS, false);
  35. }
  36. override bool IsMan()
  37. {
  38. return true;
  39. }
  40. override bool IsHealthVisible()
  41. {
  42. return false;
  43. }
  44. override bool HasFixedActionTargetCursorPosition()
  45. {
  46. return true;
  47. }
  48. bool IsUnconscious();
  49. //! uncon command might be still in progress but state already changed (for simple checks only - eg.: UI)
  50. bool IsUnconsciousStateOnly();
  51. int GetPlayerState()
  52. {
  53. if (IsAlive())
  54. return EPlayerStates.ALIVE;
  55. return EPlayerStates.DEAD;
  56. }
  57. void AddItemToDelete(EntityAI item);
  58. ///@{ inventory
  59. HumanInventory GetHumanInventory()
  60. {
  61. HumanInventory i = HumanInventory.Cast(GetInventory());
  62. return i;
  63. }
  64. //Called when an item is removed from the cargo of this item
  65. protected ref ScriptInvoker m_OnItemAddedToHands;
  66. //Called when an item is moved around in the cargo of this item
  67. protected ref ScriptInvoker m_OnItemRemovedFromHands;
  68. ScriptInvoker GetOnItemAddedToHands()
  69. {
  70. if (!m_OnItemAddedToHands)
  71. m_OnItemAddedToHands = new ScriptInvoker();
  72. return m_OnItemAddedToHands;
  73. }
  74. ScriptInvoker GetOnItemRemovedFromHands()
  75. {
  76. if( !m_OnItemRemovedFromHands )
  77. m_OnItemRemovedFromHands = new ScriptInvoker;
  78. return m_OnItemRemovedFromHands;
  79. }
  80. void EEItemIntoHands(EntityAI item)
  81. {
  82. SetWeightDirty();
  83. if( m_OnItemAddedToHands )
  84. m_OnItemAddedToHands.Invoke( item, this );
  85. }
  86. void EEItemOutOfHands(EntityAI item)
  87. {
  88. SetWeightDirty();
  89. if( m_OnItemRemovedFromHands )
  90. m_OnItemRemovedFromHands.Invoke( item, this );
  91. }
  92. ///@{ drop juncture
  93. bool JunctureDropEntity (notnull EntityAI item)
  94. {
  95. return DropEntityImpl(InventoryMode.JUNCTURE, this, item);
  96. }
  97. override bool PredictiveDropEntity (notnull EntityAI item)
  98. {
  99. if (!ScriptInputUserData.CanStoreInputUserData())
  100. {
  101. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveDropEntity input data not sent yet, cannot allow another input action");
  102. return false;
  103. }
  104. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  105. return JunctureDropEntity(item);
  106. else
  107. return DropEntityImpl(InventoryMode.PREDICTIVE, this, item);
  108. }
  109. override bool LocalDropEntity (notnull EntityAI item)
  110. {
  111. return DropEntityImpl(InventoryMode.LOCAL, this, item);
  112. }
  113. override bool ServerDropEntity (notnull EntityAI item)
  114. {
  115. return DropEntityImpl(InventoryMode.SERVER, this, item);
  116. }
  117. protected bool DropEntityImpl (InventoryMode mode, notnull EntityAI owner, notnull EntityAI item)
  118. {
  119. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::DropEntity(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  120. bool code = GetHumanInventory().DropEntity(mode, owner, item);
  121. UpdateInventoryMenu();
  122. return code;
  123. }
  124. ///@} drop juncture
  125. override bool CanDropEntity (notnull EntityAI item) { return true; }
  126. void OnItemInHandsChanged () { }
  127. bool NeedInventoryJunctureFromServer (notnull EntityAI item, EntityAI currParent, EntityAI newParent) { return false; }
  128. ///@{ hand juncture
  129. void JunctureTakeEntityToHands (notnull EntityAI item)
  130. {
  131. TakeEntityToHandsImpl(InventoryMode.JUNCTURE, item);
  132. }
  133. void PredictiveTakeEntityToHands (EntityAI item)
  134. {
  135. if (!ScriptInputUserData.CanStoreInputUserData())
  136. {
  137. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToHands input data not sent yet, cannot allow another input action");
  138. return;
  139. }
  140. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  141. JunctureTakeEntityToHands(item);
  142. else
  143. TakeEntityToHandsImpl(InventoryMode.PREDICTIVE, item);
  144. }
  145. void LocalTakeEntityToHands (EntityAI item)
  146. {
  147. TakeEntityToHandsImpl(InventoryMode.LOCAL, item);
  148. }
  149. void ServerTakeEntityToHands (EntityAI item)
  150. {
  151. TakeEntityToHandsImpl(InventoryMode.SERVER, item);
  152. }
  153. void TakeEntityToHandsImpl (InventoryMode mode, EntityAI item)
  154. {
  155. if (!GetGame().IsDedicatedServer() )
  156. {
  157. InventoryLocation il = new InventoryLocation;
  158. il.SetHands(this, item);
  159. //GetInventory().AddInventoryReservationEx(item, il ,GameInventory.c_InventoryReservationTimeoutShortMS);
  160. }
  161. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Hands(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  162. EntityAI itemInHands = GetHumanInventory().GetEntityInHands();
  163. InventoryLocation src_item = new InventoryLocation;
  164. if (item.GetInventory().GetCurrentInventoryLocation(src_item))
  165. {
  166. if (itemInHands == null)
  167. {
  168. InventoryLocation hand_dst = new InventoryLocation;
  169. hand_dst.SetHands(this, item);
  170. GetHumanInventory().TakeToDst(mode, src_item, hand_dst);
  171. }
  172. else if (GetHumanInventory().CanSwapEntitiesEx(itemInHands, item))
  173. GetInventory().SwapEntities(mode, itemInHands, item);
  174. UpdateInventoryMenu();
  175. }
  176. }
  177. ///@} hand juncture
  178. void LocalDestroyEntityInHands ()
  179. {
  180. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Destroy IH=" + GetHumanInventory().GetEntityInHands());
  181. GetHumanInventory().LocalDestroyEntity(GetHumanInventory().GetEntityInHands());
  182. UpdateInventoryMenu();
  183. }
  184. void PredictiveMoveItemFromHandsToInventory ()
  185. {
  186. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Stash IH=" + GetHumanInventory().GetEntityInHands());
  187. if (!ScriptInputUserData.CanStoreInputUserData())
  188. {
  189. Print("[inv] PredictiveMoveItemFromHandsToInventory input data not sent yet, cannot allow another input action");
  190. return;
  191. }
  192. InventoryMode invMode = InventoryMode.PREDICTIVE;
  193. if (NeedInventoryJunctureFromServer( GetHumanInventory().GetEntityInHands(), this, this))
  194. invMode = InventoryMode.JUNCTURE;
  195. //! returns item to previous location, if available
  196. if (GetHumanInventory().GetEntityInHands().m_OldLocation && GetHumanInventory().GetEntityInHands().m_OldLocation.IsValid())
  197. {
  198. InventoryLocation invLoc = new InventoryLocation;
  199. GetHumanInventory().GetEntityInHands().GetInventory().GetCurrentInventoryLocation(invLoc);
  200. //old location is somewhere on player
  201. if (GetHumanInventory().GetEntityInHands().m_OldLocation.GetParent() && GetHumanInventory().GetEntityInHands().m_OldLocation.GetParent().GetHierarchyRootPlayer())
  202. {
  203. if (GetHumanInventory().LocationCanMoveEntity(invLoc, GetHumanInventory().GetEntityInHands().m_OldLocation))
  204. {
  205. if (GetHumanInventory().TakeToDst(invMode, invLoc,GetHumanInventory().GetEntityInHands().m_OldLocation))
  206. {
  207. UpdateInventoryMenu();
  208. return;
  209. }
  210. }
  211. }
  212. }
  213. GetHumanInventory().TakeEntityToInventory(invMode, FindInventoryLocationType.ATTACHMENT | FindInventoryLocationType.CARGO, GetHumanInventory().GetEntityInHands());
  214. UpdateInventoryMenu();
  215. }
  216. ///@{ !hand -> !hand replace
  217. protected bool ReplaceItemWithNewImpl(InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  218. {
  219. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace !HND lambda=" + lambda.DumpToString());
  220. bool code = GetHumanInventory().ReplaceItemWithNew(mode, lambda);
  221. UpdateInventoryMenu();
  222. return code;
  223. }
  224. bool LocalReplaceItemWithNew(ReplaceItemWithNewLambdaBase lambda)
  225. {
  226. return ReplaceItemWithNewImpl(InventoryMode.LOCAL, lambda);
  227. }
  228. bool ServerReplaceItemWithNew(ReplaceItemWithNewLambdaBase lambda)
  229. {
  230. return ReplaceItemWithNewImpl(InventoryMode.SERVER, lambda);
  231. }
  232. ///@} !hand -> !hand replace
  233. ///@{ !hand replace -> hand
  234. protected bool ReplaceItemElsewhereWithNewInHandsImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  235. {
  236. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace !HND->HND lambda=" + lambda.DumpToString());
  237. bool code = GetHumanInventory().ReplaceItemElsewhereWithNewInHands(mode, lambda);
  238. UpdateInventoryMenu();
  239. return code;
  240. }
  241. bool LocalReplaceItemElsewhereWithNewInHands (ReplaceItemWithNewLambdaBase lambda)
  242. {
  243. return ReplaceItemElsewhereWithNewInHandsImpl(InventoryMode.LOCAL, lambda);
  244. }
  245. bool ServerReplaceItemElsewhereWithNewInHands (ReplaceItemWithNewLambdaBase lambda)
  246. {
  247. return ReplaceItemElsewhereWithNewInHandsImpl(InventoryMode.SERVER, lambda);
  248. }
  249. ///@} !hand replace -> hand
  250. ///@{ hand replace
  251. protected bool ReplaceItemInHandsWithNewImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  252. {
  253. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace HND->HND lambda=" + lambda.DumpToString());
  254. bool code = GetHumanInventory().ReplaceItemInHandsWithNew(mode, lambda);
  255. UpdateInventoryMenu();
  256. return code;
  257. }
  258. bool LocalReplaceItemInHandsWithNew (ReplaceItemWithNewLambdaBase lambda)
  259. {
  260. return ReplaceItemInHandsWithNewImpl(InventoryMode.LOCAL, lambda);
  261. }
  262. bool ServerReplaceItemInHandsWithNew (ReplaceItemWithNewLambdaBase lambda)
  263. {
  264. return ReplaceItemInHandsWithNewImpl(InventoryMode.SERVER, lambda);
  265. }
  266. ///@} hand replace
  267. ///@{ hand replace2
  268. protected bool ReplaceItemInHandsWithNewElsewhereImpl (InventoryMode mode, ReplaceItemWithNewLambdaBase lambda)
  269. {
  270. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Replace HND->elsewhere lambda=" + lambda.DumpToString());
  271. bool code = GetHumanInventory().ReplaceItemInHandsWithNewElsewhere(mode, lambda);
  272. UpdateInventoryMenu();
  273. return code;
  274. }
  275. bool LocalReplaceItemInHandsWithNewElsewhere (ReplaceItemWithNewLambdaBase lambda)
  276. {
  277. return ReplaceItemInHandsWithNewElsewhereImpl(InventoryMode.LOCAL, lambda);
  278. }
  279. bool ServerReplaceItemInHandsWithNewElsewhere (ReplaceItemWithNewLambdaBase lambda)
  280. {
  281. return ReplaceItemInHandsWithNewElsewhereImpl(InventoryMode.SERVER, lambda);
  282. }
  283. ///@} hand replace2
  284. ///@{ to inv juncture
  285. bool JunctureTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  286. {
  287. return TakeEntityToInventoryImpl(InventoryMode.JUNCTURE, flags, item);
  288. }
  289. override bool PredictiveTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  290. {
  291. if (!ScriptInputUserData.CanStoreInputUserData())
  292. {
  293. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToInventory input data not sent yet, cannot allow another input action");
  294. return false;
  295. }
  296. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  297. return JunctureTakeEntityToInventory(flags, item);
  298. else
  299. return TakeEntityToInventoryImpl(InventoryMode.PREDICTIVE, flags, item);
  300. }
  301. override bool LocalTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  302. {
  303. return TakeEntityToInventoryImpl(InventoryMode.LOCAL, flags, item);
  304. }
  305. override bool ServerTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
  306. {
  307. return TakeEntityToInventoryImpl(InventoryMode.SERVER, flags, item);
  308. }
  309. protected bool TakeEntityToInventoryImpl (InventoryMode mode, FindInventoryLocationType flags, notnull EntityAI item)
  310. {
  311. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Inv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  312. bool code = GetHumanInventory().TakeEntityToInventory(mode, flags, item);
  313. UpdateInventoryMenu();
  314. return code;
  315. }
  316. ///@} to inv juncture
  317. ///@{ to cgo juncture
  318. bool JunctureTakeEntityToCargo (notnull EntityAI item)
  319. {
  320. return TakeEntityToCargoImpl(InventoryMode.JUNCTURE, item);
  321. }
  322. override bool PredictiveTakeEntityToCargo (notnull EntityAI item)
  323. {
  324. if (!ScriptInputUserData.CanStoreInputUserData())
  325. {
  326. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToCargo input data not sent yet, cannot allow another input action");
  327. return false;
  328. }
  329. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  330. return JunctureTakeEntityToCargo(item);
  331. else
  332. return TakeEntityToCargoImpl(InventoryMode.PREDICTIVE, item);
  333. }
  334. override bool LocalTakeEntityToCargo (notnull EntityAI item)
  335. {
  336. return TakeEntityToCargoImpl(InventoryMode.LOCAL, item);
  337. }
  338. override bool ServerTakeEntityToCargo (notnull EntityAI item)
  339. {
  340. return TakeEntityToCargoImpl(InventoryMode.SERVER, item);
  341. }
  342. protected bool TakeEntityToCargoImpl (InventoryMode mode, notnull EntityAI item)
  343. {
  344. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Cgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  345. bool code = GetHumanInventory().TakeEntityToCargo(mode, item);
  346. UpdateInventoryMenu();
  347. return code;
  348. }
  349. ///@} to cgo juncture
  350. ///@{ as att juncture
  351. bool JunctureTakeEntityAsAttachment (notnull EntityAI item)
  352. {
  353. return TakeEntityAsAttachmentImpl(InventoryMode.JUNCTURE, item);
  354. }
  355. override bool PredictiveTakeEntityAsAttachment (notnull EntityAI item)
  356. {
  357. if (!ScriptInputUserData.CanStoreInputUserData())
  358. {
  359. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityAsAttachment input data not sent yet, cannot allow another input action");
  360. return false;
  361. }
  362. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  363. return JunctureTakeEntityAsAttachment(item);
  364. else
  365. return TakeEntityAsAttachmentImpl(InventoryMode.PREDICTIVE, item);
  366. }
  367. override bool LocalTakeEntityAsAttachment (notnull EntityAI item)
  368. {
  369. return TakeEntityAsAttachmentImpl(InventoryMode.LOCAL, item);
  370. }
  371. override bool ServerTakeEntityAsAttachment (notnull EntityAI item)
  372. {
  373. return TakeEntityAsAttachmentImpl(InventoryMode.SERVER, item);
  374. }
  375. protected bool TakeEntityAsAttachmentImpl (InventoryMode mode, notnull EntityAI item)
  376. {
  377. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Att(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  378. bool code = GetHumanInventory().TakeEntityAsAttachment(mode, item);
  379. UpdateInventoryMenu();
  380. return code;
  381. }
  382. ///@} as att juncture
  383. ///@{ as att ex juncture
  384. bool JunctureTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  385. {
  386. return TakeEntityAsAttachmentExImpl(InventoryMode.JUNCTURE, item, slot);
  387. }
  388. override bool PredictiveTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  389. {
  390. if (!ScriptInputUserData.CanStoreInputUserData())
  391. {
  392. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityAsAttachmentEx input data not sent yet, cannot allow another input action");
  393. return false;
  394. }
  395. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), this))
  396. return JunctureTakeEntityAsAttachmentEx(item, slot);
  397. else
  398. return TakeEntityAsAttachmentExImpl(InventoryMode.PREDICTIVE, item, slot);
  399. }
  400. override bool LocalTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  401. {
  402. return TakeEntityAsAttachmentExImpl(InventoryMode.LOCAL, item, slot);
  403. }
  404. override bool ServerTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
  405. {
  406. return TakeEntityAsAttachmentExImpl(InventoryMode.SERVER, item, slot);
  407. }
  408. protected bool TakeEntityAsAttachmentExImpl (InventoryMode mode, notnull EntityAI item, int slot)
  409. {
  410. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2AttEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  411. bool code = GetHumanInventory().TakeEntityAsAttachmentEx(mode, item, slot);
  412. UpdateInventoryMenu();
  413. return code;
  414. }
  415. ///@} as att ex juncture
  416. ///@{ swap juncture
  417. bool JunctureSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  418. {
  419. return SwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2);
  420. }
  421. bool PredictiveSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  422. {
  423. if (!ScriptInputUserData.CanStoreInputUserData())
  424. {
  425. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveSwapEntities input data not sent yet, cannot allow another input action");
  426. return false;
  427. }
  428. bool need_j1 = NeedInventoryJunctureFromServer(item1, item1.GetHierarchyParent(), item2.GetHierarchyParent());
  429. bool need_j2 = NeedInventoryJunctureFromServer(item2, item2.GetHierarchyParent(), item1.GetHierarchyParent());
  430. if (need_j1 || need_j2)
  431. return SwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2);
  432. else
  433. return SwapEntitiesImpl(InventoryMode.PREDICTIVE, item1, item2);
  434. }
  435. bool LocalSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  436. {
  437. return SwapEntitiesImpl(InventoryMode.LOCAL, item1, item2);
  438. }
  439. bool ServerSwapEntities (notnull EntityAI item1, notnull EntityAI item2)
  440. {
  441. return SwapEntitiesImpl(InventoryMode.SERVER, item1, item2);
  442. }
  443. protected bool SwapEntitiesImpl (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2)
  444. {
  445. bool code;
  446. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::SwapImpl(" + typename.EnumToString(InventoryMode, mode) + ") item1=" + Object.GetDebugName(item1) + " item2=" + item2.GetDebugName(this));
  447. if (!GameInventory.CanSwapEntitiesEx(item1, item2))
  448. Error("[inv] (Man@" + this + ") SwapEntitiesImpl - cannot swap items!");
  449. code = GetHumanInventory().SwapEntities(mode, item1, item2);
  450. UpdateInventoryMenu();
  451. if (!code)
  452. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " SwapEntitiesImpl - cannot swap or forceswap");
  453. return code;
  454. }
  455. ///@} swap juncture
  456. ///@{ ForceSwap juncture
  457. bool JunctureForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  458. {
  459. return ForceSwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2, item2_dst);
  460. }
  461. bool PredictiveForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  462. {
  463. if (!ScriptInputUserData.CanStoreInputUserData())
  464. {
  465. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveForceSwapEntities input data not sent yet, cannot allow another input action");
  466. return false;
  467. }
  468. bool need_j1 = NeedInventoryJunctureFromServer(item1, item1.GetHierarchyParent(), item2.GetHierarchyParent());
  469. bool need_j2 = NeedInventoryJunctureFromServer(item2, item2.GetHierarchyParent(), item1.GetHierarchyParent());
  470. if (need_j1 || need_j2)
  471. return ForceSwapEntitiesImpl(InventoryMode.JUNCTURE, item1, item2, item2_dst);
  472. else
  473. return ForceSwapEntitiesImpl(InventoryMode.PREDICTIVE, item1, item2, item2_dst);
  474. }
  475. bool LocalForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  476. {
  477. return ForceSwapEntitiesImpl(InventoryMode.LOCAL, item1, item2, item2_dst);
  478. }
  479. bool ServerForceSwapEntities (notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  480. {
  481. return ForceSwapEntitiesImpl(InventoryMode.SERVER, item1, item2, item2_dst);
  482. }
  483. protected bool ForceSwapEntitiesImpl (InventoryMode mode, notnull EntityAI item1, notnull EntityAI item2, notnull InventoryLocation item2_dst)
  484. {
  485. bool code = false;
  486. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ForceSwapImpl(" + typename.EnumToString(InventoryMode, mode) + ") item1=" + Object.GetDebugName(item1) + " item2=" + item2.GetDebugName(this));
  487. code = GetHumanInventory().ForceSwapEntities(mode, item1, item2, item2_dst);
  488. UpdateInventoryMenu();
  489. if (!code)
  490. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ForceSwapEntitiesImpl - cannot Forceswap");
  491. return code;
  492. }
  493. ///@} ForceSwap juncture
  494. ///@{ to target inv juncture
  495. bool JunctureTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  496. {
  497. return TakeEntityToTargetInventoryImpl(InventoryMode.JUNCTURE, target, flags, item);
  498. }
  499. override bool PredictiveTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  500. {
  501. if (!ScriptInputUserData.CanStoreInputUserData())
  502. {
  503. Print("[inv] " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetInventory input data not sent yet, cannot allow another input action");
  504. return false;
  505. }
  506. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  507. return JunctureTakeEntityToTargetInventory(target, flags, item);
  508. else
  509. return TakeEntityToTargetInventoryImpl(InventoryMode.PREDICTIVE, target, flags, item);
  510. }
  511. bool PredictiveTakeOrSwapAttachment( notnull EntityAI item )
  512. {
  513. if( GetInventory().CanAddAttachment( item ) )
  514. {
  515. return PredictiveTakeEntityAsAttachment( item );
  516. }
  517. else
  518. {
  519. for( int i = 0; i < item.GetInventory().GetSlotIdCount(); i++ )
  520. {
  521. int slot_id = item.GetInventory().GetSlotId(i);
  522. EntityAI slot_item = GetInventory().FindAttachment( slot_id );
  523. if( slot_item && GetInventory().CanSwapEntitiesEx( item, slot_item ) )
  524. {
  525. return PredictiveSwapEntities(item, slot_item);
  526. }
  527. }
  528. }
  529. return false;
  530. }
  531. override bool LocalTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  532. {
  533. return TakeEntityToTargetInventoryImpl(InventoryMode.LOCAL, target, flags, item);
  534. }
  535. protected bool TakeEntityToTargetInventoryImpl (InventoryMode mode, notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
  536. {
  537. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetInv(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  538. bool code = GetInventory().TakeEntityToTargetInventory(mode, target, flags, item);
  539. UpdateInventoryMenu();
  540. return code;
  541. }
  542. ///@} to target inv juncture
  543. ///@{ to target cgo ex juncture
  544. bool JunctureTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  545. {
  546. return TakeEntityToTargetCargoExImpl(InventoryMode.JUNCTURE, cargo, item, row, col);
  547. }
  548. override bool PredictiveTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  549. {
  550. if (!ScriptInputUserData.CanStoreInputUserData())
  551. {
  552. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetCargoEx input data not sent yet, cannot allow another input action");
  553. return false;
  554. }
  555. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), cargo.GetCargoOwner()))
  556. return JunctureTakeEntityToTargetCargoEx(cargo, item, row, col);
  557. else
  558. return TakeEntityToTargetCargoExImpl(InventoryMode.PREDICTIVE, cargo, item, row, col);
  559. }
  560. override bool LocalTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  561. {
  562. return TakeEntityToTargetCargoExImpl(InventoryMode.LOCAL, cargo, item, row, col);
  563. }
  564. override bool ServerTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  565. {
  566. return TakeEntityToTargetCargoExImpl(InventoryMode.SERVER, cargo, item, row, col);
  567. }
  568. protected bool TakeEntityToTargetCargoExImpl (InventoryMode mode, notnull CargoBase cargo, notnull EntityAI item, int row, int col)
  569. {
  570. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetCgoEx(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  571. bool code = GetInventory().TakeEntityToTargetCargoEx(mode, cargo, item, row, col);
  572. UpdateInventoryMenu();
  573. return code;
  574. }
  575. ///@} to target cgo ex juncture
  576. ///@{ to target cgo juncture
  577. bool JunctureTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  578. {
  579. return TakeEntityToTargetCargoImpl(InventoryMode.JUNCTURE, target, item);
  580. }
  581. override bool PredictiveTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  582. {
  583. if (!ScriptInputUserData.CanStoreInputUserData())
  584. {
  585. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetCargo input data not sent yet, cannot allow another input action");
  586. return false;
  587. }
  588. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  589. return JunctureTakeEntityToTargetCargo(target, item);
  590. else
  591. return TakeEntityToTargetCargoImpl(InventoryMode.PREDICTIVE, target, item);
  592. }
  593. override bool LocalTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  594. {
  595. return TakeEntityToTargetCargoImpl(InventoryMode.LOCAL, target, item);
  596. }
  597. override bool ServerTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
  598. {
  599. if (IsAlive())
  600. return TakeEntityToTargetCargoImpl(InventoryMode.SERVER, target, item);
  601. else
  602. return TakeEntityToTargetCargoImpl(InventoryMode.SERVER, target, item);
  603. }
  604. protected bool TakeEntityToTargetCargoImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  605. {
  606. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " Take2TargetCgo(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  607. bool code = GetInventory().TakeEntityToTargetInventory(mode, target, FindInventoryLocationType.CARGO, item);
  608. UpdateInventoryMenu();
  609. return code;
  610. }
  611. ///@} to target cgo juncture
  612. ///@{ to target att ex juncture
  613. bool JunctureTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  614. {
  615. return TakeEntityToTargetAttachmentExImpl(InventoryMode.JUNCTURE, target, item, slot);
  616. }
  617. override bool PredictiveTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  618. {
  619. if (!ScriptInputUserData.CanStoreInputUserData())
  620. {
  621. Print("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::PredictiveTakeEntityToTargetAttachmentEx input data not sent yet, cannot allow another input action");
  622. return false;
  623. }
  624. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  625. return JunctureTakeEntityToTargetAttachmentEx(target, item, slot);
  626. else
  627. return TakeEntityToTargetAttachmentExImpl(InventoryMode.PREDICTIVE, target, item, slot);
  628. }
  629. override bool LocalTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  630. {
  631. return TakeEntityToTargetAttachmentExImpl(InventoryMode.LOCAL, target, item, slot);
  632. }
  633. override bool ServerTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
  634. {
  635. return TakeEntityToTargetAttachmentExImpl(InventoryMode.SERVER, target, item, slot);
  636. }
  637. protected bool TakeEntityToTargetAttachmentExImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item, int slot)
  638. {
  639. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2TargetAtt(" + typename.EnumToString(InventoryMode, mode) + ") item=" + Object.GetDebugName(item));
  640. bool code = GetInventory().TakeEntityAsTargetAttachmentEx(mode, target, item, slot);
  641. UpdateInventoryMenu();
  642. return code;
  643. }
  644. ///@} to target att ex juncture
  645. ///@{ to target att juncture
  646. bool JunctureTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  647. {
  648. return TakeEntityToTargetAttachmentImpl(InventoryMode.JUNCTURE, target, item);
  649. }
  650. override bool PredictiveTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  651. {
  652. if (!ScriptInputUserData.CanStoreInputUserData())
  653. {
  654. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeEntityToTargetAttachment input data not sent yet, cannot allow another input action");
  655. return false;
  656. }
  657. if (NeedInventoryJunctureFromServer(item, item.GetHierarchyParent(), target))
  658. return JunctureTakeEntityToTargetAttachment(target, item);
  659. else
  660. return TakeEntityToTargetAttachmentImpl(InventoryMode.PREDICTIVE, target, item);
  661. }
  662. override bool LocalTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  663. {
  664. return TakeEntityToTargetAttachmentImpl(InventoryMode.LOCAL, target, item);
  665. }
  666. override bool ServerTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
  667. {
  668. return TakeEntityToTargetAttachmentImpl(InventoryMode.SERVER, target, item);
  669. }
  670. protected bool TakeEntityToTargetAttachmentImpl (InventoryMode mode, notnull EntityAI target, notnull EntityAI item)
  671. {
  672. InventoryLocation il = new InventoryLocation;
  673. if( target.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il) )
  674. {
  675. return TakeEntityToTargetAttachmentExImpl(mode, target, item, il.GetSlot());
  676. }
  677. return false;
  678. }
  679. ///@} to target att juncture
  680. ///@{ to dst juncture
  681. bool JunctureTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  682. {
  683. return TakeToDstImpl(InventoryMode.JUNCTURE, src, dst);
  684. }
  685. override bool PredictiveTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  686. {
  687. if (!ScriptInputUserData.CanStoreInputUserData())
  688. {
  689. Print("[inv] " + GetSimulationTimeStamp() + " Man@" + this + " ::PredictiveTakeToDst input data not sent yet, cannot allow another input action");
  690. return false;
  691. }
  692. if (NeedInventoryJunctureFromServer(src.GetItem(), src.GetParent(), dst.GetParent()))
  693. return JunctureTakeToDst(src, dst);
  694. else
  695. return TakeToDstImpl(InventoryMode.PREDICTIVE, src, dst);
  696. }
  697. override bool LocalTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  698. {
  699. return TakeToDstImpl(InventoryMode.LOCAL, src, dst);
  700. }
  701. override bool ServerTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
  702. {
  703. return TakeToDstImpl(InventoryMode.SERVER, src, dst);
  704. }
  705. protected bool TakeToDstImpl (InventoryMode mode, notnull InventoryLocation src, notnull InventoryLocation dst)
  706. {
  707. if (LogManager.IsSyncLogEnable()) syncDebugPrint("[inv] " + GetDebugName(this) + " STS = " + GetSimulationTimeStamp() + " ::Take2Dst(" + typename.EnumToString(InventoryMode, mode) + ") src=" + InventoryLocation.DumpToStringNullSafe(src) + " dst=" + InventoryLocation.DumpToStringNullSafe(dst));
  708. bool code = GetHumanInventory().TakeToDst(mode, src, dst);
  709. UpdateInventoryMenu();
  710. return code;
  711. }
  712. ///@} to dst juncture
  713. ///@} inventory
  714. void JunctureDeleteItem(EntityAI item)
  715. {
  716. }
  717. override bool CanBeSkinned()
  718. {
  719. return true;
  720. }
  721. override bool DisableVicinityIcon()
  722. {
  723. return true;
  724. }
  725. void UpdateInventoryMenu();
  726. ///@{ Stats
  727. //! Registers new stat type for this player.
  728. /*!
  729. \param[in] name The name of the stat type.
  730. */
  731. proto native bool StatRegister( string name );
  732. //! Gets counter value of the specified stat type.
  733. /*!
  734. \param[in] name The name of the stat type.
  735. */
  736. proto native float StatGet( string name );
  737. //! Gets counter value as string of the specified stat type.
  738. /*!
  739. \param[in] name The name of the stat type.
  740. \param[out] value A formatted string containing stat value.
  741. */
  742. proto void StatGetCounter( string name, out string value );
  743. //! Gets counter value as formatted time string of the specified stat type.
  744. /*!
  745. \param[in] name The name of the stat type.
  746. \param[out] value A formatted string containing stat value.
  747. */
  748. proto void StatGetAsTime( string name, out string value );
  749. //! Updates stat counter with given value.
  750. /*!
  751. \param[in] name The name of the stat type.
  752. \param[in] value The specified value.
  753. */
  754. proto native void StatUpdate( string name, float value );
  755. //! Updates stat counter by time.
  756. /*!
  757. Use this to measure play time.
  758. \param[in] name The name of the stat type.
  759. */
  760. proto native void StatUpdateByTime( string name );
  761. //! Updates stat counter by player's actual position.
  762. /*!
  763. Use this to measure player's travelling distance.
  764. \param[in] name The name of the stat type.
  765. */
  766. proto native void StatUpdateByPosition( string name );
  767. //! Updates stat counter by given position.
  768. /*!
  769. \param[in] name The name of the stat type.
  770. \param[in] pos The specified position.
  771. */
  772. proto native void StatUpdateByGivenPos( string name, vector pos );
  773. /*! Invokes read stats from server to client.
  774. \note Call this on client when you need update stats.
  775. */
  776. proto native void StatInvokeUpdate();
  777. /*! Invokes save stats from server to client.
  778. \note Call this on server when you need update stats.
  779. */
  780. proto native void StatSyncToClient();
  781. ///@} Stats
  782. bool IsInventorySoftLocked()
  783. {
  784. return false;
  785. }
  786. void SetInventorySoftLock(bool status);
  787. /// returns true if man is in transport, false otherwise
  788. bool IsInTransport()
  789. {
  790. return Transport.Cast(GetParent()) != null;
  791. }
  792. void StopDeathDarkeningEffect();
  793. bool PhysicalPredictiveDropItem(EntityAI entity, bool heavy_item_only = true);
  794. void SetProcessUIWarning(bool state);
  795. void OnGameplayDataHandlerSync(); //depricated, sync now happens before the player is created, calling of this event still happens for legacy reasons
  796. bool CanPlaceItem(EntityAI item);
  797. };