moved various other traits

This commit is contained in:
Chris Forbes
2010-05-20 18:47:22 +12:00
parent f75a2d2fe6
commit 7fc5007ac8
14 changed files with 75 additions and 46 deletions

View File

@@ -19,9 +19,10 @@
#endregion
using System;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA
{
class AttackTurretedInfo : AttackBaseInfo
{

32
OpenRA.Mods.RA/Fake.cs Normal file
View File

@@ -0,0 +1,32 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class FakeInfo : TraitInfo<Fake> { }
class Fake : ITags
{
public IEnumerable<TagType> GetTags() { yield return TagType.Fake; }
}
}

View File

@@ -84,6 +84,7 @@
<Compile Include="Activities\Harvest.cs" />
<Compile Include="EmitInfantryOnSell.cs" />
<Compile Include="Explodes.cs" />
<Compile Include="Fake.cs" />
<Compile Include="Harvester.cs" />
<Compile Include="HasUnitOnBuild.cs" />
<Compile Include="Husk.cs" />
@@ -105,9 +106,12 @@
<Compile Include="InfiltrateForSonarPulse.cs" />
<Compile Include="IronCurtainable.cs" />
<Compile Include="IronCurtainPower.cs" />
<Compile Include="PaletteFromFile.cs" />
<Compile Include="PaletteFromRGBA.cs" />
<Compile Include="ParaDrop.cs" />
<Compile Include="ParatroopersPower.cs" />
<Compile Include="Passenger.cs" />
<Compile Include="ProductionSurround.cs" />
<Compile Include="RenderFlare.cs" />
<Compile Include="RenderInfantry.cs" />
<Compile Include="RequiresPower.cs" />
@@ -118,8 +122,13 @@
<Compile Include="RepairableNear.cs" />
<Compile Include="Crates\SpeedUpgradeCrateAction.cs" />
<Compile Include="ReturnOnIdle.cs" />
<Compile Include="RevealsShroud.cs" />
<Compile Include="SeedsResource.cs" />
<Compile Include="SelfHealing.cs" />
<Compile Include="ShroudPalette.cs" />
<Compile Include="SonarPulsePower.cs" />
<Compile Include="SpawnDefaultUnits.cs" />
<Compile Include="SpawnMapActors.cs" />
<Compile Include="Spy.cs" />
<Compile Include="SpyPlanePower.cs" />
<Compile Include="NukePower.cs" />

View File

@@ -0,0 +1,47 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class PaletteFromFileInfo : ITraitInfo
{
public readonly string Name = null;
public readonly string Theater = null;
public readonly string Filename = null;
public readonly bool Transparent = true;
public object Create(Actor self) { return new PaletteFromFile(self, this); }
}
class PaletteFromFile
{
public PaletteFromFile(Actor self, PaletteFromFileInfo info)
{
if (info.Theater == null ||
info.Theater.ToLowerInvariant() == self.World.Map.Theater.ToLowerInvariant())
{
self.World.WorldRenderer.AddPalette(info.Name,
new Palette(FileSystem.Open(info.Filename), info.Transparent));
}
}
}
}

View File

@@ -0,0 +1,52 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class PaletteFromRGBAInfo : ITraitInfo
{
public readonly string Name = null;
public readonly string Theatre = null;
public readonly int R = 0;
public readonly int G = 0;
public readonly int B = 0;
public readonly int A = 255;
public object Create(Actor self) { return new PaletteFromRGBA(self, this); }
}
class PaletteFromRGBA
{
public PaletteFromRGBA(Actor self, PaletteFromRGBAInfo info)
{
if (info.Theatre == null ||
info.Theatre.ToLowerInvariant() == self.World.Map.Theater.ToLowerInvariant())
{
// TODO: This shouldn't rely on a base palette
var wr = self.World.WorldRenderer;
var pal = wr.GetPalette("player0");
wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))));
}
}
}
}

View File

@@ -0,0 +1,60 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class ProductionSurroundInfo : ProductionInfo
{
public override object Create(Actor self) { return new ProductionSurround(self); }
}
class ProductionSurround : Production
{
public ProductionSurround(Actor self) : base(self) { }
static int2? FindAdjacentTile(Actor self, bool waterBound)
{
var tiles = Footprint.Tiles(self);
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
var max = tiles.Aggregate(int2.Max) + new int2(1, 1);
for (var j = min.Y; j <= max.Y; j++)
for (var i = min.X; i <= max.X; i++)
if (self.World.IsCellBuildable(new int2(i, j), waterBound))
return new int2(i, j);
return null;
}
public override int2? CreationLocation(Actor self, ActorInfo producee)
{
return FindAdjacentTile(self, producee.Traits.Get<OwnedActorInfo>().WaterBound);
}
public override int CreationFacing(Actor self, Actor newUnit)
{
return Util.GetFacing(newUnit.CenterLocation - self.CenterLocation, 128);
}
}
}

