From 8ea52485cceb5f4eb3ed1d74edd3647cea1b69be Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 31 May 2010 09:24:44 +0000 Subject: [PATCH] - Attempt to fix unit id allocation issues --- source/glest_game/game/commander.cpp | 2 +- source/glest_game/gui/selection.cpp | 8 ++++++-- source/glest_game/type_instances/unit.cpp | 3 ++- source/glest_game/world/unit_updater.cpp | 4 ++-- source/glest_game/world/world.cpp | 13 ++++++++++--- source/glest_game/world/world.h | 5 +++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/source/glest_game/game/commander.cpp b/source/glest_game/game/commander.cpp index 6c63d1a8..bb145ea3 100644 --- a/source/glest_game/game/commander.cpp +++ b/source/glest_game/game/commander.cpp @@ -336,7 +336,7 @@ void Commander::giveNetworkCommand(NetworkCommand* networkCommand) const { Command* command= buildCommand(networkCommand); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] command = %p\n",__FILE__,__FUNCTION__,__LINE__,command); unit->giveCommand(command, networkCommand->getWantQueue()); diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 0da69fe7..1ccda42b 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.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 @@ -15,6 +15,7 @@ #include "unit_type.h" #include "gui.h" +#include "config.h" #include "leak_dumper.h" using namespace std; @@ -37,7 +38,8 @@ Selection::~Selection(){ void Selection::select(Unit *unit){ //check size - if(selectedUnits.size()>=maxUnits){ + //if(selectedUnits.size() >= maxUnits){ + if(selectedUnits.size() >= Config::getInstance().getInt("MaxUnitSelectCount",intToStr(maxUnits).c_str())) { return; } @@ -73,6 +75,8 @@ void Selection::select(Unit *unit){ clear(); } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit selected [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str()); + unit->addObserver(this); selectedUnits.push_back(unit); gui->onSelectionChanged(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 5fdcce60..617230b3 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -508,7 +508,8 @@ unsigned int Unit::getCommandSize() const{ //give one command (clear, and push back) CommandResult Unit::giveCommand(Command *command, bool tryQueue) { - 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->getName().c_str(), command->toString().c_str(),tryQueue); + 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); assert(command != NULL); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index 41d2bf94..0469993f 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -296,7 +296,7 @@ void UnitUpdater::updateBuild(Unit *unit){ if(map->isFreeCells(command->getPos(), ut->getSize(), fLand)){ const UnitType *builtUnitType= command->getUnitType(); CardinalDir facing = command->getFacing(); - Unit *builtUnit= new Unit(world->getNextUnitId(), command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing); + Unit *builtUnit= new Unit(world->getNextUnitId(unit->getFaction()), command->getPos(), builtUnitType, unit->getFaction(), world->getMap(), facing); builtUnit->create(); if(!builtUnitType->hasSkillClass(scBeBuilt)){ @@ -587,7 +587,7 @@ void UnitUpdater::updateProduce(Unit *unit){ if(unit->getProgress2()>pct->getProduced()->getProductionTime()){ unit->finishCommand(); unit->setCurrSkill(scStop); - produced= new Unit(world->getNextUnitId(), Vec2i(0), pct->getProducedUnit(), unit->getFaction(), world->getMap(), CardinalDir::NORTH); + produced= new Unit(world->getNextUnitId(unit->getFaction()), Vec2i(0), pct->getProducedUnit(), unit->getFaction(), world->getMap(), CardinalDir::NORTH); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to place unit for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,produced->toString().c_str()); diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index 1b39fc51..cca32de7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -49,7 +49,7 @@ World::World(){ fogOfWarSmoothingFrameSkip= config.getInt("FogOfWarSmoothingFrameSkip"); frameCount= 0; - nextUnitId= 0; + //nextUnitId= 0; scriptManager= NULL; this->game = NULL; @@ -390,7 +390,7 @@ void World::createUnit(const string &unitName, int factionIndex, const Vec2i &po const FactionType* ft= faction->getType(); const UnitType* ut= ft->getUnitType(unitName); - Unit* unit= new Unit(getNextUnitId(), pos, ut, faction, &map, CardinalDir::NORTH); + Unit* unit= new Unit(getNextUnitId(faction), pos, ut, faction, &map, CardinalDir::NORTH); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] unit created for unit [%s]\n",__FILE__,__FUNCTION__,__LINE__,unit->toString().c_str()); @@ -667,7 +667,7 @@ void World::initUnits(){ const UnitType *ut= ft->getStartingUnit(j); int initNumber= ft->getStartingUnitAmount(j); for(int l=0; lgetStartLocationIndex(); @@ -814,6 +814,13 @@ void World::computeFow(){ } } +int World::getNextUnitId(Faction *faction) { + if(mapFactionNextUnitId.find(faction->getIndex()) == mapFactionNextUnitId.end()) { + mapFactionNextUnitId[faction->getIndex()] = faction->getIndex() * 3000; + } + return mapFactionNextUnitId[faction->getIndex()]++; +} + std::string World::DumpWorldToLog(bool consoleBasicInfoOnly) const { string debugWorldLogFile = Config::getInstance().getString("DebugWorldLogFile","debugWorld.log"); diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index d0e1cc53..d9cf81b7 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -82,7 +82,8 @@ private: int thisFactionIndex; int thisTeamIndex; int frameCount; - int nextUnitId; + //int nextUnitId; + std::map mapFactionNextUnitId; //config bool fogOfWarOverride; @@ -116,7 +117,7 @@ public: const Stats *getStats() const {return &stats;}; Stats *getStats() {return &stats;}; const WaterEffects *getWaterEffects() const {return &waterEffects;} - int getNextUnitId() {return nextUnitId++;} + int getNextUnitId(Faction *faction); int getFrameCount() const {return frameCount;} //init & load