From 0d62318688c37c16834951f7de934af872fb304f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 26 Oct 2009 21:52:13 +1300 Subject: [PATCH] most of the support for boats --- OpenRa.Game/Game.cs | 7 ++++--- OpenRa.Game/GameRules/UnitInfo.cs | 5 +++-- OpenRa.Game/Graphics/Animation.cs | 16 ++++++++-------- OpenRa.Game/Traits/Mobile.cs | 5 ++--- OpenRa.Game/Traits/RenderUnit.cs | 4 +++- sequences.xml | 5 +++++ units.ini | 28 ++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index d1f3be011b..f82b46508a 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -188,9 +188,11 @@ namespace OpenRa.Game new VoicePool("await1", "ready", "report1", "yessir1")); 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()) producer.traits.Get().EjectUnit(); } diff --git a/OpenRa.Game/GameRules/UnitInfo.cs b/OpenRa.Game/GameRules/UnitInfo.cs index 31727d5d1a..03eb6eae51 100755 --- a/OpenRa.Game/GameRules/UnitInfo.cs +++ b/OpenRa.Game/GameRules/UnitInfo.cs @@ -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) { } } diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index 00fa963dc2..e29362129f 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -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(); } diff --git a/OpenRa.Game/Traits/Mobile.cs b/OpenRa.Game/Traits/Mobile.cs index 3d614711fd..3083c0a7f8 100644 --- a/OpenRa.Game/Traits/Mobile.cs +++ b/OpenRa.Game/Traits/Mobile.cs @@ -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 == null) return UnitMovementType.Foot; + if (vi.WaterBound) return UnitMovementType.Float; return vi.Tracked ? UnitMovementType.Track : UnitMovementType.Wheel; } diff --git a/OpenRa.Game/Traits/RenderUnit.cs b/OpenRa.Game/Traits/RenderUnit.cs index bb1e6f349d..43f3430aae 100644 --- a/OpenRa.Game/Traits/RenderUnit.cs +++ b/OpenRa.Game/Traits/RenderUnit.cs @@ -12,7 +12,9 @@ namespace OpenRa.Game.Traits public RenderUnit(Actor self) : base(self) { - anim.PlayFetchIndex("idle", () => self.traits.Get().facing / 8); + anim.PlayFetchIndex("idle", + () => self.traits.Get().facing + / (256/anim.CurrentSequence.Length)); } protected static Pair Centered(Sprite s, float2 location) diff --git a/sequences.xml b/sequences.xml index 9596eacae8..5d4adee951 100644 --- a/sequences.xml +++ b/sequences.xml @@ -327,6 +327,11 @@ + + + + + diff --git a/units.ini b/units.ini index e437132e5f..c972e651ad 100755 --- a/units.ini +++ b/units.ini @@ -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