port allies-02 to new Lua API

This commit is contained in:
Matthias Mailänder
2014-08-31 10:48:22 +02:00
parent 15b358afa5
commit 24732ae635
7 changed files with 202 additions and 75 deletions

View File

@@ -539,6 +539,7 @@
<Compile Include="Scripting\Properties\UpgradeProperties.cs" /> <Compile Include="Scripting\Properties\UpgradeProperties.cs" />
<Compile Include="UpgradeActorsNear.cs" /> <Compile Include="UpgradeActorsNear.cs" />
<Compile Include="WithRangeCircle.cs" /> <Compile Include="WithRangeCircle.cs" />
<Compile Include="Scripting\Properties\TransformProperties.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj"> <ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -171,6 +171,27 @@ namespace OpenRA.Mods.RA.Scripting
GetScriptTriggers(a).RegisterCallback(Trigger.OnRemovedFromWorld, func, context); GetScriptTriggers(a).RegisterCallback(Trigger.OnRemovedFromWorld, func, context);
} }
[Desc("Call a function when all of the actors in a group have been removed from the world. " +
"The callback function will be called as func().")]
public void OnAllRemovedFromWorld(Actor[] actors, LuaFunction func)
{
var group = actors.ToList();
var copy = (LuaFunction)func.CopyReference();
Action<Actor> OnMemberRemoved = m =>
{
group.Remove(m);
if (!group.Any())
{
copy.Call().Dispose();
copy.Dispose();
}
};
foreach (var a in group)
GetScriptTriggers(a).OnRemovedInternal += OnMemberRemoved;
}
[Desc("Call a function when this actor is captured. The callback function " + [Desc("Call a function when this actor is captured. The callback function " +
"will be called as func(Actor self, Actor captor, Player oldOwner, Player newOwner).")] "will be called as func(Actor self, Actor captor, Player oldOwner, Player newOwner).")]
public void OnCapture(Actor a, LuaFunction func) public void OnCapture(Actor a, LuaFunction func)

View File

@@ -0,0 +1,34 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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 OpenRA.Scripting;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Scripting
{
[ScriptPropertyGroup("Transform")]
public class TransformProperties : ScriptActorProperties, Requires<TransformsInfo>
{
readonly Transforms transforms;
public TransformProperties(ScriptContext context, Actor self)
: base(context, self)
{
transforms = self.Trait<Transforms>();
}
[ScriptActorPropertyActivity]
[Desc("Queue a new transformation.")]
public void Deploy()
{
transforms.DeployTransform(true);
}
}
}

View File

