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:
Paul Chote
2010-06-25 21:58:09 +12:00
parent 7c3a10396c
commit 2373528ad9
9 changed files with 143 additions and 171 deletions

View File

@@ -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?");
}
}
} }
} }

View File

@@ -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;
} }

View File

@@ -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;
} }

View File

@@ -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; }
} }
} }

View File

@@ -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);

View File

@@ -20,21 +20,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Activities;
using OpenRA.FileFormats;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class CrateSpawnerInfo : TraitInfo<CrateSpawner> public class CrateSpawnerInfo : TraitInfo<CrateSpawner>
{ {
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
} }
// assumption: there is always at least one free water cell, and one free land cell. public class CrateSpawner : ITick
class CrateSpawner : ITick
{ {
List<Actor> crates = new List<Actor>(); List<Actor> crates = new List<Actor>();
int ticks = 0; int ticks = 0;
@@ -46,7 +50,7 @@ namespace OpenRA.Mods.RA
var info = self.Info.Traits.Get<CrateSpawnerInfo>(); var info = self.Info.Traits.Get<CrateSpawnerInfo>();
ticks = info.SpawnInterval * 25; // todo: randomize ticks = info.SpawnInterval * 25; // todo: randomize
crates.RemoveAll(c => !c.IsInWorld); crates.RemoveAll(x => !x.IsInWorld);
var toSpawn = Math.Max(0, info.Minimum - crates.Count) var toSpawn = Math.Max(0, info.Minimum - crates.Count)
+ (crates.Count < info.Maximum ? 1 : 0); + (crates.Count < info.Maximum ? 1 : 0);
@@ -56,22 +60,30 @@ namespace OpenRA.Mods.RA
} }
} }
const int ChooseCrateLocationAttempts = 100;
void SpawnCrate(Actor self, CrateSpawnerInfo info) void SpawnCrate(Actor self, CrateSpawnerInfo info)
{ {
var threshold = 100;
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
for (var n = 0; n < ChooseCrateLocationAttempts; n++) for (var n = 0; n < threshold; n++ )
{ {
var p = self.World.ChooseRandomCell(self.World.SharedRandom); var p = self.World.ChooseRandomCell(self.World.SharedRandom);
if (self.World.IsCellBuildable(p, inWater)) // 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<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( self.World.AddFrameEndTask(
w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner))); w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner)));
break; return;
}
} }
} }
} }

View File

@@ -122,6 +122,15 @@
<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="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" /> <sequence name="levelup" start="0" length="5" src="levelup" tick="200" />
</unit> </unit>
<unit name="ionsfx"> <unit name="ionsfx">

View File

@@ -249,3 +249,26 @@ World:
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:

View File

@@ -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