Skip to content

Commit

Permalink
Update for new playtest
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Sep 25, 2017
1 parent 80a18f4 commit 7a2aad4
Show file tree
Hide file tree
Showing 55 changed files with 476 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class GrantConditionByDisguisedActorInfo : ITraitInfo, Requires<DisguiseInfo>
[Desc("Conditions to grant when disguised as specified actor.",
"A dictionary of [actor id]: [condition].")]
public readonly Dictionary<string, string> Conditions = new Dictionary<string, string>();


[GrantedConditionReference]
public IEnumerable<string> LinterConditions { get { return Conditions.Values; } }

public object Create(ActorInitializer init) { return new GrantConditionByDisguisedActor(init.Self, this); }
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/AI/HackyAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CaptureTarget<TInfoType> where TInfoType : class, ITraitInfoInterface
internal CaptureTarget(Actor actor, string orderString)
{
Actor = actor;
Info = actor.Info.TraitInfoOrDefault<TInfoType>();
Info = actor.Info.TraitInfos<TInfoType>().FirstOrDefault();
OrderString = orderString;
}
}
Expand Down
17 changes: 6 additions & 11 deletions OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public sealed class EditorActorBrush : IEditorBrush
readonly EditorActorLayer editorLayer;
readonly EditorViewportControllerWidget editorWidget;
readonly ActorPreviewWidget preview;
readonly CVec locationOffset;
readonly WVec previewOffset;
readonly WVec centerOffset;
readonly PlayerReference owner;
readonly CVec[] footprint;

Expand All @@ -49,10 +48,7 @@ public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo a

var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>();
if (buildingInfo != null)
{
locationOffset = -buildingInfo.LocationOffset();
previewOffset = buildingInfo.CenterOffset(world);
}
centerOffset = buildingInfo.CenterOffset(world);

var td = new TypeDictionary();
td.Add(new FacingInit(facing));
Expand Down Expand Up @@ -91,17 +87,16 @@ public bool HandleMouseInput(MouseInput mi)
return false;
}

var cell = worldRenderer.Viewport.ViewToWorld(mi.Location);
var cell = worldRenderer.Viewport.ViewToWorld(mi.Location - worldRenderer.ScreenPxOffset(centerOffset));
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down)
{
// Check the actor is inside the map
if (!footprint.All(c => world.Map.Tiles.Contains(cell + locationOffset + c)))
if (!footprint.All(c => world.Map.Tiles.Contains(cell + c)))
return true;

var newActorReference = new ActorReference(Actor.Name);
newActorReference.Add(new OwnerInit(owner.Name));

cell += locationOffset;
newActorReference.Add(new LocationInit(cell));

var ios = Actor.TraitInfoOrDefault<IOccupySpaceInfo>();
Expand All @@ -128,8 +123,8 @@ public bool HandleMouseInput(MouseInput mi)

public void Tick()
{
var cell = worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos);
var pos = world.Map.CenterOfCell(cell + locationOffset) + previewOffset;
var cell = worldRenderer.Viewport.ViewToWorld(Viewport.LastMousePos - worldRenderer.ScreenPxOffset(centerOffset));
var pos = world.Map.CenterOfCell(cell) + centerOffset;

var origin = worldRenderer.Viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(pos));

Expand Down
19 changes: 12 additions & 7 deletions OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ public class PlaceBuildingOrderGenerator : IOrderGenerator
readonly string faction;
readonly Sprite buildOk;
readonly Sprite buildBlocked;
readonly Viewport viewport;
readonly WVec centerOffset;
readonly int2 topLeftScreenOffset;
IActorPreview[] preview;

bool initialized;

