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,53 @@
#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 OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
public class CloakPaletteEffectInfo : TraitInfo<CloakPaletteEffect> { }
public class CloakPaletteEffect : IPaletteModifier, ITick
{
float t = 0;
readonly string paletteName = "cloak";
readonly Color[] colors =
[
Color.FromArgb(55, 205, 205, 220),
Color.FromArgb(120, 205, 205, 230),
Color.FromArgb(192, 180, 180, 255),
Color.FromArgb(178, 205, 250, 220),
];
void IPaletteModifier.AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b)
{
var i = (int)t;
var p = b[paletteName];
for (var j = 0; j < colors.Length; j++)
{
var k = (i + j) % 16 + 0xb0;
p.SetColor(k, colors[j]);
}
}
void ITick.Tick(Actor self)
{
t += 0.25f;
if (t >= 256) t = 0;
}
}
}

View File

@@ -0,0 +1,67 @@
#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 OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
[Desc("Used for bursted one-colored whole screen effects. Add this to the world actor.")]
public class FlashPostProcessEffectInfo : TraitInfo
{
[Desc("Measured in ticks.")]
public readonly int Length = 20;
public readonly Color Color = Color.White;
[Desc("Set this when using multiple independent flash effects.")]
public readonly string Type = null;
public override object Create(ActorInitializer init) { return new FlashPostProcessEffect(this); }
}
public class FlashPostProcessEffect : RenderPostProcessPassBase, ITick
{
public readonly FlashPostProcessEffectInfo Info;
int remainingFrames;
float blend;
public FlashPostProcessEffect(FlashPostProcessEffectInfo info)
: base("flash", PostProcessPassType.AfterWorld)
{
Info = info;
}
public void Enable(int ticks)
{
if (ticks == -1)
remainingFrames = Info.Length;
else
remainingFrames = ticks;
}
void ITick.Tick(Actor self)
{
if (remainingFrames > 0)
blend = Math.Min((float)--remainingFrames / Info.Length, 1);
}
protected override bool Enabled => remainingFrames > 0;
protected override void PrepareRender(WorldRenderer wr, IShader shader)
{
shader.SetVec("Blend", blend);
shader.SetVec("Color", (float)Info.Color.R / 255, (float)Info.Color.G / 255, (float)Info.Color.B / 255);
}
}
}

View File

@@ -0,0 +1,101 @@
#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 OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Traits
{
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
[Desc("Fades the world from/to black at the start/end of the game, and can (optionally) desaturate the world")]
public class MenuPostProcessEffectInfo : TraitInfo
{
public readonly int FadeInLength = 10;
[Desc("Time (in ticks) to fade between states")]
public readonly int FadeLength = 10;
[Desc("Effect style to fade to during gameplay. Accepts values of None or Desaturated.")]
public readonly MenuPostProcessEffect.EffectType Effect = MenuPostProcessEffect.EffectType.None;
[Desc("Effect style to fade from when starting the game. Accepts values of None, Black or Desaturated.")]
public readonly MenuPostProcessEffect.EffectType GameStartEffect = MenuPostProcessEffect.EffectType.Black;
[Desc("Effect style to fade to when exiting the game. Accepts values of None, Black or Desaturated.")]
public readonly MenuPostProcessEffect.EffectType GameExitEffect = MenuPostProcessEffect.EffectType.Black;
[Desc("Effect style to fade to when opening the in-game menu. Accepts values of None, Black or Desaturated.")]
public readonly MenuPostProcessEffect.EffectType MenuEffect = MenuPostProcessEffect.EffectType.None;
public override object Create(ActorInitializer init) { return new MenuPostProcessEffect(this); }
}
public class MenuPostProcessEffect : RenderPostProcessPassBase, INotifyGameLoaded, IPostWorldLoaded
{
public enum EffectType { None, Black, Desaturated }
public readonly MenuPostProcessEffectInfo Info;
EffectType from;
EffectType to;
long startTime;
long endTime;
public MenuPostProcessEffect(MenuPostProcessEffectInfo info)
: base("menufade", PostProcessPassType.AfterAnnotations)
{
Info = info;
to = info.GameStartEffect;
}
public void Fade(EffectType type, int length = -1)
{
if (length < 0)
length = Info.FadeLength;
startTime = Game.RunTime;
endTime = startTime + Ui.Timestep * length;
from = to;
to = type;
}
protected override bool Enabled => to != EffectType.None || (from != EffectType.None && Game.RunTime < endTime);
protected override void PrepareRender(WorldRenderer wr, IShader shader)
{
var blend = (endTime - Game.RunTime) * 1f / (endTime - startTime);
if (blend < 0)
blend = startTime = endTime = 0;
shader.SetVec("From", (int)from);
shader.SetVec("To", (int)to);
shader.SetVec("Blend", blend);
}
void IPostWorldLoaded.PostWorldLoaded(World w, WorldRenderer wr)
{
// HACK: Defer fade-in until the GameLoaded notification for game saves
if (!w.IsLoadingGameSave)
Fade(Info.Effect, Info.FadeInLength);
}
void INotifyGameLoaded.GameLoaded(World world)
{
// HACK: Let the menu opening trigger the fade for game saves
// to avoid glitches resulting from trying to trigger both
// the standard and menu fades at the same time
if (world.IsReplay)
Fade(Info.Effect, Info.FadeInLength);
}
}
}

