|
@@ -49,15 +49,15 @@ enum {
|
|
|
TOWN_HAS_STADIUM = 0x04
|
|
|
};
|
|
|
|
|
|
// Local
|
|
|
static int _grow_town_result;
|
|
|
|
|
|
static bool BuildTownHouse(Town *t, uint tile);
|
|
|
static void ClearTownHouse(Town *t, uint tile);
|
|
|
static void DoBuildTownHouse(Town *t, uint tile);
|
|
|
static bool BuildTownHouse(Town *t, TileIndex tile);
|
|
|
static void ClearTownHouse(Town *t, TileIndex tile);
|
|
|
static void DoBuildTownHouse(Town *t, TileIndex tile);
|
|
|
|
|
|
typedef struct DrawTownTileStruct {
|
|
|
uint32 sprite_1;
|
|
|
uint32 sprite_2;
|
|
|
|
|
|
byte subtile_x:4;
|
|
@@ -147,13 +147,13 @@ static uint GetSlopeZ_Town(TileInfo *ti)
|
|
|
|
|
|
static uint GetSlopeTileh_Town(TileInfo *ti)
|
|
|
{
|
|
|
return ti->tileh;
|
|
|
}
|
|
|
|
|
|
static void AnimateTile_Town(uint tile)
|
|
|
static void AnimateTile_Town(TileIndex tile)
|
|
|
{
|
|
|
int old;
|
|
|
int i;
|
|
|
int a,b;
|
|
|
|
|
|
if (_tick_counter & 3)
|
|
@@ -185,13 +185,13 @@ static void AnimateTile_Town(uint tile)
|
|
|
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
}
|
|
|
|
|
|
static void UpdateTownRadius(Town *t);
|
|
|
|
|
|
static bool IsCloseToTown(uint tile, uint dist)
|
|
|
static bool IsCloseToTown(TileIndex tile, uint dist)
|
|
|
{
|
|
|
Town *t;
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
if (t->xy != 0 && DistanceManhattan(tile, t->xy) < dist)
|
|
|
return true;
|
|
@@ -239,13 +239,13 @@ uint32 GetWorldPopulation(void)
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
pop += t->population;
|
|
|
}
|
|
|
return pop;
|
|
|
}
|
|
|
|
|
|
static void MakeSingleHouseBigger(uint tile)
|
|
|
static void MakeSingleHouseBigger(TileIndex tile)
|
|
|
{
|
|
|
byte b;
|
|
|
|
|
|
assert(IsTileType(tile, MP_HOUSE));
|
|
|
|
|
|
b = _map5[tile];
|
|
@@ -262,22 +262,22 @@ static void MakeSingleHouseBigger(uint t
|
|
|
if ( (_map3_lo[tile] & 0xC0) == 0xC0) {
|
|
|
ChangePopulation(GetTown(_map2[tile]), _housetype_population[_map3_hi[tile]]);
|
|
|
}
|
|
|
MarkTileDirtyByTile(tile);
|
|
|
}
|
|
|
|
|
|
static void MakeTownHouseBigger(uint tile)
|
|
|
static void MakeTownHouseBigger(TileIndex tile)
|
|
|
{
|
|
|
uint flags = _house_more_flags[_map3_hi[tile]];
|
|
|
if (flags & 8) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 0));
|
|
|
if (flags & 4) MakeSingleHouseBigger(TILE_ADDXY(tile, 0, 1));
|
|
|
if (flags & 2) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 0));
|
|
|
if (flags & 1) MakeSingleHouseBigger(TILE_ADDXY(tile, 1, 1));
|
|
|
}
|
|
|
|
|
|
static void TileLoop_Town(uint tile)
|
|
|
static void TileLoop_Town(TileIndex tile)
|
|
|
{
|
|
|
int house;
|
|
|
Town *t;
|
|
|
uint32 r;
|
|
|
|
|
|
if ((_map3_lo[tile] & 0xC0) != 0xC0) {
|
|
@@ -327,18 +327,18 @@ static void TileLoop_Town(uint tile)
|
|
|
}
|
|
|
|
|
|
_current_player = OWNER_NONE;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void ClickTile_Town(uint tile)
|
|
|
static void ClickTile_Town(TileIndex tile)
|
|
|
{
|
|
|
/* not used */
|
|
|
}
|
|
|
|
|
|
static int32 ClearTile_Town(uint tile, byte flags)
|
|
|
static int32 ClearTile_Town(TileIndex tile, byte flags)
|
|
|
{
|
|
|
int house, rating;
|
|
|
int32 cost;
|
|
|
Town *t;
|
|
|
|
|
|
// safety checks
|
|
@@ -364,40 +364,40 @@ static int32 ClearTile_Town(uint tile, b
|
|
|
ClearTownHouse(t, tile);
|
|
|
}
|
|
|
|
|
|
return cost;
|
|
|
}
|
|
|
|
|
|
static void GetAcceptedCargo_Town(uint tile, AcceptedCargo ac)
|
|
|
static void GetAcceptedCargo_Town(TileIndex tile, AcceptedCargo ac)
|
|
|
{
|
|
|
int type = _map3_hi[tile];
|
|
|
|
|
|
ac[CT_PASSENGERS] = _housetype_cargo_passengers[type];
|
|
|
ac[CT_MAIL] = _housetype_cargo_mail[type];
|
|
|
ac[CT_GOODS] = _housetype_cargo_goods[type];
|
|
|
ac[CT_FOOD] = _housetype_cargo_food[type];
|
|
|
}
|
|
|
|
|
|
static void GetTileDesc_Town(uint tile, TileDesc *td)
|
|
|
static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
|
|
|
{
|
|
|
td->str = _town_tile_names[_map3_hi[tile]];
|
|
|
if ((_map3_lo[tile] & 0xC0) != 0xC0) {
|
|
|
SetDParamX(td->dparam, 0, td->str);
|
|
|
td->str = STR_2058_UNDER_CONSTRUCTION;
|
|
|
}
|
|
|
|
|
|
td->owner = OWNER_TOWN;
|
|
|
}
|
|
|
|
|
|
static uint32 GetTileTrackStatus_Town(uint tile, TransportType mode)
|
|
|
static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode)
|
|
|
{
|
|
|
/* not used */
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
static void ChangeTileOwner_Town(uint tile, byte old_player, byte new_player)
|
|
|
static void ChangeTileOwner_Town(TileIndex tile, byte old_player, byte new_player)
|
|
|
{
|
|
|
/* not used */
|
|
|
}
|
|
|
|
|
|
|
|
|
static const TileIndexDiffC _roadblock_tileadd[] = {
|
|
@@ -463,13 +463,13 @@ static byte GetTownRoadMask(TileIndex ti
|
|
|
if (b&8) r|=6;
|
|
|
if (b&16) r|=3;
|
|
|
if (b&32) r|=12;
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
static bool IsRoadAllowedHere(uint tile, int dir)
|
|
|
static bool IsRoadAllowedHere(TileIndex tile, int dir)
|
|
|
{
|
|
|
uint k;
|
|
|
uint slope;
|
|
|
|
|
|
// If this assertion fails, it might be because the world contains
|
|
|
// land at the edges. This is not ok.
|
|
@@ -525,26 +525,26 @@ no_slope:
|
|
|
/* Can somebody explain for what this is needed? :s */
|
|
|
// tile = TILE_ADD(tile, _roadblock_tileadd[dir]);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static bool TerraformTownTile(uint tile, int edges, int dir)
|
|
|
static bool TerraformTownTile(TileIndex tile, int edges, int dir)
|
|
|
{
|
|
|
int32 r;
|
|
|
|
|
|
TILE_ASSERT(tile);
|
|
|
|
|
|
r = DoCommandByTile(tile, edges, dir, DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
|
|
|
if (r == CMD_ERROR || r >= 126*16)
|
|
|
return false;
|
|
|
DoCommandByTile(tile, edges, dir, DC_AUTO | DC_NO_WATER | DC_EXEC, CMD_TERRAFORM_LAND);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static void LevelTownLand(uint tile)
|
|
|
static void LevelTownLand(TileIndex tile)
|
|
|
{
|
|
|
TileInfo ti;
|
|
|
|
|
|
TILE_ASSERT(tile);
|
|
|
|
|
|
// Don't terraform if land is plain or if there's a house there.
|
|
@@ -557,21 +557,21 @@ static void LevelTownLand(uint tile)
|
|
|
TerraformTownTile(tile, ti.tileh & 0xF, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#define IS_WATER_TILE(t) (IsTileType((t), MP_WATER) && _map5[(t)] == 0)
|
|
|
|
|
|
static void GrowTownInTile(uint *tile_ptr, uint mask, int block, Town *t1)
|
|
|
static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
|
|
|
{
|
|
|
uint16 r;
|
|
|
int a,b,rcmd;
|
|
|
uint tmptile;
|
|
|
TileIndex tmptile;
|
|
|
TileInfo ti;
|
|
|
int i;
|
|
|
int j;
|
|
|
uint tile = *tile_ptr;
|
|
|
TileIndex tile = *tile_ptr;
|
|
|
|
|
|
TILE_ASSERT(tile);
|
|
|
|
|
|
if (mask == 0) {
|
|
|
// Tile has no road. First reset the status counter
|
|
|
// to say that this is the last iteration.
|
|
@@ -708,13 +708,13 @@ build_road_and_exit:
|
|
|
}
|
|
|
}
|
|
|
#undef IS_WATER_TILE
|
|
|
|
|
|
|
|
|
// Returns true if a house was built, or no if the build failed.
|
|
|
static int GrowTownAtRoad(Town *t, uint tile)
|
|
|
static int GrowTownAtRoad(Town *t, TileIndex tile)
|
|
|
{
|
|
|
uint mask;
|
|
|
int block = 5; // special case
|
|
|
|
|
|
TILE_ASSERT(tile);
|
|
|
|
|
@@ -769,13 +769,13 @@ static int GenRandomRoadBits(void)
|
|
|
}
|
|
|
|
|
|
// Grow the town
|
|
|
// Returns true if a house was built, or no if the build failed.
|
|
|
bool GrowTown(Town *t)
|
|
|
{
|
|
|
uint tile;
|
|
|
TileIndex tile;
|
|
|
const TileIndexDiffC *ptr;
|
|
|
TileInfo ti;
|
|
|
byte old_player;
|
|
|
|
|
|
static const TileIndexDiffC _town_coord_mod[] = {
|
|
|
{-1, 0},
|
|
@@ -1062,13 +1062,13 @@ int32 CmdBuildTown(int x, int y, uint32
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
Town *CreateRandomTown(uint attempts)
|
|
|
{
|
|
|
uint tile;
|
|
|
TileIndex tile;
|
|
|
TileInfo ti;
|
|
|
Town *t;
|
|
|
uint32 townnameparts;
|
|
|
|
|
|
do {
|
|
|
// Generate a tile index not too close from the edge
|
|
@@ -1118,13 +1118,14 @@ void GenerateTowns(void)
|
|
|
if (num == 0 && CreateRandomTown(10000) == NULL) {
|
|
|
//XXX can we handle that more gracefully?
|
|
|
error("Could not generate any town");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
|
|
|
static bool CheckBuildHouseMode(Town *t1, TileIndex tile, uint tileh, int mode)
|
|
|
{
|
|
|
int b;
|
|
|
uint slope;
|
|
|
|
|
|
static const byte _masks[8] = {
|
|
|
0xC,0x3,0x9,0x6,
|
|
|
0x3,0xC,0x6,0x9,
|
|
@@ -1140,13 +1141,13 @@ static bool CheckBuildHouseMode(Town *t1
|
|
|
if (b)
|
|
|
return false;
|
|
|
|
|
|
return DoCommandByTile(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR) != CMD_ERROR;
|
|
|
}
|
|
|
|
|
|
int GetTownRadiusGroup(Town *t, uint tile)
|
|
|
int GetTownRadiusGroup(Town *t, TileIndex tile)
|
|
|
{
|
|
|
uint dist;
|
|
|
int i,smallest;
|
|
|
|
|
|
dist = DistanceSquare(tile, t->xy);
|
|
|
if (t->fund_buildings_months && dist <= 25)
|
|
@@ -1158,13 +1159,13 @@ int GetTownRadiusGroup(Town *t, uint til
|
|
|
smallest = i;
|
|
|
}
|
|
|
|
|
|
return smallest;
|
|
|
}
|
|
|
|
|
|
static bool CheckFree2x2Area(Town *t1, uint tile)
|
|
|
static bool CheckFree2x2Area(Town *t1, TileIndex tile)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
static const TileIndexDiffC _tile_add[] = {
|
|
|
{0 , 0 },
|
|
|
{0 - 0, 1 - 0},
|
|
@@ -1182,13 +1183,13 @@ static bool CheckFree2x2Area(Town *t1, u
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
static void DoBuildTownHouse(Town *t, uint tile)
|
|
|
static void DoBuildTownHouse(Town *t, TileIndex tile)
|
|
|
{
|
|
|
int i;
|
|
|
uint bitmask;
|
|
|
int house;
|
|
|
uint slope;
|
|
|
uint z;
|
|
@@ -1355,13 +1356,13 @@ static void DoBuildTownHouse(Town *t, ui
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ENDING
|
|
|
}
|
|
|
|
|
|
static bool BuildTownHouse(Town *t, uint tile)
|
|
|
static bool BuildTownHouse(Town *t, TileIndex tile)
|
|
|
{
|
|
|
int32 r;
|
|
|
|
|
|
// make sure it's possible
|
|
|
if (!EnsureNoVehicle(tile)) return false;
|
|
|
if (GetTileSlope(tile, NULL) & 0x10) return false;
|
|
@@ -1371,20 +1372,21 @@ static bool BuildTownHouse(Town *t, uint
|
|
|
|
|
|
DoBuildTownHouse(t, tile);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
static void DoClearTownHouseHelper(uint tile)
|
|
|
static void DoClearTownHouseHelper(TileIndex tile)
|
|
|
{
|
|
|
assert(IsTileType(tile, MP_HOUSE));
|
|
|
DoClearSquare(tile);
|
|
|
DeleteAnimatedTile(tile);
|
|
|
}
|
|
|
|
|
|
static void ClearTownHouse(Town *t, uint tile) {
|
|
|
static void ClearTownHouse(Town *t, TileIndex tile)
|
|
|
{
|
|
|
uint house = _map3_hi[tile];
|
|
|
uint eflags;
|
|
|
|
|
|
assert(IsTileType(tile, MP_HOUSE));
|
|
|
|
|
|
// need to align the tile to point to the upper left corner of the house
|
|
@@ -1561,13 +1563,13 @@ static void TownActionRoadRebuild(Town *
|
|
|
SetDParam(2, p->name_2);
|
|
|
|
|
|
AddNewsItem(STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING,
|
|
|
NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_GENERAL, 0), t->xy, 0);
|
|
|
}
|
|
|
|
|
|
static bool DoBuildStatueOfCompany(uint tile)
|
|
|
static bool DoBuildStatueOfCompany(TileIndex tile)
|
|
|
{
|
|
|
TileInfo ti;
|
|
|
byte old;
|
|
|
int32 r;
|
|
|
|
|
|
FindLandscapeHeightByTile(&ti, tile);
|
|
@@ -1613,13 +1615,13 @@ static void TownActionBuildStatue(Town *
|
|
|
{ 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1}, { 0, 1},
|
|
|
{ 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0}, { 1, 0},
|
|
|
{ 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1}, { 0,-1},
|
|
|
{-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0},
|
|
|
{ 0, 0}
|
|
|
};
|
|
|
uint tile = t->xy;
|
|
|
TileIndex tile = t->xy;
|
|
|
const TileIndexDiffC *p;
|
|
|
|
|
|
SETBIT(t->statues, _current_player);
|
|
|
|
|
|
for (p = _statue_tiles; p != endof(_statue_tiles); ++p) {
|
|
|
if (DoBuildStatueOfCompany(tile))
|
|
@@ -1808,13 +1810,13 @@ static void UpdateTownUnwanted(Town *t)
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
if (t->unwanted[p->index] > 0)
|
|
|
t->unwanted[p->index]--;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool CheckIfAuthorityAllows(uint tile)
|
|
|
bool CheckIfAuthorityAllows(TileIndex tile)
|
|
|
{
|
|
|
Town *t;
|
|
|
|
|
|
if (_current_player >= MAX_PLAYERS)
|
|
|
return true;
|
|
|
|
|
@@ -1829,13 +1831,13 @@ bool CheckIfAuthorityAllows(uint tile)
|
|
|
SetDParam(0, t->index);
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
Town *ClosestTownFromTile(uint tile, uint threshold)
|
|
|
Town *ClosestTownFromTile(TileIndex tile, uint threshold)
|
|
|
{
|
|
|
Town *t;
|
|
|
uint dist, best = threshold;
|
|
|
Town *best_town = NULL;
|
|
|
|
|
|
// XXX - Fix this so for a given tiletype the owner of the type is in the same variable
|
|
@@ -1889,13 +1891,13 @@ static const int _default_rating_setting
|
|
|
// ROAD_REMOVE, TUNNELBRIDGE_REMOVE, INDUSTRY_REMOVE
|
|
|
{ 0, 128, 384}, // Permissive
|
|
|
{ 48, 192, 480}, // Neutral
|
|
|
{ 96, 384, 768}, // Hostile
|
|
|
};
|
|
|
|
|
|
bool CheckforTownRating(uint tile, uint32 flags, Town *t, byte type)
|
|
|
bool CheckforTownRating(TileIndex tile, uint32 flags, Town *t, byte type)
|
|
|
{
|
|
|
int modemod;
|
|
|
|
|
|
// if magic_bulldozer cheat is active, town doesn't restrict your destructive actions
|
|
|
if (t == NULL || _current_player >= MAX_PLAYERS || _cheats.magic_bulldozer.value)
|
|
|
return true;
|