本文整理汇总了C++中CvPlot::isWater方法的典型用法代码示例。如果您正苦于以下问题:C++ CvPlot::isWater方法的具体用法?C++ CvPlot::isWater怎么用?C++ CvPlot::isWater使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvPlot
的用法示例。
在下文中一共展示了CvPlot::isWater方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateAreas
void CvMap::calculateAreas()
{
PROFILE_FUNC();
CvPlot* pLoopPlot;
CvArea* pArea;
int iArea;
int iI;
for (iI = 0; iI < numPlotsINLINE(); iI++)
{
pLoopPlot = plotByIndexINLINE(iI);
gDLL->callUpdater();
FAssertMsg(pLoopPlot != NULL, "LoopPlot is not assigned a valid value");
if (pLoopPlot->getArea() == FFreeList::INVALID_INDEX)
{
pArea = addArea();
pArea->init(pArea->getID(), pLoopPlot->isWater());
iArea = pArea->getID();
pLoopPlot->setArea(iArea);
gDLL->getFAStarIFace()->GeneratePath(&GC.getAreaFinder(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE(), -1, -1, pLoopPlot->isWater(), iArea);
}
}
}
示例2: findWater
//"Check plots for wetlands or seaWater. Returns true if found"
bool CvMap::findWater(CvPlot* pPlot, int iRange, bool bFreshWater)
{
PROFILE_FUNC();
for (int iDX = -(iRange); iDX <= iRange; iDX++)
{
for (int iDY = -(iRange); iDY <= iRange; iDY++)
{
CvPlot* pLoopPlot = plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iDX, iDY);
if (pLoopPlot != NULL)
{
if (bFreshWater)
{
if (pLoopPlot->isRiver())
{
return true;
}
}
else
{
if (pLoopPlot->isWater())
{
return true;
}
}
}
}
}
return false;
}
示例3: addLakes
void CvMapGenerator::addLakes()
{
PROFILE_FUNC();
if (gDLL->getPythonIFace()->pythonAddLakes() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl())
{
return; // Python override
}
gDLL->NiTextOut("Adding Lakes...");
CvPlot* pLoopPlot;
int iI;
for (iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
{
gDLL->callUpdater();
pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
FAssertMsg(pLoopPlot != NULL, "LoopPlot is not assigned a valid value");
if (!(pLoopPlot->isWater()))
{
if (!(pLoopPlot->isCoastalLand()))
{
if (!(pLoopPlot->isRiver()))
{
if (GC.getGameINLINE().getMapRandNum(GC.getXMLval(XML_LAKE_PLOT_RAND), "addLakes") == 0)
{
pLoopPlot->setPlotType(PLOT_OCEAN);
}
}
}
}
}
}
示例4: AddTemporaryZones
/// Add in any temporary dominance zones from tactical AI
void CvTacticalAnalysisMap::AddTemporaryZones()
{
CvTemporaryZone* pZone;
CvTacticalAI* pTacticalAI = GET_PLAYER(m_ePlayer).GetTacticalAI();
if(pTacticalAI)
{
pTacticalAI->DropObsoleteZones();
pZone = pTacticalAI->GetFirstTemporaryZone();
while(pZone)
{
// Can't be a city zone (which is just used to boost priority but not establish a new zone)
if(pZone->GetTargetType() != AI_TACTICAL_TARGET_CITY)
{
CvPlot* pPlot = GC.getMap().plot(pZone->GetX(), pZone->GetY());
if(pPlot)
{
CvTacticalDominanceZone newZone;
newZone.SetDominanceZoneID(m_DominanceZones.size());
newZone.SetTerritoryType(TACTICAL_TERRITORY_TEMP_ZONE);
newZone.SetOwner(NO_PLAYER);
newZone.SetAreaID(pPlot->getArea());
newZone.SetWater(pPlot->isWater());
newZone.Extend(pPlot);
newZone.SetNavalInvasion(pZone->IsNavalInvasion());
m_DominanceZones.push_back(newZone);
}
}
pZone = pTacticalAI->GetNextTemporaryZone();
}
}
}
示例5: setPlotTypes
void CvMapGenerator::setPlotTypes(const int* paiPlotTypes)
{
CvPlot* pLoopPlot;
int iNumPlots;
iNumPlots = GC.getMapINLINE().numPlotsINLINE();
for (int iI = 0; iI < iNumPlots; iI++)
{
gDLL->callUpdater();
GC.getMapINLINE().plotByIndexINLINE(iI)->setPlotType(((PlotTypes)(paiPlotTypes[iI])), false, false);
}
GC.getMapINLINE().recalculateAreas();
for (int iI = 0; iI < iNumPlots; iI++)
{
gDLL->callUpdater();
pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
if (pLoopPlot->isWater())
{
if (pLoopPlot->isAdjacentToLand())
{
pLoopPlot->setTerrainType(((TerrainTypes)(GC.getXMLval(XML_SHALLOW_WATER_TERRAIN))), false, false);
}
else
{
pLoopPlot->setTerrainType(((TerrainTypes)(GC.getXMLval(XML_DEEP_WATER_TERRAIN))), false, false);
}
}
}
}
示例6: DetectNearbyEnemy
CvPlot* CvArmyAI::DetectNearbyEnemy(PlayerTypes eEnemy, bool bNaval)
{
UnitHandle pUnit = GetFirstUnit();
while(pUnit)
{
for(int iDirectionLoop = 0; iDirectionLoop < NUM_DIRECTION_TYPES; ++iDirectionLoop)
{
CvPlot* pAdjacentPlot = plotDirection(pUnit->getX(), pUnit->getY(), ((DirectionTypes)iDirectionLoop));
if(pAdjacentPlot != NULL && pAdjacentPlot->isWater()==bNaval && pAdjacentPlot->getOwner() == eEnemy)
{
UnitHandle pOtherUnit = pAdjacentPlot->getBestDefender(eEnemy);
if(pOtherUnit)
{
if(GC.getLogging() && GC.getAILogging())
{
CvString strMsg;
strMsg.Format("Ran into enemy unit during attack (x=%d y=%d). Need to declare war to continue!", pAdjacentPlot->getX(), pAdjacentPlot->getY());
GET_PLAYER(m_eOwner).getAIOperation(m_iOperationID)->LogOperationSpecialMessage(strMsg);
}
return pAdjacentPlot;
}
}
}
pUnit = GetNextUnit();
}
return NULL;
}
示例7: FindBestMerchantTargetPlot
CvPlot* CvPlayerAI::FindBestMerchantTargetPlot(CvUnit* pGreatMerchant, bool bOnlySafePaths)
{
CvAssertMsg(pGreatMerchant, "pGreatMerchant is null");
if(!pGreatMerchant)
{
return NULL;
}
int iBestTurnsToReach = MAX_INT;
CvPlot* pBestTargetPlot = NULL;
int iPathTurns;
UnitHandle pMerchant = UnitHandle(pGreatMerchant);
CvTeam& kTeam = GET_TEAM(getTeam());
// Loop through each city state
for(int iI = 0; iI < MAX_PLAYERS; iI++)
{
CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI);
if(kPlayer.isMinorCiv())
{
CvPlot* pCSPlot = kPlayer.getStartingPlot();
if(pCSPlot)
{
if(pCSPlot->isRevealed(getTeam()))
{
// Is this a minor we are friendly with?
if(GetDiplomacyAI()->GetMinorCivApproach(kPlayer.GetID()) != MINOR_CIV_APPROACH_CONQUEST &&
!kTeam.isAtWar(kPlayer.getTeam()) && GetDiplomacyAI()->GetWarGoal(kPlayer.GetID()) == NO_WAR_GOAL_TYPE)
{
// Search all the plots adjacent to this city (since can't enter the minor city plot itself)
for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++)
{
CvPlot* pAdjacentPlot = plotDirection(pCSPlot->getX(), pCSPlot->getY(), ((DirectionTypes)jJ));
if(pAdjacentPlot != NULL)
{
// Make sure this is still owned by the city state and is revealed to us and isn't a water tile
if(pAdjacentPlot->getOwner() == (PlayerTypes)iI && pAdjacentPlot->isRevealed(getTeam())
&& !pAdjacentPlot->isWater())
{
iPathTurns = TurnsToReachTarget(pMerchant, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/);
if(iPathTurns < iBestTurnsToReach)
{
iBestTurnsToReach = iPathTurns;
pBestTargetPlot = pAdjacentPlot;
}
}
}
}
}
}
}
}
}
return pBestTargetPlot;
}
示例8: addGoodies
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);
}
示例9: addGoodies
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);
}
}
}
}
}
}
}
示例10: canPlaceBonusAt
bool CvMapGenerator::canPlaceBonusAt(BonusTypes eBonus, int iX, int iY, bool bIgnoreLatitude)
{
PROFILE_FUNC();
CvArea* pArea;
CvPlot* pPlot;
CvPlot* pLoopPlot;
int iRange;
int iDX, iDY;
int iI;
pPlot = GC.getMapINLINE().plotINLINE(iX, iY);
pArea = pPlot->area();
if (!(pPlot->canHaveBonus(eBonus, bIgnoreLatitude)))
{
return false;
}
long result = 0;
if (gDLL->getPythonIFace()->pythonCanPlaceBonusAt(pPlot, &result) && !gDLL->getPythonIFace()->pythonUsingDefaultImpl()) // Python override
{
if (result >= 0)
{
return result;
}
else
{
FAssertMsg(false, "canPlaceBonusAt() must return >= 0");
}
}
for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
pLoopPlot = plotDirection(iX, iY, ((DirectionTypes)iI));
if (pLoopPlot != NULL)
{
if ((pLoopPlot->getBonusType() != NO_BONUS) && (pLoopPlot->getBonusType() != eBonus))
{
return false;
}
}
}
CvBonusInfo& pInfo = GC.getBonusInfo(eBonus);
if (pPlot->isWater())
{
if (((GC.getMapINLINE().getNumBonusesOnLand(eBonus) * 100) / (GC.getMapINLINE().getNumBonuses(eBonus) + 1)) < pInfo.getMinLandPercent())
{
return false;
}
}
// Make sure there are none of the same bonus nearby:
iRange = pInfo.getUniqueRange();
for (iDX = -(iRange); iDX <= iRange; iDX++)
{
for (iDY = -(iRange); iDY <= iRange; iDY++)
{
pLoopPlot = plotXY(iX, iY, iDX, iDY);
if (pLoopPlot != NULL)
{
if (pLoopPlot->area() == pArea)
{
if (plotDistance(iX, iY, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()) <= iRange)
{
if (pLoopPlot->getBonusType() == eBonus)
{
return false;
}
}
}
}
}
}
return true;
}
示例11: doRiver
// 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);
//.........这里部分代码省略.........
示例12: addRivers
void CvMapGenerator::addRivers()
{
PROFILE_FUNC();
if (gDLL->getPythonIFace()->pythonAddRivers() && !gDLL->getPythonIFace()->pythonUsingDefaultImpl())
{
return; // Python override
}
gDLL->NiTextOut("Adding Rivers...");
CvPlot* pLoopPlot;
CvPlot* pStartPlot;
int iPass;
int iRiverSourceRange;
int iSeaWaterRange;
int iI;
for (iPass = 0; iPass < 4; iPass++)
{
if (iPass <= 1)
{
iRiverSourceRange = GC.getXMLval(XML_RIVER_SOURCE_MIN_RIVER_RANGE);
}
else
{
iRiverSourceRange = (GC.getXMLval(XML_RIVER_SOURCE_MIN_RIVER_RANGE) / 2);
}
if (iPass <= 1)
{
iSeaWaterRange = GC.getXMLval(XML_RIVER_SOURCE_MIN_SEAWATER_RANGE);
}
else
{
iSeaWaterRange = (GC.getXMLval(XML_RIVER_SOURCE_MIN_SEAWATER_RANGE) / 2);
}
for (iI = 0; iI < GC.getMapINLINE().numPlotsINLINE(); iI++)
{
gDLL->callUpdater();
pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
FAssertMsg(pLoopPlot != NULL, "LoopPlot is not assigned a valid value");
if (!(pLoopPlot->isWater()))
{
if (((iPass == 0) && (pLoopPlot->isHills() || pLoopPlot->isPeak())) ||
((iPass == 1) && !(pLoopPlot->isCoastalLand()) && (GC.getGameINLINE().getMapRandNum(8, "addRivers") == 0)) ||
((iPass == 2) && (pLoopPlot->isHills() || pLoopPlot->isPeak()) && (pLoopPlot->area()->getNumRiverEdges() < ((pLoopPlot->area()->getNumTiles() / GC.getXMLval(XML_PLOTS_PER_RIVER_EDGE)) + 1))) ||
((iPass == 3) && (pLoopPlot->area()->getNumRiverEdges() < ((pLoopPlot->area()->getNumTiles() / GC.getXMLval(XML_PLOTS_PER_RIVER_EDGE)) + 1))))
{
if (!(GC.getMapINLINE().findWater(pLoopPlot, iRiverSourceRange, true)))
{
if (!(GC.getMapINLINE().findWater(pLoopPlot, iSeaWaterRange, false)))
{
pStartPlot = pLoopPlot->getInlandCorner();
if (pStartPlot != NULL)
{
doRiver(pStartPlot);
}
}
}
}
}
}
}
}
示例13: canPlaceBonusAt
bool CvMapGenerator::canPlaceBonusAt(BonusTypes eBonus, int iX, int iY, bool bIgnoreLatitude)
{
PROFILE_FUNC();
CvArea* pArea;
CvPlot* pPlot;
CvPlot* pLoopPlot;
int iRange;
int iDX, iDY;
int iI;
pPlot = GC.getMapINLINE().plotINLINE(iX, iY);
pArea = pPlot->area();
if (!(pPlot->canHaveBonus(eBonus, bIgnoreLatitude)))
{
return false;
}
long result = 0;
CyPlot kPlot = CyPlot(pPlot);
CyArgsList argsList;
argsList.add(gDLL->getPythonIFace()->makePythonObject(&kPlot));
if (gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "canPlaceBonusAt", argsList.makeFunctionArgs(), &result))
{
if (!gDLL->getPythonIFace()->pythonUsingDefaultImpl())
{
if (result >= 0)
{
return result;
}
else
{
FAssertMsg(false, "canPlaceBonusAt() must return >= 0");
}
}
}
for (iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
pLoopPlot = plotDirection(iX, iY, ((DirectionTypes)iI));
if (pLoopPlot != NULL)
{
if ((pLoopPlot->getBonusType() != NO_BONUS) && (pLoopPlot->getBonusType() != eBonus))
{
return false;
}
}
}
CvBonusInfo& pInfo = GC.getBonusInfo(eBonus);
CvBonusClassInfo& pClassInfo = GC.getBonusClassInfo((BonusClassTypes) pInfo.getBonusClassType());
if (pPlot->isWater())
{
if (((GC.getMapINLINE().getNumBonusesOnLand(eBonus) * 100) / (GC.getMapINLINE().getNumBonuses(eBonus) + 1)) < pInfo.getMinLandPercent())
{
return false;
}
}
// Make sure there are no bonuses of the same class (but a different type) nearby:
iRange = pClassInfo.getUniqueRange();
for (iDX = -(iRange); iDX <= iRange; iDX++)
{
for (iDY = -(iRange); iDY <= iRange; iDY++)
{
pLoopPlot = plotXY(iX, iY, iDX, iDY);
if (pLoopPlot != NULL)
{
if (pLoopPlot->area() == pArea)
{
if (plotDistance(iX, iY, pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()) <= iRange)
{
BonusTypes eOtherBonus = pLoopPlot->getBonusType();
if (eOtherBonus != NO_BONUS)
{
if (GC.getBonusInfo(eOtherBonus).getBonusClassType() == pInfo.getBonusClassType())
{
return false;
}
}
}
}
}
}
}
// Make sure there are none of the same bonus nearby:
iRange = pInfo.getUniqueRange();
for (iDX = -(iRange); iDX <= iRange; iDX++)
{
for (iDY = -(iRange); iDY <= iRange; iDY++)
{
//.........这里部分代码省略.........
示例14: GetCenterOfMass
/// Get center of mass of units in army (account for world wrap!)
CvPlot* CvArmyAI::GetCenterOfMass(DomainTypes eDomainRequired)
{
CvPlot* pRtnValue = NULL;
int iTotalX = 0;
int iTotalY = 0;
int iNumUnits = 0;
UnitHandle pUnit;
int iReferenceUnitX = -1;
int iWorldWidth = GC.getMap().getGridWidth();
pUnit = GetFirstUnit();
if(pUnit)
{
iReferenceUnitX = pUnit->getX();
}
while(pUnit)
{
int iUnitX = pUnit->getX();
bool bWorldWrapAdjust = false;
int iDiff = iUnitX - iReferenceUnitX;
if(abs(iDiff) > (iWorldWidth / 2))
{
bWorldWrapAdjust = true;
}
if(bWorldWrapAdjust)
{
iTotalX += iUnitX + iWorldWidth;
}
else
{
iTotalX += iUnitX;
}
iTotalY += pUnit->getY();
iNumUnits++;
pUnit = GetNextUnit();
}
if(iNumUnits > 0)
{
int iAverageX = (iTotalX + (iNumUnits / 2)) / iNumUnits;
if(iAverageX >= iWorldWidth)
{
iAverageX = iAverageX - iWorldWidth;
}
int iAverageY = (iTotalY + (iNumUnits / 2)) / iNumUnits;
pRtnValue = GC.getMap().plot(iAverageX, iAverageY);
}
// Domain check
if (eDomainRequired != NO_DOMAIN && pRtnValue)
{
if (pRtnValue->isWater() && eDomainRequired == DOMAIN_LAND || !pRtnValue->isWater() && eDomainRequired == DOMAIN_SEA)
{
// Find an adjacent plot that works
for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
CvPlot *pLoopPlot = plotDirection(pRtnValue->getX(), pRtnValue->getY(), ((DirectionTypes)iI));
if (pLoopPlot != NULL)
{
if (pLoopPlot->isWater() && eDomainRequired == DOMAIN_SEA || !pLoopPlot->isWater() && eDomainRequired == DOMAIN_LAND)
{
return pLoopPlot;
}
}
}
// Try two plots out if really having problems
for (int iDX = -2; iDX <= 2; iDX++)
{
for (int iDY = -2; iDY <= 2; iDY++)
{
CvPlot *pLoopPlot = plotXYWithRangeCheck(pRtnValue->getX(), pRtnValue->getY(), iDX, iDY, 2);
if (pLoopPlot)
{
if (plotDistance(pRtnValue->getX(), pRtnValue->getY(), pLoopPlot->getX(), pLoopPlot->getY()) == 2)
{
if (pLoopPlot->isWater() && eDomainRequired == DOMAIN_SEA || !pLoopPlot->isWater() && eDomainRequired == DOMAIN_LAND)
{
return pLoopPlot;
}
}
}
}
}
// Give up - just use location of first unit
pUnit = GetFirstUnit();
pRtnValue = pUnit->plot();
}
}
return pRtnValue;
}
示例15: GetCenterOfMass
/// Get center of mass of units in army (account for world wrap!)
CvPlot* CvArmyAI::GetCenterOfMass(DomainTypes eDomainRequired)
{
CvPlot* pRtnValue = NULL;
int iTotalX = 0;
int iTotalY = 0;
int iNumUnits = 0;
UnitHandle pUnit;
int iReferenceUnitX = -1;
int iWorldWidth = GC.getMap().getGridWidth();
pUnit = GetFirstUnit();
if(pUnit)
{
iReferenceUnitX = pUnit->getX();
}
while(pUnit)
{
int iUnitX = pUnit->getX();
bool bWorldWrapAdjust = false;
int iDiff = iUnitX - iReferenceUnitX;
if(abs(iDiff) > (iWorldWidth / 2))
{
bWorldWrapAdjust = true;
}
if(bWorldWrapAdjust)
{
iTotalX += iUnitX + iWorldWidth;
}
else
{
iTotalX += iUnitX;
}
iTotalY += pUnit->getY();
iNumUnits++;
pUnit = GetNextUnit();
}
if(iNumUnits > 0)
{
int iAverageX = (iTotalX + (iNumUnits / 2)) / iNumUnits;
if(iAverageX >= iWorldWidth)
{
iAverageX = iAverageX - iWorldWidth;
}
int iAverageY = (iTotalY + (iNumUnits / 2)) / iNumUnits;
pRtnValue = GC.getMap().plot(iAverageX, iAverageY);
}
// Domain check
if (eDomainRequired != NO_DOMAIN && pRtnValue)
{
if (pRtnValue->isWater() && eDomainRequired == DOMAIN_LAND || !pRtnValue->isWater() && eDomainRequired == DOMAIN_SEA)
{
// Find an adjacent plot that works
for (int iI = 0; iI < NUM_DIRECTION_TYPES; iI++)
{
CvPlot *pLoopPlot = plotDirection(pRtnValue->getX(), pRtnValue->getY(), ((DirectionTypes)iI));
if (pLoopPlot != NULL)
{
if (pLoopPlot->isWater() && eDomainRequired == DOMAIN_SEA || !pLoopPlot->isWater() && eDomainRequired == DOMAIN_LAND)
{
return pLoopPlot;
}
}
}
// Try two plots out if really having problems
#ifdef AUI_HEXSPACE_DX_LOOPS
int iMaxDX, iDX;
CvPlot* pLoopPlot;
for (int iDY = -2; iDY <= 2; iDY++)
{
iMaxDX = 2 - MAX(0, iDY);
for (iDX = -2 - MIN(0, iDY); iDX <= iMaxDX; iDX++) // MIN() and MAX() stuff is to reduce loops (hexspace!)
{
// No need for range check because loops are set up properly
pLoopPlot = plotXY(pRtnValue->getX(), pRtnValue->getY(), iDX, iDY);
if (pLoopPlot)
{
if (hexDistance(iDX, iDY) == 2)
#else
for (int iDX = -2; iDX <= 2; iDX++)
{
for (int iDY = -2; iDY <= 2; iDY++)
{
CvPlot *pLoopPlot = plotXYWithRangeCheck(pRtnValue->getX(), pRtnValue->getY(), iDX, iDY, 2);
if (pLoopPlot)
{
#ifdef AUI_FIX_HEX_DISTANCE_INSTEAD_OF_PLOT_DISTANCE
if (hexDistance(iDX, iDY) == 2)
#else
if (plotDistance(pRtnValue->getX(), pRtnValue->getY(), pLoopPlot->getX(), pLoopPlot->getY()) == 2)
#endif
#endif
{
if (pLoopPlot->isWater() && eDomainRequired == DOMAIN_SEA || !pLoopPlot->isWater() && eDomainRequired == DOMAIN_LAND)
//.........这里部分代码省略.........