Merge pull request #11361 from abcdefg30/newLua
Add new lua functions and fix the air attacks in allies05a
This commit is contained in:
@@ -196,6 +196,7 @@
|
||||
<Compile Include="Lint\LintExts.cs" />
|
||||
<Compile Include="LoadScreens\ModChooserLoadScreen.cs" />
|
||||
<Compile Include="ActorInitializer.cs" />
|
||||
<Compile Include="Scripting\Properties\AmmoPoolProperties.cs" />
|
||||
<Compile Include="ShroudExts.cs" />
|
||||
<Compile Include="Orders\BeaconOrderGenerator.cs" />
|
||||
<Compile Include="Orders\DeployOrderTargeter.cs" />
|
||||
|
||||
@@ -46,5 +46,19 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
else
|
||||
Self.QueueActivity(new HeliReturnToBase(Self));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Queues a landing activity on the specififed actor.")]
|
||||
public void Land(Actor landOn)
|
||||
{
|
||||
Self.QueueActivity(new Land(Self, Target.FromActor(landOn)));
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
[Desc("Starts the resupplying activity when being on a host building.")]
|
||||
public void Resupply()
|
||||
{
|
||||
Self.QueueActivity(new ResupplyAircraft(Self));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2016 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Scripting;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
[ScriptPropertyGroup("AmmoPool")]
|
||||
public class AmmoPoolProperties : ScriptActorProperties, Requires<AmmoPoolInfo>
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly AmmoPool[] ammoPools;
|
||||
|
||||
public AmmoPoolProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
this.self = self;
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
|
||||
}
|
||||
|
||||
[Desc("Returns the count of the actor's specified ammopool.")]
|
||||
public int AmmoCount(string poolName = "primary")
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
|
||||
return pool.GetAmmoCount();
|
||||
}
|
||||
|
||||
[Desc("Returns the maximum count of ammo the actor can load.")]
|
||||
public int MaximumAmmoCount(string poolName = "primary")
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
|
||||
return pool.Info.Ammo;
|
||||
}
|
||||
|
||||
[Desc("Adds the specified amount of ammo to the specified ammopool.",
|
||||
"(Use a negative amount to remove ammo.)")]
|
||||
public void Reload(string poolName = "primary", int amount = 1)
|
||||
{
|
||||
var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName);
|
||||
if (pool == null)
|
||||
throw new LuaException("Invalid ammopool name {0} queried on actor {1}.".F(poolName, self));
|
||||
|
||||
if (amount > 0)
|
||||
{
|
||||
while (amount-- > 0)
|
||||
if (!pool.GiveAmmo())
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (amount++ < 0)
|
||||
if (!pool.TakeAmmo())
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,11 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
|
||||
{
|
||||
readonly IMove move;
|
||||
readonly AttackBase attackBase;
|
||||
|
||||
public CombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
move = self.Trait<IMove>();
|
||||
attackBase = self.Trait<AttackBase>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
@@ -75,6 +73,18 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
using (var f = func.CopyReference() as LuaFunction)
|
||||
Self.QueueActivity(new CallFunc(() => PatrolUntil(waypoints, f, wait)));
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Combat")]
|
||||
public class GeneralCombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>
|
||||
{
|
||||
readonly AttackBase attackBase;
|
||||
|
||||
public GeneralCombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
attackBase = self.Trait<AttackBase>();
|
||||
}
|
||||
|
||||
[Desc("Attack the target actor. The target actor needs to be visible.")]
|
||||
public void Attack(Actor targetActor, bool allowMove = true, bool forceAttack = false)
|
||||
|
||||
@@ -243,25 +243,31 @@ ProduceAircraft = function()
|
||||
end
|
||||
|
||||
ussr.Build(SovietAircraftType, function(units)
|
||||
Yaks[#Yaks + 1] = units[1]
|
||||
local yak = units[1]
|
||||
Yaks[#Yaks + 1] = yak
|
||||
|
||||
if #Yaks == 2 then
|
||||
Trigger.OnKilled(units[1], ProduceAircraft)
|
||||
else
|
||||
Trigger.OnKilled(yak, ProduceAircraft)
|
||||
if #Yaks == 1 then
|
||||
Trigger.AfterDelay(DateTime.Minutes(1), ProduceAircraft)
|
||||
end
|
||||
|
||||
local target = nil
|
||||
Trigger.OnIdle(units[1], function()
|
||||
Trigger.OnIdle(yak, function()
|
||||
if not target or target.IsDead or (not target.IsInWorld) then
|
||||
|
||||
local enemies = Utils.Where(Map.ActorsInWorld, function(self) return self.Owner == greece and self.HasProperty("Health") end)
|
||||
if #enemies > 0 then
|
||||
target = Utils.Random(enemies)
|
||||
units[1].Attack(target)
|
||||
else
|
||||
yak.Wait(DateTime.Seconds(5))
|
||||
end
|
||||
end
|
||||
|
||||
if target and yak.AmmoCount() > 0 then
|
||||
yak.Attack(target)
|
||||
else
|
||||
units[1].Attack(target)
|
||||
yak.ReturnToBase()
|
||||
yak.Resupply()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
@@ -276,7 +282,7 @@ ActivateAI = function()
|
||||
Trigger.AfterDelay(DateTime.Minutes(5), function()
|
||||
ProduceInfantry()
|
||||
ProduceVehicles()
|
||||
if false and AirAttacks then -- disable air strikes for now since they are broken
|
||||
if AirAttacks then
|
||||
Trigger.AfterDelay(DateTime.Minutes(3), ProduceAircraft)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user