Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

AICommon.ShotNotifier


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
///////////////////////////////////////////////////////////////////////////////
// The ShotNotifier notifies all registered clients when the Shooter fires a weapon
// Clients of the ShotNotifier are stored in the NotificationList, and should be registered through the Pawn

class ShotNotifier extends Core.DeleteableObject
	native;
///////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////
/// Private Variables
/////////////////////////////////////////////////
var private array<IShotNotification>  NotificationList;
var private Pawn                      Shooter;


/////////////////////////////////////////////////
/// Initialization
/////////////////////////////////////////////////
function InitializeShotNotifier(Pawn shooter)
{
    assert(shooter != None);
    
    self.Shooter = shooter;
}

/////////////////////////////////////////////////
/// Notifications from Pawn
/////////////////////////////////////////////////

// The Shooter's weapon code will call this function when it fires its weapon
function OnShotFired( Actor projectile )
{
     NotifyShotFired( projectile );
}

// Notify every client on the Notification List that we can see a Pawn
private function NotifyShotFired( Actor projectile )
{
    local int i;

    for( i = 0; i < NotificationList.Length; ++i )
    {
        NotificationList[i].OnShooterFiredShot( Shooter, projectile );
    }
}

/////////////////////////////////////////////////
/// Registration functions
/////////////////////////////////////////////////

// Register to be notified when the shooter shoots
function RegisterShotNotification(IShotNotification Registrant)
{
	local int i;		// debug

    assert(Registrant != None);

	if ( IsOnShotNotificationList(Registrant) )
	{
		log( "AI ERROR:" @ Registrant @ "has already registered for" @ shooter.name );
		for( i = 0; i < NotificationList.Length; ++i )
			log( "   " @ NotificationList[i] );
    }
    
    assert(! IsOnShotNotificationList(Registrant));

    NotificationList[NotificationList.Length] = Registrant;
}

// Unregister to be notified when the shooter shoots
function UnregisterShotNotification(IShotNotification Registrant)
{
    local int i;
   
	if ( Registrant == None )
		log( "AI WARNING:" @ self @ "has 'None' Registrant" );
    assert(Registrant != None);

#if !IG_TRIBES3
	if ( !IsOnShotNotificationList(Registrant) )
		log( "AI WARNING:" @ self @ Registrant @ "not on notification list" );
	assert(IsOnShotNotificationList(Registrant));
#endif

    for( i = 0; i < NotificationList.Length; ++i )
    {
        if (NotificationList[i] == Registrant)
        {
            NotificationList.Remove(i, 1);
            break;
        }
    }
}


/////////////////////////////////////////////////
/// Shot Notification Private Functions
/////////////////////////////////////////////////

// returns true if the Client interface is on the Shot notification list
// returns false if the Client interface is not on the Shot notification list
private function bool IsOnShotNotificationList(IShotNotification PossibleRegistrant)
{
    local int i;
    
    for( i = 0; i < NotificationList.Length; ++i)
    {
        if ( NotificationList[i] == PossibleRegistrant )
        {
            return true;
        }
    }
    
    // PossibleRegistrant not found
    return false;
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:02.000 - Creation time: st 23.5.2018 00:10:47.037 - Created with UnCodeX