Fix: Don't create more than 2 goals for the same cargo type.

This commit is contained in:
Alberth
2014-12-30 18:10:13 +01:00
parent 588502838c
commit 3c9f2c8314
2 changed files with 17 additions and 4 deletions

View File

@@ -104,6 +104,7 @@ class CompanyData {
function GetMissingGoalCount();
function AddActiveGoal(cargo_id, accept, amount);
function HasGoal(cargo_id, accept);
function GetNumberOfGoalsForCargo(cargo_id);
function AddMonitorElement(mon);
function UpdateDelivered(mon);
@@ -154,6 +155,19 @@ function CompanyData::HasGoal(cargo_id, accept)
return false;
}
// Count the number of goals that ask for the given cargo type.
// @param cargo_id Cargo to check for.
// @return Number of active goals with the given cargo type.
function CompanyData::GetNumberOfGoalsForCargo(cargo_id)
{
local count = 0;
foreach (num, goal in this.active_goals) {
if (goal == null) continue;
if (goal.cargo_id == cargo_id) count += 1;
}
return count;
}
// 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'