Kill UnitMovementType; bs-free crate spawning; fix "DOME crash" (caused by crate not IOccupying space); add money and hide-map crates to cnc
This commit is contained in:
@@ -24,49 +24,11 @@ using OpenRA.Graphics;
|
|||||||
|
|
||||||
namespace OpenRA.GameRules
|
namespace OpenRA.GameRules
|
||||||
{
|
{
|
||||||
public enum UnitMovementType : byte
|
|
||||||
{
|
|
||||||
Foot = 0,
|
|
||||||
Track = 1,
|
|
||||||
Wheel = 2,
|
|
||||||
Float = 3,
|
|
||||||
Fly = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TerrainCost
|
public class TerrainCost
|
||||||
{
|
{
|
||||||
public readonly bool Buildable = true;
|
public readonly bool Buildable = true;
|
||||||
public readonly float Foot = 0, Track = 0, Wheel = 0, Float = 0;
|
|
||||||
public readonly bool AcceptSmudge = true;
|
public readonly bool AcceptSmudge = true;
|
||||||
|
|
||||||
public TerrainCost(MiniYaml y) { FieldLoader.Load(this, y); }
|
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?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public int2 from;
|
public int2 from;
|
||||||
public int2 to;
|
public int2 to;
|
||||||
public UnitMovementType umt;
|
|
||||||
public List<int2> result;
|
public List<int2> result;
|
||||||
public int tick;
|
public int tick;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
|
|||||||
public class CargoInfo : TraitInfo<Cargo>
|
public class CargoInfo : TraitInfo<Cargo>
|
||||||
{
|
{
|
||||||
public readonly int Passengers = 0;
|
public readonly int Passengers = 0;
|
||||||
public readonly UnitMovementType[] PassengerTypes = { };
|
public readonly string[] PassengerTypes = { };
|
||||||
public readonly int UnloadFacing = 0;
|
public readonly int UnloadFacing = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,15 +45,19 @@ namespace OpenRA.Mods.RA
|
|||||||
public object Create(ActorInitializer init) { return new Crate(init); }
|
public object Create(ActorInitializer init) { return new Crate(init); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Crate : ITick
|
class Crate : ITick, IOccupySpace
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
[Sync]
|
[Sync]
|
||||||
int ticks;
|
int ticks;
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
public int2 Location;
|
||||||
|
|
||||||
public Crate(ActorInitializer init)
|
public Crate(ActorInitializer init)
|
||||||
{
|
{
|
||||||
this.self = init.self;
|
this.self = init.self;
|
||||||
|
this.Location = init.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnCollected(Actor crusher)
|
public void OnCollected(Actor crusher)
|
||||||
@@ -90,5 +94,9 @@ namespace OpenRA.Mods.RA
|
|||||||
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
|
if (seq != self.traits.Get<RenderSimple>().anim.CurrentSequence.Name)
|
||||||
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
|
self.traits.Get<RenderSimple>().anim.PlayRepeating(seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int2 TopLeft {get { return Location; }}
|
||||||
|
int2[] noCells = new int2[] { };
|
||||||
|
public IEnumerable<int2> OccupiedCells() { return noCells; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,15 @@ using OpenRA.GameRules;
|
|||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Traits.Activities;
|
using OpenRA.Traits.Activities;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
public class CrateDropInfo : TraitInfo<CrateDrop>
|
public class CrateDropInfo : TraitInfo<CrateDrop>
|
||||||
{
|
{
|
||||||
public readonly int Minimum = 1; // Minumum number of crates
|
public readonly int Minimum = 1; // Minumum number of crates
|
||||||
public readonly int Maximum = 255; // Maximum 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 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 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);
|
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
|
// Don't drop on any actors
|
||||||
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||||
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p).Any()) continue;
|
if (self.World.WorldActor.traits.Get<UnitInfluence>().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 =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner);
|
var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner);
|
||||||
|
|||||||
@@ -1,78 +1,90 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
*
|
*
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
* OpenRA is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
* OpenRA is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
using System.Linq;
|
||||||
|
using OpenRA.GameRules;
|
||||||
namespace OpenRA.Mods.RA
|
using OpenRA.Traits;
|
||||||
{
|
using OpenRA.Traits.Activities;
|
||||||
class CrateSpawnerInfo : TraitInfo<CrateSpawner>
|
using OpenRA.Mods.RA.Activities;
|
||||||
{
|
using OpenRA.FileFormats;
|
||||||
public readonly int Minimum = 1; // Minumum number of crates
|
namespace OpenRA.Mods.RA
|
||||||
public readonly int Maximum = 255; // Maximum number of crates
|
{
|
||||||
public readonly int SpawnInterval = 180; // Average time (seconds) between crate spawn
|
public class CrateSpawnerInfo : TraitInfo<CrateSpawner>
|
||||||
public readonly float WaterChance = .2f; // Chance of generating a water crate instead of a land crate
|
{
|
||||||
}
|
public readonly int Minimum = 1; // Minumum number of crates
|
||||||
|
public readonly int Maximum = 255; // Maximum number of crates
|
||||||
// assumption: there is always at least one free water cell, and one free land cell.
|
public readonly string[] ValidGround = {"Clear", "Rough", "Road", "Ore", "Beach"}; // Which terrain types can we drop on?
|
||||||
|
public readonly string[] ValidWater = {"Water"};
|
||||||
class CrateSpawner : ITick
|
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
|
||||||
List<Actor> crates = new List<Actor>();
|
}
|
||||||
int ticks = 0;
|
|
||||||
|
public class CrateSpawner : ITick
|
||||||
public void Tick(Actor self)
|
{
|
||||||
{
|
List<Actor> crates = new List<Actor>();
|
||||||
if (--ticks <= 0)
|
int ticks = 0;
|
||||||
{
|
|
||||||
var info = self.Info.Traits.Get<CrateSpawnerInfo>();
|
public void Tick(Actor self)
|
||||||
ticks = info.SpawnInterval * 25; // todo: randomize
|
{
|
||||||
|
if (--ticks <= 0)
|
||||||
crates.RemoveAll(c => !c.IsInWorld);
|
{
|
||||||
|
var info = self.Info.Traits.Get<CrateSpawnerInfo>();
|
||||||
var toSpawn = Math.Max(0, info.Minimum - crates.Count)
|
ticks = info.SpawnInterval * 25; // todo: randomize
|
||||||
+ (crates.Count < info.Maximum ? 1 : 0);
|
|
||||||
|
crates.RemoveAll(x => !x.IsInWorld);
|
||||||
for (var n = 0; n < toSpawn; n++)
|
|
||||||
SpawnCrate(self, info);
|
var toSpawn = Math.Max(0, info.Minimum - crates.Count)
|
||||||
}
|
+ (crates.Count < info.Maximum ? 1 : 0);
|
||||||
}
|
|
||||||
|
for (var n = 0; n < toSpawn; n++)
|
||||||
const int ChooseCrateLocationAttempts = 100;
|
SpawnCrate(self, info);
|
||||||
|
}
|
||||||
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
}
|
||||||
{
|
|
||||||
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
||||||
|
{
|
||||||
for (var n = 0; n < ChooseCrateLocationAttempts; n++)
|
var threshold = 100;
|
||||||
{
|
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
||||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
|
||||||
|
for (var n = 0; n < threshold; n++ )
|
||||||
if (self.World.IsCellBuildable(p, inWater))
|
{
|
||||||
{
|
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||||
self.World.AddFrameEndTask(
|
|
||||||
w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner)));
|
// Is this valid terrain?
|
||||||
break;
|
// 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<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||||
|
if (self.World.WorldActor.traits.Get<UnitInfluence>().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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -122,7 +122,16 @@
|
|||||||
<sequence name="idle" start="0" src="wcrate" />
|
<sequence name="idle" start="0" src="wcrate" />
|
||||||
</unit>
|
</unit>
|
||||||
<unit name="crate-effects">
|
<unit name="crate-effects">
|
||||||
<sequence name="levelup" start="0" length="5" src="levelup" tick="200" />
|
<sequence name="airstrike" start="0" length="9" src="deviator" />
|
||||||
|
<sequence name="nuke" start="0" length="29" src="missile2" />
|
||||||
|
<sequence name="dollar" start="0" length="21" src="dollar" />
|
||||||
|
<sequence name="reveal-map" start="0" length="10" src="earth" />
|
||||||
|
<sequence name="hide-map" start="0" length="19" src="empulse" />
|
||||||
|
<sequence name="heal" start="0" length="35" src="invun" />
|
||||||
|
<sequence name="mine" start="0" length="21" src="mine" />
|
||||||
|
<sequence name="redskull" start="0" length="20" src="rapid" />
|
||||||
|
<sequence name="stealth" start="0" length="15" src="stealth2" />
|
||||||
|
<sequence name="levelup" start="0" length="5" src="levelup" tick="200" />
|
||||||
</unit>
|
</unit>
|
||||||
<unit name="ionsfx">
|
<unit name="ionsfx">
|
||||||
<sequence name="idle" start="0" length="15" />
|
<sequence name="idle" start="0" length="15" />
|
||||||
|
|||||||
@@ -248,4 +248,27 @@ World:
|
|||||||
LevelUp: text2.aud
|
LevelUp: text2.aud
|
||||||
SpatialBins:
|
SpatialBins:
|
||||||
BinSize: 4
|
BinSize: 4
|
||||||
Shroud:
|
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:
|
||||||
|
|||||||
@@ -1,82 +1,38 @@
|
|||||||
Clear:
|
Clear:
|
||||||
Foot: 90%
|
|
||||||
Track: 80%
|
|
||||||
Wheel: 60%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: yes
|
Buildable: yes
|
||||||
|
|
||||||
Rough:
|
Rough:
|
||||||
Foot: 80%
|
|
||||||
Track: 70%
|
|
||||||
Wheel: 40%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
|
|
||||||
Road:
|
Road:
|
||||||
Foot: 100%
|
|
||||||
Track: 100%
|
|
||||||
Wheel: 100%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: yes
|
Buildable: yes
|
||||||
|
|
||||||
Tree:
|
Tree:
|
||||||
Foot: 0%
|
|
||||||
Track: 0%
|
|
||||||
Wheel: 0%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
|
|
||||||
Water:
|
Water:
|
||||||
Foot: 0%
|
|
||||||
Track: 0%
|
|
||||||
Wheel: 0%
|
|
||||||
Float: 100%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
|
|
||||||
Rock:
|
Rock:
|
||||||
Foot: 0%
|
|
||||||
Track: 0%
|
|
||||||
Wheel: 0%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
|
|
||||||
Wall:
|
Wall:
|
||||||
Foot: 0%
|
|
||||||
Track: 0%
|
|
||||||
Wheel: 0%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
|
|
||||||
Ore:
|
Ore:
|
||||||
Foot: 90%
|
|
||||||
Track: 70%
|
|
||||||
Wheel: 50%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
|
|
||||||
Beach:
|
Beach:
|
||||||
Foot: 80%
|
|
||||||
Track: 70%
|
|
||||||
Wheel: 40%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
|
|
||||||
River:
|
River:
|
||||||
Foot: 0%
|
|
||||||
Track: 0%
|
|
||||||
Wheel: 0%
|
|
||||||
Float: 0%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
|
|
||||||
Special:
|
Special:
|
||||||
Foot: 100%
|
|
||||||
Track: 100%
|
|
||||||
Wheel: 100%
|
|
||||||
Float: 100%
|
|
||||||
Buildable: no
|
Buildable: no
|
||||||
AcceptSmudge: no
|
AcceptSmudge: no
|
||||||
Reference in New Issue
Block a user