From 5224eb5b182a3c47d4f2ad7b2232a30dbe5161e5 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 11 Feb 2016 22:16:19 +0100 Subject: [PATCH] Goal Resource: Variable amounts of exploitation It is possible to set the amount of resources to be extracted with an additional parameter in SetResource() now. The default amount to be extracted is 95 percent, which is the same behaviour as before the changes. --- .../Objects.ocd/Goals.ocd/Resource.ocd/Script.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/planet/Objects.ocd/Goals.ocd/Resource.ocd/Script.c b/planet/Objects.ocd/Goals.ocd/Resource.ocd/Script.c index 95f1e4c06..218fb5ff9 100644 --- a/planet/Objects.ocd/Goals.ocd/Resource.ocd/Script.c +++ b/planet/Objects.ocd/Goals.ocd/Resource.ocd/Script.c @@ -1,9 +1,13 @@ /*-- Resource Extraction - Author: Maikel + Author: Maikel, Marky Player must extract the resources of the specified type, the - tolerance of this goal is 5% currently. + tolerance of this goal is 5% currently, if no percentage of + exploitation is specified. + + Additionally, the scenario designer can specify a percentage + of material to be exploited, between 5% and 95%. TODO: Expand to liquids and digable materials. --*/ @@ -23,17 +27,22 @@ protected func Initialize() /*-- Resources --*/ -public func SetResource(string resource) +public func SetResource(string resource, int percent) { var list_end = GetLength(resource_list); resource_list[list_end] = resource; + + // Assume that all objects, with 5% tolerance, have to be exploited if no percentage is specified + percent = BoundBy(percent ?? 95, 5, 95); var material = Material(resource); var exploitable_units = GetMaterialCount(material); var exploitable_objects = ExploitableObjectCount(exploitable_units, material); + + var target_objects = percent * exploitable_objects / 100; // Calculate 100 / 20 = 5% of the exploitable objects as tolerance - tolerance_list[list_end] = Max(1, exploitable_objects / 20); + tolerance_list[list_end] = Max(1, exploitable_objects - target_objects); return; }