diff --git a/source/glest_game/ai/ai.cpp b/source/glest_game/ai/ai.cpp index 2a85b94b..e9935447 100644 --- a/source/glest_game/ai/ai.cpp +++ b/source/glest_game/ai/ai.cpp @@ -948,7 +948,7 @@ void Ai::massiveAttack(const Vec2i &pos, Field field, bool ultraAttack){ void Ai::returnBase(int unitIndex) { Vec2i pos; - CommandResult r; + std::pair r(crFailUndefined,""); aiInterface->getFactionIndex(); pos= Vec2i( random.randRange(-villageRadius, villageRadius), @@ -1141,7 +1141,7 @@ void Ai::unblockUnits() { unitGroupCommandId = aiInterface->getWorld()->getNextCommandGroupId(); } - CommandResult r = aiInterface->giveCommand(adjacentUnit,ct, pos, unitGroupCommandId); + std::pair r = aiInterface->giveCommand(adjacentUnit,ct, pos, unitGroupCommandId); } } } diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 122ef3fc..5c9afee8 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -126,36 +126,37 @@ bool AiInterface::executeCommandOverNetwork() { return faction->getCpuControl(enableServerControlledAI,isNetworkGame,role); } -CommandResult AiInterface::giveCommandSwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) { +std::pair AiInterface::giveCommandSwitchTeamVote(const Faction* faction, SwitchTeamVote *vote) { assert(this->gameSettings != NULL); commander->trySwitchTeamVote(faction,vote); - return crSuccess; + return std::pair(crSuccess,""); } -CommandResult AiInterface::giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos){ +std::pair AiInterface::giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos){ assert(this->gameSettings != NULL); + std::pair result(crFailUndefined,""); if(executeCommandOverNetwork() == true) { const Unit *unit = getMyUnit(unitIndex); - CommandResult result = commander->tryGiveCommand(unit, unit->getType()->getFirstCtOfClass(commandClass), pos, unit->getType(),CardinalDir::NORTH); - + result = commander->tryGiveCommand(unit, unit->getType()->getFirstCtOfClass(commandClass), pos, unit->getType(),CardinalDir::NORTH); return result; } else { Command *c= new Command (world->getFaction(factionIndex)->getUnit(unitIndex)->getType()->getFirstCtOfClass(commandClass), pos); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(c); + result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(c); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); return result; } } -CommandResult AiInterface::giveCommand(const Unit *unit, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId) { +std::pair AiInterface::giveCommand(const Unit *unit, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId) { assert(this->gameSettings != NULL); + std::pair result(crFailUndefined,""); if(unit == NULL) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] Can not find AI unit in AI factionIndex = %d. Game out of synch.",__FILE__,__FUNCTION__,__LINE__,factionIndex); @@ -188,7 +189,7 @@ CommandResult AiInterface::giveCommand(const Unit *unit, const CommandType *comm } if(executeCommandOverNetwork() == true) { - CommandResult result = commander->tryGiveCommand(unit, commandType, pos, + result = commander->tryGiveCommand(unit, commandType, pos, unit->getType(),CardinalDir::NORTH, false, NULL,unitGroupCommandId); return result; } @@ -199,16 +200,17 @@ CommandResult AiInterface::giveCommand(const Unit *unit, const CommandType *comm Unit *unitToCommand = faction->findUnit(unit->getId()); Command *cmd = new Command(commandType, pos); cmd->setUnitCommandGroupId(unitGroupCommandId); - CommandResult result = unitToCommand->giveCommand(cmd); + result = unitToCommand->giveCommand(cmd); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); return result; } } -CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId) { +std::pair AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId) { assert(this->gameSettings != NULL); + std::pair result(crFailUndefined,""); const Unit *unit = getMyUnit(unitIndex); if(unit == NULL) { char szBuf[8096]=""; @@ -238,7 +240,7 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command if(executeCommandOverNetwork() == true) { const Unit *unit = getMyUnit(unitIndex); - CommandResult result = commander->tryGiveCommand(unit, commandType, pos, unit->getType(),CardinalDir::NORTH); + result = commander->tryGiveCommand(unit, commandType, pos, unit->getType(),CardinalDir::NORTH); return result; } else { @@ -246,16 +248,17 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command Command *cmd = new Command(commandType, pos); cmd->setUnitCommandGroupId(unitGroupCommandId); - CommandResult result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(cmd); + result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(cmd); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); return result; } } -CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut) { +std::pair AiInterface::giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType *ut) { assert(this->gameSettings != NULL); + std::pair result(crFailUndefined,""); const Unit *unit = getMyUnit(unitIndex); if(unit == NULL) { char szBuf[8096]=""; @@ -285,13 +288,13 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command if(executeCommandOverNetwork() == true) { const Unit *unit = getMyUnit(unitIndex); - CommandResult result = commander->tryGiveCommand(unit, commandType, pos, ut,CardinalDir::NORTH); + result = commander->tryGiveCommand(unit, commandType, pos, ut,CardinalDir::NORTH); return result; } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, pos, ut, CardinalDir::NORTH)); + result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, pos, ut, CardinalDir::NORTH)); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -299,10 +302,11 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command } } -CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, Unit *u){ +std::pair AiInterface::giveCommand(int unitIndex, const CommandType *commandType, Unit *u){ assert(this->gameSettings != NULL); assert(this->commander != NULL); + std::pair result(crFailUndefined,""); const Unit *unit = getMyUnit(unitIndex); if(unit == NULL) { char szBuf[8096]=""; @@ -334,14 +338,14 @@ CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *command Unit *targetUnit = u; const Unit *unit = getMyUnit(unitIndex); - CommandResult result = commander->tryGiveCommand(unit, commandType, Vec2i(0), unit->getType(),CardinalDir::NORTH,false,targetUnit); + result = commander->tryGiveCommand(unit, commandType, Vec2i(0), unit->getType(),CardinalDir::NORTH,false,targetUnit); return result; } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, u)); + result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, u)); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/ai/ai_interface.h b/source/glest_game/ai/ai_interface.h index 988c00ec..43affe85 100644 --- a/source/glest_game/ai/ai_interface.h +++ b/source/glest_game/ai/ai_interface.h @@ -67,13 +67,13 @@ public: void printLog(int logLevel, const string &s); //interact - CommandResult giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos=Vec2i(0)); - CommandResult giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType); - CommandResult giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId); - CommandResult giveCommand(int unitIndex, const CommandType *commandType, Unit *u= NULL); - CommandResult giveCommand(const Unit *unit, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId); + std::pair giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos=Vec2i(0)); + std::pair giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType); + std::pair giveCommand(int unitIndex, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId); + std::pair giveCommand(int unitIndex, const CommandType *commandType, Unit *u= NULL); + std::pair giveCommand(const Unit *unit, const CommandType *commandType, const Vec2i &pos, int unitGroupCommandId); - CommandResult giveCommandSwitchTeamVote(const Faction* faction, SwitchTeamVote *vote); + std::pair giveCommandSwitchTeamVote(const Faction* faction, SwitchTeamVote *vote); //get data const ControlType getControlType(); diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index d26afb0c..bcd8bffd 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -171,11 +171,12 @@ bool Commander::canSubmitCommandType(const Unit *unit, const CommandType *comman return canSubmitCommand; } -CommandResult Commander::tryGiveCommand(const Selection *selection, const CommandType *commandType, +std::pair Commander::tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue,Unit *targetUnit) const { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + std::pair result(crFailUndefined,""); if(!selection->isEmpty() && commandType != NULL) { Vec2i refPos; CommandResultContainer results; @@ -202,7 +203,7 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman const Unit *unit = selection->getUnit(i); - CommandResult result = crFailUndefined; + std::pair resultCur(crFailUndefined,""); bool canSubmitCommand = canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { int unitId= unit->getId(); @@ -238,21 +239,19 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Comman unitCommandGroupId); //every unit is ordered to a the position - result= pushNetworkCommand(&networkCommand); + resultCur= pushNetworkCommand(&networkCommand); } } - results.push_back(result); + results.push_back(resultCur); } return computeResult(results); } - else{ - return crFailUndefined; - } + return std::pair(crFailUndefined,""); } -CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *commandType, +std::pair Commander::tryGiveCommand(const Unit* unit, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue,Unit *targetUnit, int unitGroupCommandId) const { @@ -268,7 +267,7 @@ CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *com 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()); - CommandResult result = crFailUndefined; + std::pair result(crFailUndefined,""); bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { NetworkCommand networkCommand(this->world,nctGiveCommand, unit->getId(), @@ -286,9 +285,10 @@ CommandResult Commander::tryGiveCommand(const Unit* unit, const CommandType *com return result; } -CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass commandClass, +std::pair Commander::tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const{ + std::pair result(crFailUndefined,""); if(selection->isEmpty() == false) { Vec2i refPos, currPos; CommandResultContainer results; @@ -305,7 +305,8 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass const Unit *unit= selection->getUnit(i); const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass); if(ct != NULL) { - CommandResult result = crFailUndefined; + std::pair resultCur(crFailUndefined,""); + bool canSubmitCommand=canSubmitCommandType(unit, ct); if(canSubmitCommand == true) { @@ -318,24 +319,26 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, CommandClass tryQueue,cst_None,-1,unitCommandGroupId); //every unit is ordered to a different pos - result= pushNetworkCommand(&networkCommand); + resultCur= pushNetworkCommand(&networkCommand); } - results.push_back(result); + results.push_back(resultCur); } else{ - results.push_back(crFailUndefined); + results.push_back(std::pair(crFailUndefined,"")); } } return computeResult(results); } else{ - return crFailUndefined; + return std::pair(crFailUndefined,""); } } -CommandResult Commander::tryGiveCommand(const Selection *selection, +std::pair Commander::tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos, const Unit *targetUnit, bool tryQueue) const { + std::pair result(crFailUndefined,""); + if(!selection->isEmpty() && commandType!=NULL){ Vec2i refPos; CommandResultContainer results; @@ -352,7 +355,8 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Unit *unit = selection->getUnit(i); assert(unit != NULL); - CommandResult result = crFailUndefined; + std::pair resultCur(crFailUndefined,""); + bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); @@ -363,24 +367,24 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, cst_None, -1, unitCommandGroupId); //every unit is ordered to a different position - result= pushNetworkCommand(&networkCommand); + resultCur= pushNetworkCommand(&networkCommand); } - results.push_back(result); + results.push_back(resultCur); } return computeResult(results); } else{ - return crFailUndefined; + return std::pair(crFailUndefined,""); } } //auto command -CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, +std::pair Commander::tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit, bool tryQueue, int unitCommandGroupId) const { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result = crFailUndefined; + std::pair result(crFailUndefined,""); if(selection->isEmpty() == false){ Vec2i refPos, currPos; @@ -407,26 +411,27 @@ CommandResult Commander::tryGiveCommand(const Selection *selection, const Vec2i int targetId= targetUnit==NULL? Unit::invalidId: targetUnit->getId(); int unitId= unit->getId(); - CommandResult result = crFailUndefined; + std::pair resultCur(crFailUndefined,""); + bool canSubmitCommand=canSubmitCommandType(unit, commandType); if(canSubmitCommand == true) { NetworkCommand networkCommand(this->world,nctGiveCommand, unitId, commandType->getId(), currPos, -1, targetId, -1, tryQueue, cst_None, -1, unitCommandGroupId); - result= pushNetworkCommand(&networkCommand); + resultCur= pushNetworkCommand(&networkCommand); } - results.push_back(result); + results.push_back(resultCur); } else if(unit->isMeetingPointSettable() == true) { NetworkCommand command(this->world,nctSetMeetingPoint, unit->getId(), -1, currPos,-1,-1,-1,false, cst_None,-1,unitCommandGroupId); - CommandResult result= pushNetworkCommand(&command); - results.push_back(result); + std::pair resultCur= pushNetworkCommand(&command); + results.push_back(resultCur); } else { - results.push_back(crFailUndefined); + results.push_back(std::pair(crFailUndefined,"")); } } result = computeResult(results); @@ -491,25 +496,27 @@ void Commander::tryNetworkPlayerDisconnected(int factionIndex) const { // ==================== PRIVATE ==================== -CommandResult Commander::computeResult(const CommandResultContainer &results) const { +std::pair Commander::computeResult(const CommandResultContainer &results) const { + std::pair result(crFailUndefined,""); switch(results.size()) { case 0: - return crFailUndefined; + return std::pair(crFailUndefined,""); case 1: return results.front(); default: for(int i = 0; i < results.size(); ++i) { - if(results[i] != crSuccess) { - return crSomeFailed; + if(results[i].first != crSuccess) { + return std::pair(crSomeFailed,results[i].second); } } - return crSuccess; + break; } + return std::pair(crSuccess,""); } -CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand) const { +std::pair Commander::pushNetworkCommand(const NetworkCommand* networkCommand) const { GameNetworkInterface *gameNetworkInterface= NetworkManager::getInstance().getGameNetworkInterface(); - CommandResult cr= crSuccess; + std::pair result(crSuccess,""); //validate unit const Unit* unit = NULL; @@ -538,10 +545,10 @@ CommandResult Commander::pushNetworkCommand(const NetworkCommand* networkCommand //calculate the result of the command if(networkCommand->getNetworkCommandType() == nctGiveCommand) { Command* command= buildCommand(networkCommand); - cr= unit->checkCommand(command); + result= unit->checkCommand(command); delete command; } - return cr; + return result; } void Commander::signalNetworkUpdate(Game *game) { diff --git a/source/glest_game/game/commander.h b/source/glest_game/game/commander.h index 5869ed67..4ba5c25c 100644 --- a/source/glest_game/game/commander.h +++ b/source/glest_game/game/commander.h @@ -77,7 +77,7 @@ public: class Commander : public CommanderNetworkCallbackInterface { private: - typedef vector CommandResultContainer; + typedef vector > CommandResultContainer; private: World *world; @@ -100,14 +100,14 @@ public: bool hasReplayCommandListForFrame() const; int getReplayCommandListForFrameCount() const; - CommandResult tryGiveCommand(const Selection *selection, const CommandType *commandType, + std::pair 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,int unitGroupCommandId=-1) 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; - CommandResult tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit= NULL, bool tryQueue = false, int unitCommandGroupId = -1) const; + std::pair tryGiveCommand(const Unit* unit, const CommandType *commandType, const Vec2i &pos, const UnitType* unitType, CardinalDir facing, bool tryQueue = false,Unit *targetUnit=NULL,int unitGroupCommandId=-1) const; + std::pair tryGiveCommand(const Selection *selection, CommandClass commandClass, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const; + std::pair tryGiveCommand(const Selection *selection, const CommandType *commandType, const Vec2i &pos= Vec2i(0), const Unit *targetUnit= NULL, bool tryQueue = false) const; + std::pair tryGiveCommand(const Selection *selection, const Vec2i &pos, const Unit *targetUnit= NULL, bool tryQueue = false, int unitCommandGroupId = -1) const; CommandResult tryCancelCommand(const Selection *selection) const; void trySetMeetingPoint(const Unit* unit, const Vec2i &pos) const; void trySwitchTeam(const Faction* faction, int teamIndex) const; @@ -120,10 +120,10 @@ public: Command* buildCommand(const NetworkCommand* networkCommand) const; private: - CommandResult pushNetworkCommand(const NetworkCommand* networkCommand) const; + std::pair pushNetworkCommand(const NetworkCommand* networkCommand) const; //void giveNetworkCommandSpecial(const NetworkCommand* networkCommand) const; - CommandResult computeResult(const CommandResultContainer &results) const; + std::pair computeResult(const CommandResultContainer &results) const; void giveNetworkCommand(NetworkCommand* networkCommand) const; virtual void commanderNetworkUpdateTask(int id); diff --git a/source/glest_game/game/console.cpp b/source/glest_game/game/console.cpp index d340e2f4..f89bf132 100644 --- a/source/glest_game/game/console.cpp +++ b/source/glest_game/game/console.cpp @@ -58,6 +58,15 @@ void Console::addStdMessage(const string &s,bool clearOtherLines) { } } +void Console::addStdMessage(const string &s,string failText, bool clearOtherLines) { + if(clearOtherLines == true) { + addLineOnly(Lang::getInstance().get(s) + failText); + } + else { + addLine(Lang::getInstance().get(s) + failText); + } +} + void Console::addStdScenarioMessage(const string &s,bool clearOtherLines) { if(clearOtherLines == true) { addLineOnly(Lang::getInstance().getScenarioString(s)); diff --git a/source/glest_game/game/console.h b/source/glest_game/game/console.h index fc6dd9bb..4e8b6087 100644 --- a/source/glest_game/game/console.h +++ b/source/glest_game/game/console.h @@ -107,6 +107,8 @@ public: void clearStoredLines(); void addStdMessage(const string &s, bool clearOtherLines=false); + void addStdMessage(const string &s, string failText, bool clearOtherLines=false); + void addStdScenarioMessage(const string &s,bool clearOtherLines=false); void addLineOnly(string line); void addLine(string line, bool playSound= false,int playerIndex=-1,Vec3f textColor=Vec3f(1.f, 1.f, 1.f),bool teamMode=false,bool clearOtherLines=false); diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index d1a0384e..fdae7b8e 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -423,7 +423,7 @@ void Gui::onSelectionChanged(){ void Gui::giveOneClickOrders(){ //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result; + std::pair result(crFailUndefined,""); bool queueKeyDown = isKeyDown(queueCommandKey); if(selection.isUniform()){ result= commander->tryGiveCommand(&selection, activeCommandType, Vec2i(0), (Unit*)NULL, queueKeyDown); @@ -458,11 +458,11 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse bool queueKeyDown = isKeyDown(queueCommandKey); Vec2i targetPos=Vec2i(x, y); //give order - CommandResult result= commander->tryGiveCommand(&selection, targetPos, targetUnit, queueKeyDown); + std::pair result= commander->tryGiveCommand(&selection, targetPos, targetUnit, queueKeyDown); //graphical result addOrdersResultToConsole(activeCommandClass, result); - if(result == crSuccess || result == crSomeFailed) { + if(result.first == crSuccess || result.first == crSomeFailed) { if(paintMouse3d) mouse3d.enable(); @@ -480,7 +480,7 @@ void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit, bool paintMouse void Gui::giveTwoClickOrders(int x, int y , bool prepared) { //printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - CommandResult result; + std::pair result(crFailUndefined,""); //compute target const Unit *targetUnit= NULL; @@ -516,7 +516,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) { //graphical result addOrdersResultToConsole(activeCommandClass, result); - if(result == crSuccess || result == crSomeFailed) { + if(result.first == crSuccess || result.first == crSomeFailed) { if(prepared == false) { mouse3d.enable(); } @@ -950,24 +950,24 @@ int Gui::computePosDisplay(int x, int y){ return posDisplay; } -void Gui::addOrdersResultToConsole(CommandClass cc, CommandResult result){ +void Gui::addOrdersResultToConsole(CommandClass cc, std::pair result) { - switch(result){ + switch(result.first) { case crSuccess: break; case crFailReqs: switch(cc){ case ccBuild: - console->addStdMessage("BuildingNoReqs"); + console->addStdMessage("BuildingNoReqs",result.second); break; case ccProduce: - console->addStdMessage("UnitNoReqs"); + console->addStdMessage("UnitNoReqs",result.second); break; case ccMorph: - console->addStdMessage("MorphNoReqs"); + console->addStdMessage("MorphNoReqs",result.second); break; case ccUpgrade: - console->addStdMessage("UpgradeNoReqs"); + console->addStdMessage("UpgradeNoReqs",result.second); break; default: break; @@ -976,16 +976,16 @@ void Gui::addOrdersResultToConsole(CommandClass cc, CommandResult result){ case crFailRes: switch(cc){ case ccBuild: - console->addStdMessage("BuildingNoRes"); + console->addStdMessage("BuildingNoRes",result.second); break; case ccProduce: - console->addStdMessage("UnitNoRes"); + console->addStdMessage("UnitNoRes",result.second); break; case ccMorph: - console->addStdMessage("MorphNoRes"); + console->addStdMessage("MorphNoRes",result.second); break; case ccUpgrade: - console->addStdMessage("UpgradeNoRes"); + console->addStdMessage("UpgradeNoRes",result.second); break; default: break; @@ -993,11 +993,11 @@ void Gui::addOrdersResultToConsole(CommandClass cc, CommandResult result){ break; case crFailUndefined: - console->addStdMessage("InvalidOrder"); + console->addStdMessage("InvalidOrder",result.second); break; case crSomeFailed: - console->addStdMessage("SomeOrdersFailed"); + console->addStdMessage("SomeOrdersFailed",result.second); break; } } diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 4f32d928..c9c8905c 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -226,7 +226,7 @@ private: void mouseDownDisplayUnitBuild(int posDisplay); void computeInfoString(int posDisplay); string computeDefaultInfoString(); - void addOrdersResultToConsole(CommandClass cc, CommandResult rr); + void addOrdersResultToConsole(CommandClass cc, std::pair result); bool isSharedCommandClass(CommandClass commandClass); void computeSelected(bool doubleCkick,bool force); bool computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 0349dcf8..5e5347e1 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1357,9 +1357,10 @@ int Unit::getCountOfProducedUnits(const UnitType *ut) const{ } //give one command (clear, and push back) -CommandResult Unit::giveCommand(Command *command, bool tryQueue) { +std::pair Unit::giveCommand(Command *command, bool tryQueue) { if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"\n======================\nUnit Command tryQueue = %d\nUnit Info:\n%s\nCommand Info:\n%s\n",tryQueue,this->toString().c_str(),command->toString().c_str()); + std::pair result(crFailUndefined,""); changedActiveCommand = false; Chrono chrono; @@ -1457,21 +1458,21 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue) { 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()); //check command - CommandResult result= checkCommand(command); - if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] checkCommand returned: [%d]\n",__FILE__,__FUNCTION__,__LINE__,result); + result= checkCommand(command); + if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d] checkCommand returned: [%d]\n",__FILE__,__FUNCTION__,__LINE__,result.first); //printf("In [%s::%s] Line: %d check command returned %d, commands.size() = %d\n[%s]\n\n",__FILE__,__FUNCTION__,__LINE__,result,commands.size(),command->toString().c_str()); 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()); - if(result == crSuccess) { + if(result.first == crSuccess) { applyCommand(command); } 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()); //push back command - if(result == crSuccess) { + if(result.first == crSuccess) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(mutexCommands,mutexOwnerId); @@ -2811,7 +2812,9 @@ void Unit::deleteQueuedCommand(Command *command) { } -CommandResult Unit::checkCommand(Command *command) const { +std::pair Unit::checkCommand(Command *command) const { + std::pair result(crSuccess,""); + if(command == NULL) { char szBuf[8096]=""; snprintf(szBuf,8096,"In [%s::%s Line: %d] ERROR: command == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str()); @@ -2832,14 +2835,16 @@ CommandResult Unit::checkCommand(Command *command) const { } else { - return crFailUndefined; + result.first = crFailUndefined; + return result; } } //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()) == false) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); - return crFailUndefined; + result.first = crFailUndefined; + return result; } //check produced @@ -2852,12 +2857,21 @@ CommandResult Unit::checkCommand(Command *command) const { const ProducibleType *produced= command->getCommandType()->getProduced(); if(produced != NULL) { if(ignoreCheckCommand == false && faction->reqsOk(produced) == false) { - return crFailReqs; + //printf("To produce this unit you need:\n%s\n",produced->getUnitAndUpgradeReqDesc().c_str()); + result.first = crFailReqs; + + Lang &lang= Lang::getInstance(); + result.second = " - " + lang.get("Reqs") + " : " + produced->getUnitAndUpgradeReqDesc(false); + return result; } if(ignoreCheckCommand == false && faction->checkCosts(produced,command->getCommandType()) == false) { - return crFailRes; + //printf("To produce this unit you need:\n%s\n",produced->getResourceReqDesc().c_str()); + result.first = crFailRes; + Lang &lang= Lang::getInstance(); + result.second = " - " + lang.get("Reqs") + " : " + produced->getResourceReqDesc(false); + return result; } } @@ -2872,10 +2886,18 @@ CommandResult Unit::checkCommand(Command *command) const { } if(faction->reqsOk(builtUnit) == false) { - return crFailReqs; + //printf("To build this unit you need:\n%s\n",builtUnit->getUnitAndUpgradeReqDesc().c_str()); + result.first = crFailReqs; + Lang &lang= Lang::getInstance(); + result.second = " - " + lang.get("Reqs") + " : " + builtUnit->getUnitAndUpgradeReqDesc(false); + return result; } if(faction->checkCosts(builtUnit,NULL) == false) { - return crFailRes; + //printf("To build this unit you need:\n%s\n",builtUnit->getResourceReqDesc().c_str()); + result.first = crFailRes; + Lang &lang= Lang::getInstance(); + result.second = " - " + lang.get("Reqs") + " : " + builtUnit->getResourceReqDesc(false); + return result; } } //upgrade command specific, check that upgrade is not upgraded @@ -2890,11 +2912,12 @@ CommandResult Unit::checkCommand(Command *command) const { if(faction->getUpgradeManager()->isUpgradingOrUpgraded(uct->getProducedUpgrade())){ if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); - return crFailUndefined; + result.first = crFailUndefined; + return result; } } - return crSuccess; + return result; } void Unit::applyCommand(Command *command){ diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 54e1981a..5588bdaf 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -597,7 +597,7 @@ public: void replaceCurrCommand(Command *cmd); int getCountOfProducedUnits(const UnitType *ut) const; unsigned int getCommandSize() const; - CommandResult giveCommand(Command *command, bool tryQueue = false); //give a command + std::pair giveCommand(Command *command, bool tryQueue = false); //give a command CommandResult finishCommand(); //command finished CommandResult cancelCommand(); //cancel canceled @@ -633,7 +633,7 @@ public: void computeTotalUpgrade(); void incKills(int team); bool morph(const MorphCommandType *mct); - CommandResult checkCommand(Command *command) const; + std::pair checkCommand(Command *command) const; void applyCommand(Command *command); void setModelFacing(CardinalDir value); diff --git a/source/glest_game/types/element_type.cpp b/source/glest_game/types/element_type.cpp index c8d4d383..8ade151c 100644 --- a/source/glest_game/types/element_type.cpp +++ b/source/glest_game/types/element_type.cpp @@ -124,31 +124,60 @@ const Resource *ProducibleType::getCost(const ResourceType *rt) const{ string ProducibleType::getReqDesc() const { return getReqDesc(false); } -string ProducibleType::getReqDesc(bool ignoreResourceRequirements) const { - string str= getName(true) + " " + Lang::getInstance().get("Reqs") + ":\n"; - if(ignoreResourceRequirements == false) { - for(int i=0; igetAmount()!=0){ - str+= getCost(i)->getType()->getName(true); - str+= ": "+ intToStr(getCost(i)->getAmount()); + +string ProducibleType::getResourceReqDesc(bool lineBreaks) const { + string str= ""; + for(int i=0; igetAmount()!=0){ + str+= getCost(i)->getType()->getName(true); + str+= ": "+ intToStr(getCost(i)->getAmount()); + if(lineBreaks == true) { str+= "\n"; } + else { + str+= " "; + } } - } + } + return str; +} + +string ProducibleType::getUnitAndUpgradeReqDesc(bool lineBreaks) const { + string str= ""; for(int i=0; igetName(true); - str+= "\n"; + if(lineBreaks == true) { + str+= "\n"; + } + else { + str+= " "; + } } for(int i=0; igetName(true); - str+= "\n"; + if(lineBreaks == true) { + str+= "\n"; + } + else { + str+= " "; + } } return str; } +string ProducibleType::getReqDesc(bool ignoreResourceRequirements) const { + string str= getName(true) + " " + Lang::getInstance().get("Reqs") + ":\n"; + if(ignoreResourceRequirements == false) { + str+= getResourceReqDesc(); + } + + str+= getUnitAndUpgradeReqDesc(); + return str; +} + //void ProducibleType::saveGame(XmlNode *rootNode) const { // RequirableType::saveGame(rootNode); // diff --git a/source/glest_game/types/element_type.h b/source/glest_game/types/element_type.h index 1653ea92..99a3b3f5 100644 --- a/source/glest_game/types/element_type.h +++ b/source/glest_game/types/element_type.h @@ -119,6 +119,8 @@ public: void checkCostStrings(TechTree *techTree); virtual string getReqDesc() const; + string getResourceReqDesc(bool lineBreaks=true) const; + string getUnitAndUpgradeReqDesc(bool lineBreaks=true) const; string getReqDesc(bool ignoreResourceRequirements) const; // virtual void saveGame(XmlNode *rootNode) const; diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 7ac3c873..281fa360 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -1499,8 +1499,8 @@ void UnitUpdater::updateRepair(Unit *unit, int frameIndex) { if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); Command* command= this->game->getCommander()->buildCommand(&networkCommand); - CommandResult cr= unit->checkCommand(command); - if(cr == crSuccess) { + std::pair cr= unit->checkCommand(command); + if(cr.first == crSuccess) { if(SystemFlags::getSystemSettingType(SystemFlags::debugUnitCommands).enabled) SystemFlags::OutputDebug(SystemFlags::debugUnitCommands,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->replaceCurrCommand(command); } diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 6bdab99a..20ea7da8 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -869,7 +869,7 @@ void World::morphToUnit(int unitId,const string &morphName,bool ignoreRequiremen if(mct != NULL && mct->getName() == morphName) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] comparing mct [%s]\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),mct->getName().c_str()); - CommandResult cr = crFailUndefined; + std::pair cr(crFailUndefined,""); try { if(unit->getFaction()->reqsOk(mct) == false && ignoreRequirements == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] comparing mct [%s] mct->getUpgradeReqCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),mct->getName().c_str(),mct->getUpgradeReqCount()); @@ -886,14 +886,14 @@ void World::morphToUnit(int unitId,const string &morphName,bool ignoreRequiremen throw megaglest_runtime_error(ex.what()); } - if(cr == crSuccess) { + if(cr.first == crSuccess) { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } else { if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } - if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] comparing mct [%s] returned = %d\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),mct->getName().c_str(),cr); + if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d] unit [%d] morphName [%s] comparing mct [%s] returned = %d\n",__FILE__,__FUNCTION__,__LINE__,unitId,morphName.c_str(),mct->getName().c_str(),cr.first); break; }