renamed Actor.unitInfo to "Info"; other minor changes

This commit is contained in:
Bob
2009-12-05 19:12:29 +13:00
parent 7f1e34e482
commit 74b7d21d4b
29 changed files with 85 additions and 76 deletions

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game
class Actor class Actor
{ {
public readonly TypeDictionary traits = new TypeDictionary(); public readonly TypeDictionary traits = new TypeDictionary();
public readonly UnitInfo unitInfo; public readonly UnitInfo Info;
public readonly uint ActorID; public readonly uint ActorID;
public int2 Location; public int2 Location;
@@ -20,18 +20,18 @@ namespace OpenRa.Game
public int Health; public int Health;
IActivity currentActivity; IActivity currentActivity;
public Actor( string name, int2 location, Player owner ) public Actor( ActorInfo info, int2 location, Player owner )
{ {
ActorID = Game.world.NextAID(); ActorID = Game.world.NextAID();
unitInfo = Rules.UnitInfo[ name ]; Info = (UnitInfo)info; // temporary
Location = location; Location = location;
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location; CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
Owner = owner; Owner = owner;
Health = unitInfo.Strength; /* todo: handle cases where this is not true! */ Health = Info.Strength; /* todo: handle cases where this is not true! */
if( unitInfo.Traits != null ) if( Info.Traits != null )
{ {
foreach( var traitName in unitInfo.Traits ) foreach( var traitName in Info.Traits )
{ {
var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false ); var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false );
var ctor = type.GetConstructor( new[] { typeof( Actor ) } ); var ctor = type.GetConstructor( new[] { typeof( Actor ) } );
@@ -39,7 +39,7 @@ namespace OpenRa.Game
} }
} }
else else
throw new InvalidOperationException( "No Actor traits for " + unitInfo.Name throw new InvalidOperationException( "No Actor traits for " + Info.Name
+ "; add Traits= to units.ini for appropriate unit" ); + "; add Traits= to units.ini for appropriate unit" );
} }
@@ -74,7 +74,7 @@ namespace OpenRa.Game
var underCursor = Game.UnitInfluence.GetUnitAt( xy ) var underCursor = Game.UnitInfluence.GetUnitAt( xy )
?? Game.BuildingInfluence.GetBuildingAt( xy ); ?? Game.BuildingInfluence.GetBuildingAt( xy );
if (underCursor != null && !underCursor.unitInfo.Selectable) if (underCursor != null && !underCursor.Info.Selectable)
underCursor = null; underCursor = null;
return traits.WithInterface<Traits.IOrder>() return traits.WithInterface<Traits.IOrder>()
@@ -117,7 +117,7 @@ namespace OpenRa.Game
Sound.Play("kaboom22.aud"); Sound.Play("kaboom22.aud");
} }
var halfStrength = unitInfo.Strength * Rules.General.ConditionYellow; var halfStrength = Info.Strength * Rules.General.ConditionYellow;
if (Health < halfStrength && (Health + damage) >= halfStrength) if (Health < halfStrength && (Health + damage) >= halfStrength)
{ {
/* we just went below half health! */ /* we just went below half health! */

View File

@@ -138,13 +138,10 @@ namespace OpenRa.Game
float GetDamageToInflict(Actor target) float GetDamageToInflict(Actor target)
{ {
if( target.unitInfo == null ) // tree or other doodad
return 0;
/* todo: some things can't be damaged AT ALL by certain weapons! */ /* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - Dest).Length; var distance = (target.CenterLocation - Dest).Length;
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread); var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
var multiplier = Warhead.EffectivenessAgainst(target.unitInfo.Armor); var multiplier = Warhead.EffectivenessAgainst(target.Info.Armor);
return rawDamage * multiplier; return rawDamage * multiplier;
} }

View File

@@ -71,7 +71,7 @@ namespace OpenRa.Game
UnitInfluence = new UnitInfluenceMap(); UnitInfluence = new UnitInfluenceMap();
foreach (TreeReference treeReference in Rules.Map.Trees) foreach (TreeReference treeReference in Rules.Map.Trees)
world.Add(new Actor(treeReference.Image, world.Add(new Actor(Rules.UnitInfo[treeReference.Image],
new int2(treeReference.Location), new int2(treeReference.Location),
null)); null));
@@ -108,7 +108,7 @@ namespace OpenRa.Game
//num=owner,type,health,location,facing,trigger,unknown,shouldRepair //num=owner,type,health,location,facing,trigger,unknown,shouldRepair
var parts = s.Value.ToLowerInvariant().Split(','); var parts = s.Value.ToLowerInvariant().Split(',');
var loc = int.Parse(parts[3]); var loc = int.Parse(parts[3]);
world.Add(new Actor(parts[1], new int2(loc % 128, loc / 128), players[0])); world.Add(new Actor(Rules.UnitInfo[parts[1]], new int2(loc % 128, loc / 128), players[0]));
} }
} }
@@ -117,9 +117,9 @@ namespace OpenRa.Game
foreach (var s in mapfile.GetSection("UNITS", true)) foreach (var s in mapfile.GetSection("UNITS", true))
{ {
//num=owner,type,health,location,facing,action,trigger //num=owner,type,health,location,facing,action,trigger
var parts = s.Value.Split(','); var parts = s.Value.ToLowerInvariant().Split( ',' );
var loc = int.Parse(parts[3]); var loc = int.Parse(parts[3]);
world.Add(new Actor(parts[1].ToLowerInvariant(), new int2(loc % 128, loc / 128), world.Add(new Actor(Rules.UnitInfo[parts[1]], new int2(loc % 128, loc / 128),
players.Values.FirstOrDefault(p => p.PlayerName == parts[0]) players.Values.FirstOrDefault(p => p.PlayerName == parts[0])
?? players[0])); ?? players[0]));
} }
@@ -244,8 +244,8 @@ namespace OpenRa.Game
public static IEnumerable<Actor> SelectActorsInBox(float2 a, float2 b) public static IEnumerable<Actor> SelectActorsInBox(float2 a, float2 b)
{ {
return FindUnits(a, b) return FindUnits(a, b)
.Where( x => x.unitInfo.Selectable ) .Where( x => x.Info.Selectable )
.GroupBy(x => (x.Owner == LocalPlayer) ? x.unitInfo.SelectionPriority : 0) .GroupBy(x => (x.Owner == LocalPlayer) ? x.Info.SelectionPriority : 0)
.OrderByDescending(g => g.Key) .OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() ) .Select( g => g.AsEnumerable() )
.DefaultIfEmpty( new Actor[] {} ) .DefaultIfEmpty( new Actor[] {} )
@@ -315,7 +315,7 @@ namespace OpenRa.Game
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType ); var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
// TODO: choose producer based on "primary building" // TODO: choose producer based on "primary building"
var producer = world.Actors var producer = world.Actors
.Where( x => producerTypes.Contains( x.unitInfo ) && x.Owner == player ) .Where( x => producerTypes.Contains( x.Info ) && x.Owner == player )
.FirstOrDefault(); .FirstOrDefault();
if (producer == null) if (producer == null)

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.GameRules
{
public class ActorInfo
{
}
}

View File

@@ -21,8 +21,8 @@ namespace OpenRa.Game.GameRules
public Cache<string, List<Actor>> GatherBuildings( Player player ) public Cache<string, List<Actor>> GatherBuildings( Player player )
{ {
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() ); var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.unitInfo is BuildingInfo ) ) foreach( var b in Game.world.Actors.Where( x => x.Owner == player && x.Info is BuildingInfo ) )
ret[ b.unitInfo.Name ].Add( b ); ret[ b.Info.Name ].Add( b );
return ret; return ret;
} }

View File

@@ -10,7 +10,7 @@ namespace OpenRa.Game.GameRules
concrete = 4, concrete = 4,
} }
public class UnitInfo public class UnitInfo : ActorInfo
{ {
public readonly string Name; public readonly string Name;

View File

@@ -116,7 +116,7 @@ namespace OpenRa.Game.Graphics
lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c); lineRenderer.DrawLine(xy + new float2(0, -2), xy + new float2(0, -4), c, c);
lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c); lineRenderer.DrawLine(Xy + new float2(0, -2), Xy + new float2(0, -4), c, c);
var healthAmount = (float)selectedUnit.Health / selectedUnit.unitInfo.Strength; var healthAmount = (float)selectedUnit.Health / selectedUnit.Info.Strength;
var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red var healthColor = (healthAmount < Rules.General.ConditionRed) ? Color.Red
: (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow : (healthAmount < Rules.General.ConditionYellow) ? Color.Yellow
: Color.LimeGreen; : Color.LimeGreen;

View File

@@ -80,6 +80,7 @@
<Compile Include="Chat.cs" /> <Compile Include="Chat.cs" />
<Compile Include="Chrome.cs" /> <Compile Include="Chrome.cs" />
<Compile Include="Exts.cs" /> <Compile Include="Exts.cs" />
<Compile Include="GameRules\ActorInfo.cs" />
<Compile Include="GameRules\GeneralInfo.cs" /> <Compile Include="GameRules\GeneralInfo.cs" />
<Compile Include="GameRules\TechTree.cs" /> <Compile Include="GameRules\TechTree.cs" />
<Compile Include="GameRules\VoiceInfo.cs" /> <Compile Include="GameRules\VoiceInfo.cs" />

View File

@@ -40,7 +40,7 @@ namespace OpenRa.Game
{ {
if (voicedUnit == null) return; if (voicedUnit == null) return;
var mi = voicedUnit.unitInfo as MobileInfo; var mi = voicedUnit.Info as MobileInfo;
if (mi == null) return; if (mi == null) return;
var vi = Rules.VoiceInfo[mi.Voice]; var vi = Rules.VoiceInfo[mi.Voice];

View File

@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits
Game.world.AddFrameEndTask( Game.world.AddFrameEndTask(
w => w =>
{ /* create the free harvester! */ { /* create the free harvester! */
var harvester = new Actor("harv", self.Location + new int2(1, 2), self.Owner); var harvester = new Actor(Rules.UnitInfo["harv"], self.Location + new int2(1, 2), self.Owner);
var unit = harvester.traits.Get<Unit>(); var unit = harvester.traits.Get<Unit>();
var mobile = harvester.traits.Get<Mobile>(); var mobile = harvester.traits.Get<Mobile>();
unit.Facing = 64; unit.Facing = 64;

View File

@@ -11,7 +11,7 @@ namespace OpenRa.Game.Traits.Activities
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
Game.world.Remove( self ); Game.world.Remove( self );
Game.world.Add( new Actor( "fact", self.Location - new int2( 1, 1 ), self.Owner ) ); Game.world.Add( new Actor( Rules.UnitInfo["fact"], self.Location - new int2( 1, 1 ), self.Owner ) );
} ); } );
return null; return null;
} }

