-
-
Save SamuXarick/bb25276e300a42f58e34400e64876a66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////// | |
// script_vehiclelist.hpp // | |
//////////////////////////// | |
/** | |
* Creates a list of vehicles of which you are the owner. | |
* @api ai game | |
* @ingroup ScriptList | |
*/ | |
class ScriptVehicleList : public ScriptList { | |
public: | |
ScriptVehicleList(); | |
/** | |
* @api -all | |
*/ | |
ScriptList ScriptVehicleList1(); | |
/** | |
* @api -all | |
*/ | |
ScriptList ScriptVehicleList2(); | |
}; | |
//////////////////////////// | |
// script_vehiclelist.cpp // | |
//////////////////////////// | |
ScriptVehicleList::ScriptVehicleList() | |
{ | |
ScriptList *list1 = new ScriptList(); | |
list1->AddList(&ScriptVehicleList1()); | |
ScriptList *list2 = new ScriptList(); | |
list2->AddList(&ScriptVehicleList2()); | |
assert(list1->Count() == list2->Count()); | |
for (SQInteger item = list1->Begin(); !list1->IsEnd(); item = list1->Next()) { | |
assert(list2->HasItem(item)); | |
} | |
this->AddList(list1); | |
delete list1; | |
delete list2; | |
} | |
ScriptList ScriptVehicleList::ScriptVehicleList1() | |
{ | |
ScriptList list; | |
for (const Company *c : Company::Iterate()) { | |
if (c->index != ScriptObject::GetCompany() && !ScriptCompanyMode::IsDeity()) continue; | |
for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { | |
GroupStatistics &stats = Company::Get(c->index)->group_all[type]; | |
for (const auto vehicle_id : stats.vehicle_list) { | |
list.AddItem(vehicle_id); | |
} | |
} | |
} | |
return list; | |
} | |
ScriptList ScriptVehicleList::ScriptVehicleList2() | |
{ | |
ScriptList list; | |
for (const Vehicle *v : Vehicle::Iterate()) { | |
if ((v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()))) list.AddItem(v->index); | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment