openclonk/planet/Objects.ocd/Structures.ocd/Foundry.ocd/Script.c

152 lines
2.9 KiB
C
Raw Normal View History

/*--
Foundry
Authors: Ringwaul, Maikel
Melts iron ore to metal, using some sort of fuel.
--*/
#include Library_Producer
2011-01-29 07:41:11 +00:00
public func Initialize()
{
_inherited(...);
queue = [[Metal, nil]];
return;
2011-01-29 07:41:11 +00:00
}
public func CanProduceItem(id item_id)
{
if (item_id == Metal)
return true;
return false;
}
2011-01-29 07:41:11 +00:00
public func NeedsRawMaterial(id rawmat_id)
2011-01-29 07:41:11 +00:00
{
if (rawmat_id == Coal || rawmat_id == Wood || rawmat_id == Ore)
return true;
return false;
}
public func IsProducing()
{
if (GetEffect("Smelting", this))
return true;
return false;
2011-01-29 07:41:11 +00:00
}
private func Produce(id item_id)
2011-01-29 07:41:11 +00:00
{
// Check if material is available.
if (item_id == Metal)
if (!FindContents(Ore))
return false;
// Check if fuel is available, TODO: oil
if (ContentsCount(Wood) < 2 && !FindContents(Coal))
return false;
// If already busy, wait a little.
if (IsProducing())
return false;
// Start production.
AddEffect("Smelting",this,1,1,this);
Sound("FurnaceStart.ogg");
AddEffect("IntSoundDelay",this,1,1,this);
return true;
2011-01-29 07:41:11 +00:00
}
local cast = 0;
protected func Collection()
2011-01-29 07:41:11 +00:00
{
Sound("Clonk.ogg");
return;
2011-01-29 07:41:11 +00:00
}
public func FxSmeltingStart(object target, num, int temporary)
2011-01-29 07:41:11 +00:00
{
FindContents(Ore)->RemoveObject();
//Use coal as firing material
var coal = FindContents(Coal);
if(coal)
{
coal->RemoveObject();
return;
}
//Use wood as firing material
if(ContentsCount(Wood) >= 2)
{
FindContents(Wood)->RemoveObject();
FindContents(Wood)->RemoveObject();
return;
}
}
public func FxSmeltingTimer(object target, num, int timer)
2011-01-29 07:41:11 +00:00
{
Message(Format("Smelting %d",timer));
//Visuals
//Fire
2011-02-12 09:40:56 +00:00
CreateParticle("Fire",10,14,RandomX(-1,1),RandomX(-1,1),RandomX(25,50),RGB(255,255,255), this);
2011-01-29 07:41:11 +00:00
//Smoke
2011-02-02 08:43:02 +00:00
CreateParticle("ExploSmoke",9,-35,RandomX(-1,1),-7 + RandomX(-2,2),RandomX(30,125),RGBa(255,255,255,50));
CreateParticle("ExploSmoke",16,-33,RandomX(-1,1),-7 + RandomX(-2,2),RandomX(30,90),RGBa(255,255,255,50));
2011-01-29 07:41:11 +00:00
if(timer == 244)
{
//Pour
SetMeshMaterial("MetalFlow",1);
}
//Molten metal hits cast... Sizzling sound
if(timer == 256) Sound("Sizzle.ogg");
2011-01-29 07:41:11 +00:00
if(timer > 244 && timer < 290)
{
CreateParticle("Fire",-17,14,-1 + RandomX(-1,1), 2+ RandomX(-1,1),RandomX(5,15),RGB(255,255,255));
}
if(timer == 290)
{
SetMeshMaterial("Metal",1);
cast = 1;
AddEffect("EjectMetal",this, 1, 1, this);
Sound("FurnaceLoop.ogg",false,100,nil,-1);
Sound("FurnaceStop.ogg");
return -1;
}
}
public func FxEjectMetalTimer(object target, num, int timer)
2011-01-29 07:41:11 +00:00
{
if(timer > 24)
{
var metal = CreateObject(Metal, -20, 16);
2011-01-29 07:41:11 +00:00
metal->SetSpeed(0,-17);
metal->SetR(30 - Random(59));
Sound("Pop.ogg");
cast = 0;
return -1;
}
}
public func FxIntSoundDelayTimer(object target, num, int timer)
2011-01-29 07:41:11 +00:00
{
if(timer >= 100)
{
Sound("FurnaceLoop.ogg",false,100,nil,+1);
return -1;
}
}
func Definition(def) {
SetProperty("PictureTransformation", Trans_Mul(Trans_Translate(2000,0,7000),Trans_Rotate(-20,1,0,0),Trans_Rotate(30,0,1,0)), def);
}
local Touchable = 1;
local Name = "$Name$";