diff --git a/ai/ai.c b/ai/ai.c index 6be0c14e41..5029d360d7 100644 --- a/ai/ai.c +++ b/ai/ai.c @@ -125,9 +125,9 @@ static void AI_RunTick(PlayerID player) Player *p = GetPlayer(player); _current_player = player; - if (_patches.ainew_active) + if (_patches.ainew_active) { AiNewDoGameLoop(p); - else { + } else { /* Enable all kind of cheats the old AI needs in order to operate correctly... */ _is_old_ai_player = true; AiDoGameLoop(p); @@ -143,8 +143,7 @@ static void AI_RunTick(PlayerID player) void AI_RunGameLoop(void) { /* Don't do anything if ai is disabled */ - if (!_ai.enabled) - return; + if (!_ai.enabled) return; /* New tick */ _ai.tick++; @@ -212,11 +211,9 @@ void AI_Initialize(void) */ void AI_Uninitialize(void) { - Player *p; + Player* p; FOR_ALL_PLAYERS(p) { - if (p->is_active && p->is_ai) { - AI_PlayerDied(p->index); - } + if (p->is_active && p->is_ai) AI_PlayerDied(p->index); } } diff --git a/ai/default/default.c b/ai/default/default.c index 1d763e483b..b627c39041 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -278,11 +278,12 @@ static void AiHandleGotoDepot(Player *p, int cmd) static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) { - int i; + uint i; - for (i = 0; bak->order[i].type != OT_NOTHING; i++) + for (i = 0; bak->order[i].type != OT_NOTHING; i++) { if (CmdFailed(DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))) break; + } } static void AiHandleReplaceTrain(Player *p) @@ -673,8 +674,7 @@ static void AiWantLongIndustryRoute(Player *p) return; } - if (!AiCheckIfRouteIsGood(p, &fr, 1)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; // Fill the source field p->ai.dst.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); @@ -688,9 +688,9 @@ static void AiWantLongIndustryRoute(Player *p) p->ai.src.buildcmd_a = 0x24; p->ai.src.buildcmd_b = 0xFF; p->ai.src.direction = AiGetDirectionBetweenTiles( - p->ai.src.spec_tile, - p->ai.dst.spec_tile - ); + p->ai.src.spec_tile, + p->ai.dst.spec_tile + ); p->ai.src.cargo = fr.cargo | 0x80; // Fill the dest field @@ -703,17 +703,17 @@ static void AiWantLongIndustryRoute(Player *p) p->ai.dst.buildcmd_a = 0x34; p->ai.dst.buildcmd_b = 0xFF; p->ai.dst.direction = AiGetDirectionBetweenTiles( - p->ai.dst.spec_tile, - p->ai.src.spec_tile - ); + p->ai.dst.spec_tile, + p->ai.src.spec_tile + ); p->ai.dst.cargo = fr.cargo; // Fill middle field 1 p->ai.mid1.spec_tile = AiGetPctTileBetween( - p->ai.src.spec_tile, - p->ai.dst.spec_tile, - 0x55 - ); + p->ai.src.spec_tile, + p->ai.dst.spec_tile, + 0x55 + ); p->ai.mid1.use_tile = 0; p->ai.mid1.rand_rng = 6; p->ai.mid1.cur_building_rule = 0xFF; @@ -726,10 +726,10 @@ static void AiWantLongIndustryRoute(Player *p) // Fill middle field 2 p->ai.mid2.spec_tile = AiGetPctTileBetween( - p->ai.src.spec_tile, - p->ai.dst.spec_tile, - 0xAA - ); + p->ai.src.spec_tile, + p->ai.dst.spec_tile, + 0xAA + ); p->ai.mid2.use_tile = 0; p->ai.mid2.rand_rng = 6; p->ai.mid2.cur_building_rule = 0xFF; @@ -781,8 +781,7 @@ static void AiWantMediumIndustryRoute(Player *p) return; } - if (!AiCheckIfRouteIsGood(p, &fr, 1)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -854,8 +853,7 @@ static void AiWantShortIndustryRoute(Player *p) return; } - if (!AiCheckIfRouteIsGood(p, &fr, 1)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -928,8 +926,7 @@ static void AiWantMailRoute(Player *p) } fr.cargo = CT_MAIL; - if (!AiCheckIfRouteIsGood(p, &fr, 1)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -1034,8 +1031,7 @@ static void AiWantPassengerRoute(Player *p) } fr.cargo = CT_PASSENGERS; - if (!AiCheckIfRouteIsGood(p, &fr, 1)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 1)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -1047,9 +1043,9 @@ static void AiWantPassengerRoute(Player *p) p->ai.src.buildcmd_a = 0x10; p->ai.src.buildcmd_b = 0xFF; p->ai.src.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.from), - GET_TOWN_OR_INDUSTRY_TILE(fr.to) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.from), + GET_TOWN_OR_INDUSTRY_TILE(fr.to) + ); p->ai.src.cargo = fr.cargo; // Fill the dest field @@ -1062,9 +1058,9 @@ static void AiWantPassengerRoute(Player *p) p->ai.dst.buildcmd_a = 0xFF; p->ai.dst.buildcmd_b = 0xFF; p->ai.dst.direction = AiGetDirectionBetweenTiles( - GET_TOWN_OR_INDUSTRY_TILE(fr.to), - GET_TOWN_OR_INDUSTRY_TILE(fr.from) - ); + GET_TOWN_OR_INDUSTRY_TILE(fr.to), + GET_TOWN_OR_INDUSTRY_TILE(fr.from) + ); p->ai.dst.cargo = fr.cargo; // Fill common fields @@ -1126,8 +1122,7 @@ static void AiWantLongRoadIndustryRoute(Player *p) return; } - if (!AiCheckIfRouteIsGood(p, &fr, 2)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -1187,8 +1182,7 @@ static void AiWantMediumRoadIndustryRoute(Player *p) return; } - if (!AiCheckIfRouteIsGood(p, &fr, 2)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.from); @@ -1250,8 +1244,7 @@ static void AiWantLongRoadPassengerRoute(Player *p) fr.cargo = CT_PASSENGERS; - if (!AiCheckIfRouteIsGood(p, &fr, 2)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; // Fill the source field p->ai.src.spec_tile = GET_TOWN_OR_INDUSTRY_TILE(fr.to); @@ -1309,8 +1302,7 @@ static void AiWantPassengerRouteInsideTown(Player *p) fr.cargo = CT_PASSENGERS; fr.from = fr.to = t; - if (!AiCheckIfRouteIsGood(p, &fr, 2)) - return; + if (!AiCheckIfRouteIsGood(p, &fr, 2)) return; // Fill the source field p->ai.src.spec_tile = t->xy; @@ -1360,7 +1352,6 @@ static void AiWantRoadRoute(Player *p) } else { AiWantPassengerRouteInsideTown(p); } - } static void AiWantPassengerAircraftRoute(Player *p) @@ -1615,14 +1606,13 @@ clear_town_stuff:; } } else if (p->mode == 2) { // Rail - if (IsTileType(c, MP_RAILWAY)) - return CMD_ERROR; + if (IsTileType(c, MP_RAILWAY)) return CMD_ERROR; j = p->attr; k = 0; // Build the rail - for(i=0; i!=6; i++,j>>=1) { + for (i = 0; i != 6; i++, j >>= 1) { if (j&1) { k = i; ret = DoCommandByTile(c, _cur_ai_player->ai.railtype_to_use, i, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_SINGLE_RAIL); @@ -1683,9 +1673,9 @@ static int AiBuildDefaultRailTrack(TileIndex tile, byte p0, byte p1, byte p2, by int i; const AiDefaultRailBlock *p; - for(i=0; (p = _default_rail_track_data[i]) != NULL; i++) { + for (i = 0; (p = _default_rail_track_data[i]) != NULL; i++) { if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 && - (p->dir == 0xFF || p->dir == dir || ((p->dir-1)&3) == dir)) { + (p->dir == 0xFF || p->dir == dir || ((p->dir - 1) & 3) == dir)) { *cost = AiDoBuildDefaultRailTrack(tile, p->data, DC_NO_TOWN_RATING); if (*cost != CMD_ERROR && AiCheckTrackResources(tile, p->data, cargo)) return i; @@ -1762,7 +1752,8 @@ static void AiDoTerraformLand(TileIndex tile, int dir, int unk, int mode) static void AiStateBuildDefaultRailBlocks(Player *p) { - int i, j; + uint i; + int j; AiBuildRec *aib; int rule; int32 cost; @@ -1823,8 +1814,7 @@ static void AiStateBuildDefaultRailBlocks(Player *p) aib = &p->ai.src; j = p->ai.num_build_rec; do { - if (aib->cur_building_rule == 255) - return; + if (aib->cur_building_rule == 255) return; } while (++aib,--j); // yep, all are done. switch state to the rail building state. @@ -1850,16 +1840,14 @@ typedef struct AiRailPathFindData { static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, uint length, byte *state) { - if (a->flag) - return true; + if (a->flag) return true; if (length > 20 || tile == a->tile) { a->flag = true; return true; } - if (DistanceMax(tile, a->tile2) < 4) - a->count++; + if (DistanceMax(tile, a->tile2) < 4) a->count++; return false; } @@ -1867,6 +1855,7 @@ static bool AiEnumFollowTrack(TileIndex tile, AiRailPathFindData *a, int track, static bool AiDoFollowTrack(Player *p) { AiRailPathFindData arpfd; + arpfd.tile = p->ai.start_tile_a; arpfd.tile2 = p->ai.cur_tile_a; arpfd.flag = false; @@ -1909,26 +1898,29 @@ static bool AiIsTileBanned(const Player* p, TileIndex tile, byte val) { int i; - for(i=0; i!=p->ai.banned_tile_count; i++) - if (p->ai.banned_tiles[i] == tile && - p->ai.banned_val[i] == val) - return true; + for (i = 0; i != p->ai.banned_tile_count; i++) { + if (p->ai.banned_tiles[i] == tile && p->ai.banned_val[i] == val) { + return true; + } + } return false; } -static void AiBanTile(Player *p, TileIndex tile, byte val) { +static void AiBanTile(Player* p, TileIndex tile, byte val) +{ int i; - for(i=lengthof(p->ai.banned_tiles)-1; i!=0; i--) { - p->ai.banned_tiles[i] = p->ai.banned_tiles[i-1]; - p->ai.banned_val[i] = p->ai.banned_val[i-1]; + for (i = lengthof(p->ai.banned_tiles) - 1; i != 0; i--) { + p->ai.banned_tiles[i] = p->ai.banned_tiles[i - 1]; + p->ai.banned_val[i] = p->ai.banned_val[i - 1]; } p->ai.banned_tiles[0] = tile; p->ai.banned_val[0] = val; - if (p->ai.banned_tile_count != lengthof(p->ai.banned_tiles)) + if (p->ai.banned_tile_count != lengthof(p->ai.banned_tiles)) { p->ai.banned_tile_count++; + } } static void AiBuildRailRecursive(AiRailFinder *arf, TileIndex tile, int dir); @@ -3201,11 +3193,13 @@ static void AiStateBuildRoadVehicles(Player *p) loco_id = _new_roadveh_id; - for(i=0; p->ai.order_list_blocks[i] != 0xFF; i++) { - AiBuildRec *aib = (&p->ai.src) + p->ai.order_list_blocks[i]; - bool is_pass = (p->ai.cargo_type == CT_PASSENGERS || - p->ai.cargo_type == CT_MAIL || - (_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES)); + for (i = 0; p->ai.order_list_blocks[i] != 0xFF; i++) { + AiBuildRec* aib = &p->ai.src + p->ai.order_list_blocks[i]; + bool is_pass = ( + p->ai.cargo_type == CT_PASSENGERS || + p->ai.cargo_type == CT_MAIL || + (_opt.landscape == LT_NORMAL && p->ai.cargo_type == CT_VALUABLES) + ); Order order; order.type = OT_GOTO_STATION; @@ -3220,15 +3214,10 @@ static void AiStateBuildRoadVehicles(Player *p) } DoCommandByTile(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH); - DoCommandByTile(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_TRAIN_SERVICE_INT); - if (p->ai.num_want_fullload != 0) - p->ai.num_want_fullload--; - - if (--p->ai.num_loco_to_build == 0) { - p->ai.state = AIS_0; - } + if (p->ai.num_want_fullload != 0) p->ai.num_want_fullload--; + if (--p->ai.num_loco_to_build == 0) p->ai.state = AIS_0; } static void AiStateDeleteRoadBlocks(Player *p) diff --git a/ai/trolly/build.c b/ai/trolly/build.c index bc173892c5..96920dddb2 100644 --- a/ai/trolly/build.c +++ b/ai/trolly/build.c @@ -250,8 +250,7 @@ int AiNew_Build_Vehicle(Player *p, TileIndex tile, byte flag) int i = AiNew_PickVehicle(p); if (i == -1) return CMD_ERROR; - if (p->ainew.tbt == AI_TRAIN) - return CMD_ERROR; + if (p->ainew.tbt == AI_TRAIN) return CMD_ERROR; return DoCommandByTile(tile, i, 0, flag, CMD_BUILD_ROAD_VEH); } diff --git a/aircraft_cmd.c b/aircraft_cmd.c index af45b88f97..23f06217cd 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -155,8 +155,9 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2) avi = AircraftVehInfo(p1); // allocate 2 or 3 vehicle structs, depending on type if (!AllocateVehicles(vl, (avi->subtype & 1) == 0 ? 3 : 2) || - IsOrderPoolFull()) - return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); + IsOrderPoolFull()) { + return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME); + } unit_num = GetFreeUnitNumber(VEH_Aircraft); if (unit_num > _patches.max_aircraft) @@ -546,21 +547,15 @@ static void CheckIfAircraftNeedsService(Vehicle *v) { const Station* st; - if (_patches.servint_aircraft == 0) - return; - - if (!VehicleNeedsService(v)) - return; - - if (v->vehstatus & VS_STOPPED) - return; + if (_patches.servint_aircraft == 0) return; + if (!VehicleNeedsService(v)) return; + if (v->vehstatus & VS_STOPPED) return; if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OF_HALT_IN_DEPOT) return; - if (_patches.gotodepot && VehicleHasDepotOrders(v)) - return; + if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; st = GetStation(v->current_order.station); // only goto depot if the target airport has terminals (eg. it is airport) @@ -581,11 +576,9 @@ void OnNewDay_Aircraft(Vehicle *v) { int32 cost; - if (v->subtype > 2) - return; + if (v->subtype > 2) return; - if ((++v->day_counter & 7) == 0) - DecreaseVehicleValue(v); + if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); CheckOrders(v->index, OC_INIT); @@ -593,8 +586,7 @@ void OnNewDay_Aircraft(Vehicle *v) AgeVehicle(v); CheckIfAircraftNeedsService(v); - if (v->vehstatus & VS_STOPPED) - return; + if (v->vehstatus & VS_STOPPED) return; cost = AircraftVehInfo(v->engine_type)->running_cost * _price.aircraft_running / 364; @@ -622,13 +614,12 @@ void AircraftYearlyLoop(void) static void AgeAircraftCargo(Vehicle *v) { - if (_age_cargo_skip_counter != 0) - return; + if (_age_cargo_skip_counter != 0) return; do { - if (v->cargo_days != 0xFF) - v->cargo_days++; - } while ( (v=v->next) != NULL ); + if (v->cargo_days != 0xFF) v->cargo_days++; + v = v->next; + } while (v != NULL); } static void HelicopterTickHandler(Vehicle *v) @@ -639,8 +630,7 @@ static void HelicopterTickHandler(Vehicle *v) u = v->next->next; - if (u->vehstatus & VS_HIDDEN) - return; + if (u->vehstatus & VS_HIDDEN) return; // if true, helicopter rotors do not rotate. This should only be the case if a helicopter is // loading/unloading at a terminal or stopped @@ -707,7 +697,8 @@ static void SetAircraftPosition(Vehicle *v, int x, int y, int z) VehiclePositionChanged(u); EndVehicleMove(u); - if ((u=u->next) != NULL) { + u = u->next; + if (u != NULL) { u->x_pos = x; u->y_pos = y; u->z_pos = z + 5; @@ -729,7 +720,8 @@ static void ServiceAircraft(Vehicle *v) u = v->next; u->vehstatus |= VS_HIDDEN; - if ((u=u->next) != NULL) { + u = u->next; + if (u != NULL) { u->vehstatus |= VS_HIDDEN; u->cur_speed = 0; } @@ -752,10 +744,10 @@ static bool UpdateAircraftSpeed(Vehicle *v) byte t; v->subspeed = (t=v->subspeed) + (byte)spd; - spd = min( v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed); + spd = min(v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed); // adjust speed for broken vehicles - if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27); + if (v->vehstatus & VS_AIRCRAFT_BROKEN) spd = min(spd, 27); //updates statusbar only if speed have changed to save CPU time if (spd != v->cur_speed) { @@ -764,19 +756,15 @@ static bool UpdateAircraftSpeed(Vehicle *v) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); } - if (!(v->direction & 1)) { - spd = spd * 3 >> 2; - } + if (!(v->direction & 1)) spd = spd * 3 / 4; - if (spd == 0) - return false; + if (spd == 0) return false; - if ((byte)++spd == 0) - return true; + if ((byte)++spd == 0) return true; v->progress = (t = v->progress) - (byte)spd; - return (t < v->progress); + return t < v->progress; } // get Aircraft running altitude @@ -822,9 +810,7 @@ static bool AircraftController(Vehicle *v) // Make sure the rotors don't rotate too fast if (u->cur_speed > 32) { v->cur_speed = 0; - if (--u->cur_speed == 32) { - SndPlayVehicleFx(SND_18_HELICOPTER, v); - } + if (--u->cur_speed == 32) SndPlayVehicleFx(SND_18_HELICOPTER, v); } else { u->cur_speed = 32; if (UpdateAircraftSpeed(v)) { @@ -865,9 +851,8 @@ static bool AircraftController(Vehicle *v) u = v->next->next; // Increase speed of rotors. When speed is 80, we've landed. - if (u->cur_speed >= 80) - return true; - u->cur_speed+=4; + if (u->cur_speed >= 80) return true; + u->cur_speed += 4; } else if (v->z_pos > z) { SetAircraftPosition(v, v->x_pos, v->y_pos, v->z_pos-1); } else { @@ -886,10 +871,7 @@ static bool AircraftController(Vehicle *v) // At final pos? if (dist == 0) { - - // Clamp speed to 12. - if (v->cur_speed > 12) - v->cur_speed = 12; + if (v->cur_speed > 12) v->cur_speed = 12; // Change direction smoothly to final direction. dirdiff = amd->direction - v->direction; @@ -900,8 +882,7 @@ static bool AircraftController(Vehicle *v) return true; } - if (!UpdateAircraftSpeed(v)) - return false; + if (!UpdateAircraftSpeed(v)) return false; v->direction = (v->direction+((dirdiff&7)<5?1:-1)) & 7; v->cur_speed >>= 1; @@ -910,24 +891,17 @@ static bool AircraftController(Vehicle *v) return false; } - // Clamp speed? - if (!(amd->flag & AMED_NOSPDCLAMP) && v->cur_speed > 12) - v->cur_speed = 12; + if (!(amd->flag & AMED_NOSPDCLAMP) && v->cur_speed > 12) v->cur_speed = 12; - if (!UpdateAircraftSpeed(v)) - return false; + if (!UpdateAircraftSpeed(v)) return false; - // Decrease animation counter. - if (v->load_unload_time_rem != 0) - v->load_unload_time_rem--; + if (v->load_unload_time_rem != 0) v->load_unload_time_rem--; // Turn. Do it slowly if in the air. newdir = GetDirectionTowards(v, x + amd->x, y + amd->y); if (newdir != v->direction) { if (amd->flag & AMED_SLOWTURN) { - if (v->load_unload_time_rem == 0) { - v->load_unload_time_rem = 8; - } + if (v->load_unload_time_rem == 0) v->load_unload_time_rem = 8; v->direction = newdir; } else { v->cur_speed >>= 1; @@ -940,19 +914,15 @@ static bool AircraftController(Vehicle *v) v->tile = gp.new_tile; // If vehicle is in the air, use tile coordinate 0. - if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) { - v->tile = 0; - } + if (amd->flag & (AMED_TAKEOFF | AMED_SLOWTURN | AMED_LAND)) v->tile = 0; // Adjust Z for land or takeoff? z = v->z_pos; if (amd->flag & AMED_TAKEOFF) { - z+=2; - // Determine running altitude + z += 2; maxz = GetAircraftFlyingAltitude(v); - if (z > maxz) - z = maxz; + if (z > maxz) z = maxz; } if (amd->flag & AMED_LAND) { @@ -969,7 +939,7 @@ static bool AircraftController(Vehicle *v) if (curz > z) { z++; } else { - int t = max(1, dist-4); + int t = max(1, dist - 4); z -= ((z - curz) + t - 1) / t; if (z < curz) z = curz; @@ -980,11 +950,13 @@ static bool AircraftController(Vehicle *v) if (amd->flag & AMED_BRAKE) { curz = GetSlopeZ(x, y) + 1; - if (z > curz) z--; - else if (z < curz) z++; + if (z > curz) { + z--; + } else if (z < curz) { + z++; + } - if (dist < 64 && v->cur_speed > 12) - v->cur_speed -= 4; + if (dist < 64 && v->cur_speed > 12) v->cur_speed -= 4; } SetAircraftPosition(v, gp.x, gp.y, z); @@ -1061,8 +1033,7 @@ static const int8 _aircraft_smoke_xy[16] = { static void HandleAircraftSmoke(Vehicle *v) { - if (!(v->vehstatus&VS_AIRCRAFT_BROKEN)) - return; + if (!(v->vehstatus & VS_AIRCRAFT_BROKEN)) return; if (v->cur_speed < 10) { v->vehstatus &= ~VS_AIRCRAFT_BROKEN; @@ -1098,8 +1069,7 @@ static void ProcessAircraftOrder(Vehicle *v) v->cur_order_index++; } - if (v->cur_order_index >= v->num_orders) - v->cur_order_index = 0; + if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0; order = GetVehicleOrder(v, v->cur_order_index); @@ -1132,18 +1102,12 @@ static void ProcessAircraftOrder(Vehicle *v) static void HandleAircraftLoading(Vehicle *v, int mode) { - if (v->current_order.type == OT_NOTHING) - return; + if (v->current_order.type == OT_NOTHING) return; if (v->current_order.type != OT_DUMMY) { - if (v->current_order.type != OT_LOADING) - return; - - if (mode != 0) - return; - - if (--v->load_unload_time_rem) - return; + if (v->current_order.type != OT_LOADING) return; + if (mode != 0) return; + if (--v->load_unload_time_rem != 0) return; if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_INC); @@ -1155,8 +1119,7 @@ static void HandleAircraftLoading(Vehicle *v, int mode) Order b = v->current_order; v->current_order.type = OT_NOTHING; v->current_order.flags = 0; - if (!(b.flags & OF_NON_STOP)) - return; + if (!(b.flags & OF_NON_STOP)) return; } } v->cur_order_index++; @@ -1183,7 +1146,7 @@ static void CrashAirplane(Vehicle *v) v->cargo_count = 0; v->next->cargo_count = 0, st = GetStation(v->u.air.targetairport); - if(st->airport_tile==0) { + if (st->airport_tile == 0) { newsitem = STR_PLANE_CRASH_OUT_OF_FUEL; } else { SetDParam(1, st->index); @@ -1230,8 +1193,7 @@ static void AircraftEntersTerminal(Vehicle *v) Station *st; Order old_order; - if (v->current_order.type == OT_GOTO_DEPOT) - return; + if (v->current_order.type == OT_GOTO_DEPOT) return; st = GetStation(v->u.air.targetairport); v->last_station_visited = v->u.air.targetairport; @@ -1267,7 +1229,7 @@ static void AircraftEntersTerminal(Vehicle *v) InvalidateWindowClasses(WC_AIRCRAFT_LIST); } -static bool ValidateAircraftInHangar( uint data_a, uint data_b ) +static bool ValidateAircraftInHangar(uint data_a, uint data_b) { const Vehicle* v = GetVehicle(data_a); @@ -1348,7 +1310,8 @@ static void AircraftLeaveHangar(Vehicle *v) u->vehstatus &= ~VS_HIDDEN; // Rotor blades - if ((u=u->next) != NULL) { + u = u->next; + if (u != NULL) { u->vehstatus &= ~VS_HIDDEN; u->cur_speed = 80; } @@ -1452,10 +1415,11 @@ static void AircraftEventHandler_AtTerminal(Vehicle *v, const AirportFTAClass *A v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; break; case OT_GOTO_DEPOT: // visit hangar for serivicing, sale, etc. - if (v->current_order.station == v->u.air.targetairport) + if (v->current_order.station == v->u.air.targetairport) { v->u.air.state = HANGAR; - else + } else { v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF; + } break; default: // orders have been deleted (no orders), goto depot and don't bother us v->current_order.type = OT_NOTHING; @@ -1498,8 +1462,10 @@ static void AircraftEventHandler_HeliTakeOff(Vehicle *v, const AirportFTAClass * AircraftNextAirportPos_and_Order(v); // check if the aircraft needs to be replaced or renewed and send it to a hangar if needed - if ((v->owner == _local_player && p->engine_replacement[v->engine_type] != INVALID_ENGINE) || - (v->owner == _local_player && p->engine_renew && v->age - v->max_age > (p->engine_renew_months * 30))) { + if (v->owner == _local_player && ( + p->engine_replacement[v->engine_type] != INVALID_ENGINE || + (p->engine_renew && v->age - v->max_age > p->engine_renew_months * 30) + )) { _current_player = _local_player; DoCommandP(v->tile, v->index, 1, NULL, CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_SHOW_NO_ERROR); _current_player = OWNER_NONE; @@ -1519,9 +1485,9 @@ static void AircraftEventHandler_Flying(Vehicle *v, const AirportFTAClass *Airpo // all other airports --> all types of flying devices (ALL) // heliport/oilrig, etc --> no airplanes (HELICOPTERS_ONLY) // runway busy or not allowed to use this airstation, circle - if (! (v->subtype == Airport->acc_planes || - st->airport_tile == 0 || (st->owner != OWNER_NONE && st->owner != v->owner) )) { - + if (v->subtype != Airport->acc_planes && + st->airport_tile != 0 && + (st->owner == OWNER_NONE || st->owner == v->owner)) { // {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41}, // if it is an airplane, look for LANDING, for helicopter HELILANDING // it is possible to choose from multiple landing runways, so loop until a free one is found @@ -1636,10 +1602,10 @@ static AircraftStateHandler * const _aircraft_state_handlers[] = { static void AirportClearBlock(const Vehicle* v, const AirportFTAClass* Airport) { - Station *st; // we have left the previous block, and entered the new one. Free the previous block if (Airport->layout[v->u.air.previous_pos].block != Airport->layout[v->u.air.pos].block) { - st = GetStation(v->u.air.targetairport); + Station* st = GetStation(v->u.air.targetairport); + CLRBITS(st->airport_flags, Airport->layout[v->u.air.previous_pos].block); } } @@ -1689,10 +1655,10 @@ static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport) // matches our heading do { if (v->u.air.state == current->heading || current->heading == TO_ALL) { - if (AirportSetBlocks(v, current, Airport)) { - v->u.air.pos = current->next_position; - } // move to next position - return retval; + if (AirportSetBlocks(v, current, Airport)) { + v->u.air.pos = current->next_position; + } // move to next position + return retval; } current = current->next_in_chain; } while (current != NULL); @@ -1731,16 +1697,15 @@ static bool AirportHasBlock(Vehicle *v, AirportFTA *current_pos, const AirportFT // returns true on success. Eg, next block was free and we have occupied it static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportFTAClass *Airport) { - Station *st; - uint32 airport_flags; - AirportFTA *current, *reference, *next; - next = &Airport->layout[current_pos->next_position]; - reference = &Airport->layout[v->u.air.pos]; + AirportFTA* next = &Airport->layout[current_pos->next_position]; + AirportFTA* reference = &Airport->layout[v->u.air.pos]; + AirportFTA* current; // if the next position is in another block, check it and wait until it is free if (Airport->layout[current_pos->position].block != next->block) { - airport_flags = next->block; - st = GetStation(v->u.air.targetairport); + uint32 airport_flags = next->block; + Station* st = GetStation(v->u.air.targetairport); + //search for all all elements in the list with the same state, and blocks != N // this means more blocks should be checked/set current = current_pos; @@ -1784,12 +1749,12 @@ static bool FreeTerminal(Vehicle *v, byte i, byte last_terminal) return false; } -static int GetNumTerminals(const AirportFTAClass *Airport) +static uint GetNumTerminals(const AirportFTAClass *Airport) { - int i, num = 0; + uint num = 0; + uint i; - for (i = Airport->terminals[0]; i > 0; i--) - num += Airport->terminals[i]; + for (i = Airport->terminals[0]; i > 0; i--) num += Airport->terminals[i]; return num; } @@ -1846,12 +1811,12 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) return FreeTerminal(v, 0, GetNumTerminals(Airport)); } -static int GetNumHelipads(const AirportFTAClass *Airport) +static uint GetNumHelipads(const AirportFTAClass *Airport) { - int i, num = 0; + uint num = 0; + uint i; - for (i = Airport->helipads[0]; i > 0; i--) - num += Airport->helipads[i]; + for (i = Airport->helipads[0]; i > 0; i--) num += Airport->helipads[i]; return num; } @@ -1914,9 +1879,7 @@ static void AircraftEventHandler(Vehicle *v, int loop) return; } - /* exit if aircraft is stopped */ - if (v->vehstatus & VS_STOPPED) - return; + if (v->vehstatus & VS_STOPPED) return; /* aircraft is broken down? */ if (v->breakdown_ctr != 0) { @@ -1931,8 +1894,7 @@ static void AircraftEventHandler(Vehicle *v, int loop) ProcessAircraftOrder(v); HandleAircraftLoading(v, loop); - if (v->current_order.type >= OT_LOADING) - return; + if (v->current_order.type >= OT_LOADING) return; // pass the right airport structure to the functions // DEREF_STATION gets target airport (Station *st), its type is passed to GetAirport @@ -1944,24 +1906,22 @@ void Aircraft_Tick(Vehicle *v) { int i; - if (v->subtype > 2) - return; + if (v->subtype > 2) return; - if (v->subtype == 0) - HelicopterTickHandler(v); + if (v->subtype == 0) HelicopterTickHandler(v); AgeAircraftCargo(v); - for(i=0; i!=6; i++) { + for (i = 0; i != 6; i++) { AircraftEventHandler(v, i); if (v->type != VEH_Aircraft) // In case it was deleted break; } } -void UpdateOilRig( void ) +void UpdateOilRig(void) { - Station *st; + Station* st; FOR_ALL_STATIONS(st) { if (st->airport_type == 5) st->airport_type = AT_OILRIG; @@ -1987,7 +1947,7 @@ void UpdateOldAircraft(void) // skip those if (v_oldstyle->type == VEH_Aircraft && v_oldstyle->subtype <= 2) { // airplane in terminal stopped doesn't hurt anyone, so goto next - if ((v_oldstyle->vehstatus & VS_STOPPED) && (v_oldstyle->u.air.state == 0)) { + if (v_oldstyle->vehstatus & VS_STOPPED && v_oldstyle->u.air.state == 0) { v_oldstyle->u.air.state = HANGAR; continue; } diff --git a/aircraft_gui.c b/aircraft_gui.c index 8cd5c620a0..970ea1673d 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -65,13 +65,11 @@ static void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selectio { int image = GetAircraftImage(v, 6); uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); - if (v->vehstatus & VS_CRASHED) - ormod = PALETTE_CRASH; - DrawSprite(image | ormod, x+25, y+10); - if (v->subtype == 0) - DrawSprite(SPR_ROTOR_STOPPED, x + 25, y + 5); + if (v->vehstatus & VS_CRASHED) ormod = PALETTE_CRASH; + DrawSprite(image | ormod, x + 25, y + 10); + if (v->subtype == 0) DrawSprite(SPR_ROTOR_STOPPED, x + 25, y + 5); if (v->index == selection) { - DrawFrameRect(x-1, y-1, x+58, y+21, 0xF, FR_BORDERONLY); + DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY); } } @@ -90,20 +88,14 @@ void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2) void CcCloneAircraft(bool success, uint tile, uint32 p1, uint32 p2) { - if (success) { - const Vehicle* v = GetVehicle(_new_aircraft_id); - - ShowAircraftViewWindow(v); - } + if (success) ShowAircraftViewWindow(GetVehicle(_new_aircraft_id)); } static void NewAircraftWndProc(Window *w, WindowEvent *e) { - switch(e->event) { - + switch (e->event) { case WE_PAINT: { - if (w->window_number == 0) - SETBIT(w->disabled_state, 5); + if (w->window_number == 0) SETBIT(w->disabled_state, 5); { int count = 0; @@ -111,8 +103,7 @@ static void NewAircraftWndProc(Window *w, WindowEvent *e) const Engine* e = GetEngine(AIRCRAFT_ENGINES_INDEX); do { - if (HASBIT(e->player_avail, _local_player)) - count++; + if (HASBIT(e->player_avail, _local_player)) count++; } while (++e,--num); SetVScrollCount(w, count); } @@ -508,7 +499,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: { const Vehicle* v = GetVehicle(w->window_number); - uint32 disabled = 1<<8; + uint32 disabled = 1 << 8; StringID str; { @@ -520,8 +511,7 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e) disabled = 0; } - if (v->owner != _local_player) - disabled |= 1<<8 | 1<<7; + if (v->owner != _local_player) disabled |= 1 << 8 | 1 << 7; w->disabled_state = disabled; /* draw widgets & caption */ @@ -555,8 +545,9 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e) if (v->num_orders == 0) { str = STR_NO_ORDERS + _patches.vehicle_speed; SetDParam(0, v->cur_speed * 8); - } else + } else { str = STR_EMPTY; + } break; } } @@ -656,9 +647,12 @@ static void DrawAircraftDepotWindow(Window *w) /* determine amount of items for scroller */ num = 0; FOR_ALL_VEHICLES(v) { - if (v->type == VEH_Aircraft && v->subtype <= 2 && v->vehstatus&VS_HIDDEN && - v->tile == tile) - num++; + if (v->type == VEH_Aircraft && + v->subtype <= 2 && + v->vehstatus & VS_HIDDEN && + v->tile == tile) { + num++; + } } SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap); @@ -729,9 +723,12 @@ static void AircraftDepotClickAircraft(Window *w, int x, int y) int mode = GetVehicleFromAircraftDepotWndPt(w, x, y, &v); // share / copy orders - if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; } + if (_thd.place_mode && mode <= 0) { + _place_clicked_vehicle = v; + return; + } - switch(mode) { + switch (mode) { case 1: return; @@ -789,30 +786,31 @@ static void AircraftDepotWndProc(Window *w, WindowEvent *e) case WE_CLICK: switch(e->click.widget) { - case 5: /* click aircraft */ - AircraftDepotClickAircraft(w, e->click.pt.x, e->click.pt.y); - break; - case 7: /* show build aircraft window */ - ResetObjectToPlace(); - ShowBuildAircraftWindow(w->window_number); - break; + case 5: /* click aircraft */ + AircraftDepotClickAircraft(w, e->click.pt.x, e->click.pt.y); + break; - case 8: /* clone button */ - InvalidateWidget(w, 8); - TOGGLEBIT(w->click_state, 8); - - if (HASBIT(w->click_state, 8)) { - _place_clicked_vehicle = NULL; - SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w); - } else { + case 7: /* show build aircraft window */ ResetObjectToPlace(); - } - break; + ShowBuildAircraftWindow(w->window_number); + break; - case 9: /* scroll to tile */ - ResetObjectToPlace(); - ScrollMainWindowToTile(w->window_number); - break; + case 8: /* clone button */ + InvalidateWidget(w, 8); + TOGGLEBIT(w->click_state, 8); + + if (HASBIT(w->click_state, 8)) { + _place_clicked_vehicle = NULL; + SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w); + } else { + ResetObjectToPlace(); + } + break; + + case 9: /* scroll to tile */ + ResetObjectToPlace(); + ScrollMainWindowToTile(w->window_number); + break; } break; @@ -920,7 +918,7 @@ void ShowAircraftDepotWindow(TileIndex tile) Window *w; w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); - if (w) { + if (w != NULL) { w->caption_color = GetTileOwner(tile); w->vscroll.cap = 2; w->hscroll.cap = 4; @@ -950,8 +948,7 @@ static void DrawSmallOrderList(const Vehicle *v, int x, int y) { DrawString(x, y, STR_A036, 0); y += 6; - if (++i == 4) - break; + if (++i == 4) break; } } } @@ -1008,8 +1005,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e) SetVScrollCount(w, vl->list_length); // disable 'Sort By' tooltip on Unsorted sorting criteria - if (vl->sort_type == SORT_BY_UNSORTED) - w->disabled_state |= (1 << 3); + if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3); /* draw the widgets */ { @@ -1137,8 +1133,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e) _sorting.aircraft.criteria = vl->sort_type; // enable 'Sort By' if a sorter criteria is chosen - if (vl->sort_type != SORT_BY_UNSORTED) - CLRBIT(w->disabled_state, 3); + if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3); } SetWindowDirty(w); break; @@ -1198,7 +1193,7 @@ void ShowPlayerAircraft(PlayerID player, StationID station) w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | player); } - if (w) { + if (w != NULL) { w->caption_color = w->window_number; w->vscroll.cap = 4; w->widget[7].unkA = (w->vscroll.cap << 8) + 1; diff --git a/airport.c b/airport.c index afe5b1e3af..f9c62a63bf 100644 --- a/airport.c +++ b/airport.c @@ -376,7 +376,7 @@ uint32 GetValidAirports(void) // 1980-1-1 is --> 21915 // 1990-1-1 is --> 25568 - if (_date >= 21915) {SETBIT(bytemask, 3);} // metropilitan airport 1980 - if (_date >= 25568) {SETBIT(bytemask, 4);} // international airport 1990 + if (_date >= 21915) SETBIT(bytemask, 3); // metropilitan airport 1980 + if (_date >= 25568) SETBIT(bytemask, 4); // international airport 1990 return bytemask; } diff --git a/airport_gui.c b/airport_gui.c index a4c072b971..d5f76fd48c 100644 --- a/airport_gui.c +++ b/airport_gui.c @@ -65,7 +65,7 @@ static OnButtonClick * const _build_air_button_proc[] = { static void BuildAirToolbWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: DrawWindowWidgets(w); break; @@ -156,9 +156,9 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) if (!HASBIT(avail_airports, 0) && sel == AT_SMALL) sel = AT_LARGE; if (!HASBIT(avail_airports, 1) && sel == AT_LARGE) sel = AT_SMALL; - /* 'Country Airport' starts at widget 3, and if its bit is set, it is available, - * so take its opposite value to set the disabled_state. There are only 5 available - * airports, so XOr with 0x1F (1 1111) */ + /* 'Country Airport' starts at widget 3, and if its bit is set, it is + * available, so take its opposite value to set the disabled_state. There + * are only 5 available airports, so XOR with 0x1F (1 1111) */ w->disabled_state = (avail_airports ^ 0x1F) << 3; _selected_airport_type = sel; @@ -177,7 +177,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) } } - if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); + if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); DrawWindowWidgets(w); // strings such as 'Size' and 'Coverage Area' @@ -188,7 +188,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) } case WE_CLICK: { - switch(e->click.widget) { + switch (e->click.widget) { case 3: case 4: case 5: case 6: case 7: _selected_airport_type = e->click.widget - 3; SndPlayFx(SND_15_BEEP); @@ -212,8 +212,7 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) } break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } diff --git a/bridge_gui.c b/bridge_gui.c index ddcc620cb8..be99c25d2a 100644 --- a/bridge_gui.c +++ b/bridge_gui.c @@ -33,7 +33,8 @@ void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2) static void BuildBridge(Window *w, int i) { DeleteWindow(w); - DoCommandP(_bridgedata.end_tile, _bridgedata.start_tile, _bridgedata.indexes[i] | (_bridgedata.type << 8), CcBuildBridge, + DoCommandP(_bridgedata.end_tile, _bridgedata.start_tile, + _bridgedata.indexes[i] | (_bridgedata.type << 8), CcBuildBridge, CMD_BUILD_BRIDGE | CMD_AUTO | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); } diff --git a/clear_cmd.c b/clear_cmd.c index e1a494b517..c79ac608d3 100644 --- a/clear_cmd.c +++ b/clear_cmd.c @@ -37,13 +37,11 @@ static int TerraformAllowTileProcess(TerraformerState *ts, TileIndex tile) TileIndex *t; int count; - if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) - return -1; + if (TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) return -1; t = ts->tile_table; - for(count = ts->tile_table_count; count != 0; count--,t++) { - if (*t == tile) - return 0; + for (count = ts->tile_table_count; count != 0; count--, t++) { + if (*t == tile) return 0; } return 1; @@ -54,9 +52,8 @@ static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile) TerraformerHeightMod *mod = ts->modheight; int count; - for(count = ts->modheight_count; count != 0; count--, mod++) { - if (mod->tile == tile) - return mod->height; + for (count = ts->modheight_count; count != 0; count--, mod++) { + if (mod->tile == tile) return mod->height; } return TileHeight(tile); @@ -69,12 +66,10 @@ static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile) count = ts->tile_table_count; - if (count >= 625) - return; + if (count >= 625) return; for(t = ts->tile_table; count != 0; count--,t++) { - if (*t == tile) - return; + if (*t == tile) return; } ts->tile_table[ts->tile_table_count++] = tile; @@ -116,8 +111,7 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) // If we have a single diagonal track there, the other side of // tile can be terraformed. - if ((_m[tile].m5&~0x40) == _railway_modes[mode]) - return 0; + if ((_m[tile].m5 & ~0x40) == _railway_modes[mode]) return 0; } ret = DoCommandByTile(tile, 0,0, ts->flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR); @@ -129,8 +123,7 @@ static int TerraformProc(TerraformerState *ts, TileIndex tile, int mode) ts->cost += ret; - if (ts->tile_table_count >= 625) - return -1; + if (ts->tile_table_count >= 625) return -1; ts->tile_table[ts->tile_table_count++] = tile; return 0; @@ -151,12 +144,10 @@ static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height _error_message = STR_1004_TOO_HIGH; - if (height > 0xF) - return false; + if (height > 15) return false; nh = TerraformGetHeightOfTile(ts, tile); - if (nh < 0 || height == nh) - return false; + if (nh < 0 || height == nh) return false; if (TerraformProc(ts, tile, 0) < 0) return false; if (TerraformProc(ts, tile + TileDiffXY( 0, -1), 1) < 0) return false; @@ -166,7 +157,7 @@ static bool TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height mod = ts->modheight; count = ts->modheight_count; - for(;;) { + for (;;) { if (count == 0) { if (ts->modheight_count >= 576) return false; @@ -280,8 +271,9 @@ int32 CmdTerraformLand(int x, int y, uint32 flags, uint32 p1, uint32 p2) t = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1)); if (t <= z) z = t; - if (!CheckTunnelInWay(tile, z*8)) + if (!CheckTunnelInWay(tile, z * 8)) { return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE); + } } } @@ -505,8 +497,7 @@ void DrawClearLandFence(const TileInfo *ti) if (ti->tileh & 2) { z += 8; - if (ti->tileh == 0x17) - z += 8; + if (ti->tileh == 0x17) z += 8; } if (GB(m4, 5, 3) != 0) { @@ -697,8 +688,7 @@ static void TileLoopClearAlps(TileIndex tile) static void TileLoopClearDesert(TileIndex tile) { - if ( (_m[tile].m5 & 0x1C) == 0x14) - return; + if ((_m[tile].m5 & 0x1C) == 0x14) return; if (GetMapExtraBits(tile) == 1) { _m[tile].m5 = 0x17; @@ -727,12 +717,10 @@ static void TileLoop_Clear(TileIndex tile) } m5 = _m[tile].m5; - if ( (m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) - return; + if ((m5 & 0x1C) == 0x10 || (m5 & 0x1C) == 0x14) return; - if ( (m5 & 0x1C) != 0xC) { - if ( (m5 & 3) == 3) - return; + if ((m5 & 0x1C) != 0xC) { + if ((m5 & 3) == 3) return; if (_game_mode != GM_EDITOR) { m5 += 0x20; diff --git a/debug.c b/debug.c index c97e5f0a31..16d3fda35b 100644 --- a/debug.c +++ b/debug.c @@ -76,12 +76,11 @@ void SetDebugString(const char *s) v = strtoul(s, &end, 0); s = end; - for (i = debug_level; i != endof(debug_level); ++i) - *i->level = v; + for (i = debug_level; i != endof(debug_level); ++i) *i->level = v; } // individual levels - for(;;) { + for (;;) { const DebugLevel *i; int *p; @@ -103,9 +102,9 @@ void SetDebugString(const char *s) if (*s == '=') s++; v = strtoul(s, &end, 0); s = end; - if (p != NULL) + if (p != NULL) { *p = v; - else { + } else { ShowInfoF("Unknown debug level '%.*s'", s - t, t); return; } diff --git a/disaster_cmd.c b/disaster_cmd.c index 724c7fe670..601bc641e0 100644 --- a/disaster_cmd.c +++ b/disaster_cmd.c @@ -21,8 +21,7 @@ static void DisasterClearSquare(TileIndex tile) { - if (!EnsureNoVehicle(tile)) - return; + if (!EnsureNoVehicle(tile)) return; switch (GetTileType(tile)) { case MP_RAILWAY: @@ -352,7 +351,7 @@ static void DisasterTick_2(Vehicle *v) v->tick_counter++; v->u.disaster.image_override = - (v->current_order.station == 1 && v->tick_counter&4) ? SPR_F_15_FIRING : 0; + (v->current_order.station == 1 && v->tick_counter & 4) ? SPR_F_15_FIRING : 0; GetNewVehiclePos(v, &gp); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); @@ -423,7 +422,7 @@ static void DisasterTick_3(Vehicle *v) v->tick_counter++; v->u.disaster.image_override = - (v->current_order.station == 1 && v->tick_counter&4) ? SPR_AH_64A_FIRING : 0; + (v->current_order.station == 1 && v->tick_counter & 4) ? SPR_AH_64A_FIRING : 0; GetNewVehiclePos(v, &gp); SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos); @@ -843,8 +842,7 @@ static void Disaster4_Init(void) Vehicle *v = ForceAllocateSpecialVehicle(), *u; int x,y; - if (v == NULL) - return; + if (v == NULL) return; x = TileX(Random()) * 16 + 8; @@ -870,8 +868,7 @@ static void Disaster5_Init(void) byte dir; uint32 r; - if (v == NULL) - return; + if (v == NULL) return; r = Random(); x = TileX(r) * 16 + 8; @@ -891,8 +888,7 @@ static void Disaster6_Init(void) byte dir; uint32 r; - if (v == NULL) - return; + if (v == NULL) return; r = Random(); x = TileX(r) * 16 + 8; @@ -964,18 +960,17 @@ static const DisasterYears _dis_years[8] = { static void DoDisaster(void) { - byte buf[8]; + byte buf[lengthof(_dis_years)]; byte year = _cur_year; - int i,j; + uint i; + uint j; - for(i=j=0; i!=lengthof(_dis_years); i++) { - if (year >= _dis_years[i].min && - year < _dis_years[i].max) - buf[j++] = i; + j = 0; + for (i = 0; i != lengthof(_dis_years); i++) { + if (year >= _dis_years[i].min && year < _dis_years[i].max) buf[j++] = i; } - if (j == 0) - return; + if (j == 0) return; _disaster_initprocs[buf[RandomRange(j)]](); } @@ -988,13 +983,11 @@ static void ResetDisasterDelay(void) void DisasterDailyLoop(void) { - if (--_disaster_delay != 0) - return; + if (--_disaster_delay != 0) return; ResetDisasterDelay(); - if (_opt.diff.disasters != 0) - DoDisaster(); + if (_opt.diff.disasters != 0) DoDisaster(); } void StartupDisasters(void) diff --git a/dock_gui.c b/dock_gui.c index a1e14b7260..0c6c97a24d 100644 --- a/dock_gui.c +++ b/dock_gui.c @@ -222,35 +222,39 @@ void ShowBuildDocksToolbar(void) static void BuildDockStationWndProc(Window *w, WindowEvent *e) { - int rad; - - switch(e->event) { + switch (e->event) { case WE_PAINT: { - if (WP(w,def_d).close) - return; + int rad; + + if (WP(w,def_d).close) return; w->click_state = (1<<3) << _station_show_coverage; DrawWindowWidgets(w); rad = (_patches.modified_catchment) ? CA_DOCK : 4; - if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); - else SetTileSelectBigSize(0, 0, 0, 0); + if (_station_show_coverage) { + SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); + } else { + SetTileSelectBigSize(0, 0, 0, 0); + } DrawStringCentered(74, 17, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); DrawStationCoverageAreaText(4, 50, (uint)-1, rad); - } break; + break; + } - case WE_CLICK: { - switch(e->click.widget) { - case 3: case 4: - _station_show_coverage = e->click.widget - 3; - SndPlayFx(SND_15_BEEP); - SetWindowDirty(w); - break; + case WE_CLICK: + switch (e->click.widget) { + case 3: + case 4: + _station_show_coverage = e->click.widget - 3; + SndPlayFx(SND_15_BEEP); + SetWindowDirty(w); + break; } - } break; + break; - case WE_MOUSELOOP: { + case WE_MOUSELOOP: if (WP(w,def_d).close) { DeleteWindow(w); return; @@ -258,11 +262,9 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e) CheckRedrawStationCoverage(w); break; - } case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } @@ -324,13 +326,11 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e) } break; case WE_MOUSELOOP: - if (WP(w,def_d).close) - DeleteWindow(w); + if (WP(w,def_d).close) DeleteWindow(w); break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } diff --git a/economy.c b/economy.c index 6b00291687..c9fcc4157b 100644 --- a/economy.c +++ b/economy.c @@ -72,7 +72,7 @@ void UpdatePlayerHouse(Player *p, uint score) MarkTileDirtyByTile(tile + TileDiffXY(1, 1)); } -int64 CalculateCompanyValue(const Player *p) +int64 CalculateCompanyValue(const Player* p) { PlayerID owner = p->index; int64 value; @@ -647,8 +647,8 @@ static void AddInflation(void) int i; int32 inf = _economy.infl_amount * 54; - for(i=0; i!=NUM_PRICES; i++) { - AddSingleInflation( (int32*)&_price + i, _price_frac + i, inf ); + for (i = 0; i != NUM_PRICES; i++) { + AddSingleInflation((int32*)&_price + i, _price_frac + i, inf); } _economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16); @@ -657,7 +657,7 @@ static void AddInflation(void) _economy.max_loan += 50000; inf = _economy.infl_amount_pr * 54; - for(i=0; i!=NUM_CARGO; i++) { + for (i = 0; i != NUM_CARGO; i++) { AddSingleInflation( (int32*)_cargo_payment_rates + i, _cargo_payment_rates_frac + i, @@ -677,8 +677,7 @@ static void PlayersPayInterest(void) int interest = _economy.interest_rate * 54; FOR_ALL_PLAYERS(p) { - if (!p->is_active) - continue; + if (!p->is_active) continue; _current_player = p->index; SET_EXPENSES_TYPE(EXPENSES_LOAN_INT); @@ -692,8 +691,7 @@ static void PlayersPayInterest(void) static void HandleEconomyFluctuations(void) { - if (_opt.diff.economy == 0) - return; + if (_opt.diff.economy == 0) return; if (--_economy.fluct == 0) { _economy.fluct = - (int)(Random()&3); @@ -985,9 +983,8 @@ static bool CheckSubsidyDuplicate(Subsidy *s) { const Subsidy* ss; - for(ss=_subsidies; ss != endof(_subsidies); ss++) { + for (ss = _subsidies; ss != endof(_subsidies); ss++) { if (s != ss && -// ss->age < 12 && ss->from == s->from && ss->to == s->to && ss->cargo_type == s->cargo_type) { @@ -1333,7 +1330,6 @@ int LoadUnloadVehicle(Vehicle *v) int result = 0; uint16 last_visited; Station *st; - GoodsEntry *ge; int t; uint count, cap; PlayerID old_player; @@ -1349,13 +1345,15 @@ int LoadUnloadVehicle(Vehicle *v) st = GetStation(last_visited = v->last_station_visited); for (; v != NULL; v = v->next) { + GoodsEntry* ge; + if (v->cargo_cap == 0) continue; ge = &st->goods[v->cargo_type]; /* unload? */ if (v->cargo_count != 0) { - if ( v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER) ) { + if (v->cargo_source != last_visited && ge->waiting_acceptance & 0x8000 && !(u->current_order.flags & OF_TRANSFER)) { // deliver goods to the station st->time_since_unload = 0; @@ -1363,7 +1361,7 @@ int LoadUnloadVehicle(Vehicle *v) profit += DeliverGoods(v->cargo_count, v->cargo_type, v->cargo_source, last_visited, v->cargo_days); result |= 1; v->cargo_count = 0; - } else if (u->current_order.flags & ( OF_UNLOAD | OF_TRANSFER) ) { + } else if (u->current_order.flags & (OF_UNLOAD | OF_TRANSFER)) { /* unload goods and let it wait at the station */ st->time_since_unload = 0; diff --git a/engine.c b/engine.c index 8b9e0b01d9..ebbe04cf8f 100644 --- a/engine.c +++ b/engine.c @@ -883,8 +883,7 @@ void EnginesDailyLoop(void) } else { e->flags |= ENGINE_PREVIEWING; e->preview_wait = 20; - if (IS_INTERACTIVE_PLAYER(best_player)) - ShowEnginePreviewWindow(i); + if (IS_INTERACTIVE_PLAYER(best_player)) ShowEnginePreviewWindow(i); } } } @@ -925,12 +924,11 @@ static void NewVehicleAvailable(Engine *e) // In case the player didn't build the vehicle during the intro period, // prevent that player from getting future intro periods for a while. - if (e->flags&ENGINE_INTRODUCING) { + if (e->flags & ENGINE_INTRODUCING) { FOR_ALL_PLAYERS(p) { uint block_preview = p->block_preview; - if (!HASBIT(e->player_avail,p->index)) - continue; + if (!HASBIT(e->player_avail, p->index)) continue; /* We assume the user did NOT build it.. prove me wrong ;) */ p->block_preview = 20; @@ -956,8 +954,7 @@ static void NewVehicleAvailable(Engine *e) e->player_avail = (byte)-1; // Do not introduce new rail wagons - if (IsWagon(index)) - return; + if (IsWagon(index)) return; // make maglev / monorail available FOR_ALL_PLAYERS(p) { diff --git a/engine_gui.c b/engine_gui.c index eb4c35d41b..2cb213064f 100644 --- a/engine_gui.c +++ b/engine_gui.c @@ -65,12 +65,11 @@ static const DrawEngineInfo _draw_engine_list[4] = { static void EnginePreviewWndProc(Window *w, WindowEvent *e) { - const DrawEngineInfo *dei; - int width; - - switch(e->event) { + switch (e->event) { case WE_PAINT: { EngineID engine = w->window_number; + const DrawEngineInfo* dei; + int width; DrawWindowWidgets(w); @@ -91,12 +90,15 @@ static void EnginePreviewWndProc(Window *w, WindowEvent *e) } case WE_CLICK: - switch(e->click.widget) { - case 3: DeleteWindow(w); break; - case 4: - DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW); - DeleteWindow(w); - break; + switch (e->click.widget) { + case 3: + DeleteWindow(w); + break; + + case 4: + DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW); + DeleteWindow(w); + break; } break; } diff --git a/functions.h b/functions.h index a73a828efd..39cbb5dfb2 100644 --- a/functions.h +++ b/functions.h @@ -151,7 +151,7 @@ void InitializeAnimatedTiles(void); /* tunnelbridge_cmd.c */ bool CheckTunnelInWay(TileIndex tile, int z); -bool CheckBridge_Stuff(byte bridge_type, int bridge_len); +bool CheckBridge_Stuff(byte bridge_type, uint bridge_len); uint32 GetBridgeLength(TileIndex begin, TileIndex end); int CalcBridgeLenCostFactor(int x); diff --git a/gfx.c b/gfx.c index 2e3079b621..c8c6d68451 100644 --- a/gfx.c +++ b/gfx.c @@ -1994,7 +1994,6 @@ uint16 GetDrawStringPlayerColor(PlayerID player) { // Get the color for DrawString-subroutines which matches the color // of the player - if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) - return 1; + if (player == OWNER_SPECTATOR || player == OWNER_SPECTATOR - 1) return 1; return (_color_list[_player_colors[player]].window_color_1b) | IS_PALETTE_COLOR; } diff --git a/gfxinit.c b/gfxinit.c index 5e0aa36697..9977536f08 100644 --- a/gfxinit.c +++ b/gfxinit.c @@ -145,7 +145,7 @@ static bool FileMD5(const MD5File file, bool warn) fclose(f); md5_finish(&filemd5state, digest); - return CheckMD5Digest(file, digest, warn); + return CheckMD5Digest(file, digest, warn); } else { // file not found return false; } @@ -321,11 +321,9 @@ static byte _sprite_page_to_load = 0xFF; static void LoadSpriteTables(void) { - uint load_index = 0; + const FileList* files = _use_dos_palette ? &files_dos : &files_win; + uint load_index; uint i; - const FileList *files; // list of grf files to be loaded. Either Windows files or DOS files - - files = _use_dos_palette? &files_dos : &files_win; LoadGrfIndexed(files->basic[0].filename, trg1idx, 0); DupSprite( 2, 130); // non-breaking space medium diff --git a/graph_gui.c b/graph_gui.c index cedca5f462..16329ecb91 100644 --- a/graph_gui.c +++ b/graph_gui.c @@ -224,15 +224,13 @@ static void GraphLegendWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: FOR_ALL_PLAYERS(p) { - if (!p->is_active) - SETBIT(_legend_excludebits, p->index); + if (!p->is_active) SETBIT(_legend_excludebits, p->index); } - w->click_state = ((~_legend_excludebits) << 3); + w->click_state = (~_legend_excludebits) << 3; DrawWindowWidgets(w); FOR_ALL_PLAYERS(p) { - if (!p->is_active) - continue; + if (!p->is_active) continue; DrawPlayerIcon(p->index, 4, 18+p->index*12); @@ -245,7 +243,7 @@ static void GraphLegendWndProc(Window *w, WindowEvent *e) case WE_CLICK: if (IS_INT_INSIDE(e->click.widget, 3, 11)) { - _legend_excludebits ^= (1 << (e->click.widget-3)); + _legend_excludebits ^= (1 << (e->click.widget - 3)); SetWindowDirty(w); InvalidateWindow(WC_INCOME_GRAPH, 0); InvalidateWindow(WC_OPERATING_PROFIT, 0); diff --git a/industry_cmd.c b/industry_cmd.c index 21419f4c40..849c3563b8 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -31,8 +31,7 @@ void IndustryPoolNewBlock(uint start_item) { Industry *i; - FOR_ALL_INDUSTRIES_FROM(i, start_item) - i->index = start_item++; + FOR_ALL_INDUSTRIES_FROM(i, start_item) i->index = start_item++; } /* Initialize the industry-pool */ @@ -251,7 +250,7 @@ static const StringID _industry_close_strings[] = { STR_4833_SUPPLY_PROBLEMS_CAUSE_TO, STR_4832_ANNOUNCES_IMMINENT_CLOSURE, STR_4832_ANNOUNCES_IMMINENT_CLOSURE, - STR_4832_ANNOUNCES_IMMINENT_CLOSURE , + STR_4832_ANNOUNCES_IMMINENT_CLOSURE }; @@ -260,19 +259,20 @@ static void IndustryDrawTileProc1(const TileInfo *ti) const DrawIndustrySpec1Struct *d; uint32 image; - if (!(_m[ti->tile].m1 & 0x80)) - return; + if (!(_m[ti->tile].m1 & 0x80)) return; d = &_draw_industry_spec1[_m[ti->tile].m3]; AddChildSpriteScreen(0x12A7 + d->image_1, d->x, 0); - if ( (image = d->image_2) != 0) - AddChildSpriteScreen(0x12B0 + image - 1, 8, 41); + image = d->image_2; + if (image != 0) AddChildSpriteScreen(0x12B0 + image - 1, 8, 41); - if ( (image = d->image_3) != 0) + image = d->image_3; + if (image != 0) { AddChildSpriteScreen(0x12AC + image - 1, - _drawtile_proc1_x[image-1], _drawtile_proc1_y[image-1]); + _drawtile_proc1_x[image - 1], _drawtile_proc1_y[image - 1]); + } } static void IndustryDrawTileProc2(const TileInfo *ti) @@ -285,17 +285,17 @@ static void IndustryDrawTileProc2(const TileInfo *ti) x = 0; } - AddChildSpriteScreen(0x129F, 22-x, x+24); + AddChildSpriteScreen(0x129F, 22 - x, 24 + x); AddChildSpriteScreen(0x129E, 6, 0xE); } static void IndustryDrawTileProc3(const TileInfo *ti) { if (_m[ti->tile].m1 & 0x80) { - AddChildSpriteScreen(0x128B, 5, - _industry_anim_offs_2[_m[ti->tile].m3]); + AddChildSpriteScreen(0x128B, 5, _industry_anim_offs_2[_m[ti->tile].m3]); + } else { + AddChildSpriteScreen(4746, 3, 67); } - AddChildSpriteScreen(4746, 3, 67); } static void IndustryDrawTileProc4(const TileInfo *ti) @@ -309,7 +309,7 @@ static void IndustryDrawTileProc4(const TileInfo *ti) } if (d->image_2 != 0xFF) { - AddChildSpriteScreen(0x1270, 0x10 - d->image_2*2, 100 + d->image_2); + AddChildSpriteScreen(0x1270, 0x10 - d->image_2 * 2, 100 + d->image_2); } AddChildSpriteScreen(0x126E, 7, d->image_3); @@ -323,8 +323,8 @@ static void DrawCoalPlantSparkles(const TileInfo *ti) image = GB(image, 2, 5); if (image != 0 && image < 7) { AddChildSpriteScreen(image + 0x806, - _coal_plant_sparkles_x[image-1], - _coal_plant_sparkles_y[image-1] + _coal_plant_sparkles_x[image - 1], + _coal_plant_sparkles_y[image - 1] ); } } @@ -348,7 +348,7 @@ static void DrawTile_Industry(TileInfo *ti) /* Pointer to industry */ ind = GetIndustry(_m[ti->tile].m2); - ormod = (ind->color_map+0x307) << PALETTE_SPRITE_START; + ormod = (ind->color_map + 0x307) << PALETTE_SPRITE_START; /* Retrieve pointer to the draw industry tile struct */ dits = &_industry_draw_tile_data[(ti->map5 << 2) | GB(_m[ti->tile].m1, 0, 2)]; @@ -369,13 +369,12 @@ static void DrawTile_Industry(TileInfo *ti) } /* Add industry on top of the ground? */ - if ((image = dits->sprite_2) != 0) { - + image = dits->sprite_2; + if (image != 0) { if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0) image |= ormod; - if (_display_opt & DO_TRANS_BUILDINGS) - MAKE_TRANSPARENT(image); + if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image); AddSortableSpriteToDraw(image, ti->x | (dits->subtile_xy>>4), @@ -385,15 +384,12 @@ static void DrawTile_Industry(TileInfo *ti) dits->dz, z); - if (_display_opt & DO_TRANS_BUILDINGS) - return; + if (_display_opt & DO_TRANS_BUILDINGS) return; } - /* TTDBUG: strange code here, return if AddSortableSpriteToDraw failed? */ - { - int proc; - if ((proc=dits->proc-1) >= 0 ) - _industry_draw_tile_procs[proc](ti); + { + int proc = dits->proc - 1; + if (proc >= 0) _industry_draw_tile_procs[proc](ti); } } @@ -451,9 +447,7 @@ static int32 ClearTile_Industry(TileIndex tile, byte flags) return_cmd_error(STR_4800_IN_THE_WAY); } - if (flags & DC_EXEC) { - DeleteIndustry(i); - } + if (flags & DC_EXEC) DeleteIndustry(i); return 0; } @@ -468,20 +462,17 @@ static const byte _industry_min_cargo[] = { static void TransportIndustryGoods(TileIndex tile) { - Industry *i; - int type; + Industry* i = GetIndustry(_m[tile].m2); uint cw, am; - byte m5; - i = GetIndustry(_m[tile].m2); - - type = i->type; cw = min(i->cargo_waiting[0], 255); - if (cw > _industry_min_cargo[type]/* && i->produced_cargo[0] != 0xFF*/) { + if (cw > _industry_min_cargo[i->type]/* && i->produced_cargo[0] != 0xFF*/) { + byte m5; + i->cargo_waiting[0] -= cw; /* fluctuating economy? */ - if (_economy.fluct <= 0) cw = (cw + 1) >> 1; + if (_economy.fluct <= 0) cw = (cw + 1) / 2; i->last_mo_production[0] += cw; @@ -494,12 +485,11 @@ static void TransportIndustryGoods(TileIndex tile) } } - type = i->type; cw = min(i->cargo_waiting[1], 255); - if (cw > _industry_min_cargo[type]) { + if (cw > _industry_min_cargo[i->type]) { i->cargo_waiting[1] -= cw; - if (_economy.fluct <= 0) cw = (cw + 1) >> 1; + if (_economy.fluct <= 0) cw = (cw + 1) / 2; i->last_mo_production[1] += cw; @@ -717,7 +707,6 @@ static void MakeIndustryTileBigger(TileIndex tile, byte size) } - static void TileLoopIndustryCase161(TileIndex tile) { int dir; @@ -739,8 +728,7 @@ static void TileLoopIndustryCase161(TileIndex tile) EV_BUBBLE ); - if (v != NULL) - v->u.special.unk2 = dir; + if (v != NULL) v->u.special.unk2 = dir; } static void TileLoop_Industry(TileIndex tile) @@ -752,8 +740,7 @@ static void TileLoop_Industry(TileIndex tile) return; } - if (_game_mode == GM_EDITOR) - return; + if (_game_mode == GM_EDITOR) return; TransportIndustryGoods(tile); @@ -768,7 +755,7 @@ static void TileLoop_Industry(TileIndex tile) #define SET_AND_ANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; AddAnimatedTile(tile); } #define SET_AND_UNANIMATE(tile, a, b) { _m[tile].m5 = a; _m[tile].m1 = b; DeleteAnimatedTile(tile); } - switch(_m[tile].m5) { + switch (_m[tile].m5) { case 0x18: // coast line at oilrigs case 0x19: case 0x1A: @@ -819,9 +806,9 @@ static void TileLoop_Industry(TileIndex tile) } break; - case 49: { + case 49: CreateEffectVehicleAbove(TileX(tile) * 16 + 6, TileY(tile) * 16 + 6, 43, EV_SMOKE); - } break; + break; case 143: { @@ -843,9 +830,7 @@ static void TileLoop_Industry(TileIndex tile) break; case 174: - if (CHANCE16(1,3)) { - AddAnimatedTile(tile); - } + if (CHANCE16(1, 3)) AddAnimatedTile(tile); break; } } @@ -1030,15 +1015,17 @@ static void ChopLumberMillTrees(Industry *i) }; TileIndex tile = i->xy; - int dir, a, j; + int a; - if ((_m[tile].m1 & 0x80) == 0) - return; + if ((_m[tile].m1 & 0x80) == 0) return; /* search outwards as a rectangular spiral */ - for(a=1; a!=41; a+=2) { - for(dir=0; dir!=4; dir++) { - j = a; + for (a = 1; a != 41; a += 2) { + uint dir; + + for (dir = 0; dir != 4; dir++) { + int j = a; + do { tile = TILE_MASK(tile); if (IsTileType(tile, MP_TREES)) { @@ -1127,10 +1114,11 @@ static void ProduceIndustryGoods(Industry *i) i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]); i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]); - if (i->type == IT_FARM) + if (i->type == IT_FARM) { MaybePlantFarmField(i); - else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) + } else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) { ChopLumberMillTrees(i); + } } } @@ -1149,12 +1137,10 @@ void OnTick_Industry(void) } } - if (_game_mode == GM_EDITOR) - return; + if (_game_mode == GM_EDITOR) return; FOR_ALL_INDUSTRIES(i) { - if (i->xy != 0) - ProduceIndustryGoods(i); + if (i->xy != 0) ProduceIndustryGoods(i); } } @@ -1180,14 +1166,9 @@ extern bool _ignore_restrictions; /* Oil Rig and Oil Refinery */ static bool CheckNewIndustry_Oil(TileIndex tile, int type) { - if(_ignore_restrictions && _game_mode == GM_EDITOR) - return true; - - if (type != IT_OIL_RIG && _game_mode == GM_EDITOR) - return true; - - if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16) - return true; + if (_game_mode == GM_EDITOR && _ignore_restrictions) return true; + if (_game_mode == GM_EDITOR && type != IT_OIL_RIG) return true; + if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < 16) return true; _error_message = STR_483B_CAN_ONLY_BE_POSITIONED; return false; @@ -1255,7 +1236,7 @@ static bool CheckSuitableIndustryPos(TileIndex tile) uint x = TileX(tile); uint y = TileY(tile); - if ( x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { + if (x < 2 || y < 2 || x > MapMaxX() - 3 || y > MapMaxY() - 3) { _error_message = STR_0239_SITE_UNSUITABLE; return false; } @@ -1270,8 +1251,7 @@ static const Town* CheckMultipleIndustryInTown(TileIndex tile, int type) t = ClosestTownFromTile(tile, (uint)-1); - if (_patches.multiple_industry_per_town) - return t; + if (_patches.multiple_industry_per_town) return t; FOR_ALL_INDUSTRIES(i) { if (i->xy != 0 && @@ -1320,26 +1300,21 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* TileIndex cur_tile = tile + ToTileIndexDiff(it->ti); if (!IsValidTile(cur_tile)) { - if (it->map5 == 0xff) - continue; + if (it->map5 == 0xff) continue; return false; } FindLandscapeHeightByTile(&ti, cur_tile); if (it->map5 == 0xFF) { - if (ti.type != MP_WATER || ti.tileh != 0) - return false; + if (ti.type != MP_WATER || ti.tileh != 0) return false; } else { - if (!EnsureNoVehicle(cur_tile)) - return false; + if (!EnsureNoVehicle(cur_tile)) return false; if (type == IT_OIL_RIG) { - if (ti.type != MP_WATER || ti.map5 != 0) - return false; + if (ti.type != MP_WATER || ti.map5 != 0) return false; } else { - if (ti.type == MP_WATER && ti.map5 == 0) - return false; + if (ti.type == MP_WATER && ti.map5 == 0) return false; if (IsSteepTileh(ti.tileh)) return false; @@ -1347,22 +1322,14 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* int t; byte bits = _industry_map5_bits[it->map5]; - if (bits & 0x10) - return false; + if (bits & 0x10) return false; t = ~ti.tileh; - if (bits & 1 && (t & (1+8))) - return false; - - if (bits & 2 && (t & (4+8))) - return false; - - if (bits & 4 && (t & (1+2))) - return false; - - if (bits & 8 && (t & (2+4))) - return false; + if (bits & 1 && (t & (1 + 8))) return false; + if (bits & 2 && (t & (4 + 8))) return false; + if (bits & 4 && (t & (1 + 2))) return false; + if (bits & 8 && (t & (2 + 4))) return false; } if (type == IT_BANK) { @@ -1376,8 +1343,7 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable* return false; } } else if (type == IT_TOY_SHOP) { - if (DistanceMax(t->xy, cur_tile) > 9) - return false; + if (DistanceMax(t->xy, cur_tile) > 9) return false; if (ti.type != MP_HOUSE) goto do_clear; } else if (type == IT_WATER_TOWER) { if (ti.type != MP_HOUSE) { @@ -1398,9 +1364,8 @@ do_clear: static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) { + const IndustrySpec* spec = &_industry_spec[type]; const Industry* i; - const IndustrySpec *spec; - spec = &_industry_spec[type]; // accepting industries won't be close, not even with patch if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID) @@ -1409,15 +1374,16 @@ static bool CheckIfTooCloseToIndustry(TileIndex tile, int type) FOR_ALL_INDUSTRIES(i) { // check if an industry that accepts the same goods is nearby if (i->xy != 0 && - (DistanceMax(tile, i->xy) <= 14) && + DistanceMax(tile, i->xy) <= 14 && spec->accepts_cargo[0] != CT_INVALID && - spec->accepts_cargo[0] == i->accepts_cargo[0] && - !(_game_mode == GM_EDITOR && - _patches.same_industry_close && - _patches.multiple_industry_per_town)) { - _error_message = STR_INDUSTRY_TOO_CLOSE; - return false; - } + spec->accepts_cargo[0] == i->accepts_cargo[0] && ( + _game_mode != GM_EDITOR || + !_patches.same_industry_close || + !_patches.multiple_industry_per_town + )) { + _error_message = STR_INDUSTRY_TOO_CLOSE; + return false; + } // check "not close to" field. if (i->xy != 0 && @@ -1438,10 +1404,9 @@ static Industry *AllocateIndustry(void) if (i->xy == 0) { uint index = i->index; - if (i->index > _total_industries) - _total_industries = i->index; + if (i->index > _total_industries) _total_industries = i->index; - memset(i, 0, sizeof(Industry)); + memset(i, 0, sizeof(*i)); i->index = index; return i; @@ -1498,8 +1463,7 @@ static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const Ind i->total_production[0] = i->production_rate[0] * 8; i->total_production[1] = i->production_rate[1] * 8; - if (_generating_world == 0) - i->total_production[0] = i->total_production[1] = 0; + if (!_generating_world) i->total_production[0] = i->total_production[1] = 0; i->prod_level = 0x10; @@ -1528,13 +1492,12 @@ static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const Ind if (i->type == IT_FARM || i->type == IT_FARM_2) { tile = i->xy + TileDiffXY(i->width / 2, i->height / 2); - for(j=0; j!=50; j++) { + for (j = 0; j != 50; j++) { int x = Random() % 31 - 16; int y = Random() % 31 - 16; - TileIndex new_tile = TileAddWrap(tile, x, y); + TileIndex new_tile = TileAddWrap(tile, x, y); - if (new_tile != INVALID_TILE) - PlantFarmField(new_tile); + if (new_tile != INVALID_TILE) PlantFarmField(new_tile); } } _industry_sort_dirty = true; @@ -1562,10 +1525,15 @@ int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) /* Check if the to-be built/founded industry is available for this climate. * Unfortunately we have no easy way of checking, except for looping the table */ - { const byte *i; + { + const byte* i; bool found = false; + for (i = &_build_industry_types[_opt_ptr->landscape][0]; i != endof(_build_industry_types[_opt_ptr->landscape]); i++) { - if (*i == p1) {found = true; break;} + if (*i == p1) { + found = true; + break; + } } if (!found) return CMD_ERROR; } @@ -1584,7 +1552,8 @@ int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (!_check_new_industry_procs[spec->check_proc](tile, p1)) return CMD_ERROR; - if ((t = CheckMultipleIndustryInTown(tile, p1)) == NULL) return CMD_ERROR; + t = CheckMultipleIndustryInTown(tile, p1); + if (t == NULL) return CMD_ERROR; num = spec->num_table; itt = spec->table; @@ -1596,10 +1565,10 @@ int32 CmdBuildIndustry(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (!CheckIfTooCloseToIndustry(tile, p1)) return CMD_ERROR; - if ( (i = AllocateIndustry()) == NULL) return CMD_ERROR; + i = AllocateIndustry(); + if (i == NULL) return CMD_ERROR; - if (flags & DC_EXEC) - DoCreateNewIndustry(i, tile, p1, it, t, OWNER_NONE); + if (flags & DC_EXEC) DoCreateNewIndustry(i, tile, p1, it, t, OWNER_NONE); return (_price.build_industry >> 5) * _industry_type_costs[p1]; } @@ -1613,28 +1582,23 @@ Industry *CreateNewIndustry(TileIndex tile, int type) const IndustrySpec *spec; - if (!CheckSuitableIndustryPos(tile)) - return NULL; + if (!CheckSuitableIndustryPos(tile)) return NULL; spec = &_industry_spec[type]; - if (!_check_new_industry_procs[spec->check_proc](tile, type)) - return NULL; + if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL; - if (!(t=CheckMultipleIndustryInTown(tile, type))) - return NULL; + t = CheckMultipleIndustryInTown(tile, type); + if (t == NULL) return NULL; /* pick a random layout */ - it = spec->table[RandomRange(spec->num_table)];; + it = spec->table[RandomRange(spec->num_table)]; - if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) - return NULL; + if (!CheckIfIndustryTilesAreFree(tile, it, type, t)) return NULL; + if (!CheckIfTooCloseToIndustry(tile, type)) return NULL; - if (!CheckIfTooCloseToIndustry(tile, type)) - return NULL; - - if ( (i = AllocateIndustry()) == NULL) - return NULL; + i = AllocateIndustry(); + if (i == NULL) return NULL; DoCreateNewIndustry(i, tile, type, it, t, OWNER_NONE); @@ -1659,18 +1623,17 @@ static void PlaceInitialIndustry(byte type, int amount) num = ScaleByMapSize(num); } - if (_opt.diff.number_industries != 0) - { + if (_opt.diff.number_industries != 0) { PlayerID old_player = _current_player; _current_player = OWNER_NONE; assert(num > 0); do { - int i = 2000; - do { - if (CreateNewIndustry(RandomTile(), type) != NULL) - break; - } while (--i != 0); + uint i; + + for (i = 0; i < 2000; i++) { + if (CreateNewIndustry(RandomTile(), type) != NULL) break; + } } while (--num); _current_player = old_player; @@ -1713,7 +1676,6 @@ static void ExtChangeIndustryProduction(Industry *i) if (CHANCE16I(20 + (i->pct_transported[j] * 20 >> 8), 1024, r >> 16)) new += ((RandomRange(50) + 10) * old) >> 8; - // make sure it doesn't exceed 255 or goes below 0 new = clamp(new, 0, 255); if (new == old) { closeit = false; @@ -1731,9 +1693,11 @@ static void ExtChangeIndustryProduction(Industry *i) SetDParam(2, mag); SetDParam(0, _cargoc.names_s[i->produced_cargo[j]]); SetDParam(1, i->index); - AddNewsItem(percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, - NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), - i->xy + TileDiffXY(1, 1), 0); + AddNewsItem( + percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN, + NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), + i->xy + TileDiffXY(1, 1), 0 + ); } } break; @@ -1742,9 +1706,11 @@ static void ExtChangeIndustryProduction(Industry *i) if (closeit) { i->prod_level = 0; SetDParam(0, i->index); - AddNewsItem(_industry_close_strings[i->type], - NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), - i->xy + TileDiffXY(1, 1), 0); + AddNewsItem( + _industry_close_strings[i->type], + NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), + i->xy + TileDiffXY(1, 1), 0 + ); } } @@ -1787,10 +1753,11 @@ static void UpdateIndustryStatistics(Industry *i) if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID) InvalidateWindow(WC_INDUSTRY_VIEW, i->index); - if (i->prod_level == 0) + if (i->prod_level == 0) { DeleteIndustry(i); - else if (_patches.smooth_economy) + } else if (_patches.smooth_economy) { ExtChangeIndustryProduction(i); + } } static const byte _new_industry_rand[4][32] = { @@ -1807,19 +1774,15 @@ static void MaybeNewIndustry(uint32 r) Industry *i; type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)]; - if (type == IT_OIL_WELL && _date > 10958) - return; - if (type == IT_OIL_RIG && _date < 14610) - return; + if (type == IT_OIL_WELL && _date > 10958) return; + if (type == IT_OIL_RIG && _date < 14610) return; j = 2000; - for(;;) { + for (;;) { i = CreateNewIndustry(RandomTile(), type); - if (i != NULL) - break; - if (--j == 0) - return; + if (i != NULL) break; + if (--j == 0) return; } SetDParam(0, type + STR_4802_COAL_MINE); @@ -1905,8 +1868,7 @@ void IndustryMonthlyLoop(void) _current_player = OWNER_NONE; FOR_ALL_INDUSTRIES(i) { - if (i->xy != 0) - UpdateIndustryStatistics(i); + if (i->xy != 0) UpdateIndustryStatistics(i); } /* 3% chance that we start a new industry */ @@ -1914,8 +1876,7 @@ void IndustryMonthlyLoop(void) MaybeNewIndustry(Random()); } else if (!_patches.smooth_economy && _total_industries > 0) { i = GetIndustry(RandomRange(_total_industries)); - if (i->xy != 0) - ChangeIndustryProduction(i); + if (i->xy != 0) ChangeIndustryProduction(i); } _current_player = old_player; @@ -1928,7 +1889,6 @@ void IndustryMonthlyLoop(void) void InitializeIndustries(void) { - CleanPool(&_industry_pool); AddBlockToPool(&_industry_pool); @@ -2012,8 +1972,7 @@ static void Load_INDY(void) i = GetIndustry(index); SlObject(i, _industry_desc); - if (index > _total_industries) - _total_industries = index; + if (index > _total_industries) _total_industries = index; } } diff --git a/intro_gui.c b/intro_gui.c index 08a7fdbfe3..1521c7b3ee 100644 --- a/intro_gui.c +++ b/intro_gui.c @@ -154,8 +154,9 @@ static const Widget _ask_abandon_game_widgets[] = { { WIDGETS_END }, }; -static void AskAbandonGameWndProc(Window *w, WindowEvent *e) { - switch(e->event) { +static void AskAbandonGameWndProc(Window* w, WindowEvent* e) +{ + switch (e->event) { case WE_PAINT: DrawWindowWidgets(w); #if defined(_WIN32) @@ -173,7 +174,7 @@ static void AskAbandonGameWndProc(Window *w, WindowEvent *e) { #else SetDParam(0, STR_0134_UNIX); #endif - DrawStringMultiCenter(0x5A, 0x26, STR_00CA_ARE_YOU_SURE_YOU_WANT_TO, 178); + DrawStringMultiCenter(90, 38, STR_00CA_ARE_YOU_SURE_YOU_WANT_TO, 178); return; case WE_CLICK: @@ -217,32 +218,29 @@ static const Widget _ask_quit_game_widgets[] = { { WIDGETS_END }, }; -static void AskQuitGameWndProc(Window *w, WindowEvent *e) { - switch(e->event) { - case WE_PAINT: - DrawWindowWidgets(w); - DrawStringMultiCenter(0x5A, 0x26, - _game_mode != GM_EDITOR ? STR_0160_ARE_YOU_SURE_YOU_WANT_TO : - STR_029B_ARE_YOU_SURE_YOU_WANT_TO, - 178); - return; - - case WE_CLICK: - switch(e->click.widget) { - case 3: - DeleteWindow(w); +static void AskQuitGameWndProc(Window* w, WindowEvent* e) +{ + switch (e->event) { + case WE_PAINT: + DrawWindowWidgets(w); + DrawStringMultiCenter( + 90, 38, + _game_mode != GM_EDITOR ? + STR_0160_ARE_YOU_SURE_YOU_WANT_TO : STR_029B_ARE_YOU_SURE_YOU_WANT_TO, + 178 + ); break; - case 4: - _switch_mode = SM_MENU; + + case WE_CLICK: + switch (e->click.widget) { + case 3: DeleteWindow(w); break; + case 4: _switch_mode = SM_MENU; break; + } break; - } - break; - - case WE_KEYPRESS: /* Return to main menu on pressing 'Enter' */ - if (e->keypress.keycode == WKC_RETURN) - _switch_mode = SM_MENU; - break; + case WE_KEYPRESS: /* Return to main menu on pressing 'Enter' */ + if (e->keypress.keycode == WKC_RETURN) _switch_mode = SM_MENU; + break; } } diff --git a/landscape.c b/landscape.c index 8309b18d10..d213fc9139 100644 --- a/landscape.c +++ b/landscape.c @@ -208,16 +208,16 @@ void DrawFoundation(TileInfo *ti, uint f) uint32 sprite_base = SPR_SLOPES_BASE-14; TileInfo ti2; - FindLandscapeHeight(&ti2, ti->x, ti->y-1); - if(hasFoundation( &ti2, true )) sprite_base += 22; // foundation in NW direction - FindLandscapeHeight(&ti2, ti->x-1, ti->y); - if(hasFoundation( &ti2, false )) sprite_base += 22*2; // foundation in NE direction + FindLandscapeHeight(&ti2, ti->x, ti->y - 1); + if (hasFoundation(&ti2, true)) sprite_base += 22; // foundation in NW direction + FindLandscapeHeight(&ti2, ti->x - 1, ti->y); + if (hasFoundation(&ti2, false)) sprite_base += 22 * 2; // foundation in NE direction if (f < 15) { // leveled foundation if (sprite_base < SPR_SLOPES_BASE) sprite_base = SPR_FOUNDATION_BASE + 1; // use original slope sprites - AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z); + AddSortableSpriteToDraw(f - 1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z); ti->z += 8; ti->tileh = 0; OffsetGroundSprite(31, 1); diff --git a/main_gui.c b/main_gui.c index 4ccc585b56..8945f3de6a 100644 --- a/main_gui.c +++ b/main_gui.c @@ -47,7 +47,7 @@ extern bool GenerateTowns(void); void HandleOnEditTextCancel(void) { - switch(_rename_what) { + switch (_rename_what) { #ifdef ENABLE_NETWORK case 4: NetworkDisconnect(); @@ -119,13 +119,11 @@ void HandleOnEditText(WindowEvent *e) * @return true if the button is clicked, false if it's unclicked */ - bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, int mode, PlaceProc *placeproc) { uint32 mask = 1 << widget; - if (w->disabled_state & mask) - return false; + if (w->disabled_state & mask) return false; SndPlayFx(SND_15_BEEP); SetWindowDirty(w); @@ -148,14 +146,11 @@ void CcPlaySound10(bool success, TileIndex tile, uint32 p1, uint32 p2) } -typedef void ToolbarButtonProc(Window *w); - static void ToolbarPauseClick(Window *w) { if (_networking && !_network_server) return; // only server can pause the game - if (DoCommandP(0, _pause ? 0 : 1, 0, NULL, CMD_PAUSE)) - SndPlayFx(SND_15_BEEP); + if (DoCommandP(0, _pause ? 0 : 1, 0, NULL, CMD_PAUSE)) SndPlayFx(SND_15_BEEP); } static void ToolbarFastForwardClick(Window *w) @@ -164,8 +159,6 @@ static void ToolbarFastForwardClick(Window *w) SndPlayFx(SND_15_BEEP); } -typedef void MenuClickedProc(int index); - static void MenuClickSettings(int index) { @@ -389,9 +382,9 @@ void ShowRenameWaypointWindow(const Waypoint *wp) static void SelectSignTool(void) { - if (_cursor.sprite == SPR_CURSOR_SIGN) + if (_cursor.sprite == SPR_CURSOR_SIGN) { ResetObjectToPlace(); - else { + } else { SetObjectToPlace(SPR_CURSOR_SIGN, 1, 1, 0); _place_proc = PlaceProc_Sign; } @@ -431,6 +424,9 @@ static void MenuClickHelp(int index) } } + +typedef void MenuClickedProc(int index); + static MenuClickedProc * const _menu_clicked_procs[] = { NULL, /* 0 */ NULL, /* 1 */ @@ -463,7 +459,7 @@ static MenuClickedProc * const _menu_clicked_procs[] = { static void MenuWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int count,sel; int x,y; @@ -519,16 +515,15 @@ static void MenuWndProc(Window *w, WindowEvent *e) action_id = WP(w,menu_d).action_id; DeleteWindow(w); - if (index >= 0) - _menu_clicked_procs[action_id](index); + if (index >= 0) _menu_clicked_procs[action_id](index); break; } + case WE_POPUPMENU_OVER: { int index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y); - if (index == -1 || index == WP(w,menu_d).sel_index) - return; + if (index == -1 || index == WP(w,menu_d).sel_index) return; WP(w,menu_d).sel_index = index; SetWindowDirty(w); @@ -555,10 +550,7 @@ static int GetPlayerIndexFromMenu(int index) const Player* p; FOR_ALL_PLAYERS(p) { - if (p->is_active) { - if (--index < 0) - return p->index; - } + if (p->is_active && --index < 0) return p->index; } } return -1; @@ -566,19 +558,15 @@ static int GetPlayerIndexFromMenu(int index) static void UpdatePlayerMenuHeight(Window *w) { - int num = 0; + uint num = 0; const Player* p; FOR_ALL_PLAYERS(p) { - if (p->is_active) - num++; + if (p->is_active) num++; } - // Increase one to fit in PlayerList in the menu when - // in network - if (_networking && WP(w,menu_d).main_button == 9) { - num++; - } + // Increase one to fit in PlayerList in the menu when in network + if (_networking && WP(w,menu_d).main_button == 9) num++; if (WP(w,menu_d).item_count != num) { WP(w,menu_d).item_count = num; @@ -594,7 +582,7 @@ extern void DrawPlayerIcon(int p, int x, int y); static void PlayerMenuWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int x,y; byte sel, color; @@ -657,10 +645,10 @@ static void PlayerMenuWndProc(Window *w, WindowEvent *e) // We have a new entry at the top of the list of menu 9 when networking // so keep that in count if (_networking && WP(w,menu_d).main_button == 9) { - if (index > 0) - index = GetPlayerIndexFromMenu(index - 1) + 1; - } else + if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; + } else { index = GetPlayerIndexFromMenu(index); + } if (index < 0) { Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0); @@ -684,13 +672,12 @@ static void PlayerMenuWndProc(Window *w, WindowEvent *e) // We have a new entry at the top of the list of menu 9 when networking // so keep that in count if (_networking && WP(w,menu_d).main_button == 9) { - if (index > 0) - index = GetPlayerIndexFromMenu(index - 1) + 1; - } else + if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; + } else { index = GetPlayerIndexFromMenu(index); + } - if (index == -1 || index == WP(w,menu_d).sel_index) - return; + if (index == -1 || index == WP(w,menu_d).sel_index) return; WP(w,menu_d).sel_index = index; SetWindowDirty(w); @@ -740,11 +727,12 @@ static Window *PopupMainPlayerToolbMenu(Window *w, int x, int main_button, int g WP(w,menu_d).item_count = 0; WP(w,menu_d).sel_index = (_local_player != OWNER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); if (_networking && main_button == 9) { - if (_local_player != OWNER_SPECTATOR) + if (_local_player != OWNER_SPECTATOR) { WP(w,menu_d).sel_index++; - else + } else { /* Select client list by default for spectators */ WP(w,menu_d).sel_index = 0; + } } WP(w,menu_d).action_id = main_button; WP(w,menu_d).main_button = main_button; @@ -809,8 +797,10 @@ static void ToolbarTrainClick(Window *w) { const Vehicle* v; int dis = -1; - FOR_ALL_VEHICLES(v) + + FOR_ALL_VEHICLES(v) { if (v->type == VEH_Train && v->subtype == TS_Front_Engine) CLRBIT(dis, v->owner); + } PopupMainPlayerToolbMenu(w, 310, 13, dis); } @@ -818,8 +808,10 @@ static void ToolbarRoadClick(Window *w) { const Vehicle* v; int dis = -1; - FOR_ALL_VEHICLES(v) + + FOR_ALL_VEHICLES(v) { if (v->type == VEH_Road) CLRBIT(dis, v->owner); + } PopupMainPlayerToolbMenu(w, 332, 14, dis); } @@ -827,8 +819,10 @@ static void ToolbarShipClick(Window *w) { const Vehicle* v; int dis = -1; - FOR_ALL_VEHICLES(v) + + FOR_ALL_VEHICLES(v) { if (v->type == VEH_Ship) CLRBIT(dis, v->owner); + } PopupMainPlayerToolbMenu(w, 354, 15, dis); } @@ -836,8 +830,10 @@ static void ToolbarAirClick(Window *w) { const Vehicle* v; int dis = -1; - FOR_ALL_VEHICLES(v) + + FOR_ALL_VEHICLES(v) { if (v->type == VEH_Aircraft) CLRBIT(dis, v->owner); + } PopupMainPlayerToolbMenu(w, 376, 16, dis); } @@ -882,15 +878,17 @@ bool DoZoomInOutWindow(int how, Window *w) // routine to disable/enable the zoom buttons. Didn't know where to place these otherwise { - Window *wt = NULL; + Window* wt = NULL; + switch (w->window_class) { - case WC_MAIN_WINDOW: - wt = FindWindowById(WC_MAIN_TOOLBAR, 0); - break; - case WC_EXTRA_VIEW_PORT: - wt = FindWindowById(WC_EXTRA_VIEW_PORT, w->window_number); - button = 5; - break; + case WC_MAIN_WINDOW: + wt = FindWindowById(WC_MAIN_TOOLBAR, 0); + break; + + case WC_EXTRA_VIEW_PORT: + wt = FindWindowById(WC_EXTRA_VIEW_PORT, w->window_number); + button = 5; + break; } assert(wt); @@ -1003,8 +1001,7 @@ static void ToolbarScenDateBackward(Window *w) HandleButtonClick(w, 6); InvalidateWidget(w, 5); - if (_date > MinDate) - SetDate(ConvertYMDToDay(_cur_year - 1, 0, 1)); + if (_date > MinDate) SetDate(ConvertYMDToDay(_cur_year - 1, 0, 1)); } _left_button_clicked = false; } @@ -1016,8 +1013,7 @@ static void ToolbarScenDateForward(Window *w) HandleButtonClick(w, 7); InvalidateWidget(w, 5); - if (_date < MaxDate) - SetDate(ConvertYMDToDay(_cur_year + 1, 0, 1)); + if (_date < MaxDate) SetDate(ConvertYMDToDay(_cur_year + 1, 0, 1)); } _left_button_clicked = false; } @@ -1070,7 +1066,7 @@ static void ResetLandscape(void) _random_seeds[0][0] = InteractiveRandom(); _random_seeds[0][1] = InteractiveRandom(); - GenerateWorld(1, 1<<_patches.map_x, 1<<_patches.map_y); + GenerateWorld(1, 1 << _patches.map_x, 1 << _patches.map_y); MarkWholeScreenDirty(); } @@ -1088,13 +1084,17 @@ static void AskResetLandscapeWndProc(Window *w, WindowEvent *e) { uint mode = w->window_number; - switch(e->event) { + switch (e->event) { case WE_PAINT: DrawWindowWidgets(w); - DrawStringMultiCenter(90, 38, mode?STR_022D_ARE_YOU_SURE_YOU_WANT_TO:STR_GENERATE_RANDOM_LANDSCAPE , 168); + DrawStringMultiCenter( + 90, 38, + mode ? STR_022D_ARE_YOU_SURE_YOU_WANT_TO : STR_GENERATE_RANDOM_LANDSCAPE, + 168 + ); break; case WE_CLICK: - switch(e->click.widget) { + switch (e->click.widget) { case 3: DeleteWindow(w); break; @@ -1110,7 +1110,6 @@ static void AskResetLandscapeWndProc(Window *w, WindowEvent *e) SndPlayFx(SND_15_BEEP); _switch_mode = SM_GENRANDLAND; } - break; } break; @@ -1358,7 +1357,7 @@ static void ScenEditLandGenWndProc(Window *w, WindowEvent *e) break; case WE_KEYPRESS: { - int i; + uint i; for (i = 0; i != lengthof(_editor_terraform_keycodes); i++) { if (e->keypress.keycode == _editor_terraform_keycodes[i]) { @@ -1471,7 +1470,7 @@ static const Widget _scen_edit_town_gen_widgets[] = { static void ScenEditTownGenWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: w->click_state = (w->click_state & ~(1<<7 | 1<<8 | 1<<9) ) | (1 << (_new_town_size + 7)); DrawWindowWidgets(w); @@ -1493,8 +1492,9 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e) if (t == NULL) { ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); - } else + } else { ScrollMainWindowToTile(t->xy); + } break; } @@ -1503,8 +1503,9 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e) _generating_world = true; _game_mode = GM_NORMAL; // little hack to avoid towns of the same size - if (!GenerateTowns()) - ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); + if (!GenerateTowns()) { + ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); + } _generating_world = false; _game_mode = GM_EDITOR; @@ -1642,8 +1643,7 @@ static bool AnyTownExists(void) const Town* t; FOR_ALL_TOWNS(t) { - if (t->xy) - return true; + if (t->xy != 0) return true; } return false; } @@ -1695,13 +1695,13 @@ static void ScenEditIndustryWndProc(Window *w, WindowEvent *e) break; case WE_CLICK: - if ((button=e->click.widget) == 3) { + if (e->click.widget == 3) { HandleButtonClick(w, 3); - if (!AnyTownExists()) { - ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); - return; - } + if (!AnyTownExists()) { + ShowErrorMessage(STR_0286_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); + return; + } _generating_world = true; GenerateIndustries(); @@ -1729,7 +1729,7 @@ static void ScenEditIndustryWndProc(Window *w, WindowEvent *e) _ignore_restrictions = true; if (!TryBuildIndustry(e->place.tile,type)) { SetDParam(0, type + STR_4802_COAL_MINE); - ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE,e->place.pt.x, e->place.pt.y); + ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, e->place.pt.x, e->place.pt.y); } _ignore_restrictions = false; _generating_world = false; @@ -1817,6 +1817,9 @@ static void ToolbarBtn_NULL(Window *w) { } + +typedef void ToolbarButtonProc(Window *w); + static ToolbarButtonProc* const _toolbar_button_procs[] = { ToolbarPauseClick, ToolbarFastForwardClick, @@ -1875,7 +1878,7 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e) case WE_KEYPRESS: { PlayerID local = (_local_player != OWNER_SPECTATOR) ? _local_player : 0; - switch(e->keypress.keycode) { + switch (e->keypress.keycode) { case WKC_F1: case WKC_PAUSE: ToolbarPauseClick(w); break; @@ -1924,7 +1927,6 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e) case WE_ON_EDIT_TEXT: HandleOnEditText(e); break; case WE_MOUSELOOP: - if (((w->click_state) & 1) != (uint)!!_pause) { w->click_state ^= (1 << 0); SetWindowDirty(w); @@ -2068,14 +2070,16 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e) switch(e->event) { case WE_PAINT: /* XXX look for better place for these */ - if (_date <= MinDate) + if (_date <= MinDate) { SETBIT(w->disabled_state, 6); - else + } else { CLRBIT(w->disabled_state, 6); - if (_date >= MaxDate) + } + if (_date >= MaxDate) { SETBIT(w->disabled_state, 7); - else + } else { CLRBIT(w->disabled_state, 7); + } // Draw brown-red toolbar bg. GfxFillRect(0, 0, w->width-1, w->height-1, 0xB2); @@ -2093,8 +2097,7 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e) break; case WE_CLICK: { - if (_game_mode == GM_MENU) - return; + if (_game_mode == GM_MENU) return; _scen_toolbar_button_procs[e->click.widget](w); } break; @@ -2111,8 +2114,8 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e) case WKC_F9: ToolbarScenPlaceSign(w); break; case WKC_F10: ShowMusicWindow(); break; case WKC_F11: PlaceLandBlockInfo(); break; - case WKC_CTRL | 'S': _make_screenshot = 1; break; - case WKC_CTRL | 'G': _make_screenshot = 2; break; + case WKC_CTRL | 'S': _make_screenshot = 1; break; + case WKC_CTRL | 'G': _make_screenshot = 2; break; case 'L': ShowEditorTerraformToolBar(); break; } break; } break; @@ -2176,20 +2179,19 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int pos) s = buf; d = buffer; - for(;;s++) { - if (*s == 0) { - *d = 0; + for (;; s++) { + if (*s == '\0') { + *d = '\0'; break; } else if (*s == 0x0D) { d[0] = d[1] = d[2] = d[3] = ' '; - d+=4; + d += 4; } else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) { *d++ = *s; } } - if (!FillDrawPixelInfo(&tmp_dpi, NULL, 141, 1, 358, 11)) - return true; + if (!FillDrawPixelInfo(&tmp_dpi, NULL, 141, 1, 358, 11)) return true; old_dpi = _cur_dpi; _cur_dpi = &tmp_dpi; @@ -2208,7 +2210,9 @@ static void StatusBarWndProc(Window *w, WindowEvent *e) DrawWindowWidgets(w); SetDParam(0, _date); - DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0); + DrawStringCentered( + 70, 1, (_pause || _patches.status_long_date) ? STR_00AF : STR_00AE, 0 + ); if (p != NULL) { // Draw player money @@ -2228,7 +2232,7 @@ static void StatusBarWndProc(Window *w, WindowEvent *e) if (!DrawScrollingStatusText(&_statusbar_news_item, WP(w,def_d).data_1)) WP(w,def_d).data_1 = -1280; } else { - if (p) { + if (p != NULL) { // This is the default text SetDParam(0, p->name_1); SetDParam(1, p->name_2); @@ -2334,65 +2338,64 @@ static void MainWindowWndProc(Window *w, WindowEvent *e) { break; } - // check to see if Command-Q has been pressed on a Mac - // must be done before checking if we are at the main menu - if ( (e->keypress.keycode == ('Q' | WKC_CTRL)) || (e->keypress.keycode == ('Q' | WKC_META)) ) - { - AskExitGame(); + switch (e->keypress.keycode) { + case 'Q' | WKC_CTRL: + case 'Q' | WKC_META: + AskExitGame(); + break; } if (_game_mode == GM_MENU) break; switch (e->keypress.keycode) { - case 'C': case 'Z': { - Point pt = GetTileBelowCursor(); - if (pt.x != -1) { - ScrollMainWindowTo(pt.x, pt.y); - if (e->keypress.keycode == 'Z') - MaxZoomIn(); + case 'C': + case 'Z': { + Point pt = GetTileBelowCursor(); + if (pt.x != -1) { + ScrollMainWindowTo(pt.x, pt.y); + if (e->keypress.keycode == 'Z') MaxZoomIn(); + } + break; } - break; - } - case WKC_ESC: ResetObjectToPlace(); break; - case WKC_DELETE: DeleteNonVitalWindows(); break; - case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break; - case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break; + case WKC_ESC: ResetObjectToPlace(); break; + case WKC_DELETE: DeleteNonVitalWindows(); break; + case WKC_DELETE | WKC_SHIFT: DeleteAllNonVitalWindows(); break; + case 'R' | WKC_CTRL: MarkWholeScreenDirty(); break; + #if defined(_DEBUG) - case '0' | WKC_ALT: /* Crash the game */ - *(byte*)0 = 0; - break; - case '1' | WKC_ALT: /* Gimme money */ - /* Server can not cheat in advertise mode either! */ - #ifdef ENABLE_NETWORK - if (!_networking || !_network_server || !_network_advertise) - #endif - DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT); - break; - case '2' | WKC_ALT: /* Update the coordinates of all station signs */ - UpdateAllStationVirtCoord(); - break; - case '3' | WKC_ALT: - case '4' | WKC_ALT: - break; + case '0' | WKC_ALT: /* Crash the game */ + *(byte*)0 = 0; + break; + + case '1' | WKC_ALT: /* Gimme money */ + /* Server can not cheat in advertise mode either! */ +#ifdef ENABLE_NETWORK + if (!_networking || !_network_server || !_network_advertise) +#endif + DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT); + break; + + case '2' | WKC_ALT: /* Update the coordinates of all station signs */ + UpdateAllStationVirtCoord(); + break; #endif - case 'X': - _display_opt ^= DO_TRANS_BUILDINGS; - MarkWholeScreenDirty(); - break; + case 'X': + _display_opt ^= DO_TRANS_BUILDINGS; + MarkWholeScreenDirty(); + break; #ifdef ENABLE_NETWORK - case WKC_RETURN: case 'T' | WKC_SHIFT: - if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); - break; + case WKC_RETURN: case 'T' | WKC_SHIFT: + if (_networking) ShowNetworkChatQueryWindow(DESTTYPE_BROADCAST, 0); + break; #endif - default: return; + default: return; } e->keypress.cont = false; break; - } } @@ -2402,11 +2405,11 @@ extern void ShowJoinStatusWindowAfterJoin(void); void SetupColorsAndInitialWindow(void) { - int i; + uint i; Window *w; int width,height; - for(i=0; i!=16; i++) { + for (i = 0; i != 16; i++) { const byte* b = GetNonSprite(0x307 + i); assert(b); @@ -2417,7 +2420,7 @@ void SetupColorsAndInitialWindow(void) height = _screen.height; // XXX: these are not done - switch(_game_mode) { + switch (_game_mode) { case GM_MENU: w = AllocateWindow(0, 0, width, height, MainWindowWndProc, WC_MAIN_WINDOW, NULL); AssignWindowViewport(w, 0, 0, width, height, TileXY(32, 32), 0); diff --git a/misc_gui.c b/misc_gui.c index c40f3bc3ff..8e9bfbb866 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -86,7 +86,10 @@ static void LandInfoWndProc(Window *w, WindowEvent *e) for (i = 0; i < NUM_CARGO; ++i) { if (lid->ac[i] > 0) { // Add a comma between each item. - if (found) { *p++ = ','; *p++ = ' '; } + if (found) { + *p++ = ','; + *p++ = ' '; + } found = true; // If the accepted value is less than 8, show it in 1/8:ths @@ -101,8 +104,7 @@ static void LandInfoWndProc(Window *w, WindowEvent *e) } } - if (found) - DrawStringMultiCenter(140, 76, BindCString(buf), 276); + if (found) DrawStringMultiCenter(140, 76, BindCString(buf), 276); } if (lid->td.build_date != 0) { @@ -221,7 +223,7 @@ static const char *credits[] = { static void AboutWindowProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_CREATE: /* Set up window counter and start position of scroller */ WP(w, scroller_d).counter = 0; WP(w, scroller_d).height = w->height - 40; @@ -292,7 +294,7 @@ static const uint32 _tree_sprites[] = { static void BuildTreesWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int x,y; int i, count; @@ -308,24 +310,24 @@ static void BuildTreesWndProc(Window *w, WindowEvent *e) DrawSprite(_tree_sprites[i], x, y); x += 35; if (!(++i & 3)) { - x -= 35*4; + x -= 35 * 4; y += 47; } } while (--count); } break; case WE_CLICK: { - int wid; + int wid = e->click.widget; - switch(wid=e->click.widget) { + switch (wid) { case 0: ResetObjectToPlace(); - return; + break; + case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11:case 12: case 13: case 14: - if ( (uint)(wid-3) >= (uint)WP(w,tree_d).count) - return; + if (wid - 3 >= WP(w,tree_d).count) break; if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, 1, NULL)) _tree_to_plant = WP(w,tree_d).base + wid - 3; @@ -462,7 +464,7 @@ static const Widget _errmsg_face_widgets[] = { static void ErrmsgWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); DrawWindowWidgets(w); @@ -498,18 +500,17 @@ static void ErrmsgWndProc(Window *w, WindowEvent *e) break; case WE_MOUSELOOP: - if (_right_button_down) - DeleteWindow(w); + if (_right_button_down) DeleteWindow(w); break; + case WE_4: - if (!--_errmsg_duration) - DeleteWindow(w); + if (--_errmsg_duration == 0) DeleteWindow(w); break; - case WE_DESTROY: { + + case WE_DESTROY: SetRedErrorSquare(0); _switch_mode_errorstr = INVALID_STRING_ID; break; - } case WE_KEYPRESS: if (e->keypress.keycode == WKC_SPACE) { @@ -619,18 +620,16 @@ static const Widget _tooltips_widgets[] = { static void TooltipsWndProc(Window *w, WindowEvent *e) { + switch (e->event) { + case WE_PAINT: + GfxFillRect(0, 0, w->width - 1, w->height - 1, 0); + GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44); + DrawStringMultiCenter((w->width >> 1), (w->height >> 1) - 5, WP(w,tooltips_d).string_id, 197); + break; - switch(e->event) { - case WE_PAINT: { - GfxFillRect(0, 0, w->width - 1, w->height - 1, 0); - GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44); - DrawStringMultiCenter((w->width>>1), (w->height>>1)-5, WP(w,tooltips_d).string_id, 197); - break; - } - case WE_MOUSELOOP: - if (!_right_button_down) - DeleteWindow(w); - break; + case WE_MOUSELOOP: + if (!_right_button_down) DeleteWindow(w); + break; } } @@ -641,8 +640,7 @@ void GuiShowTooltips(StringID string_id) int right,bottom; int x,y; - if (string_id == 0) - return; + if (string_id == 0) return; w = FindWindowById(WC_TOOLTIPS, 0); if (w != NULL) { @@ -941,8 +939,7 @@ bool HandleCaret(Textbuf *tb) void HandleEditBox(Window *w, int wid) { - if (HandleCaret(&WP(w, querystr_d).text)) - InvalidateWidget(w, wid); + if (HandleCaret(&WP(w, querystr_d).text)) InvalidateWidget(w, wid); } void DrawEditBox(Window *w, int wid) @@ -1012,7 +1009,7 @@ press_ok:; } break; case WE_KEYPRESS: { - switch(HandleEditBoxKey(w, 5, e)) { + switch (HandleEditBoxKey(w, 5, e)) { case 1: // Return goto press_ok; case 2: // Escape @@ -1240,12 +1237,16 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e) case WE_CREATE: { /* Set up OPENTTD button */ o_dir.type = FIOS_TYPE_DIRECT; switch (_saveload_mode) { - case SLD_SAVE_GAME: case SLD_LOAD_GAME: + case SLD_SAVE_GAME: + case SLD_LOAD_GAME: ttd_strlcpy(&o_dir.name[0], _path.save_dir, sizeof(o_dir.name)); break; - case SLD_SAVE_SCENARIO: case SLD_LOAD_SCENARIO: + + case SLD_SAVE_SCENARIO: + case SLD_LOAD_SCENARIO: ttd_strlcpy(&o_dir.name[0], _path.scenario_dir, sizeof(o_dir.name)); break; + default: ttd_strlcpy(&o_dir.name[0], _path.personal_dir, sizeof(o_dir.name)); } @@ -1308,12 +1309,12 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e) char *name; const FiosItem *file; - if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) - return; + if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return; file = _fios_list + y; - if ((name = FiosBrowseTo(file)) != NULL) { + name = FiosBrowseTo(file); + if (name != NULL) { if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) { _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD; @@ -1474,8 +1475,9 @@ void ShowSaveLoadDialog(int mode) // pause is only used in single-player, non-editor mode, non-menu mode. It // will be unpaused in the WE_DESTROY event handler. - if(_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) + if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) { DoCommandP(0, 1, 0, NULL, CMD_PAUSE); + } BuildFileList(); @@ -1500,9 +1502,11 @@ static const Widget _select_scenario_widgets[] = { { WIDGETS_END}, }; -static void SelectScenarioWndProc(Window *w, WindowEvent *e) { +static void SelectScenarioWndProc(Window* w, WindowEvent* e) +{ const int list_start = 45; - switch(e->event) { + + switch (e->event) { case WE_PAINT: { int y,pos; @@ -1642,8 +1646,8 @@ static int32 ClickMoneyCheat(int32 p1, int32 p2) // p1 player to set to, p2 is -1 or +1 (down/up) static int32 ClickChangePlayerCheat(int32 p1, int32 p2) { - while(p1 >= 0 && p1 < MAX_PLAYERS) { - if (_players[p1].is_active) { + while (p1 >= 0 && p1 < MAX_PLAYERS) { + if (_players[p1].is_active) { _local_player = p1; MarkWholeScreenDirty(); return _local_player; @@ -1657,8 +1661,8 @@ static int32 ClickChangePlayerCheat(int32 p1, int32 p2) // p1 -1 or +1 (down/up) static int32 ClickChangeClimateCheat(int32 p1, int32 p2) { - if(p1==-1) p1 = 3; - if(p1==4) p1 = 0; + if (p1 == -1) p1 = 3; + if (p1 == 4) p1 = 0; _opt.landscape = p1; GfxLoadSprites(); MarkWholeScreenDirty(); @@ -1673,7 +1677,7 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2) YearMonthDay ymd; ConvertDayToYMD(&ymd, _date); - if((ymd.year==0 && p2==-1) || (ymd.year==170 && p2==1)) return _cur_year; + if ((ymd.year == 0 && p2 == -1) || (ymd.year == 170 && p2 == 1)) return _cur_year; SetDate(ConvertYMDToDay(_cur_year + p2, ymd.month, ymd.day)); EnginesMonthlyLoop(); @@ -1761,11 +1765,9 @@ extern void DrawPlayerIcon(int p, int x, int y); static void CheatsWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int clk = WP(w,def_d).data_1; - const CheatEntry *ce = &_cheats_ui[0]; - int32 val; int x, y; int i; @@ -1773,53 +1775,55 @@ static void CheatsWndProc(Window *w, WindowEvent *e) DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, 350); - x=0; - y=45; + x = 0; + y = 45; + + for (i = 0; i != lengthof(_cheats_ui); i++) { + const CheatEntry* ce = &_cheats_ui[i]; - for(i=0; i!=lengthof(_cheats_ui); i++,ce++) { DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, x + 5, y + 2); if (ce->type == CE_BOOL) { - DrawFrameRect(x+20, y+1, x+30+9, y+9, (*(bool*)ce->variable) ? 6 : 4, (*(bool*)ce->variable) ? FR_LOWERED : 0); + DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, (*(bool*)ce->variable) ? 6 : 4, (*(bool*)ce->variable) ? FR_LOWERED : 0); SetDParam(0, *(bool*)ce->variable ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); - } else if (ce->type == CE_CLICK) { - DrawFrameRect(x+20, y+1, x+30+9, y+9, 0, (WP(w,def_d).data_1 == i*2+1) ? FR_LOWERED : 0); - if (i == 0) - SetDParam64(0, (int64) 10000000); - else + DrawFrameRect(x + 20, y + 1, x + 30 + 9, y + 9, 0, (WP(w,def_d).data_1 == i * 2 + 1) ? FR_LOWERED : 0); + if (i == 0) { + SetDParam64(0, 10000000); + } else { SetDParam(0, false); - + } } else { - DrawFrameRect(x+20, y+1, x+20+9, y+9, 3, clk == i*2+1 ? FR_LOWERED : 0); - DrawFrameRect(x+30, y+1, x+30+9, y+9, 3, clk == i*2+2 ? FR_LOWERED : 0); - DrawStringCentered(x+25, y+1, STR_6819, 0); - DrawStringCentered(x+35, y+1, STR_681A, 0); + int32 val; + + DrawFrameRect(x + 20, y + 1, x + 20 + 9, y + 9, 3, clk == i * 2 + 1 ? FR_LOWERED : 0); + DrawFrameRect(x + 30, y + 1, x + 30 + 9, y + 9, 3, clk == i * 2 + 2 ? FR_LOWERED : 0); + DrawStringCentered(x + 25, y + 1, STR_6819, 0); + DrawStringCentered(x + 35, y + 1, STR_681A, 0); val = ReadCE(ce); // set correct string for switch climate cheat - if(ce->str==STR_CHEAT_SWITCH_CLIMATE) - val += STR_TEMPERATE_LANDSCAPE; + if (ce->str == STR_CHEAT_SWITCH_CLIMATE) val += STR_TEMPERATE_LANDSCAPE; SetDParam(0, val); // display date for change date cheat - if(ce->str==STR_CHEAT_CHANGE_DATE) - SetDParam(0, _date); + if (ce->str == STR_CHEAT_CHANGE_DATE) SetDParam(0, _date); // draw colored flag for change player cheat - if(ce->str==STR_CHEAT_CHANGE_PLAYER) - DrawPlayerIcon(_current_player, 156, y+2); - + if (ce->str == STR_CHEAT_CHANGE_PLAYER) { + DrawPlayerIcon(_current_player, 156, y + 2); + } } - DrawString(50, y+1, ce->str, 0); + DrawString(50, y + 1, ce->str, 0); - y+=12; + y += 12; } break; } + case WE_CLICK: { const CheatEntry *ce; uint btn = (e->click.pt.y - 46) / 12; @@ -1827,19 +1831,17 @@ static void CheatsWndProc(Window *w, WindowEvent *e) uint x = e->click.pt.x; // not clicking a button? - if(!IS_INT_INSIDE(x, 20, 40) || btn>=lengthof(_cheats_ui)) - break; + if (!IS_INT_INSIDE(x, 20, 40) || btn >= lengthof(_cheats_ui)) break; ce = &_cheats_ui[btn]; oval = val = ReadCE(ce); *ce->been_used = true; - switch(ce->type) { + switch (ce->type) { case CE_BOOL: { val ^= 1; - if (ce->click_proc != NULL) - ce->click_proc(val, 0); + if (ce->click_proc != NULL) ce->click_proc(val, 0); break; } @@ -1861,11 +1863,11 @@ static void CheatsWndProc(Window *w, WindowEvent *e) } // take whatever the function returns - val = ce->click_proc(val, (x>=30) ? 1 : -1); - - if (val != oval) - WP(w,def_d).data_1 = btn * 2 + 1 + ((x>=30) ? 1 : 0); + val = ce->click_proc(val, (x >= 30) ? 1 : -1); + if (val != oval) { + WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0); + } break; } } @@ -1886,6 +1888,7 @@ static void CheatsWndProc(Window *w, WindowEvent *e) break; } } + static const WindowDesc _cheats_desc = { 240, 22, 400, 160, WC_CHEATS,0, diff --git a/music_gui.c b/music_gui.c index 353531b567..ace9ed942a 100644 --- a/music_gui.c +++ b/music_gui.c @@ -20,11 +20,11 @@ static byte _cur_playlist[33]; static byte _playlist_all[] = { - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 0 }; static byte _playlist_old_style[] = { - 1, 8, 2, 9, 14, 15, 19, 13, 0, + 1, 8, 2, 9, 14, 15, 19, 13, 0 }; static byte _playlist_new_style[] = { @@ -45,7 +45,7 @@ static byte * const _playlists[] = { }; // Map the order of the song names to the numbers of the midi filenames -static const int midi_idx[] = { +static const byte midi_idx[] = { 0, // Tycoon DELUXE Theme 2, // Easy Driver 3, // Little Red Diesel @@ -78,8 +78,7 @@ static void SkipToPrevSong(void) byte t; // empty playlist - if (b[0] == 0) - return; + if (b[0] == 0) return; // find the end do p++; while (p[0] != 0); @@ -97,10 +96,12 @@ static void SkipToPrevSong(void) static void SkipToNextSong(void) { - byte *b = _cur_playlist, t; + byte* b = _cur_playlist; + byte t; - if ((t=b[0]) != 0) { - while (b[1]) { + t = b[0]; + if (t != 0) { + while (b[1] != 0) { b[0] = b[1]; b++; } @@ -165,8 +166,7 @@ static void PlayPlaylistSong(void) { if (_cur_playlist[0] == 0) { SelectSongToPlay(); - if (_cur_playlist[0] == 0) - return; + if (_cur_playlist[0] == 0) return; } _music_wnd_cursong = _cur_playlist[0]; DoPlaySong(); @@ -189,16 +189,16 @@ void MusicLoop(void) PlayPlaylistSong(); } - if (_song_is_active == false) - return; + if (_song_is_active == false) return; if (!_music_driver->is_song_playing()) { if (_game_mode != GM_MENU) { StopMusic(); SkipToNextSong(); PlayPlaylistSong(); - } else + } else { ResetMusic(); + } } } @@ -229,18 +229,18 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) DrawString(4, 23+(i-1)*6, (i < 10) ? STR_01EC_0 : STR_01ED, 0); } - for(i=0; i!=6; i++) { - DrawStringCentered(216, 45 + i*8, STR_01D5_ALL + i, (i==msf.playlist) ? 0xC : 0x10); + for (i = 0; i != 6; i++) { + DrawStringCentered(216, 45 + i * 8, STR_01D5_ALL + i, (i == msf.playlist) ? 0xC : 0x10); } DrawStringCentered(216, 45+8*6+16, STR_01F0_CLEAR, 0); DrawStringCentered(216, 45+8*6+16*2, STR_01F1_SAVE, 0); y = 23; - for(p = _playlists[msf.playlist],i=0; (i=*p) != 0; p++) { + for (p = _playlists[msf.playlist], i = 0; (i = *p) != 0; p++) { SetDParam(0, i); - SetDParam(2, i); SetDParam(1, SPECSTR_SONGNAME); + SetDParam(2, i); DrawString(252, y, (i < 10) ? STR_01EC_0 : STR_01ED, 0); y += 6; } @@ -248,19 +248,20 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e) } case WE_CLICK: - switch(e->click.widget) { + switch (e->click.widget) { case 3: { /* add to playlist */ int y = (e->click.pt.y - 23) / 6; - int i; + uint i; byte *p; + if (msf.playlist < 4) return; - if ((uint)y >= NUM_SONGS_AVAILABLE) return; + if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return; p = _playlists[msf.playlist]; - for(i=0; i!=32; i++) { + for (i = 0; i != 32; i++) { if (p[i] == 0) { - p[i] = (byte)(y + 1); - p[i+1] = 0; + p[i] = y + 1; + p[i + 1] = 0; SetWindowDirty(w); SelectSongToPlay(); break; @@ -323,7 +324,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) { switch(e->event) { case WE_PAINT: { - int i,num; + uint i; StringID str; w->click_state |= 0x280; @@ -331,8 +332,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) GfxFillRect(187, 16, 200, 33, 0); - num = 8; - for (i=0; i!=num; i++) { + for (i = 0; i != 8; i++) { int color = 0xD0; if (i > 4) { color = 0xBF; @@ -340,17 +340,16 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) color = 0xB8; } } - GfxFillRect(187, 33 - i*2, 200, 33 - i*2, color); + GfxFillRect(187, 33 - i * 2, 200, 33 - i * 2, color); } GfxFillRect(60, 46, 239, 52, 0); - str = STR_01E3; - if (_song_is_active != 0 && _music_wnd_cursong != 0) { - str = STR_01E4_0; + if (_song_is_active == 0 || _music_wnd_cursong == 0) { + str = STR_01E3; + } else { SetDParam(0, _music_wnd_cursong); - if (_music_wnd_cursong >= 10) - str = STR_01E5; + str = (_music_wnd_cursong < 10) ? STR_01E4_0 : STR_01E5; } DrawString(62, 46, str, 0); @@ -365,8 +364,8 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e) DrawString(60, 38, STR_01E8_TRACK_XTITLE, 0); - for(i=0; i!=6; i++) { - DrawStringCentered(25+i*50, 59, STR_01D5_ALL+i, msf.playlist == i ? 0xC : 0x10); + for (i = 0; i != 6; i++) { + DrawStringCentered(25 + i * 50, 59, STR_01D5_ALL + i, msf.playlist == i ? 0xC : 0x10); } DrawStringCentered(31, 43, STR_01E9_SHUFFLE, (msf.shuffle ? 0xC : 0x10)); diff --git a/network.c b/network.c index 6143c79251..0bee0b6dbb 100644 --- a/network.c +++ b/network.c @@ -1257,7 +1257,7 @@ static void NetworkGenerateUniqueId(void) /* Generate the MD5 hash */ md5_init(&state); - md5_append(&state, coding_string, strlen(coding_string)); + md5_append(&state, (const md5_byte_t*)coding_string, strlen(coding_string)); md5_finish(&state, digest); for (di = 0; di < 16; ++di) diff --git a/network_gui.c b/network_gui.c index c99e105389..e3dbac77ec 100644 --- a/network_gui.c +++ b/network_gui.c @@ -62,11 +62,10 @@ static FiosItem *_selected_map = NULL; // to highlight slected map // called when a new server is found on the network void UpdateNetworkGameWindow(bool unselect) { - Window *w; - w = FindWindowById(WC_NETWORK_WINDOW, 0); + Window* w = FindWindowById(WC_NETWORK_WINDOW, 0); + if (w != NULL) { - if (unselect) - _selected_item = NULL; + if (unselect) _selected_item = NULL; w->vscroll.count = _network_game_count; SetWindowDirty(w); } @@ -123,8 +122,8 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) while (cur_item != NULL) { bool compatible = - !strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) || - !strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision)); + strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) == 0 || + strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision) == 0); if (cur_item == sel) GfxFillRect(11, y - 2, 218, y + 9, 10); // show highlighted item with a different colour @@ -138,10 +137,8 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) // only draw icons if the server is online if (cur_item->online) { - // draw a lock if the server is password protected. - if(cur_item->info.use_password) - DrawSprite(SPR_LOCK, 186, y-1); + if (cur_item->info.use_password) DrawSprite(SPR_LOCK, 186, y - 1); // draw red or green icon, depending on compatibility with server. DrawSprite(SPR_BLOT | (compatible ? PALETTE_TO_GREEN : PALETTE_TO_RED), 195, y); @@ -180,43 +177,43 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) SetDParam(0, sel->info.clients_on); SetDParam(1, sel->info.clients_max); DrawString(260, y, STR_NETWORK_CLIENTS, 2); // clients on the server / maximum slots - y+=10; + y += 10; if (sel->info.server_lang < NETWORK_NUM_LANGUAGES) { - SetDParam(0, STR_NETWORK_LANG_ANY+sel->info.server_lang); + SetDParam(0, STR_NETWORK_LANG_ANY + sel->info.server_lang); DrawString(260, y, STR_NETWORK_LANGUAGE, 2); // server language } - y+=10; + y += 10; if (sel->info.map_set < NUM_LANDSCAPE ) { - SetDParam(0, STR_TEMPERATE_LANDSCAPE+sel->info.map_set); + SetDParam(0, STR_TEMPERATE_LANDSCAPE + sel->info.map_set); DrawString(260, y, STR_NETWORK_TILESET, 2); // tileset } - y+=10; + y += 10; SetDParam(0, sel->info.map_width); SetDParam(1, sel->info.map_height); DrawString(260, y, STR_NETWORK_MAP_SIZE, 2); // map size - y+=10; + y += 10; SetDParamStr(0, sel->info.server_revision); DrawString(260, y, STR_NETWORK_SERVER_VERSION, 2); // server version - y+=10; + y += 10; SetDParamStr(0, sel->info.hostname); SetDParam(1, sel->port); DrawString(260, y, STR_NETWORK_SERVER_ADDRESS, 2); // server address - y+=10; + y += 10; SetDParam(0, sel->info.start_date); DrawString(260, y, STR_NETWORK_START_DATE, 2); // start date - y+=10; + y += 10; SetDParam(0, sel->info.game_date); DrawString(260, y, STR_NETWORK_CURRENT_DATE, 2); // current date - y+=10; + y += 10; - y+=2; + y += 2; if (strncmp(sel->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) { if (strncmp(sel->info.server_revision, NOREV_STRING, sizeof(sel->info.server_revision)) != 0) @@ -224,10 +221,11 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) } else if (sel->info.clients_on == sel->info.clients_max) { // Show: server full, when clients_on == clients_max DrawStringMultiCenter(365, y, STR_NETWORK_SERVER_FULL, 2); // server full - } else if (sel->info.use_password) + } else if (sel->info.use_password) { DrawStringMultiCenter(365, y, STR_NETWORK_PASSWORD, 2); // password warning + } - y+=10; + y += 10; } } break; @@ -306,9 +304,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) break; case WE_MOUSELOOP: - if (_selected_field == 3) - HandleEditBox(w, 3); - + if (_selected_field == 3) HandleEditBox(w, 3); break; case WE_KEYPRESS: @@ -331,10 +327,11 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e) if (HandleEditBoxKey(w, 3, e) == 1) break; // enter pressed // The name is only allowed when it starts with a letter! - if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') + if (_edit_str_buf[0] != '\0' && _edit_str_buf[0] != ' ') { ttd_strlcpy(_network_player_name, _edit_str_buf, lengthof(_network_player_name)); - else + } else { ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name)); + } break; @@ -396,7 +393,7 @@ void ShowNetworkGameWindow(void) if (_first_time_show_network_game_window) { _first_time_show_network_game_window = false; // add all servers from the config file to our list - for (i=0; i != lengthof(_network_host_list); i++) { + for (i = 0; i != lengthof(_network_host_list); i++) { if (_network_host_list[i] == NULL) break; NetworkAddServer(_network_host_list[i]); } @@ -489,18 +486,22 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) case WE_CLICK: _selected_field = e->click.widget; - switch(e->click.widget) { - case 0: case 15: /* Close 'X' | Cancel button */ + switch (e->click.widget) { + case 0: /* Close 'X' */ + case 15: /* Cancel button */ ShowNetworkGameWindow(); break; - case 4: { /* Set password button */ + + case 4: /* Set password button */ ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, w->window_class, w->window_number); - } break; + break; + case 5: { /* Select map */ int y = (e->click.pt.y - NSSWND_START) / NSSWND_ROWSIZE; - if ((y += w->vscroll.pos) >= w->vscroll.count) - return; + + y += w->vscroll.pos; + if (y >= w->vscroll.count) return; _selected_map = (y == 0) ? NULL : _fios_list + y - 1; SetWindowDirty(w); @@ -561,18 +562,15 @@ static void NetworkStartServerWindowWndProc(Window *w, WindowEvent *e) break; case WE_MOUSELOOP: - if (_selected_field == 3) - HandleEditBox(w, 3); + if (_selected_field == 3) HandleEditBox(w, 3); break; case WE_KEYPRESS: - if (_selected_field == 3) - HandleEditBoxKey(w, 3, e); + if (_selected_field == 3) HandleEditBoxKey(w, 3, e); break; case WE_ON_EDIT_TEXT: { - const char *b = e->edittext.str; - ttd_strlcpy(_network_server_password, b, sizeof(_network_server_password)); + ttd_strlcpy(_network_server_password, e->edittext.str, lengthof(_network_server_password)); _network_game_info.use_password = (_network_server_password[0] != '\0'); SetWindowDirty(w); } break; @@ -636,12 +634,12 @@ static void ShowNetworkStartServerWindow(void) static byte NetworkLobbyFindCompanyIndex(byte pos) { byte i; + /* Scroll through all _network_player_info and get the 'pos' item that is not empty */ for (i = 0; i < MAX_PLAYERS; i++) { if (_network_player_info[i].company_name[0] != '\0') { - if (pos-- == 0) - return i; + if (pos-- == 0) return i; } } @@ -650,7 +648,7 @@ static byte NetworkLobbyFindCompanyIndex(byte pos) static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos; @@ -678,7 +676,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) GfxFillRect(11, y - 1, 154, y + 10, 155); // show highlighted item with a different colour DoDrawString(_network_player_info[index].company_name, 13, y, 2); - if(_network_player_info[index].use_password != 0) + if (_network_player_info[index].use_password != 0) DrawSprite(SPR_LOCK, 135, y); /* If the company's income was positive puts a green dot else a red dot */ @@ -688,8 +686,7 @@ static void NetworkLobbyWindowWndProc(Window *w, WindowEvent *e) pos++; y += NET_PRC__SIZE_OF_ROW_COMPANY; - if (pos >= w->vscroll.cap) - break; + if (pos >= w->vscroll.cap) break; } // draw info about selected company @@ -1087,7 +1084,7 @@ static Window *PopupClientList(Window *w, int client_no, int x, int y) // Main handle for the popup static void ClientListPopupWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { int i, y, sel; byte colour; @@ -1141,7 +1138,7 @@ static void ClientListPopupWndProc(Window *w, WindowEvent *e) // Main handle for clientlist static void ClientListWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { NetworkClientInfo *ci; int y, i = 0; @@ -1166,8 +1163,9 @@ static void ClientListWndProc(Window *w, WindowEvent *e) if (ci->client_index == NETWORK_SERVER_INDEX) { DrawString(4, y, STR_NETWORK_SERVER, colour); - } else + } else { DrawString(4, y, STR_NETWORK_CLIENT, colour); + } // Filter out spectators if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) @@ -1220,15 +1218,14 @@ static void ClientListWndProc(Window *w, WindowEvent *e) void ShowClientList(void) { Window *w = AllocateWindowDescFront(&_client_list_desc, 0); - if (w) - w->window_number = 0; + if (w != NULL) w->window_number = 0; } extern void SwitchMode(int new_mode); static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { uint8 progress; // used for progress bar DrawWindowWidgets(w); @@ -1258,13 +1255,14 @@ static void NetworkJoinStatusWindowWndProc(Window *w, WindowEvent *e) } break; case WE_CLICK: - switch(e->click.widget) { - case 0: case 3: /* Close 'X' | Disconnect button */ - NetworkDisconnect(); - DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); - SwitchMode(SM_MENU); - ShowNetworkGameWindow(); - break; + switch (e->click.widget) { + case 0: /* Close 'X' */ + case 3: /* Disconnect button */ + NetworkDisconnect(); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); + SwitchMode(SM_MENU); + ShowNetworkGameWindow(); + break; } break; @@ -1311,6 +1309,7 @@ void ShowJoinStatusWindowAfterJoin(void) static void ChatWindowWndProc(Window *w, WindowEvent *e) { static bool closed = false; + switch (e->event) { case WE_CREATE: SendWindowMessage(WC_NEWS_WINDOW, 0, WE_CREATE, w->height, 0); @@ -1324,7 +1323,7 @@ static void ChatWindowWndProc(Window *w, WindowEvent *e) break; case WE_CLICK: - switch(e->click.widget) { + switch (e->click.widget) { case 3: DeleteWindow(w); break; // Cancel case 2: // Send press_ok:; diff --git a/news_gui.c b/news_gui.c index aae18aed4f..443765c33e 100644 --- a/news_gui.c +++ b/news_gui.c @@ -376,8 +376,7 @@ static void ShowNewspaper(NewsItem *ni) ni->duration = 555; sound = _news_sounds[ni->type]; - if (sound != 0) - SndPlayFx(sound); + if (sound != 0) SndPlayFx(sound); top = _screen.height; switch (ni->display_mode) { @@ -422,8 +421,7 @@ static void ShowTicker(const NewsItem *ni) _statusbar_news_item = *ni; w = FindWindowById(WC_STATUS_BAR, 0); - if (w != NULL) - WP(w, def_d).data_1 = 360; + if (w != NULL) WP(w, def_d).data_1 = 360; } @@ -441,8 +439,7 @@ static bool ReadyForNextItem(void) // Ticker message // Check if the status bar message is still being displayed? w = FindWindowById(WC_STATUS_BAR, 0); - if (w != NULL && WP(w, def_d).data_1 > -1280) - return false; + if (w != NULL && WP(w, const def_d).data_1 > -1280) return false; // Newspaper message // Wait until duration reaches 0 @@ -468,31 +465,33 @@ static void MoveToNexItem(void) ni = &_news_items[_current_news]; // check the date, don't show too old items - if (_date - _news_items_age[ni->type] > ni->date) - return; + if (_date - _news_items_age[ni->type] > ni->date) return; // execute the validation function to see if this item is still valid - if ( ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b) ) - return; + if (ni->isValid != NULL && !ni->isValid(ni->data_a, ni->data_b)) return; + + switch (GetNewsDisplayValue(ni->type)) { + case 0: { /* Off - show nothing only a small reminder in the status bar */ + Window* w = FindWindowById(WC_STATUS_BAR, 0); - switch (GetNewsDisplayValue(ni->type)) { - case 0: { /* Off - show nothing only a small reminder in the status bar */ - Window *w = FindWindowById(WC_STATUS_BAR, 0); if (w != NULL) { WP(w, def_d).data_2 = 91; SetWindowDirty(w); } - } break; - case 1: /* Summary - show ticker, but if forced big, cascade to full */ - if (!(ni->flags & NF_FORCE_BIG)) { - ShowTicker(ni); - break; - } - /* Fallthrough */ - case 2: /* Full - show newspaper*/ - ShowNewspaper(ni); - break; - } + break; + } + + case 1: /* Summary - show ticker, but if forced big, cascade to full */ + if (!(ni->flags & NF_FORCE_BIG)) { + ShowTicker(ni); + break; + } + /* Fallthrough */ + + case 2: /* Full - show newspaper*/ + ShowNewspaper(ni); + break; + } } } @@ -501,8 +500,7 @@ void NewsLoop(void) // no news item yet if (_total_news == 0) return; - if (ReadyForNextItem()) - MoveToNexItem(); + if (ReadyForNextItem()) MoveToNexItem(); } /* Do a forced show of a specific message */ @@ -541,13 +539,13 @@ void ShowLastNewsMessage(void) recent news. Returns INVALID_NEWS if end of queue reached. */ static byte getNews(byte i) { - if (i >= _total_news) - return INVALID_NEWS; + if (i >= _total_news) return INVALID_NEWS; - if (_latest_news < i) + if (_latest_news < i) { i = _latest_news + MAX_NEWS - i; - else + } else { i = _latest_news - i; + } i %= MAX_NEWS; return i; @@ -636,10 +634,11 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) p = y + w->vscroll.pos; if (p > _total_news - 1) break; - if (_latest_news >= p) + if (_latest_news >= p) { q = _latest_news - p; - else + } else { q = _latest_news + MAX_NEWS - p; + } ShowNewsMessage(q); break; diff --git a/openttd.c b/openttd.c index 783b58810e..58246a62cb 100644 --- a/openttd.c +++ b/openttd.c @@ -69,16 +69,17 @@ bool _dbg_screen_rect; * caused by the user, i.e. missing files or fatal configuration errors. * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */ -void CDECL error(const char *s, ...) { +void CDECL error(const char* s, ...) +{ va_list va; char buf[512]; + va_start(va, s); vsprintf(buf, s, va); va_end(va); ShowOSErrorBox(buf); - if (_video_driver) - _video_driver->stop(); + if (_video_driver != NULL) _video_driver->stop(); assert(0); exit(1); @@ -102,8 +103,7 @@ void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) size_t len; in = fopen(filename, "rb"); - if (in == NULL) - return NULL; + if (in == NULL) return NULL; fseek(in, 0, SEEK_END); len = ftell(in); @@ -178,12 +178,12 @@ static int MyGetOpt(MyGetOptData *md) { char *s,*r,*t; - if ((s=md->cont) != NULL) + s = md->cont; + if (s != NULL) goto md_continue_here; - while(true) { - if (--md->numleft < 0) - return -1; + for (;;) { + if (--md->numleft < 0) return -1; s = *md->argv++; if (*s == '-') { @@ -347,9 +347,9 @@ int ttd_main(int argc, char* argv[]) case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break; case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break; case 'D': { - sprintf(musicdriver,"null"); - sprintf(sounddriver,"null"); - sprintf(videodriver,"dedicated"); + strcpy(musicdriver, "null"); + strcpy(sounddriver, "null"); + strcpy(videodriver, "dedicated"); dedicated = true; } break; case 'f': { @@ -364,23 +364,18 @@ int ttd_main(int argc, char* argv[]) network_conn = NULL; } break; case 'r': ParseResolution(resolution, mgo.opt); break; - case 'l': { - language = mgo.opt; - } break; - case 't': { - startdate = atoi(mgo.opt); - } break; + case 'l': language = mgo.opt; break; + case 't': startdate = atoi(mgo.opt); break; case 'd': { #if defined(WIN32) CreateConsole(); #endif - if (mgo.opt) - SetDebugString(mgo.opt); + if (mgo.opt != NULL) SetDebugString(mgo.opt); } break; case 'e': _switch_mode = SM_EDITOR; break; case 'i': _use_dos_palette = true; break; case 'g': - if (mgo.opt) { + if (mgo.opt != NULL) { strcpy(_file_to_saveload.name, mgo.opt); _switch_mode = SM_LOAD; } else @@ -598,7 +593,7 @@ static void MakeNewGame(void) // Copy in game options _opt_ptr = &_opt; - memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions)); + memcpy(_opt_ptr, &_opt_newgame, sizeof(*_opt_ptr)); GfxLoadSprites(); @@ -643,7 +638,7 @@ static void MakeNewEditorWorld(void) SetupColorsAndInitialWindow(); // Startup the game system - GenerateWorld(1, 1<<_patches.map_x, 1<<_patches.map_y); + GenerateWorld(1, 1 << _patches.map_x, 1 << _patches.map_y); _local_player = OWNER_NONE; MarkWholeScreenDirty(); @@ -716,8 +711,9 @@ bool SafeSaveOrLoad(const char *filename, int mode, int newgm) } else if (r != SL_OK) { _game_mode = ogm; return false; - } else + } else { return true; + } } void SwitchMode(int new_mode) @@ -804,9 +800,9 @@ void SwitchMode(int new_mode) _generating_world = false; // delete all stations owned by a player DeleteAllPlayerStations(); - } else + } else { ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0); - + } break; } @@ -816,10 +812,11 @@ void SwitchMode(int new_mode) break; case SM_SAVE: /* Save game */ - if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) + if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) { ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0); - else + } else { DeleteWindowById(WC_SAVELOAD, 0); + } break; case SM_GENRANDLAND: /* Generate random land within scenario editor */ @@ -847,8 +844,7 @@ void StateGameLoop(void) // _frame_counter is increased somewhere else when in network-mode // Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games // Should that not be deleted? If so, the next 2 lines can also be deleted - if (!_networking) - _frame_counter++; + if (!_networking) _frame_counter++; if (_savedump_path[0] && (uint)_frame_counter >= _savedump_first && (uint)(_frame_counter -_savedump_first) % _savedump_freq == 0 ) { char buf[100]; @@ -951,7 +947,6 @@ void GameLoop(void) int m; ThreadMsg message; - if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message); // autosave game? @@ -987,13 +982,14 @@ void GameLoop(void) IncreaseSpriteLRU(); InteractiveRandom(); - if (_scroller_click_timeout > 3) + if (_scroller_click_timeout > 3) { _scroller_click_timeout -= 3; - else + } else { _scroller_click_timeout = 0; + } _caret_timer += 3; - _timer_counter+=8; + _timer_counter += 8; CursorTick(); #ifdef ENABLE_NETWORK @@ -1016,11 +1012,9 @@ void GameLoop(void) StateGameLoop(); #endif /* ENABLE_NETWORK */ - if (!_pause && _display_opt&DO_FULL_ANIMATION) - DoPaletteAnimations(); + if (!_pause && _display_opt & DO_FULL_ANIMATION) DoPaletteAnimations(); - if (!_pause || _cheats.build_in_pause.value) - MoveAllTextEffects(); + if (!_pause || _cheats.build_in_pause.value) MoveAllTextEffects(); InputLoop(); @@ -1044,8 +1038,7 @@ static void ConvertTownOwner(void) for (tile = 0; tile != MapSize(); tile++) { if (IsTileType(tile, MP_STREET)) { - if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80) - _m[tile].m3 = OWNER_TOWN; + if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80) _m[tile].m3 = OWNER_TOWN; if (_m[tile].m1 & 0x80) SetTileOwner(tile, OWNER_TOWN); } else if (IsTileType(tile, MP_TUNNELBRIDGE)) { @@ -1057,20 +1050,20 @@ static void ConvertTownOwner(void) // before savegame version 4, the name of the company determined if it existed static void CheckIsPlayerActive(void) { - Player *p; + Player* p; + FOR_ALL_PLAYERS(p) { - if (p->name_1 != 0) { - p->is_active = true; - } + if (p->name_1 != 0) p->is_active = true; } } // since savegame version 4.1, exclusive transport rights are stored at towns static void UpdateExclusiveRights(void) { - Town *t; - FOR_ALL_TOWNS(t) if (t->xy != 0) { - t->exclusivity=(byte)-1; + Town* t; + + FOR_ALL_TOWNS(t) { + if (t->xy != 0) t->exclusivity = (byte)-1; } /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) @@ -1113,9 +1106,8 @@ static void UpdateVoidTiles(void) static void UpdateSignOwner(void) { SignStruct *ss; - FOR_ALL_SIGNS(ss) { - ss->owner = OWNER_NONE; // no owner - } + + FOR_ALL_SIGNS(ss) ss->owner = OWNER_NONE; } extern void UpdateOldAircraft( void ); @@ -1128,24 +1120,16 @@ bool AfterLoadGame(uint version) Player *p; // in version 2.1 of the savegame, town owner was unified. - if (version <= 0x200) { - ConvertTownOwner(); - } + if (version <= 0x200) ConvertTownOwner(); // from version 4.1 of the savegame, exclusive rights are stored at towns - if (version <= 0x400) { - UpdateExclusiveRights(); - } + if (version <= 0x400) UpdateExclusiveRights(); // from version 4.2 of the savegame, currencies are in a different order - if (version <= 0x401) { - UpdateCurrencies(); - } + if (version <= 0x401) UpdateCurrencies(); // from version 6.0 of the savegame, signs have an "owner" - if (version <= 0x600) { - UpdateSignOwner(); - } + if (version <= 0x600) UpdateSignOwner(); /* In old version there seems to be a problem that water is owned by OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current @@ -1178,15 +1162,12 @@ bool AfterLoadGame(uint version) AfterLoadVehicles(); // Update all waypoints - if (version < 0x0C00) - FixOldWaypoints(); + if (version < 0x0C00) FixOldWaypoints(); UpdateAllWaypointSigns(); // in version 2.2 of the savegame, we have new airports - if (version <= 0x201) { - UpdateOldAircraft(); - } + if (version <= 0x201) UpdateOldAircraft(); UpdateAllStationVirtCoord(); @@ -1195,8 +1176,7 @@ bool AfterLoadGame(uint version) UpdateAllSignVirtCoords(); // make sure there is a town in the game - if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) - { + if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) { _error_message = STR_NO_TOWN_IN_SCENARIO; return false; } @@ -1215,16 +1195,12 @@ bool AfterLoadGame(uint version) vp->virtual_width = vp->width << vp->zoom; vp->virtual_height = vp->height << vp->zoom; - // in version 4.0 of the savegame, is_active was introduced to determine // if a player does exist, rather then checking name_1 - if (version <= 0x400) { - CheckIsPlayerActive(); - } + if (version <= 0x400) CheckIsPlayerActive(); // the void tiles on the southern border used to belong to a wrong class. - if (version <= 0x402) - UpdateVoidTiles(); + if (version <= 0x402) UpdateVoidTiles(); // If Load Scenario / New (Scenario) Game is used, // a player does not exist yet. So create one here. @@ -1237,9 +1213,7 @@ bool AfterLoadGame(uint version) MarkWholeScreenDirty(); //In 5.1, Oilrigs have been moved (again) - if (version <= 0x500) { - UpdateOilRig(); - } + if (version <= 0x500) UpdateOilRig(); if (version <= 0x600) { BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) { @@ -1265,9 +1239,7 @@ bool AfterLoadGame(uint version) if (version < 0x900) { Town *t; - FOR_ALL_TOWNS(t) { - UpdateTownMaxPass(t); - } + FOR_ALL_TOWNS(t) UpdateTownMaxPass(t); } if (version < 0xF00) { @@ -1320,9 +1292,7 @@ bool AfterLoadGame(uint version) } } - FOR_ALL_PLAYERS(p) { - p->avail_railtypes = GetPlayerRailtypes(p->index); - } + FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index); return true; } diff --git a/order_cmd.c b/order_cmd.c index 2820e88bd8..38515d80bd 100644 --- a/order_cmd.c +++ b/order_cmd.c @@ -29,8 +29,7 @@ static void OrderPoolNewBlock(uint start_item) { Order *order; - FOR_ALL_ORDERS_FROM(order, start_item) - order->index = start_item++; + FOR_ALL_ORDERS_FROM(order, start_item) order->index = start_item++; } /* Initialize the order-pool */ @@ -117,7 +116,7 @@ static Order *AllocateOrder(void) if (order->type == OT_NOTHING) { uint index = order->index; - memset(order, 0, sizeof(Order)); + memset(order, 0, sizeof(*order)); order->index = index; order->next = NULL; @@ -126,8 +125,7 @@ static Order *AllocateOrder(void) } /* Check if we can add a block to the pool */ - if (AddBlockToPool(&_order_pool)) - return AllocateOrder(); + if (AddBlockToPool(&_order_pool)) return AllocateOrder(); return NULL; } @@ -207,19 +205,19 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) * [full-load | unload] [+ transfer] [+ non-stop] * non-stop orders (if any) are only valid for trains */ switch (new_order.flags) { - case 0: /* Fallthrough */ + case 0: case OF_FULL_LOAD: - case OF_FULL_LOAD | OF_TRANSFER: /* Fallthrough */ + case OF_FULL_LOAD | OF_TRANSFER: case OF_UNLOAD: - case OF_UNLOAD | OF_TRANSFER: /* Fallthrough */ + case OF_UNLOAD | OF_TRANSFER: case OF_TRANSFER: break; case OF_NON_STOP: case OF_NON_STOP | OF_FULL_LOAD: - case OF_NON_STOP | OF_FULL_LOAD | OF_TRANSFER: /* Fallthrough */ + case OF_NON_STOP | OF_FULL_LOAD | OF_TRANSFER: case OF_NON_STOP | OF_UNLOAD: - case OF_NON_STOP | OF_UNLOAD | OF_TRANSFER: /* Fallthrough */ + case OF_NON_STOP | OF_UNLOAD | OF_TRANSFER: case OF_NON_STOP | OF_TRANSFER: if (v->type != VEH_Train) return CMD_ERROR; break; @@ -407,9 +405,7 @@ int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) static int32 DecloneOrder(Vehicle *dst, uint32 flags) { if (flags & DC_EXEC) { - /* Delete orders from vehicle */ DeleteVehicleOrders(dst); - InvalidateVehicleOrder(dst); RebuildVehicleLists(); } @@ -568,8 +564,7 @@ int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2) switch (p2) { case OFB_FULL_LOAD: TOGGLEBIT(order->flags, OFB_FULL_LOAD); - if (order->type != OT_GOTO_DEPOT) - CLRBIT(order->flags, OFB_UNLOAD); + if (order->type != OT_GOTO_DEPOT) CLRBIT(order->flags, OFB_UNLOAD); break; case OFB_UNLOAD: TOGGLEBIT(order->flags, OFB_UNLOAD); @@ -750,7 +745,7 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) /* Safe custom string, if any */ if ((v->string_id & 0xF800) != 0x7800) { - bak->name[0] = 0; + bak->name[0] = '\0'; } else { GetName(v->string_id & 0x7FF, bak->name); } @@ -899,8 +894,7 @@ bool CheckOrders(uint data_a, uint data_b) n_st++; st = GetStation(order->station); required_tile = GetStationTileForVehicle(v, st); - if (!required_tile) - problem_type = 3; + if (required_tile == 0) problem_type = 3; } } @@ -912,8 +906,7 @@ bool CheckOrders(uint data_a, uint data_b) problem_type = 2; /* Do we only have 1 station in our order list? */ - if ((n_st < 2) && (problem_type == -1)) - problem_type = 0; + if (n_st < 2 && problem_type == -1) problem_type = 0; /* We don't have a problem */ if (problem_type < 0) { @@ -1104,9 +1097,7 @@ bool CheckForValidOrders(const Vehicle* v) { const Order *order; - FOR_VEHICLE_ORDERS(v, order) - if (order->type != OT_DUMMY) - return true; + FOR_VEHICLE_ORDERS(v, order) if (order->type != OT_DUMMY) return true; return false; } diff --git a/order_gui.c b/order_gui.c index e7b1ccba5a..30d1e92fc1 100644 --- a/order_gui.c +++ b/order_gui.c @@ -472,13 +472,15 @@ static void OrdersWndProc(Window *w, WindowEvent *e) } case WE_RCLICK: { - Vehicle *v = GetVehicle(w->window_number); - int sel = OrderGetSel(w); - if (e->click.widget != 8) break; - if (sel == v->num_orders || GetVehicleOrder(v, sel)->type != OT_GOTO_DEPOT) + Vehicle* v = GetVehicle(w->window_number); + int s = OrderGetSel(w); + + if (e->click.widget != 8) break; + if (s == v->num_orders || GetVehicleOrder(v, s)->type != OT_GOTO_DEPOT) { GuiShowTooltips(STR_8857_MAKE_THE_HIGHLIGHTED_ORDER); - else + } else { GuiShowTooltips(STR_SERVICE_HINT); + } } break; case WE_4: { diff --git a/player_gui.c b/player_gui.c index 300abd686c..eba18b1430 100644 --- a/player_gui.c +++ b/player_gui.c @@ -685,10 +685,10 @@ static const WindowDesc _other_player_company_desc = { void ShowPlayerCompany(PlayerID player) { - Window *w; - w = AllocateWindowDescFront(player == _local_player ? &_my_player_company_desc : &_other_player_company_desc, player); - if (w) - w->caption_color = w->window_number; + Window* w; + + w = AllocateWindowDescFront(player == _local_player ? &_my_player_company_desc : &_other_player_company_desc, player); + if (w != NULL) w->caption_color = w->window_number; } @@ -881,7 +881,7 @@ void ShowHighscoreTable(int difficulty, int8 ranking) if (!_networking) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); /* Close all always on-top windows to get a clean screen */ - if (_game_mode != GM_MENU) HideVitalWindows(); + if (_game_mode != GM_MENU) HideVitalWindows(); DeleteWindowByClass(WC_HIGHSCORE); w = AllocateWindowDesc(&_highscore_desc); diff --git a/players.c b/players.c index 15a53aba59..766bd07d4e 100644 --- a/players.c +++ b/players.c @@ -135,17 +135,17 @@ void DrawPlayerFace(uint32 face, int color, int x, int y) /* draw the hair */ { uint val = GB(face, 16, 4); - if (!(flag&2)) { - if (!(flag&1)) { - DrawSprite(0x382 + (val*9>>4), x, y); + if (flag & 2) { + if (flag & 1) { + DrawSprite(0x3D9 + (val * 5 >> 4), x, y); } else { - DrawSprite(0x38B + (val*5>>4), x, y); + DrawSprite(0x3D4 + (val * 5 >> 4), x, y); } } else { - if (!(flag&1)) { - DrawSprite(0x3D4 + (val*5>>4), x, y); + if (flag & 1) { + DrawSprite(0x38B + (val * 5 >> 4), x, y); } else { - DrawSprite(0x3D9 + (val*5>>4), x, y); + DrawSprite(0x382 + (val * 9 >> 4), x, y); } } } @@ -163,9 +163,7 @@ void DrawPlayerFace(uint32 face, int color, int x, int y) DrawSprite(0x37B + (GB(val, 2, 2) * 4 >> 2), x, y); val >>= 4; - if (val < 3) { - DrawSprite((flag&2 ? 0x3D1 : 0x37F) + val, x, y); - } + if (val < 3) DrawSprite((flag & 2 ? 0x3D1 : 0x37F) + val, x, y); } } @@ -173,14 +171,10 @@ void DrawPlayerFace(uint32 face, int color, int x, int y) { uint val = GB(face, 28, 3); - if (!(flag&2)) { - if (val<=1) { - DrawSprite(0x347 + val, x, y); - } + if (flag & 2) { + if (val <= 1) DrawSprite(0x3AE + val, x, y); } else { - if (val<=1) { - DrawSprite(0x3AE + val, x, y); - } + if (val <= 1) DrawSprite(0x347 + val, x, y); } } } diff --git a/rail_cmd.c b/rail_cmd.c index a5c48743d5..9b39295b85 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -224,7 +224,7 @@ uint GetRailFoundation(uint tileh, uint bits) return 0; } -// + static uint32 CheckRailSlope(uint tileh, TrackBits rail_bits, TrackBits existing, TileIndex tile) { // never allow building on top of steep tiles @@ -689,8 +689,7 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2) cost = ret; d = AllocateDepot(); - if (d == NULL) - return CMD_ERROR; + if (d == NULL) return CMD_ERROR; if (flags & DC_EXEC) { if (IsLocalPlayer()) _last_built_train_depot_tile = tile; @@ -820,10 +819,11 @@ int32 CmdBuildSingleSignal(int x, int y, uint32 flags, uint32 p1, uint32 p2) _m[tile].m3 &= ~SignalOnTrack(track); _m[tile].m3 |= p2 & SignalOnTrack(track); // convert between signal<->semaphores when dragging - if (semaphore) + if (semaphore) { SETBIT(_m[tile].m4, 3); - else + } else { CLRBIT(_m[tile].m4, 3); + } } MarkTileDirtyByTile(tile); @@ -859,8 +859,7 @@ static int32 CmdSignalTrackHelper(int x, int y, uint32 flags, uint32 p1, uint32 if (p1 > MapSize()) return CMD_ERROR; if (signal_density == 0 || signal_density > 20) return CMD_ERROR; - if (!IsTileType(tile, MP_RAILWAY)) - return CMD_ERROR; + if (!IsTileType(tile, MP_RAILWAY)) return CMD_ERROR; SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); @@ -1290,8 +1289,7 @@ static void DrawTrackFence_NE_SW(const TileInfo *ti) static void DrawTrackFence_NS_1(const TileInfo *ti) { int z = ti->z; - if (ti->tileh & 1) - z += 8; + if (ti->tileh & 1) z += 8; AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, ti->x + 8, ti->y + 8, 1, 1, 4, z); } @@ -1299,8 +1297,7 @@ static void DrawTrackFence_NS_1(const TileInfo *ti) static void DrawTrackFence_NS_2(const TileInfo *ti) { int z = ti->z; - if (ti->tileh & 4) - z += 8; + if (ti->tileh & 4) z += 8; AddSortableSpriteToDraw(0x517 | _drawtile_track_palette, ti->x + 8, ti->y + 8, 1, 1, 4, z); } @@ -1308,8 +1305,7 @@ static void DrawTrackFence_NS_2(const TileInfo *ti) static void DrawTrackFence_WE_1(const TileInfo *ti) { int z = ti->z; - if (ti->tileh & 8) - z += 8; + if (ti->tileh & 8) z += 8; AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, ti->x + 8, ti->y + 8, 1, 1, 4, z); } @@ -1317,8 +1313,7 @@ static void DrawTrackFence_WE_1(const TileInfo *ti) static void DrawTrackFence_WE_2(const TileInfo *ti) { int z = ti->z; - if (ti->tileh & 2) - z += 8; + if (ti->tileh & 2) z += 8; AddSortableSpriteToDraw(0x518 | _drawtile_track_palette, ti->x + 8, ti->y + 8, 1, 1, 4, z); } @@ -1795,8 +1790,7 @@ static void SetSignalsAfterProc(TrackPathFinder *tpf) /* Go through all the PF tiles */ for (i = 0; i < lengthof(tpf->hash_head); i++) { /* Empty hash item */ - if (tpf->hash_head[i] == 0) - continue; + if (tpf->hash_head[i] == 0) continue; /* If 0x8000 is not set, there is only 1 item */ if (!(tpf->hash_head[i] & 0x8000)) { @@ -1917,8 +1911,7 @@ bool UpdateSignalsOnSegment(TileIndex tile, byte direction) if (result < 0) result = ssd.stop; // if any exit signals were changed, we need to keep going to modify the stuff behind those. - if(!ssd.cur_stack) - break; + if (ssd.cur_stack == 0) break; // one or more exit signals were changed, so we need to update another segment too. tile = ssd.next_tile[--ssd.cur_stack]; @@ -2020,8 +2013,7 @@ static void TileLoop_Track(TileIndex tile) } // Don't continue tile loop for depots - if (_m[tile].m5 & RAIL_TYPE_SPECIAL) - return; + if (_m[tile].m5 & RAIL_TYPE_SPECIAL) return; a2 = RAIL_GROUND_GREEN; @@ -2085,8 +2077,7 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode) uint16 b; uint32 ret; - if (mode != TRANSPORT_RAIL) - return 0; + if (mode != TRANSPORT_RAIL) return 0; m5 = _m[tile].m5; @@ -2111,10 +2102,10 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode) if ((a & 0xC0) == 0) b |= 0xC0; if ((a & 0x30) == 0) b |= 0x30; - if ( (b & 0x80) == 0) ret |= 0x10070000; - if ( (b & 0x40) == 0) ret |= 0x7100000; - if ( (b & 0x20) == 0) ret |= 0x20080000; - if ( (b & 0x10) == 0) ret |= 0x8200000; + if ((b & 0x80) == 0) ret |= 0x10070000; + if ((b & 0x40) == 0) ret |= 0x07100000; + if ((b & 0x20) == 0) ret |= 0x20080000; + if ((b & 0x10) == 0) ret |= 0x08200000; } } else if (m5 & 0x40) { static const byte _train_spec_tracks[6] = {1,2,1,2,1,2}; @@ -2193,8 +2184,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) int length; // this routine applies only to trains in depot tiles - if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) - return 0; + if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; /* depot direction */ dir = GetDepotDirection(tile, TRANSPORT_RAIL); diff --git a/rail_gui.c b/rail_gui.c index 2d31d4fbb5..415498958a 100644 --- a/rail_gui.c +++ b/rail_gui.c @@ -24,7 +24,7 @@ static RailType _cur_railtype; static bool _remove_button_clicked; static byte _build_depot_direction; -static byte _waypoint_count=1; +static byte _waypoint_count = 1; static byte _cur_waypoint_type; static struct { @@ -40,8 +40,6 @@ static void ShowBuildTrainDepotPicker(void); static void ShowBuildWaypointPicker(void); static void ShowStationBuilder(void); -typedef void OnButtonClick(Window *w); - void CcPlaySound1E(bool success, TileIndex tile, uint32 p1, uint32 p2) { if (success) SndPlayTileFx(SND_20_SPLAT_2, tile); @@ -53,7 +51,7 @@ static void GenericPlaceRail(TileIndex tile, int cmd) _remove_button_clicked ? CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER : CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER - ); + ); } static void PlaceRail_N(TileIndex tile) @@ -159,7 +157,7 @@ static void PlaceRail_Station(TileIndex tile) static void GenericPlaceSignals(TileIndex tile) { uint trackstat; - int i; + uint i; trackstat = (byte)GetTileTrackStatus(tile, TRANSPORT_RAIL); @@ -171,7 +169,9 @@ static void GenericPlaceSignals(TileIndex tile) // Lookup the bit index i = 0; - if (trackstat != 0) { while (!(trackstat & 1)) { i++; trackstat >>= 1; }} + if (trackstat != 0) { + for (; !(trackstat & 1); trackstat >>= 1) i++; + } if (!_remove_button_clicked) { DoCommandP(tile, i + (_ctrl_pressed ? 8 : 0), 0, CcPlaySound1E, @@ -258,9 +258,10 @@ static void BuildRailClick_Depot(Window *w) static void BuildRailClick_Waypoint(Window *w) { _waypoint_count = GetNumCustomStations(STAT_CLASS_WAYP); - if (HandlePlacePushButton(w, 11, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) - && _waypoint_count > 1) + if (HandlePlacePushButton(w, 11, SPR_CURSOR_WAYPOINT, 1, PlaceRail_Waypoint) && + _waypoint_count > 1) { ShowBuildWaypointPicker(); + } } static void BuildRailClick_Station(Window *w) @@ -295,10 +296,11 @@ static void BuildRailClick_Remove(Window *w) // handle station builder if (HASBIT(w->click_state, 16)) { - if(_remove_button_clicked) + if (_remove_button_clicked) { SetTileSelectSize(1, 1); - else + } else { BringWindowToFrontById(WC_BUILD_STATION, 0); + } } } @@ -346,13 +348,20 @@ static void HandleAutoSignalPlacement(void) // _patches.drag_signals_density is given as a parameter such that each user in a network // game can specify his/her own signal density - DoCommandP(TileVirtXY(thd->selstart.x, thd->selstart.y), TileVirtXY(thd->selend.x, thd->selend.y), - (_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) | (_patches.drag_signals_density << 24), - CcPlaySound1E, - (_remove_button_clicked ? CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) : - CMD_BUILD_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE) ) ); + DoCommandP( + TileVirtXY(thd->selstart.x, thd->selstart.y), + TileVirtXY(thd->selend.x, thd->selend.y), + (_ctrl_pressed ? 1 << 3 : 0) | (trackstat << 4) | (_patches.drag_signals_density << 24), + CcPlaySound1E, + _remove_button_clicked ? + CMD_REMOVE_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM) : + CMD_BUILD_SIGNAL_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE) + ); } + +typedef void OnButtonClick(Window *w); + static OnButtonClick * const _build_railroad_button_proc[] = { BuildRailClick_N, BuildRailClick_NE, @@ -390,11 +399,9 @@ static const uint16 _rail_keycodes[] = { }; - - static void BuildRailToolbWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: w->disabled_state &= ~(1 << 16); if (!(w->click_state & ((1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<11)|(1<<12)|(1<<13)))) { @@ -412,9 +419,9 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e) break; case WE_KEYPRESS: { - int i; + uint i; - for(i=0; i!=lengthof(_rail_keycodes); i++) { + for (i = 0; i != lengthof(_rail_keycodes); i++) { if (e->keypress.keycode == _rail_keycodes[i]) { e->keypress.cont = false; _remove_button_clicked = false; @@ -467,16 +474,16 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e) SetWindowDirty(w); w = FindWindowById(WC_BUILD_STATION, 0); - if (w != NULL) WP(w,def_d).close=true; + if (w != NULL) WP(w,def_d).close = true; w = FindWindowById(WC_BUILD_DEPOT, 0); - if (w != NULL) WP(w,def_d).close=true; + if (w != NULL) WP(w,def_d).close = true; break; case WE_PLACE_PRESIZE: { TileIndex tile = e->place.tile; DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL); - VpSetPresizeRange(tile, _build_tunnel_endtile==0?tile:_build_tunnel_endtile); + VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); } break; case WE_DESTROY: @@ -541,7 +548,7 @@ typedef enum { * @param railtype the railtype to display * @param w the window to modify */ -static void SetupRailToolbar(RailType railtype, Window *w) +static void SetupRailToolbar(RailType railtype, Window* w) { const RailtypeInfo *rti = GetRailTypeInfo(railtype); @@ -703,17 +710,16 @@ static void StationBuildWndProc(Window *w, WindowEvent *e) } } break; - case WE_MOUSELOOP: { + case WE_MOUSELOOP: if (WP(w,def_d).close) { DeleteWindow(w); return; } CheckRedrawStationCoverage(w); - } break; + break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } @@ -772,28 +778,30 @@ static void BuildTrainDepotWndProc(Window *w, WindowEvent *e) r = _cur_railtype; DrawTrainDepotSprite(70, 17, 0, r); DrawTrainDepotSprite(70, 69, 1, r); - DrawTrainDepotSprite(2, 69, 2, r); - DrawTrainDepotSprite(2, 17, 3, r); + DrawTrainDepotSprite( 2, 69, 2, r); + DrawTrainDepotSprite( 2, 17, 3, r); break; } - case WE_CLICK: { - switch(e->click.widget) { - case 3: case 4: case 5: case 6: - _build_depot_direction = e->click.widget - 3; - SndPlayFx(SND_15_BEEP); - SetWindowDirty(w); - break; + + case WE_CLICK: + switch (e->click.widget) { + case 3: + case 4: + case 5: + case 6: + _build_depot_direction = e->click.widget - 3; + SndPlayFx(SND_15_BEEP); + SetWindowDirty(w); + break; } - } break; + break; case WE_MOUSELOOP: - if (WP(w,def_d).close) - DeleteWindow(w); + if (WP(w,def_d).close) DeleteWindow(w); return; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } @@ -827,15 +835,16 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e) { switch (e->event) { case WE_PAINT: { - int i; + uint i; + w->click_state = (1 << 3) << (_cur_waypoint_type - w->hscroll.pos); DrawWindowWidgets(w); for (i = 0; i < 5; i++) { - if (w->hscroll.pos + i < _waypoint_count) + if (w->hscroll.pos + i < _waypoint_count) { DrawWaypointSprite(2 + i * 68, 25, w->hscroll.pos + i, _cur_railtype); + } } - break; } case WE_CLICK: { @@ -850,13 +859,11 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e) } case WE_MOUSELOOP: - if (WP(w,def_d).close) - DeleteWindow(w); + if (WP(w,def_d).close) DeleteWindow(w); break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } diff --git a/road_cmd.c b/road_cmd.c index 6638647051..34382402ce 100644 --- a/road_cmd.c +++ b/road_cmd.c @@ -377,7 +377,7 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (ti.type == MP_STREET) { if (!(ti.map5 & 0xF0)) { - if ( (pieces & (byte)(ti.map5)) == (pieces)) + if ((pieces & (byte)ti.map5) == pieces) return_cmd_error(STR_1007_ALREADY_BUILT); existing = ti.map5; } else { @@ -680,12 +680,9 @@ static int32 RemoveRoadDepot(TileIndex tile, uint32 flags) if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; - if (!EnsureNoVehicle(tile)) - return CMD_ERROR; + if (!EnsureNoVehicle(tile)) return CMD_ERROR; - if (flags & DC_EXEC) { - DoDeleteDepot(tile); - } + if (flags & DC_EXEC) DoDeleteDepot(tile); return _price.remove_road_depot; } @@ -790,21 +787,16 @@ void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool fla foundation = GetRoadFoundation(ti->tileh, road); } - if (foundation != 0) - DrawFoundation(ti, foundation); + if (foundation != 0) DrawFoundation(ti, foundation); // DrawFoundation() modifies ti. // Default sloped sprites.. - if (ti->tileh != 0) { - image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; - } + if (ti->tileh != 0) image = _road_sloped_sprites[ti->tileh - 1] + 0x53F; } - if (image == 0) - image = _road_tile_sprites_1[road]; + if (image == 0) image = _road_tile_sprites_1[road]; - if (ground_type == 0) - image |= PALETTE_TO_BARE_LAND; + if (ground_type == 0) image |= PALETTE_TO_BARE_LAND; if (snow) { image += 19; @@ -816,8 +808,7 @@ void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool fla DrawGroundSprite(image); // Return if full detail is disabled, or we are zoomed fully out. - if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) - return; + if (!(_display_opt & DO_FULL_DETAIL) || _cur_dpi->zoom == 2) return; if (ground_type >= 6) { // Road works @@ -831,8 +822,7 @@ void DrawRoadBits(TileInfo *ti, byte road, byte ground_type, bool snow, bool fla int x = ti->x | drts->subcoord_x; int y = ti->y | drts->subcoord_y; byte z = ti->z; - if (ti->tileh != 0) - z = GetSlopeZ(x, y); + if (ti->tileh != 0) z = GetSlopeZ(x, y); AddSortableSpriteToDraw(image, x, y, 2, 2, 0x10, z); drts++; } @@ -915,8 +905,8 @@ void DrawRoadDepotSprite(int x, int y, int image) dtss = _road_display_datas[image]; - x+=33; - y+=17; + x += 33; + y += 17; DrawSprite(dtss++->image, x, y); @@ -924,8 +914,7 @@ void DrawRoadDepotSprite(int x, int y, int image) Point pt = RemapCoords(dtss->subcoord_x, dtss->subcoord_y, 0); image = dtss->image; - if (image & PALETTE_MODIFIER_COLOR) - image |= ormod; + if (image & PALETTE_MODIFIER_COLOR) image |= ormod; DrawSprite(image, x + pt.x, y + pt.y); } @@ -986,9 +975,7 @@ static void GetAcceptedCargo_Road(TileIndex tile, AcceptedCargo ac) static void AnimateTile_Road(TileIndex tile) { - if (IsLevelCrossing(tile)) { - MarkTileDirtyByTile(tile); - } + if (IsLevelCrossing(tile)) MarkTileDirtyByTile(tile); } static const byte _town_road_types[5][2] = { diff --git a/road_gui.c b/road_gui.c index dbb0ea1afb..448617ecd3 100644 --- a/road_gui.c +++ b/road_gui.c @@ -171,7 +171,7 @@ static void BuildRoadClick_Landscaping(Window *w) ShowTerraformToolbar(); } -static OnButtonClick * const _build_road_button_proc[] = { +static OnButtonClick* const _build_road_button_proc[] = { BuildRoadClick_NE, BuildRoadClick_NW, BuildRoadClick_Demolish, @@ -184,8 +184,9 @@ static OnButtonClick * const _build_road_button_proc[] = { BuildRoadClick_Landscaping, }; -static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) { - switch(e->event) { +static void BuildRoadToolbWndProc(Window* w, WindowEvent* e) +{ + switch (e->event) { case WE_PAINT: w->disabled_state &= ~(1 << 11); if (!(w->click_state & ((1<<3)|(1<<4)))) { @@ -196,8 +197,7 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) { break; case WE_CLICK: { - if (e->click.widget >= 3) - _build_road_button_proc[e->click.widget - 3](w); + if (e->click.widget >= 3) _build_road_button_proc[e->click.widget - 3](w); } break; case WE_KEYPRESS: @@ -228,11 +228,11 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e) { SetWindowDirty(w); w = FindWindowById(WC_BUS_STATION, 0); - if (w != NULL) WP(w,def_d).close=true; + if (w != NULL) WP(w,def_d).close = true; w = FindWindowById(WC_TRUCK_STATION, 0); - if (w != NULL) WP(w,def_d).close=true; + if (w != NULL) WP(w,def_d).close = true; w = FindWindowById(WC_BUILD_DEPOT, 0); - if (w != NULL) WP(w,def_d).close=true; + if (w != NULL) WP(w,def_d).close = true; break; case WE_PLACE_DRAG: { @@ -351,16 +351,17 @@ void ShowBuildRoadScenToolbar(void) AllocateWindowDescFront(&_build_road_scen_desc, 0); } -static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) { - switch(e->event) { +static void BuildRoadDepotWndProc(Window* w, WindowEvent* e) +{ + switch (e->event) { case WE_PAINT: w->click_state = (1<<3) << _road_depot_orientation; DrawWindowWidgets(w); DrawRoadDepotSprite(70, 17, 0); DrawRoadDepotSprite(70, 69, 1); - DrawRoadDepotSprite(2, 69, 2); - DrawRoadDepotSprite(2, 17, 3); + DrawRoadDepotSprite( 2, 69, 2); + DrawRoadDepotSprite( 2, 17, 3); break; case WE_CLICK: { @@ -374,13 +375,11 @@ static void BuildRoadDepotWndProc(Window *w, WindowEvent *e) { } break; case WE_MOUSELOOP: - if (WP(w,def_d).close) - DeleteWindow(w); + if (WP(w,def_d).close) DeleteWindow(w); break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } @@ -466,8 +465,7 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e) } break; case WE_DESTROY: - if (!WP(w,def_d).close) - ResetObjectToPlace(); + if (!WP(w,def_d).close) ResetObjectToPlace(); break; } } diff --git a/roadveh_gui.c b/roadveh_gui.c index f2fda83746..460dbc1f9e 100644 --- a/roadveh_gui.c +++ b/roadveh_gui.c @@ -65,12 +65,11 @@ static void DrawRoadVehImage(const Vehicle *v, int x, int y, VehicleID selection { int image = GetRoadVehImage(v, 6); uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); - if (v->vehstatus & VS_CRASHED) - ormod = PALETTE_CRASH; - DrawSprite(image | ormod, x+14, y+6); + if (v->vehstatus & VS_CRASHED) ormod = PALETTE_CRASH; + DrawSprite(image | ormod, x + 14, y + 6); if (v->index == selection) { - DrawFrameRect(x-1, y-1, x+28, y+12, 15, FR_BORDERONLY); + DrawFrameRect(x - 1, y - 1, x + 28, y + 12, 15, FR_BORDERONLY); } } @@ -215,6 +214,7 @@ static void ShowRoadVehDetailsWindow(const Vehicle* v) { Window *w; VehicleID veh = v->index; + DeleteWindowById(WC_VEHICLE_ORDERS, veh); DeleteWindowById(WC_VEHICLE_DETAILS, veh); _alloc_wnd_parent_num = veh; @@ -225,11 +225,7 @@ static void ShowRoadVehDetailsWindow(const Vehicle* v) void CcCloneRoadVeh(bool success, uint tile, uint32 p1, uint32 p2) { - if (success) { - const Vehicle* v = GetVehicle(_new_roadveh_id); - - ShowRoadVehViewWindow(v); - } + if (success) ShowRoadVehViewWindow(GetVehicle(_new_roadveh_id)); } static void RoadVehViewWndProc(Window *w, WindowEvent *e) @@ -445,7 +441,7 @@ void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) static void NewRoadVehWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: DrawNewRoadVehWindow(w); break; @@ -1073,7 +1069,7 @@ void ShowPlayerRoadVehicles(PlayerID player, StationID station) } else { w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | player); } - if (w) { + if (w != NULL) { w->caption_color = player; w->vscroll.cap = 7; // maximum number of vehicles shown w->widget[7].unkA = (w->vscroll.cap << 8) + 1; diff --git a/settings_gui.c b/settings_gui.c index 4b404992b9..b53f5e3a52 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -63,16 +63,20 @@ static StringID *BuildDynamicDropdown(StringID base, int num) static int GetCurRes(void) { int i; - for(i = 0; i != _num_resolutions; i++) + + for (i = 0; i != _num_resolutions; i++) { if (_resolutions[i][0] == _screen.width && - _resolutions[i][1] == _screen.height) + _resolutions[i][1] == _screen.height) { break; + } + } return i; } static inline bool RoadVehiclesAreBuilt(void) { - const Vehicle *v; + const Vehicle* v; + FOR_ALL_VEHICLES(v) { if (v->type == VEH_Road) return true; } @@ -551,30 +555,23 @@ void ShowGameDifficulty(void) // virtual PositionMainToolbar function, calls the right one. static int32 v_PositionMainToolbar(int32 p1) { - if (_game_mode != GM_MENU) - PositionMainToolbar(NULL); - + if (_game_mode != GM_MENU) PositionMainToolbar(NULL); return 0; } static int32 AiNew_PatchActive_Warning(int32 p1) { - if (p1 == 1) - ShowErrorMessage(-1, TEMP_AI_ACTIVATED, 0, 0); - - return 0; + if (p1 == 1) ShowErrorMessage(-1, TEMP_AI_ACTIVATED, 0, 0); + return 0; } static int32 PopulationInLabelActive(int32 p1) { - Town *t; + Town* t; FOR_ALL_TOWNS(t) { - if (t->xy) { - UpdateTownVirtCoord(t); - } + if (t->xy != 0) UpdateTownVirtCoord(t); } - return 0; } @@ -639,14 +636,14 @@ static int32 EngineRenewMoneyUpdate(int32 p1) typedef int32 PatchButtonClick(int32); typedef struct PatchEntry { - byte type; // type of selector - byte flags; // selector flags - StringID str; // string with descriptive text - char console_name[40]; // the name this patch has in console - void *variable; // pointer to the variable - int32 min, max; // range for spinbox setting - uint32 step; // step for spinbox - PatchButtonClick *click_proc; // callback procedure + byte type; // type of selector + byte flags; // selector flags + StringID str; // string with descriptive text + char console_name[40]; // the name this patch has in console + void* variable; // pointer to the variable + int32 min, max; // range for spinbox setting + uint32 step; // step for spinbox + PatchButtonClick* click_proc; // callback procedure } PatchEntry; enum { @@ -821,7 +818,6 @@ static void WritePE(const PatchEntry* p, int32 v) static void PatchesSelectionWndProc(Window *w, WindowEvent *e) { - uint i; switch (e->event) { case WE_PAINT: { int x,y; @@ -829,6 +825,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) const PatchPage *page; uint clk; int32 val; + uint i; w->click_state = 1 << (WP(w,def_d).data_1 + 4); @@ -1116,8 +1113,9 @@ void IConsoleGetPatchSetting(const char *name) if (pe->type == PE_BOOL) { snprintf(value, sizeof(value), (ReadPE(pe) == 1) ? "on" : "off"); - } else + } else { snprintf(value, sizeof(value), "%d", ReadPE(pe)); + } IConsolePrintF(_icolour_warn, "Current value for '%s' is: '%s'", name, value); } @@ -1175,9 +1173,9 @@ static void NewgrfWndProc(Window *w, WindowEvent *e) // draw list of all grf files while (c != NULL) { if (i >= w->vscroll.pos) { // draw files according to scrollbar position - bool h = (_sel_grffile==c); + bool h = (_sel_grffile == c); // show highlighted item with a different background and highlighted text - if(h) GfxFillRect(1, y + 1, 267, y + 12, 156); + if (h) GfxFillRect(1, y + 1, 267, y + 12, 156); // XXX - will be grf name later DoDrawString(c->filename, 25, y + 2, h ? 0xC : 0x10); DrawSprite(SPRITE_PALETTE(SPR_SQUARE | PALETTE_TO_RED), 5, y + 2); @@ -1448,23 +1446,27 @@ static void CustCurrencyWndProc(Window *w, WindowEvent *e) val = atoi(b); val = clamp(val, 1, 5000); _custom_currency.rate = val; - break; + break; + case 1: /* Thousands seperator */ _custom_currency.separator = (b[0] == '\0') ? ' ' : b[0]; ttd_strlcpy(_str_separator, b, lengthof(_str_separator)); - break; + break; + case 2: /* Currency prefix */ ttd_strlcpy(_custom_currency.prefix, b, lengthof(_custom_currency.prefix)); - break; + break; + case 3: /* Currency suffix */ ttd_strlcpy(_custom_currency.suffix, b, lengthof(_custom_currency.suffix)); - break; + break; + case 4: /* Year to switch to euro */ val = atoi(b); val = clamp(val, 1999, MAX_YEAR_END_REAL); if (val == 1999) val = 0; _custom_currency.to_euro = val; - break; + break; } MarkWholeScreenDirty(); @@ -1500,11 +1502,9 @@ static const WindowDesc _cust_currency_desc = { void ShowCustCurrency(void) { - Window *w; - _str_separator[0] = _custom_currency.separator; _str_separator[1] = '\0'; DeleteWindowById(WC_CUSTOM_CURRENCY, 0); - w = AllocateWindowDesc(&_cust_currency_desc); + AllocateWindowDesc(&_cust_currency_desc); } diff --git a/ship_cmd.c b/ship_cmd.c index bd2bb2b6bf..b153c5cccb 100644 --- a/ship_cmd.c +++ b/ship_cmd.c @@ -35,7 +35,7 @@ void DrawShipEngine(int x, int y, EngineID engine, uint32 image_ormod) if (is_custom_sprite(spritenum)) { int sprite = GetCustomVehicleIcon(engine, 6); - if (sprite) { + if (sprite != 0) { DrawSprite(sprite | image_ormod, x, y); return; } @@ -51,7 +51,7 @@ int GetShipImage(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_ship_vehicle_info[v->engine_type - SHIP_ENGINES_INDEX].image_index; } return _ship_sprites[spritenum] + direction; @@ -70,10 +70,11 @@ static const Depot* FindClosestShipDepot(const Vehicle* v) NPFFoundTargetData ftd; byte trackdir = GetVehicleTrackdir(v); ftd = NPFRouteToDepotTrialError(v->tile, trackdir, TRANSPORT_WATER, v->owner, INVALID_RAILTYPE); - if (ftd.best_bird_dist == 0) + if (ftd.best_bird_dist == 0) { best_depot = GetDepotByTile(ftd.node.tile); /* Found target */ - else + } else { best_depot = NULL; /* Did not find target */ + } } else { FOR_ALL_DEPOTS(depot) { tile = depot->xy; @@ -93,21 +94,15 @@ static void CheckIfShipNeedsService(Vehicle *v) { const Depot* depot; - if (_patches.servint_ships == 0) - return; - - if (!VehicleNeedsService(v)) - return; - - if (v->vehstatus & VS_STOPPED) - return; + if (_patches.servint_ships == 0) return; + if (!VehicleNeedsService(v)) return; + if (v->vehstatus & VS_STOPPED) return; if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OF_HALT_IN_DEPOT) return; - if (_patches.gotodepot && VehicleHasDepotOrders(v)) - return; + if (_patches.gotodepot && VehicleHasDepotOrders(v)) return; depot = FindClosestShipDepot(v); @@ -140,10 +135,7 @@ void OnNewDay_Ship(Vehicle *v) CheckOrders(v->index, OC_INIT); - if (v->vehstatus & VS_STOPPED) - return; - - + if (v->vehstatus & VS_STOPPED) return; cost = ShipVehInfo(v->engine_type)->running_cost * _price.ship_running / 364; v->profit_this_year -= cost >> 8; @@ -173,8 +165,7 @@ static void HandleBrokenShip(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; } } @@ -268,15 +259,11 @@ static void ProcessShipOrder(Vehicle *v) static void HandleShipLoading(Vehicle *v) { - if (v->current_order.type == OT_NOTHING) - return; + if (v->current_order.type == OT_NOTHING) return; if (v->current_order.type != OT_DUMMY) { - if (v->current_order.type != OT_LOADING) - return; - - if (--v->load_unload_time_rem) - return; + if (v->current_order.type != OT_LOADING) return; + if (--v->load_unload_time_rem) return; if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) { SET_EXPENSES_TYPE(EXPENSES_SHIP_INC); @@ -292,8 +279,7 @@ static void HandleShipLoading(Vehicle *v) Order b = v->current_order; v->current_order.type = OT_LEAVESTATION; v->current_order.flags = 0; - if (!(b.flags & OF_NON_STOP)) - return; + if (!(b.flags & OF_NON_STOP)) return; } } @@ -341,8 +327,7 @@ static void CheckShipLeaveDepot(Vehicle *v) int d; uint m; - if (v->u.ship.state != 0x80) - return; + if (v->u.ship.state != 0x80) return; tile = v->tile; d = (_m[tile].m5&2) ? 1 : 0; @@ -383,15 +368,10 @@ static bool ShipAccelerate(Vehicle *v) } // Decrease somewhat when turning - if (!(v->direction&1)) { - spd = spd * 3 >> 2; - } + if (!(v->direction & 1)) spd = spd * 3 / 4; - if (spd == 0) - return false; - - if ((byte)++spd == 0) - return true; + if (spd == 0) return false; + if ((byte)++spd == 0) return true; v->progress = (t = v->progress) - (byte)spd; @@ -447,7 +427,9 @@ static void ShipArrivesAt(const Vehicle* v, Station* st) /* Check if station was ever visited before */ if (!(st->had_vehicle_of_type & HVOT_SHIP)) { uint32 flags; + st->had_vehicle_of_type |= HVOT_SHIP; + SetDParam(0, st->index); flags = (v->owner == _local_player) ? NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_PLAYER, 0) : NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ARRIVAL_OTHER, 0); AddNewsItem( @@ -564,14 +546,15 @@ static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks ftd = NPFRouteToStationOrTile(src_tile, trackdir, &fstd, TRANSPORT_WATER, v->owner, INVALID_RAILTYPE, PBS_MODE_NONE); - if (ftd.best_trackdir != 0xff) + if (ftd.best_trackdir != 0xff) { /* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains the direction we need to take to get there, if ftd.best_bird_dist is not 0, we did not find our target, but ftd.best_trackdir contains the direction leading to the tile closest to our target. */ return ftd.best_trackdir & 7; /* TODO: Wrapper function? */ - else + } else { return -1; /* Already at target, reverse? */ + } } else { uint b; uint tot_dist, dist; @@ -676,19 +659,16 @@ static void ShipController(Vehicle *v) v->breakdown_ctr--; } - if (v->vehstatus & VS_STOPPED) - return; + if (v->vehstatus & VS_STOPPED) return; ProcessShipOrder(v); HandleShipLoading(v); - if (v->current_order.type == OT_LOADING) - return; + if (v->current_order.type == OT_LOADING) return; CheckShipLeaveDepot(v); - if (!ShipAccelerate(v)) - return; + if (!ShipAccelerate(v)) return; BeginVehicleMove(v); @@ -811,10 +791,8 @@ reverse_direction: static void AgeShipCargo(Vehicle *v) { - if (_age_cargo_skip_counter != 0) - return; - if (v->cargo_days != 255) - v->cargo_days++; + if (_age_cargo_skip_counter != 0) return; + if (v->cargo_days != 255) v->cargo_days++; } void Ship_Tick(Vehicle *v) diff --git a/ship_gui.c b/ship_gui.c index 1ce2503e3e..01a1154733 100644 --- a/ship_gui.c +++ b/ship_gui.c @@ -66,10 +66,10 @@ static void DrawShipImage(const Vehicle *v, int x, int y, VehicleID selection) { int image = GetShipImage(v, 6); uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); - DrawSprite(image | ormod, x+32, y+10); + DrawSprite(image | ormod, x + 32, y + 10); if (v->index == selection) { - DrawFrameRect(x-5, y-1, x+67, y+21, 15, FR_BORDERONLY); + DrawFrameRect(x - 5, y - 1, x + 67, y + 21, 15, FR_BORDERONLY); } } @@ -100,7 +100,7 @@ static void ShipRefitWndProc(Window *w, WindowEvent *e) } break; case WE_CLICK: - switch(e->click.widget) { + switch (e->click.widget) { case 2: { /* listbox */ int y = e->click.pt.y - 25; if (y >= 0) { @@ -291,6 +291,7 @@ static void ShowShipDetailsWindow(const Vehicle* v) { Window *w; VehicleID veh = v->index; + DeleteWindowById(WC_VEHICLE_ORDERS, veh); DeleteWindowById(WC_VEHICLE_DETAILS, veh); _alloc_wnd_parent_num = veh; @@ -314,19 +315,14 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) void CcCloneShip(bool success, uint tile, uint32 p1, uint32 p2) { - if (success) { - const Vehicle* v = GetVehicle(_new_ship_id); - - ShowShipViewWindow(v); - } + if (success) ShowShipViewWindow(GetVehicle(_new_ship_id)); } static void NewShipWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: - if (w->window_number == 0) - w->disabled_state = 1 << 5; + if (w->window_number == 0) w->disabled_state = 1 << 5; // Setup scroll count { @@ -335,8 +331,7 @@ static void NewShipWndProc(Window *w, WindowEvent *e) const Engine* e = GetEngine(SHIP_ENGINES_INDEX); do { - if (HASBIT(e->player_avail, _local_player)) - count++; + if (HASBIT(e->player_avail, _local_player)) count++; } while (++e,--num); SetVScrollCount(w, count); } @@ -760,8 +755,9 @@ static void ClonePlaceObj(TileIndex tile, const Window* w) if (v != NULL) HandleCloneVehClick(v, w); } -static void ShipDepotWndProc(Window *w, WindowEvent *e) { - switch(e->event) { +static void ShipDepotWndProc(Window* w, WindowEvent* e) +{ + switch (e->event) { case WE_PAINT: DrawShipDepotWindow(w); break; @@ -896,10 +892,9 @@ static const WindowDesc _ship_depot_desc = { void ShowShipDepotWindow(TileIndex tile) { - Window *w; + Window* w = AllocateWindowDescFront(&_ship_depot_desc,tile); - w = AllocateWindowDescFront(&_ship_depot_desc,tile); - if (w) { + if (w != NULL) { w->caption_color = GetTileOwner(w->window_number); w->vscroll.cap = 2; w->hscroll.cap = 3; @@ -911,7 +906,8 @@ void ShowShipDepotWindow(TileIndex tile) } -static void DrawSmallOrderList(const Vehicle *v, int x, int y) { +static void DrawSmallOrderList(const Vehicle* v, int x, int y) +{ const Order *order; int sel, i = 0; @@ -920,7 +916,7 @@ static void DrawSmallOrderList(const Vehicle *v, int x, int y) { FOR_VEHICLE_ORDERS(v, order) { if (sel == 0) { _stringwidth_base = 0xE0; - DoDrawString( "\xAF", x-6, y, 16); + DoDrawString("\xAF", x - 6, y, 16); _stringwidth_base = 0; } sel--; @@ -931,8 +927,7 @@ static void DrawSmallOrderList(const Vehicle *v, int x, int y) { DrawString(x, y, STR_A036, 0); y += 6; - if (++i == 4) - break; + if (++i == 4) break; } } } @@ -1081,9 +1076,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e) case 9: { /* Build new Vehicle */ TileIndex tile; - if (!IsWindowOfPrototype(w, _player_ships_widgets)) - break; - + if (!IsWindowOfPrototype(w, _player_ships_widgets)) break; tile = _last_built_ship_depot_tile; do { @@ -1100,8 +1093,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e) } break; case 10: { - if (!IsWindowOfPrototype(w, _player_ships_widgets)) - break; + if (!IsWindowOfPrototype(w, _player_ships_widgets)) break; ShowReplaceVehicleWindow(VEH_Ship); break; @@ -1173,12 +1165,12 @@ void ShowPlayerShips(PlayerID player, StationID station) { Window *w; - if ( player == _local_player) { + if (player == _local_player) { w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | player); } else { w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | player); } - if (w) { + if (w != NULL) { w->caption_color = w->window_number; w->vscroll.cap = 4; w->widget[7].unkA = (w->vscroll.cap << 8) + 1; diff --git a/station_cmd.c b/station_cmd.c index c0a0203df6..b0bceaf8e6 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -44,8 +44,7 @@ static void StationPoolNewBlock(uint start_item) { Station *st; - FOR_ALL_STATIONS_FROM(st, start_item) - st->index = start_item++; + FOR_ALL_STATIONS_FROM(st, start_item) st->index = start_item++; } /** @@ -55,8 +54,7 @@ static void RoadStopPoolNewBlock(uint start_item) { RoadStop *rs; - FOR_ALL_ROADSTOPS_FROM(rs, start_item) - rs->index = start_item++; + FOR_ALL_ROADSTOPS_FROM(rs, start_item) rs->index = start_item++; } /* Initialize the station-pool and roadstop-pool */ @@ -96,7 +94,7 @@ static void InitializeRoadStop(RoadStop *road_stop, RoadStop *previous, TileInde road_stop->station = index; } -RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type) +RoadStop* GetPrimaryRoadStop(const Station* st, RoadStopType type) { switch (type) { case RS_BUS: return st->bus_stops; @@ -107,13 +105,14 @@ RoadStop * GetPrimaryRoadStop(const Station *st, RoadStopType type) return NULL; } -RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type) +RoadStop* GetRoadStopByTile(TileIndex tile, RoadStopType type) { - const Station *st = GetStation(_m[tile].m2); - RoadStop *rs; + const Station* st = GetStation(_m[tile].m2); + RoadStop* rs; - for ( rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) + for (rs = GetPrimaryRoadStop(st, type); rs->xy != tile; rs = rs->next) { assert(rs->next != NULL); + } return rs; } @@ -145,8 +144,7 @@ RoadStop *AllocateRoadStop(void) } /* Check if we can add a block to the pool */ - if (AddBlockToPool(&_roadstop_pool)) - return AllocateRoadStop(); + if (AddBlockToPool(&_roadstop_pool)) return AllocateRoadStop(); return NULL; } @@ -266,8 +264,7 @@ static Station *AllocateStation(void) } /* Check if we can add a block to the pool */ - if (AddBlockToPool(&_station_pool)) - return AllocateStation(); + if (AddBlockToPool(&_station_pool)) return AllocateStation(); _error_message = STR_3008_TOO_MANY_STATIONS_LOADING; return NULL; @@ -480,10 +477,10 @@ static void UpdateStationVirtCoord(Station *st) // Update the virtual coords needed to draw the station sign for all stations. void UpdateAllStationVirtCoord(void) { - Station *st; + Station* st; + FOR_ALL_STATIONS(st) { - if (st->xy != 0) - UpdateStationVirtCoord(st); + if (st->xy != 0) UpdateStationVirtCoord(st); } } @@ -602,8 +599,7 @@ void GetAcceptanceAroundTiles(AcceptedCargo accepts, TileIndex tile, uint i; GetAcceptedCargo(tile, ac); - for (i = 0; i < lengthof(ac); ++i) - accepts[i] += ac[i]; + for (i = 0; i < lengthof(ac); ++i) accepts[i] += ac[i]; } } } @@ -642,8 +638,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg) rect.min_y = MapSizeY(); rect.max_x = rect.max_y = 0; // Don't update acceptance for a buoy - if (IsBuoy(st)) - return; + if (IsBuoy(st)) return; /* old accepted goods types */ old_acc = GetAcceptanceMask(st); @@ -732,7 +727,8 @@ static void UpdateStationAcceptance(Station *st, bool show_msg) // This is called right after a station was deleted. // It checks if the whole station is free of substations, and if so, the station will be // deleted after a little while. -static void DeleteStationIfEmpty(Station *st) { +static void DeleteStationIfEmpty(Station* st) +{ if (st->facilities == 0) { st->delete_ctr = 0; InvalidateWindow(WC_STATION_LIST, st->owner); @@ -753,8 +749,7 @@ int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invali int flat_z; BEGIN_TILE_LOOP(tile_cur, w, h, tile) - if (!EnsureNoVehicle(tile_cur)) - return CMD_ERROR; + if (!EnsureNoVehicle(tile_cur)) return CMD_ERROR; tileh = GetTileSlope(tile_cur, &z); @@ -767,9 +762,7 @@ int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invali b) the build_on_slopes switch is disabled */ if (IsSteepTileh(tileh) || - ((_is_old_ai_player || !_patches.build_on_slopes) - && tileh != 0)) { - + ((_is_old_ai_player || !_patches.build_on_slopes) && tileh != 0)) { _error_message = STR_0007_FLAT_LAND_REQUIRED; return CMD_ERROR; } @@ -897,7 +890,6 @@ static inline byte *CreateMulti(byte *layout, int n, byte b) return layout; } -// stolen from TTDPatch static void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *spec) { if (spec != NULL && spec->lengths >= plat_len && @@ -912,9 +904,8 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, const St if (plat_len == 1) { CreateSingle(layout, numtracks); } else { - if (numtracks & 1) - layout = CreateSingle(layout, plat_len); - numtracks>>=1; + if (numtracks & 1) layout = CreateSingle(layout, plat_len); + numtracks >>= 1; while (--numtracks >= 0) { layout = CreateMulti(layout, plat_len, 4); @@ -1004,24 +995,19 @@ int32 CmdBuildRailroadStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) } //XXX can't we pack this in the "else" part of the if above? - if (!CheckStationSpreadOut(st, tile_org, w_org, h_org)) - return CMD_ERROR; - + if (!CheckStationSpreadOut(st, tile_org, w_org, h_org)) return CMD_ERROR; } else { // Create a new station st = AllocateStation(); - if (st == NULL) - return CMD_ERROR; + if (st == NULL) return CMD_ERROR; st->town = ClosestTownFromTile(tile_org, (uint)-1); - if (_current_player < MAX_PLAYERS && flags&DC_EXEC) + if (_current_player < MAX_PLAYERS && flags & DC_EXEC) SETBIT(st->town->have_ratings, _current_player); - if (!GenerateStationName(st, tile_org, 0)) - return CMD_ERROR; + if (!GenerateStationName(st, tile_org, 0)) return CMD_ERROR; - if (flags & DC_EXEC) - StationInitialize(st, tile_org); + if (flags & DC_EXEC) StationInitialize(st, tile_org); } if (flags & DC_EXEC) { @@ -1176,20 +1162,26 @@ uint GetStationPlatforms(const Station *st, TileIndex tile) TileIndex t; TileIndexDiff delta; int dir; - int len; + uint len; assert(TileBelongsToRailStation(st, tile)); len = 0; - dir = _m[tile].m5&1; + dir = _m[tile].m5 & 1; delta = dir ? TileDiffXY(0, 1) : TileDiffXY(1, 0); // find starting tile.. t = tile; - do { t -= delta; len++; } while (TileBelongsToRailStation(st, t) && (_m[t].m5&1) == dir); + do { + t -= delta; + len++; + } while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir); // find ending tile t = tile; - do { t += delta; len++; }while (TileBelongsToRailStation(st, t) && (_m[t].m5&1) == dir); + do { + t += delta; + len++; + } while (TileBelongsToRailStation(st, t) && (_m[t].m5 & 1) == dir); return len - 1; } @@ -1396,17 +1388,15 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2) return CMD_ERROR; cost = CheckFlatLandBelow(tile, 1, 1, flags, 1 << p1, NULL); - if (cost == CMD_ERROR) - return CMD_ERROR; + if (cost == CMD_ERROR) return CMD_ERROR; st = GetStationAround(tile, 1, 1, -1); - if (st == CHECK_STATIONS_ERR) - return CMD_ERROR; + if (st == CHECK_STATIONS_ERR) return CMD_ERROR; /* 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) st = NULL; } //give us a road stop in the list, and check if something went wrong @@ -1429,8 +1419,7 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2) Town *t; st = AllocateStation(); - if (st == NULL) - return CMD_ERROR; + if (st == NULL) return CMD_ERROR; st->town = t = ClosestTownFromTile(tile, (uint)-1); @@ -1441,11 +1430,9 @@ int32 CmdBuildRoadStop(int x, int y, uint32 flags, uint32 p1, uint32 p2) st->sign.width_1 = 0; - if (!GenerateStationName(st, tile, 0)) - return CMD_ERROR; + if (!GenerateStationName(st, tile, 0)) return CMD_ERROR; - if (flags & DC_EXEC) - StationInitialize(st, tile); + if (flags & DC_EXEC) StationInitialize(st, tile); } cost += (type) ? _price.build_truck_station : _price.build_bus_station; @@ -1489,7 +1476,7 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) if (_current_player != OWNER_WATER && !CheckOwnership(st->owner)) return CMD_ERROR; - if (is_truck) { //truck stop + if (is_truck) { // truck stop primary_stop = &st->truck_stops; cur_stop = GetRoadStopByTile(tile, RS_TRUCK); } else { @@ -1503,7 +1490,7 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) return CMD_ERROR; if (flags & DC_EXEC) { - int i; + uint i; DoClearSquare(tile); /* Clear all vehicles destined for this station */ @@ -1515,19 +1502,14 @@ static int32 RemoveRoadStop(Station *st, uint32 flags, TileIndex tile) } cur_stop->used = false; - if (cur_stop->prev != NULL) //alter previous stop - cur_stop->prev->next = cur_stop->next; - - if (cur_stop->next != NULL) //alter next stop - cur_stop->next->prev = cur_stop->prev; + if (cur_stop->prev != NULL) cur_stop->prev->next = cur_stop->next; + if (cur_stop->next != NULL) cur_stop->next->prev = cur_stop->prev; //we only had one stop left if (cur_stop->next == NULL && cur_stop->prev == NULL) { - //so we remove ALL stops *primary_stop = NULL; st->facilities &= (is_truck) ? ~FACIL_TRUCK_STOP : ~FACIL_BUS_STOP; - } else if (cur_stop == *primary_stop) { //removed the first stop in the list //need to set the primary element to the next stop @@ -1666,7 +1648,7 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) st->town = t; - if (_current_player < MAX_PLAYERS && flags&DC_EXEC) + if (_current_player < MAX_PLAYERS && flags & DC_EXEC) SETBIT(t->have_ratings, _current_player); st->sign.width_1 = 0; @@ -1697,12 +1679,13 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2) st->build_date = _date; - /* if airport was demolished while planes were en-route to it, the positions can no longer - be the same (v->u.air.pos), since different airports have different indexes. So update - all planes en-route to this airport. Only update if - 1. airport is upgraded - 2. airport is added to existing station (unfortunately unavoideable) - */ + /* if airport was demolished while planes were en-route to it, the + * positions can no longer be the same (v->u.air.pos), since different + * airports have different indexes. So update all planes en-route to this + * airport. Only update if + * 1. airport is upgraded + * 2. airport is added to existing station (unfortunately unavoideable) + */ if (airport_upgrade) UpdateAirplanesOnNewStation(st); { @@ -1850,11 +1833,8 @@ static int32 RemoveBuoy(Station *st, uint32 flags) tile = st->dock_tile; - if (CheckShipsOnBuoy(st)) - return_cmd_error(STR_BUOY_IS_IN_USE); - - if (!EnsureNoVehicle(tile)) - return CMD_ERROR; + if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE); + if (!EnsureNoVehicle(tile)) return CMD_ERROR; if (flags & DC_EXEC) { st->dock_tile = 0; @@ -1963,8 +1943,7 @@ int32 CmdBuildDock(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (!GenerateStationName(st, tile, 3)) return CMD_ERROR; - if (flags & DC_EXEC) - StationInitialize(st, tile); + if (flags & DC_EXEC) StationInitialize(st, tile); } if (flags & DC_EXEC) { @@ -2001,17 +1980,13 @@ static int32 RemoveDock(Station *st, uint32 flags) TileIndex tile1; TileIndex tile2; - if (!CheckOwnership(st->owner)) - return CMD_ERROR; + if (!CheckOwnership(st->owner)) return CMD_ERROR; tile1 = st->dock_tile; tile2 = tile1 + TileOffsByDir(_m[tile1].m5 - 0x4C); - if (!EnsureNoVehicle(tile1)) - return CMD_ERROR; - - if (!EnsureNoVehicle(tile2)) - return CMD_ERROR; + if (!EnsureNoVehicle(tile1)) return CMD_ERROR; + if (!EnsureNoVehicle(tile2)) return CMD_ERROR; if (flags & DC_EXEC) { DoClearSquare(tile1); @@ -2048,8 +2023,7 @@ static void DrawTile_Station(TileInfo *ti) { PlayerID owner = GetTileOwner(ti->tile); image_or_modificator = PALETTE_TO_GREY; /* NOTE: possible bug in ttd here? */ - if (owner < MAX_PLAYERS) - image_or_modificator = PLAYER_SPRITE_COLOR(owner); + if (owner < MAX_PLAYERS) image_or_modificator = PLAYER_SPRITE_COLOR(owner); } // don't show foundation for docks (docks are between 76 (0x4C) and 81 (0x51)) @@ -2074,8 +2048,7 @@ static void DrawTile_Station(TileInfo *ti) if (t == NULL) t = &_station_display_datas[ti->map5]; image = t->ground_sprite; - if (image & PALETTE_MODIFIER_COLOR) - image |= image_or_modificator; + if (image & PALETTE_MODIFIER_COLOR) image |= image_or_modificator; // For custom sprites, there's no railtype-based pitching. offset = (image & SPRITE_MASK) < _custom_sprites_base ? rti->total_offset : railtype; @@ -2124,8 +2097,7 @@ void StationPickerDrawSprite(int x, int y, RailType railtype, int image) t = &_station_display_datas[image]; img = t->ground_sprite; - if (img & PALETTE_MODIFIER_COLOR) - img |= ormod; + if (img & PALETTE_MODIFIER_COLOR) img |= ormod; DrawSprite(img + rti->total_offset, x, y); foreach_draw_tile_seq(dtss, t->seq) { @@ -2280,7 +2252,6 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) { StationID station_id; byte dir; - uint16 spd; if (v->type == VEH_Train) { if (IS_BYTE_INSIDE(_m[tile].m5, 0, 8) && v->subtype == TS_Front_Engine && @@ -2289,7 +2260,6 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) 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) { @@ -2299,15 +2269,14 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) dir = v->direction & 6; if (dir & 2) intswap(x,y); if (y == 8) { - if (dir != 2 && dir != 4) { - x = (~x)&0xF; - } + if (dir != 2 && dir != 4) x = ~x & 0xF; if (x == 12) return 2 | (station_id << 8); /* enter station */ if (x < 12) { + uint16 spd; + v->vehstatus |= VS_TRAIN_SLOWING; spd = _enter_station_speedtable[x]; - if (spd < v->cur_speed) - v->cur_speed = spd; + if (spd < v->cur_speed) v->cur_speed = spd; } } } @@ -2391,8 +2360,7 @@ static void DeleteStation(Station *st) } } //Orders for the vehicle have been changed, invalidate the window - if (invalidate) - InvalidateWindow(WC_VEHICLE_ORDERS, v->index); + if (invalidate) InvalidateWindow(WC_VEHICLE_ORDERS, v->index); } //Subsidies need removal as well @@ -2404,8 +2372,7 @@ void DeleteAllPlayerStations(void) Station *st; FOR_ALL_STATIONS(st) { - if (st->xy && st->owner < MAX_PLAYERS) - DeleteStation(st); + if (st->xy != 0 && st->owner < MAX_PLAYERS) DeleteStation(st); } } @@ -2435,10 +2402,7 @@ static void StationHandleBigTick(Station *st) { UpdateStationAcceptance(st, true); - if (st->facilities == 0) { - if (++st->delete_ctr >= 8) - DeleteStation(st); - } + if (st->facilities == 0 && ++st->delete_ctr >= 8) DeleteStation(st); // Here we saveguard against orphaned slots CheckOrphanedSlots(st, RS_BUS); @@ -2546,15 +2510,13 @@ static void StationHandleSmallTick(Station *st) { byte b; - if (st->facilities == 0) - return; + if (st->facilities == 0) return; b = st->delete_ctr + 1; if (b >= 185) b = 0; st->delete_ctr = b; - if (b == 0) - UpdateStationRating(st); + if (b == 0) UpdateStationRating(st); } void OnTick_Station(void) @@ -2562,22 +2524,17 @@ void OnTick_Station(void) uint i; Station *st; - if (_game_mode == GM_EDITOR) - return; + if (_game_mode == GM_EDITOR) return; i = _station_tick_ctr; - if (++_station_tick_ctr == GetStationPoolSize()) - _station_tick_ctr = 0; + if (++_station_tick_ctr == GetStationPoolSize()) _station_tick_ctr = 0; st = GetStation(i); - if (st->xy != 0) - StationHandleBigTick(st); + if (st->xy != 0) StationHandleBigTick(st); FOR_ALL_STATIONS(st) { - if (st->xy != 0) - StationHandleSmallTick(st); + if (st->xy != INVALID_TILE) StationHandleSmallTick(st); } - } void StationMonthlyLoop(void) @@ -2623,7 +2580,7 @@ static void UpdateStationWaiting(Station *st, int type, uint amount) */ int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) { - StringID str,old_str; + StringID str; Station *st; if (!IsStationIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR; @@ -2635,7 +2592,8 @@ int32 CmdRenameStation(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (str == 0) return CMD_ERROR; if (flags & DC_EXEC) { - old_str = st->string_id; + StringID old_str = st->string_id; + st->string_id = str; UpdateStationVirtCoord(st); DeleteName(old_str); @@ -2686,7 +2644,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) cur_tile = TILE_MASK(cur_tile); if (IsTileType(cur_tile, MP_STATION)) { st_index = _m[cur_tile].m2; - for(i=0; i!=8; i++) { + for (i = 0; i != 8; i++) { if (around[i] == INVALID_STATION) { st = GetStation(st_index); if (!IsBuoy(st) && @@ -2788,7 +2746,7 @@ uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount) void BuildOilRig(TileIndex tile) { - int j; + uint j; Station *st = AllocateStation(); if (st == NULL) { @@ -2804,11 +2762,11 @@ void BuildOilRig(TileIndex tile) st->sign.width_1 = 0; SetTileType(tile, MP_STATION); - _m[tile].m5 = 0x4B; SetTileOwner(tile, OWNER_NONE); + _m[tile].m2 = st->index; _m[tile].m3 = 0; _m[tile].m4 = 0; - _m[tile].m2 = st->index; + _m[tile].m5 = 0x4B; st->owner = OWNER_NONE; st->airport_flags = 0; @@ -2887,24 +2845,14 @@ static int32 ClearTile_Station(TileIndex tile, byte flags) st = GetStation(_m[tile].m2); - if (m5 < 8) - return RemoveRailroadStation(st, tile, flags); - + if (m5 < 8) return RemoveRailroadStation(st, tile, flags); // original airports < 67, new airports between 83 - 114 - if (m5 < 0x43 || ( m5 >= 83 && m5 <= 114) ) - return RemoveAirport(st, flags); - - if (m5 < 0x4B) - return RemoveRoadStop(st, flags, tile); - - if (m5 == 0x52) - return RemoveBuoy(st, flags); - - if (m5 != 0x4B && m5 < 0x53) - return RemoveDock(st, flags); + if (m5 < 0x43 || (m5 >= 83 && m5 <= 114)) return RemoveAirport(st, flags); + if (m5 < 0x4B) return RemoveRoadStop(st, flags, tile); + if (m5 == 0x52) return RemoveBuoy(st, flags); + if (m5 != 0x4B && m5 < 0x53) return RemoveDock(st, flags); return CMD_ERROR; - } void InitializeStations(void) @@ -3036,8 +2984,9 @@ static void SaveLoad_STNS(Station *st) SlObject(&st->goods[i], _goods_desc); /* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */ - if (_sl_full_version < 0x700 && st->goods[i].enroute_from == 0xFF) + if (_sl_full_version < 0x700 && st->goods[i].enroute_from == 0xFF) { st->goods[i].enroute_from = INVALID_STATION; + } } } @@ -3066,10 +3015,11 @@ static void Load_STNS(void) SaveLoad_STNS(st); // this means it's an oldstyle savegame without support for nonuniform stations - if (st->train_tile && st->trainst_h == 0) { + if (st->train_tile != 0 && st->trainst_h == 0) { int w = st->trainst_w >> 4; int h = st->trainst_w & 0xF; - if (_m[st->train_tile].m5&1) intswap(w,h); + + if (_m[st->train_tile].m5 & 1) intswap(w, h); st->trainst_w = w; st->trainst_h = h; } @@ -3094,8 +3044,7 @@ static void Load_STNS(void) } /* This is to ensure all pointers are within the limits of _stations_size */ - if (_station_tick_ctr > GetStationPoolSize()) - _station_tick_ctr = 0; + if (_station_tick_ctr > GetStationPoolSize()) _station_tick_ctr = 0; } static void Save_ROADSTOP(void) diff --git a/station_gui.c b/station_gui.c index 48d3fdf6c0..268ec56ee1 100644 --- a/station_gui.c +++ b/station_gui.c @@ -22,34 +22,33 @@ static void StationsWndShowStationRating(int x, int y, int type, uint acceptance int color = _rating_colors[type]; uint w; - if (acceptance > 575) - acceptance = 575; + if (acceptance > 575) acceptance = 575; - acceptance = (acceptance + 7) >> 3; + acceptance = (acceptance + 7) / 8; /* draw cargo */ - if ( (w=acceptance>>3) != 0) { - GfxFillRect(x, y, x+w-1, y+6, color); + w = acceptance / 8; + if (w != 0) { + GfxFillRect(x, y, x + w - 1, y + 6, color); x += w; } - if ( (w=acceptance&7) != 0) { - if (w==7) w--; - GfxFillRect(x, y+(w-1), x, y+6, color); + w = acceptance % 8; + if (w != 0) { + if (w == 7) w--; + GfxFillRect(x, y + (w - 1), x, y + 6, color); } - x -= (acceptance>>3); + x -= acceptance / 8; - DrawString(x+1, y, _cargoc.names_short[type], 0x10); + DrawString(x + 1, y, _cargoc.names_short[type], 0x10); /* draw green/red ratings bar */ - GfxFillRect(x+1, y+8, x+7, y+8, 0xB8); + GfxFillRect(x + 1, y + 8, x + 7, y + 8, 0xB8); - rating = (rating >> 5); + rating >>= 5; - if (rating != 0) { - GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0); - } + if (rating != 0) GfxFillRect(x + 1, y + 8, x + rating, y + 8, 0xD0); } static uint16 _num_station_sort[MAX_PLAYERS]; @@ -67,7 +66,7 @@ static int CDECL StationNameSorter(const void *a, const void *b) argv[0] = cmp1->index; GetStringWithArgs(buf1, STR_STATION, argv); - if ( cmp2->index != _last_station_idx) { + if (cmp2->index != _last_station_idx) { _last_station_idx = cmp2->index; argv[0] = cmp2->index; GetStringWithArgs(_bufcache, STR_STATION, argv); @@ -91,7 +90,7 @@ static void GlobalSortStationList(void) error("Could not allocate memory for the station-sorting-list"); FOR_ALL_STATIONS(st) { - if(st->xy && st->owner != OWNER_NONE) { + if (st->xy != 0 && st->owner != OWNER_NONE) { _station_sort[n].index = st->index; _station_sort[n++].owner = st->owner; _num_station_sort[st->owner]++; // add number of stations of player @@ -101,7 +100,9 @@ static void GlobalSortStationList(void) // create cumulative station-ownership // stations are stored as a cummulative index, eg 25, 41, 43. This means // Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 - for (i = &_num_station_sort[1]; i != endof(_num_station_sort); i++) {*i += *(i-1);} + for (i = &_num_station_sort[1]; i != endof(_num_station_sort); i++) { + *i += *(i - 1); + } qsort(_station_sort, n, sizeof(_station_sort[0]), GeneralOwnerSorter); // sort by owner @@ -135,18 +136,14 @@ static void MakeSortedStationList(PlayerID owner) static void PlayerStationsWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: { const PlayerID owner = w->window_number; uint32 i; // resort station window if stations have been added/removed - if (_global_station_sort_dirty) - GlobalSortStationList(); - - if (_station_sort_dirty[owner]) { // resort in case of a station rename. - MakeSortedStationList(owner); - } + if (_global_station_sort_dirty) GlobalSortStationList(); + if (_station_sort_dirty[owner]) MakeSortedStationList(owner); // stations are stored as a cummulative index, eg 25, 41, 43. This means // Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 stations @@ -187,8 +184,9 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e) x = DrawString(xb, y, STR_3049_0, 0) + 5; // show cargo waiting and station ratings - for(j=0; j!=NUM_CARGO; j++) { - int acc = GB(st->goods[j].waiting_acceptance, 0, 12); + for (j = 0; j != NUM_CARGO; j++) { + uint acc = GB(st->goods[j].waiting_acceptance, 0, 12); + if (acc != 0) { StationsWndShowStationRating(x, y, j, acc, st->goods[j].rating); x += 10; @@ -196,16 +194,16 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e) } y += 10; i++; // next station - if (++p == w->vscroll.cap) { break;} // max number of stations in 1 window + if (++p == w->vscroll.cap) break; // max number of stations in 1 window } } } break; case WE_CLICK: { - switch(e->click.widget) { + switch (e->click.widget) { case 3: { uint32 id_v = (e->click.pt.y - 15) / 10; - if (id_v >= w->vscroll.cap) { return;} // click out of bounds + if (id_v >= w->vscroll.cap) return; // click out of bounds id_v += w->vscroll.pos; @@ -215,7 +213,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e) id_v += (owner == 0) ? 0 : _num_station_sort[owner - 1]; // first element in list - if (id_v >= _num_station_sort[owner]) { return;} // click out of station bound + if (id_v >= _num_station_sort[owner]) return; // click out of station bound st = GetStation(_station_sort[id_v].index); @@ -229,7 +227,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e) case WE_4: WP(w,plstations_d).refresh_counter++; - if (WP(w,plstations_d).refresh_counter==5) { + if (WP(w,plstations_d).refresh_counter == 5) { WP(w,plstations_d).refresh_counter = 0; SetWindowDirty(w); } @@ -320,11 +318,10 @@ static void DrawStationViewWindow(Window *w) StringID str; num = 1; - for(i=0; i!=NUM_CARGO; i++) { + for (i = 0; i != NUM_CARGO; i++) { if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) { num++; - if (st->goods[i].enroute_from != station_id) - num++; + if (st->goods[i].enroute_from != station_id) num++; } } SetVScrollCount(w, num); @@ -347,8 +344,9 @@ static void DrawStationViewWindow(Window *w) if (--pos < 0) { str = STR_00D0_NOTHING; - for(i=0; i!=NUM_CARGO; i++) + for (i = 0; i != NUM_CARGO; i++) { if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY; + } SetDParam(0, str); DrawString(x, y, STR_0008_WAITING, 0); y += 10; @@ -357,8 +355,7 @@ static void DrawStationViewWindow(Window *w) i = 0; do { uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12); - if (waiting == 0) - continue; + if (waiting == 0) continue; num = (waiting + 5) / 10; if (num != 0) { @@ -417,11 +414,10 @@ static void DrawStationViewWindow(Window *w) DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245); } else { - DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0); y = 77; - for(i=0; i!=NUM_CARGO; i++) { + for (i = 0; i != NUM_CARGO; i++) { if (st->goods[i].enroute_from != INVALID_STATION) { SetDParam(0, _cargoc.names_s[i]); SetDParam(2, st->goods[i].rating * 101 >> 8); @@ -436,13 +432,13 @@ static void DrawStationViewWindow(Window *w) static void StationViewWndProc(Window *w, WindowEvent *e) { - switch(e->event) { + switch (e->event) { case WE_PAINT: DrawStationViewWindow(w); break; case WE_CLICK: - switch(e->click.widget) { + switch (e->click.widget) { case 7: ScrollMainWindowToTile(GetStation(w->window_number)->xy); break; diff --git a/stdafx.h b/stdafx.h index c790cdc905..74c44e46de 100644 --- a/stdafx.h +++ b/stdafx.h @@ -198,21 +198,21 @@ typedef unsigned char byte; static inline uint16 TO_LE16(uint16 x) { return BSWAP16(x); } static inline uint32 FROM_LE32(uint32 x) { return BSWAP32(x); } static inline uint16 FROM_LE16(uint16 x) { return BSWAP16(x); } -# define TO_BE32(x) x -# define TO_BE16(x) x -# define FROM_BE32(x) x -# define FROM_BE16(x) x -# define TO_BE32X(x) x +# define TO_BE32(x) (x) +# define TO_BE16(x) (x) +# define FROM_BE32(x) (x) +# define FROM_BE16(x) (x) +# define TO_BE32X(x) (x) #else static inline uint32 TO_BE32(uint32 x) { return BSWAP32(x); } static inline uint16 TO_BE16(uint16 x) { return BSWAP16(x); } static inline uint32 FROM_BE32(uint32 x) { return BSWAP32(x); } static inline uint16 FROM_BE16(uint16 x) { return BSWAP16(x); } -# define TO_LE32(x) x -# define TO_LE16(x) x +# define TO_LE32(x) (x) +# define TO_LE16(x) (x) # define TO_BE32X(x) BSWAP32(x) -# define FROM_LE32(x) x -# define FROM_LE16(x) x +# define FROM_LE32(x) (x) +# define FROM_LE16(x) (x) #endif /* TTD_BIG_ENDIAN */ #if !defined(GAME_DATA_DIR) @@ -241,7 +241,7 @@ typedef unsigned char byte; assert_compile(sizeof(uint32) == 4); assert_compile(sizeof(uint16) == 2); -assert_compile(sizeof(uint8) == 1); +assert_compile(sizeof(uint8) == 1); #define lengthof(x) (sizeof(x)/sizeof(x[0])) #define endof(x) (&x[lengthof(x)]) diff --git a/strings.c b/strings.c index cde711a470..ee03b9978d 100644 --- a/strings.c +++ b/strings.c @@ -188,11 +188,12 @@ char *GetStringWithArgs(char *buffr, uint string, const int32 *argv) return FormatString(buffr, _userstring, NULL, 0); } - if (index >= _langtab_num[tab]) + if (index >= _langtab_num[tab]) { error( "!String 0x%X is invalid. " "Probably because an old version of the .lng file.\n", string ); + } return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8)); } @@ -317,7 +318,7 @@ static char *FormatYmdString(char *buff, uint16 number) memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4); buff[3] = ' '; - return FormatNoCommaNumber(buff+4, ymd.year + MAX_YEAR_BEGIN_REAL); + return FormatNoCommaNumber(buff + 4, ymd.year + MAX_YEAR_BEGIN_REAL); } static char *FormatMonthAndYear(char *buff, uint16 number) @@ -615,8 +616,7 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c byte *s = (byte*)GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender. int len; int gender = 0; - if (s && s[0] == 0x87) - gender = s[1]; + if (s != NULL && s[0] == 0x87) gender = s[1]; str = ParseStringChoice(str, gender, buff, &len); buff += len; break; @@ -715,7 +715,8 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c case 0x9B: { // {TOWN} const Town* t = GetTown(GetInt32(&argv)); int32 temp[1]; - assert(t->xy); + + assert(t->xy != 0); temp[0] = t->townnameparts; buff = GetStringWithArgs(buff, t->townnametype, temp); @@ -728,7 +729,7 @@ static char *FormatString(char *buff, const char *str, const int32 *argv, uint c } case 0x9D: { // {SETCASE} - // This is a pseudo command, it's outputted when someone does {STRING.ack} + // This is a pseudo command, it's outputted when someone does {STRING.ack} // The modifier is added to all subsequent GetStringWithArgs that accept the modifier. modifier = (byte)*str++ << 24; break; diff --git a/subsidy_gui.c b/subsidy_gui.c index 70cc3078c5..647cefc3ef 100644 --- a/subsidy_gui.c +++ b/subsidy_gui.c @@ -17,14 +17,14 @@ static void HandleSubsidyClick(int y) { const Subsidy* s; - int num,offs; + uint num; + int offs; TileIndex xy; - if (y < 0) - return; + if (y < 0) return; num = 0; - for(s=_subsidies; s != endof(_subsidies); s++) { + for (s = _subsidies; s != endof(_subsidies); s++) { if (s->cargo_type != CT_INVALID && s->age < 12) { y -= 10; if (y < 0) goto handle_click; @@ -40,7 +40,7 @@ static void HandleSubsidyClick(int y) y -= 11; if (y < 0) return; - for(s=_subsidies; s != endof(_subsidies); s++) { + for (s = _subsidies; s != endof(_subsidies); s++) { if (s->cargo_type != CT_INVALID && s->age >= 12) { y -= 10; if (y < 0) goto handle_click; @@ -78,7 +78,9 @@ static void DrawSubsidiesWindow(const Window* w) { YearMonthDay ymd; const Subsidy* s; - int x,xt,y,num,x2; + uint num; + int x; + int y; DrawWindowWidgets(w); @@ -90,10 +92,12 @@ static void DrawSubsidiesWindow(const Window* w) y += 10; num = 0; - for(s=_subsidies; s != endof(_subsidies); s++) { + for (s = _subsidies; s != endof(_subsidies); s++) { if (s->cargo_type != CT_INVALID && s->age < 12) { + int x2; + SetupSubsidyDecodeParam(s, 1); - x2 = DrawString(x+2, y, STR_2027_FROM_TO, 0); + x2 = DrawString(x + 2, y, STR_2027_FROM_TO, 0); SetDParam(0, _date - ymd.day + 384 - s->age * 32); DrawString(x2, y, STR_2028_BY, 0); @@ -103,17 +107,18 @@ static void DrawSubsidiesWindow(const Window* w) } if (num == 0) { - DrawString(x+2, y, STR_202A_NONE, 0); + DrawString(x + 2, y, STR_202A_NONE, 0); y += 10; } - DrawString(x, y+1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); + DrawString(x, y + 1, STR_202B_SERVICES_ALREADY_SUBSIDISED, 0); y += 10; num = 0; - for(s=_subsidies; s != endof(_subsidies); s++) { + for (s = _subsidies; s != endof(_subsidies); s++) { if (s->cargo_type != CT_INVALID && s->age >= 12) { const Player* p; + int xt; SetupSubsidyDecodeParam(s, 1); @@ -121,7 +126,7 @@ static void DrawSubsidiesWindow(const Window* w) SetDParam(3, p->name_1); SetDParam(4, p->name_2); - xt = DrawString(x+2, y, STR_202C_FROM_TO, 0); + xt = DrawString(x + 2, y, STR_202C_FROM_TO, 0); SetDParam(0, _date - ymd.day + 768 - s->age * 32); DrawString(xt, y, STR_202D_UNTIL, 0); @@ -130,21 +135,19 @@ static void DrawSubsidiesWindow(const Window* w) } } - if (num == 0) { - DrawString(x+2, y, STR_202A_NONE, 0); - } + if (num == 0) DrawString(x + 2, y, STR_202A_NONE, 0); } static void SubsidiesListWndProc(Window *w, WindowEvent *e) { - switch(e->event) { - case WE_PAINT: DrawSubsidiesWindow(w); break; - case WE_CLICK: { - switch(e->click.widget) { - case 2: HandleSubsidyClick(e->click.pt.y - 25); break; - } - } - break; + switch (e->event) { + case WE_PAINT: DrawSubsidiesWindow(w); break; + + case WE_CLICK: + switch (e->click.widget) { + case 2: HandleSubsidyClick(e->click.pt.y - 25); break; + } + break; } } diff --git a/table/engines.h b/table/engines.h index b1ace97c69..df9b9bc252 100644 --- a/table/engines.h +++ b/table/engines.h @@ -469,7 +469,7 @@ const AircraftVehicleInfo orig_aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES] = { { 6, 18, 240, 3, SND_09_JET, 40, 74, 30, 200 }, /* 5 */ { 2, 17, 150, 1, SND_09_JET, 35, 74, 15, 100 }, /* 6 */ { 2, 18, 245, 3, SND_09_JET, 40, 74, 30, 150 }, /* 7 */ - { 3, 19, 192, 3, SND_09_JET, 40, 74, 40, 220 }, /* 8 */ + { 3, 19, 192, 3, SND_09_JET, 40, 74, 40, 220 }, /* 8 */ { 3, 20, 190, 3, SND_09_JET, 40, 74, 25, 230 }, /* 9 */ { 2, 16, 135, 3, SND_09_JET, 35, 74, 10, 95 }, /* 10 */ { 2, 18, 240, 3, SND_09_JET, 40, 74, 35, 170 }, /* 11 */ diff --git a/table/sprites.h b/table/sprites.h index 8ee56c20d2..663fbdd286 100644 --- a/table/sprites.h +++ b/table/sprites.h @@ -51,7 +51,7 @@ enum Sprites { SPR_CANALS_BASE = 5382, SPR_SLOPES_BASE = SPR_CANALS_BASE + 70, SPR_AUTORAIL_BASE = SPR_SLOPES_BASE + 78, - SPR_OPENTTD_BASE = SPR_AUTORAIL_BASE + 55, // can be lowered once autorail.grf is finalized + SPR_OPENTTD_BASE = SPR_AUTORAIL_BASE + 55, SPR_BLOT = SPR_OPENTTD_BASE + 29, // colored circle (mainly used as vehicle profit marker and for sever compatibility) @@ -963,7 +963,6 @@ typedef enum CursorSprites { SPR_CURSOR_EW_MAGLEV = 1273, SPR_CURSOR_NWSE_MAGLEV = 1274, - SPR_CURSOR_RAIL_DEPOT = 1296, SPR_CURSOR_RAIL_STATION = 1300, SPR_CURSOR_TUNNEL_RAIL = 2434, @@ -975,6 +974,8 @@ typedef enum CursorSprites { SPR_CURSOR_AUTOMAGLEV = SPR_OPENTTD_BASE + 6, SPR_CURSOR_WAYPOINT = SPR_OPENTTD_BASE + 7, + + SPR_CURSOR_RAIL_DEPOT = 1296, SPR_CURSOR_MONO_DEPOT = SPR_OPENTTD_BASE + 11, SPR_CURSOR_MAGLEV_DEPOT = SPR_OPENTTD_BASE + 12, @@ -1004,15 +1005,15 @@ enum AnimCursors { }; /** - * Bitmask setup. For the graphics system, 32 bits are used to define - * the sprite to be displayed. This variable contains various information:

- *