statemanager.c 22 KB

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