XIIIMP
Class TeamBotController

source: C:\XIII\XIIIMP\Classes\TeamBotController.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Controller
         |
         +--Engine.AIController
            |
            +--XIIIMP.BotController
               |
               +--XIIIMP.TeamBotController
Direct Known Subclasses:CTFBotController

class TeamBotController
extends XIIIMP.BotController

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 bool IsGrouped
 float LastBumpingTime
 Pawn Leader
 Array MyTeam
 int RepeatGrouping
 XIIIMPTeamStorage StorageObj
 vector UnBlockPos1,UnBlockPos2
 Pawn UnBumpActor
 bool UnBumping

States
UnBump, Kill, Dead, Grouping

Function Summary
 bool CanTryToHelp(TeamBotController Bot)
     
//__________________________________________________________________
 void FindTeamRole()
     
//__________________________________________________________________
 void InitPickUpList()
     
//__________________________________________________________________
 bool IsEnemy(Pawn Target)
     
//__________________________________________________________________
 void TryToHelpMe()
     
//__________________________________________________________________


State UnBump Function Summary


State Kill Function Summary


State Dead Function Summary


State Grouping Function Summary
 void FindRandomTeamPrey()
     
//--------------------------------------------------------------
 void FindMyBinome()
     
//--------------------------------------------------------------
 void FindPathToMyLeader()
     
