mirror of
https://github.com/glest/glest-source.git
synced 2025-08-30 03:09:49 +02:00
- bugfix for multi-build queued commands
This commit is contained in:
@@ -144,7 +144,7 @@ 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{
|
||||
|
||||
if(!selection->isEmpty()){
|
||||
if(selection->isEmpty() == false) {
|
||||
Vec2i refPos, currPos;
|
||||
CommandResultContainer results;
|
||||
|
||||
|
@@ -400,7 +400,7 @@ void Gui::giveDefaultOrders(int x, int y){
|
||||
//compute target
|
||||
const Unit *targetUnit= NULL;
|
||||
Vec2i targetPos;
|
||||
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){
|
||||
if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) {
|
||||
console->addStdMessage("InvalidPosition");
|
||||
return;
|
||||
}
|
||||
@@ -445,9 +445,8 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
|
||||
if(prepared){
|
||||
targetPos=Vec2i(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){
|
||||
else {
|
||||
if(computeTarget(Vec2i(x, y), targetPos, targetUnit) == false) {
|
||||
console->addStdMessage("InvalidPosition");
|
||||
return;
|
||||
}
|
||||
@@ -455,7 +454,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
|
||||
|
||||
bool queueKeyDown = isKeyDown(queueCommandKey);
|
||||
//give orders to the units of this faction
|
||||
if(!selectingBuilding){
|
||||
if(selectingBuilding == false) {
|
||||
if(selection.isUniform()) {
|
||||
result= commander->tryGiveCommand(&selection, activeCommandType,
|
||||
targetPos, targetUnit,queueKeyDown);
|
||||
@@ -475,7 +474,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
|
||||
//graphical result
|
||||
addOrdersResultToConsole(activeCommandClass, result);
|
||||
if(result == crSuccess || result == crSomeFailed) {
|
||||
if(!prepared){
|
||||
if(prepared == false) {
|
||||
mouse3d.enable();
|
||||
}
|
||||
|
||||
@@ -489,7 +488,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
|
||||
}
|
||||
|
||||
void Gui::centerCameraOnSelection() {
|
||||
if(!selection.isEmpty()){
|
||||
if(selection.isEmpty() == false) {
|
||||
Vec3f refPos= selection.getRefPos();
|
||||
gameCamera->centerXZ(refPos.x, refPos.z);
|
||||
}
|
||||
@@ -956,7 +955,7 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
|
||||
renderer.computeSelected(uc, screenPos, screenPos);
|
||||
validPosObjWorld= false;
|
||||
|
||||
if(!uc.empty()){
|
||||
if(uc.empty() == false) {
|
||||
targetUnit= uc.front();
|
||||
targetPos= targetUnit->getPos();
|
||||
return true;
|
||||
|
@@ -501,7 +501,7 @@ bool Unit::isInteresting(InterestingUnitType iut) const {
|
||||
switch(iut) {
|
||||
case iutIdleHarvester:
|
||||
if(type->hasCommandClass(ccHarvest)) {
|
||||
if(!commands.empty()){
|
||||
if(commands.empty() == false) {
|
||||
const CommandType *ct= commands.front()->getCommandType();
|
||||
if(ct != NULL){
|
||||
return ct->getClass() == ccStop;
|
||||
@@ -706,7 +706,7 @@ Command *Unit::getCurrCommand() const{
|
||||
}
|
||||
|
||||
void Unit::replaceCurrCommand(Command *cmd) {
|
||||
assert(!commands.empty());
|
||||
assert(commands.empty() == false);
|
||||
commands.front() = cmd;
|
||||
this->setCurrentUnitTitle("");
|
||||
}
|
||||
@@ -749,25 +749,21 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||
chrono.start();
|
||||
|
||||
assert(command != 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();
|
||||
|
||||
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(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
|
||||
for (list<Command*>::iterator i = commands.begin(); i != commands.end();) {
|
||||
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);
|
||||
i = commands.erase(i);
|
||||
}
|
||||
@@ -781,8 +777,10 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||
//cancel current command if it is not queuable
|
||||
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::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();
|
||||
}
|
||||
@@ -792,6 +790,8 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) {
|
||||
else {
|
||||
//empty command queue
|
||||
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();
|
||||
|
||||
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
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
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());
|
||||
@@ -849,7 +850,7 @@ CommandResult Unit::finishCommand() {
|
||||
commands.erase(commands.begin());
|
||||
this->unitPath->clear();
|
||||
|
||||
while (!commands.empty()) {
|
||||
while (commands.empty() == false) {
|
||||
if (commands.front()->getUnit() != NULL && livingUnitsp.find(commands.front()->getUnit()) == livingUnitsp.end()) {
|
||||
delete commands.front();
|
||||
commands.erase(commands.begin());
|
||||
@@ -1298,7 +1299,7 @@ string Unit::getDesc() const {
|
||||
}
|
||||
|
||||
//command info
|
||||
if(!commands.empty()){
|
||||
if(commands.empty() == false) {
|
||||
str+= "\n" + commands.front()->getCommandType()->getName();
|
||||
if(commands.size()>1){
|
||||
str+="\n"+lang.get("OrdersOnQueue")+": "+intToStr(commands.size());
|
||||
@@ -1437,7 +1438,7 @@ void Unit::updateTarget(){
|
||||
void Unit::clearCommands() {
|
||||
this->setCurrentUnitTitle("");
|
||||
this->unitPath->clear();
|
||||
while(!commands.empty()){
|
||||
while(commands.empty() == false) {
|
||||
undoCommand(commands.back());
|
||||
delete commands.back();
|
||||
commands.pop_back();
|
||||
@@ -1445,8 +1446,7 @@ void Unit::clearCommands() {
|
||||
}
|
||||
|
||||
void Unit::deleteQueuedCommand(Command *command) {
|
||||
if(getCurrCommand()==command)
|
||||
{
|
||||
if(getCurrCommand() == command) {
|
||||
this->setCurrentUnitTitle("");
|
||||
this->unitPath->clear();
|
||||
}
|
||||
@@ -1465,15 +1465,17 @@ CommandResult Unit::checkCommand(Command *command) const {
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
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(!map->isInside(command->getPos())) {
|
||||
|
||||
if(map->isInside(command->getPos()) == false) {
|
||||
return crFailUndefined;
|
||||
}
|
||||
|
||||
|
@@ -187,6 +187,8 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
|
||||
|
||||
//if unit has command process it
|
||||
if(unit->anyCommand()) {
|
||||
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);
|
||||
}
|
||||
@@ -195,7 +197,7 @@ void UnitUpdater::updateUnitCommand(Unit *unit) {
|
||||
|
||||
//if no commands stop and add stop command
|
||||
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);
|
||||
|
||||
if(unit->getType()->hasCommandClass(ccStop)) {
|
||||
@@ -445,6 +447,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
chrono.start();
|
||||
|
||||
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();
|
||||
const BuildCommandType *bct= static_cast<const BuildCommandType*>(command->getCommandType());
|
||||
@@ -454,6 +457,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
|
||||
if(unit->getCurrSkill()->getClass() != scBuild) {
|
||||
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
|
||||
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::debugUnitCommands,"In [%s::%s Line: %d] tsValue = %d\n",__FILE__,__FUNCTION__,__LINE__,tsValue);
|
||||
|
||||
switch (tsValue) {
|
||||
case tsMoving:
|
||||
@@ -517,6 +522,8 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
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) {
|
||||
const UnitType *builtUnitType= command->getUnitType();
|
||||
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::debugUnitCommands,"In [%s::%s Line: %d] got BuildingNoPlace\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -603,6 +611,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
unit->cancelCommand();
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -611,6 +620,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
}
|
||||
else {
|
||||
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
|
||||
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::debugUnitCommands,"In [%s::%s Line: %d] builtUnit = [%p]\n",__FILE__,__FUNCTION__,__LINE__,builtUnit);
|
||||
|
||||
//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__);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] builtUnit is not the command's unit!\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
unit->setCurrSkill(scStop);
|
||||
}
|
||||
else if(builtUnit == NULL || builtUnit->isBuilt()) {
|
||||
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->setCurrSkill(scStop);
|
||||
@@ -636,6 +650,7 @@ void UnitUpdater::updateBuild(Unit *unit) {
|
||||
}
|
||||
else if(builtUnit == NULL || builtUnit->repair()) {
|
||||
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
|
||||
unit->finishCommand();
|
||||
@@ -1063,7 +1078,9 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
|
||||
if(command != NULL) {
|
||||
const RepairCommandType *rct= dynamic_cast<const RepairCommandType*>(command->getCommandType());
|
||||
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) {
|
||||
Unit *peerUnit = unit->getFaction()->getUnit(i);
|
||||
@@ -1084,12 +1101,35 @@ Unit * UnitUpdater::findPeerUnitBuilder(Unit *unit) {
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user