Fix: Don't create more than 2 goals for the same cargo type.
This commit is contained in:
14
company.nut
14
company.nut
@@ -104,6 +104,7 @@ class CompanyData {
|
|||||||
function GetMissingGoalCount();
|
function GetMissingGoalCount();
|
||||||
function AddActiveGoal(cargo_id, accept, amount);
|
function AddActiveGoal(cargo_id, accept, amount);
|
||||||
function HasGoal(cargo_id, accept);
|
function HasGoal(cargo_id, accept);
|
||||||
|
function GetNumberOfGoalsForCargo(cargo_id);
|
||||||
|
|
||||||
function AddMonitorElement(mon);
|
function AddMonitorElement(mon);
|
||||||
function UpdateDelivered(mon);
|
function UpdateDelivered(mon);
|
||||||
@@ -154,6 +155,19 @@ function CompanyData::HasGoal(cargo_id, accept)
|
|||||||
return false;
|
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.
|
// Add monitor elements of a company, if they exist.
|
||||||
// @param [inout] cmon Monitors of all companies, updated in-place.
|
// @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'
|
// Result is 'comp_id' number to 'cargo_id' numbers to 'ind' and/or 'town' indices to 'null'
|
||||||
|
|||||||
7
main.nut
7
main.nut
@@ -165,13 +165,13 @@ function BusyBeeClass::FindChallenge(cargo_id, distance, cid)
|
|||||||
// Try to add a goal for a company.
|
// Try to add a goal for a company.
|
||||||
function BusyBeeClass::CreateChallenge(cid)
|
function BusyBeeClass::CreateChallenge(cid)
|
||||||
{
|
{
|
||||||
local attempt = 0;
|
local cdata = this.companies[cid];
|
||||||
while (attempt < 20) {
|
for (local attempt = 0;attempt < 20; attempt += 1) {
|
||||||
local cargo = GSBase.RandRange(this.num_cargoes);
|
local cargo = GSBase.RandRange(this.num_cargoes);
|
||||||
|
if (cdata.GetNumberOfGoalsForCargo(cargo) > 1) continue; // Already 2 goals for this cargo.
|
||||||
local distance = GSBase.RandRange(200) + 50; // Distance 50 .. 250 tiles.
|
local distance = GSBase.RandRange(200) + 50; // Distance 50 .. 250 tiles.
|
||||||
local accept = FindChallenge(cargo, distance, cid);
|
local accept = FindChallenge(cargo, distance, cid);
|
||||||
if (accept != null) {
|
if (accept != null) {
|
||||||
local cdata = this.companies[cid];
|
|
||||||
local amount = GSBase.RandRange(100) + 1;
|
local amount = GSBase.RandRange(100) + 1;
|
||||||
if (amount < 10) {
|
if (amount < 10) {
|
||||||
amount = amount * 25; // 25 .. 225
|
amount = amount * 25; // 25 .. 225
|
||||||
@@ -195,7 +195,6 @@ function BusyBeeClass::CreateChallenge(cid)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attempt += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user