Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add production support to Lua API, port gdi04a, gdi04b and intervention missions #6762

Merged
merged 6 commits into from
Oct 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenRA.Mods.RA/OpenRA.Mods.RA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
<Compile Include="Warheads\PerCellDamageWarhead.cs" />
<Compile Include="Warheads\SpreadDamageWarhead.cs" />
<Compile Include="Scripting\Global\ReinforcementsGlobal.cs" />
<Compile Include="Scripting\Global\DateGlobal.cs" />
<Compile Include="Scripting\Global\DateTimeGlobal.cs" />
<Compile Include="Scripting\Properties\HarvesterProperties.cs" />
<Compile Include="Scripting\Properties\HelicopterProperties.cs" />
<Compile Include="Scripting\Properties\PlaneProperties.cs" />
Expand Down Expand Up @@ -586,4 +586,4 @@ copy "FuzzyLogicLibrary.dll" "$(SolutionDir)"
cd "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<ItemGroup />
</Project>
</Project>
2 changes: 1 addition & 1 deletion OpenRA.Mods.RA/Player/ClassicProductionQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace OpenRA.Mods.RA
{
[Desc("Attach this to the world actor (not a building!) to define a new shared build queue.",
[Desc("Attach this to the player actor (not a building!) to define a new shared build queue.",
"Will only work together with the Production: trait on the actor that actually does the production.",
"You will also want to add PrimaryBuildings: to let the user choose where new units should exit.")]
public class ClassicProductionQueueInfo : ProductionQueueInfo, Requires<TechTreeInfo>, Requires<PowerManagerInfo>, Requires<PlayerResourcesInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ namespace OpenRA.Mods.RA.Scripting
[ScriptGlobal("Date")]
public class DateGlobal : ScriptGlobal
{
public DateGlobal(ScriptContext context) : base(context) { }
public DateGlobal(ScriptContext context)
: base(context) { }

[Desc("True on the 31st of October.")]
public bool IsHalloween
{
get { return DateTime.Today.Month == 10 && DateTime.Today.Day == 31; }
}
}

[ScriptGlobal("Time")]
public class TimeGlobal : ScriptGlobal
{
public TimeGlobal(ScriptContext context)
: base(context) { }

[Desc("Get the current game time (in ticks)")]
public int GameTime
{
get { return context.World.WorldTick; }
}
}
}
2 changes: 1 addition & 1 deletion OpenRA.Mods.RA/Scripting/Global/TriggerGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TriggerGlobal : ScriptGlobal
{
public TriggerGlobal(ScriptContext context) : base(context) { }

static ScriptTriggers GetScriptTriggers(Actor a)
public static ScriptTriggers GetScriptTriggers(Actor a)
{
var events = a.TraitOrDefault<ScriptTriggers>();
if (events == null)
Expand Down
42 changes: 37 additions & 5 deletions OpenRA.Mods.RA/Scripting/Properties/CombatProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/
#endregion

using Eluant;
using System;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Scripting;
using OpenRA.Traits;
Expand All @@ -17,8 +20,13 @@ namespace OpenRA.Mods.RA.Scripting
[ScriptPropertyGroup("Combat")]
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
{
readonly IMove move;

public CombatProperties(ScriptContext context, Actor self)
: base(context, self) { }
: base(context, self)
{
move = self.Trait<IMove>();
}

[ScriptActorPropertyActivity]
[Desc("Seek out and attack nearby targets.")]
Expand All @@ -33,11 +41,35 @@ public void Hunt()
"close enough to complete the activity.")]
public void AttackMove(CPos cell, int closeEnough = 0)
{
var move = self.TraitOrDefault<IMove>();
if (move == null)
return;

self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(cell, closeEnough)));
}

[ScriptActorPropertyActivity]
[Desc("Patrol along a set of given waypoints. The action is repeated by default, " +
"and the actor will wait for `wait` ticks at each waypoint.")]
public void Patrol(CPos[] waypoints, bool loop = true, int wait = 0)
{
foreach (var wpt in waypoints)
{
self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(wpt, 2)));
self.QueueActivity(new Wait(wait));
}

if (loop)
self.QueueActivity(new CallFunc(() => Patrol(waypoints, loop, wait)));
}

[ScriptActorPropertyActivity]
[Desc("Patrol along a set of given waypoints until a condition becomes true. " +
"The actor will wait for `wait` ticks at each waypoint.")]
public void PatrolUntil(CPos[] waypoints, LuaFunction func, int wait = 0)
{
Patrol(waypoints, false, wait);

var repeat = func.Call(self.ToLuaValue(context)).First().ToBoolean();
if (repeat)
using (var f = func.CopyReference() as LuaFunction)
self.QueueActivity(new CallFunc(() => PatrolUntil(waypoints, f, wait)));
}
}
}
31 changes: 31 additions & 0 deletions OpenRA.Mods.RA/Scripting/Properties/HealthProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#endregion

using OpenRA.Mods.RA.Buildings;
using OpenRA.Scripting;
using OpenRA.Traits;

Expand All @@ -33,4 +34,34 @@ public int Health
[Desc("Maximum health of the actor.")]
public int MaxHealth { get { return health.MaxHP; } }
}

[ScriptPropertyGroup("General")]
public class RepairableBuildingProperties : ScriptActorProperties, Requires<RepairableBuildingInfo>
{
readonly RepairableBuilding rb;

public RepairableBuildingProperties(ScriptContext context, Actor self)
: base(context, self)
{
rb = self.Trait<RepairableBuilding>();
}

[Desc("Start repairs on this building. `repairer` can be an allied player.")]
public void StartBuildingRepairs(Player repairer = null)
{
repairer = repairer ?? self.Owner;

if (!rb.Repairers.Contains(repairer))
rb.RepairBuilding(self, repairer);
}

[Desc("Stop repairs on this building. `repairer` can be an allied player.")]
public void StopBuildingRepairs(Player repairer = null)
{
repairer = repairer ?? self.Owner;

if (rb.RepairActive && rb.Repairers.Contains(repairer))
rb.RepairBuilding(self, repairer);
}
}
}
13 changes: 13 additions & 0 deletions OpenRA.Mods.RA/Scripting/Properties/PlaneProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,17 @@ public void Move(CPos cell)
self.QueueActivity(new Fly(self, Target.FromCell(self.World, cell)));
}
}

[ScriptPropertyGroup("Combat")]
public class PlaneCombatProperties : ScriptActorProperties, Requires<AttackPlaneInfo>
{
public PlaneCombatProperties(ScriptContext context, Actor self)
: base(context, self) { }

[Desc("Fly an attack against the target actor.")]
public void Attack(Actor target)
{
self.QueueActivity(new FlyAttack(Target.FromActor(target)));
}
}
}