Group.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. * Group.cpp
  22. *
  23. * DESCRIPTION
  24. * Group manager for GameObjects
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. *
  29. * VERSION INFO
  30. * $Author: Denzil_l $
  31. * $Revision: 1 $
  32. * $Modtime: 4/17/00 9:47a $
  33. * $Archive: /Commando/Code/Scripts/Group.cpp $
  34. *
  35. ******************************************************************************/
  36. #include "group.h"
  37. /******************************************************************************
  38. *
  39. * NAME
  40. * Group::Group
  41. *
  42. * DESCRIPTION
  43. * Group Constructor
  44. *
  45. * INPUTS
  46. * Name - Name of team.
  47. *
  48. * RESULTS
  49. * NONE
  50. *
  51. ******************************************************************************/
  52. Group::Group(const char* name)
  53. {
  54. mName[0] = '\0';
  55. // Make copy of team name
  56. assert(name != NULL);
  57. if (name != NULL)
  58. {
  59. strncpy(mName, name, sizeof(mName));
  60. mName[sizeof(mName) - 1] = '\0';
  61. }
  62. }
  63. /******************************************************************************
  64. *
  65. * NAME
  66. * Group::~Group
  67. *
  68. * DESCRIPTION
  69. * Group Destructor
  70. *
  71. * INPUTS
  72. * NONE
  73. *
  74. * RESULTS
  75. * NONE
  76. *
  77. ******************************************************************************/
  78. Group::~Group()
  79. {
  80. }
  81. /******************************************************************************
  82. *
  83. * NAME
  84. * Group::GetName
  85. *
  86. * DESCRIPTION
  87. * Retrieve name of Group.
  88. *
  89. * INPUTS
  90. * NONE
  91. *
  92. * RESULTS
  93. * Name - Name of team
  94. *
  95. ******************************************************************************/
  96. const char* Group::GetName(void) const
  97. {
  98. return mName;
  99. }
  100. /******************************************************************************
  101. *
  102. * NAME
  103. * Group::AddMember
  104. *
  105. * DESCRIPTION
  106. * Add a game object to the Group.
  107. *
  108. * INPUTS
  109. * GameObject - Pointer to game object to add.
  110. *
  111. * RESULTS
  112. * NONE
  113. *
  114. ******************************************************************************/
  115. void Group::AddMember(GameObject* object)
  116. {
  117. assert(object != NULL);
  118. // Add the object if it is not already a member of the team.
  119. if (IsMember(object) == false)
  120. {
  121. mMembers.Add(object);
  122. }
  123. }
  124. /******************************************************************************
  125. *
  126. * NAME
  127. * Group::RemoveMember
  128. *
  129. * DESCRIPTION
  130. * Remove a game object from the Group.
  131. *
  132. * INPUTS
  133. * GameObject - Pointer to game object to remove.
  134. *
  135. * RESULTS
  136. * NONE
  137. *
  138. ******************************************************************************/
  139. void Group::RemoveMember(GameObject* object)
  140. {
  141. assert(object != NULL);
  142. mMembers.Delete(object);
  143. }
  144. /******************************************************************************
  145. *
  146. * NAME
  147. * Group::IsMember
  148. *
  149. * DESCRIPTION
  150. * Check if a game object is member of the Group.
  151. *
  152. * INPUTS
  153. * GameObjectID objectID
  154. *
  155. * RESULTS
  156. * bool
  157. *
  158. ******************************************************************************/
  159. bool Group::IsMember(GameObject* object) const
  160. {
  161. assert(object != NULL);
  162. for (int index = 0; index < mMembers.Count(); index++)
  163. {
  164. if (mMembers[index] == object)
  165. {
  166. return true;
  167. }
  168. }
  169. return false;
  170. }
  171. /******************************************************************************
  172. *
  173. * NAME
  174. * MemberCount
  175. *
  176. * DESCRIPTION
  177. * Get the number of members in the Group.
  178. *
  179. * INPUTS
  180. * NONE
  181. *
  182. * RESULTS
  183. * Count - Member count
  184. *
  185. ******************************************************************************/
  186. int Group::MemberCount(void) const
  187. {
  188. return mMembers.Count();
  189. }
  190. /******************************************************************************
  191. *
  192. * NAME
  193. * Group::GetMember
  194. *
  195. * DESCRIPTION
  196. * Get a Group member.
  197. *
  198. * INPUTS
  199. * int index
  200. *
  201. * RESULTS
  202. * GameObject*
  203. *
  204. ******************************************************************************/
  205. GameObject* Group::GetMember(int index)
  206. {
  207. assert(index >= 0);
  208. assert(index < MemberCount());
  209. return mMembers[index];
  210. }
  211. /******************************************************************************
  212. *
  213. * NAME
  214. * Group::SendCommand
  215. *
  216. * DESCRIPTION
  217. * Send a command to all the members of the Group.
  218. *
  219. * INPUTS
  220. * Command - Command to send to Group members.
  221. * Data - Command specific data parameter.
  222. *
  223. * RESULTS
  224. * NONE
  225. *
  226. ******************************************************************************/
  227. void Group::SendCustomEvent(GameObject* from, int event, int data)
  228. {
  229. for (int index = 0; index < mMembers.Count(); index++)
  230. {
  231. GameObject* object = mMembers[index];
  232. assert(object != NULL);
  233. Commands->Send_Custom_Event(from, object, event, data);
  234. }
  235. }