diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs index 912b5907ed..300d718a96 100755 --- a/OpenRA.Game/Network/Order.cs +++ b/OpenRA.Game/Network/Order.cs @@ -58,6 +58,10 @@ namespace OpenRA this.ExtraLocation = extraLocation; } + // For scripting special powers + public Order() + : this(null, null, null, int2.Zero, null, false, int2.Zero) { } + public Order(string orderString, Actor subject, bool queued) : this(orderString, subject, null, int2.Zero, null, queued, int2.Zero) { } diff --git a/OpenRA.Mods.RA/DefaultShellmapScript.cs b/OpenRA.Mods.RA/DefaultShellmapScript.cs index 66da752be2..8cf11f22d4 100755 --- a/OpenRA.Mods.RA/DefaultShellmapScript.cs +++ b/OpenRA.Mods.RA/DefaultShellmapScript.cs @@ -54,11 +54,11 @@ namespace OpenRA.Mods.RA if (ticks == 100) - Actors["mslo1"].Trait().Activate(Actors["mslo1"], new Order(null,null,false) { TargetLocation = new int2(98, 52) }); + Actors["mslo1"].Trait().Activate(Actors["mslo1"], new Order(){ TargetLocation = new int2(98, 52) }); if (ticks == 140) - Actors["mslo2"].Trait().Activate(Actors["mslo2"], new Order(null,null,false) { TargetLocation = new int2(95, 54) }); + Actors["mslo2"].Trait().Activate(Actors["mslo2"], new Order(){ TargetLocation = new int2(95, 54) }); if (ticks == 180) - Actors["mslo3"].Trait().Activate(Actors["mslo3"], new Order(null,null,false) { TargetLocation = new int2(95, 49) }); + Actors["mslo3"].Trait().Activate(Actors["mslo3"], new Order(){ TargetLocation = new int2(95, 49) }); if (ticks == 430) { diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index f48c4655f8..48d0c13476 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -15,7 +15,7 @@ using OpenRA.Graphics; using OpenRA.Mods.RA.Render; using OpenRA.Traits; using OpenRA.Mods.RA.Effects; -/* + namespace OpenRA.Mods.RA { class ChronoshiftPowerInfo : SupportPowerInfo @@ -27,55 +27,49 @@ namespace OpenRA.Mods.RA public override object Create(ActorInitializer init) { return new ChronoshiftPower(init.self,this); } } - class ChronoshiftPower : SupportPower, IResolveOrder + class ChronoshiftPower : SupportPower { public ChronoshiftPower(Actor self, ChronoshiftPowerInfo info) : base(self, info) { } - protected override void OnActivate() { Self.World.OrderGenerator = new SelectTarget(this); } - - public void ResolveOrder(Actor self, Order order) + + public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager) { - if (!IsReady) return; - - if (order.OrderString == "Chronoshift") + Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound); + return new SelectTarget(order, manager, this); + } + + public override void Activate(Actor self, Order order) + { + self.Trait().PlayCustomAnim(self, "active"); + + // Trigger screen desaturate effect + foreach (var a in self.World.Queries.WithTrait()) + a.Trait.Enable(); + + Sound.Play("chrono2.aud", Game.CellSize * order.TargetLocation); + Sound.Play("chrono2.aud", Game.CellSize * order.ExtraLocation); + System.Console.WriteLine("Searching for units around {0}",order.ExtraLocation); + + foreach (var target in UnitsInRange(order.ExtraLocation)) { - var chronosphere = self.World.Queries - .OwnedBy[self.Owner] - .WithTrait() - .Select(x => x.Actor).FirstOrDefault(); + System.Console.WriteLine("Found actor {0} at {1}",target.Info.Name, target.Location); - if (chronosphere != null) - chronosphere.Trait().PlayCustomAnim(chronosphere, "active"); - - // Trigger screen desaturate effect - foreach (var a in self.World.Queries.WithTrait()) - a.Trait.Enable(); - - Sound.Play("chrono2.aud", Game.CellSize * order.TargetLocation); - Sound.Play("chrono2.aud", Game.CellSize * order.ExtraLocation); - - var targets = UnitsInRange(order.ExtraLocation); - foreach (var target in targets) - { - var cs = target.Trait(); - var targetCell = target.Location + order.TargetLocation - order.ExtraLocation; - - if (cs.CanChronoshiftTo(target, targetCell)) - target.Trait().Teleport(target, - targetCell, - (Info as ChronoshiftPowerInfo).Duration * 25, - (Info as ChronoshiftPowerInfo).KillCargo, - chronosphere); - } - - FinishActivate(); + var cs = target.Trait(); + var targetCell = target.Location + order.TargetLocation - order.ExtraLocation; + // TODO: Fix CanChronoshiftTo desync + if (cs.CanChronoshiftTo(target, targetCell)) + target.Trait().Teleport(target, + targetCell, + (Info as ChronoshiftPowerInfo).Duration * 25, + (Info as ChronoshiftPowerInfo).KillCargo, + self); } } public IEnumerable UnitsInRange(int2 xy) { int range = (Info as ChronoshiftPowerInfo).Range; - var uim = Self.World.WorldActor.Trait(); - var tiles = Self.World.FindTilesInCircle(xy, range); + var uim = self.World.WorldActor.Trait(); + var tiles = self.World.FindTilesInCircle(xy, range); var units = new List(); foreach (var t in tiles) units.AddRange(uim.GetUnitsAt(t)); @@ -85,37 +79,35 @@ namespace OpenRA.Mods.RA class SelectTarget : IOrderGenerator { - ChronoshiftPower power; - int range; - Sprite tile; + readonly ChronoshiftPower power; + readonly int range; + readonly Sprite tile; + readonly SupportPowerManager manager; + readonly string order; - public SelectTarget(ChronoshiftPower power) + public SelectTarget(string order, SupportPowerManager manager, ChronoshiftPower power) { + this.manager = manager; + this.order = order; this.power = power; this.range = (power.Info as ChronoshiftPowerInfo).Range; tile = UiOverlay.SynthesizeTile(0x04); } - + public IEnumerable Order(World world, int2 xy, MouseInput mi) { - if (mi.Button == MouseButton.Right) - world.CancelInputMode(); - else - world.OrderGenerator = new SelectDestination(power, xy); - + world.CancelInputMode(); + world.OrderGenerator = new SelectDestination(order, manager, power, xy); yield break; } - public void Tick( World world ) + public void Tick(World world) { - var hasChronosphere = world.Queries.OwnedBy[world.LocalPlayer] - .WithTrait() - .Any(); - - if (!hasChronosphere) + // Cancel the OG if we can't use the power + if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - + public void RenderAfterWorld(WorldRenderer wr, World world) { var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); @@ -140,13 +132,17 @@ namespace OpenRA.Mods.RA class SelectDestination : IOrderGenerator { - ChronoshiftPower power; - int2 sourceLocation; - int range; - Sprite validTile, invalidTile, sourceTile; + readonly ChronoshiftPower power; + readonly int2 sourceLocation; + readonly int range; + readonly Sprite validTile, invalidTile, sourceTile; + readonly SupportPowerManager manager; + readonly string order; - public SelectDestination(ChronoshiftPower power, int2 sourceLocation) + public SelectDestination(string order, SupportPowerManager manager, ChronoshiftPower power, int2 sourceLocation) { + this.manager = manager; + this.order = order; this.power = power; this.sourceLocation = sourceLocation; this.range = (power.Info as ChronoshiftPowerInfo).Range; @@ -175,23 +171,20 @@ namespace OpenRA.Mods.RA { // Cannot chronoshift into unexplored location if (isValidTarget(xy)) - yield return new Order("Chronoshift", world.LocalPlayer.PlayerActor, false) + yield return new Order(order, manager.self, false) { TargetLocation = xy, ExtraLocation = sourceLocation }; } - + public void Tick(World world) { - var hasChronosphere = world.Queries.OwnedBy[world.LocalPlayer] - .WithTrait() - .Any(); - - if (!hasChronosphere) + // Cancel the OG if we can't use the power + if (!manager.Powers.ContainsKey(order)) world.CancelInputMode(); } - + public void RenderAfterWorld(WorldRenderer wr, World world) { foreach (var unit in power.UnitsInRange(sourceLocation)) @@ -244,15 +237,11 @@ namespace OpenRA.Mods.RA } return canTeleport; } + public string GetCursor(World world, int2 xy, MouseInput mi) { return isValidTarget(xy) ? "chrono-target" : "move-blocked"; } } } - - // tag trait for the building - class ChronosphereInfo : TraitInfo {} - class Chronosphere {} } -*/ \ No newline at end of file diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 2c207e10b3..8f76ada73d 100755 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -24,7 +24,8 @@ MSLO: IronCurtainable: NukePower: Image: atomicon - ChargeTime: 540 +# ChargeTime: 540 + ChargeTime: 10 Description: Atom Bomb LongDesc: Launches a nuclear missile at a target location. BeginChargeSound: aprep1.aud @@ -229,8 +230,18 @@ PDOX: RevealsShroud: Range: 10 Bib: -# Chronosphere: IronCurtainable: + ChronoshiftPower: + Image: warpicon +# ChargeTime: 120 + ChargeTime: 10 + Description: Chronoshift + LongDesc: Teleport a group of vehicles across\nthe map for 30 seconds. + SelectTargetSound: slcttgt1.aud + BeginChargeSound: chrochr1.aud + EndChargeSound: chrordy1.aud + Duration: 30 + KillCargo: yes TSLA: RequiresPower: diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 658b169935..53f8aee29f 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -34,17 +34,6 @@ Player: # Prerequisites: ATEK # RevealDelay: 15 # LaunchSound: satlnch1.aud -# ChronoshiftPower: -# Image: warpicon -# ChargeTime: 2 -# Description: Chronoshift -# LongDesc: Teleport a group of vehicles across\nthe map for 30 seconds. -# Prerequisites: PDOX -# SelectTargetSound: slcttgt1.aud -# BeginChargeSound: chrochr1.aud -# EndChargeSound: chrordy1.aud -# Duration: 30 -# KillCargo: yes # IronCurtainPower: # Image: infxicon # ChargeTime: 2