infantry squads; a bit tight at the moment.
This commit is contained in:
@@ -38,7 +38,7 @@ namespace OpenRa.Game.GameRules
|
||||
public readonly string[] Prerequisite = { };
|
||||
public readonly string Primary = null;
|
||||
public readonly string Secondary = null;
|
||||
public readonly int ROT = 0;
|
||||
public readonly int ROT = 255;
|
||||
public readonly int Reload = 0;
|
||||
public readonly bool SelfHealing = false;
|
||||
public readonly bool Sensors = false; // no idea what this does
|
||||
@@ -67,6 +67,7 @@ namespace OpenRa.Game.GameRules
|
||||
public readonly bool FraidyCat = false;
|
||||
public readonly bool Infiltrate = false;
|
||||
public readonly bool IsCanine = false;
|
||||
public readonly int SquadSize = 1;
|
||||
|
||||
public InfantryInfo(string name) : base(name) { }
|
||||
}
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
<Compile Include="Graphics\TreeCache.cs" />
|
||||
<Compile Include="Traits\AttackTurreted.cs" />
|
||||
<Compile Include="Traits\Building.cs" />
|
||||
<Compile Include="Traits\InfantrySquad.cs" />
|
||||
<Compile Include="Traits\McvDeploy.cs" />
|
||||
<Compile Include="Traits\Mobile.cs" />
|
||||
<Compile Include="Traits\RenderBuilding.cs" />
|
||||
|
||||
94
OpenRa.Game/Traits/InfantrySquad.cs
Normal file
94
OpenRa.Game/Traits/InfantrySquad.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Graphics;
|
||||
using IjwFramework.Types;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
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 = (UnitInfo.InfantryInfo)self.unitInfo;
|
||||
for (int i = 0; i < ii.SquadSize; i++)
|
||||
elements.Add(new Soldier(self.unitInfo.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]);
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
||||
{
|
||||
return elements.Select(
|
||||
e => Util.Centered(e.anim.Image, e.location))
|
||||
.OrderBy( a => a.Second.Y ); /* important to y-order elements of a squad! */
|
||||
}
|
||||
}
|
||||
|
||||
class Soldier
|
||||
{
|
||||
public Animation anim;
|
||||
public float2 location;
|
||||
string name;
|
||||
int facing = 128;
|
||||
|
||||
string currentSequence;
|
||||
|
||||
void PlaySequence(string seq, bool isFacing)
|
||||
{
|
||||
if (currentSequence == seq) return;
|
||||
currentSequence = seq;
|
||||
|
||||
if (isFacing)
|
||||
anim.PlayFetchIndex(seq, () => facing / (256 / anim.CurrentSequence.Length));
|
||||
else
|
||||
anim.PlayRepeating(seq);
|
||||
}
|
||||
|
||||
public Soldier(string type, int2 initialLocation)
|
||||
{
|
||||
name = type;
|
||||
anim = new Animation(type);
|
||||
anim.PlayFetchIndex("stand",
|
||||
() => facing / (256 / anim.CurrentSequence.Length) );
|
||||
location = initialLocation;
|
||||
}
|
||||
|
||||
public void Tick( int2 desiredLocation )
|
||||
{
|
||||
anim.Tick();
|
||||
var d = (desiredLocation - location);
|
||||
var speed = ((UnitInfo.InfantryInfo)Rules.UnitInfo[name]).Speed / 2;
|
||||
|
||||
facing = Util.GetFacing(d, facing);
|
||||
|
||||
if (float2.WithinEpsilon(d, float2.Zero, .1f))
|
||||
PlaySequence("stand", true);
|
||||
else
|
||||
PlaySequence("run-" + (facing / 32), false);
|
||||
|
||||
if (d.Length > speed)
|
||||
d = (d.Length / speed) * d;
|
||||
|
||||
location += d;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,15 +17,9 @@ namespace OpenRa.Game.Traits
|
||||
/ (256/anim.CurrentSequence.Length));
|
||||
}
|
||||
|
||||
protected static Pair<Sprite, float2> Centered(Sprite s, float2 location)
|
||||
{
|
||||
var loc = location - 0.5f * s.size;
|
||||
return Pair.New(s, loc.Round());
|
||||
}
|
||||
|
||||
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
|
||||
{
|
||||
yield return Centered( anim.Image, self.CenterLocation );
|
||||
yield return Util.Centered(anim.Image, self.CenterLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
var mobile = self.traits.Get<Mobile>();
|
||||
|
||||
yield return Centered(anim.Image, self.CenterLocation);
|
||||
yield return Centered(turretAnim.Image, self.CenterLocation
|
||||
yield return Util.Centered(anim.Image, self.CenterLocation);
|
||||
yield return Util.Centered(turretAnim.Image, self.CenterLocation
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset, primaryRecoil));
|
||||
if (self.unitInfo.SecondaryOffset != null)
|
||||
yield return Centered(turretAnim.Image, self.CenterLocation
|
||||
yield return Util.Centered(turretAnim.Image, self.CenterLocation
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.SecondaryOffset, secondaryRecoil));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using IjwFramework.Types;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
@@ -88,5 +90,11 @@ namespace OpenRa.Game.Traits
|
||||
return (RotateVectorByFacing(new float2(offset[0], offset[1]), quantizedFacing, .7f) + GetRecoil(self, recoil));
|
||||
}
|
||||
|
||||
public static Pair<Sprite, float2> Centered(Sprite s, float2 location)
|
||||
{
|
||||
var loc = location - 0.5f * s.size;
|
||||
return Pair.New(s, loc.Round());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,14 +372,19 @@ Description=Attack Dog
|
||||
BuiltAt=KENN
|
||||
[E1]
|
||||
Description=Rifle Infantry
|
||||
Traits=InfantrySquad,Mobile
|
||||
SquadSize=3
|
||||
[E2]
|
||||
Description=Grenadier
|
||||
[E3]
|
||||
Description=Rocket Soldier
|
||||
Traits=InfantrySquad,Mobile
|
||||
SquadSize=2
|
||||
[E4]
|
||||
Description=Flamethrower
|
||||
[E6]
|
||||
Description=Engineer
|
||||
Traits=InfantrySquad,Mobile
|
||||
[SPY]
|
||||
Description=Spy
|
||||
[THF]
|
||||
|
||||
Reference in New Issue
Block a user