From 58386a72e8d14149372e588df2797e869b898dfc Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 1 May 2010 09:27:08 +0000 Subject: [PATCH] Bugfix for cases where command cache was not yet initialized --- source/glest_game/ai/ai_interface.cpp | 27 ++++++++++--- source/glest_game/game/commander.cpp | 1 + source/glest_game/type_instances/command.cpp | 7 +++- source/glest_game/type_instances/unit.cpp | 16 +++++++- source/glest_game/types/unit_type.cpp | 38 ++++++++++++++++++- source/glest_game/world/world.cpp | 6 +++ .../sources/platform/sdl/window.cpp | 2 +- 7 files changed, 87 insertions(+), 10 deletions(-) diff --git a/source/glest_game/ai/ai_interface.cpp b/source/glest_game/ai/ai_interface.cpp index 99a79c94..b9ef7614 100644 --- a/source/glest_game/ai/ai_interface.cpp +++ b/source/glest_game/ai/ai_interface.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -89,19 +89,36 @@ void AiInterface::printLog(int logLevel, const string &s){ CommandResult AiInterface::giveCommand(int unitIndex, CommandClass commandClass, const Vec2i &pos){ Command *c= new Command (world->getFaction(factionIndex)->getUnit(unitIndex)->getType()->getFirstCtOfClass(commandClass), pos); - return world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(c); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + CommandResult result = world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(c); + 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){ - return world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, pos)); + 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)); + 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){ - return world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, pos, ut, CardinalDir::NORTH)); + 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)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + return result; } CommandResult AiInterface::giveCommand(int unitIndex, const CommandType *commandType, Unit *u){ - return world->getFaction(factionIndex)->getUnit(unitIndex)->giveCommand(new Command(commandType, u)); + 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)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + return result; } // ==================== get data ==================== diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index cfe8939e..25235e86 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -310,6 +310,7 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); Command* command= buildCommand(networkCommand); + unit->giveCommand(command, networkCommand->getWantQueue()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found nctGiveCommand networkCommand->getUnitId() = %d\n",__FILE__,__FUNCTION__,__LINE__,networkCommand->getUnitId()); diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index fe467bd9..69daa7a9 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -13,6 +13,9 @@ #include "command_type.h" #include "leak_dumper.h" +#include "util.h" + +using namespace Shared::Util; namespace Glest{ namespace Game{ @@ -21,6 +24,8 @@ namespace Glest{ namespace Game{ // ===================================================== Command::Command(const CommandType *ct, const Vec2i &pos){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ct = [%p]\n",__FILE__,__FUNCTION__,__LINE__,ct); + this->commandType= ct; this->pos= pos; unitType= NULL; diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 1bf46421..eebebfa7 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -116,7 +116,8 @@ set Unit::livingUnitsp; Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing):id(id) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + allowRotateUnits = Config::getInstance().getBool("AllowRotateUnits","0"); modelFacing = CardinalDir::NORTH; @@ -169,11 +170,14 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map //starting skill this->currSkill=getType()->getFirstStOfClass(scStop); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); livingUnits.insert(id); livingUnitsp.insert(this); logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } Unit::~Unit(){ @@ -485,6 +489,16 @@ CommandResult Unit::giveCommand(Command *command, bool tryQueue){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); + assert(command != NULL); + + assert(command->getCommandType() != NULL); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,command->getCommandType()->getId()); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(command->getCommandType()->isQueuable(tryQueue)){ //cancel current command if it is not queuable SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index e94de839..ceb79e6c 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -59,6 +59,14 @@ UnitType::UnitType(){ multiSelect= false; armorType= NULL; + for(int i=0; igetClass()== CommandClass(j)){ + return commandTypes[i]; + } + } + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } return firstCommandTypeOfClass[commandClass]; } const SkillType *UnitType::getFirstStOfClass(SkillClass skillClass) const{ + if(firstSkillTypeOfClass[skillClass] == NULL) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + for(int j= 0; jgetClass()== SkillClass(j)){ + return skillTypes[i]; + } + } + } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + } return firstSkillTypeOfClass[skillClass]; } const HarvestCommandType *UnitType::getFirstHarvestCommand(const ResourceType *resourceType) const{ - for(int i=0; igetClass()== ccHarvest){ const HarvestCommandType *hct= static_cast(commandTypes[i]); if(hct->canHarvest(resourceType)){ @@ -546,7 +580,7 @@ void UnitType::computeFirstStOfClass(){ } void UnitType::computeFirstCtOfClass(){ - //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__); for(int j=0; jgetFullName().c_str()); unit->giveCommand(new Command( unit->getType()->getFirstCtOfClass(cc), pos )); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } } @@ -396,7 +398,9 @@ void World::giveProductionCommand(int unitId, const string &producedName){ if(ct->getClass()==ccProduce){ const ProduceCommandType *pct= static_cast(ct); if(pct->getProducedUnit()->getName()==producedName){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(pct)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); break; } } @@ -415,7 +419,9 @@ void World::giveUpgradeCommand(int unitId, const string &upgradeName){ if(ct->getClass()==ccUpgrade){ const UpgradeCommandType *uct= static_cast(ct); if(uct->getProducedUpgrade()->getName()==upgradeName){ + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); unit->giveCommand(new Command(uct)); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); break; } } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 4aae8aba..ab500954 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -18,7 +18,7 @@ #include "sdl_private.h" #include "noimpl.h" #include "util.h" -#include "SDL_syswm.h" +//#include "SDL_syswm.h" #include "leak_dumper.h" using namespace Shared::Util;