public PlaceBuildingOrderGenerator(ProductionQueue queue, string name)
public PlaceBuildingOrderGenerator(ProductionQueue queue, string name, WorldRenderer worldRenderer)
{
var world = queue.Actor.World;
this.queue = queue;
viewport = worldRenderer.Viewport;
placeBuildingInfo = queue.Actor.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>();
building = name;

Expand All @@ -53,6 +57,8 @@ public PlaceBuildingOrderGenerator(ProductionQueue queue, string name)

var info = map.Rules.Actors[building];
buildingInfo = info.TraitInfo<BuildingInfo>();
centerOffset = buildingInfo.CenterOffset(world);
topLeftScreenOffset = -worldRenderer.ScreenPxOffset(centerOffset);

var buildableInfo = info.TraitInfo<BuildableInfo>();
var mostLikelyProducer = queue.MostLikelyProducer();
Expand Down Expand Up @@ -100,7 +106,7 @@ IEnumerable<Order> InnerOrder(World world, CPos cell, MouseInput mi)
if (mi.Button == MouseButton.Left)
{
var orderType = "PlaceBuilding";
var topLeft = cell - buildingInfo.LocationOffset();
var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset);

var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
if (plugInfo != null)
Expand Down Expand Up @@ -163,14 +169,13 @@ bool AcceptsPlug(CPos cell, PlugInfo plug)
public IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
{
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
var topLeft = xy - buildingInfo.LocationOffset();
var offset = world.Map.CenterOfCell(topLeft) + buildingInfo.CenterOffset(world);
var topLeft = viewport.ViewToWorld(Viewport.LastMousePos + topLeftScreenOffset);
var centerPosition = world.Map.CenterOfCell(topLeft) + centerOffset;
var rules = world.Map.Rules;

var actorInfo = rules.Actors[building];
foreach (var dec in actorInfo.TraitInfos<IPlaceBuildingDecorationInfo>())
foreach (var r in dec.Render(wr, world, actorInfo, offset))
foreach (var r in dec.Render(wr, world, actorInfo, centerPosition))
yield return r;

var cells = new Dictionary<CPos, CellType>();
Expand Down Expand Up @@ -220,7 +225,7 @@ public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
}

var previewRenderables = preview
.SelectMany(p => p.Render(wr, offset))
.SelectMany(p => p.Render(wr, centerPosition))
.OrderBy(WorldRenderer.RenderableScreenZPositionComparisonKey);

foreach (var r in previewRenderables)
Expand Down
104 changes: 98 additions & 6 deletions OpenRA.Mods.Common/Traits/AttackMove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
*/
#endregion

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Orders;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Traits
Expand All @@ -20,54 +23,143 @@ class AttackMoveInfo : ITraitInfo, Requires<IMoveInfo>
{
[VoiceReference] public readonly string Voice = "Action";

[GrantedConditionReference]
[Desc("The condition to grant to self while scanning for targets during an attack-move.")]
public readonly string AttackMoveScanCondition = null;

[GrantedConditionReference]
[Desc("The condition to grant to self while scanning for targets during an assault-move.")]
public readonly string AssaultMoveScanCondition = null;

public object Create(ActorInitializer init) { return new AttackMove(init.Self, this); }
}

class AttackMove : IResolveOrder, IOrderVoice, INotifyIdle, ISync
class AttackMove : INotifyCreated, ITick, IResolveOrder, IOrderVoice, INotifyIdle, ISync
{
[Sync] public CPos _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : CPos.Zero; } }
public CPos? TargetLocation = null;

readonly IMove move;
readonly AttackMoveInfo info;

ConditionManager conditionManager;
int attackMoveToken = ConditionManager.InvalidConditionToken;
int assaultMoveToken = ConditionManager.InvalidConditionToken;
bool assaultMoving = false;

public AttackMove(Actor self, AttackMoveInfo info)
{
move = self.Trait<IMove>();
this.info = info;
}

void INotifyCreated.Created(Actor self)
{
conditionManager = self.TraitOrDefault<ConditionManager>();
}

void ITick.Tick(Actor self)
{
if (conditionManager == null)
return;

var activity = self.CurrentActivity as AttackMoveActivity;
var attackActive = activity != null && !assaultMoving;
var assaultActive = activity != null && assaultMoving;

if (attackActive && attackMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.AttackMoveScanCondition))
attackMoveToken = conditionManager.GrantCondition(self, info.AttackMoveScanCondition);
else if (!attackActive && attackMoveToken != ConditionManager.InvalidConditionToken)
attackMoveToken = conditionManager.RevokeCondition(self, attackMoveToken);

if (assaultActive && assaultMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.AssaultMoveScanCondition))
assaultMoveToken = conditionManager.GrantCondition(self, info.AssaultMoveScanCondition);
else if (!assaultActive && assaultMoveToken != ConditionManager.InvalidConditionToken)
assaultMoveToken = conditionManager.RevokeCondition(self, assaultMoveToken);
}

public string VoicePhraseForOrder(Actor self, Order order)
{
if (order.OrderString == "AttackMove")
if (order.OrderString == "AttackMove" || order.OrderString == "AssaultMove")
return info.Voice;

return null;
}

void Activate(Actor self)
void Activate(Actor self, bool assaultMove)
{
self.CancelActivity();
assaultMoving = assaultMove;
self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(TargetLocation.Value, 1)));
}

public void TickIdle(Actor self)
{
// This might cause the actor to be stuck if the target location is unreachable
if (TargetLocation.HasValue && self.Location != TargetLocation.Value)
Activate(self);
Activate(self, assaultMoving);
}

public void ResolveOrder(Actor self, Order order)
{
TargetLocation = null;

if (order.OrderString == "AttackMove")
if (order.OrderString == "AttackMove" || order.OrderString == "AssaultMove")
{
TargetLocation = move.NearestMoveableCell(order.TargetLocation);
self.SetTargetLine(Target.FromCell(self.World, TargetLocation.Value), Color.Red);
Activate(self);
Activate(self, order.OrderString == "AssaultMove");
}
}
}

public class AttackMoveOrderGenerator : UnitOrderGenerator
{
readonly TraitPair<AttackMove>[] subjects;
readonly MouseButton expectedButton;

public AttackMoveOrderGenerator(IEnumerable<Actor> subjects, MouseButton button)
{
expectedButton = button;

this.subjects = subjects.SelectMany(a => a.TraitsImplementing<AttackMove>()
.Select(am => new TraitPair<AttackMove>(a, am)))
.ToArray();
}

public override IEnumerable<Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
if (mi.Button != expectedButton)
world.CancelInputMode();

return OrderInner(world, cell, mi);
}

