Start unbreaking ScaredyCat

This commit is contained in:
Scott_NZ
2013-01-01 15:30:56 +13:00
parent 3b9fac9c84
commit 11c45e4388
4 changed files with 64 additions and 21 deletions

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Render
protected override string NormalizeInfantrySequence(Actor self, string baseSequence) 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)) if (anim.HasSequence(prefix + baseSequence))
return prefix + baseSequence; return prefix + baseSequence;
@@ -40,15 +40,15 @@ namespace OpenRA.Mods.RA.Render
protected override bool AllowIdleAnimation(Actor self) protected override bool AllowIdleAnimation(Actor self)
{ {
return base.AllowIdleAnimation(self) && !sc.Panicked; return base.AllowIdleAnimation(self) && !sc.Panicking;
} }
public override void Tick (Actor self) public override void Tick (Actor self)
{ {
if (wasPanic != sc.Panicked) if (wasPanic != sc.Panicking)
dirty = true; dirty = true;
wasPanic = sc.Panicked; wasPanic = sc.Panicking;
base.Tick(self); base.Tick(self);
} }
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -15,26 +15,66 @@ namespace OpenRA.Mods.RA
{ {
class ScaredyCatInfo : ITraitInfo 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); } 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; 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) 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<Mobile>().Nudge(self, self, true);
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
} }
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;
}
} }
} }

View File

@@ -8,50 +8,50 @@ C2:
C3: C3:
Inherits: ^CivInfantry Inherits: ^CivInfantry
RenderInfantry: RenderInfantryPanic:
Image: C1 Image: C1
C4: C4:
Inherits: ^CivInfantry Inherits: ^CivInfantry
Selectable: Selectable:
Voice: CivilianFemaleVoice Voice: CivilianFemaleVoice
RenderInfantry: RenderInfantryPanic:
Image: C2 Image: C2
C5: C5:
Inherits: ^CivInfantry Inherits: ^CivInfantry
RenderInfantry: RenderInfantryPanic:
Image: C1 Image: C1
C6: C6:
Inherits: ^CivInfantry Inherits: ^CivInfantry
Selectable: Selectable:
Voice: CivilianFemaleVoice Voice: CivilianFemaleVoice
RenderInfantry: RenderInfantryPanic:
Image: C2 Image: C2
C7: C7:
Inherits: ^CivInfantry Inherits: ^CivInfantry
RenderInfantry: RenderInfantryPanic:
Image: C1 Image: C1
C8: C8:
Inherits: ^CivInfantry Inherits: ^CivInfantry
Selectable: Selectable:
Voice: CivilianFemaleVoice Voice: CivilianFemaleVoice
RenderInfantry: RenderInfantryPanic:
Image: C2 Image: C2
C9: C9:
Inherits: ^CivInfantry Inherits: ^CivInfantry
RenderInfantry: RenderInfantryPanic:
Image: C1 Image: C1
C10: C10:
Inherits: ^CivInfantry Inherits: ^CivInfantry
Selectable: Selectable:
Voice: CivilianFemaleVoice Voice: CivilianFemaleVoice
RenderInfantry: RenderInfantryPanic:
Image: C2 Image: C2
FCOM: FCOM:

View File

@@ -286,6 +286,9 @@
PrimaryWeapon: Pistol PrimaryWeapon: Pistol
ProximityCaptor: ProximityCaptor:
Types:CivilianInfantry Types:CivilianInfantry
-RenderInfantry:
RenderInfantryPanic:
ScaredyCat:
^CivBuilding: ^CivBuilding:
Inherits: ^TechBuilding Inherits: ^TechBuilding