2011-10-19 23:42:32 +00:00
|
|
|
/*--
|
|
|
|
Sawmill
|
|
|
|
Authors: Ringwaul, Clonkonaut
|
|
|
|
|
|
|
|
Cuts trees or other objects into wood. Accepts only objects purely made from wood.
|
|
|
|
--*/
|
|
|
|
|
2012-05-10 19:20:06 +00:00
|
|
|
#include Library_Structure
|
2012-02-18 21:50:18 +00:00
|
|
|
#include Library_Ownable
|
2011-10-19 23:42:32 +00:00
|
|
|
#include Library_Producer
|
|
|
|
|
2012-04-16 15:31:38 +00:00
|
|
|
public func Construction(object creator)
|
2011-10-19 23:42:32 +00:00
|
|
|
{
|
|
|
|
SetProperty("MeshTransformation",Trans_Rotate(-20,0,1,0));
|
2012-04-16 15:31:38 +00:00
|
|
|
SetAction("Default");
|
|
|
|
return _inherited(creator, ...);
|
2011-10-19 23:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public func Initialize()
|
|
|
|
{
|
|
|
|
this.SpinAnimation = PlayAnimation("work", 10, Anim_Const(0), Anim_Const(1000));
|
2012-05-05 10:09:44 +00:00
|
|
|
AddTimer("CollectionZone", 1);
|
2011-10-19 23:42:32 +00:00
|
|
|
return _inherited(...);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-- Interaction --*/
|
|
|
|
|
2012-03-04 16:12:39 +00:00
|
|
|
// Sawmill can't be accessed as a container.
|
|
|
|
public func IsContainer() { return false; }
|
|
|
|
|
2012-10-12 16:21:32 +00:00
|
|
|
// Sawmill can't be interacted with.
|
|
|
|
public func IsInteractable() { return false; }
|
|
|
|
|
2011-10-19 23:42:32 +00:00
|
|
|
// Automatically search for trees in front of sawmill
|
|
|
|
// Temporary solution?
|
|
|
|
protected func FindTrees()
|
|
|
|
{
|
2012-03-24 15:09:11 +00:00
|
|
|
var tree = FindObject(Find_AtPoint(), Find_Func("IsTree"), Find_Not(Find_Func("IsStanding")), Find_Func("GetComponent", Wood));
|
2012-04-16 15:31:38 +00:00
|
|
|
if (!tree) return;
|
2012-03-24 15:09:11 +00:00
|
|
|
|
2011-10-19 23:42:32 +00:00
|
|
|
Saw(tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
private func CheckWoodObject(object target)
|
|
|
|
{
|
|
|
|
if (target->GetComponent(nil, 0) != Wood) return false;
|
|
|
|
if (target->GetComponent(nil, 1)) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-- Production --*/
|
|
|
|
|
2012-01-19 22:31:05 +00:00
|
|
|
private func IgnoreKnowledge() { return true; }
|
2012-01-16 23:32:46 +00:00
|
|
|
|
2011-10-19 23:42:32 +00:00
|
|
|
public func Saw(object target)
|
|
|
|
{
|
|
|
|
target->Enter(this);
|
|
|
|
var output = target->GetComponent(Wood);
|
|
|
|
target->Split2Components();
|
|
|
|
AddToQueue(Wood, output);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private func IsProduct(id product_id)
|
|
|
|
{
|
|
|
|
return product_id->~IsSawmillProduct();
|
|
|
|
}
|
2012-04-15 16:45:43 +00:00
|
|
|
private func ProductionTime(id toProduce) { return 100; }
|
2012-12-17 12:52:53 +00:00
|
|
|
private func PowerNeed() { return 50; }
|
2011-10-19 23:42:32 +00:00
|
|
|
|
2012-01-19 22:31:05 +00:00
|
|
|
public func NeedRawMaterial(id rawmat_id)
|
2011-10-19 23:42:32 +00:00
|
|
|
{
|
|
|
|
if (rawmat_id->~IsSawmillProduct())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public func OnProductionStart(id product)
|
|
|
|
{
|
|
|
|
if (!GetEffect("Sawing", this))
|
|
|
|
{
|
|
|
|
SpinOn();
|
|
|
|
AddEffect("Sawing", this, 100, 1, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func OnProductionHold(id product)
|
|
|
|
{
|
|
|
|
SpinOff();
|
|
|
|
RemoveEffect("Sawing", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public func OnProductionContinued(id product)
|
|
|
|
{
|
2012-02-20 23:02:32 +00:00
|
|
|
if (!GetEffect("Sawing", this))
|
|
|
|
{
|
|
|
|
SpinOn();
|
|
|
|
AddEffect("Sawing", this, 100, 1, this);
|
|
|
|
}
|
2011-10-19 23:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public func OnProductionFinish(id product)
|
|
|
|
{
|
|
|
|
if (!GetLength(queue))
|
|
|
|
{
|
|
|
|
SpinOff();
|
|
|
|
RemoveEffect("Sawing", this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 15:31:38 +00:00
|
|
|
// Timer, check for objects to collect in the designated collection zone
|
|
|
|
func CollectionZone()
|
|
|
|
{
|
|
|
|
if (GetCon() < 100) return;
|
2012-10-13 15:41:13 +00:00
|
|
|
|
|
|
|
// Only take one tree at a time
|
|
|
|
if (!(FrameCounter() % 35))
|
|
|
|
if (GetLength(queue) == 0)
|
|
|
|
FindTrees();
|
2012-04-16 15:31:38 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 23:42:32 +00:00
|
|
|
protected func Collection()
|
|
|
|
{
|
|
|
|
Sound("Clonk");
|
|
|
|
}
|
|
|
|
|
|
|
|
public func FxSawingTimer(object target, proplist effect, int time)
|
|
|
|
{
|
2013-11-04 12:13:51 +00:00
|
|
|
var dir = GetCalcDir();
|
2011-10-19 23:42:32 +00:00
|
|
|
if (time >= this.SpinStep * 3 && time % 5)
|
2013-12-17 20:40:40 +00:00
|
|
|
CreateParticle("WoodChip", PV_Random(-7 * dir, -3 * dir), PV_Random(3, 6), PV_Random(-5 * dir, -11 * dir), PV_Random(-4, -2), PV_Random(36 * 3, 36 * 10), Particles_WoodChip(), 3);
|
2011-10-19 23:42:32 +00:00
|
|
|
|
|
|
|
if (!(time % 20))
|
2012-04-16 15:31:38 +00:00
|
|
|
Smoke(10 * GetCalcDir(),10,10);
|
2011-10-19 23:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public func OnProductEjection(object product)
|
|
|
|
{
|
2012-04-16 15:31:38 +00:00
|
|
|
product->SetPosition(GetX() - 25 * GetCalcDir(), GetY() - 8);
|
|
|
|
product->SetSpeed(-7 * GetCalcDir(), 5);
|
2011-10-19 23:42:32 +00:00
|
|
|
product->SetR(30 - Random(59));
|
|
|
|
Sound("Pop");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected func RejectCollect(id id_def, object collect)
|
|
|
|
{
|
|
|
|
// Don't collect wood
|
2012-02-20 23:02:32 +00:00
|
|
|
if (id_def == Wood)
|
2011-10-19 23:42:32 +00:00
|
|
|
return true;
|
2012-02-20 23:02:32 +00:00
|
|
|
if (collect->~IsSawmillIngredient() || CheckWoodObject(collect))
|
|
|
|
return false;
|
|
|
|
return true;
|
2011-10-19 23:42:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-- Animation --*/
|
|
|
|
|
|
|
|
private func SpinOn(int call)
|
|
|
|
{
|
|
|
|
var spin;
|
|
|
|
// Slowest spin on first call
|
|
|
|
if (!call) { spin = 100; SetMeshMaterial("Beltspin", 1); ClearScheduleCall(this, "SpinOff"); }
|
|
|
|
if (call == 1) spin = 75;
|
|
|
|
if (call == 2) spin = 50;
|
|
|
|
if (call == 3) { spin = 30; SetMeshMaterial("SawmillBlade.Spin", 2); }
|
|
|
|
|
|
|
|
SetAnimationPosition(this.SpinAnimation, Anim_Linear(GetAnimationPosition(this.SpinAnimation), GetAnimationLength("work"), 0, spin, ANIM_Loop));
|
|
|
|
|
|
|
|
if (call < 3) ScheduleCall(this, "SpinOn", this.SpinStep, nil, call+1);
|
|
|
|
else Sound("SawmillRipcut", nil, nil, nil, +1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private func SpinOff(int call, int animation_no)
|
|
|
|
{
|
|
|
|
var spin;
|
|
|
|
if (!call) { spin = 50; SetMeshMaterial("SawmillBlade", 2); Sound("SawmillRipcut", nil, nil, nil, -1); ClearScheduleCall(this, "SpinOn"); }
|
|
|
|
if (call == 1) spin = 75;
|
|
|
|
if (call == 2) spin = 100;
|
|
|
|
if (call == 3) spin = 150;
|
|
|
|
if (call == 4)
|
|
|
|
{
|
|
|
|
SetMeshMaterial("SawmillBelt", 1);
|
|
|
|
SetAnimationPosition(this.SpinAnimation, Anim_Const(GetAnimationPosition(this.SpinAnimation)));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetAnimationPosition(this.SpinAnimation, Anim_Linear(GetAnimationPosition(this.SpinAnimation), GetAnimationLength("work"), 0, spin, ANIM_Loop));
|
|
|
|
|
|
|
|
ScheduleCall(this, "SpinOff", this.SpinStep * 2, nil, call+1);
|
|
|
|
}
|
|
|
|
|
2012-04-16 15:31:38 +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-10-19 23:42:32 +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$";
|
2012-04-28 14:17:38 +00:00
|
|
|
local SpinStep = 30;
|
2015-01-14 19:30:55 +00:00
|
|
|
local ContainBlast = true;
|
2012-05-10 19:20:06 +00:00
|
|
|
local BlastIncinerate = 100;
|
2012-10-12 16:21:32 +00:00
|
|
|
local HitPoints = 70;
|