- Attempt to fix unit id allocation issues

This commit is contained in:
Mark Vejvoda 2010-05-31 09:24:44 +00:00
parent 0069fbf4f0
commit 8ea52485cc
6 changed files with 24 additions and 11 deletions

View File

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

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

View File

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

View File

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

View File

@ -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; l<initNumber; l++){
Unit *unit= new Unit(getNextUnitId(), Vec2i(0), ut, f, &map, CardinalDir::NORTH);
Unit *unit= new Unit(getNextUnitId(f), Vec2i(0), ut, f, &map, CardinalDir::NORTH);
int startLocationIndex= f->getStartLocationIndex();
@ -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");

View File

@ -82,7 +82,8 @@ private:
int thisFactionIndex;
int thisTeamIndex;
int frameCount;
int nextUnitId;
//int nextUnitId;
std::map<int,int> 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