1
0
Fork 0

(svn r11934) -Codechange: add persistent random data for river and canal tiles.

release/0.6
peter1138 2008-01-20 18:30:53 +00:00
parent ffb9ca164e
commit 9ca929c812
5 changed files with 27 additions and 12 deletions

View File

@ -864,6 +864,11 @@
<td align=left>coast or riverbank</td> <td align=left>coast or riverbank</td>
</tr> </tr>
<tr>
<td noswap valign=top><tt>02</tt>&nbsp; </td>
<td align=left>river</td>
</tr>
<tr> <tr>
<td nowrap valign=top><tt>10</tt>..<tt>1B</tt>&nbsp; </td> <td nowrap valign=top><tt>10</tt>..<tt>1B</tt>&nbsp; </td>
<td align=left>canal locks <td align=left>canal locks
@ -945,7 +950,8 @@
</tr> </tr>
</table> </table>
</li> </li>
<li>m4: Owner of the water</li> <li>m4: Owner of the water when ship depot</li>
<li>m4: Random data for canal or river tiles</li>
<li>m6 bits 7..6 : Possibility of a bridge above, in the <a href="#bridge_direction">direction specified</a></li> <li>m6 bits 7..6 : Possibility of a bridge above, in the <a href="#bridge_direction">direction specified</a></li>
<li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li> <li>m6 bits 1..0 : <a href="#tropic_zone">Tropic zone definition</a></li>
</ul> </ul>

View File

@ -11,6 +11,7 @@
#include "newgrf_spritegroup.h" #include "newgrf_spritegroup.h"
#include "newgrf_canal.h" #include "newgrf_canal.h"
#include "tile_map.h" #include "tile_map.h"
#include "water_map.h"
/** Table of canal 'feature' sprite groups */ /** Table of canal 'feature' sprite groups */
@ -21,7 +22,7 @@ const SpriteGroup *_canal_sg[CF_END];
* three functions are stubs. */ * three functions are stubs. */
static uint32 CanalGetRandomBits(const ResolverObject *object) static uint32 CanalGetRandomBits(const ResolverObject *object)
{ {
return 0; return GetWaterTileRandomBits(object->u.canal.tile);
} }
@ -47,6 +48,9 @@ static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte
case 0x81: case 0x81:
return GetTerrainType(tile); return GetTerrainType(tile);
case 0x83:
return GetWaterTileRandomBits(tile);
} }
DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable); DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable);

View File

@ -1710,7 +1710,7 @@ bool AfterLoadGame()
if (GB(_m[t].m5, 3, 2) == 0) { if (GB(_m[t].m5, 3, 2) == 0) {
MakeClear(t, CLEAR_GRASS, 3); MakeClear(t, CLEAR_GRASS, 3);
} else { } else {
MakeCanal(t, (GetTileOwner(t) == OWNER_WATER) ? OWNER_NONE : GetTileOwner(t)); MakeCanal(t, (GetTileOwner(t) == OWNER_WATER) ? OWNER_NONE : GetTileOwner(t), Random());
} }
} }
SetBridgeMiddle(t, axis); SetBridgeMiddle(t, axis);

View File

@ -56,7 +56,7 @@ void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
/* Non-sealevel -> canal */ /* Non-sealevel -> canal */
if (TileHeight(t) != 0) { if (TileHeight(t) != 0) {
MakeCanal(t, o); MakeCanal(t, o, Random());
return; return;
} }
@ -71,7 +71,7 @@ void MakeWaterOrCanalDependingOnSurroundings(TileIndex t, Owner o)
} }
} }
if (has_canal || !has_water) { if (has_canal || !has_water) {
MakeCanal(t, o); MakeCanal(t, o, Random());
} else { } else {
MakeWater(t); MakeWater(t);
} }
@ -128,7 +128,7 @@ void MakeWaterOrCanalDependingOnOwner(TileIndex tile, Owner o)
if (o == OWNER_WATER) { if (o == OWNER_WATER) {
MakeWater(tile); MakeWater(tile);
} else { } else {
MakeCanal(tile, o); MakeCanal(tile, o, Random());
} }
} }
@ -305,9 +305,9 @@ CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (TileHeight(tile) == 0 && p2 == 1) { if (TileHeight(tile) == 0 && p2 == 1) {
MakeWater(tile); MakeWater(tile);
} else if (p2 == 2) { } else if (p2 == 2) {
MakeRiver(tile); MakeRiver(tile, Random());
} else { } else {
MakeCanal(tile, _current_player); MakeCanal(tile, _current_player, Random());
} }
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
MarkTilesAroundDirty(tile); MarkTilesAroundDirty(tile);

View File

@ -108,6 +108,11 @@ static inline byte GetSection(TileIndex t)
return GB(_m[t].m5, 0, 4); return GB(_m[t].m5, 0, 4);
} }
static inline byte GetWaterTileRandomBits(TileIndex t)
{
return _m[t].m4;
}
static inline void MakeWater(TileIndex t) static inline void MakeWater(TileIndex t)
{ {
@ -129,24 +134,24 @@ static inline void MakeShore(TileIndex t)
_m[t].m5 = 1; _m[t].m5 = 1;
} }
static inline void MakeRiver(TileIndex t) static inline void MakeRiver(TileIndex t, uint8 random_bits)
{ {
SetTileType(t, MP_WATER); SetTileType(t, MP_WATER);
SetTileOwner(t, OWNER_WATER); SetTileOwner(t, OWNER_WATER);
_m[t].m2 = 0; _m[t].m2 = 0;
_m[t].m3 = 0; _m[t].m3 = 0;
_m[t].m4 = 0; _m[t].m4 = random_bits;
_m[t].m5 = 2; _m[t].m5 = 2;
} }
static inline void MakeCanal(TileIndex t, Owner o) static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
{ {
assert(o != OWNER_WATER); assert(o != OWNER_WATER);
SetTileType(t, MP_WATER); SetTileType(t, MP_WATER);
SetTileOwner(t, o); SetTileOwner(t, o);
_m[t].m2 = 0; _m[t].m2 = 0;
_m[t].m3 = 0; _m[t].m3 = 0;
_m[t].m4 = 0; _m[t].m4 = random_bits;
_m[t].m5 = 0; _m[t].m5 = 0;
} }