(svn r3564) Several smaller changes:

- Don't treat non-booleans as booleans
- Reduce variable scope
- Bracing
- Use DeMorgan's law to make conditionals easier to read
- if cascade -> switch
- Replace some magic numbers by symbolic names
- Avoid assignments within other statements
pull/155/head
tron 19 years ago
parent 75a70e1def
commit 087fe86ed2

@ -2778,8 +2778,7 @@ static bool AiEnumFollowRoad(TileIndex tile, AiRoadEnum *a, int track, uint leng
if (dist <= a->best_dist) {
TileIndex tile2 = TILE_MASK(tile + TileOffsByDir(_dir_by_track[track]));
if (IsTileType(tile2, MP_STREET) &&
(_m[tile2].m5&0xF0) == 0) {
if (IsTileType(tile2, MP_STREET) && GB(_m[tile2].m5, 4, 4) == 0) {
a->best_dist = dist;
a->best_tile = tile;
a->best_track = track;

@ -98,7 +98,7 @@ int GetAircraftImage(const Vehicle *v, byte direction)
if (is_custom_sprite(spritenum)) {
int sprite = GetCustomVehicleSprite(v, direction);
if (sprite) return sprite;
if (sprite != 0) return sprite;
spritenum = orig_aircraft_vehicle_info[v->engine_type - AIRCRAFT_ENGINES_INDEX].image_index;
}
return direction + _aircraft_sprite[spritenum];

@ -637,10 +637,9 @@ static void TileLoop_Clear(TileIndex tile)
{
TileLoopClearHelper(tile);
if (_opt.landscape == LT_DESERT) {
TileLoopClearDesert(tile);
} else if (_opt.landscape == LT_HILLY) {
TileLoopClearAlps(tile);
switch (_opt.landscape) {
case LT_DESERT: TileLoopClearDesert(tile); break;
case LT_HILLY: TileLoopClearAlps(tile); break;
}
switch (GetClearGround(tile)) {

@ -898,10 +898,11 @@ static void Disaster6_Init(void)
static void Disaster7_Init(void)
{
int index = GB(Random(), 0, 4);
Industry *i;
uint m;
for (m = 0; m < 15; m++) {
const Industry* i;
FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
SetDParam(0, i->town->index);

@ -346,14 +346,12 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
DeleteVehicle(v);
} else {
v->owner = new_player;
if (v->type == VEH_Train && IsFrontEngine(v))
v->unitnumber = ++num_train;
else if (v->type == VEH_Road)
v->unitnumber = ++num_road;
else if (v->type == VEH_Ship)
v->unitnumber = ++num_ship;
else if (v->type == VEH_Aircraft && v->subtype <= 2)
v->unitnumber = ++num_aircraft;
switch (v->type) {
case VEH_Train: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break;
case VEH_Road: v->unitnumber = ++num_road; break;
case VEH_Ship: v->unitnumber = ++num_ship; break;
case VEH_Aircraft: if (v->subtype <= 2) v->unitnumber = ++num_aircraft; break;
}
}
}
}
@ -1190,10 +1188,17 @@ static bool CheckSubsidised(Station *from, Station *to, byte cargo_type)
if (DistanceMax(xy, from->xy) > 9) continue;
/* Check distance from dest */
if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) {
xy = GetTown(s->to)->xy;
} else {
xy = (GetIndustry(s->to))->xy;
switch (cargo_type) {
case CT_PASSENGERS:
case CT_MAIL:
case CT_GOODS:
case CT_FOOD:
xy = GetTown(s->to)->xy;
break;
default:
xy = GetIndustry(s->to)->xy;
break;
}
if (DistanceMax(xy, to->xy) > 9) continue;
@ -1256,18 +1261,11 @@ static int32 DeliverGoods(int num_pieces, byte cargo_type, uint16 source, uint16
// Modify profit if a subsidy is in effect
if (subsidised) {
if (_opt.diff.subsidy_multiplier < 1) {
/* 1.5x */
profit += profit >> 1;
} else if (_opt.diff.subsidy_multiplier == 1) {
/* 2x */
profit *= 2;
} else if (_opt.diff.subsidy_multiplier == 2) {
/* 3x */
profit *= 3;
} else {
/* 4x */
profit *= 4;
switch (_opt.diff.subsidy_multiplier) {
case 0: profit += profit >> 1;
case 1: profit *= 2;
case 2: profit *= 3;
default: profit *= 4;
}
}
@ -1353,7 +1351,8 @@ int LoadUnloadVehicle(Vehicle *v)
old_player = _current_player;
_current_player = v->owner;
st = GetStation(last_visited = v->last_station_visited);
last_visited = v->last_station_visited;
st = GetStation(last_visited);
for (; v != NULL; v = v->next) {
GoodsEntry* ge;
@ -1413,12 +1412,14 @@ int LoadUnloadVehicle(Vehicle *v)
/* update stats */
ge->days_since_pickup = 0;
t = u->max_speed;
if (u->type == VEH_Road) t >>=1;
if (u->type == VEH_Train) t = u->u.rail.cached_max_speed;
switch (u->type) {
case VEH_Train: t = u->u.rail.cached_max_speed; break;
case VEH_Road: t = u->max_speed / 2; break;
default: t = u->max_speed; break;
}
// if last speed is 0, we treat that as if no vehicle has ever visited the station.
ge->last_speed = t < 255 ? t : 255;
ge->last_speed = min(t, 255);
ge->last_age = _cur_year - v->build_year;
// If there's goods waiting at the station, and the vehicle

@ -280,22 +280,22 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
switch (e->event) {
case WE_PAINT: {
const Industry *i;
StringID str;
const Industry* i = GetIndustry(w->window_number);
i = GetIndustry(w->window_number);
SetDParam(0, w->window_number);
DrawWindowWidgets(w);
if (i->accepts_cargo[0] != CT_INVALID) {
StringID str;
SetDParam(0, _cargoc.names_s[i->accepts_cargo[0]]);
str = STR_4827_REQUIRES;
if (i->accepts_cargo[1] != CT_INVALID) {
SetDParam(1, _cargoc.names_s[i->accepts_cargo[1]]);
str++;
str = STR_4828_REQUIRES;
if (i->accepts_cargo[2] != CT_INVALID) {
SetDParam(2, _cargoc.names_s[i->accepts_cargo[2]]);
str++;
str = STR_4829_REQUIRES;
}
}
DrawString(2, 107, str, 0);
@ -442,17 +442,14 @@ static const WindowDesc _industry_view_desc = {
void ShowIndustryViewWindow(int industry)
{
Window *w;
Industry *i;
Window* w = AllocateWindowDescFront(&_industry_view_desc, industry);
w = AllocateWindowDescFront(&_industry_view_desc, industry);
if (w) {
if (w != NULL) {
w->flags4 |= WF_DISABLE_VP_SCROLL;
WP(w,vp2_d).data_1 = 0;
WP(w,vp2_d).data_2 = 0;
WP(w,vp2_d).data_3 = 0;
i = GetIndustry(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TileDiffXY(1, 1), 1);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetIndustry(w->window_number)->xy + TileDiffXY(1, 1), 1);
}
}
@ -550,8 +547,7 @@ static void MakeSortedIndustryList(void)
error("Could not allocate memory for the industry-sorting-list");
FOR_ALL_INDUSTRIES(i) {
if (i->xy)
_industry_sort[n++] = i->index;
if (i->xy != 0) _industry_sort[n++] = i->index;
}
_num_industry_sort = n;
_last_industry_idx = 0xFFFF; // used for "cache"
@ -568,7 +564,6 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
case WE_PAINT: {
int n;
uint p;
Industry *i;
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
if (_industry_sort_dirty) {
@ -585,7 +580,8 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
n = 0;
while (p < _num_industry_sort) {
i = GetIndustry(_industry_sort[p]);
const Industry* i = GetIndustry(_industry_sort[p]);
SetDParam(0, i->index);
if (i->produced_cargo[0] != CT_INVALID) {
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
@ -638,14 +634,11 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
case 8: {
int y = (e->click.pt.y - 28) / 10;
uint16 p;
Industry *c;
if (!IS_INT_INSIDE(y, 0, w->vscroll.cap))
return;
if (!IS_INT_INSIDE(y, 0, w->vscroll.cap)) return;
p = y + w->vscroll.pos;
if (p < _num_industry_sort) {
c = GetIndustry(_industry_sort[p]);
ScrollMainWindowToTile(c->xy);
ScrollMainWindowToTile(GetIndustry(_industry_sort[p])->xy);
}
} break;
}
@ -674,11 +667,9 @@ static const WindowDesc _industry_directory_desc = {
void ShowIndustryDirectory(void)
{
/* Industry List */
Window *w;
Window* w = AllocateWindowDescFront(&_industry_directory_desc, 0);
w = AllocateWindowDescFront(&_industry_directory_desc, 0);
if (w) {
if (w != NULL) {
w->vscroll.cap = 16;
w->resize.height = w->height - 6 * 10; // minimum 10 items
w->resize.step_height = 10;

@ -78,7 +78,9 @@ uint InteractiveRandomRange(uint max)
void SetDate(uint date)
{
YearMonthDay ymd;
ConvertDayToYMD(&ymd, _date = date);
_date = date;
ConvertDayToYMD(&ymd, date);
_cur_year = ymd.year;
_cur_month = ymd.month;
#ifdef ENABLE_NETWORK
@ -186,8 +188,6 @@ void InitializeGame(int mode, uint size_x, uint size_y)
void GenerateWorld(int mode, uint size_x, uint size_y)
{
int i;
// Make sure everything is done via OWNER_NONE
_current_player = OWNER_NONE;
@ -223,7 +223,9 @@ void GenerateWorld(int mode, uint size_x, uint size_y)
// No need to run the tile loop in the scenario editor.
if (mode != GW_EMPTY) {
for (i = 0x500; i != 0; i--) RunTileLoop();
uint i;
for (i = 0; i < 0x500; i++) RunTileLoop();
}
ResetObjectToPlace();
@ -410,7 +412,7 @@ typedef struct LandscapePredefVar {
void InitializeLandscapeVariables(bool only_constants)
{
const LandscapePredefVar *lpd;
int i;
uint i;
StringID str;
lpd = &_landscape_predef_var[_opt.landscape];
@ -487,7 +489,8 @@ static const uint16 _autosave_months[] = {
*/
static void RunVehicleDayProc(uint daytick)
{
uint i, total = _vehicle_pool.total_items;
uint total = _vehicle_pool.total_items;
uint i;
for (i = daytick; i < total; i += DAY_TICKS) {
Vehicle* v = GetVehicle(i);
@ -976,13 +979,13 @@ static void Save_CHTS(void)
static void Load_CHTS(void)
{
Cheat* cht = (Cheat*) &_cheats;
Cheat* cht = (Cheat*)&_cheats;
uint count = SlGetFieldLength() / 2;
uint i;
uint count = SlGetFieldLength()/2;
for (; count; count--, cht++)
{
cht->been_used = (byte)SlReadByte();
cht->value = (byte)SlReadByte();
for (i = 0; i < count; i++) {
cht[i].been_used = SlReadByte();
cht[i].value = SlReadByte();
}
}

@ -100,8 +100,8 @@ void NetworkSend_Packet(Packet *packet, NetworkClientState *cs)
packet->pos = 0;
packet->next = NULL;
packet->buffer[0] = packet->size & 0xFF;
packet->buffer[1] = packet->size >> 8;
packet->buffer[0] = GB(packet->size, 0, 8);
packet->buffer[1] = GB(packet->size, 8, 8);
// Locate last packet buffered for the client
p = cs->packet_queue;

@ -657,7 +657,7 @@ static void StartScenario(void)
}
_opt_ptr = &_opt;
memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(GameDifficulty));
memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(_opt_ptr->diff));
_opt.diff_level = _opt_newgame.diff_level;
// Inititalize data
@ -731,7 +731,7 @@ void SwitchMode(int new_mode)
case SM_NEWGAME: /* New Game --> 'Random game' */
#ifdef ENABLE_NETWORK
if (_network_server) {
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "Random Map");
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
}
#endif /* ENABLE_NETWORK */
MakeNewGame();
@ -740,7 +740,7 @@ void SwitchMode(int new_mode)
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
#ifdef ENABLE_NETWORK
if (_network_server) {
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title);
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
}
#endif /* ENABLE_NETWORK */
StartScenario();
@ -757,7 +757,7 @@ void SwitchMode(int new_mode)
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
#ifdef ENABLE_NETWORK
if (_network_server) {
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title);
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
}
#endif /* ENABLE_NETWORK */
}

@ -366,8 +366,7 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
}
u = GetFirstVehicleFromSharedList(v);
while (u != NULL) {
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
/* Increase amount of orders */
u->num_orders++;
@ -386,8 +385,6 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
/* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u);
u = u->next_shared;
}
/* Make sure to rebuild the whole list */
@ -454,8 +451,7 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
order->type = OT_NOTHING;
order->next = NULL;
u = GetFirstVehicleFromSharedList(v);
while (u != NULL) {
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
u->num_orders--;
if (sel_ord < u->cur_order_index)
@ -476,8 +472,6 @@ int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* Update any possible open window of the vehicle */
InvalidateVehicleOrder(u);
u = u->next_shared;
}
RebuildVehicleLists();
@ -579,14 +573,15 @@ int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* Update the windows and full load flags, also for vehicles that share the same order list */
{
Vehicle *u = GetFirstVehicleFromSharedList(v);
while (u != NULL) {
Vehicle* u;
for (u = GetFirstVehicleFromSharedList(v); u != NULL; u = u->next_shared) {
/* toggle u->current_order "Full load" flag if it changed */
if (sel_ord == u->cur_order_index &&
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD))
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD)) {
TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD);
}
InvalidateVehicleOrder(u);
u = u->next_shared;
}
}
}
@ -632,11 +627,10 @@ int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* Is the vehicle already in the shared list? */
{
Vehicle *u = GetFirstVehicleFromSharedList(src);
while (u != NULL) {
if (u == dst)
return CMD_ERROR;
u = u->next_shared;
const Vehicle* u;
for (u = GetFirstVehicleFromSharedList(src); u != NULL; u = u->next_shared) {
if (u == dst) return CMD_ERROR;
}
}

@ -635,9 +635,9 @@ static inline bool TracksOverlap(TrackBits bits)
/* We know that there are at least two tracks present. When there are more
* than 2 tracks, they will surely overlap. When there are two, they will
* always overlap unless they are lower & upper or right & left. */
if ((bits == (TRACK_BIT_UPPER|TRACK_BIT_LOWER)) || (bits == (TRACK_BIT_LEFT | TRACK_BIT_RIGHT)))
return false;
return true;
return
bits != (TRACK_BIT_UPPER | TRACK_BIT_LOWER) &&
bits != (TRACK_BIT_LEFT | TRACK_BIT_RIGHT);
}
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);

@ -1469,10 +1469,11 @@ static void DrawTile_Track(TileInfo *ti)
DrawGroundSprite(image);
foreach_draw_tile_seq(seq, cust->seq) {
uint32 image = seq->image + relocation;
DrawSpecialBuilding(image, 0, ti,
seq->delta_x, seq->delta_y, seq->delta_z,
seq->width, seq->height, seq->unk);
DrawSpecialBuilding(
seq->image + relocation, 0, ti,
seq->delta_x, seq->delta_y, seq->delta_z,
seq->width, seq->height, seq->unk
);
}
return;
}

@ -1112,9 +1112,8 @@ static const StringID _road_tile_strings[] = {
static void GetTileDesc_Road(TileIndex tile, TileDesc *td)
{
int i = (_m[tile].m5 >> 4);
if (i == 0)
i = GB(_m[tile].m4, 4, 3) + 3;
int i = GB(_m[tile].m5, 4, 4);
if (i == 0) i = GB(_m[tile].m4, 4, 3) + 3;
td->str = _road_tile_strings[i - 1];
td->owner = GetTileOwner(tile);
}

@ -66,13 +66,12 @@ int GetRoadVehImage(const Vehicle *v, byte direction)
if (is_custom_sprite(img)) {
image = GetCustomVehicleSprite(v, direction);
if (image) return image;
if (image != 0) return image;
img = orig_road_vehicle_info[v->engine_type - ROAD_ENGINES_INDEX].image_index;
}
image = direction + _roadveh_images[img];
if (v->cargo_count >= (v->cargo_cap >> 1))
image += _roadveh_full_adder[img];
if (v->cargo_count >= v->cargo_cap / 2) image += _roadveh_full_adder[img];
return image;
}
@ -509,12 +508,12 @@ static void RoadVehIsCrashed(Vehicle *v)
static void *EnumCheckRoadVehCrashTrain(Vehicle *v, Vehicle *u)
{
if (v->type != VEH_Train ||
myabs(v->z_pos - u->z_pos) > 6 ||
myabs(v->x_pos - u->x_pos) > 4 ||
myabs(v->y_pos - u->y_pos) > 4)
return NULL;
return v;
return
v->type == VEH_Train &&
myabs(v->z_pos - u->z_pos) <= 6 &&
myabs(v->x_pos - u->x_pos) <= 4 &&
myabs(v->y_pos - u->y_pos) <= 4 ?
v : NULL;
}
static void RoadVehCrash(Vehicle *v)
@ -527,7 +526,7 @@ static void RoadVehCrash(Vehicle *v)
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
pass = 1;
if (v->cargo_type == 0) pass += v->cargo_count;
if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
v->cargo_count = 0;
SetDParam(0, pass);
@ -573,13 +572,12 @@ static void HandleBrokenRoadVeh(Vehicle *v)
if (!(v->vehstatus & VS_HIDDEN)) {
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
if (u)
u->u.special.unk0 = v->breakdown_delay * 2;
if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2;
}
}
if (!(v->tick_counter & 1)) {
if (!--v->breakdown_delay) {
if ((v->tick_counter & 1) == 0) {
if (--v->breakdown_delay == 0) {
v->breakdown_ctr = 0;
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
}
@ -1643,7 +1641,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
}
// best_stop now contains the best stop we found.
if (best_stop) {
if (best_stop != NULL) {
int slot;
// Find a free slot in this stop. We know that at least one is free.
assert(best_stop->slot[0] == INVALID_SLOT || best_stop->slot[1] == INVALID_SLOT);
@ -1654,7 +1652,7 @@ void OnNewDay_RoadVeh(Vehicle *v)
v->u.road.slot_age = -5;
v->u.road.slotindex = slot;
DEBUG(ms, 1) ("Multistop: Slot %d at 0x%x assigned to vehicle %d (0x%x)", slot, best_stop->xy, v->unitnumber, v->tile);
} else if (first_stop) {
} else if (first_stop != NULL) {
//now we couldn't assign a slot for one reason or another.
//so we just go towards the first station
DEBUG(ms, 1) ("Multistop: No free slot found for vehicle %d, going to default station", v->unitnumber);

@ -347,12 +347,10 @@ static inline TileType GetEffectiveTileType(TileIndex tile)
if (t == MP_TUNNELBRIDGE) {
t = _m[tile].m5;
if ((t & 0x80) == 0) t >>= 1;
if ((t & 6) == 0) {
t = MP_RAILWAY;
} else if ((t & 6) == 2) {
t = MP_STREET;
} else {
t = MP_WATER;
switch (t & 0x06) {
case 0x00: t = MP_RAILWAY; break;
case 0x02: t = MP_STREET; break;
default: t = MP_WATER; break;
}
}
return t;
@ -642,12 +640,10 @@ static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_town
y = 0;
for (;;) {
uint32 mask;
uint32 mask = 0xFFFFFFFF;
int reps;
int t;
mask = 0xFFFFFFFF;
/* distance from left edge */
if (x < 0) {
if (x < -3) goto skip_column;
@ -895,7 +891,7 @@ void ShowSmallMap(void)
int x,y;
w = AllocateWindowDescFront(&_smallmap_desc, 0);
if (w) {
if (w != NULL) {
w->click_state = ((1<<5) << _smallmap_type) | (_smallmap_show_towns << 12);
w->resize.width = 350;
w->resize.height = 250;
@ -993,12 +989,10 @@ void ShowExtraViewPortWindow(void)
int i = 0;
// find next free window number for extra viewport
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) ) {
i++;
}
while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
w = AllocateWindowDescFront(&_extra_view_port_desc, i);
if (w) {
if (w != NULL) {
int x, y;
// the main window with the main view
v = FindWindowById(WC_MAIN_WINDOW, 0);

@ -102,7 +102,7 @@ static void OpenBankFile(const char *filename)
static bool SetBankSource(MixerChannel *mc, uint bank)
{
FileEntry* fe;
const FileEntry* fe;
int8* mem;
uint i;

@ -1325,7 +1325,7 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* Find a station close to us */
if (st == NULL) {
st = GetClosestStationFromTile(tile, 8, _current_player);
if (st != NULL && st->facilities) st = NULL;
if (st != NULL && st->facilities != 0) st = NULL;
}
//give us a road stop in the list, and check if something went wrong
@ -1334,7 +1334,8 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
}
if (st != NULL && GetNumRoadStops(st, RS_BUS) + GetNumRoadStops(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
if (st != NULL &&
GetNumRoadStops(st, RS_BUS) + GetNumRoadStops(st, RS_TRUCK) >= ROAD_STOP_LIMIT) {
return_cmd_error(type ? STR_3008B_TOO_MANY_TRUCK_STOPS : STR_3008A_TOO_MANY_BUS_STOPS);
}
@ -2172,19 +2173,18 @@ static const byte _enter_station_speedtable[12] = {
static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
{
StationID station_id;
byte dir;
if (v->type == VEH_Train) {
if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && IsFrontEngine(v) &&
!IsCompatibleTrainStationTile(tile + TileOffsByDir(v->direction >> 1), tile)) {
StationID station_id = _m[tile].m2;
station_id = _m[tile].m2;
if ((!(v->current_order.flags & OF_NON_STOP) && !_patches.new_nonstop) ||
(v->current_order.type == OT_GOTO_STATION && v->current_order.station == station_id)) {
if (!(_patches.new_nonstop && v->current_order.flags & OF_NON_STOP) &&
v->current_order.type != OT_LEAVESTATION &&
v->last_station_visited != station_id) {
byte dir;
x &= 0xF;
y &= 0xF;

@ -3,11 +3,11 @@
#ifndef TREE_LAND_H
#define TREE_LAND_H
static const SpriteID _tree_sprites_1[4] = {
0x118D,
0x11A0,
0x11B3,
0x11C6,
static const SpriteID _tree_sprites_1[] = {
SPR_FLAT_1_QUART_SNOWY_TILE,
SPR_FLAT_2_QUART_SNOWY_TILE,
SPR_FLAT_3_QUART_SNOWY_TILE,
SPR_FLAT_SNOWY_TILE
};
static const byte _tree_base_by_landscape[4] = {0, 12, 20, 32};

@ -44,9 +44,7 @@ static void TrainCargoChanged(Vehicle* v)
for (u = v; u != NULL; u = u->next) {
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
uint16 vweight = 0;
vweight += (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16;
uint16 vweight = (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16;
// Vehicle weight is not added for articulated parts.
if (!IsArticulatedPart(u)) {

@ -1466,12 +1466,12 @@ static const byte _tunnel_fractcoord_7[4] = {0x52, 0x85, 0x96, 0x49};
static uint32 VehicleEnter_TunnelBridge(Vehicle *v, TileIndex tile, int x, int y)
{
int z;
int dir, vdir;
byte fc;
if (GB(_m[tile].m5, 4, 4) == 0) {
z = GetSlopeZ(x, y) - v->z_pos;
int z = GetSlopeZ(x, y) - v->z_pos;
byte fc;
if (myabs(z) > 2) return 8;
if (v->type == VEH_Train) {

@ -981,18 +981,20 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
byte click_side = 1;
switch (e->click.widget) {
case 12: {
WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
SetWindowDirty(w);
break;
}
case 14: case 15: { /* Select sorting criteria dropdown menu */
case 12:
WP(w, replaceveh_d).wagon_btnstate = !(WP(w, replaceveh_d).wagon_btnstate);
SetWindowDirty(w);
break;
case 14:
case 15: /* Railtype selection dropdown menu */
ShowDropDownMenu(w, _rail_types_list, _railtype_selected_in_replace_gui, 15, 0, ~GetPlayer(_local_player)->avail_railtypes);
break;
}
case 17: { /* toggle renew_keep_length */
case 17: /* toggle renew_keep_length */
DoCommandP(0, 5, GetPlayer(_local_player)->renew_keep_length ? 0 : 1, NULL, CMD_REPLACE_VEHICLE);
} break;
break;
case 4: { /* Start replacing */
EngineID veh_from = WP(w, replaceveh_d).sel_engine[0];
EngineID veh_to = WP(w, replaceveh_d).sel_engine[1];
@ -1012,29 +1014,32 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
click_scroll_pos = w->vscroll.pos;
click_scroll_cap = w->vscroll.cap;
click_side = 0;
/* FALL THROUGH */
case 9: {
uint i = (e->click.pt.y - 14) / w->resize.step_height;
if (i < click_scroll_cap) {
WP(w,replaceveh_d).sel_index[click_side] = i + click_scroll_pos;
SetWindowDirty(w);
}
} break;
break;
}
}
break;
}
} break;
case WE_DROPDOWN_SELECT: { /* we have selected a dropdown item in the list */
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
_railtype_selected_in_replace_gui = e->dropdown.index;
SetWindowDirty(w);
} break;
break;
case WE_RESIZE: {
case WE_RESIZE:
w->vscroll.cap += e->sizing.diff.y / (int)w->resize.step_height;
w->vscroll2.cap += e->sizing.diff.y / (int)w->resize.step_height;
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
w->widget[9].unkA = (w->vscroll2.cap << 8) + 1;
} break;
break;
}
}

@ -375,20 +375,28 @@ void DrawCanalWater(TileIndex tile)
if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60);
// right corner
if ((wa & 3) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 4);
else if ((wa & 3) == 3 && !IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8);
switch (wa & 0x03) {
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4); break;
case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8); break;
}
// bottom corner
if ((wa & 6) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 5);
else if ((wa & 6) == 6 && !IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9);
switch (wa & 0x06) {
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5); break;
case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9); break;
}
// left corner
if ((wa & 12) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 6);
else if ((wa & 12) == 12 && !IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10);
switch (wa & 0x0C) {
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6); break;
case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10); break;
}
// upper corner
if ((wa & 9) == 0) DrawGroundSprite(SPR_CANALS_BASE + 57 + 7);
else if ((wa & 9) == 9 && !IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11);
switch (wa & 0x09) {
case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7); break;
case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11); break;
}
}
typedef struct LocksDrawTileStruct {
@ -403,12 +411,10 @@ static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
uint32 palette, uint base
)
{
uint32 image;
DrawGroundSprite(wdts++->image);
for (; wdts->delta_x != 0x80; wdts++) {
image = wdts->image + base;
uint32 image = wdts->image + base;
if (_display_opt & DO_TRANS_BUILDINGS) {
MAKE_TRANSPARENT(image);
} else {
@ -624,7 +630,6 @@ static void FloodVehicle(Vehicle *v)
// called from tunnelbridge_cmd
void TileLoop_Water(TileIndex tile)
{
int i;
static const TileIndexDiffC _tile_loop_offs_array[][5] = {
// tile to mod shore? shore?
{{-1, 0}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1}},
@ -635,6 +640,8 @@ void TileLoop_Water(TileIndex tile)
if (IS_INT_INSIDE(TileX(tile), 1, MapSizeX() - 3 + 1) &&
IS_INT_INSIDE(TileY(tile), 1, MapSizeY() - 3 + 1)) {
uint i;
for (i = 0; i != lengthof(_tile_loop_offs_array); i++) {
TileLoopWaterHelper(tile, _tile_loop_offs_array[i]);
}

@ -1144,8 +1144,8 @@ static bool HandleScrollbarScrolling(void)
static bool HandleViewportScroll(void)
{
Window *w;
ViewPort *vp;
int dx,dy, x, y, sub;
int dx;
int dy;
if (!_scrolling_viewport) return true;
@ -1168,17 +1168,18 @@ stop_capt:;
}
if (w->window_class != WC_SMALLMAP) {
vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
ViewPort* vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
if (vp == NULL)
goto stop_capt;
WP(w,vp_d).scrollpos_x += dx << vp->zoom;
WP(w,vp_d).scrollpos_y += dy << vp->zoom;
_cursor.delta.x = _cursor.delta.y = 0;
return false;
} else {
// scroll the smallmap ?
int x;
int y;
int sub;
int hx;
int hy;
int hvx;
@ -1233,11 +1234,12 @@ stop_capt:;
WP(w,smallmap_d).scroll_y = y;
WP(w,smallmap_d).subscroll = sub;
_cursor.delta.x = _cursor.delta.y = 0;
SetWindowDirty(w);
return false;
}
_cursor.delta.x = 0;
_cursor.delta.y = 0;
return false;
}
static Window *MaybeBringWindowToFront(Window *w)
@ -1376,7 +1378,7 @@ static void MouseLoop(int click, int mousewheel)
w = FindWindowFromPt(x, y);
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
vp = IsPtInWindowViewport(w, x, y);
if (vp) {
if (vp != NULL) {
x -= vp->left;
y -= vp->top;
//here allows scrolling in both x and y axis
@ -1662,26 +1664,40 @@ void RelocateAllWindows(int neww, int newh)
IConsoleResize();
if (w->window_class == WC_MAIN_TOOLBAR) {
top = w->top;
left = PositionMainToolbar(w); // changes toolbar orientation
} else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){
top = (newh - w->height) >> 1;
left = (neww - w->width) >> 1;
} else if (w->window_class == WC_NEWS_WINDOW) {
top = newh - w->height;
left = (neww - w->width) >> 1;
} else if (w->window_class == WC_STATUS_BAR) {
top = newh - w->height;
left = (neww - w->width) >> 1;
} else if (w->window_class == WC_SEND_NETWORK_MSG) {
top = (newh - 26); // 26 = height of status bar + height of chat bar
left = (neww - w->width) >> 1;
} else {
left = w->left;
if (left + (w->width>>1) >= neww) left = neww - w->width;
top = w->top;
if (top + (w->height>>1) >= newh) top = newh - w->height;
switch (w->window_class) {
case WC_MAIN_TOOLBAR:
top = w->top;
left = PositionMainToolbar(w); // changes toolbar orientation
break;
case WC_SELECT_GAME:
case WC_GAME_OPTIONS:
case WC_NETWORK_WINDOW:
top = (newh - w->height) >> 1;
left = (neww - w->width) >> 1;
break;
case WC_NEWS_WINDOW:
top = newh - w->height;
left = (neww - w->width) >> 1;
break;
case WC_STATUS_BAR:
top = newh - w->height;
left = (neww - w->width) >> 1;
break;
case WC_SEND_NETWORK_MSG:
top = (newh - 26); // 26 = height of status bar + height of chat bar
left = (neww - w->width) >> 1;
break;
default:
left = w->left;
if (left + (w->width >> 1) >= neww) left = neww - w->width;
top = w->top;
if (top + (w->height >> 1) >= newh) top = newh - w->height;
break;
}
if (w->viewport != NULL) {

Loading…
Cancel
Save