Merge pull request #6921 from reaperrr/common-traits01
Moved various traits to Mods.Common
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRA;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.AI;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
[Desc("Overrides the build time calculated by actor value.")]
|
||||
public class CustomBuildTimeValueInfo : TraitInfo<CustomBuildTimeValue>
|
||||
{
|
||||
public readonly int Value = 0;
|
||||
}
|
||||
|
||||
public class CustomBuildTimeValue { }
|
||||
|
||||
public static class CustomBuildTimeValueExts
|
||||
{
|
||||
public static int GetBuildTime(this ActorInfo a)
|
||||
{
|
||||
var csv = a.Traits.GetOrDefault<CustomBuildTimeValueInfo>();
|
||||
if (csv != null)
|
||||
return csv.Value;
|
||||
|
||||
var cost = a.Traits.Contains<ValuedInfo>() ? a.Traits.Get<ValuedInfo>().Cost : 0;
|
||||
var time = cost
|
||||
* (25 * 60) /* frames per min */
|
||||
/ 1000;
|
||||
return
|
||||
time;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
[Desc("Allow a non-standard sell/repair value to avoid buy-sell exploits.")]
|
||||
public class CustomSellValueInfo : TraitInfo<CustomSellValue>
|
||||
{
|
||||
public readonly int Value = 0;
|
||||
}
|
||||
|
||||
public class CustomSellValue { }
|
||||
|
||||
public static class CustomSellValueExts
|
||||
{
|
||||
public static int GetSellValue( this Actor a )
|
||||
{
|
||||
var csv = a.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||
if (csv != null) return csv.Value;
|
||||
|
||||
var valued = a.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
if (valued != null) return valued.Cost;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Handle demolitions from C4 explosives.")]
|
||||
public class DemolishableInfo : IDemolishableInfo, ITraitInfo
|
||||
{
|
||||
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return true; }
|
||||
|
||||
public object Create(ActorInitializer init) { return new Demolishable(); }
|
||||
}
|
||||
|
||||
public class Demolishable : IDemolishable
|
||||
{
|
||||
public void Demolish(Actor self, Actor saboteur)
|
||||
{
|
||||
self.Kill(saboteur);
|
||||
}
|
||||
|
||||
public bool IsValidTarget(Actor self, Actor saboteur)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class ShakeOnDeathInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Intensity = 10;
|
||||
public object Create(ActorInitializer init) { return new ShakeOnDeath(this); }
|
||||
}
|
||||
|
||||
public class ShakeOnDeath : INotifyKilled
|
||||
{
|
||||
readonly ShakeOnDeathInfo Info;
|
||||
|
||||
public ShakeOnDeath(ShakeOnDeathInfo info)
|
||||
{
|
||||
this.Info = info;
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(Info.Intensity, self.CenterPosition, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class SoundOnDamageTransitionInfo : ITraitInfo
|
||||
{
|
||||
public readonly string DamagedSound;
|
||||
public readonly string DestroyedSound;
|
||||
|
||||
public object Create(ActorInitializer init) { return new SoundOnDamageTransition(this);}
|
||||
}
|
||||
|
||||
public class SoundOnDamageTransition : INotifyDamageStateChanged
|
||||
{
|
||||
readonly SoundOnDamageTransitionInfo Info;
|
||||
|
||||
public SoundOnDamageTransition( SoundOnDamageTransitionInfo info )
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (e.DamageState == DamageState.Dead)
|
||||
Sound.Play(Info.DestroyedSound, self.CenterPosition);
|
||||
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
|
||||
Sound.Play(Info.DamagedSound, self.CenterPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Traits.Render;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("This actor will play a fire animation over its body and take damage over time.")]
|
||||
class BurnsInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly string Anim = "1";
|
||||
public readonly int Damage = 1;
|
||||
public readonly int Interval = 8;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Burns(init.self, this); }
|
||||
}
|
||||
|
||||
class Burns : ITick, ISync
|
||||
{
|
||||
[Sync] int ticks;
|
||||
BurnsInfo Info;
|
||||
|
||||
public Burns(Actor self, BurnsInfo info)
|
||||
{
|
||||
Info = info;
|
||||
|
||||
var anim = new Animation(self.World, "fire", () => 0);
|
||||
anim.IsDecoration = true;
|
||||
anim.PlayRepeating(Info.Anim);
|
||||
self.Trait<RenderSprites>().Add("fire", anim);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
self.InflictDamage(self, Info.Damage, null);
|
||||
ticks = Info.Interval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
|
||||
@@ -164,16 +164,11 @@
|
||||
<Compile Include="CaptureNotification.cs" />
|
||||
<Compile Include="Buildings\Building.cs" />
|
||||
<Compile Include="Buildings\BuildingInfluence.cs" />
|
||||
<Compile Include="Buildings\CustomSellValue.cs" />
|
||||
<Compile Include="Buildings\CustomBuildTimeValue.cs" />
|
||||
<Compile Include="Buildings\DeadBuildingState.cs" />
|
||||
<Compile Include="Buildings\FootprintUtils.cs" />
|
||||
<Compile Include="Buildings\LineBuild.cs" />
|
||||
<Compile Include="Buildings\RepairableBuilding.cs" />
|
||||
<Compile Include="Buildings\ShakeOnDeath.cs" />
|
||||
<Compile Include="Buildings\SoundOnDamageTransition.cs" />
|
||||
<Compile Include="Buildings\Util.cs" />
|
||||
<Compile Include="Burns.cs" />
|
||||
<Compile Include="C4Demolition.cs" />
|
||||
<Compile Include="ExternalCapturable.cs" />
|
||||
<Compile Include="ExternalCapturableBar.cs" />
|
||||
@@ -291,7 +286,6 @@
|
||||
<Compile Include="SeedsResource.cs" />
|
||||
<Compile Include="SelfHealing.cs" />
|
||||
<Compile Include="Sellable.cs" />
|
||||
<Compile Include="ShroudPalette.cs" />
|
||||
<Compile Include="SmokeTrailWhenDamaged.cs" />
|
||||
<Compile Include="SpawnMPUnits.cs" />
|
||||
<Compile Include="Disguise.cs" />
|
||||
@@ -316,7 +310,6 @@
|
||||
<Compile Include="TransformOnPassenger.cs" />
|
||||
<Compile Include="Transforms.cs" />
|
||||
<Compile Include="Turreted.cs" />
|
||||
<Compile Include="Valued.cs" />
|
||||
<Compile Include="Widgets\Logic\KickSpectatorsLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\MissionBrowserLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\IngameMenuLogic.cs" />
|
||||
@@ -387,9 +380,7 @@
|
||||
<Compile Include="CombatDebugOverlay.cs" />
|
||||
<Compile Include="World\PathfinderDebugOverlay.cs" />
|
||||
<Compile Include="AttackBomber.cs" />
|
||||
<Compile Include="ShroudRenderer.cs" />
|
||||
<Compile Include="Render\WithCrateBody.cs" />
|
||||
<Compile Include="Buildings\Demolishable.cs" />
|
||||
<Compile Include="Activities\FlyFollow.cs" />
|
||||
<Compile Include="Widgets\Logic\GameTimerLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\ReplayControlBarLogic.cs" />
|
||||
@@ -402,7 +393,6 @@
|
||||
<Compile Include="Widgets\Logic\ControlGroupLogic.cs" />
|
||||
<Compile Include="Buildings\LineBuildNode.cs" />
|
||||
<Compile Include="Render\WithBuildingPlacedAnimation.cs" />
|
||||
<Compile Include="StartGameNotification.cs" />
|
||||
<Compile Include="Scripting\LuaScript.cs" />
|
||||
<Compile Include="Scripting\CallLuaFunc.cs" />
|
||||
<Compile Include="Scripting\Global\ActorGlobal.cs" />
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Power;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Power;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using Eluant;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Adds the hard-coded shroud palette to the game")]
|
||||
class ShroudPaletteInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Internal palette name")]
|
||||
public readonly string Name = "shroud";
|
||||
|
||||
[Desc("Palette type")]
|
||||
public readonly bool Fog = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
|
||||
}
|
||||
|
||||
class ShroudPalette : ILoadsPalettes
|
||||
{
|
||||
readonly ShroudPaletteInfo info;
|
||||
|
||||
public ShroudPalette(ShroudPaletteInfo info) { this.info = info; }
|
||||
|
||||
public void LoadPalettes(WorldRenderer wr)
|
||||
{
|
||||
var c = info.Fog ? Fog : Shroud;
|
||||
wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (uint)c[i % 8].ToArgb())));
|
||||
}
|
||||
|
||||
static Color[] Fog = new[] {
|
||||
Color.Transparent, Color.Green,
|
||||
Color.Blue, Color.Yellow,
|
||||
Color.FromArgb(128,0,0,0),
|
||||
Color.FromArgb(96,0,0,0),
|
||||
Color.FromArgb(64,0,0,0),
|
||||
Color.FromArgb(32,0,0,0)
|
||||
};
|
||||
|
||||
static Color[] Shroud = new[] {
|
||||
Color.Transparent, Color.Green,
|
||||
Color.Blue, Color.Yellow,
|
||||
Color.Black,
|
||||
Color.FromArgb(160,0,0,0),
|
||||
Color.FromArgb(128,0,0,0),
|
||||
Color.FromArgb(64,0,0,0)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,302 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class ShroudRendererInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Sequence = "shroud";
|
||||
public readonly string[] ShroudVariants = new[] { "shroud" };
|
||||
public readonly string[] FogVariants = new[] { "fog" };
|
||||
|
||||
public readonly string ShroudPalette = "shroud";
|
||||
public readonly string FogPalette = "fog";
|
||||
|
||||
[Desc("Bitfield of shroud directions for each frame. Lower four bits are",
|
||||
"corners clockwise from TL; upper four are edges clockwise from top")]
|
||||
public readonly int[] Index = new[] { 12, 9, 8, 3, 1, 6, 4, 2, 13, 11, 7, 14 };
|
||||
|
||||
[Desc("Use the upper four bits when calculating frame")]
|
||||
public readonly bool UseExtendedIndex = false;
|
||||
|
||||
[Desc("Override for source art that doesn't define a fully shrouded tile")]
|
||||
public readonly string OverrideFullShroud = null;
|
||||
public readonly int OverrideShroudIndex = 15;
|
||||
|
||||
[Desc("Override for source art that doesn't define a fully fogged tile")]
|
||||
public readonly string OverrideFullFog = null;
|
||||
public readonly int OverrideFogIndex = 15;
|
||||
|
||||
public readonly BlendMode ShroudBlend = BlendMode.Alpha;
|
||||
public object Create(ActorInitializer init) { return new ShroudRenderer(init.world, this); }
|
||||
}
|
||||
|
||||
public class ShroudRenderer : IRenderShroud, IWorldLoaded
|
||||
{
|
||||
[Flags]
|
||||
enum Edges : byte
|
||||
{
|
||||
None = 0,
|
||||
TopLeft = 0x01,
|
||||
TopRight = 0x02,
|
||||
BottomRight = 0x04,
|
||||
BottomLeft = 0x08,
|
||||
AllCorners = TopLeft | TopRight | BottomRight | BottomLeft,
|
||||
TopSide = 0x10,
|
||||
RightSide = 0x20,
|
||||
BottomSide = 0x40,
|
||||
LeftSide = 0x80,
|
||||
AllSides = TopSide | RightSide | BottomSide | LeftSide,
|
||||
Top = TopSide | TopLeft | TopRight,
|
||||
Right = RightSide | TopRight | BottomRight,
|
||||
Bottom = BottomSide | BottomRight | BottomLeft,
|
||||
Left = LeftSide | TopLeft | BottomLeft,
|
||||
All = Top | Right | Bottom | Left
|
||||
}
|
||||
|
||||
struct ShroudTile
|
||||
{
|
||||
public readonly float2 ScreenPosition;
|
||||
public readonly byte Variant;
|
||||
|
||||
public Sprite Fog;
|
||||
public Sprite Shroud;
|
||||
|
||||
public ShroudTile(float2 screenPosition, byte variant)
|
||||
{
|
||||
ScreenPosition = screenPosition;
|
||||
Variant = variant;
|
||||
|
||||
Fog = null;
|
||||
Shroud = null;
|
||||
}
|
||||
}
|
||||
|
||||
readonly ShroudRendererInfo info;
|
||||
readonly Sprite[] shroudSprites, fogSprites;
|
||||
readonly byte[] spriteMap;
|
||||
readonly CellLayer<ShroudTile> tiles;
|
||||
readonly byte variantStride;
|
||||
readonly Map map;
|
||||
readonly Edges notVisibleEdges;
|
||||
|
||||
bool clearedForNullShroud;
|
||||
int lastShroudHash;
|
||||
CellRegion updatedRegion;
|
||||
|
||||
PaletteReference fogPalette, shroudPalette;
|
||||
|
||||
public ShroudRenderer(World world, ShroudRendererInfo info)
|
||||
{
|
||||
if (info.ShroudVariants.Length != info.FogVariants.Length)
|
||||
throw new ArgumentException("ShroudRenderer must define the same number of shroud and fog variants!", "info");
|
||||
|
||||
if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
|
||||
throw new ArgumentException("ShroudRenderer cannot define overrides for only one of shroud or fog!", "info");
|
||||
|
||||
if (info.ShroudVariants.Length > byte.MaxValue)
|
||||
throw new ArgumentException("ShroudRenderer cannot define this many shroud and fog variants.", "info");
|
||||
|
||||
if (info.Index.Length >= byte.MaxValue)
|
||||
throw new ArgumentException("ShroudRenderer cannot define this many indexes for shroud directions.", "info");
|
||||
|
||||
this.info = info;
|
||||
map = world.Map;
|
||||
|
||||
tiles = new CellLayer<ShroudTile>(map);
|
||||
|
||||
// Load sprite variants
|
||||
var variantCount = info.ShroudVariants.Length;
|
||||
variantStride = (byte)(info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0));
|
||||
shroudSprites = new Sprite[variantCount * variantStride];
|
||||
fogSprites = new Sprite[variantCount * variantStride];
|
||||
|
||||
for (var j = 0; j < variantCount; j++)
|
||||
{
|
||||
var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
|
||||
var fog = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
|
||||
for (var i = 0; i < info.Index.Length; i++)
|
||||
{
|
||||
shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
|
||||
fogSprites[j * variantStride + i] = fog.GetSprite(i);
|
||||
}
|
||||
|
||||
if (info.OverrideFullShroud != null)
|
||||
{
|
||||
var i = (j + 1) * variantStride - 1;
|
||||
shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
|
||||
fogSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Mapping of shrouded directions -> sprite index
|
||||
spriteMap = new byte[(byte)(info.UseExtendedIndex ? Edges.All : Edges.AllCorners) + 1];
|
||||
for (var i = 0; i < info.Index.Length; i++)
|
||||
spriteMap[info.Index[i]] = (byte)i;
|
||||
|
||||
if (info.OverrideFullShroud != null)
|
||||
spriteMap[info.OverrideShroudIndex] = (byte)(variantStride - 1);
|
||||
|
||||
notVisibleEdges = info.UseExtendedIndex ? Edges.AllSides : Edges.AllCorners;
|
||||
}
|
||||
|
||||
Edges GetEdges(CPos p, Func<CPos, bool> isVisible)
|
||||
{
|
||||
if (!isVisible(p))
|
||||
return notVisibleEdges;
|
||||
|
||||
// If a side is shrouded then we also count the corners
|
||||
var u = Edges.None;
|
||||
if (!isVisible(p + new CVec(0, -1))) u |= Edges.Top;
|
||||
if (!isVisible(p + new CVec(1, 0))) u |= Edges.Right;
|
||||
if (!isVisible(p + new CVec(0, 1))) u |= Edges.Bottom;
|
||||
if (!isVisible(p + new CVec(-1, 0))) u |= Edges.Left;
|
||||
|
||||
var ucorner = u & Edges.AllCorners;
|
||||
if (!isVisible(p + new CVec(-1, -1))) u |= Edges.TopLeft;
|
||||
if (!isVisible(p + new CVec(1, -1))) u |= Edges.TopRight;
|
||||
if (!isVisible(p + new CVec(1, 1))) u |= Edges.BottomRight;
|
||||
if (!isVisible(p + new CVec(-1, 1))) u |= Edges.BottomLeft;
|
||||
|
||||
// RA provides a set of frames for tiles with shrouded
|
||||
// corners but unshrouded edges. We want to detect this
|
||||
// situation without breaking the edge -> corner enabling
|
||||
// in other combinations. The XOR turns off the corner
|
||||
// bits that are enabled twice, which gives the behavior
|
||||
// we want here.
|
||||
return info.UseExtendedIndex ? u ^ ucorner : u & Edges.AllCorners;
|
||||
}
|
||||
|
||||
Edges GetObserverEdges(CPos p)
|
||||
{
|
||||
var u = Edges.None;
|
||||
if (!map.Contains(p + new CVec(0, -1))) u |= Edges.Top;
|
||||
if (!map.Contains(p + new CVec(1, 0))) u |= Edges.Right;
|
||||
if (!map.Contains(p + new CVec(0, 1))) u |= Edges.Bottom;
|
||||
if (!map.Contains(p + new CVec(-1, 0))) u |= Edges.Left;
|
||||
|
||||
var ucorner = u & Edges.AllCorners;
|
||||
if (!map.Contains(p + new CVec(-1, -1))) u |= Edges.TopLeft;
|
||||
if (!map.Contains(p + new CVec(1, -1))) u |= Edges.TopRight;
|
||||
if (!map.Contains(p + new CVec(1, 1))) u |= Edges.BottomRight;
|
||||
if (!map.Contains(p + new CVec(-1, 1))) u |= Edges.BottomLeft;
|
||||
|
||||
return info.UseExtendedIndex ? u ^ ucorner : u & Edges.AllCorners;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
// Initialize tile cache
|
||||
// Adds a 1-cell border around the border to cover any sprites peeking outside the map
|
||||
foreach (var cell in CellRegion.Expand(w.Map.Cells, 1))
|
||||
{
|
||||
var screen = wr.ScreenPosition(w.Map.CenterOfCell(cell));
|
||||
var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length);
|
||||
tiles[cell] = new ShroudTile(screen, variant);
|
||||
|
||||
// Set the cells outside the border so they don't need to be touched again
|
||||
if (!map.Contains(cell))
|
||||
{
|
||||
var shroudTile = tiles[cell];
|
||||
shroudTile.Shroud = GetTile(shroudSprites, notVisibleEdges, variant);
|
||||
tiles[cell] = shroudTile;
|
||||
}
|
||||
}
|
||||
|
||||
fogPalette = wr.Palette(info.FogPalette);
|
||||
shroudPalette = wr.Palette(info.ShroudPalette);
|
||||
}
|
||||
|
||||
Sprite GetTile(Sprite[] sprites, Edges edges, int variant)
|
||||
{
|
||||
if (edges == Edges.None)
|
||||
return null;
|
||||
|
||||
return sprites[variant * variantStride + spriteMap[(byte)edges]];
|
||||
}
|
||||
|
||||
void Update(Shroud shroud, CellRegion region)
|
||||
{
|
||||
if (shroud != null)
|
||||
{
|
||||
// If the current shroud hasn't changed and we have already updated the specified area, we don't need to do anything.
|
||||
if (lastShroudHash == shroud.Hash && !clearedForNullShroud && updatedRegion != null && updatedRegion.Contains(region))
|
||||
return;
|
||||
|
||||
lastShroudHash = shroud.Hash;
|
||||
clearedForNullShroud = false;
|
||||
updatedRegion = region;
|
||||
UpdateShroud(shroud);
|
||||
}
|
||||
else if (!clearedForNullShroud)
|
||||
{
|
||||
// We need to clear any applied shroud.
|
||||
clearedForNullShroud = true;
|
||||
updatedRegion = new CellRegion(map.TileShape, new CPos(0, 0), new CPos(-1, -1));
|
||||
UpdateNullShroud();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateShroud(Shroud shroud)
|
||||
{
|
||||
var visibleUnderShroud = shroud.IsExploredTest(updatedRegion);
|
||||
var visibleUnderFog = shroud.IsVisibleTest(updatedRegion);
|
||||
foreach (var cell in updatedRegion)
|
||||
{
|
||||
var shrouded = GetEdges(cell, visibleUnderShroud);
|
||||
var fogged = GetEdges(cell, visibleUnderFog);
|
||||
var shroudTile = tiles[cell];
|
||||
var variant = shroudTile.Variant;
|
||||
shroudTile.Shroud = GetTile(shroudSprites, shrouded, variant);
|
||||
shroudTile.Fog = GetTile(fogSprites, fogged, variant);
|
||||
tiles[cell] = shroudTile;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateNullShroud()
|
||||
{
|
||||
foreach (var cell in map.Cells)
|
||||
{
|
||||
var edges = GetObserverEdges(cell);
|
||||
var shroudTile = tiles[cell];
|
||||
var variant = shroudTile.Variant;
|
||||
shroudTile.Shroud = GetTile(shroudSprites, edges, variant);
|
||||
shroudTile.Fog = GetTile(fogSprites, edges, variant);
|
||||
tiles[cell] = shroudTile;
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderShroud(WorldRenderer wr, Shroud shroud)
|
||||
{
|
||||
Update(shroud, wr.Viewport.VisibleCells);
|
||||
|
||||
foreach (var cell in CellRegion.Expand(wr.Viewport.VisibleCells, 1))
|
||||
{
|
||||
var t = tiles[cell];
|
||||
|
||||
if (t.Shroud != null)
|
||||
{
|
||||
var pos = t.ScreenPosition - 0.5f * t.Shroud.size;
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(t.Shroud, pos, shroudPalette);
|
||||
}
|
||||
|
||||
if (t.Fog != null)
|
||||
{
|
||||
var pos = t.ScreenPosition - 0.5f * t.Fog.size;
|
||||
Game.Renderer.WorldSpriteRenderer.DrawSprite(t.Fog, pos, fogPalette);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class StartGameNotificationInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Notification = "StartGame";
|
||||
|
||||
public object Create(ActorInitializer init) { return new StartGameNotification(this); }
|
||||
}
|
||||
|
||||
class StartGameNotification : IWorldLoaded
|
||||
{
|
||||
StartGameNotificationInfo info;
|
||||
public StartGameNotification(StartGameNotificationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
Sound.PlayNotification(world.Map.Rules, null, "Speech", info.Notification, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.UtilityCommands
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("How much the unit is worth.")]
|
||||
public class ValuedInfo : TraitInfo<Valued>
|
||||
{
|
||||
[Desc("Used in production, but also for bounties so remember to set it > 0 even for NPCs.")]
|
||||
public readonly int Cost = 0;
|
||||
}
|
||||
|
||||
public class Valued { }
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Power;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Power;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
Reference in New Issue
Block a user