From a10ba81b3ec9b3bdc71d414f145f9eae768d7eb4 Mon Sep 17 00:00:00 2001 From: Felix Wagner Date: Thu, 7 Jun 2012 01:45:38 +0100 Subject: [PATCH] Added Place() to plants library --- .../Libraries.ocd/Plant.ocd/Script.c | 34 ++++++++++++++++--- .../SproutBerryBush.ocd/Script.c | 11 ------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c index 6dab063e7..365de0601 100644 --- a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c @@ -11,20 +11,47 @@ public func IsPlant() return true; } +/* Placement */ + +/** Places the given amount of plants inside the area. If no area is given, the whole landscape is used. + @param amount The amount of plants to be created (not necessarily every plant is created). + @param rectangle The area where to put the plants. +*/ +public func Place(int amount, proplist rectangle) +{ + // No calls to objects, only definitions + if (GetType(this) == C4V_C4Object) return; + if (!rectangle) + rectangle = Rectangle(0,0, LandscapeWidth(), LandscapeHeight()); + for (var i = 0 ; i < amount ; i++) + PlaceVegetation(this, rectangle.x, rectangle.y, rectangle.w, rectangle.h, 100000); +} + +/* Reproduction */ + /** Chance to reproduce plant. Chances are one out of return value. Default is 500. @return the chance, higher = less chance. */ -private func SeedChance() { return 500; } +private func SeedChance() +{ + return 500; +} /** Distance the seeds may travel. Default is 250. @return the maximum distance. */ -private func SeedArea() { return 250; } +private func SeedArea() +{ + return 250; +} /** The amount of plants allowed within SeedAreaSize. Default is 10. @return the maximum amount of plants. */ -private func SeedAmount() { return 10; } +private func SeedAmount() +{ + return 10; +} /** Automated positioning via RootSurface, make sure to call this if needed (in case Construction is overloaded) */ @@ -106,7 +133,6 @@ protected func Damage() _inherited(...); } - // restarts the growing of the tree (for example after taking damage) func RestartGrowth(int old_value) { diff --git a/planet/Objects.ocd/Vegetation.ocd/SproutBerryBush.ocd/Script.c b/planet/Objects.ocd/Vegetation.ocd/SproutBerryBush.ocd/Script.c index 5688a73fb..3ba26c10f 100644 --- a/planet/Objects.ocd/Vegetation.ocd/SproutBerryBush.ocd/Script.c +++ b/planet/Objects.ocd/Vegetation.ocd/SproutBerryBush.ocd/Script.c @@ -18,17 +18,6 @@ static const SproutBerryBush_water_per_berry = 10; static const SproutBerryBush_max_sprouts = 8; static const SproutBerryBush_evolve_steps_per_new_sprout = 2; -// static function -func Place(int amount) -{ - // place some sprout berries - var bush = PlaceVegetation(SproutBerryBush, 0, LandscapeHeight() / 3, LandscapeWidth(), LandscapeHeight(), 100000); - if(bush) - for (var i = 1; i < amount; i++) - PlaceVegetation(SproutBerryBush, bush->GetX() - 200, bush->GetY() - 200, 400, 400, 100000); - return true; -} - func Construction() { SetCon(100);