2010-07-11 20:31:02 +02:00
// This file is part of Glest (www.glest.org)
//
2011-12-14 08:40:48 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-07-11 20:31:02 +02: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 "path_finder.h"
# include <algorithm>
# include "config.h"
# include "map.h"
# include "unit.h"
# include "unit_type.h"
2010-08-22 22:13:30 +02:00
# include "platform_common.h"
2010-10-17 08:34:42 +02:00
# include "command.h"
2010-10-20 00:26:49 +02:00
# include "faction.h"
2011-01-28 08:17:32 +01:00
# include "randomgen.h"
2010-07-11 20:31:02 +02:00
# include "leak_dumper.h"
using namespace std ;
using namespace Shared : : Graphics ;
using namespace Shared : : Util ;
2010-08-22 22:13:30 +02:00
using namespace Shared : : PlatformCommon ;
2011-01-28 08:17:32 +01:00
using Shared : : Util : : RandomGen ;
2010-07-11 20:31:02 +02:00
namespace Glest { namespace Game {
// =====================================================
// class PathFinder
// =====================================================
// ===================== PUBLIC ========================
2011-01-28 08:17:32 +01:00
const int PathFinder : : maxFreeSearchRadius = 10 ;
2010-10-17 08:34:42 +02:00
//const int PathFinder::pathFindNodesMax= 400;
2011-04-14 04:51:13 +02:00
2011-06-25 20:14:20 +02:00
int PathFinder : : pathFindNodesAbsoluteMax = 900 ;
2011-09-24 22:30:41 +02:00
int PathFinder : : pathFindNodesMax = 2000 ;
2013-01-03 18:30:59 +01:00
//const int PathFinder::pathFindRefresh = 10;
2011-01-28 08:17:32 +01:00
const int PathFinder : : pathFindBailoutRadius = 20 ;
2011-04-26 23:51:18 +02:00
const int PathFinder : : pathFindExtendRefreshForNodeCount = 25 ;
2011-06-25 22:44:46 +02:00
const int PathFinder : : pathFindExtendRefreshNodeCountMin = 40 ;
2011-06-27 01:51:37 +02:00
const int PathFinder : : pathFindExtendRefreshNodeCountMax = 40 ;
2010-07-11 20:31:02 +02:00
2010-10-17 08:34:42 +02:00
PathFinder : : PathFinder ( ) {
2012-05-04 16:57:59 +02:00
minorDebugPathfinder = false ;
2013-02-04 09:30:43 +01:00
factionMutex = new Mutex ( ) ;
2011-03-18 04:53:06 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
factions . push_back ( FactionState ( ) ) ;
2012-05-04 16:57:59 +02:00
//factions.resize(GameConstants::maxPlayers);
2011-03-18 04:53:06 +01:00
}
2010-09-07 23:01:22 +02:00
map = NULL ;
2010-07-11 20:31:02 +02:00
}
2011-06-24 21:40:47 +02:00
int PathFinder : : getPathFindExtendRefreshNodeCount ( int factionIndex ) {
int refreshNodeCount = factions [ factionIndex ] . random . randRange ( PathFinder : : pathFindExtendRefreshNodeCountMin , PathFinder : : pathFindExtendRefreshNodeCountMax ) ;
return refreshNodeCount ;
}
2010-10-17 08:34:42 +02:00
PathFinder : : PathFinder ( const Map * map ) {
2012-05-04 16:57:59 +02:00
minorDebugPathfinder = false ;
2013-02-04 09:30:43 +01:00
factionMutex = new Mutex ( ) ;
2011-03-18 04:53:06 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
factions . push_back ( FactionState ( ) ) ;
2012-05-04 16:57:59 +02:00
//factions.resize(GameConstants::maxPlayers);
2011-03-18 04:53:06 +01:00
}
2010-09-07 23:01:22 +02:00
map = NULL ;
2010-07-30 03:05:52 +02:00
init ( map ) ;
2010-07-11 20:31:02 +02:00
}
2010-10-17 08:34:42 +02:00
void PathFinder : : init ( const Map * map ) {
2013-05-19 07:16:21 +02:00
//PathFinder::pathFindNodesMax = Config::getInstance().getInt("MaxPathfinderNodeCount",intToStr(PathFinder::pathFindNodesMax).c_str());
2011-03-18 04:53:06 +01:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2011-04-14 04:51:13 +02:00
factions [ i ] . nodePool . resize ( pathFindNodesAbsoluteMax ) ;
2011-03-18 04:53:06 +01:00
factions [ i ] . useMaxNodeCount = PathFinder : : pathFindNodesMax ;
}
2010-07-11 20:31:02 +02:00
this - > map = map ;
}
2013-05-17 07:21:14 +02:00
void PathFinder : : init ( ) {
minorDebugPathfinder = false ;
factionMutex = NULL ;
map = NULL ;
}
2011-03-18 04:53:06 +01:00
PathFinder : : ~ PathFinder ( ) {
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
factions [ i ] . nodePool . clear ( ) ;
}
2011-09-27 19:15:56 +02:00
factions . clear ( ) ;
2010-09-07 23:01:22 +02:00
map = NULL ;
2013-02-04 09:30:43 +01:00
delete factionMutex ;
factionMutex = NULL ;
2010-07-11 20:31:02 +02:00
}
2013-02-19 05:53:24 +01:00
void PathFinder : : clearCaches ( ) {
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
factions [ i ] . precachedTravelState . clear ( ) ;
factions [ i ] . precachedPath . clear ( ) ;
factions [ i ] . badCellList . clear ( ) ;
}
}
2011-03-18 04:53:06 +01:00
void PathFinder : : clearUnitPrecache ( Unit * unit ) {
2013-02-04 09:30:43 +01:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2013-05-20 04:51:26 +02:00
if ( unit ! = NULL & & factions . size ( ) > unit - > getFactionIndex ( ) ) {
factions [ unit - > getFactionIndex ( ) ] . precachedTravelState [ unit - > getId ( ) ] = tsImpossible ;
factions [ unit - > getFactionIndex ( ) ] . precachedPath [ unit - > getId ( ) ] . clear ( ) ;
factions [ unit - > getFactionIndex ( ) ] . badCellList . clear ( ) ;
}
2011-03-18 04:53:06 +01:00
}
2011-03-29 12:01:01 +02:00
void PathFinder : : removeUnitPrecache ( Unit * unit ) {
2013-02-04 09:30:43 +01:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2013-05-20 04:51:26 +02:00
if ( unit ! = NULL & & factions . size ( ) > unit - > getFactionIndex ( ) ) {
2013-09-19 03:19:36 +02:00
//bool clearTravelState = false;
//bool clearPath = false;
2013-05-20 04:51:26 +02:00
2011-03-29 12:01:01 +02:00
if ( factions [ unit - > getFactionIndex ( ) ] . precachedTravelState . find ( unit - > getId ( ) ) ! = factions [ unit - > getFactionIndex ( ) ] . precachedTravelState . end ( ) ) {
factions [ unit - > getFactionIndex ( ) ] . precachedTravelState . erase ( unit - > getId ( ) ) ;
2013-09-19 03:19:36 +02:00
//clearTravelState = true;
2011-03-29 12:01:01 +02:00
}
if ( factions [ unit - > getFactionIndex ( ) ] . precachedPath . find ( unit - > getId ( ) ) ! = factions [ unit - > getFactionIndex ( ) ] . precachedPath . end ( ) ) {
factions [ unit - > getFactionIndex ( ) ] . precachedPath . erase ( unit - > getId ( ) ) ;
2013-09-19 03:19:36 +02:00
//clearPath = true;
2013-05-20 04:51:26 +02:00
}
2013-09-12 05:33:43 +02:00
// if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
// char szBuf[8096]="";
// snprintf(szBuf,8096,"[removeUnitPrecache] clearTravelState: %d clearPath: %d",clearTravelState,clearPath);
// unit->logSynchData(extractFileFromDirectoryPath(__FILE__).c_str(),__LINE__,szBuf);
// }
2011-03-29 12:01:01 +02:00
}
}
2011-03-18 04:53:06 +01:00
TravelState PathFinder : : findPath ( Unit * unit , const Vec2i & finalPos , bool * wasStuck , int frameIndex ) {
2013-11-08 16:30:53 +01:00
TravelState ts = tsImpossible ;
string codeLocation = " 1 " ;
try {
2010-09-07 23:01:22 +02:00
if ( map = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " map == NULL " ) ;
2010-09-07 23:01:22 +02:00
}
2012-03-31 21:50:45 +02:00
2012-05-04 16:57:59 +02:00
unit - > setCurrentPathFinderDesiredFinalPos ( finalPos ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2012-05-10 01:56:14 +02:00
//printf("Unit Pathfind Unit [%d - %s] from = %s to = %s frameIndex = %d\n",unit->getId(),unit->getType()->getName().c_str(),unit->getPos().getString().c_str(),finalPos.getString().c_str(),frameIndex);
2011-03-18 04:53:06 +01:00
if ( frameIndex > = 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2011-03-18 04:53:06 +01:00
clearUnitPrecache ( unit ) ;
}
2013-05-20 04:51:26 +02:00
if ( unit - > getFaction ( ) - > canUnitsPathfind ( ) = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 3 " ;
2013-05-20 04:51:26 +02:00
unit - > getFaction ( ) - > addUnitToPathfindingList ( unit - > getId ( ) ) ;
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 4 " ;
2013-05-20 04:51:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " canUnitsPathfind() == false " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2012-03-31 21:50:45 +02:00
}
2013-05-20 04:51:26 +02:00
return tsBlocked ;
}
2010-11-09 10:06:52 +01:00
2011-04-03 04:42:45 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " [findPath] unit->getPos() [%s] finalPos [%s] " ,
2010-12-02 00:38:03 +01:00
unit - > getPos ( ) . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2010-11-09 10:06:52 +01:00
}
2010-07-11 20:31:02 +02:00
//route cache
2010-10-17 08:34:42 +02:00
if ( finalPos = = unit - > getPos ( ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 5 " ;
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 6 " ;
2011-03-18 04:53:06 +01:00
//if arrived
unit - > setCurrSkill ( scStop ) ;
2013-05-18 00:51:40 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Unit finalPos [%s] == unit->getPos() [%s] " , finalPos . getString ( ) . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-03-18 04:53:06 +01:00
}
2010-10-17 08:34:42 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
string commandDesc = " none " ;
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) ! = NULL ) {
2013-09-21 22:50:58 +02:00
commandDesc = command - > getCommandType ( ) - > toString ( false ) ;
2010-10-17 08:34:42 +02:00
}
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " State: arrived#1 at pos: %s, command [%s] " , finalPos . getString ( ) . c_str ( ) , commandDesc . c_str ( ) ) ;
2010-10-17 08:34:42 +02:00
unit - > setCurrentUnitTitle ( szBuf ) ;
}
2010-07-11 20:31:02 +02:00
return tsArrived ;
}
2010-10-26 08:43:42 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 7 " ;
2011-03-18 04:53:06 +01:00
UnitPathInterface * path = unit - > getPath ( ) ;
if ( path - > isEmpty ( ) = = false ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 8 " ;
2011-03-18 04:53:06 +01:00
if ( dynamic_cast < UnitPathBasic * > ( path ) ! = NULL ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 9 " ;
2011-03-18 04:53:06 +01:00
//route cache
UnitPathBasic * basicPath = dynamic_cast < UnitPathBasic * > ( path ) ;
Vec2i pos = basicPath - > pop ( frameIndex < 0 ) ;
if ( map - > canMove ( unit , unit - > getPos ( ) , pos ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 10 " ;
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 11 " ;
2010-07-21 20:21:40 +02:00
unit - > setTargetPos ( pos ) ;
2013-05-18 00:51:40 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " map->canMove to pos [%s] from [%s] " , pos . getString ( ) . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2010-07-21 20:21:40 +02:00
}
2013-05-21 07:43:57 +02:00
2011-03-18 04:53:06 +01:00
return tsMoving ;
2010-07-21 20:21:40 +02:00
}
2011-03-18 04:53:06 +01:00
}
else if ( dynamic_cast < UnitPath * > ( path ) ! = NULL ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 12 " ;
2011-03-18 04:53:06 +01:00
UnitPath * advPath = dynamic_cast < UnitPath * > ( path ) ;
//route cache
Vec2i pos = advPath - > peek ( ) ;
if ( map - > canMove ( unit , unit - > getPos ( ) , pos ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 13 " ;
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2010-07-21 21:17:45 +02:00
advPath - > pop ( ) ;
2010-07-21 20:21:40 +02:00
unit - > setTargetPos ( pos ) ;
}
2013-05-21 07:43:57 +02:00
2011-03-18 04:53:06 +01:00
return tsMoving ;
2010-07-21 20:21:40 +02:00
}
2011-03-18 04:53:06 +01:00
}
else {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " unsupported or missing path finder detected! " ) ;
2010-07-21 21:17:45 +02:00
}
2010-07-11 20:31:02 +02:00
}
2011-03-18 04:53:06 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 14 " ;
2013-02-22 07:52:51 +01:00
if ( path - > isStuck ( ) = = true & &
( unit - > getLastStuckPos ( ) = = finalPos | | path - > getBlockCount ( ) > 500 ) & &
2013-09-23 19:16:34 +02:00
unit - > isLastStuckFrameWithinCurrentFrameTolerance ( frameIndex > = 0 ) = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 15 " ;
2013-05-18 00:51:40 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
2013-09-23 19:16:34 +02:00
snprintf ( szBuf , 8096 , " path->isStuck() == true unit->getLastStuckPos() [%s] finalPos [%s] path->getBlockCount() [%d] " , unit - > getLastStuckPos ( ) . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , path - > getBlockCount ( ) ) ;
2013-05-18 00:51:40 +02:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-04-04 06:32:01 +02:00
//printf("$$$$ Unit STILL BLOCKED for [%d - %s]\n",unit->getId(),unit->getFullName().c_str());
return tsBlocked ;
}
2011-03-29 18:27:01 +02:00
//route cache miss
2013-11-08 16:30:53 +01:00
codeLocation = " 16 " ;
2011-04-14 04:51:13 +02:00
int maxNodeCount = - 1 ;
if ( unit - > getUsePathfinderExtendedMaxNodes ( ) = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 17 " ;
2011-04-14 04:51:13 +02:00
const bool showConsoleDebugInfo = Config : : getInstance ( ) . getBool ( " EnablePathfinderDistanceOutput " , " false " ) ;
if ( showConsoleDebugInfo | | SystemFlags : : VERBOSE_MODE_ENABLED ) {
2013-06-13 10:55:48 +02:00
printf ( " \n \n \n \n ### Continued call to AStar with LARGE maxnodes for unit [%d - %s] \n \n " , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) ) ;
2011-04-14 04:51:13 +02:00
}
maxNodeCount = PathFinder : : pathFindNodesAbsoluteMax ;
2013-05-20 04:51:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " maxNodeCount: %d " , maxNodeCount ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-04-14 04:51:13 +02:00
}
2012-09-22 22:37:42 +02:00
//int unitFactionIndex = unit->getFactionIndex();
2013-11-08 16:30:53 +01:00
codeLocation = " 18 " ;
2012-05-04 23:03:52 +02:00
bool minorDebugPathfinderPerformance = false ;
Chrono chrono ;
if ( minorDebugPathfinderPerformance ) chrono . start ( ) ;
uint32 searched_node_count = 0 ;
2012-05-04 16:57:59 +02:00
minorDebugPathfinder = false ;
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinder ) printf ( " Legacy Pathfind Unit [%d - %s] from = %s to = %s frameIndex = %d \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , frameIndex ) ;
2010-12-01 00:32:39 +01:00
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " calling aStar() " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 19 " ;
2012-09-22 23:05:06 +02:00
ts = aStar ( unit , finalPos , false , frameIndex , maxNodeCount , & searched_node_count ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 20 " ;
2012-05-04 18:48:14 +02:00
//post actions
switch ( ts ) {
case tsBlocked :
case tsArrived :
2013-11-08 16:30:53 +01:00
codeLocation = " 21 " ;
2012-05-04 18:48:14 +02:00
// The unit is stuck (not only blocked but unable to go anywhere for a while)
// We will try to bail out of the immediate area
if ( ts = = tsBlocked & & unit - > getInBailOutAttempt ( ) = = false & &
path - > isStuck ( ) = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 22 " ;
2012-05-04 18:48:14 +02:00
//printf("$$$$ Unit START BAILOUT ATTEMPT for [%d - %s]\n",unit->getId(),unit->getFullName().c_str());
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinder ) printf ( " Pathfind Unit [%d - %s] START BAILOUT ATTEMPT frameIndex = %d \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , frameIndex ) ;
2012-05-04 18:48:14 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " [attempting to BAIL OUT] finalPos [%s] ts [%d] " ,
2012-05-04 18:48:14 +02:00
finalPos . getString ( ) . c_str ( ) , ts ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2012-05-04 18:48:14 +02:00
}
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
if ( wasStuck ! = NULL ) {
* wasStuck = true ;
}
unit - > setInBailOutAttempt ( true ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 23 " ;
2013-05-19 07:16:21 +02:00
//bool useBailoutRadius = Config::getInstance().getBool("EnableBailoutPathfinding","true");
bool useBailoutRadius = true ;
2012-05-04 18:48:14 +02:00
if ( useBailoutRadius = = true ) {
bool unitImmediatelyBlocked = false ;
// First check if unit currently blocked all around them, if so don't try to pathfind
const bool showConsoleDebugInfo = Config : : getInstance ( ) . getBool ( " EnablePathfinderDistanceOutput " , " false " ) ;
const Vec2i unitPos = unit - > getPos ( ) ;
int failureCount = 0 ;
int cellCount = 0 ;
2013-11-08 16:30:53 +01:00
codeLocation = " 24 " ;
2012-05-04 18:48:14 +02:00
for ( int i = - 1 ; i < = 1 ; + + i ) {
for ( int j = - 1 ; j < = 1 ; + + j ) {
Vec2i pos = unitPos + Vec2i ( i , j ) ;
if ( pos ! = unitPos ) {
bool canUnitMoveToCell = map - > aproxCanMove ( unit , unitPos , pos ) ;
if ( canUnitMoveToCell = = false ) {
failureCount + + ;
2012-05-04 16:57:59 +02:00
}
2012-05-04 18:48:14 +02:00
cellCount + + ;
2012-05-04 16:57:59 +02:00
}
}
2012-05-04 18:48:14 +02:00
}
unitImmediatelyBlocked = ( failureCount = = cellCount ) ;
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
if ( showConsoleDebugInfo & & unitImmediatelyBlocked ) {
printf ( " **Check if src blocked [%d], unit [%d - %s] from [%s] to [%s] unitImmediatelyBlocked = %d, failureCount = %d [%d] \n " ,
2013-06-13 10:55:48 +02:00
unitImmediatelyBlocked , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , unitImmediatelyBlocked , failureCount , cellCount ) ;
2012-05-04 18:48:14 +02:00
}
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
if ( unitImmediatelyBlocked = = false ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 25 " ;
2012-05-04 18:48:14 +02:00
int tryRadius = factions [ unit - > getFactionIndex ( ) ] . random . randRange ( 0 , 1 ) ;
// Try to bail out up to PathFinder::pathFindBailoutRadius cells away
if ( tryRadius > 0 ) {
for ( int bailoutX = - PathFinder : : pathFindBailoutRadius ; bailoutX < = PathFinder : : pathFindBailoutRadius & & ts = = tsBlocked ; + + bailoutX ) {
for ( int bailoutY = - PathFinder : : pathFindBailoutRadius ; bailoutY < = PathFinder : : pathFindBailoutRadius & & ts = = tsBlocked ; + + bailoutY ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 26 " ;
2012-05-04 18:48:14 +02:00
const Vec2i newFinalPos = finalPos + Vec2i ( bailoutX , bailoutY ) ;
bool canUnitMove = map - > canMove ( unit , unit - > getPos ( ) , newFinalPos ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " [attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d] " ,
2012-05-04 18:48:14 +02:00
finalPos . getString ( ) . c_str ( ) , newFinalPos . getString ( ) . c_str ( ) , ts , canUnitMove ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2012-05-04 18:48:14 +02:00
}
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
if ( canUnitMove ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 27 " ;
2012-05-04 18:48:14 +02:00
//printf("$$$$ Unit BAILOUT(1) ASTAR ATTEMPT for [%d - %s] newFinalPos = [%s]\n",unit->getId(),unit->getFullName().c_str(),newFinalPos.getString().c_str());
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
int maxBailoutNodeCount = ( PathFinder : : pathFindBailoutRadius * 2 ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " calling aStar() " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2012-09-22 23:05:06 +02:00
ts = aStar ( unit , newFinalPos , true , frameIndex , maxBailoutNodeCount , & searched_node_count ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 28 " ;
2012-05-04 16:57:59 +02:00
}
}
}
2012-05-04 18:48:14 +02:00
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 29 " ;
2012-05-04 18:48:14 +02:00
for ( int bailoutX = PathFinder : : pathFindBailoutRadius ; bailoutX > = - PathFinder : : pathFindBailoutRadius & & ts = = tsBlocked ; - - bailoutX ) {
for ( int bailoutY = PathFinder : : pathFindBailoutRadius ; bailoutY > = - PathFinder : : pathFindBailoutRadius & & ts = = tsBlocked ; - - bailoutY ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 30 " ;
2012-05-04 18:48:14 +02:00
const Vec2i newFinalPos = finalPos + Vec2i ( bailoutX , bailoutY ) ;
bool canUnitMove = map - > canMove ( unit , unit - > getPos ( ) , newFinalPos ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " [attempting to BAIL OUT] finalPos [%s] newFinalPos [%s] ts [%d] canUnitMove [%d] " ,
2012-05-04 18:48:14 +02:00
finalPos . getString ( ) . c_str ( ) , newFinalPos . getString ( ) . c_str ( ) , ts , canUnitMove ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2012-05-04 18:48:14 +02:00
}
if ( canUnitMove ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 31 " ;
2012-05-04 18:48:14 +02:00
//printf("$$$$ Unit BAILOUT(1) ASTAR ATTEMPT for [%d - %s] newFinalPos = [%s]\n",unit->getId(),unit->getFullName().c_str(),newFinalPos.getString().c_str());
int maxBailoutNodeCount = ( PathFinder : : pathFindBailoutRadius * 2 ) ;
2012-05-04 16:57:59 +02:00
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " calling aStar() " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2012-09-22 23:05:06 +02:00
ts = aStar ( unit , newFinalPos , true , frameIndex , maxBailoutNodeCount , & searched_node_count ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 32 " ;
2012-05-04 16:57:59 +02:00
}
}
2011-01-28 08:17:32 +01:00
}
}
}
2012-05-04 18:48:14 +02:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 33 " ;
2012-05-04 18:48:14 +02:00
unit - > setInBailOutAttempt ( false ) ;
2012-05-04 16:57:59 +02:00
2012-05-04 18:48:14 +02:00
//printf("$$$$ Unit END BAILOUT ATTEMPT for [%d - %s] ts = %d\n",unit->getId(),unit->getFullName().c_str(),ts);
2011-04-14 04:51:13 +02:00
2012-05-04 18:48:14 +02:00
if ( ts = = tsBlocked ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 34 " ;
2012-05-04 18:48:14 +02:00
unit - > setLastStuckFrameToCurrentFrame ( ) ;
unit - > setLastStuckPos ( finalPos ) ;
2011-04-14 04:51:13 +02:00
}
2012-05-04 18:48:14 +02:00
}
if ( ts = = tsArrived | | ts = = tsBlocked ) {
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 35 " ;
2012-05-04 18:48:14 +02:00
unit - > setCurrSkill ( scStop ) ;
}
}
break ;
case tsMoving :
{
2013-11-08 16:30:53 +01:00
codeLocation = " 36 " ;
2012-05-04 18:48:14 +02:00
if ( dynamic_cast < UnitPathBasic * > ( path ) ! = NULL ) {
UnitPathBasic * basicPath = dynamic_cast < UnitPathBasic * > ( path ) ;
Vec2i pos ;
2012-05-04 16:57:59 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 37 " ;
2012-05-04 18:48:14 +02:00
pos = basicPath - > pop ( frameIndex < 0 ) ;
2012-05-04 16:57:59 +02:00
}
2012-05-04 18:48:14 +02:00
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 38 " ;
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2012-05-04 18:48:14 +02:00
if ( factions [ unit - > getFactionIndex ( ) ] . precachedPath [ unit - > getId ( ) ] . size ( ) < = 0 ) {
throw megaglest_runtime_error ( " factions[unit->getFactionIndex() ] . precachedPath [ unit - > getId ( ) ] . size ( ) < = 0 ! " ) ;
2012-05-04 16:57:59 +02:00
}
2011-04-14 04:51:13 +02:00
2012-05-04 18:48:14 +02:00
pos = factions [ unit - > getFactionIndex ( ) ] . precachedPath [ unit - > getId ( ) ] [ 0 ] ;
2013-11-08 16:30:53 +01:00
codeLocation = " 39 " ;
2012-05-04 18:48:14 +02:00
}
2011-04-14 04:51:13 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 40 " ;
2012-05-04 18:48:14 +02:00
if ( map - > canMove ( unit , unit - > getPos ( ) , pos ) ) {
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 41 " ;
2012-05-04 18:48:14 +02:00
unit - > setTargetPos ( pos ) ;
2012-05-04 16:57:59 +02:00
}
}
2012-05-04 18:48:14 +02:00
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 42 " ;
2012-05-04 18:48:14 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 43 " ;
2012-05-04 18:48:14 +02:00
unit - > setCurrSkill ( scStop ) ;
2011-04-14 04:51:13 +02:00
}
2012-05-04 23:03:52 +02:00
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinderPerformance & & chrono . getMillis ( ) > = 1 ) printf ( " Unit [%d - %s] astar #2 took [%lld] msecs, ts = %d searched_node_count = %d. \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , ( long long int ) chrono . getMillis ( ) , ts , searched_node_count ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " tsBlocked " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2012-05-04 18:48:14 +02:00
return tsBlocked ;
}
}
else if ( dynamic_cast < UnitPath * > ( path ) ! = NULL ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 44 " ;
2012-05-04 18:48:14 +02:00
UnitPath * advPath = dynamic_cast < UnitPath * > ( path ) ;
Vec2i pos = advPath - > peek ( ) ;
if ( map - > canMove ( unit , unit - > getPos ( ) , pos ) ) {
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 45 " ;
2012-05-04 18:48:14 +02:00
advPath - > pop ( ) ;
unit - > setTargetPos ( pos ) ;
2012-05-04 16:57:59 +02:00
}
2011-04-14 04:51:13 +02:00
}
else {
2012-05-04 18:48:14 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 46 " ;
2012-05-04 18:48:14 +02:00
unit - > setCurrSkill ( scStop ) ;
}
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinder ) printf ( " Pathfind Unit [%d - %s] INT BAILOUT ATTEMPT BLOCKED frameIndex = %d \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , frameIndex ) ;
2012-05-04 23:03:52 +02:00
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinderPerformance & & chrono . getMillis ( ) > = 1 ) printf ( " Unit [%d - %s] astar #3 took [%lld] msecs, ts = %d searched_node_count = %d. \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , ( long long int ) chrono . getMillis ( ) , ts , searched_node_count ) ;
2012-05-04 18:48:14 +02:00
return tsBlocked ;
2012-05-04 16:57:59 +02:00
}
}
2012-05-04 18:48:14 +02:00
else {
throw megaglest_runtime_error ( " unsupported or missing path finder detected! " ) ;
}
}
break ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 47 " ;
2013-06-13 10:55:48 +02:00
if ( minorDebugPathfinderPerformance & & chrono . getMillis ( ) > = 1 ) printf ( " Unit [%d - %s] astar took [%lld] msecs, ts = %d searched_node_count = %d. \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( false ) . c_str ( ) , ( long long int ) chrono . getMillis ( ) , ts , searched_node_count ) ;
2012-05-04 23:03:52 +02:00
2013-11-08 16:30:53 +01:00
}
catch ( const exception & ex ) {
//setRunningStatus(false);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Loc [%s] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw megaglest_runtime_error ( ex . what ( ) ) ;
}
catch ( . . . ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] UNKNOWN error Loc [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2012-05-04 18:48:14 +02:00
return ts ;
}
// ==================== PRIVATE ====================
2012-05-04 16:57:59 +02:00
2010-07-11 20:31:02 +02:00
//route a unit using A* algorithm
2011-03-18 04:53:06 +01:00
TravelState PathFinder : : aStar ( Unit * unit , const Vec2i & targetPos , bool inBailout ,
2012-05-04 23:03:52 +02:00
int frameIndex , int maxNodeCount , uint32 * searched_node_count ) {
2013-11-08 16:30:53 +01:00
TravelState ts = tsImpossible ;
string codeLocation = " 1 " ;
try {
2011-02-25 23:13:11 +01:00
2013-05-21 07:43:57 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex > = 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In aStar() " ) ;
unit - > logSynchDataThreaded ( __FILE__ , __LINE__ , szBuf ) ;
}
2010-12-05 00:19:43 +01:00
Chrono chrono ;
2011-03-29 18:27:01 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ) chrono . start ( ) ;
2010-12-05 00:19:43 +01:00
2010-09-07 23:01:22 +02:00
if ( map = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " map == NULL " ) ;
2010-09-07 23:01:22 +02:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2011-03-18 22:23:34 +01:00
const bool showConsoleDebugInfo = Config : : getInstance ( ) . getBool ( " EnablePathfinderDistanceOutput " , " false " ) ;
2013-05-19 07:16:21 +02:00
const bool tryLastPathCache = false ;
2011-03-18 22:23:34 +01:00
2011-04-14 04:51:13 +02:00
if ( maxNodeCount < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 3 " ;
2011-04-14 04:51:13 +02:00
maxNodeCount = factions [ unit - > getFactionIndex ( ) ] . useMaxNodeCount ;
2012-04-29 06:45:51 +02:00
}
2012-05-01 07:12:38 +02:00
if ( maxNodeCount > = 1 & & unit - > getPathfindFailedConsecutiveFrameCount ( ) > = 3 ) {
2012-04-29 06:45:51 +02:00
maxNodeCount = 200 ;
2011-04-14 04:51:13 +02:00
}
2012-04-29 06:45:51 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 4 " ;
2011-03-18 04:53:06 +01:00
UnitPathInterface * path = unit - > getPath ( ) ;
2012-03-31 21:50:45 +02:00
int unitFactionIndex = unit - > getFactionIndex ( ) ;
2011-03-18 04:53:06 +01:00
2013-11-08 17:26:36 +01:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexFaction ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . nodePoolCount = 0 ;
factions [ unitFactionIndex ] . openNodesList . clear ( ) ;
factions [ unitFactionIndex ] . openPosList . clear ( ) ;
factions [ unitFactionIndex ] . closedNodesList . clear ( ) ;
2010-10-26 08:43:42 +02:00
2013-11-08 17:26:36 +01:00
safeMutexFaction . ReleaseLock ( true ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 5 " ;
2012-03-31 21:50:45 +02:00
// check the pre-cache to see if we can re-use a cached path
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 6 " ;
2012-03-31 21:50:45 +02:00
if ( factions [ unitFactionIndex ] . precachedTravelState . find ( unit - > getId ( ) ) ! = factions [ unitFactionIndex ] . precachedTravelState . end ( ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 7 " ;
2013-05-19 07:16:21 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " factions[unitFactionIndex].precachedTravelState[unit->getId()]: %d " , factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2012-03-31 21:50:45 +02:00
if ( factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] = = tsMoving ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 8 " ;
2011-03-18 04:53:06 +01:00
bool canMoveToCells = true ;
Vec2i lastPos = unit - > getPos ( ) ;
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
for ( int i = 0 ; i < factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . size ( ) ; i + + ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 9 " ;
2012-03-31 21:50:45 +02:00
Vec2i nodePos = factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] [ i ] ;
2011-03-18 04:53:06 +01:00
if ( map - > isInside ( nodePos ) = = false | | map - > isInsideSurface ( map - > toSurfCoords ( nodePos ) ) = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Pathfinder invalid node path position = " + nodePos . getString ( ) + " i = " + intToStr ( i ) ) ;
2011-03-18 04:53:06 +01:00
}
2012-05-12 03:06:55 +02:00
//if(i < pathFindRefresh ||
if ( i < unit - > getPathFindRefreshCellCount ( ) | |
2012-03-31 21:50:45 +02:00
( factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . size ( ) > = pathFindExtendRefreshForNodeCount & &
i < getPathFindExtendRefreshNodeCount ( unitFactionIndex ) ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 10 " ;
2011-09-27 01:55:18 +02:00
//!!! Test MV
2012-04-13 22:20:40 +02:00
if ( canUnitMoveSoon ( unit , lastPos , nodePos ) = = false ) {
2011-03-18 04:53:06 +01:00
canMoveToCells = false ;
break ;
}
lastPos = nodePos ;
}
else {
break ;
}
}
2013-05-20 04:51:26 +02:00
safeMutex . ReleaseLock ( ) ;
2011-03-18 04:53:06 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 11 " ;
2011-03-18 04:53:06 +01:00
if ( canMoveToCells = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 12 " ;
2011-03-18 04:53:06 +01:00
path - > clear ( ) ;
UnitPathBasic * basicPathFinder = dynamic_cast < UnitPathBasic * > ( path ) ;
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex1 ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
for ( int i = 0 ; i < factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . size ( ) ; i + + ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 13 " ;
2012-03-31 21:50:45 +02:00
Vec2i nodePos = factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] [ i ] ;
2011-03-18 04:53:06 +01:00
if ( map - > isInside ( nodePos ) = = false | | map - > isInsideSurface ( map - > toSurfCoords ( nodePos ) ) = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Pathfinder invalid node path position = " + nodePos . getString ( ) + " i = " + intToStr ( i ) ) ;
2011-03-18 04:53:06 +01:00
}
2012-05-12 03:06:55 +02:00
//if(i < pathFindRefresh ||
if ( i < unit - > getPathFindRefreshCellCount ( ) | |
2012-03-31 21:50:45 +02:00
( factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . size ( ) > = pathFindExtendRefreshForNodeCount & &
i < getPathFindExtendRefreshNodeCount ( unitFactionIndex ) ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 14 " ;
2011-03-18 04:53:06 +01:00
path - > add ( nodePos ) ;
}
2011-04-18 18:51:30 +02:00
if ( basicPathFinder ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 15 " ;
2011-03-18 22:23:34 +01:00
basicPathFinder - > addToLastPathCache ( nodePos ) ;
}
2011-03-18 04:53:06 +01:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 16 " ;
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " return factions[unitFactionIndex].precachedTravelState[unit->getId()]; " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 17 " ;
2012-03-31 21:50:45 +02:00
return factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] ;
2011-03-18 04:53:06 +01:00
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 18 " ;
2011-03-18 04:53:06 +01:00
clearUnitPrecache ( unit ) ;
}
}
2013-05-20 04:51:26 +02:00
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 19 " ;
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex1 ( factionMutex , mutexOwnerId ) ;
if ( factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] = = tsBlocked ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 20 " ;
2013-05-20 04:51:26 +02:00
path - > incBlockCount ( ) ;
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " return factions[unitFactionIndex].precachedTravelState[unit->getId()]; " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 21 " ;
2013-05-20 04:51:26 +02:00
return factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] ;
}
2011-03-18 04:53:06 +01:00
}
}
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 22 " ;
2011-03-18 04:53:06 +01:00
clearUnitPrecache ( unit ) ;
2013-05-20 04:51:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " [clearUnitPrecache] " ) ;
2013-05-20 23:52:36 +02:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2013-05-20 04:51:26 +02:00
}
2011-03-18 04:53:06 +01:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 23 " ;
2011-02-12 00:32:24 +01:00
const Vec2i unitPos = unit - > getPos ( ) ;
2010-07-11 20:31:02 +02:00
const Vec2i finalPos = computeNearestFreePos ( unit , targetPos ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 24 " ;
2013-10-03 02:17:51 +02:00
float dist = unitPos . dist ( finalPos ) ;
2013-11-08 17:26:36 +01:00
safeMutexFaction . Lock ( ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . useMaxNodeCount = PathFinder : : pathFindNodesMax ;
2013-11-08 17:26:36 +01:00
safeMutexFaction . ReleaseLock ( true ) ;
2011-02-23 08:03:38 +01:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2011-02-12 00:32:24 +01:00
// Check the previous path find cache for the unit to see if its good to
// use
2011-03-29 18:27:01 +02:00
if ( showConsoleDebugInfo | | tryLastPathCache ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 25 " ;
2013-06-13 10:55:48 +02:00
if ( showConsoleDebugInfo & & dist > 60 ) printf ( " Distance from [%d - %s] to destination is %.2f tryLastPathCache = %d \n " , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , dist , tryLastPathCache ) ;
2011-02-23 08:03:38 +01:00
if ( tryLastPathCache = = true & & path ! = NULL ) {
UnitPathBasic * basicPathFinder = dynamic_cast < UnitPathBasic * > ( path ) ;
if ( basicPathFinder ! = NULL & & basicPathFinder - > getLastPathCacheQueueCount ( ) > 0 ) {
2013-05-19 07:16:21 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " basicPathFinder->getLastPathCacheQueueCount(): %d " , basicPathFinder - > getLastPathCacheQueueCount ( ) ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-02-23 08:03:38 +01:00
vector < Vec2i > cachedPath = basicPathFinder - > getLastPathCacheQueue ( ) ;
for ( int i = 0 ; i < cachedPath . size ( ) ; + + i ) {
Vec2i & pos1 = cachedPath [ i ] ;
// Looking to find if the unit is in one of the cells in the cached path
if ( unitPos = = pos1 ) {
// Now see if we can re-use this path to get to the final destination
for ( int j = i + 1 ; j < cachedPath . size ( ) ; + + j ) {
Vec2i & pos2 = cachedPath [ j ] ;
bool canUnitMoveToCell = map - > aproxCanMove ( unit , pos1 , pos2 ) ;
if ( canUnitMoveToCell = = true ) {
if ( pos2 = = finalPos ) {
//on the way
ts = tsMoving ;
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-23 08:03:38 +01:00
//store path
2011-03-18 22:23:34 +01:00
if ( frameIndex < 0 ) {
basicPathFinder - > clear ( ) ;
}
2011-02-23 08:03:38 +01:00
int pathCount = 0 ;
for ( int k = i + 1 ; k < = j ; k + + ) {
if ( k > = cachedPath . size ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " k >= cachedPath.size() k = " + intToStr(k) + " cachedPath . size ( ) = " + intToStr(cachedPath.size())) ;
2011-02-23 08:03:38 +01:00
}
2011-03-18 22:23:34 +01:00
if ( frameIndex > = 0 ) {
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . push_back ( cachedPath [ k ] ) ;
2011-03-18 22:23:34 +01:00
}
else {
2012-05-12 03:06:55 +02:00
//if(pathCount < pathFindRefresh) {
if ( pathCount < unit - > getPathFindRefreshCellCount ( ) ) {
2011-03-18 22:23:34 +01:00
basicPathFinder - > add ( cachedPath [ k ] ) ;
}
basicPathFinder - > addToLastPathCache ( cachedPath [ k ] ) ;
2011-02-23 08:03:38 +01:00
}
pathCount + + ;
2011-02-12 00:32:24 +01:00
}
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-12 00:32:24 +01:00
2011-04-03 04:42:45 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-11-10 07:37:23 +01:00
snprintf ( szBuf , 8096 , " [Setting new path for unit] openNodesList.size() [ " MG_SIZE_T_SPECIFIER " ] openPosList.size() [ " MG_SIZE_T_SPECIFIER " ] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d] " ,
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList . size ( ) , factions [ unitFactionIndex ] . openPosList . size ( ) , finalPos . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , inBailout , ts ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2011-02-12 00:32:24 +01:00
}
2011-02-23 08:03:38 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
string commandDesc = " none " ;
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) ! = NULL ) {
2013-09-21 22:50:58 +02:00
commandDesc = command - > getCommandType ( ) - > toString ( false ) ;
2011-02-23 08:03:38 +01:00
}
2011-02-12 00:32:24 +01:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " State: moving, cmd [%s] pos: %s dest pos: %s, Queue= %d " , commandDesc . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , path - > getQueueCount ( ) ) ;
2011-02-23 08:03:38 +01:00
unit - > setCurrentUnitTitle ( szBuf ) ;
}
2011-02-12 00:32:24 +01:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-12 00:32:24 +01:00
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " return ts: %d " , ts ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-02-23 08:03:38 +01:00
return ts ;
}
2012-05-12 03:06:55 +02:00
else if ( j - i > unit - > getPathFindRefreshCellCount ( ) ) {
2011-02-23 08:03:38 +01:00
//on the way
ts = tsMoving ;
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-23 08:03:38 +01:00
//store path
2011-03-18 22:23:34 +01:00
if ( frameIndex < 0 ) {
basicPathFinder - > clear ( ) ;
}
2011-02-23 08:03:38 +01:00
int pathCount = 0 ;
for ( int k = i + 1 ; k < cachedPath . size ( ) ; k + + ) {
if ( k > = cachedPath . size ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " #2 k >= cachedPath.size() k = " + intToStr(k) + " cachedPath . size ( ) = " + intToStr(cachedPath.size())) ;
2011-02-23 08:03:38 +01:00
}
2011-03-18 22:23:34 +01:00
if ( frameIndex > = 0 ) {
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . push_back ( cachedPath [ k ] ) ;
2011-03-18 22:23:34 +01:00
}
else {
2012-05-12 03:06:55 +02:00
if ( pathCount < unit - > getPathFindRefreshCellCount ( ) ) {
2011-03-18 22:23:34 +01:00
basicPathFinder - > add ( cachedPath [ k ] ) ;
}
basicPathFinder - > addToLastPathCache ( cachedPath [ k ] ) ;
2011-02-23 08:03:38 +01:00
}
pathCount + + ;
}
2011-02-12 00:32:24 +01:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-12 00:32:24 +01:00
2011-04-03 04:42:45 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-11-10 07:37:23 +01:00
snprintf ( szBuf , 8096 , " [Setting new path for unit] openNodesList.size() [ " MG_SIZE_T_SPECIFIER " ] openPosList.size() [ " MG_SIZE_T_SPECIFIER " ] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d] " ,
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList . size ( ) , factions [ unitFactionIndex ] . openPosList . size ( ) , finalPos . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , inBailout , ts ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2011-02-12 00:32:24 +01:00
}
2011-02-23 08:03:38 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
string commandDesc = " none " ;
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) ! = NULL ) {
2013-09-21 22:50:58 +02:00
commandDesc = command - > getCommandType ( ) - > toString ( false ) ;
2011-02-23 08:03:38 +01:00
}
2011-02-12 00:32:24 +01:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " State: moving, cmd [%s] pos: %s dest pos: %s, Queue= %d " , commandDesc . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , path - > getQueueCount ( ) ) ;
2011-02-23 08:03:38 +01:00
unit - > setCurrentUnitTitle ( szBuf ) ;
2011-02-12 00:32:24 +01:00
}
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2011-02-12 00:32:24 +01:00
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " return ts: %d " , ts ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-02-23 08:03:38 +01:00
return ts ;
}
2011-02-12 00:32:24 +01:00
}
2011-02-23 08:03:38 +01:00
pos1 = pos2 ;
2011-02-12 00:32:24 +01:00
}
2011-02-23 08:03:38 +01:00
break ;
2011-02-12 00:32:24 +01:00
}
}
}
}
}
2010-07-11 20:31:02 +02:00
//path find algorithm
2013-11-08 16:30:53 +01:00
codeLocation = " 26 " ;
2010-07-11 20:31:02 +02:00
//a) push starting pos into openNodes
2013-11-08 17:26:36 +01:00
safeMutexFaction . Lock ( ) ;
2012-03-31 21:50:45 +02:00
Node * firstNode = newNode ( factions [ unitFactionIndex ] , maxNodeCount ) ;
2010-10-17 08:34:42 +02:00
if ( firstNode = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " firstNode == NULL " ) ;
2010-10-17 08:34:42 +02:00
}
2010-07-11 20:31:02 +02:00
firstNode - > next = NULL ;
firstNode - > prev = NULL ;
2010-09-07 23:01:22 +02:00
firstNode - > pos = unitPos ;
firstNode - > heuristic = heuristic ( unitPos , finalPos ) ;
2010-07-11 20:31:02 +02:00
firstNode - > exploredCell = true ;
2012-03-31 21:50:45 +02:00
if ( factions [ unitFactionIndex ] . openNodesList . find ( firstNode - > heuristic ) = = factions [ unitFactionIndex ] . openNodesList . end ( ) ) {
factions [ unitFactionIndex ] . openNodesList [ firstNode - > heuristic ] . clear ( ) ;
2011-02-16 20:44:12 +01:00
}
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList [ firstNode - > heuristic ] . push_back ( firstNode ) ;
factions [ unitFactionIndex ] . openPosList [ firstNode - > pos ] = true ;
2010-07-11 20:31:02 +02:00
2013-11-08 17:26:36 +01:00
safeMutexFaction . ReleaseLock ( true ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 27 " ;
2010-07-11 20:31:02 +02:00
//b) loop
2010-11-09 10:06:52 +01:00
bool pathFound = true ;
bool nodeLimitReached = false ;
Node * node = NULL ;
2010-08-22 22:13:30 +02:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2011-03-29 18:27:01 +02:00
// First check if unit currently blocked all around them, if so don't try to pathfind
2011-02-25 17:32:27 +01:00
if ( inBailout = = false & & unitPos ! = finalPos ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 28 " ;
2011-02-25 17:32:27 +01:00
int failureCount = 0 ;
int cellCount = 0 ;
for ( int i = - 1 ; i < = 1 ; + + i ) {
for ( int j = - 1 ; j < = 1 ; + + j ) {
Vec2i pos = unitPos + Vec2i ( i , j ) ;
if ( pos ! = unitPos ) {
2011-09-27 01:55:18 +02:00
//!!! Test MV
2012-04-13 22:20:40 +02:00
bool canUnitMoveToCell = canUnitMoveSoon ( unit , unitPos , pos ) ;
2011-02-25 17:32:27 +01:00
if ( canUnitMoveToCell = = false ) {
failureCount + + ;
}
cellCount + + ;
}
}
}
nodeLimitReached = ( failureCount = = cellCount ) ;
pathFound = ! nodeLimitReached ;
2013-05-19 07:16:21 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " nodeLimitReached: %d failureCount: %d cellCount: %d " , nodeLimitReached , failureCount , cellCount ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-06-13 10:55:48 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 1 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , dist , ( long long int ) chrono . getMillis ( ) , nodeLimitReached , failureCount ) ;
2011-02-25 17:32:27 +01:00
if ( showConsoleDebugInfo & & nodeLimitReached ) {
printf ( " **Check if src blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d] \n " ,
2013-06-13 10:55:48 +02:00
nodeLimitReached , inBailout , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , dist , ( long long int ) chrono . getMillis ( ) , nodeLimitReached , failureCount , cellCount ) ;
2011-02-25 17:32:27 +01:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 29 " ;
2011-02-25 17:32:27 +01:00
if ( nodeLimitReached = = false ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 30 " ;
2011-02-25 17:32:27 +01:00
// First check if final destination blocked
failureCount = 0 ;
cellCount = 0 ;
for ( int i = - 1 ; i < = 1 ; + + i ) {
for ( int j = - 1 ; j < = 1 ; + + j ) {
Vec2i pos = finalPos + Vec2i ( i , j ) ;
if ( pos ! = finalPos ) {
2011-09-27 01:55:18 +02:00
//!!! Test MV
2012-04-13 22:20:40 +02:00
bool canUnitMoveToCell = canUnitMoveSoon ( unit , pos , finalPos ) ;
2011-02-25 17:32:27 +01:00
if ( canUnitMoveToCell = = false ) {
failureCount + + ;
}
cellCount + + ;
}
}
}
nodeLimitReached = ( failureCount = = cellCount ) ;
pathFound = ! nodeLimitReached ;
2013-05-19 07:16:21 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " nodeLimitReached: %d failureCount: %d cellCount: %d " , nodeLimitReached , failureCount , cellCount ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-06-13 10:55:48 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 1 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] **Check if dest blocked, distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , dist , ( long long int ) chrono . getMillis ( ) , nodeLimitReached , failureCount ) ;
2011-02-25 17:32:27 +01:00
if ( showConsoleDebugInfo & & nodeLimitReached ) {
printf ( " **Check if dest blocked [%d - %d], unit [%d - %s] from [%s] to [%s] distance %.2f took msecs: %lld nodeLimitReached = %d, failureCount = %d [%d] \n " ,
2013-06-13 10:55:48 +02:00
nodeLimitReached , inBailout , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , dist , ( long long int ) chrono . getMillis ( ) , nodeLimitReached , failureCount , cellCount ) ;
2011-02-25 17:32:27 +01:00
}
}
}
2013-05-20 04:51:26 +02:00
else {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " inBailout: %d unitPos: [%s] finalPos [%s] " , inBailout , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
}
2011-02-25 17:32:27 +01:00
//
2013-11-08 16:30:53 +01:00
codeLocation = " 31 " ;
2011-03-29 18:27:01 +02:00
// START
2011-09-27 01:55:18 +02:00
std : : map < std : : pair < Vec2i , Vec2i > , bool > canAddNode ;
std : : map < Vec2i , bool > closedNodes ;
std : : map < Vec2i , Vec2i > cameFrom ;
cameFrom [ unitPos ] = Vec2i ( - 1 , - 1 ) ;
2011-04-04 06:32:01 +02:00
// Do the a-star base pathfind work if required
2010-10-26 08:43:42 +02:00
int whileLoopCount = 0 ;
2011-04-14 04:51:13 +02:00
if ( nodeLimitReached = = false ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 32 " ;
2011-09-27 01:55:18 +02:00
2013-05-18 05:11:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Calling doAStarPathSearch nodeLimitReached: %d whileLoopCount: %d unitFactionIndex: %d pathFound: %d finalPos [%s] maxNodeCount: %d frameIndex: %d " , nodeLimitReached , whileLoopCount , unitFactionIndex ,
pathFound , finalPos . getString ( ) . c_str ( ) , maxNodeCount , frameIndex ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2012-04-21 05:42:25 +02:00
doAStarPathSearch ( nodeLimitReached , whileLoopCount , unitFactionIndex ,
2013-11-08 18:01:32 +01:00
pathFound , node , finalPos ,
2012-04-29 06:45:51 +02:00
closedNodes , cameFrom , canAddNode , unit , maxNodeCount , frameIndex ) ;
2011-04-14 04:51:13 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 33 " ;
2012-05-04 23:03:52 +02:00
if ( searched_node_count ! = NULL ) {
* searched_node_count = whileLoopCount ;
}
2011-04-14 04:51:13 +02:00
// Now see if the unit is eligble for pathfind max nodes boost?
2012-04-29 06:45:51 +02:00
if ( nodeLimitReached = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 34 " ;
2012-04-29 06:45:51 +02:00
unit - > incrementPathfindFailedConsecutiveFrameCount ( ) ;
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 35 " ;
2012-04-29 06:45:51 +02:00
unit - > resetPathfindFailedConsecutiveFrameCount ( ) ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 36 " ;
2013-05-18 05:11:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Calling doAStarPathSearch nodeLimitReached: %d whileLoopCount: %d unitFactionIndex: %d pathFound: %d finalPos [%s] maxNodeCount: %d pathFindNodesAbsoluteMax: %d frameIndex: %d " , nodeLimitReached , whileLoopCount , unitFactionIndex ,
pathFound , finalPos . getString ( ) . c_str ( ) , maxNodeCount , pathFindNodesAbsoluteMax , frameIndex ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-04-14 04:51:13 +02:00
if ( nodeLimitReached = = true & & maxNodeCount ! = pathFindNodesAbsoluteMax ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 37 " ;
2011-04-14 04:51:13 +02:00
if ( unit - > isLastPathfindFailedFrameWithinCurrentFrameTolerance ( ) = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 38 " ;
2011-04-14 04:51:13 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 39 " ;
2011-04-14 04:51:13 +02:00
unit - > setLastPathfindFailedFrameToCurrentFrame ( ) ;
unit - > setLastPathfindFailedPos ( finalPos ) ;
}
if ( showConsoleDebugInfo | | SystemFlags : : VERBOSE_MODE_ENABLED ) {
2013-06-13 10:55:48 +02:00
printf ( " \n \n \n \n $$$ Calling AStar with LARGE maxnodes for unit [%d - %s] \n \n " , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) ) ;
2011-04-14 04:51:13 +02:00
}
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " calling aStar() " ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2011-04-14 04:51:13 +02:00
return aStar ( unit , targetPos , false , frameIndex , pathFindNodesAbsoluteMax ) ;
}
2010-07-11 20:31:02 +02:00
}
2011-04-14 04:51:13 +02:00
}
2013-05-20 04:51:26 +02:00
else {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " nodeLimitReached: %d " , nodeLimitReached ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
}
2010-07-11 20:31:02 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 40 " ;
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 1 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) , nodeLimitReached , whileLoopCount , factions [ unitFactionIndex ] . nodePoolCount ) ;
2011-02-23 08:03:38 +01:00
if ( showConsoleDebugInfo & & chrono . getMillis ( ) > 2 ) {
2013-06-13 10:55:48 +02:00
printf ( " Distance for unit [%d - %s] from [%s] to [%s] is %.2f took msecs: %lld nodeLimitReached = %d whileLoopCount = %d nodePoolCount = %d \n " , unit - > getId ( ) , unit - > getFullName ( false ) . c_str ( ) , unitPos . getString ( ) . c_str ( ) , finalPos . getString ( ) . c_str ( ) , dist , ( long long int ) chrono . getMillis ( ) , nodeLimitReached , whileLoopCount , factions [ unitFactionIndex ] . nodePoolCount ) ;
2011-02-23 08:03:38 +01:00
}
2010-12-05 00:19:43 +01:00
2010-07-11 20:31:02 +02:00
Node * lastNode = node ;
2010-08-25 09:29:35 +02:00
//if consumed all nodes find best node (to avoid strange behaviour)
2010-10-17 08:34:42 +02:00
if ( nodeLimitReached = = true ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 41 " ;
2012-03-31 21:50:45 +02:00
if ( factions [ unitFactionIndex ] . closedNodesList . size ( ) > 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 42 " ;
2013-10-03 02:17:51 +02:00
float bestHeuristic = factions [ unitFactionIndex ] . closedNodesList . begin ( ) - > first ;
2010-10-26 08:43:42 +02:00
if ( bestHeuristic < lastNode - > heuristic ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 43 " ;
2012-03-31 21:50:45 +02:00
lastNode = factions [ unitFactionIndex ] . closedNodesList . begin ( ) - > second [ 0 ] ;
2010-10-26 08:43:42 +02:00
}
}
2010-07-11 20:31:02 +02:00
}
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 44 " ;
2010-07-11 20:31:02 +02:00
//check results of path finding
2011-02-12 00:32:24 +01:00
ts = tsImpossible ;
2010-10-17 08:34:42 +02:00
if ( pathFound = = false | | lastNode = = firstNode ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 45 " ;
2012-05-04 16:57:59 +02:00
if ( minorDebugPathfinder ) printf ( " Legacy Pathfind Unit [%d - %s] NOT FOUND PATH count = %d frameIndex = %d \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( ) . c_str ( ) , whileLoopCount , frameIndex ) ;
2010-07-11 20:31:02 +02:00
//blocked
2010-10-17 08:34:42 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
string commandDesc = " none " ;
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) ! = NULL ) {
2013-09-21 22:50:58 +02:00
commandDesc = command - > getCommandType ( ) - > toString ( false ) ;
2010-10-17 08:34:42 +02:00
}
2010-12-01 00:32:39 +01:00
std : : pair < Vec2i , int > lastHarvest = unit - > getLastHarvestResourceTarget ( ) ;
2010-10-17 10:50:27 +02:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " State: blocked, cmd [%s] pos: [%s], dest pos: [%s], lastHarvest = [%s - %d], reason A= %d, B= %d, C= %d, D= %d, E= %d, F = %d " , commandDesc . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , lastHarvest . first . getString ( ) . c_str ( ) , lastHarvest . second , pathFound , ( lastNode = = firstNode ) , path - > getBlockCount ( ) , path - > isBlocked ( ) , nodeLimitReached , path - > isStuck ( ) ) ;
2010-10-17 08:34:42 +02:00
unit - > setCurrentUnitTitle ( szBuf ) ;
}
2011-04-14 04:51:13 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 46 " ;
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
}
2010-07-11 20:31:02 +02:00
ts = tsBlocked ;
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 47 " ;
2011-03-18 04:53:06 +01:00
path - > incBlockCount ( ) ;
}
2010-12-01 00:32:39 +01:00
2011-04-03 04:42:45 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-11-10 07:37:23 +01:00
snprintf ( szBuf , 8096 , " [path for unit BLOCKED] openNodesList.size() [ " MG_SIZE_T_SPECIFIER " ] openPosList.size() [ " MG_SIZE_T_SPECIFIER " ] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d] " ,
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList . size ( ) , factions [ unitFactionIndex ] . openPosList . size ( ) , finalPos . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , inBailout , ts ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2010-12-01 00:32:39 +01:00
}
2010-12-05 00:19:43 +01:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-07-11 20:31:02 +02:00
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 48 " ;
2012-05-04 16:57:59 +02:00
if ( minorDebugPathfinder ) printf ( " Legacy Pathfind Unit [%d - %s] FOUND PATH count = %d frameIndex = %d \n " , unit - > getId ( ) , unit - > getType ( ) - > getName ( ) . c_str ( ) , whileLoopCount , frameIndex ) ;
2010-07-11 20:31:02 +02:00
//on the way
2010-07-22 00:05:50 +02:00
ts = tsMoving ;
2010-07-11 20:31:02 +02:00
//build next pointers
Node * currNode = lastNode ;
2010-10-17 08:34:42 +02:00
while ( currNode - > prev ! = NULL ) {
2010-07-11 20:31:02 +02:00
currNode - > prev - > next = currNode ;
currNode = currNode - > prev ;
}
2010-12-05 00:19:43 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 49 " ;
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2011-04-14 04:51:13 +02:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 50 " ;
2011-04-14 04:51:13 +02:00
if ( maxNodeCount = = pathFindNodesAbsoluteMax ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 51 " ;
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( true ) ;
}
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 52 " ;
2011-04-14 04:51:13 +02:00
unit - > setUsePathfinderExtendedMaxNodes ( false ) ;
}
}
2010-07-11 20:31:02 +02:00
//store path
2011-03-18 04:53:06 +01:00
if ( frameIndex < 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 53 " ;
2011-03-18 04:53:06 +01:00
path - > clear ( ) ;
}
2011-09-27 01:55:18 +02:00
if ( pathFound = = true ) {
//printf("FULL PATH FOUND from [%s] to [%s]\n",unitPos.getString().c_str(),finalPos.getString().c_str());
}
2013-11-08 16:30:53 +01:00
codeLocation = " 54 " ;
2011-02-12 00:32:24 +01:00
UnitPathBasic * basicPathFinder = dynamic_cast < UnitPathBasic * > ( path ) ;
2010-07-11 20:31:02 +02:00
currNode = firstNode ;
2011-02-12 00:32:24 +01:00
for ( int i = 0 ; currNode - > next ! = NULL ; currNode = currNode - > next , i + + ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 55 " ;
2011-02-23 08:03:38 +01:00
Vec2i nodePos = currNode - > next - > pos ;
if ( map - > isInside ( nodePos ) = = false | | map - > isInsideSurface ( map - > toSurfCoords ( nodePos ) ) = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Pathfinder invalid node path position = " + nodePos . getString ( ) + " i = " + intToStr ( i ) ) ;
2011-02-23 08:03:38 +01:00
}
2011-09-27 01:55:18 +02:00
//printf("nodePos [%s]\n",nodePos.getString().c_str());
2012-05-04 16:57:59 +02:00
if ( minorDebugPathfinder ) printf ( " nodePos [%s] \n " , nodePos . getString ( ) . c_str ( ) ) ;
2011-09-27 01:55:18 +02:00
2011-03-18 04:53:06 +01:00
if ( frameIndex > = 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 56 " ;
2013-05-20 04:51:26 +02:00
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutex ( factionMutex , mutexOwnerId ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . precachedPath [ unit - > getId ( ) ] . push_back ( nodePos ) ;
2011-02-23 08:03:38 +01:00
}
2011-03-18 04:53:06 +01:00
else {
2013-11-08 16:30:53 +01:00
codeLocation = " 57 " ;
2012-05-12 03:06:55 +02:00
if ( i < unit - > getPathFindRefreshCellCount ( ) | |
2011-06-24 21:40:47 +02:00
( whileLoopCount > = pathFindExtendRefreshForNodeCount & &
2012-03-31 21:50:45 +02:00
i < getPathFindExtendRefreshNodeCount ( unitFactionIndex ) ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 58 " ;
2011-03-18 04:53:06 +01:00
path - > add ( nodePos ) ;
}
2011-04-18 18:51:30 +02:00
if ( basicPathFinder ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 59 " ;
2011-03-18 04:53:06 +01:00
basicPathFinder - > addToLastPathCache ( nodePos ) ;
}
2011-02-12 00:32:24 +01:00
}
2010-07-11 20:31:02 +02:00
}
2010-10-17 08:34:42 +02:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2011-04-03 04:42:45 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-11-10 07:37:23 +01:00
snprintf ( szBuf , 8096 , " [Setting new path for unit] openNodesList.size() [ " MG_SIZE_T_SPECIFIER " ] openPosList.size() [ " MG_SIZE_T_SPECIFIER " ] finalPos [%s] targetPos [%s] inBailout [%d] ts [%d] " ,
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList . size ( ) , factions [ unitFactionIndex ] . openPosList . size ( ) , finalPos . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , inBailout , ts ) ;
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2011-02-16 20:44:12 +01:00
string pathToTake = " " ;
for ( int i = 0 ; i < path - > getQueueCount ( ) ; + + i ) {
Vec2i & pos = path - > getQueue ( ) [ i ] ;
if ( pathToTake ! = " " ) {
pathToTake + = " , " ;
}
pathToTake + = pos . getString ( ) ;
}
2013-01-03 18:30:59 +01:00
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Path for unit to take = %s " , pathToTake . c_str ( ) ) ;
2010-12-01 00:32:39 +01:00
}
2010-10-17 08:34:42 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
string commandDesc = " none " ;
Command * command = unit - > getCurrCommand ( ) ;
if ( command ! = NULL & & command - > getCommandType ( ) ! = NULL ) {
2013-09-21 22:50:58 +02:00
commandDesc = command - > getCommandType ( ) - > toString ( false ) ;
2010-10-17 08:34:42 +02:00
}
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " State: moving, cmd [%s] pos: %s dest pos: %s, Queue= %d " , commandDesc . c_str ( ) , unit - > getPos ( ) . getString ( ) . c_str ( ) , targetPos . getString ( ) . c_str ( ) , path - > getQueueCount ( ) ) ;
2010-10-17 08:34:42 +02:00
unit - > setCurrentUnitTitle ( szBuf ) ;
}
2010-12-05 00:19:43 +01:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s Line: %d] took msecs: %lld \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-07-11 20:31:02 +02:00
}
2013-11-08 16:30:53 +01:00
codeLocation = " 60 " ;
2013-11-08 17:26:36 +01:00
safeMutexFaction . Lock ( ) ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . openNodesList . clear ( ) ;
factions [ unitFactionIndex ] . openPosList . clear ( ) ;
factions [ unitFactionIndex ] . closedNodesList . clear ( ) ;
2010-07-11 20:31:02 +02:00
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = = true & & chrono . getMillis ( ) > 4 ) SystemFlags : : OutputDebug ( SystemFlags : : debugPerformance , " In [%s::%s] Line: %d took msecs: %lld --------------------------- [END OF METHOD] --------------------------- \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , chrono . getMillis ( ) ) ;
2010-12-05 00:19:43 +01:00
2011-03-18 04:53:06 +01:00
if ( frameIndex > = 0 ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 61 " ;
2012-03-31 21:50:45 +02:00
factions [ unitFactionIndex ] . precachedTravelState [ unit - > getId ( ) ] = ts ;
2011-03-18 04:53:06 +01:00
}
else {
2013-01-03 18:30:59 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED & & chrono . getMillis ( ) > = 5 ) printf ( " In [%s::%s Line: %d] astar took [%lld] msecs, ts = %d. \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , ( long long int ) chrono . getMillis ( ) , ts ) ;
2011-03-18 04:53:06 +01:00
}
2013-11-08 17:26:36 +01:00
safeMutexFaction . ReleaseLock ( ) ;
2011-04-04 06:32:01 +02:00
//printf("$$$$ Path for Unit [%d - %s] return value = %d inBailout = %d\n",unit->getId(),unit->getFullName().c_str(),ts,inBailout);
2013-05-21 00:54:07 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = = true & & frameIndex < 0 ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " return ts: %d " , ts ) ;
unit - > logSynchData ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __LINE__ , szBuf ) ;
}
2013-11-08 16:30:53 +01:00
}
catch ( const exception & ex ) {
//setRunningStatus(false);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Loc [%s] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw megaglest_runtime_error ( ex . what ( ) ) ;
}
catch ( . . . ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] UNKNOWN error Loc [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2010-07-11 20:31:02 +02:00
return ts ;
}
2013-10-03 02:17:51 +02:00
void PathFinder : : processNearestFreePos ( const Vec2i & finalPos , int i , int j , int size , Field field , int teamIndex , Vec2i unitPos , Vec2i & nearestPos , float & nearestDist ) {
2013-11-08 16:30:53 +01:00
string codeLocation = " 1 " ;
try {
2011-02-04 07:34:32 +01:00
Vec2i currPos = finalPos + Vec2i ( i , j ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2011-02-04 07:34:32 +01:00
if ( map - > isAproxFreeCells ( currPos , size , field , teamIndex ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 3 " ;
2013-10-03 02:17:51 +02:00
float dist = currPos . dist ( finalPos ) ;
2011-02-04 07:34:32 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 4 " ;
2011-02-04 07:34:32 +01:00
//if nearer from finalPos
if ( dist < nearestDist ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 5 " ;
2011-02-04 07:34:32 +01:00
nearestPos = currPos ;
nearestDist = dist ;
}
//if the distance is the same compare distance to unit
else if ( dist = = nearestDist ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 6 " ;
2011-02-04 07:34:32 +01:00
if ( currPos . dist ( unitPos ) < nearestPos . dist ( unitPos ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 7 " ;
2011-02-04 07:34:32 +01:00
nearestPos = currPos ;
}
}
2013-11-08 16:30:53 +01:00
codeLocation = " 8 " ;
}
}
catch ( const exception & ex ) {
//setRunningStatus(false);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Loc [%s] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw megaglest_runtime_error ( ex . what ( ) ) ;
2011-02-04 07:34:32 +01:00
}
2013-11-08 16:30:53 +01:00
catch ( . . . ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] UNKNOWN error Loc [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2011-02-04 07:34:32 +01:00
}
2010-10-17 08:34:42 +02:00
Vec2i PathFinder : : computeNearestFreePos ( const Unit * unit , const Vec2i & finalPos ) {
2013-11-08 16:30:53 +01:00
string codeLocation = " 1 " ;
Vec2i nearestPos ( 0 , 0 ) ;
try {
2010-09-07 23:01:22 +02:00
if ( map = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " map == NULL " ) ;
2010-09-07 23:01:22 +02:00
}
2010-07-11 20:31:02 +02:00
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2010-07-11 20:31:02 +02:00
//unit data
int size = unit - > getType ( ) - > getSize ( ) ;
Field field = unit - > getCurrField ( ) ;
int teamIndex = unit - > getTeam ( ) ;
2013-11-08 16:30:53 +01:00
codeLocation = " 3 " ;
2010-07-11 20:31:02 +02:00
//if finalPos is free return it
2010-10-17 08:34:42 +02:00
if ( map - > isAproxFreeCells ( finalPos , size , field , teamIndex ) ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 4 " ;
2010-07-11 20:31:02 +02:00
return finalPos ;
}
2013-11-08 16:30:53 +01:00
codeLocation = " 5 " ;
2010-07-11 20:31:02 +02:00
//find nearest pos
2013-02-04 09:30:43 +01:00
Vec2i unitPos = unit - > getPosNotThreadSafe ( ) ;
2013-11-08 16:30:53 +01:00
nearestPos = unitPos ;
codeLocation = " 6 " ;
2013-10-03 02:17:51 +02:00
float nearestDist = unitPos . dist ( finalPos ) ;
2011-02-04 07:34:32 +01:00
2013-11-08 16:30:53 +01:00
codeLocation = " 7 " ;
2010-10-17 08:34:42 +02:00
for ( int i = - maxFreeSearchRadius ; i < = maxFreeSearchRadius ; + + i ) {
for ( int j = - maxFreeSearchRadius ; j < = maxFreeSearchRadius ; + + j ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 8 " ;
2011-02-04 07:34:32 +01:00
processNearestFreePos ( finalPos , i , j , size , field , teamIndex , unitPos , nearestPos , nearestDist ) ;
2010-07-11 20:31:02 +02:00
}
}
2013-11-08 16:30:53 +01:00
codeLocation = " 9 " ;
}
catch ( const exception & ex ) {
//setRunningStatus(false);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Loc [%s] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw megaglest_runtime_error ( ex . what ( ) ) ;
}
catch ( . . . ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] UNKNOWN error Loc [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2010-07-11 20:31:02 +02:00
return nearestPos ;
}
2012-03-10 04:27:25 +01:00
int PathFinder : : findNodeIndex ( Node * node , Nodes & nodeList ) {
int index = - 1 ;
if ( node ! = NULL ) {
for ( unsigned int i = 0 ; i < nodeList . size ( ) ; + + i ) {
Node * curnode = nodeList [ i ] ;
if ( node = = curnode ) {
index = i ;
break ;
}
}
}
return index ;
}
int PathFinder : : findNodeIndex ( Node * node , std : : vector < Node > & nodeList ) {
int index = - 1 ;
if ( node ! = NULL ) {
for ( unsigned int i = 0 ; i < nodeList . size ( ) ; + + i ) {
Node & curnode = nodeList [ i ] ;
if ( node = = & curnode ) {
index = i ;
break ;
}
}
}
return index ;
}
2013-02-22 07:52:51 +01:00
bool PathFinder : : unitCannotMove ( Unit * unit ) {
bool unitImmediatelyBlocked = false ;
2013-11-08 16:30:53 +01:00
string codeLocation = " 1 " ;
try {
2013-02-22 07:52:51 +01:00
// First check if unit currently blocked all around them, if so don't try to pathfind
const Vec2i unitPos = unit - > getPos ( ) ;
int failureCount = 0 ;
int cellCount = 0 ;
2013-11-08 16:30:53 +01:00
codeLocation = " 2 " ;
2013-02-22 07:52:51 +01:00
for ( int i = - 1 ; i < = 1 ; + + i ) {
for ( int j = - 1 ; j < = 1 ; + + j ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 3 " ;
2013-02-22 07:52:51 +01:00
Vec2i pos = unitPos + Vec2i ( i , j ) ;
if ( pos ! = unitPos ) {
2013-11-08 16:30:53 +01:00
codeLocation = " 4 " ;
2013-02-22 07:52:51 +01:00
bool canUnitMoveToCell = map - > aproxCanMove ( unit , unitPos , pos ) ;
if ( canUnitMoveToCell = = false ) {
failureCount + + ;
}
cellCount + + ;
}
}
}
2013-11-08 16:30:53 +01:00
codeLocation = " 5 " ;
2013-02-22 07:52:51 +01:00
unitImmediatelyBlocked = ( failureCount = = cellCount ) ;
2013-11-08 16:30:53 +01:00
}
catch ( const exception & ex ) {
//setRunningStatus(false);
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] Loc [%s] Error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) , ex . what ( ) ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
throw megaglest_runtime_error ( ex . what ( ) ) ;
}
catch ( . . . ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] UNKNOWN error Loc [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , codeLocation . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2013-02-22 07:52:51 +01:00
return unitImmediatelyBlocked ;
}
2012-03-10 04:27:25 +01:00
void PathFinder : : saveGame ( XmlNode * rootNode ) {
std : : map < string , string > mapTagReplacements ;
XmlNode * pathfinderNode = rootNode - > addChild ( " PathFinder " ) ;
pathfinderNode - > addAttribute ( " pathFindNodesMax " , intToStr ( pathFindNodesMax ) , mapTagReplacements ) ;
pathfinderNode - > addAttribute ( " pathFindNodesAbsoluteMax " , intToStr ( pathFindNodesAbsoluteMax ) , mapTagReplacements ) ;
for ( unsigned int i = 0 ; i < factions . size ( ) ; + + i ) {
FactionState & factionState = factions [ i ] ;
XmlNode * factionsNode = pathfinderNode - > addChild ( " factions " ) ;
for ( unsigned int j = 0 ; j < factionState . nodePool . size ( ) ; + + j ) {
Node * curNode = & factionState . nodePool [ j ] ;
XmlNode * nodePoolNode = factionsNode - > addChild ( " nodePool " ) ;
nodePoolNode - > addAttribute ( " pos " , curNode - > pos . getString ( ) , mapTagReplacements ) ;
int nextIdx = findNodeIndex ( curNode - > next , factionState . nodePool ) ;
nodePoolNode - > addAttribute ( " next " , intToStr ( nextIdx ) , mapTagReplacements ) ;
int prevIdx = findNodeIndex ( curNode - > prev , factionState . nodePool ) ;
2012-03-28 08:25:57 +02:00
nodePoolNode - > addAttribute ( " prev " , intToStr ( prevIdx ) , mapTagReplacements ) ;
2013-10-03 02:17:51 +02:00
nodePoolNode - > addAttribute ( " heuristic " , floatToStr ( curNode - > heuristic , 6 ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
nodePoolNode - > addAttribute ( " exploredCell " , intToStr ( curNode - > exploredCell ) , mapTagReplacements ) ;
}
2012-03-13 16:21:25 +01:00
factionsNode - > addAttribute ( " nodePoolCount " , intToStr ( factionState . nodePoolCount ) , mapTagReplacements ) ;
factionsNode - > addAttribute ( " random " , intToStr ( factionState . random . getLastNumber ( ) ) , mapTagReplacements ) ;
factionsNode - > addAttribute ( " useMaxNodeCount " , intToStr ( factionState . useMaxNodeCount ) , mapTagReplacements ) ;
2012-03-10 04:27:25 +01:00
}
}
2012-03-13 16:21:25 +01:00
void PathFinder : : loadGame ( const XmlNode * rootNode ) {
const XmlNode * pathfinderNode = rootNode - > getChild ( " PathFinder " ) ;
vector < XmlNode * > factionsNodeList = pathfinderNode - > getChildList ( " factions " ) ;
for ( unsigned int i = 0 ; i < factionsNodeList . size ( ) ; + + i ) {
XmlNode * factionsNode = factionsNodeList [ i ] ;
FactionState & factionState = factions [ i ] ;
vector < XmlNode * > nodePoolListNode = factionsNode - > getChildList ( " nodePool " ) ;
2013-01-03 18:30:59 +01:00
for ( unsigned int j = 0 ; j < nodePoolListNode . size ( ) & & j < pathFindNodesAbsoluteMax ; + + j ) {
2012-03-13 16:21:25 +01:00
XmlNode * nodePoolNode = nodePoolListNode [ j ] ;
Node * curNode = & factionState . nodePool [ j ] ;
curNode - > pos = Vec2i : : strToVec2 ( nodePoolNode - > getAttribute ( " pos " ) - > getValue ( ) ) ;
2012-04-04 17:36:09 +02:00
int nextNode = nodePoolNode - > getAttribute ( " next " ) - > getIntValue ( ) ;
if ( nextNode > = 0 ) {
curNode - > next = & factionState . nodePool [ nextNode ] ;
}
else {
curNode - > next = NULL ;
}
int prevNode = nodePoolNode - > getAttribute ( " prev " ) - > getIntValue ( ) ;
if ( prevNode > = 0 ) {
curNode - > prev = & factionState . nodePool [ prevNode ] ;
}
else {
curNode - > prev = NULL ;
}
2012-03-13 16:21:25 +01:00
curNode - > heuristic = nodePoolNode - > getAttribute ( " heuristic " ) - > getFloatValue ( ) ;
2012-04-16 22:15:57 +02:00
curNode - > exploredCell = nodePoolNode - > getAttribute ( " exploredCell " ) - > getIntValue ( ) ! = 0 ;
2012-03-13 16:21:25 +01:00
}
factionState . nodePoolCount = factionsNode - > getAttribute ( " nodePoolCount " ) - > getIntValue ( ) ;
factionState . random . setLastNumber ( factionsNode - > getAttribute ( " random " ) - > getIntValue ( ) ) ;
2013-01-03 18:30:59 +01:00
factionState . useMaxNodeCount = PathFinder : : pathFindNodesMax ;
2012-03-13 16:21:25 +01:00
}
}
2010-07-11 20:31:02 +02:00
} } //end namespace