summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--town_cmd.c69
-rw-r--r--town_map.h28
2 files changed, 37 insertions, 60 deletions
diff --git a/town_cmd.c b/town_cmd.c
index 694d93197..94ba74938 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1281,73 +1281,22 @@ static void DoBuildTownHouse(Town *t, TileIndex tile)
t->flags12 |= oneof;
{
- int m3lo,m5,eflags;
+ byte construction_counter = 0, construction_stage = 0, size_flags;
- // ENDING_2
- m3lo = 0;
- m5 = 0;
if (_generating_world) {
uint32 r = Random();
- // Value for map3lo
- m3lo = 0xC0;
- if (GB(r, 0, 8) >= 220) m3lo &= (r>>8);
+ construction_stage = 3; /* House is finished */
+ if (CHANCE16(1, 7)) construction_stage = GB(r, 0, 2);
- if (m3lo == 0xC0)
+ if (construction_stage == 3) {
ChangePopulation(t, _housetype_population[house]);
-
- // Initial value for map5.
- m5 = GB(r, 16, 6);
- }
-
- assert(IsTileType(tile, MP_CLEAR));
-
- ModifyTile(tile,
- MP_SETTYPE(MP_HOUSE) | MP_MAP3HI | MP_MAP3LO | MP_MAP2 | MP_MAP5 | MP_MAPOWNER,
- t->index,
- m3lo, /* map3_lo */
- house, /* map3_hi */
- 0, /* map_owner */
- m5 /* map5 */
- );
-
- eflags = _housetype_extra_flags[house];
-
- if (eflags&0x18) {
- assert(IsTileType(tile + TileDiffXY(0, 1), MP_CLEAR));
- ModifyTile(tile + TileDiffXY(0, 1),
- MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
- t->index,
- m3lo, /* map3_lo */
- ++house, /* map3_hi */
- 0, /* map_owner */
- m5 /* map5 */
- );
- }
-
- if (eflags&0x14) {
- assert(IsTileType(tile + TileDiffXY(1, 0), MP_CLEAR));
- ModifyTile(tile + TileDiffXY(1, 0),
- MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
- t->index,
- m3lo, /* map3_lo */
- ++house, /* map3_hi */
- 0, /* map_owner */
- m5 /* map5 */
- );
- }
-
- if (eflags&0x10) {
- assert(IsTileType(tile + TileDiffXY(1, 1), MP_CLEAR));
- ModifyTile(tile + TileDiffXY(1, 1),
- MP_SETTYPE(MP_HOUSE) | MP_MAP2 | MP_MAP3LO | MP_MAP3HI | MP_MAP5 | MP_MAPOWNER,
- t->index,
- m3lo, /* map3_lo */
- ++house, /* map3_hi */
- 0, /* map_owner */
- m5 /* map5 */
- );
+ } else {
+ construction_counter = GB(r, 2, 2);
+ }
}
+ size_flags = GB(_housetype_extra_flags[house], 2, 3);
+ MakeTownHouse(tile, t->index, construction_counter, construction_stage, size_flags, house);
}
// ENDING
diff --git a/town_map.h b/town_map.h
index 48d3ad94b..b673722bf 100644
--- a/town_map.h
+++ b/town_map.h
@@ -18,3 +18,31 @@ static inline Town* GetTownByTile(TileIndex t)
{
return GetTown(GetTownIndex(t));
}
+
+static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
+{
+ assert(IsTileType(t, MP_CLEAR));
+
+ SetTileType(t, MP_HOUSE);
+ _m[t].m1 = 0;
+ _m[t].m2 = tid;
+ SB(_m[t].m3, 6, 2, stage);
+ _m[t].m4 = type;
+ SB(_m[t].m5, 0, 2, counter);
+
+ MarkTileDirtyByTile(t);
+}
+
+enum {
+ TWO_BY_TWO_BIT = 2, ///< House is two tiles in X and Y directions
+ ONE_BY_TWO_BIT = 1, ///< House is two tiles in Y direction
+ TWO_BY_ONE_BIT = 0, ///< House is two tiles in X direction
+};
+
+static inline void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, byte size, byte type)
+{
+ MakeHouseTile(t, tid, counter, stage, type);
+ if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, ONE_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type);
+ if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, TWO_BY_ONE_BIT)) MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type);
+ if (HASBIT(size, TWO_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type);
+}