- bugfix for multi-build queued commands

This commit is contained in:
Mark Vejvoda
2011-01-08 21:53:05 +00:00
parent 0305ae9152
commit 7347dc9545
5 changed files with 120 additions and 79 deletions

View File

@@ -144,17 +144,17 @@ CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *com
CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{
if(!selection->isEmpty()){ if(selection->isEmpty() == false) {
Vec2i refPos, currPos; Vec2i refPos, currPos;
CommandResultContainer results; CommandResultContainer results;
refPos= world->getMap()->computeRefPos(selection); refPos= world->getMap()->computeRefPos(selection);
//give orders to all selected units //give orders to all selected units
for(int i=0; i<selection->getCount(); ++i){ for(int i = 0; i < selection->getCount(); ++i) {
const Unit *unit= selection->getUnit(i); const Unit *unit= selection->getUnit(i);
const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass); const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass);
if(ct!=NULL){ if(ct != NULL) {
int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId();
int unitId= selection->getUnit(i)->getId(); int unitId= selection->getUnit(i)->getId();
Vec2i currPos= world->getMap()->computeDestPos(refPos, selection->getUnit(i)->getPos(), pos); Vec2i currPos= world->getMap()->computeDestPos(refPos, selection->getUnit(i)->getPos(), pos);
@@ -204,7 +204,7 @@ CommandResult Commander::tryGiveCommand(const Selection *selection,
} }
//auto command //auto command
CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const {
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__);
CommandResult result = crFailUndefined; CommandResult result = crFailUndefined;
@@ -279,19 +279,19 @@ void Commander::trySetMeetingPoint(const Unit* unit, const Vec2i &pos)const{
// ==================== PRIVATE ==================== // ==================== PRIVATE ====================
CommandResult Commander::computeResult(const CommandResultContainer &results) const{ CommandResult Commander::computeResult(const CommandResultContainer &results) const {
switch(results.size()){ switch(results.size()) {
case 0: case 0:
return crFailUndefined; return crFailUndefined;
case 1: case 1:
return results.front(); return results.front();
default: default:
for(int i=0; i<results.size(); ++i){ for(int i = 0; i < results.size(); ++i) {
if(results[i]!=crSuccess){ if(results[i] != crSuccess) {
return crSomeFailed; return crSomeFailed;
} }
} }
return crSuccess; return crSuccess;
} }
} }

View File

@@ -159,7 +159,7 @@ void Gui::resetState(){
// ==================== events ==================== // ==================== events ====================
void Gui::update(){ void Gui::update(){
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){ if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){
computeSelected(false,false); computeSelected(false,false);
} }
@@ -395,12 +395,12 @@ void Gui::giveOneClickOrders(){
activeCommandClass= ccStop; activeCommandClass= ccStop;
} }
void Gui::giveDefaultOrders(int x, int y){ void Gui::giveDefaultOrders(int x, int y) {
//compute target //compute target
const Unit *targetUnit= NULL; const Unit *targetUnit= NULL;
Vec2i targetPos; Vec2i targetPos;
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) {
console->addStdMessage("InvalidPosition"); console->addStdMessage("InvalidPosition");
return; return;
} }
@@ -411,7 +411,7 @@ void Gui::givePreparedDefaultOrders(int x, int y){
giveDefaultOrders(x, y, NULL,false); giveDefaultOrders(x, y, NULL,false);
} }
void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse3d){ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse3d) {
bool queueKeyDown = isKeyDown(queueCommandKey); bool queueKeyDown = isKeyDown(queueCommandKey);
Vec2i targetPos=Vec2i(x, y); Vec2i targetPos=Vec2i(x, y);
//give order //give order
@@ -419,7 +419,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse
//graphical result //graphical result
addOrdersResultToConsole(activeCommandClass, result); addOrdersResultToConsole(activeCommandClass, result);
if(result == crSuccess || result == crSomeFailed){ if(result == crSuccess || result == crSomeFailed) {
if(paintMouse3d) if(paintMouse3d)
mouse3d.enable(); mouse3d.enable();
@@ -435,7 +435,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse
resetState(); resetState();
} }
void Gui::giveTwoClickOrders(int x, int y , bool prepared){ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
CommandResult result; CommandResult result;
@@ -445,9 +445,8 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
if(prepared){ if(prepared){
targetPos=Vec2i(x, y); targetPos=Vec2i(x, y);
} }
else else {
{ if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) {
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){
console->addStdMessage("InvalidPosition"); console->addStdMessage("InvalidPosition");
return; return;
} }
@@ -455,17 +454,17 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
bool queueKeyDown = isKeyDown(queueCommandKey); bool queueKeyDown = isKeyDown(queueCommandKey);
//give orders to the units of this faction //give orders to the units of this faction
if(!selectingBuilding){ if(selectingBuilding == false) {
if(selection.isUniform()){ if(selection.isUniform()) {
result= commander->tryGiveCommand(&selection, activeCommandType, result= commander->tryGiveCommand(&selection, activeCommandType,
targetPos, targetUnit,queueKeyDown); targetPos, targetUnit,queueKeyDown);
} }
else{ else {
result= commander->tryGiveCommand(&selection, activeCommandClass, result= commander->tryGiveCommand(&selection, activeCommandClass,
targetPos, targetUnit,queueKeyDown); targetPos, targetUnit,queueKeyDown);
} }
} }
else{ else {
//selecting building //selecting building
result= commander->tryGiveCommand(&selection, result= commander->tryGiveCommand(&selection,
activeCommandType, posObjWorld, choosenBuildingType, activeCommandType, posObjWorld, choosenBuildingType,
@@ -474,12 +473,12 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
//graphical result //graphical result
addOrdersResultToConsole(activeCommandClass, result); addOrdersResultToConsole(activeCommandClass, result);
if(result == crSuccess || result == crSomeFailed){ if(result == crSuccess || result == crSomeFailed) {
if(!prepared){ if(prepared == false) {
mouse3d.enable(); mouse3d.enable();
} }
if(random.randRange(0, 1)==0){ if(random.randRange(0, 1) == 0) {
SoundRenderer::getInstance().playFx( SoundRenderer::getInstance().playFx(
selection.getFrontUnit()->getType()->getCommandSound(), selection.getFrontUnit()->getType()->getCommandSound(),
selection.getFrontUnit()->getCurrVector(), selection.getFrontUnit()->getCurrVector(),
@@ -488,14 +487,14 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
} }
} }
void Gui::centerCameraOnSelection(){ void Gui::centerCameraOnSelection() {
if(!selection.isEmpty()){ if(selection.isEmpty() == false) {
Vec3f refPos= selection.getRefPos(); Vec3f refPos= selection.getRefPos();
gameCamera->centerXZ(refPos.x, refPos.z); gameCamera->centerXZ(refPos.x, refPos.z);
} }
} }
void Gui::selectInterestingUnit(InterestingUnitType iut){ void Gui::selectInterestingUnit(InterestingUnitType iut) {
const Faction* thisFaction= world->getThisFaction(); const Faction* thisFaction= world->getThisFaction();
const Unit* previousUnit= NULL; const Unit* previousUnit= NULL;
bool previousFound= true; bool previousFound= true;
@@ -916,7 +915,7 @@ void Gui::computeSelected(bool doubleClick, bool force){
} }
selectingBuilding= false; selectingBuilding= false;
activeCommandType= NULL; activeCommandType= NULL;
//select all units of the same type if double click //select all units of the same type if double click
if(doubleClick && units.size()==1){ if(doubleClick && units.size()==1){
const Unit *refUnit= units.front(); const Unit *refUnit= units.front();
@@ -930,15 +929,15 @@ void Gui::computeSelected(bool doubleClick, bool force){
} }
} }
} }
bool shiftDown= isKeyDown(vkShift); bool shiftDown= isKeyDown(vkShift);
bool controlDown= isKeyDown(vkControl); bool controlDown= isKeyDown(vkControl);
if(!shiftDown && !controlDown){ if(!shiftDown && !controlDown){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.clear()\n",__FILE__,__FUNCTION__,__LINE__);
selection.clear(); selection.clear();
} }
if(!controlDown){ if(!controlDown){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to call selection.select(units)\n",__FILE__,__FUNCTION__,__LINE__);
selection.select(units); selection.select(units);
@@ -950,25 +949,25 @@ void Gui::computeSelected(bool doubleClick, bool force){
} }
} }
bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit){ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit) {
Selection::UnitContainer uc; Selection::UnitContainer uc;
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
renderer.computeSelected(uc, screenPos, screenPos); renderer.computeSelected(uc, screenPos, screenPos);
validPosObjWorld= false; validPosObjWorld= false;
if(!uc.empty()){ if(uc.empty() == false) {
targetUnit= uc.front(); targetUnit= uc.front();
targetPos= targetUnit->getPos(); targetPos= targetUnit->getPos();
return true; return true;
} }
else{ else {
targetUnit= NULL; targetUnit= NULL;
if(renderer.computePosition(screenPos, targetPos)){ if(renderer.computePosition(screenPos, targetPos)) {
validPosObjWorld= true; validPosObjWorld= true;
posObjWorld= targetPos; posObjWorld= targetPos;
return true; return true;
} }
else{ else {
return false; return false;
} }
} }

View File

@@ -498,13 +498,13 @@ bool Unit::isInteresting(InterestingUnitType iut) const {
throw runtime_error(szBuf); throw runtime_error(szBuf);
} }
switch(iut){ switch(iut) {
case iutIdleHarvester: case iutIdleHarvester:
if(type->hasCommandClass(ccHarvest)){ if(type->hasCommandClass(ccHarvest)) {
if(!commands.empty()){ if(commands.empty() == false) {
const CommandType *ct= commands.front()->getCommandType(); const CommandType *ct= commands.front()->getCommandType();
if(ct!=NULL){ if(ct != NULL){
return ct->getClass()==ccStop; return ct->getClass() == ccStop;
} }
} }
} }
@@ -698,7 +698,7 @@ bool Unit::anyCommand(bool validateCommandtype) const {
} }
//return current command, assert that there is always one command //return current command, assert that there is always one command
Command *Unit::getCurrCommand() const{ Command *Unit::getCurrCommand() const {
if(commands.empty() == false) { if(commands.empty() == false) {
return commands.front(); return commands.front();
} }
@@ -706,13 +706,13 @@ Command *Unit::getCurrCommand() const{
} }
void Unit::replaceCurrCommand(Command *cmd) { void Unit::replaceCurrCommand(Command *cmd) {
assert(!commands.empty()); assert(commands.empty() == false);
commands.front() = cmd; commands.front() = cmd;
this->setCurrentUnitTitle(""); this->setCurrentUnitTitle("");
} }
//returns the size of the commands //returns the size of the commands
unsigned int Unit::getCommandSize() const{ unsigned int Unit::getCommandSize() const {
return commands.size(); return commands.size();
} }
@@ -749,25 +749,21 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
chrono.start(); chrono.start();
assert(command != NULL); assert(command != NULL);
assert(command->getCommandType() != NULL); assert(command->getCommandType() != NULL);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Unit id = %d name = %s, Command [%s] tryQueue = %d\n",
// __FILE__,__FUNCTION__, __LINE__,this->id,(this->type != NULL ? this->type->getName().c_str() : "null"), (command != NULL ? command->toString().c_str() : "null"),tryQueue);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
const int command_priority = command->getPriority(); const int command_priority = command->getPriority();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
if(command->getCommandType()->isQueuable(tryQueue)){ if(command->getCommandType()->isQueuable(tryQueue)) {
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Command is Queable\n",__FILE__,__FUNCTION__,__LINE__);
//Delete all lower-prioirty commands //Delete all lower-prioirty commands
for (list<Command*>::iterator i = commands.begin(); i != commands.end();) { for (list<Command*>::iterator i = commands.begin(); i != commands.end();) {
if ((*i)->getPriority() < command_priority) { if ((*i)->getPriority() < command_priority) {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",__FILE__,__FUNCTION__,__LINE__,(*i)->toString().c_str());
deleteQueuedCommand(*i); deleteQueuedCommand(*i);
i = commands.erase(i); i = commands.erase(i);
} }
@@ -781,8 +777,10 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
//cancel current command if it is not queuable //cancel current command if it is not queuable
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__);
if(!commands.empty() && !commands.back()->getCommandType()->isQueueAppendable()){ if(commands.empty() == false &&
commands.back()->getCommandType()->isQueueAppendable() == false) {
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Cancel command because last one is NOT queable [%s]\n",__FILE__,__FUNCTION__,__LINE__,commands.back()->toString().c_str());
cancelCommand(); cancelCommand();
} }
@@ -792,6 +790,8 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
else { else {
//empty command queue //empty command queue
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Clear commands because current is NOT queable.\n",__FILE__,__FUNCTION__,__LINE__);
clearCommands(); clearCommands();
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@@ -804,6 +804,7 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
//check command //check command
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__);
CommandResult result= checkCommand(command); CommandResult result= checkCommand(command);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] checkCommand returned: [%d]\n",__FILE__,__FUNCTION__,__LINE__,result);
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis()); if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
@@ -840,7 +841,7 @@ CommandResult Unit::finishCommand() {
retryCurrCommandCount=0; retryCurrCommandCount=0;
this->setCurrentUnitTitle(""); this->setCurrentUnitTitle("");
//is empty? //is empty?
if(commands.empty()){ if(commands.empty()) {
return crFailUndefined; return crFailUndefined;
} }
@@ -849,7 +850,7 @@ CommandResult Unit::finishCommand() {
commands.erase(commands.begin()); commands.erase(commands.begin());
this->unitPath->clear(); this->unitPath->clear();
while (!commands.empty()) { while (commands.empty() == false) {
if (commands.front()->getUnit() != NULL && livingUnitsp.find(commands.front()->getUnit()) == livingUnitsp.end()) { if (commands.front()->getUnit() != NULL && livingUnitsp.find(commands.front()->getUnit()) == livingUnitsp.end()) {
delete commands.front(); delete commands.front();
commands.erase(commands.begin()); commands.erase(commands.begin());
@@ -1298,7 +1299,7 @@ string Unit::getDesc() const {
} }
//command info //command info
if(!commands.empty()){ if(commands.empty() == false) {
str+= "\n" + commands.front()->getCommandType()->getName(); str+= "\n" + commands.front()->getCommandType()->getName();
if(commands.size()>1){ if(commands.size()>1){
str+="\n"+lang.get("OrdersOnQueue")+": "+intToStr(commands.size()); str+="\n"+lang.get("OrdersOnQueue")+": "+intToStr(commands.size());
@@ -1437,7 +1438,7 @@ void Unit::updateTarget(){
void Unit::clearCommands() { void Unit::clearCommands() {
this->setCurrentUnitTitle(""); this->setCurrentUnitTitle("");
this->unitPath->clear(); this->unitPath->clear();
while(!commands.empty()){ while(commands.empty() == false) {
undoCommand(commands.back()); undoCommand(commands.back());
delete commands.back(); delete commands.back();
commands.pop_back(); commands.pop_back();
@@ -1445,8 +1446,7 @@ void Unit::clearCommands() {
} }
void Unit::deleteQueuedCommand(Command *command) { void Unit::deleteQueuedCommand(Command *command) {
if(getCurrCommand()==command) if(getCurrCommand() == command) {
{
this->setCurrentUnitTitle(""); this->setCurrentUnitTitle("");
this->unitPath->clear(); this->unitPath->clear();
} }
@@ -1465,15 +1465,17 @@ CommandResult Unit::checkCommand(Command *command) const {
} }
//if not operative or has not command type => fail //if not operative or has not command type => fail
if(!isOperative() || command->getUnit()==this || !getType()->hasCommandType(command->getCommandType())|| !this->getFaction()->reqsOk(command->getCommandType())){ if(isOperative() == false ||
command->getUnit() == this ||
getType()->hasCommandType(command->getCommandType()) == false ||
this->getFaction()->reqsOk(command->getCommandType()) == false) {
return crFailUndefined; return crFailUndefined;
} }
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__);
//if pos is not inside the world (if comand has not a pos, pos is (0, 0) and is inside world //if pos is not inside the world (if comand has not a pos, pos is (0, 0) and is inside world
if(!map->isInside(command->getPos())) { if(map->isInside(command->getPos()) == false) {
return crFailUndefined; return crFailUndefined;
} }
@@ -1500,7 +1502,7 @@ CommandResult Unit::checkCommand(Command *command) const {
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__);
//build command specific, check resources and requirements for building //build command specific, check resources and requirements for building
if(command->getCommandType()->getClass()==ccBuild) { if(command->getCommandType()->getClass() == ccBuild) {
const UnitType *builtUnit= command->getUnitType(); const UnitType *builtUnit= command->getUnitType();
if(builtUnit == NULL) { if(builtUnit == NULL) {

View File

@@ -314,7 +314,7 @@ string AttackStoppedCommandType::getDesc(const TotalUpgrade *totalUpgrade) const
return str; return str;
} }
string AttackStoppedCommandType::toString() const{ string AttackStoppedCommandType::toString() const {
Lang &lang= Lang::getInstance(); Lang &lang= Lang::getInstance();
return lang.get("AttackStopped"); return lang.get("AttackStopped");
} }
@@ -325,12 +325,12 @@ string AttackStoppedCommandType::toString() const{
// ===================================================== // =====================================================
//varios //varios
BuildCommandType::BuildCommandType(){ BuildCommandType::BuildCommandType() {
commandTypeClass= ccBuild; commandTypeClass= ccBuild;
clicks= cTwo; clicks= cTwo;
} }
BuildCommandType::~BuildCommandType(){ BuildCommandType::~BuildCommandType() {
deleteValues(builtSounds.getSounds().begin(), builtSounds.getSounds().end()); deleteValues(builtSounds.getSounds().begin(), builtSounds.getSounds().end());
deleteValues(startSounds.getSounds().begin(), startSounds.getSounds().end()); deleteValues(startSounds.getSounds().begin(), startSounds.getSounds().end());
} }
@@ -606,7 +606,7 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
} }
str+= "\n" + getProducedUnit()->getReqDesc(); str+= "\n" + getProducedUnit()->getReqDesc();
return str; return str;
} }

View File

@@ -187,7 +187,9 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
//if unit has command process it //if unit has command process it
if(unit->anyCommand()) { if(unit->anyCommand()) {
CommandClass cc=unit->getCurrCommand()->getCommandType()->commandTypeClass; SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] unit [%s] has command [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str(), unit->getCurrCommand()->toString().c_str());
CommandClass cc = unit->getCurrCommand()->getCommandType()->commandTypeClass;
unit->getCurrCommand()->getCommandType()->update(this, unit); unit->getCurrCommand()->getCommandType()->update(this, unit);
} }
@@ -195,7 +197,7 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
//if no commands stop and add stop command //if no commands stop and add stop command
if(unit->anyCommand() == false && unit->isOperative()) { if(unit->anyCommand() == false && unit->isOperative()) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
if(unit->getType()->hasCommandClass(ccStop)) { if(unit->getType()->hasCommandClass(ccStop)) {
@@ -445,6 +447,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
chrono.start(); chrono.start();
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] unit [%s] will build using command [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str(), unit->getCurrCommand()->toString().c_str());
Command *command= unit->getCurrCommand(); Command *command= unit->getCurrCommand();
const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType()); const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType());
@@ -454,6 +457,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
if(unit->getCurrSkill()->getClass() != scBuild) { if(unit->getCurrSkill()->getClass() != scBuild) {
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//if not building //if not building
const UnitType *ut= command->getUnitType(); const UnitType *ut= command->getUnitType();
@@ -486,6 +490,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
} }
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] tsValue = %d\n",__FILE__,__FUNCTION__,__LINE__,tsValue);
switch (tsValue) { switch (tsValue) {
case tsMoving: case tsMoving:
@@ -517,6 +522,8 @@ void UnitUpdater::updateBuild(Unit *unit) {
throw runtime_error("detected unsupported pathfinder type!"); throw runtime_error("detected unsupported pathfinder type!");
} }
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] canOccupyCell = %d\n",__FILE__,__FUNCTION__,__LINE__,canOccupyCell);
if (canOccupyCell == true) { if (canOccupyCell == true) {
const UnitType *builtUnitType= command->getUnitType(); const UnitType *builtUnitType= command->getUnitType();
CardinalDir facing = command->getFacing(); CardinalDir facing = command->getFacing();
@@ -594,6 +601,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
} }
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__);
} }
} }
break; break;
@@ -603,6 +611,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
unit->cancelCommand(); unit->cancelCommand();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got tsBlocked\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] got tsBlocked\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] got tsBlocked\n",__FILE__,__FUNCTION__,__LINE__);
} }
break; break;
} }
@@ -611,6 +620,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
} }
else { else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived unit = %s\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] tsArrived unit = %s\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str());
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"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);
@@ -622,13 +632,17 @@ void UnitUpdater::updateBuild(Unit *unit) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builtUnit = %s\n",__FILE__,__FUNCTION__,__LINE__,builtUnit->toString().c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] builtUnit = %s\n",__FILE__,__FUNCTION__,__LINE__,builtUnit->toString().c_str());
} }
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit = [%p]\n",__FILE__,__FUNCTION__,__LINE__,builtUnit);
//if unit is killed while building then u==NULL; //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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is not the command's unit!\n",__FILE__,__FUNCTION__,__LINE__);
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
} }
else if(builtUnit == NULL || builtUnit->isBuilt()) { else if(builtUnit == NULL || builtUnit->isBuilt()) {
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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is NULL or ALREADY built\n",__FILE__,__FUNCTION__,__LINE__);
unit->finishCommand(); unit->finishCommand();
unit->setCurrSkill(scStop); unit->setCurrSkill(scStop);
@@ -636,6 +650,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
} }
else if(builtUnit == NULL || 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__);
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//building finished //building finished
unit->finishCommand(); unit->finishCommand();
@@ -1063,7 +1078,9 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
if(command != NULL) { if(command != NULL) {
const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType()); const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType());
if(rct != NULL && command->getStateType() == cst_linkedUnit) { if(rct != NULL && command->getStateType() == cst_linkedUnit) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] looking for command->getStateValue() = %d\n",__FILE__,__FUNCTION__,__LINE__,command->getStateValue());
Unit *firstLinkedPeerRepairer = NULL;
for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) { for(int i = 0; i < unit->getFaction()->getUnitCount(); ++i) {
Unit *peerUnit = unit->getFaction()->getUnit(i); Unit *peerUnit = unit->getFaction()->getUnit(i);
@@ -1084,13 +1101,36 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
break; break;
} }
} }
else {
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] **peer NOT building**, peerUnit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,peerUnit->toString().c_str());
if(firstLinkedPeerRepairer == NULL) {
const RepairCommandType *prct = dynamic_cast<const RepairCommandType*>(peerCommand->getCommandType());
if(prct != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(command->getStateValue() == peerUnit->getId()) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
firstLinkedPeerRepairer = peerUnit;
break;
}
}
}
}
} }
} }
} }
if(foundUnitBuilder == NULL) {
foundUnitBuilder = firstLinkedPeerRepairer;
}
} }
} }
} }
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] returning foundUnitBuilder = [%s]\n",__FILE__,__FUNCTION__,__LINE__,(foundUnitBuilder != NULL ? foundUnitBuilder->toString().c_str() : "null"));
return foundUnitBuilder; return foundUnitBuilder;
} }