Added Cancel() to Mobile.CurrentAction. Added QueueAction to Mobile. Made Order.Apply use queue rather than SetNextAction.

This commit is contained in:
Bob
2009-10-24 19:17:13 +13:00
parent d66475edcb
commit d25bd8550a
4 changed files with 156 additions and 118 deletions

View File

@@ -5,9 +5,9 @@ using OpenRa.TechTree;
using System.Drawing;
using System.Linq;
using IrrKlang;
using IjwFramework.Collections;
using System;
using IjwFramework.Types;
using IjwFramework.Collections;
using System;
using IjwFramework.Types;
using OpenRa.Game.Traits;
namespace OpenRa.Game
@@ -16,7 +16,7 @@ namespace OpenRa.Game
{
public static readonly int CellSize = 24;
public static World world;
public static World world;
public static Map map;
static TreeCache treeCache;
public static TerrainRenderer terrain;
@@ -40,8 +40,8 @@ namespace OpenRa.Game
Rules.LoadRules( mapName );
for( int i = 0 ; i < 8 ; i++ )
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
players.Add(i, new Player(i, string.Format("Multi{0}", i), Race.Soviet));
localPlayerIndex = localPlayer;
var mapFile = new IniFile( FileSystem.Open( mapName ) );
@@ -55,8 +55,8 @@ namespace OpenRa.Game
treeCache = new TreeCache(map);
foreach( TreeReference treeReference in map.Trees )
world.Add( new Actor( treeReference, treeCache, map.Offset ) );
world.Add( new Actor( treeReference, treeCache, map.Offset ) );
BuildingInfluence = new BuildingInfluenceMap(world, 8);
LoadMapBuildings( mapFile );
@@ -136,67 +136,69 @@ namespace OpenRa.Game
return map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(umt,
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
static IEnumerable<Actor> FindUnits(float2 a, float2 b)
{
var min = float2.Min(a, b);
var max = float2.Max(a, b);
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
return world.Actors
.Where(x => x.Bounds.IntersectsWith(rect));
}
public static IEnumerable<Actor> FindUnitsInCircle(float2 a, float r)
{
return FindUnits(a - new float2(r, r), a + new float2(r, r))
.Where(x => (x.CenterLocation - a).LengthSquared < r * r);
}
static IEnumerable<Actor> FindUnits(float2 a, float2 b)
{
var min = float2.Min(a, b);
var max = float2.Max(a, b);
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
return world.Actors
.Where(x => x.Bounds.IntersectsWith(rect));
}
public static IEnumerable<Actor> FindUnitsInCircle(float2 a, float r)
{
return FindUnits(a - new float2(r, r), a + new float2(r, r))
.Where(x => (x.CenterLocation - a).LengthSquared < r * r);
}
public static IEnumerable<Actor> SelectUnitsInBox(float2 a, float2 b)
{
{
return FindUnits(a, b).Where(x => x.Owner == LocalPlayer && x.traits.Contains<Traits.Mobile>());
}
public static IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
{
var q = FindUnits(a, a);
return q.Where(x => x.traits.Contains<Traits.Mobile>()).Concat(q).Take(1);
}
public static int GetDistanceToBase(int2 b, Player p)
{
var building = BuildingInfluence.GetNearestBuilding(b);
if (building == null || building.Owner != p)
return int.MaxValue;
return BuildingInfluence.GetDistanceToBuilding(b);
}
public static Random SharedRandom = new Random(); /* for things that require sync */
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
Pair.New(
new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"),
new VoicePool("await1", "ready", "report1", "yessir1"));
public static void BuildUnit(Player player, string name)
{
var producer = world.Actors
.FirstOrDefault(a => a.unitInfo != null && a.unitInfo.Name == "weap" && a.Owner == player);
if (producer == null)
throw new InvalidOperationException("BuildUnit without suitable production structure!");
}
public static IEnumerable<Actor> SelectUnitOrBuilding(float2 a)
{
var q = FindUnits(a, a);
return q.Where(x => x.traits.Contains<Traits.Mobile>()).Concat(q).Take(1);
}
public static int GetDistanceToBase(int2 b, Player p)
{
var building = BuildingInfluence.GetNearestBuilding(b);
if (building == null || building.Owner != p)
return int.MaxValue;
return BuildingInfluence.GetDistanceToBuilding(b);
}
public static Random SharedRandom = new Random(); /* for things that require sync */
public static Random CosmeticRandom = new Random(); /* for things that are just fluff */
public static readonly Pair<VoicePool, VoicePool> SovietVoices =
Pair.New(
new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"),
new VoicePool("await1", "ready", "report1", "yessir1"));
public static void BuildUnit(Player player, string name)
{
var producer = world.Actors
.FirstOrDefault(a => a.unitInfo != null && a.unitInfo.Name == "weap" && 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);
unit.Order(unit.Location + new int2(0, 3)).Apply(false);
world.AddFrameEndTask(_ => world.Add(unit));
// todo: make the producing building play `build`
}
var mobile = unit.traits.Get<Mobile>();
mobile.facing = 128;
mobile.SetNextAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
world.AddFrameEndTask(_ => world.Add(unit));
// todo: make the producing building play `build`
}
}
}