Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // baseline thinking frequency may need adjustment on a per-game basis
- $AIManager::ThinkCycle = 64;
- // cycle through the list, triggering one bot decision per iteration
- // this avoids clumping heavy calculations together trying to run simultaneously
- function AIManager::think(%this,%botnum)
- {
- %thinkrate = $AIManager::ThinkCycle;
- if (isObject(%this.bots))
- {
- %botcount = %this.bots.getCount();
- %botnum++;
- if (%botnum>%botcount-1)
- {
- %botnum = -1;
- %this.updateTargetlist();
- }
- else
- {
- %bot = %this.bots.getObject(%botnum);
- if(isObject(%bot)) %bot.aiDecide();
- }
- // no point cycling through decisions faster than we can ghost the results
- if (%botcount<2)
- %thinkrate = 2* $AIManager::ThinkCycle;
- }
- %this.schedule(%thinkrate, think ,%botnum);
- }
- //planning
- function AIPlayer::aiDecide(%this)
- {
- if(!isObject(%this)||(%this.getState() $="Dead")) return;
- if (%this.isFalling) return;
- %this.Muttering();
- if(!isObject(%this.enemy))
- {
- %this.enemy = -1;
- %this.setstate($botstate_PathToNearest);
- }
- if (%this.confused) %this.setstate($botstate_Confused);
- if (%this.nextCommandTime>$Sim::Time) return;
- if( VectorLen(%this.getVelocity()) > 0.1 )
- %this.moving = true;
- else
- %this.moving = false;
- switch(%this.botstate)
- {
- case $botstate_Moving:
- if (%this.updateNavmesh>1000/$AIManager::ThinkCycle)
- {
- %this.updateNavmesh = 0;
- if( %this.moving)
- {
- %pos = %this.getPosition();
- NavMeshIgnore(%this,true);
- NavMeshUpdateBox(%pos,"3 3 3");
- schedule(200,0,"NavMeshUpdateBox",%pos,"3 3 3");
- return;
- }
- else
- {
- %pos = %this.getPosition();
- NavMeshIgnore(%this,false);
- NavMeshUpdateBox(%pos,"3 3 3");
- schedule(200,0,"NavMeshUpdateBox",%pos,"3 3 3");
- %this.setstate($botstate_Wander);
- }
- }
- else
- %this.updateNavmesh++;
- case $botstate_Confused:
- %this.randomPath();
- case $botstate_fire:
- %this.aiShoot();
- case $botstate_Wander:
- %this.randomPath();
- case $botstate_Shuffle:
- %this.randomPoint(1);
- case $botstate_PathToNearest:
- %this.PathToNearest();
- case $botstate_WaypointMove:
- %this.moving = true;
- return;
- default:
- %this.setstate($botstate_Wander);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement