Fix style issues in CrateSpawner / convert altitude to world coords
This commit is contained in:
@@ -12,8 +12,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Mods.RA.Buildings;
|
|
||||||
using OpenRA.Mods.RA.Air;
|
using OpenRA.Mods.RA.Air;
|
||||||
|
using OpenRA.Mods.RA.Buildings;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
@@ -46,12 +46,12 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
List<Actor> crates = new List<Actor>();
|
List<Actor> crates = new List<Actor>();
|
||||||
int ticks = 0;
|
int ticks = 0;
|
||||||
CrateSpawnerInfo Info;
|
CrateSpawnerInfo info;
|
||||||
Actor self;
|
Actor self;
|
||||||
|
|
||||||
public CrateSpawner(CrateSpawnerInfo info, Actor self)
|
public CrateSpawner(CrateSpawnerInfo info, Actor self)
|
||||||
{
|
{
|
||||||
Info = info;
|
this.info = info;
|
||||||
this.self = self;
|
this.self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +62,12 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
if (--ticks <= 0)
|
if (--ticks <= 0)
|
||||||
{
|
{
|
||||||
ticks = Info.SpawnInterval * 25;
|
ticks = info.SpawnInterval * 25;
|
||||||
|
|
||||||
crates.RemoveAll(x => !x.IsInWorld); // BUG: this removes crates that are cargo of a BADR!
|
crates.RemoveAll(x => !x.IsInWorld); // BUG: this removes crates that are cargo of a BADR!
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
for (var n = 0; n < toSpawn; n++)
|
for (var n = 0; n < toSpawn; n++)
|
||||||
SpawnCrate(self);
|
SpawnCrate(self);
|
||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA
|
|||||||
void SpawnCrate(Actor self)
|
void SpawnCrate(Actor self)
|
||||||
{
|
{
|
||||||
var threshold = 100;
|
var threshold = 100;
|
||||||
var inWater = self.World.SharedRandom.NextFloat() < Info.WaterChance;
|
var inWater = self.World.SharedRandom.NextFloat() < info.WaterChance;
|
||||||
var pp = ChooseDropCell(self, inWater, threshold);
|
var pp = ChooseDropCell(self, inWater, threshold);
|
||||||
|
|
||||||
if (pp == null)
|
if (pp == null)
|
||||||
@@ -88,18 +88,18 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (Info.DeliveryAircraft != null)
|
if (info.DeliveryAircraft != null)
|
||||||
{
|
{
|
||||||
var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
|
var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
|
||||||
crates.Add(crate);
|
crates.Add(crate);
|
||||||
|
|
||||||
var startPos = w.ChooseRandomEdgeCell();
|
var startPos = w.ChooseRandomEdgeCell();
|
||||||
var plane = w.CreateActor(Info.DeliveryAircraft, new TypeDictionary
|
var altitude = Rules.Info[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||||
|
var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary
|
||||||
{
|
{
|
||||||
new LocationInit(startPos),
|
new CenterPositionInit(startPos.CenterPosition + new WVec(WRange.Zero, WRange.Zero, altitude)),
|
||||||
new OwnerInit(w.WorldActor.Owner),
|
new OwnerInit(w.WorldActor.Owner),
|
||||||
new FacingInit(Util.GetFacing(p - startPos, 0)),
|
new FacingInit(Util.GetFacing(p - startPos, 0))
|
||||||
new AltitudeInit(Rules.Info[Info.DeliveryAircraft].Traits.Get<AircraftInfo>().CruiseAltitude),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
plane.CancelActivity();
|
plane.CancelActivity();
|
||||||
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
// Is this valid terrain?
|
// Is this valid terrain?
|
||||||
var terrainType = self.World.GetTerrainType(p);
|
var terrainType = self.World.GetTerrainType(p);
|
||||||
if (!(inWater ? Info.ValidWater : Info.ValidGround).Contains(terrainType))
|
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Don't drop on any actors
|
// Don't drop on any actors
|
||||||
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
string ChooseCrateActor()
|
string ChooseCrateActor()
|
||||||
{
|
{
|
||||||
var crateShares = Info.CrateActorShares;
|
var crateShares = info.CrateActorShares;
|
||||||
var n = self.World.SharedRandom.Next(crateShares.Sum());
|
var n = self.World.SharedRandom.Next(crateShares.Sum());
|
||||||
|
|
||||||
var cumulativeShares = 0;
|
var cumulativeShares = 0;
|
||||||
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
cumulativeShares += crateShares[i];
|
cumulativeShares += crateShares[i];
|
||||||
if (n <= cumulativeShares)
|
if (n <= cumulativeShares)
|
||||||
return Info.CrateActors[i];
|
return info.CrateActors[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user