add cloak crate action to cnc

This commit is contained in:
Chris Forbes
2010-08-01 00:21:20 +12:00
parent 2c73d8a48d
commit 765bedb592
4 changed files with 72 additions and 8 deletions

View File

@@ -10,20 +10,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class CloakInfo : ITraitInfo
public class CloakInfo : ITraitInfo
{
public readonly float InitialDelay = .4f; // seconds
public readonly float CloakDelay = 1.2f; // Seconds
public readonly string CloakSound = "subshow1.aud";
public readonly string UncloakSound = "subshow1.aud";
public object Create(ActorInitializer init) { return new Cloak(init.self); }
public CloakInfo() { } /* only because we have other ctors */
/* for CloakCrateAction */
public CloakInfo(float initialDelay, float cloakDelay, string cloakSound, string uncloakSound)
{
InitialDelay = initialDelay;
CloakDelay = cloakDelay;
CloakSound = cloakSound;
UncloakSound = uncloakSound;
}
public object Create(ActorInitializer init) { return new Cloak(init.self, this); }
}
public class Cloak : IRenderModifier, INotifyAttack, ITick, INotifyDamage, IVisibilityModifier, IRadarColorModifier
@@ -32,10 +43,13 @@ namespace OpenRA.Mods.RA
int remainingTime;
Actor self;
public Cloak(Actor self)
CloakInfo info;
public Cloak(Actor self, CloakInfo info)
{
remainingTime = (int)(self.Info.Traits.Get<CloakInfo>().InitialDelay * 25);
this.info = info;
this.self = self;
remainingTime = (int)(info.InitialDelay * 25);
}
void DoSurface()
@@ -43,7 +57,7 @@ namespace OpenRA.Mods.RA
if (remainingTime <= 0)
OnSurface();
remainingTime = Math.Max(remainingTime, (int)(self.Info.Traits.Get<CloakInfo>().CloakDelay * 25));
remainingTime = Math.Max(remainingTime, (int)(info.CloakDelay * 25));
}
public void Attacking(Actor self) { DoSurface(); }
@@ -70,12 +84,12 @@ namespace OpenRA.Mods.RA
void OnSurface()
{
Sound.Play(self.Info.Traits.Get<CloakInfo>().UncloakSound, self.CenterLocation);
Sound.Play(info.UncloakSound, self.CenterLocation);
}
void OnDive()
{
Sound.Play(self.Info.Traits.Get<CloakInfo>().CloakSound, self.CenterLocation);
Sound.Play(info.CloakSound, self.CenterLocation);
}
public bool Cloaked { get { return remainingTime == 0; } }

View File

@@ -0,0 +1,47 @@
#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.Mods.RA.Crates
{
class CloakCrateActionInfo : CrateActionInfo
{
public readonly float InitialDelay = .4f;
public readonly float CloakDelay = 1.2f;
public readonly string CloakSound = "subshow1.aud";
public readonly string UncloakSound = "subshow1.aud";
public override object Create(ActorInitializer init) { return new CloakCrateAction(init.self, this); }
}
class CloakCrateAction : CrateAction
{
CloakCrateActionInfo Info;
public CloakCrateAction(Actor self, CloakCrateActionInfo info)
: base(self, info) { Info = info; }
public override int GetSelectionShares(Actor collector)
{
return collector.traits.Contains<Cloak>()
? 0 : base.GetSelectionShares(collector);
}
public override void Activate(Actor collector)
{
var cloakInfo = new CloakInfo(Info.InitialDelay, Info.CloakDelay,
Info.CloakSound, Info.UncloakSound);
var cloak = cloakInfo.Create(new ActorInitializer(collector, collector.Location));
collector.World.AddFrameEndTask(w => collector.traits.Add(cloak));
base.Activate(collector);
}
}
}

View File

@@ -78,6 +78,7 @@
<Compile Include="Activities\Wait.cs" />
<Compile Include="AttackBase.cs" />
<Compile Include="Combat.cs" />
<Compile Include="Crates\CloakCrateAction.cs" />
<Compile Include="Crates\GiveMcvCrateAction.cs" />
<Compile Include="Crates\GiveUnitCrateAction.cs" />
<Compile Include="DetectCloaked.cs" />

View File

@@ -156,6 +156,8 @@ CRATE:
HideMapCrateAction:
SelectionShares: 5
Effect: hide-map
CloakCrateAction:
SelectionShares: 1000
Unit:
RenderUnit:
BelowUnits: