Codechange: Check NewGRF feature is defined before processing any sprite group mapping.

Previously this was checked after loading ids, or repeatedly checked for
each item.
This commit is contained in:
Peter Nelson 2023-04-06 20:29:57 +01:00 committed by PeterN
parent 04215afe3f
commit 96f4eb3681
1 changed files with 35 additions and 30 deletions

View File

@ -5706,6 +5706,11 @@ static void CanalMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void StationMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->stations == nullptr) {
grfmsg(1, "StationMapSpriteGroup: No stations defined, skipping");
return;
}
uint8 *stations = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
stations[i] = buf->ReadByte();
@ -5758,6 +5763,11 @@ static void StationMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void TownHouseMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->housespec == nullptr) {
grfmsg(1, "TownHouseMapSpriteGroup: No houses defined, skipping");
return;
}
uint8 *houses = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
houses[i] = buf->ReadByte();
@ -5770,11 +5780,6 @@ static void TownHouseMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "TownHouseMapSpriteGroup")) return;
if (_cur.grffile->housespec == nullptr) {
grfmsg(1, "TownHouseMapSpriteGroup: No houses defined, skipping");
return;
}
for (uint i = 0; i < idcount; i++) {
HouseSpec *hs = _cur.grffile->housespec[houses[i]];
@ -5789,6 +5794,11 @@ static void TownHouseMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void IndustryMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->industryspec == nullptr) {
grfmsg(1, "IndustryMapSpriteGroup: No industries defined, skipping");
return;
}
uint8 *industries = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
industries[i] = buf->ReadByte();
@ -5801,11 +5811,6 @@ static void IndustryMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "IndustryMapSpriteGroup")) return;
if (_cur.grffile->industryspec == nullptr) {
grfmsg(1, "IndustryMapSpriteGroup: No industries defined, skipping");
return;
}
for (uint i = 0; i < idcount; i++) {
IndustrySpec *indsp = _cur.grffile->industryspec[industries[i]];
@ -5820,6 +5825,11 @@ static void IndustryMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void IndustrytileMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->indtspec == nullptr) {
grfmsg(1, "IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
return;
}
uint8 *indtiles = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
indtiles[i] = buf->ReadByte();
@ -5832,11 +5842,6 @@ static void IndustrytileMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "IndustrytileMapSpriteGroup")) return;
if (_cur.grffile->indtspec == nullptr) {
grfmsg(1, "IndustrytileMapSpriteGroup: No industry tiles defined, skipping");
return;
}
for (uint i = 0; i < idcount; i++) {
IndustryTileSpec *indtsp = _cur.grffile->indtspec[indtiles[i]];
@ -5998,6 +6003,11 @@ static void RoadTypeMapSpriteGroup(ByteReader *buf, uint8 idcount, RoadTramType
static void AirportMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->airportspec == nullptr) {
grfmsg(1, "AirportMapSpriteGroup: No airports defined, skipping");
return;
}
uint8 *airports = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
airports[i] = buf->ReadByte();
@ -6010,11 +6020,6 @@ static void AirportMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "AirportMapSpriteGroup")) return;
if (_cur.grffile->airportspec == nullptr) {
grfmsg(1, "AirportMapSpriteGroup: No airports defined, skipping");
return;
}
for (uint i = 0; i < idcount; i++) {
AirportSpec *as = _cur.grffile->airportspec[airports[i]];
@ -6029,6 +6034,11 @@ static void AirportMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void AirportTileMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->airtspec == nullptr) {
grfmsg(1, "AirportTileMapSpriteGroup: No airport tiles defined, skipping");
return;
}
uint8 *airptiles = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
airptiles[i] = buf->ReadByte();
@ -6041,11 +6051,6 @@ static void AirportTileMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "AirportTileMapSpriteGroup")) return;
if (_cur.grffile->airtspec == nullptr) {
grfmsg(1, "AirportTileMapSpriteGroup: No airport tiles defined, skipping");
return;
}
for (uint i = 0; i < idcount; i++) {
AirportTileSpec *airtsp = _cur.grffile->airtspec[airptiles[i]];
@ -6060,6 +6065,11 @@ static void AirportTileMapSpriteGroup(ByteReader *buf, uint8 idcount)
static void RoadStopMapSpriteGroup(ByteReader *buf, uint8 idcount)
{
if (_cur.grffile->roadstops == nullptr) {
grfmsg(1, "RoadStopMapSpriteGroup: No roadstops defined, skipping");
return;
}
uint8 *roadstops = AllocaM(uint8, idcount);
for (uint i = 0; i < idcount; i++) {
roadstops[i] = buf->ReadByte();
@ -6089,11 +6099,6 @@ static void RoadStopMapSpriteGroup(ByteReader *buf, uint8 idcount)
uint16 groupid = buf->ReadWord();
if (!IsValidGroupID(groupid, "RoadStopMapSpriteGroup")) return;
if (_cur.grffile->roadstops == nullptr) {
grfmsg(0, "RoadStopMapSpriteGroup: No roadstops defined, skipping.");
return;
}
for (uint i = 0; i < idcount; i++) {
RoadStopSpec *roadstopspec = _cur.grffile->roadstops == nullptr ? nullptr : _cur.grffile->roadstops[roadstops[i]];