protected virtual IEnumerable<Order> OrderInner(World world, CPos cell, MouseInput mi)
{
if (mi.Button == expectedButton && world.Map.Contains(cell))
{
world.CancelInputMode();

var queued = mi.Modifiers.HasModifier(Modifiers.Shift);
var orderName = mi.Modifiers.HasModifier(Modifiers.Ctrl) ? "AssaultMove" : "AttackMove";
foreach (var s in subjects)
yield return new Order(orderName, s.Actor, queued) { TargetLocation = cell };
}
}

public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
{
if (world.Map.Contains(cell))
return mi.Modifiers.HasModifier(Modifiers.Ctrl) ? "assaultmove" : "attackmove";

return "generic-blocked";
}

public override bool InputOverridesSelection(World world, int2 xy, MouseInput mi)
{
// Custom order generators always override selection
return true;
}
}
}
5 changes: 0 additions & 5 deletions OpenRA.Mods.Common/Traits/Buildings/Building.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public IEnumerable<CPos> PathableTiles(CPos location)
yield return t;
}

public CVec LocationOffset()
{
return new CVec(Dimensions.X / 2, Dimensions.Y > 1 ? (Dimensions.Y + 1) / 2 : 0);
}

public WVec CenterOffset(World w)
{
var off = (w.Map.CenterOfCell(new CPos(Dimensions.X, Dimensions.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,14 @@ public class SupportPowerInstance
public int RemainingTime;
public int TotalTime;
public bool Active { get; private set; }
public bool Disabled { get { return (!prereqsAvailable && !manager.DevMode.AllTech) || !instancesEnabled; } }
public bool Disabled { get { return (!prereqsAvailable && !manager.DevMode.AllTech) || !instancesEnabled || oneShotFired; } }

public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
public bool Ready { get { return Active && RemainingTime == 0; } }

bool instancesEnabled;
bool prereqsAvailable = true;
bool oneShotFired;

public SupportPowerInstance(string key, SupportPowerManager manager)
{
Expand Down Expand Up @@ -249,7 +250,10 @@ public void Activate(Order order)
notifiedCharging = notifiedReady = false;

if (Info.OneShot)
{
PrerequisitesAvailable(false);
oneShotFired = true;
}
}
}

Expand Down
13 changes: 10 additions & 3 deletions OpenRA.Mods.Common/UtilityCommands/ExtractWeaponDocsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ void IUtilityCommand.Run(Utility utility, string[] args)

var toc = new StringBuilder();
var doc = new StringBuilder();

var currentNamespace = "";

var objectCreator = utility.ModData.ObjectCreator;
var weaponInfo = objectCreator.GetTypesImplementing<WeaponInfo>();
var warheads = objectCreator.GetTypesImplementing<IWarhead>().OrderBy(t => t.Namespace);
var projectiles = objectCreator.GetTypesImplementing<IProjectileInfo>().OrderBy(t => t.Namespace);

var weaponTypes = Enumerable.Concat(weaponInfo, Enumerable.Concat(projectiles, warheads));
foreach (var t in weaponTypes)
{
// skip helpers like TraitInfo<T>
if (t.ContainsGenericParameters || t.IsAbstract)
continue; // skip helpers like TraitInfo<T>
continue;

if (currentNamespace != t.Namespace)
{
Expand All @@ -63,10 +66,11 @@ void IUtilityCommand.Run(Utility utility, string[] args)
}

var traitName = t.Name.EndsWith("Info") ? t.Name.Substring(0, t.Name.Length - 4) : t.Name;
toc.AppendLine(" * [{0}](#{1})".F(traitName, traitName.ToLowerInvariant()));
var traitDescLines = t.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
toc.AppendLine(" * [{0}](#{1})".F(traitName, traitName.ToLowerInvariant()));
doc.AppendLine();
doc.AppendLine("### {0}".F(traitName));

var traitDescLines = t.GetCustomAttributes<DescAttribute>(false).SelectMany(d => d.Lines);
foreach (var line in traitDescLines)
doc.AppendLine(line);

Expand All @@ -76,6 +80,7 @@ void IUtilityCommand.Run(Utility utility, string[] args)

doc.AppendLine("<table>");
doc.AppendLine("<tr><th>Property</th><th>Default Value</th><th>Type</th><th>Description</th></tr>");

var liveTraitInfo = t == typeof(WeaponInfo) ? null : objectCreator.CreateBasic(t);
foreach (var info in infos)
{
Expand All @@ -84,8 +89,10 @@ void IUtilityCommand.Run(Utility utility, string[] args)
var defaultValue = liveTraitInfo == null ? "" : FieldSaver.SaveField(liveTraitInfo, info.Field.Name).Value.Value;
doc.Append("<tr><td>{0}</td><td>{1}</td><td>{2}</td>".F(info.YamlName, defaultValue, fieldType));
doc.Append("<td>");

foreach (var line in fieldDescLines)
doc.Append(line + " ");

doc.AppendLine("</td></tr>");
}

Expand Down
Loading

0 comments on commit 7a2aad4

Please sign in to comment.