@@ -26,7 +26,8 @@ namespace OpenRA.Mods.RA.Scripting
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable
{ {
public event Action<Actor> OnKilledInternal = _ => {}; public event Action<Actor> OnKilledInternal = _ => { };
public event Action<Actor> OnRemovedInternal = _ => { };
public Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>> Triggers = new Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>>(); public Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>> Triggers = new Dictionary<Trigger, List<Pair<LuaFunction, ScriptContext>>>();
@@ -58,7 +59,7 @@ namespace OpenRA.Mods.RA.Scripting
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
// Run lua callbacks // Run Lua callbacks
foreach (var f in Triggers[Trigger.OnKilled]) foreach (var f in Triggers[Trigger.OnKilled])
using (var a = self.ToLuaValue(f.Second)) using (var a = self.ToLuaValue(f.Second))
using (var b = e.Attacker.ToLuaValue(f.Second)) using (var b = e.Attacker.ToLuaValue(f.Second))
@@ -133,9 +134,13 @@ namespace OpenRA.Mods.RA.Scripting
public void RemovedFromWorld(Actor self) public void RemovedFromWorld(Actor self)
{ {
// Run Lua callbacks
foreach (var f in Triggers[Trigger.OnRemovedFromWorld]) foreach (var f in Triggers[Trigger.OnRemovedFromWorld])
using (var a = self.ToLuaValue(f.Second)) using (var a = self.ToLuaValue(f.Second))
f.First.Call(a).Dispose(); f.First.Call(a).Dispose();
// Run any internally bound callbacks
OnRemovedInternal(self);
} }
public void Clear(Trigger trigger) public void Clear(Trigger trigger)

View File

@@ -1,76 +1,132 @@
JeepReinforcements = { "e1", "e1", "e1", "jeep" } ConstructionVehicleReinforcements = { "mcv" }
JeepReinforcementsInterval = 15 ConstructionVehiclePath = { ReinforcementsEntryPoint.Location, DeployPoint.Location }
TruckNames = { "truk", "truk", "truk" }
TruckInterval = 25
TruckDelay = 75
FirstJeepReinforcementsDelay = 125
SecondJeepReinforcementsDelay = 250
SendMcvReinforcements = function() JeepReinforcements = { "e1", "e1", "e1", "jeep" }
Media.PlaySpeechNotification("ReinforcementsArrived") JeepPath = { ReinforcementsEntryPoint.Location, ReinforcementsRallyPoint.Location }
local mcv = Actor.Create("mcv", { Owner = player, Location = ReinforcementsEntryPoint.Location })
Actor.Move(mcv, McvDeployPoint.Location) TruckReinforcements = { "truk", "truk", "truk" }
Actor.DeployTransform(mcv) TruckPath = { TruckEntryPoint.Location, TruckRallyPoint.Location }
SendConstructionVehicleReinforcements = function()
local mcv = Reinforcements.Reinforce(player, ConstructionVehicleReinforcements, ConstructionVehiclePath)[1]
end end
SendJeepReinforcements = function() SendJeepReinforcements = function()
Media.PlaySpeechNotification("ReinforcementsArrived") Media.PlaySpeechNotification(player, "ReinforcementsArrived")
Reinforcements.Reinforce(player, JeepReinforcements, ReinforcementsEntryPoint.Location, ReinforcementsRallyPoint.Location, JeepReinforcementsInterval) Reinforcements.Reinforce(player, JeepReinforcements, JeepPath, Utils.Seconds(1))
end end
RunInitialActivities = function() RunInitialActivities = function()
Actor.Harvest(Harvester) Harvester.FindResources()
end end
MissionAccomplished = function() MissionAccomplished = function()
Mission.MissionOver({ player }, nil, true) Media.PlaySpeechNotification(player, "Win")
Media.PlayMovieFullscreen("montpass.vqa") Trigger.AfterDelay(Utils.Seconds(1), function()
Media.PlayMovieFullscreen("montpass.vqa")
end)
end end
MissionFailed = function() MissionFailed = function()
Mission.MissionOver(nil, { player }, true) Media.PlaySpeechNotification(player, "Lose")
Media.PlayMovieFullscreen("frozen.vqa") Trigger.AfterDelay(Utils.Seconds(1), function()
Media.PlayMovieFullscreen("frozen.vqa")
end)
end end
Tick = function() Tick = function()
Mission.TickTakeOre(ussr) ussr.Resources = ussr.Resources - (0.01 * ussr.ResourceCapacity / 25)
if Mission.RequiredUnitsAreDestroyed(player) then if ukraine.HasNoRequiredUnits() then
MissionFailed()
end
if not trucksSent and Mission.RequiredUnitsAreDestroyed(ussr) and Mission.RequiredUnitsAreDestroyed(badGuy) then
SendTrucks() SendTrucks()
trucksSent = true player.MarkCompletedObjective(ConquestObjective)
end
if player.HasNoRequiredUnits() then
player.MarkFailedObjective(ConquestObjective)
end end
end end
ConvoyOnSite = false
SendTrucks = function() SendTrucks = function()
Media.PlaySpeechNotification("ConvoyApproaching") if not ConvoyOnSite then
OpenRA.RunAfterDelay(TruckDelay, function() ConvoyOnSite = true
local trucks = Reinforcements.Reinforce(france, TruckNames, TruckEntryPoint.Location, TruckRallyPoint.Location, TruckInterval, ConvoyObjective = player.AddPrimaryObjective("Escort the convoy")
function(truck) Media.PlaySpeechNotification(player, "ConvoyApproaching")
Actor.Move(truck, TruckExitPoint.Location) Trigger.AfterDelay(Utils.Seconds(3), function()
Actor.RemoveSelf(truck) ConvoyUnharmed = true
local trucks = Reinforcements.Reinforce(france, TruckReinforcements, TruckPath, Utils.Seconds(1),
function(truck)
Trigger.OnIdle(truck, function() truck.Move(TruckExitPoint.Location) end)
end)
count = 0
Trigger.OnEnteredFootprint( { TruckExitPoint.Location }, function(a, id)
if a.Owner == france then
count = count + 1
a.Destroy()
if count == 3 then
player.MarkCompletedObjective(ConvoyObjective)
Trigger.RemoveFootprintTrigger(id)
end
end
end) end)
local trucksTeam = Team.New(trucks) Trigger.OnAnyKilled(trucks, ConvoyCasualites)
Team.AddEventHandler(trucksTeam.OnAllRemovedFromWorld, MissionAccomplished) end)
Team.AddEventHandler(trucksTeam.OnAnyKilled, MissionFailed) end
end
ConvoyCasualites = function()
Media.PlaySpeechNotification(player, "ConvoyUnitLost")
if ConvoyUnharmed then
ConvoyUnharmed = false
Trigger.AfterDelay(Utils.Seconds(1), function() player.MarkFailedObjective(ConvoyObjective) end)
end
end
ConvoyTimer = function(delay, notification)
Trigger.AfterDelay(delay, function()
if not ConvoyOnSite then
Media.PlaySpeechNotification(player, notification)
end
end) end)
end end
WorldLoaded = function() WorldLoaded = function()
player = OpenRA.GetPlayer("Greece") player = Player.GetPlayer("Greece")
france = OpenRA.GetPlayer("France") france = Player.GetPlayer("France")
ussr = OpenRA.GetPlayer("USSR") ussr = Player.GetPlayer("USSR")
badGuy = OpenRA.GetPlayer("BadGuy") ukraine = Player.GetPlayer("Ukraine")
ConquestObjective = player.AddPrimaryObjective("Secure the area.")
ussr.AddPrimaryObjective("Defend your base.")
ukraine.AddPrimaryObjective("Destroy the convoy.")
RunInitialActivities() RunInitialActivities()
SendMcvReinforcements() SendConstructionVehicleReinforcements()
OpenRA.RunAfterDelay(FirstJeepReinforcementsDelay, SendJeepReinforcements) Trigger.AfterDelay(Utils.Seconds(5), SendJeepReinforcements)
OpenRA.RunAfterDelay(SecondJeepReinforcementsDelay, SendJeepReinforcements) Trigger.AfterDelay(Utils.Seconds(10), SendJeepReinforcements)
OpenRA.SetViewportCenterPosition(ReinforcementsEntryPoint.CenterPosition) Trigger.AfterDelay(Utils.Minutes(10), SendTrucks)
Media.PlayMovieFullscreen("ally2.vqa", function() Media.PlayMovieFullscreen("mcv.vqa", Media.PlayRandomMusic) end) Trigger.OnPlayerLost(player, MissionFailed)
Trigger.OnPlayerWon(player, MissionAccomplished)
Trigger.OnObjectiveCompleted(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective completed")
end)
Trigger.OnObjectiveFailed(player, function(p, id)
Media.DisplayMessage(p.GetObjectiveDescription(id), "Objective failed")
end)
Camera.Position = ReinforcementsEntryPoint.CenterPosition
Media.PlayMovieFullscreen("ally2.vqa", function() Media.PlayMovieFullscreen("mcv.vqa") end)
ConvoyTimer(Utils.Seconds(3), "TenMinutesRemaining")
ConvoyTimer(Utils.Minutes(5), "WarningFiveMinutesRemaining")
ConvoyTimer(Utils.Minutes(6), "WarningFourMinutesRemaining")
ConvoyTimer(Utils.Minutes(7), "WarningThreeMinutesRemaining")
ConvoyTimer(Utils.Minutes(8), "WarningTwoMinutesRemaining")
ConvoyTimer(Utils.Minutes(9), "WarningOneMinuteRemaining")
end end

View File

@@ -6,7 +6,7 @@ RequiresMod: ra
Title: Allies 02: Five to one Title: Allies 02: Five to one
Description: A critical supply convoy is due through this area in 25 minutes, but Soviet forces have blocked the road in several places.\n\nUnless you can clear them out, those supplies will never make it to the front.\n\nThe convoy will come from the northwest, and time is short so work quickly. Description: A critical supply convoy is due through this area in 10 minutes, but Soviet forces have blocked the road in several places.\n\nUnless you can clear them out, those supplies will never make it to the front.\n\nThe convoy will come from the northwest, and time is short so work quickly.
Author: Westwood Studios Author: Westwood Studios
@@ -34,26 +34,26 @@ Players:
Name: USSR Name: USSR
Race: soviet Race: soviet
ColorRamp: 3,255,127 ColorRamp: 3,255,127
Allies: BadGuy Allies: Ukraine
Enemies: Greece Enemies: Greece, France
PlayerReference@France: PlayerReference@France:
Name: France Name: France
Race: allies Race: allies
NonCombatant: True
ColorRamp: 115,115,143 ColorRamp: 115,115,143
Allies: Greece Allies: Greece, France
Enemies: USSR,BadGuy Enemies: USSR, Ukraine
PlayerReference@Neutral: PlayerReference@Neutral:
Name: Neutral Name: Neutral
OwnsWorld: True OwnsWorld: True
NonCombatant: True NonCombatant: True
Race: allies Race: allies
Enemies: Greece PlayerReference@Ukraine:
PlayerReference@BadGuy: Name: Ukraine
Name: BadGuy
Race: soviet Race: soviet
ColorRamp: 3,255,127 ColorRamp: 3,255,127
Allies: USSR Allies: USSR
Enemies: Greece Enemies: Greece, France
PlayerReference@Greece: PlayerReference@Greece:
Name: Greece Name: Greece
Playable: True Playable: True
@@ -66,7 +66,7 @@ Players:
LockSpawn: True LockSpawn: True
LockTeam: True LockTeam: True
Allies: France Allies: France
Enemies: USSR,BadGuy Enemies: USSR, Ukraine
Actors: Actors:
EntryPoint: t06 EntryPoint: t06
@@ -240,7 +240,7 @@ Actors:
Actor56: tc03 Actor56: tc03
Location: 43,70 Location: 43,70
Owner: Neutral Owner: Neutral
Actor57: weap SovietWarfactory: weap
Location: 60,66 Location: 60,66
Owner: USSR Owner: USSR
Health: 1 Health: 1
@@ -480,7 +480,7 @@ Actors:
SubCell: 0 SubCell: 0
Actor103: e1 Actor103: e1
Location: 77,74 Location: 77,74
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 128 Facing: 128
SubCell: 2 SubCell: 2
@@ -612,67 +612,67 @@ Actors:
SubCell: 1 SubCell: 1
Actor125: dog Actor125: dog
Location: 78,75 Location: 78,75
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 160 Facing: 160
SubCell: 1 SubCell: 1
Actor126: e1 Actor126: e1
Location: 71,61 Location: 71,61
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 160 Facing: 160
SubCell: 0 SubCell: 0
Actor127: dog Actor127: dog
Location: 70,61 Location: 70,61
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 96 Facing: 96
SubCell: 4 SubCell: 4
Actor128: e1 Actor128: e1
Location: 50,46 Location: 50,46
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 32 Facing: 32
SubCell: 1 SubCell: 1
Actor129: e1 Actor129: e1
Location: 49,47 Location: 49,47
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 64 Facing: 64
SubCell: 0 SubCell: 0
Actor130: e2 Actor130: e2
Location: 49,49 Location: 49,49
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 160 Facing: 160
SubCell: 1 SubCell: 1
Actor131: e2 Actor131: e2
Location: 47,46 Location: 47,46
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 96 Facing: 96
SubCell: 3 SubCell: 3
Actor132: e2 Actor132: e2
Location: 48,63 Location: 48,63
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 0 Facing: 0
SubCell: 1 SubCell: 1
Actor133: e1 Actor133: e1
Location: 49,63 Location: 49,63
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 96 Facing: 96
SubCell: 2 SubCell: 2
Actor134: e1 Actor134: e1
Location: 74,81 Location: 74,81
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 64 Facing: 64
SubCell: 3 SubCell: 3
Actor135: e2 Actor135: e2
Location: 75,83 Location: 75,83
Owner: BadGuy Owner: Ukraine
Health: 1 Health: 1
Facing: 96 Facing: 96
SubCell: 0 SubCell: 0
@@ -751,7 +751,7 @@ Actors:
waypoint94: waypoint waypoint94: waypoint
Location: 90,46 Location: 90,46
Owner: Neutral Owner: Neutral
McvDeployPoint: waypoint DeployPoint: waypoint
Location: 89,51 Location: 89,51
Owner: Neutral Owner: Neutral
waypoint96: waypoint waypoint96: waypoint
@@ -875,8 +875,8 @@ Rules:
-CrateSpawner: -CrateSpawner:
-SpawnMPUnits: -SpawnMPUnits:
-MPStartLocations: -MPStartLocations:
LuaScriptInterface: LuaScript:
LuaScripts: allies02.lua Scripts: allies02.lua
ObjectivesPanel: ObjectivesPanel:
PanelName: MISSION_OBJECTIVES PanelName: MISSION_OBJECTIVES
^Vehicle: ^Vehicle:

View File

@@ -28,12 +28,22 @@ Speech:
SignalFlareNorth: flaren1 SignalFlareNorth: flaren1
AlliedReinforcementsArrived: aarrive1 AlliedReinforcementsArrived: aarrive1
ConvoyApproaching: convyap1 ConvoyApproaching: convyap1
ConvoyUnitLost: convlst1
TargetFreed: targfre1 TargetFreed: targfre1
TargetRescued: targres1 TargetRescued: targres1
ObjectiveMet: objmet1 ObjectiveMet: objmet1
ObjectiveNotMet: objnmet1 ObjectiveNotMet: objnmet1
ObjectiveReached: objrch1 ObjectiveReached: objrch1
ObjectiveNotReached: objnrch1 ObjectiveNotReached: objnrch1
TenMinutesRemaining: 10minr
TwentyMinutesRemaining: 20minr
ThirtyMinutesRemaining: 30minr
FourtyMinutesRemaining: 40minr
WarningOneMinuteRemaining: 1minr
WarningTwoMinutesRemaining: 2minr
WarningThreeMinutesRemaining: 3minr
WarningFourMinutesRemaining: 4minr
WarningFiveMinutesRemaining: 5minr
Sounds: Sounds:
Notifications: Notifications: