move render{building,buildingturreted,unit} into mods.ra; move all render traits into mods.ra.render

This commit is contained in:
Bob
2010-07-08 17:24:12 +12:00
parent 281d013c3b
commit fb6c44bce3
34 changed files with 71 additions and 60 deletions

View File

@@ -0,0 +1,100 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class RenderBuildingInfo : RenderSimpleInfo
{
public readonly bool HasMakeAnimation = true;
public override object Create(ActorInitializer init) { return new RenderBuilding(init.self);}
}
public class RenderBuilding : RenderSimple, INotifyDamage, INotifySold
{
public RenderBuilding( Actor self )
: this( self, () => 0 )
{
}
public RenderBuilding(Actor self, Func<int> baseFacing)
: base(self, baseFacing)
{
if( Game.skipMakeAnims || !self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation )
anim.PlayThen( "idle", () => self.World.AddFrameEndTask( _ => Complete( self ) ) );
else
anim.PlayThen( "make", () => self.World.AddFrameEndTask( _ => Complete( self ) ) );
}
void Complete( Actor self )
{
anim.PlayRepeating( GetPrefix(self) + "idle" );
foreach( var x in self.traits.WithInterface<INotifyBuildComplete>() )
x.BuildingComplete( self );
}
public void PlayCustomAnimThen(Actor self, string name, Action a)
{
anim.PlayThen(GetPrefix(self) + name,
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
}
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
{
var hasSequence = anim.HasSequence(GetPrefix(self) + name);
anim.PlayBackwardsThen(hasSequence ? GetPrefix(self) + name : name,
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
}
public virtual void Damaged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged)
return;
switch( e.DamageState )
{
case DamageState.Normal:
anim.ReplaceAnim("idle");
break;
case DamageState.Half:
anim.ReplaceAnim("damaged-idle");
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
break;
case DamageState.Dead:
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, self.CenterLocation.ToInt2(), "building", false)));
break;
}
}
public void Selling( Actor self )
{
if( !Game.skipMakeAnims && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation )
anim.PlayBackwardsThen( "make", null );
foreach (var s in self.Info.Traits.Get<BuildingInfo>().SellSounds)
Sound.PlayToPlayer(self.Owner, s, self.CenterLocation);
}
public void Sold(Actor self) {}
}
}

View File

@@ -0,0 +1,44 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.Mods.RA.Render
{
class RenderBuildingChargeInfo : RenderBuildingInfo
{
public readonly string ChargeAudio = "tslachg2.aud";
public override object Create(ActorInitializer init) { return new RenderBuildingCharge(init.self); }
}
/* used for tesla */
public class RenderBuildingCharge : RenderBuilding
{
public RenderBuildingCharge(Actor self)
: base(self)
{
}
public void PlayCharge(Actor self)
{
Sound.Play(self.Info.Traits.Get<RenderBuildingChargeInfo>().ChargeAudio, self.CenterLocation);
anim.PlayThen(GetPrefix(self) + "active",
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
}
}
}

View File

@@ -0,0 +1,43 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderBuildingOreInfo : RenderBuildingInfo
{
public override object Create(ActorInitializer init) { return new RenderBuildingOre(init.self); }
}
class RenderBuildingOre : RenderBuilding, INotifyBuildComplete
{
public RenderBuildingOre(Actor self)
: base(self)
{
}
public void BuildingComplete( Actor self )
{
anim.PlayFetchIndex( "idle",
() => (int)( 4.9 * self.Owner.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() ) );
}
}
}

View File

@@ -0,0 +1,58 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderBuildingTurretedInfo : RenderBuildingInfo
{
public override object Create(ActorInitializer init) { return new RenderBuildingTurreted(init.self); }
}
class RenderBuildingTurreted : RenderBuilding, INotifyBuildComplete
{
public RenderBuildingTurreted(Actor self)
: base(self, () => self.traits.Get<Turreted>().turretFacing)
{
}
public void BuildingComplete( Actor self )
{
anim.Play( "idle" );
}
public override void Damaged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged) return;
switch (e.DamageState)
{
case DamageState.Normal:
anim.Play( "idle" );
break;
case DamageState.Half:
anim.Play( "damaged-idle" );
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
break;
}
}
}
}

View File

@@ -0,0 +1,127 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderBuildingWallInfo : RenderBuildingInfo
{
public readonly int DamageStates = 2;
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init.self); }
}
class RenderBuildingWall : RenderBuilding
{
string seqName;
int adjacentWalls = 0;
public RenderBuildingWall(Actor self)
: base(self)
{
seqName = "idle";
anim.PlayFetchIndex(seqName, () => adjacentWalls);
}
enum ExtendedDamageState { Normal, ThreeQuarter, Half, Quarter, Dead };
ExtendedDamageState GetExtendedState( Actor self, int damage )
{
var effectiveHealth = self.Health + damage;
if (effectiveHealth <= 0)
return ExtendedDamageState.Dead;
if (effectiveHealth < self.GetMaxHP() * self.World.Defaults.ConditionRed)
return ExtendedDamageState.Quarter;
if (effectiveHealth < self.GetMaxHP() * self.World.Defaults.ConditionYellow)
return ExtendedDamageState.Half;
if (effectiveHealth < self.GetMaxHP() * 0.75)
return ExtendedDamageState.ThreeQuarter;
return ExtendedDamageState.Normal;
}
public override void Damaged(Actor self, AttackInfo e)
{
var oldState = GetExtendedState(self, e.Damage);
var newState = GetExtendedState(self, 0);
var numStates = self.Info.Traits.Get<RenderBuildingWallInfo>().DamageStates;
if (oldState == newState) return;
switch (newState)
{
case ExtendedDamageState.Normal:
seqName = "idle";
break;
case ExtendedDamageState.ThreeQuarter:
if (numStates >= 4)
seqName = "minor-damaged-idle";
break;
case ExtendedDamageState.Half:
seqName = "damaged-idle";
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
break;
case ExtendedDamageState.Quarter:
if (numStates >= 3)
{
seqName = "critical-idle";
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound, self.CenterLocation);
}
break;
}
anim.PlayFetchIndex(seqName, () => adjacentWalls);
}
bool hasTicked = false;
public override void Tick(Actor self)
{
base.Tick(self);
if (!hasTicked)
{
var oneCell = new float2(Game.CellSize, Game.CellSize);
var adjWalls = self.World.FindUnits(self.CenterLocation - oneCell, self.CenterLocation + oneCell)
.Where(a => a.Info == self.Info && a != self);
foreach (var w in adjWalls)
{
w.traits.Get<RenderBuildingWall>().AddAdjacentWall(w.Location, self.Location);
AddAdjacentWall(self.Location, w.Location);
}
hasTicked = true;
}
}
void AddAdjacentWall(int2 location, int2 otherLocation)
{
if (otherLocation == location + new int2(0, -1)) adjacentWalls |= 1;
if (otherLocation == location + new int2(+1, 0)) adjacentWalls |= 2;
if (otherLocation == location + new int2(0, +1)) adjacentWalls |= 4;
if (otherLocation == location + new int2(-1, 0)) adjacentWalls |= 8;
}
}
}

View File

@@ -0,0 +1,90 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderWarFactoryInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{
public object Create(ActorInitializer init) { return new RenderWarFactory(init.self); }
}
class RenderWarFactory : INotifyBuildComplete, INotifyDamage, ITick, INotifyProduction, INotifySold
{
public Animation roof;
[Sync]
bool isOpen;
string GetPrefix(Actor self)
{
return self.GetDamageState() == DamageState.Half ? "damaged-" : "";
}
public RenderWarFactory(Actor self)
{
roof = new Animation(self.traits.Get<RenderSimple>().GetImage(self));
}
public void BuildingComplete( Actor self )
{
roof.Play( GetPrefix(self) + "idle-top" );
self.traits.Get<RenderSimple>().anims.Add( "roof", new RenderSimple.AnimationWithOffset( roof ) { ZOffset = 2 } );
}
public void Tick(Actor self)
{
if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>()
.GetUnitsAt(((1f/Game.CellSize) * self.CenterLocation).ToInt2()).Any())
{
isOpen = false;
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));
}
}
public void Damaged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged) return;
switch (e.DamageState)
{
case DamageState.Normal:
roof.ReplaceAnim(roof.CurrentSequence.Name.Replace("damaged-",""));
break;
case DamageState.Half:
roof.ReplaceAnim("damaged-" + roof.CurrentSequence.Name);
break;
}
}
public void UnitProduced(Actor self, Actor other)
{
roof.PlayThen(GetPrefix(self) + "build-top", () => isOpen = true);
}
public void Selling( Actor self )
{
self.traits.Get<RenderSimple>().anims.Remove( "roof" );
}
public void Sold( Actor self ) { }
}
}

View File

@@ -0,0 +1,38 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderFlareInfo : RenderSimpleInfo
{
public override object Create(ActorInitializer init) { return new RenderFlare(init.self); }
}
class RenderFlare : RenderSimple
{
public RenderFlare(Actor self)
: base(self, () => 0)
{
anim.PlayThen("open", () => anim.PlayRepeating("idle"));
}
}
}

View File

@@ -0,0 +1,99 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Effects;
namespace OpenRA.Mods.RA.Render
{
public class RenderInfantryInfo : RenderSimpleInfo
{
public override object Create(ActorInitializer init) { return new RenderInfantry(init.self); }
}
public class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage
{
public RenderInfantry(Actor self)
: base(self, () => self.traits.Get<Unit>().Facing)
{
anim.Play("stand");
}
bool ChooseMoveAnim(Actor self)
{
if (!(self.GetCurrentActivity() is Move))
return false;
var mobile = self.traits.Get<Mobile>();
if (float2.WithinEpsilon(self.CenterLocation, Util.CenterOfCell(mobile.toCell), 2)) return false;
var seq = IsProne(self) ? "crawl" : "run";
if (anim.CurrentSequence.Name != seq)
anim.PlayRepeating(seq);
return true;
}
bool inAttack = false;
bool IsProne(Actor self)
{
var takeCover = self.traits.GetOrDefault<TakeCover>();
return takeCover != null && takeCover.IsProne;
}
public void Attacking(Actor self)
{
inAttack = true;
var seq = IsProne(self) ? "prone-shoot" : "shoot";
if (anim.HasSequence(seq))
anim.PlayThen(seq, () => inAttack = false);
else if (anim.HasSequence("heal"))
anim.PlayThen("heal", () => inAttack = false);
}
public override void Tick(Actor self)
{
base.Tick(self);
if (inAttack) return;
if (ChooseMoveAnim(self)) return;
/* todo: idle anims, etc */
if (IsProne(self))
anim.PlayFetchIndex("crawl", () => 0); /* what a hack. */
else
anim.Play("stand");
}
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
{
var death = e.Warhead != null ? e.Warhead.InfDeath : 0;
Sound.PlayVoice("Die", self);
self.World.AddFrameEndTask(w => w.Add(new Corpse(self, death)));
}
}
}
}

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderSpyInfo : RenderInfantryInfo
{
public override object Create(ActorInitializer init) { return new RenderSpy(init.self); }
}
class RenderSpy : RenderInfantry, IRenderModifier
{
public RenderSpy(Actor self) : base(self) { }
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{
if (self.Owner == self.World.LocalPlayer)
return r;
return r.Select(a => a.WithPalette(self.World.LocalPlayer.Palette));
}
public override void Tick(Actor self)
{
anim.ChangeImage(self.Owner == self.World.LocalPlayer ? GetImage(self) : "e1");
base.Tick(self);
}
}
}

View File

@@ -0,0 +1,61 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class RenderUnitInfo : RenderSimpleInfo
{
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
}
public class RenderUnit : RenderSimple, INotifyDamage
{
public RenderUnit(Actor self)
: base(self, () => self.traits.Get<Unit>().Facing)
{
anim.Play("idle");
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
}
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
{
anim.PlayThen(newAnim, () => { anim.Play("idle"); if (after != null) after(); });
}
bool isSmoking;
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState != DamageState.Half) return;
if (isSmoking) return;
isSmoking = true;
var smoke = anims[ "smoke" ].Animation;
smoke.PlayThen( "idle",
() => smoke.PlayThen( "loop",
() => smoke.PlayBackwardsThen( "end",
() => isSmoking = false ) ) );
}
}
}

View File

@@ -0,0 +1,48 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderUnitReloadInfo : RenderUnitInfo
{
public override object Create(ActorInitializer init) { return new RenderUnitReload(init.self); }
}
class RenderUnitReload : RenderUnit
{
public RenderUnitReload(Actor self)
: base(self) { }
public override void Tick(Actor self)
{
var isAttacking = self.GetCurrentActivity() is Attack;
var attack = self.traits.GetOrDefault<AttackBase>();
if (attack != null)
anim.ReplaceAnim((attack.IsReloading() ? "empty-" : "")
+ (isAttacking ? "aim" : "idle"));
base.Tick(self);
}
}
}

