tidy up some bizarre namespacing

This commit is contained in:
Chris Forbes
2011-11-04 20:10:28 +13:00
parent cbee1513f3
commit cd155b21c9
10 changed files with 28 additions and 33 deletions

View File

@@ -10,7 +10,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{

View File

@@ -19,16 +19,17 @@ namespace OpenRA.Mods.RA.Buildings
public readonly int RepairPercent = 20;
public readonly int RepairInterval = 24;
public readonly int RepairStep = 7;
public object Create(ActorInitializer init) { return new RepairableBuilding(init.self, this); }
}
public class RepairableBuilding : ITick, ISync
{
[Sync]
public Player Repairer = null;
[Sync] public Player Repairer = null;
Health Health;
RepairableBuildingInfo Info;
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
{
Health = self.Trait<Health>();
@@ -57,6 +58,7 @@ namespace OpenRA.Mods.RA.Buildings
}
int remainingTicks;
public void Tick(Actor self)
{
if (Repairer == null) return;

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Mods.RA.Buildings
class RequiresPower : IDisable, INotifyCapture
{
PowerManager power;
public RequiresPower( Actor self )
{
power = self.Owner.PlayerActor.Trait<PowerManager>();

View File

@@ -8,9 +8,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
@@ -24,6 +21,7 @@ namespace OpenRA.Mods.RA.Buildings
public class ShakeOnDeath : INotifyKilled
{
readonly ShakeOnDeathInfo Info;
public ShakeOnDeath(ShakeOnDeathInfo info)
{
this.Info = info;

View File

@@ -8,15 +8,9 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
namespace OpenRA.Mods.RA.Buildings
{
public class SoundOnDamageTransitionInfo : ITraitInfo
{
@@ -29,6 +23,7 @@ namespace OpenRA.Mods.RA.Render
public class SoundOnDamageTransition : INotifyDamageStateChanged
{
readonly SoundOnDamageTransitionInfo Info;
public SoundOnDamageTransition( SoundOnDamageTransitionInfo info )
{
Info = info;

View File

@@ -1,136 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{
public class TechTreeInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new TechTree(init);}
}
public class TechTree
{
readonly List<Watcher> watchers = new List<Watcher>();
readonly Player player;
public TechTree(ActorInitializer init)
{
player = init.self.Owner;
init.world.ActorAdded += ActorChanged;
init.world.ActorRemoved += ActorChanged;
}
public void ActorChanged(Actor a)
{
if (a.Owner == player && a.HasTrait<ITechTreePrerequisite>())
Update();
}
public void Update()
{
var buildings = GatherBuildings(player);
foreach(var w in watchers)
w.Update(buildings);
}
public void Add(string key, List<string> prerequisites, ITechTreeElement tte)
{
watchers.Add(new Watcher( key, prerequisites, tte ));
}
public void Remove(string key)
{
watchers.RemoveAll(x => x.key == key);
}
static Cache<string, List<Actor>> GatherBuildings( Player player )
{
var ret = new Cache<string, List<Actor>>( x => new List<Actor>() );
if (player == null)
return ret;
foreach (var b in player.World.ActorsWithTrait<ITechTreePrerequisite>()
.Where(a => a.Actor.IsInWorld && !a.Actor.IsDead() && a.Actor.Owner == player))
foreach (var p in b.Trait.ProvidesPrerequisites)
ret[ p ].Add( b.Actor );
return ret;
}
class Watcher
{
public readonly string key;
// strings may be either actor type, or "alternate name" key
public readonly List<string> prerequisites;
public readonly ITechTreeElement watcher;
bool hasPrerequisites;
public Watcher(string key, List<string> prerequisites, ITechTreeElement watcher)
{
this.key = key;
this.prerequisites = prerequisites;
this.watcher = watcher;
this.hasPrerequisites = false;
}
public void Update(Cache<string, List<Actor>> buildings)
{
var nowHasPrerequisites = true;
foreach (var p in prerequisites)
if (!buildings.Keys.Contains(p))
{
nowHasPrerequisites = false;
break;
}
if( nowHasPrerequisites && !hasPrerequisites )
watcher.PrerequisitesAvailable(key);
if( !nowHasPrerequisites && hasPrerequisites )
watcher.PrerequisitesUnavailable(key);
hasPrerequisites = nowHasPrerequisites;
}
}
}
public interface ITechTreeElement
{
void PrerequisitesAvailable(string key);
void PrerequisitesUnavailable(string key);
}
public interface ITechTreePrerequisite
{
IEnumerable<string> ProvidesPrerequisites {get;}
}
public class ProvidesCustomPrerequisiteInfo : ITraitInfo
{
public string Prerequisite;
public object Create(ActorInitializer init) { return new ProvidesCustomPrerequisite(this);}
}
public class ProvidesCustomPrerequisite : ITechTreePrerequisite
{
ProvidesCustomPrerequisiteInfo Info;
public IEnumerable<string> ProvidesPrerequisites { get { yield return Info.Prerequisite; } }
public ProvidesCustomPrerequisite(ProvidesCustomPrerequisiteInfo info)
{
Info = info;
}
}
}

View File

@@ -8,7 +8,6 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;