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

UTPlusStandaloneHitSounds.UTPlusHitSounds


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
/******************************************************************************
UTPlusHitSounds

Creation date: 2011-08-29 11:08
Last change: $Id$
Copyright © 2011, Wormbo
Website: http://www.koehler-homepage.de/Wormbo/
Feel free to reuse this code. Send me a note if you found it helpful or want
to report bugs/provide improvements.
Please ask for permission first, if you intend to make money off reused code.
******************************************************************************/

class UTPlusHitSounds extends GameRules;


//=============================================================================
// Variables
//=============================================================================

var bool bAllowVariableHitSounds;
var bool bLineOfSightHitSounds;
var bool bObjectiveHitSounds;

/** List of hit sound replicators. */
var UTPlusHitSoundTag firstTagHitSound;

// Hit sound replicators are spawned in FindPlayerStart().
// These vars help reducing the number of checks.
var float LastFindStartTime;
var Controller LastFindStartPlayer;


static function UTPlusHitSounds FindFor(LevelInfo Level)
{
	local GameRules GR;

	if (Level.Game != None) {
		for (GR = Level.Game.GameRulesModifiers; GR != None; GR = GR.NextGameRules) {
			if (UTPlusHitSounds(GR) != None)
				return UTPlusHitSounds(GR);
		}
	}
	return None;
}


function PostBeginPlay()
{
	local array<name> NodeEvents;
	local DestroyableObjective O;
	local UTPlusEventForwarder EF;
	local int i;

	bAllowVariableHitSounds = class'MutUTPlusHitSounds'.default.bAllowVariableHitSounds;
	bLineOfSightHitSounds   = class'MutUTPlusHitSounds'.default.bLineOfSightHitSounds;
	bObjectiveHitSounds     = class'MutUTPlusHitSounds'.default.bObjectiveHitSounds;

	Level.Game.AddGameModifier(Self);
	AddtoPackageMap(string(Class.Outer));

	if (bObjectiveHitSounds) {
		// sweet little hack
		foreach AllActors(class'DestroyableObjective', O) {
			if (O.TakeDamageEvent == '')
				O.TakeDamageEvent = 'UTPlusObjectiveTakeDamage';
			O.DamageEventThreshold = Max(O.DamageEventThreshold, 1);

			for (i = 0; i < NodeEvents.Length; ++i) {
				if (NodeEvents[i] == O.TakeDamageEvent)
					break;
			}
			if (i == NodeEvents.Length) {
				NodeEvents[i] = O.TakeDamageEvent;
				EF = Spawn(class'UTPlusEventForwarder',, O.TakeDamageEvent);
				EF.OnTrigger = CalcObjectiveDamage;
			}
		}
	}
}


/**
Ensure the player has a hit sound replicator.
*/
/*
function NavigationPoint FindPlayerStart(Controller Player, optional byte InTeam, optional string IncomingName)
{
	if (Player != None && Player.PlayerReplicationInfo != None && (LastFindStartTime != Level.TimeSeconds || LastFindStartPlayer != Player)) {
		LastFindStartTime = Level.TimeSeconds;
		LastFindStartPlayer = Player;
		class'UTPlusHitSoundTag'.static.SpawnFor(Player.PlayerReplicationInfo);
	}
	return Super.FindPlayerStart(Player, InTeam, IncomingName);
}
*/


/**
Check for HitSound damage and add momentum to miniguns and linkguns.
*/
function int NetDamage(int OriginalDamage, int Damage, Pawn Injured, Pawn InstigatedBy, vector HitLocation, out vector Momentum, class<DamageType> DamageType)
{
	local Controller InstigatorController;
	local byte InjuredTeam;

	Damage = Super.NetDamage(OriginalDamage, Damage, Injured, InstigatedBy, HitLocation, Momentum, DamageType);

	if (InstigatedBy != None && Injured != None && InstigatedBy != Injured && InstigatedBy.Health > 0) {
		InstigatorController = InstigatedBy.Controller;
		if (InstigatorController == None && DamageType != None && DamageType.default.bDelayedDamage) {
			InstigatorController = Injured.DelayedDamageInstigatorController;
		}
		if (InstigatorController != None) {
			if (Injured.Controller != None)
				InjuredTeam = Injured.Controller.GetTeamNum();
			else if (Vehicle(Injured) != None)
				InjuredTeam = Vehicle(Injured).Team;
			else
				InjuredTeam = 255;
			if (Level.Game.IsOnTeam(InstigatorController, InjuredTeam)) {
				// original damage for friendly-fire
				CalcHitSoundsFor(InstigatorController, OriginalDamage, Injured);
			}
			else {
				// actual damage in all other cases
				CalcHitSoundsFor(InstigatorController, Damage, Injured);
			}
		}
	}
	return Damage;
}

/**
Plays a hit sound on the player.
*/
function CalcHitSoundsFor(Controller Player, int Damage, Pawn Victim)
{
	local UTPlusHitSoundTag PlayerTag;

	if (Player == None || Player.PlayerReplicationInfo == None || Damage < 0 || Victim == None || Victim.Health <= 0 || bLineOfSightHitSounds && !Player.LineOfSightTo(Victim)) {
		// ignore this hit
		return;
	}

	PlayerTag = class'UTPlusHitSoundTag'.static.SpawnFor(Player.PlayerReplicationInfo);
	if (PlayerTag != None)
		PlayerTag.AddDamage(Damage, Victim);

	if (TimerRate == 0)
		SetTimer(0.05, false);
}


function CalcObjectiveDamage(Actor Damaged, Pawn Attacker)
{
	local DestroyableObjective Objective;
	local UTPlusHitSoundTag PlayerTag;

	Objective = DestroyableObjective(Damaged);
	if (Attacker != None && Attacker.PlayerReplicationInfo != None)
		PlayerTag = class'UTPlusHitSoundTag'.static.SpawnFor(Attacker.PlayerReplicationInfo);
	if (Objective == None || Objective.AccumulatedDamage <= 0 || PlayerTag == None)
		return;
	PlayerTag.AddObjectiveDamage(Objective);

	if (TimerRate == 0)
		SetTimer(0.05, false);
}


event Timer()
{
	local UTPlusHitSoundTag PlayerTag;

	for (PlayerTag = firstTagHitSound; PlayerTag != None; PlayerTag = PlayerTag.nextTag) {
		PlayerTag.DispatchHitSound(bAllowVariableHitSounds);
	}
}


//=============================================================================
// Default values
//=============================================================================

defaultproperties
{
	bAllowVariableHitSounds = True
	bLineOfSightHitSounds   = True
	bObjectiveHitSounds     = True
}


Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: So 2.12.2012 17:24:46.000 - Creation time: Sa 23.8.2014 09:19:04.576 - Created with UnCodeX