Make animal library properties editor-adjustable

Allows e.g. placement of animals that do not reproduce.
console-destruction
Sven Eberhardt 2016-09-01 02:23:42 -04:00
parent cd4e419aef
commit 9cec9b5071
4 changed files with 63 additions and 14 deletions

View File

@ -486,9 +486,10 @@ private func Death()
/*-- Reproduction --*/
private func ReproductionAreaSize() { return 1200; }
private func ReproductionRate() { return 200; }
private func MaxAnimalCount() { return 10; }
// Overloading animal library default values
local animal_reproduction_area_size = 1200;
local animal_reproduction_rate = 50;
local animal_max_count = 10;
// Only bats with full health reproduce.
private func SpecialReproductionCondition()

View File

@ -10,15 +10,26 @@
// This object is an animal.
public func IsAnimal() { return true; }
protected func Construction()
protected func Construction(...)
{
// Add a reproduction timer.
AddEffect("IntReproduction", this, 100, 72, this);
AddReproductionEffect();
// Add a growth effect.
StartGrowth(GrowthSpeed());
_inherited(...);
}
private func AddReproductionEffect()
{
if (!GetEffect("IntReproduction", this))
return AddEffect("IntReproduction", this, 100, 72, this);
}
private func RemoveReproductionEffect()
{
return RemoveEffect("IntReproduction");
}
/*-- Growth --*/
@ -28,14 +39,26 @@ private func GrowthSpeed() { return 5; }
/*-- Reproduction --*/
local animal_reproduction_area_size = 800;
local animal_reproduction_rate = 67;
local animal_max_count = 10;
// Population control is handled through these variables.
// The area, in which new animals of this kind can appear.
private func ReproductionAreaSize() { return 800; }
// The chance that reproduction takes place in one timer interval.
// The higher this value the less likely it is to reproduce.
private func ReproductionRate() { return 150; }
public func ReproductionAreaSize() { return animal_reproduction_area_size; }
public func SetReproductionAreaSize(int v) { animal_reproduction_area_size = v; return true; }
// The chance that reproduction takes place in one timer interval. From 0 to 10000.
// The higher this value the more likely it is to reproduce. Special: If it is zero, reproduction is off.
public func ReproductionRate() { return animal_reproduction_rate; }
public func SetReproductionRate(int v)
{
animal_reproduction_rate = v;
if (v) AddReproductionEffect(); else RemoveReproductionEffect();
return true;
}
// The maximal animal count in the area.
private func MaxAnimalCount() { return 10; }
public func MaxAnimalCount() { return animal_max_count; }
public func SetMaxAnimalCount(int v) { animal_max_count = v; return true; }
// Special reproduction method (e.g. with egg).
private func SpecialReproduction()
@ -66,14 +89,14 @@ public func FxIntReproductionTimer(object target, proplist effect, int time)
// Already dead or not full grown? Don't do anything.
if (!GetAlive() || GetCon() < 100)
return FX_OK;
// Apply the reproduction rate.
if (Random(10000) >= ReproductionRate())
return FX_OK;
// Special conditions not fulfilled? Don't do anything either.
if (!SpecialReproductionCondition())
return FX_OK;
// Check whether there are already enough animals of this kind.
if (CountAnimalsInArea() > MaxAnimalCount())
return FX_OK;
// Then apply the reproduction rate.
if (Random(ReproductionRate()))
if (CountAnimalsInArea() >= MaxAnimalCount())
return FX_OK;
// Reproduction: first try special reproduction, otherwise normal.
if (!SpecialReproduction())
@ -110,3 +133,16 @@ protected func RejectEntrance(object container)
// For all other cases the entrance is blocked.
return true;
}
/* Editor */
public func Definition(def, ...)
{
if (!def.EditorProps) def.EditorProps = {};
def.EditorProps.animal_reproduction_area_size = { Name="$ReproductionAreaSize$", EditorHelp="$ReproductionAreaSizeHelp$", Type="int", Min=0, AsyncGet="ReproductionAreaSize", Set="SetReproductionAreaSize" };
def.EditorProps.animal_reproduction_rate = { Name="$ReproductionRate$", EditorHelp="$ReproductionRateHelp$", Type="int", Min=0, Max=10000, AsyncGet="ReproductionRate", Set="SetReproductionRate" };
def.EditorProps.animal_max_count = { Name="$MaxCount$", EditorHelp="$MaxCountHelp$", Type="int", Min=1, AsyncGet="MaxAnimalCount", Set="SetMaxAnimalCount" };
return _inherited(def, ...);
}

View File

@ -0,0 +1,6 @@
ReproductionAreaSize=Reproduktionsgebiet
ReproductionAreaSizeHelp=Groesse des quadratischen Gebietes in Pixeln in dem Tiere der gleichen Art gezaehlt werden, um eine Reproduktion zu verhindern.
ReproductionRate=Reproduktionsrate
ReproductionRateHelp=Reproduktionsrate von 0 bis 10000. 0 ist keine Reproduktion; 10000 ist maximale Rate (etwa alle zwei Sekunden).
MaxCount=Maximale Anzahl
MaxCountHelp=Maximale Anzahl an Tieren im Reproduktionsgebiet. Wenn diese Zahl ueberschritten wird, vermehren sich die Tiere nichtmehr.

View File

@ -0,0 +1,6 @@
ReproductionAreaSize=Reproduction area
ReproductionAreaSizeHelp=Size of the square area in pixels in which animals of the same kind are counted in order to prevent over-population.
ReproductionRate=Reproduction rate
ReproductionRateHelp=Reproduction rate from 0 to 10,000. 0 is no reproduktion; 10000 ist maximum rate (approximately every two seconds).
MaxCount=Maximum count
MaxCountHelp=Maximale number of animals in reproduction area. If this number is exceeded, animals stop reproducing.