void CvMapGenerator::eraseRivers() { for (int i = 0; i < GC.getMapINLINE().numPlotsINLINE(); i++) { CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(i); if (pPlot->isNOfRiver()) { pPlot->setNOfRiver(false, NO_CARDINALDIRECTION); } if (pPlot->isWOfRiver()) { pPlot->setWOfRiver(false, NO_CARDINALDIRECTION); } } }
void CvReplayInfo::createInfo() { CvGame& game = GC.getGame(); const PlayerTypes eActivePlayer = game.getActivePlayer(); m_strMapScriptName = CvPreGame::mapScriptName(); m_eWorldSize = CvPreGame::worldSize(); m_eClimate = CvPreGame::climate(); m_eSeaLevel = CvPreGame::seaLevel(); m_eEra = CvPreGame::era(); m_eGameSpeed = game.getGameSpeedType(); m_listGameOptions.clear(); for(int i = 0; i < NUM_GAMEOPTION_TYPES; i++) { GameOptionTypes eOption = (GameOptionTypes)i; if(game.isOption(eOption)) { m_listGameOptions.push_back(eOption); } } m_listVictoryTypes.clear(); for(int i = 0; i < GC.getNumVictoryInfos(); i++) { VictoryTypes eVictory = (VictoryTypes)i; if(game.isVictoryValid(eVictory)) { m_listVictoryTypes.push_back(eVictory); } } m_eVictoryType = NO_VICTORY; m_iNormalizedScore = 0; if(NO_PLAYER != eActivePlayer) { CvPlayer& player = GET_PLAYER(eActivePlayer); if(game.getWinner() == player.getTeam()) { m_eVictoryType = game.getVictory(); } m_iNormalizedScore = player.GetScore(true, player.getTeam() == game.getWinner()); } //m_eGameType = CvPreGame::getGameType(); m_iInitialTurn = game.getStartTurn(); m_iStartYear = game.getStartYear(); m_iFinalTurn = game.getGameTurn(); CvGameTextMgr::setYearStr(m_strFinalDate, m_iFinalTurn, false, game.getCalendar(), game.getStartYear(), game.getGameSpeedType()); m_eCalendar = game.getCalendar(); m_dataSetMap.clear(); m_listPlayerDataSets.clear(); m_listPlayerInfo.clear(); m_listPlots.clear(); std::map<int, int> mapPlayers; mapPlayers[-1] = -1; //account for NO_PLAYER. m_iActivePlayer = -1; int iPlayerIndex = 0; for(int iPlayer = 0; iPlayer < MAX_CIV_PLAYERS; iPlayer++) { CvPlayer& player = GET_PLAYER((PlayerTypes)iPlayer); if(player.isEverAlive()) { //Ensure that final turn is stored. player.GatherPerTurnReplayStats(m_iFinalTurn); mapPlayers[iPlayer] = iPlayerIndex; if(iPlayer == game.getActivePlayer()) { m_iActivePlayer = iPlayerIndex; } ++iPlayerIndex; PlayerInfo playerInfo; playerInfo.m_eLeader = player.getLeaderType(); playerInfo.m_eCivilization = player.getCivilizationType(); playerInfo.m_eDifficulty = player.getHandicapType(); playerInfo.m_strCustomLeaderName = player.getName(); playerInfo.m_strCustomCivilizationName = player.getCivilizationDescription(); playerInfo.m_strCustomCivilizationShortName = player.getCivilizationShortDescription(); playerInfo.m_strCustomCivilizationAdjective = player.getCivilizationAdjective(); playerInfo.m_ePlayerColor = player.getPlayerColor(); TurnDataSets dataSet(m_dataSetMap.size()); unsigned int uiNumDataSets = player.getNumReplayDataSets(); for(unsigned int uiPlayerDataSet = 0; uiPlayerDataSet < uiNumDataSets; ++uiPlayerDataSet) { // First, Locate the index of the dataset std::string playerDataSetName = player.getReplayDataSetName(uiPlayerDataSet); unsigned int uiDataSet = 0; bool bFound = false; for(uiDataSet = 0; uiDataSet < m_dataSetMap.size(); ++uiDataSet) { const std::string& dataSetName = m_dataSetMap[uiDataSet]; if(dataSetName == playerDataSetName) { bFound = true; break; } } // Add a new index if one doesn't exist. if(!bFound) { m_dataSetMap.push_back(playerDataSetName); dataSet.push_back(TurnData()); uiDataSet = m_dataSetMap.size() - 1; } CvPlayer::TurnData playerData = player.getReplayDataHistory(uiPlayerDataSet); TurnData turnData; for(CvPlayer::TurnData::iterator it = playerData.begin(); it != playerData.end(); ++it) { turnData[(*it).first - m_iInitialTurn] = (*it).second; } dataSet[uiDataSet] = turnData; } m_listPlayerDataSets.push_back(dataSet); m_listPlayerInfo.push_back(playerInfo); } } m_listReplayMessages.clear(); const uint nMessages = game.getNumReplayMessages(); m_listReplayMessages.reserve(nMessages); for(uint i = 0; i < nMessages; ++i) { const CvReplayMessage* pMessage = game.getReplayMessage(i); if(pMessage) { CvReplayMessage modifiedMessage = (*pMessage); modifiedMessage.setPlayer((PlayerTypes)mapPlayers[modifiedMessage.getPlayer()]); m_listReplayMessages.push_back(modifiedMessage); } } CvMap& kMap = GC.getMap(); m_iMapWidth = kMap.getGridWidth(); m_iMapHeight = kMap.getGridHeight(); int numPlots = kMap.numPlots(); m_listPlots.clear(); m_listPlots.reserve(numPlots); for(int i = 0; i < numPlots; i++) { PlotState plotState; CvPlot* pkPlot = kMap.plotByIndexUnchecked(i); plotState.m_ePlotType = pkPlot->getPlotType(); plotState.m_eTerrain = pkPlot->getTerrainType(); plotState.m_eFeature = pkPlot->getFeatureType(); plotState.m_bNEOfRiver = pkPlot->isNEOfRiver(); plotState.m_bWOfRiver = pkPlot->isWOfRiver(); plotState.m_bNWOfRiver = pkPlot->isNWOfRiver(); PlotStatePerTurn plotStatePerTurn; plotStatePerTurn[m_iFinalTurn] = plotState; m_listPlots.push_back(plotStatePerTurn); } }
// pStartPlot = the plot at whose SE corner the river is starting // void CvMapGenerator::doRiver(CvPlot *pStartPlot, CardinalDirectionTypes eLastCardinalDirection, CardinalDirectionTypes eOriginalCardinalDirection, int iThisRiverID) { if (iThisRiverID == -1) { iThisRiverID = GC.getMapINLINE().getNextRiverID(); GC.getMapINLINE().incrementNextRiverID(); } int iOtherRiverID = pStartPlot->getRiverID(); if (iOtherRiverID != -1 && iOtherRiverID != iThisRiverID) { return; // Another river already exists here; can't branch off of an existing river! } CvPlot *pRiverPlot = NULL; CvPlot *pAdjacentPlot = NULL; CardinalDirectionTypes eBestCardinalDirection = NO_CARDINALDIRECTION; if (eLastCardinalDirection==CARDINALDIRECTION_NORTH) { pRiverPlot = pStartPlot; if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if ((pAdjacentPlot == NULL) || pRiverPlot->isWOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setWOfRiver(true, eLastCardinalDirection); pRiverPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_NORTH); } else if (eLastCardinalDirection==CARDINALDIRECTION_EAST) { pRiverPlot = plotCardinalDirection(pStartPlot->getX_INLINE(), pStartPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if ((pAdjacentPlot == NULL) || pRiverPlot->isNOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setNOfRiver(true, eLastCardinalDirection); } else if (eLastCardinalDirection==CARDINALDIRECTION_SOUTH) { pRiverPlot = plotCardinalDirection(pStartPlot->getX_INLINE(), pStartPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_EAST); if ((pAdjacentPlot == NULL) || pRiverPlot->isWOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setWOfRiver(true, eLastCardinalDirection); } else if (eLastCardinalDirection==CARDINALDIRECTION_WEST) { pRiverPlot = pStartPlot; if (pRiverPlot == NULL) { return; } pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_SOUTH); if ((pAdjacentPlot == NULL) || pRiverPlot->isNOfRiver() || pRiverPlot->isWater() || pAdjacentPlot->isWater()) { return; } pStartPlot->setRiverID(iThisRiverID); pRiverPlot->setNOfRiver(true, eLastCardinalDirection); pRiverPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), CARDINALDIRECTION_WEST); } else { //FAssertMsg(false, "Illegal direction type"); // River is starting here, set the direction in the next step pRiverPlot = pStartPlot; long result = 0; if (gDLL->getPythonIFace()->pythonGetRiverStartCardinalDirection(pRiverPlot, &result) && !gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override { if (result >= 0) { eBestCardinalDirection = ((CardinalDirectionTypes)result); } else { FAssertMsg(false, "python pythonGetRiverStartCardinalDirection() must return >= 0"); } } } if (pRiverPlot == NULL) { return; // The river has flowed off the edge of the map. All is well. } else if (pRiverPlot->hasCoastAtSECorner()) { return; // The river has flowed into the ocean. All is well. } if (eBestCardinalDirection == NO_CARDINALDIRECTION) { int iBestValue = MAX_INT; for (int iI = 0; iI < NUM_CARDINALDIRECTION_TYPES; iI++) { if (getOppositeCardinalDirection((CardinalDirectionTypes)iI) != eOriginalCardinalDirection) { if (getOppositeCardinalDirection((CardinalDirectionTypes)iI) != eLastCardinalDirection) { CvPlot* pAdjacentPlot; pAdjacentPlot = plotCardinalDirection(pRiverPlot->getX_INLINE(), pRiverPlot->getY_INLINE(), ((CardinalDirectionTypes)iI)); if (pAdjacentPlot != NULL) { int iValue = getRiverValueAtPlot(pAdjacentPlot); if (iValue < iBestValue) { iBestValue = iValue; eBestCardinalDirection = (CardinalDirectionTypes)iI; } } } } } } if (eBestCardinalDirection != NO_CARDINALDIRECTION) { if (eOriginalCardinalDirection == NO_CARDINALDIRECTION) { eOriginalCardinalDirection = eBestCardinalDirection; } doRiver(pRiverPlot, eBestCardinalDirection, eOriginalCardinalDirection, iThisRiverID); } }