forked from mirror/OpenTTD
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
These scale a number relative to the map size/circumference. Use them to scale the amount of map objects. Of course at the moment they return just the input, because there are no bigger/smaller maps yet.
This commit is contained in:
22
map.c
22
map.c
@@ -54,6 +54,28 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
const TileIndexDiffC _tileoffs_by_dir[] = {
|
||||
{-1, 0},
|
||||
{ 0, 1},
|
||||
|
Reference in New Issue
Block a user