moved more traits from engine into mods

This commit is contained in:
Bob
2010-09-20 21:17:50 +12:00
parent aff6889995
commit afda1647fd
13 changed files with 57 additions and 41 deletions

View File

@@ -153,19 +153,15 @@
<Compile Include="Graphics\TerrainRenderer.cs" />
<Compile Include="Traits\Activities\Move.cs" />
<Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\Buildable.cs" />
<Compile Include="Traits\Building.cs" />
<Compile Include="Traits\World\BuildingInfluence.cs" />
<Compile Include="Traits\World\PlayerColorPalette.cs" />
<Compile Include="Traits\World\ResourceLayer.cs" />
<Compile Include="Traits\World\ResourceType.cs" />
<Compile Include="Traits\SupportPower.cs" />
<Compile Include="Traits\ProvidesRadar.cs" />
<Compile Include="Traits\Selectable.cs" />
<Compile Include="Traits\Mobile.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\World\UnitInfluence.cs" />
<Compile Include="Network\UnitOrders.cs" />
<Compile Include="Traits\Util.cs" />
@@ -185,8 +181,6 @@
<Compile Include="Widgets\BackgroundWidget.cs" />
<Compile Include="Widgets\LabelWidget.cs" />
<Compile Include="Widgets\CheckboxWidget.cs" />
<Compile Include="Traits\World\BibLayer.cs" />
<Compile Include="Traits\World\SmudgeLayer.cs" />
<Compile Include="Widgets\Delegates\MusicPlayerDelegate.cs" />
<Compile Include="Widgets\PerfGraphWidget.cs" />
<Compile Include="Widgets\Delegates\PerfDebugDelegate.cs" />
@@ -194,7 +188,6 @@
<Compile Include="Widgets\ColorBlockWidget.cs" />
<Compile Include="GameRules\MusicInfo.cs" />
<Compile Include="Widgets\ImageWidget.cs" />
<Compile Include="Traits\SharesCell.cs" />
<Compile Include="Widgets\TextFieldWidget.cs" />
<Compile Include="Widgets\ChatDisplayWidget.cs" />
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
@@ -212,7 +205,6 @@
<Compile Include="Traits\Activities\Drag.cs" />
<Compile Include="Widgets\VqaPlayerWidget.cs" />
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
<Compile Include="Traits\MPStartLocations.cs" />
<Compile Include="GameRules\Settings.cs" />
<Compile Include="Support\Arguments.cs" />
<Compile Include="Traits\ActorStance.cs" />
@@ -234,6 +226,9 @@
<Compile Include="ObjectCreator.cs" />
<Compile Include="Network\SyncReport.cs" />
<Compile Include="TraitDictionary.cs" />
<Compile Include="Traits\SharesCell.cs" />
<Compile Include="Traits\Valued.cs" />
<Compile Include="Traits\World\BibLayer.cs" />
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,49 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
namespace OpenRA.Traits
{
public class ValuedInfo : ITraitInfo
{
public readonly int Cost = 0;
public object Create(ActorInitializer init) { return new Valued(); }
}
public class TooltipInfo : ITraitInfo
{
public readonly string Description = "";
public readonly string Name = "";
public readonly string Icon = null;
public readonly string[] AlternateName = { };
public object Create(ActorInitializer init) { return new Tooltip(); }
}
public class BuildableInfo : ITraitInfo
{
[ActorReference]
public readonly string[] Prerequisites = { };
[ActorReference]
public readonly string[] BuiltAt = { };
public readonly string[] Owner = { };
public readonly string Queue;
public readonly bool Hidden = false;
// todo: UI fluff; doesn't belong here
public readonly int BuildPaletteOrder = 9999;
public readonly string Hotkey = null;
public object Create(ActorInitializer init) { return new Buildable(); }
}
class Valued { }
class Buildable { }
class Tooltip { }
}

View File

