forked from Mirrors/openclonk
Tidy up Crop Library.
parent
bdad81d2d1
commit
e196ddcb2c
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
private func IsCrop()
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Determines whether the plant can only be harvested when using a sickle.
|
||||
|
@ -19,7 +19,7 @@ private func IsCrop()
|
|||
*/
|
||||
public func SickleHarvesting()
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Determines whether the plant is harvestable right now (i.e. is fully grown).
|
||||
|
@ -30,9 +30,11 @@ public func IsHarvestable()
|
|||
return GetCon() >= 100;
|
||||
}
|
||||
|
||||
/** By default, plants are interactable if SickleHarvesting is false. The plant should be picked on interaction.
|
||||
*/
|
||||
public func IsInteractable(object clonk)
|
||||
{
|
||||
return clonk->IsWalking() && IsCrop() && !SickleHarvesting() && (IsHarvestable() || _inherited(clonk));
|
||||
return clonk->IsWalking() && !SickleHarvesting() && IsHarvestable();
|
||||
}
|
||||
|
||||
public func GetInteractionMetaInfo(object clonk)
|
||||
|
@ -47,19 +49,17 @@ public func GetInteractionMetaInfo(object clonk)
|
|||
return _inherited(clonk);
|
||||
}
|
||||
|
||||
/** Default will call Harvest if IsHarvestable.
|
||||
*/
|
||||
public func Interact(object clonk)
|
||||
{
|
||||
if (IsCrop())
|
||||
{
|
||||
if (IsHarvestable())
|
||||
return Harvest(clonk);
|
||||
else
|
||||
return _inherited();
|
||||
}
|
||||
return _inherited(clonk);
|
||||
if (IsHarvestable())
|
||||
return Harvest(clonk);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Called when the plant is harvested
|
||||
/** Called when the plant is harvested. Default is Split2Components.
|
||||
@param The harvesting clonk
|
||||
@return \c true is successfully harvested
|
||||
*/
|
||||
|
@ -67,4 +67,76 @@ public func Harvest(object clonk)
|
|||
{
|
||||
Split2Components();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Watering */
|
||||
|
||||
/** This is optional behaviour. Plant will grow faster if there is a little water around. The plant may also shrink if its submerged.
|
||||
To activate, use AddTimer("WaterCheck", 70+Random(10)); or similar in Construction.
|
||||
Plant must have the following properties defined:
|
||||
growth: Usual growth factor
|
||||
fastgrowth: Growth factor when water was absorbed (until it is check again)
|
||||
|
||||
Optionally you can also define degrowth. If != 0 the plant will start shrinking if the liquid is more than 10 pixels deep.
|
||||
*/
|
||||
private func WaterCheck()
|
||||
{
|
||||
// Fully grown
|
||||
if (GetCon() >= 100) return RemoveTimer("WaterCheck");
|
||||
if (OnFire()) return;
|
||||
|
||||
// Center must be clear
|
||||
if (GBackSolid()) return;
|
||||
|
||||
var next_growth = this.growth;
|
||||
|
||||
// I still have water
|
||||
if (this.watered)
|
||||
{
|
||||
next_growth = this.fastgrowth;
|
||||
this.watered--;
|
||||
}
|
||||
else
|
||||
{
|
||||
var skip_extract = false;
|
||||
var my_width = GetObjWidth();
|
||||
var my_height = GetObjHeight() / 2;
|
||||
var water = 0;
|
||||
if (this.degrowth)
|
||||
{
|
||||
// Do a simple check if there is too much water present
|
||||
if (GBackLiquid(0, my_height) && GBackLiquid(0, my_height - 10))
|
||||
{
|
||||
next_growth = this.degrowth;
|
||||
skip_extract = true;
|
||||
}
|
||||
}
|
||||
if (!skip_extract)
|
||||
{
|
||||
// Check for water
|
||||
for (var i = 0; i < my_width+1; i++)
|
||||
{
|
||||
var y = 0;
|
||||
var x = i - my_width/2;
|
||||
while (!GBackLiquid(x, my_height - y) && y < my_height + 1)
|
||||
y--;
|
||||
if (MaterialName(GetMaterial(x, y)) == "Water")
|
||||
if (ExtractLiquid(x, y))
|
||||
water++;
|
||||
if (water >= 5) // Extract a maximum of 5 pixels of water
|
||||
break;
|
||||
}
|
||||
if (water)
|
||||
{
|
||||
next_growth = this.fastgrowth;
|
||||
// Save how much water has been consumed
|
||||
this.watered = water;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var grow_effect = GetEffect("IntGrowth", this);
|
||||
if (!grow_effect) StartGrowth(next_growth);
|
||||
else if (grow_effect.growth != next_growth)
|
||||
grow_effect.growth = next_growth;
|
||||
}
|
||||
|
|
|
@ -10,5 +10,4 @@ VertexX=0,0
|
|||
VertexY=7,12
|
||||
VertexFriction=50,100
|
||||
VertexCNAT=16,8
|
||||
Components=Moss=4
|
||||
Mass=10
|
||||
Components=Moss=4
|
|
@ -8,7 +8,6 @@ local grow_stage;
|
|||
private func SeedChance() { return 1000; }
|
||||
private func SeedOffset() { return 10; }
|
||||
|
||||
private func IsCrop() { return true; }
|
||||
private func SickleHarvesting() { return false; }
|
||||
|
||||
protected func Construction()
|
||||
|
@ -17,6 +16,8 @@ protected func Construction()
|
|||
if(graphic)
|
||||
SetGraphics(Format("%d",graphic));
|
||||
_inherited();
|
||||
|
||||
if(GetCon() < 100) SetCon(100);
|
||||
}
|
||||
|
||||
protected func Initialize()
|
||||
|
|
|
@ -9,87 +9,34 @@
|
|||
#include Library_Crop
|
||||
|
||||
private func SeedArea() { return 60; }
|
||||
private func SeedChance() { return 250; }
|
||||
private func SeedChance() { return 250; }
|
||||
private func SeedAmount() { return 4; } // small seed area -> don't allow too many plants
|
||||
private func SeedOffset() { return 20; }
|
||||
|
||||
protected func Construction()
|
||||
{
|
||||
// Editable ActMap
|
||||
ActMap = { Prototype = this.Prototype.ActMap };
|
||||
//ActMap = { Prototype = this.Prototype.ActMap };
|
||||
StartGrowth(this.growth);
|
||||
AddTimer("WaterCheck", 70+Random(10));
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
//****** TODO: Fix mesh animation to make this work
|
||||
|
||||
/*
|
||||
protected func Initialize()
|
||||
{
|
||||
SetAction("Swing");
|
||||
|
||||
AddEffect("WaterCheck", this, 2, 70, this);
|
||||
AddEffect("WindCheck", this, 3, 350, this);
|
||||
}
|
||||
|
||||
/* Absorb water to grow faster */
|
||||
*/
|
||||
|
||||
protected func FxWaterCheckTimer(object obj, effect)
|
||||
{
|
||||
// Fully grown
|
||||
if (GetCon() == 100) return -1;
|
||||
// Submerged
|
||||
if (InLiquid())
|
||||
{
|
||||
var degrowth = true;
|
||||
// Ignore minimum amount of water if small
|
||||
if (GetCon() < 20)
|
||||
if (!GBackLiquid(0,-5))
|
||||
degrowth = false;
|
||||
if (degrowth)
|
||||
{
|
||||
var grow_effect = GetEffect("IntGrowth", this);
|
||||
if (!grow_effect) { grow_effect = StartGrowth(this.degrowth); return; }
|
||||
if (grow_effect.growth == this.degrowth) return;
|
||||
grow_effect.growth = this.degrowth;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Decrease water amount
|
||||
if (effect.water)
|
||||
effect.water--;
|
||||
// Search for water
|
||||
var water = 0;
|
||||
for (var i = 0; i < GetObjWidth()+1; i++)
|
||||
{
|
||||
var y = (GetObjHeight()/2)+1;
|
||||
var x = i-(GetObjWidth()/2);
|
||||
if (!GBackSolid(x,y)) continue;
|
||||
while(GBackSolid(x,y) && y) --y;
|
||||
if (!y) continue;
|
||||
if (MaterialName(GetMaterial(x,y)) == "Water")
|
||||
if (ExtractLiquid(x,y))
|
||||
water++;
|
||||
if (water == 5) // maximum amount of water extracted in one check
|
||||
break;
|
||||
}
|
||||
// Fasten growth if needed
|
||||
effect.water += water;
|
||||
if (effect.water)
|
||||
{
|
||||
var grow_effect = GetEffect("IntGrowth", this);
|
||||
if (!grow_effect) { grow_effect = StartGrowth(this.fastgrowth); return; }
|
||||
if (grow_effect.growth == this.fastgrowth) return;
|
||||
grow_effect.growth = this.fastgrowth;
|
||||
}
|
||||
else
|
||||
{
|
||||
var grow_effect = GetEffect("IntGrowth", this);
|
||||
if (!grow_effect) { grow_effect = StartGrowth(this.growth); return; }
|
||||
if (grow_effect.growth == this.growth) return;
|
||||
grow_effect.growth = this.growth;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check the wind to adjust the swinging speed of the stalks */
|
||||
|
||||
/*
|
||||
protected func FxWindCheckStart(object obj, effect)
|
||||
{
|
||||
if (Abs(GetWind()) < 25) effect.speed = 0;
|
||||
|
@ -134,17 +81,15 @@ public func SetSwingSpeed(int delay)
|
|||
SetPhase(phase);
|
||||
}
|
||||
|
||||
/* Callbacks */
|
||||
|
||||
public func IsCrop() { return true; }
|
||||
*/
|
||||
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
||||
local Collectible = 0;
|
||||
local growth = 3;
|
||||
local degrowth = -6;
|
||||
local fastgrowth = 9;
|
||||
|
||||
/*
|
||||
local ActMap = {
|
||||
Swing = {
|
||||
Prototype = Action,
|
||||
|
@ -176,3 +121,4 @@ local ActMap = {
|
|||
NextAction = "Swing"
|
||||
}
|
||||
};
|
||||
*/
|
Loading…
Reference in New Issue