//--------------------------------------------------------------



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class TeamBotController extends BotController;
00005	
00006	var Array<TeamBotController> MyTeam;
00007	var pawn Leader;
00008	var bool UnBumping;
00009	var float LastBumpingTime;
00010	var bool IsGrouped;
00011	var XIIIMPTeamStorage StorageObj;
00012	var int RepeatGrouping;
00013	var pawn UnBumpActor;
00014	var vector UnBlockPos1,UnBlockPos2;
00015	
00016	
00017	const Order_Grouping       = 512;
00018	const Order_UnBump         = 2147483648; //31
00019	
00020	
00021	//__________________________________________________________________
00022	
00023	function bool CanTryToHelp(TeamBotController Bot)
00024	{
00025	    if( Bot.Enemy != none )
00026	        return false;
00027	
00028	    if( Bot.IsInState('Dead') || Bot.IsInState('GameEnded') )
00029	        return false;
00030	    else
00031	        return true;
00032	}
00033	
00034	//__________________________________________________________________
00035	
00036	function TryToHelpMe()
00037	{
00038	    local int loop;
00039	    local TeamBotController TmpBot;
00040	    local vector MyVect,OtherVect;
00041	
00042	    for( Loop=0;Loop<MyTeam.Length;Loop++)
00043	    {
00044	        TmpBot = MyTeam[Loop];
00045	
00046	        if( CanTryToHelp( TmpBot ) )
00047	        {
00048	            if( VSize( Pawn.Location - TmpBot.Pawn.Location ) < 2500 )
00049	            {
00050	                MyVect = Pawn.Location;
00051	                OtherVect = TmpBot.Pawn.Location;
00052	                OtherVect.Z = MyVect.Z;
00053	
00054	                if( ( normal( MyVect - OtherVect ) dot ( vector( TmpBot.Pawn.Rotation ) ) ) > 0.7 )
00055	                {
00056	                    if( FastTrace( Pawn.Location, TmpBot.Pawn.Location ) )
00057	                    {
00058	                        TmpBot.SeePlayer(Enemy);
00059	                    }
00060	                }
00061	            }
00062	        }
00063	    }
00064	
00065	}
00066	
00067	//__________________________________________________________________
00068	
00069	function FindTeamRole()
00070	{
00071	    local int Loop,BestLevel,SecondBestLevel,WorstLevel;
00072	    local TeamBotController Best,SecondBest,Worst;
00073	    local Array<TeamBotController> TmpTeam;
00074	    local TeamBotController Bot;
00075	
00076	
00077	    foreach DynamicActors(class'TeamBotController', BOT)
00078	    {
00079	        if( Bot.TeamID == TeamID )
00080	        {
00081	            TmpTeam.Length = TmpTeam.Length+1;
00082	            TmpTeam[ TmpTeam.Length-1 ] = BOT;
00083	        }
00084	    }
00085	
00086	
00087	    for( Loop=0;Loop<TmpTeam.Length;Loop++)
00088	    {
00089	        if( ( TmpTeam[Loop].Skill > BestLevel ) || ( Best == none ) )
00090	        {
00091	            BestLevel = TmpTeam[Loop].Skill;
00092	            Best = TmpTeam[Loop];
00093	        }
00094	    }
00095	
00096	    if( Best == self )
00097	    {
00098	        TeamRole = 0;
00099	        return;
00100	    }
00101	
00102	    for( Loop=0;Loop<TmpTeam.Length;Loop++)
00103	    {
00104	        if( ( TmpTeam[Loop].Skill > SecondBestLevel ) || ( SecondBest == none ) )
00105	        {
00106	            if( TmpTeam[Loop] != Best )
00107	            {
00108	                SecondBestLevel = TmpTeam[Loop].Skill;
00109	                SecondBest = TmpTeam[Loop];
00110	            }
00111	        }
00112	    }
00113	
00114	    if( SecondBest == self )
00115	    {
00116	        TeamRole = 0;
00117	        return;
00118	    }
00119	
00120	    TeamRole = 1;
00121	}
00122	
00123	//__________________________________________________________________
00124	
00125	event AddDefaultOrders()
00126	{
00127	    if( ( Level.TimeSeconds - LastDefaultOrderTime < 2.0 ) && ( LastDefaultOrderTime != 0) )
00128	    {
00129			 if( ( DBugBot ) || ( DBugWarning ) )
00130				Log("[ WARNING ][ ORDER ][ BOT"@ID@"] : Runaway Loop !...");
00131	
00132	        AddOrder(79,Order_UnBlock,"UnBlock",0);
00133	    }
00134	    else
00135	    {
00136	        if( ! PathErrorToAllLife )
00137	            AddOrder(GetLifePriority(),Order_Life,"Life",0);
00138	
00139	        if( ! PathErrorToAllWeapon )
00140	            AddOrder(60,Order_Weapon,"Weapon",0);
00141	
00142	        if( ! PathErrorToAllArmor )
00143	            AddOrder(40,Order_Armor,"Armor",0);
00144	
00145	        AddOrder( 35,Order_Grouping,"Grouping",0);
00146	    }
00147	
00148	    LastDefaultOrderTime = Level.TimeSeconds;
00149	}
00150	
00151	//__________________________________________________________________
00152	
00153	event ChangeState()
00154	{
00155	    switch( CurrentOrder.TypeId )
00156	    {
00157	        case Order_Grouping : GotoState( 'Grouping' ); break;
00158	        case Order_UnBump : gotoState( 'UnBump' ); break;
00159	        case Order_Kill : GotoState( 'Kill' ); break;
00160	        case Order_Life : GotoState( 'Life' ); break;
00161	        case Order_Seek : GotoState( 'Seek' ); break;
00162	        case Order_Fear : gotoState( 'Fear' ); break;
00163	        case Order_Weapon : GotoState( 'Weapon' ); break;
00164	        case Order_Armor : GotoState( 'Armor' ); break;
00165	        case Order_SnipeSpot : GotoState( 'SnipeSpot' ); break;
00166	        case Order_SnipeAndKill : GotoState( 'SnipeAndKill' ); break;
00167	        case Order_UnBlock : gotoState( 'UnBlock' ); break;
00168	        case Order_TrakNar : gotoState( 'TrakNar' ); break;
00169	        case Order_GrenadLauncher : gotoState( 'GrenadLauncher' ); break;
00170	    }
00171	}
00172	
00173	//__________________________________________________________________
00174	
00175	function InitPickUpList()
00176	{
00177	    local PickUp A;
00178	    local NavigationPoint Nav;
00179	    local Pawn P;
00180	    local TeamBotController Bot;
00181	    local int Loop;
00182	
00183	    bInitPickUpList = true;
00184	
00185	    Nav = Level.NavigationPointList;
00186	
00187	    while( Nav != none)
00188	    {
00189	        if( SnipePathNode( Nav) != none )
00190	        {
00191	            if( ( ( SnipePathNode( Nav ).Team == TeamID ) || ( SnipePathNode( Nav ).Team == 2 ) ) && ( SnipePathNode( Nav).BotLevel <= Skill ) )
00192	            {
00193	                SnipeSpotList.Length = SnipeSpotList.Length+1;
00194	                SnipeSpotList[ SnipeSpotList.Length-1 ] = Nav;
00195	            }
00196	        }
00197	
00198	        Nav = Nav.NextNavigationPoint;
00199	    }
00200	
00201	    foreach DynamicActors(class'PickUp', A)
00202	    {
00203	        FullPickUpList.Length = FullPickUpList.Length+1;
00204	        FullPickUpList[ FullPickUpList.Length-1 ] = A;
00205	
00206	        if ( MultiPlayerMedPickUp(A) != none )
00207	        {
00208	            MedKitList.Length = MedKitList.Length+1;
00209	            MedKitList[ MedKitList.Length-1 ] = MultiPlayerMedPickUp(A);
00210	        }
00211	        else if( XIIIWeaponPickUp(A) != none )
00212	        {
00213	            WeaponList.Length = WeaponList.Length+1;
00214	            WeaponList[ WeaponList.Length-1 ] = XIIIWeaponPickUp(A);
00215	        }
00216	        else if( XIIIArmorPickUp(A) != none )
00217	        {
00218	            ArmorList.Length = ArmorList.Length+1;
00219	            ArmorList[ ArmorList.Length-1 ] = XIIIArmorPickUp(A);
00220	        }
00221	    }
00222	
00223	    foreach DynamicActors(class'TeamBotController', BOT)
00224	    {
00225	        if( ( Bot.TeamID == TeamID ) && ( BOT != self ) )
00226	        {
00227	            MyTeam.Length = MyTeam.Length+1;
00228	            MyTeam[ MyTeam.Length-1 ] = BOT;
00229	        }
00230	    }
00231	
00232	    foreach DynamicActors(class'XIIIMPTeamStorage', StorageObj)
00233	    {
00234	        if( StorageObj.TeamId == TeamId )
00235	            break;
00236	    }
00237	
00238	    FindTeamRole();
00239	
00240	    if( DBugBot )
00241	    {
00242	        Log("");
00243	        Log("[ BOT"@ID@"] : PickUpList Construction");
00244	        log("    > MedKit="$MedKitList.Length);
00245	        log("    > Weapon="$WeaponList.Length);
00246	        log("    > Armor="$ArmorList.Length);
00247	        log("    > SnipePoint="$SnipeSpotList.Length);
00248	        Log("    > Other Team Bot :"@MyTeam.Length );
00249	    }
00250	}
00251	
00252	//__________________________________________________________________
00253	
00254	function bool IsEnemy( Pawn Target )
00255	{
00256	    return ( Target.Controller.PlayerReplicationInfo.Team.TeamIndex != TeamID );
00257	}
00258	
00259	//__________________________________________________________________
00260	
00261	event bool NotifyBump(Actor Other)
00262	{
00263		local Pawn BumpPawn;
00264	//    if( LastBumpingTime == -1 )
00265	//        LastBumpingTime = Level.TimeSeconds;
00266	//    else if ( Level.TimeSeconds - LastBumpingTime > 3.0 )
00267	//        LastBumpingTime = Level.TimeSeconds;
00268		BumpPawn=Pawn(other);
00269	    if ( BumpPawn!= none && !BumpPawn.bIsDead)
00270	    {
00271	        if( Pawn.velocity!=vect(0,0,0) )
00272	        {
00273					if( ! IsEnemy( Pawn(Other) ) )
00274	            {
00275						UnBumpActor = Pawn(Other);
00276						AddOrder(79,Order_UnBump,"Un Bump",0);
00277	            }
00278	        }
00279	    }
00280		 return false;
00281	}
00282	
00283	//__________________________________________________________________
00284	//__________________________________________________________________
00285	//                            Grouping
00286	//__________________________________________________________________
00287	//__________________________________________________________________
00288	
00289	state Grouping
00290	{
00291	    event BeginState()
00292	    {
00293	        if( DBugBot )
00294	        {
00295	            Log("");
00296	            Log("[ BOT"@ID@"] : *STATE* ---> Grouping");
00297	
00298	        }
00299	
00300	        Enemy = none;
00301	        Pawn.ControllerPitch = 0;
00302	
00303	        Pawn.ShouldCrouch( false );
00304	
00305	        RepeatGrouping = 0;
00306	    }
00307	
00308	    //--------------------------------------------------------------
00309	
00310	    event SeePlayer( Pawn Seen )
00311	    {
00312	        if( ( Seen == Leader ) && ( VSize( Pawn.Location - Leader.Location ) < 500 ) )
00313	        {
00314	            if( DBugBot )
00315	            {
00316	                Log("");
00317	                Log("[ BOT"@ID@"] : FIND The LEADER");
00318	            }
00319	
00320	            IsGrouped = true;
00321	            gotostate('Grouping','TakeGodPrey');
00322	        }
00323	        else
00324	            global.SeePlayer( Seen );
00325	    }
00326	
00327	    //--------------------------------------------------------------
00328	
00329	    function FindPathToMyLeader()
00330	    {
00331	        local actor Path;
00332	
00333	        if( Leader == none || Leader.bIsDead)
00334	            return;
00335	
00336	        if( DBugBot ) Log(" > Search for"@Leader);
00337	
00338	        Path = ExtendFindPathToward(Leader);
00339	
00340	//        if( Path == none )
00341	//            Path = FindPathToward(Leader);
00342	
00343	        if( Path == none )
00344	        {
00345	            if( DBugBot ) Log("  > Failed ....");
00346	            Leader = none;
00347	        }
00348	        else
00349	        {
00350	            MoveTarget = Path;
00351	
00352	            if( DBugBot )
00353	                Log("    > Ok");
00354	        }
00355	    }
00356	
00357	    //--------------------------------------------------------------
00358	
00359	    function FindMyBinome()
00360	    {
00361	        local Controller C;
00362	        local float TmpDist, BestDist;
00363	        local Array<Pawn> TmpBinome;
00364	
00365	        Leader = none ;
00366	
00367	        foreach DynamicActors(class'Controller', C)
00368	        {
00369	            if( ( C.PlayerReplicationInfo.Team.TeamIndex == TeamID ) && ( C != self ) )
00370	            {
00371	                if( ( C.Pawn != none ) && ( ! C.Pawn.bIsDead ) )
00372	                {
00373	                    if( ( TeamBotController(C) != none ) && ( TeamBotController(C).TeamRole == TeamRole ) )
00374	                    {
00375	                        Leader = C.Pawn;
00376	                        return;
00377	                    }
00378	                    else
00379	                    {
00380	                        TmpBinome.Length = TmpBinome.Length+1;
00381	                        TmpBinome[ TmpBinome.Length-1 ] = C.Pawn;
00382	                    }
00383	                }
00384	            }
00385	        }
00386	
00387	        if( ( Leader == none ) && ( TmpBinome.Length != 0 ) )
00388	            Leader = TmpBinome[ Rand(TmpBinome.Length) ];
00389	    }
00390	
00391	    //--------------------------------------------------------------
00392	
00393	    function FindRandomTeamPrey()
00394	    {
00395	        local Controller C;
00396	        local Array<Pawn> TmpPrey;
00397	
00398	        if( StorageObj.Prey[ TeamID ] != none )
00399	            return;
00400	
00401	        foreach DynamicActors(class'Controller', C)
00402	        {
00403	            if( C.PlayerReplicationInfo.Team.TeamIndex != TeamID )
00404	            {
00405	                if( ( C.Pawn != none ) && ( ! C.Pawn.bIsDead ) )
00406	                {
00407	                    TmpPrey.Length = TmpPrey.Length+1;
00408	                    TmpPrey[ TmpPrey.Length-1 ] = C.Pawn;
00409	                }
00410	            }
00411	        }
00412	
00413	        if( TmpPrey.Length != 0 )
00414	            StorageObj.Prey[ TeamID ] = TmpPrey[ Rand(TmpPrey.Length) ];
00415	        else
00416	            StorageObj.Prey[ TeamID ] = none;
00417	    }
00418	
00419	    //--------------------------------------------------------------
00420	
00421	Begin:
00422	    if( Pawn.Physics == PHYS_Falling )
00423	    {
00424	        while( true )
00425	        {
00426	            sleep( 0.1 );
00427	
00428	            if ( Pawn.Physics != PHYS_Falling )
00429	               break;
00430	        }
00431	    }
00432	
00433	    FindMyBinome();
00434	
00435	    if( DBugBot ) log(" > Leader ="@Leader);
00436	
00437	
00438		while( true )
00439	   {
00440	        FindPathToMyLeader();   //FRD findpathtomyleader peut mettre le leader a none si pas de chemin
00441	
00442	        if( Leader == none || Leader.bIsDEad ) //FRD because find
00443	        {
00444	            log("[ BOT"@ID@"] ABORD GROUPING");
00445	            goto('TakeGodPrey');
00446	        }
00447	
00448	        ActorPathStorage( Leader );
00449	
00450	        if( ( Leader.bIsDead ) || ( Leader == none ) )
00451	        {
00452	            RepeatGrouping++;
00453	
00454	            if( RepeatGrouping > 2 )
00455	                goto('TakeGodPrey');
00456	            else
00457	                goto('begin');
00458	        }
00459	
00460	        if( TeamId == 0 ) Log("Grouping");
00461	
00462	        for( PathIndex = 0; PathIndex < PathCacheSize ; PathIndex ++ )
00463	        {
00464	            if( ( Leader.bIsDead ) || ( Leader == none ) )
00465	            {
00466	                RepeatGrouping++;
00467	
00468	                if( RepeatGrouping > 2 )
00469	                    goto('TakeGodPrey');
00470	                else
00471	                    goto('begin');
00472	            }
00473	
00474	            Pawn.ShouldCrouch( false );
00475	            MoveTarget = PathCache[ PathIndex ];
00476	            Focus=MoveTarget;
00477	
00478	            MoveToward( MoveTarget, Focus , MoveSpeed );
00479	        }
00480	    }
00481	
00482	    goto('TakeGodPrey');
00483	
00484	
00485	TakeGodPrey:
00486	
00487	    FindRandomTeamPrey();
00488	
00489	    if( StorageObj.Prey[ TeamID ] != none )
00490	    {
00491	        if( ! FindOrder( Order_Seek ) )
00492	        {
00493	            Enemy = StorageObj.Prey[ TeamID ];
00494	            AddOrder(70,Order_Seek,"Seek",Order_Grouping);
00495	        }
00496	    }
00497	
00498	    RemoveOrder( Order_Grouping );
00499	}
00500	
00501	//__________________________________________________________________
00502	//__________________________________________________________________
00503	//                            Dead
00504	//__________________________________________________________________
00505	//__________________________________________________________________
00506	/*state Dead
00507	{
00508	 	event BeginState()
00509	   {
00510	       super.BeginState();
00511		}
00512	} */
00513	
00514	//__________________________________________________________________
00515	//__________________________________________________________________
00516	//                            Kill
00517	//__________________________________________________________________
00518	//__________________________________________________________________
00519	
00520	state Kill
00521	{
00522	    event BeginState()
00523	    {
00524	        if( ( Rand( 100 ) < 50 ) && ( FindOrder( Order_Grouping ) ) )
00525	            RemoveOrder( Order_Grouping );
00526	
00527	        TryToHelpMe();
00528	
00529	        super.BeginState();
00530	    }
00531	
00532	    //--------------------------------------------------------------
00533	}
00534	
00535	//__________________________________________________________________
00536	//__________________________________________________________________
00537	//                            UnBump
00538	//__________________________________________________________________
00539	//__________________________________________________________________
00540	
00541	state UnBump
00542	{
00543	    event BeginState()
00544	    {
00545	        if( DBugBot )
00546	        {
00547	            Log("");
00548	            Log("[ BOT"@ID@"] : *STATE* ---> UnBump");
00549	        }
00550	
00551	        Pawn.ControllerPitch = 0;
00552	
00553	        Pawn.ShouldCrouch( false );
00554	
00555	
00556	        if( NavigationPoint( MoveTarget ) != none )
00557	        {
00558	            NavToUpDate = NavigationPoint( MoveTarget );
00559	            NavToUpDate.bSpecialCost=true;
00560	        }
00561	        else
00562	            NavToUpDate = none;
00563	    }
00564	
00565	    //--------------------------------------------------------------
00566	
00567	    event MayFall()
00568	    {
00569	        StopMvtWhenMayFall();
00570	        Pawn.velocity=vect(0,0,0);
00571	        Pawn.acceleration=vect(0,0,0);
00572	    }
00573	
00574	    //--------------------------------------------------------------
00575	
00576	    event bool NotifyBump(Actor Other);
00577	
00578	    //--------------------------------------------------------------
00579	
00580	Begin:
00581	
00582	    UnBlockPos1 = Pawn.Location + ( vector(pawn.rotation) cross (vect(0,0,1)) )*300;
00583	    UnBlockPos2 = Pawn.Location + ( vector(pawn.rotation) cross (vect(0,0,1)) )*300 + vector(pawn.rotation)*400;
00584	
00585	    Pawn.velocity=vect(0,0,0);
00586	    Pawn.acceleration=vect(0,0,0);
00587	
00588	    sleep(FRand());
00589	
00590	UnBlockPahse1:
00591	
00592	    focus = none;
00593	    focalpoint = UnBlockPos1;
00594	    MoveTo( UnBlockPos1 );
00595	
00596	UnBlockPahse2:
00597	
00598	    focus = none;
00599	    focalpoint = UnBlockPos2;
00600	    MoveTo( UnBlockPos2 );
00601	
00602	    Pawn.velocity=vect(0,0,0);
00603	    Pawn.acceleration=vect(0,0,0);
00604	
00605	    RemoveOrder(Order_UnBump);
00606	}
00607	
00608	//__________________________________________________________________
00609	
00610	
00611	
00612	defaultproperties
00613	{
00614	     LastBumpingTime=-1.000000
00615	}

End Source Code