View File

@@ -180,7 +180,7 @@ namespace OpenRa.Game.Traits.Activities
var oldFraction = moveFraction; var oldFraction = moveFraction;
var oldTotal = moveFractionTotal; var oldTotal = moveFractionTotal;
moveFraction += ( self.unitInfo as MobileInfo ).Speed; moveFraction += ( self.Info as MobileInfo ).Speed;
UpdateCenterLocation( self, mobile ); UpdateCenterLocation( self, mobile );
if( moveFraction >= moveFractionTotal ) if( moveFraction >= moveFractionTotal )
{ {

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits.Activities
if( desiredFacing == unit.Facing ) if( desiredFacing == unit.Facing )
return NextActivity; return NextActivity;
Util.TickFacing( ref unit.Facing, desiredFacing, self.unitInfo.ROT ); Util.TickFacing( ref unit.Facing, desiredFacing, self.Info.ROT );
return null; return null;
} }

View File

@@ -39,18 +39,18 @@ namespace OpenRa.Game.Traits
{ {
var unit = self.traits.Get<Unit>(); var unit = self.traits.Get<Unit>();
if (self.unitInfo.Primary != null && CheckFire(self, unit, self.unitInfo.Primary, ref primaryFireDelay, if (self.Info.Primary != null && CheckFire(self, unit, self.Info.Primary, ref primaryFireDelay,
self.unitInfo.PrimaryOffset)) self.Info.PrimaryOffset))
{ {
secondaryFireDelay = Math.Max(4, secondaryFireDelay); secondaryFireDelay = Math.Max(4, secondaryFireDelay);
primaryRecoil = 1; primaryRecoil = 1;
return; return;
} }
if (self.unitInfo.Secondary != null && CheckFire(self, unit, self.unitInfo.Secondary, ref secondaryFireDelay, if (self.Info.Secondary != null && CheckFire(self, unit, self.Info.Secondary, ref secondaryFireDelay,
self.unitInfo.SecondaryOffset ?? self.unitInfo.PrimaryOffset)) self.Info.SecondaryOffset ?? self.Info.PrimaryOffset))
{ {
if (self.unitInfo.SecondaryOffset != null) secondaryRecoil = 1; if (self.Info.SecondaryOffset != null) secondaryRecoil = 1;
else primaryRecoil = 1; else primaryRecoil = 1;
return; return;
} }
@@ -91,7 +91,7 @@ namespace OpenRa.Game.Traits
{ {
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
/* todo: choose the appropriate weapon, when only one works against this target */ /* todo: choose the appropriate weapon, when only one works against this target */
var weapon = order.Subject.unitInfo.Primary ?? order.Subject.unitInfo.Secondary; var weapon = order.Subject.Info.Primary ?? order.Subject.Info.Secondary;
self.QueueActivity(new Traits.Activities.Attack(order.TargetActor, self.QueueActivity(new Traits.Activities.Attack(order.TargetActor,
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance))); Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));

View File

@@ -24,7 +24,7 @@ namespace OpenRa.Game.Traits
{ {
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */ const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
/* todo: choose the appropriate weapon, when only one works against this target */ /* todo: choose the appropriate weapon, when only one works against this target */
var weapon = order.Subject.unitInfo.Primary ?? order.Subject.unitInfo.Secondary; var weapon = order.Subject.Info.Primary ?? order.Subject.Info.Secondary;
self.QueueActivity( new Traits.Activities.Follow( order.TargetActor, self.QueueActivity( new Traits.Activities.Follow( order.TargetActor,
Math.Max( 0, (int)Rules.WeaponInfo[ weapon ].Range - RangeTolerance ) ) ); Math.Max( 0, (int)Rules.WeaponInfo[ weapon ].Range - RangeTolerance ) ) );

View File

@@ -8,7 +8,7 @@ namespace OpenRa.Game.Traits
public Building(Actor self) public Building(Actor self)
{ {
unitInfo = (BuildingInfo)self.unitInfo; unitInfo = (BuildingInfo)self.Info;
} }
bool first = true; bool first = true;

View File

@@ -47,10 +47,10 @@ namespace OpenRa.Game.Traits
var dist = Game.CellSize * (targetLocation + new float2(.5f,.5f)) - self.CenterLocation; var dist = Game.CellSize * (targetLocation + new float2(.5f,.5f)) - self.CenterLocation;
var desiredFacing = Util.GetFacing(dist, unit.Facing); var desiredFacing = Util.GetFacing(dist, unit.Facing);
Util.TickFacing(ref unit.Facing, desiredFacing, Util.TickFacing(ref unit.Facing, desiredFacing,
self.unitInfo.ROT); self.Info.ROT);
// .6f going the wrong way; .8f going sideways, 1f going forward. // .6f going the wrong way; .8f going sideways, 1f going forward.
var rawSpeed = .2f * (self.unitInfo as VehicleInfo).Speed; var rawSpeed = .2f * (self.Info as VehicleInfo).Speed;
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI; var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
var scale = .4f + .6f * (float)Math.Cos(angle); var scale = .4f + .6f * (float)Math.Cos(angle);

View File

@@ -19,9 +19,9 @@ namespace OpenRa.Game.Traits
public InfantrySquad(Actor self) public InfantrySquad(Actor self)
{ {
var ii = (InfantryInfo)self.unitInfo; var ii = (InfantryInfo)self.Info;
for (int i = 0; i < ii.SquadSize; i++) for (int i = 0; i < ii.SquadSize; i++)
elements.Add(new Soldier(self.unitInfo.Name, elements.Add(new Soldier(self.Info.Name,
self.CenterLocation.ToInt2() + elementOffsets[ii.SquadSize][i])); self.CenterLocation.ToInt2() + elementOffsets[ii.SquadSize][i]));
} }

View File

@@ -52,12 +52,12 @@ namespace OpenRa.Game.Traits
public UnitMovementType GetMovementType() public UnitMovementType GetMovementType()
{ {
switch( Rules.UnitCategory[ self.unitInfo.Name ] ) switch( Rules.UnitCategory[ self.Info.Name ] )
{ {
case "Infantry": case "Infantry":
return UnitMovementType.Foot; return UnitMovementType.Foot;
case "Vehicle": case "Vehicle":
return ( self.unitInfo as VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel; return ( self.Info as VehicleInfo ).Tracked ? UnitMovementType.Track : UnitMovementType.Wheel;
case "Ship": case "Ship":
return UnitMovementType.Float; return UnitMovementType.Float;
case "Plane": case "Plane":

View File

@@ -13,7 +13,7 @@ namespace OpenRa.Game.Traits
public virtual int CreationFacing( Actor self, Actor newUnit ) public virtual int CreationFacing( Actor self, Actor newUnit )
{ {
return newUnit.unitInfo.InitialFacing; return newUnit.Info.InitialFacing;
} }
public bool Produce( Actor self, UnitInfo producee ) public bool Produce( Actor self, UnitInfo producee )
@@ -22,7 +22,7 @@ namespace OpenRa.Game.Traits
if( location == null || Game.UnitInfluence.GetUnitAt( location.Value ) != null ) if( location == null || Game.UnitInfluence.GetUnitAt( location.Value ) != null )
return false; return false;
var newUnit = new Actor( producee.Name, location.Value, self.Owner ); var newUnit = new Actor( producee, location.Value, self.Owner );
newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ;
var rp = self.traits.GetOrDefault<RallyPoint>(); var rp = self.traits.GetOrDefault<RallyPoint>();
@@ -37,7 +37,7 @@ namespace OpenRa.Game.Traits
heli.targetLocation = rp.rallyPoint; // TODO: make Activity.Move work for helis. heli.targetLocation = rp.rallyPoint; // TODO: make Activity.Move work for helis.
} }
var bi = self.unitInfo as BuildingInfo; var bi = self.Info as BuildingInfo;
if (bi != null && bi.SpawnOffset != null) if (bi != null && bi.SpawnOffset != null)
newUnit.CenterLocation = self.CenterLocation newUnit.CenterLocation = self.CenterLocation
+ new float2(bi.SpawnOffset[0], bi.SpawnOffset[1]); + new float2(bi.SpawnOffset[0], bi.SpawnOffset[1]);

View File

@@ -16,7 +16,7 @@ namespace OpenRa.Game.Traits
{ {
this.self = self; this.self = self;
roof = new Animation(self.unitInfo.Image ?? self.unitInfo.Name); roof = new Animation(self.Info.Image ?? self.Info.Name);
Make( () => Make( () =>
{ {
doneBuilding = true; doneBuilding = true;

View File

@@ -9,7 +9,7 @@ namespace OpenRa.Game.Traits
public RenderSimple(Actor self) public RenderSimple(Actor self)
{ {
anim = new Animation(self.unitInfo.Image ?? self.unitInfo.Name); anim = new Animation(self.Info.Image ?? self.Info.Name);
} }
public abstract IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); public abstract IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self);

View File

@@ -12,9 +12,9 @@ namespace OpenRa.Game.Traits
public RenderUnitMuzzleFlash(Actor self) public RenderUnitMuzzleFlash(Actor self)
: base(self) : base(self)
{ {
if (!self.unitInfo.MuzzleFlash) throw new InvalidOperationException("wtf??"); if (!self.Info.MuzzleFlash) throw new InvalidOperationException("wtf??");
muzzleFlash = new Animation(self.unitInfo.Name); muzzleFlash = new Animation(self.Info.Name);
muzzleFlash.PlayFetchIndex("muzzle", muzzleFlash.PlayFetchIndex("muzzle",
() => () =>
{ {
@@ -37,8 +37,8 @@ namespace OpenRa.Game.Traits
if (attack.primaryRecoil > 0) if (attack.primaryRecoil > 0)
return base.Render(self).Concat(new[] {Util.Centered(self, return base.Render(self).Concat(new[] {Util.Centered(self,
muzzleFlash.Image, self.CenterLocation + new float2( muzzleFlash.Image, self.CenterLocation + new float2(
self.unitInfo.PrimaryOffset.ElementAtOrDefault(2), self.Info.PrimaryOffset.ElementAtOrDefault(2),
self.unitInfo.PrimaryOffset.ElementAtOrDefault(3)))}); self.Info.PrimaryOffset.ElementAtOrDefault(3)))});
else else
return base.Render(self); return base.Render(self);
} }

View File

@@ -10,13 +10,13 @@ namespace OpenRa.Game.Traits
public RenderUnitRotor( Actor self ) public RenderUnitRotor( Actor self )
: base(self) : base(self)
{ {
rotorAnim = new Animation(self.unitInfo.Name); rotorAnim = new Animation(self.Info.Name);
rotorAnim.PlayRepeating("rotor"); rotorAnim.PlayRepeating("rotor");
if (self.unitInfo.SecondaryAnim != null) if (self.Info.SecondaryAnim != null)
{ {
secondRotorAnim = new Animation(self.unitInfo.Name); secondRotorAnim = new Animation(self.Info.Name);
secondRotorAnim.PlayRepeating(self.unitInfo.SecondaryAnim); secondRotorAnim.PlayRepeating(self.Info.SecondaryAnim);
} }
} }
@@ -26,20 +26,20 @@ namespace OpenRa.Game.Traits
yield return Util.CenteredShadow(self, anim.Image, self.CenterLocation); yield return Util.CenteredShadow(self, anim.Image, self.CenterLocation);
yield return Util.CenteredShadow(self, rotorAnim.Image, self.CenterLocation yield return Util.CenteredShadow(self, rotorAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.PrimaryOffset, 0)); + Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, 0));
if (self.unitInfo.SecondaryOffset != null) if (self.Info.SecondaryOffset != null)
yield return Util.CenteredShadow(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation yield return Util.CenteredShadow(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.SecondaryOffset, 0)); + Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, 0));
var heli = self.traits.Get<Helicopter>(); var heli = self.traits.Get<Helicopter>();
var p = self.CenterLocation - new float2( 0, heli.altitude ); var p = self.CenterLocation - new float2( 0, heli.altitude );
yield return Util.Centered(self, anim.Image, p); yield return Util.Centered(self, anim.Image, p);
yield return Util.Centered(self, rotorAnim.Image, p yield return Util.Centered(self, rotorAnim.Image, p
+ Util.GetTurretPosition( self, unit, self.unitInfo.PrimaryOffset, 0 ) ); + Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, 0 ) );
if (self.unitInfo.SecondaryOffset != null) if (self.Info.SecondaryOffset != null)
yield return Util.Centered(self, (secondRotorAnim ?? rotorAnim).Image, p yield return Util.Centered(self, (secondRotorAnim ?? rotorAnim).Image, p
+ Util.GetTurretPosition( self, unit, self.unitInfo.SecondaryOffset, 0 ) ); + Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, 0 ) );
} }
public override void Tick(Actor self) public override void Tick(Actor self)

View File

@@ -10,7 +10,7 @@ namespace OpenRa.Game.Traits
public RenderUnitSpinner( Actor self ) public RenderUnitSpinner( Actor self )
: base(self) : base(self)
{ {
spinnerAnim = new Animation( self.unitInfo.Name ); spinnerAnim = new Animation( self.Info.Name );
spinnerAnim.PlayRepeating( "spinner" ); spinnerAnim.PlayRepeating( "spinner" );
} }
@@ -20,7 +20,7 @@ namespace OpenRa.Game.Traits
yield return Util.Centered(self, anim.Image, self.CenterLocation); yield return Util.Centered(self, anim.Image, self.CenterLocation);
yield return Util.Centered( self, spinnerAnim.Image, self.CenterLocation yield return Util.Centered( self, spinnerAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.PrimaryOffset, 0)); + Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, 0));
} }
public override void Tick(Actor self) public override void Tick(Actor self)

View File

@@ -13,12 +13,12 @@ namespace OpenRa.Game.Traits
: base(self) : base(self)
{ {
self.traits.Get<Turreted>(); self.traits.Get<Turreted>();
turretAnim = new Animation(self.unitInfo.Name); turretAnim = new Animation(self.Info.Name);
if (self.unitInfo.MuzzleFlash) if (self.Info.MuzzleFlash)
{ {
var attack = self.traits.WithInterface<AttackBase>().First(); var attack = self.traits.WithInterface<AttackBase>().First();
muzzleFlash = new Animation(self.unitInfo.Name); muzzleFlash = new Animation(self.Info.Name);
muzzleFlash.PlayFetchIndex("muzzle", muzzleFlash.PlayFetchIndex("muzzle",
() => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6 + (int)(attack.primaryRecoil * 5.9f)); () => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6 + (int)(attack.primaryRecoil * 5.9f));
/* hack: recoil can be 1.0f, but don't overflow into next anim */ /* hack: recoil can be 1.0f, but don't overflow into next anim */
@@ -35,14 +35,14 @@ namespace OpenRa.Game.Traits
yield return Util.Centered(self, anim.Image, self.CenterLocation); yield return Util.Centered(self, anim.Image, self.CenterLocation);
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.PrimaryOffset, attack.primaryRecoil)); + Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil));
if (self.unitInfo.SecondaryOffset != null) if (self.Info.SecondaryOffset != null)
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.SecondaryOffset, attack.secondaryRecoil)); + Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil));
if (muzzleFlash != null && attack.primaryRecoil > 0) if (muzzleFlash != null && attack.primaryRecoil > 0)
yield return Util.Centered(self, muzzleFlash.Image, self.CenterLocation yield return Util.Centered(self, muzzleFlash.Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.unitInfo.PrimaryOffset, attack.primaryRecoil)); + Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil));
} }
public override void Tick(Actor self) public override void Tick(Actor self)

