| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /******************************************************************************
- *
- * FILE
- * GroupControl.cpp
- *
- * DESCRIPTION
- * Group controller
- *
- * PROGRAMMER
- * Denzil E. Long, Jr.
- *
- * VERSION INFO
- * $Author: Pat_p $
- * $Revision: 2 $
- * $Modtime: 4/26/00 10:31a $
- * $Archive: /Commando/Code/Scripts/GroupControl.cpp $
- *
- ******************************************************************************/
- #include "groupcontrol.h"
- #include "group.h"
- #include "scripts.h"
- #include <assert.h>
- GroupController _GroupController;
- GroupController* GroupController::_mInstance = NULL;
- /******************************************************************************
- *
- * NAME
- * GroupController::Instance
- *
- * DESCRIPTION
- * Retrieve GroupController instance.
- *
- * INPUTS
- * NONE
- *
- * RESULTS
- * GroupController - GroupController instance pointer.
- *
- ******************************************************************************/
- GroupController* GroupController::Instance(void)
- {
- assert(_mInstance != NULL);
- return _mInstance;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::GroupController
- *
- * DESCRIPTION
- * Construct GroupController
- *
- * INPUTS
- * NONE
- *
- * RESULTS
- * NONE
- *
- ******************************************************************************/
- GroupController::GroupController()
- {
- _mInstance = this;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::~GroupController
- *
- * DESCRIPTION
- * Destruct GroupController
- *
- * INPUTS
- * NONE
- *
- * RESULTS
- * NONE
- *
- ******************************************************************************/
- GroupController::~GroupController()
- {
- mGroups.Remove_All();
- _mInstance = NULL;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::AddToGroup
- *
- * DESCRIPTION
- * Add a game object to the specified Group.
- *
- * INPUTS
- * GroupName - Name of the team to object to.
- * GameObject - Object to add.
- *
- * RESULTS
- * Success - Success / Failure condition
- *
- ******************************************************************************/
- bool GroupController::AddToGroup(const char* groupName, GameObject* object)
- {
- assert(groupName != NULL);
- assert(object != NULL);
- if ((groupName != NULL) && (object != NULL))
- {
- // Find the team to add the GameObject to.
- Group* group = FindOrCreateGroup(groupName);
- if (group != NULL)
- {
- group->AddMember(object);
- return true;
- }
- }
- return false;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::RemoveFromGroup
- *
- * DESCRIPTION
- * Remove a game object from the specified Group.
- *
- * INPUTS
- * GroupName - Name of group to remove object from.
- * GameObject - Object to remove.
- *
- * RESULTS
- * NONE
- *
- ******************************************************************************/
- void GroupController::RemoveFromGroup(const char* groupName, GameObject* object)
- {
- assert(groupName != NULL);
- assert(object != NULL);
- Group* group = FindGroup(groupName);
- if (group != NULL)
- {
- group->RemoveMember(object);
- }
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::FindGroup
- *
- * DESCRIPTION
- * Find a group by name,
- *
- * INPUTS
- * GroupName - Name of group to find.
- *
- * RESULTS
- * Group - Pointer to Group; NULL if not found.
- *
- ******************************************************************************/
- Group* GroupController::FindGroup(const char* groupName)
- {
- SLNode<Group>* node = mGroups.Head();
- // Go through all the Groups
- while (node != NULL)
- {
- Group* group = node->Data();
- assert(group != NULL);
- // If there is a group with a matching name then return with that group.
- const char* name = group->GetName();
- if (stricmp(groupName, name) == 0)
- {
- return group;
- }
- node = node->Next();
- }
- return NULL;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::FindOrCreateGroup
- *
- * DESCRIPTION
- * Create a new group with the specified name. If the group already exists
- * then the existing group will be returned.
- *
- * INPUTS
- * GroupName - Name of group to find or create.
- *
- * RESULTS
- * Group - Pointer to Group; NULL if failure to create group.
- *
- ******************************************************************************/
- Group* GroupController::FindOrCreateGroup(const char* groupName)
- {
- Group* group = FindGroup(groupName);
- // Create the group only if it doesn't already exist.
- if (group == NULL)
- {
- Group* group = new Group(groupName);
- assert(group != NULL);
- if (group != NULL)
- {
- mGroups.Add_Tail(group);
- }
- }
- return group;
- }
- /******************************************************************************
- *
- * NAME
- * GroupController::SendGroupCustomEvent
- *
- * DESCRIPTION
- * Send a Group a custom event.
- *
- * INPUTS
- * GroupName - Name of group to send event to.
- * GameObject - Object event is from.
- * Event - Event to send to Group.
- * Data - Event specific data parameter.
- *
- * RESULTS
- * NONE
- *
- ******************************************************************************/
- void GroupController::SendGroupCustomEvent(const char* groupName, GameObject* from,
- int event, int data)
- {
- Group* group = FindGroup(groupName);
- if (group != NULL)
- {
- group->SendCustomEvent(from, event, data);
- }
- }
|