Add cargo goal for specific type of cargo
Arastais opened this issue · 2 comments
Create an objective/goal for delivering a specific cargo, not just any cargo (requires tracking cargo deliveries manually)
To get the total amount of cargo delivered by a company, you can run the following code for each company and cargo in a quarterly update loop, where company
is the company being scored and cargo_id
is the cargo ID for the goal.
This works as far as I can tell because GetTownDeliveryAmount
accumulates cargo deliveries to not only the town's houses, but also any industries associated with the town.
local cargo_delivered = 0;
local towns = GSTownList();
foreach (index, town in towns) {
cargo_delivered += GSCargoMonitor.GetTownDeliveryAmount(company, cargo_id, index, true)
}
(It's up to you how to add this to your script; feel free to edit and/or rename variables if necessary)
For a monthly cargo delivery goal, divide the (quarterly) result by 3 to get per month.
For a yearly cargo delivery goal, multiply the quarterly result by 4, or sum over the past 4 quarterly results.
For a lifetime cargo delivery goal, keep track of each company's deliveries and update them each quarter as new results come in.
Thanks for the comment. I was planning on doing this feature similar to how you're doing it, but obviously haven't gotten around to it.
The main problem for me was actually GSInfo. Specifically, when someone wants to select which cargo type, it doesn't make much sense if they just see cargo Ids, so they'd need to be able to see the name of the cargo. There is of course static char* GSCargo::GetName(CargoID cargo_type)
and static char* GSCargo::GetCargoLabel(CargoID cargo_type)
, but I don't think I can change GSInfo to add labels to the setting. Not to mention it would also have to take into account and NewGRFs which add cargo, and then the script itself has to add/remove labels based on the NewGRFs loaded when creating a game. There are ways to check the NewGRFs and the current cargos, but again I don't think there's a way to change GSInfo setting labels outside of info.nut.