@@ -1,85 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using System;
using OpenRA.FileFormats;
using OpenRA.Network;
namespace OpenRA.Traits
{
public class MPStartLocationsInfo : TraitInfo<MPStartLocations>
{
public readonly int InitialExploreRange = 5;
}
public class MPStartLocations : IWorldLoaded
{
public Dictionary<Player, int2> Start = new Dictionary<Player, int2>();
public void WorldLoaded(World world)
{
var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
var available = world.Map.SpawnPoints.Except(taken).ToList();
// Set spawn
foreach (var slot in Game.LobbyInfo.Slots)
{
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
var player = FindPlayerInSlot(world, slot);
if (player == null) continue;
var spid = (client == null || client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken)
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1);
Start.Add(player, spid);
}
// Explore allied shroud
foreach (var p in Start)
if (p.Key == world.LocalPlayer || p.Key.Stances[world.LocalPlayer] == Stance.Ally)
world.WorldActor.Trait<Shroud>().Explore(world, p.Value,
world.WorldActor.Info.Traits.Get<MPStartLocationsInfo>().InitialExploreRange);
// Set viewport
if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer))
Game.viewport.Center(Start[world.LocalPlayer]);
}
static Player FindPlayerInSlot(World world, Session.Slot slot)
{
return world.players.Values.FirstOrDefault(p => p.PlayerRef.Name == slot.MapPlayer);
}
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken)
{
if (available.Count == 0)
throw new InvalidOperationException("No free spawnpoint.");
var n = taken.Count == 0
? world.SharedRandom.Next(available.Count)
: available // pick the most distant spawnpoint from everyone else
.Select((k, i) => Pair.New(k, i))
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
.Select(a => a.Second)
.First();
var sp = available[n];
available.RemoveAt(n);
taken.Add(sp);
return sp;
}
}
}

View File

@@ -1,39 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System.Linq;
namespace OpenRA.Traits
{
public class ProvidesRadarInfo : TraitInfo<ProvidesRadar> { }
public class ProvidesRadar : ITick
{
public bool IsActive { get; private set; }
public void Tick(Actor self) { IsActive = UpdateActive(self); }
bool UpdateActive(Actor self)
{
// Check if powered
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled))
return false;
var isJammed = self.World.Queries.WithTrait<JamsRadar>().Any(a => self.Owner != a.Actor.Owner
&& (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<JamsRadarInfo>().Range);
return !isJammed;
}
}
class JamsRadarInfo : TraitInfo<JamsRadar> { public readonly int Range = 0; }
class JamsRadar { }
}

0
OpenRA.Game/Traits/SharesCell.cs Normal file → Executable file
View File

View File

@@ -1,147 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System.Linq;
namespace OpenRA.Traits
{
public abstract class SupportPowerInfo : ITraitInfo, ITraitPrerequisite<TechTreeInfo>, ITraitPrerequisite<PowerManagerInfo>
{
public readonly bool RequiresPower = true;
public readonly bool OneShot = false;
public readonly float ChargeTime = 0;
public readonly string Image = null;
public readonly string Description = "";
public readonly string LongDesc = "";
[ActorReference]
public readonly string[] Prerequisites = { };
public readonly bool GivenAuto = true;
public readonly string OrderName;
public readonly string BeginChargeSound = null;
public readonly string EndChargeSound = null;
public readonly string SelectTargetSound = null;
public readonly string LaunchSound = null;
public abstract object Create(ActorInitializer init);
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
}
public class SupportPower : ITick, ITechTreeElement
{
public readonly SupportPowerInfo Info;
public int RemainingTime { get; private set; }
public int TotalTime { get { return (int)(Info.ChargeTime * 60 * 25); } }
public bool IsUsed;
public bool IsAvailable;
public bool IsReady { get { return IsAvailable && RemainingTime == 0; } }
protected readonly Actor Self;
protected readonly Player Owner;
bool notifiedCharging;
bool notifiedReady;
readonly PowerManager PlayerPower;
public SupportPower(Actor self, SupportPowerInfo info)
{
Info = info;
RemainingTime = TotalTime;
Self = self;
Owner = self.Owner;
PlayerPower = self.Trait<PowerManager>();
self.Trait<TechTree>().Add( Info.OrderName, Info.Prerequisites.Select( a => a.ToLowerInvariant() ).ToList(), this );
}
public void Tick(Actor self)
{
if (Info.OneShot && IsUsed)
return;
if (Info.GivenAuto)
IsAvailable = hasPrerequisites;
if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal))
{
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0;
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
Sound.PlayToPlayer(Owner, Info.BeginChargeSound);
OnBeginCharging();
notifiedCharging = true;
}
}
if (RemainingTime == 0
&& !notifiedReady)
{
Sound.PlayToPlayer(Owner, Info.EndChargeSound);
OnFinishCharging();
notifiedReady = true;
}
}
public void FinishActivate()
{
if (Info.OneShot)
{
IsUsed = true;
IsAvailable = false;
}
RemainingTime = TotalTime;
notifiedReady = false;
notifiedCharging = false;
}
public void Give(float charge)
{
IsAvailable = true;
IsUsed = false;
RemainingTime = (int)(charge * TotalTime);
}
protected virtual void OnBeginCharging() { }
protected virtual void OnFinishCharging() { }
protected virtual void OnActivate() { }
public void Activate()
{
if (!IsAvailable || !IsReady)
return;
if (Info.RequiresPower && PlayerPower.PowerState != PowerState.Normal)
{
var eva = Owner.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.AbilityInsufficientPower);
return;
}
Sound.PlayToPlayer(Owner, Info.SelectTargetSound);
OnActivate();
}
bool hasPrerequisites;
public void PrerequisitesAvailable(string key)
{
hasPrerequisites = true;
}
public void PrerequisitesUnavailable(string key)
{
hasPrerequisites = false;
}
}
}

