timeaccel.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifdef DIAG_DEVELOPER
  2. typedef Param3<bool, float, int> TimeAccelParam;//enabled, timeAccel,category mask
  3. enum ETimeAccelCategories
  4. {
  5. //DO NOT FORGET TO INCLUDE IN THE MAPPING 'Init()' FUNCTION
  6. UNDERGROUND_ENTRANCE = 0x00000001,
  7. UNDERGROUND_RESERVOIR = 0x00000002,
  8. ENERGY_CONSUMPTION = 0x00000004,
  9. ENERGY_RECHARGE = 0x00000008,
  10. FOOD_DECAY = 0x00000010,
  11. DYNAMIC_MUSIC_PLAYER = 0x00000020,
  12. //SYSTEM6 = 0x00000040,
  13. //SYSTEM6 = 0x00000080,
  14. }
  15. class FeatureTimeAccel
  16. {
  17. static ref TimeAccelParam m_CurrentTimeAccel;// = new TimeAccelParam(false, 0, 0);
  18. static ref map<int,int> m_Mapping = new map<int,int>();
  19. static ref array<int> m_IDs = new array<int>();
  20. static bool m_Initializeded = Init();
  21. static bool Init()
  22. {
  23. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_UG_ENTRANCES, ETimeAccelCategories.UNDERGROUND_ENTRANCE);
  24. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_UG_RESERVOIR, ETimeAccelCategories.UNDERGROUND_RESERVOIR);
  25. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_ENERGY_CONSUME, ETimeAccelCategories.ENERGY_CONSUMPTION);
  26. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_ENERGY_RECHARGE, ETimeAccelCategories.ENERGY_RECHARGE);
  27. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_FOOD_DECAY, ETimeAccelCategories.FOOD_DECAY);
  28. Bind(DiagMenuIDs.FEATURE_TIME_ACCEL_DYNAMIC_MUSIC_PLAYER, ETimeAccelCategories.DYNAMIC_MUSIC_PLAYER);
  29. return true;
  30. }
  31. //-------------------------------
  32. static void Bind(DiagMenuIDs id, ETimeAccelCategories catBit)
  33. {
  34. m_Mapping.Insert(id, catBit);
  35. m_IDs.Insert(id);
  36. }
  37. //-------------------------------
  38. static int GetCategoryByDiagID(DiagMenuIDs id)
  39. {
  40. return m_Mapping.Get(id);
  41. }
  42. //-------------------------------
  43. static int GetDiagIDByCategory(ETimeAccelCategories category)
  44. {
  45. for (int i = 0; i < m_Mapping.Count();i++)
  46. {
  47. if (m_Mapping.GetElement(i) == category)
  48. {
  49. return m_Mapping.GetKey(i);
  50. }
  51. }
  52. return -1;
  53. }
  54. //-------------------------------
  55. static bool GetFeatureTimeAccelEnabled(ETimeAccelCategories categoryBit)
  56. {
  57. return (m_CurrentTimeAccel && m_CurrentTimeAccel.param1 && (categoryBit & m_CurrentTimeAccel.param3) != 0);
  58. }
  59. //-------------------------------
  60. static float GetFeatureTimeAccelValue()
  61. {
  62. if (m_CurrentTimeAccel)
  63. return m_CurrentTimeAccel.param2;
  64. else return 1;
  65. }
  66. //-------------------------------
  67. static void CopyTimeAccelClipboard(bool enable, int timeAccelBig, float timeAccelSmall, int bitMask)
  68. {
  69. string output = "-timeAccel=";
  70. int val = enable;
  71. output += val.ToString()+","+timeAccelBig.ToString()+","+timeAccelSmall.ToString()+","+bitMask.ToString();
  72. GetGame().CopyToClipboard(output);
  73. }
  74. //-------------------------------
  75. static int GetTimeAccelBitmask()
  76. {
  77. int bitmask = 0;
  78. foreach (int id : m_IDs)
  79. {
  80. WriteCategoryBit(bitmask, id);
  81. }
  82. return bitmask;
  83. }
  84. //-------------------------------
  85. static void WriteCategoryBit(out int bitmask, int diagMenuID)
  86. {
  87. int bit = GetCategoryByDiagID(diagMenuID);
  88. if (DiagMenu.GetValue(diagMenuID))
  89. {
  90. bitmask = bitmask | bit;
  91. }
  92. }
  93. //-------------------------------
  94. static bool AreTimeAccelParamsSame(TimeAccelParam p1, TimeAccelParam p2)
  95. {
  96. if (!p1 || !p2)
  97. return false;
  98. if (p1.param1 != p2.param1)
  99. return false;
  100. if (p1.param2 != p2.param2)
  101. return false;
  102. if (p1.param3 != p2.param3)
  103. return false;
  104. return true;
  105. }
  106. //-------------------------------
  107. static void SendTimeAccel(Man player, TimeAccelParam param)
  108. {
  109. GetGame().RPCSingleParam(player, ERPCs.DIAG_TIMEACCEL, param, true, player.GetIdentity());
  110. }
  111. }
  112. #endif