Reimplemented chronoshift. (still has desync)

This commit is contained in:
Paul Chote
2010-12-05 15:23:14 +13:00
parent 24b322053c
commit 9e16eb513f
5 changed files with 83 additions and 90 deletions

View File

@@ -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) { }

View File

@@ -54,11 +54,11 @@ namespace OpenRA.Mods.RA
if (ticks == 100)
Actors["mslo1"].Trait<NukePower>().Activate(Actors["mslo1"], new Order(null,null,false) { TargetLocation = new int2(98, 52) });
Actors["mslo1"].Trait<NukePower>().Activate(Actors["mslo1"], new Order(){ TargetLocation = new int2(98, 52) });
if (ticks == 140)
Actors["mslo2"].Trait<NukePower>().Activate(Actors["mslo2"], new Order(null,null,false) { TargetLocation = new int2(95, 54) });
Actors["mslo2"].Trait<NukePower>().Activate(Actors["mslo2"], new Order(){ TargetLocation = new int2(95, 54) });
if (ticks == 180)
Actors["mslo3"].Trait<NukePower>().Activate(Actors["mslo3"], new Order(null,null,false) { TargetLocation = new int2(95, 49) });
Actors["mslo3"].Trait<NukePower>().Activate(Actors["mslo3"], new Order(){ TargetLocation = new int2(95, 49) });
if (ticks == 430)
{

View File

@@ -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,24 +27,19 @@ 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;
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
return new SelectTarget(order, manager, this);
}
if (order.OrderString == "Chronoshift")
public override void Activate(Actor self, Order order)
{
var chronosphere = self.World.Queries
.OwnedBy[self.Owner]
.WithTrait<Chronosphere>()
.Select(x => x.Actor).FirstOrDefault();
if (chronosphere != null)
chronosphere.Trait<RenderBuilding>().PlayCustomAnim(chronosphere, "active");
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
// Trigger screen desaturate effect
foreach (var a in self.World.Queries.WithTrait<ChronoshiftPaletteEffect>())
@@ -52,30 +47,29 @@ namespace OpenRA.Mods.RA
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);
var targets = UnitsInRange(order.ExtraLocation);
foreach (var target in targets)
foreach (var target in UnitsInRange(order.ExtraLocation))
{
System.Console.WriteLine("Found actor {0} at {1}",target.Info.Name, target.Location);
var cs = target.Trait<Chronoshiftable>();
var targetCell = target.Location + order.TargetLocation - order.ExtraLocation;
// TODO: Fix CanChronoshiftTo desync
if (cs.CanChronoshiftTo(target, targetCell))
target.Trait<Chronoshiftable>().Teleport(target,
targetCell,
(Info as ChronoshiftPowerInfo).Duration * 25,
(Info as ChronoshiftPowerInfo).KillCargo,
chronosphere);
}
FinishActivate();
self);
}
}
public IEnumerable<Actor> UnitsInRange(int2 xy)
{
int range = (Info as ChronoshiftPowerInfo).Range;
var uim = Self.World.WorldActor.Trait<UnitInfluence>();
var tiles = Self.World.FindTilesInCircle(xy, range);
var uim = self.World.WorldActor.Trait<UnitInfluence>();
var tiles = self.World.FindTilesInCircle(xy, range);
var units = new List<Actor>();
foreach (var t in tiles)
units.AddRange(uim.GetUnitsAt(t));
@@ -85,12 +79,16 @@ 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);
@@ -98,21 +96,15 @@ namespace OpenRA.Mods.RA
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
world.CancelInputMode();
else
world.OrderGenerator = new SelectDestination(power, xy);
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<Chronosphere>()
.Any();
if (!hasChronosphere)
// Cancel the OG if we can't use the power
if (!manager.Powers.ContainsKey(order))
world.CancelInputMode();
}
@@ -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,7 +171,7 @@ 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
@@ -184,11 +180,8 @@ namespace OpenRA.Mods.RA
public void Tick(World world)
{
var hasChronosphere = world.Queries.OwnedBy[world.LocalPlayer]
.WithTrait<Chronosphere>()
.Any();
if (!hasChronosphere)
// Cancel the OG if we can't use the power
if (!manager.Powers.ContainsKey(order))
world.CancelInputMode();
}
@@ -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<Chronosphere> {}
class Chronosphere {}
}
*/

View File

@@ -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:

View File

@@ -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