//------------------------------------------------------------------------------ //int getNumTiles(); int CvLuaArea::lGetNumTiles(lua_State* L) { CvArea* pkArea = GetInstance(L); const int iResult = pkArea->getNumTiles(); lua_pushinteger(L, iResult); return 1; }
void CvMapGenerator::addGoodies() { PROFILE("CvMapGenerator::addGoodies"); if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "addGoodies")) { if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl()) { return; // Python override } } gDLL->NiTextOut("Adding Goodies..."); if (GC.getEraInfo(GC.getGameINLINE().getStartEra()).isNoGoodies()) { return; } int iNumPlots = GC.getMapINLINE().numPlotsINLINE(); int* piShuffle = shuffle(iNumPlots, GC.getGameINLINE().getMapRand()); for (int iI = 0; iI < GC.getNumImprovementInfos(); iI++) { if (GC.getImprovementInfo((ImprovementTypes)iI).isGoody() && GC.getImprovementInfo((ImprovementTypes)iI).getTilesPerGoody() > 0) { for (int iJ = 0; iJ < iNumPlots; iJ++) { gDLL->callUpdater(); CvPlot *pPlot = GC.getMapINLINE().plotByIndexINLINE(piShuffle[iJ]); FAssertMsg(pPlot, "pPlot is expected not to be NULL"); if (!(pPlot->isWater())) { CvArea *pArea = GC.getMapINLINE().getArea(pPlot->getArea()); FAssertMsg(pArea, "pArea is expected not to be NULL"); if (pArea->getNumImprovements((ImprovementTypes)iI) < ((pArea->getNumTiles() + (GC.getImprovementInfo((ImprovementTypes)iI).getTilesPerGoody() / 2)) / GC.getImprovementInfo((ImprovementTypes) iI).getTilesPerGoody())) { if (canPlaceGoodyAt(((ImprovementTypes)iI), pPlot->getX_INLINE(), pPlot->getY_INLINE())) { pPlot->setImprovementType((ImprovementTypes)iI); } } } } } } SAFE_DELETE_ARRAY(piShuffle); }
void CvMapGenerator::addGoodies() { PROFILE_FUNC(); if (gDLL->getPythonIFace()->pythonAddGoodies() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl()) { return; // Python override } gDLL->NiTextOut("Adding Goodies..."); if (GC.getEraInfo(GC.getGameINLINE().getStartEra()).isNoGoodies()) { return; } int iNumPlots = GC.getMapINLINE().numPlotsINLINE(); std::vector<int> aiShuffle(iNumPlots); GC.getGameINLINE().getMapRand().shuffleSequence(aiShuffle, "addNonUniqueBonusType shuffle"); for (int iI = 0; iI < GC.getNumImprovementInfos(); iI++) { if (GC.getImprovementInfo((ImprovementTypes)iI).isGoody() && GC.getImprovementInfo((ImprovementTypes)iI).getTilesPerGoody() > 0) { for (int iJ = 0; iJ < iNumPlots; iJ++) { gDLL->callUpdater(); CvPlot *pPlot = GC.getMapINLINE().plotByIndexINLINE(aiShuffle[iJ]); FAssertMsg(pPlot, "pPlot is expected not to be NULL"); if (!(pPlot->isWater())) { CvArea *pArea = GC.getMapINLINE().getArea(pPlot->getArea()); FAssertMsg(pArea, "pArea is expected not to be NULL"); if (pArea->getNumImprovements((ImprovementTypes)iI) < ((pArea->getNumTiles() + (GC.getImprovementInfo((ImprovementTypes)iI).getTilesPerGoody() / 2)) / GC.getImprovementInfo((ImprovementTypes) iI).getTilesPerGoody())) { if (canPlaceGoodyAt(((ImprovementTypes)iI), pPlot->getX_INLINE(), pPlot->getY_INLINE())) { pPlot->setImprovementType((ImprovementTypes)iI); } } } } } } }
CvArea* CvMap::findBiggestArea(bool bWater) { int iBestValue = 0; CvArea* pBestArea = NULL; int iLoop; for (CvArea* pLoopArea = firstArea(&iLoop); pLoopArea != NULL; pLoopArea = nextArea(&iLoop)) { if (pLoopArea->isWater() == bWater) { int iValue = pLoopArea->getNumTiles(); if (iValue > iBestValue) { iBestValue = iValue; pBestArea = pLoopArea; } } } return pBestArea; }
void CvMapGenerator::addUniqueBonusType(BonusTypes eBonusType) { int* piAreaTried = new int[GC.getMapINLINE().getNumAreas()]; for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++) { piAreaTried[iI] = FFreeList::INVALID_INDEX; } CvBonusInfo& pBonusInfo = GC.getBonusInfo(eBonusType); int iBonusCount = calculateNumBonusesToAdd(eBonusType); bool bIgnoreLatitude = false; gDLL->getPythonIFace()->pythonIsBonusIgnoreLatitudes(&bIgnoreLatitude); FAssertMsg(pBonusInfo.isOneArea(), "addUniqueBonusType called with non-unique bonus type"); while (true) { int iBestValue = 0; int iLoop = 0; CvArea *pBestArea = NULL; CvArea *pLoopArea = NULL; for(pLoopArea = GC.getMapINLINE().firstArea(&iLoop); pLoopArea != NULL; pLoopArea = GC.getMapINLINE().nextArea(&iLoop)) { bool bTried = false; for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++) { if (pLoopArea->getID() == piAreaTried[iI]) { bTried = true; break; } } if (!bTried) { int iNumUniqueBonusesOnArea = pLoopArea->countNumUniqueBonusTypes() + 1; // number of unique bonuses starting on the area, plus this one int iNumTiles = pLoopArea->getNumTiles(); int iValue = iNumTiles / iNumUniqueBonusesOnArea; if (iValue > iBestValue) { iBestValue = iValue; pBestArea = pLoopArea; } } } if (pBestArea == NULL) { break; // can't place bonus on any area } for (int iI = 0; iI < GC.getMapINLINE().getNumAreas(); iI++) { if (piAreaTried[iI] == FFreeList::INVALID_INDEX) { piAreaTried[iI] = pBestArea->getID(); break; } } // Place the bonuses: std::vector<int> aiShuffle(GC.getMapINLINE().numPlotsINLINE()); GC.getGameINLINE().getMapRand().shuffleSequence(aiShuffle, "addUniqueBonusType shuffle"); for (int iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++) { CvPlot* pPlot = GC.getMapINLINE().plotByIndexINLINE(aiShuffle[iI]); FAssertMsg(pPlot != NULL, "addUniqueBonusType(): pPlot is null"); if (GC.getMapINLINE().getNumBonuses(eBonusType) >= iBonusCount) { break; // We already have enough } if (pBestArea == pPlot->area()) { if (canPlaceBonusAt(eBonusType, pPlot->getX_INLINE(), pPlot->getY_INLINE(), bIgnoreLatitude)) { pPlot->setBonusType(eBonusType); for (int iDX = -(pBonusInfo.getGroupRange()); iDX <= pBonusInfo.getGroupRange(); iDX++) { for (int iDY = -(pBonusInfo.getGroupRange()); iDY <= pBonusInfo.getGroupRange(); iDY++) { if (GC.getMapINLINE().getNumBonuses(eBonusType) < iBonusCount) { CvPlot* pLoopPlot = plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iDX, iDY); if (pLoopPlot != NULL && (pLoopPlot->area() == pBestArea)) { if (canPlaceBonusAt(eBonusType, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE(), bIgnoreLatitude)) { if (GC.getGameINLINE().getMapRandNum(100, "addUniqueBonusType") < pBonusInfo.getGroupRand()) { pLoopPlot->setBonusType(eBonusType); } } } } } } } } } } SAFE_DELETE_ARRAY(piAreaTried); }