Bugfix for cases where command cache was not yet initialized

This commit is contained in:
Mark Vejvoda 2010-05-01 09:27:08 +00:00
parent e379905942
commit 58386a72e8
7 changed files with 87 additions and 10 deletions

View File

@ -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 ====================

View File

@ -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());

View File

@ -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;

View File

@ -116,7 +116,8 @@ set<Unit*> 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__);

View File

@ -59,6 +59,14 @@ UnitType::UnitType(){
multiSelect= false;
armorType= NULL;
for(int i=0; i<ccCount; ++i){
firstCommandTypeOfClass[i]= NULL;
}
for(int i=0; i<scCount; ++i){
firstSkillTypeOfClass[i] = NULL;
}
for(int i=0; i<pCount; ++i){
properties[i]= false;
}
@ -379,15 +387,41 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
// ==================== get ====================
const CommandType *UnitType::getFirstCtOfClass(CommandClass commandClass) const{
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(firstCommandTypeOfClass[commandClass] == NULL) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
for(int j=0; j<ccCount; ++j){
for(int i=0; i<commandTypes.size(); ++i){
if(commandTypes[i]->getClass()== 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; j<scCount; ++j){
for(int i= 0; i<skillTypes.size(); ++i){
if(skillTypes[i]->getClass()== 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; i<commandTypes.size(); ++i){
for(int i=0; i<commandTypes.size(); ++i) {
if(commandTypes[i]->getClass()== ccHarvest){
const HarvestCommandType *hct= static_cast<const HarvestCommandType*>(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; j<ccCount; ++j){
firstCommandTypeOfClass[j]= NULL;

View File

@ -381,7 +381,9 @@ void World::givePositionCommand(int unitId, const string &commandName, const Vec
throw runtime_error("Invalid position commmand: " + commandName);
}
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cc = %d Unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,cc,unit->getFullName().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<const ProduceCommandType*>(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<const UpgradeCommandType*>(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;
}
}

View File

@ -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;