Initial commit: OpenRA game engine
Some checks failed
Continuous Integration / Linux (.NET 8.0) (push) Has been cancelled
Continuous Integration / Windows (.NET 8.0) (push) Has been cancelled

Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
let5sne.win10
2026-01-10 21:46:54 +08:00
commit 9cf6ebb986
4065 changed files with 635973 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
#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.Linq;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities
{
sealed class Infiltrate : Enter
{
readonly Infiltrates infiltrates;
readonly INotifyInfiltration[] notifiers;
Actor enterActor;
public Infiltrate(Actor self, in Target target, Infiltrates infiltrates, Color? targetLineColor)
: base(self, target, targetLineColor)
{
this.infiltrates = infiltrates;
notifiers = self.TraitsImplementing<INotifyInfiltration>().ToArray();
}
protected override void TickInner(Actor self, in Target target, bool targetIsDeadOrHiddenActor)
{
if (infiltrates.IsTraitDisabled)
Cancel(self, true);
}
protected override bool TryStartEnter(Actor self, Actor targetActor)
{
// Make sure we can still demolish the target before entering
// (but not before, because this may stop the actor in the middle of nowhere)
if (!infiltrates.CanInfiltrateTarget(self, Target.FromActor(targetActor)))
{
Cancel(self, true);
return false;
}
enterActor = targetActor;
return true;
}
protected override void OnEnterComplete(Actor self, Actor targetActor)
{
// Make sure the target hasn't changed while entering
// OnEnterComplete is only called if targetActor is alive
if (targetActor != enterActor || !infiltrates.CanInfiltrateTarget(self, Target.FromActor(targetActor)))
return;
foreach (var ini in notifiers)
ini.Infiltrating(self);
foreach (var t in targetActor.TraitsImplementing<INotifyInfiltrated>())
t.Infiltrated(targetActor, self, infiltrates.Info.Types);
if (!string.IsNullOrEmpty(infiltrates.Info.Notification))
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
infiltrates.Info.Notification, self.Owner.Faction.InternalName);
TextNotificationsManager.AddTransientLine(self.Owner, infiltrates.Info.TextNotification);
if (infiltrates.Info.EnterBehaviour == EnterBehaviour.Dispose)
self.Dispose();
else if (infiltrates.Info.EnterBehaviour == EnterBehaviour.Suicide)
self.Kill(self);
}
}
}

View File

@@ -0,0 +1,126 @@
#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;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities
{
public class Leap : Activity
{
readonly Mobile mobile;
readonly Mobile targetMobile;
readonly int speed;
readonly AttackLeap attack;
readonly EdibleByLeap edible;
readonly Target target;
CPos destinationCell;
SubCell destinationSubCell = SubCell.Any;
WPos destination, origin;
int length;
bool canceled = false;
bool jumpComplete = false;
int ticks = 0;
WPos targetPosition;
public Leap(in Target target, Mobile mobile, Mobile targetMobile, int speed, AttackLeap attack, EdibleByLeap edible)
{
this.mobile = mobile;
this.targetMobile = targetMobile;
this.attack = attack;
this.target = target;
this.edible = edible;
this.speed = speed;
}
protected override void OnFirstRun(Actor self)
{
destinationCell = target.Actor.Location;
if (targetMobile != null)
destinationSubCell = targetMobile.ToSubCell;
origin = self.CenterPosition;
destination = self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell);
length = Math.Max((origin - destination).Length / speed, 1);
// First check if we are still allowed to leap
// We need an extra boolean as using Cancel() in OnFirstRun doesn't work
canceled = !edible.GetLeapAtBy(self) || target.Type != TargetType.Actor;
IsInterruptible = false;
if (canceled)
return;
targetPosition = target.CenterPosition;
attack.GrantLeapCondition(self);
}
public override bool Tick(Actor self)
{
// Correct the visual position after we jumped
if (canceled || jumpComplete)
return true;
if (target.Type != TargetType.Invalid)
targetPosition = target.CenterPosition;
var position = length > 1 ? WPos.Lerp(origin, targetPosition, ticks, length - 1) : targetPosition;
mobile.SetCenterPosition(self, position);
// We are at the destination
if (++ticks >= length)
{
// Revoke the run condition
attack.IsAiming = false;
// Move to the correct subcells, if our target actor uses subcells
// (This does not update the visual position!)
mobile.SetLocation(destinationCell, destinationSubCell, destinationCell, destinationSubCell);
// Update movement which results in movementType set to MovementType.None.
// This is needed to prevent the move animation from playing.
mobile.UpdateMovement();
// Revoke the condition before attacking, as it is usually used to pause the attack trait
attack.RevokeLeapCondition(self);
attack.DoAttack(self, target);
jumpComplete = true;
QueueChild(mobile.LocalMove(self, position, self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell)));
}
return false;
}
protected override void OnLastRun(Actor self)
{
attack.RevokeLeapCondition(self);
base.OnLastRun(self);
}
protected override void OnActorDispose(Actor self)
{
attack.RevokeLeapCondition(self);
base.OnActorDispose(self);
}
public override IEnumerable<Target> GetTargets(Actor self)
{
yield return Target.FromPos(ticks < length / 2 ? origin : destination);
}
}
}

