2010-03-12 07:42:55 +00:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2010-03-19 18:58:46 +00:00
// Copyright (C) 2001-2008 Marti<74> o Figueroa
2010-03-12 07:42:55 +00:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
# include "world.h"
# include <algorithm>
# include <cassert>
# include "config.h"
# include "faction.h"
# include "unit.h"
# include "game.h"
# include "logger.h"
# include "sound_renderer.h"
# include "game_settings.h"
2010-05-03 06:25:54 +00:00
# include "cache_manager.h"
2010-05-20 20:19:34 +00:00
# include <iostream>
2010-03-12 07:42:55 +00:00
# include "leak_dumper.h"
using namespace Shared : : Graphics ;
using namespace Shared : : Util ;
namespace Glest { namespace Game {
// =====================================================
// class World
// =====================================================
const float World : : airHeight = 5.f ;
// ===================== PUBLIC ========================
World : : World ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
Config & config = Config : : getInstance ( ) ;
2010-05-03 06:25:54 +00:00
techTree = NULL ;
2010-04-23 02:48:56 +00:00
fogOfWarOverride = false ;
2010-03-12 07:42:55 +00:00
fogOfWarSmoothing = config . getBool ( " FogOfWarSmoothing " ) ;
fogOfWarSmoothingFrameSkip = config . getInt ( " FogOfWarSmoothingFrameSkip " ) ;
2010-07-06 19:24:36 +00:00
bool perfTimerEnabled = SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ;
2010-03-12 07:42:55 +00:00
frameCount = 0 ;
2010-05-31 09:24:44 +00:00
//nextUnitId= 0;
2010-03-12 07:42:55 +00:00
scriptManager = NULL ;
this - > game = NULL ;
2010-03-13 21:10:45 +00:00
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
World : : ~ World ( ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
delete techTree ;
techTree = NULL ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
void World : : end ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
Logger : : getInstance ( ) . add ( " World " , true ) ;
for ( int i = 0 ; i < factions . size ( ) ; + + i ) {
factions [ i ] . end ( ) ;
}
2010-04-23 02:48:56 +00:00
fogOfWarOverride = false ;
2010-03-12 07:42:55 +00:00
//stats will be deleted by BattleEnd
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
// ========================== init ===============================================
2010-04-23 02:48:56 +00:00
void World : : setFogOfWar ( bool value ) {
fogOfWar = value ;
fogOfWarOverride = true ;
if ( game ! = NULL & & game - > getGameSettings ( ) ! = NULL ) {
game - > getGameSettings ( ) - > setFogOfWar ( fogOfWar ) ;
initCells ( fogOfWar ) ; //must be done after knowing faction number and dimensions
2010-05-17 16:02:47 +00:00
//initMinimap();
minimap . setFogOfWar ( fogOfWar ) ;
computeFow ( ) ;
2010-04-23 02:48:56 +00:00
}
}
2010-03-12 07:42:55 +00:00
void World : : init ( Game * game , bool createUnits ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
this - > game = game ;
scriptManager = game - > getScriptManager ( ) ;
unitUpdater . init ( game ) ;
2010-03-27 07:09:34 +00:00
GameSettings * gs = game - > getGameSettings ( ) ;
2010-04-23 02:48:56 +00:00
if ( fogOfWarOverride = = false ) {
fogOfWar = gs - > getFogOfWar ( ) ;
}
2010-03-27 07:09:34 +00:00
initFactionTypes ( gs ) ;
initCells ( fogOfWar ) ; //must be done after knowing faction number and dimensions
2010-03-12 07:42:55 +00:00
initMap ( ) ;
initSplattedTextures ( ) ;
//minimap must be init after sum computation
initMinimap ( ) ;
if ( createUnits ) {
initUnits ( ) ;
}
2010-03-27 07:09:34 +00:00
//initExplorationState(); ... was only for !fog-of-war, now handled in initCells()
2010-03-12 07:42:55 +00:00
computeFow ( ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//load tileset
2010-03-18 21:26:40 +00:00
void World : : loadTileset ( const vector < string > pathList , const string & tilesetName , Checksum * checksum ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-18 21:26:40 +00:00
tileset . loadTileset ( pathList , tilesetName , checksum ) ;
2010-05-27 23:46:38 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-18 21:26:40 +00:00
timeFlow . init ( & tileset ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-18 21:26:40 +00:00
}
2010-03-12 07:42:55 +00:00
void World : : loadTileset ( const string & dir , Checksum * checksum ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
tileset . load ( dir , checksum ) ;
2010-05-27 23:46:38 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
timeFlow . init ( & tileset ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//load tech
2010-03-18 21:26:40 +00:00
void World : : loadTech ( const vector < string > pathList , const string & techName , set < string > & factions , Checksum * checksum ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
/*
std : : map < string , TechTree * > & techCache = Shared : : PlatformCommon : : CacheManager : : getCachedItem < std : : map < string , TechTree * > > ( " techCache " ) ;
if ( techCache . find ( techName ) ! = techCache . end ( ) ) {
techTree = new TechTree ( ) ;
* techTree = * techCache [ techName ] ;
return ;
}
*/
techTree = new TechTree ( ) ;
techTree - > loadTech ( pathList , techName , factions , checksum ) ;
//techCache[techName] = techTree;
2010-03-12 07:42:55 +00:00
}
//load map
void World : : loadMap ( const string & path , Checksum * checksum ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
checksum - > addFile ( path ) ;
2010-05-03 06:25:54 +00:00
map . load ( path , techTree , & tileset ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//load map
void World : : loadScenario ( const string & path , Checksum * checksum ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
checksum - > addFile ( path ) ;
scenario . load ( path ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
// ==================== misc ====================
void World : : update ( ) {
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true ) {
chronoPerfTimer . start ( ) ;
}
2010-03-12 07:42:55 +00:00
+ + frameCount ;
//time
timeFlow . update ( ) ;
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//water effects
waterEffects . update ( ) ;
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//units
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
for ( int j = 0 ; j < getFaction ( i ) - > getUnitCount ( ) ; + + j ) {
unitUpdater . updateUnit ( getFaction ( i ) - > getUnit ( j ) ) ;
}
}
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//undertake the dead
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
2010-04-20 02:19:37 +00:00
int unitCount = getFaction ( i ) - > getUnitCount ( ) ;
for ( int j = unitCount - 1 ; j > = 0 ; j - - ) {
2010-03-12 07:42:55 +00:00
Unit * unit = getFaction ( i ) - > getUnit ( j ) ;
2010-04-20 02:19:37 +00:00
if ( unit - > getToBeUndertaken ( ) ) {
2010-03-12 07:42:55 +00:00
unit - > undertake ( ) ;
delete unit ;
2010-04-20 02:19:37 +00:00
//j--;
2010-03-12 07:42:55 +00:00
}
}
}
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//food costs
2010-05-03 06:25:54 +00:00
for ( int i = 0 ; i < techTree - > getResourceTypeCount ( ) ; + + i ) {
const ResourceType * rt = techTree - > getResourceType ( i ) ;
2010-03-12 07:42:55 +00:00
if ( rt - > getClass ( ) = = rcConsumable & & frameCount % ( rt - > getInterval ( ) * GameConstants : : updateFps ) = = 0 ) {
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
getFaction ( i ) - > applyCostsOnInterval ( ) ;
}
}
}
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//fow smoothing
if ( fogOfWarSmoothing & & ( ( frameCount + 1 ) % ( fogOfWarSmoothingFrameSkip + 1 ) ) = = 0 ) {
float fogFactor = static_cast < float > ( frameCount % GameConstants : : updateFps ) / GameConstants : : updateFps ;
minimap . updateFowTex ( clamp ( fogFactor , 0.f , 1.f ) ) ;
}
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
//tick
if ( frameCount % GameConstants : : updateFps = = 0 ) {
computeFow ( ) ;
tick ( ) ;
}
2010-07-06 19:24:36 +00:00
if ( perfTimerEnabled = = true & & chronoPerfTimer . getMillis ( ) > 0 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld \n " , __FILE__ , __FUNCTION__ , __LINE__ , chronoPerfTimer . getMillis ( ) ) ;
2010-03-12 07:42:55 +00:00
}
void World : : tick ( ) {
if ( ! fogOfWarSmoothing ) {
minimap . updateFowTex ( 1.f ) ;
}
//increase hp
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
for ( int j = 0 ; j < getFaction ( i ) - > getUnitCount ( ) ; + + j ) {
getFaction ( i ) - > getUnit ( j ) - > tick ( ) ;
}
}
//compute resources balance
for ( int k = 0 ; k < getFactionCount ( ) ; + + k ) {
Faction * faction = getFaction ( k ) ;
//for each resource
2010-05-03 06:25:54 +00:00
for ( int i = 0 ; i < techTree - > getResourceTypeCount ( ) ; + + i ) {
const ResourceType * rt = techTree - > getResourceType ( i ) ;
2010-03-12 07:42:55 +00:00
//if consumable
if ( rt - > getClass ( ) = = rcConsumable ) {
int balance = 0 ;
for ( int j = 0 ; j < faction - > getUnitCount ( ) ; + + j ) {
//if unit operative and has this cost
const Unit * u = faction - > getUnit ( j ) ;
if ( u - > isOperative ( ) ) {
const Resource * r = u - > getType ( ) - > getCost ( rt ) ;
if ( r ! = NULL ) {
balance - = u - > getType ( ) - > getCost ( rt ) - > getAmount ( ) ;
}
}
}
faction - > setResourceBalance ( rt , balance ) ;
}
}
}
}
Unit * World : : findUnitById ( int id ) {
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
Faction * faction = getFaction ( i ) ;
for ( int j = 0 ; j < faction - > getUnitCount ( ) ; + + j ) {
Unit * unit = faction - > getUnit ( j ) ;
if ( unit - > getId ( ) = = id ) {
return unit ;
}
}
}
return NULL ;
}
const UnitType * World : : findUnitTypeById ( const FactionType * factionType , int id ) {
for ( int i = 0 ; i < factionType - > getUnitTypeCount ( ) ; + + i ) {
const UnitType * unitType = factionType - > getUnitType ( i ) ;
if ( unitType - > getId ( ) = = id ) {
return unitType ;
}
}
return NULL ;
}
//looks for a place for a unit around a start lociacion, returns true if succeded
bool World : : placeUnit ( const Vec2i & startLoc , int radius , Unit * unit , bool spaciated ) {
bool freeSpace ;
int size = unit - > getType ( ) - > getSize ( ) ;
Field currField = unit - > getCurrField ( ) ;
for ( int r = 1 ; r < radius ; r + + ) {
for ( int i = - r ; i < r ; + + i ) {
for ( int j = - r ; j < r ; + + j ) {
Vec2i pos = Vec2i ( i , j ) + startLoc ;
if ( spaciated ) {
const int spacing = 2 ;
freeSpace = map . isFreeCells ( pos - Vec2i ( spacing ) , size + spacing * 2 , currField ) ;
}
else {
freeSpace = map . isFreeCells ( pos , size , currField ) ;
}
if ( freeSpace ) {
unit - > setPos ( pos ) ;
unit - > setMeetingPos ( pos - Vec2i ( 1 ) ) ;
return true ;
}
}
}
}
return false ;
}
//clears a unit old position from map and places new position
void World : : moveUnitCells ( Unit * unit ) {
Vec2i newPos = unit - > getTargetPos ( ) ;
//newPos must be free or the same pos as current
assert ( map . getCell ( unit - > getPos ( ) ) - > getUnit ( unit - > getCurrField ( ) ) = = unit | | map . isFreeCell ( newPos , unit - > getCurrField ( ) ) ) ;
map . clearUnitCells ( unit , unit - > getPos ( ) ) ;
map . putUnitCells ( unit , newPos ) ;
//water splash
if ( tileset . getWaterEffects ( ) & & unit - > getCurrField ( ) = = fLand ) {
if ( map . getSubmerged ( map . getCell ( unit - > getLastPos ( ) ) ) ) {
2010-05-07 08:01:14 +00:00
int unitSize = unit - > getType ( ) - > getSize ( ) ;
2010-03-12 07:42:55 +00:00
for ( int i = 0 ; i < 3 ; + + i ) {
waterEffects . addWaterSplash (
2010-05-07 08:01:14 +00:00
Vec2f ( unit - > getLastPos ( ) . x + ( float ) unitSize / 2.0f + random . randRange ( - 0.9f , - 0.1f ) , unit - > getLastPos ( ) . y + random . randRange ( - 0.9f , - 0.1f ) + ( float ) unitSize / 2.0f ) , unit - > getType ( ) - > getSize ( ) ) ;
2010-03-12 07:42:55 +00:00
}
}
}
}
//returns the nearest unit that can store a type of resource given a position and a faction
Unit * World : : nearestStore ( const Vec2i & pos , int factionIndex , const ResourceType * rt ) {
float currDist = infinity ;
Unit * currUnit = NULL ;
for ( int i = 0 ; i < getFaction ( factionIndex ) - > getUnitCount ( ) ; + + i ) {
Unit * u = getFaction ( factionIndex ) - > getUnit ( i ) ;
float tmpDist = u - > getPos ( ) . dist ( pos ) ;
if ( tmpDist < currDist & & u - > getType ( ) - > getStore ( rt ) > 0 & & u - > isOperative ( ) ) {
currDist = tmpDist ;
currUnit = u ;
}
}
return currUnit ;
}
bool World : : toRenderUnit ( const Unit * unit , const Quad2i & visibleQuad ) const {
//a unit is rendered if it is in a visible cell or is attacking a unit in a visible cell
return
visibleQuad . isInside ( unit - > getPos ( ) ) & &
toRenderUnit ( unit ) ;
}
bool World : : toRenderUnit ( const Unit * unit ) const {
return
2010-06-16 07:18:06 +00:00
( map . getSurfaceCell ( Map : : toSurfCoords ( unit - > getCenteredPos ( ) ) ) - > isVisible ( thisTeamIndex ) & &
map . getSurfaceCell ( Map : : toSurfCoords ( unit - > getCenteredPos ( ) ) ) - > isExplored ( thisTeamIndex ) ) | |
2010-03-12 07:42:55 +00:00
( unit - > getCurrSkill ( ) - > getClass ( ) = = scAttack & &
2010-06-16 07:18:06 +00:00
map . getSurfaceCell ( Map : : toSurfCoords ( unit - > getTargetPos ( ) ) ) - > isVisible ( thisTeamIndex ) & &
map . getSurfaceCell ( Map : : toSurfCoords ( unit - > getTargetPos ( ) ) ) - > isExplored ( thisTeamIndex ) ) ;
2010-03-12 07:42:55 +00:00
}
void World : : createUnit ( const string & unitName , int factionIndex , const Vec2i & pos ) {
2010-05-01 10:46:56 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] unitName [%s] factionIndex = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , unitName . c_str ( ) , factionIndex ) ;
2010-03-12 07:42:55 +00:00
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
2010-05-29 09:38:00 +00:00
if ( faction - > getIndex ( ) ! = factionIndex ) {
throw runtime_error ( " faction->getIndex() ! = factionIndex " ) ;
}
2010-03-12 07:42:55 +00:00
const FactionType * ft = faction - > getType ( ) ;
const UnitType * ut = ft - > getUnitType ( unitName ) ;
2010-05-31 09:24:44 +00:00
Unit * unit = new Unit ( getNextUnitId ( faction ) , pos , ut , faction , & map , CardinalDir : : NORTH ) ;
2010-03-12 07:42:55 +00:00
2010-05-29 09:38:00 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] unit created for unit [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , unit - > toString ( ) . c_str ( ) ) ;
2010-03-12 07:42:55 +00:00
if ( placeUnit ( pos , generationArea , unit , true ) ) {
unit - > create ( true ) ;
unit - > born ( ) ;
scriptManager - > onUnitCreated ( unit ) ;
}
else {
throw runtime_error ( " Unit cant be placed " ) ;
}
2010-05-29 09:38:00 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] unit created for unit [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , unit - > toString ( ) . c_str ( ) ) ;
2010-03-12 07:42:55 +00:00
}
else
{
throw runtime_error ( " Invalid faction index in createUnitAtPosition: " + intToStr ( factionIndex ) ) ;
}
2010-05-01 10:46:56 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
void World : : giveResource ( const string & resourceName , int factionIndex , int amount ) {
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
2010-05-03 06:25:54 +00:00
const ResourceType * rt = techTree - > getResourceType ( resourceName ) ;
2010-03-12 07:42:55 +00:00
faction - > incResourceAmount ( rt , amount ) ;
}
else
{
throw runtime_error ( " Invalid faction index in giveResource: " + intToStr ( factionIndex ) ) ;
}
}
void World : : givePositionCommand ( int unitId , const string & commandName , const Vec2i & pos ) {
Unit * unit = findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
CommandClass cc ;
if ( commandName = = " move " ) {
cc = ccMove ;
}
else if ( commandName = = " attack " ) {
cc = ccAttack ;
}
else {
throw runtime_error ( " Invalid position commmand: " + commandName ) ;
}
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] cc = %d Unit [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , cc , unit - > getFullName ( ) . c_str ( ) ) ;
2010-03-12 07:42:55 +00:00
unit - > giveCommand ( new Command ( unit - > getType ( ) - > getFirstCtOfClass ( cc ) , pos ) ) ;
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
}
void World : : giveProductionCommand ( int unitId , const string & producedName ) {
Unit * unit = findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
const UnitType * ut = unit - > getType ( ) ;
//Search for a command that can produce the unit
for ( int i = 0 ; i < ut - > getCommandTypeCount ( ) ; + + i ) {
const CommandType * ct = ut - > getCommandType ( i ) ;
if ( ct - > getClass ( ) = = ccProduce ) {
const ProduceCommandType * pct = static_cast < const ProduceCommandType * > ( ct ) ;
if ( pct - > getProducedUnit ( ) - > getName ( ) = = producedName ) {
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
unit - > giveCommand ( new Command ( pct ) ) ;
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
break ;
}
}
}
}
}
void World : : giveUpgradeCommand ( int unitId , const string & upgradeName ) {
Unit * unit = findUnitById ( unitId ) ;
if ( unit ! = NULL ) {
const UnitType * ut = unit - > getType ( ) ;
//Search for a command that can produce the unit
for ( int i = 0 ; i < ut - > getCommandTypeCount ( ) ; + + i ) {
const CommandType * ct = ut - > getCommandType ( i ) ;
if ( ct - > getClass ( ) = = ccUpgrade ) {
const UpgradeCommandType * uct = static_cast < const UpgradeCommandType * > ( ct ) ;
if ( uct - > getProducedUpgrade ( ) - > getName ( ) = = upgradeName ) {
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
unit - > giveCommand ( new Command ( uct ) ) ;
2010-05-01 09:27:08 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
break ;
}
}
}
}
}
int World : : getResourceAmount ( const string & resourceName , int factionIndex ) {
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
2010-05-03 06:25:54 +00:00
const ResourceType * rt = techTree - > getResourceType ( resourceName ) ;
2010-03-12 07:42:55 +00:00
return faction - > getResource ( rt ) - > getAmount ( ) ;
}
else
{
throw runtime_error ( " Invalid faction index in giveResource: " + intToStr ( factionIndex ) ) ;
}
}
Vec2i World : : getStartLocation ( int factionIndex ) {
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
return map . getStartLocation ( faction - > getStartLocationIndex ( ) ) ;
}
else
{
throw runtime_error ( " Invalid faction index in getStartLocation: " + intToStr ( factionIndex ) ) ;
}
}
Vec2i World : : getUnitPosition ( int unitId ) {
Unit * unit = findUnitById ( unitId ) ;
if ( unit = = NULL ) {
throw runtime_error ( " Can not find unit to get position " ) ;
}
return unit - > getPos ( ) ;
}
int World : : getUnitFactionIndex ( int unitId ) {
Unit * unit = findUnitById ( unitId ) ;
if ( unit = = NULL ) {
throw runtime_error ( " Can not find unit to get position " ) ;
}
return unit - > getFactionIndex ( ) ;
}
int World : : getUnitCount ( int factionIndex ) {
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
int count = 0 ;
for ( int i = 0 ; i < faction - > getUnitCount ( ) ; + + i ) {
const Unit * unit = faction - > getUnit ( i ) ;
if ( unit - > isAlive ( ) ) {
+ + count ;
}
}
return count ;
}
else
{
throw runtime_error ( " Invalid faction index in getUnitCount: " + intToStr ( factionIndex ) ) ;
}
}
int World : : getUnitCountOfType ( int factionIndex , const string & typeName ) {
if ( factionIndex < factions . size ( ) ) {
Faction * faction = & factions [ factionIndex ] ;
int count = 0 ;
for ( int i = 0 ; i < faction - > getUnitCount ( ) ; + + i ) {
const Unit * unit = faction - > getUnit ( i ) ;
if ( unit - > isAlive ( ) & & unit - > getType ( ) - > getName ( ) = = typeName ) {
+ + count ;
}
}
return count ;
}
else
{
throw runtime_error ( " Invalid faction index in getUnitCountOfType: " + intToStr ( factionIndex ) ) ;
}
}
// ==================== PRIVATE ====================
// ==================== private init ====================
//init basic cell state
2010-03-27 07:09:34 +00:00
void World : : initCells ( bool fogOfWar ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
Logger : : getInstance ( ) . add ( " State cells " , true ) ;
for ( int i = 0 ; i < map . getSurfaceW ( ) ; + + i ) {
for ( int j = 0 ; j < map . getSurfaceH ( ) ; + + j ) {
SurfaceCell * sc = map . getSurfaceCell ( i , j ) ;
sc - > setFowTexCoord ( Vec2f (
i / ( next2Power ( map . getSurfaceW ( ) ) - 1.f ) ,
j / ( next2Power ( map . getSurfaceH ( ) ) - 1.f ) ) ) ;
2010-04-23 04:29:11 +00:00
for ( int k = 0 ; k < GameConstants : : maxPlayers ; k + + ) {
sc - > setExplored ( k , ! fogOfWar ) ;
sc - > setVisible ( k , ! fogOfWar ) ;
2010-03-27 07:09:34 +00:00
}
2010-03-12 07:42:55 +00:00
}
}
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//init surface textures
void World : : initSplattedTextures ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
for ( int i = 0 ; i < map . getSurfaceW ( ) - 1 ; + + i ) {
for ( int j = 0 ; j < map . getSurfaceH ( ) - 1 ; + + j ) {
Vec2f coord ;
const Texture2D * texture ;
SurfaceCell * sc00 = map . getSurfaceCell ( i , j ) ;
SurfaceCell * sc10 = map . getSurfaceCell ( i + 1 , j ) ;
SurfaceCell * sc01 = map . getSurfaceCell ( i , j + 1 ) ;
SurfaceCell * sc11 = map . getSurfaceCell ( i + 1 , j + 1 ) ;
tileset . addSurfTex (
sc00 - > getSurfaceType ( ) ,
sc10 - > getSurfaceType ( ) ,
sc01 - > getSurfaceType ( ) ,
sc11 - > getSurfaceType ( ) ,
coord , texture ) ;
sc00 - > setSurfTexCoord ( coord ) ;
sc00 - > setSurfaceTexture ( texture ) ;
}
}
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//creates each faction looking at each faction name contained in GameSettings
void World : : initFactionTypes ( GameSettings * gs ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
Logger : : getInstance ( ) . add ( " Faction types " , true ) ;
if ( gs - > getFactionCount ( ) > map . getMaxPlayers ( ) ) {
throw runtime_error ( " This map only supports " + intToStr ( map . getMaxPlayers ( ) ) + " players " ) ;
}
//create stats
stats . init ( gs - > getFactionCount ( ) , gs - > getThisFactionIndex ( ) , gs - > getDescription ( ) ) ;
//create factions
this - > thisFactionIndex = gs - > getThisFactionIndex ( ) ;
factions . resize ( gs - > getFactionCount ( ) ) ;
for ( int i = 0 ; i < factions . size ( ) ; + + i ) {
2010-05-03 06:25:54 +00:00
const FactionType * ft = techTree - > getType ( gs - > getFactionTypeName ( i ) ) ;
2010-03-12 07:42:55 +00:00
factions [ i ] . init (
2010-05-03 06:25:54 +00:00
ft , gs - > getFactionControl ( i ) , techTree , game , i , gs - > getTeam ( i ) ,
2010-03-12 07:42:55 +00:00
gs - > getStartLocationIndex ( i ) , i = = thisFactionIndex , gs - > getDefaultResources ( ) ) ;
stats . setTeam ( i , gs - > getTeam ( i ) ) ;
stats . setFactionTypeName ( i , formatString ( gs - > getFactionTypeName ( i ) ) ) ;
stats . setControl ( i , gs - > getFactionControl ( i ) ) ;
2010-06-24 01:23:18 +00:00
stats . setPlayerName ( i , gs - > getNetworkPlayerName ( i ) ) ;
stats . setPlayerColor ( i , getFaction ( i ) - > getTexture ( ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
2010-03-12 07:42:55 +00:00
}
thisTeamIndex = getFaction ( thisFactionIndex ) - > getTeam ( ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
void World : : initMinimap ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-27 07:09:34 +00:00
minimap . init ( map . getW ( ) , map . getH ( ) , this , game - > getGameSettings ( ) - > getFogOfWar ( ) ) ;
2010-03-12 07:42:55 +00:00
Logger : : getInstance ( ) . add ( " Compute minimap surface " , true ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
//place units randomly aroud start location
void World : : initUnits ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
Logger : : getInstance ( ) . add ( " Generate elements " , true ) ;
//put starting units
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
Faction * f = & factions [ i ] ;
const FactionType * ft = f - > getType ( ) ;
for ( int j = 0 ; j < ft - > getStartingUnitCount ( ) ; + + j ) {
const UnitType * ut = ft - > getStartingUnit ( j ) ;
int initNumber = ft - > getStartingUnitAmount ( j ) ;
for ( int l = 0 ; l < initNumber ; l + + ) {
2010-05-31 09:24:44 +00:00
Unit * unit = new Unit ( getNextUnitId ( f ) , Vec2i ( 0 ) , ut , f , & map , CardinalDir : : NORTH ) ;
2010-03-12 07:42:55 +00:00
int startLocationIndex = f - > getStartLocationIndex ( ) ;
if ( placeUnit ( map . getStartLocation ( startLocationIndex ) , generationArea , unit , true ) ) {
unit - > create ( true ) ;
unit - > born ( ) ;
}
else {
throw runtime_error ( " Unit cant be placed, this error is caused because there is no enough place to put the units near its start location, make a better map: " + unit - > getType ( ) - > getName ( ) + " Faction: " + intToStr ( i ) ) ;
}
if ( unit - > getType ( ) - > hasSkillClass ( scBeBuilt ) ) {
map . flatternTerrain ( unit ) ;
}
2010-05-29 09:38:00 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] unit created for unit [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , unit - > toString ( ) . c_str ( ) ) ;
2010-03-12 07:42:55 +00:00
}
}
}
map . computeNormals ( ) ;
map . computeInterpolatedHeights ( ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
void World : : initMap ( ) {
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
map . init ( ) ;
2010-05-03 06:25:54 +00:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-03-12 07:42:55 +00:00
}
// ==================== exploration ====================
void World : : exploreCells ( const Vec2i & newPos , int sightRange , int teamIndex ) {
Vec2i newSurfPos = Map : : toSurfCoords ( newPos ) ;
int surfSightRange = sightRange / Map : : cellScale + 1 ;
//explore
for ( int i = - surfSightRange - indirectSightRange - 1 ; i < = surfSightRange + indirectSightRange + 1 ; + + i ) {
for ( int j = - surfSightRange - indirectSightRange - 1 ; j < = surfSightRange + indirectSightRange + 1 ; + + j ) {
Vec2i currRelPos = Vec2i ( i , j ) ;
Vec2i currPos = newSurfPos + currRelPos ;
if ( map . isInsideSurface ( currPos ) ) {
SurfaceCell * sc = map . getSurfaceCell ( currPos ) ;
//explore
if ( Vec2i ( 0 ) . dist ( currRelPos ) < surfSightRange + indirectSightRange + 1 ) {
sc - > setExplored ( teamIndex , true ) ;
}
//visible
if ( Vec2i ( 0 ) . dist ( currRelPos ) < surfSightRange ) {
sc - > setVisible ( teamIndex , true ) ;
}
}
}
}
}
//computes the fog of war texture, contained in the minimap
void World : : computeFow ( ) {
//reset texture
minimap . resetFowTex ( ) ;
//reset cells
for ( int i = 0 ; i < map . getSurfaceW ( ) ; + + i ) {
for ( int j = 0 ; j < map . getSurfaceH ( ) ; + + j ) {
for ( int k = 0 ; k < GameConstants : : maxPlayers ; + + k ) {
if ( fogOfWar | | k ! = thisTeamIndex ) {
map . getSurfaceCell ( i , j ) - > setVisible ( k , false ) ;
}
}
}
}
//compute cells
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
for ( int j = 0 ; j < getFaction ( i ) - > getUnitCount ( ) ; + + j ) {
Unit * unit = getFaction ( i ) - > getUnit ( j ) ;
//exploration
if ( unit - > isOperative ( ) ) {
exploreCells ( unit - > getCenteredPos ( ) , unit - > getType ( ) - > getSight ( ) , unit - > getTeam ( ) ) ;
}
}
}
//fire
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
for ( int j = 0 ; j < getFaction ( i ) - > getUnitCount ( ) ; + + j ) {
Unit * unit = getFaction ( i ) - > getUnit ( j ) ;
//fire
ParticleSystem * fire = unit - > getFire ( ) ;
if ( fire ! = NULL ) {
fire - > setActive ( map . getSurfaceCell ( Map : : toSurfCoords ( unit - > getPos ( ) ) ) - > isVisible ( thisTeamIndex ) ) ;
}
}
}
//compute texture
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
Faction * faction = getFaction ( i ) ;
if ( faction - > getTeam ( ) = = thisTeamIndex ) {
for ( int j = 0 ; j < faction - > getUnitCount ( ) ; + + j ) {
const Unit * unit = faction - > getUnit ( j ) ;
if ( unit - > isOperative ( ) ) {
int sightRange = unit - > getType ( ) - > getSight ( ) ;
//iterate through all cells
PosCircularIterator pci ( & map , unit - > getPos ( ) , sightRange + indirectSightRange ) ;
while ( pci . next ( ) ) {
2010-07-06 19:24:36 +00:00
const Vec2i & pos = pci . getPos ( ) ;
2010-03-12 07:42:55 +00:00
Vec2i surfPos = Map : : toSurfCoords ( pos ) ;
//compute max alpha
float maxAlpha ;
if ( surfPos . x > 1 & & surfPos . y > 1 & & surfPos . x < map . getSurfaceW ( ) - 2 & & surfPos . y < map . getSurfaceH ( ) - 2 ) {
maxAlpha = 1.f ;
}
else if ( surfPos . x > 0 & & surfPos . y > 0 & & surfPos . x < map . getSurfaceW ( ) - 1 & & surfPos . y < map . getSurfaceH ( ) - 1 ) {
maxAlpha = 0.3f ;
}
else {
maxAlpha = 0.0f ;
}
//compute alpha
float alpha ;
float dist = unit - > getPos ( ) . dist ( pos ) ;
if ( dist > sightRange ) {
alpha = clamp ( 1.f - ( dist - sightRange ) / ( indirectSightRange ) , 0.f , maxAlpha ) ;
}
else {
alpha = maxAlpha ;
}
minimap . incFowTextureAlphaSurface ( surfPos , alpha ) ;
}
}
}
}
}
}
2010-05-31 09:45:54 +00:00
// WARNING! This id is critical! MAke sure it fits inside the network packet
// (currently cannot be larger than 2,147,483,647)
// Make sure each faction has their own unique section of id #'s for proper
// multi-platform play
// Calculates the unit unit ID for each faction
//
2010-05-31 09:24:44 +00:00
int World : : getNextUnitId ( Faction * faction ) {
if ( mapFactionNextUnitId . find ( faction - > getIndex ( ) ) = = mapFactionNextUnitId . end ( ) ) {
2010-05-31 09:45:54 +00:00
mapFactionNextUnitId [ faction - > getIndex ( ) ] = faction - > getIndex ( ) * 100000 ;
2010-05-31 09:24:44 +00:00
}
return mapFactionNextUnitId [ faction - > getIndex ( ) ] + + ;
}
2010-05-20 20:19:34 +00:00
std : : string World : : DumpWorldToLog ( bool consoleBasicInfoOnly ) const {
2010-05-18 03:53:57 +00:00
string debugWorldLogFile = Config : : getInstance ( ) . getString ( " DebugWorldLogFile " , " debugWorld.log " ) ;
2010-05-20 20:19:34 +00:00
if ( getGameReadWritePath ( ) ! = " " ) {
debugWorldLogFile = getGameReadWritePath ( ) + debugWorldLogFile ;
}
if ( consoleBasicInfoOnly = = true ) {
std : : cout < < " World debug information: " < < std : : endl ;
std : : cout < < " ======================== " < < std : : endl ;
//factions (and their related info)
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
std : : cout < < " Faction detail for index: " < < i < < std : : endl ;
std : : cout < < " -------------------------- " < < std : : endl ;
std : : cout < < " FactionName = " < < getFaction ( i ) - > getType ( ) - > getName ( ) < < std : : endl ;
std : : cout < < " FactionIndex = " < < intToStr ( getFaction ( i ) - > getIndex ( ) ) < < std : : endl ;
std : : cout < < " teamIndex = " < < intToStr ( getFaction ( i ) - > getTeam ( ) ) < < std : : endl ;
std : : cout < < " startLocationIndex = " < < intToStr ( getFaction ( i ) - > getStartLocationIndex ( ) ) < < std : : endl ;
std : : cout < < " thisFaction = " < < intToStr ( getFaction ( i ) - > getThisFaction ( ) ) < < std : : endl ;
std : : cout < < " control = " < < intToStr ( getFaction ( i ) - > getControlType ( ) ) < < std : : endl ;
}
}
else {
2010-05-18 03:53:57 +00:00
2010-05-20 20:19:34 +00:00
std : : ofstream logFile ;
logFile . open ( debugWorldLogFile . c_str ( ) , ios_base : : out | ios_base : : trunc ) ;
2010-05-18 03:53:57 +00:00
2010-05-20 20:19:34 +00:00
logFile < < " World debug information: " < < std : : endl ;
logFile < < " ======================== " < < std : : endl ;
2010-05-18 03:53:57 +00:00
2010-05-20 20:19:34 +00:00
//factions (and their related info)
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
logFile < < " Faction detail for index: " < < i < < std : : endl ;
logFile < < " -------------------------- " < < std : : endl ;
logFile < < getFaction ( i ) - > toString ( ) < < std : : endl ;
}
2010-05-18 03:53:57 +00:00
2010-05-20 20:19:34 +00:00
//undertake the dead
logFile < < " Undertake stats: " < < std : : endl ;
for ( int i = 0 ; i < getFactionCount ( ) ; + + i ) {
logFile < < " Faction: " < < getFaction ( i ) - > getType ( ) - > getName ( ) < < std : : endl ;
int unitCount = getFaction ( i ) - > getUnitCount ( ) ;
for ( int j = unitCount - 1 ; j > = 0 ; j - - ) {
Unit * unit = getFaction ( i ) - > getUnit ( j ) ;
if ( unit - > getToBeUndertaken ( ) ) {
logFile < < " Undertake unit index = " < < j < < unit - > getFullName ( ) < < std : : endl ;
}
2010-05-18 03:53:57 +00:00
}
}
2010-05-20 20:19:34 +00:00
logFile . close ( ) ;
}
2010-05-18 03:53:57 +00:00
return debugWorldLogFile ;
}
2010-03-12 07:42:55 +00:00
} } //end namespace