SpatialFear.SFMedStationMover

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
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
//=============================================================================
// Spatial Fear
// Class: SFMedStationMover
// Descripton: Subclasses of SFMover, refills the smart vest when triggered.
//
// Author: Markus Nuebel
//=============================================================================

#exec AUDIO IMPORT FILE="Sounds\medstation\hiss2.WAV" NAME="hiss2" GROUP="SpatialFear"
#exec AUDIO IMPORT FILE="Sounds\medstation\hiss4.WAV" NAME="hiss4" GROUP="SpatialFear"
#exec AUDIO IMPORT FILE="Sounds\medstation\hiss5.WAV" NAME="hiss5" GROUP="SpatialFear"

class SFMedStationMover extends SFMover;

var (SpatialFear) bool	Broken; // Is station broken? If this is true, the station just plays the BrokenSound on activation. No healt is provided.. Default: false
var (SpatialFear) int	HealingAmount; // HealingAmount, the MedStation can provide. Defaults to 50.
var (SpatialFear) Sound	BrokenSound; // Sound played when a broken station is activated.
var (SpatialFear) Sound	DrainedSound; // Sound played when the station is drained.
var (SpatialFear) Sound	HealthFillingSound; // Sound played when the station is filling up the players health.
var (SpatialFear) Sound	SmartVestFillingSound; // Sound played when the station is filling up the smart vest.
var (SpatialFear) float RefillRadius; // The Radius in UUs, in within the refill works. When player leaves the radius, the refilling stops. Default: 40
var (SpatialFear) float Intervall; // Intervall for station refillment. Default: 0.6 secs.
var (SpatialFear) int	HealingStep; // Amount of health that is provided during on timer event of a refill action. Default: 4
var SFPlayer	m_oPlayer; // Private: Reference to SFPlayer, that starts the refill action
var name		m_strReturnState;
var float		m_fElapsedTime;



// Checks wheather the player is still in the range of the station
function bool  isPlayerInRange()
{
	local SFPlayer	oPlayer;
	local bool		bFound;
	
	bFound = false;
	foreach RadiusActors(class'SFPlayer', oPlayer, RefillRadius,


		Location) 
	{
		if(oPlayer == m_oPlayer)
			bFound = true;
	}
	return bFound;
}

state Refilling
{
	function Timer()
	{
		local int nAmount;

		// Todo check for RadiusActor

		if(isPlayerInRange())
		{
			nAmount = provideHealth();

			// Check if there is still a need and still health available
			if((0 < nAmount) && (0 < HealingAmount))
				SetTimer(Intervall, false);
			else
				GotoState(m_strReturnState);
		}
		else
			GotoState(m_strReturnState);
	}

	// Called from a timer event to refill player healh or smart vest
	// Retuns the amount of provided health
	function int provideHealth()
	{
		local int	nHealth, nNeededHealth;
		local int	nHealingAmount, nRest;

		// Some inits
		nRest			= 0;
		nHealingAmount	= 0;

		// Restore health
		nNeededHealth = 100 - m_oPlayer.Health;
		if(0 < nNeededHealth)
		{
			// Get max healing amount for this tick
			nHealingAmount = getHealingAmount(nNeededHealth);
			if(0 < nHealingAmount)
				PlaySound(HealthFillingSound,,2.0);

			// Restore health
			m_oPlayer.Health += nHealingAmount;
		}
		else
		{
			// Refill smart vest
			if((None != m_oPlayer.m_oSmartVest) && (0 < HealingAmount))
			{
				if(m_oPlayer.m_oSmartVest.needRefill())
				{
					// Get health need from vest
					nNeededHealth = m_oPlayer.m_oSmartVest.getRefillAmount();
					// Try to get one chunk from the station
					nHealingAmount = getHealingAmount(nNeededHealth );
					if(0 < nHealingAmount)
						PlaySound(SmartVestFillingSound,,2.0);
		
					// Refill the vest
					m_oPlayer.m_oSmartVest.refill(nHealingAmount);
				}
			}
		}

		// Check if there is health left in the statino
		if(0 >= HealingAmount)
		{
			Broken=true;
			PlaySound(DrainedSound,,2.0);
		}

		return nHealingAmount;
	}

	// Returns the healing amount a player
	// can get at max during one timer call
	function int getHealingAmount(int nRequested)
	{
		local int nAmount;
		
		// Get a stepsize or less
		nRequested = Min(nRequested, HealingStep);

		if(nRequested < HealingAmount)
		{
			// You get one healing step at max
			nAmount			= nRequested;
			HealingAmount	-= nRequested;
		}
		else
		{
			// We are going empty, if we are already empty we also go here and return 0
			nAmount			= HealingAmount;
			HealingAmount	= 0;
		}

		return nAmount;
	}

	function BeginState()
	{
		SetTimer(Intervall, false);
	}

	function EndState()
	{
	}
}


// When bumped by player.
function ManualBump( actor Other )
{
	local actor A;

	class'SFUtils'.Static.sfLogEx(15,"SFMedStationMover - ManualBump: Caused by: " $ Other.name);

	// check, if currently in refilling state
	if(IsInState('Refilling'))
		return; // Ignore new trigger

	// Check for player bumping
	if(!Other.IsA('SFPlayer'))
		return;
	
	// Save reference
	m_oPlayer = SFPlayer(Other);

	// Check radius
	if(!isPlayerInRange())
		return;

	// Inform player about med station contact
	m_oPlayer.m_actNearestMedStation = Self;

	// Check if station is working
	if(Broken)
	{
		PlaySound(BrokenSound,,2.0);
		return;
	}

	// Call to base class
	Super.ManualBump(Other);


}

function FinishedClosing()
{
	if(isPlayerInRange())
	{
		Super.FinishedClosing();

		m_strReturnState = GetStateName();

		if(0 < HealingAmount)
			// Start refilling
			GotoState('Refilling');
	}
}

defaultproperties
{
     HealingAmount=50
     BrokenSound=Sound'UnrealI.General.Endpush'
     DrainedSound=Sound'SpatialFear.SpatialFear.hiss2'
     HealthFillingSound=Sound'SpatialFear.SpatialFear.hiss4'
     SmartVestFillingSound=Sound'SpatialFear.SpatialFear.hiss5'
     RefillRadius=55.000000
     Intervall=0.600000
     HealingStep=4
}

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:45 PM
Created with UnCodeX