View File

@@ -0,0 +1,176 @@
#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.Cnc.Traits;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities
{
public class LeapAttack : Activity, IActivityNotifyStanceChanged
{
readonly AttackLeapInfo info;
readonly AttackLeap attack;
readonly Mobile mobile;
readonly bool allowMovement;
readonly bool forceAttack;
readonly Color? targetLineColor;
readonly MoveCooldownHelper moveCooldownHelper;
Target target;
Target lastVisibleTarget;
bool useLastVisibleTarget;
WDist lastVisibleMinRange;
WDist lastVisibleMaxRange;
BitSet<TargetableType> lastVisibleTargetTypes;
Player lastVisibleOwner;
public LeapAttack(Actor self, in Target target, bool allowMovement, bool forceAttack, AttackLeap attack, AttackLeapInfo info, Color? targetLineColor = null)
{
this.target = target;
this.targetLineColor = targetLineColor;
this.info = info;
this.attack = attack;
this.allowMovement = allowMovement;
this.forceAttack = forceAttack;
mobile = self.Trait<Mobile>();
moveCooldownHelper = new MoveCooldownHelper(self.World, mobile);
// The target may become hidden between the initial order request and the first tick (e.g. if queued)
// Moving to any position (even if quite stale) is still better than immediately giving up
if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner))
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
{
lastVisibleTarget = Target.FromPos(target.CenterPosition);
lastVisibleMinRange = attack.GetMinimumRangeVersusTarget(target);
lastVisibleMaxRange = attack.GetMaximumRangeVersusTarget(target);
if (target.Type == TargetType.Actor)
{
lastVisibleOwner = target.Actor.Owner;
lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
}
else if (target.Type == TargetType.FrozenActor)
{
lastVisibleOwner = target.FrozenActor.Owner;
lastVisibleTargetTypes = target.FrozenActor.TargetTypes;
}
}
}
protected override void OnFirstRun(Actor self)
{
attack.IsAiming = true;
}
public override bool Tick(Actor self)
{
if (IsCanceling)
return true;
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
{
lastVisibleTarget = Target.FromTargetPositions(target);
lastVisibleMinRange = attack.GetMinimumRangeVersusTarget(target);
lastVisibleMaxRange = attack.GetMaximumRangeVersusTarget(target);
lastVisibleOwner = target.Actor.Owner;
lastVisibleTargetTypes = target.Actor.GetEnabledTargetTypes();
}
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
var result = moveCooldownHelper.Tick(targetIsHiddenActor);
if (result != null)
return result.Value;
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return true;
var pos = self.CenterPosition;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
if (!checkTarget.IsInRange(pos, lastVisibleMaxRange) || checkTarget.IsInRange(pos, lastVisibleMinRange))
{
if (!allowMovement || lastVisibleMaxRange == WDist.Zero || lastVisibleMaxRange < lastVisibleMinRange)
return true;
moveCooldownHelper.NotifyMoveQueued();
QueueChild(mobile.MoveWithinRange(target, lastVisibleMinRange, lastVisibleMaxRange, checkTarget.CenterPosition, Color.Red));
return false;
}
// Ready to leap, but target isn't visible
if (targetIsHiddenActor || target.Type != TargetType.Actor)
return true;
// Target is not valid
if (!target.IsValidFor(self) || !attack.HasAnyValidWeapons(target))
return true;
var edible = target.Actor.TraitOrDefault<EdibleByLeap>();
if (edible == null || !edible.CanLeap(self))
return true;
// Can't leap yet
if (attack.Armaments.All(a => a.IsReloading))
return false;
// Use CenterOfSubCell with ToSubCell instead of target.Centerposition
// to avoid continuous facing adjustments as the target moves
var targetMobile = target.Actor.TraitOrDefault<Mobile>();
var targetSubcell = targetMobile != null ? targetMobile.ToSubCell : SubCell.Any;
var destination = self.World.Map.CenterOfSubCell(target.Actor.Location, targetSubcell);
var origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell);
var desiredFacing = (destination - origin).Yaw;
if (mobile.Facing != desiredFacing)
{
QueueChild(new Turn(self, desiredFacing));
return false;
}
QueueChild(new Leap(target, mobile, targetMobile, info.Speed.Length, attack, edible));
// Re-queue the child activities to kill the target if it didn't die in one go
return false;
}
protected override void OnLastRun(Actor self)
{
attack.IsAiming = false;
}
void IActivityNotifyStanceChanged.StanceChanged(Actor self, AutoTarget autoTarget, UnitStance oldStance, UnitStance newStance)
{
// Cancel non-forced targets when switching to a more restrictive stance if they are no longer valid for auto-targeting
if (newStance > oldStance || forceAttack)
return;
// If lastVisibleTarget is invalid we could never view the target in the first place, so we just drop it here too
if (!lastVisibleTarget.IsValidFor(self) || !autoTarget.HasValidTargetPriority(self, lastVisibleOwner, lastVisibleTargetTypes))
target = Target.Invalid;
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(useLastVisibleTarget ? lastVisibleTarget : target, targetLineColor.Value);
}
}
}

