Skip to content

Commit

Permalink
Allow FreePassenger to spawn multiple actors at once.
Browse files Browse the repository at this point in the history
This doesn't have the location limitations of FreeActor.
  • Loading branch information
MustaphaTR committed Aug 23, 2023
1 parent 8716002 commit 96c46f1
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions OpenRA.Mods.AS/Traits/FreePassenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
*/
#endregion

using System;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.AS.Traits
{
[Desc("Player receives a unit for free as passenger once the trait is enabled.",
"If you want more than one unit to appear copy this section and assign IDs like FreePassener@2, ...")]
[Desc("Player receives listed units for free as passenger once the trait is enabled.")]
public class FreePassengerInfo : ConditionalTraitInfo, Requires<CargoInfo>
{
[ActorReference]
[FieldLoader.Require]
[Desc("Name of the actor.")]
public readonly string Actor = null;
public readonly string[] Actors = Array.Empty<string>();

[Desc("Whether another actor should spawn upon re-enabling the trait.")]
public readonly bool AllowRespawn = false;
Expand Down Expand Up @@ -50,20 +50,23 @@ protected override void TraitEnabled(Actor self)

self.World.AddFrameEndTask(w =>
{
var passenger = self.World.Map.Rules.Actors[Info.Actor].TraitInfoOrDefault<PassengerInfo>();
foreach (var actor in Info.Actors)
{
var passenger = self.World.Map.Rules.Actors[actor].TraitInfoOrDefault<PassengerInfo>();
if (passenger == null || !cargo.Info.Types.Contains(passenger.CargoType) || !cargo.HasSpace(passenger.Weight))
return;
if (passenger == null || !cargo.Info.Types.Contains(passenger.CargoType) || !cargo.HasSpace(passenger.Weight))
return;
var a = w.CreateActor(Info.Actor, new TypeDictionary
{
new ParentActorInit(self),
new LocationInit(self.Location),
new OwnerInit(self.Owner),
});
var a = w.CreateActor(actor, new TypeDictionary
{
new ParentActorInit(self),
new LocationInit(self.Location),
new OwnerInit(self.Owner),
});
w.Remove(a);
cargo.Load(self, a);
w.Remove(a);
cargo.Load(self, a);
}
});
}
}
Expand Down

0 comments on commit 96c46f1

Please sign in to comment.