| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545 |
- /*
- ** Command & Conquer Generals(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/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: GameInfo.cpp //////////////////////////////////////////////////////
- // game setup state info
- // Author: Matthew D. Campbell, December 2001
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- #include "Common/CRCDebug.h"
- #include "Common/File.h"
- #include "Common/FileSystem.h"
- #include "Common/GameState.h"
- #include "GameClient/GameText.h"
- #include "GameClient/MapUtil.h"
- #include "Common/MultiplayerSettings.h"
- #include "Common/PlayerTemplate.h"
- #include "Common/Xfer.h"
- #include "GameNetwork/FileTransfer.h"
- #include "GameNetwork/GameInfo.h"
- #include "GameNetwork/GameSpy/ThreadUtils.h"
- #include "GameNetwork/GameSpy/StagingRoomGameInfo.h"
- #include "GameNetwork/LANAPI.h" // for testing packet size
- #include "GameNetwork/LANAPICallbacks.h" // for testing packet size
- #include "strtok_r.h"
- #ifdef _INTERNAL
- // for occasional debugging...
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- GameInfo *TheGameInfo = NULL;
- // GameSlot ----------------------------------------
- GameSlot::GameSlot()
- {
- reset();
- }
- void GameSlot::reset()
- {
- m_state = SLOT_CLOSED; // decent default
- m_isAccepted = false;
- m_hasMap = true;
- m_color = -1;
- m_startPos = -1;
- m_playerTemplate = -1;
- m_teamNumber = -1;
- m_NATBehavior = FirewallHelperClass::FIREWALL_TYPE_SIMPLE;
- m_lastFrameInGame = 0;
- m_disconnected = FALSE;
- m_port = 0;
- m_isMuted = FALSE;
- m_origPlayerTemplate = -1;
- m_origStartPos = -1;
- m_origColor = -1;
- }
- void GameSlot::saveOffOriginalInfo( void )
- {
- DEBUG_LOG(("GameSlot::saveOffOriginalInfo() - orig was color=%d, pos=%d, house=%d\n",
- m_origColor, m_origStartPos, m_origPlayerTemplate));
- m_origPlayerTemplate = m_playerTemplate;
- m_origStartPos = m_startPos;
- m_origColor = m_color;
- DEBUG_LOG(("GameSlot::saveOffOriginalInfo() - color=%d, pos=%d, house=%d\n",
- m_color, m_startPos, m_playerTemplate));
- }
- static Int getSlotIndex(const GameSlot *slot)
- {
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (TheGameInfo->getConstSlot(i) == slot)
- return i;
- }
- return -1;
- }
- static Bool isSlotLocalAlly(const GameSlot *slot)
- {
- Int slotIndex = getSlotIndex(slot);
- Int localIndex = TheGameInfo->getLocalSlotNum();
- const GameSlot *localSlot = TheGameInfo->getConstSlot(localIndex);
- // if either doesn't exist, not an ally
- if (slotIndex < 0 || localIndex < 0)
- return FALSE;
- // if slot is us, ally
- if (slotIndex == localIndex)
- return TRUE;
- // if slot is same team as us, ally
- if (slot->getTeamNumber() == localSlot->getTeamNumber() && slot->getTeamNumber() >= 0)
- return TRUE;
- // if we're an observer, we see all
- if (localSlot->getOriginalPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)
- return TRUE;
- // nope
- return FALSE;
- }
- UnicodeString GameSlot::getApparentPlayerTemplateDisplayName( void ) const
- {
- if (TheMultiplayerSettings && TheMultiplayerSettings->showRandomPlayerTemplate() &&
- m_origPlayerTemplate == PLAYERTEMPLATE_RANDOM && !isSlotLocalAlly(this))
- {
- return TheGameText->fetch("GUI:Random");
- }
- else if (m_origPlayerTemplate == PLAYERTEMPLATE_OBSERVER)
- {
- return TheGameText->fetch("GUI:Observer");
- }
- DEBUG_LOG(("Fetching player template display name for player template %d (orig is %d)\n",
- m_playerTemplate, m_origPlayerTemplate));
- if (m_playerTemplate < 0)
- {
- return TheGameText->fetch("GUI:Random");
- }
- return ThePlayerTemplateStore->getNthPlayerTemplate(m_playerTemplate)->getDisplayName();
- }
- Int GameSlot::getApparentPlayerTemplate( void ) const
- {
- if (TheMultiplayerSettings && TheMultiplayerSettings->showRandomPlayerTemplate() &&
- !isSlotLocalAlly(this))
- {
- return m_origPlayerTemplate;
- }
- return m_playerTemplate;
- }
- Int GameSlot::getApparentColor( void ) const
- {
- if (TheMultiplayerSettings && m_origPlayerTemplate == PLAYERTEMPLATE_OBSERVER)
- return TheMultiplayerSettings->getColor(PLAYERTEMPLATE_OBSERVER)->getColor();
- if (TheMultiplayerSettings && TheMultiplayerSettings->showRandomColor() &&
- !isSlotLocalAlly(this))
- {
- return m_origColor;
- }
- return m_color;
- }
- Int GameSlot::getApparentStartPos( void ) const
- {
- if (TheMultiplayerSettings && TheMultiplayerSettings->showRandomStartPos() &&
- !isSlotLocalAlly(this))
- {
- return m_origStartPos;
- }
- return m_startPos;
- }
- void GameSlot::unAccept( void )
- {
- if (isHuman())
- {
- m_isAccepted = false;
- }
- }
- void GameSlot::setMapAvailability( Bool hasMap )
- {
- if (isHuman())
- {
- m_hasMap = hasMap;
- }
- }
- void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP )
- {
- if (!(isAI() && (state == SLOT_EASY_AI || state == SLOT_MED_AI || state == SLOT_BRUTAL_AI)))
- {
- m_color = -1;
- m_startPos = -1;
- m_playerTemplate = -1;
- m_teamNumber = -1;
- if (state == SLOT_OPEN && TheGameSpyGame && TheGameSpyGame->getConstSlot(0) == this)
- {
- DEBUG_CRASH(("Game Is Hosed!\n"));
- }
- }
- if (state == SLOT_PLAYER)
- {
- reset();
- m_state = state;
- m_name = name;
- }// state == SLOT_PLAYER
- else
- {
- m_state = state;
- m_isAccepted = true;
- m_hasMap = true;
- switch(state)
- {
- case SLOT_OPEN:
- m_name = TheGameText->fetch("GUI:Open");
- break;
- case SLOT_EASY_AI:
- m_name = TheGameText->fetch("GUI:EasyAI");
- break;
- case SLOT_MED_AI:
- m_name = TheGameText->fetch("GUI:MediumAI");
- break;
- case SLOT_BRUTAL_AI:
- m_name = TheGameText->fetch("GUI:HardAI");
- break;
- case SLOT_CLOSED:
- default:
- m_name = TheGameText->fetch("GUI:Closed");
- break;
- }
- }
- m_IP = IP;
- }
- // Various tests
- Bool GameSlot::isHuman( void ) const
- {
- return m_state == SLOT_PLAYER;
- }
- Bool GameSlot::isOccupied( void ) const
- {
- return m_state == SLOT_PLAYER || m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI;
- }
- Bool GameSlot::isAI( void ) const
- {
- return m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI;
- }
- Bool GameSlot::isPlayer( AsciiString userName ) const
- {
- UnicodeString uName;
- uName.translate(userName);
- return (m_state == SLOT_PLAYER && !m_name.compareNoCase(uName));
- }
- Bool GameSlot::isPlayer( UnicodeString userName ) const
- {
- return (m_state == SLOT_PLAYER && !m_name.compareNoCase(userName));
- }
- Bool GameSlot::isPlayer( UnsignedInt ip ) const
- {
- return (m_state == SLOT_PLAYER && m_IP == ip);
- }
- Bool GameSlot::isOpen( void ) const
- {
- return m_state == SLOT_OPEN;
- }
- // GameInfo ----------------------------------------
- GameInfo::GameInfo()
- {
- for (int i=0; i<MAX_SLOTS; ++i)
- {
- m_slot[i] = NULL;
- }
- reset();
- }
- void GameInfo::init( void )
- {
- reset();
- }
- void GameInfo::reset( void )
- {
- m_crcInterval = NET_CRC_INTERVAL;
- m_inGame = false;
- m_inProgress = false;
- m_gameID = 0;
- m_mapName = AsciiString("NOMAP");
- m_mapMask = 0;
- m_seed = GetTickCount(); //GameClientRandomValue(0, INT_MAX - 1);
- m_surrendered = FALSE;
- // Added By Sadullah Nader
- // Initializations missing and needed
- // m_localIP = 0; // BGC - actually we don't want this to be reset since the m_localIP is
- // set properly in the constructor of LANGameInfo which uses this as a base class.
- m_mapCRC = 0;
- m_mapSize = 0;
- //
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (m_slot[i])
- m_slot[i]->reset();
- }
- m_preorderMask = 0;
- }
- Bool GameInfo::isPlayerPreorder(Int index)
- {
- if (index >= 0 && index < MAX_SLOTS)
- return ((m_preorderMask & (1 << index)) != 0);
- return FALSE;
- }
- void GameInfo::markPlayerAsPreorder(Int index)
- {
- if (index >= 0 && index < MAX_SLOTS)
- m_preorderMask |= 1 << index;
- }
- void GameInfo::clearSlotList( void )
- {
- for (int i=0; i<MAX_SLOTS; ++i)
- {
- if (m_slot[i])
- m_slot[i]->setState(SLOT_CLOSED);
- }
- }
- Int GameInfo::getNumPlayers( void ) const
- {
- Int numPlayers = 0;
- for (int i=0; i<MAX_SLOTS; ++i)
- {
- if (m_slot[i] && m_slot[i]->isOccupied())
- numPlayers++;
- }
- return numPlayers;
- }
- Int GameInfo::getNumNonObserverPlayers( void ) const
- {
- Int numPlayers = 0;
- for (int i=0; i<MAX_SLOTS; ++i)
- {
- if (m_slot[i] && m_slot[i]->isOccupied() && m_slot[i]->getPlayerTemplate() != PLAYERTEMPLATE_OBSERVER)
- numPlayers++;
- }
- return numPlayers;
- }
- Int GameInfo::getMaxPlayers( void ) const
- {
- if (!TheMapCache)
- return -1;
- AsciiString lowerMap = m_mapName;
- lowerMap.toLower();
- MapCache::iterator it = TheMapCache->find(lowerMap);
- if (it == TheMapCache->end())
- return -1;
- MapMetaData data = it->second;
- return data.m_numPlayers;
- }
- void GameInfo::enterGame( void )
- {
- DEBUG_ASSERTCRASH(!m_inGame && !m_inProgress, ("Entering game at a bad time!"));
- reset();
- m_inGame = true;
- m_inProgress = false;
- }
- void GameInfo::leaveGame( void )
- {
- DEBUG_ASSERTCRASH(m_inGame && !m_inProgress, ("Leaving game at a bad time!"));
- reset();
- }
- void GameInfo::startGame( Int gameID )
- {
- DEBUG_ASSERTCRASH(m_inGame && !m_inProgress, ("Starting game at a bad time!"));
- m_gameID = gameID;
- closeOpenSlots();
- m_inProgress = true;
- }
- void GameInfo::endGame( void )
- {
- DEBUG_ASSERTCRASH(m_inGame && m_inProgress, ("Ending game without playing one!"));
- m_inGame = false;
- m_inProgress = false;
- }
- void GameInfo::setSlot( Int slotNum, GameSlot slotInfo )
- {
- DEBUG_ASSERTCRASH( slotNum >= 0 && slotNum < MAX_SLOTS, ("GameInfo::setSlot - Invalid slot number"));
- if (slotNum < 0 || slotNum >= MAX_SLOTS)
- return;
- DEBUG_ASSERTCRASH( m_slot[slotNum], ("NULL slot pointer"));
- if (!m_slot[slotNum])
- return;
- // Bool isHuman = slotInfo.isHuman();
- // Bool wasHuman = m_slot[slotNum]->isHuman();
- if (slotNum == 0)
- {
- slotInfo.setAccept();
- slotInfo.setMapAvailability(true);
- }
- *m_slot[slotNum] = slotInfo;
- #ifdef DEBUG_LOGGING
- UnsignedInt ip = slotInfo.getIP();
- #endif
- DEBUG_LOG(("GameInfo::setSlot - setting slot %d to be player %ls with IP %d.%d.%d.%d\n", slotNum, slotInfo.getName().str(),
- ip >> 24, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff));
- }
- GameSlot* GameInfo::getSlot( Int slotNum )
- {
- DEBUG_ASSERTCRASH( slotNum >= 0 && slotNum < MAX_SLOTS, ("GameInfo::getSlot - Invalid slot number"));
- if (slotNum < 0 || slotNum >= MAX_SLOTS)
- return NULL;
- return m_slot[slotNum];
- }
- const GameSlot* GameInfo::getConstSlot( Int slotNum ) const
- {
- DEBUG_ASSERTCRASH( slotNum >= 0 && slotNum < MAX_SLOTS, ("GameInfo::getSlot - Invalid slot number"));
- if (slotNum < 0 || slotNum >= MAX_SLOTS)
- return NULL;
- return m_slot[slotNum];
- }
- Int GameInfo::getLocalSlotNum( void ) const
- {
- DEBUG_ASSERTCRASH(m_inGame, ("Looking for local game slot while not in game"));
- if (!m_inGame)
- return -1;
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- const GameSlot *slot = getConstSlot(i);
- if (slot == NULL) {
- continue;
- }
- if (slot->isPlayer(m_localIP))
- return i;
- }
- return -1;
- }
- Int GameInfo::getSlotNum( AsciiString userName ) const
- {
- DEBUG_ASSERTCRASH(m_inGame, ("Looking for game slot while not in game"));
- if (!m_inGame)
- return -1;
- UnicodeString uName;
- uName.translate(userName);
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- const GameSlot *slot = getConstSlot(i);
- if (slot->isPlayer( uName ))
- return i;
- }
- return -1;
- }
- Bool GameInfo::amIHost( void ) const
- {
- DEBUG_ASSERTCRASH(m_inGame, ("Looking for game slot while not in game"));
- if (!m_inGame)
- return false;
- return getConstSlot(0)->isPlayer(m_localIP);
- }
- void GameInfo::setMap( AsciiString mapName )
- {
- m_mapName = mapName;
- if (m_inGame && amIHost())
- {
- const MapMetaData *mapData = TheMapCache->findMap( mapName );
- if (mapData)
- {
- m_mapMask = 1;
- AsciiString path = mapName;
- path.removeLastChar();
- path.removeLastChar();
- path.removeLastChar();
- path.concat("tga");
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", path.str()));
- File *fp = TheFileSystem->openFile(path.str());
- if (fp)
- {
- m_mapMask |= 2;
- fp->close();
- fp = NULL;
- }
- AsciiString newMapName;
- if (mapName.getLength() > 0)
- {
- AsciiString token;
- mapName.nextToken(&token, "\\/");
- // add all the tokens except the last one.
- // that way we don't add the filename, just the
- // directory name, we can do this since the filename
- // is just the directory name with the file extention
- // added onto it.
- while (mapName.find('\\') != NULL)
- {
- if (newMapName.getLength() > 0)
- {
- newMapName.concat('/');
- }
- newMapName.concat(token);
- mapName.nextToken(&token, "\\/");
- }
- }
- newMapName.concat("/map.ini");
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", newMapName.str()));
- fp = TheFileSystem->openFile(newMapName.str());
- if (fp)
- {
- m_mapMask |= 4;
- fp->close();
- fp = NULL;
- }
- path = GetStrFileFromMap(m_mapName);
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", path.str()));
- fp = TheFileSystem->openFile(path.str());
- if (fp)
- {
- m_mapMask |= 8;
- fp->close();
- fp = NULL;
- }
- path = GetSoloINIFromMap(m_mapName);
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", path.str()));
- fp = TheFileSystem->openFile(path.str());
- if (fp)
- {
- m_mapMask |= 16;
- fp->close();
- fp = NULL;
- }
- path = GetAssetUsageFromMap(m_mapName);
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", path.str()));
- fp = TheFileSystem->openFile(path.str());
- if (fp)
- {
- m_mapMask |= 32;
- fp->close();
- fp = NULL;
- }
- path = GetReadmeFromMap(m_mapName);
- DEBUG_LOG(("GameInfo::setMap() - Looking for '%s'\n", path.str()));
- fp = TheFileSystem->openFile(path.str());
- if (fp)
- {
- m_mapMask |= 64;
- fp->close();
- fp = NULL;
- }
- }
- else
- {
- m_mapMask = 0;
- }
- }
- }
- void GameInfo::setMapContentsMask( Int mask )
- {
- m_mapMask = mask;
- }
- void GameInfo::setMapCRC( UnsignedInt mapCRC )
- {
- m_mapCRC = mapCRC;
- if (!TheMapCache)
- return;
- // check the map cache
- if (m_inGame && getLocalSlotNum() >= 0)
- {
- //TheMapCache->updateCache();
- AsciiString lowerMap = m_mapName;
- lowerMap.toLower();
- //DEBUG_LOG(("GameInfo::setMapCRC - looking for map file \"%s\" in the map cache\n", lowerMap.str()));
- std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
- if (it == TheMapCache->end())
- {
- /*
- DEBUG_LOG(("GameInfo::setMapCRC - could not find map file.\n"));
- it = TheMapCache->begin();
- while (it != TheMapCache->end())
- {
- DEBUG_LOG(("\t\"%s\"\n", it->first.str()));
- ++it;
- }
- */
- getSlot(getLocalSlotNum())->setMapAvailability(false);
- }
- else if (m_mapCRC != it->second.m_CRC)
- {
- DEBUG_LOG(("GameInfo::setMapCRC - map CRC's do not match (%X/%X).\n", m_mapCRC, it->second.m_CRC));
- getSlot(getLocalSlotNum())->setMapAvailability(false);
- }
- else
- {
- //DEBUG_LOG(("GameInfo::setMapCRC - map CRC's match.\n"));
- getSlot(getLocalSlotNum())->setMapAvailability(true);
- }
- }
- }
- void GameInfo::setMapSize( UnsignedInt mapSize )
- {
- m_mapSize = mapSize;
- if (!TheMapCache)
- return;
- // check the map cache
- if (m_inGame && getLocalSlotNum() >= 0)
- {
- //TheMapCache->updateCache();
- AsciiString lowerMap = m_mapName;
- lowerMap.toLower();
- std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);
- if (it == TheMapCache->end())
- {
- DEBUG_LOG(("GameInfo::setMapSize - could not find map file.\n"));
- getSlot(getLocalSlotNum())->setMapAvailability(false);
- }
- else if (m_mapCRC != it->second.m_CRC)
- {
- DEBUG_LOG(("GameInfo::setMapSize - map CRC's do not match.\n"));
- getSlot(getLocalSlotNum())->setMapAvailability(false);
- }
- else
- {
- //DEBUG_LOG(("GameInfo::setMapSize - map CRC's match.\n"));
- getSlot(getLocalSlotNum())->setMapAvailability(true);
- }
- }
- }
- void GameInfo::setSeed( Int seed )
- {
- m_seed = seed;
- }
- void GameInfo::setSlotPointer( Int index, GameSlot *slot )
- {
- if (index < 0 || index >= MAX_SLOTS)
- return;
- m_slot[index] = slot;
- }
- Bool GameInfo::isColorTaken(Int colorIdx, Int slotToIgnore ) const
- {
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- const GameSlot *slot = getConstSlot(i);
- if (slot && slot->getColor() == colorIdx && i != slotToIgnore)
- return true;
- }
- return false;
- }
- Bool GameInfo::isStartPositionTaken(Int positionIdx, Int slotToIgnore ) const
- {
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- const GameSlot *slot = getConstSlot(i);
- if (slot && slot->getStartPos() == positionIdx && i != slotToIgnore)
- return true;
- }
- return false;
- }
- void GameInfo::resetAccepted( void )
- {
- GameSlot *slot = getSlot(0);
- if (slot)
- slot->setAccept();
- for(int i = 1; i< MAX_SLOTS; i++)
- {
- slot = getSlot(i);
- if (slot)
- slot->unAccept();
- }
- }
- void GameInfo::resetStartSpots()
- {
- GameSlot *slot = NULL;
- for (Int i = 0; i < MAX_SLOTS; ++i)
- {
- slot = getSlot(i);
- if (slot != NULL)
- {
- slot->setStartPos(-1);
- }
- }
- }
- // adjust the slots in the game to open or closed
- // depending on the players in there now and the number of
- // players the map can hold.
- void GameInfo::adjustSlotsForMap()
- {
- const MapMetaData *md = TheMapCache->findMap(m_mapName);
- if (md != NULL)
- {
- // get the number of players allowed from the map.
- Int numPlayers = md->m_numPlayers;
- Int numPlayerSlots = 0;
- // first get the number of occupied slots.
- for (Int i = 0; i < MAX_SLOTS; ++i)
- {
- GameSlot *tempSlot = getSlot(i);
- if (tempSlot->isOccupied())
- {
- ++numPlayerSlots;
- }
- }
- // now go through and close the appropriate number of slots.
- // note that no players are kicked in this process, we leave
- // that up to the user.
- for (i = 0; i < MAX_SLOTS; ++i)
- {
- // we have room for more players, if this slot is unoccupied, set it to open.
- GameSlot *slot = getSlot(i);
- if (numPlayers > numPlayerSlots)
- {
- if (!(slot->isOccupied()))
- {
- GameSlot newSlot;
- newSlot.setState(SLOT_OPEN);
- setSlot(i, newSlot);
- ++numPlayerSlots;
- }
- }
- else
- {
- if (!(slot->isOccupied()))
- {
- // we don't have any more room, set this slot to closed.
- GameSlot newSlot;
- newSlot.setState(SLOT_CLOSED);
- setSlot(i, newSlot);
- }
- }
- }
- }
- }
- void GameInfo::closeOpenSlots()
- {
- for (Int i = 0; i < MAX_SLOTS; ++i)
- {
- GameSlot *slot = getSlot(i);
- if (!(slot->isOccupied()))
- {
- GameSlot newSlot;
- newSlot.setState(SLOT_CLOSED);
- setSlot(i, newSlot);
- }
- }
- }
- static Bool isSlotLocalAlly(GameInfo *game, const GameSlot *slot)
- {
- const GameSlot *localSlot = game->getConstSlot(game->getLocalSlotNum());
- if (!localSlot)
- return TRUE;
- if (slot == localSlot)
- return TRUE;
- if (slot->getTeamNumber() < 0)
- return FALSE;
- return slot->getTeamNumber() == localSlot->getTeamNumber();
- }
- Bool GameInfo::isSkirmish(void)
- {
- Bool sawAI = FALSE;
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (i == getLocalSlotNum())
- continue;
- if (getConstSlot(i)->isHuman())
- return FALSE;
- if (getConstSlot(i)->isAI())
- {
- if (isSlotLocalAlly(getConstSlot(i)))
- return FALSE;
- sawAI = TRUE;
- }
- }
- return sawAI;
- }
- Bool GameInfo::isMultiPlayer(void)
- {
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (i == getLocalSlotNum())
- continue;
- if (getConstSlot(i)->isHuman())
- return TRUE;
- }
- return FALSE;
- }
- Bool GameInfo::isSandbox(void)
- {
- Int localSlotNum = getLocalSlotNum();
- Int localTeam = getConstSlot(localSlotNum)->getTeamNumber();
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- if (i == localSlotNum)
- continue;
- const GameSlot *slot = getConstSlot(i);
- if (slot->isOccupied() && (slot->getTeamNumber() < 0 || slot->getTeamNumber() != localTeam))
- return FALSE;
- }
- return TRUE;
- }
- // Convenience Functions ----------------------------------------
- static const char slotListID = 'S';
- AsciiString GameInfoToAsciiString( const GameInfo *game )
- {
- if (!game)
- return AsciiString::TheEmptyString;
- AsciiString mapName = game->getMap();
- mapName = TheGameState->realMapPathToPortableMapPath(mapName);
- AsciiString newMapName;
- if (mapName.getLength() > 0)
- {
- AsciiString token;
- mapName.nextToken(&token, "\\/");
- // add all the tokens except the last one.
- // that way we don't add the filename, just the
- // directory name, we can do this since the filename
- // is just the directory name with the file extention
- // added onto it.
- while (mapName.find('\\') != NULL)
- {
- if (newMapName.getLength() > 0)
- {
- newMapName.concat('/');
- }
- newMapName.concat(token);
- mapName.nextToken(&token, "\\/");
- }
- DEBUG_LOG(("Map name is %s\n", mapName.str()));
- }
- AsciiString optionsString;
- optionsString.format("M=%2.2x%s;MC=%X;MS=%d;SD=%d;C=%d;", game->getMapContentsMask(), newMapName.str(),
- game->getMapCRC(), game->getMapSize(), game->getSeed(), game->getCRCInterval());
- optionsString.concat(slotListID);
- optionsString.concat('=');
- for (Int i=0; i<MAX_SLOTS; ++i)
- {
- const GameSlot *slot = game->getConstSlot(i);
- AsciiString str;
- if (slot && slot->isHuman())
- {
- AsciiString name = WideCharStringToMultiByte(slot->getName().str()).c_str();
-
- str.format( "H%s,%X,%d,%c%c,%d,%d,%d,%d,%d:",
- name.str(), slot->getIP(), slot->getPort(),
- (slot->isAccepted()?'T':'F'),
- (slot->hasMap()?'T':'F'),
- slot->getColor(), slot->getPlayerTemplate(),
- slot->getStartPos(), slot->getTeamNumber(),
- slot->getNATBehavior() );
- }
- else if (slot && slot->isAI())
- {
- Char c;
- if (slot->getState() == SLOT_EASY_AI)
- c = 'E';
- else if (slot->getState() == SLOT_MED_AI)
- c = 'M';
- else
- c = 'H';
- str.format("C%c,%d,%d,%d,%d:", c,
- slot->getColor(), slot->getPlayerTemplate(),
- slot->getStartPos(), slot->getTeamNumber());
- }
- else if (slot && slot->getState() == SLOT_OPEN)
- {
- str = "O:";
- }
- else if (slot && slot->getState() == SLOT_CLOSED)
- {
- str = "X:";
- }
- else
- {
- DEBUG_ASSERTCRASH(false, ("Bad slot type"));
- str = "X:";
- }
- optionsString.concat(str);
- }
- optionsString.concat(';');
- DEBUG_ASSERTCRASH(!TheLAN || (optionsString.getLength() < m_lanMaxOptionsLength),
- ("WARNING: options string is longer than expected! Length is %d, but max is %d!\n",
- optionsString.getLength(), m_lanMaxOptionsLength));
-
- return optionsString;
- }
- static Int grabHexInt(const char *s)
- {
- char tmp[5] = "0xff";
- tmp[2] = s[0];
- tmp[3] = s[1];
- Int b = strtol(tmp, NULL, 16);
- return b;
- }
- Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)
- {
- // Parse game options
- char *buf = strdup(options.str());
- char *bufPtr = buf;
- char *strPos, *keyValPair;
- GameSlot newSlot[MAX_SLOTS];
- Bool optionsOk = true;
- AsciiString mapName;
- Int mapContentsMask;
- UnsignedInt mapCRC, mapSize;
- Int seed = 0;
- Int crc = 100;
- Bool sawCRC = FALSE;
- Bool sawMap, sawMapCRC, sawMapSize, sawSeed, sawSlotlist;
- sawMap = sawMapCRC = sawMapSize = sawSeed = sawSlotlist = FALSE;
- //DEBUG_LOG(("Saw options of %s\n", options.str()));
- DEBUG_LOG(("ParseAsciiStringToGameInfo - parsing [%s]\n", options.str()));
- while ( (keyValPair = strtok_r(bufPtr, ";", &strPos)) != NULL )
- {
- bufPtr = NULL; // strtok within the same string
- AsciiString key, val;
- char *pos = NULL;
- char *keyPtr, *valPtr;
- keyPtr = (strtok_r(keyValPair, "=", &pos));
- valPtr = (strtok_r(NULL, "\n", &pos));
- if (keyPtr)
- key = keyPtr;
- if (valPtr)
- val = valPtr;
- if (val.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - saw empty value, quitting\n"));
- break;
- }
- if (key.compare("M") == 0)
- {
- if (val.getLength() < 3)
- {
- optionsOk = FALSE;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - saw bogus map; quitting\n"));
- break;
- }
- mapContentsMask = grabHexInt(val.str());
- AsciiString tempstr;
- AsciiString token;
- tempstr = val.str()+2;
- tempstr.nextToken(&token, "\\/");
- while (tempstr.getLength() > 0)
- {
- mapName.concat(token);
- mapName.concat('\\');
- tempstr.nextToken(&token, "\\/");
- }
- mapName.concat(token);
- mapName.concat('\\');
- mapName.concat(token);
- mapName.concat('.');
- mapName.concat(TheMapCache->getMapExtension());
- mapName = TheGameState->portableMapPathToRealMapPath(mapName);
- sawMap = true;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - map name is %s\n", mapName.str()));
- }
- else if (key.compare("MC") == 0)
- {
- mapCRC = 0;
- sscanf(val.str(), "%X", &mapCRC);
- sawMapCRC = true;
- }
- else if (key.compare("MS") == 0)
- {
- mapSize = atoi(val.str());
- sawMapSize = true;
- }
- else if (key.compare("SD") == 0)
- {
- seed = atoi(val.str());
- sawSeed = true;
- // DEBUG_LOG(("ParseAsciiStringToGameInfo - random seed is %d\n", seed));
- }
- else if (key.compare("C") == 0)
- {
- crc = atoi(val.str());
- sawCRC = TRUE;
- }
- else if (key.getLength() == 1 && *key.str() == slotListID)
- {
- sawSlotlist = true;
- /// @TODO: Need to read in all the slot info... big mess right now.
- char *rawSlotBuf = strdup(val.str());
- char *freeMe = NULL;
- AsciiString rawSlot;
- // Bool slotsOk = true; //flag that lets us know whether or not the slot list is good.
- // DEBUG_LOG(("ParseAsciiStringToGameInfo - Parsing slot list\n"));
- for (int i=0; i<MAX_SLOTS; ++i)
- {
- rawSlot = strtok_r(rawSlotBuf,":",&pos);
- if( rawSlotBuf )
- freeMe = rawSlotBuf;
- rawSlotBuf = NULL;
- switch (*rawSlot.str())
- {
- case 'H':
- {
- // DEBUG_LOG(("ParseAsciiStringToGameInfo - Human player\n"));
- char *slotPos = NULL;
- //Parse out the Name
- AsciiString slotValue(strtok_r((char *)rawSlot.str(),",",&slotPos));
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue name is empty, quitting\n"));
- break;
- }
- UnicodeString name;
- name.set(MultiByteToWideCharSingleLine(slotValue.str() +1).c_str());
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - name is %s\n", slotValue.str()+1));
-
- //Parse out the IP
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue IP address is empty, quitting\n"));
- break;
- }
- UnsignedInt playerIP = 0;
- sscanf(slotValue.str(),"%x", &playerIP);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - IP address is %x\n", playerIP));
-
- //set the state of the slot
- newSlot[i].setState(SLOT_PLAYER, name, playerIP);
- // parse out the port
- slotValue = strtok_r(NULL, ",", &slotPos);
- if (slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue port is empty, quitting\n"));
- break;
- }
- UnsignedInt playerPort = 0;
- sscanf(slotValue.str(), "%d", &playerPort);
- newSlot[i].setPort(playerPort);
- DEBUG_LOG(("ParseAsciiStringToGameInfo - port is %d\n", playerPort));
- //Read if it's accepted or not
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.getLength() != 2)
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue accepted is mis-sized, quitting\n"));
- break;
- }
- const char *svs = slotValue.str();
- if(*svs == 'T') {
- newSlot[i].setAccept();
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player has accepted\n"));
- } else if (*svs == 'F') {
- newSlot[i].unAccept();
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player has not accepted\n"));
- }
- ++svs;
- if(*svs == 'T') {
- newSlot[i].setMapAvailability(TRUE);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player has map\n"));
- } else {
- newSlot[i].setMapAvailability(FALSE);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player does not have map\n"));
- }
- //Read color index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue color is empty, quitting\n"));
- break;
- }
- Int color = atoi(slotValue.str());
- if (color < -1 || color >= TheMultiplayerSettings->getNumColors())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - player color was invalid, quitting\n"));
- break;
- }
- newSlot[i].setColor(color);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player color set to %d\n", color));
- //Read playerTemplate index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue player template is empty, quitting\n"));
- break;
- }
- Int playerTemplate = atoi(slotValue.str());
- if (playerTemplate < PLAYERTEMPLATE_MIN || playerTemplate >= ThePlayerTemplateStore->getPlayerTemplateCount())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - player template value is invalid, quitting\n"));
- break;
- }
- newSlot[i].setPlayerTemplate(playerTemplate);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player template is %d\n", playerTemplate));
- //Read start position index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue start position is empty, quitting\n"));
- break;
- }
- Int startPos = atoi(slotValue.str());
- if (startPos < -1 || startPos >= MAX_SLOTS)
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - player start position is invalid, quitting\n"));
- break;
- }
- newSlot[i].setStartPos(startPos);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player start position is %d\n", startPos));
- //Read team index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue team number is empty, quitting\n"));
- break;
- }
- Int team = atoi(slotValue.str());
- if (team < -1 || team >= MAX_SLOTS/2)
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - team number is invalid, quitting\n"));
- break;
- }
- newSlot[i].setTeamNumber(team);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - team number is %d\n", team));
- // Read the NAT behavior
- slotValue = strtok_r(NULL, ",",&slotPos);
- if (slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - NAT behavior is empty, quitting\n"));
- break;
- }
- FirewallHelperClass::FirewallBehaviorType NATType = (FirewallHelperClass::FirewallBehaviorType)atoi(slotValue.str());
- if ((NATType < FirewallHelperClass::FIREWALL_MIN) ||
- (NATType > FirewallHelperClass::FIREWALL_MAX)) {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - NAT behavior is invalid, quitting\n"));
- break;
- }
- newSlot[i].setNATBehavior(NATType);
- DEBUG_LOG(("ParseAsciiStringToGameInfo - NAT behavior is %X\n", NATType));
- }// case 'H':
- break;
- case 'C':
- {
- DEBUG_LOG(("ParseAsciiStringToGameInfo - AI player\n"));
- char *slotPos = NULL;
- //Parse out the Name
- AsciiString slotValue(strtok_r((char *)rawSlot.str(),",",&slotPos));
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue AI Type is empty, quitting\n"));
- break;
- }
-
- switch(*(slotValue.str() + 1))
- {
- case 'E':
- {
- newSlot[i].setState(SLOT_EASY_AI);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Easy AI\n"));
- }
- break;
- case 'M':
- {
- newSlot[i].setState(SLOT_MED_AI);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Medium AI\n"));
- }
- break;
- case 'H':
- {
- newSlot[i].setState(SLOT_BRUTAL_AI);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Brutal AI\n"));
- }
- break;
- default:
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - Unknown AI, quitting\n"));
- }
- break;
- }//switch(*rawSlot.str()+1)
-
- //Read color index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue color is empty, quitting\n"));
- break;
- }
- Int color = atoi(slotValue.str());
- if (color < -1 || color >= TheMultiplayerSettings->getNumColors())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - player color was invalid, quitting\n"));
- break;
- }
- newSlot[i].setColor(color);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player color set to %d\n", color));
- //Read playerTemplate index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue player template is empty, quitting\n"));
- break;
- }
- Int playerTemplate = atoi(slotValue.str());
- if (playerTemplate < PLAYERTEMPLATE_MIN || playerTemplate >= ThePlayerTemplateStore->getPlayerTemplateCount())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - player template value is invalid, quitting\n"));
- break;
- }
- newSlot[i].setPlayerTemplate(playerTemplate);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - player template is %d\n", playerTemplate));
- //Read start pos
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue start pos is empty, quitting\n"));
- break;
- }
- Int startPos = atoi(slotValue.str());
- Bool isStartPosBad = FALSE;
- if (startPos < -1 || startPos >= MAX_SLOTS)
- {
- isStartPosBad = TRUE;
- }
- for (Int j=0; j<i; ++j)
- {
- if (startPos >= 0 && startPos == newSlot[i].getStartPos())
- {
- isStartPosBad = TRUE; // can't have multiple people using the same start pos
- }
- }
- if (isStartPosBad)
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - start pos is invalid, quitting\n"));
- break;
- }
- newSlot[i].setStartPos(startPos);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - start spot is %d\n", startPos));
- //Read team index
- slotValue = strtok_r(NULL,",",&slotPos);
- if(slotValue.isEmpty())
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - slotValue team number is empty, quitting\n"));
- break;
- }
- Int team = atoi(slotValue.str());
- if (team < -1 || team >= MAX_SLOTS/2)
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - team number is invalid, quitting\n"));
- break;
- }
- newSlot[i].setTeamNumber(team);
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - team number is %d\n", team));
- }//case 'C':
- break;
- case 'O':
- {
- newSlot[i].setState( SLOT_OPEN );
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Slot is open\n"));
- }// case 'O':
- break;
- case 'X':
- {
- newSlot[i].setState( SLOT_CLOSED );
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Slot is closed\n"));
- }// case 'X':
- break;
- default:
- {
- optionsOk = false;
- DEBUG_LOG(("ParseAsciiStringToGameInfo - unrecognized slot entry, quitting\n"));
- }
- break;
- }
- }
- if(freeMe)
- free(freeMe);
- }
- else
- {
- optionsOk = false;
- break;
- }
- }
- if( buf )
- free(buf);
- //DEBUG_LOG(("Options were ok == %d\n", optionsOk));
- if (optionsOk && sawMap && sawMapCRC && sawMapSize && sawSeed && sawSlotlist && sawCRC)
- {
- // We were setting the Global Data directly here, but Instead, I'm now
- // first setting the data in game. We'll set the global data when
- // we start a game.
- if (!game)
- return true;
- //DEBUG_LOG(("ParseAsciiStringToGameInfo - game options all good, setting info\n"));
- for(Int i = 0; i<MAX_SLOTS; i++)
- game->setSlot(i,newSlot[i]);
- game->setMap(mapName);
- game->setMapCRC(mapCRC);
- game->setMapSize(mapSize);
- game->setMapContentsMask(mapContentsMask);
- game->setSeed(seed);
- game->setCRCInterval(crc);
- return true;
- }
- DEBUG_LOG(("ParseAsciiStringToGameInfo - game options messed up\n"));
- return false;
- }
- //----------------------------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------------------------
- //------------------------- SkirmishGameInfo ---------------------------------------------------------------
- // ------------------------------------------------------------------------------------------------
- /** CRC */
- // ------------------------------------------------------------------------------------------------
- void SkirmishGameInfo::crc( Xfer *xfer )
- {
- } // end crc
- // ------------------------------------------------------------------------------------------------
- /** Xfer Method */
- // ------------------------------------------------------------------------------------------------
- void SkirmishGameInfo::xfer( Xfer *xfer )
- {
- const XferVersion currentVersion = 2;
- XferVersion version = currentVersion;
- xfer->xferVersion( &version, currentVersion );
- xfer->xferInt(&m_preorderMask);
- xfer->xferInt(&m_crcInterval);
- xfer->xferBool(&m_inGame);
- xfer->xferBool(&m_inProgress);
- xfer->xferBool(&m_surrendered);
- xfer->xferInt(&m_gameID);
- Int slot = MAX_SLOTS;
- xfer->xferInt(&slot);
- DEBUG_ASSERTCRASH(slot==MAX_SLOTS, ("MAX_SLOTS changed, need to change version. jba."));
- for (slot = 0; slot < MAX_SLOTS; slot++)
- {
- Int state = m_slot[slot]->getState();
- xfer->xferInt(&state);
- UnicodeString name=m_slot[slot]->getName();
- if (version >= 2)
- {
- xfer->xferUnicodeString(&name);
- }
- Bool isAccepted=m_slot[slot]->isAccepted();
- xfer->xferBool(&isAccepted);
- Bool isMuted=m_slot[slot]->isMuted();
- xfer->xferBool(&isMuted);
- m_slot[slot]->mute(isMuted);
- Int color=m_slot[slot]->getColor();
- xfer->xferInt(&color);
- Int startPos=m_slot[slot]->getStartPos();
- xfer->xferInt(&startPos);
- Int playerTemplate=m_slot[slot]->getPlayerTemplate();
- xfer->xferInt(&playerTemplate);
- Int teamNumber=m_slot[slot]->getTeamNumber();
- xfer->xferInt(&teamNumber);
- Int origColor=m_slot[slot]->getOriginalColor();
- xfer->xferInt(&origColor);
- Int origStartPos=m_slot[slot]->getOriginalStartPos();
- xfer->xferInt(&origStartPos);
- Int origPlayerTemplate=m_slot[slot]->getOriginalPlayerTemplate();
- xfer->xferInt(&origPlayerTemplate);
- if( xfer->getXferMode() == XFER_LOAD ) {
- m_slot[slot]->setState((SlotState)state, name);
- if (isAccepted) m_slot[slot]->setAccept();
- m_slot[slot]->setPlayerTemplate(origPlayerTemplate);
- m_slot[slot]->setStartPos(origStartPos);
- m_slot[slot]->setColor(origColor);
- m_slot[slot]->saveOffOriginalInfo();
- m_slot[slot]->setTeamNumber(teamNumber);
- m_slot[slot]->setColor(color);
- m_slot[slot]->setStartPos(startPos);
- m_slot[slot]->setPlayerTemplate(playerTemplate);
- }
- }
- xfer->xferUnsignedInt(&m_localIP);
- xfer->xferMapName(&m_mapName);
- xfer->xferUnsignedInt(&m_mapCRC);
- xfer->xferUnsignedInt(&m_mapSize);
- xfer->xferInt(&m_mapMask);
- xfer->xferInt(&m_seed);
- } // end xfer
- // ------------------------------------------------------------------------------------------------
- /** Load post process */
- // ------------------------------------------------------------------------------------------------
- void SkirmishGameInfo::loadPostProcess( void )
- {
- } // end loadPostProcess
|