diff --git a/company.nut b/company.nut index 7e9990b..d40356b 100644 --- a/company.nut +++ b/company.nut @@ -6,12 +6,14 @@ class CompanyGoal { accept = null; // Accepting resource. wanted_amount = null; // Amount to deliver for achieving the goal. delivered_amount = 0; // Amount delivered so far. - goal_id = null; + goal_id = null; // Number of the goal in OpenTTD goal window. + timeout = null; // Timeout in ticks before the goal becomes obsolete. constructor(comp_id, cargo_id, accept, wanted_amount) { this.cargo_id = cargo_id; this.accept = accept; this.wanted_amount = wanted_amount; + this.timeout = 60 * 30 * 74; // 60 months timeout (30 days, 74 ticks). // Construct goal. local destination, destination_string, goal_type; @@ -30,6 +32,7 @@ class CompanyGoal { function AddMonitorElement(mon); function UpdateDelivered(mon); + function UpdateTimeout(step); function CheckFinished(); function FinalizeGoal(); }; @@ -76,11 +79,25 @@ function CompanyGoal::UpdateDelivered(mon) } } -// Test whether the goal can be considered 'done'. +// Update the timeout of the goal +// @param step Number of passed ticks. +function CompanyGoal::UpdateTimeout(step) +{ + this.timeout -= step; + if (this.goal_id != null) { + local remaining = this.timeout; + if (remaining < 0) remaining = 0; + if (this.delivered_amount > 0) return; // Don't print remaining ticks when there is cargo delivered. + local progress_text = GSText(GSText.STR_TIMEOUT, remaining); + GSGoal.SetProgress(this.goal_id, progress_text); + } +} + +// Test whether the goal can be considered 'done' (or obsolete). // @return Whether the goal is considered done. function CompanyGoal::CheckFinished() { - return this.delivered_amount >= this.wanted_amount; + return this.timeout < 0 || this.delivered_amount >= this.wanted_amount; } // Goal is considered 'done', last chance to clean up before the goal is dropped @@ -108,6 +125,7 @@ class CompanyData { function AddMonitorElement(mon); function UpdateDelivered(mon); + function UpdateTimeout(step); function CheckAndFinishGoals(); }; @@ -201,6 +219,14 @@ function CompanyData::UpdateDelivereds(cmon) return finished; // One or more goals was considered 'done' } +function CompanyData::UpdateTimeout(step) +{ + foreach (num, goal in this.active_goals) { + if (goal == null) continue; + goal.UpdateTimeout(step); + } +} + // Test whether goals of the company are 'done', and if so, drop them. function CompanyData::CheckAndFinishGoals() { diff --git a/lang/english.txt b/lang/english.txt index d0c1ed5..ad77986 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -1,5 +1,6 @@ STR_LAKE_NEWS :There are {NUM} {}fish here STR_COMPANY_GOAL :Deliver {CARGO_LONG} to {STRING} STR_PROGRESS :{NUM}% done +STR_TIMEOUT :{NUM} ticks remaining STR_TOWN_NAME :{TOWN} STR_INDUSTRY_NAME :{INDUSTRY} diff --git a/main.nut b/main.nut index 0352f2b..2950487 100644 --- a/main.nut +++ b/main.nut @@ -325,6 +325,14 @@ function BusyBeeClass::Start() new_goal_timeout -= delay_time; monitor_timeout -= delay_time; finished_timeout -= delay_time; + + // Update timeout of the goals as well. + if (!GSGame.IsPaused()) { + foreach (cid, cdata in companies) { + if (cdata == null) continue; + cdata.UpdateTimeout(delay_time); + } + } } }