From 11c45e43884f57de6daa2a38543eb7670a0c99e4 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Tue, 1 Jan 2013 15:30:56 +1300 Subject: [PATCH] Start unbreaking ScaredyCat --- OpenRA.Mods.RA/Render/RenderInfantryPanic.cs | 8 +-- OpenRA.Mods.RA/ScaredyCat.cs | 58 +++++++++++++++++--- mods/ra/rules/civilian.yaml | 16 +++--- mods/ra/rules/defaults.yaml | 3 + 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs b/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs index 4316606702..63322618db 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantryPanic.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render protected override string NormalizeInfantrySequence(Actor self, string baseSequence) { - var prefix = sc != null && sc.Panicked ? "panic-" : ""; + var prefix = sc != null && sc.Panicking ? "panic-" : ""; if (anim.HasSequence(prefix + baseSequence)) return prefix + baseSequence; @@ -40,15 +40,15 @@ namespace OpenRA.Mods.RA.Render protected override bool AllowIdleAnimation(Actor self) { - return base.AllowIdleAnimation(self) && !sc.Panicked; + return base.AllowIdleAnimation(self) && !sc.Panicking; } public override void Tick (Actor self) { - if (wasPanic != sc.Panicked) + if (wasPanic != sc.Panicking) dirty = true; - wasPanic = sc.Panicked; + wasPanic = sc.Panicking; base.Tick(self); } } diff --git a/OpenRA.Mods.RA/ScaredyCat.cs b/OpenRA.Mods.RA/ScaredyCat.cs index 0d1421997d..086e8effb2 100644 --- a/OpenRA.Mods.RA/ScaredyCat.cs +++ b/OpenRA.Mods.RA/ScaredyCat.cs @@ -1,4 +1,4 @@ -#region Copyright & License Information +#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * This file is part of OpenRA, which is free software. It is made @@ -15,26 +15,66 @@ namespace OpenRA.Mods.RA { class ScaredyCatInfo : ITraitInfo { - public readonly int MoveRadius = 2; + public readonly int PanicLength = 25 * 10; + public readonly decimal PanicSpeedModifier = 2; + public readonly int AttackPanicChance = 20; public object Create(ActorInitializer init) { return new ScaredyCat(init.self, this); } } - class ScaredyCat : INotifyIdle, INotifyDamage + class ScaredyCat : ITick, INotifyIdle, INotifyDamage, INotifyAttack, ISpeedModifier { readonly ScaredyCatInfo Info; - public bool Panicked = false; + readonly Actor Self; - public ScaredyCat(Actor self, ScaredyCatInfo info) { Info = info; } + public int PanicStartedTick; + public bool Panicking { get { return PanicStartedTick > 0; } } + + public ScaredyCat(Actor self, ScaredyCatInfo info) + { + Self = self; + Info = info; + } + + public void Panic() + { + if (!Panicking) + Self.CancelActivity(); + PanicStartedTick = Self.World.FrameNumber; + } + + public void Tick(Actor self) + { + if (!Panicking) return; + + if (self.World.FrameNumber >= PanicStartedTick + Info.PanicLength) + { + self.CancelActivity(); + PanicStartedTick = 0; + } + } public void TickIdle(Actor self) { - if (!Panicked) return; + if (!Panicking) return; - var target = ( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius ).ToPVecInt().ToCVec() + self.Location; - self.Trait().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target }); + self.Trait().Nudge(self, self, true); } - public void Damaged(Actor self, AttackInfo e) { Panicked = true; } + public void Damaged(Actor self, AttackInfo e) + { + Panic(); + } + + public void Attacking(Actor self, Target target) + { + if (self.World.SharedRandom.Next(100 / Info.AttackPanicChance) == 0) + Panic(); + } + + public decimal GetSpeedModifier() + { + return Panicking ? Info.PanicSpeedModifier : 1; + } } } diff --git a/mods/ra/rules/civilian.yaml b/mods/ra/rules/civilian.yaml index 09a3c2b38b..4fa2b20146 100644 --- a/mods/ra/rules/civilian.yaml +++ b/mods/ra/rules/civilian.yaml @@ -8,50 +8,50 @@ C2: C3: Inherits: ^CivInfantry - RenderInfantry: + RenderInfantryPanic: Image: C1 C4: Inherits: ^CivInfantry Selectable: Voice: CivilianFemaleVoice - RenderInfantry: + RenderInfantryPanic: Image: C2 C5: Inherits: ^CivInfantry - RenderInfantry: + RenderInfantryPanic: Image: C1 C6: Inherits: ^CivInfantry Selectable: Voice: CivilianFemaleVoice - RenderInfantry: + RenderInfantryPanic: Image: C2 C7: Inherits: ^CivInfantry - RenderInfantry: + RenderInfantryPanic: Image: C1 C8: Inherits: ^CivInfantry Selectable: Voice: CivilianFemaleVoice - RenderInfantry: + RenderInfantryPanic: Image: C2 C9: Inherits: ^CivInfantry - RenderInfantry: + RenderInfantryPanic: Image: C1 C10: Inherits: ^CivInfantry Selectable: Voice: CivilianFemaleVoice - RenderInfantry: + RenderInfantryPanic: Image: C2 FCOM: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index e4ab34216d..443484f2ad 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -286,6 +286,9 @@ PrimaryWeapon: Pistol ProximityCaptor: Types:CivilianInfantry + -RenderInfantry: + RenderInfantryPanic: + ScaredyCat: ^CivBuilding: Inherits: ^TechBuilding