2004-12-15 22:18:54 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ttd.h"
|
|
|
|
#include "map.h"
|
|
|
|
|
2005-01-07 17:40:23 +00:00
|
|
|
#define TILE_X_BITS 8
|
|
|
|
#define TILE_Y_BITS 8
|
|
|
|
|
2004-12-16 12:30:13 +00:00
|
|
|
uint _map_log_x = TILE_X_BITS;
|
|
|
|
uint _map_log_y = TILE_Y_BITS;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
#define MAP_SIZE ((1 << TILE_X_BITS) * (1 << TILE_Y_BITS))
|
|
|
|
|
|
|
|
byte _map_type_and_height [MAP_SIZE];
|
|
|
|
byte _map5 [MAP_SIZE];
|
|
|
|
byte _map3_lo [MAP_SIZE];
|
|
|
|
byte _map3_hi [MAP_SIZE];
|
|
|
|
byte _map_owner [MAP_SIZE];
|
|
|
|
uint16 _map2 [MAP_SIZE];
|
|
|
|
byte _map_extra_bits [MAP_SIZE / 4];
|
2005-01-05 13:32:03 +00:00
|
|
|
|
2005-01-09 17:55:11 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
|
|
|
|
const char *exp, const char *file, int line)
|
|
|
|
{
|
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
uint x;
|
|
|
|
uint y;
|
|
|
|
|
|
|
|
dx = add & MapMaxX();
|
2005-01-09 18:59:16 +00:00
|
|
|
if (dx >= (int)MapSizeX() / 2) dx -= MapSizeX();
|
2005-01-09 17:55:11 +00:00
|
|
|
dy = (add - dx) / (int)MapSizeX();
|
|
|
|
|
|
|
|
x = TileX(tile) + dx;
|
|
|
|
y = TileY(tile) + dy;
|
|
|
|
|
|
|
|
if (x >= MapSizeX() || y >= MapSizeY()) {
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
|
|
|
|
exp, tile, add);
|
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
fprintf(stderr, "%s:%d %s\n", file, line, buf);
|
|
|
|
#else
|
|
|
|
_assert(buf, (char*)file, line);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(TILE_XY(x,y) == TILE_MASK(tile + add));
|
|
|
|
|
|
|
|
return TILE_XY(x,y);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-01-28 15:31:04 +00:00
|
|
|
uint ScaleByMapSize(uint n)
|
|
|
|
{
|
|
|
|
int shift = (int)MapLogX() - 8 + (int)MapLogY() - 8;
|
|
|
|
|
|
|
|
if (shift < 0)
|
|
|
|
return (n + (1 << -shift) - 1) >> -shift;
|
|
|
|
else
|
|
|
|
return n << shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint ScaleByMapSize1D(uint n)
|
|
|
|
{
|
|
|
|
int shift = ((int)MapLogX() - 8 + (int)MapLogY() - 8) / 2;
|
|
|
|
|
|
|
|
if (shift < 0)
|
|
|
|
return (n + (1 << -shift) - 1) >> -shift;
|
|
|
|
else
|
|
|
|
return n << shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-06 11:39:00 +00:00
|
|
|
const TileIndexDiffC _tileoffs_by_dir[] = {
|
|
|
|
{-1, 0},
|
|
|
|
{ 0, 1},
|
|
|
|
{ 1, 0},
|
|
|
|
{ 0, -1}
|
2005-01-05 13:32:03 +00:00
|
|
|
};
|