man.c 34 KB

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