Skip to content
Permalink
Browse files

Let plants grow less crowded, especially different kinds of plants (#…

…1607).

This will need some testing whether all scenarios are still playable.
  • Loading branch information...
Armag3ddon committed Jan 4, 2017
1 parent 3fe8398 commit e4cfd39fdcabda4b4ea276d07e23b47f1962e262
@@ -6,6 +6,7 @@
local plant_seed_chance = 20;
local plant_seed_area = 400;
local plant_seed_amount = 10;
local plant_seed_offset = 30;

local lib_tree_burned = Deco_Tree_Deciduous3_Burned;

@@ -6,6 +6,7 @@
local plant_seed_chance = 20;
local plant_seed_area = 400;
local plant_seed_amount = 10;
local plant_seed_offset = 50;

local lib_tree_burned = Deco_Tree_Deciduous4_Burned;

@@ -99,7 +99,6 @@ private func UpdateSeedTimer()
return true;
}


/** Distance the seeds may travel. Default is 250.
@return the maximum distance.
*/
@@ -135,7 +134,7 @@ public func SetSeedAmount(int v)
}

/** The closest distance a new plant may seed to its nearest neighbour. Default is 20.
@return the maximum amount of plants.
@return the closest distance to another plant.
*/

local plant_seed_offset = 20;
@@ -151,7 +150,6 @@ public func SetSeedOffset(int v)
return true;
}


/** Evaluates parameters for this definition to determine if seeding should occur.
@par offx X offset added to context position for check.
@par offy Y offset added to context position for check.
@@ -185,15 +183,44 @@ private func Seed()
var plant;
if (CheckSeedChance())
{
plant = DoSeed();
plant = DoSeed(true);
// Check if it is not close to another one.
if (plant)
{
var neighbours = FindObjects(Find_Func("IsPlant"), Find_Exclude(plant),
Sort_Multiple(Sort_Distance(plant->GetX() - GetX(), plant->GetY() - GetY()), Sort_Reverse(Sort_Func("SeedOffset"))));
// Only check the nearest 3 plants
var too_close = false;
for (var i = 0; i < GetLength(neighbours) && i < 3; i++)
{
var neighbour = neighbours[i];
var x_distance = plant->SeedOffset() + 1;
var y_distance = 151;
if (neighbour)
{
x_distance = Abs(neighbour->GetX() - plant->GetX());
y_distance = Abs(neighbour->GetY() - plant->GetY());
}
if ((x_distance < plant->SeedOffset() || x_distance < neighbour->~SeedOffset()) && y_distance < 151)
{
too_close = true;
break;
}
}
// Closeness check
if (too_close)
plant->RemoveObject();
else
plant->InitChild(this);
}
}
return plant;
}

/** Forcefully places a seed of the plant, without random chance
or other sanity checks. This is useful for testing.
*/
private func DoSeed()
public func DoSeed(bool no_init)
{
// Apply confinement for plant placement
var size = SeedArea();
@@ -212,19 +239,11 @@ private func DoSeed()
// Place the new plant in the original area
confined_area = area;
}
// Place the plant...
// Place the plant
var plant = PlaceVegetation(GetID(), 0, 0, 0, 0, 3, confined_area);
if (plant)
{
// ...but check if it is not close to another one.
var neighbour = FindObject(Find_ID(GetID()), Find_Exclude(plant), Sort_Distance(plant->GetX() - GetX(), plant->GetY() - GetY()));
var distance = ObjectDistance(plant, neighbour);
// Closeness check
if (distance < SeedOffset())
plant->RemoveObject();
else
plant->InitChild(this);
}
if (!no_init && plant)
plant->InitChild(this);

return plant;
}

@@ -236,8 +255,6 @@ private func RemoveInTunnel()
}
}



/* Editor */

public func Definition(def, ...)
@@ -5,6 +5,7 @@
local plant_seed_chance = 25;
local plant_seed_area = 120;
local plant_seed_amount = 4;
local plant_seed_offset = 10;

func Construction()
{
@@ -12,6 +12,7 @@ local is_explicit_skin = false;
local plant_seed_chance = 33;
local plant_seed_area = 120;
local plant_seed_amount = 6;
local plant_seed_offset = 5;

public func Construction()
{
@@ -10,7 +10,7 @@
local plant_seed_chance = 17;
local plant_seed_area = 150;
local plant_seed_amount = 4;
local plant_seed_offset = 10;
local plant_seed_offset = 5;

private func Incineration()
{
@@ -6,6 +6,7 @@
local plant_seed_chance = 100;
local plant_seed_area = 400;
local plant_seed_amount = 12;
local plant_seed_offset = 30;

local coconuts;
// Saved for GetTreetopPosition
@@ -6,6 +6,7 @@
local plant_seed_chance = 20;
local plant_seed_area = 400;
local plant_seed_amount = 10;
local plant_seed_offset = 30;

local lib_tree_burned = Tree_Coniferous_Burned;

@@ -6,6 +6,7 @@
local plant_seed_chance = 20;
local plant_seed_area = 400;
local plant_seed_amount = 10;
local plant_seed_offset = 30;

local lib_tree_burned = Tree_Deciduous_Burned;

@@ -13,7 +13,7 @@ local swing_anim;
local plant_seed_area = 60;
local plant_seed_chance = 40;
local plant_seed_amount = 4; // small seed area -> don't allow too many plants
local plant_seed_offset = 20;
local plant_seed_offset = 10;
public func SickleHarvesting() { return true; }

private func Construction()

0 comments on commit e4cfd39

Please sign in to comment.
You can’t perform that action at this time.