Move Targetable*, Seeds/StoresResource(s) and two RenderBuilding traits to Mods.Common
This commit is contained in:
@@ -143,7 +143,6 @@
|
||||
<Compile Include="Traits\MadTank.cs" />
|
||||
<Compile Include="Traits\Mine.cs" />
|
||||
<Compile Include="Traits\Minelayer.cs" />
|
||||
<Compile Include="Traits\SeedsResource.cs" />
|
||||
<Compile Include="Orders\PlaceBuildingOrderGenerator.cs" />
|
||||
<Compile Include="Orders\GlobalButtonOrderGenerator.cs" />
|
||||
<Compile Include="Orders\RepairOrderGenerator.cs" />
|
||||
@@ -161,8 +160,6 @@
|
||||
<Compile Include="RenderDetectionCircle.cs" />
|
||||
<Compile Include="RenderJammerCircle.cs" />
|
||||
<Compile Include="RenderRangeCircle.cs" />
|
||||
<Compile Include="Render\RenderBuildingSilo.cs" />
|
||||
<Compile Include="Render\RenderBuildingWall.cs" />
|
||||
<Compile Include="Render\RenderBuildingWarFactory.cs" />
|
||||
<Compile Include="Render\RenderHarvester.cs" />
|
||||
<Compile Include="Render\RenderDisguise.cs" />
|
||||
@@ -170,7 +167,6 @@
|
||||
<Compile Include="Repairable.cs" />
|
||||
<Compile Include="RepairableNear.cs" />
|
||||
<Compile Include="Disguise.cs" />
|
||||
<Compile Include="StoresResources.cs" />
|
||||
<Compile Include="Traits\SupplyTruck.cs" />
|
||||
<Compile Include="SupportPowers\AirstrikePower.cs" />
|
||||
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
|
||||
@@ -182,20 +178,17 @@
|
||||
<Compile Include="SupportPowers\SupportPowerManager.cs" />
|
||||
<Compile Include="ThrowsParticle.cs" />
|
||||
<Compile Include="TraitsInterfaces.cs" />
|
||||
<Compile Include="Traits\Air\TargetableAircraft.cs" />
|
||||
<Compile Include="Traits\Buildings\Bridge.cs" />
|
||||
<Compile Include="Traits\Buildings\BridgeHut.cs" />
|
||||
<Compile Include="Traits\Buildings\Fake.cs" />
|
||||
<Compile Include="Traits\Buildings\OreRefinery.cs" />
|
||||
<Compile Include="Traits\Buildings\PrimaryBuilding.cs" />
|
||||
<Compile Include="Traits\Buildings\RepairableBuilding.cs" />
|
||||
<Compile Include="Traits\Buildings\TargetableBuilding.cs" />
|
||||
<Compile Include="Traits\Harvester.cs" />
|
||||
<Compile Include="Traits\HarvesterHuskModifier.cs" />
|
||||
<Compile Include="Traits\LeavesHusk.cs" />
|
||||
<Compile Include="Traits\RepairsBridges.cs" />
|
||||
<Compile Include="Traits\TargetableSubmarine.cs" />
|
||||
<Compile Include="Traits\TargetableUnit.cs" />
|
||||
<Compile Include="Traits\World\BridgeLayer.cs" />
|
||||
<Compile Include="TransformOnCapture.cs" />
|
||||
<Compile Include="TransformOnPassenger.cs" />
|
||||
|
||||
@@ -1,59 +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.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class RenderBuildingSiloInfo : RenderBuildingInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingSilo(init, this); }
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
// Show a static frame instead of animating all of the fullness states
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex("idle", () => 0);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderBuildingSilo : RenderBuilding, INotifyBuildComplete, INotifyOwnerChanged
|
||||
{
|
||||
PlayerResources playerResources;
|
||||
|
||||
public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
|
||||
public override void BuildingComplete(Actor self)
|
||||
{
|
||||
var animation = (self.GetDamageState() >= DamageState.Heavy) ? "damaged-idle" : "idle";
|
||||
|
||||
DefaultAnimation.PlayFetchIndex(animation,
|
||||
() => playerResources.ResourceCapacity != 0
|
||||
? ((10 * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity)
|
||||
: 0);
|
||||
}
|
||||
|
||||
public override void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||
base.OnOwnerChanged(self, oldOwner, newOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class RenderBuildingWallInfo : RenderBuildingInfo
|
||||
{
|
||||
public readonly string Type = "wall";
|
||||
public readonly string Sequence = "idle";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new RenderBuildingWall(init, this); }
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
// Show a static frame instead of animating all of the wall states
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex("idle", () => 0);
|
||||
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderBuildingWall : RenderBuilding, INotifyAddedToWorld, INotifyRemovedFromWorld
|
||||
{
|
||||
readonly RenderBuildingWallInfo info;
|
||||
int adjacent = 0;
|
||||
bool dirty = true;
|
||||
|
||||
public RenderBuildingWall(ActorInitializer init, RenderBuildingWallInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void BuildingComplete(Actor self)
|
||||
{
|
||||
DefaultAnimation.PlayFetchIndex(info.Sequence, () => adjacent);
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
|
||||
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
DefaultAnimation.PlayFetchIndex(NormalizeSequence(DefaultAnimation, e.DamageState, info.Sequence), () => adjacent);
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
|
||||
if (!dirty)
|
||||
return;
|
||||
|
||||
// Update connection to neighbours
|
||||
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
||||
self.World.ActorMap.GetUnitsAt(self.Location + dir));
|
||||
|
||||
adjacent = 0;
|
||||
foreach (var a in adjacentActors)
|
||||
{
|
||||
var rb = a.TraitOrDefault<RenderBuildingWall>();
|
||||
if (rb == null || rb.info.Type != info.Type)
|
||||
continue;
|
||||
|
||||
var location = self.Location;
|
||||
var otherLocation = a.Location;
|
||||
|
||||
if (otherLocation == location + new CVec(0, -1))
|
||||
adjacent |= 1;
|
||||
else if (otherLocation == location + new CVec(+1, 0))
|
||||
adjacent |= 2;
|
||||
else if (otherLocation == location + new CVec(0, +1))
|
||||
adjacent |= 4;
|
||||
else if (otherLocation == location + new CVec(-1, 0))
|
||||
adjacent |= 8;
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
static void UpdateNeighbours(Actor self)
|
||||
{
|
||||
var adjacentActors = CVec.Directions.SelectMany(dir =>
|
||||
self.World.ActorMap.GetUnitsAt(self.Location + dir))
|
||||
.Select(a => a.TraitOrDefault<RenderBuildingWall>())
|
||||
.Where(a => a != null);
|
||||
|
||||
foreach (var rb in adjacentActors)
|
||||
rb.dirty = true;
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
{
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
|
||||
public void RemovedFromWorld(Actor self)
|
||||
{
|
||||
UpdateNeighbours(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
[Desc("Used for silos.")]
|
||||
class StoresResourcesInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Number of little squares used to display how filled unit is.")]
|
||||
public readonly int PipCount = 0;
|
||||
public readonly PipType PipColor = PipType.Yellow;
|
||||
public readonly int Capacity = 0;
|
||||
public object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
|
||||
}
|
||||
|
||||
class StoresResources : IPips, INotifyOwnerChanged, INotifyCapture, INotifyKilled, IExplodeModifier, IStoreResources, ISync
|
||||
{
|
||||
readonly StoresResourcesInfo info;
|
||||
|
||||
[Sync] public int Stored { get { return player.ResourceCapacity == 0 ? 0 : info.Capacity * player.Resources / player.ResourceCapacity; } }
|
||||
|
||||
PlayerResources player;
|
||||
public StoresResources(Actor self, StoresResourcesInfo info)
|
||||
{
|
||||
player = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public int Capacity { get { return info.Capacity; } }
|
||||
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
player = newOwner.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
var resources = Stored;
|
||||
oldOwner.PlayerActor.Trait<PlayerResources>().TakeResources(resources);
|
||||
newOwner.PlayerActor.Trait<PlayerResources>().GiveResources(resources);
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
player.TakeResources(Stored); // lose the stored resources
|
||||
}
|
||||
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
return Enumerable.Range(0, info.PipCount).Select(i =>
|
||||
player.Resources * info.PipCount > i * player.ResourceCapacity
|
||||
? info.PipColor : PipType.Transparent);
|
||||
}
|
||||
|
||||
public bool ShouldExplode(Actor self) { return Stored > 0; }
|
||||
}
|
||||
}
|
||||
@@ -1,41 +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.Collections.Generic;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class TargetableAircraftInfo : TargetableUnitInfo
|
||||
{
|
||||
public readonly string[] GroundedTargetTypes = { };
|
||||
public override object Create(ActorInitializer init) { return new TargetableAircraft(init.Self, this); }
|
||||
}
|
||||
|
||||
public class TargetableAircraft : TargetableUnit
|
||||
{
|
||||
readonly TargetableAircraftInfo info;
|
||||
readonly Actor self;
|
||||
|
||||
public TargetableAircraft(Actor self, TargetableAircraftInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
public override string[] TargetTypes
|
||||
{
|
||||
get { return (self.CenterPosition.Z > 0) ? info.TargetTypes
|
||||
: info.GroundedTargetTypes; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class TargetableBuildingInfo : ITraitInfo, ITargetableInfo, Requires<BuildingInfo>
|
||||
{
|
||||
public readonly string[] TargetTypes = { };
|
||||
public string[] GetTargetTypes() { return TargetTypes; }
|
||||
|
||||
public bool RequiresForceFire = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new TargetableBuilding(init.Self, this); }
|
||||
}
|
||||
|
||||
public class TargetableBuilding : ITargetable
|
||||
{
|
||||
readonly TargetableBuildingInfo info;
|
||||
readonly Building building;
|
||||
|
||||
public TargetableBuilding(Actor self, TargetableBuildingInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
building = self.Trait<Building>();
|
||||
}
|
||||
|
||||
public string[] TargetTypes { get { return info.TargetTypes; } }
|
||||
public bool TargetableBy(Actor self, Actor byActor) { return true; }
|
||||
|
||||
public IEnumerable<WPos> TargetablePositions(Actor self)
|
||||
{
|
||||
return building.OccupiedCells().Select(c => self.World.Map.CenterOfCell(c.First));
|
||||
}
|
||||
|
||||
public bool RequiresForceFire { get { return info.RequiresForceFire; } }
|
||||
}
|
||||
}
|
||||
@@ -1,87 +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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Lets the actor spread resources around it in a circle.")]
|
||||
class SeedsResourceInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Interval = 75;
|
||||
public readonly string ResourceType = "Ore";
|
||||
public readonly int MaxRange = 100;
|
||||
|
||||
public object Create(ActorInitializer init) { return new SeedsResource(init.Self, this); }
|
||||
}
|
||||
|
||||
class SeedsResource : ITick, ISeedableResource
|
||||
{
|
||||
readonly SeedsResourceInfo info;
|
||||
|
||||
readonly ResourceType resourceType;
|
||||
readonly ResourceLayer resLayer;
|
||||
|
||||
public SeedsResource(Actor self, SeedsResourceInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
resourceType = self.World.WorldActor.TraitsImplementing<ResourceType>()
|
||||
.FirstOrDefault(t => t.Info.Name == info.ResourceType);
|
||||
|
||||
if (resourceType == null)
|
||||
throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType));
|
||||
|
||||
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
}
|
||||
|
||||
int ticks;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
Seed(self);
|
||||
ticks = info.Interval;
|
||||
}
|
||||
}
|
||||
|
||||
public void Seed(Actor self)
|
||||
{
|
||||
var cell = RandomWalk(self.Location, self.World.SharedRandom)
|
||||
.Take(info.MaxRange)
|
||||
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p))
|
||||
.Cast<CPos?>().FirstOrDefault();
|
||||
|
||||
if (cell != null && resLayer.CanSpawnResourceAt(resourceType, cell.Value))
|
||||
resLayer.AddResource(resourceType, cell.Value, 1);
|
||||
}
|
||||
|
||||
static IEnumerable<CPos> RandomWalk(CPos p, MersenneTwister r)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
var dx = r.Next(-1, 2);
|
||||
var dy = r.Next(-1, 2);
|
||||
|
||||
if (dx == 0 && dy == 0)
|
||||
continue;
|
||||
|
||||
p += new CVec(dx, dy);
|
||||
yield return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +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.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
[Desc("Actor can be targeted.")]
|
||||
public class TargetableUnitInfo : ITraitInfo, ITargetableInfo
|
||||
{
|
||||
[Desc("Target type. Used for filtering (in)valid targets.")]
|
||||
public readonly string[] TargetTypes = { };
|
||||
public string[] GetTargetTypes() { return TargetTypes; }
|
||||
|
||||
public bool RequiresForceFire = false;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new TargetableUnit(init.Self, this); }
|
||||
}
|
||||
|
||||
public class TargetableUnit : ITargetable
|
||||
{
|
||||
readonly TargetableUnitInfo info;
|
||||
protected Cloak cloak;
|
||||
|
||||
public TargetableUnit(Actor self, TargetableUnitInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
cloak = self.TraitOrDefault<Cloak>();
|
||||
}
|
||||
|
||||
public virtual bool TargetableBy(Actor self, Actor viewer)
|
||||
{
|
||||
if (cloak == null || !cloak.Cloaked)
|
||||
return true;
|
||||
|
||||
return cloak.IsVisible(self, viewer.Owner);
|
||||
}
|
||||
|
||||
public virtual string[] TargetTypes { get { return info.TargetTypes; } }
|
||||
|
||||
public virtual IEnumerable<WPos> TargetablePositions(Actor self)
|
||||
{
|
||||
yield return self.CenterPosition;
|
||||
}
|
||||
|
||||
public bool RequiresForceFire { get { return info.RequiresForceFire; } }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user