pass World to Effects/*

This commit is contained in:
Bob
2010-01-21 13:27:44 +13:00
parent 90b5df73b5
commit 4fa56f16c0
20 changed files with 43 additions and 43 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRa
if (warhead.Explosion != 0) if (warhead.Explosion != 0)
world.AddFrameEndTask( world.AddFrameEndTask(
w => w.Add(new Explosion(visualLoc, warhead.Explosion, hitWater))); w => w.Add(new Explosion(w, visualLoc, warhead.Explosion, hitWater)));
var impactSound = warhead.ImpactSound; var impactSound = warhead.ImpactSound;
if (hitWater && warhead.WaterImpactSound != null) if (hitWater && warhead.WaterImpactSound != null)

View File

@@ -61,7 +61,7 @@ namespace OpenRa
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor); Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
if (isMove) if (isMove)
Game.world.Add(new Effects.MoveFlash(Game.CellSize * xy)); Game.world.Add(new Effects.MoveFlash(Game.world, Game.CellSize * xy));
} }
} }

View File

@@ -56,13 +56,13 @@ namespace OpenRa.Effects
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; } int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick() public void Tick( World world )
{ {
t += 40; t += 40;
if (t > TotalTime()) /* remove finished bullets */ if (t > TotalTime()) /* remove finished bullets */
{ {
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
Combat.DoImpact(Dest, VisualDest - new int2( 0, DestAltitude ), Combat.DoImpact(Dest, VisualDest - new int2( 0, DestAltitude ),
Weapon, Projectile, Warhead, FiredBy); Weapon, Projectile, Warhead, FiredBy);
} }

View File

@@ -15,13 +15,13 @@ namespace OpenRa.Effects
{ {
anim = new Animation(fromActor.traits.GetOrDefault<RenderSimple>().GetImage(fromActor)); anim = new Animation(fromActor.traits.GetOrDefault<RenderSimple>().GetImage(fromActor));
anim.PlayThen("die{0}".F(death + 1), anim.PlayThen("die{0}".F(death + 1),
() => Game.world.AddFrameEndTask(w => w.Remove(this))); () => fromActor.World.AddFrameEndTask(w => w.Remove(this)));
pos = fromActor.CenterLocation; pos = fromActor.CenterLocation;
owner = fromActor.Owner; owner = fromActor.Owner;
} }
public void Tick() { anim.Tick(); } public void Tick( World world ) { anim.Tick(); }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {

View File

@@ -15,10 +15,10 @@ namespace OpenRa.Effects
this.delay = delay; this.delay = delay;
} }
public void Tick() public void Tick( World world )
{ {
if (--delay <= 0) if (--delay <= 0)
Game.world.AddFrameEndTask(w => { w.Remove(this); a(); }); world.AddFrameEndTask(w => { w.Remove(this); a(); });
} }
public IEnumerable<Renderable> Render() { yield break; } public IEnumerable<Renderable> Render() { yield break; }

View File

