Skip to content

Commit b957edc

Browse files
BanestormBanestorm
authored andcommitted
Remove command priority system
This was resulting in non-intuitive and surprising behaviour when queuing commands. Removing this system results in Megaglest behaving more like other RTS games. For instance, the following are now possible and weren't previously: - Queuing multiple attack ground commands to move along a specific path attacking all enemies on the way. - Queuing attack ground followed by hold position, which is a sensible thing to do if you want a unit to guard a specific area. - Queuing a move command followed by a produce command, if you want to have your summoner summon a daemon at a specific location. The behaviour of queuing the stop command is unchanged, and commands that must be the last in the queue, such as morphing, are still properly replaced when something else is queued.
1 parent 1e4441e commit b957edc

File tree

5 files changed

+1
-56
lines changed

5 files changed

+1
-56
lines changed

source/glest_game/type_instances/command.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ Command::Command(const CommandType *ct, const Vec2i &pos, const UnitType *unitTy
7676
//}
7777
}
7878

79-
int Command::getPriority(){
80-
if(this->commandType->commandTypeClass==ccAttack && getUnit()==NULL){
81-
return 5; // attacks to the ground have low priority
82-
}
83-
return this->commandType->getTypePriority();
84-
}
8579
// =============== set ===============
8680

8781
void Command::setCommandType(const CommandType *commandType) {

source/glest_game/type_instances/command.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ class Command {
7171
inline const UnitType* getUnitType() const {return unitType;}
7272
inline CardinalDir getFacing() const {return facing;}
7373

74-
//Priority: commands of higher priority will cancel commands of lower priority
75-
virtual int getPriority();
76-
7774
//set
7875
void setCommandType(const CommandType *commandType);
7976
void setPos(const Vec2i &pos);

source/glest_game/type_instances/unit.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,6 @@ std::pair<CommandResult,string> Unit::giveCommand(Command *command, bool tryQueu
18281828
throw megaglest_runtime_error("command->getCommandType() == NULL");
18291829
}
18301830

1831-
const int command_priority = command->getPriority();
1832-
18331831
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
18341832

18351833
//printf("In [%s::%s] Line: %d unit [%d - %s] command [%s] tryQueue = %d command->getCommandType()->isQueuable(tryQueue) = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->getId(),this->getType()->getName().c_str(), command->getCommandType()->getName().c_str(), tryQueue,command->getCommandType()->isQueuable(tryQueue));
@@ -1839,32 +1837,6 @@ std::pair<CommandResult,string> Unit::giveCommand(Command *command, bool tryQueu
18391837
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
18401838
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Command is Queable\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
18411839

1842-
if(command->getCommandType()->isQueuable() == qAlways && tryQueue){
1843-
// Its a produce or upgrade command called without queued key
1844-
// in this case we must NOT delete lower priority commands!
1845-
// we just queue it!
1846-
1847-
}
1848-
else {
1849-
//Delete all lower-prioirty commands
1850-
for(list<Command*>::iterator i= commands.begin(); i != commands.end();){
1851-
if((*i)->getPriority() < command_priority){
1852-
if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled)
1853-
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] Deleting lower priority command [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,(*i)->toString(false).c_str());
1854-
1855-
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
1856-
MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId);
1857-
1858-
deleteQueuedCommand(*i);
1859-
i= commands.erase(i);
1860-
1861-
safeMutex.ReleaseLock();
1862-
}
1863-
else {
1864-
++i;
1865-
}
1866-
}
1867-
}
18681840
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis());
18691841

18701842
//cancel current command if it is not queuable

source/glest_game/types/command_type.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ class CommandType: public RequirableType {
108108
Queueability q = isQueuable();
109109
return (q != qNever) && (q != qOnlyLast);
110110
}
111-
//Priority: commands of higher priority will cancel commands of lower priority
112-
virtual int getTypePriority() const {return 10;}
113111
virtual bool usesPathfinder() const= 0;
114112

115113
//get
@@ -139,7 +137,6 @@ class StopCommandType: public CommandType {
139137
virtual string getDesc(const TotalUpgrade *totalUpgrade, bool translatedValue) const;
140138
virtual string toString(bool translatedValue) const;
141139
virtual Queueability isQueuable() const {return qNever;}
142-
virtual int getTypePriority() const {return 100000;}
143140
//get
144141
const StopSkillType *getStopSkillType() const {return stopSkillType;};
145142

@@ -213,6 +210,7 @@ class AttackStoppedCommandType: public CommandType {
213210
const TechTree *tt, const FactionType *ft, const UnitType &ut,
214211
std::map<string,vector<pair<string, string> > > &loadedFileList, string parentLoader);
215212
virtual string getDesc(const TotalUpgrade *totalUpgrade, bool translatedValue) const;
213+
virtual Queueability isQueuable() const {return qOnlyLast;}
216214
virtual string toString(bool translatedValue) const;
217215

218216
//get
@@ -369,7 +367,6 @@ class ProduceCommandType: public CommandType {
369367
virtual string toString(bool translatedValue) const;
370368
virtual const ProducibleType *getProduced() const;
371369
virtual Queueability isQueuable() const {return qAlways;}
372-
virtual int getTypePriority() const {return 15;}
373370

374371
//get
375372
const ProduceSkillType *getProduceSkillType() const {return produceSkillType;}
@@ -399,7 +396,6 @@ class UpgradeCommandType: public CommandType {
399396
virtual string getReqDesc(bool translatedValue) const;
400397
virtual const ProducibleType *getProduced() const;
401398
virtual Queueability isQueuable() const {return qAlways;}
402-
virtual int getTypePriority() const {return 15;}
403399

404400
//get
405401
const UpgradeSkillType *getUpgradeSkillType() const {return upgradeSkillType;}

source/glest_game/world/unit_updater.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -720,20 +720,6 @@ void UnitUpdater::updateAttack(Unit *unit, int frameIndex) {
720720

721721
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
722722

723-
if( (command->getUnit() == NULL || !(command->getUnit()->isAlive()) ) && unit->getCommandSize() > 1) {
724-
725-
if(frameIndex < 0) {
726-
unit->finishCommand(); // all queued "ground attacks" are skipped if somthing else is queued after them.
727-
728-
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true && frameIndex < 0) {
729-
char szBuf[8096]="";
730-
snprintf(szBuf,8096,"[updateAttack]");
731-
unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
732-
}
733-
}
734-
return;
735-
}
736-
737723
//if found
738724
//if(frameIndex < 0) {
739725
{

0 commit comments

Comments
 (0)