- first attempt at allowing multiple units to build at the same time
This commit is contained in:
parent
4ef61fc85e
commit
2ea8b69e22
|
@ -41,7 +41,57 @@ void Commander::init(World *world){
|
|||
this->world= world;
|
||||
}
|
||||
|
||||
CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue,Unit *targetUnit) const {
|
||||
CommandResult Commander::tryGiveCommand(const Selection *selection, const CommandType *commandType,
|
||||
const Vec2i &pos, const UnitType* unitType,
|
||||
CardinalDir facing, bool tryQueue,Unit *targetUnit) const {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(!selection->isEmpty() && commandType != NULL) {
|
||||
Vec2i refPos;
|
||||
CommandResultContainer results;
|
||||
|
||||
refPos= computeRefPos(selection);
|
||||
|
||||
bool unitSignalledToBuild = false;
|
||||
//give orders to all selected units
|
||||
for(int i=0; i<selection->getCount(); ++i) {
|
||||
const Unit *unit = selection->getUnit(i);
|
||||
int unitId= unit->getId();
|
||||
Vec2i currPos= computeDestPos(refPos, unit->getPos(), pos);
|
||||
|
||||
Vec2i usePos = currPos;
|
||||
const CommandType *useCommandtype = commandType;
|
||||
if(dynamic_cast<const BuildCommandType *>(commandType) != NULL) {
|
||||
usePos = pos;
|
||||
if(unitSignalledToBuild == false) {
|
||||
unitSignalledToBuild = true;
|
||||
}
|
||||
else {
|
||||
useCommandtype = unit->getType()->getFirstRepairCommand(unitType);
|
||||
tryQueue = true;
|
||||
}
|
||||
}
|
||||
|
||||
NetworkCommand networkCommand(this->world,nctGiveCommand, unitId,
|
||||
useCommandtype->getId(), usePos, unitType->getId(),
|
||||
(targetUnit != NULL ? targetUnit->getId() : -1),
|
||||
facing, tryQueue);
|
||||
|
||||
//every unit is ordered to a different position
|
||||
CommandResult result= pushNetworkCommand(&networkCommand);
|
||||
results.push_back(result);
|
||||
}
|
||||
|
||||
return computeResult(results);
|
||||
}
|
||||
else{
|
||||
return crFailUndefined;
|
||||
}
|
||||
}
|
||||
|
||||
CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *commandType,
|
||||
const Vec2i &pos, const UnitType* unitType,
|
||||
CardinalDir facing, bool tryQueue,Unit *targetUnit) const {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
assert(this->world != NULL);
|
||||
|
@ -51,7 +101,10 @@ CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *com
|
|||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(), commandType->getId(), pos, unitType->getId(), (targetUnit != NULL ? targetUnit->getId() : -1), facing, tryQueue);
|
||||
NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(),
|
||||
commandType->getId(), pos, unitType->getId(),
|
||||
(targetUnit != NULL ? targetUnit->getId() : -1),
|
||||
facing, tryQueue);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -91,7 +144,9 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass
|
|||
}
|
||||
}
|
||||
|
||||
CommandResult Commander::tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{
|
||||
CommandResult Commander::tryGiveCommand(const Selection *selection,
|
||||
const CommandType *commandType, const Vec2i &pos,
|
||||
const Unit *targetUnit, bool tryQueue) const{
|
||||
if(!selection->isEmpty() && commandType!=NULL){
|
||||
Vec2i refPos;
|
||||
CommandResultContainer results;
|
||||
|
|
|
@ -50,6 +50,10 @@ public:
|
|||
void init(World *world);
|
||||
void updateNetwork();
|
||||
|
||||
CommandResult tryGiveCommand(const Selection *selection, const CommandType *commandType,
|
||||
const Vec2i &pos, const UnitType* unitType,
|
||||
CardinalDir facing, bool tryQueue,Unit *targetUnit=NULL) const;
|
||||
|
||||
CommandResult tryGiveCommand(const Unit* unit, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue = false,Unit *targetUnit=NULL) const;
|
||||
CommandResult tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const;
|
||||
CommandResult tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const;
|
||||
|
|
|
@ -435,16 +435,19 @@ void Gui::giveTwoClickOrders(int x, int y){
|
|||
//give orders to the units of this faction
|
||||
if(!selectingBuilding){
|
||||
if(selection.isUniform()){
|
||||
result= commander->tryGiveCommand(&selection, activeCommandType, targetPos, targetUnit,queueKeyDown);
|
||||
result= commander->tryGiveCommand(&selection, activeCommandType,
|
||||
targetPos, targetUnit,queueKeyDown);
|
||||
}
|
||||
else{
|
||||
result= commander->tryGiveCommand(&selection, activeCommandClass, targetPos, targetUnit,queueKeyDown);
|
||||
result= commander->tryGiveCommand(&selection, activeCommandClass,
|
||||
targetPos, targetUnit,queueKeyDown);
|
||||
}
|
||||
}
|
||||
else{
|
||||
//selecting building
|
||||
result= commander->tryGiveCommand(selection.getFrontUnit(),
|
||||
activeCommandType, posObjWorld, choosenBuildingType, selectedBuildingFacing,queueKeyDown);
|
||||
result= commander->tryGiveCommand(&selection,
|
||||
activeCommandType, posObjWorld, choosenBuildingType,
|
||||
selectedBuildingFacing,queueKeyDown);
|
||||
}
|
||||
|
||||
//graphical result
|
||||
|
|
|
@ -174,6 +174,7 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
|||
this->targetPos = Vec2i(0);
|
||||
this->lastRenderFrame = 0;
|
||||
this->visible = true;
|
||||
this->retryCurrCommandCount=0;
|
||||
|
||||
level= NULL;
|
||||
loadType= NULL;
|
||||
|
@ -643,6 +644,12 @@ Command *Unit::getCurrCommand() const{
|
|||
assert(!commands.empty());
|
||||
return commands.front();
|
||||
}
|
||||
|
||||
void Unit::replaceCurrCommand(Command *cmd) {
|
||||
assert(!commands.empty());
|
||||
commands.front() = cmd;
|
||||
}
|
||||
|
||||
//returns the size of the commands
|
||||
unsigned int Unit::getCommandSize() const{
|
||||
return commands.size();
|
||||
|
@ -742,6 +749,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
|||
//pop front (used when order is done)
|
||||
CommandResult Unit::finishCommand(){
|
||||
|
||||
retryCurrCommandCount=0;
|
||||
//is empty?
|
||||
if(commands.empty()){
|
||||
return crFailUndefined;
|
||||
|
@ -767,6 +775,7 @@ CommandResult Unit::finishCommand(){
|
|||
//to cancel a command
|
||||
CommandResult Unit::cancelCommand(){
|
||||
|
||||
retryCurrCommandCount=0;
|
||||
//is empty?
|
||||
if(commands.empty()){
|
||||
return crFailUndefined;
|
||||
|
@ -1461,6 +1470,8 @@ CommandResult Unit::undoCommand(Command *command){
|
|||
faction->cancelUpgrade(uct->getProducedUpgrade());
|
||||
}
|
||||
|
||||
retryCurrCommandCount=0;
|
||||
|
||||
return crSuccess;
|
||||
}
|
||||
|
||||
|
@ -1692,6 +1703,8 @@ std::string Unit::toString() const {
|
|||
|
||||
result += "modelFacing = " + intToStr(modelFacing.asInt()) + "\n";
|
||||
|
||||
result += "retryCurrCommandCount = " + intToStr(retryCurrCommandCount) + "\n";
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -104,6 +104,7 @@ public:
|
|||
virtual bool isEmpty() const = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
virtual void clearBlockCount() = 0;
|
||||
virtual void incBlockCount() = 0;
|
||||
virtual void push(const Vec2i &path) = 0;
|
||||
//virtual Vec2i pop() = 0;
|
||||
|
@ -125,6 +126,7 @@ public:
|
|||
virtual bool isEmpty() const;
|
||||
|
||||
virtual void clear();
|
||||
virtual void clearBlockCount() { blockCount = 0; }
|
||||
virtual void incBlockCount();
|
||||
virtual void push(const Vec2i &path);
|
||||
Vec2i pop();
|
||||
|
@ -151,6 +153,7 @@ public:
|
|||
virtual bool isEmpty() const {return list<Vec2i>::empty();} /**< is path empty */
|
||||
int size() const {return list<Vec2i>::size();} /**< size of path */
|
||||
virtual void clear() {list<Vec2i>::clear(); blockCount = 0;} /**< clear the path */
|
||||
virtual void clearBlockCount() { blockCount = 0; }
|
||||
virtual void incBlockCount() {++blockCount;} /**< increment block counter */
|
||||
virtual void push(const Vec2i &pos) {push_front(pos);} /**< push onto front of path */
|
||||
bool empty() const {return list<Vec2i>::empty();} /**< is path empty */
|
||||
|
@ -188,7 +191,7 @@ public:
|
|||
/// A game unit or building
|
||||
// ===============================
|
||||
|
||||
class Unit{
|
||||
class Unit {
|
||||
private:
|
||||
typedef list<Command*> Commands;
|
||||
typedef list<UnitObserver*> Observers;
|
||||
|
@ -260,6 +263,8 @@ private:
|
|||
int lastRenderFrame;
|
||||
bool visible;
|
||||
|
||||
int retryCurrCommandCount;
|
||||
|
||||
public:
|
||||
Unit(int id, UnitPathInterface *path, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||
~Unit();
|
||||
|
@ -343,6 +348,7 @@ public:
|
|||
//command related
|
||||
bool anyCommand() const;
|
||||
Command *getCurrCommand() const;
|
||||
void replaceCurrCommand(Command *cmd);
|
||||
int getCountOfProducedUnits(const UnitType *ut) const;
|
||||
unsigned int getCommandSize() const;
|
||||
CommandResult giveCommand(Command *command, bool tryQueue = false); //give a command
|
||||
|
@ -385,6 +391,9 @@ public:
|
|||
int getLastRenderFrame() const { return lastRenderFrame; }
|
||||
void setLastRenderFrame(int value) { lastRenderFrame = value; }
|
||||
|
||||
int getRetryCurrCommandCount() const { return retryCurrCommandCount; }
|
||||
void setRetryCurrCommandCount(int value) { retryCurrCommandCount = value; }
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -478,7 +478,7 @@ void Map::clearUnitCells(Unit *unit, const Vec2i &pos){
|
|||
|
||||
// ==================== misc ====================
|
||||
|
||||
//returnis if unit is next to pos
|
||||
//return if unit is next to pos
|
||||
bool Map::isNextTo(const Vec2i &pos, const Unit *unit) const{
|
||||
|
||||
for(int i=-1; i<=1; ++i){
|
||||
|
@ -493,6 +493,21 @@ bool Map::isNextTo(const Vec2i &pos, const Unit *unit) const{
|
|||
return false;
|
||||
}
|
||||
|
||||
//return if unit is next to pos
|
||||
bool Map::isNextTo(const Vec2i &pos, const Vec2i &nextToPos) const {
|
||||
|
||||
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) == getCell(nextToPos.x,nextToPos.y)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Map::clampPos(Vec2i &pos) const{
|
||||
if(pos.x<0){
|
||||
pos.x=0;
|
||||
|
|
|
@ -217,6 +217,7 @@ public:
|
|||
|
||||
//misc
|
||||
bool isNextTo(const Vec2i &pos, const Unit *unit) const;
|
||||
bool isNextTo(const Vec2i &pos, const Vec2i &nextToPos) const;
|
||||
void clampPos(Vec2i &pos) const;
|
||||
|
||||
void prepareTerrain(const Unit *unit);
|
||||
|
|
|
@ -386,6 +386,8 @@ void UnitUpdater::updateAttackStopped(Unit *unit){
|
|||
// ==================== updateBuild ====================
|
||||
|
||||
void UnitUpdater::updateBuild(Unit *unit){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
|
@ -393,6 +395,8 @@ void UnitUpdater::updateBuild(Unit *unit){
|
|||
const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType());
|
||||
|
||||
if(unit->getCurrSkill()->getClass() != scBuild) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if not building
|
||||
const UnitType *ut= command->getUnitType();
|
||||
|
||||
|
@ -408,13 +412,19 @@ void UnitUpdater::updateBuild(Unit *unit){
|
|||
throw runtime_error("detected unsupported pathfinder type!");
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
switch (tsValue) {
|
||||
case tsMoving:
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsMoving\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
unit->setCurrSkill(bct->getMoveSkillType());
|
||||
break;
|
||||
|
||||
case tsArrived:
|
||||
{
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived:\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if arrived destination
|
||||
assert(ut);
|
||||
|
||||
|
@ -498,7 +508,9 @@ void UnitUpdater::updateBuild(Unit *unit){
|
|||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived:\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if building
|
||||
Unit *builtUnit= map->getCell(unit->getTargetPos())->getUnit(fLand);
|
||||
|
||||
|
@ -717,41 +729,154 @@ void UnitUpdater::updateHarvest(Unit *unit){
|
|||
if(chrono.getMillis() > 0) chrono.start();
|
||||
}
|
||||
|
||||
void UnitUpdater::SwapActiveCommand(Unit *unitSrc, Unit *unitDest) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(unitSrc->getCommandSize() > 0 && unitDest->getCommandSize() > 0) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Command *cmd1 = unitSrc->getCurrCommand();
|
||||
Command *cmd2 = unitDest->getCurrCommand();
|
||||
unitSrc->replaceCurrCommand(cmd2);
|
||||
unitDest->replaceCurrCommand(cmd1);
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Unit *foundUnitBuilder = NULL;
|
||||
if(unit->getCommandSize() > 0 ) {
|
||||
Command *command= unit->getCurrCommand();
|
||||
if(command != NULL) {
|
||||
const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType());
|
||||
if(rct) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) {
|
||||
Unit *peerUnit = unit->getFaction()->getUnit(i);
|
||||
if(peerUnit != NULL) {
|
||||
if(peerUnit->getCommandSize() > 0 ) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
Command *peerCommand = peerUnit->getCurrCommand();
|
||||
const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(peerCommand->getCommandType());
|
||||
if(bct != NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(command->getPos() == peerCommand->getPos()) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
foundUnitBuilder = peerUnit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundUnitBuilder;
|
||||
}
|
||||
|
||||
// ==================== updateRepair ====================
|
||||
|
||||
void UnitUpdater::updateRepair(Unit *unit){
|
||||
void UnitUpdater::updateRepair(Unit *unit) {
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit = %p\n",__FILE__,__FUNCTION__,__LINE__,unit);
|
||||
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
Command *command= unit->getCurrCommand();
|
||||
const RepairCommandType *rct= static_cast<const RepairCommandType*>(command->getCommandType());
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] rct = %p\n",__FILE__,__FUNCTION__,__LINE__,rct);
|
||||
|
||||
Unit *repaired= map->getCell(command->getPos())->getUnit(fLand);
|
||||
bool nextToRepaired= repaired!=NULL && map->isNextTo(unit->getPos(), repaired);
|
||||
|
||||
Unit *peerUnitBuilder = NULL;
|
||||
if(repaired == NULL) {
|
||||
peerUnitBuilder = findPeerUnitBuilder(unit);
|
||||
|
||||
if(peerUnitBuilder != NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] peerUnitBuilder = %p\n",__FILE__,__FUNCTION__,__LINE__,peerUnitBuilder);
|
||||
|
||||
// command->getPos()-Vec2i(1)
|
||||
//nextToRepaired= map->isNextTo(unit->getPos(), command->getPos()-Vec2i(1));
|
||||
nextToRepaired= (unit->getPos() == (command->getPos()-Vec2i(1)));
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] peerUnitBuilder = %p, nextToRepaired = %d\n",__FILE__,__FUNCTION__,__LINE__,peerUnitBuilder,nextToRepaired);
|
||||
|
||||
if(nextToRepaired == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
SwapActiveCommand(unit,peerUnitBuilder);
|
||||
// Give the swapped unit a fresh chance to help build in case they
|
||||
// were or are about to be blocked
|
||||
peerUnitBuilder->getPath()->clear();
|
||||
peerUnitBuilder->setRetryCurrCommandCount(1);
|
||||
updateUnitCommand(unit);
|
||||
//updateUnitCommand(peerUnitBuilder);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
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);
|
||||
|
||||
UnitPathInterface *path= unit->getPath();
|
||||
|
||||
if(unit->getCurrSkill()->getClass()!=scRepair || !nextToRepaired){
|
||||
//if not repairing
|
||||
if(repaired!=NULL && rct->isRepairableUnitType(repaired->getType()) && repaired->isDamaged()){
|
||||
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());
|
||||
if(startRepairing == false && peerUnitBuilder != NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
startRepairing = true;
|
||||
// Since the unit to be built is not yet existing we need to tell the
|
||||
// other units to move to the build position or else they get in the way
|
||||
repairPos = command->getPos()-Vec2i(1);
|
||||
}
|
||||
|
||||
//if not repairing
|
||||
if(startRepairing == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(nextToRepaired == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(nextToRepaired){
|
||||
unit->setTarget(repaired);
|
||||
unit->setCurrSkill(rct->getRepairSkillType());
|
||||
}
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
TravelState ts;
|
||||
switch(this->game->getGameSettings()->getPathFinderType()) {
|
||||
case pfBasic:
|
||||
ts = pathFinder->findPath(unit, command->getPos());
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
ts = pathFinder->findPath(unit, repairPos);
|
||||
break;
|
||||
case pfRoutePlanner:
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if (repaired && !repaired->getType()->isMobile()) {
|
||||
ts = routePlanner->findPathToBuildSite(unit, repaired->getType(), repaired->getPos(), repaired->getModelFacing());
|
||||
}
|
||||
else {
|
||||
ts = routePlanner->findPath(unit, command->getPos());
|
||||
ts = routePlanner->findPath(unit, repairPos);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -760,32 +885,60 @@ void UnitUpdater::updateRepair(Unit *unit){
|
|||
|
||||
switch(ts) {
|
||||
case tsMoving:
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsMoving\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
unit->setCurrSkill(rct->getMoveSkillType());
|
||||
break;
|
||||
case tsBlocked:
|
||||
if(unit->getPath()->isBlocked()){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsBlocked\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(unit->getPath()->isBlocked()) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call [scStop]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(unit->getRetryCurrCommandCount() > 0) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] will retry command, unit->getRetryCurrCommandCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,unit->getRetryCurrCommandCount());
|
||||
|
||||
unit->setRetryCurrCommandCount(0);
|
||||
unit->getPath()->clear();
|
||||
updateUnitCommand(unit);
|
||||
}
|
||||
else {
|
||||
unit->finishCommand();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call [scStop]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
unit->setCurrSkill(scStop);
|
||||
unit->finishCommand();
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if repairing
|
||||
if(repaired!=NULL){
|
||||
if(repaired != NULL) {
|
||||
unit->setTarget(repaired);
|
||||
}
|
||||
if(repaired==NULL || repaired->repair()){
|
||||
else if(peerUnitBuilder != NULL) {
|
||||
unit->setTargetPos(command->getPos());
|
||||
}
|
||||
|
||||
if((repaired == NULL || repaired->repair()) &&
|
||||
peerUnitBuilder == NULL) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call [scStop]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
unit->setCurrSkill(scStop);
|
||||
unit->finishCommand();
|
||||
if(repaired!=NULL && !repaired->isBuilt()){
|
||||
|
||||
if(repaired != NULL && repaired->isBuilt() == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
repaired->born();
|
||||
scriptManager->onUnitCreated(repaired);
|
||||
}
|
||||
|
|
|
@ -115,6 +115,9 @@ private:
|
|||
bool attackableOnRange(const Unit *unit, Unit **enemyPtr, const AttackSkillType *ast);
|
||||
bool unitOnRange(const Unit *unit, int range, Unit **enemyPtr, const AttackSkillType *ast);
|
||||
void enemiesAtDistance(const Unit *unit, const Unit *priorityUnit, int distance, vector<Unit*> &enemies);
|
||||
|
||||
Unit * findPeerUnitBuilder(Unit *unit);
|
||||
void SwapActiveCommand(Unit *unitSrc, Unit *unitDest);
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -288,11 +288,11 @@ bool isdir(const char *path)
|
|||
ret = S_ISDIR(stats.st_mode); // #define S_ISDIR(mode) ((mode) & _S_IFDIR)
|
||||
|
||||
if(ret == false) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,friendly_path.c_str(),ret);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s] ret = %d\n",__FILE__,__FUNCTION__,__LINE__,friendly_path.c_str(),ret);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s] ret = %d, result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,friendly_path.c_str(),ret,result,errno);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s] ret = %d, result = %d, errno = %d\n",__FILE__,__FUNCTION__,__LINE__,friendly_path.c_str(),ret,result,errno);
|
||||
}
|
||||
//if(ret == false) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] NOT a path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path);
|
||||
|
||||
|
|
Loading…
Reference in New Issue