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
|
||||
{
|
||||
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?");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace OpenRA
|
||||
{
|
||||
public int2 from;
|
||||
public int2 to;
|
||||
public UnitMovementType umt;
|
||||
public List<int2> result;
|
||||
public int tick;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA
|
||||
public class CargoInfo : TraitInfo<Cargo>
|
||||
{
|
||||
public readonly int Passengers = 0;
|
||||
public readonly UnitMovementType[] PassengerTypes = { };
|
||||
public readonly string[] PassengerTypes = { };
|
||||
public readonly int UnloadFacing = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<RenderSimple>().anim.CurrentSequence.Name)
|
||||
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.Activities;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
|
||||
using OpenRA.FileFormats;
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class CrateDropInfo : TraitInfo<CrateDrop>
|
||||
{
|
||||
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<BuildingInfluence>().GetBuildingAt(p) != null) 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 =>
|
||||
{
|
||||
var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner);
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class CrateSpawnerInfo : TraitInfo<CrateSpawner>
|
||||
{
|
||||
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<Actor> crates = new List<Actor>();
|
||||
int ticks = 0;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
var info = self.Info.Traits.Get<CrateSpawnerInfo>();
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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<CrateSpawner>
|
||||
{
|
||||
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<Actor> crates = new List<Actor>();
|
||||
int ticks = 0;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
var info = self.Info.Traits.Get<CrateSpawnerInfo>();
|
||||
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<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" />
|
||||
</unit>
|
||||
<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 name="ionsfx">
|
||||
<sequence name="idle" start="0" length="15" />
|
||||
|
||||
@@ -248,4 +248,27 @@ World:
|
||||
LevelUp: text2.aud
|
||||
SpatialBins:
|
||||
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:
|
||||
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
|
||||
Reference in New Issue
Block a user