mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 12:12:25 +01:00
- added new calculation method when building units, builder units use best approach to build it instead of top left.
This commit is contained in:
parent
db25b5391e
commit
4bc00cbf73
@ -439,6 +439,28 @@ bool Map::aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) c
|
||||
}
|
||||
}
|
||||
|
||||
//put a units into the cells
|
||||
bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos) {
|
||||
|
||||
assert(ut!=NULL);
|
||||
|
||||
Cell *testCell = getCell(testPos);
|
||||
for(int i=0; i < ut->getSize(); ++i){
|
||||
for(int j = 0; j < ut->getSize(); ++j) {
|
||||
Vec2i currPos = pos + Vec2i(i, j);
|
||||
if(isInside(currPos) == true) {
|
||||
//if(ut->hasCellMap() == false || ut->getCellMapCell(i, j, facing)) {
|
||||
Cell *unitCell = getCell(currPos);
|
||||
|
||||
if(unitCell == testCell) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//put a units into the cells
|
||||
void Map::putUnitCells(Unit *unit, const Vec2i &pos){
|
||||
|
||||
|
@ -214,6 +214,7 @@ public:
|
||||
bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;
|
||||
void putUnitCells(Unit *unit, const Vec2i &pos);
|
||||
void clearUnitCells(Unit *unit, const Vec2i &pos);
|
||||
bool isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,const Vec2i &testPos);
|
||||
|
||||
//misc
|
||||
bool isNextTo(const Vec2i &pos, const Unit *unit) const;
|
||||
|
@ -385,6 +385,30 @@ void UnitUpdater::updateAttackStopped(Unit *unit){
|
||||
|
||||
// ==================== updateBuild ====================
|
||||
|
||||
Vec2i UnitUpdater::findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, const UnitType *ut) {
|
||||
Vec2i pos = originalBuildPos;
|
||||
|
||||
float bestRange = -1;
|
||||
|
||||
Vec2i start = pos - Vec2i(1);
|
||||
Vec2i end = pos + Vec2i(ut->getSize());
|
||||
|
||||
for(int i = start.x; i <= end.x; ++i) {
|
||||
for(int j = start.y; j <= end.y; ++j){
|
||||
Vec2i testPos(i,j);
|
||||
if(map->isInUnitTypeCells(ut, originalBuildPos,testPos) == false) {
|
||||
float distance = unitBuilderPos.dist(testPos);
|
||||
if(bestRange < 0 || bestRange > distance) {
|
||||
bestRange = distance;
|
||||
pos = testPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void UnitUpdater::updateBuild(Unit *unit){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
@ -403,7 +427,12 @@ void UnitUpdater::updateBuild(Unit *unit){
|
||||
TravelState tsValue = tsImpossible;
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
tsValue = pathFinder->findPath(unit, command->getPos()-Vec2i(1));
|
||||
{
|
||||
//Vec2i buildPos = (command->getPos()-Vec2i(1));
|
||||
Vec2i buildPos = findBestBuildApproach(unit->getPos(), command->getPos(), ut);
|
||||
//Vec2i buildPos = (command->getPos() + Vec2i(ut->getSize() / 2));
|
||||
tsValue = pathFinder->findPath(unit, buildPos);
|
||||
}
|
||||
break;
|
||||
case pfRoutePlanner:
|
||||
tsValue = routePlanner->findPathToBuildSite(unit, ut, command->getPos(), command->getFacing());
|
||||
|
@ -118,6 +118,7 @@ private:
|
||||
|
||||
Unit * findPeerUnitBuilder(Unit *unit);
|
||||
void SwapActiveCommand(Unit *unitSrc, Unit *unitDest);
|
||||
Vec2i findBestBuildApproach(Vec2i unitBuilderPos, Vec2i originalBuildPos, const UnitType *ut);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user