forked from Mirrors/openclonk
Library_Flammable: Logic for flammable objects / items.
When ignited, the object will burn for a fixed time (BurnTime property, default is 70 frames) with no detriment to its function. After that time, the object will change to a 'Burned Object', no longer useful for anything.install-platforms
parent
5c45d7a08e
commit
41676186a1
|
@ -0,0 +1,9 @@
|
|||
[DefCore]
|
||||
id=Icon_Flame
|
||||
Version=8,0
|
||||
Category=C4D_StaticBack
|
||||
Picture=0,0,128,128
|
||||
Width=128
|
||||
Height=128
|
||||
Offset=-64,-64
|
||||
HideInCreator=true
|
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
|
@ -0,0 +1,17 @@
|
|||
[DefCore]
|
||||
id=BurnedObject
|
||||
Version=8,0
|
||||
Category=C4D_Object
|
||||
Width=12
|
||||
Height=5
|
||||
Offset=-6,-3
|
||||
Vertices=3
|
||||
VertexX=5,-4
|
||||
VertexY=0,0
|
||||
VertexCNAT=1,2
|
||||
VertexFriction=50,50
|
||||
Mass=1
|
||||
Rotate=1
|
||||
Picture=0,24,60,60
|
||||
Float=1
|
||||
StretchGrowth=1
|
Binary file not shown.
After Width: | Height: | Size: 9.6 KiB |
|
@ -0,0 +1,80 @@
|
|||
/*-- Burned Object --*/
|
||||
|
||||
func Incineration()
|
||||
{
|
||||
CreateEffect(BurnDown, 1, 5); // No need for a 1 frame timer anymore
|
||||
|
||||
// Notify the clonk (if held) that this object is now burning
|
||||
if (Contained())
|
||||
Contained()->~OnInventoryChange();
|
||||
}
|
||||
|
||||
public func Extinguishing()
|
||||
{
|
||||
// Notify the clonk (if held) that this object is no longer burning
|
||||
if (Contained())
|
||||
Contained()->~OnInventoryChange();
|
||||
}
|
||||
|
||||
public func BurstIntoAshes()
|
||||
{
|
||||
var particles =
|
||||
{
|
||||
Prototype = Particles_Dust(),
|
||||
R = 50, G = 50, B = 50,
|
||||
Size = PV_KeyFrames(0, 0, 0, 200, PV_Random(2, 10), 1000, 0),
|
||||
};
|
||||
|
||||
var r = GetR();
|
||||
var size = GetCon() * 110 / 100;
|
||||
|
||||
for(var cnt = 0; cnt < 5; ++cnt)
|
||||
{
|
||||
var distance = 3;
|
||||
var x = Sin(r, distance);
|
||||
var y = -Cos(r, distance);
|
||||
|
||||
for(var mirror = -1; mirror <= 1; mirror += 2)
|
||||
{
|
||||
CreateParticle("Dust", x * mirror, y * mirror, PV_Random(-3, 3), PV_Random(-3, -3), PV_Random(18, 1 * 36), particles, 2);
|
||||
CastPXS("Ashes", 1, 30, x * mirror, y * mirror);
|
||||
}
|
||||
}
|
||||
RemoveObject();
|
||||
}
|
||||
|
||||
local BurnDown = new Effect {
|
||||
Timer = func (int time) {
|
||||
if (this.Target->GetCon() <= 65)
|
||||
this.Target->BurstIntoAshes();
|
||||
}
|
||||
};
|
||||
|
||||
func Hit()
|
||||
{
|
||||
Sound("Hits::GeneralHit?");
|
||||
}
|
||||
|
||||
public func GetInventoryIconOverlay() // Display a flame in the inventory bar
|
||||
{
|
||||
if (!OnFire()) return;
|
||||
|
||||
var overlay =
|
||||
{
|
||||
Symbol = Icon_Flame
|
||||
};
|
||||
return overlay;
|
||||
}
|
||||
|
||||
public func IsFuel() { return true; }
|
||||
public func GetFuelAmount()
|
||||
{
|
||||
return GetCon()/2;
|
||||
}
|
||||
|
||||
local Collectible = 1;
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
||||
local BlastIncinerate = 1;
|
||||
local ContactIncinerate = 1;
|
||||
local Plane = 390;
|
|
@ -0,0 +1,2 @@
|
|||
Name=Verbrannter Gegenstand
|
||||
Description=War mal nützlich, ist jetzt aber verbrannt. Kann weiter verbrannt werden!
|
|
@ -0,0 +1,2 @@
|
|||
Name=Burned object
|
||||
Description=Once useful, now just junk. Or fuel.
|
|
@ -0,0 +1,5 @@
|
|||
[DefCore]
|
||||
id=Library_Flammable
|
||||
Version=8,0
|
||||
Category=C4D_StaticBack
|
||||
HideInCreator=true
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
Library_Flammable
|
||||
|
||||
Contains the logic for any object/item that is flammable.
|
||||
Flammable objects (items) shouldn't burn like any other object because dealing with
|
||||
half burned (con < 100) items is a hassle.
|
||||
|
||||
Implement OnBurnDown() to do this things right when the definition change is about to happen.
|
||||
Return true to prevent regular library behaviour.
|
||||
|
||||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
// Obviously, we don't want these items to burn down
|
||||
local NoBurnDecay = 1;
|
||||
// Items will burn for roughly 2 seconds until changing into a 'burned item' (no longer functional)
|
||||
// Feel free to change this time in your object (in frames)
|
||||
local BurnDownTime = 70;
|
||||
|
||||
public func Incineration(int caused_by)
|
||||
{
|
||||
_inherited(caused_by);
|
||||
// You shouldn't remove the object in Incineration but let's check anyway
|
||||
if (!this) return;
|
||||
|
||||
CreateEffect(LibraryFlammable, 1, 1, caused_by); // The effect will not last long, so timer 1 should be fine
|
||||
|
||||
// Notify the clonk (if held) that this object is now burning
|
||||
if (Contained())
|
||||
Contained()->~OnInventoryChange();
|
||||
}
|
||||
|
||||
public func Extinguishing()
|
||||
{
|
||||
// Notify the clonk (if held) that this object is no longer burning
|
||||
if (Contained())
|
||||
Contained()->~OnInventoryChange();
|
||||
}
|
||||
|
||||
local LibraryFlammable = new Effect {
|
||||
Construction = func (int caused_by)
|
||||
{
|
||||
this.caused_by = caused_by;
|
||||
},
|
||||
Timer = func (int time)
|
||||
{
|
||||
if (!this.Target->OnFire()) // Extinguished! No harm done
|
||||
return FX_Execute_Kill;
|
||||
if (time >= this.Target.BurnDownTime)
|
||||
{
|
||||
this.Target->BurnDown(this.caused_by);
|
||||
return FX_Execute_Kill;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public func BurnDown(int caused_by)
|
||||
{
|
||||
if (this->~OnBurnDown()) return;
|
||||
var burned = CreateObject(BurnedObject, 0,0, GetOwner());
|
||||
var x = GetDefWidth();
|
||||
var y = GetDefHeight();
|
||||
var container = Contained();
|
||||
burned->SetR(GetR());
|
||||
burned->Incinerate(100, caused_by);
|
||||
//RemoveObject(true); // TODO: uncomment once bug #1950 has been resolved
|
||||
RemoveObject();
|
||||
if (container)
|
||||
burned->Enter(container);
|
||||
}
|
||||
|
||||
public func GetInventoryIconOverlay() // Display a flame in the inventory bar
|
||||
{
|
||||
if (!OnFire()) return;
|
||||
|
||||
var overlay =
|
||||
{
|
||||
Symbol = Icon_Flame
|
||||
};
|
||||
return overlay;
|
||||
}
|
Loading…
Reference in New Issue