Changeset - r28758:c2c73029ff81
[Not reviewed]
master
0 2 0
Peter Nelson - 10 months ago 2024-02-14 19:21:13
peter1138@openttd.org
Fix: NewGRF roadstops were ignored if only in default class. (#12089)

If a NewGRF defines roadstops in the default class and no other classes are defined, they would be ignored and not selectable.
2 files changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/newgrf_roadstop.cpp
Show inline comments
 
@@ -455,42 +455,43 @@ void TriggerRoadStopRandomisation(Statio
 
		st->random_bits |= Random() & whole_reseed;
 
	}
 
}
 

	
 
/**
 
 * Checks if there's any new stations by a specific RoadStopType
 
 * @param rs the RoadStopType to check.
 
 * @param roadtype the RoadType to check.
 
 * @return true if there was any new RoadStopSpec's found for the given RoadStopType and RoadType, else false.
 
 */
 
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype)
 
{
 
	if (!(RoadStopClass::GetClassCount() > 1 || RoadStopClass::Get(ROADSTOP_CLASS_DFLT)->GetSpecCount() > 1)) return false;
 
	for (uint i = 0; i < RoadStopClass::GetClassCount(); i++) {
 
		// We don't want to check the default or waypoint classes. These classes are always available.
 
		if (i == ROADSTOP_CLASS_DFLT || i == ROADSTOP_CLASS_WAYP) continue;
 
		RoadStopClass *roadstopclass = RoadStopClass::Get((RoadStopClassID)i);
 
		/* Ignore the waypoint class. */
 
		if (i == ROADSTOP_CLASS_WAYP) continue;
 
		const RoadStopClass *roadstopclass = RoadStopClass::Get((RoadStopClassID)i);
 
		/* Ignore the default class with only the default station. */
 
		if (i == ROADSTOP_CLASS_DFLT && roadstopclass->GetSpecCount() == 1) continue;
 
		if (GetIfClassHasNewStopsByType(roadstopclass, rs, roadtype)) return true;
 
	}
 
	return false;
 
}
 

	
 
/**
 
 * Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopType.
 
 * @param roadstopclass the RoadStopClass to check.
 
 * @param rs the RoadStopType to check.
 
 * @param roadtype the RoadType to check.
 
 * @return true if the RoadStopSpec has any specs compatible with the given RoadStopType and RoadType.
 
 */
 
bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
 
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
 
{
 
	for (uint j = 0; j < roadstopclass->GetSpecCount(); j++) {
 
		if (GetIfStopIsForType(roadstopclass->GetSpec(j), rs, roadtype)) return true;
 
	}
 
	return false;
 
}
 

	
 
/**
 
 * Checks if the given RoadStopSpec is compatible with the given RoadStopType.
 
 * @param roadstopspec the RoadStopSpec to check.
 
 * @param rs the RoadStopType to check.
 
 * @param roadtype the RoadType to check.
src/newgrf_roadstop.h
Show inline comments
 
@@ -164,23 +164,23 @@ struct RoadStopSpec {
 
typedef NewGRFClass<RoadStopSpec, RoadStopClassID, ROADSTOP_CLASS_MAX> RoadStopClass;
 

	
 
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view);
 

	
 
uint16_t GetRoadStopCallback(CallbackID callback, uint32_t param1, uint32_t param2, const RoadStopSpec *roadstopspec, BaseStation *st, TileIndex tile, RoadType roadtype, StationType type, uint8_t view);
 

	
 
void AnimateRoadStopTile(TileIndex tile);
 
uint8_t GetRoadStopTileAnimationSpeed(TileIndex tile);
 
void TriggerRoadStopAnimation(BaseStation *st, TileIndex tile, StationAnimationTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 
void TriggerRoadStopRandomisation(Station *st, TileIndex tile, RoadStopRandomTrigger trigger, CargoID cargo_type = INVALID_CARGO);
 

	
 
bool GetIfNewStopsByType(RoadStopType rs, RoadType roadtype);
 
bool GetIfClassHasNewStopsByType(RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
 
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype);
 
bool GetIfStopIsForType(const RoadStopSpec *roadstopspec, RoadStopType rs, RoadType roadtype);
 

	
 
uint GetCountOfCompatibleStopsByType(RoadStopClass *roadstopclass, RoadStopType rs);
 

	
 
const RoadStopSpec *GetRoadStopSpec(TileIndex t);
 
int AllocateSpecToRoadStop(const RoadStopSpec *statspec, BaseStation *st, bool exec);
 
void DeallocateSpecFromRoadStop(BaseStation *st, byte specindex);
 
void RoadStopUpdateCachedTriggers(BaseStation *st);
 

	
 
#endif /* NEWGRF_ROADSTATION_H */
0 comments (0 inline, 0 general)