Fix: Industry layouts with zero regular tiles should be invalid

This commit is contained in:
Niels Martin Hansen 2022-05-29 15:56:30 +02:00
parent 578bb6638f
commit 5587e439a9
1 changed files with 10 additions and 2 deletions

View File

@ -27,6 +27,7 @@
#include "newgrf_sound.h" #include "newgrf_sound.h"
#include "newgrf_station.h" #include "newgrf_station.h"
#include "industrytype.h" #include "industrytype.h"
#include "industry_map.h"
#include "newgrf_canal.h" #include "newgrf_canal.h"
#include "newgrf_townname.h" #include "newgrf_townname.h"
#include "newgrf_industries.h" #include "newgrf_industries.h"
@ -3374,15 +3375,22 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf)
static bool ValidateIndustryLayout(const IndustryTileLayout &layout) static bool ValidateIndustryLayout(const IndustryTileLayout &layout)
{ {
const size_t size = layout.size(); const size_t size = layout.size();
if (size == 0) return false;
size_t valid_regular_tiles = 0;
for (size_t i = 0; i < size - 1; i++) { for (size_t i = 0; i < size - 1; i++) {
for (size_t j = i + 1; j < size; j++) { for (size_t j = i + 1; j < size; j++) {
if (layout[i].ti.x == layout[j].ti.x && if (layout[i].ti.x == layout[j].ti.x &&
layout[i].ti.y == layout[j].ti.y) { layout[i].ti.y == layout[j].ti.y) {
return false; return false;
} }
if (layout[i].gfx != GFX_WATERTILE_SPECIALCHECK) {
++valid_regular_tiles;
}
} }
} }
return true; return valid_regular_tiles > 0;
} }
/** /**
@ -3533,7 +3541,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
/* Declared as been valid, can be used */ /* Declared as been valid, can be used */
it.gfx = tempid; it.gfx = tempid;
} }
} else if (it.gfx == 0xFF) { } else if (it.gfx == GFX_WATERTILE_SPECIALCHECK) {
it.ti.x = (int8)GB(it.ti.x, 0, 8); it.ti.x = (int8)GB(it.ti.x, 0, 8);
it.ti.y = (int8)GB(it.ti.y, 0, 8); it.ti.y = (int8)GB(it.ti.y, 0, 8);