mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 11:42:31 +01:00
- 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:
parent
060a9d3fe6
commit
dfedf2259b
@ -233,6 +233,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||
|
||||
//starting skill
|
||||
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__);
|
||||
|
||||
@ -344,25 +345,28 @@ Vec2i Unit::getCellPos() const {
|
||||
}
|
||||
|
||||
if(type->hasCellMap()) {
|
||||
if( type->hasEmptyCellMap() == false ||
|
||||
type->getAllowEmptyCellMap() == true) {
|
||||
|
||||
//find nearest pos to center that is free
|
||||
Vec2i centeredPos= getCenteredPos();
|
||||
float nearestDist= -1.f;
|
||||
Vec2i nearestPos= pos;
|
||||
//find nearest pos to center that is free
|
||||
Vec2i centeredPos= getCenteredPos();
|
||||
float nearestDist= -1.f;
|
||||
Vec2i nearestPos= pos;
|
||||
|
||||
for(int i=0; i<type->getSize(); ++i){
|
||||
for(int j=0; j<type->getSize(); ++j){
|
||||
if(type->getCellMapCell(i, j, modelFacing)){
|
||||
Vec2i currPos= pos + Vec2i(i, j);
|
||||
float dist= currPos.dist(centeredPos);
|
||||
if(nearestDist==-1.f || dist<nearestDist){
|
||||
nearestDist= dist;
|
||||
nearestPos= currPos;
|
||||
for(int i=0; i<type->getSize(); ++i){
|
||||
for(int j=0; j<type->getSize(); ++j){
|
||||
if(type->getCellMapCell(i, j, modelFacing)){
|
||||
Vec2i currPos= pos + Vec2i(i, j);
|
||||
float dist= currPos.dist(centeredPos);
|
||||
if(nearestDist==-1.f || dist<nearestDist){
|
||||
nearestDist= dist;
|
||||
nearestPos= currPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nearestPos;
|
||||
}
|
||||
return nearestPos;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
@ -533,6 +537,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
|
||||
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()) {
|
||||
animProgress= 0;
|
||||
lastAnimProgress= 0;
|
||||
@ -557,7 +563,7 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
|
||||
this->currSkill= currSkill;
|
||||
}
|
||||
|
||||
void Unit::setCurrSkill(SkillClass sc){
|
||||
void Unit::setCurrSkill(SkillClass sc) {
|
||||
if(getType() == NULL) {
|
||||
char szBuf[4096]="";
|
||||
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 y2= computeHeight(pos);
|
||||
|
||||
if(currSkill->getClass()==scMove){
|
||||
if(currSkill->getClass() == scMove) {
|
||||
v.x= lastPos.x + progress * (pos.x-lastPos.x);
|
||||
v.z= lastPos.y + progress * (pos.y-lastPos.y);
|
||||
v.y= y1+progress*(y2-y1);
|
||||
@ -869,13 +875,15 @@ void Unit::create(bool startingUnit){
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::born(){
|
||||
void Unit::born() {
|
||||
if(type == NULL) {
|
||||
char szBuf[4096]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||
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->applyStaticProduction(type);
|
||||
setCurrSkill(scStop);
|
||||
@ -883,19 +891,20 @@ void Unit::born(){
|
||||
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
|
||||
if(isBeingBuilt()){
|
||||
if(isBeingBuilt()) {
|
||||
faction->deApplyStaticConsumption(type);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
faction->deApplyStaticCosts(type);
|
||||
}
|
||||
|
||||
//do the cleaning
|
||||
map->clearUnitCells(this, pos);
|
||||
if(!isBeingBuilt()){
|
||||
if(isBeingBuilt() == false) {
|
||||
faction->removeStore(type);
|
||||
}
|
||||
setCurrSkill(scDie);
|
||||
@ -995,11 +1004,11 @@ bool Unit::update() {
|
||||
//speed modifier
|
||||
float diagonalFactor= 1.f;
|
||||
float heightFactor= 1.f;
|
||||
if(currSkill->getClass()==scMove){
|
||||
if(currSkill->getClass() == scMove) {
|
||||
|
||||
//if moving in diagonal move slower
|
||||
Vec2i dest= pos-lastPos;
|
||||
if(abs(dest.x)+abs(dest.y) == 2){
|
||||
if(abs(dest.x)+abs(dest.y) == 2) {
|
||||
diagonalFactor= 0.71f;
|
||||
}
|
||||
|
||||
@ -1019,7 +1028,7 @@ bool Unit::update() {
|
||||
updateTarget();
|
||||
|
||||
//rotation
|
||||
if(currSkill->getClass()!=scStop){
|
||||
if(currSkill->getClass() != scStop) {
|
||||
const int rotFactor= 2;
|
||||
if(progress<1.f/rotFactor){
|
||||
if(type->getFirstStOfClass(scMove)){
|
||||
@ -1057,7 +1066,7 @@ bool Unit::update() {
|
||||
//checks
|
||||
if(progress>=1.f) {
|
||||
lastRotation= targetRotation;
|
||||
if(currSkill->getClass()!=scDie) {
|
||||
if(currSkill->getClass() != scDie) {
|
||||
progress= 0.f;
|
||||
return_value = true;
|
||||
}
|
||||
@ -1105,7 +1114,7 @@ int Unit::update2(){
|
||||
return progress2;
|
||||
}
|
||||
|
||||
bool Unit::computeEp(){
|
||||
bool Unit::computeEp() {
|
||||
|
||||
if(currSkill == NULL) {
|
||||
char szBuf[4096]="";
|
||||
@ -1114,7 +1123,7 @@ bool Unit::computeEp(){
|
||||
}
|
||||
|
||||
//if not enough ep
|
||||
if(ep-currSkill->getEpCost() < 0){
|
||||
if(ep-currSkill->getEpCost() < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1536,7 +1545,7 @@ CommandResult Unit::undoCommand(Command *command){
|
||||
|
||||
//return building cost if not already building it or dead
|
||||
if(command->getCommandType()->getClass() == ccBuild){
|
||||
if(currSkill->getClass()!=scBuild && currSkill->getClass()!=scDie){
|
||||
if(currSkill->getClass() != scBuild && currSkill->getClass() != scDie) {
|
||||
faction->deApplyCosts(command->getUnitType());
|
||||
}
|
||||
}
|
||||
|
@ -546,9 +546,14 @@ string RepairCommandType::toString() const{
|
||||
}
|
||||
|
||||
//get
|
||||
bool RepairCommandType::isRepairableUnitType(const UnitType *unitType) const{
|
||||
for(int i=0; i<repairableUnits.size(); ++i){
|
||||
if(static_cast<const UnitType*>(repairableUnits[i])==unitType){
|
||||
bool RepairCommandType::isRepairableUnitType(const UnitType *unitType) const {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unitType [%s] repairableUnits.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,unitType->toString().c_str(),repairableUnits.size());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ UnitType::UnitType(){
|
||||
}
|
||||
|
||||
cellMap= NULL;
|
||||
allowEmptyCellMap=false;
|
||||
hpRegeneration= 0;
|
||||
epRegeneration= 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();
|
||||
|
||||
//cellmap
|
||||
allowEmptyCellMap = false;
|
||||
const XmlNode *cellMapNode= parametersNode->getChild("cellmap");
|
||||
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];
|
||||
for(int i=0; i<size; ++i){
|
||||
const XmlNode *rowNode= cellMapNode->getChild("row", i);
|
||||
@ -478,8 +484,26 @@ const RepairCommandType *UnitType::getFirstRepairCommand(const UnitType *repaire
|
||||
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 {
|
||||
assert(cellMap);
|
||||
if(cellMap == NULL) {
|
||||
throw runtime_error("cellMap == NULL");
|
||||
}
|
||||
int tmp;
|
||||
switch (facing) {
|
||||
case CardinalDir::EAST:
|
||||
|
@ -109,6 +109,7 @@ private:
|
||||
|
||||
//cellmap
|
||||
bool *cellMap;
|
||||
bool allowEmptyCellMap;
|
||||
|
||||
//sounds
|
||||
SoundContainer selectionSounds;
|
||||
@ -189,6 +190,8 @@ public:
|
||||
bool hasSkillType(const SkillType *skillType) const;
|
||||
bool hasSkillClass(SkillClass skillClass) const;
|
||||
bool hasCellMap() const {return cellMap!=NULL;}
|
||||
bool getAllowEmptyCellMap() const {return allowEmptyCellMap;}
|
||||
bool hasEmptyCellMap() const;
|
||||
|
||||
//is
|
||||
bool isOfClass(UnitClass uc) const;
|
||||
|
@ -38,10 +38,11 @@ namespace Glest{ namespace Game{
|
||||
// class Cell
|
||||
// =====================================================
|
||||
|
||||
Cell::Cell(){
|
||||
Cell::Cell() {
|
||||
//game data
|
||||
for(int i=0; i<fieldCount; ++i){
|
||||
for(int i = 0; i < fieldCount; ++i) {
|
||||
units[i]= NULL;
|
||||
unitsWithEmptyCellMap[i]=NULL;
|
||||
}
|
||||
height= 0;
|
||||
}
|
||||
@ -326,7 +327,12 @@ bool Map::isFreeCellOrHasUnit(const Vec2i &pos, Field field, const Unit *unit) c
|
||||
return false;
|
||||
}
|
||||
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
|
||||
void Map::putUnitCells(Unit *unit, const Vec2i &pos){
|
||||
void Map::putUnitCells(Unit *unit, const Vec2i &pos) {
|
||||
|
||||
assert(unit!=NULL);
|
||||
const UnitType *ut= unit->getType();
|
||||
|
||||
for(int i=0; i<ut->getSize(); ++i){
|
||||
for(int j=0; j<ut->getSize(); ++j){
|
||||
for(int i = 0; i < ut->getSize(); ++i) {
|
||||
for(int j = 0; j < ut->getSize(); ++j) {
|
||||
Vec2i currPos= pos + Vec2i(i, j);
|
||||
assert(isInside(currPos));
|
||||
if(!ut->hasCellMap() || ut->getCellMapCell(i, j, unit->getModelFacing())){
|
||||
assert(getCell(currPos)->getUnit(unit->getCurrField())==NULL);
|
||||
if( ut->hasCellMap() == false || ut->getCellMapCell(i, j, unit->getModelFacing())) {
|
||||
assert(getCell(currPos)->getUnit(unit->getCurrField()) == NULL);
|
||||
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
|
||||
void Map::clearUnitCells(Unit *unit, const Vec2i &pos){
|
||||
|
||||
void Map::clearUnitCells(Unit *unit, const Vec2i &pos) {
|
||||
assert(unit!=NULL);
|
||||
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){
|
||||
Vec2i currPos= pos + Vec2i(i, j);
|
||||
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);
|
||||
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 ====================
|
||||
|
||||
//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 j=-1; j<=1; ++j){
|
||||
for(int i=-1; i<=1; ++i) {
|
||||
for(int j=-1; j<=1; ++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;
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ class GameSettings;
|
||||
class Cell{
|
||||
private:
|
||||
Unit *units[fieldCount]; //units on this cell
|
||||
Unit *unitsWithEmptyCellMap[fieldCount]; //units with an empty cellmap on this cell
|
||||
float height;
|
||||
|
||||
private:
|
||||
@ -59,9 +60,11 @@ public:
|
||||
|
||||
//get
|
||||
Unit *getUnit(int field) const {return units[field];}
|
||||
Unit *getUnitWithEmptyCellMap(int field) const {return unitsWithEmptyCellMap[field];}
|
||||
float getHeight() const {return height;}
|
||||
|
||||
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;}
|
||||
|
||||
bool isFree(Field field) const;
|
||||
|
@ -472,32 +472,49 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
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();
|
||||
|
||||
if(!builtUnitType->hasSkillClass(scBeBuilt)){
|
||||
if(builtUnitType->hasSkillClass(scBeBuilt) == false) {
|
||||
throw runtime_error("Unit " + builtUnitType->getName() + "has no be_built skill");
|
||||
}
|
||||
|
||||
builtUnit->setCurrSkill(scBeBuilt);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
unit->setCurrSkill(bct->getBuildSkillType());
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
unit->setTarget(builtUnit);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
map->prepareTerrain(builtUnit);
|
||||
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
break;
|
||||
case pfRoutePlanner:
|
||||
world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight());
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("detected unsupported pathfinder type!");
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
break;
|
||||
case pfRoutePlanner:
|
||||
world->getCartographer()->updateMapMetrics(builtUnit->getPos(), builtUnit->getType()->getSight());
|
||||
break;
|
||||
default:
|
||||
throw runtime_error("detected unsupported pathfinder type!");
|
||||
}
|
||||
|
||||
command->setUnit(builtUnit);
|
||||
|
||||
//play start sound
|
||||
if(unit->getFactionIndex()==world->getThisFactionIndex()){
|
||||
if(unit->getFactionIndex() == world->getThisFactionIndex()) {
|
||||
SoundRenderer::getInstance().playFx(
|
||||
bct->getStartSound(),
|
||||
unit->getCurrVector(),
|
||||
@ -511,7 +528,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
unit->cancelCommand();
|
||||
unit->setCurrSkill(scStop);
|
||||
|
||||
if(unit->getFactionIndex()==world->getThisFactionIndex()){
|
||||
if(unit->getFactionIndex() == world->getThisFactionIndex()) {
|
||||
console->addStdMessage("BuildingNoPlace");
|
||||
}
|
||||
|
||||
@ -530,12 +547,19 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
}
|
||||
}
|
||||
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
|
||||
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()) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
unit->setCurrSkill(scStop);
|
||||
@ -547,7 +571,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
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__);
|
||||
|
||||
//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);
|
||||
|
||||
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) {
|
||||
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] 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();
|
||||
|
||||
if(unit->getCurrSkill()->getClass() != scRepair ||
|
||||
(nextToRepaired == false && peerUnitBuilder == NULL)) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Vec2i repairPos = command->getPos();
|
||||
|
||||
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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
startRepairing = true;
|
||||
@ -1109,6 +1137,8 @@ void UnitUpdater::updateRepair(Unit *unit) {
|
||||
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) {
|
||||
case tsMoving:
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsMoving\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
@ -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
|
||||
bool World::placeUnit(const Vec2i &startLoc, int radius, Unit *unit, bool spaciated){
|
||||
bool freeSpace;
|
||||
bool freeSpace=false;
|
||||
int size= unit->getType()->getSize();
|
||||
Field currField= unit->getCurrField();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user