View File

@@ -1,43 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
namespace OpenRA.Traits
{
public class TurretedInfo : ITraitInfo
{
public readonly int ROT = 255;
public readonly int InitialFacing = 128;
public object Create(ActorInitializer init) { return new Turreted(init, this); }
}
public class Turreted : ITick
{
[Sync]
public int turretFacing = 0;
public int? desiredFacing;
TurretedInfo info;
IFacing facing;
public Turreted(ActorInitializer init, TurretedInfo info)
{
this.info = info;
turretFacing = info.InitialFacing;
turretFacing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
facing = init.self.TraitOrDefault<IFacing>();
}
public void Tick( Actor self )
{
var df = desiredFacing ?? ( facing != null ? facing.Facing : turretFacing );
turretFacing = Util.TickFacing(turretFacing, df, info.ROT);
}
}
}

23
OpenRA.Game/Traits/Valued.cs Executable file
View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRA.Traits
{
public class ValuedInfo : TraitInfo<Valued>
{
public readonly int Cost = 0;
}
public class TooltipInfo : TraitInfo<Tooltip>
{
public readonly string Description = "";
public readonly string Name = "";
public readonly string Icon = null;
public readonly string[] AlternateName = { };
}
public class Valued { }
public class Tooltip { }
}

0
OpenRA.Game/Traits/World/BibLayer.cs Normal file → Executable file
View File

View File

@@ -1,92 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using System.Collections.Generic;
namespace OpenRA.Traits
{
public class SmudgeLayerInfo : ITraitInfo
{
public readonly string Type = "Scorch";
public readonly string[] Types = {"sc1", "sc2", "sc3", "sc4", "sc5", "sc6"};
public readonly int[] Depths = {1,1,1,1,1,1};
public object Create(ActorInitializer init) { return new SmudgeLayer(this); }
}
public class SmudgeLayer: IRenderOverlay, IWorldLoaded
{
public SmudgeLayerInfo Info;
Dictionary<int2,TileReference<byte,byte>> tiles;
Sprite[][] smudgeSprites;
World world;
public SmudgeLayer(SmudgeLayerInfo info)
{
this.Info = info;
smudgeSprites = Info.Types.Select(x => SpriteSheetBuilder.LoadAllSprites(x)).ToArray();
}
public void WorldLoaded(World w)
{
world = w;
tiles = new Dictionary<int2,TileReference<byte,byte>>();
// Add map smudges
foreach (var s in w.Map.Smudges.Where( s => Info.Types.Contains(s.Type )))
tiles.Add(s.Location,new TileReference<byte,byte>((byte)Array.IndexOf(Info.Types,s.Type),
(byte)s.Depth));
}
public void AddSmudge(int2 loc)
{
if (!world.GetTerrainInfo(loc).AcceptSmudge)
return;
// No smudge; create a new one
if (!tiles.ContainsKey(loc))
{
byte st = (byte)(1 + world.SharedRandom.Next(Info.Types.Length - 1));
tiles.Add(loc, new TileReference<byte,byte>(st,(byte)0));
return;
}
var tile = tiles[loc];
// Existing smudge; make it deeper
int depth = Info.Depths[tile.type-1];
if (tile.image < depth - 1)
{
tile.image++;
tiles[loc] = tile; // struct semantics.
}
}
public void Render()
{
var cliprect = Game.viewport.ShroudBounds().HasValue
? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds;
cliprect = Rectangle.Intersect(Game.viewport.ViewBounds(), cliprect);
foreach (var kv in tiles)
{
if (!cliprect.Contains(kv.Key.X,kv.Key.Y))
continue;
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(kv.Key))
continue;
Game.Renderer.SpriteRenderer.DrawSprite(smudgeSprites[kv.Value.type- 1][kv.Value.image],
Game.CellSize * kv.Key, "terrain");
}
}
}
}