some progress on Repair

This commit is contained in:
Alli
2010-01-02 13:45:06 +13:00
parent d2be508523
commit 7a32619b9b
6 changed files with 108 additions and 0 deletions

View File

@@ -184,6 +184,8 @@ namespace OpenRa.Game
case "PlaceBuilding": return Cursor.Default; case "PlaceBuilding": return Cursor.Default;
case "Sell": return Cursor.Sell; case "Sell": return Cursor.Sell;
case "NoSell": return Cursor.SellBlocked; case "NoSell": return Cursor.SellBlocked;
case "Repair": return Cursor.Repair;
case "NoRepair": return Cursor.RepairBlocked;
default: default:
return null; return null;
} }

View File

@@ -28,5 +28,7 @@ namespace OpenRa.Game
public static Cursor Heal { get { return new Cursor("heal"); } } public static Cursor Heal { get { return new Cursor("heal"); } }
public static Cursor Sell { get { return new Cursor("sell"); } } public static Cursor Sell { get { return new Cursor("sell"); } }
public static Cursor SellBlocked { get { return new Cursor("sell-blocked"); } } public static Cursor SellBlocked { get { return new Cursor("sell-blocked"); } }
public static Cursor Repair { get { return new Cursor("repair"); } }
public static Cursor RepairBlocked { get { return new Cursor("repair-blocked"); } }
} }
} }

View File

@@ -135,6 +135,8 @@ namespace OpenRa.Game
Game.LocalPlayer = Game.players[(Game.LocalPlayer.Index + 1) % 4]; Game.LocalPlayer = Game.players[(Game.LocalPlayer.Index + 1) % 4];
if (e.KeyCode == Keys.F3) if (e.KeyCode == Keys.F3)
Game.controller.orderGenerator = new SellOrderGenerator(); Game.controller.orderGenerator = new SellOrderGenerator();
if (e.KeyCode == Keys.F4)
Game.controller.orderGenerator = new RepairOrderGenerator();
if (!Game.chat.isChatting) if (!Game.chat.isChatting)
if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)

View File

@@ -99,6 +99,7 @@
<Compile Include="Orders\NetworkOrderSource.cs" /> <Compile Include="Orders\NetworkOrderSource.cs" />
<Compile Include="Orders\OrderIO.cs" /> <Compile Include="Orders\OrderIO.cs" />
<Compile Include="Orders\OrderManager.cs" /> <Compile Include="Orders\OrderManager.cs" />
<Compile Include="Orders\RepairOrderGenerator.cs" />
<Compile Include="Orders\SellOrderGenerator.cs" /> <Compile Include="Orders\SellOrderGenerator.cs" />
<Compile Include="Ore.cs" /> <Compile Include="Ore.cs" />
<Compile Include="PathSearch.cs" /> <Compile Include="PathSearch.cs" />

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Orders
{
class RepairOrderGenerator : IOrderGenerator
{
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
{
if (!mi.IsFake && mi.Button == MouseButton.Right)
{
Game.controller.CancelInputMode();
yield break;
}
var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault();
var building = underCursor != null ? underCursor.Info as BuildingInfo : null;
if (building == null || !building.Repairable)
{
yield return new Order("NoRepair", Game.LocalPlayer.PlayerActor, null, int2.Zero, null);
yield break;
}
yield return new Order("Repair", underCursor, null, int2.Zero, null);
}
public void Tick() {}
public void Render() {}
}
}

View File

@@ -0,0 +1,60 @@
using System.Collections.Generic;
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
namespace OpenRa.Game
{
class RepairBuilding : IOrderGenerator
{
readonly Actor Producer;
readonly BuildingInfo Building;
public RepairBuilding(Actor producer, string name)
{
Producer = producer;
Building = (BuildingInfo)Rules.UnitInfo[name];
}
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
var actorBuilding = Game.FindUnits(xy.ToFloat2(), xy.ToFloat2())
.FirstOrDefault(a => a.traits.Contains<RenderBuilding>());
yield return new Order("RepairBuilding", Producer.Owner.PlayerActor, null, xy, Building.Name);
}
else // rmb
{
Game.world.AddFrameEndTask(_ => { Game.controller.orderGenerator = null; });
}
}
public void Tick()
{
//var producing = Producer.traits.Get<Traits.ProductionQueue>().CurrentItem(Rules.UnitCategory[Building.Name]);
//if (producing == null || producing.Item != Building.Name || producing.RemainingTime != 0)
//Game.world.AddFrameEndTask(_ => { Game.controller.orderGenerator = null; });
//const int ticksPerPoint = 15;
//const int hpPerPoint = 8;
//int remainingTicks = ticksPerPoint;
// if (--remainingTicks == 0)
// {
// self.Health += hpPerPoint;
// if (self.Health >= self.Info.Strength)
// {
// self.Health = self.Info.Strength;
// return NextActivity;
// }
}
public void Render()
{
//Game.worldRenderer.uiOverlay.DrawBuildingGrid(Building);
}
}
}