forked from Mirrors/openclonk
airplane and airship use destructible library
parent
4b4e4a5522
commit
477bde5c88
|
@ -5,6 +5,9 @@
|
|||
@author: Ringwaul, Clonkonaut, Maikel
|
||||
*/
|
||||
|
||||
// Airplane is destructible.
|
||||
#include Library_Destructible
|
||||
|
||||
local dir = DIR_Left;
|
||||
|
||||
local prop_speed, prop_speed_target, prop_speed_timer; // current and target propeller speed [0, 100]
|
||||
|
@ -40,17 +43,6 @@ public func RejectCollect(id def, object obj)
|
|||
return false;
|
||||
}
|
||||
|
||||
public func Damage(int change, int cause, int by_player)
|
||||
{
|
||||
if (GetDamage() >= this.HitPoints)
|
||||
{
|
||||
if (pilot)
|
||||
PlaneDismount(pilot);
|
||||
SetController(by_player);
|
||||
PlaneDeath();
|
||||
}
|
||||
}
|
||||
|
||||
public func ActivateEntrance(object clonk)
|
||||
{
|
||||
if (clonk->Contained() == this)
|
||||
|
@ -77,18 +69,6 @@ public func Ejection(object obj)
|
|||
obj->SetSpeed(this->GetXDir(), this->GetYDir());
|
||||
}
|
||||
|
||||
// Inflict damage when hitting something with the plane and already damaged.
|
||||
public func Hit(int xdir, int ydir)
|
||||
{
|
||||
var remaining_hp = this.HitPoints - GetDamage();
|
||||
if (remaining_hp < 10)
|
||||
{
|
||||
var speed = Distance(0, 0, xdir, ydir) / 10;
|
||||
if (speed > 4 * remaining_hp)
|
||||
DoDamage(speed / 6, FX_Call_DmgScript, GetController());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-- Callbacks --*/
|
||||
|
||||
|
@ -1185,14 +1165,8 @@ public func GetPilot()
|
|||
return pilot;
|
||||
}
|
||||
|
||||
/*-- Effects --*/
|
||||
|
||||
private func PlaneDeath()
|
||||
{
|
||||
while (Contents(0))
|
||||
Contents(0)->Exit();
|
||||
Explode(36);
|
||||
}
|
||||
/*-- Effects --*/
|
||||
|
||||
// Instantly set new propeller speed
|
||||
public func SetPropellerSpeed(int new_speed)
|
||||
|
@ -1236,6 +1210,41 @@ private func SetPropellerSound(int speed)
|
|||
}
|
||||
|
||||
|
||||
/*-- Destruction --*/
|
||||
|
||||
// Destroyed by any type of damage.
|
||||
public func IsDestroyedByExplosions() { return false; }
|
||||
|
||||
// Custom explosion on callback from destructible library.
|
||||
public func OnDestruction(int change, int cause, int by_player)
|
||||
{
|
||||
if (pilot)
|
||||
PlaneDismount(pilot);
|
||||
SetController(by_player);
|
||||
PlaneDeath();
|
||||
return true;
|
||||
}
|
||||
|
||||
private func PlaneDeath()
|
||||
{
|
||||
while (Contents(0))
|
||||
Contents(0)->Exit();
|
||||
Explode(36);
|
||||
}
|
||||
|
||||
// Inflict damage when hitting something with the plane and already damaged.
|
||||
public func Hit(int xdir, int ydir)
|
||||
{
|
||||
var remaining_hp = this.HitPoints - GetDamage();
|
||||
if (remaining_hp < 10)
|
||||
{
|
||||
var speed = Distance(0, 0, xdir, ydir) / 10;
|
||||
if (speed > 4 * remaining_hp)
|
||||
DoDamage(speed / 6, FX_Call_DmgScript, GetController());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*-- Production --*/
|
||||
|
||||
public func IsVehicle() { return true; }
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
|
||||
#include Library_AlignVehicleRotation
|
||||
// Airship is destructible.
|
||||
#include Library_Destructible
|
||||
|
||||
// Graphic module variables for animation
|
||||
local propanim, turnanim;
|
||||
|
@ -14,8 +16,8 @@ local propanim, turnanim;
|
|||
local throttle;
|
||||
local enginesound;
|
||||
|
||||
//Rectangle defining where to look for objents contained in the gondola
|
||||
local gondola = [-20,-2,40,30];
|
||||
// Rectangle defining where to look for objects contained in the gondola.
|
||||
local gondola = [-20, -2, 40, 30];
|
||||
|
||||
|
||||
protected func Initialize()
|
||||
|
@ -36,15 +38,6 @@ protected func Initialize()
|
|||
AddEffect("IntAirshipMovement", this, 1, 1, this);
|
||||
}
|
||||
|
||||
public func Damage(int change, int cause, int by_player)
|
||||
{
|
||||
if (GetDamage() >= this.HitPoints)
|
||||
{
|
||||
SetController(by_player);
|
||||
AirshipDeath();
|
||||
}
|
||||
}
|
||||
|
||||
public func FxIntAirshipMovementStart(object target, proplist effect, int temporary)
|
||||
{
|
||||
if (temporary)
|
||||
|
@ -321,9 +314,20 @@ public func IsProjectileTarget(object projectile, object shooter)
|
|||
}
|
||||
|
||||
|
||||
/* -- Airship Destruction --*/
|
||||
/*-- Destruction --*/
|
||||
|
||||
func AirshipDeath()
|
||||
// Destroyed by any type of damage.
|
||||
public func IsDestroyedByExplosions() { return false; }
|
||||
|
||||
// Custom explosion on callback from destructible library.
|
||||
public func OnDestruction(int change, int cause, int by_player)
|
||||
{
|
||||
SetController(by_player);
|
||||
AirshipDeath();
|
||||
return true;
|
||||
}
|
||||
|
||||
private func AirshipDeath()
|
||||
{
|
||||
//First let's create the burnt airship
|
||||
var burntairship = CreateObjectAbove(Airship_Burnt,0,27); //27 pixels down to align ruin with original
|
||||
|
@ -331,17 +335,18 @@ func AirshipDeath()
|
|||
//Now let's copy it's animation, and hold it there
|
||||
var animspot;
|
||||
animspot = GetAnimationPosition(turnanim);
|
||||
if(turnanim == -1) burntairship->PlayAnimation("TurnLeft", 10, Anim_Const(animspot)); // this doesn't make sense
|
||||
if (turnanim == -1)
|
||||
burntairship->PlayAnimation("TurnLeft", 10, Anim_Const(animspot)); // this doesn't make sense
|
||||
else
|
||||
burntairship->PlayAnimation("TurnRight", 10, Anim_Const(animspot));
|
||||
|
||||
// Set ruin on fire: set controller of the fire to the cause of the death (which is the current controller of the airship).
|
||||
burntairship->Incinerate(100, GetController());
|
||||
|
||||
//Make sure engine sound is gone
|
||||
// Make sure engine sound is gone
|
||||
Sound("Structures::FanLoop",nil,nil,nil,-1);
|
||||
|
||||
//This object has served its purpose.
|
||||
// This object has served its purpose.
|
||||
Explode(20);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue