statemanager.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. enum AnimType
  2. {
  3. FULL_BODY = 1,
  4. ADDITIVE,
  5. }
  6. enum SymptomIDs
  7. {
  8. SYMPTOM_COUGH = 1,
  9. SYMPTOM_VOMIT,
  10. SYMPTOM_BLINDNESS,
  11. SYMPTOM_BULLET_HIT,
  12. SYMPTOM_BLEEDING_SOURCE,
  13. SYMPTOM_BLOODLOSS,
  14. SYMPTOM_SNEEZE,
  15. SYMPTOM_FEVERBLUR,
  16. SYMPTOM_LAUGHTER,
  17. SYMPTOM_UNCONSCIOUS,
  18. SYMPTOM_FREEZE,
  19. SYMPTOM_FREEZE_RATTLE,
  20. SYMPTOM_HOT,
  21. SYMPTOM_PAIN_LIGHT,
  22. SYMPTOM_PAIN_HEAVY,
  23. SYMPTOM_HAND_SHIVER,
  24. SYMPTOM_DEAFNESS_COMPLETE,
  25. SYMPTOM_HMP_SEVERE,
  26. SYMPTOM_GASP,
  27. LAST_INDEX
  28. };
  29. enum SymptomTypes
  30. {
  31. PRIMARY,
  32. SECONDARY
  33. };
  34. enum EAnimPlayState
  35. {
  36. OK,
  37. POSTPONED,
  38. FAILED,
  39. };
  40. const int DEBUG_PADDING_OFFSET = 2;
  41. const int MAX_QUEUE_SIZE = 5;
  42. class SymptomManager
  43. {
  44. PlayerBase m_Player;
  45. ref map<int, ref SymptomBase> m_AvailableSymptoms;
  46. ref map<int, int> m_ActiveSymptomTypes;//for each type(symptom id), keep track of how many times it is in queue
  47. ref array<ref SymptomBase> m_SymptomQueuePrimary;
  48. ref array<ref SymptomBase> m_SymptomQueueSecondary;
  49. ref map<int , SymptomBase > m_SymptomsUIDs;
  50. ref array<ref Param> m_SymptomQueueServerDbg;
  51. ref array<ref Param> m_SymptomQueueServerDbgPrimary;
  52. ref array<ref Param> m_SymptomQueueServerDbgSecondary;
  53. //ref array<string> m_SymptomQueueSecondaryServerDbg;
  54. ref Timer m_Timer;
  55. int m_ActiveSymptomIndexPrimary = -1;
  56. int m_CurrentCommandID;
  57. const int STORAGE_VERSION = 121;
  58. bool m_ShowDebug = false;
  59. bool m_ShowDebug2 = false;
  60. ref SmptAnimMetaBase m_AnimMeta;
  61. void Init()
  62. {
  63. RegisterSymptom(new CoughSymptom);
  64. RegisterSymptom(new VomitSymptom);
  65. RegisterSymptom(new BlindnessSymptom);
  66. RegisterSymptom(new SneezeSymptom);
  67. RegisterSymptom(new FeverBlurSymptom);
  68. RegisterSymptom(new BloodLoss);
  69. RegisterSymptom(new LaughterSymptom);
  70. RegisterSymptom(new FreezeSymptom);
  71. RegisterSymptom(new FreezeRattleSymptom);
  72. RegisterSymptom(new HotSymptom);
  73. RegisterSymptom(new PainLightSymptom);
  74. RegisterSymptom(new PainHeavySymptom);
  75. RegisterSymptom(new HandShiversSymptom);
  76. RegisterSymptom(new DeafnessCompleteSymptom);
  77. RegisterSymptom(new HMP3Symptom);
  78. RegisterSymptom(new GaspSymptom);
  79. }
  80. int GetStorageVersion()
  81. {
  82. return STORAGE_VERSION;
  83. }
  84. void AutoactivateSymptoms()
  85. {
  86. if ( GetGame().IsClient() )
  87. {
  88. return;
  89. }
  90. QueueUpSecondarySymptom(SymptomIDs.SYMPTOM_BLOODLOSS);
  91. }
  92. void SymptomManager(PlayerBase player)
  93. {
  94. m_ActiveSymptomTypes = new map<int, int>();
  95. m_SymptomsUIDs = new map<int, SymptomBase>();
  96. m_SymptomQueuePrimary = new array<ref SymptomBase>();
  97. m_SymptomQueueSecondary = new array<ref SymptomBase>();
  98. m_SymptomQueueServerDbg = new array<ref Param>();
  99. m_AvailableSymptoms = new map<int, ref SymptomBase>();
  100. m_SymptomQueueServerDbgPrimary = new array<ref Param>();
  101. m_SymptomQueueServerDbgSecondary = new array<ref Param>();
  102. m_Player = player;
  103. Init();
  104. AutoactivateSymptoms();
  105. }
  106. void OnPlayerKilled()
  107. {
  108. foreach (SymptomBase symptomPrimary : m_SymptomQueuePrimary)
  109. symptomPrimary.OnOwnerKilled();
  110. foreach (SymptomBase symptomSecondary : m_SymptomQueueSecondary)
  111. symptomSecondary.OnOwnerKilled();
  112. }
  113. SymptomBase GetSymptomByUID(int SYMPTOM_uid)
  114. {
  115. return m_SymptomsUIDs.Get(SYMPTOM_uid);
  116. }
  117. PlayerBase GetPlayer()
  118. {
  119. return m_Player;
  120. }
  121. void RegisterSymptom(SymptomBase Symptom)
  122. {
  123. Symptom.Init(this, m_Player,0);
  124. int id = Symptom.GetType();
  125. if (m_AvailableSymptoms.Contains(id))
  126. {
  127. ErrorEx(string.Format("Symptom %1 already registered!", Symptom.GetName()));
  128. return;
  129. }
  130. m_AvailableSymptoms.Insert(id, Symptom);
  131. }
  132. void OnAnimationFinished(eAnimFinishType type = eAnimFinishType.SUCCESS)
  133. {
  134. if (m_AnimMeta)
  135. {
  136. m_AnimMeta.AnimFinished(type);
  137. }
  138. }
  139. void OnAnimationStarted()
  140. {
  141. if (GetCurrentPrimaryActiveSymptom())
  142. GetCurrentPrimaryActiveSymptom().AnimationStart();
  143. }
  144. int CreateUniqueID()
  145. {
  146. int uid = Math.RandomInt(1, 2147483647);
  147. if (!IsUIDUsed(uid))
  148. return uid;
  149. else
  150. return CreateUniqueID();
  151. }
  152. bool IsUIDUsed(int uid)
  153. {
  154. return m_SymptomsUIDs.Contains(uid);
  155. }
  156. string GetSymptomName(int symptom_id)
  157. {
  158. return m_AvailableSymptoms.Get(symptom_id).GetName();
  159. }
  160. SmptAnimMetaBase SpawnAnimMetaObject(int symptom_id)
  161. {
  162. SmptAnimMetaBase animMeta = m_AvailableSymptoms.Get(symptom_id).SpawnAnimMetaObject();
  163. animMeta.m_StateType = symptom_id;
  164. return animMeta;
  165. }
  166. //! Exits a specific Symptom with a given UID
  167. void RequestSymptomExit(int SYMPTOM_uid)
  168. {
  169. if (m_SymptomsUIDs.Get(SYMPTOM_uid))
  170. m_SymptomsUIDs.Get(SYMPTOM_uid).RequestDestroy();
  171. }
  172. bool IsSymptomPrimary(int symptom_id)
  173. {
  174. return m_AvailableSymptoms.Get(symptom_id).IsPrimary();
  175. }
  176. void OnInputUserDataReceived(ParamsReadContext ctx)
  177. {
  178. }
  179. int GetCurrentCommandID()
  180. {
  181. return m_CurrentCommandID;
  182. }
  183. void OnTick(float deltatime, int pCurrentCommandID, HumanMovementState movement_state)
  184. {
  185. // pCurrentCommandID might be the initial value, but the system itself requires
  186. // current value, so retrieve the current value from player instead
  187. m_CurrentCommandID = m_Player.GetCurrentCommandID();
  188. if (m_ActiveSymptomIndexPrimary == -1)
  189. {
  190. m_ActiveSymptomIndexPrimary = FindFirstAvailableSymptomIndex();
  191. if (m_ActiveSymptomIndexPrimary != -1 && m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary).IsSyncToRemotes())
  192. m_Player.SetActivePrimarySymptomID(m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary).GetType());
  193. }
  194. UpdateActiveSymptoms(deltatime);
  195. if ( m_AnimMeta )
  196. {
  197. if ( m_AnimMeta.IsDestroyReqested() )
  198. {
  199. m_AnimMeta = null;
  200. }
  201. }
  202. if ( m_AnimMeta )
  203. {
  204. //anim requested
  205. if ( !m_AnimMeta.IsPlaying() )
  206. {
  207. // not playing yet and not possible to play
  208. SymptomBase symptom = m_AvailableSymptoms.Get( m_AnimMeta.m_StateType );
  209. if ( symptom && !symptom.CanActivate() )
  210. {
  211. m_AnimMeta = null;
  212. }
  213. else if ( m_AnimMeta.PlayRequest() == EAnimPlayState.FAILED )
  214. {
  215. OnAnimationFinished(eAnimFinishType.FAILURE);
  216. }
  217. }
  218. else
  219. {
  220. m_AnimMeta.Update(movement_state);
  221. }
  222. }
  223. #ifdef DIAG_DEVELOPER
  224. #ifndef SERVER //must be here !!!
  225. if ( DiagMenu.GetBool(DiagMenuIDs.MISC_PLAYER_SYMPTOMS_SHOW) )
  226. {
  227. //DisplayDebug(true);
  228. array<ref Param> primary_debug = PrepareClientDebug(m_SymptomQueuePrimary);
  229. array<ref Param> secondary_debug = PrepareClientDebug(m_SymptomQueueSecondary);
  230. DisplayDebug1("Symptoms Client", 50, primary_debug, secondary_debug);
  231. DisplayDebug2("Symptoms Server", 300, m_SymptomQueueServerDbgPrimary, m_SymptomQueueServerDbgSecondary);
  232. ShowAvailableSymptoms();
  233. }
  234. else
  235. {
  236. CleanDebug1("Symptoms Client", 50);
  237. CleanDebug2("Symptoms Server", 300);
  238. CleanAvailableSymptoms();
  239. }
  240. int HMPRange = DiagMenu.GetRangeValue(DiagMenuIDs.MISC_PLAYER_SYMPTOMS_TOGGLE_HMP);
  241. if (HMPRange == 1 && m_ActiveSymptomTypes.Get(SymptomIDs.SYMPTOM_HMP_SEVERE) == 0)
  242. {
  243. QueueUpSecondarySymptomEx(SymptomIDs.SYMPTOM_HMP_SEVERE);
  244. }
  245. else if (HMPRange == 0 && m_ActiveSymptomTypes.Get(SymptomIDs.SYMPTOM_HMP_SEVERE) > 0)
  246. {
  247. RemoveSecondarySymptom(SymptomIDs.SYMPTOM_HMP_SEVERE);
  248. }
  249. #endif
  250. #endif
  251. }
  252. void SetAnimation(ParamsReadContext ctx)
  253. {
  254. if (m_AnimMeta)
  255. {
  256. // animation meta already exists
  257. // pass
  258. }
  259. else
  260. {
  261. int state_type;
  262. if (ctx.Read(state_type))
  263. {
  264. m_AnimMeta = SpawnAnimMetaObject(state_type);
  265. if (m_AnimMeta)
  266. {
  267. m_AnimMeta.Init(ctx, this, m_Player);
  268. }
  269. }
  270. }
  271. }
  272. void UpdateActiveSymptoms(float deltatime)
  273. {
  274. //if( GetGame().IsClient() && !m_Player.IsPlayer() ) return;
  275. //primary
  276. if ( GetCurrentPrimaryActiveSymptom() )
  277. {
  278. if ( !GetCurrentPrimaryActiveSymptom().IsActivated() )
  279. {
  280. if ( GetCurrentPrimaryActiveSymptom().CanActivate() )
  281. GetCurrentPrimaryActiveSymptom().Activate();
  282. }
  283. if ( GetCurrentPrimaryActiveSymptom().IsActivated() )
  284. {
  285. GetCurrentPrimaryActiveSymptom().Update(deltatime);
  286. }
  287. }
  288. //secondary
  289. for (int i = 0; i < m_SymptomQueueSecondary.Count(); i++)
  290. {
  291. if ( m_SymptomQueueSecondary.Get(i) && !m_SymptomQueueSecondary.Get(i).IsActivated() )
  292. {
  293. m_SymptomQueueSecondary.Get(i).Activate();
  294. }
  295. else
  296. {
  297. if (m_SymptomQueueSecondary.Get(i)) m_SymptomQueueSecondary.Get(i).Update(deltatime);
  298. }
  299. }
  300. }
  301. void OnSymptomExit(SymptomBase Symptom, int uid)
  302. {
  303. bool is_primary;
  304. if ( Symptom )
  305. {
  306. is_primary = Symptom.IsPrimary();
  307. DecreaseSymptomCount(Symptom.GetType());
  308. }
  309. if (m_SymptomsUIDs.Contains(uid))
  310. m_SymptomsUIDs.Remove(uid);
  311. else
  312. Debug.LogError("Symptom with this UID does not exist", "PlayerSymptoms");
  313. if (is_primary)
  314. {
  315. for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
  316. {
  317. if ( m_SymptomQueuePrimary.Get(i) == Symptom )
  318. {
  319. m_SymptomQueuePrimary.RemoveOrdered(i);
  320. break;
  321. }
  322. }
  323. }
  324. else
  325. {
  326. for (i = 0; i < m_SymptomQueueSecondary.Count(); i++)
  327. {
  328. if (m_SymptomQueueSecondary.Get(i) == Symptom)
  329. {
  330. m_SymptomQueueSecondary.RemoveOrdered(i);
  331. break;
  332. }
  333. }
  334. }
  335. m_ActiveSymptomIndexPrimary = -1;
  336. m_Player.SetActivePrimarySymptomID(0);
  337. #ifdef DIAG_DEVELOPER
  338. if ( GetGame() ) SendServerDebugToClient();
  339. #endif
  340. }
  341. int GetSymptomMaxCount(int symptom_id)
  342. {
  343. return m_AvailableSymptoms.Get(symptom_id).GetMaxCount();
  344. }
  345. int GetSymptomCount(int symptom_id)
  346. {
  347. if ( m_ActiveSymptomTypes.Contains(symptom_id) )
  348. return m_ActiveSymptomTypes.Get(symptom_id);
  349. else
  350. return -1;
  351. }
  352. void IncreaseSymptomCount(int symptom_id)
  353. {
  354. if ( m_ActiveSymptomTypes.Contains(symptom_id) )
  355. {
  356. m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) + 1);
  357. }
  358. else
  359. {
  360. m_ActiveSymptomTypes.Insert(symptom_id, 1);
  361. }
  362. }
  363. void DecreaseSymptomCount(int symptom_id)
  364. {
  365. if ( m_ActiveSymptomTypes.Contains(symptom_id) )
  366. {
  367. if ( m_ActiveSymptomTypes.Get(symptom_id) == 1)
  368. m_ActiveSymptomTypes.Remove(symptom_id);
  369. else
  370. m_ActiveSymptomTypes.Set(symptom_id, m_ActiveSymptomTypes.Get(symptom_id) - 1);
  371. }
  372. }
  373. SymptomBase SpawnSymptom(int symptom_id, int uid = -1)
  374. {
  375. if (m_AvailableSymptoms.Get(symptom_id))
  376. {
  377. SymptomBase symptom = SymptomBase.Cast(m_AvailableSymptoms.Get(symptom_id).ClassName().ToType().Spawn());
  378. if (uid == -1)
  379. {
  380. uid = CreateUniqueID();
  381. }
  382. symptom.Init(this, m_Player,uid);
  383. if ( m_SymptomsUIDs.Contains(uid) )
  384. ErrorEx(string.Format("Symptoms: Unique ID (=%1) already exists!", uid));
  385. m_SymptomsUIDs.Insert(uid, symptom);
  386. IncreaseSymptomCount(symptom_id);
  387. return symptom;
  388. }
  389. if (!symptom)
  390. {
  391. Error("Symptom not registered");
  392. }
  393. return null;
  394. }
  395. void CleanUpPrimaryQueue()
  396. {
  397. foreach (SymptomBase symptom : m_SymptomQueuePrimary)
  398. {
  399. symptom.RequestDestroy();
  400. }
  401. }
  402. SymptomBase QueueUpPrimarySymptom(int symptom_id, int uid = -1)
  403. {
  404. if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
  405. return null;
  406. SymptomBase symptom = m_AvailableSymptoms.Get(symptom_id);
  407. if (m_Player.IsUnconscious() && !symptom.AllowInUnconscious())
  408. return null;
  409. else
  410. symptom = null; // needed for check below
  411. for (int i = 0; i < m_SymptomQueuePrimary.Count(); i++)
  412. {
  413. if (m_SymptomQueuePrimary.Get(i).CanBeInterupted() && ComparePriority(GetSymptomPriority(symptom_id), m_SymptomQueuePrimary.Get(i).GetPriority()) == 1)
  414. {
  415. symptom = SpawnSymptom(symptom_id, uid);
  416. m_SymptomQueuePrimary.InsertAt(symptom,i);
  417. if (m_SymptomQueuePrimary.Count() > MAX_QUEUE_SIZE)
  418. m_SymptomQueuePrimary.Get(MAX_QUEUE_SIZE).RequestDestroy();// no need to remove from the array, that's done via Symptom callback on destruct
  419. break;
  420. }
  421. }
  422. if ( !symptom && m_SymptomQueuePrimary.Count() < MAX_QUEUE_SIZE)
  423. {
  424. symptom = SpawnSymptom( symptom_id, uid );
  425. m_SymptomQueuePrimary.Insert(symptom);
  426. }
  427. #ifdef DIAG_DEVELOPER
  428. SendServerDebugToClient();
  429. #endif
  430. return symptom;
  431. }
  432. void QueueUpSecondarySymptom(int symptom_id, int uid = -1)
  433. {
  434. QueueUpSecondarySymptomEx(symptom_id, uid);
  435. }
  436. SymptomBase QueueUpSecondarySymptomEx(int symptom_id, int uid = -1)
  437. {
  438. if ((GetSymptomCount(symptom_id) >= GetSymptomMaxCount(symptom_id)) && GetSymptomMaxCount(symptom_id) != -1)
  439. return null;
  440. if (m_AvailableSymptoms.Get(symptom_id).IsPrimary())
  441. return null;
  442. if (m_Player.IsUnconscious() && !m_AvailableSymptoms.Get(symptom_id).AllowInUnconscious())
  443. return null;
  444. SymptomBase Symptom = SpawnSymptom( symptom_id, uid);
  445. m_SymptomQueueSecondary.Insert(Symptom);
  446. return Symptom;
  447. }
  448. //! Removes a single Symptom
  449. void RemoveSecondarySymptom(int symptom_id)
  450. {
  451. for (int i = 0; i < m_SymptomQueueSecondary.Count();i++)
  452. {
  453. if ( m_SymptomQueueSecondary.Get(i) && m_SymptomQueueSecondary.Get(i).GetType() == symptom_id )
  454. {
  455. m_SymptomQueueSecondary.Get(i).RequestDestroy();
  456. return;
  457. }
  458. }
  459. }
  460. SymptomBase GetCurrentPrimaryActiveSymptom()
  461. {
  462. if ( GetGame().IsServer() )
  463. {
  464. if ( m_ActiveSymptomIndexPrimary >= 0 && m_ActiveSymptomIndexPrimary < m_SymptomQueuePrimary.Count() )
  465. {
  466. if ( m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary) ) return m_SymptomQueuePrimary.Get(m_ActiveSymptomIndexPrimary);
  467. }
  468. }
  469. if ( !GetGame().IsDedicatedServer() )
  470. {
  471. if ( m_SymptomQueuePrimary.Count() > 0 )
  472. return m_SymptomQueuePrimary.Get(0);
  473. }
  474. return NULL;
  475. }
  476. int FindFirstAvailableSymptomIndex()
  477. {
  478. for (int i = 0; i < m_SymptomQueuePrimary.Count();i++)
  479. {
  480. if ( m_SymptomQueuePrimary.Get(i).CanActivate() )
  481. {
  482. return i;
  483. }
  484. }
  485. return -1;
  486. }
  487. int ComparePriority( int prio1, int prio2 )
  488. {
  489. if ( prio1 > prio2 )
  490. {
  491. return 1;
  492. }
  493. else if ( prio2 > prio1 )
  494. {
  495. return 2;
  496. }
  497. return 0;
  498. }
  499. int GetSymptomPriority(int symptom_id)
  500. {
  501. return m_AvailableSymptoms.Get(symptom_id).GetPriority();
  502. }
  503. void OnRPC(int rpc_type, ParamsReadContext ctx)
  504. {
  505. ctx.Read(CachedObjectsParams.PARAM2_INT_INT);
  506. int symptom_id = CachedObjectsParams.PARAM2_INT_INT.param1;
  507. int uid = CachedObjectsParams.PARAM2_INT_INT.param2;
  508. bool is_primary = m_AvailableSymptoms.Get(symptom_id).IsPrimary();
  509. if ( rpc_type == ERPCs.RPC_PLAYER_SYMPTOM_ON )
  510. {
  511. if ( is_primary )
  512. {
  513. CleanUpPrimaryQueue();
  514. QueueUpPrimarySymptom(symptom_id,uid);
  515. }
  516. else
  517. {
  518. QueueUpSecondarySymptom(symptom_id,uid);
  519. }
  520. }
  521. else if ( rpc_type == ERPCs.RPC_PLAYER_SYMPTOM_OFF )
  522. {
  523. if ( is_primary )
  524. {
  525. CleanUpPrimaryQueue();
  526. }
  527. else
  528. {
  529. RemoveSecondarySymptom( symptom_id );
  530. }
  531. }
  532. }
  533. void OnStoreSave( ParamsWriteContext ctx )
  534. {
  535. array<int> m_SaveQueue = new array<int>;
  536. for ( int i = 0; i < m_SymptomQueuePrimary.Count(); i++ )
  537. {
  538. if ( m_SymptomQueuePrimary.Get(i).IsPersistent() )
  539. {
  540. m_SaveQueue.Insert( m_SymptomQueuePrimary.Get(i).GetType() );
  541. }
  542. }
  543. for ( i = 0; i < m_SymptomQueueSecondary.Count(); i++ )
  544. {
  545. if ( m_SymptomQueueSecondary.Get(i).IsPersistent() )
  546. {
  547. m_SaveQueue.Insert( m_SymptomQueueSecondary.Get(i).GetType() );
  548. }
  549. }
  550. ctx.Write( m_SaveQueue );
  551. }
  552. bool OnStoreLoad( ParamsReadContext ctx, int version )
  553. {
  554. array<int> m_SaveQueue;
  555. if (ctx.Read(m_SaveQueue))
  556. {
  557. for ( int i = 0; i < m_SaveQueue.Count(); i++ )
  558. {
  559. int id = m_SaveQueue.Get(i);
  560. if ( IsSymptomPrimary(id) )
  561. {
  562. QueueUpPrimarySymptom( id );
  563. }
  564. else
  565. {
  566. QueueUpSecondarySymptom( id );
  567. }
  568. }
  569. return true;
  570. }
  571. else
  572. {
  573. return false;
  574. }
  575. }
  576. #ifdef DIAG_DEVELOPER
  577. void OnRPCDebug(int rpc_type, ParamsReadContext ctx)
  578. {
  579. switch (rpc_type)
  580. {
  581. case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON:
  582. {
  583. if (ctx.Read(CachedObjectsParams.PARAM1_INT))
  584. {
  585. if (IsSymptomPrimary(CachedObjectsParams.PARAM1_INT.param1))
  586. {
  587. QueueUpPrimarySymptom(CachedObjectsParams.PARAM1_INT.param1);
  588. }
  589. else
  590. {
  591. QueueUpSecondarySymptom(CachedObjectsParams.PARAM1_INT.param1);
  592. }
  593. }
  594. break;
  595. }
  596. case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF:
  597. {
  598. if (ctx.Read(CachedObjectsParams.PARAM1_INT))
  599. RequestSymptomExit(CachedObjectsParams.PARAM1_INT.param1);
  600. break;
  601. }
  602. case ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG:
  603. {
  604. int primary_Symptoms_count;
  605. int secondary_Symptoms_count;
  606. int symptom_id;
  607. if (ctx.Read(CachedObjectsParams.PARAM1_INT))
  608. {
  609. primary_Symptoms_count = CachedObjectsParams.PARAM1_INT.param1;
  610. }
  611. if (ctx.Read(CachedObjectsParams.PARAM1_INT))
  612. {
  613. secondary_Symptoms_count = CachedObjectsParams.PARAM1_INT.param1;
  614. }
  615. m_SymptomQueueServerDbg.Clear();
  616. m_SymptomQueueServerDbgPrimary.Clear();
  617. m_SymptomQueueServerDbgSecondary.Clear();
  618. int overall_count = primary_Symptoms_count + secondary_Symptoms_count;
  619. for (int i = 0; i < overall_count ; ++i)
  620. {
  621. Param3<bool, int, int> p3 = new Param3<bool, int, int>(false,0,0);
  622. ctx.Read(p3);
  623. bool is_primary = p3.param1;
  624. if (is_primary)
  625. {
  626. m_SymptomQueueServerDbgPrimary.Insert(p3);// m_SymptomQueueServerDbg.Insert(p3);
  627. }
  628. else
  629. {
  630. m_SymptomQueueServerDbgSecondary.Insert(p3);
  631. }
  632. //PrintString("elements m_SymptomQueueServerDbgPrimary:" + m_SymptomQueueServerDbgPrimary.Count());
  633. //PrintString("elements m_SymptomQueueServerDbgSecondary:" + m_SymptomQueueServerDbgSecondary.Count());
  634. }
  635. /*
  636. for(i = 0; i < secondary_Symptoms_count; i++)
  637. {
  638. ctx.Read(CachedObjectsParams.PARAM1_STRING);
  639. m_SymptomQueueSecondaryServerDbg.Insert(CachedObjectsParams.PARAM1_STRING.param1);
  640. }*/
  641. break;
  642. }
  643. }
  644. }
  645. void SendServerDebugToClient()
  646. {
  647. array<ref Param> debug_list = new array<ref Param>;
  648. Param1<int> p1 = new Param1<int>(0);
  649. Param1<int> p2 = new Param1<int>(0);
  650. p1.param1 = m_SymptomQueuePrimary.Count();
  651. p2.param1 = m_SymptomQueueSecondary.Count();
  652. debug_list.Insert(p1);
  653. debug_list.Insert(p2);
  654. Param3<bool,int,int> p;
  655. bool is_primary;
  656. int symptom_id;
  657. int SYMPTOM_uid;
  658. foreach ( SymptomBase symptom : m_SymptomQueuePrimary )
  659. {
  660. is_primary = symptom.IsPrimary();
  661. symptom_id = symptom.GetType();
  662. SYMPTOM_uid = symptom.GetUID();
  663. p = new Param3<bool,int,int>(is_primary, symptom_id, SYMPTOM_uid );
  664. debug_list.Insert(p);
  665. }
  666. foreach ( SymptomBase secSymptom : m_SymptomQueueSecondary )
  667. {
  668. is_primary = secSymptom.IsPrimary();
  669. symptom_id = secSymptom.GetType();
  670. SYMPTOM_uid = secSymptom.GetUID();
  671. p = new Param3<bool,int,int>(is_primary, symptom_id, SYMPTOM_uid );
  672. debug_list.Insert(p);
  673. }
  674. GetGame().RPC(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG, debug_list, true);
  675. }
  676. void DebugRequestExitSymptom(int SYMPTOM_uid)
  677. {
  678. CachedObjectsParams.PARAM1_INT.param1 = SYMPTOM_uid;
  679. if (GetPlayer())
  680. GetGame().RPCSingleParam(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_OFF, CachedObjectsParams.PARAM1_INT, true, GetPlayer().GetIdentity());
  681. }
  682. array<ref Param> PrepareClientDebug(array<ref SymptomBase> Symptoms)
  683. {
  684. array<ref Param> debug_array = new array<ref Param>;
  685. Param3<bool, int, int> p3;
  686. for (int i = 0; i < Symptoms.Count(); i++)
  687. {
  688. bool is_primary = Symptoms.Get(i).IsPrimary();
  689. int symptom_id = Symptoms.Get(i).GetType();
  690. int SYMPTOM_uid = Symptoms.Get(i).GetUID();
  691. p3 = new Param3<bool,int,int>(is_primary, symptom_id, SYMPTOM_uid );
  692. debug_array.Insert(p3);
  693. }
  694. return debug_array;
  695. }
  696. void DisplayDebug1(string name, int y_offset, array<ref Param> Symptoms_primary, array<ref Param> Symptoms_secondary)
  697. {
  698. string primary;
  699. Param3<bool, int, int> p3 = new Param3<bool, int, int>(false,0,0);
  700. DbgUI.BeginCleanupScope();
  701. DbgUI.Begin(name, 50, y_offset);
  702. DbgUI.Text("Primary: ");
  703. bool is_primary;
  704. int symptom_id;
  705. int SYMPTOM_uid;
  706. string SYMPTOM_name;
  707. for (int i = 0; i < Symptoms_primary.Count(); i++)
  708. {
  709. p3 = Param3<bool, int, int>.Cast(Symptoms_primary.Get(i));
  710. is_primary = p3.param1;
  711. symptom_id = p3.param2;
  712. SYMPTOM_uid = p3.param3;
  713. SYMPTOM_name = GetSymptomName(symptom_id);
  714. primary += SYMPTOM_name + " | ";
  715. }
  716. DbgUI.Text(primary);
  717. DbgUI.Text("Secondary: ");
  718. for (i = 0; i < Symptoms_secondary.Count(); i++)
  719. {
  720. p3 = Param3<bool, int, int>.Cast(Symptoms_secondary.Get(i));
  721. is_primary = p3.param1;
  722. symptom_id = p3.param2;
  723. SYMPTOM_uid = p3.param3;
  724. SYMPTOM_name = GetSymptomName(symptom_id);
  725. DbgUI.Text(SYMPTOM_name);
  726. }
  727. DbgUI.End();
  728. DbgUI.EndCleanupScope();
  729. }
  730. void DisplayDebug2(string name, int y_offset, array<ref Param> Symptoms_primary, array<ref Param> Symptoms_secondary)
  731. {
  732. string primary;
  733. Param3<bool, int, int> p3 = new Param3<bool, int, int>(false,0,0);
  734. DbgUI.BeginCleanupScope();
  735. DbgUI.Begin(name, 50, y_offset);
  736. DbgUI.Text("Primary: ");
  737. bool is_primary;
  738. int symptom_id;
  739. int SYMPTOM_uid;
  740. string SYMPTOM_name;
  741. for (int i = 0; i < Symptoms_primary.Count(); i++)
  742. {
  743. p3 = Param3<bool, int, int>.Cast(Symptoms_primary.Get(i));
  744. is_primary = p3.param1;
  745. symptom_id = p3.param2;
  746. SYMPTOM_uid = p3.param3;
  747. SYMPTOM_name = GetSymptomName(symptom_id);
  748. if (DbgUI.Button( i.ToString() + " " + SYMPTOM_name, 80))
  749. {
  750. DebugRequestExitSymptom(SYMPTOM_uid);
  751. }
  752. }
  753. DbgUI.Text("Secondary: ");
  754. for (i = 0; i < Symptoms_secondary.Count(); i++)
  755. {
  756. p3 = Param3<bool, int, int>.Cast(Symptoms_secondary.Get(i));
  757. is_primary = p3.param1;
  758. symptom_id = p3.param2;
  759. SYMPTOM_uid = p3.param3;
  760. SYMPTOM_name = GetSymptomName(symptom_id);
  761. if (DbgUI.Button( i.ToString() + " " + SYMPTOM_name, 80))
  762. {
  763. DebugRequestExitSymptom(SYMPTOM_uid);
  764. }
  765. }
  766. DbgUI.End();
  767. DbgUI.EndCleanupScope();
  768. }
  769. void ShowAvailableSymptoms()
  770. {
  771. DbgUI.BeginCleanupScope();
  772. DbgUI.Begin("available Symptoms", 300, 50);
  773. for (int i = 0; i < m_AvailableSymptoms.Count(); i++)
  774. {
  775. SymptomBase Symptom = m_AvailableSymptoms.GetElement(i);
  776. string SYMPTOM_name = Symptom.GetName();
  777. int symptom_id = Symptom.GetType();
  778. if (DbgUI.Button( i.ToString() + " " + SYMPTOM_name, 80))
  779. {
  780. DebugRequestActivateSymptom(symptom_id);
  781. }
  782. }
  783. DbgUI.End();
  784. DbgUI.EndCleanupScope();
  785. }
  786. void CleanAvailableSymptoms()
  787. {
  788. DbgUI.BeginCleanupScope();
  789. DbgUI.Begin("available Symptoms", 300, 50);
  790. DbgUI.End();
  791. DbgUI.EndCleanupScope();
  792. }
  793. void CleanDebug1(string name, int y_offset)
  794. {
  795. DbgUI.BeginCleanupScope();
  796. DbgUI.Begin(name, 50, y_offset);
  797. DbgUI.End();
  798. DbgUI.EndCleanupScope();
  799. }
  800. void CleanDebug2(string name, int y_offset)
  801. {
  802. DbgUI.BeginCleanupScope();
  803. DbgUI.Begin(name, 50, y_offset);
  804. DbgUI.End();
  805. DbgUI.EndCleanupScope();
  806. }
  807. void DebugRequestActivateSymptom(int symptom_id)
  808. {
  809. CachedObjectsParams.PARAM1_INT.param1 = symptom_id;
  810. if (GetPlayer())
  811. GetGame().RPCSingleParam(GetPlayer(), ERPCs.DIAG_PLAYER_SYMPTOMS_DEBUG_ON, CachedObjectsParams.PARAM1_INT, true, GetPlayer().GetIdentity());
  812. }
  813. #endif
  814. }