@@ -520,6 +520,7 @@
|
|||||||
<Compile Include="Render\WithMakeAnimation.cs" />
|
<Compile Include="Render\WithMakeAnimation.cs" />
|
||||||
<Compile Include="Widgets\Logic\InstallFromCDLogic.cs" />
|
<Compile Include="Widgets\Logic\InstallFromCDLogic.cs" />
|
||||||
<Compile Include="Widgets\Logic\InstallMusicLogic.cs" />
|
<Compile Include="Widgets\Logic\InstallMusicLogic.cs" />
|
||||||
|
<Compile Include="Render\WithActiveAnimation.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
|
||||||
|
|||||||
65
OpenRA.Mods.RA/Render/WithActiveAnimation.cs
Normal file
65
OpenRA.Mods.RA/Render/WithActiveAnimation.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#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.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Render
|
||||||
|
{
|
||||||
|
[Desc("Replaces the idle animation of a building.")]
|
||||||
|
public class WithActiveAnimationInfo : ITraitInfo, Requires<RenderBuildingInfo>
|
||||||
|
{
|
||||||
|
[Desc("Sequence name to use")]
|
||||||
|
public readonly string Sequence = "active";
|
||||||
|
|
||||||
|
public readonly int Interval = 750;
|
||||||
|
|
||||||
|
public readonly bool PauseOnLowPower = false;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new WithActiveAnimation(init.self, this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WithActiveAnimation : ITickRender, INotifyBuildComplete
|
||||||
|
{
|
||||||
|
readonly IEnumerable<IDisable> disabled;
|
||||||
|
readonly WithActiveAnimationInfo info;
|
||||||
|
readonly RenderBuilding renderBuilding;
|
||||||
|
|
||||||
|
public WithActiveAnimation(Actor self, WithActiveAnimationInfo info)
|
||||||
|
{
|
||||||
|
disabled = self.TraitsImplementing<IDisable>();
|
||||||
|
renderBuilding = self.Trait<RenderBuilding>();
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ticks;
|
||||||
|
public void TickRender(WorldRenderer wr, Actor self)
|
||||||
|
{
|
||||||
|
if (!buildComplete)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (--ticks <= 0)
|
||||||
|
{
|
||||||
|
if (!(info.PauseOnLowPower && disabled.Any(d => d.Disabled)))
|
||||||
|
renderBuilding.PlayCustomAnim(self, info.Sequence);
|
||||||
|
ticks = info.Interval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool buildComplete = false;
|
||||||
|
|
||||||
|
public void BuildingComplete(Actor self)
|
||||||
|
{
|
||||||
|
buildComplete = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,47 +17,49 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class SeedsResourceInfo : TraitInfo<SeedsResource>
|
[Desc("Lets the actor spread resources around it in a circle.")]
|
||||||
|
class SeedsResourceInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly int Interval = 75;
|
public readonly int Interval = 75;
|
||||||
public readonly string ResourceType = "Ore";
|
public readonly string ResourceType = "Ore";
|
||||||
public readonly int MaxRange = 100;
|
public readonly int MaxRange = 100;
|
||||||
public readonly int AnimationInterval = 750;
|
|
||||||
|
public object Create(ActorInitializer init) { return new SeedsResource(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class SeedsResource : ITick, ISeedableResource
|
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;
|
int ticks;
|
||||||
int animationTicks;
|
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (--ticks <= 0)
|
if (--ticks <= 0)
|
||||||
{
|
{
|
||||||
Seed(self);
|
Seed(self);
|
||||||
ticks = self.Info.Traits.Get<SeedsResourceInfo>().Interval;
|
ticks = info.Interval;
|
||||||
}
|
|
||||||
|
|
||||||
if (--animationTicks <= 0)
|
|
||||||
{
|
|
||||||
var info = self.Info.Traits.Get<SeedsResourceInfo>();
|
|
||||||
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
|
|
||||||
animationTicks = info.AnimationInterval;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Seed(Actor self)
|
public void Seed(Actor self)
|
||||||
{
|
{
|
||||||
var info = self.Info.Traits.Get<SeedsResourceInfo>();
|
|
||||||
var 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));
|
|
||||||
|
|
||||||
var resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
|
||||||
|
|
||||||
var cell = RandomWalk(self.Location, self.World.SharedRandom)
|
var cell = RandomWalk(self.Location, self.World.SharedRandom)
|
||||||
.Take(info.MaxRange)
|
.Take(info.MaxRange)
|
||||||
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p))
|
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ SPLIT2:
|
|||||||
SeedsResource:
|
SeedsResource:
|
||||||
ResourceType: Tiberium
|
ResourceType: Tiberium
|
||||||
Interval: 55
|
Interval: 55
|
||||||
|
WithActiveAnimation:
|
||||||
|
|
||||||
SPLIT3:
|
SPLIT3:
|
||||||
Inherits: ^TibTree
|
Inherits: ^TibTree
|
||||||
@@ -11,6 +12,7 @@ SPLIT3:
|
|||||||
SeedsResource:
|
SeedsResource:
|
||||||
ResourceType: Tiberium
|
ResourceType: Tiberium
|
||||||
Interval: 55
|
Interval: 55
|
||||||
|
WithActiveAnimation:
|
||||||
|
|
||||||
SPLITBLUE:
|
SPLITBLUE:
|
||||||
Inherits: ^TibTree
|
Inherits: ^TibTree
|
||||||
@@ -19,6 +21,7 @@ SPLITBLUE:
|
|||||||
SeedsResource:
|
SeedsResource:
|
||||||
ResourceType: BlueTiberium
|
ResourceType: BlueTiberium
|
||||||
Interval: 110
|
Interval: 110
|
||||||
|
WithActiveAnimation:
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Blossom Tree (blue)
|
Name: Blossom Tree (blue)
|
||||||
RadarColorFromTerrain:
|
RadarColorFromTerrain:
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ SPICEBLOOM:
|
|||||||
SeedsResource:
|
SeedsResource:
|
||||||
ResourceType: Spice
|
ResourceType: Spice
|
||||||
Interval: 75
|
Interval: 75
|
||||||
|
WithActiveAnimation:
|
||||||
RadarColorFromTerrain:
|
RadarColorFromTerrain:
|
||||||
Terrain: Spice
|
Terrain: Spice
|
||||||
BodyOrientation:
|
BodyOrientation:
|
||||||
|
|||||||
@@ -223,18 +223,6 @@ t01:
|
|||||||
Length: 8
|
Length: 8
|
||||||
Tick: 80
|
Tick: 80
|
||||||
|
|
||||||
mine:
|
|
||||||
idle:
|
|
||||||
Start: 0
|
|
||||||
active:
|
|
||||||
Start: 0
|
|
||||||
|
|
||||||
railmine:
|
|
||||||
idle:
|
|
||||||
Start: 0
|
|
||||||
active:
|
|
||||||
Start: 0
|
|
||||||
|
|
||||||
v01:
|
v01:
|
||||||
idle:
|
idle:
|
||||||
Start: 0
|
Start: 0
|
||||||
|
|||||||
@@ -608,3 +608,11 @@ craters:
|
|||||||
Length: *
|
Length: *
|
||||||
cr6: cr6
|
cr6: cr6
|
||||||
Length: *
|
Length: *
|
||||||
|
|
||||||
|
mine:
|
||||||
|
idle:
|
||||||
|
Start: 0
|
||||||
|
|
||||||
|
railmine:
|
||||||
|
idle:
|
||||||
|
Start: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user