mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use locals for company/deity mode during script loops. (#11686)
This commit is contained in:
parent
06050f7bb3
commit
91ea8e3fa6
|
@ -27,8 +27,10 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
|||
|
||||
case ScriptTile::TRANSPORT_AIR: {
|
||||
/* Hangars are not seen as real depots by the depot code. */
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Station *st : Station::Iterate()) {
|
||||
if (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) {
|
||||
if (is_deity || st->owner == owner) {
|
||||
for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
|
||||
this->AddItem(st->airport.GetHangarTile(i).base());
|
||||
}
|
||||
|
@ -39,7 +41,9 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
|
|||
}
|
||||
|
||||
/* Handle 'standard' depots. */
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Depot *depot : Depot::Iterate()) {
|
||||
if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy.base());
|
||||
if ((is_deity || ::GetTileOwner(depot->xy) == owner) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy.base());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
ScriptEngineList::ScriptEngineList(ScriptVehicle::VehicleType vehicle_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Engine *e : Engine::IterateType((::VehicleType)vehicle_type)) {
|
||||
if (ScriptCompanyMode::IsDeity() || HasBit(e->company_avail, ScriptObject::GetCompany())) this->AddItem(e->index);
|
||||
if (is_deity || HasBit(e->company_avail, owner)) this->AddItem(e->index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
ScriptGroupList::ScriptGroupList()
|
||||
{
|
||||
EnforceCompanyModeValid_Void();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Group *g : Group::Iterate()) {
|
||||
if (g->owner == ScriptObject::GetCompany()) this->AddItem(g->index);
|
||||
if (g->owner == owner) this->AddItem(g->index);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
ScriptRailTypeList::ScriptRailTypeList()
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
if (ScriptCompanyMode::IsDeity() || ::HasRailTypeAvail(ScriptObject::GetCompany(), rt)) this->AddItem(rt);
|
||||
if (is_deity || ::HasRailTypeAvail(owner, rt)) this->AddItem(rt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
ScriptRoadTypeList::ScriptRoadTypeList(ScriptRoad::RoadTramTypes rtts)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
|
||||
if (!HasBit(rtts, GetRoadTramType(rt))) continue;
|
||||
if (::HasRoadTypeAvail(ScriptObject::GetCompany(), rt)) this->AddItem(rt);
|
||||
if (::HasRoadTypeAvail(owner, rt)) this->AddItem(rt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
|
||||
{
|
||||
EnforceDeityOrCompanyModeValid_Void();
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (Station *st : Station::Iterate()) {
|
||||
if ((st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && (st->facilities & station_type) != 0) this->AddItem(st->index);
|
||||
if ((is_deity || st->owner == owner) && (st->facilities & station_type) != 0) this->AddItem(st->index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,8 +51,10 @@ ScriptVehicleList::ScriptVehicleList(HSQUIRRELVM vm)
|
|||
}
|
||||
AutoRestoreBackup ops_error_threshold_backup(vm->_ops_till_suspend_error_threshold, new_ops_error_threshold);
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->owner != ScriptObject::GetCompany() && !ScriptCompanyMode::IsDeity()) continue;
|
||||
if (v->owner != owner && !is_deity) continue;
|
||||
if (!v->IsPrimaryVehicle() && !(v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon())) continue;
|
||||
|
||||
if (nparam < 1) {
|
||||
|
@ -107,8 +109,10 @@ ScriptVehicleList_Station::ScriptVehicleList_Station(StationID station_id)
|
|||
EnforceDeityOrCompanyModeValid_Void();
|
||||
if (!ScriptBaseStation::IsValidBaseStation(station_id)) return;
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if ((v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && v->IsPrimaryVehicle()) {
|
||||
if ((v->owner == owner || is_deity) && v->IsPrimaryVehicle()) {
|
||||
for (const Order *order : v->Orders()) {
|
||||
if ((order->IsType(OT_GOTO_STATION) || order->IsType(OT_GOTO_WAYPOINT)) && order->GetDestination() == station_id) {
|
||||
this->AddItem(v->index);
|
||||
|
@ -156,8 +160,10 @@ ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
|
|||
return;
|
||||
}
|
||||
|
||||
bool is_deity = ScriptCompanyMode::IsDeity();
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if ((v->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && v->IsPrimaryVehicle() && v->type == type) {
|
||||
if ((v->owner == owner || is_deity) && v->IsPrimaryVehicle() && v->type == type) {
|
||||
for (const Order *order : v->Orders()) {
|
||||
if (order->IsType(OT_GOTO_DEPOT) && order->GetDestination() == dest) {
|
||||
this->AddItem(v->index);
|
||||
|
@ -182,8 +188,9 @@ ScriptVehicleList_Group::ScriptVehicleList_Group(GroupID group_id)
|
|||
EnforceCompanyModeValid_Void();
|
||||
if (!ScriptGroup::IsValidGroup((ScriptGroup::GroupID)group_id)) return;
|
||||
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->owner == ScriptObject::GetCompany() && v->IsPrimaryVehicle()) {
|
||||
if (v->owner == owner && v->IsPrimaryVehicle()) {
|
||||
if (v->group_id == group_id) this->AddItem(v->index);
|
||||
}
|
||||
}
|
||||
|
@ -194,8 +201,9 @@ ScriptVehicleList_DefaultGroup::ScriptVehicleList_DefaultGroup(ScriptVehicle::Ve
|
|||
EnforceCompanyModeValid_Void();
|
||||
if (vehicle_type < ScriptVehicle::VT_RAIL || vehicle_type > ScriptVehicle::VT_AIR) return;
|
||||
|
||||
CompanyID owner = ScriptObject::GetCompany();
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
if (v->owner == ScriptObject::GetCompany() && v->IsPrimaryVehicle()) {
|
||||
if (v->owner == owner && v->IsPrimaryVehicle()) {
|
||||
if (v->type == (::VehicleType)vehicle_type && v->group_id == ScriptGroup::GROUP_DEFAULT) this->AddItem(v->index);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue