most of the support for boats

This commit is contained in:
Chris Forbes
2009-10-26 21:52:13 +13:00
parent 384a3ee2e9
commit 0d62318688
7 changed files with 53 additions and 17 deletions

View File

@@ -189,8 +189,10 @@ namespace OpenRa.Game
public static void BuildUnit(Player player, string name)
{
var producerTypes = Rules.UnitInfo[name].BuiltAt;
var producer = world.Actors
.FirstOrDefault(a => a.unitInfo != null && a.unitInfo.Name == "weap" && a.Owner == player);
.FirstOrDefault(a => a.unitInfo != null
&& producerTypes.Contains(a.unitInfo.Name) && a.Owner == player);
if (producer == null)
throw new InvalidOperationException("BuildUnit without suitable production structure!");
@@ -202,7 +204,6 @@ namespace OpenRa.Game
world.AddFrameEndTask(_ => world.Add(unit));
// todo: make the producing building play `build`
if (producer.traits.Contains<RenderWarFactory>())
producer.traits.Get<RenderWarFactory>().EjectUnit();
}

View File

@@ -35,7 +35,7 @@ namespace OpenRa.Game.GameRules
public readonly bool Invisible = false;
public readonly string Owner = "allies,soviet"; // TODO: make this an enum
public readonly int Points = 0;
public readonly string[] Prerequisite = new string[ 0 ];
public readonly string[] Prerequisite = { };
public readonly string Primary = null;
public readonly string Secondary = null;
public readonly int ROT = 0;
@@ -45,6 +45,8 @@ namespace OpenRa.Game.GameRules
public readonly int Sight = 1;
public readonly int Strength = 1;
public readonly int TechLevel = -1;
public readonly bool WaterBound = false;
public readonly string[] BuiltAt = { };
public UnitInfo(string name) { Name = name; }
@@ -89,7 +91,6 @@ namespace OpenRa.Game.GameRules
public readonly bool Repairable = true;
public readonly int Storage = 0;
public readonly bool Unsellable = false;
public readonly bool WaterBound = false;
public BuildingInfo(string name) : base(name) { }
}

View File

@@ -5,7 +5,7 @@ namespace OpenRa.Game.Graphics
class Animation
{
readonly string name;
Sequence currentSequence;
public Sequence CurrentSequence { get; private set; }
int frame = 0;
bool backwards = false;
bool tickAlways;
@@ -21,12 +21,12 @@ namespace OpenRa.Game.Graphics
get
{
return backwards
? currentSequence.GetSprite(currentSequence.End - frame - 1)
: currentSequence.GetSprite(frame);
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1)
: CurrentSequence.GetSprite(frame);
}
}
public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } }
public float2 Center { get { return 0.25f * new float2(CurrentSequence.GetSprite(0).bounds.Size); } }
public void Play( string sequenceName )
{
@@ -47,14 +47,14 @@ namespace OpenRa.Game.Graphics
{
backwards = false;
tickAlways = false;
currentSequence = SequenceProvider.GetSequence( name, sequenceName );
CurrentSequence = SequenceProvider.GetSequence( name, sequenceName );
frame = 0;
tickFunc = () =>
{
++frame;
if( frame >= currentSequence.Length )
if( frame >= CurrentSequence.Length )
{
frame = currentSequence.Length - 1;
frame = CurrentSequence.Length - 1;
tickFunc = () => { };
after();
}
@@ -71,7 +71,7 @@ namespace OpenRa.Game.Graphics
{
backwards = false;
tickAlways = true;
currentSequence = SequenceProvider.GetSequence( name, sequenceName );
CurrentSequence = SequenceProvider.GetSequence( name, sequenceName );
frame = func();
tickFunc = () => frame = func();
}

View File

@@ -70,10 +70,9 @@ namespace OpenRa.Game.Traits
public UnitMovementType GetMovementType()
{
/* todo: boats */
var vi = self.unitInfo as UnitInfo.VehicleInfo;
if (vi == null) return UnitMovementType.Foot;
if (vi.WaterBound) return UnitMovementType.Float;
return vi.Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
}

View File

@@ -12,7 +12,9 @@ namespace OpenRa.Game.Traits
public RenderUnit(Actor self)
: base(self)
{
anim.PlayFetchIndex("idle", () => self.traits.Get<Mobile>().facing / 8);
anim.PlayFetchIndex("idle",
() => self.traits.Get<Mobile>().facing
/ (256/anim.CurrentSequence.Length));
}
protected static Pair<Sprite, float2> Centered(Sprite s, float2 location)

View File

@@ -328,6 +328,11 @@
<sequence name="turret" start="32" length="8"/>
</unit>
<!-- submarine -->
<unit name="ss">
<sequence name="idle" start="0" length="16" />
</unit>
<!-- build clock - hacked in -->
<unit name="clock">
<sequence name="idle" start="0" length="*"/>

View File

@@ -16,42 +16,55 @@ MNLY
[V2RL]
Description=V2 Rocket
Traits=Mobile, RenderUnit
BuiltAt=weap
[1TNK]
Description=Light Tank
Traits=Mobile, Turreted, AttackTurreted, RenderUnitTurreted
BuiltAt=weap
[2TNK]
Description=Medium Tank
Traits=Mobile, Turreted, AttackTurreted, RenderUnitTurreted
BuiltAt=weap
[3TNK]
Description=Heavy Tank
Traits=Mobile, Turreted, AttackTurreted, RenderUnitTurreted
BuiltAt=weap
[4TNK]
Description=Mammoth Tank
Traits=Mobile, Turreted, AttackTurreted, RenderUnitTurreted
BuiltAt=weap
[MRJ]
Description=Radar Jammer
Traits=Mobile, Turreted, RenderUnitTurreted ; temporary. It's not a turret, it's a spinney-thing
BuiltAt=weap
[MGG]
Description=Mobile Gap Generator
Traits=Mobile, Turreted, RenderUnitTurreted ; temporary. It's not a turret, it's a spinney-thing
BuiltAt=weap
[ARTY]
Description=Artillery
Traits=Mobile, RenderUnit
BuiltAt=weap
[HARV]
Description=Ore Truck
Traits=Mobile, RenderUnit
BuiltAt=weap
[MCV]
Description=Mobile Construction Vehicle
Traits=Mobile, McvDeploy, RenderUnit
BuiltAt=weap
[JEEP]
Description=Ranger
Traits=Mobile, Turreted, AttackTurreted, RenderUnitTurreted
BuiltAt=weap
[APC]
Description=Armored Personnel Carrier
Traits=Mobile, RenderUnit
BuiltAt=weap
[MNLY]
Description=Minelayer
Traits=Mobile, RenderUnit
BuiltAt=weap
@@ -66,14 +79,29 @@ PT
[SS]
Description=Submarine
WaterBound=yes
BuiltAt=spen
Traits=Mobile, RenderUnit
[DD]
Description=Destroyer
WaterBound=yes
BuiltAt=syrd
Traits=Mobile, RenderUnit
[CA]
Description=Cruiser
WaterBound=yes
BuiltAt=syrd
Traits=Mobile, RenderUnit
[LST]
Description=Transport
WaterBound=yes
BuiltAt=syrd,spen
Traits=Mobile, RenderUnit
[PT]
Description=Gunboat
WaterBound=yes
BuiltAt=syrd
Traits=Mobile, RenderUnit