Change: Monitor company new/merge/delete, and industry closure events,

re-organized handling of creating/updating/removal of goals.
This commit is contained in:
Alberth
2014-12-31 18:02:06 +01:00
parent 4e661c91ce
commit 524b958782
2 changed files with 142 additions and 73 deletions

View File

@@ -123,13 +123,28 @@ class CompanyData {
function AddActiveGoal(cargo_id, accept, amount);
function HasGoal(cargo_id, accept);
function GetNumberOfGoalsForCargo(cargo_id);
function IndustryClosed(ind_id);
function AddMonitorElement(mon);
function UpdateDelivered(mon);
function UpdateTimeout(step);
function CheckAndFinishGoals();
function FinalizeCompany();
};
// Company is about to be deleted, last chance to clean up.
function CompanyData::FinalizeCompany()
{
foreach (num, goal in this.active_goals) {
if (goal != null) {
goal.FinalizeGoal();
this.active_goals[num] = null;
}
}
}
// Find the number of active goals that are missing for this company.
// @return Number of additional goals that the company needs.
function CompanyData::GetMissingGoalCount()
@@ -187,6 +202,19 @@ function CompanyData::GetNumberOfGoalsForCargo(cargo_id)
return count;
}
// The given industry closed, delete any goal with it.
// @param ind_id Industry that closed.
function CompanyData::IndustryClosed(ind_id)
{
foreach (num, goal in this.active_goals) {
if (goal == null) continue;
if ("ind" in goal.accept && goal.accept.ind == ind_id) {
goal.FinalizeGoal();
this.active_goals[num] = null;
}
}
}
// Add monitor elements of a company, if they exist.
// @param [inout] cmon Monitors of all companies, updated in-place.
// Result is 'comp_id' number to 'cargo_id' numbers to 'ind' and/or 'town' indices to 'null'