Changeset - r28397:940ec1a88c17
[Not reviewed]
master
0 7 0
Peter Nelson - 11 months ago 2024-01-05 08:32:43
peter1138@openttd.org
Codechange: Use locals for company/deity mode during script loops. (#11686)
7 files changed with 32 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_depotlist.cpp
Show inline comments
 
@@ -27,8 +27,10 @@ ScriptDepotList::ScriptDepotList(ScriptT
 

	
 
		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(ScriptT
 
	}
 

	
 
	/* 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());
 
	}
 
}
src/script/api/script_enginelist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
src/script/api/script_grouplist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
src/script/api/script_railtypelist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
src/script/api/script_roadtypelist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
src/script/api/script_stationlist.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
 

	
src/script/api/script_vehiclelist.cpp
Show inline comments
 
@@ -51,8 +51,10 @@ ScriptVehicleList::ScriptVehicleList(HSQ
 
	}
 
	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::ScriptVehicle
 
	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::ScriptVehicleLi
 
			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::ScriptVehicleLi
 
	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::ScriptVe
 
	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);
 
		}
 
	}
0 comments (0 inline, 0 general)