View File

@@ -0,0 +1,121 @@
#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.Frozen;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
[Desc("Palette effect used for sprinkle \"animations\".")]
sealed class RotationPaletteEffectInfo : TraitInfo
{
[Desc("Defines to which palettes this effect should be applied to.",
"If none specified, it applies to all palettes not explicitly excluded.")]
public readonly FrozenSet<string> Palettes = FrozenSet<string>.Empty;
[Desc("Defines for which tileset IDs this effect should be loaded.",
"If none specified, it applies to all tileset IDs not explicitly excluded.")]
public readonly FrozenSet<string> Tilesets = FrozenSet<string>.Empty;
[Desc("Defines which palettes should be excluded from this effect.")]
public readonly FrozenSet<string> ExcludePalettes = FrozenSet<string>.Empty;
[Desc("Don't apply the effect for these tileset IDs.")]
public readonly FrozenSet<string> ExcludeTilesets = FrozenSet<string>.Empty;
[Desc("Palette index of first RotationRange color.")]
public readonly int RotationBase = 0x60;
[Desc("Range of colors to rotate.")]
public readonly int RotationRange = 7;
[Desc("Step towards next color index per tick.")]
public readonly float RotationStep = .25f;
public override object Create(ActorInitializer init) { return new RotationPaletteEffect(init.World, this); }
}
sealed class RotationPaletteEffect : ITick, IPaletteModifier
{
readonly RotationPaletteEffectInfo info;
readonly uint[] rotationBuffer;
readonly bool validTileset;
readonly string tilesetId;
float t = 0;
public RotationPaletteEffect(World world, RotationPaletteEffectInfo info)
{
this.info = info;
rotationBuffer = new uint[info.RotationRange];
tilesetId = world.Map.Rules.TerrainInfo.Id;
validTileset = IsValidTileset();
}
bool IsValidTileset()
{
if (info.Tilesets.Count == 0 && info.ExcludeTilesets.Count == 0)
return true;
if (info.Tilesets.Count == 0 && !info.ExcludeTilesets.Contains(tilesetId))
return true;
return info.Tilesets.Contains(tilesetId) && !info.ExcludeTilesets.Contains(tilesetId);
}
void ITick.Tick(Actor self)
{
if (!validTileset)
return;
t += info.RotationStep;
}
public void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> palettes)
{
if (!validTileset)
return;
var rotate = (int)t % info.RotationRange;
if (rotate == 0)
return;
foreach (var kvp in palettes)
{
if ((info.Palettes.Count > 0 && !StartsWithAny(kvp.Key, info.Palettes))
|| (info.ExcludePalettes.Count > 0 && StartsWithAny(kvp.Key, info.ExcludePalettes)))
continue;
var palette = kvp.Value;
for (var i = 0; i < info.RotationRange; i++)
rotationBuffer[(rotate + i) % info.RotationRange] = palette[info.RotationBase + i];
for (var i = 0; i < info.RotationRange; i++)
palette[info.RotationBase + i] = rotationBuffer[i];
}
}
static bool StartsWithAny(string name, FrozenSet<string> prefixes)
{
// PERF: Avoid LINQ.
foreach (var pref in prefixes)
if (name.StartsWith(pref, StringComparison.Ordinal))
return true;
return false;
}
}
}

View File

@@ -0,0 +1,51 @@
#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 OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Used for day/night effects.")]
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
public class TintPostProcessEffectInfo : TraitInfo, ILobbyCustomRulesIgnore
{
public readonly float Red = 1f;
public readonly float Green = 1f;
public readonly float Blue = 1f;
public readonly float Ambient = 1f;
public override object Create(ActorInitializer init) { return new TintPostProcessEffect(this); }
}
public class TintPostProcessEffect : RenderPostProcessPassBase
{
public float Red;
public float Green;
public float Blue;
public float Ambient;
public TintPostProcessEffect(TintPostProcessEffectInfo info)
: base("tint", PostProcessPassType.AfterActors)
{
Red = info.Red;
Green = info.Green;
Blue = info.Blue;
Ambient = info.Ambient;
}
protected override bool Enabled => true;
protected override void PrepareRender(WorldRenderer wr, IShader shader)
{
shader.SetVec("Tint", Ambient * Red, Ambient * Green, Ambient * Blue);
}
}
}