Update copyright header. Normalize line endings to LF.
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
class BibLayer: IRenderOverlay, IWorldLoaded
|
||||
{
|
||||
World world;
|
||||
BibLayerInfo info;
|
||||
BibLayerInfo info;
|
||||
Dictionary<int2, TileReference<byte, byte>> tiles;
|
||||
Sprite[][] bibSprites;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
world = w;
|
||||
world = w;
|
||||
tiles = new Dictionary<int2, TileReference<byte, byte>>();
|
||||
}
|
||||
|
||||
@@ -64,26 +64,26 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
for (int i = 0; i < 2 * size; i++)
|
||||
{
|
||||
var p = b.Location + new int2(i % size, i / size + bibOffset);
|
||||
if (isAdd)
|
||||
tiles[p] = new TileReference<byte, byte>((byte)((isAdd) ? bib + 1 : 0), (byte)i);
|
||||
else
|
||||
var p = b.Location + new int2(i % size, i / size + bibOffset);
|
||||
if (isAdd)
|
||||
tiles[p] = new TileReference<byte, byte>((byte)((isAdd) ? bib + 1 : 0), (byte)i);
|
||||
else
|
||||
tiles.Remove(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void Render( WorldRenderer wr )
|
||||
{
|
||||
{
|
||||
var cliprect = Game.viewport.WorldBounds(world);
|
||||
foreach (var kv in tiles)
|
||||
{
|
||||
if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
|
||||
continue;
|
||||
if (!world.LocalShroud.IsExplored(kv.Key))
|
||||
continue;
|
||||
|
||||
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt( wr,
|
||||
Game.CellSize * kv.Key, "terrain");
|
||||
foreach (var kv in tiles)
|
||||
{
|
||||
if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
|
||||
continue;
|
||||
if (!world.LocalShroud.IsExplored(kv.Key))
|
||||
continue;
|
||||
|
||||
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt( wr,
|
||||
Game.CellSize * kv.Key, "terrain");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
#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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class BuildingInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Power = 0;
|
||||
public readonly bool BaseNormal = true;
|
||||
public readonly bool WaterBound = false;
|
||||
public readonly int Adjacent = 2;
|
||||
public readonly bool Capturable = false;
|
||||
public readonly string Footprint = "x";
|
||||
public readonly int2 Dimensions = new int2(1, 1);
|
||||
public readonly bool Unsellable = false;
|
||||
public readonly int RefundPercent = 50;
|
||||
|
||||
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
|
||||
public readonly string[] SellSounds = {"cashturn.aud"};
|
||||
|
||||
|
||||
public object Create(ActorInitializer init) { return new Building(init, this); }
|
||||
|
||||
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft)
|
||||
{
|
||||
var buildingMaxBounds = Dimensions;
|
||||
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
|
||||
buildingMaxBounds.Y += 1;
|
||||
|
||||
var scanStart = world.ClampToWorld( topLeft - new int2( Adjacent, Adjacent ) );
|
||||
var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( Adjacent, Adjacent ) );
|
||||
|
||||
var nearnessCandidates = new List<int2>();
|
||||
|
||||
for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
|
||||
{
|
||||
for( int x = scanStart.X ; x < scanEnd.X ; x++ )
|
||||
{
|
||||
var at = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
|
||||
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get<BuildingInfo>().BaseNormal )
|
||||
nearnessCandidates.Add( new int2( x, y ) );
|
||||
}
|
||||
}
|
||||
var buildingTiles = FootprintUtils.Tiles( buildingName, this, topLeft ).ToList();
|
||||
return nearnessCandidates
|
||||
.Any( a => buildingTiles
|
||||
.Any( b => Math.Abs( a.X - b.X ) <= Adjacent
|
||||
&& Math.Abs( a.Y - b.Y ) <= Adjacent ) );
|
||||
}
|
||||
}
|
||||
|
||||
public class Building : INotifyDamage, IResolveOrder, IOccupySpace, INotifyCapture, ISync
|
||||
{
|
||||
readonly Actor self;
|
||||
public readonly BuildingInfo Info;
|
||||
[Sync]
|
||||
readonly int2 topLeft;
|
||||
|
||||
PowerManager PlayerPower;
|
||||
|
||||
public int2 PxPosition { get { return ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2; } }
|
||||
|
||||
public Building(ActorInitializer init, BuildingInfo info)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.topLeft = init.Get<LocationInit,int2>();
|
||||
this.Info = info;
|
||||
this.PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public int GetPowerUsage()
|
||||
{
|
||||
if (Info.Power <= 0)
|
||||
return Info.Power;
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
return health != null ? (Info.Power * health.HP / health.MaxHP) : Info.Power;
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
// Power plants lose power with damage
|
||||
if (Info.Power > 0)
|
||||
PlayerPower.UpdateActor(self, GetPowerUsage());
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Sell")
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Sell());
|
||||
}
|
||||
}
|
||||
|
||||
public int2 TopLeft
|
||||
{
|
||||
get { return topLeft; }
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<int2, SubCell>> OccupiedCells()
|
||||
{
|
||||
return FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft ).Select(c => Pair.New(c, SubCell.FullCell));
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class BuildingInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Power = 0;
|
||||
public readonly bool BaseNormal = true;
|
||||
public readonly bool WaterBound = false;
|
||||
public readonly int Adjacent = 2;
|
||||
public readonly bool Capturable = false;
|
||||
public readonly string Footprint = "x";
|
||||
public readonly int2 Dimensions = new int2(1, 1);
|
||||
public readonly bool Unsellable = false;
|
||||
public readonly int RefundPercent = 50;
|
||||
|
||||
public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"};
|
||||
public readonly string[] SellSounds = {"cashturn.aud"};
|
||||
|
||||
|
||||
public object Create(ActorInitializer init) { return new Building(init, this); }
|
||||
|
||||
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft)
|
||||
{
|
||||
var buildingMaxBounds = Dimensions;
|
||||
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
|
||||
buildingMaxBounds.Y += 1;
|
||||
|
||||
var scanStart = world.ClampToWorld( topLeft - new int2( Adjacent, Adjacent ) );
|
||||
var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( Adjacent, Adjacent ) );
|
||||
|
||||
var nearnessCandidates = new List<int2>();
|
||||
|
||||
for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
|
||||
{
|
||||
for( int x = scanStart.X ; x < scanEnd.X ; x++ )
|
||||
{
|
||||
var at = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
|
||||
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get<BuildingInfo>().BaseNormal )
|
||||
nearnessCandidates.Add( new int2( x, y ) );
|
||||
}
|
||||
}
|
||||
var buildingTiles = FootprintUtils.Tiles( buildingName, this, topLeft ).ToList();
|
||||
return nearnessCandidates
|
||||
.Any( a => buildingTiles
|
||||
.Any( b => Math.Abs( a.X - b.X ) <= Adjacent
|
||||
&& Math.Abs( a.Y - b.Y ) <= Adjacent ) );
|
||||
}
|
||||
}
|
||||
|
||||
public class Building : INotifyDamage, IResolveOrder, IOccupySpace, INotifyCapture, ISync
|
||||
{
|
||||
readonly Actor self;
|
||||
public readonly BuildingInfo Info;
|
||||
[Sync]
|
||||
readonly int2 topLeft;
|
||||
|
||||
PowerManager PlayerPower;
|
||||
|
||||
public int2 PxPosition { get { return ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2; } }
|
||||
|
||||
public Building(ActorInitializer init, BuildingInfo info)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.topLeft = init.Get<LocationInit,int2>();
|
||||
this.Info = info;
|
||||
this.PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public int GetPowerUsage()
|
||||
{
|
||||
if (Info.Power <= 0)
|
||||
return Info.Power;
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
return health != null ? (Info.Power * health.HP / health.MaxHP) : Info.Power;
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
// Power plants lose power with damage
|
||||
if (Info.Power > 0)
|
||||
PlayerPower.UpdateActor(self, GetPowerUsage());
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Sell")
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Sell());
|
||||
}
|
||||
}
|
||||
|
||||
public int2 TopLeft
|
||||
{
|
||||
get { return topLeft; }
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<int2, SubCell>> OccupiedCells()
|
||||
{
|
||||
return FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft ).Select(c => Pair.New(c, SubCell.FullCell));
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
#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
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class BuildingInfluenceInfo : ITraitInfo
|
||||
{
|
||||
public object Create( ActorInitializer init ) { return new BuildingInfluence( init.world ); }
|
||||
}
|
||||
|
||||
public class BuildingInfluence
|
||||
{
|
||||
Actor[,] influence;
|
||||
Map map;
|
||||
|
||||
public BuildingInfluence( World world )
|
||||
{
|
||||
map = world.Map;
|
||||
|
||||
influence = new Actor[map.MapSize.X, map.MapSize.Y];
|
||||
|
||||
world.ActorAdded +=
|
||||
a => { if (a.HasTrait<Building>())
|
||||
ChangeInfluence(a, a.Trait<Building>(), true); };
|
||||
world.ActorRemoved +=
|
||||
a => { if (a.HasTrait<Building>())
|
||||
ChangeInfluence(a, a.Trait<Building>(), false); };
|
||||
}
|
||||
|
||||
void ChangeInfluence( Actor a, Building building, bool isAdd )
|
||||
{
|
||||
foreach( var u in FootprintUtils.Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location ) )
|
||||
if( map.IsInMap( u ) )
|
||||
influence[ u.X, u.Y ] = isAdd ? a : null;
|
||||
}
|
||||
|
||||
public Actor GetBuildingAt(int2 cell)
|
||||
{
|
||||
if (!map.IsInMap(cell)) return null;
|
||||
return influence[cell.X, cell.Y];
|
||||
}
|
||||
}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class BuildingInfluenceInfo : ITraitInfo
|
||||
{
|
||||
public object Create( ActorInitializer init ) { return new BuildingInfluence( init.world ); }
|
||||
}
|
||||
|
||||
public class BuildingInfluence
|
||||
{
|
||||
Actor[,] influence;
|
||||
Map map;
|
||||
|
||||
public BuildingInfluence( World world )
|
||||
{
|
||||
map = world.Map;
|
||||
|
||||
influence = new Actor[map.MapSize.X, map.MapSize.Y];
|
||||
|
||||
world.ActorAdded +=
|
||||
a => { if (a.HasTrait<Building>())
|
||||
ChangeInfluence(a, a.Trait<Building>(), true); };
|
||||
world.ActorRemoved +=
|
||||
a => { if (a.HasTrait<Building>())
|
||||
ChangeInfluence(a, a.Trait<Building>(), false); };
|
||||
}
|
||||
|
||||
void ChangeInfluence( Actor a, Building building, bool isAdd )
|
||||
{
|
||||
foreach( var u in FootprintUtils.Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location ) )
|
||||
if( map.IsInMap( u ) )
|
||||
influence[ u.X, u.Y ] = isAdd ? a : null;
|
||||
}
|
||||
|
||||
public Actor GetBuildingAt(int2 cell)
|
||||
{
|
||||
if (!map.IsInMap(cell)) return null;
|
||||
return influence[cell.X, cell.Y];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
#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
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class CanPowerDownInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new CanPowerDown(init); }
|
||||
}
|
||||
|
||||
public class CanPowerDown : IResolveOrder, IDisable, INotifyCapture, ISync
|
||||
{
|
||||
[Sync]
|
||||
bool disabled = false;
|
||||
int normalPower = 0;
|
||||
PowerManager PowerManager;
|
||||
TechTree TechTree;
|
||||
|
||||
public CanPowerDown(ActorInitializer init)
|
||||
{
|
||||
PowerManager = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = init.self.Owner.PlayerActor.Trait<TechTree>();
|
||||
normalPower = init.self.Info.Traits.Get<BuildingInfo>().Power;
|
||||
}
|
||||
public bool Disabled { get { return disabled; } }
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "PowerDown")
|
||||
{
|
||||
disabled = !disabled;
|
||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||
Sound.PlayToPlayer(self.Owner, disabled ? eva.EnablePower : eva.DisablePower);
|
||||
|
||||
PowerManager.UpdateActor(self, disabled ? 0 : normalPower);
|
||||
|
||||
// Rebuild the tech tree; some support powers require active buildings
|
||||
TechTree.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
PowerManager = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = newOwner.PlayerActor.Trait<TechTree>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class CanPowerDownInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new CanPowerDown(init); }
|
||||
}
|
||||
|
||||
public class CanPowerDown : IResolveOrder, IDisable, INotifyCapture, ISync
|
||||
{
|
||||
[Sync]
|
||||
bool disabled = false;
|
||||
int normalPower = 0;
|
||||
PowerManager PowerManager;
|
||||
TechTree TechTree;
|
||||
|
||||
public CanPowerDown(ActorInitializer init)
|
||||
{
|
||||
PowerManager = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = init.self.Owner.PlayerActor.Trait<TechTree>();
|
||||
normalPower = init.self.Info.Traits.Get<BuildingInfo>().Power;
|
||||
}
|
||||
public bool Disabled { get { return disabled; } }
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "PowerDown")
|
||||
{
|
||||
disabled = !disabled;
|
||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||
Sound.PlayToPlayer(self.Owner, disabled ? eva.EnablePower : eva.DisablePower);
|
||||
|
||||
PowerManager.UpdateActor(self, disabled ? 0 : normalPower);
|
||||
|
||||
// Rebuild the tech tree; some support powers require active buildings
|
||||
TechTree.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
PowerManager = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
TechTree = newOwner.PlayerActor.Trait<TechTree>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#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
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
// allow a nonstandard sell/repair value to avoid
|
||||
// buy-sell exploits like c&c's PROC.
|
||||
|
||||
public class CustomSellValueInfo : TraitInfo<CustomSellValue>
|
||||
{
|
||||
public readonly int Value = 0;
|
||||
}
|
||||
|
||||
public class CustomSellValue { }
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
// allow a nonstandard sell/repair value to avoid
|
||||
// buy-sell exploits like c&c's PROC.
|
||||
|
||||
public class CustomSellValueInfo : TraitInfo<CustomSellValue>
|
||||
{
|
||||
public readonly int Value = 0;
|
||||
}
|
||||
|
||||
public class CustomSellValue { }
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
#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
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public static class FootprintUtils
|
||||
{
|
||||
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
|
||||
{
|
||||
var dim = buildingInfo.Dimensions;
|
||||
|
||||
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
|
||||
|
||||
if (Rules.Info[ name ].Traits.Contains<BibInfo>())
|
||||
{
|
||||
dim.Y += 1;
|
||||
footprint = footprint.Concat(new char[dim.X]);
|
||||
}
|
||||
|
||||
return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft );
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> Tiles(Actor a)
|
||||
{
|
||||
return Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location );
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> UnpathableTiles( string name, BuildingInfo buildingInfo, int2 position )
|
||||
{
|
||||
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
|
||||
foreach( var tile in TilesWhere( name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
|
||||
yield return tile + position;
|
||||
}
|
||||
|
||||
static IEnumerable<int2> TilesWhere( string name, int2 dim, char[] footprint, Func<char, bool> cond )
|
||||
{
|
||||
if( footprint.Length != dim.X * dim.Y )
|
||||
throw new InvalidOperationException( "Invalid footprint for " + name );
|
||||
int index = 0;
|
||||
|
||||
for( int y = 0 ; y < dim.Y ; y++ )
|
||||
for( int x = 0 ; x < dim.X ; x++ )
|
||||
if( cond( footprint[ index++ ] ) )
|
||||
yield return new int2( x, y );
|
||||
}
|
||||
|
||||
public static int2 AdjustForBuildingSize( BuildingInfo buildingInfo )
|
||||
{
|
||||
var dim = buildingInfo.Dimensions;
|
||||
return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public static class FootprintUtils
|
||||
{
|
||||
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
|
||||
{
|
||||
var dim = buildingInfo.Dimensions;
|
||||
|
||||
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
|
||||
|
||||
if (Rules.Info[ name ].Traits.Contains<BibInfo>())
|
||||
{
|
||||
dim.Y += 1;
|
||||
footprint = footprint.Concat(new char[dim.X]);
|
||||
}
|
||||
|
||||
return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft );
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> Tiles(Actor a)
|
||||
{
|
||||
return Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location );
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> UnpathableTiles( string name, BuildingInfo buildingInfo, int2 position )
|
||||
{
|
||||
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray();
|
||||
foreach( var tile in TilesWhere( name, buildingInfo.Dimensions, footprint, a => a == 'x' ) )
|
||||
yield return tile + position;
|
||||
}
|
||||
|
||||
static IEnumerable<int2> TilesWhere( string name, int2 dim, char[] footprint, Func<char, bool> cond )
|
||||
{
|
||||
if( footprint.Length != dim.X * dim.Y )
|
||||
throw new InvalidOperationException( "Invalid footprint for " + name );
|
||||
int index = 0;
|
||||
|
||||
for( int y = 0 ; y < dim.Y ; y++ )
|
||||
for( int x = 0 ; x < dim.X ; x++ )
|
||||
if( cond( footprint[ index++ ] ) )
|
||||
yield return new int2( x, y );
|
||||
}
|
||||
|
||||
public static int2 AdjustForBuildingSize( BuildingInfo buildingInfo )
|
||||
{
|
||||
var dim = buildingInfo.Dimensions;
|
||||
return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#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
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class LineBuildInfo : TraitInfo<LineBuild>
|
||||
{
|
||||
public readonly int Range = 5;
|
||||
}
|
||||
|
||||
public class LineBuild {}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class LineBuildInfo : TraitInfo<LineBuild>
|
||||
{
|
||||
public readonly int Range = 5;
|
||||
}
|
||||
|
||||
public class LineBuild {}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
@@ -17,12 +17,12 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public readonly int AdviceInterval = 250;
|
||||
public object Create(ActorInitializer init) { return new PowerManager(init, this); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PowerManager : ITick, ISync
|
||||
{
|
||||
PowerManagerInfo Info;
|
||||
Player Player;
|
||||
Player Player;
|
||||
DeveloperMode devMode;
|
||||
|
||||
Dictionary<Actor, int> PowerDrain = new Dictionary<Actor, int>();
|
||||
@@ -38,9 +38,9 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
Player = init.self.Owner;
|
||||
|
||||
init.world.ActorAdded += ActorAdded;
|
||||
init.world.ActorRemoved += ActorRemoved;
|
||||
|
||||
devMode = init.self.Trait<DeveloperMode>();
|
||||
init.world.ActorRemoved += ActorRemoved;
|
||||
|
||||
devMode = init.self.Trait<DeveloperMode>();
|
||||
wasHackEnabled = devMode.UnlimitedPower;
|
||||
}
|
||||
|
||||
@@ -71,9 +71,9 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
totalProvided += p;
|
||||
else
|
||||
totalDrained -= p;
|
||||
}
|
||||
|
||||
if (devMode.UnlimitedPower)
|
||||
}
|
||||
|
||||
if (devMode.UnlimitedPower)
|
||||
totalProvided = 1000000;
|
||||
}
|
||||
|
||||
@@ -87,15 +87,15 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
}
|
||||
|
||||
int nextPowerAdviceTime = 0;
|
||||
bool wasLowPower = false;
|
||||
bool wasLowPower = false;
|
||||
bool wasHackEnabled;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (wasHackEnabled != devMode.UnlimitedPower)
|
||||
{
|
||||
UpdateTotals();
|
||||
wasHackEnabled = devMode.UnlimitedPower;
|
||||
{
|
||||
if (wasHackEnabled != devMode.UnlimitedPower)
|
||||
{
|
||||
UpdateTotals();
|
||||
wasHackEnabled = devMode.UnlimitedPower;
|
||||
}
|
||||
|
||||
var lowPower = totalProvided < totalDrained;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
@@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
public readonly float RepairRate = 0.016f;
|
||||
public readonly int RepairStep = 7;
|
||||
public object Create(ActorInitializer init) { return new RepairableBuilding(init.self, this); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RepairableBuilding : ITick, IResolveOrder, ISync
|
||||
{
|
||||
[Sync]
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
#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
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
class RequiresPowerInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new RequiresPower(init.self); }
|
||||
}
|
||||
|
||||
class RequiresPower : IDisable, INotifyCapture
|
||||
{
|
||||
PowerManager power;
|
||||
public RequiresPower( Actor self )
|
||||
{
|
||||
power = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get { return power.PowerProvided < power.PowerDrained; }
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
power = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
class RequiresPowerInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new RequiresPower(init.self); }
|
||||
}
|
||||
|
||||
class RequiresPower : IDisable, INotifyCapture
|
||||
{
|
||||
PowerManager power;
|
||||
public RequiresPower( Actor self )
|
||||
{
|
||||
power = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get { return power.PowerProvided < power.PowerDrained; }
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
power = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
#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
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
class Sell : IActivity
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
bool started;
|
||||
|
||||
int framesRemaining;
|
||||
|
||||
void DoSell(Actor self)
|
||||
{
|
||||
var h = self.TraitOrDefault<Health>();
|
||||
var bi = self.Info.Traits.Get<BuildingInfo>();
|
||||
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||
|
||||
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
|
||||
var refund = (cost * bi.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
|
||||
pr.GiveCash(refund);
|
||||
|
||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||
ns.Sold(self);
|
||||
self.Destroy();
|
||||
}
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if( !started )
|
||||
{
|
||||
framesRemaining = self.Trait<RenderSimple>().anim.HasSequence("make")
|
||||
? self.Trait<RenderSimple>().anim.GetSequence( "make" ).Length : 0;
|
||||
|
||||
foreach( var ns in self.TraitsImplementing<INotifySold>() )
|
||||
ns.Selling( self );
|
||||
|
||||
started = true;
|
||||
}
|
||||
else if( framesRemaining <= 0 )
|
||||
DoSell( self );
|
||||
|
||||
else
|
||||
--framesRemaining;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { /* never gonna give you up.. */ }
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
class Sell : IActivity
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
bool started;
|
||||
|
||||
int framesRemaining;
|
||||
|
||||
void DoSell(Actor self)
|
||||
{
|
||||
var h = self.TraitOrDefault<Health>();
|
||||
var bi = self.Info.Traits.Get<BuildingInfo>();
|
||||
var pr = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||
|
||||
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
|
||||
var refund = (cost * bi.RefundPercent * (h == null ? 1 : h.HP)) / (100 * (h == null ? 1 : h.MaxHP));
|
||||
pr.GiveCash(refund);
|
||||
|
||||
foreach (var ns in self.TraitsImplementing<INotifySold>())
|
||||
ns.Sold(self);
|
||||
self.Destroy();
|
||||
}
|
||||
|
||||
public IActivity Tick(Actor self)
|
||||
{
|
||||
if( !started )
|
||||
{
|
||||
framesRemaining = self.Trait<RenderSimple>().anim.HasSequence("make")
|
||||
? self.Trait<RenderSimple>().anim.GetSequence( "make" ).Length : 0;
|
||||
|
||||
foreach( var ns in self.TraitsImplementing<INotifySold>() )
|
||||
ns.Selling( self );
|
||||
|
||||
started = true;
|
||||
}
|
||||
else if( framesRemaining <= 0 )
|
||||
DoSell( self );
|
||||
|
||||
else
|
||||
--framesRemaining;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Cancel(Actor self) { /* never gonna give you up.. */ }
|
||||
|
||||
public void Queue( IActivity activity )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
NextActivity.Queue( activity );
|
||||
else
|
||||
NextActivity = activity;
|
||||
}
|
||||
|
||||
public IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
|
||||
* 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 LICENSE.
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,116 +1,116 @@
|
||||
#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
|
||||
|
||||
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<Building>())
|
||||
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.Queries.OwnedBy[player].Where( x=>x.Info.Traits.Contains<BuildingInfo>() ) )
|
||||
{
|
||||
ret[ b.Info.Name ].Add( b );
|
||||
var tt = b.Info.Traits.GetOrDefault<TooltipInfo>();
|
||||
if( tt != null )
|
||||
foreach( var alt in tt.AlternateName )
|
||||
ret[ alt ].Add( b );
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
#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<Building>())
|
||||
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.Queries.OwnedBy[player].Where( x=>x.Info.Traits.Contains<BuildingInfo>() ) )
|
||||
{
|
||||
ret[ b.Info.Name ].Add( b );
|
||||
var tt = b.Info.Traits.GetOrDefault<TooltipInfo>();
|
||||
if( tt != null )
|
||||
foreach( var alt in tt.AlternateName )
|
||||
ret[ alt ].Add( b );
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
#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
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public static class BuildingUtils
|
||||
{
|
||||
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
|
||||
{
|
||||
return world.IsCellBuildable(a, waterBound, null);
|
||||
}
|
||||
|
||||
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
|
||||
{
|
||||
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
||||
if (world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||
|
||||
if (waterBound)
|
||||
return world.Map.IsInMap(a.X,a.Y) && world.GetTerrainInfo(a).IsWater;
|
||||
|
||||
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
|
||||
}
|
||||
|
||||
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
|
||||
{
|
||||
var res = world.WorldActor.Trait<ResourceLayer>();
|
||||
return FootprintUtils.Tiles(name, building, topLeft).All(
|
||||
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
|
||||
world.IsCellBuildable(t, building.WaterBound, toIgnore));
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
|
||||
{
|
||||
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi.WaterBound))
|
||||
yield return topLeft;
|
||||
|
||||
// Start at place location, search outwards
|
||||
// TODO: First make it work, then make it nice
|
||||
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
|
||||
int[] dirs = { 0, 0, 0, 0 };
|
||||
for (int d = 0; d < 4; d++)
|
||||
{
|
||||
for (int i = 1; i < range; i++)
|
||||
{
|
||||
if (dirs[d] != 0)
|
||||
continue;
|
||||
|
||||
int2 cell = topLeft + i * vecs[d];
|
||||
if (world.IsCellBuildable(cell, bi.WaterBound))
|
||||
continue; // Cell is empty; continue search
|
||||
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
if (world.Queries.WithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
|
||||
dirs[d] = i; // Cell contains actor of correct type
|
||||
else
|
||||
dirs[d] = -1; // Cell is blocked by another actor type
|
||||
}
|
||||
|
||||
// Place intermediate-line sections
|
||||
if (dirs[d] > 0)
|
||||
for (int i = 1; i < dirs[d]; i++)
|
||||
yield return topLeft + i * vecs[d];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public static class BuildingUtils
|
||||
{
|
||||
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
|
||||
{
|
||||
return world.IsCellBuildable(a, waterBound, null);
|
||||
}
|
||||
|
||||
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
|
||||
{
|
||||
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
||||
if (world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||
|
||||
if (waterBound)
|
||||
return world.Map.IsInMap(a.X,a.Y) && world.GetTerrainInfo(a).IsWater;
|
||||
|
||||
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
|
||||
}
|
||||
|
||||
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
|
||||
{
|
||||
var res = world.WorldActor.Trait<ResourceLayer>();
|
||||
return FootprintUtils.Tiles(name, building, topLeft).All(
|
||||
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
|
||||
world.IsCellBuildable(t, building.WaterBound, toIgnore));
|
||||
}
|
||||
|
||||
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
|
||||
{
|
||||
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi.WaterBound))
|
||||
yield return topLeft;
|
||||
|
||||
// Start at place location, search outwards
|
||||
// TODO: First make it work, then make it nice
|
||||
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
|
||||
int[] dirs = { 0, 0, 0, 0 };
|
||||
for (int d = 0; d < 4; d++)
|
||||
{
|
||||
for (int i = 1; i < range; i++)
|
||||
{
|
||||
if (dirs[d] != 0)
|
||||
continue;
|
||||
|
||||
int2 cell = topLeft + i * vecs[d];
|
||||
if (world.IsCellBuildable(cell, bi.WaterBound))
|
||||
continue; // Cell is empty; continue search
|
||||
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
if (world.Queries.WithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
|
||||
dirs[d] = i; // Cell contains actor of correct type
|
||||
else
|
||||
dirs[d] = -1; // Cell is blocked by another actor type
|
||||
}
|
||||
|
||||
// Place intermediate-line sections
|
||||
if (dirs[d] > 0)
|
||||
for (int i = 1; i < dirs[d]; i++)
|
||||
yield return topLeft + i * vecs[d];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
#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
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class WallInfo : ITraitInfo, ITraitPrerequisite<BuildingInfo>
|
||||
{
|
||||
public readonly string[] CrushClasses = { };
|
||||
public readonly string CrushSound;
|
||||
public object Create(ActorInitializer init) { return new Wall(init.self, this); }
|
||||
}
|
||||
|
||||
public class Wall : ICrushable, IBlocksBullets
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly WallInfo info;
|
||||
|
||||
public Wall(Actor self, WallInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<string> CrushClasses { get { return info.CrushClasses; } }
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
self.Kill(crusher);
|
||||
Sound.Play(info.CrushSound, self.CenterLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
#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 OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
public class WallInfo : ITraitInfo, ITraitPrerequisite<BuildingInfo>
|
||||
{
|
||||
public readonly string[] CrushClasses = { };
|
||||
public readonly string CrushSound;
|
||||
public object Create(ActorInitializer init) { return new Wall(init.self, this); }
|
||||
}
|
||||
|
||||
public class Wall : ICrushable, IBlocksBullets
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly WallInfo info;
|
||||
|
||||
public Wall(Actor self, WallInfo info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public IEnumerable<string> CrushClasses { get { return info.CrushClasses; } }
|
||||
public void OnCrush(Actor crusher)
|
||||
{
|
||||
self.Kill(crusher);
|
||||
Sound.Play(info.CrushSound, self.CenterLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user