boat spawn works now
This commit is contained in:
@@ -8,7 +8,8 @@ using IrrKlang;
|
|||||||
using IjwFramework.Collections;
|
using IjwFramework.Collections;
|
||||||
using System;
|
using System;
|
||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
using OpenRa.Game.Traits;
|
using OpenRa.Game.Traits;
|
||||||
|
using OpenRa.Game.GameRules;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -185,8 +186,22 @@ namespace OpenRa.Game
|
|||||||
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
|
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
|
||||||
Pair.New(
|
Pair.New(
|
||||||
new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"),
|
new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"),
|
||||||
new VoicePool("await1", "ready", "report1", "yessir1"));
|
new VoicePool("await1", "ready", "report1", "yessir1"));
|
||||||
|
|
||||||
|
static int2? FindAdjacentTile(Actor a, UnitMovementType umt)
|
||||||
|
{
|
||||||
|
var tiles = Footprint.Tiles(a);
|
||||||
|
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
||||||
|
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
|
||||||
|
|
||||||
|
for (var j = min.Y; j <= max.Y; j++)
|
||||||
|
for (var i = min.X; i <= max.X; i++)
|
||||||
|
if (IsCellBuildable(new int2(i, j), umt))
|
||||||
|
return new int2(i, j);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static void BuildUnit(Player player, string name)
|
public static void BuildUnit(Player player, string name)
|
||||||
{
|
{
|
||||||
var producerTypes = Rules.UnitInfo[name].BuiltAt;
|
var producerTypes = Rules.UnitInfo[name].BuiltAt;
|
||||||
@@ -195,12 +210,29 @@ namespace OpenRa.Game
|
|||||||
&& producerTypes.Contains(a.unitInfo.Name) && a.Owner == player);
|
&& producerTypes.Contains(a.unitInfo.Name) && a.Owner == player);
|
||||||
|
|
||||||
if (producer == null)
|
if (producer == null)
|
||||||
throw new InvalidOperationException("BuildUnit without suitable production structure!");
|
throw new InvalidOperationException("BuildUnit without suitable production structure!");
|
||||||
|
|
||||||
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
|
Actor unit;
|
||||||
var mobile = unit.traits.Get<Mobile>();
|
|
||||||
mobile.facing = 128;
|
if (producerTypes.Contains("spen") || producerTypes.Contains("syrd"))
|
||||||
mobile.QueueActivity( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
|
{
|
||||||
|
var space = FindAdjacentTile(producer, Rules.UnitInfo[name].WaterBound ?
|
||||||
|
UnitMovementType.Float : UnitMovementType.Wheel ); /* hackety hack */
|
||||||
|
|
||||||
|
if (space == null)
|
||||||
|
throw new NotImplementedException("Nowhere to place this unit.");
|
||||||
|
|
||||||
|
unit = new Actor(name, space.Value, player);
|
||||||
|
var mobile = unit.traits.Get<Mobile>();
|
||||||
|
mobile.facing = SharedRandom.Next(256);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unit = new Actor(name, (1 / 24f * producer.CenterLocation).ToInt2(), player);
|
||||||
|
var mobile = unit.traits.Get<Mobile>();
|
||||||
|
mobile.facing = 128;
|
||||||
|
mobile.QueueActivity(new Traits.Mobile.MoveTo(unit.Location + new int2(0, 3)));
|
||||||
|
}
|
||||||
|
|
||||||
world.AddFrameEndTask(_ => world.Add(unit));
|
world.AddFrameEndTask(_ => world.Add(unit));
|
||||||
|
|
||||||
|
|||||||
@@ -10,25 +10,38 @@ namespace OpenRa.Game.GameRules
|
|||||||
static class Footprint
|
static class Footprint
|
||||||
{
|
{
|
||||||
public static IEnumerable<int2> Tiles( UnitInfo unitInfo, int2 position )
|
public static IEnumerable<int2> Tiles( UnitInfo unitInfo, int2 position )
|
||||||
|
{
|
||||||
|
return Tiles(unitInfo, position, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<int2> Tiles(UnitInfo unitInfo, int2 position, bool adjustForPlacement)
|
||||||
{
|
{
|
||||||
var buildingInfo = unitInfo as UnitInfo.BuildingInfo;
|
var buildingInfo = unitInfo as UnitInfo.BuildingInfo;
|
||||||
var dim = buildingInfo.Dimensions;
|
var dim = buildingInfo.Dimensions;
|
||||||
|
|
||||||
var footprint = buildingInfo.Footprint.ToCharArray().Where( x => !char.IsWhiteSpace( x ) );
|
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
|
||||||
if( buildingInfo.Bib )
|
if (buildingInfo.Bib)
|
||||||
{
|
{
|
||||||
dim.Y += 1;
|
dim.Y += 1;
|
||||||
footprint = footprint.Concat( new char[ dim.X ] );
|
footprint = footprint.Concat(new char[dim.X]);
|
||||||
}
|
}
|
||||||
foreach( var tile in TilesWhere( unitInfo.Name, dim, footprint.ToArray(), a => a != '_' ) )
|
|
||||||
yield return tile + position - AdjustForBuildingSize( buildingInfo );
|
var adjustment = adjustForPlacement ? AdjustForBuildingSize(buildingInfo) : int2.Zero;
|
||||||
|
|
||||||
|
var tiles = TilesWhere(unitInfo.Name, dim, footprint.ToArray(), a => a != '_');
|
||||||
|
return tiles.Select(t => t + position - adjustment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<int2> Tiles(Actor a)
|
||||||
|
{
|
||||||
|
return Tiles(a.unitInfo, a.Location, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<int2> UnpathableTiles( UnitInfo unitInfo, int2 position )
|
public static IEnumerable<int2> UnpathableTiles( UnitInfo unitInfo, int2 position )
|
||||||
{
|
{
|
||||||
var buildingInfo = unitInfo as UnitInfo.BuildingInfo;
|
var buildingInfo = unitInfo as UnitInfo.BuildingInfo;
|
||||||
|
|
||||||
var footprint = buildingInfo.Footprint.ToCharArray().Where( x => !char.IsWhiteSpace( x ) ).ToArray();
|
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
|
||||||
foreach( var tile in TilesWhere( unitInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
|
foreach( var tile in TilesWhere( unitInfo.Name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
|
||||||
yield return tile + position;
|
yield return tile + position;
|
||||||
}
|
}
|
||||||
@@ -38,15 +51,14 @@ namespace OpenRa.Game.GameRules
|
|||||||
if( footprint.Length != dim.X * dim.Y )
|
if( footprint.Length != dim.X * dim.Y )
|
||||||
throw new InvalidOperationException( "Invalid footprint for " + name );
|
throw new InvalidOperationException( "Invalid footprint for " + name );
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for( int y = 0 ; y < dim.Y ; y++ )
|
for( int y = 0 ; y < dim.Y ; y++ )
|
||||||
{
|
|
||||||
for( int x = 0 ; x < dim.X ; x++ )
|
for( int x = 0 ; x < dim.X ; x++ )
|
||||||
{
|
{
|
||||||
if( cond( footprint[ index ] ) )
|
if( cond( footprint[ index ] ) )
|
||||||
yield return new int2( x, y );
|
yield return new int2( x, y );
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int2 AdjustForBuildingSize( string name )
|
public static int2 AdjustForBuildingSize( string name )
|
||||||
|
|||||||
Reference in New Issue
Block a user