@ -705,18 +705,65 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const&
grp - > clrBotsAreNamedFlag ( ) ;
//addGroupInfo(grp, name, grp->getAlias());
eventCreateNpcBot ( grp , nbBots , false , sheetId , pos , " " , orientation , dispersionRadius , look ) ;
grp - > spawn ( ) ;
CSpawnGroupNpc * spawnGroup = grp - > getSpawnObj ( ) ;
if ( ! spawnGroup )
{
// the spawning has failed, delete the useless object
nlwarning ( " Failed to spawn the event group " ) ;
_EventNpcManager - > groups ( ) . removeChildByIndex ( grp - > getChildIndex ( ) ) ;
return NULL ;
}
spawnGroup - > setCell ( cell ) ;
NLMISC : : CSmartPtr < CNpcZonePlaceNoPrim > destZone = NLMISC : : CSmartPtr < CNpcZonePlaceNoPrim > ( new CNpcZonePlaceNoPrim ( ) ) ;
destZone - > setPosAndRadius ( AITYPES : : vp_auto , CAIPos ( pos , 0 , 0 ) , ( uint32 ) ( dispersionRadius * 1000. ) ) ;
spawnGroup - > movingProfile ( ) . setAIProfile ( new CGrpProfileWanderNoPrim ( spawnGroup , destZone ) ) ;
if ( ! botsName . empty ( ) )
{
// build unnamed bot
CStateMachine * sm = _EventNpcManager - > getStateMachine ( ) ;
uint32 stateAlias = grp - > getStateAlias ( " start " ) ;
CAIStatePositional * statePositional ;
if ( stateAlias = = 0 )
{
_LastStateAlias + + ;
statePositional = new CAIStatePositional ( sm , _LastStateAlias , " start " ) ;
grp - > setStateAlias ( " start " , statePositional - > getAlias ( ) ) ;
sm - > states ( ) . addChild ( statePositional ) ;
}
else
{
statePositional = safe_cast < CAIStatePositional * > ( sm - > states ( ) . getChildByAlias ( stateAlias ) ) ;
}
grp - > setNextState ( statePositional ) ;
}
if ( spawnBots )
grp - > getSpawnObj ( ) - > spawnBots ( ) ;
return grp ;
}
bool CAIInstance : : eventCreateNpcBot ( CGroupNpc * grp , uint nbBots , bool spawnBots , NLMISC : : CSheetId const & sheetId , CAIVector const & pos , const std : : string & name , double orientation , double dispersionRadius , const std : : string & look )
{
uint32 offset = grp - > bots ( ) . size ( ) ;
for ( uint i = 0 ; i < nbBots ; + + i )
{
_LastSpawnAlias + + ;
nlinfo ( " Spawn with alias : %d (%s) " , _LastSpawnAlias , _LigoConfig . aliasToString ( _LastSpawnAlias ) . c_str ( ) ) ;
grp - > bots ( ) . addChild ( new CBotNpc ( grp , _LastSpawnAlias , name ) , i ) ; // Doub: 0 instead of getAlias()+i otherwise aliases are wrong
grp - > bots ( ) . addChild ( new CBotNpc ( grp , _LastSpawnAlias , grp - > getName ( ) ) , offset + i ) ;
CBotNpc * const bot = NLMISC : : safe_cast < CBotNpc * > ( grp - > bots ( ) [ i ] ) ;
CBotNpc * const bot = NLMISC : : safe_cast < CBotNpc * > ( grp - > bots ( ) [ offset + i ] ) ;
AISHEETS : : ICreatureCPtr sheet = AISHEETS : : CSheets : : getInstance ( ) - > lookup ( sheetId ) ;
if ( ! sheet )
{
nlwarning ( " invalid sheet while creating event npc group " ) ;
return false ;
}
bot - > setSheet ( sheet ) ;
bot - > setPrimAlias ( 900 + _InstanceNumber ) ;
@ -726,10 +773,7 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const&
bot - > initEnergy ( /*groupEnergyCoef()*/ 0 ) ;
CAIVector rpos ( pos ) ;
if ( dispersionRadius = = 0 )
{
nlinfo ( " Stucked ! " ) ;
bot - > setStuck ( true ) ;
}
float angle = 0.f ;
if ( orientation < ( NLMISC : : Pi * 2.0 ) & & orientation > ( - NLMISC : : Pi * 2.0 ) )
@ -759,48 +803,15 @@ CGroupNpc* CAIInstance::eventCreateNpcGroup(uint nbBots, NLMISC::CSheetId const&
else
bot - > setStartPos ( rpos . x ( ) . asDouble ( ) , rpos . y ( ) . asDouble ( ) , angle , AITYPES : : vp_auto ) ;
}
}
grp - > spawn ( ) ;
CSpawnGroupNpc * spawnGroup = grp - > getSpawnObj ( ) ;
if ( ! spawnGroup )
{
// the spawning has failed, delete the useless object
nlwarning ( " Failed to spawn the event group " ) ;
_EventNpcManager - > groups ( ) . removeChildByIndex ( grp - > getChildIndex ( ) ) ;
return NULL ;
}
spawnGroup - > setCell ( cell ) ;
NLMISC : : CSmartPtr < CNpcZonePlaceNoPrim > destZone = NLMISC : : CSmartPtr < CNpcZonePlaceNoPrim > ( new CNpcZonePlaceNoPrim ( ) ) ;
destZone - > setPosAndRadius ( AITYPES : : vp_auto , CAIPos ( pos , 0 , 0 ) , ( uint32 ) ( dispersionRadius * 1000. ) ) ;
spawnGroup - > movingProfile ( ) . setAIProfile ( new CGrpProfileWanderNoPrim ( spawnGroup , destZone ) ) ;
if ( spawnBots )
grp - > getSpawnObj ( ) - > spawnBots ( name ) ;
if ( ! botsName . empty ( ) )
{
CStateMachine * sm = _EventNpcManager - > getStateMachine ( ) ;
uint32 stateAlias = grp - > getStateAlias ( " start " ) ;
CAIStatePositional * statePositional ;
if ( stateAlias = = 0 )
{
_LastStateAlias + + ;
statePositional = new CAIStatePositional ( sm , _LastStateAlias , " start " ) ;
grp - > setStateAlias ( " start " , statePositional - > getAlias ( ) ) ;
sm - > states ( ) . addChild ( statePositional ) ;
}
else
{
statePositional = safe_cast < CAIStatePositional * > ( sm - > states ( ) . getChildByAlias ( stateAlias ) ) ;
}
grp - > setNextState ( statePositional ) ;
return true ;
}
if ( spawnBots )
grp - > getSpawnObj ( ) - > spawnBots ( ) ;
return grp ;
}
CBotEasterEgg * CAIInstance : : createEasterEgg ( uint32 easterEggId , NLMISC : : CSheetId const & sheetId , std : : string const & botName , double x , double y , double z , double heading , const std : : string & look )
{