Files
OpenRA/OpenRA.Mods.Common/Activities/Air/DeliverBulkOrder.cs
let5sne.win10 9cf6ebb986
Some checks failed
Continuous Integration / Linux (.NET 8.0) (push) Has been cancelled
Continuous Integration / Windows (.NET 8.0) (push) Has been cancelled
Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:46:54 +08:00

119 lines
3.4 KiB
C#

#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
public class DeliverBulkOrder : Activity
{
readonly Actor producer;
readonly List<(ActorInfo Actor, int Resources, int Cash)> orderedActors;
readonly string productionType;
readonly BulkProductionQueue queue;
readonly Cargo cargo;
int delayBetweenUnloads = 0;
public DeliverBulkOrder(Actor transport, Actor producer, List<(ActorInfo Actor, int Resources, int Cash)> orderedActors,
string productionType, BulkProductionQueue queue)
{
this.producer = producer;
this.orderedActors = orderedActors;
this.productionType = productionType;
this.queue = queue;
cargo = transport.Trait<Cargo>();
}
protected override void OnFirstRun(Actor self)
{
var landingOffset = producer.Info.TraitInfo<ProductionBulkAirdropInfo>().LandOffset;
QueueChild(new Land(self, Target.FromActor(producer), WDist.FromCells(0), landingOffset));
if (cargo.Info.BeforeUnloadDelay > 0)
QueueChild(new Wait(cargo.Info.BeforeUnloadDelay));
}
protected override void OnLastRun(Actor self)
{
if (!producer.IsDead || producer.IsInWorld)
foreach (var cargo in producer.TraitsImplementing<INotifyDelivery>())
cargo.Delivered(producer);
if (cargo.Info.AfterUnloadDelay > 0)
Queue(new Wait(cargo.Info.AfterUnloadDelay));
Queue(new FlyOffMap(self, Target.FromCell(self.World, self.World.Map.ChooseClosestEdgeCell(self.Location))));
Queue(new RemoveSelf());
}
protected override void OnActorDispose(Actor self)
{
queue.DeliverFinished();
}
public override bool Tick(Actor self)
{
if (!producer.IsInWorld || producer.IsDead)
{
// Try to find another ProductionBulkAirDrop
var newProducer = self.World.ActorsHavingTrait<ProductionBulkAirdrop>()
.Where(a => a.Owner == self.Owner)
.ClosestToIgnoringPath(self);
if (newProducer != null)
{
Cancel(self);
Queue(new DeliverBulkOrder(self, newProducer, orderedActors, productionType, queue));
return true;
}
else
{
queue.DeliverFinished();
return true;
}
}
if (orderedActors == null || orderedActors.Count == 0)
{
queue.DeliverFinished();
return true;
}
var actor = orderedActors[^1];
var productionTrait = producer.Trait<ProductionBulkAirdrop>();
var exit = productionTrait.PublicExit(producer, actor.Actor, productionType);
if (exit == null)
return false;
if (delayBetweenUnloads > 0)
{
delayBetweenUnloads--;
return false;
}
delayBetweenUnloads = cargo.Info.BetweenUnloadDelay;
producer.World.AddFrameEndTask(ww =>
{
var inits = new TypeDictionary
{
new OwnerInit(self.Owner),
new FactionInit(BuildableInfo.GetInitialFaction(actor.Actor, producer.Trait<ProductionBulkAirdrop>().Faction))
};
productionTrait.DoProduction(producer, actor.Actor, exit?.Info, productionType, inits);
orderedActors.Remove(actor);
});
return false;
}
}
}