Target balloon: Allow deployment of any items.

liquid_container
Sven Eberhardt 2016-02-07 14:27:51 -05:00
parent 35fcc0ff51
commit 3d3e848aeb
1 changed files with 68 additions and 4 deletions

View File

@ -4,7 +4,9 @@
*/
local rider;
local cargo, has_cargo=false, old_cargo_action;
local parent;
local deployment_yoffset=50;
protected func Initialize()
{
@ -24,6 +26,64 @@ public func SetRider(object clonk)
rider = clonk;
}
public func SetInflated()
{
// Skip inflating animation
if (GetAction() == "Inflate") SetAction("Float");
}
// Sets a cargo object that is held by the balloon
// (only works with objects that do not themselves have an action)
// attach_vertex: Vertex in attached object to stick to the balloon
// xoff, yoff: Move attachment vertex on balloon by this
// deploy_yoff: Move deployment vertices vertically by this (for e.g. firestones to not drop and explode)
public func SetCargo(object new_cargo, int attach_vertex, int xoff, int yoff, int deploy_yoff)
{
DropCargo(); // drop any previous
cargo = new_cargo;
has_cargo = !!cargo;
if (has_cargo)
{
old_cargo_action = cargo->GetAction();
if (new_cargo.ActMap)
{
if (new_cargo.ActMap == new_cargo.Prototype.ActMap) new_cargo.ActMap = new new_cargo.ActMap {};
}
else
{
new_cargo.ActMap = { };
}
new_cargo.ActMap.BalloonDeployedAttach = new Action {
Prototype = Action,
Name = "BalloonDeployedAttach",
Procedure = DFA_ATTACH,
Delay = 9999999,
Length = 1,
FacetBase = 1,
};
cargo->SetAction("BalloonDeployedAttach", this);
cargo->SetActionData(attach_vertex);
SetVertex(0, VTX_X, xoff);
SetVertex(0, VTX_Y, yoff + 30);
deployment_yoffset = deploy_yoff + 50;
SetVertex(8, VTX_Y, deploy_yoff + 35);
SetVertex(9, VTX_Y, deploy_yoff + 30);
SetVertex(10, VTX_Y, deploy_yoff + 30);
}
return true;
}
public func DropCargo()
{
if (has_cargo && cargo)
{
cargo->SetAction(old_cargo_action);
cargo = nil;
has_cargo = false;
return true;
}
}
public func SetParent(object balloon)
{
parent = balloon;
@ -36,6 +96,7 @@ public func GetParent()
private func Deflate()
{
DropCargo();
if (GetAction() != "Deflate")
{
SetAction("Deflate");
@ -124,14 +185,14 @@ public func FxControlFloatTimer(object target, proplist effect, int time)
xdir_dev = 1;
}
SetXDir(xdir + xdir_dev);
// Has a bottom vertex hit? Is the balloon stuck in material? Then deflate.
if (GetContact(-1) & CNAT_Bottom || Stuck())
// Has a bottom vertex hit? Is the balloon stuck in material? Is the cargo gone? Then deflate.
if (GetContact(-1) & CNAT_Bottom || Stuck() || (has_cargo && (!cargo || cargo->Contained())))
{
Deflate();
return FX_Execute_Kill;
}
if (GBackSolid(0, 50) || GBackLiquid(0, 50))
if (GBackSolid(0, deployment_yoffset) || GBackLiquid(0, deployment_yoffset))
{
Deflate();
return FX_OK;
@ -179,6 +240,9 @@ public func OnProjectileHit(object projectile)
rider->SetKiller(projectile->GetController());
rider->SetAction("Tumble");
}
// Drop anything being transported
DropCargo();
// We're done.
RemoveObject();
}