fix build-site and store adjacency maps for potential building rotation
fix potential annotated map update problem with morphing to a smaller UnitType
This commit is contained in:
parent
ff61cd9c36
commit
f18061a7ee
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#if _GAE_DEBUG_EDITION_
|
||||
#if DEBUG_RENDERING_ENABLED
|
||||
# include "debug_renderer.h"
|
||||
#endif
|
||||
|
||||
|
@ -177,8 +177,10 @@ void Cartographer::fixupResourceMaps(const ResourceType *rt, const Vec2i &pos) {
|
|||
PatchMap<1>* Cartographer::buildSiteMap(BuildSiteMapKey key) {
|
||||
PF_TRACE();
|
||||
PatchMap<1> *sMap = siteMaps[key] = buildAdjacencyMap(key.buildingType, key.buildingPosition,
|
||||
key.workerField, key.workerSize);
|
||||
// IF_DEBUG_EDITION( debugAddBuildSiteMap(sMap); )
|
||||
key.buildingFacing, key.workerField, key.workerSize);
|
||||
# ifdef DEBUG_RENDERING_ENABLED
|
||||
debugAddBuildSiteMap(sMap);
|
||||
# endif
|
||||
return sMap;
|
||||
}
|
||||
|
||||
|
@ -216,20 +218,21 @@ PatchMap<1>* Cartographer::getSiteMap(BuildSiteMapKey key) {
|
|||
|
||||
}
|
||||
|
||||
PatchMap<1>* Cartographer::getSiteMap(const UnitType *ut, const Vec2i &pos, Unit *worker) {
|
||||
PatchMap<1>* Cartographer::getSiteMap(const UnitType *ut, const Vec2i &pos,
|
||||
CardinalDir facing, Unit *worker) {
|
||||
PF_TRACE();
|
||||
BuildSiteMapKey key(ut, pos, worker->getCurrField(), worker->getType()->getSize());
|
||||
BuildSiteMapKey key(ut, pos, facing, worker->getCurrField(), worker->getType()->getSize());
|
||||
return getSiteMap(key);
|
||||
}
|
||||
|
||||
|
||||
void Cartographer::onStoreDestroyed(Unit *unit) {
|
||||
///@todo fixme
|
||||
// delete storeMaps[unit];
|
||||
// storeMaps.erase(unit);
|
||||
}
|
||||
|
||||
PatchMap<1>* Cartographer::buildAdjacencyMap(const UnitType *uType, const Vec2i &pos, Field f, int size) {
|
||||
PatchMap<1>* Cartographer::buildAdjacencyMap(const UnitType *uType, const Vec2i &pos,
|
||||
CardinalDir facing, Field f, int size) {
|
||||
PF_TRACE();
|
||||
const Vec2i mapPos = pos + (OrdinalOffsets[odNorthWest] * size);
|
||||
const int sx = pos.x;
|
||||
|
@ -246,7 +249,7 @@ PatchMap<1>* Cartographer::buildAdjacencyMap(const UnitType *uType, const Vec2i
|
|||
Util::RectIterator rIter(pos, pos + Vec2i(uType->getSize() - 1));
|
||||
while (rIter.more()) {
|
||||
Vec2i gpos = rIter.next();
|
||||
if (!uType->hasCellMap() || uType->getCellMapCell(gpos.x - sx, gpos.y - sy, CardinalDir::NORTH)) {
|
||||
if (!uType->hasCellMap() || uType->getCellMapCell(gpos.x - sx, gpos.y - sy, facing)) {
|
||||
tmpMap.setInfluence(gpos, 1);
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +272,8 @@ PatchMap<1>* Cartographer::buildAdjacencyMap(const UnitType *uType, const Vec2i
|
|||
return pMap;
|
||||
}
|
||||
|
||||
/*IF_DEBUG_EDITION(
|
||||
#ifdef DEBUG_RENDERING_ENABLED
|
||||
|
||||
void Cartographer::debugAddBuildSiteMap(PatchMap<1> *siteMap) {
|
||||
Rectangle mapBounds = siteMap->getBounds();
|
||||
for (int ly = 0; ly < mapBounds.h; ++ly) {
|
||||
|
@ -277,13 +281,14 @@ PatchMap<1>* Cartographer::buildAdjacencyMap(const UnitType *uType, const Vec2i
|
|||
for (int lx = 0; lx < mapBounds.w; ++lx) {
|
||||
Vec2i pos(mapBounds.x + lx, y);
|
||||
if (siteMap->getInfluence(pos)) {
|
||||
g_debugRenderer.addBuildSiteCell(pos);
|
||||
getDebugRenderer().addBuildSiteCell(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
void Cartographer::tick() {
|
||||
PF_TRACE();
|
||||
if (clusterMap->isDirty()) {
|
||||
|
|
|
@ -59,11 +59,13 @@ struct StoreMapKey {
|
|||
struct BuildSiteMapKey {
|
||||
const UnitType *buildingType;
|
||||
Vec2i buildingPosition;
|
||||
CardinalDir buildingFacing;
|
||||
Field workerField;
|
||||
int workerSize;
|
||||
|
||||
BuildSiteMapKey(const UnitType *type, const Vec2i &pos, Field f, int s)
|
||||
: buildingType(type), buildingPosition(pos), workerField(f), workerSize(s) {}
|
||||
BuildSiteMapKey(const UnitType *type, const Vec2i &pos, CardinalDir facing, Field f, int s)
|
||||
: buildingType(type), buildingPosition(pos), buildingFacing(facing)
|
||||
, workerField(f), workerSize(s) {}
|
||||
|
||||
bool operator<(const BuildSiteMapKey &that) const {
|
||||
return (memcmp(this, &that, sizeof(BuildSiteMapKey)) < 0);
|
||||
|
@ -115,19 +117,20 @@ private:
|
|||
void initResourceMap(ResourceMapKey key, PatchMap<1> *pMap);
|
||||
void fixupResourceMaps(const ResourceType *rt, const Vec2i &pos);
|
||||
|
||||
PatchMap<1>* buildAdjacencyMap(const UnitType *uType, const Vec2i &pos, Field f, int sz);
|
||||
PatchMap<1>* buildAdjacencyMap(const UnitType *uType, const Vec2i &pos) {
|
||||
return buildAdjacencyMap(uType, pos, fLand, 1);
|
||||
}
|
||||
PatchMap<1>* buildAdjacencyMap(const UnitType *uType, const Vec2i &pos, CardinalDir facing, Field f, int sz);
|
||||
|
||||
PatchMap<1>* buildStoreMap(StoreMapKey key) {
|
||||
return (storeMaps[key] = buildAdjacencyMap(key.storeUnit->getType(),
|
||||
key.storeUnit->getPos(), key.workerField, key.workerSize));
|
||||
return (storeMaps[key] =
|
||||
buildAdjacencyMap(key.storeUnit->getType(), key.storeUnit->getPos(),
|
||||
key.storeUnit->getModelFacing(), key.workerField, key.workerSize));
|
||||
}
|
||||
|
||||
// IF_DEBUG_EDITION( void debugAddBuildSiteMap(PatchMap<1>*); )
|
||||
PatchMap<1>* buildSiteMap(BuildSiteMapKey key);
|
||||
|
||||
# ifdef DEBUG_RENDERING_ENABLED
|
||||
void debugAddBuildSiteMap(PatchMap<1>*);
|
||||
# endif
|
||||
|
||||
public:
|
||||
Cartographer(World *world);
|
||||
virtual ~Cartographer();
|
||||
|
@ -153,7 +156,7 @@ public:
|
|||
PatchMap<1>* getStoreMap(const Unit *store, const Unit *worker);
|
||||
|
||||
PatchMap<1>* getSiteMap(BuildSiteMapKey key);
|
||||
PatchMap<1>* getSiteMap(const UnitType *ut, const Vec2i &pos, Unit *worker);
|
||||
PatchMap<1>* getSiteMap(const UnitType *ut, const Vec2i &pos, CardinalDir facing, Unit *worker);
|
||||
|
||||
void adjustGlestimalMap(Field f, TypeMap<float> &iMap, const Vec2i &pos, float range);
|
||||
void buildGlestimalMap(Field f, V2iList &positions);
|
||||
|
|
|
@ -184,10 +184,12 @@ TravelState RoutePlanner::findPathToStore(Unit *unit, const Unit *store) {
|
|||
return findPathToGoal(unit, goal, target);
|
||||
}
|
||||
|
||||
TravelState RoutePlanner::findPathToBuildSite(Unit *unit, const UnitType *buildingType, const Vec2i &buildingPos) {
|
||||
TravelState RoutePlanner::findPathToBuildSite(Unit *unit, const UnitType *bType,
|
||||
const Vec2i &bPos, CardinalDir bFacing) {
|
||||
PF_TRACE();
|
||||
PMap1Goal goal(world->getCartographer()->getSiteMap(buildingType, buildingPos, unit));
|
||||
return findPathToGoal(unit, goal, buildingPos + Vec2i(buildingType->getSize() / 2));
|
||||
PatchMap<1> *pMap = world->getCartographer()->getSiteMap(bType, bPos, bFacing, unit);
|
||||
PMap1Goal goal(pMap);
|
||||
return findPathToGoal(unit, goal, bPos + Vec2i(bType->getSize() / 2));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ public:
|
|||
|
||||
TravelState findPathToStore(Unit *unit, const Unit *store);
|
||||
|
||||
TravelState findPathToBuildSite(Unit *unit, const UnitType *buildingType, const Vec2i &buildingPos);
|
||||
TravelState findPathToBuildSite(Unit *unit, const UnitType *bType, const Vec2i &bPos, CardinalDir bFacing);
|
||||
|
||||
bool isLegalMove(Unit *unit, const Vec2i &pos) const;
|
||||
|
||||
|
|
|
@ -131,12 +131,12 @@ DebugRenderer::DebugRenderer() {
|
|||
showFrustum =
|
||||
captureFrustum =
|
||||
gridTextures =
|
||||
buildSiteMaps =
|
||||
influenceMap =
|
||||
false;
|
||||
|
||||
AAStarTextures =
|
||||
HAAStarOverlay =
|
||||
false;
|
||||
|
||||
buildSiteMaps =
|
||||
true;
|
||||
}
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ void UnitUpdater::updateBuild(Unit *unit){
|
|||
//if not building
|
||||
const UnitType *ut= command->getUnitType();
|
||||
|
||||
switch (routePlanner->findPathToBuildSite(unit, ut, command->getPos())) {
|
||||
switch (routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing())) {
|
||||
case PathFinder::tsOnTheWay:
|
||||
unit->setCurrSkill(bct->getMoveSkillType());
|
||||
break;
|
||||
|
@ -383,8 +383,7 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
|||
Resource *r= map->getSurfaceCell(Map::toSurfCoords(command->getPos()))->getResource();
|
||||
if(r!=NULL && hct->canHarvest(r->getType())){
|
||||
//if can harvest dest. pos
|
||||
if(/*unit->getPos().dist(command->getPos())<harvestDistance &&*/
|
||||
map->isResourceNear(unit->getPos(), unit->getType()->getSize(), r->getType(), targetPos)) {
|
||||
if (map->isResourceNear(unit->getPos(), unit->getType()->getSize(), r->getType(), targetPos)) {
|
||||
//if it finds resources it starts harvesting
|
||||
unit->setCurrSkill(hct->getHarvestSkillType());
|
||||
unit->setTargetPos(targetPos);
|
||||
|
@ -635,6 +634,7 @@ void UnitUpdater::updateMorph(Unit *unit){
|
|||
unit->update2();
|
||||
if(unit->getProgress2()>mct->getProduced()->getProductionTime()){
|
||||
|
||||
int oldSize = unit->getType()->getSize();
|
||||
bool needMapUpdate = unit->getType()->isMobile() != mct->getMorphUnit()->isMobile();
|
||||
|
||||
//finish the command
|
||||
|
@ -644,7 +644,8 @@ void UnitUpdater::updateMorph(Unit *unit){
|
|||
gui->onSelectionChanged();
|
||||
}
|
||||
if (needMapUpdate) {
|
||||
world->getCartographer()->updateMapMetrics(unit->getPos(), unit->getType()->getSize());
|
||||
int size = std::max(oldSize, unit->getType()->getSize());
|
||||
world->getCartographer()->updateMapMetrics(unit->getPos(), size);
|
||||
}
|
||||
scriptManager->onUnitCreated(unit);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ private:
|
|||
|
||||
private:
|
||||
static const int maxResSearchRadius= 10;
|
||||
static const int harvestDistance= 5;
|
||||
//static const int harvestDistance= 5;
|
||||
static const int ultraResourceFactor= 3;
|
||||
static const int megaResourceFactor= 4;
|
||||
|
||||
|
|
Loading…
Reference in New Issue