diff --git a/OpenRA.Game/GameRules/TerrainCost.cs b/OpenRA.Game/GameRules/TerrainCost.cs index 28ee1d7c56..7e91b44df6 100644 --- a/OpenRA.Game/GameRules/TerrainCost.cs +++ b/OpenRA.Game/GameRules/TerrainCost.cs @@ -24,49 +24,11 @@ using OpenRA.Graphics; namespace OpenRA.GameRules { - public enum UnitMovementType : byte - { - Foot = 0, - Track = 1, - Wheel = 2, - Float = 3, - Fly = 4, - } - public class TerrainCost { public readonly bool Buildable = true; - public readonly float Foot = 0, Track = 0, Wheel = 0, Float = 0; public readonly bool AcceptSmudge = true; public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); } - - public float GetSpeedModifier(UnitMovementType umt) - { - switch (umt) /* todo: make this nice */ - { - case UnitMovementType.Fly: return 1; - case UnitMovementType.Foot: return Foot; - case UnitMovementType.Wheel: return Wheel; - case UnitMovementType.Track: return Track; - case UnitMovementType.Float: return Float; - default: - throw new InvalidOperationException("wtf?"); - } - } - - public float GetCost(UnitMovementType umt) - { - switch (umt) /* todo: make this nice */ - { - case UnitMovementType.Fly: return 1; - case UnitMovementType.Foot: return 1 / Foot; - case UnitMovementType.Wheel: return 1 / Wheel; - case UnitMovementType.Track: return 1 / Track; - case UnitMovementType.Float: return 1 / Float; - default: - throw new InvalidOperationException("wtf?"); - } - } } } diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index 51530e91fd..dcaf7e4dbd 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -41,7 +41,6 @@ namespace OpenRA { public int2 from; public int2 to; - public UnitMovementType umt; public List result; public int tick; } diff --git a/OpenRA.Mods.RA/Cargo.cs b/OpenRA.Mods.RA/Cargo.cs index 7f9a73a925..1dd5882de3 100644 --- a/OpenRA.Mods.RA/Cargo.cs +++ b/OpenRA.Mods.RA/Cargo.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA public class CargoInfo : TraitInfo { public readonly int Passengers = 0; - public readonly UnitMovementType[] PassengerTypes = { }; + public readonly string[] PassengerTypes = { }; public readonly int UnloadFacing = 0; } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 68fd5d5d92..84d443da4c 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -45,15 +45,19 @@ namespace OpenRA.Mods.RA public object Create(ActorInitializer init) { return new Crate(init); } } - class Crate : ITick + class Crate : ITick, IOccupySpace { readonly Actor self; [Sync] int ticks; + [Sync] + public int2 Location; + public Crate(ActorInitializer init) { this.self = init.self; + this.Location = init.location; } public void OnCollected(Actor crusher) @@ -90,5 +94,9 @@ namespace OpenRA.Mods.RA if (seq != self.traits.Get().anim.CurrentSequence.Name) self.traits.Get().anim.PlayRepeating(seq); } + + public int2 TopLeft {get { return Location; }} + int2[] noCells = new int2[] { }; + public IEnumerable OccupiedCells() { return noCells; } } } diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index 9af7f3ef8e..433fe5349d 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -25,13 +25,15 @@ using OpenRA.GameRules; using OpenRA.Traits; using OpenRA.Traits.Activities; using OpenRA.Mods.RA.Activities; - +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { public class CrateDropInfo : TraitInfo { public readonly int Minimum = 1; // Minumum number of crates public readonly int Maximum = 255; // Maximum number of crates + public readonly string[] ValidGround = {"Clear", "Rough", "Road", "Ore", "Beach"}; // Which terrain types can we drop on? + public readonly string[] ValidWater = {"Water"}; public readonly int SpawnInterval = 180; // Average time (seconds) between crate spawn public readonly float WaterChance = .2f; // Chance of generating a water crate instead of a land crate } @@ -67,15 +69,16 @@ namespace OpenRA.Mods.RA { var p = self.World.ChooseRandomCell(self.World.SharedRandom); + // Is this valid terrain? + // Ugly hack until terraintypes are converted from enums + var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]); + var terrain = Enum.GetName( typeof(TerrainType), terrainType); + if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue; + // Don't drop on any actors if (self.World.WorldActor.traits.Get().GetBuildingAt(p) != null) continue; if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any()) continue; - // Don't drop on unpathable cells - if (!(self.World.Map.IsInMap(p.X, p.Y) && - Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y])] - .GetCost(inWater ? UnitMovementType.Float : UnitMovementType.Wheel) < float.PositiveInfinity)) continue; - self.World.AddFrameEndTask(w => { var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner); diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index 546cc206f9..6f8faf44ef 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -1,78 +1,90 @@ -#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 . - */ -#endregion - -using System; -using System.Collections.Generic; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - class CrateSpawnerInfo : TraitInfo - { - public readonly int Minimum = 1; // Minumum number of crates - public readonly int Maximum = 255; // Maximum number of crates - public readonly int SpawnInterval = 180; // Average time (seconds) between crate spawn - public readonly float WaterChance = .2f; // Chance of generating a water crate instead of a land crate - } - - // assumption: there is always at least one free water cell, and one free land cell. - - class CrateSpawner : ITick - { - List crates = new List(); - int ticks = 0; - - public void Tick(Actor self) - { - if (--ticks <= 0) - { - var info = self.Info.Traits.Get(); - ticks = info.SpawnInterval * 25; // todo: randomize - - crates.RemoveAll(c => !c.IsInWorld); - - var toSpawn = Math.Max(0, info.Minimum - crates.Count) - + (crates.Count < info.Maximum ? 1 : 0); - - for (var n = 0; n < toSpawn; n++) - SpawnCrate(self, info); - } - } - - const int ChooseCrateLocationAttempts = 100; - - void SpawnCrate(Actor self, CrateSpawnerInfo info) - { - var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; - - for (var n = 0; n < ChooseCrateLocationAttempts; n++) - { - var p = self.World.ChooseRandomCell(self.World.SharedRandom); - - if (self.World.IsCellBuildable(p, inWater)) - { - self.World.AddFrameEndTask( - w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner))); - break; - } - } - } - } -} +#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 . + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; +using OpenRA.GameRules; +using OpenRA.Traits; +using OpenRA.Traits.Activities; +using OpenRA.Mods.RA.Activities; +using OpenRA.FileFormats; +namespace OpenRA.Mods.RA +{ + public class CrateSpawnerInfo : TraitInfo + { + public readonly int Minimum = 1; // Minumum number of crates + public readonly int Maximum = 255; // Maximum number of crates + public readonly string[] ValidGround = {"Clear", "Rough", "Road", "Ore", "Beach"}; // Which terrain types can we drop on? + public readonly string[] ValidWater = {"Water"}; + public readonly int SpawnInterval = 180; // Average time (seconds) between crate spawn + public readonly float WaterChance = .2f; // Chance of generating a water crate instead of a land crate + } + + public class CrateSpawner : ITick + { + List crates = new List(); + int ticks = 0; + + public void Tick(Actor self) + { + if (--ticks <= 0) + { + var info = self.Info.Traits.Get(); + ticks = info.SpawnInterval * 25; // todo: randomize + + crates.RemoveAll(x => !x.IsInWorld); + + var toSpawn = Math.Max(0, info.Minimum - crates.Count) + + (crates.Count < info.Maximum ? 1 : 0); + + for (var n = 0; n < toSpawn; n++) + SpawnCrate(self, info); + } + } + + void SpawnCrate(Actor self, CrateSpawnerInfo info) + { + var threshold = 100; + var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; + + for (var n = 0; n < threshold; n++ ) + { + var p = self.World.ChooseRandomCell(self.World.SharedRandom); + + // Is this valid terrain? + // Ugly hack until terraintypes are converted from enums + var terrainType = self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y]); + var terrain = Enum.GetName( typeof(TerrainType), terrainType); + if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrain)) continue; + + // Don't spawn on any actors + if (self.World.WorldActor.traits.Get().GetBuildingAt(p) != null) continue; + if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any()) continue; + + System.Console.WriteLine("Spawning crate at {0}", p); + + self.World.AddFrameEndTask( + w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner))); + return; + } + } + } +} diff --git a/mods/cnc/sequences.xml b/mods/cnc/sequences.xml index d5690b186a..b7ba5f28c3 100644 --- a/mods/cnc/sequences.xml +++ b/mods/cnc/sequences.xml @@ -122,7 +122,16 @@ - + + + + + + + + + + diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 2f4475180b..c02c50c781 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -248,4 +248,27 @@ World: LevelUp: text2.aud SpatialBins: BinSize: 4 - Shroud: \ No newline at end of file + Shroud: + CrateSpawner: + Minimum: 1 + Maximum: 300 + SpawnInterval: 12 + WaterChance: 0 + +CRATE: + Valued: + Cost: 0 + Description: Crate + Crate: + Lifetime: 120 + GiveCashCrateAction: + Amount: 1000 + SelectionShares: 50 + Effect: dollar + HideMapCrateAction: + SelectionShares: 5 + Effect: hide-map + Unit: + HP: 1 + RenderUnit: + BelowUnits: diff --git a/mods/cnc/terrain.yaml b/mods/cnc/terrain.yaml index a9192f7efb..50f3a8e23f 100644 --- a/mods/cnc/terrain.yaml +++ b/mods/cnc/terrain.yaml @@ -1,82 +1,38 @@ Clear: - Foot: 90% - Track: 80% - Wheel: 60% - Float: 0% Buildable: yes Rough: - Foot: 80% - Track: 70% - Wheel: 40% - Float: 0% Buildable: no Road: - Foot: 100% - Track: 100% - Wheel: 100% - Float: 0% Buildable: yes Tree: - Foot: 0% - Track: 0% - Wheel: 0% - Float: 0% Buildable: no AcceptSmudge: no Water: - Foot: 0% - Track: 0% - Wheel: 0% - Float: 100% Buildable: no AcceptSmudge: no Rock: - Foot: 0% - Track: 0% - Wheel: 0% - Float: 0% Buildable: no AcceptSmudge: no Wall: - Foot: 0% - Track: 0% - Wheel: 0% - Float: 0% Buildable: no Ore: - Foot: 90% - Track: 70% - Wheel: 50% - Float: 0% Buildable: no Beach: - Foot: 80% - Track: 70% - Wheel: 40% - Float: 0% Buildable: no AcceptSmudge: no River: - Foot: 0% - Track: 0% - Wheel: 0% - Float: 0% Buildable: no AcceptSmudge: no Special: - Foot: 100% - Track: 100% - Wheel: 100% - Float: 100% Buildable: no AcceptSmudge: no \ No newline at end of file