| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /*
- ** 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
- * $Archive: /Commando/Code/WWOnline/WOLSquad.cpp $
- *
- * DESCRIPTION
- *
- * PROGRAMMER
- * $Author: Denzil_l $
- *
- * VERSION INFO
- * $Revision: 9 $
- * $Modtime: 1/12/02 9:45p $
- *
- ******************************************************************************/
- #include <stdlib.h>
- #include <memory.h>
- #include "WOLSquad.h"
- #include <WWDebug\WWDebug.h>
- namespace WWOnline {
- SquadData::SquadColl SquadData::_mSquadColl;
- /******************************************************************************
- *
- * NAME
- * SquadData::Reset
- *
- * DESCRIPTION
- * Release all cached squads
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void SquadData::Reset(void)
- {
- _mSquadColl.clear();
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::FindByID
- *
- * DESCRIPTION
- * Find a squad in the local cache by its ID
- *
- * INPUTS
- * SquadID - ID of squad to search for.
- *
- * RESULT
- * Squad - Reference to squad
- *
- ******************************************************************************/
- RefPtr<SquadData> SquadData::FindByID(unsigned long id)
- {
- const unsigned int count = _mSquadColl.size();
- for (unsigned int index = 0; index < count; ++index)
- {
- const RefPtr<SquadData>& squad = _mSquadColl[index];
- WWASSERT(squad.IsValid());
- if (squad->GetID() == id)
- {
- return squad;
- }
- }
- return NULL;
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::FindByAbbr
- *
- * DESCRIPTION
- * Find a squad in the local cache by its abbreviation.
- *
- * INPUTS
- * Abbr - Abbreviation of squad to search for.
- *
- * RESULT
- * Squad - Reference to squad
- *
- ******************************************************************************/
- RefPtr<SquadData> SquadData::FindByAbbr(const wchar_t* abbr)
- {
- if (abbr && (wcslen(abbr) > 0))
- {
- char squadAbbr[64];
- wcstombs(squadAbbr, abbr, sizeof(squadAbbr));
- squadAbbr[sizeof(squadAbbr) - 1] = 0;
- const unsigned int count = _mSquadColl.size();
- for (unsigned int index = 0; index < count; ++index)
- {
- const RefPtr<SquadData>& squad = _mSquadColl[index];
- WWASSERT(squad.IsValid());
- if ((strcmp(squad->GetAbbr(), squadAbbr) == 0))
- {
- return squad;
- }
- }
- }
- return NULL;
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::Create
- *
- * DESCRIPTION
- * Create a squad data
- *
- * INPUTS
- * WOLSquad - WOLAPI squad data structure
- *
- * RESULT
- * SquadData - Instance of squad data.
- *
- ******************************************************************************/
- RefPtr<SquadData> SquadData::Create(const WOL::Squad& wolSquad)
- {
- if (wolSquad.id == 0)
- {
- return NULL;
- }
- RefPtr<SquadData> squad = FindByID(wolSquad.id);
- if (squad.IsValid())
- {
- squad->UpdateData(wolSquad);
- }
- else
- {
- squad = new SquadData(wolSquad);
- _mSquadColl.push_back(squad);
- }
- return squad;
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::SquadData
- *
- * DESCRIPTION
- * Constructor
- *
- * INPUTS
- * WOLSquad - WOLAPI squad structure
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- SquadData::SquadData(const WOL::Squad& squad)
- {
- WWDEBUG_SAY(("WOL: Instantiating SquadData '%s'\n", (char*)squad.name));
- UpdateData(squad);
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::~SquadData
- *
- * DESCRIPTION
- * Destructor
- *
- * INPUTS
- * NONE
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- SquadData::~SquadData()
- {
- WWDEBUG_SAY(("WOL: Destructing SquadData '%s'\n", (char*)mData.name));
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::UpdateData
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void SquadData::UpdateData(const WOL::Squad& squad)
- {
- memcpy(&mData, &squad, sizeof(mData));
- mData.next = NULL;
- }
- /******************************************************************************
- *
- * NAME
- * SquadData::SetLadder
- *
- * DESCRIPTION
- *
- * INPUTS
- *
- * RESULT
- * NONE
- *
- ******************************************************************************/
- void SquadData::SetLadder(const RefPtr<LadderData>& ladder)
- {
- mLadder = ladder;
- }
- } // namespace WWOnline
|