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

141 lines
3.1 KiB
C
Raw Normal View History

/*--
Foundry
Authors: Ringwaul, Maikel
Melts iron ore to metal, using some sort of fuel.
--*/
#include Library_Ownable
#include Library_Producer
2011-01-29 07:41:11 +00:00
2012-02-18 23:48:48 +00:00
// does not need power
func PowerNeed() { return 0; }
public func Construction(object creator)
2011-01-29 07:41:11 +00:00
{
//SetProperty("MeshTransformation",Trans_Rotate(RandomX(-40,20),0,1,0));
SetAction("Default");
if (!creator) return;
var dir = creator->~GetConstructionDirection();
if (dir)
SetDir(dir);
return _inherited(creator, ...);
2011-01-29 07:41:11 +00:00
}
/*-- Production --*/
private func IgnoreKnowledge() { return true; }
private func IsProduct(id product_id)
{
return product_id->~IsFoundryProduct();
}
private func ProductionTime(id toProduce) { return 290; }
2011-01-29 07:41:11 +00:00
public func NeedRawMaterial(id rawmat_id)
2011-01-29 07:41:11 +00:00
{
if (rawmat_id->~IsFuel() || rawmat_id == Ore || rawmat_id == Nugget)
return true;
return false;
}
2011-01-29 07:41:11 +00:00
public func OnProductionStart(id product)
2011-01-29 07:41:11 +00:00
{
AddEffect("Smelting", this, 100, 1, this);
Sound("FurnaceStart");
return;
2011-01-29 07:41:11 +00:00
}
public func OnProductionHold(id product)
{
return;
}
public func OnProductionFinish(id product)
{
RemoveEffect("Smelting", this);
return;
}
// Timer, check for objects to collect in the designated collection zone
func CollectionZone()
{
if (GetCon() < 100) return;
for (var object in FindObjects(Find_InRect(16 - 45 * GetDir(),3,13,13), Find_OCF(OCF_Collectible), Find_NoContainer(), Find_Layer(GetObjectLayer())))
Collect(object);
}
func Collection()
2011-01-29 07:41:11 +00:00
{
Sound("Clonk");
return;
2011-01-29 07:41:11 +00:00
}
public func FxSmeltingTimer(object target, proplist effect, int time)
2011-01-29 07:41:11 +00:00
{
//Message(Format("Smelting %d",timer));
// Fire in the furnace.
CreateParticle("Fire",-10*GetCalcDir(),20,RandomX(-1,1),RandomX(-1,1),RandomX(25,50),RGB(255,255,255), this);
2011-01-29 07:41:11 +00:00
// Smoke from the pipes.
CreateParticle("ExploSmoke", -9*GetCalcDir(), -31, RandomX(-2,1), -7 + RandomX(-2,2), RandomX(60,125), RGBa(255,255,255,50));
CreateParticle("ExploSmoke", -16*GetCalcDir(), -27, RandomX(-1,2), -7 + RandomX(-2,2), RandomX(30,90), RGBa(255,255,255,50));
2011-01-29 07:41:11 +00:00
// Furnace sound after some time.
if (time == 100)
Sound("FurnaceLoop", false, 100, nil, +1);
// Pour after some time.
if(time == 244)
SetMeshMaterial("MetalFlow", 1);
2011-01-29 07:41:11 +00:00
//Molten metal hits cast... Sizzling sound
if (time == 256)
Sound("Sizzle");
2011-01-29 07:41:11 +00:00
// Fire from the pouring exit.
if (Inside(time, 244, 290))
CreateParticle("Fire",17*GetCalcDir(),19,-1 + RandomX(-1,1), 2+ RandomX(-1,1),RandomX(5,15),RGB(255,255,255));
2011-01-29 07:41:11 +00:00
if (time == 290)
2011-01-29 07:41:11 +00:00
{
SetMeshMaterial("Metal", 1);
Sound("FurnaceLoop", false ,100, nil, -1);
Sound("FurnaceStop");
2011-01-29 07:41:11 +00:00
return -1;
}
return 1;
2011-01-29 07:41:11 +00:00
}
public func OnProductEjection(object product)
2011-01-29 07:41:11 +00:00
{
product->SetPosition(GetX() + 18 * GetCalcDir(), GetY() + 16);
product->SetSpeed(0, -17);
product->SetR(30 - Random(59));
Sound("Pop");
return;
2011-01-29 07:41:11 +00:00
}
local ActMap = {
Default = {
Prototype = Action,
Name = "Default",
Procedure = DFA_NONE,
Directions = 2,
FlipDir = 1,
Length = 1,
Delay = 0,
FacetBase = 1,
NextAction = "Default",
},
};
2011-01-29 07:41:11 +00:00
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 Name = "$Name$";
2012-04-15 11:13:14 +00:00
local Description = "$Description$";