/* Copyright (C) 2001-2004 Stephane Magnenat & Luc-Olivier de Charrière for any question or comment contact us at or 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "MapGenerationDescriptor.h" #include "Marshaling.h" #include "Utilities.h" #include MapGenerationDescriptor::MapGenerationDescriptor() { wDec=7; hDec=7; terrainType=GRASS; methode=eUNIFORM; waterRatio=50; sandRatio=50; grassRatio=50; desertRatio=50; wheatRatio=50; woodRatio=50; stoneRatio=50; algaeRatio=50; riverDiameter=50; craterDensity=50; extraIslands=0; smooth=4; fruitRatio=4; logRepeatAreaTimes=0; oldIslandSize=50; oldBeach=1; for (int i=0; i=32) good=false; if (hDec>=32) good=false; if (terrainType>GRASS) good=false; return (good); } void MapGenerationDescriptor::save(GAGCore::OutputStream *stream) { stream->writeEnterSection("MapGenerationDescriptor"); stream->write("MgdB", 4, "signatureStart"); stream->write(getData(), DATA_SIZE, "data"); stream->write("MgdE", 4, "signatureEnd"); stream->writeLeaveSection(); } bool MapGenerationDescriptor::load(GAGCore::InputStream *stream, Sint32 versionMinor) { stream->readEnterSection("MapGenerationDescriptor"); char signature[4]; stream->read(signature, 4, "signatureStart"); if (memcmp(signature, "MgdB", 4) != 0) { stream->readLeaveSection(); return false; } stream->read(getData(), DATA_SIZE, "data"); setData(data, DATA_SIZE); stream->read(signature, 4, "signatureEnd"); stream->readLeaveSection(); if (memcmp(signature, "MgdE", 4) != 0) return false; return true; } Uint32 MapGenerationDescriptor::checkSum() { Uint32 cs=0; cs^=wDec+(hDec<<16); cs^=(Sint32)terrainType; cs=(cs<<31)|(cs>>1); cs^=(Sint32)methode; cs=(cs<<31)|(cs>>1); cs ^= waterRatio; cs=(cs<<31)|(cs>>1); cs ^= sandRatio; cs=(cs<<31)|(cs>>1); cs ^= grassRatio; cs=(cs<<31)|(cs>>1); cs ^= desertRatio; cs=(cs<<31)|(cs>>1); cs ^= wheatRatio; cs=(cs<<31)|(cs>>1); cs ^= fruitRatio; cs=(cs<<31)|(cs>>1); cs ^= woodRatio; cs=(cs<<31)|(cs>>1); cs ^= algaeRatio; cs=(cs<<31)|(cs>>1); cs ^= stoneRatio; cs=(cs<<31)|(cs>>1); cs ^= riverDiameter; cs=(cs<<31)|(cs>>1); cs ^= craterDensity; cs=(cs<<31)|(cs>>1); cs ^= extraIslands; cs=(cs<<31)|(cs>>1); cs ^= smooth; cs=(cs<<31)|(cs>>1); cs ^= oldIslandSize; cs=(cs<<31)|(cs>>1); cs ^= oldBeach; cs=(cs<<31)|(cs>>1); cs ^= logRepeatAreaTimes; for (unsigned i=0; i>1); cs^=nbWorkers; cs^=nbTeams<<5; cs=(cs<<31)|(cs>>1); cs^=randa%randb; cs^=randb%randc; cs^=randc%randa; return cs; } void MapGenerationDescriptor::saveSyncronization(void) { randa=getSyncRandSeedA(); randb=getSyncRandSeedB(); randc=getSyncRandSeedC(); } void MapGenerationDescriptor::loadSyncronization(void) { setSyncRandSeedA(randa); setSyncRandSeedB(randb); setSyncRandSeedC(randc); } void MapGenerationDescriptor::synchronizeNow(void) { if (randa|randb|randc) loadSyncronization(); else saveSyncronization(); }