UTRACKER.CPP 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * File Name : UTRACKER.CPP *
  25. * *
  26. * Programmer : Steve Tall *
  27. * *
  28. * Start Date : June 3rd, 1996 *
  29. * *
  30. * Last Update : June 7th, 1996 [ST] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. * The UnitTracker class exists to track the various statistics *
  34. * required for internet games. *
  35. * *
  36. * *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  38. * *
  39. * Functions: *
  40. * *
  41. * *
  42. * *
  43. * *
  44. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  45. #include "function.h"
  46. /***********************************************************************************************
  47. * UTC::UnitTrackerClass -- Class constructor *
  48. * *
  49. * *
  50. * *
  51. * INPUT: Number of unit types to reserve space for *
  52. * *
  53. * OUTPUT: Nothing *
  54. * *
  55. * WARNINGS: None *
  56. * *
  57. * HISTORY: *
  58. * 6/7/96 0:10AM ST : Created *
  59. *=============================================================================================*/
  60. UnitTrackerClass::UnitTrackerClass (int unit_count)
  61. {
  62. UnitTotals = new long [unit_count]; // Allocate memory for the unit totals
  63. UnitCount = unit_count; // Keep a record of how many unit entries there are
  64. InNetworkFormat = 0; // The unit entries are in host format
  65. Clear_Unit_Total(); // Clear each entry
  66. }
  67. /***********************************************************************************************
  68. * UTC::~UnitTrackerClass -- Class destructor *
  69. * *
  70. * *
  71. * *
  72. * INPUT: Nothing *
  73. * *
  74. * OUTPUT: Nothing *
  75. * *
  76. * WARNINGS: None *
  77. * *
  78. * HISTORY: *
  79. * 6/7/96 0:10AM ST : Created *
  80. *=============================================================================================*/
  81. UnitTrackerClass::~UnitTrackerClass (void)
  82. {
  83. delete UnitTotals;
  84. }
  85. /***********************************************************************************************
  86. * UTC::Increment_Unit_Total -- Increment the total for the specefied unit *
  87. * *
  88. * *
  89. * *
  90. * INPUT: Unit number *
  91. * *
  92. * OUTPUT: Nothing *
  93. * *
  94. * WARNINGS: None *
  95. * *
  96. * HISTORY: *
  97. * 6/7/96 0:12AM ST : Created *
  98. *=============================================================================================*/
  99. void UnitTrackerClass::Increment_Unit_Total(int unit_type)
  100. {
  101. UnitTotals[unit_type]++;
  102. }
  103. /***********************************************************************************************
  104. * UTC::Decrement_Unit_Total -- Decrement the total for the specefied unit *
  105. * *
  106. * *
  107. * *
  108. * INPUT: Unit number *
  109. * *
  110. * OUTPUT: Nothing *
  111. * *
  112. * WARNINGS: None *
  113. * *
  114. * HISTORY: *
  115. * 6/7/96 0:13AM ST : Created *
  116. *=============================================================================================*/
  117. void UnitTrackerClass::Decrement_Unit_Total(int unit_type)
  118. {
  119. UnitTotals[unit_type]--;
  120. }
  121. /***********************************************************************************************
  122. * UTC::Get_All_Totals -- Returns a pointer to the start of the unit totals list *
  123. * *
  124. * *
  125. * *
  126. * INPUT: Nothing *
  127. * *
  128. * OUTPUT: Ptr to unit totals list *
  129. * *
  130. * WARNINGS: None *
  131. * *
  132. * HISTORY: *
  133. * 6/7/96 0:13AM ST : Created *
  134. *=============================================================================================*/
  135. long *UnitTrackerClass::Get_All_Totals (void)
  136. {
  137. return (UnitTotals);
  138. }
  139. /***********************************************************************************************
  140. * UTC::Clear_Unit_Total -- Clear out all the unit totals *
  141. * *
  142. * *
  143. * *
  144. * INPUT: Nothing *
  145. * *
  146. * OUTPUT: Nothing *
  147. * *
  148. * WARNINGS: None *
  149. * *
  150. * HISTORY: *
  151. * 6/7/96 0:14AM ST : Created *
  152. *=============================================================================================*/
  153. void UnitTrackerClass::Clear_Unit_Total (void)
  154. {
  155. memset (UnitTotals, 0, UnitCount * sizeof(long) );
  156. }
  157. /***********************************************************************************************
  158. * UTC::To_Network_Format -- Changes all unit totals to network format for the internet *
  159. * *
  160. * *
  161. * *
  162. * INPUT: Nothing *
  163. * *
  164. * OUTPUT: Nothing *
  165. * *
  166. * WARNINGS: None *
  167. * *
  168. * HISTORY: *
  169. * 6/7/96 0:15AM ST : Created *
  170. *=============================================================================================*/
  171. void UnitTrackerClass::To_Network_Format (void)
  172. {
  173. if (!InNetworkFormat){
  174. for (int i=0 ; i<UnitCount ; i++){
  175. UnitTotals[i] = htonl (UnitTotals[i]);
  176. }
  177. }
  178. InNetworkFormat = 1; // Flag that data is now in network format
  179. }
  180. /***********************************************************************************************
  181. * UTC::To_PC_Format -- Changes all unit totals to PC format from network format *
  182. * *
  183. * *
  184. * *
  185. * INPUT: Nothing *
  186. * *
  187. * OUTPUT: Nothing *
  188. * *
  189. * WARNINGS: None *
  190. * *
  191. * HISTORY: *
  192. * 6/7/96 0:15AM ST : Created *
  193. *=============================================================================================*/
  194. void UnitTrackerClass::To_PC_Format (void)
  195. {
  196. if (InNetworkFormat){
  197. for (int i=0 ; i<UnitCount ; i++){
  198. UnitTotals[i] = ntohl (UnitTotals[i]);
  199. }
  200. }
  201. InNetworkFormat = 0; // Flag that data is now in PC format
  202. }