1
0
Fork 0

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.
pull/10629/head
Peter Nelson 2023-04-06 20:29:57 +01:00 committed by Charles Pigott
parent 4a1361b044
commit d510e0baa8
1 changed files with 30 additions and 25 deletions

View File

@ -5572,6 +5572,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();
@ -5624,6 +5629,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();
@ -5636,11 +5646,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]];
@ -5655,6 +5660,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();
@ -5667,11 +5677,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]];
@ -5686,6 +5691,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();
@ -5698,11 +5708,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]];
@ -5864,6 +5869,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();
@ -5876,11 +5886,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]];
@ -5895,6 +5900,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();
@ -5907,11 +5917,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]];