View File

@@ -8,13 +8,13 @@ namespace OpenRa.Game.Traits
public Turreted(Actor self) public Turreted(Actor self)
{ {
turretFacing = self.unitInfo.InitialFacing; turretFacing = self.Info.InitialFacing;
} }
public void Tick( Actor self ) public void Tick( Actor self )
{ {
var df = desiredFacing ?? ( self.traits.Contains<Unit>() ? self.traits.Get<Unit>().Facing : turretFacing ); var df = desiredFacing ?? ( self.traits.Contains<Unit>() ? self.traits.Get<Unit>().Facing : turretFacing );
Util.TickFacing( ref turretFacing, df, self.unitInfo.ROT ); Util.TickFacing( ref turretFacing, df, self.Info.ROT );
} }
} }
} }

View File

@@ -73,14 +73,14 @@ namespace OpenRa.Game.Traits
static float2 GetRecoil(Actor self, float recoil) static float2 GetRecoil(Actor self, float recoil)
{ {
if (self.unitInfo.Recoil == 0) return float2.Zero; if (self.Info.Recoil == 0) return float2.Zero;
var rut = self.traits.WithInterface<RenderUnitTurreted>().FirstOrDefault(); var rut = self.traits.WithInterface<RenderUnitTurreted>().FirstOrDefault();
if (rut == null) return float2.Zero; if (rut == null) return float2.Zero;
var facing = self.traits.Get<Turreted>().turretFacing; var facing = self.traits.Get<Turreted>().turretFacing;
var quantizedFacing = QuantizeFacing(facing, rut.turretAnim.CurrentSequence.Length) * (256 / rut.turretAnim.CurrentSequence.Length); var quantizedFacing = QuantizeFacing(facing, rut.turretAnim.CurrentSequence.Length) * (256 / rut.turretAnim.CurrentSequence.Length);
return RotateVectorByFacing(new float2(0, recoil * self.unitInfo.Recoil), quantizedFacing, .7f); return RotateVectorByFacing(new float2(0, recoil * self.Info.Recoil), quantizedFacing, .7f);
} }
public static float2 GetTurretPosition(Actor self, Unit unit, int[] offset, float recoil) public static float2 GetTurretPosition(Actor self, Unit unit, int[] offset, float recoil)

View File

@@ -40,7 +40,7 @@ namespace OpenRa.Game
Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name ); Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name );
Game.world.Add( new Actor( building.Name, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building ), order.Player ) ); Game.world.Add( new Actor( building, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building ), order.Player ) );
if (order.Player == Game.LocalPlayer) if (order.Player == Game.LocalPlayer)
{ {
Sound.Play("placbldg.aud"); Sound.Play("placbldg.aud");