Skip to content

Instantly share code, notes, and snippets.

@SamuXarick
Created February 13, 2023 13:30
Show Gist options
  • Save SamuXarick/02ff9c95a80f6ed4b8ec1d4f254af175 to your computer and use it in GitHub Desktop.
Save SamuXarick/02ff9c95a80f6ed4b8ec1d4f254af175 to your computer and use it in GitHub Desktop.
The sum of profit this year + profit last year is not working correctly
function LeagueTable::GetMostProfitableVehicle_Val(company)
{
if (GSCompany.ResolveCompanyID(company) != GSCompany.COMPANY_INVALID) {
local company_scope = GSCompanyMode(company);
local total_profits = GSList();
local vehicle_list = GSVehicleList();
if (vehicle_list.Count() == 0) return [ 0, { str = GetMostProfitableVehicle_ElementString(), p = [ -1 ] } ];
vehicle_list.Valuate(GSVehicle.GetProfitThisYear);
total_profits.AddList(vehicle_list);
vehicle_list.Valuate(GSVehicle.GetProfitLastYear);
foreach(vehicle in total_profits) {
total_profits.SetValue(vehicle, (total_profits.GetValue(vehicle) + vehicle_list.GetValue(vehicle)));
}
return [ total_profits.GetValue(total_profits.Begin()), { str = GetMostProfitableVehicle_ElementString(), p = [ total_profits.Begin() ] } ];
}
return [ 0, { str = GetMostProfitableVehicle_ElementString(), p = [ -1 ] } ];
}
@glx22
Copy link

glx22 commented Feb 13, 2023

		foreach(vehicle, value in vehicle_list) {
			total_profits.SetValue(vehicle, (total_profits.GetValue(vehicle) + value));
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment