Add: Timeout counter for the goals. Addresses #7371
This commit is contained in:
32
company.nut
32
company.nut
@@ -6,12 +6,14 @@ class CompanyGoal {
|
|||||||
accept = null; // Accepting resource.
|
accept = null; // Accepting resource.
|
||||||
wanted_amount = null; // Amount to deliver for achieving the goal.
|
wanted_amount = null; // Amount to deliver for achieving the goal.
|
||||||
delivered_amount = 0; // Amount delivered so far.
|
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) {
|
constructor(comp_id, cargo_id, accept, wanted_amount) {
|
||||||
this.cargo_id = cargo_id;
|
this.cargo_id = cargo_id;
|
||||||
this.accept = accept;
|
this.accept = accept;
|
||||||
this.wanted_amount = wanted_amount;
|
this.wanted_amount = wanted_amount;
|
||||||
|
this.timeout = 60 * 30 * 74; // 60 months timeout (30 days, 74 ticks).
|
||||||
|
|
||||||
// Construct goal.
|
// Construct goal.
|
||||||
local destination, destination_string, goal_type;
|
local destination, destination_string, goal_type;
|
||||||
@@ -30,6 +32,7 @@ class CompanyGoal {
|
|||||||
|
|
||||||
function AddMonitorElement(mon);
|
function AddMonitorElement(mon);
|
||||||
function UpdateDelivered(mon);
|
function UpdateDelivered(mon);
|
||||||
|
function UpdateTimeout(step);
|
||||||
function CheckFinished();
|
function CheckFinished();
|
||||||
function FinalizeGoal();
|
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.
|
// @return Whether the goal is considered done.
|
||||||
function CompanyGoal::CheckFinished()
|
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
|
// Goal is considered 'done', last chance to clean up before the goal is dropped
|
||||||
@@ -108,6 +125,7 @@ class CompanyData {
|
|||||||
|
|
||||||
function AddMonitorElement(mon);
|
function AddMonitorElement(mon);
|
||||||
function UpdateDelivered(mon);
|
function UpdateDelivered(mon);
|
||||||
|
function UpdateTimeout(step);
|
||||||
function CheckAndFinishGoals();
|
function CheckAndFinishGoals();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -201,6 +219,14 @@ function CompanyData::UpdateDelivereds(cmon)
|
|||||||
return finished; // One or more goals was considered 'done'
|
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.
|
// Test whether goals of the company are 'done', and if so, drop them.
|
||||||
function CompanyData::CheckAndFinishGoals()
|
function CompanyData::CheckAndFinishGoals()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
STR_LAKE_NEWS :There are {NUM} {}fish here
|
STR_LAKE_NEWS :There are {NUM} {}fish here
|
||||||
STR_COMPANY_GOAL :Deliver {CARGO_LONG} to {STRING}
|
STR_COMPANY_GOAL :Deliver {CARGO_LONG} to {STRING}
|
||||||
STR_PROGRESS :{NUM}% done
|
STR_PROGRESS :{NUM}% done
|
||||||
|
STR_TIMEOUT :{NUM} ticks remaining
|
||||||
STR_TOWN_NAME :{TOWN}
|
STR_TOWN_NAME :{TOWN}
|
||||||
STR_INDUSTRY_NAME :{INDUSTRY}
|
STR_INDUSTRY_NAME :{INDUSTRY}
|
||||||
|
|||||||
8
main.nut
8
main.nut
@@ -325,6 +325,14 @@ function BusyBeeClass::Start()
|
|||||||
new_goal_timeout -= delay_time;
|
new_goal_timeout -= delay_time;
|
||||||
monitor_timeout -= delay_time;
|
monitor_timeout -= delay_time;
|
||||||
finished_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user