mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
This commit is contained in:
parent
357aba7475
commit
833032adc0
|
@ -1086,9 +1086,9 @@ static void AiWantPassengerRoute(Player *p)
|
|||
|
||||
static void AiWantTrainRoute(Player *p)
|
||||
{
|
||||
uint16 r;
|
||||
uint16 r = GB(Random(), 0, 16);
|
||||
|
||||
p->ai.railtype_to_use = GetBestRailtype(p);
|
||||
r = (uint16)Random();
|
||||
|
||||
if (r > 0xD000) {
|
||||
AiWantLongIndustryRoute(p);
|
||||
|
@ -1349,7 +1349,7 @@ static void AiWantPassengerRouteInsideTown(Player *p)
|
|||
|
||||
static void AiWantRoadRoute(Player *p)
|
||||
{
|
||||
uint16 r = (uint16)Random();
|
||||
uint16 r = GB(Random(), 0, 16);
|
||||
|
||||
if (r > 0x4000) {
|
||||
AiWantLongRoadIndustryRoute(p);
|
||||
|
|
|
@ -781,7 +781,8 @@ static void AiNew_State_FindDepot(Player *p)
|
|||
// To make the depot stand in the middle of the route, we start from the center..
|
||||
// But first we walk through the route see if we can find a depot that is ours
|
||||
// this keeps things nice ;)
|
||||
int g, i, j, r;
|
||||
int g, i, r;
|
||||
uint j;
|
||||
TileIndex tile;
|
||||
assert(p->ainew.state == AI_STATE_FIND_DEPOT);
|
||||
|
||||
|
@ -796,7 +797,7 @@ static void AiNew_State_FindDepot(Player *p)
|
|||
// We found a depot, is it ours? (TELL ME!!!)
|
||||
if (IsTileOwner(tile + TileOffsByDir(j), _current_player)) {
|
||||
// Now, is it pointing to the right direction.........
|
||||
if ((_m[tile + TileOffsByDir(j)].m5 & 3) == (j ^ 2)) {
|
||||
if (GB(_m[tile + TileOffsByDir(j)].m5, 0, 2) == (j ^ 2)) {
|
||||
// Yeah!!!
|
||||
p->ainew.depot_tile = tile + TileOffsByDir(j);
|
||||
p->ainew.depot_direction = j ^ 2; // Reverse direction
|
||||
|
|
|
@ -475,14 +475,14 @@ int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32
|
|||
* @param x,y unused
|
||||
* @param p1 vehicle ID of the aircraft to refit
|
||||
* @param p2 various bitstuffed elements
|
||||
* - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
|
||||
* - p2 = (bit 0-7) - the new cargo type to refit to
|
||||
*/
|
||||
int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
int pass, mail;
|
||||
int32 cost;
|
||||
CargoID new_cid = p2 & 0xFF; //gets the cargo number
|
||||
CargoID new_cid = GB(p2, 0, 8);
|
||||
const AircraftVehicleInfo *avi;
|
||||
|
||||
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
||||
|
|
|
@ -772,14 +772,14 @@ void GenerateClearTile(void)
|
|||
TileIndex tile;
|
||||
|
||||
/* add hills */
|
||||
i = ScaleByMapSize((Random() & 0x3FF) + 0x400);
|
||||
i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
|
||||
do {
|
||||
tile = RandomTile();
|
||||
if (IsTileType(tile, MP_CLEAR)) SB(_m[tile].m5, 2, 2, 1);
|
||||
} while (--i);
|
||||
|
||||
/* add grey squares */
|
||||
i = ScaleByMapSize((Random() & 0x7F) + 0x80);
|
||||
i = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
|
||||
do {
|
||||
uint32 r = Random();
|
||||
tile = RandomTileSeed(r);
|
||||
|
@ -791,7 +791,7 @@ void GenerateClearTile(void)
|
|||
SB(_m[tile].m5, 2, 2, 2);
|
||||
do {
|
||||
if (--j == 0) goto get_out;
|
||||
tile_new = tile + TileOffsByDir(Random() & 3);
|
||||
tile_new = tile + TileOffsByDir(GB(Random(), 0, 2));
|
||||
} while (!IsTileType(tile_new, MP_CLEAR));
|
||||
tile = tile_new;
|
||||
}
|
||||
|
|
|
@ -920,7 +920,7 @@ static void Disaster7_Init(void)
|
|||
|
||||
{
|
||||
TileIndex tile = i->xy;
|
||||
TileIndexDiff step = TileOffsByDir(Random() & 3);
|
||||
TileIndexDiff step = TileOffsByDir(GB(Random(), 0, 2));
|
||||
|
||||
int count = 30;
|
||||
do {
|
||||
|
|
4
gfx.c
4
gfx.c
|
@ -441,7 +441,7 @@ void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
|
|||
GetString(buffer, str);
|
||||
|
||||
tmp = FormatStringLinebreaks(buffer, maxw);
|
||||
num = (uint16)tmp;
|
||||
num = GB(tmp, 0, 16);
|
||||
|
||||
switch (GB(tmp, 16, 16)) {
|
||||
case 0: mt = 10; break;
|
||||
|
@ -487,7 +487,7 @@ void DrawStringMultiLine(int x, int y, StringID str, int maxw)
|
|||
GetString(buffer, str);
|
||||
|
||||
tmp = FormatStringLinebreaks(buffer, maxw);
|
||||
num = (uint16)tmp;
|
||||
num = GB(tmp, 0, 16);
|
||||
|
||||
switch (GB(tmp, 16, 16)) {
|
||||
case 0: mt = 10; break;
|
||||
|
|
16
main_gui.c
16
main_gui.c
|
@ -979,14 +979,14 @@ static void ToolbarOptionsClick(Window *w)
|
|||
w = PopupMainToolbMenu(w, 43, 2, STR_02C3_GAME_OPTIONS, 13, 0);
|
||||
|
||||
x = (uint16)-1;
|
||||
if (_display_opt & DO_SHOW_TOWN_NAMES) x &= ~(1<<5);
|
||||
if (_display_opt & DO_SHOW_STATION_NAMES) x &= ~(1<<6);
|
||||
if (_display_opt & DO_SHOW_SIGNS) x &= ~(1<<7);
|
||||
if (_display_opt & DO_WAYPOINTS) x &= ~(1<<8);
|
||||
if (_display_opt & DO_FULL_ANIMATION) x &= ~(1<<9);
|
||||
if (_display_opt & DO_FULL_DETAIL) x &= ~(1<<10);
|
||||
if (_display_opt & DO_TRANS_BUILDINGS) x &= ~(1<<11);
|
||||
if (_display_opt & DO_TRANS_SIGNS) x &= ~(1<<12);
|
||||
if (_display_opt & DO_SHOW_TOWN_NAMES) CLRBIT(x, 5);
|
||||
if (_display_opt & DO_SHOW_STATION_NAMES) CLRBIT(x, 6);
|
||||
if (_display_opt & DO_SHOW_SIGNS) CLRBIT(x, 7);
|
||||
if (_display_opt & DO_WAYPOINTS) CLRBIT(x, 8);
|
||||
if (_display_opt & DO_FULL_ANIMATION) CLRBIT(x, 9);
|
||||
if (_display_opt & DO_FULL_DETAIL) CLRBIT(x, 10);
|
||||
if (_display_opt & DO_TRANS_BUILDINGS) CLRBIT(x, 11);
|
||||
if (_display_opt & DO_TRANS_SIGNS) CLRBIT(x, 12);
|
||||
WP(w,menu_d).checked_items = x;
|
||||
}
|
||||
|
||||
|
|
|
@ -830,8 +830,8 @@ void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak)
|
|||
int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
Vehicle *v;
|
||||
OrderID cur_ord = p2 & 0xFFFF;
|
||||
uint16 serv_int = p2 >> 16;
|
||||
OrderID cur_ord = GB(p2, 0, 16);
|
||||
uint16 serv_int = GB(p2, 16, 16);
|
||||
|
||||
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
||||
|
||||
|
|
10
players.c
10
players.c
|
@ -155,12 +155,12 @@ void DrawPlayerFace(uint32 face, int color, int x, int y)
|
|||
uint val = GB(face, 20, 8);
|
||||
|
||||
if (!(flag&1)) {
|
||||
DrawSprite(0x36B + ((val&3)*3>>2), x, y);
|
||||
DrawSprite(0x36E + ((val>>2)&3), x, y);
|
||||
DrawSprite(0x372 + ((val>>4)*6>>4), x, y);
|
||||
DrawSprite(0x36B + (GB(val, 0, 2) * 3 >> 2), x, y);
|
||||
DrawSprite(0x36E + (GB(val, 2, 2) * 4 >> 2), x, y);
|
||||
DrawSprite(0x372 + (GB(val, 4, 4) * 6 >> 4), x, y);
|
||||
} else {
|
||||
DrawSprite(0x378 + ((val&3)*3>>2), x, y);
|
||||
DrawSprite(0x37B + ((val>>2)&3), x, y);
|
||||
DrawSprite(0x378 + (GB(val, 0, 2) * 3 >> 2), x, y);
|
||||
DrawSprite(0x37B + (GB(val, 2, 2) * 4 >> 2), x, y);
|
||||
|
||||
val >>= 4;
|
||||
if (val < 3) {
|
||||
|
|
12
rail_gui.c
12
rail_gui.c
|
@ -285,18 +285,16 @@ static void BuildRailClick_Tunnel(Window *w)
|
|||
|
||||
static void BuildRailClick_Remove(Window *w)
|
||||
{
|
||||
if (w->disabled_state & (1<<16))
|
||||
return;
|
||||
if (HASBIT(w->disabled_state, 16)) return;
|
||||
SetWindowDirty(w);
|
||||
SndPlayFx(SND_15_BEEP);
|
||||
|
||||
w->click_state ^= (1 << 16);
|
||||
_remove_button_clicked = (w->click_state & (1 << 16)) != 0;
|
||||
SetSelectionRed((w->click_state & (1 << 16)) != 0);
|
||||
TOGGLEBIT(w->click_state, 16);
|
||||
_remove_button_clicked = HASBIT(w->click_state, 16) != 0;
|
||||
SetSelectionRed(HASBIT(w->click_state, 16) != 0);
|
||||
|
||||
// handle station builder
|
||||
if( w->click_state & (1 << 16) )
|
||||
{
|
||||
if (HASBIT(w->click_state, 16)) {
|
||||
if(_remove_button_clicked)
|
||||
SetTileSelectSize(1, 1);
|
||||
else
|
||||
|
|
|
@ -159,12 +159,11 @@ static void BuildRoadClick_Tunnel(Window *w)
|
|||
|
||||
static void BuildRoadClick_Remove(Window *w)
|
||||
{
|
||||
if (w->disabled_state & (1<<11))
|
||||
return;
|
||||
if (HASBIT(w->disabled_state, 11)) return;
|
||||
SetWindowDirty(w);
|
||||
SndPlayFx(SND_15_BEEP);
|
||||
w->click_state ^= (1 << 11);
|
||||
SetSelectionRed((w->click_state & (1 << 11)) != 0);
|
||||
TOGGLEBIT(w->click_state, 11);
|
||||
SetSelectionRed(HASBIT(w->click_state, 11) != 0);
|
||||
}
|
||||
|
||||
static void BuildRoadClick_Landscaping(Window *w)
|
||||
|
|
|
@ -356,8 +356,8 @@ static void CheckShipLeaveDepot(Vehicle *v)
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
v->direction = (byte)m;
|
||||
v->u.ship.state = (byte)(m >> 8);
|
||||
v->direction = GB(m, 0, 8);
|
||||
v->u.ship.state = GB(m, 8, 8);
|
||||
v->vehstatus &= ~VS_HIDDEN;
|
||||
|
||||
v->cur_speed = 0;
|
||||
|
|
|
@ -197,15 +197,15 @@ static const uint16 * const _legend_table[] = {
|
|||
static inline void WRITE_PIXELS(Pixel* d, uint32 val)
|
||||
{
|
||||
# if defined(TTD_BIG_ENDIAN)
|
||||
d[0] = (byte)(val >> 24);
|
||||
d[1] = (byte)(val >> 16);
|
||||
d[2] = (byte)(val >> 8);
|
||||
d[3] = (byte)(val >> 0);
|
||||
d[0] = GB(val, 24, 8);
|
||||
d[1] = GB(val, 16, 8);
|
||||
d[2] = GB(val, 8, 8);
|
||||
d[3] = GB(val, 0, 8);
|
||||
# elif defined(TTD_LITTLE_ENDIAN)
|
||||
d[0] = (byte)(val >> 0);
|
||||
d[1] = (byte)(val >> 8);
|
||||
d[2] = (byte)(val >> 16);
|
||||
d[3] = (byte)(val >> 24);
|
||||
d[0] = GB(val, 0, 8);
|
||||
d[1] = GB(val, 8, 8);
|
||||
d[2] = GB(val, 16, 8);
|
||||
d[3] = GB(val, 24, 8);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
@ -213,15 +213,15 @@ static const uint16 * const _legend_table[] = {
|
|||
static inline void WRITE_PIXELS_OR(Pixel* d, uint32 val)
|
||||
{
|
||||
# if defined(TTD_BIG_ENDIAN)
|
||||
d[0] |= (byte)(val >> 24);
|
||||
d[1] |= (byte)(val >> 16);
|
||||
d[2] |= (byte)(val >> 8);
|
||||
d[3] |= (byte)(val >> 0);
|
||||
d[0] |= GB(val, 24, 8);
|
||||
d[1] |= GB(val, 16, 8);
|
||||
d[2] |= GB(val, 8, 8);
|
||||
d[3] |= GB(val, 0, 8);
|
||||
# elif defined(TTD_LITTLE_ENDIAN)
|
||||
d[0] |= (byte)(val >> 0);
|
||||
d[1] |= (byte)(val >> 8);
|
||||
d[2] |= (byte)(val >> 16);
|
||||
d[3] |= (byte)(val >> 24);
|
||||
d[0] |= GB(val, 0, 8);
|
||||
d[1] |= GB(val, 8, 8);
|
||||
d[2] |= GB(val, 16, 8);
|
||||
d[3] |= GB(val, 24, 8);
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -222,8 +222,8 @@ static inline bool IsCompatibleTrainStationTile(TileIndex tile, TileIndex ref)
|
|||
assert(IsTrainStationTile(ref));
|
||||
return
|
||||
IsTrainStationTile(tile) &&
|
||||
(_m[tile].m3 & 0x0F) == (_m[ref].m3 & 0x0F) && // same rail type?
|
||||
(_m[tile].m5 & 0x01) == (_m[ref].m5 & 0x01); // same direction?
|
||||
GB(_m[tile].m3, 0, 4) == GB(_m[ref].m3, 0, 4) && // same rail type?
|
||||
GB(_m[tile].m5, 0, 1) == GB(_m[ref].m5, 0, 1); // same direction?
|
||||
}
|
||||
|
||||
static inline bool IsRoadStationTile(TileIndex tile) {
|
||||
|
|
|
@ -161,9 +161,7 @@ char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
|
|||
uint index = GB(string, 0, 11);
|
||||
uint tab = GB(string, 11, 5);
|
||||
|
||||
if (!(string & 0xFFFF)) {
|
||||
error("!invalid string id 0 in GetString");
|
||||
}
|
||||
if (GB(string, 0, 16) == 0) error("!invalid string id 0 in GetString");
|
||||
|
||||
switch (tab) {
|
||||
case 4:
|
||||
|
@ -196,7 +194,7 @@ char *GetStringWithArgs(char *buffr, uint string, const int32 *argv)
|
|||
"Probably because an old version of the .lng file.\n", string
|
||||
);
|
||||
|
||||
return FormatString(buffr, GetStringPtr(string&0xFFFF), argv, string >> 24);
|
||||
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8));
|
||||
}
|
||||
|
||||
char *GetString(char *buffr, StringID string)
|
||||
|
|
|
@ -97,7 +97,7 @@ static void DrawTile_Town(TileInfo *ti)
|
|||
{
|
||||
/* this "randomizes" on the (up to) 4 variants of a building */
|
||||
byte gfx = _m[ti->tile].m4;
|
||||
byte stage = _m[ti->tile].m3 >> 6;
|
||||
byte stage = GB(_m[ti->tile].m3, 6, 2);
|
||||
uint variant;
|
||||
variant = ti->x >> 4;
|
||||
variant ^= ti->x >> 6;
|
||||
|
@ -635,7 +635,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, uint mask, int block, Town *t1)
|
|||
|
||||
// Possibly extend the road in a direction.
|
||||
// Randomize a direction and if it has a road, bail out.
|
||||
i = (int)Random() & 3;
|
||||
i = GB(Random(), 0, 2);
|
||||
if (HASBIT(mask, i))
|
||||
return;
|
||||
|
||||
|
|
|
@ -1623,10 +1623,10 @@ int32 CmdForceTrainProceed(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||
*/
|
||||
int32 CmdRefitRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
{
|
||||
CargoID new_cid = GB(p2, 0, 8);
|
||||
Vehicle *v;
|
||||
int32 cost;
|
||||
uint num;
|
||||
CargoID new_cid = p2 & 0xFF; //gets the cargo number
|
||||
|
||||
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
||||
|
||||
|
@ -3173,7 +3173,7 @@ static void ChangeTrainDirRandomly(Vehicle *v)
|
|||
do {
|
||||
//I need to buffer the train direction
|
||||
if (!(v->u.rail.track & 0x40))
|
||||
v->direction = (v->direction + _random_dir_change[Random()&3]) & 7;
|
||||
v->direction = (v->direction + _random_dir_change[GB(Random(), 0, 2)]) & 7;
|
||||
if (!(v->vehstatus & VS_HIDDEN)) {
|
||||
BeginVehicleMove(v);
|
||||
UpdateTrainDeltaXY(v, v->direction);
|
||||
|
|
|
@ -214,7 +214,7 @@ int32 CmdPlantTree(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
treetype = p1;
|
||||
if (treetype == -1) {
|
||||
treetype = GetRandomTreeType(tile, Random() >> 24);
|
||||
treetype = GetRandomTreeType(tile, GB(Random(), 24, 8));
|
||||
if (treetype == -1) treetype = 27;
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ static void TileLoop_Trees(TileIndex tile)
|
|||
if (_opt.landscape == LT_DESERT && _m[tile].m3 != 0x1B && GetMapExtraBits(tile) == 1) {
|
||||
m5++; /* start destructing */
|
||||
} else {
|
||||
switch(Random() & 0x7) {
|
||||
switch (GB(Random(), 0, 3)) {
|
||||
case 0: /* start destructing */
|
||||
m5++;
|
||||
break;
|
||||
|
@ -567,7 +567,7 @@ void OnTick_Trees(void)
|
|||
(r = Random(), tile = RandomTileSeed(r), GetMapExtraBits(tile) == 2) &&
|
||||
IsTileType(tile, MP_CLEAR) &&
|
||||
(m = _m[tile].m5 & 0x1C, m <= 4) &&
|
||||
(tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
|
||||
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
|
||||
|
||||
ModifyTile(tile,
|
||||
MP_SETTYPE(MP_TREES) |
|
||||
|
@ -587,7 +587,7 @@ void OnTick_Trees(void)
|
|||
tile = TILE_MASK(r);
|
||||
if (IsTileType(tile, MP_CLEAR) &&
|
||||
(m = _m[tile].m5 & 0x1C, m == 0 || m == 4 || m == 0x10) &&
|
||||
(tree = GetRandomTreeType(tile, r >> 24)) >= 0) {
|
||||
(tree = GetRandomTreeType(tile, GB(r, 24, 8))) >= 0) {
|
||||
int m2;
|
||||
|
||||
if (m == 0) {
|
||||
|
|
|
@ -813,7 +813,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
|
|||
static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0};
|
||||
new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5&1)];
|
||||
} else {
|
||||
if (!(m5 & 0x18)) goto clear_it;
|
||||
if (GB(m5, 3, 2) == 0) goto clear_it;
|
||||
new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001;
|
||||
}
|
||||
|
||||
|
@ -1398,14 +1398,14 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode
|
|||
|
||||
if ((m5 & 0xF0) == 0) {
|
||||
/* This is a tunnel */
|
||||
if (((m5 & 0xCU) >> 2) == mode) {
|
||||
if (GB(m5, 2, 2) == mode) {
|
||||
/* Tranport in the tunnel is compatible */
|
||||
return m5&1 ? 0x202 : 0x101;
|
||||
}
|
||||
} else if (m5 & 0x80) {
|
||||
/* This is a bridge */
|
||||
result = 0;
|
||||
if (((m5 & 0x6U) >> 1) == mode) {
|
||||
if (GB(m5, 1, 2) == mode) {
|
||||
/* Transport over the bridge is compatible */
|
||||
result = m5&1 ? 0x202 : 0x101;
|
||||
}
|
||||
|
@ -1421,7 +1421,7 @@ static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode
|
|||
return result;
|
||||
} else {
|
||||
/* Transport underneath */
|
||||
if ((m5 & 0x18U) >> 3 != mode)
|
||||
if (GB(m5, 3, 2) != mode)
|
||||
/* Incompatible transport underneath */
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue