Make crates not suck

* allow for crates without any associated CrateActions
* allow for crates to not auto-remove
This commit is contained in:
Oliver Brakmann
2014-10-25 13:54:24 +02:00
parent f891b626f3
commit 7b1ab34392
3 changed files with 37 additions and 25 deletions

View File

@@ -20,8 +20,9 @@ namespace OpenRA.Mods.RA
{
class CrateInfo : ITraitInfo, IOccupySpaceInfo, Requires<RenderSpritesInfo>
{
[Desc("Seconds")]
public readonly int Lifetime = 5;
[Desc("Length of time (in seconds) until the crate gets removed automatically. " +
"A value of zero disables auto-removal.")]
public readonly int Lifetime = 0;
[Desc("Allowed to land on.")]
public readonly string[] TerrainTypes = { };
@@ -57,24 +58,27 @@ namespace OpenRA.Mods.RA
if (collected)
return;
var shares = self.TraitsImplementing<CrateAction>()
.Select(a => Pair.New(a, a.GetSelectionSharesOuter(crusher)));
var totalShares = shares.Sum(a => a.Second);
var n = self.World.SharedRandom.Next(totalShares);
var crateActions = self.TraitsImplementing<CrateAction>();
self.Destroy();
collected = true;
foreach (var s in shares)
if (crateActions.Any())
{
if (n < s.Second)
var shares = crateActions.Select(a => Pair.New(a, a.GetSelectionSharesOuter(crusher)));
var totalShares = shares.Sum(a => a.Second);
var n = self.World.SharedRandom.Next(totalShares);
foreach (var s in shares)
{
s.First.Activate(crusher);
return;
if (n < s.Second)
{
s.First.Activate(crusher);
return;
} else
n -= s.Second;
}
else
n -= s.Second;
}
}
@@ -107,7 +111,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
if (++ticks >= info.Lifetime * 25)
if (info.Lifetime != 0 && ++ticks >= info.Lifetime * 25)
self.Destroy();
}

View File

@@ -646,4 +646,18 @@
DestroyedSound: xplobig4.aud
BodyOrientation:
ScriptTriggers:
^Crate:
Tooltip:
Name: Crate
GenericName: Crate
Crate:
TerrainTypes: Clear, Rough, Road, Tiberium, BlueTiberium, Beach
RenderSprites:
Palette: effect
WithCrateBody:
XmasImages: xcratea, xcrateb, xcratec, xcrated
Selectable:
Selectable: false
Bounds: 15,15,-1,-1
BodyOrientation:

View File

@@ -1,9 +1,11 @@
CRATE.plain:
Inherits: ^Crate
ScriptTriggers:
CRATE:
Tooltip:
Name: Crate
Inherits: ^Crate
Crate:
Lifetime: 240
TerrainTypes: Clear, Rough, Road, Tiberium, BlueTiberium, Beach
GiveCashCrateAction:
Amount: 1000
SelectionShares: 20
@@ -27,14 +29,6 @@ CRATE:
SelectionShares: 0
NoBaseSelectionShares: 120
Units: mcv
RenderSprites:
Palette: effect
WithCrateBody:
XmasImages: xcratea, xcrateb, xcratec, xcrated
Selectable:
Selectable: false
Bounds: 15,15,-1,-1
BodyOrientation:
mpspawn:
Immobile: