move Building et al into Mods/

This commit is contained in:
Bob
2010-11-04 17:26:56 +13:00
committed by Chris Forbes
parent fdfa1ddf97
commit 480c5edd75
60 changed files with 322 additions and 285 deletions

View File

@@ -1,93 +0,0 @@
#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.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Traits
{
class BibLayerInfo : ITraitInfo
{
public readonly string[] BibTypes = {"bib3", "bib2", "bib1"};
public readonly int[] BibWidths = {2,3,4};
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
}
class BibLayer: IRenderOverlay, IWorldLoaded
{
World world;
BibLayerInfo info;
Dictionary<int2, TileReference<byte, byte>> tiles;
Sprite[][] bibSprites;
public BibLayer(Actor self, BibLayerInfo info)
{
this.info = info;
bibSprites = info.BibTypes.Select(x => SpriteSheetBuilder.LoadAllSprites(x)).ToArray();
self.World.ActorAdded +=
a => { if (a.HasTrait<Bib>()) DoBib(a,true); };
self.World.ActorRemoved +=
a => { if (a.HasTrait<Bib>()) DoBib(a,false); };
}
public void WorldLoaded(World w)
{
world = w;
tiles = new Dictionary<int2, TileReference<byte, byte>>();
}
public void DoBib(Actor b, bool isAdd)
{
var buildingInfo = b.Info.Traits.Get<BuildingInfo>();
var size = buildingInfo.Dimensions.X;
var bibOffset = buildingInfo.Dimensions.Y - 1;
int bib = Array.IndexOf(info.BibWidths,size);
if (bib < 0)
{
Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name);
return;
}
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
tiles.Remove(p);
}
}
public void Render( WorldRenderer wr )
{
var cliprect = Game.viewport.ShroudBounds( world );
cliprect = Rectangle.Intersect(Game.viewport.ViewBounds(), cliprect);
foreach (var kv in tiles)
{
if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
continue;
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(kv.Key))
continue;
bibSprites[kv.Value.type - 1][kv.Value.image].DrawAt( wr,
Game.CellSize * kv.Key, "terrain");
}
}
}
class BibInfo : TraitInfo<Bib> { }
public class Bib { }
}

View File

@@ -1,54 +0,0 @@
#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.FileFormats;
using OpenRA.GameRules;
using System;
namespace OpenRA.Traits
{
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 Footprint.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];
}
}
}

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Traits
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
{
// Todo: Valid terrain should be specified in the resource
if (!w.IsCellBuildable(new int2(x,y), false))
if (!AllowOreAt(new int2(x,y)))
continue;
content[x, y].type = resourceTypes.FirstOrDefault(
@@ -89,6 +89,14 @@ namespace OpenRA.Traits
}
}
bool AllowOreAt( int2 a )
{
if( !world.Map.IsInMap( a.X, a.Y ) ) return false;
if( !world.GetTerrainInfo( a ).Buildable ) return false;
if( world.WorldActor.Trait<UnitInfluence>().AnyUnitsAt( a ) ) return false;
return true;
}
Sprite[] ChooseContent(ResourceType t)
{
return t.info.Sprites[world.SharedRandom.Next(t.info.Sprites.Length)];

View File

@@ -12,9 +12,6 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Traits
{
@@ -122,22 +119,14 @@ namespace OpenRA.Traits
public static IEnumerable<int2> GetVisOrigins(Actor a)
{
if (a.Info.Traits.Contains<BuildingInfo>())
var ios = a.TraitOrDefault<IOccupySpace>();
if (ios != null)
{
var bi = a.Info.Traits.Get<BuildingInfo>();
return Footprint.Tiles(a.Info.Name, bi, a.Location);
var cells = ios.OccupiedCells();
if (cells.Any()) return cells;
}
else
{
var ios = a.TraitOrDefault<IOccupySpace>();
if (ios != null)
{
var cells = ios.OccupiedCells();
if (cells.Any()) return cells;
}
return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() };
}
return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() };
}
void RemoveActor(Actor a)