Tried to fix the command-queing bug not canceling attack on produce command

This commit is contained in:
PolitikerNEU 2010-05-18 21:18:51 +00:00
parent f010130c38
commit 6d4697f2ba
2 changed files with 24 additions and 2 deletions

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
// Copyright (C) 2001-2008 Martiño Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -500,6 +500,11 @@ unsigned int Unit::getCommandSize() const{
return commands.size();
}
#define deleteSingleCommand(command) {\
undoCommand(command);\
delete command;\
}
//give one command (clear, and push back)
CommandResult Unit::giveCommand(Command *command, bool tryQueue){
@ -515,7 +520,18 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(command->getCommandType()->isQueuable(tryQueue)){
const int command_priority = command->getCommandType()->getPriority();
if(command->getCommandType()->isQueuable(tryQueue) && (commands.empty() || (command_priority >= commands.back()->getCommandType()->getPriority()))){
//Delete all lower-prioirty commands
for (list<Command*>::iterator i = commands.begin(); i != commands.end();) {
if ((*i)->getCommandType()->getPriority() < command_priority) {
deleteSingleCommand(*i);
i = commands.erase(i);
} else {
++i;
}
}
//cancel current command if it is not queuable
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -88,6 +88,8 @@ public:
Queueability q = isQueuable();
return (q != qNever) && (q != qOnlyLast);
}
//Priority: commands of higher priority will cancel commands of lower priority
virtual int getPriority() const {return 0;}
//get
CommandClass getClass() const;
@ -110,6 +112,7 @@ public:
virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const;
virtual Queueability isQueuable() const {return qNever;}
virtual int getPriority() const {return 100000;}
//get
const StopSkillType *getStopSkillType() const {return stopSkillType;};
};
@ -151,6 +154,7 @@ public:
virtual string getDesc(const TotalUpgrade *totalUpgrade) const;
virtual string toString() const;
//get
const MoveSkillType * getMoveSkillType() const {return moveSkillType;}
const AttackSkillType * getAttackSkillType() const {return attackSkillType;}
@ -286,6 +290,7 @@ public:
virtual string toString() const;
virtual const ProducibleType *getProduced() const;
virtual Queueability isQueuable() const {return qAlways;}
virtual int getPriority() const {return 5;} //higher priority to cancel attack
//get
const ProduceSkillType *getProduceSkillType() const {return produceSkillType;}
@ -311,6 +316,7 @@ public:
virtual string getReqDesc() const;
virtual const ProducibleType *getProduced() const;
virtual Queueability isQueuable() const {return qAlways;}
virtual int getPriority() const {return 5;} //higher priority to cancel attack (and same as Build)
//get
const UpgradeSkillType *getUpgradeSkillType() const {return upgradeSkillType;}