Restructuring orders.

This commit is contained in:
Bob
2009-10-28 22:06:39 +13:00
parent 5d1ae1cb2a
commit c0cb248bc1
14 changed files with 632 additions and 621 deletions

View File

@@ -4,24 +4,33 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using IjwFramework.Types;
using System.Drawing;
using System.Drawing;
using OpenRa.Game.Traits;
namespace OpenRa.Game
{
class Controller
{
public IOrderGenerator orderGenerator;
void ApplyOrders(float2 xy, bool left)
{
var doVoice = true;
if (orderGenerator != null)
foreach (var order in orderGenerator.Order(xy.ToInt2(), left))
{
order.Apply(doVoice);
doVoice = false;
}
public IOrderGenerator orderGenerator;
void ApplyOrders(float2 xy, bool left)
{
var doVoice = null as Actor;
if (orderGenerator != null)
foreach( var order in orderGenerator.Order( xy.ToInt2(), left ) )
{
UnitOrders.ProcessOrder( order );
if( order.Subject != null && order.Player == Game.LocalPlayer )
doVoice = order.Subject;
}
if( doVoice != null )
Game.PlaySound( Game.SovietVoices.First.GetNext() + GetVoiceSuffix( doVoice ), false );
}
static string GetVoiceSuffix( Actor unit )
{
var suffixes = new[] { ".r01", ".r03" };
return suffixes[ unit.traits.Get<Traits.Mobile>().Voice ];
}
float2 dragStart, dragEnd;
@@ -32,7 +41,7 @@ namespace OpenRa.Game
if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down)
{
if (!(orderGenerator is PlaceBuilding))
dragStart = dragEnd = xy;
dragStart = dragEnd = xy;
ApplyOrders(xy, true);
}
@@ -59,9 +68,9 @@ namespace OpenRa.Game
/* update the cursor to reflect the thing under us - note this
* needs to also happen when the *thing* changes, so per-frame hook */
dragStart = dragEnd = xy;
}
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
}
if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down)
ApplyOrders(xy, false);
}
@@ -84,10 +93,10 @@ namespace OpenRa.Game
if (uog != null && uog.selection.Count > 0
&& uog.selection.Any(a => a.traits.Contains<Traits.Mobile>())
&& uog.selection.All( a => a.Owner == Game.LocalPlayer ))
{
var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
.Where(m => m != null)
.Select(m => m.GetMovementType())
{
var umts = uog.selection.Select(a => a.traits.GetOrDefault<Mobile>())
.Where(m => m != null)
.Select(m => m.GetMovementType())
.Distinct();
if (!umts.Any( umt => Game.IsCellBuildable( dragEnd.ToInt2(), umt ) ))