Merge pull request #3926 from Phrohdoh/EjectOnDeath
EjectOnDeath - updated and 100% working
This commit is contained in:
@@ -137,6 +137,7 @@ namespace OpenRA.Traits
|
||||
public interface IPositionable : IOccupySpace
|
||||
{
|
||||
bool CanEnterCell(CPos location);
|
||||
bool CanEnterCell(CPos location, Actor ignoreActor, bool checkTransientActors);
|
||||
void SetPosition(Actor self, CPos cell);
|
||||
void SetPosition(Actor self, WPos pos);
|
||||
void SetVisualPosition(Actor self, WPos pos);
|
||||
|
||||
@@ -140,6 +140,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
}
|
||||
|
||||
public bool CanEnterCell(CPos location) { return true; }
|
||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { return CanEnterCell(cell, null, true); }
|
||||
|
||||
public int MovementSpeed
|
||||
{
|
||||
|
||||
@@ -88,19 +88,26 @@ namespace OpenRA.Mods.RA
|
||||
public void SetPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
|
||||
public void SetVisualPosition(Actor self, WPos pos) { SetPosition(self, pos.ToCPos()); }
|
||||
|
||||
public bool CanEnterCell(CPos cell)
|
||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false;
|
||||
|
||||
var type = self.World.GetTerrainType(cell);
|
||||
if (!info.TerrainTypes.Contains(type))
|
||||
return false;
|
||||
|
||||
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell) != null) return false;
|
||||
if (self.World.ActorMap.GetUnitsAt(cell).Any()) return false;
|
||||
|
||||
return true;
|
||||
if (!checkTransientActors)
|
||||
return true;
|
||||
|
||||
return !self.World.ActorMap.GetUnitsAt(cell)
|
||||
.Where(x => x != ignoreActor)
|
||||
.Any();
|
||||
}
|
||||
|
||||
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
|
||||
|
||||
public void SetPosition(Actor self, CPos cell)
|
||||
{
|
||||
self.World.ActorMap.RemoveInfluence(self, this);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -20,33 +20,46 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string PilotActor = "E1";
|
||||
public readonly int SuccessRate = 50;
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
public readonly WRange MinimumEjectHeight = new WRange(427);
|
||||
public readonly bool EjectInAir = false;
|
||||
public readonly bool EjectOnGround = false;
|
||||
}
|
||||
|
||||
public class EjectOnDeath : INotifyKilled
|
||||
{
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
|
||||
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
|
||||
new TypeDictionary { new OwnerInit(self.Owner) });
|
||||
if (self.Owner.WinState == WinState.Lost)
|
||||
return;
|
||||
|
||||
var r = self.World.SharedRandom.Next(1, 100);
|
||||
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
|
||||
|
||||
if (r <= 100 - info.SuccessRate)
|
||||
return;
|
||||
|
||||
var cp = self.CenterPosition;
|
||||
|
||||
if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && cp.Z > info.MinimumEjectHeight.Range
|
||||
&& self.Owner.WinState != WinState.Lost)
|
||||
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
|
||||
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
|
||||
|
||||
|
||||
if (IsSuitableCell(self, pilot, self.Location))
|
||||
{
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
|
||||
Sound.Play(info.ChuteSound, cp);
|
||||
if (cp.Z > 0)
|
||||
{
|
||||
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
|
||||
Sound.Play(info.ChuteSound, cp);
|
||||
}
|
||||
else
|
||||
self.World.AddFrameEndTask(w => w.Add(pilot));
|
||||
}
|
||||
else
|
||||
pilot.Destroy();
|
||||
}
|
||||
|
||||
bool IsSuitableCell(Actor actorToDrop, CPos p)
|
||||
bool IsSuitableCell(Actor self, Actor actorToDrop, CPos p)
|
||||
{
|
||||
return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
|
||||
return actorToDrop.Trait<IPositionable>().CanEnterCell(self.Location, self, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
||||
public bool CanEnterCell(CPos cell)
|
||||
public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors)
|
||||
{
|
||||
if (!self.World.Map.IsInMap(cell.X, cell.Y))
|
||||
return false;
|
||||
@@ -60,9 +60,16 @@ namespace OpenRA.Mods.RA
|
||||
if (!info.AllowedTerrain.Contains(self.World.GetTerrainType(cell)))
|
||||
return false;
|
||||
|
||||
return !self.World.ActorMap.AnyUnitsAt(cell);
|
||||
if (!checkTransientActors)
|
||||
return true;
|
||||
|
||||
return !self.World.ActorMap.GetUnitsAt(cell)
|
||||
.Where(x => x != ignoreActor)
|
||||
.Any();
|
||||
}
|
||||
|
||||
public bool CanEnterCell(CPos cell) { return CanEnterCell(cell, null, true); }
|
||||
|
||||
public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); }
|
||||
public void SetVisualPosition(Actor self, WPos pos)
|
||||
{
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
<Compile Include="Air\Aircraft.cs" />
|
||||
<Compile Include="Air\AttackHeli.cs" />
|
||||
<Compile Include="Air\AttackPlane.cs" />
|
||||
<Compile Include="Air\EjectOnDeath.cs" />
|
||||
<Compile Include="EjectOnDeath.cs" />
|
||||
<Compile Include="Air\FallsToEarth.cs" />
|
||||
<Compile Include="Air\Fly.cs" />
|
||||
<Compile Include="Air\FlyAttack.cs" />
|
||||
|
||||
@@ -37,6 +37,11 @@
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
EjectOnDeath:
|
||||
PilotActor: e1
|
||||
SuccessRate: 20
|
||||
EjectOnGround: yes
|
||||
EjectInAir: no
|
||||
|
||||
^Tank:
|
||||
AppearsOnRadar:
|
||||
@@ -77,6 +82,11 @@
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
EjectOnDeath:
|
||||
PilotActor: e1
|
||||
SuccessRate: 20
|
||||
EjectOnGround: yes
|
||||
EjectInAir: no
|
||||
|
||||
^Infantry:
|
||||
AppearsOnRadar:
|
||||
@@ -185,6 +195,8 @@
|
||||
EjectOnDeath:
|
||||
PilotActor: E1
|
||||
SuccessRate: 50
|
||||
EjectOnGround: no
|
||||
EjectInAir: yes
|
||||
GivesBounty:
|
||||
GpsDot:
|
||||
String:Plane
|
||||
|
||||
Reference in New Issue
Block a user