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

138 lines
3.2 KiB
C
Raw Normal View History

/*--
Foundry
Authors: Ringwaul, Maikel
Melts iron ore to metal, using some sort of fuel.
--*/
#include Library_Structure
#include Library_Ownable
#include Library_Producer
#include Library_LampPost
2011-01-29 07:41:11 +00:00
2012-02-18 23:48:48 +00:00
// does not need power
public func PowerNeed() { return 0; }
public func IsPowerConsumer() { return false; }
2012-02-18 23:48:48 +00:00
public func LampPosition(id def) { return [GetCalcDir()*-11,2]; }
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");
AddTimer("CollectionZone", 1);
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 OnProductionStart(id product)
2011-01-29 07:41:11 +00:00
{
AddEffect("Smelting", this, 100, 1, this);
Sound("Structures::Furnace::Start");
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;
2015-09-12 20:35:33 +00:00
for (var obj in FindObjects(Find_InRect(16 - 45 * GetDir(),3,13,13), Find_OCF(OCF_Collectible), Find_NoContainer(), Find_Layer(GetObjectLayer())))
Collect(obj, true);
}
func Collection()
2011-01-29 07:41:11 +00:00
{
Sound("Objects::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() + RandomX(-1, 1), 20 + RandomX(-1, 1), PV_Random(-1, 1), PV_Random(-1, 1), PV_Random(3, 10), Particles_Fire(), 2);
2011-01-29 07:41:11 +00:00
// Smoke from the pipes.
Smoke( -10*GetCalcDir(), -26, 6);
Smoke(-16*GetCalcDir(), -22, 3);
2011-01-29 07:41:11 +00:00
// Furnace sound after some time.
2012-05-11 17:14:43 +00:00
if (time == 30)
Sound("Structures::Furnace::Loop", 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("Liquids::Sizzle");
2011-01-29 07:41:11 +00:00
// Fire from the pouring exit.
if (Inside(time, 244, 290))
CreateParticle("SphereSpark", 16 * GetCalcDir(), 20, PV_Random(2 * GetCalcDir(), 0), PV_Random(-2, 3), PV_Random(18, 36), Particles_Material(RGB(255, 200, 0)), 2);
2011-01-29 07:41:11 +00:00
if (time == 290)
2011-01-29 07:41:11 +00:00
{
SetMeshMaterial("Metal", 1);
Sound("Structures::Furnace::Loop", false ,100, nil, -1);
Sound("Structures::Furnace::Stop");
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$";
local ContainBlast = true;
local BlastIncinerate = 100;
local HitPoints = 100;