@@ -9,16 +9,16 @@ namespace OpenRa.Effects
Animation anim; Animation anim;
int2 pos; int2 pos;
public Explosion(int2 pixelPos, int style, bool isWater) public Explosion( World world, int2 pixelPos, int style, bool isWater)
{ {
this.pos = pixelPos; this.pos = pixelPos;
var variantSuffix = isWater ? "w" : ""; var variantSuffix = isWater ? "w" : "";
anim = new Animation("explosion"); anim = new Animation("explosion");
anim.PlayThen(style.ToString() + variantSuffix, anim.PlayThen(style.ToString() + variantSuffix,
() => Game.world.AddFrameEndTask(w => w.Remove(this))); () => world.AddFrameEndTask(w => w.Remove(this)));
} }
public void Tick() { anim.Tick(); } public void Tick( World world ) { anim.Tick(); }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {

View File

@@ -15,14 +15,14 @@ namespace OpenRa.Effects
public FlashTarget(Actor target) public FlashTarget(Actor target)
{ {
this.target = target; this.target = target;
foreach (var e in Game.world.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray()) foreach (var e in target.World.Effects.OfType<FlashTarget>().Where(a => a.target == target).ToArray())
Game.world.Remove(e); target.World.Remove(e);
} }
public void Tick() public void Tick( World world )
{ {
if (--remainingTicks == 0) if (--remainingTicks == 0)
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()

View File

@@ -16,13 +16,13 @@ namespace OpenRa.Effects
anim.PlayRepeating("idle"); anim.PlayRepeating("idle");
} }
public void Tick() public void Tick( World world )
{ {
anim.Tick(); anim.Tick();
offset.Y -= heightPerTick; offset.Y -= heightPerTick;
if (offset.Y < 0) if (offset.Y < 0)
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()

View File

@@ -6,7 +6,7 @@ namespace OpenRa.Effects
{ {
public interface IEffect public interface IEffect
{ {
void Tick(); void Tick( World world );
IEnumerable<Renderable> Render(); IEnumerable<Renderable> Render();
} }
} }

View File

@@ -15,10 +15,10 @@ namespace OpenRa.Effects
this.b = a.traits.Get<IronCurtainable>(); this.b = a.traits.Get<IronCurtainable>();
} }
public void Tick() public void Tick( World world )
{ {
if (a.IsDead || b.GetDamageModifier() > 0) if (a.IsDead || b.GetDamageModifier() > 0)
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()

View File

@@ -47,7 +47,7 @@ namespace OpenRa.Effects
const int MissileCloseEnough = 7; const int MissileCloseEnough = 7;
const float Scale = .2f; const float Scale = .2f;
public void Tick() public void Tick( World world )
{ {
t += 40; t += 40;
@@ -64,7 +64,7 @@ namespace OpenRa.Effects
var dist = Target.CenterLocation - Pos; var dist = Target.CenterLocation - Pos;
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead) if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead)
{ {
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */ if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy); Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
@@ -78,7 +78,7 @@ namespace OpenRa.Effects
Pos += move; Pos += move;
if (Projectile.Animates) if (Projectile.Animates)
Game.world.AddFrameEndTask(w => w.Add(new Smoke((Pos - 1.5f * move - new int2( 0, Altitude )).ToInt2()))); world.AddFrameEndTask(w => w.Add(new Smoke(w, (Pos - 1.5f * move - new int2( 0, Altitude )).ToInt2())));
// todo: running out of fuel // todo: running out of fuel
} }

View File

@@ -12,15 +12,15 @@ namespace OpenRa.Effects
Animation anim = new Animation("moveflsh"); Animation anim = new Animation("moveflsh");
float2 pos; float2 pos;
public MoveFlash( float2 pos ) public MoveFlash( World world, float2 pos )
{ {
this.pos = pos; this.pos = pos;
anim.PlayThen( "idle", anim.PlayThen( "idle",
() => Game.world.AddFrameEndTask( () => world.AddFrameEndTask(
w => w.Remove( this ) ) ); w => w.Remove( this ) ) );
} }
public void Tick() { anim.Tick(); } public void Tick( World world ) { anim.Tick(); }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {

View File

@@ -20,10 +20,10 @@ namespace OpenRa.Effects
anim.PlayRepeating("disabled"); anim.PlayRepeating("disabled");
} }
public void Tick() public void Tick( World world )
{ {
if (removeNextFrame == true) if (removeNextFrame == true)
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
// Fix off-by one frame bug with undisabling causing low-power // Fix off-by one frame bug with undisabling causing low-power
if (!b.Disabled || a.IsDead) if (!b.Disabled || a.IsDead)

View File

@@ -12,10 +12,10 @@ namespace OpenRa.Effects
public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); } public RepairIndicator(Actor a) { this.a = a; anim.PlayRepeating("repair"); }
public void Tick() public void Tick( World world )
{ {
if (--framesLeft == 0 || a.IsDead) if (--framesLeft == 0 || a.IsDead)
Game.world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()

View File

@@ -15,16 +15,16 @@ namespace OpenRa.Effects
{ {
this.a = a; this.a = a;
doors.PlayThen("active", doors.PlayThen("active",
() => Game.world.AddFrameEndTask(w => w.Remove(this))); () => a.World.AddFrameEndTask(w => w.Remove(this)));
} }
public void Tick() public void Tick( World world )
{ {
doors.Tick(); doors.Tick();
if (++frame == 19) if (++frame == 19)
{ {
Game.world.AddFrameEndTask(w => w.Add(new GpsSatellite(a.CenterLocation - .5f * doors.Image.size + doorOffset))); world.AddFrameEndTask(w => w.Add(new GpsSatellite(a.CenterLocation - .5f * doors.Image.size + doorOffset)));
} }
} }

View File

@@ -9,14 +9,14 @@ namespace OpenRa.Effects
readonly int2 pos; readonly int2 pos;
readonly Animation anim = new Animation("smokey"); readonly Animation anim = new Animation("smokey");
public Smoke(int2 pos) public Smoke(World world, int2 pos)
{ {
this.pos = pos; this.pos = pos;
anim.PlayThen("idle", anim.PlayThen("idle",
() => Game.world.AddFrameEndTask(w => w.Remove(this))); () => world.AddFrameEndTask(w => w.Remove(this)));
} }
public void Tick() public void Tick( World world )
{ {
anim.Tick(); anim.Tick();
} }

View File

@@ -20,10 +20,10 @@ namespace OpenRa.Effects
this.tesla = SequenceProvider.GetSequence( "litning", "bright" ); this.tesla = SequenceProvider.GetSequence( "litning", "bright" );
} }
public void Tick() public void Tick( World world )
{ {
if( timeUntilRemove <= 0 ) if( timeUntilRemove <= 0 )
Game.world.AddFrameEndTask( w => w.Remove( this ) ); world.AddFrameEndTask( w => w.Remove( this ) );
--timeUntilRemove; --timeUntilRemove;
} }

View File

@@ -87,7 +87,7 @@ namespace OpenRa.Traits
break; break;
case DamageState.Dead: case DamageState.Dead:
DoBib(self, true); DoBib(self, true);
self.World.AddFrameEndTask(w => w.Add(new Explosion(self.CenterLocation.ToInt2(), 7, false))); self.World.AddFrameEndTask(w => w.Add(new Explosion(w, self.CenterLocation.ToInt2(), 7, false)));
break; break;
} }
} }

View File

@@ -110,7 +110,7 @@ namespace OpenRa
} }
foreach (var a in actors) a.Tick(); foreach (var a in actors) a.Tick();
foreach (var e in effects) e.Tick(); foreach (var e in effects) e.Tick( this );
Game.viewport.Tick(); Game.viewport.Tick();

View File

@@ -32,10 +32,10 @@ namespace OpenRa.Mods.RA
var info = self.Info.Traits.Get<MineInfo>(); var info = self.Info.Traits.Get<MineInfo>();
var warhead = Rules.WarheadInfo[info.Warhead]; var warhead = Rules.WarheadInfo[info.Warhead];
self.World.AddFrameEndTask(_ => self.World.AddFrameEndTask(w =>
{ {
self.World.Remove(self); w.Remove(self);
self.World.Add(new Explosion(self.CenterLocation.ToInt2(), warhead.Explosion, false)); w.Add(new Explosion(w, self.CenterLocation.ToInt2(), warhead.Explosion, false));
crusher.InflictDamage(crusher, info.Damage, warhead); crusher.InflictDamage(crusher, info.Damage, warhead);
}); });
} }