|
|
@ -1717,43 +1717,33 @@ static bool CheckFree2x2Area(TileIndex tile, uint z, bool noslope)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
uint bitmask;
|
|
|
|
|
|
|
|
HouseID house;
|
|
|
|
|
|
|
|
Slope slope;
|
|
|
|
|
|
|
|
uint z;
|
|
|
|
|
|
|
|
uint oneof = 0;
|
|
|
|
|
|
|
|
HouseSpec *hs;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no house allowed at all, bail out */
|
|
|
|
/* no house allowed at all, bail out */
|
|
|
|
if (!CanBuildHouseHere(tile, false)) return false;
|
|
|
|
if (!CanBuildHouseHere(tile, false)) return false;
|
|
|
|
|
|
|
|
|
|
|
|
/* Above snow? */
|
|
|
|
uint z;
|
|
|
|
slope = GetTileSlope(tile, &z);
|
|
|
|
Slope slope = GetTileSlope(tile, &z);
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the town zone type of the current tile, as well as the climate.
|
|
|
|
/* Get the town zone type of the current tile, as well as the climate.
|
|
|
|
* This will allow to easily compare with the specs of the new house to build */
|
|
|
|
* This will allow to easily compare with the specs of the new house to build */
|
|
|
|
{
|
|
|
|
|
|
|
|
HouseZonesBits rad = GetTownRadiusGroup(t, tile);
|
|
|
|
HouseZonesBits rad = GetTownRadiusGroup(t, tile);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Above snow? */
|
|
|
|
int land = _opt.landscape;
|
|
|
|
int land = _opt.landscape;
|
|
|
|
if (land == LT_ARCTIC && z >= _opt.snow_line) land = -1;
|
|
|
|
if (land == LT_ARCTIC && z >= _opt.snow_line) land = -1;
|
|
|
|
|
|
|
|
|
|
|
|
bitmask = (1 << rad) + (1 << (land + 12));
|
|
|
|
uint bitmask = (1 << rad) + (1 << (land + 12));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* bits 0-4 are used
|
|
|
|
/* bits 0-4 are used
|
|
|
|
* bits 11-15 are used
|
|
|
|
* bits 11-15 are used
|
|
|
|
* bits 5-10 are not used. */
|
|
|
|
* bits 5-10 are not used. */
|
|
|
|
{
|
|
|
|
|
|
|
|
HouseID houses[HOUSE_MAX];
|
|
|
|
HouseID houses[HOUSE_MAX];
|
|
|
|
int num = 0;
|
|
|
|
uint num = 0;
|
|
|
|
uint probs[HOUSE_MAX];
|
|
|
|
uint probs[HOUSE_MAX];
|
|
|
|
uint probability_max = 0;
|
|
|
|
uint probability_max = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Generate a list of all possible houses that can be built. */
|
|
|
|
/* Generate a list of all possible houses that can be built. */
|
|
|
|
for (i = 0; i < HOUSE_MAX; i++) {
|
|
|
|
for (uint i = 0; i < HOUSE_MAX; i++) {
|
|
|
|
hs = GetHouseSpecs(i);
|
|
|
|
HouseSpec *hs = GetHouseSpecs(i);
|
|
|
|
/* Verify that the candidate house spec matches the current tile status */
|
|
|
|
/* Verify that the candidate house spec matches the current tile status */
|
|
|
|
if ((~hs->building_availability & bitmask) == 0 && hs->enabled) {
|
|
|
|
if ((~hs->building_availability & bitmask) == 0 && hs->enabled) {
|
|
|
|
/* Without NewHouses, all houses have probability '1' */
|
|
|
|
/* Without NewHouses, all houses have probability '1' */
|
|
|
@ -1768,12 +1758,13 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
|
|
|
|
|
|
|
|
while (probability_max > 0) {
|
|
|
|
while (probability_max > 0) {
|
|
|
|
uint r = RandomRange(probability_max);
|
|
|
|
uint r = RandomRange(probability_max);
|
|
|
|
|
|
|
|
uint i;
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
if (probs[i] > r) break;
|
|
|
|
if (probs[i] > r) break;
|
|
|
|
r -= probs[i];
|
|
|
|
r -= probs[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
house = houses[i];
|
|
|
|
HouseID house = houses[i];
|
|
|
|
probability_max -= probs[i];
|
|
|
|
probability_max -= probs[i];
|
|
|
|
|
|
|
|
|
|
|
|
/* remove tested house from the set */
|
|
|
|
/* remove tested house from the set */
|
|
|
@ -1781,7 +1772,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
houses[i] = houses[num];
|
|
|
|
houses[i] = houses[num];
|
|
|
|
probs[i] = probs[num];
|
|
|
|
probs[i] = probs[num];
|
|
|
|
|
|
|
|
|
|
|
|
hs = GetHouseSpecs(house);
|
|
|
|
HouseSpec *hs = GetHouseSpecs(house);
|
|
|
|
|
|
|
|
|
|
|
|
if (_loaded_newgrf_features.has_newhouses) {
|
|
|
|
if (_loaded_newgrf_features.has_newhouses) {
|
|
|
|
if (hs->override != 0) {
|
|
|
|
if (hs->override != 0) {
|
|
|
@ -1800,12 +1791,12 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue;
|
|
|
|
if (_cur_year < hs->min_date || _cur_year > hs->max_date) continue;
|
|
|
|
|
|
|
|
|
|
|
|
/* Special houses that there can be only one of. */
|
|
|
|
/* Special houses that there can be only one of. */
|
|
|
|
|
|
|
|
uint oneof = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (hs->building_flags & BUILDING_IS_CHURCH) {
|
|
|
|
if (hs->building_flags & BUILDING_IS_CHURCH) {
|
|
|
|
SetBit(oneof, TOWN_HAS_CHURCH);
|
|
|
|
SetBit(oneof, TOWN_HAS_CHURCH);
|
|
|
|
} else if (hs->building_flags & BUILDING_IS_STADIUM) {
|
|
|
|
} else if (hs->building_flags & BUILDING_IS_STADIUM) {
|
|
|
|
SetBit(oneof, TOWN_HAS_STADIUM);
|
|
|
|
SetBit(oneof, TOWN_HAS_STADIUM);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
oneof = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (HASBITS(t->flags12 , oneof)) continue;
|
|
|
|
if (HASBITS(t->flags12 , oneof)) continue;
|
|
|
@ -1843,8 +1834,8 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
/* Special houses that there can be only one of. */
|
|
|
|
/* Special houses that there can be only one of. */
|
|
|
|
t->flags12 |= oneof;
|
|
|
|
t->flags12 |= oneof;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
byte construction_counter = 0;
|
|
|
|
byte construction_counter = 0, construction_stage = 0;
|
|
|
|
byte construction_stage = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (_generating_world) {
|
|
|
|
if (_generating_world) {
|
|
|
|
uint32 r = Random();
|
|
|
|
uint32 r = Random();
|
|
|
@ -1858,12 +1849,11 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
|
construction_counter = GB(r, 2, 2);
|
|
|
|
construction_counter = GB(r, 2, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, Random());
|
|
|
|
MakeTownHouse(tile, t->index, construction_counter, construction_stage, house, Random());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|