UTRACKER.CPP (15289B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /*************************************************************************** 17 ** 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 ** 18 *************************************************************************** 19 * * 20 * Project Name : Command & Conquer * 21 * * 22 * File Name : UTRACKER.CPP * 23 * * 24 * Programmer : Steve Tall * 25 * * 26 * Start Date : June 3rd, 1996 * 27 * * 28 * Last Update : June 7th, 1996 [ST] * 29 * * 30 *-------------------------------------------------------------------------* 31 * The UnitTracker class exists to track the various statistics * 32 * required for internet games. * 33 * * 34 * * 35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * 36 * * 37 * Functions: * 38 * * 39 * * 40 * * 41 * * 42 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 43 44 45 46 47 #include "function.h" 48 49 50 /*********************************************************************************************** 51 * UTC::UnitTrackerClass -- Class constructor * 52 * * 53 * * 54 * * 55 * INPUT: Number of unit types to reserve space for * 56 * * 57 * OUTPUT: Nothing * 58 * * 59 * WARNINGS: None * 60 * * 61 * HISTORY: * 62 * 6/7/96 0:10AM ST : Created * 63 *=============================================================================================*/ 64 UnitTrackerClass::UnitTrackerClass (int unit_count) 65 { 66 UnitTotals = new long [unit_count]; // Allocate memory for the unit totals 67 UnitCount = unit_count; // Keep a record of how many unit entries there are 68 InNetworkFormat = 0; // The unit entries are in host format 69 Clear_Unit_Total(); // Clear each entry 70 } 71 72 73 /*********************************************************************************************** 74 * UTC::~UnitTrackerClass -- Class destructor * 75 * * 76 * * 77 * * 78 * INPUT: Nothing * 79 * * 80 * OUTPUT: Nothing * 81 * * 82 * WARNINGS: None * 83 * * 84 * HISTORY: * 85 * 6/7/96 0:10AM ST : Created * 86 *=============================================================================================*/ 87 UnitTrackerClass::~UnitTrackerClass (void) 88 { 89 delete UnitTotals; 90 } 91 92 93 94 /*********************************************************************************************** 95 * UTC::Increment_Unit_Total -- Increment the total for the specefied unit * 96 * * 97 * * 98 * * 99 * INPUT: Unit number * 100 * * 101 * OUTPUT: Nothing * 102 * * 103 * WARNINGS: None * 104 * * 105 * HISTORY: * 106 * 6/7/96 0:12AM ST : Created * 107 *=============================================================================================*/ 108 void UnitTrackerClass::Increment_Unit_Total(int unit_type) 109 { 110 UnitTotals[unit_type]++; 111 } 112 113 114 /*********************************************************************************************** 115 * UTC::Decrement_Unit_Total -- Decrement the total for the specefied unit * 116 * * 117 * * 118 * * 119 * INPUT: Unit number * 120 * * 121 * OUTPUT: Nothing * 122 * * 123 * WARNINGS: None * 124 * * 125 * HISTORY: * 126 * 6/7/96 0:13AM ST : Created * 127 *=============================================================================================*/ 128 void UnitTrackerClass::Decrement_Unit_Total(int unit_type) 129 { 130 UnitTotals[unit_type]--; 131 } 132 133 134 /*********************************************************************************************** 135 * UTC::Get_All_Totals -- Returns a pointer to the start of the unit totals list * 136 * * 137 * * 138 * * 139 * INPUT: Nothing * 140 * * 141 * OUTPUT: Ptr to unit totals list * 142 * * 143 * WARNINGS: None * 144 * * 145 * HISTORY: * 146 * 6/7/96 0:13AM ST : Created * 147 *=============================================================================================*/ 148 long *UnitTrackerClass::Get_All_Totals (void) 149 { 150 return (UnitTotals); 151 } 152 153 154 /*********************************************************************************************** 155 * UTC::Clear_Unit_Total -- Clear out all the unit totals * 156 * * 157 * * 158 * * 159 * INPUT: Nothing * 160 * * 161 * OUTPUT: Nothing * 162 * * 163 * WARNINGS: None * 164 * * 165 * HISTORY: * 166 * 6/7/96 0:14AM ST : Created * 167 *=============================================================================================*/ 168 void UnitTrackerClass::Clear_Unit_Total (void) 169 { 170 memset (UnitTotals, 0, UnitCount * sizeof(long) ); 171 } 172 173 174 175 /*********************************************************************************************** 176 * UTC::To_Network_Format -- Changes all unit totals to network format for the internet * 177 * * 178 * * 179 * * 180 * INPUT: Nothing * 181 * * 182 * OUTPUT: Nothing * 183 * * 184 * WARNINGS: None * 185 * * 186 * HISTORY: * 187 * 6/7/96 0:15AM ST : Created * 188 *=============================================================================================*/ 189 void UnitTrackerClass::To_Network_Format (void) 190 { 191 if (!InNetworkFormat){ 192 for (int i=0 ; i<UnitCount ; i++){ 193 UnitTotals[i] = htonl (UnitTotals[i]); 194 } 195 } 196 InNetworkFormat = 1; // Flag that data is now in network format 197 } 198 199 200 /*********************************************************************************************** 201 * UTC::To_PC_Format -- Changes all unit totals to PC format from network format * 202 * * 203 * * 204 * * 205 * INPUT: Nothing * 206 * * 207 * OUTPUT: Nothing * 208 * * 209 * WARNINGS: None * 210 * * 211 * HISTORY: * 212 * 6/7/96 0:15AM ST : Created * 213 *=============================================================================================*/ 214 void UnitTrackerClass::To_PC_Format (void) 215 { 216 if (InNetworkFormat){ 217 for (int i=0 ; i<UnitCount ; i++){ 218 UnitTotals[i] = ntohl (UnitTotals[i]); 219 } 220 } 221 InNetworkFormat = 0; // Flag that data is now in PC format 222 } 223 224 225 // MBL 01.17.2020: Defined in .h, but not implemented 226 int UnitTrackerClass::Get_Unit_Total (int unit_type) 227 { 228 if (UnitTotals == NULL) 229 { 230 return 0; 231 } 232 if (unit_type >= 0 && unit_type < UnitCount) 233 { 234 return UnitTotals[unit_type]; 235 } 236 return 0; 237 } 238 239