WOLSquad.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. ** Command & Conquer Renegade(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. *
  20. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLSquad.cpp $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * $Author: Denzil_l $
  27. *
  28. * VERSION INFO
  29. * $Revision: 9 $
  30. * $Modtime: 1/12/02 9:45p $
  31. *
  32. ******************************************************************************/
  33. #include <stdlib.h>
  34. #include <memory.h>
  35. #include "WOLSquad.h"
  36. #include <WWDebug\WWDebug.h>
  37. namespace WWOnline {
  38. SquadData::SquadColl SquadData::_mSquadColl;
  39. /******************************************************************************
  40. *
  41. * NAME
  42. * SquadData::Reset
  43. *
  44. * DESCRIPTION
  45. * Release all cached squads
  46. *
  47. * INPUTS
  48. * NONE
  49. *
  50. * RESULT
  51. * NONE
  52. *
  53. ******************************************************************************/
  54. void SquadData::Reset(void)
  55. {
  56. _mSquadColl.clear();
  57. }
  58. /******************************************************************************
  59. *
  60. * NAME
  61. * SquadData::FindByID
  62. *
  63. * DESCRIPTION
  64. * Find a squad in the local cache by its ID
  65. *
  66. * INPUTS
  67. * SquadID - ID of squad to search for.
  68. *
  69. * RESULT
  70. * Squad - Reference to squad
  71. *
  72. ******************************************************************************/
  73. RefPtr<SquadData> SquadData::FindByID(unsigned long id)
  74. {
  75. const unsigned int count = _mSquadColl.size();
  76. for (unsigned int index = 0; index < count; ++index)
  77. {
  78. const RefPtr<SquadData>& squad = _mSquadColl[index];
  79. WWASSERT(squad.IsValid());
  80. if (squad->GetID() == id)
  81. {
  82. return squad;
  83. }
  84. }
  85. return NULL;
  86. }
  87. /******************************************************************************
  88. *
  89. * NAME
  90. * SquadData::FindByAbbr
  91. *
  92. * DESCRIPTION
  93. * Find a squad in the local cache by its abbreviation.
  94. *
  95. * INPUTS
  96. * Abbr - Abbreviation of squad to search for.
  97. *
  98. * RESULT
  99. * Squad - Reference to squad
  100. *
  101. ******************************************************************************/
  102. RefPtr<SquadData> SquadData::FindByAbbr(const wchar_t* abbr)
  103. {
  104. if (abbr && (wcslen(abbr) > 0))
  105. {
  106. char squadAbbr[64];
  107. wcstombs(squadAbbr, abbr, sizeof(squadAbbr));
  108. squadAbbr[sizeof(squadAbbr) - 1] = 0;
  109. const unsigned int count = _mSquadColl.size();
  110. for (unsigned int index = 0; index < count; ++index)
  111. {
  112. const RefPtr<SquadData>& squad = _mSquadColl[index];
  113. WWASSERT(squad.IsValid());
  114. if ((strcmp(squad->GetAbbr(), squadAbbr) == 0))
  115. {
  116. return squad;
  117. }
  118. }
  119. }
  120. return NULL;
  121. }
  122. /******************************************************************************
  123. *
  124. * NAME
  125. * SquadData::Create
  126. *
  127. * DESCRIPTION
  128. * Create a squad data
  129. *
  130. * INPUTS
  131. * WOLSquad - WOLAPI squad data structure
  132. *
  133. * RESULT
  134. * SquadData - Instance of squad data.
  135. *
  136. ******************************************************************************/
  137. RefPtr<SquadData> SquadData::Create(const WOL::Squad& wolSquad)
  138. {
  139. if (wolSquad.id == 0)
  140. {
  141. return NULL;
  142. }
  143. RefPtr<SquadData> squad = FindByID(wolSquad.id);
  144. if (squad.IsValid())
  145. {
  146. squad->UpdateData(wolSquad);
  147. }
  148. else
  149. {
  150. squad = new SquadData(wolSquad);
  151. _mSquadColl.push_back(squad);
  152. }
  153. return squad;
  154. }
  155. /******************************************************************************
  156. *
  157. * NAME
  158. * SquadData::SquadData
  159. *
  160. * DESCRIPTION
  161. * Constructor
  162. *
  163. * INPUTS
  164. * WOLSquad - WOLAPI squad structure
  165. *
  166. * RESULT
  167. * NONE
  168. *
  169. ******************************************************************************/
  170. SquadData::SquadData(const WOL::Squad& squad)
  171. {
  172. WWDEBUG_SAY(("WOL: Instantiating SquadData '%s'\n", (char*)squad.name));
  173. UpdateData(squad);
  174. }
  175. /******************************************************************************
  176. *
  177. * NAME
  178. * SquadData::~SquadData
  179. *
  180. * DESCRIPTION
  181. * Destructor
  182. *
  183. * INPUTS
  184. * NONE
  185. *
  186. * RESULT
  187. * NONE
  188. *
  189. ******************************************************************************/
  190. SquadData::~SquadData()
  191. {
  192. WWDEBUG_SAY(("WOL: Destructing SquadData '%s'\n", (char*)mData.name));
  193. }
  194. /******************************************************************************
  195. *
  196. * NAME
  197. * SquadData::UpdateData
  198. *
  199. * DESCRIPTION
  200. *
  201. * INPUTS
  202. *
  203. * RESULT
  204. * NONE
  205. *
  206. ******************************************************************************/
  207. void SquadData::UpdateData(const WOL::Squad& squad)
  208. {
  209. memcpy(&mData, &squad, sizeof(mData));
  210. mData.next = NULL;
  211. }
  212. /******************************************************************************
  213. *
  214. * NAME
  215. * SquadData::SetLadder
  216. *
  217. * DESCRIPTION
  218. *
  219. * INPUTS
  220. *
  221. * RESULT
  222. * NONE
  223. *
  224. ******************************************************************************/
  225. void SquadData::SetLadder(const RefPtr<LadderData>& ladder)
  226. {
  227. mLadder = ladder;
  228. }
  229. } // namespace WWOnline