openclonk/planet/Objects.ocd/Vegetation.ocd/Trees.ocd/Coniferous.ocd/Script.c

75 lines
1.9 KiB
C

/*-- Coniferous Tree --*/
#include Library_Plant
#include Library_Tree
// Overloaded from the plant library to add the foreground parameter, foreground = true will roughly make every 3rd tree foreground (not the offspring though)
func Place(int amount, proplist rectangle, proplist settings, bool foreground)
{
// Default behaviour
var trees = inherited(amount, rectangle, settings);
if (GetLength(trees) < 1) return trees;
for (var tree in trees)
if (!Random(3))
tree.Plane = 510;
return trees;
}
private func SeedChance() { return 500; }
private func SeedArea() { return 400; }
private func SeedAmount() { return 10; }
func Construction()
{
StartGrowth(5);
// set random rotation so trees don't look alike too much
SetProperty("MeshTransformation", Trans_Rotate(RandomX(0,359),0,1,0));
inherited(...);
}
public func ChopDown()
{
// Use Special Vertex Mode 1 (see documentation) so the removed vertex won't come back when rotating the tree.
SetVertex(0, VTX_Y, 0, 1);
// Remove the bottom vertex
RemoveVertex(0);
_inherited(...);
}
func SplitDown()
{
for (var i = 0 ; i < GetComponent(Chunk_Wood) ; i++)
{
var x = Sin(GetR(), 15 * ( i - GetComponent(Chunk_Wood,nil,nil, GetID())/2 )); // Chunk_Wood is 12 in size, 15 seems about good
var y = Cos(GetR(), -15 * ( i - GetComponent(Chunk_Wood,nil,nil, GetID())/2 ));
CreateObject(Chunk_Wood, x,y)->SetR(GetR());
}
RemoveObject();
}
func Damage()
{
_inherited();
if (GetDamage() > MaxDamage() && OnFire())
{
var burned = CreateObject(Tree_Coniferous_Burned, 0, 0, GetOwner());
burned->SetCategory(GetCategory());
burned.Touchable = this.Touchable;
burned->SetCon(GetCon());
burned->SetR(GetR());
burned->Incinerate(OnFire());
burned->SetPosition(GetX(), GetY());
Sound("TreeCrack", false);
RemoveObject();
return;
}
}
local Name = "$Name$";
local Touchable = 0;
local BlastIncinerate = 2;
local ContactIncinerate = 6;
local NoBurnDecay = 1;