split WithActiveAnimation from SeedsResource

closes #5300
This commit is contained in:
Matthias Mailänder
2014-07-03 12:57:55 +02:00
parent 59dcd297f5
commit 69209cd340
7 changed files with 101 additions and 33 deletions

View File

@@ -520,6 +520,7 @@
<Compile Include="Render\WithMakeAnimation.cs" />
<Compile Include="Widgets\Logic\InstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\InstallMusicLogic.cs" />
<Compile Include="Render\WithActiveAnimation.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View 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;
}
}
}

View File

@@ -17,47 +17,49 @@ using OpenRA.Traits;
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 string ResourceType = "Ore";
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
{
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 animationTicks;
public void Tick(Actor self)
{
if (--ticks <= 0)
{
Seed(self);
ticks = self.Info.Traits.Get<SeedsResourceInfo>().Interval;
}
if (--animationTicks <= 0)
{
var info = self.Info.Traits.Get<SeedsResourceInfo>();
self.Trait<RenderBuilding>().PlayCustomAnim(self, "active");
animationTicks = info.AnimationInterval;
ticks = info.Interval;
}
}
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)
.Take(info.MaxRange)
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p))

View File

@@ -3,6 +3,7 @@ SPLIT2:
SeedsResource:
ResourceType: Tiberium
Interval: 55
WithActiveAnimation:
SPLIT3:
Inherits: ^TibTree
@@ -11,6 +12,7 @@ SPLIT3:
SeedsResource:
ResourceType: Tiberium
Interval: 55
WithActiveAnimation:
SPLITBLUE:
Inherits: ^TibTree
@@ -19,6 +21,7 @@ SPLITBLUE:
SeedsResource:
ResourceType: BlueTiberium
Interval: 110
WithActiveAnimation:
Tooltip:
Name: Blossom Tree (blue)
RadarColorFromTerrain:

View File

@@ -113,6 +113,7 @@ SPICEBLOOM:
SeedsResource:
ResourceType: Spice
Interval: 75
WithActiveAnimation:
RadarColorFromTerrain:
Terrain: Spice
BodyOrientation:

View File

@@ -223,18 +223,6 @@ t01:
Length: 8
Tick: 80
mine:
idle:
Start: 0
active:
Start: 0
railmine:
idle:
Start: 0
active:
Start: 0
v01:
idle:
Start: 0

View File

@@ -608,3 +608,11 @@ craters:
Length: *
cr6: cr6
Length: *
mine:
idle:
Start: 0
railmine:
idle:
Start: 0