XIIIMP
Class DuckBotController

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

class DuckBotController
extends XIIIMP.BotController

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 bool SeekAndFire

States
Seek, Kill

Function Summary
 rotator AdjustAim(Ammunition FiredAmmunition, vector projStart, int aimerror)
     
//__________________________________________________________________
 void InitPickUpList()
     
//__________________________________________________________________
 bool MissTheShoot()
     
//__________________________________________________________________


State Seek Function Summary
 void SomeoneWantKillMe(Pawn Agressor)


State Kill Function Summary



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class DuckBotController extends BotController;
00005	
00006	var bool SeekAndFire;
00007	
00008	//__________________________________________________________________
00009	
00010	event ChangeState()
00011	{
00012	    switch( CurrentOrder.TypeId )
00013	    {
00014	        case Order_Kill : GotoState( 'Kill' ); break;
00015	        case Order_Life : GotoState( 'Life' ); break;
00016	        case Order_Seek : GotoState( 'Seek' ); break;
00017	        case Order_Fear : gotoState( 'Fear' ); break;
00018	        case Order_Weapon : GotoState( 'Weapon' ); break;
00019	        case Order_Armor : GotoState( 'Armor' ); break;
00020	        case Order_SnipeSpot : GotoState( 'SnipeSpot' ); break;
00021	        case Order_SnipeAndKill : GotoState( 'SnipeAndKill' ); break;
00022	        case Order_UnBlock : gotoState( 'UnBlock' ); break;
00023	        case Order_TrakNar : gotoState( 'TrakNar' ); break;
00024	        case Order_GrenadLauncher : gotoState( 'GrenadLauncher' ); break;
00025	    }
00026	}
00027	
00028	//__________________________________________________________________
00029	
00030	function InitPickUpList()
00031	{
00032	    local PickUp A;
00033	
00034	    bInitPickUpList = true;
00035	    MarioMode = false;
00036	
00037	    foreach DynamicActors(class'PickUp', A)
00038	    {
00039	        FullPickUpList.Length = FullPickUpList.Length+1;
00040	        FullPickUpList[ FullPickUpList.Length-1 ] = A;
00041	
00042	        if ( MultiPlayerMedPickUp(A) != none )
00043	        {
00044	            MedKitList.Length = MedKitList.Length+1;
00045	            MedKitList[ MedKitList.Length-1 ] = MultiPlayerMedPickUp(A);
00046	        }
00047	        else if( XIIIAmmoPick(A) != none )
00048	        {
00049	            WeaponList.Length = WeaponList.Length+1;
00050	            WeaponList[ WeaponList.Length-1 ] = XIIIAmmoPick(A);
00051	        }
00052	        else if( XIIIArmorPickUp(A) != none )
00053	        {
00054	            ArmorList.Length = ArmorList.Length+1;
00055	            ArmorList[ ArmorList.Length-1 ] = XIIIArmorPickUp(A);
00056	        }
00057	    }
00058	
00059	    if( DBugBot )
00060	    {
00061	        Log("");
00062	        Log("[ BOT"@ID@"] : PickUpList Construction");
00063	        log("    > MedKit="$MedKitList.Length);
00064	        log("    > Armor="$ArmorList.Length);
00065	        log("    > Ammo="$WeaponList.Length);
00066	        log("    > FullPickUpList="$FullPickUpList.Length);
00067	    }
00068	}
00069	
00070	//__________________________________________________________________
00071	
00072	event AddDefaultOrders()
00073	{
00074	    if( ( Level.TimeSeconds - LastDefaultOrderTime < 3.0 ) && ( LastDefaultOrderTime != 0) )
00075	    {
00076			 if( ( DBugBot ) || ( DBugWarning ) )
00077				Log("[ WARNING ][ ORDER ][ BOT"@ID@"] : Runaway Loop !...");
00078	
00079	        AddOrder(79,Order_UnBlock,"UnBlock",0);
00080	    }
00081	    else
00082	    {
00083	        if( ! PathErrorToAllLife )
00084	            AddOrder(GetLifePriority(),Order_Life,"Life",0);
00085	
00086	        if( ! PathErrorToAllWeapon )
00087	            AddOrder(50,Order_Weapon,"Weapon",0);
00088	
00089	        if( ! PathErrorToAllArmor )
00090	            AddOrder(30,Order_Armor,"Armor",0);
00091	    }
00092	
00093	    LastDefaultOrderTime = Level.TimeSeconds;
00094	}
00095	
00096	//__________________________________________________________________
00097	
00098	event bool NotifyBump(Actor Other)
00099	{
00100	    if( Pawn( Other ) != none )
00101	    {
00102	        super.SeePlayer( Pawn(Other) );
00103	    }
00104	}
00105	
00106	//__________________________________________________________________
00107	
00108	event SeeMonster( Pawn Seen )
00109	{
00110	    SeePlayer( Seen );
00111	}
00112	
00113	//__________________________________________________________________
00114	
00115	event SeePlayer( Pawn Seen )
00116	{
00117	    if( TheDuck(Seen) != none )
00118	    {
00119	        if( Enemy == none )
00120	        {
00121	            Enemy = Seen;
00122	
00123	            if( IsShootable( Seen ) )
00124	                AddOrder(KillOrderPriority,Order_Kill,"Kill",0);
00125	            else
00126	                AddOrder(70,Order_Seek,"Seek",0);
00127	        }
00128	        else
00129	        {
00130	            Enemy = Seen;
00131	        }
00132	    }
00133	//    else if ( IsInAttackArea( Seen ) )
00134	//        super.SeePlayer( Seen );
00135	}
00136	
00137	//__________________________________________________________________
00138	
00139	function bool MissTheShoot()
00140	{
00141	    if( Rand( 100 ) < (3.5-Skill)*MissPercent )
00142	        return true;
00143	    else
00144	        return false;
00145	}
00146	
00147	//__________________________________________________________________
00148	
00149	function rotator AdjustAim(Ammunition FiredAmmunition, vector projStart, int aimerror)
00150	{
00151		local rotator RotatorError;
00152	
00153		if( Enemy == none )
00154	    	return ( Rotation );
00155	
00156	    if((  Level.TimeSeconds - ShotErrorTime < 0 ) || ( MissTheShoot() ) )
00157	    {
00158	        if( Rand( 2 ) == 1 )
00159	            RotatorError.Yaw = InitialShotError;
00160	        else
00161	            RotatorError.Yaw = 65535-InitialShotError;
00162	
00163	
00164	        if( TheDuck(Enemy ) != none )
00165	            SetRotation( rotator(Enemy.Location-(Pawn.Location+Pawn.EyePosition()) ) );
00166	        else
00167	            SetRotation( rotator(Enemy.GetBoneCoords('X Spine1').Origin-(Pawn.Location+Pawn.EyePosition()) ) );
00168	
00169	        Pawn.ControllerPitch = Rotation.Pitch / 256;
00170	    }
00171	    else
00172	    {
00173	        if( Rand( 100 ) < (Skill+1)*10 + HeadShotModificator )
00174	        {
00175	            if( TheDuck(Enemy ) != none )
00176	                SetRotation( rotator(Enemy.Location-(Pawn.Location+Pawn.EyePosition()) ) );
00177	            else
00178	                SetRotation( rotator(Enemy.GetBoneCoords('X Head').Origin-(Pawn.Location+Pawn.EyePosition()) ) );
00179	
00180	            Pawn.ControllerPitch = Rotation.Pitch / 256;
00181	        }
00182	        else
00183	        {
00184	            if( TheDuck(Enemy ) != none )
00185	                SetRotation( rotator(Enemy.Location-(Pawn.Location+Pawn.EyePosition()) ) );
00186	            else
00187	                SetRotation( rotator(Enemy.GetBoneCoords('X Spine1').Origin-(Pawn.Location+Pawn.EyePosition()) ) );
00188	
00189	            Pawn.ControllerPitch = Rotation.Pitch / 256;
00190	        }
00191	    }
00192	
00193	    return ( Rotation + RotatorError );
00194	}
00195	
00196	//__________________________________________________________________
00197	//__________________________________________________________________
00198	//                            Kill
00199	//__________________________________________________________________
00200	//__________________________________________________________________
00201	
00202	state Kill
00203	{
00204	    event SeeMonster( Pawn Seen )
00205	    {
00206	        SeePlayer( Seen );
00207	    }
00208	
00209	    //--------------------------------------------------------------
00210	
00211	    event SeePlayer( Pawn Seen )
00212	    {
00213	        local vector MyVect,OtherVect;
00214	
00215	        if( ( WaitBeforeFire ) && ( Seen == Enemy ) )
00216	        {
00217	            MyVect = Pawn.Location;
00218	            OtherVect = Seen.Location;
00219	            OtherVect.Z = MyVect.Z;
00220	
00221	            if( ( normal( OtherVect - MyVect ) dot ( vector( Pawn.Rotation ) ) ) > 0.85 )
00222	            {
00223	                WaitBeforeFire = false;
00224	
00225	                if( Rand( 100 ) < 10 + Skill*10 )
00226	                {
00227	                    Pawn.ShouldCrouch( true );
00228	                    InitShotError(True);
00229	                }
00230	                else
00231	                    InitShotError(false);
00232	
00233	                if( Pawn.WeaponMode == 'FM_Snipe' )
00234	                {
00235	                    SetTimer( 1.0 + FRand()/2, false );
00236	                }
00237	                else
00238	                    SetTimer( (4-Skill)*0.2+FRand()/2 ,False );
00239	            }
00240	        }
00241	
00242	        if( bFireMove )
00243	            return;
00244	
00245	        if( ( TheDuck(Seen) != none ) && ( Rand( 100 ) < 70 + Skill*10 ) )
00246	        {
00247	            Enemy = Seen;
00248	        }
00249	        else if( IsNearest( Enemy,Seen) )
00250	        {
00251	            Enemy = Seen;
00252	        }
00253	    }
00254	
00255	    //--------------------------------------------------------------
00256	
00257	    event EnemyNotVisible()
00258	    {
00259	        if( WaitBeforeFire )
00260	            return;
00261	
00262	        if( Pawn.bIsCrouched )
00263	            Pawn.ShouldCrouch( false );
00264	
00265	        SetTimer(0.0,false);
00266	        SetTimer2(0.0,false);
00267	
00268	        bFireMove = false;
00269	        NbStraffe = 0;
00270	
00271	        if( TheDuck(Enemy) != none )
00272	        {
00273	            bFire=0;
00274	            AddOrder( 70 ,Order_Seek,"Seek", 0);
00275	            RemoveOrder( Order_Kill );
00276	        }
00277	        else
00278	        {
00279	            bFire=0;
00280	            Enemy = none;
00281	
00282	            RemoveOrder( Order_Kill );
00283	        }
00284	    }
00285	
00286	    //--------------------------------------------------------------
00287	}
00288	
00289	//__________________________________________________________________
00290	//__________________________________________________________________
00291	//                            Seek
00292	//__________________________________________________________________
00293	//__________________________________________________________________
00294	
00295	state Seek
00296	{
00297	    event EndState()
00298	    {
00299	        bFire=0;
00300	        SetTimer(0.0,false);
00301	        SetTimer2(0.0,false);
00302	        SeekAndFire=false;
00303	    }
00304	
00305	    function SomeoneWantKillMe( Pawn Agressor )
00306	    {
00307	        if( ! PathErrorToAllLife )
00308	        {
00309	            if( FindOrder( Order_Life ) )
00310	                ModifyOrder( Order_Life, GetLifePriority() );
00311	            else
00312	                AddOrder(GetLifePriority(),Order_Life,"Life",0);
00313	        }
00314	
00315	        if( Agressor == Pawn )
00316	            return;
00317	
00318	        if( ( Agressor == Enemy ) || ( IsNearest( Enemy,Agressor ) ) )
00319	        {
00320	            Enemy = Agressor;
00321	            AddOrder(KillOrderPriority,Order_Kill,"Kill",Order_Seek);
00322	        }
00323	    }
00324	
00325	    event SeePlayer( Pawn Seen )
00326	    {
00327	        if( Seen == Enemy )
00328	        {
00329	            if( TheDuck(Seen) != none )
00330	            {
00331	                if( IsShootable( Seen ) )
00332	                {
00333	                    if( VSize( Seen.Location - Pawn.Location ) > 300 )
00334	                    {
00335	                        if( ! SeekAndFire )
00336	                        {
00337	                            SeekAndFire=true;
00338	                            SetTimer( (4-Skill)*0.2+FRand()/2 ,False );
00339	                        }
00340	                    }
00341	                    else
00342	                        AddOrder(KillOrderPriority,Order_Kill,"Kill",Order_Seek);
00343	                }
00344	            }
00345	            else if( IsShootable( Seen ) )
00346	                AddOrder(KillOrderPriority,Order_Kill,"Kill",Order_Seek);
00347	        }
00348	        else if( ( IsNearest( Enemy,Seen) ) && ( TheDuck(Enemy) != none ) )
00349	        {
00350	            Enemy = Seen;
00351	
00352	            if( IsShootable(Seen) )
00353	                AddOrder(KillOrderPriority,Order_Kill,"Kill",Order_Seek);
00354	            else
00355	                FindPathToMyEnemy();
00356	        }
00357	    }
00358	
00359	    event Timer()
00360	    {
00361	        if( MyWeaponIsAGrenad )
00362	        {
00363	            bFire=1;
00364	            Pawn.Weapon.Fire(0);
00365	            bFire=0;
00366	
00367	            SetTimer2(0.5,false);
00368	            SetTimer(0.0,false);
00369	        }
00370	        else if( XIIIWeapon(Pawn.Weapon).WeaponMode == WM_SemiAuto )
00371	        {
00372	            bFire=1;
00373	            Pawn.Weapon.Fire(0);
00374	            bFire=0;
00375	
00376	            SetTimer2( XIIIWeapon(Pawn.Weapon).ShotTime + ( 3 - Skill )*0.25,false );
00377	            SetTimer(0.0,false);
00378	        }
00379	        else if ( ( ( XIIIPawn(Pawn).WeaponMode == 'FM_M16' ) && ( XIIIWeapon(Pawn.Weapon).HasAltAmmo() ) ) && ( VSize( Enemy.Location - Pawn.Location ) < 1600 ) )
00380	        {
00381	            bFire=1;
00382	            Pawn.Weapon.AltFire(0);
00383	            bFire=0;
00384	
00385	            SetTimer2( 0.5,false );
00386	            SetTimer(0.0,false);
00387	        }
00388	        else
00389	        {
00390	            bFire=1;
00391	            Pawn.Weapon.Fire(0);
00392	
00393	            SetTimer2( 2.5 - skill/2,false );
00394	            SetTimer(0.0,false);
00395	        }
00396	    }
00397	
00398	    event Timer2()
00399	    {
00400	        if( MyWeaponIsAGrenad )
00401	        {
00402	            Pawn.Weapon.AIRating = 0.11;
00403	            SwitchWeapon();
00404	            SetTimer(1.0,false);
00405	            SetTimer2(0.0,false);
00406	        }
00407	        else if( XIIIWeapon(Pawn.Weapon).WeaponMode == WM_SemiAuto )
00408	        {
00409	            if( XIIIPawn(Pawn).WeaponMode == 'FM_Snipe' )
00410	                SetTimer(0.01 + FRand()/2,false);
00411	            else
00412	                SetTimer(0.01,false);
00413	
00414	            SetTimer2(0.0,false);
00415	        }
00416	        else if ( ( ( XIIIPawn(Pawn).WeaponMode == 'FM_M16' ) && ( XIIIWeapon(Pawn.Weapon).HasAltAmmo() ) ) && ( VSize( Enemy.Location - Pawn.Location ) < 1600 ) )
00417	        {
00418	            SetTimer(0.1,false);
00419	            SetTimer2(0.0,false);
00420	        }
00421	        else
00422	        {
00423	            bFire=0;
00424	            SetTimer(0.01,false);
00425	            SetTimer2(0.0,false);
00426	        }
00427	
00428	        if( ! Pawn.Weapon.HasAmmo() )
00429	            SwitchWeapon();
00430	    }
00431	
00432	}
00433	
00434	//__________________________________________________________________
00435	
00436	
00437	
00438	defaultproperties
00439	{
00440	}

End Source Code