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 Support for dropping Cargo with Parachute from an Aircraft #14276

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Add UnloadWithParachute to Cargo

  • Loading branch information
MustaphaTR committed Oct 30, 2017
commit fdafabf5b1527e99d10a3b7d213df8fab3f9ff39
@@ -0,0 +1,69 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.Common.Activities
{
public class ParadropCargo : Activity
{
readonly bool unloadAll;

public ParadropCargo(bool unloadAll)
{
this.unloadAll = unloadAll;
}

public override Activity Tick(Actor self)
{
var cargo = self.Trait<Cargo>();

This comment has been minimized.

Copy link
@pchote

pchote Nov 15, 2017

Member

Please assign these from the constructor (passing Actor self as a parameter to query from) instead of looking it up ever tick.

var notifiers = self.TraitsImplementing<INotifyUnload>().ToArray();

cargo.Unloading = false;
if (IsCanceled || cargo.IsEmpty(self))
return NextActivity;

foreach (var inu in notifiers)
inu.Unloading(self);

var actor = cargo.Peek(self);
var spawn = self.CenterPosition;

This comment has been minimized.

Copy link
@pchote

pchote Nov 15, 2017

Member

This doesn't appear to check for suitable drop cells...?

This comment has been minimized.

Copy link
@MustaphaTR

MustaphaTR Nov 16, 2017

Author Member

Current checks indeed doesn't seem right, but i'm not sure what exactly to do either, it makes more sense that Cargo -> CanUnload checks this, rather than ParadropCargo activity.

CanUnload already still checking for LandableTerrainTypes. I think this shouldn't be checked for them.


cargo.Unload(self);
self.World.AddFrameEndTask(w =>
{
if (actor.Disposed)
return;

var pos = actor.Trait<IPositionable>();

pos.SetVisualPosition(actor, spawn);

actor.CancelActivity();
actor.QueueActivity(new Parachute(actor, spawn));
w.Add(actor);
});
Game.Sound.Play(SoundType.World, self.Info.TraitInfo<ParaDropInfo>().ChuteSound, spawn);

if (!unloadAll || cargo.IsEmpty(self))
return NextActivity;

cargo.Unloading = true;
return this;
}
}
}
@@ -107,6 +107,7 @@
<Compile Include="Activities\Move\MoveAdjacentTo.cs" />
<Compile Include="Activities\Move\MoveWithinRange.cs" />
<Compile Include="Activities\Parachute.cs" />
<Compile Include="Activities\ParadropCargo.cs" />
<Compile Include="Activities\Rearm.cs" />
<Compile Include="Activities\RemoveSelf.cs" />
<Compile Include="Activities\Repair.cs" />
@@ -40,6 +40,10 @@ public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>
[Desc("When this actor dies should all of its passengers be unloaded?")]
public readonly bool EjectOnDeath = false;

[Desc("If the actor is on air, drop passengers with parachute instead of landing.",
"This requires `ParaDrop` and `Aircraft` traits on actor to work.")]
public readonly bool UnloadWithParachute = false;

[Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")]
public readonly HashSet<string> UnloadTerrainTypes = new HashSet<string>();

@@ -88,6 +92,7 @@ public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCrea
int totalWeight = 0;
int reservedWeight = 0;
Aircraft aircraft;
ParaDrop paradrop;
ConditionManager conditionManager;
int loadingToken = ConditionManager.InvalidConditionToken;
Stack<int> loadedTokens = new Stack<int>();
@@ -141,6 +146,7 @@ public Cargo(ActorInitializer init, CargoInfo info)
void INotifyCreated.Created(Actor self)
{
aircraft = self.TraitOrDefault<Aircraft>();
paradrop = self.TraitOrDefault<ParaDrop>();
conditionManager = self.TraitOrDefault<ConditionManager>();
}

@@ -172,11 +178,23 @@ public void ResolveOrder(Actor self, Order order)
if (!CanUnload())
return;

var inAir = !self.IsAtGroundLevel();

Unloading = true;
self.CancelActivity();
if (aircraft != null)
if (paradrop != null && aircraft != null && Info.UnloadWithParachute && inAir)
{
self.QueueActivity(new ParadropCargo(false));
if (!aircraft.Info.CanHover)
self.QueueActivity(new FlyCircle(self));
}
else if (aircraft != null)
{
self.QueueActivity(new HeliLand(self, true));
self.QueueActivity(new UnloadCargo(self, true));
self.QueueActivity(new UnloadCargo(self, true));
}
else
self.QueueActivity(new UnloadCargo(self, true));
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.