- numerous bugfixes to building an d repairing units.

- added new unit cell property called allowEmpty to allow units to build other units with cellmaps that have all 0's (since you can produce these types of units anyways)
This commit is contained in:
Mark Vejvoda 2010-10-30 08:54:00 +00:00
parent 060a9d3fe6
commit dfedf2259b
8 changed files with 167 additions and 67 deletions

View File

@ -233,6 +233,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
//starting skill //starting skill
this->currSkill = getType()->getFirstStOfClass(scStop); this->currSkill = getType()->getFirstStOfClass(scStop);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit ID = %d [%s], this->currSkill = %s\n",__FILE__,__FUNCTION__,__LINE__,this->getId(),this->getFullName().c_str(), (this->currSkill == NULL ? "" : this->currSkill->toString().c_str()));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -344,25 +345,28 @@ Vec2i Unit::getCellPos() const {
} }
if(type->hasCellMap()) { if(type->hasCellMap()) {
if( type->hasEmptyCellMap() == false ||
type->getAllowEmptyCellMap() == true) {
//find nearest pos to center that is free //find nearest pos to center that is free
Vec2i centeredPos= getCenteredPos(); Vec2i centeredPos= getCenteredPos();
float nearestDist= -1.f; float nearestDist= -1.f;
Vec2i nearestPos= pos; Vec2i nearestPos= pos;
for(int i=0; i<type->getSize(); ++i){ for(int i=0; i<type->getSize(); ++i){
for(int j=0; j<type->getSize(); ++j){ for(int j=0; j<type->getSize(); ++j){
if(type->getCellMapCell(i, j, modelFacing)){ if(type->getCellMapCell(i, j, modelFacing)){
Vec2i currPos= pos + Vec2i(i, j); Vec2i currPos= pos + Vec2i(i, j);
float dist= currPos.dist(centeredPos); float dist= currPos.dist(centeredPos);
if(nearestDist==-1.f || dist<nearestDist){ if(nearestDist==-1.f || dist<nearestDist){
nearestDist= dist; nearestDist= dist;
nearestPos= currPos; nearestPos= currPos;
}
} }
} }
} }
return nearestPos;
} }
return nearestPos;
} }
return pos; return pos;
} }
@ -533,6 +537,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit ID = %d [%s], this->currSkill = %s\n currSkill = %s\n",__FILE__,__FUNCTION__,__LINE__,this->getId(), this->getFullName().c_str(), this->currSkill->toString().c_str(),currSkill->toString().c_str());
if(currSkill->getClass() != this->currSkill->getClass()) { if(currSkill->getClass() != this->currSkill->getClass()) {
animProgress= 0; animProgress= 0;
lastAnimProgress= 0; lastAnimProgress= 0;
@ -557,7 +563,7 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
this->currSkill= currSkill; this->currSkill= currSkill;
} }
void Unit::setCurrSkill(SkillClass sc){ void Unit::setCurrSkill(SkillClass sc) {
if(getType() == NULL) { if(getType() == NULL) {
char szBuf[4096]=""; char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: getType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str()); sprintf(szBuf,"In [%s::%s Line: %d] ERROR: getType() == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
@ -654,7 +660,7 @@ Vec3f Unit::getCurrVectorFlat() const{
float y1= computeHeight(lastPos); float y1= computeHeight(lastPos);
float y2= computeHeight(pos); float y2= computeHeight(pos);
if(currSkill->getClass()==scMove){ if(currSkill->getClass() == scMove) {
v.x= lastPos.x + progress * (pos.x-lastPos.x); v.x= lastPos.x + progress * (pos.x-lastPos.x);
v.z= lastPos.y + progress * (pos.y-lastPos.y); v.z= lastPos.y + progress * (pos.y-lastPos.y);
v.y= y1+progress*(y2-y1); v.y= y1+progress*(y2-y1);
@ -869,13 +875,15 @@ void Unit::create(bool startingUnit){
} }
} }
void Unit::born(){ void Unit::born() {
if(type == NULL) { if(type == NULL) {
char szBuf[4096]=""; char szBuf[4096]="";
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str()); sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit ID = %d [%s], this->currSkill = %s\n",__FILE__,__FUNCTION__,__LINE__,this->getId(),this->getFullName().c_str(), (this->currSkill == NULL ? "" : this->currSkill->toString().c_str()));
faction->addStore(type); faction->addStore(type);
faction->applyStaticProduction(type); faction->applyStaticProduction(type);
setCurrSkill(scStop); setCurrSkill(scStop);
@ -883,19 +891,20 @@ void Unit::born(){
hp= type->getMaxHp(); hp= type->getMaxHp();
} }
void Unit::kill(){ void Unit::kill() {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit ID = %d [%s], this->currSkill = %s\n",__FILE__,__FUNCTION__,__LINE__,this->getId(),this->getFullName().c_str(), (this->currSkill == NULL ? "" : this->currSkill->toString().c_str()));
//no longer needs static resources //no longer needs static resources
if(isBeingBuilt()){ if(isBeingBuilt()) {
faction->deApplyStaticConsumption(type); faction->deApplyStaticConsumption(type);
} }
else{ else {
faction->deApplyStaticCosts(type); faction->deApplyStaticCosts(type);
} }
//do the cleaning //do the cleaning
map->clearUnitCells(this, pos); map->clearUnitCells(this, pos);
if(!isBeingBuilt()){ if(isBeingBuilt() == false) {
faction->removeStore(type); faction->removeStore(type);
} }
setCurrSkill(scDie); setCurrSkill(scDie);
@ -995,11 +1004,11 @@ bool Unit::update() {
//speed modifier //speed modifier
float diagonalFactor= 1.f; float diagonalFactor= 1.f;
float heightFactor= 1.f; float heightFactor= 1.f;
if(currSkill->getClass()==scMove){ if(currSkill->getClass() == scMove) {
//if moving in diagonal move slower //if moving in diagonal move slower
Vec2i dest= pos-lastPos; Vec2i dest= pos-lastPos;
if(abs(dest.x)+abs(dest.y) == 2){ if(abs(dest.x)+abs(dest.y) == 2) {
diagonalFactor= 0.71f; diagonalFactor= 0.71f;
} }
@ -1019,7 +1028,7 @@ bool Unit::update() {
updateTarget(); updateTarget();
//rotation //rotation
if(currSkill->getClass()!=scStop){ if(currSkill->getClass() != scStop) {
const int rotFactor= 2; const int rotFactor= 2;
if(progress<1.f/rotFactor){ if(progress<1.f/rotFactor){
if(type->getFirstStOfClass(scMove)){ if(type->getFirstStOfClass(scMove)){
@ -1057,7 +1066,7 @@ bool Unit::update() {
//checks //checks
if(progress>=1.f) { if(progress>=1.f) {
lastRotation= targetRotation; lastRotation= targetRotation;
if(currSkill->getClass()!=scDie) { if(currSkill->getClass() != scDie) {
progress= 0.f; progress= 0.f;
return_value = true; return_value = true;
} }
@ -1105,7 +1114,7 @@ int Unit::update2(){
return progress2; return progress2;
} }
bool Unit::computeEp(){ bool Unit::computeEp() {
if(currSkill == NULL) { if(currSkill == NULL) {
char szBuf[4096]=""; char szBuf[4096]="";
@ -1114,7 +1123,7 @@ bool Unit::computeEp(){
} }
//if not enough ep //if not enough ep
if(ep-currSkill->getEpCost() < 0){ if(ep-currSkill->getEpCost() < 0) {
return true; return true;
} }
@ -1536,7 +1545,7 @@ CommandResult Unit::undoCommand(Command *command){
//return building cost if not already building it or dead //return building cost if not already building it or dead
if(command->getCommandType()->getClass() == ccBuild){ if(command->getCommandType()->getClass() == ccBuild){
if(currSkill->getClass()!=scBuild && currSkill->getClass()!=scDie){ if(currSkill->getClass() != scBuild && currSkill->getClass() != scDie) {
faction->deApplyCosts(command->getUnitType()); faction->deApplyCosts(command->getUnitType());
} }
} }

View File

@ -546,9 +546,14 @@ string RepairCommandType::toString() const{
} }
//get //get
bool RepairCommandType::isRepairableUnitType(const UnitType *unitType) const{ bool RepairCommandType::isRepairableUnitType(const UnitType *unitType) const {
for(int i=0; i<repairableUnits.size(); ++i){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitType [%s] repairableUnits.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,unitType->toString().c_str(),repairableUnits.size());
if(static_cast<const UnitType*>(repairableUnits[i])==unitType){
for(int i = 0; i < repairableUnits.size(); ++i) {
const UnitType *curUnitType = static_cast<const UnitType*>(repairableUnits[i]);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] curUnitType [%s] i = %d\n",__FILE__,__FUNCTION__,__LINE__,curUnitType->toString().c_str(),i);
if(curUnitType == unitType) {
return true; return true;
} }
} }

View File

@ -78,6 +78,7 @@ UnitType::UnitType(){
} }
cellMap= NULL; cellMap= NULL;
allowEmptyCellMap=false;
hpRegeneration= 0; hpRegeneration= 0;
epRegeneration= 0; epRegeneration= 0;
maxUnitCount= 0; maxUnitCount= 0;
@ -163,9 +164,14 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue(); multiSelect= parametersNode->getChild("multi-selection")->getAttribute("value")->getBoolValue();
//cellmap //cellmap
allowEmptyCellMap = false;
const XmlNode *cellMapNode= parametersNode->getChild("cellmap"); const XmlNode *cellMapNode= parametersNode->getChild("cellmap");
bool hasCellMap= cellMapNode->getAttribute("value")->getBoolValue(); bool hasCellMap= cellMapNode->getAttribute("value")->getBoolValue();
if(hasCellMap){ if(hasCellMap == true) {
if(cellMapNode->getAttribute("allowEmpty",false) != NULL) {
allowEmptyCellMap = cellMapNode->getAttribute("allowEmpty")->getBoolValue();
}
cellMap= new bool[size*size]; cellMap= new bool[size*size];
for(int i=0; i<size; ++i){ for(int i=0; i<size; ++i){
const XmlNode *rowNode= cellMapNode->getChild("row", i); const XmlNode *rowNode= cellMapNode->getChild("row", i);
@ -478,8 +484,26 @@ const RepairCommandType *UnitType::getFirstRepairCommand(const UnitType *repaire
return NULL; return NULL;
} }
bool UnitType::hasEmptyCellMap() const {
bool result = (size > 0);
for(int i = 0; i < size; ++i) {
for(int j = 0; j < size; ++j){
if(cellMap[i*size+j] == true) {
result = false;
break;
}
}
}
return result;
}
bool UnitType::getCellMapCell(int x, int y, CardinalDir facing) const { bool UnitType::getCellMapCell(int x, int y, CardinalDir facing) const {
assert(cellMap); assert(cellMap);
if(cellMap == NULL) {
throw runtime_error("cellMap == NULL");
}
int tmp; int tmp;
switch (facing) { switch (facing) {
case CardinalDir::EAST: case CardinalDir::EAST:

View File

@ -109,6 +109,7 @@ private:
//cellmap //cellmap
bool *cellMap; bool *cellMap;
bool allowEmptyCellMap;
//sounds //sounds
SoundContainer selectionSounds; SoundContainer selectionSounds;
@ -189,6 +190,8 @@ public:
bool hasSkillType(const SkillType *skillType) const; bool hasSkillType(const SkillType *skillType) const;
bool hasSkillClass(SkillClass skillClass) const; bool hasSkillClass(SkillClass skillClass) const;
bool hasCellMap() const {return cellMap!=NULL;} bool hasCellMap() const {return cellMap!=NULL;}
bool getAllowEmptyCellMap() const {return allowEmptyCellMap;}
bool hasEmptyCellMap() const;
//is //is
bool isOfClass(UnitClass uc) const; bool isOfClass(UnitClass uc) const;

View File

@ -38,10 +38,11 @@ namespace Glest{ namespace Game{
// class Cell // class Cell
// ===================================================== // =====================================================
Cell::Cell(){ Cell::Cell() {
//game data //game data
for(int i=0; i<fieldCount; ++i){ for(int i = 0; i < fieldCount; ++i) {
units[i]= NULL; units[i]= NULL;
unitsWithEmptyCellMap[i]=NULL;
} }
height= 0; height= 0;
} }
@ -326,7 +327,12 @@ bool Map::isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) c
return false; return false;
} }
else if(field == fLand) { else if(field == fLand) {
return sc->isFree(); if(sc->isFree() == false) {
return false;
}
else if(c->getUnit(field) != NULL) {
return false;
}
} }
} }
} }
@ -658,18 +664,27 @@ bool Map::isInUnitTypeCells(const UnitType *ut, const Vec2i &pos,
} }
//put a units into the cells //put a units into the cells
void Map::putUnitCells(Unit *unit, const Vec2i &pos){ void Map::putUnitCells(Unit *unit, const Vec2i &pos) {
assert(unit!=NULL); assert(unit!=NULL);
const UnitType *ut= unit->getType(); const UnitType *ut= unit->getType();
for(int i=0; i<ut->getSize(); ++i){ for(int i = 0; i < ut->getSize(); ++i) {
for(int j=0; j<ut->getSize(); ++j){ for(int j = 0; j < ut->getSize(); ++j) {
Vec2i currPos= pos + Vec2i(i, j); Vec2i currPos= pos + Vec2i(i, j);
assert(isInside(currPos)); assert(isInside(currPos));
if(!ut->hasCellMap() || ut->getCellMapCell(i, j, unit->getModelFacing())){ if( ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
assert(getCell(currPos)->getUnit(unit->getCurrField())==NULL); assert(getCell(currPos)->getUnit(unit->getCurrField()) == NULL);
getCell(currPos)->setUnit(unit->getCurrField(), unit); getCell(currPos)->setUnit(unit->getCurrField(), unit);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
}
else if(ut->hasCellMap() == true &&
ut->hasEmptyCellMap() == true &&
ut->getAllowEmptyCellMap() == true) {
getCell(currPos)->setUnitWithEmptyCellMap(unit->getCurrField(), unit);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
} }
} }
} }
@ -677,8 +692,7 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos){
} }
//removes a unit from cells //removes a unit from cells
void Map::clearUnitCells(Unit *unit, const Vec2i &pos){ void Map::clearUnitCells(Unit *unit, const Vec2i &pos) {
assert(unit!=NULL); assert(unit!=NULL);
const UnitType *ut= unit->getType(); const UnitType *ut= unit->getType();
@ -686,9 +700,18 @@ void Map::clearUnitCells(Unit *unit, const Vec2i &pos){
for(int j=0; j<ut->getSize(); ++j){ for(int j=0; j<ut->getSize(); ++j){
Vec2i currPos= pos + Vec2i(i, j); Vec2i currPos= pos + Vec2i(i, j);
assert(isInside(currPos)); assert(isInside(currPos));
if(!ut->hasCellMap() || ut->getCellMapCell(i, j, unit->getModelFacing())){ if(ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
assert(getCell(currPos)->getUnit(unit->getCurrField())==unit); assert(getCell(currPos)->getUnit(unit->getCurrField())==unit);
getCell(currPos)->setUnit(unit->getCurrField(), NULL); getCell(currPos)->setUnit(unit->getCurrField(), NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
}
else if(ut->hasCellMap() == true &&
ut->hasEmptyCellMap() == true &&
ut->getAllowEmptyCellMap() == true) {
getCell(currPos)->setUnitWithEmptyCellMap(unit->getCurrField(), NULL);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currPos = %s unit = %s\n",__FILE__,__FUNCTION__,__LINE__,currPos.getString().c_str(),unit->toString().c_str());
} }
} }
} }
@ -697,12 +720,15 @@ void Map::clearUnitCells(Unit *unit, const Vec2i &pos){
// ==================== misc ==================== // ==================== misc ====================
//return if unit is next to pos //return if unit is next to pos
bool Map::isNextTo(const Vec2i &pos, const Unit *unit) const{ bool Map::isNextTo(const Vec2i &pos, const Unit *unit) const {
for(int i=-1; i<=1; ++i){ for(int i=-1; i<=1; ++i) {
for(int j=-1; j<=1; ++j){ for(int j=-1; j<=1; ++j) {
if(isInside(pos.x+i, pos.y+j)) { if(isInside(pos.x+i, pos.y+j)) {
if(getCell(pos.x+i, pos.y+j)->getUnit(fLand)==unit){ if(getCell(pos.x+i, pos.y+j)->getUnit(fLand) == unit) {
return true;
}
else if(getCell(pos.x+i, pos.y+j)->getUnitWithEmptyCellMap(fLand) == unit) {
return true; return true;
} }
} }

View File

@ -48,6 +48,7 @@ class GameSettings;
class Cell{ class Cell{
private: private:
Unit *units[fieldCount]; //units on this cell Unit *units[fieldCount]; //units on this cell
Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell
float height; float height;
private: private:
@ -59,9 +60,11 @@ public:
//get //get
Unit *getUnit(int field) const {return units[field];} Unit *getUnit(int field) const {return units[field];}
Unit *getUnitWithEmptyCellMap(int field) const {return unitsWithEmptyCellMap[field];}
float getHeight() const {return height;} float getHeight() const {return height;}
void setUnit(int field, Unit *unit) {units[field]= unit;} void setUnit(int field, Unit *unit) {units[field]= unit;}
void setUnitWithEmptyCellMap(int field, Unit *unit) {unitsWithEmptyCellMap[field]= unit;}
void setHeight(float height) {this->height= height;} void setHeight(float height) {this->height= height;}
bool isFree(Field field) const; bool isFree(Field field) const;

View File

@ -472,32 +472,49 @@ void UnitUpdater::updateBuild(Unit *unit) {
throw runtime_error("detected unsupported pathfinder type!"); throw runtime_error("detected unsupported pathfinder type!");
} }
Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), newpath, command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Vec2i buildPos = command->getPos();
Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), newpath, buildPos, builtUnitType, unit->getFaction(), world->getMap(), facing);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
builtUnit->create(); builtUnit->create();
if(!builtUnitType->hasSkillClass(scBeBuilt)){ if(builtUnitType->hasSkillClass(scBeBuilt) == false) {
throw runtime_error("Unit " + builtUnitType->getName() + "has no be_built skill"); throw runtime_error("Unit " + builtUnitType->getName() + "has no be_built skill");
} }
builtUnit->setCurrSkill(scBeBuilt); builtUnit->setCurrSkill(scBeBuilt);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
unit->setCurrSkill(bct->getBuildSkillType()); unit->setCurrSkill(bct->getBuildSkillType());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
unit->setTarget(builtUnit); unit->setTarget(builtUnit);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
map->prepareTerrain(builtUnit); map->prepareTerrain(builtUnit);
switch(this->game->getGameSettings()->getPathFinderType()) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
case pfBasic:
break; switch(this->game->getGameSettings()->getPathFinderType()) {
case pfRoutePlanner: case pfBasic:
world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight()); break;
break; case pfRoutePlanner:
default: world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight());
throw runtime_error("detected unsupported pathfinder type!"); break;
} default:
throw runtime_error("detected unsupported pathfinder type!");
}
command->setUnit(builtUnit); command->setUnit(builtUnit);
//play start sound //play start sound
if(unit->getFactionIndex()==world->getThisFactionIndex()){ if(unit->getFactionIndex() == world->getThisFactionIndex()) {
SoundRenderer::getInstance().playFx( SoundRenderer::getInstance().playFx(
bct->getStartSound(), bct->getStartSound(),
unit->getCurrVector(), unit->getCurrVector(),
@ -511,7 +528,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
unit->cancelCommand(); unit->cancelCommand();
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
if(unit->getFactionIndex()==world->getThisFactionIndex()){ if(unit->getFactionIndex() == world->getThisFactionIndex()) {
console->addStdMessage("BuildingNoPlace"); console->addStdMessage("BuildingNoPlace");
} }
@ -530,12 +547,19 @@ void UnitUpdater::updateBuild(Unit *unit) {
} }
} }
else { else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived:\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived unit = %s\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
//if building //if building
Unit *builtUnit = map->getCell(unit->getTargetPos())->getUnit(fLand); Unit *builtUnit = map->getCell(unit->getTargetPos())->getUnit(fLand);
if(builtUnit == NULL) {
builtUnit = map->getCell(unit->getTargetPos())->getUnitWithEmptyCellMap(fLand);
}
//if u is killed while building then u==NULL; if(builtUnit != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builtUnit = %s\n",__FILE__,__FUNCTION__,__LINE__,builtUnit->toString().c_str());
}
//if unit is killed while building then u==NULL;
if(builtUnit != NULL && builtUnit != command->getUnit()) { if(builtUnit != NULL && builtUnit != command->getUnit()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
@ -547,7 +571,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
} }
else if(builtUnit->repair()) { else if(builtUnit == NULL || builtUnit->repair()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//building finished //building finished
@ -982,7 +1006,10 @@ void UnitUpdater::updateRepair(Unit *unit) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] rct = %p\n",__FILE__,__FUNCTION__,__LINE__,rct); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] rct = %p\n",__FILE__,__FUNCTION__,__LINE__,rct);
Unit *repaired = map->getCell(command->getPos())->getUnit(fLand); Unit *repaired = map->getCell(command->getPos())->getUnitWithEmptyCellMap(fLand);
if(repaired == NULL) {
repaired = map->getCell(command->getPos())->getUnit(fLand);
}
if(repaired != NULL) { if(repaired != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit to repair [%s] - %d\n",__FILE__,__FUNCTION__,__LINE__,repaired->getFullName().c_str(),repaired->getId()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit to repair [%s] - %d\n",__FILE__,__FUNCTION__,__LINE__,repaired->getFullName().c_str(),repaired->getId());
@ -1054,17 +1081,18 @@ void UnitUpdater::updateRepair(Unit *unit) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit to repair[%s]\n",__FILE__,__FUNCTION__,__LINE__,repaired->getFullName().c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit to repair[%s]\n",__FILE__,__FUNCTION__,__LINE__,repaired->getFullName().c_str());
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] repaired = %p, nextToRepaired = %d\n",__FILE__,__FUNCTION__,__LINE__,repaired,nextToRepaired); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] repaired = %p, nextToRepaired = %d, unit->getCurrSkill()->getClass() = %d\n",__FILE__,__FUNCTION__,__LINE__,repaired,nextToRepaired,unit->getCurrSkill()->getClass());
UnitPathInterface *path= unit->getPath(); UnitPathInterface *path= unit->getPath();
if(unit->getCurrSkill()->getClass() != scRepair || if(unit->getCurrSkill()->getClass() != scRepair ||
(nextToRepaired == false && peerUnitBuilder == NULL)) { (nextToRepaired == false && peerUnitBuilder == NULL)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
Vec2i repairPos = command->getPos(); Vec2i repairPos = command->getPos();
bool startRepairing = (repaired != NULL && rct->isRepairableUnitType(repaired->getType()) && repaired->isDamaged()); bool startRepairing = (repaired != NULL && rct->isRepairableUnitType(repaired->getType()) && repaired->isDamaged());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] repairPos = %s, startRepairing = %d\n",__FILE__,__FUNCTION__,__LINE__,repairPos.getString().c_str(),startRepairing);
if(startRepairing == false && peerUnitBuilder != NULL) { if(startRepairing == false && peerUnitBuilder != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
startRepairing = true; startRepairing = true;
@ -1109,6 +1137,8 @@ void UnitUpdater::updateRepair(Unit *unit) {
throw runtime_error("detected unsupported pathfinder type!"); throw runtime_error("detected unsupported pathfinder type!");
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ts = %d\n",__FILE__,__FUNCTION__,__LINE__,ts);
switch(ts) { switch(ts) {
case tsMoving: case tsMoving:
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsMoving\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsMoving\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -482,7 +482,7 @@ const UnitType* World::findUnitTypeById(const FactionType* factionType, int id){
//looks for a place for a unit around a start lociacion, returns true if succeded //looks for a place for a unit around a start lociacion, returns true if succeded
bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated){ bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated){
bool freeSpace; bool freeSpace=false;
int size= unit->getType()->getSize(); int size= unit->getType()->getSize();
Field currField= unit->getCurrField(); Field currField= unit->getCurrField();