Add unit guarding
This commit is contained in:
@@ -151,6 +151,7 @@ namespace OpenRA.GameRules
|
|||||||
public string ScatterKey = "x";
|
public string ScatterKey = "x";
|
||||||
public string DeployKey = "f";
|
public string DeployKey = "f";
|
||||||
public string StanceCycleKey = "z";
|
public string StanceCycleKey = "z";
|
||||||
|
public string GuardKey = "d";
|
||||||
|
|
||||||
public string CycleTabsKey = "tab";
|
public string CycleTabsKey = "tab";
|
||||||
}
|
}
|
||||||
|
|||||||
98
OpenRA.Mods.RA/Guard.cs
Normal file
98
OpenRA.Mods.RA/Guard.cs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
class GuardInfo : TraitInfo<Guard>, Requires<MobileInfo> { }
|
||||||
|
|
||||||
|
class Guard : IResolveOrder, IOrderVoice
|
||||||
|
{
|
||||||
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
if (order.OrderString == "Guard")
|
||||||
|
{
|
||||||
|
var target = Target.FromActor(order.TargetActor);
|
||||||
|
self.SetTargetLine(target, Color.Yellow);
|
||||||
|
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self,
|
||||||
|
new Follow(target, target.Actor.Info.Traits.Get<GuardableInfo>().Range)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
{
|
||||||
|
return order.OrderString == "Guard" ? "Move" : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GuardOrderGenerator : IOrderGenerator
|
||||||
|
{
|
||||||
|
readonly IEnumerable<Actor> subjects;
|
||||||
|
|
||||||
|
public GuardOrderGenerator(IEnumerable<Actor> subjects)
|
||||||
|
{
|
||||||
|
this.subjects = subjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
|
||||||
|
{
|
||||||
|
if (mi.Button == Game.mouseButtonPreference.Cancel)
|
||||||
|
{
|
||||||
|
world.CancelInputMode();
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var target = FriendlyGuardableUnitsAtMouse(world, mi).FirstOrDefault();
|
||||||
|
|
||||||
|
if (target == null || subjects.All(s => s.IsDead()))
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
foreach (var actor in subjects)
|
||||||
|
yield return new Order("Guard", actor, false) { TargetActor = target };
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(World world)
|
||||||
|
{
|
||||||
|
if (subjects.All(s => s.IsDead() || !s.HasTrait<Guard>()))
|
||||||
|
world.CancelInputMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenderBeforeWorld(WorldRenderer wr, World world) { }
|
||||||
|
public void RenderAfterWorld(WorldRenderer wr, World world) { }
|
||||||
|
|
||||||
|
public string GetCursor(World world, CPos xy, MouseInput mi)
|
||||||
|
{
|
||||||
|
return world.Map.IsInMap(xy)
|
||||||
|
&& FriendlyGuardableUnitsAtMouse(world, mi).Any()
|
||||||
|
? "guard"
|
||||||
|
: "move-blocked";
|
||||||
|
}
|
||||||
|
|
||||||
|
static IEnumerable<Actor> FriendlyGuardableUnitsAtMouse(World world, MouseInput mi)
|
||||||
|
{
|
||||||
|
return world.FindUnitsAtMouse(mi.Location)
|
||||||
|
.Where(a => !a.IsDead() && a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && a.HasTrait<Guardable>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GuardableInfo : TraitInfo<Guardable>
|
||||||
|
{
|
||||||
|
public readonly int Range = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Guardable { }
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
@@ -229,6 +229,7 @@
|
|||||||
<Compile Include="GainsExperience.cs" />
|
<Compile Include="GainsExperience.cs" />
|
||||||
<Compile Include="GivesBounty.cs" />
|
<Compile Include="GivesBounty.cs" />
|
||||||
<Compile Include="GivesExperience.cs" />
|
<Compile Include="GivesExperience.cs" />
|
||||||
|
<Compile Include="Guard.cs" />
|
||||||
<Compile Include="Harvester.cs" />
|
<Compile Include="Harvester.cs" />
|
||||||
<Compile Include="HarvesterHuskModifier.cs" />
|
<Compile Include="HarvesterHuskModifier.cs" />
|
||||||
<Compile Include="Husk.cs" />
|
<Compile Include="Husk.cs" />
|
||||||
|
|||||||
@@ -208,6 +208,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
|
SetupKeyBinding(deployKey, "Deploy:", () => keyConfig.DeployKey, k => keyConfig.DeployKey = k);
|
||||||
unitCommandHotkeyList.AddChild(deployKey);
|
unitCommandHotkeyList.AddChild(deployKey);
|
||||||
|
|
||||||
|
var guardKey = ScrollItemWidget.Setup(unitCommandHotkeyTemplate, () => false, () => { });
|
||||||
|
SetupKeyBinding(guardKey, "Guard: ", () => keyConfig.GuardKey, k => keyConfig.GuardKey = k);
|
||||||
|
unitCommandHotkeyList.AddChild(guardKey);
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
var debug = bg.Get("DEBUG_PANE");
|
var debug = bg.Get("DEBUG_PANE");
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
if (e.KeyName == Game.Settings.Keys.StanceCycleKey)
|
if (e.KeyName == Game.Settings.Keys.StanceCycleKey)
|
||||||
return PerformStanceCycle();
|
return PerformStanceCycle();
|
||||||
|
|
||||||
|
if (e.KeyName == Game.Settings.Keys.GuardKey)
|
||||||
|
return PerformGuard();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -79,12 +82,11 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
bool PerformAttackMove()
|
bool PerformAttackMove()
|
||||||
{
|
{
|
||||||
var actors = World.Selection.Actors
|
var actors = World.Selection.Actors.Where(a => a.Owner == World.LocalPlayer).ToArray();
|
||||||
.Where(a => a.Owner == World.LocalPlayer).ToArray();
|
|
||||||
|
|
||||||
if (actors.Length > 0)
|
if (actors.Any())
|
||||||
World.OrderGenerator = new GenericSelectTarget(actors, "AttackMove",
|
World.OrderGenerator = new GenericSelectTarget(actors,
|
||||||
"attackmove", Game.mouseButtonPreference.Action);
|
"AttackMove", "attackmove", Game.mouseButtonPreference.Action);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -146,6 +148,16 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PerformGuard()
|
||||||
|
{
|
||||||
|
var actors = World.Selection.Actors.Where(a => a.Owner == World.LocalPlayer && a.HasTrait<Guard>());
|
||||||
|
|
||||||
|
if (actors.Any())
|
||||||
|
World.OrderGenerator = new GuardOrderGenerator(actors);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CycleBases()
|
bool CycleBases()
|
||||||
{
|
{
|
||||||
var bases = World.ActorsWithTrait<BaseBuilding>()
|
var bases = World.ActorsWithTrait<BaseBuilding>()
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
AcceptsCloakCrate:
|
AcceptsCloakCrate:
|
||||||
WithSmoke:
|
WithSmoke:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -68,6 +70,8 @@
|
|||||||
Weapon: UnitExplodeSmall
|
Weapon: UnitExplodeSmall
|
||||||
EmptyWeapon: UnitExplodeSmall
|
EmptyWeapon: UnitExplodeSmall
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Helicopter:
|
^Helicopter:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -145,6 +149,8 @@
|
|||||||
Buildings: hosp
|
Buildings: hosp
|
||||||
CloseEnough: 1
|
CloseEnough: 1
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^CivInfantry:
|
^CivInfantry:
|
||||||
Inherits: ^Infantry
|
Inherits: ^Infantry
|
||||||
@@ -176,7 +182,7 @@
|
|||||||
Notification: CivilianKilled
|
Notification: CivilianKilled
|
||||||
NotifyAll: true
|
NotifyAll: true
|
||||||
ScaredyCat:
|
ScaredyCat:
|
||||||
RenderInfantryPanic:
|
RenderInfantryPanic:
|
||||||
AttackMove:
|
AttackMove:
|
||||||
JustMove: yes
|
JustMove: yes
|
||||||
CrushableInfantry:
|
CrushableInfantry:
|
||||||
@@ -214,6 +220,8 @@
|
|||||||
ActorLostNotification:
|
ActorLostNotification:
|
||||||
AttackMove:
|
AttackMove:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Building:
|
^Building:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -260,6 +268,8 @@
|
|||||||
Capturable:
|
Capturable:
|
||||||
CapturableBar:
|
CapturableBar:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guardable:
|
||||||
|
Range: 3
|
||||||
|
|
||||||
^CivBuilding:
|
^CivBuilding:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
@@ -347,6 +357,7 @@
|
|||||||
RelativeToTopLeft: yes
|
RelativeToTopLeft: yes
|
||||||
AutoTargetIgnore:
|
AutoTargetIgnore:
|
||||||
Sellable:
|
Sellable:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Tree:
|
^Tree:
|
||||||
Tooltip:
|
Tooltip:
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
Repairable:
|
Repairable:
|
||||||
RepairBuildings: repair
|
RepairBuildings: repair
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -65,6 +67,8 @@
|
|||||||
Repairable:
|
Repairable:
|
||||||
RepairBuildings: repair
|
RepairBuildings: repair
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Husk:
|
^Husk:
|
||||||
Health:
|
Health:
|
||||||
@@ -145,6 +149,8 @@
|
|||||||
Buildings: barra, barro
|
Buildings: barra, barro
|
||||||
CloseEnough: 1
|
CloseEnough: 1
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -200,7 +206,6 @@
|
|||||||
ActorTypes: rifle,rifle,rifle,rifle,rifle,bazooka,bazooka,bazooka,engineer
|
ActorTypes: rifle,rifle,rifle,rifle,rifle,bazooka,bazooka,bazooka,engineer
|
||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
GivesExperience:
|
GivesExperience:
|
||||||
|
|
||||||
FrozenUnderFog:
|
FrozenUnderFog:
|
||||||
CaptureNotification:
|
CaptureNotification:
|
||||||
ActorLostNotification:
|
ActorLostNotification:
|
||||||
@@ -215,3 +220,5 @@
|
|||||||
GivesBounty:
|
GivesBounty:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
Bib:
|
Bib:
|
||||||
|
Guardable:
|
||||||
|
Range: 3
|
||||||
|
|||||||
@@ -371,6 +371,7 @@ WALL:
|
|||||||
ProximityCaptor:
|
ProximityCaptor:
|
||||||
Types:Wall
|
Types:Wall
|
||||||
Sellable:
|
Sellable:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
GUNTOWER:
|
GUNTOWER:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
WithSmoke:
|
WithSmoke:
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -71,6 +73,8 @@
|
|||||||
WithSmoke:
|
WithSmoke:
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Infantry:
|
^Infantry:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -122,6 +126,8 @@
|
|||||||
CloseEnough: 1
|
CloseEnough: 1
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Ship:
|
^Ship:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -151,6 +157,8 @@
|
|||||||
WithSmoke:
|
WithSmoke:
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guard:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -224,6 +232,8 @@
|
|||||||
GivesBounty:
|
GivesBounty:
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
DebugMuzzlePositions:
|
DebugMuzzlePositions:
|
||||||
|
Guardable:
|
||||||
|
Range: 3
|
||||||
|
|
||||||
^Wall:
|
^Wall:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -257,6 +267,7 @@
|
|||||||
Types:Wall
|
Types:Wall
|
||||||
Sellable:
|
Sellable:
|
||||||
UpdatesPlayerStatistics:
|
UpdatesPlayerStatistics:
|
||||||
|
Guardable:
|
||||||
|
|
||||||
^TechBuilding:
|
^TechBuilding:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
|
|||||||
Reference in New Issue
Block a user