## XIDPawn
Class SharkController

source: C:\XIII\XIDPawn\Classes\SharkController.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Controller
             |
             +--Engine.AIController
                |
                +--XIDPawn.SharkController

Direct Known Subclasses:None

class SharkController
extends Engine.AIController

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`bool` | `CHARGE_LES_LOGS` Pour voir mes logs
`array` | `PathNodeSharkList`
`bool` | `bMove` Pour voir mes logs

States
PathWandering, init

Function Summary
`void` | `InitPathNodeSharkList()`
    //-----------------------------------------------------
    // init PathNodeJohan List
`NavigationPoint` | `PickStartPoint()`
    //-----------------------------------------------------
    // troouve le point le plus pres pour commencer

State PathWandering Function Summary
`NavigationPoint` | `LookForNextPoint()`

State init Function Summary

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class SharkController extends AIController;
    00005
    00006	var array<NavigationPoint> PathNodeSharkList;
    00007	var bool CHARGE_LES_LOGS; // Pour voir mes logs
    00008	var bool bMove;
    00009
    00010	//-----------------------------------------------------
    00011	// init PathNodeJohan List
    00012	function InitPathNodeSharkList()
    00013	{
    00014		local navigationpoint nav;
    00015
    00016		nav = Level.NavigationPointList;
    00017	   while (nav != None)
    00018	   {
    00019	      if (nav.tag==pawn.tag)
    00020			{
    00021				PathNodeSharkList.Length = PathNodeSharkList.Length + 1;
    00022	   		PathNodeSharkList[PathNodeSharkList.Length - 1] = nav;
    00023			}
    00024	      nav = nav.nextNavigationPoint;
    00025		}
    00026	}
    00027
    00028	//-----------------------------------------------------
    00029	// troouve le point le plus pres pour commencer
    00030	function NavigationPoint PickStartPoint()
    00031	{
    00032	   local int i;
    00033	   local NavigationPoint BestPoint;
    00034
    00035		for (i=0;i<PathNodeSharkList.Length;i++)
    00036	   {
    00037			if (BestPoint==none)
    00038			{
    00039				BestPoint=PathNodeSharkList[i];
    00040			}
    00041			else
    00042			{
    00043				if (vsize(PathNodeSharkList[i].location-pawn.location)<vsize(BestPoint.location-pawn.location))
    00044					BestPoint=PathNodeSharkList[i];
    00045			}
    00046	   }
    00047		return BestPoint;
    00048	}
    00049
    00050	//_________________________________________________________________________
    00051	// ETAT INIT
    00052	auto state init
    00053	{
    00054	begin:
    00055	   //CHARGE_LES_LOGS=true;
    00056	InitShark:
    00057	   InitPathNodeSharkList();
    00058		if (PickStartPoint()==none)
    00059		{
    00060			log("WARNING PAS DE POINTS POUR LE REQUIN:"@pawn.tag);
    00061			stop;
    00062		}
    00063	   pawn.rotationrate.yaw=9000;
    00064		pawn.velocity=vect(0,0,0);
    00065		pawn.acceleration=vect(0,0,0);
    00066		pawn.PlayMoving();
    00067		pawn.bcanswim=true;
    00068	   //bRotateToDesired = false;
    00069	   pawn.SetPhysics(PHYS_Swimming);
    00070	   gotostate('PathWandering');
    00071	}
    00072
    00073
    00074	//_________________________________________________________________________
    00075	// ETAT PathWandering
    00076	State PathWandering
    00077	{
    00078	   event tick(float dt) //steering
    00079		{
    00080		   super.tick(dt);
    00081
    00082		   if (vsize((movetarget.location-pawn.location)*vect(1,1,0))>150)
    00083		   {
    00084				pawn.acceleration=shark(pawn).fFacteurvitesse*( 150*normal((movetarget.location-pawn.location)*vect(1,1,0)) + 350*(1-(normal(movetarget.location-pawn.location) dot vector(pawn.rotation)))*vector(pawn.rotation)*vect(1,1,0));
    00085				if (CHARGE_LES_LOGS)  log("...suite"@vsize(pawn.acceleration)@vsize(pawn.velocity));
    00086		   }
    00087			else
    00088				gotostate('PathWandering','move');
    00089		}
    00090		event timer()
    00091		{
    00092			focalpoint=10000*(movetarget.location-pawn.location)*vect(1,1,0)+pawn.Location;
    00093		}
    00094		function NavigationPoint LookForNextPoint()
    00095	   {
    00096	   	local int i;
    00097			local NavigationPoint BestPoint;
    00098			local float Proba;
    00099
    00100			for (i=0;i<PathNodeSharkList.Length;i++)
    00101	      {
    00102				if (vSize(PathNodeSharkList[i].location-pawn.location)<2000)
    00103				{
    00104					Proba=0.5*normal(PathNodeSharkList[i].location-pawn.location) dot vector(pawn.rotation);
    00105			   	if (frand()<proba*0.7)
    00106					{
    00107						 BestPoint=PathNodeSharkList[i];
    00108						 break;
    00109					}
    00110				}
    00111	      }
    00112			if (BestPoint==none)
    00113			{
    00114	         if (CHARGE_LES_LOGS) log("jai pas selectionne de points j'en prend un au hasard");
    00115				BestPoint=PathNodeSharkList[rand(i-2)];
    00116			}
    00117			return  BestPoint;
    00118	   }
    00119	begin:
    00120		bmove=true;
    00121	Move:
    00122		MoveTarget=LookForNextPoint();
    00123	   timer(); //actualisation vision
    00124		settimer(2,true); //actualisation vision
    00125		focus=none;
    00126		destination=MoveTarget.location; //juste pour avoir visuel dans debug
    00127		stop;
    00128	}
    00129
    00130
    00131
    00132	defaultproperties
    00133	{
    00134	}

End Source Code