infantry that sortof work
This commit is contained in:
@@ -161,7 +161,7 @@
|
||||
<Compile Include="Traits\Building.cs" />
|
||||
<Compile Include="Traits\Harvester.cs" />
|
||||
<Compile Include="Traits\Helicopter.cs" />
|
||||
<Compile Include="Traits\InfantrySquad.cs" />
|
||||
<Compile Include="Traits\RenderInfantry.cs" />
|
||||
<Compile Include="Traits\McvDeploy.cs" />
|
||||
<Compile Include="Traits\Mobile.cs" />
|
||||
<Compile Include="Traits\Production.cs" />
|
||||
|
||||
@@ -27,10 +27,12 @@ namespace OpenRa.Game.Traits.Activities
|
||||
return new Move( Target, Range ) { NextActivity = this };
|
||||
|
||||
var desiredFacing = Util.GetFacing((Target.Location - self.Location).ToFloat2(), 0);
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().FirstOrDefault();
|
||||
var numDirs = (renderUnit != null)
|
||||
? renderUnit.anim.CurrentSequence.Length : 8;
|
||||
|
||||
if (Util.QuantizeFacing(unit.Facing, renderUnit.anim.CurrentSequence.Length)
|
||||
!= Util.QuantizeFacing(desiredFacing, renderUnit.anim.CurrentSequence.Length))
|
||||
if (Util.QuantizeFacing(unit.Facing, numDirs)
|
||||
!= Util.QuantizeFacing(desiredFacing, numDirs))
|
||||
{
|
||||
return new Turn( desiredFacing ) { NextActivity = this };
|
||||
}
|
||||
|
||||
@@ -94,6 +94,9 @@ namespace OpenRa.Game.Traits
|
||||
Game.world.Add(new Bullet(weaponName, self.Owner, self,
|
||||
firePos, target.CenterLocation.ToInt2()));
|
||||
|
||||
foreach (var na in self.traits.WithInterface<INotifyAttack>())
|
||||
na.Attacking(self);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class InfantrySquad : ITick, IRender
|
||||
{
|
||||
readonly List<Soldier> elements = new List<Soldier>();
|
||||
|
||||
readonly int2[][] elementOffsets = new []
|
||||
{
|
||||
new int2[] {},
|
||||
new [] { new int2(0,0) },
|
||||
new [] { new int2(-5,-5), new int2(5,5) },
|
||||
new [] { new int2(-6,5), new int2(0, -5), new int2(6,4) }, /* todo: move squad arrangements ! */
|
||||
};
|
||||
|
||||
public InfantrySquad(Actor self)
|
||||
{
|
||||
var ii = (InfantryInfo)self.Info;
|
||||
for (int i = 0; i < ii.SquadSize; i++)
|
||||
elements.Add(new Soldier(self.Info.Name,
|
||||
self.CenterLocation.ToInt2() + elementOffsets[ii.SquadSize][i]));
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
for (int i = 0; i < elements.Count; i++)
|
||||
elements[i].Tick(
|
||||
self.CenterLocation.ToInt2() + elementOffsets[elements.Count][i], self);
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
||||
{
|
||||
return elements.Select(
|
||||
e => Util.Centered(self, e.anim.Image, e.location))
|
||||
.OrderBy( a => a.b.Y ); /* important to y-order elements of a squad! */
|
||||
}
|
||||
}
|
||||
|
||||
class Soldier
|
||||
{
|
||||
public Animation anim;
|
||||
public float2 location;
|
||||
string name;
|
||||
int facing = 128;
|
||||
float speed;
|
||||
|
||||
string currentSequence;
|
||||
|
||||
void PlaySequence(string seq, bool isFacing)
|
||||
{
|
||||
if (currentSequence == seq) return;
|
||||
|
||||
if (isFacing)
|
||||
anim.PlayFacing(seq, () => facing );
|
||||
else
|
||||
anim.PlayRepeatingPreservingPosition(seq);
|
||||
|
||||
currentSequence = seq;
|
||||
}
|
||||
|
||||
public Soldier(string type, int2 initialLocation)
|
||||
{
|
||||
name = type;
|
||||
anim = new Animation(type);
|
||||
anim.PlayFacing("stand", () => facing);
|
||||
location = initialLocation;
|
||||
speed = ((InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
|
||||
}
|
||||
|
||||
public void Tick( int2 desiredLocation, Actor self )
|
||||
{
|
||||
anim.Tick();
|
||||
var d = (desiredLocation - location);
|
||||
|
||||
facing = /*Util.GetFacing(d, facing); */ self.traits.Get<Unit>().Facing;
|
||||
|
||||
if (float2.WithinEpsilon(d, float2.Zero, .1f))
|
||||
PlaySequence("stand", true);
|
||||
else
|
||||
PlaySequence("run-" + Util.QuantizeFacing(facing, 8), false);
|
||||
|
||||
if (d.Length <= speed)
|
||||
location = desiredLocation;
|
||||
else
|
||||
location += (speed / d.Length) * d;
|
||||
}
|
||||
}
|
||||
}
|
||||
61
OpenRa.Game/Traits/RenderInfantry.cs
Normal file
61
OpenRa.Game/Traits/RenderInfantry.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class RenderInfantry : RenderSimple, INotifyAttack
|
||||
{
|
||||
public RenderInfantry(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
anim.PlayFacing("stand",
|
||||
() => self.traits.Get<Unit>().Facing);
|
||||
}
|
||||
|
||||
bool ChooseMoveAnim(Actor self)
|
||||
{
|
||||
if (!(self.GetCurrentActivity() is Activities.Move))
|
||||
return false;
|
||||
|
||||
var mobile = self.traits.Get<Mobile>();
|
||||
if (float2.WithinEpsilon(self.CenterLocation, Util.CenterOfCell(mobile.toCell), 2)) return false;
|
||||
var dir = Util.QuantizeFacing(self.traits.Get<Unit>().Facing, 8);
|
||||
|
||||
if (anim.CurrentSequence.Name.StartsWith("run-"))
|
||||
anim.ReplaceAnim("run-" + dir);
|
||||
else
|
||||
anim.PlayRepeating("run-" + dir);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool inAttack = false;
|
||||
|
||||
public void Attacking(Actor self)
|
||||
{
|
||||
var dir = Util.QuantizeFacing(self.traits.Get<Unit>().Facing, 8);
|
||||
inAttack = true;
|
||||
anim.PlayThen("shoot-" + dir, () => inAttack = false);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
if (inAttack) return;
|
||||
if (ChooseMoveAnim(self)) return;
|
||||
|
||||
/* todo: idle anims, etc */
|
||||
|
||||
anim.PlayFacing("stand",
|
||||
() => self.traits.Get<Unit>().Facing);
|
||||
}
|
||||
|
||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
||||
{
|
||||
yield return Util.Centered(self, anim.Image, self.CenterLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,5 @@ namespace OpenRa.Game.Traits
|
||||
}
|
||||
interface IProducer { bool Produce( Actor self, UnitInfo producee ); }
|
||||
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }
|
||||
interface INotifyAttack { void Attacking(Actor self); }
|
||||
}
|
||||
|
||||
@@ -105,8 +105,9 @@ namespace OpenRa.Game.Traits
|
||||
if( unit == null ) return int2.Zero; /* things that don't have a rotating base don't need the turrets repositioned */
|
||||
|
||||
var ru = self.traits.WithInterface<RenderUnit>().FirstOrDefault();
|
||||
var numDirs = (ru != null) ? ru.anim.CurrentSequence.Length : 8;
|
||||
var bodyFacing = unit.Facing;
|
||||
var quantizedFacing = QuantizeFacing(bodyFacing, ru.anim.CurrentSequence.Length) * (256 / ru.anim.CurrentSequence.Length);
|
||||
var quantizedFacing = QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs);
|
||||
|
||||
return (RotateVectorByFacing(new float2(offset[0], offset[1]), quantizedFacing, .7f) + GetRecoil(self, recoil))
|
||||
+ new float2(offset.ElementAtOrDefault(2), offset.ElementAtOrDefault(3));
|
||||
|
||||
@@ -407,6 +407,14 @@
|
||||
<sequence name="run-5" start="46" length="6" />
|
||||
<sequence name="run-6" start="52" length="6" />
|
||||
<sequence name="run-7" start="58" length="6" />
|
||||
<sequence name="shoot-0" start="64" length="8" />
|
||||
<sequence name="shoot-1" start="72" length="8" />
|
||||
<sequence name="shoot-2" start="80" length="8" />
|
||||
<sequence name="shoot-3" start="88" length="8" />
|
||||
<sequence name="shoot-4" start="96" length="8" />
|
||||
<sequence name="shoot-5" start="104" length="8" />
|
||||
<sequence name="shoot-6" start="112" length="8" />
|
||||
<sequence name="shoot-7" start="120" length="8" />
|
||||
</unit>
|
||||
<unit name="e6">
|
||||
<sequence name="stand" start="0" length="8" />
|
||||
|
||||
@@ -463,13 +463,13 @@ BuiltAt=KENN
|
||||
Voice=DogVoice
|
||||
[E1]
|
||||
Description=Rifle Infantry
|
||||
Traits=Unit, Mobile, InfantrySquad
|
||||
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
||||
SquadSize=3
|
||||
[E2]
|
||||
Description=Grenadier
|
||||
[E3]
|
||||
Description=Rocket Soldier
|
||||
Traits=Unit, Mobile, InfantrySquad
|
||||
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
||||
SquadSize=2
|
||||
[E4]
|
||||
Description=Flamethrower
|
||||
|
||||
Reference in New Issue
Block a user