diff --git a/OpenRa.Game/Effects/TeslaZap.cs b/OpenRa.Game/Effects/TeslaZap.cs new file mode 100755 index 0000000000..a8f57a488b --- /dev/null +++ b/OpenRa.Game/Effects/TeslaZap.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.Graphics; + +namespace OpenRa.Game.Effects +{ + class TeslaZap : IEffect + { + readonly int2 from, to; + readonly Sequence tesla; + int timeUntilRemove = 2; // # of frames + + public TeslaZap( int2 from, int2 to ) + { + this.from = from; + this.to = to; + this.tesla = SequenceProvider.GetSequence( "litning", "bright" ); + } + + public void Tick() + { + if( timeUntilRemove <= 0 ) + Game.world.AddFrameEndTask( w => w.Remove( this ) ); + --timeUntilRemove; + } + + public IEnumerable> Render() + { + if( from.X < to.X ) + return Foo( from, to, tesla ); + else if( from.X > to.X || from.Y > to.Y ) + return Foo( to, from, tesla ); + else + return Foo( from, to, tesla ); + } + + static IEnumerable> Foo( int2 from, int2 to, Sequence tesla ) + { + int2 d = to - from; + if( d.X < 8 ) + { + var prev = new int2( 0, 0 ); + var y = d.Y; + while( y >= prev.Y + 8 ) + { + yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 8 ) ), 0 ); + prev.Y += 8; + } + } + else + { + var prev = new int2( 0, 0 ); + for( int i = 1 ; i < d.X ; i += 8 ) + { + var y = i * d.Y / d.X; + if( y <= prev.Y - 8 ) + { + yield return Tuple.New( tesla.GetSprite( 3 ), (float2)( from + prev - new int2( 8, 16 ) ), 0 ); + prev.Y -= 8; + while( y <= prev.Y - 8 ) + { + yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 16 ) ), 0 ); + prev.Y -= 8; + } + } + else if( y >= prev.Y + 8 ) + { + yield return Tuple.New( tesla.GetSprite( 0 ), (float2)( from + prev - new int2( 8, 8 ) ), 0 ); + prev.Y += 8; + while( y >= prev.Y + 8 ) + { + yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 8 ) ), 0 ); + prev.Y -= 8; + } + } + else + yield return Tuple.New( tesla.GetSprite( 1 ), (float2)( from + prev - new int2( 8, 8 ) ), 0 ); + + prev.X += 8; + } + } + } + } +} diff --git a/OpenRa.Game/GameRules/WeaponInfo.cs b/OpenRa.Game/GameRules/WeaponInfo.cs index 66938c5490..b33479095b 100755 --- a/OpenRa.Game/GameRules/WeaponInfo.cs +++ b/OpenRa.Game/GameRules/WeaponInfo.cs @@ -16,5 +16,7 @@ namespace OpenRa.Game.GameRules public readonly bool Supress = false; public readonly bool TurboBoost = false; public readonly string Warhead = null; + + public readonly bool RenderAsTesla = false; } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index c15f4223cd..2d1dc29d4e 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -81,6 +81,7 @@ + diff --git a/OpenRa.Game/Traits/AttackBase.cs b/OpenRa.Game/Traits/AttackBase.cs index e9ff75aa51..30c36908a1 100644 --- a/OpenRa.Game/Traits/AttackBase.cs +++ b/OpenRa.Game/Traits/AttackBase.cs @@ -108,7 +108,10 @@ namespace OpenRa.Game.Traits var thisTarget = target; ScheduleDelayedAction(self.Info.FireDelay, () => { - if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0) + if( weapon.RenderAsTesla ) + Game.world.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) ); + + if( Rules.ProjectileInfo[ weapon.Projectile ].ROT != 0 ) Game.world.Add(new Missile(weaponName, self.Owner, self, firePos, thisTarget)); else diff --git a/aftermathUnits.ini b/aftermathUnits.ini index 9eeb2ff4b1..9ec343a9e6 100755 --- a/aftermathUnits.ini +++ b/aftermathUnits.ini @@ -10,7 +10,7 @@ Description=Stealth Tank Traits=Unit, Mobile, RenderUnit [TTNK] Description=Tesla Tank -Traits=Unit, Mobile, RenderUnitSpinner +Traits=Unit, Mobile, AttackBase, RenderUnitSpinner [CTNK] Description=Chrono Tank Traits=Unit, Mobile, RenderUnit @@ -32,7 +32,7 @@ MSUB Description=Missile Submarine WaterBound=yes BuiltAt=spen -Traits=Mobile, RenderUnit +Traits=Unit, Mobile, RenderUnit @@ -44,12 +44,12 @@ MECH [SHOK] Description=Tesla Trooper -Traits=InfantrySquad,Mobile +Traits=Unit, Mobile, AttackBase, RenderInfantry SquadSize=1 [MECH] Description=Mechanic -Traits=InfantrySquad,Mobile +Traits=Unit, Mobile, AttackBase, RenderInfantry SquadSize=1 @@ -62,8 +62,10 @@ TTankZap GoodWrench [PortaTesla] +RenderAsTesla=true [TTankZap] +RenderAsTesla=true [GoodWrench] diff --git a/sequences-aftermath.xml b/sequences-aftermath.xml index 3ac918ed03..82f89ed97b 100644 --- a/sequences-aftermath.xml +++ b/sequences-aftermath.xml @@ -17,4 +17,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sequences.xml b/sequences.xml index efb5502637..4d366ebe4f 100644 --- a/sequences.xml +++ b/sequences.xml @@ -675,4 +675,8 @@ + + + + \ No newline at end of file diff --git a/units.ini b/units.ini index eb68530946..75ce224f38 100755 --- a/units.ini +++ b/units.ini @@ -200,7 +200,7 @@ Footprint=x SelectionPriority=3 [TSLA] Description=Tesla Coil -Traits=Building, RenderBuilding +Traits=Building, Turreted, RenderBuilding, AttackTurreted, AutoTarget Dimensions=1,2 Footprint=_ x SelectionPriority=3 @@ -542,6 +542,8 @@ DogJaw Heal SCUD +[TeslaZap] +RenderAsTesla=true @@ -649,4 +651,4 @@ Move=girlokay [EinsteinVoice] Select=einah1,einok1,einyes1 -Move=einah1,einok1,einyes1 \ No newline at end of file +Move=einah1,einok1,einyes1