Fixing uses of legacyInfo.WaterBound

This commit is contained in:
Bob
2010-01-12 19:31:06 +13:00
parent 5afedbf001
commit b21e1adc2d
8 changed files with 109 additions and 8 deletions

View File

@@ -68,7 +68,7 @@ namespace OpenRa.Game
if (unit != null && unit.Altitude > 0)
return projectile.AA;
if (projectile.UnderWater && !target.LegacyInfo.WaterBound)
if (projectile.UnderWater && !target.Info.Traits.Get<OwnedActorInfo>().WaterBound)
return false;
return projectile.AG;

View File

@@ -10,6 +10,7 @@ namespace OpenRa.Game.Traits
public readonly int TechLevel = -1;
public readonly string Tab = null;
public readonly string[] Prerequisites = { };
public readonly string[] BuiltAt = { };
public readonly Race[] Owner = { };
public readonly int Cost = 0;
public readonly string Description = "";

View File

@@ -16,6 +16,7 @@ namespace OpenRa.Game.Traits
public readonly bool Crewed = false; // replace with trait?
public readonly int InitialFacing = 128;
public readonly int Sight = 0;
public readonly bool WaterBound = false;
}
class BuildingInfo : OwnedActorInfo, ITraitInfo
@@ -30,7 +31,6 @@ namespace OpenRa.Game.Traits
public readonly string Footprint = "x";
public readonly string[] Produces = { }; // does this go somewhere else?
public readonly int2 Dimensions = new int2(1, 1);
public readonly bool WaterBound = false;
public readonly bool Unsellable = false;
public object Create(Actor self) { return new Building(self); }

View File

@@ -19,7 +19,7 @@ namespace OpenRa.Game.Traits
public Production( Actor self ) { }
public virtual int2? CreationLocation( Actor self, LegacyUnitInfo producee )
public virtual int2? CreationLocation( Actor self, NewUnitInfo producee )
{
return ( 1 / 24f * self.CenterLocation ).ToInt2();
}
@@ -29,7 +29,7 @@ namespace OpenRa.Game.Traits
return newUnit.Info.Traits.GetOrDefault<OwnedActorInfo>().InitialFacing;
}
public bool Produce( Actor self, LegacyUnitInfo producee )
public bool Produce( Actor self, NewUnitInfo producee )
{
var location = CreationLocation( self, producee );
if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() )

View File

@@ -126,7 +126,7 @@ namespace OpenRa.Game.Traits
public void BuildUnit( string name )
{
var newUnitType = Rules.UnitInfo[ name ];
var newUnitType = Rules.NewUnitInfo[ name ];
var producerTypes = Rules.TechTree.UnitBuiltAt( newUnitType );
Actor producer = null;

View File

@@ -26,9 +26,9 @@ namespace OpenRa.Game.Traits
return null;
}
public override int2? CreationLocation(Actor self, LegacyUnitInfo producee)
public override int2? CreationLocation(Actor self, NewUnitInfo producee)
{
return FindAdjacentTile(self, producee.WaterBound ?
return FindAdjacentTile(self, producee.Traits.Get<OwnedActorInfo>().WaterBound ?
UnitMovementType.Float : UnitMovementType.Wheel); /* hackety hack */
}

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Traits
interface IProducer
{
bool Produce( Actor self, LegacyUnitInfo producee );
bool Produce( Actor self, NewUnitInfo producee );
void SetPrimaryProducer(Actor self, bool isPrimary);
}
interface IOccupySpace { IEnumerable<int2> OccupiedCells(); }

100
RulesConverter/MiniYamlExts.cs Executable file
View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.FileFormats;
namespace RulesConverter
{
using MiniYamlNodes = Dictionary<string, MiniYaml>;
using System.IO;
static class MiniYamlExts
{
public static void WriteToFile( this MiniYamlNodes y, string filename )
{
File.WriteAllLines( filename, y.ToLines( true ).ToArray() );
}
public static IEnumerable<string> ToLines( this MiniYamlNodes y, bool lowest )
{
foreach( var kv in y )
{
foreach( var line in kv.Value.ToLines( kv.Key ) )
yield return line;
if( lowest )
yield return "";
}
}
public static IEnumerable<string> ToLines( this MiniYaml y, string name )
{
yield return name + ": " + y.Value;
foreach( var line in y.Nodes.ToLines( false ) )
yield return "\t" + line;
}
public static void OptimizeInherits( this MiniYamlNodes y, MiniYamlNodes baseYaml )
{
foreach( var key in y.Keys.ToList() )
{
var node = y[ key ];
MiniYaml inherits;
node.Nodes.TryGetValue( "Inherits", out inherits );
if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
continue;
MiniYaml parent;
baseYaml.TryGetValue( inherits.Value, out parent );
if( parent == null )
continue;
y[ key ] = Diff( node, parent );
if( y[ key ] == null )
y.Remove( key );
}
}
public static MiniYamlNodes Diff( MiniYamlNodes a, MiniYamlNodes b )
{
if( a.Count == 0 && b.Count == 0 )
return null;
if( b.Count == 0 )
return a;
if( a.Count == 0 )
throw new NotImplementedException( "parent has key not in child" );
var ret = new MiniYamlNodes();
var keys = a.Keys.Union( b.Keys ).ToList();
foreach( var key in keys )
{
MiniYaml aa, bb;
a.TryGetValue( key, out aa );
b.TryGetValue( key, out bb );
var diff = Diff( aa, bb );
if( diff != null )
ret.Add( key, diff );
}
if( ret.Count == 0 ) return null;
return ret;
}
public static MiniYaml Diff( MiniYaml a, MiniYaml b )
{
if( a == null && b == null )
throw new InvalidOperationException( "can't happen" );
else if( a == null )
throw new NotImplementedException( "parent has key not in child" );
else if( b == null )
return a;
var diff = Diff( a.Nodes, b.Nodes );
if( diff == null )
return null;
return new MiniYaml( a.Value, diff );
}
}
}