* fix for build command (problems with some cellmaps)

* fix for repair command (problems if top-left cell of repairee is blocked)
This commit is contained in:
James McCulloch 2010-07-14 06:54:43 +00:00
parent 6e26641799
commit 5f16b486d7
3 changed files with 28 additions and 3 deletions

View File

@ -339,6 +339,22 @@ bool Map::isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamInde
return true;
}
bool Map::canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing) {
if (ut->hasCellMap()) {
for (int y=0; y < ut->getSize(); ++y) {
for (int x=0; x < ut->getSize(); ++x) {
if (ut->getCellMapCell(x, y, facing)) {
if (!isFreeCell(pos + Vec2i(x, y), field)) {
return false;
}
}
}
}
return true;
} else {
return isFreeCells(pos, ut->getSize(), field);
}
}
// ==================== unit placement ====================

View File

@ -206,6 +206,8 @@ public:
bool isFreeCellsOrHasUnit(const Vec2i &pos, int size, Field field, const Unit *unit) const;
bool isAproxFreeCells(const Vec2i &pos, int size, Field field, int teamIndex) const;
bool canOccupy(const Vec2i &pos, Field field, const UnitType *ut, CardinalDir facing);
//unit placement
bool aproxCanMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;
bool canMove(const Unit *unit, const Vec2i &pos1, const Vec2i &pos2) const;

View File

@ -294,8 +294,9 @@ void UnitUpdater::updateBuild(Unit *unit){
case PathFinder::tsArrived:
//if arrived destination
assert(command->getUnitType()!=NULL);
if(map->isFreeCells(command->getPos(), ut->getSize(), fLand)){
assert(ut);
if (map->canOccupy(command->getPos(), ut->getField(), ut, command->getFacing())) {
//if(map->isFreeCells(command->getPos(), ut->getSize(), fLand)){
const UnitType *builtUnitType= command->getUnitType();
CardinalDir facing = command->getFacing();
Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing);
@ -510,7 +511,13 @@ void UnitUpdater::updateRepair(Unit *unit){
unit->setCurrSkill(rct->getRepairSkillType());
}
else{
switch(routePlanner->findPath(unit, command->getPos())){
TravelState ts;
if (repaired && !repaired->getType()->isMobile()) {
ts = routePlanner->findPathToBuildSite(unit, repaired->getType(), repaired->getPos(), repaired->getModelFacing());
} else {
ts = routePlanner->findPath(unit, command->getPos());
}
switch(ts) {
case PathFinder::tsOnTheWay:
unit->setCurrSkill(rct->getMoveSkillType());
break;