-Feature: Reset the timeout when delivering cargo for a goal.
This commit is contained in:
23
company.nut
23
company.nut
@@ -38,14 +38,7 @@ class CompanyGoal {
|
|||||||
this.cargo = cargo;
|
this.cargo = cargo;
|
||||||
this.accept = accept;
|
this.accept = accept;
|
||||||
this.wanted_amount = wanted_amount;
|
this.wanted_amount = wanted_amount;
|
||||||
|
this.ResetTimeout();
|
||||||
local years = GSController.GetSetting("wait_years");
|
|
||||||
this.timeout = years * 365 * 74;
|
|
||||||
while (years >= 4) {
|
|
||||||
this.timeout += 74; // Add one day for every 4 years.
|
|
||||||
years -= 4;
|
|
||||||
}
|
|
||||||
if (years >= 2) this.timeout += 74 / 2; // And 1/2 a day for 2 years.
|
|
||||||
|
|
||||||
// Construct goal if a company id was provided.
|
// Construct goal if a company id was provided.
|
||||||
if (comp_id != null) {
|
if (comp_id != null) {
|
||||||
@@ -70,6 +63,7 @@ class CompanyGoal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetTimeoutDays();
|
||||||
function AddMonitorElement(mon);
|
function AddMonitorElement(mon);
|
||||||
function UpdateDelivered(mon, comp_id);
|
function UpdateDelivered(mon, comp_id);
|
||||||
function UpdateTimeout(step);
|
function UpdateTimeout(step);
|
||||||
@@ -81,6 +75,18 @@ class CompanyGoal {
|
|||||||
static function LoadGoal(num, loaded_data);
|
static function LoadGoal(num, loaded_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reset the timeout of the goal.
|
||||||
|
function CompanyGoal::ResetTimeout()
|
||||||
|
{
|
||||||
|
local years = GSController.GetSetting("wait_years");
|
||||||
|
this.timeout = years * 365 * 74;
|
||||||
|
while (years >= 4) {
|
||||||
|
this.timeout += 74; // Add one day for every 4 years.
|
||||||
|
years -= 4;
|
||||||
|
}
|
||||||
|
if (years >= 2) this.timeout += 74 / 2; // And 1/2 a day for 2 years.
|
||||||
|
}
|
||||||
|
|
||||||
function CompanyGoal::SaveGoal()
|
function CompanyGoal::SaveGoal()
|
||||||
{
|
{
|
||||||
return {cid=this.cargo.cid, accept=this.accept, wanted=this.wanted_amount,
|
return {cid=this.cargo.cid, accept=this.accept, wanted=this.wanted_amount,
|
||||||
@@ -133,6 +139,7 @@ function CompanyGoal::UpdateDelivered(mon, comp_id)
|
|||||||
|
|
||||||
if (delivered > 0) {
|
if (delivered > 0) {
|
||||||
this.delivered_amount += delivered;
|
this.delivered_amount += delivered;
|
||||||
|
this.ResetTimeout();
|
||||||
if (this.goal_id != null) {
|
if (this.goal_id != null) {
|
||||||
local perc;
|
local perc;
|
||||||
if (this.delivered_amount >= this.wanted_amount) {
|
if (this.delivered_amount >= this.wanted_amount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user