boat spawn works now

This commit is contained in:
Chris Forbes
2009-10-26 23:05:26 +13:00
parent 65f7f8c145
commit 612490e5b8
2 changed files with 61 additions and 17 deletions

View File

@@ -8,7 +8,8 @@ using IrrKlang;
using IjwFramework.Collections;
using System;
using IjwFramework.Types;
using OpenRa.Game.Traits;
using OpenRa.Game.Traits;
using OpenRa.Game.GameRules;
namespace OpenRa.Game
{
@@ -185,8 +186,22 @@ namespace OpenRa.Game
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
Pair.New(
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)
{
var producerTypes = Rules.UnitInfo[name].BuiltAt;
@@ -195,12 +210,29 @@ namespace OpenRa.Game
&& producerTypes.Contains(a.unitInfo.Name) && a.Owner == player);
if (producer == null)
throw new InvalidOperationException("BuildUnit without suitable production structure!");
var 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 ) ) );
throw new InvalidOperationException("BuildUnit without suitable production structure!");
Actor unit;
if (producerTypes.Contains("spen") || producerTypes.Contains("syrd"))
{
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));