View File

@@ -0,0 +1,144 @@
#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;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities
{
public class Teleport : Activity
{
readonly Actor teleporter;
readonly int? maximumDistance;
readonly bool killOnFailure;
readonly BitSet<DamageType> killDamageTypes;
CPos destination;
readonly bool killCargo;
readonly bool screenFlash;
readonly string sound;
public Teleport(Actor teleporter, CPos destination, int? maximumDistance,
bool killCargo, bool screenFlash, string sound, bool interruptable = true,
bool killOnFailure = false, BitSet<DamageType> killDamageTypes = default)
{
var max = teleporter.World.Map.Grid.MaximumTileSearchRange;
if (maximumDistance > max)
throw new InvalidOperationException($"Teleport distance cannot exceed the value of MaximumTileSearchRange ({max}).");
this.teleporter = teleporter;
this.destination = destination;
this.maximumDistance = maximumDistance;
this.killCargo = killCargo;
this.screenFlash = screenFlash;
this.sound = sound;
this.killOnFailure = killOnFailure;
this.killDamageTypes = killDamageTypes;
if (!interruptable)
IsInterruptible = false;
}
public override bool Tick(Actor self)
{
var pc = self.TraitOrDefault<PortableChrono>();
if (teleporter == self && pc != null && (!pc.CanTeleport || IsCanceling))
{
if (killOnFailure)
self.Kill(teleporter, killDamageTypes);
return true;
}
var bestCell = ChooseBestDestinationCell(self, destination);
if (bestCell == null)
{
if (killOnFailure)
self.Kill(teleporter, killDamageTypes);
return true;
}
destination = bestCell.Value;
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.World.Map.CenterOfCell(destination));
self.Trait<IPositionable>().SetPosition(self, destination);
self.Generation++;
if (killCargo)
{
var cargo = self.TraitOrDefault<Cargo>();
if (cargo != null && teleporter != null)
{
while (!cargo.IsEmpty())
{
var a = cargo.Unload(self);
// Kill all the units that are unloaded into the void
// Kill() handles kill and death statistics
a.Kill(teleporter);
}
}
}
// Consume teleport charges if this wasn't triggered via chronosphere
if (teleporter == self)
pc?.ResetChargeTime();
// Trigger screen desaturate effect
if (screenFlash)
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPostProcessEffect>())
a.Trait.Enable();
if (teleporter != null && self != teleporter && !teleporter.Disposed)
{
var building = teleporter.TraitOrDefault<WithSpriteBody>();
if (building != null && building.DefaultAnimation.HasSequence("active"))
building.PlayCustomAnimation(teleporter, "active");
}
return true;
}
CPos? ChooseBestDestinationCell(Actor self, CPos destination)
{
if (teleporter == null)
return null;
var restrictTo = maximumDistance == null ? null : self.World.Map.FindTilesInCircle(self.Location, maximumDistance.Value).ToHashSet();
if (maximumDistance != null)
destination = restrictTo.MinBy(x => (x - destination).LengthSquared);
var pos = self.Trait<IPositionable>();
if (pos.CanEnterCell(destination) && teleporter.Owner.Shroud.IsExplored(destination))
return destination;
var max = maximumDistance ?? teleporter.World.Map.Grid.MaximumTileSearchRange;
foreach (var tile in self.World.Map.FindTilesInCircle(destination, max))
{
if (teleporter.Owner.Shroud.IsExplored(tile)
&& (restrictTo == null || restrictTo.Contains(tile))
&& pos.CanEnterCell(tile))
return tile;
}
return null;
}
}
}