View File

@@ -0,0 +1,40 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class RevealsShroudInfo : TraitInfo<RevealsShroud> { }
class RevealsShroud : ITick
{
int2 previousLocation;
public void Tick(Actor self)
{
if (!self.IsIdle && previousLocation != self.Location)
{
previousLocation = self.Location;
self.World.WorldActor.traits.Get<Shroud>().UpdateActor(self);
}
}
}
}

View File

@@ -0,0 +1,85 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class SeedsResourceInfo : ITraitInfo
{
public readonly int Interval = 75;
public readonly string ResourceType = "Ore";
public readonly int MaxRange = 100;
public object Create(Actor self) { return new SeedsResource(); }
}
class SeedsResource : ITick
{
int ticks;
public void Tick(Actor self)
{
if (--ticks <= 0)
{
var info = self.Info.Traits.Get<SeedsResourceInfo>();
var resourceType = self.World.WorldActor.traits
.WithInterface<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.traits.Get<ResourceLayer>();
var cell = RandomWalk(self.Location, self.World.SharedRandom)
.Take(info.MaxRange)
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p.X, p.Y))
.Cast<int2?>().FirstOrDefault();
if (cell != null &&
(resLayer.GetResource(cell.Value) == resourceType || resLayer.GetResource(cell.Value) == null) &&
self.World.IsCellBuildable(cell.Value, false))
resLayer.AddResource(resourceType, cell.Value.X, cell.Value.Y, 1);
ticks = info.Interval;
}
}
static IEnumerable<int2> RandomWalk(int2 p, Thirdparty.Random r)
{
for (; ; )
{
var dx = r.Next(-1, 2);
var dy = r.Next(-1, 2);
if (dx == 0 && dy == 0)
continue;
p.X += dx;
p.Y += dy;
yield return p;
}
}
}
}

View File

@@ -0,0 +1,43 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class ShroudPaletteInfo : ITraitInfo
{
public readonly string Name = "shroud";
public readonly bool IsFog = false;
public object Create(Actor self) { return new ShroudPalette(self, this); }
}
class ShroudPalette
{
public ShroudPalette(Actor self, ShroudPaletteInfo info)
{
// TODO: This shouldn't rely on a base palette
var wr = self.World.WorldRenderer;
var pal = wr.GetPalette("terrain");
wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)));
}
}
}

View File

@@ -0,0 +1,80 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class SpawnDefaultUnitsInfo : TraitInfo<SpawnDefaultUnits>
{
public readonly int InitialExploreRange = 5;
}
class SpawnDefaultUnits : IGameStarted
{
public void GameStarted(World world)
{
var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
var available = world.Map.SpawnPoints.Except(taken).ToList();
foreach (var client in Game.LobbyInfo.Clients)
{
SpawnUnitsForPlayer(world.players[client.Index],
(client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken)
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1));
}
}
void SpawnUnitsForPlayer(Player p, int2 sp)
{
p.World.CreateActor("mcv", sp, p);
if (p == p.World.LocalPlayer || p.Stances[p.World.LocalPlayer] == Stance.Ally)
p.World.WorldActor.traits.Get<Shroud>().Explore(p.World, sp,
p.World.WorldActor.Info.Traits.Get<SpawnDefaultUnitsInfo>().InitialExploreRange);
}
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken)
{
if (available.Count == 0)
throw new InvalidOperationException("No free spawnpoint.");
var n = taken.Count == 0
? world.SharedRandom.Next(available.Count)
: available // pick the most distant spawnpoint from everyone else
.Select((k, i) => Pair.New(k, i))
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
.Select(a => a.Second)
.First();
var sp = available[n];
available.RemoveAt(n);
taken.Add(sp);
return sp;
}
}
}

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class SpawnMapActorsInfo : TraitInfo<SpawnMapActors> { }
public class SpawnMapActors : IGameStarted
{
public Dictionary<string, Actor> MapActors = new Dictionary<string, Actor>();
public void GameStarted(World world)
{
Game.skipMakeAnims = true; // rude hack
foreach (var actorReference in world.Map.Actors)
MapActors[actorReference.Key] = world.CreateActor(actorReference.Value.Name, actorReference.Value.Location,
world.players.Values.FirstOrDefault(p => p.InternalName == actorReference.Value.Owner)
?? world.NeutralPlayer);
Game.skipMakeAnims = false;
}
}
}