Index: rail.h
===================================================================
--- rail.h (revision 3272)
+++ rail.h (working copy)
@@ -550,6 +550,34 @@
}
/**
+ * Returns the owner of the road on the level crossing located on the tile
+ */
+static inline Owner GetLevelCrossingRoadOwner(TileIndex tile){
+ return _m[tile].m3;
+}
+
+/**
+ * Returns the owner of the rails on the level crossing on the tile
+ */
+static inline Owner GetLevelCrossingRailOwner(TileIndex tile){
+ return _m[tile].m1;
+}
+
+/**
+ * Sets the owner of the road on the level crossing located on the tile
+ */
+static inline void SetLevelCrossingRoadOwner(TileIndex tile, Owner owner){
+ _m[tile].m3 = owner;
+}
+
+/**
+ * Sets the owner of the rails on the level crossing on the tile
+ */
+static inline void SetLevelCrossingRailOwner(TileIndex tile, Owner owner){
+ _m[tile].m1 = owner;
+}
+
+/**
* Gets the transport type of the given track on the given crossing tile.
* @return The transport type of the given track, either TRANSPORT_ROAD,
* TRANSPORT_RAIL.
Index: docs/landscape.html
===================================================================
--- docs/landscape.html (revision 3272)
+++ docs/landscape.html (working copy)
@@ -175,9 +175,9 @@
m5 bit 3: clear - road in the X direction, set - road in the Y direction (railway track always perpendicular)
m5 bit 2: set if crossing lights are on
m5 bit 0: set if rail track is reserved by pbs
-m1: owner of the railway track
+m1: owner of the railway track (Get|Set)LevelCrossingRailOwner()
m2: Index into the array of towns, 0 for non-town roads
-m3 bits 0..7: owner of the road
+m3 bits 0..7: owner of the road (Get|Set)LevelCrossingRoadOwner()
m4 bits 3..0: track type
m4 bits 4..6: 0 - on bare land, 1 - on grass, 2 or higher - paved
m4 bit 7 set = on snow or desert
@@ -288,8 +288,8 @@
m5 bits 2..0: construction counter, for buildings under construction incremented on every periodic tile processing, on wraparound the stage of construction in m3 is increased
for large office blocks (types 04 and 05):
-- m1 bits 6..0: position of the lift
-- m1 bit 7: if set the lift is moving
+- m1 bits 6..0: position of the lift (Get|Set)HouseLiftPosition()
+- m1 bit 7: if set the lift is moving (Is|Set)HouseLiftMoving()
- m5 bit 7: if set then m5 bits 5..0 hold the final position of the lift divided by 6 (valid values 0..6 except 1)
@@ -442,19 +442,19 @@
8 |
Industry tile
-- m5: type:
+
- m5: type: (Get|Set)TileIndustryType()
(note: this is not the same as the industry type stored in the array of industries)
00..06 | coal mine
00 | wheel tower when not animated |
-01 | wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated |
+01 | wheel tower when animated; animation state in m1 bits 5..0 (Get|Set)MineAnimationState(); m1 bit 6 set = sound already generated (Get|Set)MiningMachinerySoundPlayed() |
|
07..0A | power station
08 | chimney |
-0A | transformer; animation progress in m1 bits 5..2 (valid range 0..7) |
+0A | transformer; animation progress in m1 bits 5..2 (valid range 0..7) (Get|Set)PowerStationSparklesAnimationState() |
|
0B..0F | sawmill |
@@ -468,7 +468,7 @@
1D..20 | oil wells
1D | not animated |
-1E..20 | various stages of animation; progress of animation in m1 bits 1..0 |
+1E..20 | various stages of animation; progress of animation in m1 bits 1..0 (Get|Set)OilWellsAnimationState() |
|
21..26 | farm |
@@ -477,7 +477,7 @@
2F..33 | copper ore mine
2F | wheel tower when not animated |
-30 | wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated |
+30 | wheel tower when animated; animation state in m1 bits 5..0 (Get|Set)MineAnimationState(); m1 bit 6 set = sound already generated (Get|Set)MiningMachinerySoundPlayed() |
31 | chimney |
|
@@ -488,7 +488,7 @@
48..58 | gold mine
4F | wheel tower when not animated |
-58 | wheel tower when animated; animation state in m1 bits 5..0; m1 bit 6 set = sound already generated |
+58 | wheel tower when animated; animation state in m1 bits 5..0 (Get|Set)MineAnimationState(); m1 bit 6 set = sound already generated (Get|Set)MiningMachinerySoundPlayed() |
|
59..5A | bank (sub-arctic or sub-tropical climate) |
@@ -540,15 +540,16 @@
|
-- m2: index into the array of industries
+
- m2: index into the array of industries GetIndustryIndexByTile()
-- m1 bit 7: clear = under construction
+
- m1 bit 7: clear = under construction (Is|Set)IndustryTileUnderConstruction()
-- m1 bits 4..2: construction counter, for buildings under construction incremented on every periodic tile processing
+
- m1 bits 3..2: construction counter, for buildings under construction incremented on every periodic tile processing (Get|Set)IndustryTileConstructionCounter()
- m1 bits 1..0: stage of construction (3 = completed), incremented when the construction counter wraps around
the meaning is different for some animated tiles which are never under construction (types 01, 1E..20, 30, 58; see above)
+(Get|Set)IndustryTileConstructionStage()
|
Index: openttd.c
===================================================================
--- openttd.c (revision 3272)
+++ openttd.c (working copy)
@@ -1057,12 +1057,21 @@
TileIndex tile;
for (tile = 0; tile != MapSize(); tile++) {
+
if (IsTileType(tile, MP_STREET)) {
- if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80) _m[tile].m3 = OWNER_TOWN;
- if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
+ if (IsLevelCrossing(tile) && GetLevelCrossingRoadOwner(tile) & 0x80){
+ SetLevelCrossingRoadOwner(tile, OWNER_TOWN);
+ }
+
+ if (GetTileOwner(tile) & 0x80){
+ SetTileOwner(tile, OWNER_TOWN);
+ }
+
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN);
+ if (GetTileOwner(tile) & 0x80){
+ SetTileOwner(tile, OWNER_TOWN);
+ }
}
}
}
Index: industry_cmd.c
===================================================================
--- industry_cmd.c (revision 3272)
+++ industry_cmd.c (working copy)
@@ -255,13 +255,144 @@
STR_4832_ANNOUNCES_IMMINENT_CLOSURE
};
+// =============== Industry tile map accessors =====================
+/**
+ * I'm not quite sure what this function does. for some reason it sets bit 4
+ * which is never used elsewhere in industry_cmd.c and thus does not quite fit
+ * into the model..... So just leave it be
+ */
+static inline void SetInitialIndutryTileConstructionState(TileIndex tile){
+ _m[tile].m1 = 0x1E;
+}
+
+/**
+ * Returns the industry construction stage of the specified tile
+ */
+static inline byte GetIndustryTileConstructionStage(TileIndex tile){
+ return GB(_m[tile].m1, 0, 2);
+}
+
+/**
+ * Sets the industry construction stage of the specified tile
+ */
+static inline void SetIndustryTileConstructionStage(TileIndex tile, byte value){
+ SB(_m[tile].m1, 0, 2, value);
+}
+
+/**
+ * Checks if the industry that owns the tile is under constructions
+ */
+static inline bool IsIndustryTileUnderConstruction(TileIndex tile){
+ return _m[tile].m1 & 0x80;
+}
+
+/**
+ * Set if the industry that owns the tile as under construction or not
+ */
+static inline void SetIndustryTileUnderConstruction(TileIndex tile, bool underconstruction){
+ if(underconstruction){
+ SB(_m[tile].m1, 7, 1, 0);
+ }else{
+ SB(_m[tile].m1, 7, 1, 1);
+ }
+}
+
+/**
+ * Returns the state of thae power stations transformer spakles animation
+ */
+static inline uint16 GetPowerStationSparklesAnimationState(TileIndex tile){
+ return GB(_m[tile].m1, 2, 5);
+}
+
+/**
+ * Sets the state of thae power stations transformer spakles animation
+ */
+static inline void SetPowerStationSparklesAnimationState(TileIndex tile, uint16 state){
+ SB(_m[tile].m1, 2, 5, state);
+}
+
+/**
+ * Returns this indutry tile's construction counter value
+ */
+static inline byte GetIndustryTileConstructionCounter(TileIndex tile){
+ return GB(_m[tile].m1, 2, 2);
+}
+
+/**
+ * Sets this indutry tile's construction counter value
+ */
+static inline void SetIndustryTileConstructionCounter(TileIndex tile, byte value){
+ SB(_m[tile].m1, 2, 2, value);
+}
+
+/**
+ * Returns the state of this oil wells's animation
+ */
+static inline uint16 GetOilWellsAnimationState(TileIndex tile){
+ return GB(_m[tile].m1, 0, 2);
+}
+
+/**
+ * Sets the state of this oil wells's animation
+ */
+static inline void SetOilWellsAnimationState(TileIndex tile, byte state){
+ SB(_m[tile].m1, 0, 2, state);
+}
+
+/**
+ * Returns the industry type of the tile
+ */
+static inline byte GetTileIndustryType(TileIndex tile){
+ return _m[tile].m5;
+}
+
+/**
+ * Sets the industry type of the tile
+ */
+static inline void SetTileIndustryType(TileIndex tile, byte type){
+ _m[tile].m5 = type;
+}
+
+/**
+ * Sets the mining machinery sound played flag
+ */
+static inline void SetMiningMachinerySoundPlayed(TileIndex tile, bool played){
+ if(played){
+ SB(_m[tile].m1, 6, 1, 1);
+ }else{
+ SB(_m[tile].m1, 6, 1, 0);
+ }
+}
+
+/**
+ * Returns the mining machinery sound played flag
+ */
+static inline bool GetMiningMachinerySoundPlayed(TileIndex tile){
+ return GB(_m[tile].m1, 6, 1) == 1;
+}
+
+/**
+ * Sets the mine animation state of the tile
+ */
+static inline void SetMineAnimationState(TileIndex tile, byte state){
+ SB(_m[tile].m1, 0, 6, state);
+}
+
+/**
+ * Returns the mine animation state of the tile
+ */
+static inline byte GetMineAnimationState(TileIndex tile){
+ return GB(_m[tile].m1, 0, 6);
+}
+// =========== end of Industry tile map accessors ==================
+
static void IndustryDrawTileProc1(const TileInfo *ti)
{
const DrawIndustrySpec1Struct *d;
uint32 image;
- if (!(_m[ti->tile].m1 & 0x80)) return;
+ if (IsIndustryTileUnderConstruction(ti->tile)) return;
d = &_draw_industry_spec1[_m[ti->tile].m3];
@@ -281,7 +412,7 @@
{
int x = 0;
- if (_m[ti->tile].m1 & 0x80) {
+ if (!IsIndustryTileUnderConstruction(ti->tile)) {
x = _industry_anim_offs[_m[ti->tile].m3];
if ( (byte)x == 0xFF)
x = 0;
@@ -293,7 +424,7 @@
static void IndustryDrawTileProc3(const TileInfo *ti)
{
- if (_m[ti->tile].m1 & 0x80) {
+ if (!IsIndustryTileUnderConstruction(ti->tile)) {
AddChildSpriteScreen(0x128B, 5, _industry_anim_offs_2[_m[ti->tile].m3]);
} else {
AddChildSpriteScreen(4746, 3, 67);
@@ -320,9 +451,8 @@
static void DrawCoalPlantSparkles(const TileInfo *ti)
{
- int image = _m[ti->tile].m1;
- if (image & 0x80) {
- image = GB(image, 2, 5);
+ if (!IsIndustryTileUnderConstruction(ti->tile)) {
+ int image = GetPowerStationSparklesAnimationState(ti->tile);
if (image != 0 && image < 7) {
AddChildSpriteScreen(image + 0x806,
_coal_plant_sparkles_x[image - 1],
@@ -353,7 +483,7 @@
ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START;
/* Retrieve pointer to the draw industry tile struct */
- dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)];
+ dits = &_industry_draw_tile_data[(ti->map5 << 2) | GetIndustryTileConstructionStage(ti->tile)];
image = dits->sprite_1;
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
@@ -427,7 +557,7 @@
td->owner = i->owner;
td->str = STR_4802_COAL_MINE + i->type;
- if ((_m[tile].m1 & 0x80) == 0) {
+ if (IsIndustryTileUnderConstruction(tile)) {
SetDParamX(td->dparam, 0, td->str);
td->str = STR_2058_UNDER_CONSTRUCTION;
}
@@ -481,7 +611,7 @@
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
i->last_mo_transported[0] += am;
if (am != 0 && (m5 = _industry_produce_map5[_m[tile].m5]) != 0xFF) {
- _m[tile].m1 = 0x80;
+ SetIndustryTileUnderConstruction(tile, false);
_m[tile].m5 = m5;
MarkTileDirtyByTile(tile);
}
@@ -503,119 +633,129 @@
static void AnimateTile_Industry(TileIndex tile)
{
- byte m,n;
+ byte state, tileType;
- switch(_m[tile].m5) {
- case 174:
+ switch(GetTileIndustryType(tile)) {
+ case 174: // Sugar Mine
if ((_tick_counter & 1) == 0) {
- m = _m[tile].m3 + 1;
+ state = _m[tile].m3 + 1;
- switch(m & 7) {
+ switch(state & 7) {
case 2: SndPlayTileFx(SND_2D_RIP_2, tile); break;
case 6: SndPlayTileFx(SND_29_RIP, tile); break;
}
- if (m >= 96) {
- m = 0;
+ if (state >= 96) {
+ state = 0;
DeleteAnimatedTile(tile);
}
- _m[tile].m3 = m;
+ _m[tile].m3 = state;
MarkTileDirtyByTile(tile);
}
break;
- case 165:
+ case 165: // Tofee Quary
if ((_tick_counter & 3) == 0) {
- m = _m[tile].m3;
+ state = _m[tile].m3;
- if (_industry_anim_offs[m] == 0xFF) {
+ if (_industry_anim_offs[state] == 0xFF) {
SndPlayTileFx(SND_30_CARTOON_SOUND, tile);
}
- if (++m >= 70) {
- m = 0;
+ if (++state >= 70) {
+ state = 0;
DeleteAnimatedTile(tile);
}
- _m[tile].m3 = m;
+ _m[tile].m3 = state;
MarkTileDirtyByTile(tile);
}
break;
- case 162:
+ case 162: // bubble generator
if ((_tick_counter&1) == 0) {
- m = _m[tile].m3;
+ state = _m[tile].m3;
- if (++m >= 40) {
- m = 0;
+ if (++state >= 40) {
+ state = 0;
DeleteAnimatedTile(tile);
}
- _m[tile].m3 = m;
+ _m[tile].m3 = state;
MarkTileDirtyByTile(tile);
}
break;
- // Sparks on a coal plant
- case 10:
+ case 10: // power station transformer sparks animation
if ((_tick_counter & 3) == 0) {
- m = _m[tile].m1;
- if (GB(m, 2, 5) == 6) {
- SB(_m[tile].m1, 2, 5, 0);
+ state = GetPowerStationSparklesAnimationState(tile);
+ if (state == 6) { //
+ SetPowerStationSparklesAnimationState(tile, 0);
DeleteAnimatedTile(tile);
} else {
- _m[tile].m1 = m + (1<<2);
+ SetPowerStationSparklesAnimationState(tile, state + 1);
MarkTileDirtyByTile(tile);
}
}
break;
- case 143:
+ case 143: // toy factory
if ((_tick_counter & 1) == 0) {
- m = _m[tile].m3 + 1;
+ state = _m[tile].m3 + 1;
- if (m == 1) {
+ if (state == 1) {
SndPlayTileFx(SND_2C_MACHINERY, tile);
- } else if (m == 23) {
+ } else if (state == 23) {
SndPlayTileFx(SND_2B_COMEDY_HIT, tile);
- } else if (m == 28) {
+ } else if (state == 28) {
SndPlayTileFx(SND_2A_EXTRACT_AND_POP, tile);
}
- if (m >= 50 && (m=0,++_m[tile].m4 >= 8)) {
+ if (state >= 50 && (state=0,++_m[tile].m4 >= 8)) {
_m[tile].m4 = 0;
DeleteAnimatedTile(tile);
}
- _m[tile].m3 = m;
+ _m[tile].m3 = state;
MarkTileDirtyByTile(tile);
}
break;
case 148: case 149: case 150: case 151:
- case 152: case 153: case 154: case 155:
+ case 152: case 153: case 154: case 155: // plastic fountains
if ((_tick_counter & 3) == 0) {
- m = _m[tile].m5 + 1;
- if (m == 155+1) m = 148;
- _m[tile].m5 = m;
+ state = _m[tile].m5 + 1;
+ if (state == 155+1) state = 148;
+ _m[tile].m5 = state;
MarkTileDirtyByTile(tile);
}
break;
- case 30: case 31: case 32:
+ case 30: case 31: case 32: // oil wells
if ((_tick_counter & 7) == 0) {
bool b = CHANCE16(1,7);
- m = _m[tile].m1;
- m = (m & 3) + 1;
- n = _m[tile].m5;
- if (m == 4 && (m=0,++n) == 32+1 && (n=30,b)) {
- _m[tile].m1 = 0x83;
- _m[tile].m5 = 29;
- DeleteAnimatedTile(tile);
- } else {
- SB(_m[tile].m1, 0, 2, m);
- _m[tile].m5 = n;
+ bool wrapAnimation = false;
+ state = GetOilWellsAnimationState(tile);
+ state ++;
+ tileType = GetTileIndustryType(tile);
+
+ if(state == 4){
+ state = 0;
+ tileType ++;
+ if(tileType == 32 + 1){ // animation is wrapping
+ tileType = 30;
+ if(b){
+ wrapAnimation = true;
+ SetOilWellsAnimationState(tile, 3);
+ SetTileIndustryType(tile, 29);
+ DeleteAnimatedTile(tile);
+ }
+ }
+ }
+ if(!wrapAnimation){
+ SetOilWellsAnimationState(tile, state);
+ SetTileIndustryType(tile, tileType);
MarkTileDirtyByTile(tile);
}
}
@@ -623,7 +763,7 @@
case 88:
case 48:
- case 1: {
+ case 1: { // animated wheel tower for coal, gold and copper ore mines
int state = _tick_counter & 0x7FF;
if ((state -= 0x400) < 0)
@@ -631,8 +771,8 @@
if (state < 0x1A0) {
if (state < 0x20 || state >= 0x180) {
- if (!(_m[tile].m1 & 0x40)) {
- _m[tile].m1 |= 0x40;
+ if (!GetMiningMachinerySoundPlayed(tile)) {
+ SetMiningMachinerySoundPlayed(tile, true);
SndPlayTileFx(SND_0B_MINING_MACHINERY, tile);
}
if (state & 7)
@@ -641,19 +781,29 @@
if (state & 3)
return;
}
- m = (_m[tile].m1 + 1) | 0x40;
- if (m > 0xC2) m = 0xC0;
- _m[tile].m1 = m;
+
+ state = GetMineAnimationState(tile) + 1;
+ if(state > 2){
+ state = 0;
+ }
+ SetMineAnimationState(tile, state);
+ SetMiningMachinerySoundPlayed(tile, true);
MarkTileDirtyByTile(tile);
+
} else if (state >= 0x200 && state < 0x3A0) {
int i;
i = (state < 0x220 || state >= 0x380) ? 7 : 3;
if (state & i)
return;
- m = (_m[tile].m1 & 0xBF) - 1;
- if (m < 0x80) m = 0x82;
- _m[tile].m1 = m;
+ SetMiningMachinerySoundPlayed(tile, false);
+ state = GetMineAnimationState(tile);
+ if(state == 0){
+ state = 2;
+ }else{
+ state --;
+ }
+ SetMineAnimationState(tile, state);
MarkTileDirtyByTile(tile);
}
} break;
@@ -667,22 +817,32 @@
CreateEffectVehicle(ti.x + 15, ti.y + 14, ti.z + 59 + (ti.tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE);
}
-static void MakeIndustryTileBigger(TileIndex tile, byte size)
+/**
+ * This function
+ */
+static void MakeIndustryTileBigger(TileIndex tile)
{
- byte b = (byte)((size + (1<<2)) & (3<<2));
+ byte stage = GetIndustryTileConstructionStage(tile);
+ byte counter = GetIndustryTileConstructionCounter(tile);
+ counter ++;
- if (b != 0) {
- _m[tile].m1 = b | (size & 3);
+ if(counter > 3){
+ SetIndustryTileConstructionCounter(tile, counter);
return;
}
+ // the construction counter passed the max, so set it to 0
+ SetIndustryTileConstructionCounter(tile, 0);
- size = (size + 1) & 3;
- if (size == 3) size |= 0x80;
- _m[tile].m1 = size | b;
+ stage ++;
+ if(stage == 3){
+ SetIndustryTileUnderConstruction(tile, false);
+ }else{
+ SetIndustryTileConstructionStage(tile, stage);
+ }
MarkTileDirtyByTile(tile);
- if (!(_m[tile].m1 & 0x80))
+ if (IsIndustryTileUnderConstruction(tile))
return;
switch(_m[tile].m5) {
@@ -737,8 +897,8 @@
{
byte n;
- if (!(_m[tile].m1 & 0x80)) {
- MakeIndustryTileBigger(tile, _m[tile].m1);
+ if (IsIndustryTileUnderConstruction(tile)) {
+ MakeIndustryTileBigger(tile);
return;
}
@@ -748,15 +908,16 @@
n = _industry_map5_animation_next[_m[tile].m5];
if (n != 255) {
- _m[tile].m1 = 0;
+ // set the industry tile to be at the very beginning of the construction progress
+ SetIndustryTileUnderConstruction(tile, true);
+ SetIndustryTileConstructionStage(tile, 0);
+ SetIndustryTileConstructionCounter(tile, 0);
+
_m[tile].m5 = n;
MarkTileDirtyByTile(tile);
return;
}
-#define SET_AND_ANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; AddAnimatedTile(tile); }
-#define SET_AND_UNANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; DeleteAnimatedTile(tile); }
-
switch (_m[tile].m5) {
case 0x18: // coast line at oilrigs
case 0x19:
@@ -766,42 +927,91 @@
TileLoop_Water(tile);
break;
- case 0:
- if (!(_tick_counter & 0x400) && CHANCE16(1,2))
- SET_AND_ANIMATE(tile,1,0x80);
+ case 0: // non animated coal mine wheel tower
+ if (!(_tick_counter & 0x400) && CHANCE16(1,2)){
+ _m[tile].m5 = 1;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetIndustryTileConstructionStage(tile, 0);
+ SetIndustryTileConstructionCounter(tile, 0);
+
+ AddAnimatedTile(tile);
+ }
break;
- case 47:
- if (!(_tick_counter & 0x400) && CHANCE16(1,2))
- SET_AND_ANIMATE(tile,0x30,0x80);
+ case 47: // non animated copper mine wheel tower
+ if (!(_tick_counter & 0x400) && CHANCE16(1,2)){
+ _m[tile].m5 = 0x30;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetIndustryTileConstructionStage(tile, 0);
+ SetIndustryTileConstructionCounter(tile, 0);
+
+ AddAnimatedTile(tile);
+ }
break;
- case 79:
- if (!(_tick_counter & 0x400) && CHANCE16(1,2))
- SET_AND_ANIMATE(tile,0x58,0x80);
+ case 79: // non animated gold mine wheel tower
+ if (!(_tick_counter & 0x400) && CHANCE16(1,2)){
+ _m[tile].m5 = 0x58;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetIndustryTileConstructionStage(tile, 0);
+ SetIndustryTileConstructionCounter(tile, 0);
+
+ AddAnimatedTile(tile);
+ }
break;
- case 29:
- if (CHANCE16(1,6))
- SET_AND_ANIMATE(tile,0x1E,0x80);
+ case 29: // non animated oil wells
+ if (CHANCE16(1,6)){
+ _m[tile].m5 = 0x1E;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetIndustryTileConstructionStage(tile, 0);
+ SetIndustryTileConstructionCounter(tile, 0);
+
+ AddAnimatedTile(tile);
+ }
break;
- case 1:
- if (!(_tick_counter & 0x400))
- SET_AND_UNANIMATE(tile, 0, 0x83);
+ case 1: // animated coal mine wheel tower
+ if (!(_tick_counter & 0x400)){
+ _m[tile].m5 = 0;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetMiningMachinerySoundPlayed(tile, false);
+ SetMineAnimationState(tile, 3);
+
+ DeleteAnimatedTile(tile);
+ }
break;
- case 48:
- if (!(_tick_counter & 0x400))
- SET_AND_UNANIMATE(tile, 0x2F, 0x83);
+ case 48: // animated coper mine wheel tower
+ if (!(_tick_counter & 0x400)){
+ _m[tile].m5 = 0x2F;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetMiningMachinerySoundPlayed(tile, false);
+ SetMineAnimationState(tile, 3);
+
+ DeleteAnimatedTile(tile);
+ }
break;
- case 88:
- if (!(_tick_counter & 0x400))
- SET_AND_UNANIMATE(tile, 0x4F, 0x83);
+ case 88: // animated gold mine wheel tower
+ if (!(_tick_counter & 0x400)){
+ _m[tile].m5 = 0x4F;
+
+ SetIndustryTileUnderConstruction(tile, false);
+ SetMiningMachinerySoundPlayed(tile, false);
+ SetMineAnimationState(tile, 3);
+
+ DeleteAnimatedTile(tile);
+ }
break;
- case 10:
+ case 10: // power plant transformer
if (CHANCE16(1,3)) {
SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
AddAnimatedTile(tile);
@@ -1019,7 +1229,7 @@
TileIndex tile = i->xy;
int a;
- if ((_m[tile].m1 & 0x80) == 0) return;
+ if (IsIndustryTileUnderConstruction(tile)) return;
/* search outwards as a rectangular spiral */
for (a = 1; a != 41; a += 2) {
@@ -1485,7 +1695,11 @@
SetTileType(cur_tile, MP_INDUSTRY);
_m[cur_tile].m5 = it->map5;
_m[cur_tile].m2 = i->index;
- _m[cur_tile].m1 = _generating_world ? 0x1E : 0; /* maturity */
+ if(_generating_world){
+ SetInitialIndutryTileConstructionState(cur_tile);
+ }else{
+ ResetIndustryTileConstructionProgress(cur_tile);
+ }
}
} while ((++it)->ti.x != -0x80);
Index: landscape.c
===================================================================
--- landscape.c (revision 3272)
+++ landscape.c (working copy)
@@ -382,7 +382,7 @@
if (flags & (MP_MAPOWNER|MP_MAPOWNER_CURRENT)) {
PlayerID x = _current_player;
if (flags & MP_MAPOWNER) x = va_arg(va, int);
- _m[tile].m1 = x;
+ SetTileOwner(tile, x);
}
if (flags & MP_MAP5) {
@@ -436,7 +436,7 @@
map_size = MapSize();
for (i = 0; i < map_size; i++) {
_m[i].type_height = MP_CLEAR << 4;
- _m[i].m1 = OWNER_NONE;
+ SetTileOwner(i,OWNER_NONE);
_m[i].m2 = 0;
_m[i].m3 = 0;
_m[i].m4 = 0;
Index: misc.c
===================================================================
--- misc.c (revision 3272)
+++ misc.c (working copy)
@@ -776,28 +776,32 @@
static void Load_MAP1(void)
{
uint size = MapSize();
- uint i;
+ TileIndex t;
- for (i = 0; i != size;) {
+ for (t = 0; t != size;) {
byte buf[4096];
uint j;
SlArray(buf, lengthof(buf), SLE_UINT8);
- for (j = 0; j != lengthof(buf); j++) _m[i++].m1 = buf[j];
+ for (j = 0; j != lengthof(buf); j++){
+ SetTileOwner(t++, buf[j]);
+ }
}
}
static void Save_MAP1(void)
{
uint size = MapSize();
- uint i;
+ TileIndex tile;
SlSetLength(size);
- for (i = 0; i != size;) {
+ for (tile = 0; tile != size;) {
byte buf[4096];
uint j;
- for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m1;
+ for (j = 0; j != lengthof(buf); j++){
+ buf[j] = GetTileOwner(tile++);
+ }
SlArray(buf, lengthof(buf), SLE_UINT8);
}
}
Index: town_cmd.c
===================================================================
--- town_cmd.c (revision 3272)
+++ town_cmd.c (working copy)
@@ -75,10 +75,41 @@
#include "table/town_land.h"
+/**
+ * Returns the position of the house lift
+ */
+static inline byte GetHouseLiftPosition(TileIndex tile){
+ return GB(_m[tile].m1, 0, 7);
+}
+/**
+ * Sets the position of the house lift
+ */
+static inline void SetHouseLiftPosition(TileIndex tile, byte position){
+ SB(_m[tile].m1, 0, 7, position);
+}
+
+/**
+ * Checks if the house's lift is moving
+ */
+static inline bool IsHouseLiftMoving(TileIndex tile){
+ return GB(_m[tile].m1,7,1) == 1;
+}
+
+/**
+ * Sets if the house's lift is moving
+ */
+static inline void SetHouseLiftMoving(TileIndex tile, bool moving){
+ if(moving){
+ SB(_m[tile].m1, 7, 1, 1);
+ }else{
+ SB(_m[tile].m1, 7, 1, 0);
+ }
+}
+
static void TownDrawHouseLift(const TileInfo *ti)
{
- AddChildSpriteScreen(0x5A3, 0xE, 0x3C - GB(_m[ti->tile].m1, 0, 7));
+ AddChildSpriteScreen(0x5A3, 0xE, 0x3C - GetHouseLiftPosition(ti->tile));
}
typedef void TownDrawTileProc(const TileInfo *ti);
@@ -156,8 +187,7 @@
static void AnimateTile_Town(TileIndex tile)
{
- int old;
- int a,b;
+ int liftPos,b;
if (_tick_counter & 3) return;
@@ -170,11 +200,11 @@
return;
}
- if (!((old = _m[tile].m1) & 0x80)) {
+ if (!IsHouseLiftMoving(tile)) {
int i;
+ int old = GetHouseLiftPosition(tile);
+ SetHouseLiftMoving(tile, true);
- _m[tile].m1 |= 0x80;
-
do {
i = (Random() & 7) - 1;
} while (i < 0 || i == 1 || i * 6 == old);
@@ -182,13 +212,13 @@
SB(_m[tile].m5, 0, 6, i);
}
- a = GB(_m[tile].m1, 0, 7);
+ liftPos = GetHouseLiftPosition(tile);
b = GB(_m[tile].m5, 0, 6) * 6;
- a += (a < b) ? 1 : -1;
- SB(_m[tile].m1, 0, 7, a);
+ liftPos += (liftPos < b) ? 1 : -1;
+ SetHouseLiftPosition(tile, liftPos);
- if (a == b) {
- _m[tile].m1 &= 0x7F;
+ if (liftPos == b) {
+ SetHouseLiftMoving(tile, false);
_m[tile].m5 &= 0x40;
DeleteAnimatedTile(tile);
}
Index: disaster_cmd.c
===================================================================
--- disaster_cmd.c (revision 3272)
+++ disaster_cmd.c (working copy)
@@ -337,8 +337,8 @@
TileIndex tile;
for (tile = 0; tile != MapSize(); tile++) {
- if (IsTileType(tile, MP_INDUSTRY) && _m[tile].m2 == i->index) {
- _m[tile].m1 = 0;
+ if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndexByTile(tile) == i->index) {
+ ResetIndustryTileConstructionProgress(tile);
MarkTileDirtyByTile(tile);
}
}
Index: tile.h
===================================================================
--- tile.h (revision 3272)
+++ tile.h (working copy)
@@ -122,6 +122,20 @@
_m[tile].m1 = owner;
}
+/**
+ * TODO: code this function using other accessor functions and add a meaningful comment
+ */
+static inline void ResetIndustryTileConstructionProgress(TileIndex tile){
+ _m[tile].m1 = 0;
+}
+
+/**
+ * Return the index of the industry (in the industry pool) to which the tile belongs
+ */
+static inline uint16 GetIndustryIndexByTile(TileIndex tile){
+ return _m[tile].m2;
+}
+
static inline bool IsTileOwner(TileIndex tile, Owner owner)
{
return GetTileOwner(tile) == owner;