View File

@@ -0,0 +1,77 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderUnitRotorInfo : RenderUnitInfo
{
public readonly int[] PrimaryOffset = { 0, 0 };
public readonly int[] SecondaryOffset = null;
public override object Create(ActorInitializer init) { return new RenderUnitRotor(init.self); }
}
class RenderUnitRotor : RenderUnit
{
public Animation rotorAnim, secondRotorAnim;
public RenderUnitRotor( Actor self )
: base(self)
{
var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitRotorInfo>();
rotorAnim = new Animation(GetImage(self));
rotorAnim.PlayRepeating("rotor");
anims.Add( "rotor_1", new AnimationWithOffset(
rotorAnim,
() => Combat.GetTurretPosition( self, unit, info.PrimaryOffset, 0 ),
null ) { ZOffset = 1 } );
if (info.SecondaryOffset == null) return;
secondRotorAnim = new Animation(GetImage(self));
secondRotorAnim.PlayRepeating( "rotor2" );
anims.Add( "rotor_2", new AnimationWithOffset(
secondRotorAnim,
() => Combat.GetTurretPosition(self, unit, info.SecondaryOffset, 0),
null) { ZOffset = 1 });
}
public override void Tick(Actor self)
{
base.Tick(self);
var unit = self.traits.Get<Unit>();
var isFlying = unit.Altitude > 0;
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
return;
rotorAnim.ReplaceAnim(isFlying ? "rotor" : "slow-rotor");
if (secondRotorAnim != null)
secondRotorAnim.ReplaceAnim(isFlying ? "rotor2" : "slow-rotor2");
}
}
}

View File

@@ -0,0 +1,48 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderUnitSpinnerInfo : RenderUnitInfo
{
public readonly int[] Offset = { 0, 0 };
public override object Create(ActorInitializer init) { return new RenderUnitSpinner(init.self); }
}
class RenderUnitSpinner : RenderUnit
{
public RenderUnitSpinner( Actor self )
: base(self)
{
var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>();
var spinnerAnim = new Animation( GetImage(self) );
spinnerAnim.PlayRepeating( "spinner" );
anims.Add( "spinner", new AnimationWithOffset(
spinnerAnim,
() => Combat.GetTurretPosition( self, unit, info.Offset, 0 ),
null ) { ZOffset = 1 } );
}
}
}

View File

@@ -0,0 +1,68 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderUnitTurretedInfo : RenderUnitInfo
{
public override object Create(ActorInitializer init) { return new RenderUnitTurreted(init.self); }
}
class RenderUnitTurreted : RenderUnit
{
public RenderUnitTurreted(Actor self)
: base(self)
{
var unit = self.traits.Get<Unit>();
var turreted = self.traits.Get<Turreted>();
var attack = self.traits.GetOrDefault<AttackBase>();
var attackInfo = self.Info.Traits.Get<AttackBaseInfo>();
var turretAnim = new Animation(GetImage(self), () => turreted.turretFacing );
turretAnim.Play( "turret" );
if( attackInfo.PrimaryOffset != null )
anims.Add("turret_1", new AnimationWithOffset(
turretAnim,
() => Combat.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil),
null) { ZOffset = 1 });
if (attackInfo.SecondaryOffset != null)
anims.Add("turret_2", new AnimationWithOffset(
turretAnim,
() => Combat.GetTurretPosition(self, unit, attackInfo.SecondaryOffset, attack.secondaryRecoil),
null) { ZOffset = 1 });
if( attackInfo.MuzzleFlash )
{
var muzzleFlash = new Animation( GetImage(self), () => self.traits.Get<Turreted>().turretFacing );
muzzleFlash.PlayFetchIndex( "muzzle",
() => (int)( attack.primaryRecoil * 5.9f ) ); /* hack: recoil can be 1.0f, but don't overflow into next anim */
anims.Add( "muzzle_flash", new AnimationWithOffset(
muzzleFlash,
() => Combat.GetTurretPosition(self, unit, attackInfo.PrimaryOffset, attack.primaryRecoil),
() => attack.primaryRecoil <= 0 ) );
}
}
}
}