Use add and remove world notifications on Crate to maintain the CrateSpawner list of crates
This commit is contained in:
@@ -132,6 +132,10 @@ namespace OpenRA.Mods.RA
|
|||||||
self.World.ActorMap.AddInfluence(self, this);
|
self.World.ActorMap.AddInfluence(self, this);
|
||||||
self.World.ActorMap.AddPosition(self, this);
|
self.World.ActorMap.AddPosition(self, this);
|
||||||
self.World.ScreenMap.Add(self);
|
self.World.ScreenMap.Add(self);
|
||||||
|
|
||||||
|
var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>();
|
||||||
|
if (cs != null)
|
||||||
|
cs.IncrementCrates();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemovedFromWorld(Actor self)
|
public void RemovedFromWorld(Actor self)
|
||||||
@@ -139,6 +143,10 @@ namespace OpenRA.Mods.RA
|
|||||||
self.World.ActorMap.RemoveInfluence(self, this);
|
self.World.ActorMap.RemoveInfluence(self, this);
|
||||||
self.World.ActorMap.RemovePosition(self, this);
|
self.World.ActorMap.RemovePosition(self, this);
|
||||||
self.World.ScreenMap.Remove(self);
|
self.World.ScreenMap.Remove(self);
|
||||||
|
|
||||||
|
var cs = self.World.WorldActor.TraitOrDefault<CrateSpawner>();
|
||||||
|
if (cs != null)
|
||||||
|
cs.DecrementCrates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public class CrateSpawner : ITick
|
public class CrateSpawner : ITick
|
||||||
{
|
{
|
||||||
List<Actor> crates = new List<Actor>();
|
int crates = 0;
|
||||||
int ticks = 0;
|
int ticks = 0;
|
||||||
CrateSpawnerInfo info;
|
CrateSpawnerInfo info;
|
||||||
Actor self;
|
Actor self;
|
||||||
@@ -64,10 +64,8 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
ticks = info.SpawnInterval * 25;
|
ticks = info.SpawnInterval * 25;
|
||||||
|
|
||||||
crates.RemoveAll(x => !x.IsInWorld); // BUG: this removes crates that are cargo of a BADR!
|
var toSpawn = Math.Max(0, info.Minimum - crates)
|
||||||
|
+ (crates < info.Maximum ? 1 : 0);
|
||||||
var toSpawn = Math.Max(0, info.Minimum - crates.Count)
|
|
||||||
+ (crates.Count < info.Maximum ? 1 : 0);
|
|
||||||
|
|
||||||
for (var n = 0; n < toSpawn; n++)
|
for (var n = 0; n < toSpawn; n++)
|
||||||
SpawnCrate(self);
|
SpawnCrate(self);
|
||||||
@@ -91,8 +89,6 @@ namespace OpenRA.Mods.RA
|
|||||||
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);
|
|
||||||
|
|
||||||
var startPos = w.ChooseRandomEdgeCell();
|
var startPos = w.ChooseRandomEdgeCell();
|
||||||
var altitude = Rules.Info[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
|
var altitude = Rules.Info[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||||
var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary
|
var plane = w.CreateActor(info.DeliveryAircraft, new TypeDictionary
|
||||||
@@ -109,7 +105,7 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
crates.Add(w.CreateActor(crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner), new LocationInit(p) }));
|
w.CreateActor(crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner), new LocationInit(p) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -151,5 +147,15 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void IncrementCrates()
|
||||||
|
{
|
||||||
|
crates++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DecrementCrates()
|
||||||
|
{
|
||||||
|
crates--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user