mirror of
https://github.com/glest/glest-source.git
synced 2025-08-20 07:01:21 +02: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:
@@ -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,6 +345,8 @@ 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();
|
||||
@@ -364,6 +367,7 @@ Vec2i Unit::getCellPos() const {
|
||||
}
|
||||
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;
|
||||
@@ -876,6 +882,8 @@ void Unit::born(){
|
||||
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);
|
||||
@@ -884,6 +892,7 @@ void Unit::born(){
|
||||
}
|
||||
|
||||
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()) {
|
||||
@@ -895,7 +904,7 @@ void Unit::kill(){
|
||||
|
||||
//do the cleaning
|
||||
map->clearUnitCells(this, pos);
|
||||
if(!isBeingBuilt()){
|
||||
if(isBeingBuilt() == false) {
|
||||
faction->removeStore(type);
|
||||
}
|
||||
setCurrSkill(scDie);
|
||||
|
@@ -547,8 +547,13 @@ string RepairCommandType::toString() const{
|
||||
|
||||
//get
|
||||
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) {
|
||||
if(static_cast<const UnitType*>(repairableUnits[i])==unitType){
|
||||
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;
|
||||
|
@@ -42,6 +42,7 @@ Cell::Cell(){
|
||||
//game data
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -667,9 +673,18 @@ void Map::putUnitCells(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()) == 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -678,7 +693,6 @@ void Map::putUnitCells(Unit *unit, const Vec2i &pos){
|
||||
|
||||
//removes a unit from cells
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -705,6 +728,9 @@ bool Map::isNextTo(const Vec2i &pos, const Unit *unit) const{
|
||||
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,18 +472,35 @@ 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);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
break;
|
||||
@@ -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();
|
||||
|
||||
|
Reference in New Issue
Block a user