Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Commit

Permalink
Rewrote awareness.
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Dinklage <pdinklag@googlemail.com>
  • Loading branch information
pdinklag committed Feb 18, 2013
1 parent 5e1c2b7 commit 09e2288
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 207 deletions.
94 changes: 59 additions & 35 deletions Classes/Ability_Awareness.uc
@@ -1,10 +1,10 @@
class Ability_Awareness extends RPGAbility;

//client
var AwarenessInteraction Interaction;
//Client
var Interaction_Awareness Interaction;
var array<Pawn> Enemies;

replication
{
replication {
reliable if(Role == ROLE_Authority)
ClientCreateInteraction;
}
Expand All @@ -13,44 +13,68 @@ simulated function ClientCreateInteraction()
{
local PlayerController PC;

if(Interaction == None)
{
PC = Level.GetLocalPlayerController();
if(PC == None)
return;

Interaction = AwarenessInteraction(
PC.Player.InteractionMaster.AddInteraction(
class'MutTitanRPG'.default.PackageName $ ".AwarenessInteraction", PC.Player));
}

if(Interaction != None)
Interaction.AbilityLevel = AbilityLevel;
if(Level.NetMode != NM_DedicatedServer) {
if(Interaction == None) {
PC = Level.GetLocalPlayerController();
if(PC == None) {
return;
}

Interaction = Interaction_Awareness(
PC.Player.InteractionMaster.AddInteraction(
class'MutTitanRPG'.default.PackageName $ ".Interaction_Awareness", PC.Player));

Interaction.Ability = Self;

SetTimer(1.0, true);
}
}
}

simulated event Destroyed()
{
if(Interaction != None)
Interaction.Remove();

Interaction = None;
Super.Destroyed();
simulated function Timer() {
local PlayerController PC;
local Pawn P;

if(Interaction != None) {
Enemies.Length = 0;

PC = Level.GetLocalPlayerController();
if(PC != None && PC.Pawn != None && PC.Pawn.Health > 0) {
foreach DynamicActors(class'Pawn', P) {
if(P.GetTeamNum() != 255 && P.GetTeamNum() == PC.GetTeamNum()) {
continue;
}

if(P.DrivenVehicle != None) {
continue;
}

if(P.IsA('Vehicle') && ((!Vehicle(P).bDriving && !Vehicle(P).bAutoTurret) || Vehicle(P).GetVehicleBase() != None)) {
continue;
}

if(Interaction.GlobalInteraction != None && Interaction.GlobalInteraction.IsFriendlyPawn(P)) {
continue;
}

Enemies[Enemies.Length] = P;
}
}
}
}

function ModifyPawn(Pawn Other)
{
Super.ModifyPawn(Other);

if(Role == ROLE_Authority)
ClientCreateInteraction();
function ModifyPawn(Pawn Other) {
Super.ModifyPawn(Other);

if(Role == ROLE_Authority)
ClientCreateInteraction();
}

defaultproperties
{
defaultproperties {
AbilityName="Awareness"
Description="Informs you of your enemies' health with a display over their heads."
LevelDescription(0)="At level 1 you get a colored indicator (green, yellow, or red)."
LevelDescription(1)="At level 2 you get a colored health bar and a shield bar."
Description="Informs you of your enemies' health and shield."
LevelDescription(0)="At level 1, a health bar will be displayed above the heads of enemies."
LevelDescription(1)="At level 2, an additional shield bar will be displayed above the heads of enemies."
StartingCost=20
CostAddPerLevel=5
MaxLevel=2
Expand Down
46 changes: 0 additions & 46 deletions Classes/AwarenessEnemyList.uc

This file was deleted.

116 changes: 0 additions & 116 deletions Classes/AwarenessInteraction.uc

This file was deleted.

95 changes: 95 additions & 0 deletions Classes/Interaction_Awareness.uc
@@ -0,0 +1,95 @@
class Interaction_Awareness extends RPGBaseInteraction;

var Interaction_Global GlobalInteraction;
var Ability_Awareness Ability;

event Initialized() {
local int i;

Super.Initialized();

for(i = 0; i < ViewportOwner.LocalInteractions.Length; i++) {
if(ViewportOwner.LocalInteractions[i].IsA('Interaction_Global')) {
GlobalInteraction = Interaction_Global(ViewportOwner.LocalInteractions[i]);
break;
}
}
}

function PostRender(Canvas C) {
local int i;
local float FarAwayInv, Dist, ScaledDist, Height, Pct;
local vector ScreenPos;
local Pawn P;
local Color BarColor;

if(Ability == None || Ability.AbilityLevel <= 0) {
return;
}

if(ViewportOwner.Actor.Pawn == None || ViewportOwner.Actor.Pawn.Health <= 0) {
return;
}

FarAwayInv = 1.0f / TeamBeaconMaxDist;

for(i = 0; i < Ability.Enemies.Length; i++) {
P = Ability.Enemies[i];
if(IsPawnVisible(C, P, ScreenPos, Dist)) {
ScaledDist = TeamBeaconMaxDist * FClamp(0.04f * P.CollisionRadius, 1.0f, 2.0f);

if(Dist < 0.0f || Dist > 3.0f * ScaledDist) {
continue;
}

//Draw height
Height = P.CollisionHeight * FClamp(0.85f + Dist * 0.85f * FarAwayInv, 1.1f, 1.75f);

//Offset
ScreenPos = C.WorldToScreen(P.Location + Height * vect(0, 0, 0.75));

//Bar height
Height = SmallFontHeight * FClamp(1 - Dist / (TeamBeaconMaxDist / 2), 0.5, 1);

if(P.IsA('Vehicle')) {
Height *= 1.75;
}

BarColor.A = 255;

if(Ability.AbilityLevel >= 2 && P.IsA('xPawn') && P.ShieldStrength > 0) {
//Shield bar
ScreenPos.Y -= Height + 2;
Pct = P.ShieldStrength / xPawn(P).ShieldStrengthMax;

BarColor.R = 255;
BarColor.G = 240;
BarColor.B = 0;

DrawBar(C, ScreenPos.X, ScreenPos.Y, BarColor, Pct, 5 * Height, Height, true);
}

//Health bar
if(P.Health > 0) {
ScreenPos.Y -= Height + 2;
Pct = float(P.Health) / P.HealthMax;

if(Pct > 0.5) {
BarColor.R = byte(255.0 * FClamp(1.0 - (P.HealthMax - (P.HealthMax - P.Health) * 2) / P.HealthMax, 0, 1));
BarColor.G = 255;
BarColor.B = 0;
} else {
BarColor.R = 255;
BarColor.G = byte(255.0 * FClamp(2.0 * P.Health / P.HealthMax, 0, 1));
BarColor.B = 0;
}

DrawBar(C, ScreenPos.X, ScreenPos.Y, BarColor, Pct, 5 * Height, Height, true);
}
}
}
}

defaultproperties {
bVisible = true;
}

0 comments on commit 09e2288

Please sign in to comment.