## XIIIMP
Class CatchableDuckBotController

source: C:\XIII\XIIIMP\Classes\CatchableDuckBotController.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Controller
             |
             +--Engine.AIController
                |
                +--XIIIMP.BotController
                   |
                   +--XIIIMP.CatchableDuckBotController

Direct Known Subclasses:None

class CatchableDuckBotController
extends XIIIMP.BotController

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

Variables
`bool` | `SeekAndFire`

States
Kill, SeekDuckCarrier, Hunted, CatchTheDuck

Function Summary
`int` | `GetLifePriority()`
    //__________________________________________________________________
`void` | `GetTheDuck()`
    //__________________________________________________________________
`void` | `InitPickUpList()`
    //__________________________________________________________________

State Kill Function Summary

State SeekDuckCarrier Function Summary
`void` | `CheckDuckState()`
`void` | `FindPathToMyEnemy()`
`void` | `SomeoneWantKillMe(Pawn Agressor)`

State Hunted Function Summary
`bool` | `CheckPath()`
`void` | `SomeoneWantKillMe(Pawn Agressor)`

State CatchTheDuck Function Summary
`void` | `CheckDuckState()`
`void` | `SomeoneWantKillMe(Pawn Agressor)`

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class CatchableDuckBotController extends BotController;
    00005
    00006	const Order_CatchTheDuck       = 131072;
    00007	const Order_Hunted             = 262144;
    00008	const Order_SeekDuckCarrier    = 524288;
    00009
    00010	var bool SeekAndFire;
    00011
    00012	//__________________________________________________________________
    00013
    00014	function GetTheDuck()
    00015	{
    00016	    if( !FindOrder( Order_Hunted ) )
    00017	    {
    00018	        AddOrder( 75, Order_Hunted,"Hunted",Order_CatchTheDuck);
    00019
    00020	        if( FindOrder( Order_Life ) )
    00021	            RemoveOrder( Order_Life );
    00022
    00023	        if( FindOrder( Order_Armor ) )
    00024	            RemoveOrder( Order_Armor );
    00025
    00026	        if( FindOrder( Order_Weapon ) )
    00027	            RemoveOrder( Order_Weapon );
    00028
    00029	        if( FindOrder( Order_Seek ) )
    00030	            RemoveOrder( Order_Seek );
    00031	    }
    00032	}
    00033
    00034	//__________________________________________________________________
    00035
    00036	event SeeMonster( Pawn Seen )
    00037	{
    00038	    log("see monster");
    00039
    00040	    if( FindOrder( Order_CatchTheDuck ) )
    00041	        ModifyOrder( Order_CatchTheDuck , 74 );
    00042	}
    00043
    00044	//__________________________________________________________________
    00045
    00046	event SeePlayer( Pawn Seen )
    00047	{
    00048	    if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck == Seen )
    00049	    {
    00050	        if( FindOrder( Order_SeekDuckCarrier ) )
    00051	            ModifyOrder( Order_SeekDuckCarrier , 75 );
    00052	    }
    00053	    else
    00054	    {
    00055	        super.SeePlayer( Seen );
    00056	    }
    00057	}
    00058
    00059	//__________________________________________________________________
    00060
    00061	event ChangeState()
    00062	{
    00063	    switch( CurrentOrder.TypeId )
    00064	    {
    00065	        case Order_Kill : GotoState( 'Kill' ); break;
    00066	        case Order_Life : GotoState( 'Life' ); break;
    00067	        case Order_Armor : GotoState( 'Armor' ); break;
    00068	        case Order_Weapon : GotoState( 'Weapon' ); break;
    00069	        case Order_Seek : GotoState( 'Seek' ); break;
    00070	        case Order_Fear : gotoState( 'Fear' ); break;
    00071	        case Order_UnBlock : gotoState( 'UnBlock' ); break;
    00072	        case Order_CatchTheDuck : gotoState( 'CatchTheDuck' ); break;
    00073	        case Order_SeekDuckCarrier : gotoState( 'SeekDuckCarrier' ); break;
    00074	        case Order_Hunted : gotoState( 'Hunted' ); break;
    00075	    }
    00076	}
    00077
    00078	//__________________________________________________________________
    00079
    00080	function InitPickUpList()
    00081	{
    00082	    local PickUp A;
    00083
    00084	    bInitPickUpList = true;
    00085	    MarioMode = false;
    00086
    00087	    foreach DynamicActors(class'PickUp', A)
    00088	    {
    00089	        FullPickUpList.Length = FullPickUpList.Length+1;
    00090	        FullPickUpList[ FullPickUpList.Length-1 ] = A;
    00091
    00092	        if ( MultiPlayerMedPickUp(A) != none )
    00093	        {
    00094	            MedKitList.Length = MedKitList.Length+1;
    00095	            MedKitList[ MedKitList.Length-1 ] = MultiPlayerMedPickUp(A);
    00096	        }
    00097	        else if( XIIIAmmoPick(A) != none )
    00098	        {
    00099	            WeaponList.Length = WeaponList.Length+1;
    00100	            WeaponList[ WeaponList.Length-1 ] = XIIIAmmoPick(A);
    00101	        }
    00102	        else if( XIIIArmorPickUp(A) != none )
    00103	        {
    00104	            ArmorList.Length = ArmorList.Length+1;
    00105	            ArmorList[ ArmorList.Length-1 ] = XIIIArmorPickUp(A);
    00106	        }
    00107	    }
    00108
    00109	    if( DBugBot )
    00110	    {
    00111	        Log("");
    00112	        Log("[ BOT"@ID@"] : PickUpList Construction");
    00113	        log("    > MedKit="$MedKitList.Length);
    00114	        log("    > Armor="$ArmorList.Length);
    00115	        log("    > Ammo="$WeaponList.Length);
    00116	        log("    > FullPickUpList="$FullPickUpList.Length);
    00117	    }
    00118	}
    00119
    00120	//__________________________________________________________________
    00121
    00122	function int GetLifePriority()
    00123	{
    00124	    if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck == Pawn )
    00125	        return 0;
    00126	    else
    00127	        super.GetLifePriority();
    00128	}
    00129
    00130	//__________________________________________________________________
    00131
    00132	event AddDefaultOrders()
    00133	{
    00134	    if( ( Level.TimeSeconds - LastDefaultOrderTime < 3.0 ) && ( LastDefaultOrderTime != 0) )
    00135	    {
    00136			 if( ( DBugBot ) || ( DBugWarning ) )
    00137				Log("[ WARNING ][ ORDER ][ BOT"@ID@"] : Runaway Loop !...");
    00138
    00139	        AddOrder(79,Order_UnBlock,"UnBlock",0);
    00140	    }
    00141	    else
    00142	    {
    00143	        if( ! PathErrorToAllLife )
    00144	            AddOrder(GetLifePriority(),Order_Life,"Life",0);
    00145
    00146	        if( ! PathErrorToAllArmor )
    00147	            AddOrder(60,Order_Armor,"Armor",0);
    00148
    00149	        if( ! PathErrorToAllWeapon )
    00150	            AddOrder(50,Order_Weapon,"Weapon",0);
    00151
    00152	        if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck != none )
    00153	            AddOrder(45,Order_SeekDuckCarrier,"SeekDuckCarrier",0);
    00154
    00155	        AddOrder(40,Order_CatchTheDuck,"CatchTheDuck",0);
    00156	    }
    00157
    00158	    LastDefaultOrderTime = Level.TimeSeconds;
    00159	}
    00160
    00161	//__________________________________________________________________
    00162	//__________________________________________________________________
    00163	//                            CatchTheDuck
    00164	//__________________________________________________________________
    00165	//__________________________________________________________________
    00166
    00167	state CatchTheDuck
    00168	{
    00169	    event BeginState()
    00170	    {
    00171	        if( DBugBot )
    00172	        {
    00173	            Log("");
    00174	            Log("[ BOT"@ID@"] : *STATE* ---> CatchTheDuck");
    00175	        }
    00176
    00177	        if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck != none )
    00178	        {
    00179	            ModifyOrder( Order_CatchTheDuck , 40 ); //Security if Priority = 75
    00180	        }
    00181
    00182	        Enemy = XIIIMPDuckGameInfo(Level.Game).TheDuck;
    00183	        Pawn.ControllerPitch = 0;
    00184
    00185	        Pawn.ShouldCrouch( false );
    00186
    00187	        SetTimer3(1.0,true);
    00188	    }
    00189
    00190	    event EndState()
    00191	    {
    00192	        SetTimer3(0.0,False);
    00193	    }
    00194
    00195	    event Timer3()
    00196	    {
    00197	        CheckDuckState();
    00198	    }
    00199
    00200	    event SeePlayer( Pawn Seen )
    00201	    {
    00202	        if( ( ( VSize( Seen.Location - Pawn.Location ) < 500 ) || ( Rand( 100 ) > skill*30 ) ) && ( PathIndex < PathCacheSize - 1 ) )
    00203	            global.SeePlayer( Seen );
    00204	    }
    00205
    00206	    function SomeoneWantKillMe( Pawn Agressor )
    00207	    {
    00208	        if( Agressor == Pawn )
    00209	            return;
    00210
    00211	        if( PathIndex < PathCacheSize - 1 )
    00212	            global.SomeoneWantKillMe( Agressor );
    00213	    }
    00214
    00215	    function CheckDuckState()
    00216	    {
    00217	        if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck != none )
    00218	        {
    00219	            if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck != Pawn )
    00220	            {
    00221	                AddOrder(45,Order_SeekDuckCarrier,"SeekDuckCarrier",0);
    00222	                ModifyOrder( Order_CatchTheDuck , 40 ); //Security if Priority = 75
    00223	            }
    00224	        }
    00225	    }
    00226
    00227	Begin:
    00228
    00229	    while(true)
    00230	    {
    00231	        ActorPathStorage( Enemy );
    00232
    00233	        if( MoveTarget == none )
    00234	            RemoveOrder( Order_CatchTheDuck );
    00235
else 00236 { 00237 for( PathIndex = 0; PathIndex < PathCacheSize ; PathIndex ++ ) 00238 { 00239 MoveTarget = PathCache[ PathIndex ]; 00240 Focus=MoveTarget; 00241 00242 MoveToward( MoveTarget, Focus , MoveSpeed ); 00243 } 00244 00245 if( Rand( 100 ) < 30 + skill*15 ) 00246 RemoveOrder( Order_CatchTheDuck ); 00247 } 00248 } 00249 } 00250 00251 //__________________________________________________________________ 00252 //__________________________________________________________________ 00253 // Hunted 00254 //__________________________________________________________________ 00255 //__________________________________________________________________ 00256 00257 state Hunted 00258 { 00259 event BeginState() 00260 { 00261 if( DBugBot ) 00262 { 00263 Log(""); 00264 Log("[ BOT"@ID@"] : *STATE* ---> Hunted"); 00265 } 00266 00267 Enemy = none; 00268 Pawn.ControllerPitch = 0; 00269 00270 Pawn.ShouldCrouch( false ); 00271 00272 if( ! Pawn.Weapon.HasAmmo() ) 00273 SwitchWeapon(); 00274 else 00275 Pawn.Weapon.ForceReload(); 00276 } 00277 00278 event SeePlayer( Pawn Seen ) 00279 { 00280 if( VSize( Seen.Location - Pawn.Location ) < 200 ) 00281 SomeoneWantKillMe( Seen ); 00282 } 00283 00284 function SomeoneWantKillMe( Pawn Agressor ) 00285 { 00286 if( Agressor == Pawn ) 00287 return; 00288 00289 if( ( !FindOrder( Order_Kill ) ) && ( VSize( Agressor.Location - Pawn.Location ) < 600 ) ) 00290 { 00291 Enemy = Agressor; 00292 AddOrder(KillOrderPriority,Order_Kill,"Kill",0); 00293 } 00294 } 00295 00296 function bool CheckPath() 00297 { 00298 local vector HitLocation; 00299 local vector HitNormal; 00300 local actor ColActor; 00301 00302 ColActor=Trace( HitLocation,HitNormal,MoveTarget.Location,Pawn.Location, true); 00303 00304 if( ColActor == none ) 00305 return true; 00306 else 00307 return false; 00308 } 00309 00310 Begin: 00311 00312 GetRandomLocation(); 00313 00314 while( true ) 00315 { 00316 PickUpPathStorage(Item); 00317 00318 for( PathIndex = 0; PathIndex < PathCacheSize ; PathIndex ++ ) 00319 { 00320 MoveTarget = PathCache[ PathIndex ]; 00321 Focus=MoveTarget; 00322 00323 if( ! CheckPath() ) 00324 Goto('begin'); 00325 00326 MoveToward( MoveTarget, Focus , MoveSpeed ); 00327 } 00328 00329 if( FullPath ) 00330 goto('begin'); 00331 } 00332 } 00333 00334 //__________________________________________________________________ 00335 //__________________________________________________________________ 00336 // SeekDuckCarrier 00337 //__________________________________________________________________ 00338 //__________________________________________________________________ 00339 00340 state SeekDuckCarrier 00341 { 00342 event EndState() 00343 { 00344 bFire=0; 00345 SetTimer(0.0,false); 00346 SetTimer2(0.0,false); 00347 SetTimer3(0.0,false); 00348 SeekAndFire=false; 00349 } 00350 00351 event BeginState() 00352 { 00353 if( DBugBot ) 00354 { 00355 Log(""); 00356 Log("[ BOT"@ID@"] : *STATE* ---> SeekDuckCarrier"); 00357 00358 } 00359 00360 Pawn.ControllerPitch = 0; 00361 00362 Pawn.ShouldCrouch( false ); 00363 00364 Enemy = XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck; 00365 00366 SetTimer3(1.0,true); 00367 } 00368 00369 event Timer() 00370 { 00371 if( MyWeaponIsAGrenad ) 00372 { 00373 bFire=1; 00374 Pawn.Weapon.Fire(0); 00375 bFire=0; 00376 00377 SetTimer2(0.5,false); 00378 SetTimer(0.0,false); 00379 } 00380 else if( XIIIWeapon(Pawn.Weapon).WeaponMode == WM_SemiAuto ) 00381 { 00382 bFire=1; 00383 Pawn.Weapon.Fire(0); 00384 bFire=0; 00385 00386 SetTimer2( XIIIWeapon(Pawn.Weapon).ShotTime + ( 3 - Skill )*0.25,false ); 00387 SetTimer(0.0,false); 00388 } 00389 else if ( ( ( XIIIPawn(Pawn).WeaponMode == 'FM_M16' ) && ( XIIIWeapon(Pawn.Weapon).HasAltAmmo() ) ) && ( VSize( Enemy.Location - Pawn.Location ) < 1600 ) ) 00390 { 00391 bFire=1; 00392 Pawn.Weapon.AltFire(0); 00393 bFire=0; 00394 00395 SetTimer2( 0.5,false ); 00396 SetTimer(0.0,false); 00397 } 00398 else 00399 { 00400 bFire=1; 00401 Pawn.Weapon.Fire(0); 00402 00403 SetTimer2( 2.5 - skill/2,false ); 00404 SetTimer(0.0,false); 00405 } 00406 } 00407 00408 event Timer2() 00409 { 00410 if( MyWeaponIsAGrenad ) 00411 { 00412 Pawn.Weapon.AIRating = 0.11; 00413 SwitchWeapon(); 00414 SetTimer(1.0,false); 00415 SetTimer2(0.0,false); 00416 } 00417 else if( XIIIWeapon(Pawn.Weapon).WeaponMode == WM_SemiAuto ) 00418 { 00419 if( XIIIPawn(Pawn).WeaponMode == 'FM_Snipe' ) 00420 SetTimer(0.01 + FRand()/2,false); 00421 else 00422 SetTimer(0.01,false); 00423 00424 SetTimer2(0.0,false); 00425 } 00426 else if ( ( ( XIIIPawn(Pawn).WeaponMode == 'FM_M16' ) && ( XIIIWeapon(Pawn.Weapon).HasAltAmmo() ) ) && ( VSize( Enemy.Location - Pawn.Location ) < 1600 ) ) 00427 { 00428 SetTimer(0.1,false); 00429 SetTimer2(0.0,false); 00430 } 00431 else 00432 { 00433 bFire=0; 00434 SetTimer(0.01,false); 00435 SetTimer2(0.0,false); 00436 } 00437 00438 if( ! Pawn.Weapon.HasAmmo() ) 00439 SwitchWeapon(); 00440 } 00441 00442 event Timer3() 00443 { 00444 CheckDuckState(); 00445 } 00446 00447 function SomeoneWantKillMe( Pawn Agressor ) 00448 { 00449 if( ! PathErrorToAllLife ) 00450 { 00451 if( FindOrder( Order_Life ) ) 00452 ModifyOrder( Order_Life, GetLifePriority() ); 00453 else 00454 AddOrder(GetLifePriority(),Order_Life,"Life",0); 00455 } 00456 00457 if( ! IsEnemy( Agressor ) ) 00458 return; 00459 00460 if( Agressor == Pawn ) 00461 return; 00462 00463 if( ( Agressor == Enemy ) || ( VSize( Agressor.Location - Pawn.Location ) < 500 ) ) 00464 { 00465 Enemy = Agressor; 00466 AddOrder(KillOrderPriority,Order_Kill,"Kill",0); 00467 } 00468 } 00469 00470 event SeePlayer( Pawn Seen ) 00471 { 00472 if( Seen == Enemy ) 00473 { 00474 if( IsShootable( Seen ) ) 00475 { 00476 if( VSize( Seen.Location - Pawn.Location ) > 300 ) 00477 { 00478 if( ! SeekAndFire ) 00479 { 00480 SeekAndFire=true; 00481 SetTimer( (4-Skill)*0.2+FRand()/2 ,False ); 00482 } 00483 } 00484 else 00485 AddOrder(KillOrderPriority,Order_Kill,"Kill",Order_Seek); 00486 } 00487 } 00488 else if( ( VSize( Seen.Location - Pawn.Location ) < 400 ) && ( Rand( 100 ) < 90 - Skill*20 ) ) 00489 { 00490 if( IsShootable(Seen) ) 00491 { 00492 Enemy = Seen; 00493 AddOrder(KillOrderPriority,Order_Kill,"Kill",0); 00494 } 00495 } 00496 } 00497 00498 event EnemyNotVisible() 00499 { 00500 if( SeekAndFire ) 00501 { 00502 SeekAndFire=false; 00503 SetTimer(0.0,false); 00504 SetTimer2(0.0,false); 00505 Pawn.Weapon.ForceReload(); 00506 } 00507 } 00508 00509 function FindPathToMyEnemy() 00510 { 00511 local actor Path; 00512 00513 if( DBugBot ) 00514 { 00515 Log(""); 00516 Log("[ BOT"@ID@"] : Search for"@Enemy); 00517 } 00518 00519 Path = ExtendFindPathToward(Enemy); 00520 00521 if( Path == none ) 00522 Path = FindPathToward(Enemy); 00523 00524 if( Path == none ) 00525 { 00526 if( DBugBot ) Log(" > Failed ...."); 00527 Enemy = none; 00528 } 00529 else 00530 { 00531 MoveTarget = Path; 00532 00533 if( DBugBot ) 00534 Log(" > Ok"); 00535 } 00536 } 00537 00538 function CheckDuckState() 00539 { 00540 if( XIIIMPDuckGameInfo(Level.Game).WhoHasTheDuck == none ) 00541 RemoveOrder(Order_SeekDuckCarrier); 00542 } 00543 00544 Begin: 00545 00546 FindPathToMyEnemy(); 00547 00548 if( Enemy == none ) 00549 RemoveOrder( Order_SeekDuckCarrier ); 00550 00551 while( true ) 00552 { 00553 ActorPathStorage( Enemy); 00554 00555 if( MoveTarget == none ) 00556 RemoveOrder( Order_SeekDuckCarrier ); 00557 00558 for( PathIndex = 0; PathIndex < PathCacheSize ; PathIndex ++ ) 00559 { 00560 MoveTarget = PathCache[ PathIndex ]; 00561 Focus=MoveTarget; 00562 00563 MoveToward( MoveTarget, Focus , MoveSpeed ); 00564 } 00565 00566 if( ( Rand( 100 ) < 60 + skill*10 ) && ( ! IsShootable( Enemy ) ) ) 00567 RemoveOrder( Order_SeekDuckCarrier ); 00568 } 00569 } 00570 00571 //__________________________________________________________________ 00572 //__________________________________________________________________ 00573 // Kill 00574 //__________________________________________________________________ 00575 //__________________________________________________________________ 00576 00577 state Kill 00578 { 00579 event EnemyNotVisible() 00580 { 00581 if( Pawn.bIsCrouched ) 00582 Pawn.ShouldCrouch( false ); 00583 00584 RemoveOrder( Order_Kill ); 00585 } 00586 } 00587 00588 //__________________________________________________________________ 00589 00590 00591 00592 defaultproperties 00593 { 00594 }

End Source Code