|
@@ -701,12 +701,12 @@ void makePossibleUpgrades(const CArmedInstance *obj)
|
|
|
|
|
|
void VCAI::makeTurn()
|
|
void VCAI::makeTurn()
|
|
{
|
|
{
|
|
|
|
+ logGlobal->infoStream() << boost::format("Player %d starting turn") % static_cast<int>(playerID.getNum());
|
|
|
|
+
|
|
MAKING_TURN;
|
|
MAKING_TURN;
|
|
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
|
boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
|
|
setThreadName("VCAI::makeTurn");
|
|
setThreadName("VCAI::makeTurn");
|
|
|
|
|
|
- logGlobal->infoStream() << boost::format("Player %d starting turn") % static_cast<int>(playerID.getNum());
|
|
|
|
-
|
|
|
|
switch(cb->getDate(Date::DAY_OF_WEEK))
|
|
switch(cb->getDate(Date::DAY_OF_WEEK))
|
|
{
|
|
{
|
|
case 1:
|
|
case 1:
|
|
@@ -2779,18 +2779,20 @@ BattleState AIStatus::getBattle()
|
|
}
|
|
}
|
|
|
|
|
|
void AIStatus::addQuery(QueryID ID, std::string description)
|
|
void AIStatus::addQuery(QueryID ID, std::string description)
|
|
-{
|
|
|
|
- boost::unique_lock<boost::mutex> lock(mx);
|
|
|
|
|
|
+{
|
|
if(ID == QueryID(-1))
|
|
if(ID == QueryID(-1))
|
|
{
|
|
{
|
|
logAi->debugStream() << boost::format("The \"query\" has an id %d, it'll be ignored as non-query. Description: %s") % ID % description;
|
|
logAi->debugStream() << boost::format("The \"query\" has an id %d, it'll be ignored as non-query. Description: %s") % ID % description;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- assert(!vstd::contains(remainingQueries, ID));
|
|
|
|
assert(ID.getNum() >= 0);
|
|
assert(ID.getNum() >= 0);
|
|
|
|
+ boost::unique_lock<boost::mutex> lock(mx);
|
|
|
|
+
|
|
|
|
+ assert(!vstd::contains(remainingQueries, ID));
|
|
|
|
|
|
remainingQueries[ID] = description;
|
|
remainingQueries[ID] = description;
|
|
|
|
+
|
|
cv.notify_all();
|
|
cv.notify_all();
|
|
logAi->debugStream() << boost::format("Adding query %d - %s. Total queries count: %d") % ID % description % remainingQueries.size();
|
|
logAi->debugStream() << boost::format("Adding query %d - %s. Total queries count: %d") % ID % description % remainingQueries.size();
|
|
}
|
|
}
|
|
@@ -2802,6 +2804,7 @@ void AIStatus::removeQuery(QueryID ID)
|
|
|
|
|
|
std::string description = remainingQueries[ID];
|
|
std::string description = remainingQueries[ID];
|
|
remainingQueries.erase(ID);
|
|
remainingQueries.erase(ID);
|
|
|
|
+
|
|
cv.notify_all();
|
|
cv.notify_all();
|
|
logAi->debugStream() << boost::format("Removing query %d - %s. Total queries count: %d") % ID % description % remainingQueries.size();
|
|
logAi->debugStream() << boost::format("Removing query %d - %s. Total queries count: %d") % ID % description % remainingQueries.size();
|
|
}
|
|
}
|
|
@@ -2912,7 +2915,7 @@ SectorMap::SectorMap(HeroPtr h)
|
|
makeParentBFS(h->visitablePos());
|
|
makeParentBFS(h->visitablePos());
|
|
}
|
|
}
|
|
|
|
|
|
-bool markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
|
|
|
|
|
|
+bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
|
|
{
|
|
{
|
|
if(t->blocked && !t->visitable)
|
|
if(t->blocked && !t->visitable)
|
|
{
|
|
{
|
|
@@ -2923,13 +2926,15 @@ bool markIfBlocked(ui8 &sec, crint3 pos, const TerrainTile *t)
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-bool markIfBlocked(ui8 &sec, crint3 pos)
|
|
|
|
|
|
+bool SectorMap::markIfBlocked(ui8 &sec, crint3 pos)
|
|
{
|
|
{
|
|
- return markIfBlocked(sec, pos, cb->getTile(pos));
|
|
|
|
|
|
+ return markIfBlocked(sec, pos, getTile(pos));
|
|
}
|
|
}
|
|
|
|
|
|
void SectorMap::update()
|
|
void SectorMap::update()
|
|
{
|
|
{
|
|
|
|
+ visibleTiles = cb->getAllVisibleTiles();
|
|
|
|
+
|
|
clear();
|
|
clear();
|
|
int curSector = 3; //0 is invisible, 1 is not explored
|
|
int curSector = 3; //0 is invisible, 1 is not explored
|
|
|
|
|
|
@@ -2955,7 +2960,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num, CCallback * cbp)
|
|
{
|
|
{
|
|
Sector &s = infoOnSectors[num];
|
|
Sector &s = infoOnSectors[num];
|
|
s.id = num;
|
|
s.id = num;
|
|
- s.water = cbp->getTile(pos)->isWater();
|
|
|
|
|
|
+ s.water = getTile(pos)->isWater();
|
|
|
|
|
|
std::queue<int3> toVisit;
|
|
std::queue<int3> toVisit;
|
|
toVisit.push(pos);
|
|
toVisit.push(pos);
|
|
@@ -2966,7 +2971,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num, CCallback * cbp)
|
|
ui8 &sec = retreiveTile(curPos);
|
|
ui8 &sec = retreiveTile(curPos);
|
|
if(sec == NOT_CHECKED)
|
|
if(sec == NOT_CHECKED)
|
|
{
|
|
{
|
|
- const TerrainTile *t = cbp->getTile(curPos);
|
|
|
|
|
|
+ const TerrainTile *t = getTile(curPos);
|
|
if(!markIfBlocked(sec, curPos, t))
|
|
if(!markIfBlocked(sec, curPos, t))
|
|
{
|
|
{
|
|
if(t->isWater() == s.water) //sector is only-water or only-land
|
|
if(t->isWater() == s.water) //sector is only-water or only-land
|
|
@@ -2980,7 +2985,7 @@ void SectorMap::exploreNewSector(crint3 pos, int num, CCallback * cbp)
|
|
toVisit.push(neighPos);
|
|
toVisit.push(neighPos);
|
|
//parent[neighPos] = curPos;
|
|
//parent[neighPos] = curPos;
|
|
}
|
|
}
|
|
- const TerrainTile *nt = cbp->getTile(neighPos, false);
|
|
|
|
|
|
+ const TerrainTile *nt = getTile(neighPos);
|
|
if(nt && nt->isWater() != s.water && canBeEmbarkmentPoint(nt, s.water))
|
|
if(nt && nt->isWater() != s.water && canBeEmbarkmentPoint(nt, s.water))
|
|
{
|
|
{
|
|
s.embarkmentPoints.push_back(neighPos);
|
|
s.embarkmentPoints.push_back(neighPos);
|
|
@@ -3221,7 +3226,7 @@ For ship construction etc, another function (goal?) is needed
|
|
//embark on ship -> look for an EP with a boat
|
|
//embark on ship -> look for an EP with a boat
|
|
auto firstEP = boost::find_if(src->embarkmentPoints, [=](crint3 pos) -> bool
|
|
auto firstEP = boost::find_if(src->embarkmentPoints, [=](crint3 pos) -> bool
|
|
{
|
|
{
|
|
- const TerrainTile *t = cb->getTile(pos);
|
|
|
|
|
|
+ const TerrainTile *t = getTile(pos);
|
|
return t && t->visitableObjects.size() == 1 && t->topVisitableId() == Obj::BOAT
|
|
return t && t->visitableObjects.size() == 1 && t->topVisitableId() == Obj::BOAT
|
|
&& retreiveTile(pos) == sectorToReach->id;
|
|
&& retreiveTile(pos) == sectorToReach->id;
|
|
});
|
|
});
|
|
@@ -3311,7 +3316,7 @@ For ship construction etc, another function (goal?) is needed
|
|
{
|
|
{
|
|
//make sure no hero block the way
|
|
//make sure no hero block the way
|
|
auto pos = ai->knownSubterraneanGates[gate]->visitablePos();
|
|
auto pos = ai->knownSubterraneanGates[gate]->visitablePos();
|
|
- const TerrainTile *t = cb->getTile(pos);
|
|
|
|
|
|
+ const TerrainTile *t = getTile(pos);
|
|
return t && t->visitableObjects.size() == 1 && t->topVisitableId() == Obj::SUBTERRANEAN_GATE
|
|
return t && t->visitableObjects.size() == 1 && t->topVisitableId() == Obj::SUBTERRANEAN_GATE
|
|
&& retreiveTile(pos) == sectorToReach->id;
|
|
&& retreiveTile(pos) == sectorToReach->id;
|
|
});
|
|
});
|
|
@@ -3412,3 +3417,9 @@ unsigned char & SectorMap::retreiveTile(crint3 pos)
|
|
return retreiveTileN(sector, pos);
|
|
return retreiveTileN(sector, pos);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+TerrainTile* SectorMap::getTile(crint3 pos) const
|
|
|
|
+{
|
|
|
|
+ //out of bounds access should be handled by boost::multi_array
|
|
|
|
+ //still we cached this array to avoid any checks
|
|
|
|
+ return visibleTiles->operator[](pos.x)[pos.y][pos.z];
|
|
|
|
+}
|