ScaredyCat trait for civilians.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
@@ -326,6 +326,7 @@
|
||||
<Compile Include="Widgets\GameInitInfoWidget.cs" />
|
||||
<Compile Include="Widgets\Delegates\GameInitDelegate.cs" />
|
||||
<Compile Include="AttackWander.cs" />
|
||||
<Compile Include="ScaredyCat.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage, INotifyIdle
|
||||
{
|
||||
public bool Panicked = false;
|
||||
public enum AnimationState
|
||||
{
|
||||
Idle,
|
||||
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
|
||||
// If path is blocked, we can have !isMoving and !idle
|
||||
// Need to handle this case specially
|
||||
if (!mobile.IsMoving && State == AnimationState.Moving)
|
||||
@@ -64,7 +65,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
else if (State != AnimationState.Moving && mobile.IsMoving)
|
||||
{
|
||||
State = AnimationState.Moving;
|
||||
anim.PlayRepeating("run");
|
||||
anim.PlayRepeating(Panicked ? "panic-run" : "run");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
51
OpenRA.Mods.RA/ScaredyCat.cs
Normal file
51
OpenRA.Mods.RA/ScaredyCat.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#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
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using System.Drawing;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ScaredyCatInfo : ITraitInfo
|
||||
{
|
||||
public readonly int MoveRadius = 2;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ScaredyCat(init.self, this); }
|
||||
}
|
||||
|
||||
class ScaredyCat : INotifyIdle, INotifyDamage
|
||||
{
|
||||
readonly ScaredyCatInfo Info;
|
||||
bool Panicked = false;
|
||||
public ScaredyCat(Actor self, ScaredyCatInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public void TickIdle(Actor self)
|
||||
{
|
||||
if (!Panicked)
|
||||
return;
|
||||
var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location;
|
||||
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (Panicked)
|
||||
return;
|
||||
Panicked = true;
|
||||
self.Trait<RenderInfantry>().Panicked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user