summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai/trolly/build.c4
-rw-r--r--ai/trolly/pathfinder.c6
-rw-r--r--ai/trolly/trolly.c23
-rw-r--r--aircraft_cmd.c74
-rw-r--r--aircraft_gui.c7
-rw-r--r--airport.c52
-rw-r--r--dock_gui.c20
-rw-r--r--engine_gui.c9
-rw-r--r--gui.h4
-rw-r--r--industry_cmd.c23
-rw-r--r--main_gui.c8
-rw-r--r--misc_gui.c66
-rw-r--r--namegen.c2
-rw-r--r--network_gui.c4
-rw-r--r--newgrf.c12
-rw-r--r--news_gui.c24
-rw-r--r--order_cmd.c18
-rw-r--r--order_gui.c60
-rw-r--r--player_gui.c42
-rw-r--r--rail_cmd.c85
-rw-r--r--road_cmd.c26
-rw-r--r--roadveh_cmd.c11
-rw-r--r--roadveh_gui.c2
-rw-r--r--settings_gui.c2
-rw-r--r--ship_gui.c2
-rw-r--r--station_cmd.c77
-rw-r--r--station_gui.c8
-rw-r--r--texteff.c33
-rw-r--r--tile.c8
-rw-r--r--town_cmd.c11
-rw-r--r--town_gui.c6
-rw-r--r--train_cmd.c43
-rw-r--r--train_gui.c2
-rw-r--r--vehicle.c30
-rw-r--r--vehicle_gui.c39
-rw-r--r--water_cmd.c27
-rw-r--r--window.c25
-rw-r--r--window.h2
38 files changed, 443 insertions, 454 deletions
diff --git a/ai/trolly/build.c b/ai/trolly/build.c
index 80f0fdf1b..bc173892c 100644
--- a/ai/trolly/build.c
+++ b/ai/trolly/build.c
@@ -229,7 +229,7 @@ int AiNew_PickVehicle(Player *p)
count = _cargoc.ai_roadveh_count[p->ainew.cargo];
// Let's check it backwards.. we simply want to best engine available..
- for (i=start+count-1;i>=start;i--) {
+ for (i = start + count - 1; i >= start; i--) {
// Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY
if (!HASBIT(GetEngine(i)->player_avail, _current_player) || GetEngine(i)->reliability * 100 < AI_VEHICLE_MIN_RELIABILTY << 16) continue;
@@ -238,7 +238,7 @@ int AiNew_PickVehicle(Player *p)
if (!CmdFailed(ret)) break;
}
// We did not find a vehicle :(
- if (CmdFailed(ret)) { return -1; }
+ if (CmdFailed(ret)) return -1;
return i;
}
}
diff --git a/ai/trolly/pathfinder.c b/ai/trolly/pathfinder.c
index aa44014f9..126e0cd41 100644
--- a/ai/trolly/pathfinder.c
+++ b/ai/trolly/pathfinder.c
@@ -506,9 +506,5 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
}
}
- // Res should never be below zero.. if so, make it zero!
- if (res < 0) { res = 0; }
-
- // Return our value
- return res;
+ return (res < 0) ? 0 : res;
}
diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c
index 5e16c51a9..c40b0faef 100644
--- a/ai/trolly/trolly.c
+++ b/ai/trolly/trolly.c
@@ -1,17 +1,18 @@
-/* $Id: ai_new.c 2891 2005-08-26 20:26:34Z tron $ */
+/* $Id$ */
/*
- * This AI was created as a direct reaction to the big demand for some good AIs in OTTD.
- * Too bad it never left alpha-stage, and it is considered dead in his current form.
- * By the time of writing this, we, the creator of this AI and a good friend of mine,
- * are designing a whole new AI-system that allows us to create AIs easier and without
- * all the fuzz we encountered while I was working on this AI. By the time that system
- * is finished, you can expect that this AI will dissapear, because it is pretty
- * obselete and bad programmed.
+ * This AI was created as a direct reaction to the big demand for some good AIs
+ * in OTTD. Too bad it never left alpha-stage, and it is considered dead in its
+ * current form.
+ * By the time of writing this, we, the creator of this AI and a good friend of
+ * mine, are designing a whole new AI-system that allows us to create AIs
+ * easier and without all the fuzz we encountered while I was working on this
+ * AI. By the time that system is finished, you can expect that this AI will
+ * dissapear, because it is pretty obselete and bad programmed.
*
- * In the meanwhile I wish you all much fun with this AI; if you are interested as
- * AI-developer in this AI, I advise you not stare too long to some code, some things in
- * here really are... strange ;) But in either way: enjoy :)
+ * Meanwhile I wish you all much fun with this AI; if you are interested as
+ * AI-developer in this AI, I advise you not stare too long to some code, some
+ * things in here really are... strange ;) But in either way: enjoy :)
*
* -- TrueLight :: 2005-09-01
*/
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 0e1f6f4b7..5b0c1b99f 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -690,16 +690,16 @@ static void HelicopterTickHandler(Vehicle *v)
if (spd == 0) {
img = SPR_ROTOR_STOPPED;
- if (u->cur_image == img)
- return;
+ if (u->cur_image == img) return;
} else if (tick >= spd) {
u->tick_counter = 0;
img = u->cur_image + 1;
if (img > SPR_ROTOR_MOVING_3) img = SPR_ROTOR_MOVING_1;
- } else
+ } else {
return;
+ }
- u->cur_image=img;
+ u->cur_image = img;
BeginVehicleMove(u);
VehiclePositionChanged(u);
@@ -767,7 +767,7 @@ static void ServiceAircraft(Vehicle *v)
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
}
-static void PlayAircraftSound(Vehicle *v)
+static void PlayAircraftSound(const Vehicle* v)
{
SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
}
@@ -1229,7 +1229,7 @@ static void MaybeCrashAirplane(Vehicle *v)
{
Station *st;
uint16 prob;
- int i;
+ uint i;
st = GetStation(v->u.air.targetairport);
@@ -1242,7 +1242,7 @@ static void MaybeCrashAirplane(Vehicle *v)
if (GB(Random(), 0, 16) > prob) return;
// Crash the airplane. Remove all goods stored at the station.
- for(i=0; i!=NUM_CARGO; i++) {
+ for (i = 0; i != NUM_CARGO; i++) {
st->goods[i].rating = 1;
SB(st->goods[i].waiting_acceptance, 0, 12, 0);
}
@@ -1425,16 +1425,18 @@ static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Air
return;
// if the block of the next position is busy, stay put
- if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
+ if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) return;
// We are already at the target airport, we need to find a terminal
if (v->current_order.station == v->u.air.targetairport) {
// FindFreeTerminal:
// 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal
- if (v->subtype != 0) {if(!AirportFindFreeTerminal(v, Airport)) {return;}} // airplane
- else {if(!AirportFindFreeHelipad(v, Airport)) {return;}} // helicopter
- }
- else { // Else prepare for launch.
+ if (v->subtype != 0) {
+ if (!AirportFindFreeTerminal(v, Airport)) return; // airplane
+ } else {
+ if (!AirportFindFreeHelipad(v, Airport)) return; // helicopter
+ }
+ } else { // Else prepare for launch.
// airplane goto state takeoff, helicopter to helitakeoff
v->u.air.state = (v->subtype != 0) ? TAKEOFF : HELITAKEOFF;
}
@@ -1606,14 +1608,14 @@ static void AircraftEventHandler_HeliLanding(Vehicle *v, const AirportFTAClass *
static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport)
{
// next block busy, don't do a thing, just wait
- if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
+ if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) return;
// if going to terminal (OT_GOTO_STATION) choose one
// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
// 2. not going for terminal (but depot, no order),
// --> get out of the way to the hangar.
if (v->current_order.type == OT_GOTO_STATION) {
- if (AirportFindFreeTerminal(v, Airport)) {return;}
+ if (AirportFindFreeTerminal(v, Airport)) return;
}
v->u.air.state = HANGAR;
@@ -1622,7 +1624,7 @@ static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *A
static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport)
{
// next block busy, don't do a thing, just wait
- if(AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) {return;}
+ if (AirportHasBlock(v, &Airport->layout[v->u.air.pos], Airport)) return;
// if going to helipad (OT_GOTO_STATION) choose one. If airport doesn't have helipads, choose terminal
// 1. in case all terminals/helipads are busy (AirportFindFreeHelipad() returns false) or
@@ -1632,7 +1634,7 @@ static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClas
// the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
// must go to a hangar.
if (v->current_order.type == OT_GOTO_STATION) {
- if (AirportFindFreeHelipad(v, Airport)) {return;}
+ if (AirportFindFreeHelipad(v, Airport)) return;
}
v->u.air.state = (Airport->terminals != NULL) ? HANGAR : HELITAKEOFF;
}
@@ -1673,7 +1675,7 @@ static void AirportClearBlock(Vehicle *v, const AirportFTAClass *Airport)
static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport)
{
// if aircraft is not in position, wait until it is
- if (!AircraftController(v)) {return;}
+ if (!AircraftController(v)) return;
AirportClearBlock(v, Airport);
AirportMove(v, Airport); // move aircraft to next position
@@ -1697,7 +1699,7 @@ static bool AirportMove(Vehicle *v, const AirportFTAClass *Airport)
if (current->heading == v->u.air.state) {
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
_aircraft_state_handlers[v->u.air.state](v, Airport);
- if (v->u.air.state != FLYING) {v->u.air.previous_pos = prev_pos;}
+ if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
return true;
}
@@ -1772,7 +1774,7 @@ static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportF
//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;
- if (current == reference) { current = current->next_in_chain;}
+ if (current == reference) current = current->next_in_chain;
while (current != NULL) {
if (current->heading == current_pos->heading && current->block != 0) {
airport_flags |= current->block;
@@ -1783,7 +1785,7 @@ static bool AirportSetBlocks(Vehicle *v, AirportFTA *current_pos, const AirportF
// if the block to be checked is in the next position, then exclude that from
// checking, because it has been set by the airplane before
- if (current_pos->block == next->block) {airport_flags ^= next->block;}
+ if (current_pos->block == next->block) airport_flags ^= next->block;
if (HASBITS(st->airport_flags, airport_flags)) {
v->cur_speed = 0;
@@ -1855,14 +1857,17 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
//at what terminal does the group start?
//that means, sum up all terminals of
//groups with lower number
- for(i = 1; i < target_group; i++)
+ for (i = 1; i < target_group; i++)
group_start += Airport->terminals[i];
group_end = group_start + Airport->terminals[target_group];
- if (FreeTerminal(v, group_start, group_end)) {return true;}
+ if (FreeTerminal(v, group_start, group_end)) return true;
}
+ } else {
+ /* once the heading isn't 255, we've exhausted the possible blocks.
+ * So we cannot move */
+ return false;
}
- else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move
temp = temp->next_in_chain;
}
}
@@ -1888,7 +1893,7 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
AirportFTA *temp;
// if an airport doesn't have helipads, use terminals
- if (Airport->helipads == NULL) {return AirportFindFreeTerminal(v, Airport);}
+ if (Airport->helipads == NULL) return AirportFindFreeTerminal(v, Airport);
// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
if (Airport->helipads[0] > 1) {
@@ -1913,16 +1918,20 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
group_start += Airport->helipads[i];
group_end = group_start + Airport->helipads[target_group];
- if (FreeTerminal(v, group_start, group_end)) {return true;}
+ if (FreeTerminal(v, group_start, group_end)) return true;
}
+ } else {
+ /* once the heading isn't 255, we've exhausted the possible blocks.
+ * So we cannot move */
+ return false;
}
- else {return false;} // once the heading isn't 255, we've exhausted the possible blocks. So we cannot move
temp = temp->next_in_chain;
}
+ } else {
+ // only 1 helicoptergroup, check all helipads
+ // The blocks for helipads start after the last terminal (MAX_TERMINALS)
+ return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);
}
- // only 1 helicoptergroup, check all helipads
- // The blocks for helipads start after the last terminal (MAX_TERMINALS)
- else {return FreeTerminal(v, MAX_TERMINALS, GetNumHelipads(Airport) + MAX_TERMINALS);}
return false; // it shouldn't get here anytime, but just to be sure
}
@@ -2000,7 +2009,7 @@ void UpdateOldAircraft(void)
FOR_ALL_STATIONS(st) {
st->airport_flags = 0; // reset airport
// type of oilrig has been moved, update it (3-5)
- if (st->airport_type == 3) {st->airport_type = AT_OILRIG;}
+ if (st->airport_type == 3) st->airport_type = AT_OILRIG;
}
FOR_ALL_VEHICLES(v_oldstyle) {
@@ -2021,7 +2030,7 @@ void UpdateOldAircraft(void)
v_oldstyle->tile = 0; // aircraft in air is tile=0
// correct speed of helicopter-rotors
- if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;}
+ if (v_oldstyle->subtype == 0) v_oldstyle->next->next->cur_speed = 32;
// set new position x,y,z
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle));
@@ -2051,8 +2060,7 @@ void UpdateAirplanesOnNewStation(Station *st)
GetNewVehiclePos(v, &gp);
// set new position x,y,z
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
- }
- else {
+ } else {
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF;
// search in airportdata for that heading
diff --git a/aircraft_gui.c b/aircraft_gui.c
index 522a6535b..4bea5c350 100644
--- a/aircraft_gui.c
+++ b/aircraft_gui.c
@@ -1063,10 +1063,11 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
DrawVehicleProfitButton(v, x, y + 13);
SetDParam(0, v->unitnumber);
- if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN))
+ if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) {
str = STR_021F;
- else
+ } else {
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
+ }
DrawString(x, y + 2, str, 0);
SetDParam(0, v->profit_this_year);
@@ -1100,7 +1101,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
- 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;
diff --git a/airport.c b/airport.c
index f375e67cb..afe5b1e3a 100644
--- a/airport.c
+++ b/airport.c
@@ -176,14 +176,15 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
// build the state machine
AirportBuildAutomata(Airport, FA);
- DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d", Airport->nofelements,
- nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point);
+ DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
+ Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point
+ );
{
- byte _retval = AirportTestFTA(Airport);
- if (_retval != MAX_ELEMENTS) {printf("ERROR with element: %d\n", _retval-1);}
- assert(_retval == MAX_ELEMENTS);
+ byte ret = AirportTestFTA(Airport);
+ if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
+ assert(ret == MAX_ELEMENTS);
}
// print out full information
// true -- full info including heading, block, etc
@@ -213,12 +214,13 @@ static uint16 AirportGetNofElements(const AirportFTAbuildup *FA)
int i;
uint16 nofelements = 0;
int temp = FA[0].position;
+
for (i = 0; i < MAX_ELEMENTS; i++) {
if (temp != FA[i].position) {
nofelements++;
temp = FA[i].position;
}
- if (FA[i].position == MAX_ELEMENTS) {break;}
+ if (FA[i].position == MAX_ELEMENTS) break;
}
return nofelements;
}
@@ -228,7 +230,7 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
AirportFTA *FAutomata;
AirportFTA *current;
uint16 internalcounter, i;
- FAutomata = (AirportFTA *)malloc(sizeof(AirportFTA) * Airport->nofelements);
+ FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements);
Airport->layout = FAutomata;
internalcounter = 0;
@@ -240,12 +242,13 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
current->next_position = FA[internalcounter].next_in_chain;
// outgoing nodes from the same position, create linked list
- while (current->position == FA[internalcounter+1].position) {
- AirportFTA *newNode = (AirportFTA *)malloc(sizeof(AirportFTA));
- newNode->position = FA[internalcounter+1].position;
- newNode->heading = FA[internalcounter+1].heading;
- newNode->block = FA[internalcounter+1].block;
- newNode->next_position = FA[internalcounter+1].next_in_chain;
+ while (current->position == FA[internalcounter + 1].position) {
+ AirportFTA* newNode = malloc(sizeof(AirportFTA));
+
+ newNode->position = FA[internalcounter + 1].position;
+ newNode->heading = FA[internalcounter + 1].heading;
+ newNode->block = FA[internalcounter + 1].block;
+ newNode->next_position = FA[internalcounter + 1].next_in_chain;
// create link
current->next_in_chain = newNode;
current = current->next_in_chain;
@@ -264,14 +267,14 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
for (i = 0; i < Airport->nofelements; i++) {
position = Airport->layout[i].position;
- if (position != next_element) {return i;}
+ if (position != next_element) return i;
temp = &Airport->layout[i];
do {
- if (temp->heading > MAX_HEADINGS && temp->heading != 255) {return i;}
- if (temp->heading == 0 && temp->next_in_chain != 0) {return i;}
- if (position != temp->position) {return i;}
- if (temp->next_position >= Airport->nofelements) {return i;}
+ if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
+ if (temp->heading == 0 && temp->next_in_chain != 0) return i;
+ if (position != temp->position) return i;
+ if (temp->next_position >= Airport->nofelements) return i;
temp = temp->next_in_chain;
} while (temp != NULL);
next_element++;
@@ -279,7 +282,8 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
return MAX_ELEMENTS;
}
-static const char* const _airport_heading_strings[MAX_HEADINGS+2] = {
+#if 0
+static const char* const _airport_heading_strings[] = {
"TO_ALL",
"HANGAR",
"TERM1",
@@ -302,7 +306,6 @@ static const char* const _airport_heading_strings[MAX_HEADINGS+2] = {
"DUMMY" // extra heading for 255
};
-/*
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
{
AirportFTA *temp;
@@ -316,16 +319,18 @@ static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_repo
heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block));
+ } else {
+ printf("P:%2d NP:%2d", temp->position, temp->next_position);
}
- else { printf("P:%2d NP:%2d", temp->position, temp->next_position);}
while (temp->next_in_chain != NULL) {
temp = temp->next_in_chain;
if (full_report) {
heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block));
+ } else {
+ printf("P:%2d NP:%2d", temp->position, temp->next_position);
}
- else { printf("P:%2d NP:%2d", temp->position, temp->next_position);}
}
printf("\n");
}
@@ -341,7 +346,8 @@ static byte AirportBlockToString(uint32 block)
if (block & 0x0000000c) { block >>= 2; i += 2; }
if (block & 0x00000002) { i += 1; }
return i;
-}*/
+}
+#endif
const AirportFTAClass* GetAirport(const byte airport_type)
{
diff --git a/dock_gui.c b/dock_gui.c
index 98fcfe865..02942d203 100644
--- a/dock_gui.c
+++ b/dock_gui.c
@@ -124,8 +124,8 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
if (e->click.widget - 3 >= 0 && e->click.widget != 5) _build_docks_button_proc[e->click.widget - 3](w);
break;
- case WE_KEYPRESS: {
- switch(e->keypress.keycode) {
+ case WE_KEYPRESS:
+ switch (e->keypress.keycode) {
case '1': BuildDocksClick_Canal(w); break;
case '2': BuildDocksClick_Lock(w); break;
case '3': BuildDocksClick_Demolish(w); break;
@@ -133,10 +133,9 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
case '5': BuildDocksClick_Dock(w); break;
case '6': BuildDocksClick_Buoy(w); break;
case 'l': BuildDocksClick_Landscaping(w); break;
- default:
- return;
+ default: return;
}
- } break;
+ break;
case WE_PLACE_OBJ:
_place_proc(e->place.tile);
@@ -151,8 +150,9 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
if (e->click.pt.x != -1) {
if ((e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions
GUIPlaceProcDragXY(e);
- } else if(e->place.userdata == VPM_X_OR_Y)
+ } else if (e->place.userdata == VPM_X_OR_Y) {
DoCommandP(e->place.tile, e->place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS));
+ }
}
break;
@@ -161,10 +161,10 @@ static void BuildDocksToolbWndProc(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: {
@@ -298,7 +298,7 @@ static void UpdateDocksDirection(void)
static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
{
- switch(e->event) {
+ switch (e->event) {
case WE_PAINT:
w->click_state = (1<<3) << _ship_depot_direction;
DrawWindowWidgets(w);
@@ -310,7 +310,7 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
return;
case WE_CLICK: {
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 3:
case 4:
_ship_depot_direction = e->click.widget - 3;
diff --git a/engine_gui.c b/engine_gui.c
index 54d0395f7..eb4c35d41 100644
--- a/engine_gui.c
+++ b/engine_gui.c
@@ -122,7 +122,6 @@ void ShowEnginePreviewWindow(EngineID engine)
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
{
const RailVehicleInfo *rvi = RailVehInfo(engine);
- int cap;
uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0;
SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5);
@@ -132,11 +131,11 @@ static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8 << multihead);
- cap = rvi->capacity;
- SetDParam(5, STR_8838_N_A);
- if (cap != 0) {
- SetDParam(6, cap << multihead);
+ if (rvi->capacity != 0) {
SetDParam(5, _cargoc.names_long[rvi->cargo_type]);
+ SetDParam(6, rvi->capacity << multihead);
+ } else {
+ SetDParam(5, STR_8838_N_A);
}
DrawStringMultiCenter(x, y, STR_885B_COST_WEIGHT_T_SPEED_POWER, maxw);
}
diff --git a/gui.h b/gui.h
index 4867cacf8..d1f776c48 100644
--- a/gui.h
+++ b/gui.h
@@ -42,7 +42,7 @@ void PlaceProc_BuyLand(TileIndex tile);
void ShowPlayerTrains(PlayerID player, StationID station);
void ShowTrainViewWindow(Vehicle *v);
void ShowTrainDetailsWindow(Vehicle *v);
-void ShowOrdersWindow(Vehicle *v);
+void ShowOrdersWindow(const Vehicle* v);
void ShowRoadVehViewWindow(Vehicle *v);
@@ -95,7 +95,7 @@ void ShowEstimatedCostOrIncome(int32 cost, int x, int y);
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y);
void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad);
-void CheckRedrawStationCoverage(Window *w);
+void CheckRedrawStationCoverage(const Window* w);
void ShowSmallMap(void);
void ShowExtraViewPortWindow(void);
diff --git a/industry_cmd.c b/industry_cmd.c
index f08b68515..66ab18eb1 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1011,14 +1011,11 @@ static void PlantFarmField(TileIndex tile)
static void MaybePlantFarmField(const Industry* i)
{
- TileIndex tile;
-
- if (CHANCE16(1,8)) {
- int x = (i->width>>1) + Random() % 31 - 16;
- int y = (i->height>>1) + Random() % 31 - 16;
- tile = TileAddWrap(i->xy, x, y);
- if (tile != INVALID_TILE)
- PlantFarmField(tile);
+ if (CHANCE16(1, 8)) {
+ int x = i->width / 2 + Random() % 31 - 16;
+ int y = i->height / 2 + Random() % 31 - 16;
+ TileIndex tile = TileAddWrap(i->xy, x, y);
+ if (tile != INVALID_TILE) PlantFarmField(tile);
}
}
@@ -1237,10 +1234,7 @@ static bool CheckNewIndustry_Lumbermill(TileIndex tile, int type)
static bool CheckNewIndustry_BubbleGen(TileIndex tile, int type)
{
- if (GetTileZ(tile) > 32) {
- return false;
- }
- return true;
+ return GetTileZ(tile) <= 32;
}
typedef bool CheckNewIndustryProc(TileIndex tile, int type);
@@ -1454,10 +1448,7 @@ static Industry *AllocateIndustry(void)
}
/* Check if we can add a block to the pool */
- if (AddBlockToPool(&_industry_pool))
- return AllocateIndustry();
-
- return NULL;
+ return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
}
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, Town *t, byte owner)
diff --git a/main_gui.c b/main_gui.c
index 6bb72b1c4..c562465f2 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -152,7 +152,7 @@ typedef void ToolbarButtonProc(Window *w);
static void ToolbarPauseClick(Window *w)
{
- if (_networking && !_network_server) { return;} // only server can pause the game
+ 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);
@@ -913,8 +913,10 @@ bool DoZoomInOutWindow(int how, Window *w)
// update the toolbar button too
CLRBIT(wt->disabled_state, button);
CLRBIT(wt->disabled_state, button + 1);
- if (vp->zoom == 0) SETBIT(wt->disabled_state, button);
- else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1);
+ switch (vp->zoom) {
+ case 0: SETBIT(wt->disabled_state, button); break;
+ case 2: SETBIT(wt->disabled_state, button + 1); break;
+ }
SetWindowDirty(wt);
}
diff --git a/misc_gui.c b/misc_gui.c
index e3053a23c..6f95c5c3e 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -719,10 +719,10 @@ void DrawStationCoverageAreaText(int sx, int sy, uint mask, int rad) {
}
}
-void CheckRedrawStationCoverage(Window *w)
+void CheckRedrawStationCoverage(const Window* w)
{
- if (_thd.dirty&1) {
- _thd.dirty&=~1;
+ if (_thd.dirty & 1) {
+ _thd.dirty &= ~1;
SetWindowDirty(w);
}
}
@@ -734,15 +734,15 @@ void UnclickSomeWindowButtons(Window *w, uint32 mask)
int i = 0;
w->click_state ^= x;
do {
- if (x&1) InvalidateWidget(w,i);
- } while(i++,x>>=1);
+ if (x & 1) InvalidateWidget(w, i);
+ } while (i++, x >>= 1);
}
void UnclickWindowButtons(Window *w)
{
bool sticky = false;
- if (w->desc_flags & WDF_STICKY_BUTTON && HASBIT(w->click_state, 2)) sticky = true;
+ if (w->desc_flags & WDF_STICKY_BUTTON && HASBIT(w->click_state, 2)) sticky = true;
UnclickSomeWindowButtons(w, (uint32)-1);
@@ -1164,10 +1164,17 @@ void BuildFileList(void)
{
_fios_path_changed = true;
FiosFreeSavegameList();
- if (_saveload_mode == SLD_NEW_GAME || _saveload_mode == SLD_LOAD_SCENARIO || _saveload_mode == SLD_SAVE_SCENARIO) {
- _fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode);
- } else
- _fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
+ switch (_saveload_mode) {
+ case SLD_NEW_GAME:
+ case SLD_LOAD_SCENARIO:
+ case SLD_SAVE_SCENARIO:
+ _fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode);
+ break;
+
+ default:
+ _fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
+ break;
+ }
}
static void DrawFiosTexts(uint maxw)
@@ -1258,9 +1265,8 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
item = _fios_list + pos;
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18);
pos++;
- y+=10;
- if (y >= w->vscroll.cap*10+w->widget[6].top+1)
- break;
+ y += 10;
+ if (y >= w->vscroll.cap * 10 + w->widget[6].top + 1) break;
}
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
@@ -1506,11 +1512,10 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
pos = w->vscroll.pos;
while (pos < _fios_num) {
item = _fios_list + pos;
- DoDrawString(item->title, 4, y, _fios_colors[item->type] );
+ DoDrawString(item->title, 4, y, _fios_colors[item->type]);
pos++;
- y+=10;
- if (y >= w->vscroll.cap*10+list_start)
- break;
+ y += 10;
+ if (y >= w->vscroll.cap * 10 + list_start) break;
}
}
break;
@@ -1544,7 +1549,8 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
file = _fios_list + y;
- if ((name = FiosBrowseTo(file)) != NULL) {
+ name = FiosBrowseTo(file);
+ if (name != NULL) {
SetFiosType(file->type);
strcpy(_file_to_saveload.name, name);
DeleteWindow(w);
@@ -1571,14 +1577,19 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
void SetFiosType(const byte fiostype)
{
switch (fiostype) {
- case FIOS_TYPE_FILE: case FIOS_TYPE_SCENARIO:
- _file_to_saveload.mode = SL_LOAD;
- break;
- case FIOS_TYPE_OLDFILE: case FIOS_TYPE_OLD_SCENARIO:
- _file_to_saveload.mode = SL_OLD_LOAD;
- break;
- default:
- _file_to_saveload.mode = SL_INVALID;
+ case FIOS_TYPE_FILE:
+ case FIOS_TYPE_SCENARIO:
+ _file_to_saveload.mode = SL_LOAD;
+ break;
+
+ case FIOS_TYPE_OLDFILE:
+ case FIOS_TYPE_OLD_SCENARIO:
+ _file_to_saveload.mode = SL_OLD_LOAD;
+ break;
+
+ default:
+ _file_to_saveload.mode = SL_INVALID;
+ break;
}
}
@@ -1878,6 +1889,5 @@ void ShowCheatWindow(void)
DeleteWindowById(WC_CHEATS, 0);
w = AllocateWindowDesc(&_cheats_desc);
- if (w)
- SetWindowDirty(w);
+ if (w != NULL) SetWindowDirty(w);
}
diff --git a/namegen.c b/namegen.c
index 8aa009f10..f058a3e8f 100644
--- a/namegen.c
+++ b/namegen.c
@@ -642,7 +642,7 @@ uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type)
/* NUM_SILLY_1 - lower 16 bits
* NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes)
* 1000 0000 2222 2222 0000 0000 1111 1111 */
- return FIXNUM(townnameparts, lengthof(name_silly_1), 0) | FIXNUM(((townnameparts >> 16)&0xFF), lengthof(name_silly_2), 16);
+ return FIXNUM(townnameparts, lengthof(name_silly_1), 0) | FIXNUM(GB(townnameparts, 16, 8), lengthof(name_silly_2), 16);
}
return 0;
}
diff --git a/network_gui.c b/network_gui.c
index b8e5606a8..5f09d9934 100644
--- a/network_gui.c
+++ b/network_gui.c
@@ -151,7 +151,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
cur_item = cur_item->next;
y += NET_PRC__SIZE_OF_ROW;
- if (++n == w->vscroll.cap) { break;} // max number of games in the window
+ if (++n == w->vscroll.cap) break; // max number of games in the window
}
}
@@ -242,7 +242,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
case 9: { /* Matrix to show networkgames */
uint32 id_v = (e->click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW;
- 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;
{
diff --git a/newgrf.c b/newgrf.c
index 482cc5e57..b745522ed 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -258,15 +258,9 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
uint32 base = grf_load_dword(&buf);
switch (base) {
- case 0x4C30:
- rvi[i].engclass = 0;
- break;
- case 0x4C36:
- rvi[i].engclass = 1;
- break;
- case 0x4C3C:
- rvi[i].engclass = 2;
- break;
+ case 0x4C30: rvi[i].engclass = 0; break;
+ case 0x4C36: rvi[i].engclass = 1; break;
+ case 0x4C3C: rvi[i].engclass = 2; break;
}
dewagonize(base, engine + i);
}
diff --git a/news_gui.c b/news_gui.c
index bd26e7310..aae18aed4 100644
--- a/news_gui.c
+++ b/news_gui.c
@@ -351,8 +351,8 @@ static const SoundFx _news_sounds[] = {
*/
static inline byte GetNewsDisplayValue(byte item)
{
- assert(item < 10 && ((_news_display_opt >> (item * 2)) & 0x3) <= 2);
- return (_news_display_opt >> (item * 2)) & 0x3;
+ assert(item < 10 && GB(_news_display_opt, item * 2, 2) <= 2);
+ return GB(_news_display_opt, item * 2, 2);
}
/** Set the value of an item in the news-display settings. This is
@@ -363,10 +363,7 @@ static inline byte GetNewsDisplayValue(byte item)
static inline void SetNewsDisplayValue(byte item, byte val)
{
assert(item < 10 && val <= 2);
- item *= 2;
- CLRBIT(_news_display_opt, item);
- CLRBIT(_news_display_opt, item + 1);
- _news_display_opt |= val << item;
+ SB(_news_display_opt, item * 2, 2, val);
}
// open up an own newspaper window for the news item
@@ -530,15 +527,12 @@ static void ShowNewsMessage(byte i)
void ShowLastNewsMessage(void)
{
- if (_forced_news == INVALID_NEWS)
+ if (_forced_news == INVALID_NEWS) {
ShowNewsMessage(_current_news);
- else if (_forced_news != 0)
+ } else if (_forced_news != 0) {
ShowNewsMessage(_forced_news - 1);
- else {
- if (_total_news != MAX_NEWS)
- ShowNewsMessage(_latest_news);
- else
- ShowNewsMessage(MAX_NEWS - 1);
+ } else {
+ ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1);
}
}
@@ -619,7 +613,6 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
DrawNewsString(82, y, 12, ni, w->width - 95);
y += 12;
}
-
break;
}
@@ -630,8 +623,7 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
byte p, q;
#if 0 // === DEBUG code only
- for (p = 0; p < _total_news; p++)
- {
+ for (p = 0; p < _total_news; p++) {
NewsItem *ni;
byte buffer[256];
ni = &_news_items[p];
diff --git a/order_cmd.c b/order_cmd.c
index 882f119b1..227152cde 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -851,25 +851,23 @@ int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/
bool CheckOrders(uint data_a, uint data_b)
{
- Vehicle *v = GetVehicle(data_a);
+ const Vehicle* v = GetVehicle(data_a);
+
/* Does the user wants us to check things? */
- if (_patches.order_review_system == 0)
- return false;
+ if (_patches.order_review_system == 0) return false;
/* Do nothing for crashed vehicles */
- if(v->vehstatus & VS_CRASHED)
- return false;
+ if (v->vehstatus & VS_CRASHED) return false;
/* Do nothing for stopped vehicles if setting is '1' */
- if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) )
+ if (_patches.order_review_system == 1 && v->vehstatus & VS_STOPPED)
return false;
/* do nothing we we're not the first vehicle in a share-chain */
- if (v->next_shared != NULL)
- return false;
+ if (v->next_shared != NULL) return false;
/* Only check every 20 days, so that we don't flood the message log */
- if ( (v->owner == _local_player) && (v->day_counter % 20 == 0) ) {
+ if (v->owner == _local_player && v->day_counter % 20 == 0) {
int n_st, problem_type = -1;
const Order *order;
const Station *st;
@@ -930,7 +928,7 @@ bool CheckOrders(uint data_a, uint data_b)
return true;
}
- message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type;
+ message = STR_TRAIN_HAS_TOO_FEW_ORDERS + ((v->type - VEH_Train) << 2) + problem_type;
/*DEBUG(misc, 3) ("Checkorder mode 0: Triggered News Item for %d", v->index);*/
SetDParam(0, v->unitnumber);
diff --git a/order_gui.c b/order_gui.c
index 17936adc4..04c0688ed 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -23,10 +23,7 @@ static int OrderGetSel(const Window* w)
const Vehicle* v = GetVehicle(w->window_number);
int num = WP(w,order_d).sel;
- if (num < 0 || num > v->num_orders)
- return v->num_orders;
-
- return num;
+ return (num >= 0 && num < v->num_orders) ? num : v->num_orders;
}
static StringID StationOrderStrings[] = {
@@ -91,6 +88,7 @@ static void DrawOrdersWindow(Window *w)
switch (order->type) {
case OT_GOTO_STATION:
break;
+
case OT_GOTO_DEPOT:
SETBIT(w->disabled_state, 9); /* unload */
SETBIT(w->disabled_state, 10); /* transfer */
@@ -188,7 +186,6 @@ static void DrawOrdersWindow(Window *w)
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
{
Order order;
- Station *st;
int st_index;
// check depot first
@@ -255,7 +252,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
}
if (IsTileType(tile, MP_STATION)) {
- st = GetStation(st_index = _m[tile].m2);
+ const Station* st = GetStation(st_index = _m[tile].m2);
if (st->owner == _current_player || st->owner == OWNER_NONE) {
byte facil;
@@ -279,20 +276,18 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
return order;
}
-static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
+static bool HandleOrderVehClick(const Vehicle* v, const Vehicle* u, Window* w)
{
- if (u->type != v->type)
- return false;
+ if (u->type != v->type) return false;
if (u->type == VEH_Train && u->subtype != TS_Front_Engine) {
u = GetFirstVehicleInChain(u);
- if (u->subtype != TS_Front_Engine)
- return false;
+ if (u->subtype != TS_Front_Engine) return false;
}
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
- if (v->num_orders != 0 && _ctrl_pressed == 0) {return false;}
+ if (v->num_orders != 0 && _ctrl_pressed == 0) return false;
if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? 0 : 1, NULL,
_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
@@ -303,27 +298,25 @@ static bool HandleOrderVehClick(Vehicle *v, Vehicle *u, Window *w)
return true;
}
-static void OrdersPlaceObj(Vehicle *v, TileIndex tile, Window *w)
+static void OrdersPlaceObj(const Vehicle* v, TileIndex tile, Window* w)
{
Order cmd;
- Vehicle *u;
+ const Vehicle* u;
// check if we're clicking on a vehicle first.. clone orders in that case.
u = CheckMouseOverVehicle();
- if (u && HandleOrderVehClick(v, u, w))
- return;
+ if (u != NULL && HandleOrderVehClick(v, u, w)) return;
cmd = GetOrderCmdFromTile(v, tile);
if (cmd.type == OT_NOTHING) return;
if (DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), PackOrder(&cmd), NULL, CMD_INSERT_ORDER | CMD_MSG(STR_8833_CAN_T_INSERT_NEW_ORDER))) {
- if (WP(w,order_d).sel != -1)
- WP(w,order_d).sel++;
+ if (WP(w,order_d).sel != -1) WP(w,order_d).sel++;
ResetObjectToPlace();
}
}
-static void OrderClick_Goto(Window *w, Vehicle *v)
+static void OrderClick_Goto(Window* w, const Vehicle* v)
{
InvalidateWidget(w, 7);
TOGGLEBIT(w->click_state, 7);
@@ -335,39 +328,39 @@ static void OrderClick_Goto(Window *w, Vehicle *v)
}
}
-static void OrderClick_FullLoad(Window *w, Vehicle *v)
+static void OrderClick_FullLoad(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_FULL_LOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
}
-static void OrderClick_Unload(Window *w, Vehicle *v)
+static void OrderClick_Unload(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_UNLOAD, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
}
-static void OrderClick_Nonstop(Window *w, Vehicle *v)
+static void OrderClick_Nonstop(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_NON_STOP, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
}
-static void OrderClick_Transfer(Window *w, Vehicle *v)
+static void OrderClick_Transfer(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index + (OrderGetSel(w) << 16), OFB_TRANSFER, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
}
-static void OrderClick_Skip(Window *w, Vehicle *v)
+static void OrderClick_Skip(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index, 0, NULL, CMD_SKIP_ORDER);
}
-static void OrderClick_Delete(Window *w, Vehicle *v)
+static void OrderClick_Delete(Window* w, const Vehicle* v)
{
DoCommandP(v->tile, v->index, OrderGetSel(w), NULL, CMD_DELETE_ORDER | CMD_MSG(STR_8834_CAN_T_DELETE_THIS_ORDER));
}
-typedef void OnButtonClick(Window *w, Vehicle *v);
+typedef void OnButtonClick(Window* w, const Vehicle* v);
-static OnButtonClick * const _order_button_proc[] = {
+static OnButtonClick* const _order_button_proc[] = {
OrderClick_Skip,
OrderClick_Delete,
OrderClick_Nonstop,
@@ -388,7 +381,7 @@ static const uint16 _order_keycodes[] = {
static void OrdersWndProc(Window *w, WindowEvent *e)
{
- switch(e->event) {
+ switch (e->event) {
case WE_PAINT:
DrawOrdersWindow(w);
break;
@@ -502,7 +495,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
// check if a vehicle in a depot was clicked..
case WE_MOUSELOOP: {
- Vehicle *v = _place_clicked_vehicle;
+ const Vehicle* v = _place_clicked_vehicle;
/*
* Check if we clicked on a vehicle
* and if the GOTO button of this window is pressed
@@ -599,7 +592,7 @@ static const WindowDesc _other_orders_desc = {
OrdersWndProc
};
-void ShowOrdersWindow(Vehicle *v)
+void ShowOrdersWindow(const Vehicle* v)
{
Window *w;
VehicleID veh = v->index;
@@ -610,9 +603,10 @@ void ShowOrdersWindow(Vehicle *v)
_alloc_wnd_parent_num = veh;
if (v->owner != _local_player) {
- w = AllocateWindowDesc( &_other_orders_desc);
- } else
- w = AllocateWindowDesc( (v->type == VEH_Train) ? &_orders_train_desc : &_orders_desc);
+ w = AllocateWindowDesc(&_other_orders_desc);
+ } else {
+ w = AllocateWindowDesc((v->type == VEH_Train) ? &_orders_train_desc : &_orders_desc);
+ }
if (w != NULL) {
w->window_number = veh;
diff --git a/player_gui.c b/player_gui.c
index 39f7642d0..1790f0ee7 100644
--- a/player_gui.c
+++ b/player_gui.c
@@ -228,8 +228,8 @@ static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_sti
int mode;
mode = (player != _local_player) * 2 + show_small;
- w = AllocateWindowDescFront( desc_table[mode], player);
- if (w) {
+ w = AllocateWindowDescFront(desc_table[mode], player);
+ if (w != NULL) {
w->caption_color = w->window_number;
WP(w,def_d).data_1 = mode;
if (show_stickied) {
@@ -484,28 +484,26 @@ static void DrawCompanyOwnerText(const Player *p)
{
const Player* p2;
int num = -1;
- int amt;
FOR_ALL_PLAYERS(p2) {
- if ((amt=GetAmountOwnedBy(p, p2->index)) != 0) {
+ uint amt = GetAmountOwnedBy(p, p2->index);
+ if (amt != 0) {
num++;
- SetDParam(num*3+0, amt*25);
- SetDParam(num*3+1, p2->name_1);
- SetDParam(num*3+2, p2->name_2);
+ SetDParam(num * 3 + 0, amt * 25);
+ SetDParam(num * 3 + 1, p2->name_1);
+ SetDParam(num * 3 + 2, p2->name_2);
- if (num != 0)
- break;
+ if (num != 0) break;
}
}
- if (num >= 0)
- DrawString(120, 124, STR_707D_OWNED_BY+num, 0);
+ if (num >= 0) DrawString(120, 124, STR_707D_OWNED_BY + num, 0);
}
static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
{
- switch(e->event) {
+ switch (e->event) {
case WE_PAINT: {
const Player* p = GetPlayer(w->window_number);
uint32 dis = 0;
@@ -562,10 +560,10 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
} break;
case WE_CLICK:
- switch(e->click.widget) {
+ switch (e->click.widget) {
case 3: { /* select face */
Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
- if (wf) {
+ if (wf != NULL) {
wf->caption_color = w->window_number;
WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
WP(wf,facesel_d).gender = 0;
@@ -574,15 +572,15 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
case 4: {/* change color */
Window *wf = AllocateWindowDescFront(&_select_player_color_desc,w->window_number);
- if (wf) {
+ if (wf != NULL) {
wf->caption_color = wf->window_number;
wf->vscroll.cap = 8;
}
} break;
case 5: {/* change president name */
- Player *p = GetPlayer(w->window_number);
- WP(w,def_d).byte_1 = 0;
+ const Player* p = GetPlayer(w->window_number);
+ WP(w, def_d).byte_1 = 0;
SetDParam(0, p->president_name_2);
ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number);
} break;
@@ -649,8 +647,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
case WE_ON_EDIT_TEXT: {
char *b = e->edittext.str;
- if (*b == 0 && WP(w,def_d).byte_1 != 2) // empty string is allowed for password
- return;
+ // empty string is allowed for password
+ if (*b == '\0' && WP(w,def_d).byte_1 != 2) return;
_cmd_text = b;
switch (WP(w,def_d).byte_1) {
@@ -662,7 +660,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
break;
#ifdef ENABLE_NETWORK
case 2: /* Change company password */
- if (*b == 0) *b = '*'; // empty password is a '*' because of console argument
+ if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
NetworkChangeCompanyPassword(1, &b);
#endif
}
@@ -673,8 +671,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
static const WindowDesc _my_player_company_desc = {
- -1,-1, 360, 170,
- WC_COMPANY,0,
+ -1, -1, 360, 170,
+ WC_COMPANY, 0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_my_player_company_widgets,
PlayerCompanyWndProc
diff --git a/rail_cmd.c b/rail_cmd.c
index 1e96b329a..2814b23b4 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -983,12 +983,10 @@ typedef int32 DoConvertRailProc(TileIndex tile, uint totype, bool exec);
static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
{
- if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile))
- return CMD_ERROR;
+ if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
// tile is already of requested type?
- if ( GetRailType(tile) == totype)
- return CMD_ERROR;
+ if (GetRailType(tile) == totype) return CMD_ERROR;
// change type.
if (exec) {
@@ -1031,20 +1029,26 @@ int32 CmdConvertRail(int ex, int ey, uint32 flags, uint32 p1, uint32 p2)
for (x = sx; x <= ex; x += TILE_SIZE) {
for (y = sy; y <= ey; y += TILE_SIZE) {
TileIndex tile = TileVirtXY(x, y);
- DoConvertRailProc *proc;
-
- if (IsTileType(tile, MP_RAILWAY)) proc = DoConvertRail;
- else if (IsTileType(tile, MP_STATION)) proc = DoConvertStationRail;
- else if (IsTileType(tile, MP_STREET)) proc = DoConvertStreetRail;
- else if (IsTileType(tile, MP_TUNNELBRIDGE)) proc = DoConvertTunnelBridgeRail;
- else continue;
+ DoConvertRailProc* proc;
+
+ switch (GetTileType(tile)) {
+ case MP_RAILWAY: proc = DoConvertRail; break;
+ case MP_STATION: proc = DoConvertStationRail; break;
+ case MP_STREET: proc = DoConvertStreetRail; break;
+ case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break;
+ default: continue;
+ }
ret = proc(tile, p2, false);
if (CmdFailed(ret)) continue;
cost += ret;
if (flags & DC_EXEC) {
- if ( (money -= ret) < 0) { _additional_cash_required = ret; return cost - ret; }
+ money -= ret;
+ if (money < 0) {
+ _additional_cash_required = ret;
+ return cost - ret;
+ }
proc(tile, p2, true);
}
}
@@ -1062,7 +1066,7 @@ static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
return CMD_ERROR;
if (flags & DC_EXEC) {
- int track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL)));
+ Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL)));
DoDeleteDepot(tile);
SetSignalsOnBothDir(tile, track);
@@ -1349,15 +1353,13 @@ DetailedTrackProc * const _detailed_track_proc[16] = {
};
static void DrawSpecialBuilding(uint32 image, uint32 offset,
- TileInfo *ti,
+ const TileInfo* ti,
byte x, byte y, byte z,
byte xsize, byte ysize, byte zsize)
{
- if (image & PALETTE_MODIFIER_COLOR)
- image |= _drawtile_track_palette;
+ if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
image += offset;
- if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots
- MAKE_TRANSPARENT(image);
+ if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z);
}
@@ -1511,7 +1513,7 @@ static void DrawTile_Track(TileInfo *ti)
* complains about it. If not, we'll remove this check. (Matthijs). */
assert(0);
- if (ti->tileh != 0) { DrawFoundation(ti, ti->tileh); }
+ if (ti->tileh != 0) DrawFoundation(ti, ti->tileh);
if (IsRailWaypoint(m5) && HASBIT(_m[ti->tile].m3, 4)) {
// look for customization
@@ -1558,10 +1560,11 @@ static void DrawTile_Track(TileInfo *ti)
// (don't adjust for arctic depots, because snow in depots looks weird)
// type >= 4 means waypoints
if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type >= 4)) {
- if (image != SPR_FLAT_GRASS_TILE)
+ if (image != SPR_FLAT_GRASS_TILE) {
image += rti->snow_offset; // tile with tracks
- else
+ } else {
image = SPR_FLAT_SNOWY_TILE; // flat ground
+ }
}
DrawGroundSprite(image);
@@ -1576,11 +1579,10 @@ static void DrawTile_Track(TileInfo *ti)
if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
}
- while ((image = drss->image) != 0) {
- DrawSpecialBuilding(image, type < 4 ? rti->total_offset : 0, ti,
+ for (; drss->image != 0; drss++) {
+ DrawSpecialBuilding(drss->image, type < 4 ? rti->total_offset : 0, ti,
drss->subcoord_x, drss->subcoord_y, 0,
drss->width, drss->height, 0x17);
- drss++;
}
}
}
@@ -1595,8 +1597,8 @@ void DrawTrainDepotSprite(int x, int y, int image, RailType railtype)
dtss = _track_depot_layout_table[image];
- x+=33;
- y+=17;
+ x += 33;
+ y += 17;
img = dtss++->image;
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates
@@ -1703,8 +1705,9 @@ static bool SetSignalsEnumProc(TileIndex tile, SetSignalsData *ssd, int track, u
}
return true;
- } else if (IsTileDepotType(tile, TRANSPORT_RAIL))
+ } else if (IsTileDepotType(tile, TRANSPORT_RAIL)) {
return true; // don't look further if the tile is a depot
+ }
}
return false;
}
@@ -1717,25 +1720,23 @@ typedef struct SignalVehicleCheckStruct {
static void *SignalVehicleCheckProc(Vehicle *v, void *data)
{
- SignalVehicleCheckStruct *dest = data;
+ const SignalVehicleCheckStruct* dest = data;
TileIndex tile;
- if (v->type != VEH_Train)
- return NULL;
+ if (v->type != VEH_Train) return NULL;
/* Find the tile outside the tunnel, for signalling */
- if (v->u.rail.track == 0x40)
+ if (v->u.rail.track == 0x40) {
tile = GetVehicleOutOfTunnelTile(v);
- else
+ } else {
tile = v->tile;
+ }
/* Wrong tile, or no train? Not a match */
- if (tile != dest->tile)
- return NULL;
+ if (tile != dest->tile) return NULL;
/* Are we on the same piece of track? */
- if (dest->track & (v->u.rail.track + (v->u.rail.track<<8)))
- return v;
+ if (dest->track & (v->u.rail.track + (v->u.rail.track << 8))) return v;
return NULL;
}
@@ -1752,7 +1753,7 @@ bool SignalVehicleCheck(TileIndex tile, uint track)
* is some kind of invisible black hole, and there is some special magic going
* on in there. This 'workaround' can be removed once the maprewrite is done.
*/
- if (GetTileType(tile) == MP_TUNNELBRIDGE && GB(_m[tile].m5, 4, 4) == 0) {
+ if (IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0) {
// It is a tunnel we're checking, we need to do some special stuff
// because VehicleFromPos will not find the vihicle otherwise
byte direction = GB(_m[tile].m5, 0, 2);
@@ -1838,14 +1839,14 @@ static void ChangeSignalStates(SetSignalsData *ssd)
// convert the block to pbs, if needed
if (_patches.auto_pbs_placement && !(ssd->stop) && (ssd->has_pbssignal == 0xE) && !ssd->has_presignal && (ssd->presignal_exits == 0)) // 0xE means at least 2 pbs signals, and at least 1 entry and 1 exit, see comments ssd->has_pbssignal
- for(i=0; i!=ssd->pbs_cur; i++) {
+ for (i = 0; i != ssd->pbs_cur; i++) {
TileIndex tile = ssd->pbs_tile[i];
SB(_m[tile].m4, 0, 3, SIGTYPE_PBS);
MarkTileDirtyByTile(tile);
};
// then mark the signals in the segment accordingly
- for(i=0; i!=ssd->cur; i++) {
+ for (i = 0; i != ssd->cur; i++) {
TileIndex tile = ssd->tile[i];
byte bit = _signals_table[ssd->bit[i]];
uint16 m2 = _m[tile].m2;
@@ -1900,7 +1901,7 @@ bool UpdateSignalsOnSegment(TileIndex tile, byte direction)
int result = -1;
ssd.cur_stack = 0;
- direction>>=1;
+ direction >>= 1;
for(;;) {
// go through one segment and update all signals pointing into that segment.
@@ -2107,8 +2108,8 @@ static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode)
* direction), we pretend them to be green. (So if
* signals are only one way, the other way will
* implicitely become `red' */
- if ((a & 0xC0) == 0) { b |= 0xC0; }
- if ((a & 0x30) == 0) { b |= 0x30; }
+ if ((a & 0xC0) == 0) b |= 0xC0;
+ if ((a & 0x30) == 0) b |= 0x30;
if ( (b & 0x80) == 0) ret |= 0x10070000;
if ( (b & 0x40) == 0) ret |= 0x7100000;
diff --git a/road_cmd.c b/road_cmd.c
index 5275d461b..663864705 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -460,7 +460,7 @@ do_clear:;
if (cost && (!_patches.build_on_slopes || _is_old_ai_player))
return CMD_ERROR;
- if (!(ti.type == MP_STREET && (ti.map5 & 0xF0) == 0)) {
+ if (ti.type != MP_STREET || (ti.map5 & 0xF0) != 0) {
cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
} else {
// Don't put the pieces that already exist
@@ -483,7 +483,7 @@ do_clear:;
SetTileOwner(tile, _current_player);
}
- _m[tile].m5 |= (byte)pieces;
+ _m[tile].m5 |= pieces;
MarkTileDirtyByTile(tile);
}
@@ -554,8 +554,9 @@ int32 CmdBuildLongRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
ret = DoCommandByTile(tile, bits, 0, flags, CMD_BUILD_ROAD);
if (CmdFailed(ret)) {
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
- } else
+ } else {
cost += ret;
+ }
if (tile == end_tile) break;
@@ -642,24 +643,21 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile = ti.tile;
- if (!EnsureNoVehicle(tile))
- return CMD_ERROR;
+ if (!EnsureNoVehicle(tile)) return CMD_ERROR;
- if ((ti.tileh != 0) && (
- !_patches.build_on_slopes ||
- IsSteepTileh(ti.tileh) ||
- !CanBuildDepotByTileh(p1, ti.tileh)
- )
- ) {
- return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
+ if (ti.tileh != 0 && (
+ !_patches.build_on_slopes ||
+ IsSteepTileh(ti.tileh) ||
+ !CanBuildDepotByTileh(p1, ti.tileh)
+ )) {
+ return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
}
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR;
dep = AllocateDepot();
- if (dep == NULL)
- return CMD_ERROR;
+ if (dep == NULL) return CMD_ERROR;
if (flags & DC_EXEC) {
if (IsLocalPlayer()) _last_built_road_depot_tile = tile;
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 9a5cc09f3..73887f6a2 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -300,7 +300,7 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
TileIndex tile = v->tile;
int i;
- if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); }
+ if (v->u.road.state == 255) tile = GetVehicleOutOfTunnelTile(v);
if (_patches.new_pathfinding_all) {
NPFFoundTargetData ftd;
@@ -1034,13 +1034,14 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
}
if (IsTileType(tile, MP_STREET)) {
- if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner))
- /* Road crossing */
- bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3];
+ if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner)) {
+ /* Road depot */
+ bitmask |= _road_veh_fp_ax_or[GB(_m[tile].m5, 0, 2)];
+ }
} else if (IsTileType(tile, MP_STATION)) {
if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
/* Our station */
- Station *st = GetStation(_m[tile].m2);
+ const Station* st = GetStation(_m[tile].m2);
byte val = _m[tile].m5;
if (v->cargo_type != CT_PASSENGERS) {
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3))
diff --git a/roadveh_gui.c b/roadveh_gui.c
index be6928989..32920f633 100644
--- a/roadveh_gui.c
+++ b/roadveh_gui.c
@@ -973,7 +973,7 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
- 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;
diff --git a/settings_gui.c b/settings_gui.c
index cc7a5b5f9..223517890 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -1219,7 +1219,7 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
case 3: { // select a grf file
int y = (e->click.pt.y - NEWGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE;
- if (y >= w->vscroll.cap) { return;} // click out of bounds
+ if (y >= w->vscroll.cap) return; // click out of bounds
y += w->vscroll.pos;
diff --git a/ship_gui.c b/ship_gui.c
index c2486fd9e..49006f9bf 100644
--- a/ship_gui.c
+++ b/ship_gui.c
@@ -1077,7 +1077,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
- 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;
diff --git a/station_cmd.c b/station_cmd.c
index b5acc6d0b..1a5e81bda 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -72,7 +72,7 @@ const byte _airport_size_y[] = {3, 6, 1, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
void ShowAircraftDepotWindow(TileIndex tile);
extern void UpdateAirplanesOnNewStation(Station *st);
-static void MarkStationDirty(Station *st)
+static void MarkStationDirty(const Station* st)
{
if (st->sign.width_1 != 0) {
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1);
@@ -121,16 +121,16 @@ RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type)
uint GetNumRoadStops(const Station *st, RoadStopType type)
{
- int num = 0;
+ uint num = 0;
const RoadStop *rs;
assert(st != NULL);
- for ( rs = GetPrimaryRoadStop(st, type); rs != NULL; num++, rs = rs->next);
+ for (rs = GetPrimaryRoadStop(st, type); rs != NULL; rs = rs->next) num++;
return num;
}
-RoadStop *AllocateRoadStop( void )
+RoadStop *AllocateRoadStop(void)
{
RoadStop *rs;
@@ -138,7 +138,7 @@ RoadStop *AllocateRoadStop( void )
if (!rs->used) {
uint index = rs->index;
- memset(rs, 0, sizeof(RoadStop));
+ memset(rs, 0, sizeof(*rs));
rs->index = index;
return rs;
@@ -211,15 +211,9 @@ TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
case VEH_Ship: return st->dock_tile;
case VEH_Road:
if (v->cargo_type == CT_PASSENGERS) {
- if (st->bus_stops != NULL)
- return st->bus_stops->xy;
- else
- return 0;
+ return (st->bus_stops != NULL) ? st->bus_stops->xy : 0;
} else {
- if (st->truck_stops != NULL)
- return st->truck_stops->xy;
- else
- return 0;
+ return (st->truck_stops != NULL) ? st->truck_stops->xy : 0;
}
default:
assert(false);
@@ -249,7 +243,7 @@ static bool CheckStationSpreadOut(Station *st, TileIndex tile, int w, int h)
}
}
- if (y2-y1 >= _patches.station_spread || x2-x1 >= _patches.station_spread) {
+ if (y2 - y1 >= _patches.station_spread || x2 - x1 >= _patches.station_spread) {
_error_message = STR_306C_STATION_TOO_SPREAD_OUT;
return false;
}
@@ -519,8 +513,8 @@ static uint GetAcceptanceMask(const Station *st)
static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg)
{
if (items) {
- SetDParam(2, items >> 16);
- SetDParam(1, items & 0xFFFF);
+ SetDParam(2, GB(items, 16, 16));
+ SetDParam(1, GB(items, 0, 16));
SetDParam(0, st->index);
AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0);
}
@@ -1645,8 +1639,8 @@ static const byte _airport_map5_tiles_country[] = {
// City Airport (large)
static const byte _airport_map5_tiles_town[] = {
- 31, 9, 33, 9, 9, 32,
- 27, 36, 29, 34, 8, 10,
+ 31, 9, 33, 9, 9, 32,
+ 27, 36, 29, 34, 8, 10,
30, 11, 35, 13, 20, 21,
51, 12, 14, 17, 19, 28,
38, 13, 15, 16, 18, 39,
@@ -1655,23 +1649,23 @@ static const byte _airport_map5_tiles_town[] = {
// Metropolitain Airport (large) - 2 runways
static const byte _airport_map5_tiles_metropolitan[] = {
- 31, 9, 33, 9, 9, 32,
- 27, 36, 29, 34, 8, 10,
- 30, 11, 35, 13, 20, 21,
- 102, 8, 8, 8, 8, 28,
- 83, 84, 84, 84, 84, 83,
- 26, 23, 23, 23, 23, 26
+ 31, 9, 33, 9, 9, 32,
+ 27, 36, 29, 34, 8, 10,
+ 30, 11, 35, 13, 20, 21,
+ 102, 8, 8, 8, 8, 28,
+ 83, 84, 84, 84, 84, 83,
+ 26, 23, 23, 23, 23, 26
};
// International Airport (large) - 2 runways
static const byte _airport_map5_tiles_international[] = {
- 88, 89, 89, 89, 89, 89, 88,
- 51, 8, 8, 8, 8, 8, 32,
- 30, 8, 11, 27, 11, 8, 10,
+ 88, 89, 89, 89, 89, 89, 88,
+ 51, 8, 8, 8, 8, 8, 32,
+ 30, 8, 11, 27, 11, 8, 10,
32, 8, 11, 27, 11, 8, 114,
87, 8, 11, 85, 11, 8, 114,
- 87, 8, 8, 8, 8, 8, 90,
- 26, 23, 23, 23, 23, 23, 26
+ 87, 8, 8, 8, 8, 8, 90,
+ 26, 23, 23, 23, 23, 23, 26
};
// Heliport
@@ -1795,16 +1789,17 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
1. airport is upgraded
2. airport is added to existing station (unfortunately unavoideable)
*/
- if (airport_upgrade) {UpdateAirplanesOnNewStation(st);}
+ if (airport_upgrade) UpdateAirplanesOnNewStation(st);
{
const byte *b = _airport_map5_tiles[p1];
-BEGIN_TILE_LOOP(tile_cur,w,h,tile)
+
+ BEGIN_TILE_LOOP(tile_cur,w,h,tile) {
ModifyTile(tile_cur,
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
st->index, *b++);
-END_TILE_LOOP(tile_cur,w,h,tile)
+ } END_TILE_LOOP(tile_cur,w,h,tile)
}
UpdateStationVirtCoordDirty(st);
@@ -2227,10 +2222,7 @@ void StationPickerDrawSprite(int x, int y, RailType railtype, int image)
static uint GetSlopeZ_Station(const TileInfo* ti)
{
- uint z = ti->z;
- if (ti->tileh != 0)
- z += 8;
- return z;
+ return (ti->tileh != 0) ? ti->z + 8 : ti->z;
}
static uint GetSlopeTileh_Station(const TileInfo *ti)
@@ -2682,14 +2674,15 @@ void StationMonthlyLoop(void)
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
{
Station *st;
- GoodsEntry *ge;
- int i;
FOR_ALL_STATIONS(st) {
if (st->xy != 0 && st->owner == owner &&
DistanceManhattan(tile, st->xy) <= radius) {
- ge = st->goods;
- for(i=0; i!=NUM_CARGO; i++,ge++) {
+ uint i;
+
+ for (i = 0; i != NUM_CARGO; i++) {
+ GoodsEntry* ge = &st->goods[i];
+
if (ge->enroute_from != INVALID_STATION) {
ge->rating = clamp(ge->rating + amount, 0, 255);
}
@@ -3191,7 +3184,7 @@ static void Load_STNS(void)
_station_tick_ctr = 0;
}
-static void Save_ROADSTOP( void )
+static void Save_ROADSTOP(void)
{
RoadStop *rs;
@@ -3203,7 +3196,7 @@ static void Save_ROADSTOP( void )
}
}
-static void Load_ROADSTOP( void )
+static void Load_ROADSTOP(void)
{
int index;
diff --git a/station_gui.c b/station_gui.c
index 91b706411..568416bbe 100644
--- a/station_gui.c
+++ b/station_gui.c
@@ -264,7 +264,7 @@ void ShowPlayerStations(PlayerID player)
Window *w;
w = AllocateWindowDescFront(&_player_stations_desc, player);
- if (w) {
+ if (w != NULL) {
w->caption_color = (byte)w->window_number;
w->vscroll.cap = 12;
w->resize.step_height = 10;
@@ -500,13 +500,13 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
}
break;
- case WE_ON_EDIT_TEXT: {
+ case WE_ON_EDIT_TEXT:
if (e->edittext.str[0] != '\0') {
_cmd_text = e->edittext.str;
DoCommandP(0, w->window_number, 0, NULL,
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
}
- } break;
+ break;
case WE_DESTROY: {
WindowNumber wno =
@@ -535,7 +535,7 @@ void ShowStationViewWindow(StationID station)
Window *w;
w = AllocateWindowDescFront(&_station_view_desc, station);
- if (w) {
+ if (w != NULL) {
PlayerID owner = GetStation(w->window_number)->owner;
if (owner != OWNER_NONE) w->caption_color = owner;
w->vscroll.cap = 5;
diff --git a/texteff.c b/texteff.c
index 2492fb5bf..67284886b 100644
--- a/texteff.c
+++ b/texteff.c
@@ -261,7 +261,7 @@ static void MoveTextEffect(TextEffect *te)
if (te->duration < 8) {
te->string_id = INVALID_STRING_ID;
} else {
- te->duration-=8;
+ te->duration -= 8;
te->y--;
te->bottom--;
}
@@ -272,9 +272,8 @@ void MoveAllTextEffects(void)
{
TextEffect *te;
- for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) {
- if (te->string_id != INVALID_STRING_ID)
- MoveTextEffect(te);
+ for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
+ if (te->string_id != INVALID_STRING_ID) MoveTextEffect(te);
}
}
@@ -282,7 +281,7 @@ void InitTextEffects(void)
{
TextEffect *te;
- for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) {
+ for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
te->string_id = INVALID_STRING_ID;
}
}
@@ -292,7 +291,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
TextEffect *te;
if (dpi->zoom < 1) {
- for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) {
+ for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
if (te->string_id == INVALID_STRING_ID)
continue;
@@ -305,7 +304,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2, 0);
}
} else if (dpi->zoom == 1) {
- for (te = _text_effect_list; te != endof(_text_effect_list); te++ ) {
+ for (te = _text_effect_list; te != endof(_text_effect_list); te++) {
if (te->string_id == INVALID_STRING_ID)
continue;
@@ -323,12 +322,12 @@ void DrawTextEffects(DrawPixelInfo *dpi)
void DeleteAnimatedTile(TileIndex tile)
{
- TileIndex *ti;
+ TileIndex* ti;
- for(ti=_animated_tile_list; ti!=endof(_animated_tile_list); ti++) {
+ for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
if (tile == *ti) {
/* remove the hole */
- memmove(ti, ti+1, endof(_animated_tile_list) - 1 - ti);
+ memmove(ti, ti + 1, endof(_animated_tile_list) - 1 - ti);
/* and clear last item */
endof(_animated_tile_list)[-1] = 0;
MarkTileDirtyByTile(tile);
@@ -339,9 +338,9 @@ void DeleteAnimatedTile(TileIndex tile)
bool AddAnimatedTile(TileIndex tile)
{
- TileIndex *ti;
+ TileIndex* ti;
- for(ti=_animated_tile_list; ti!=endof(_animated_tile_list); ti++) {
+ for (ti = _animated_tile_list; ti != endof(_animated_tile_list); ti++) {
if (tile == *ti || *ti == 0) {
*ti = tile;
MarkTileDirtyByTile(tile);
@@ -354,11 +353,10 @@ bool AddAnimatedTile(TileIndex tile)
void AnimateAnimatedTiles(void)
{
- TileIndex *ti;
- TileIndex tile;
+ const TileIndex* ti;
- for(ti=_animated_tile_list; ti!=endof(_animated_tile_list) && (tile=*ti) != 0; ti++) {
- AnimateTile(tile);
+ for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) {
+ AnimateTile(*ti);
}
}
@@ -371,8 +369,9 @@ static void SaveLoad_ANIT(void)
{
if (_sl_version < 6) {
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32);
- } else
+ } else {
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
+ }
}
diff --git a/tile.c b/tile.c
index 862acc417..9fe175766 100644
--- a/tile.c
+++ b/tile.c
@@ -41,10 +41,10 @@ uint GetTileSlope(TileIndex tile, uint *h)
if (min >= d) min = d;
r = 0;
- if ((a -= min) != 0) { r += (--a << 4) + 8; }
- if ((c -= min) != 0) { r += (--c << 4) + 4; }
- if ((d -= min) != 0) { r += (--d << 4) + 2; }
- if ((b -= min) != 0) { r += (--b << 4) + 1; }
+ if ((a -= min) != 0) r += (--a << 4) + 8;
+ if ((c -= min) != 0) r += (--c << 4) + 4;
+ if ((d -= min) != 0) r += (--d << 4) + 2;
+ if ((b -= min) != 0) r += (--b << 4) + 1;
if (h != NULL)
*h = min * 8;
diff --git a/town_cmd.c b/town_cmd.c
index b265057c0..3894164b2 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1657,9 +1657,7 @@ static void TownActionBuyRights(Town *t, int action)
static void TownActionBribe(Town *t, int action)
{
if (!RandomRange(15)) {
- GoodsEntry *ge;
Station *st;
- int i, rating;
// set as unwanted for 6 months
t->unwanted[_current_player] = 6;
@@ -1667,8 +1665,9 @@ static void TownActionBribe(Town *t, int action)
// set all close by station ratings to 0
FOR_ALL_STATIONS(st) {
if (st->town == t && st->owner == _current_player) {
- for (i=0, ge = st->goods; i != NUM_CARGO; i++, ge++)
- ge->rating = 0;
+ uint i;
+
+ for (i = 0; i != NUM_CARGO; i++) st->goods[i].rating = 0;
}
}
@@ -1680,9 +1679,9 @@ static void TownActionBribe(Town *t, int action)
* ChangeTownRating is only for stuff in demolishing. Bribe failure should
* be independent of any cheat settings
*/
- rating = t->ratings[_current_player];
- if (rating > -50)
+ if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) {
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO;
+ }
} else {
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM);
}
diff --git a/town_gui.c b/town_gui.c
index f5d6e9a57..a348bf27c 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -455,7 +455,7 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
y += 10;
i++;
- if (++n == w->vscroll.cap) { break;} // max number of towns in 1 window
+ if (++n == w->vscroll.cap) break; // max number of towns in 1 window
}
SetDParam(0, GetWorldPopulation());
DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0);
@@ -479,11 +479,11 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
case 5: { /* Click on Town Matrix */
uint16 id_v = (e->click.pt.y - 28) / 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;
- if (id_v >= _num_town_sort) { return;} // click out of town bounds
+ if (id_v >= _num_town_sort) return; // click out of town bounds
{
Town *t = GetTown(_town_sort[id_v]);
diff --git a/train_cmd.c b/train_cmd.c
index 1e9603f95..2a65b91b8 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1080,14 +1080,17 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tmp = v->next;
if (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) {
- /* Always delete newly encountered front-engines */
if (IS_FIRSTHEAD_SPRITE(v->spritenum)) {
+ /* Always delete newly encountered front-engines */
enf_count--;
- /* If we have more rear engines than front engines, then that means
- * that this rear-engine does not belong to any front-engine; delete */
- } else if (enr_count > enf_count) { enr_count--;}
- /* Otherwise leave it alone */
- else continue;
+ } else if (enr_count > enf_count) {
+ /* More rear engines than front engines means this rear-engine does
+ * not belong to any front-engine; delete */
+ enr_count--;
+ } else {
+ /* Otherwise leave it alone */
+ continue;
+ }
}
cost -= v->value;
@@ -1180,8 +1183,8 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r)
Vehicle *a, *b;
/* locate vehicles to swap */
- for(a=v; l!=0; l--) { a = a->next; }
- for(b=v; r!=0; r--) { b = b->next; }
+ for (a = v; l != 0; l--) a = a->next;
+ for (b = v; r != 0; r--) b = b->next;
if (a != b) {
/* swap the hidden bits */
@@ -1586,7 +1589,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
return tfdd;
}
- if (v->u.rail.track == 0x40) { tile = GetVehicleOutOfTunnelTile(v); }
+ if (v->u.rail.track == 0x40) tile = GetVehicleOutOfTunnelTile(v);
if (_patches.new_pathfinding_all) {
NPFFoundTargetData ftd;
@@ -1756,7 +1759,7 @@ static void HandleLocomotiveSmokeCloud(Vehicle *v)
}
-static void TrainPlayLeaveStationSound(Vehicle *v)
+static void TrainPlayLeaveStationSound(const Vehicle* v)
{
static const SoundFx sfx[] = {
SND_04_TRAIN,
@@ -2157,8 +2160,10 @@ static bool ProcessTrainOrder(Vehicle *v)
}
// check if we've reached a non-stop station while TTDPatch nonstop is enabled..
- if (_patches.new_nonstop && v->current_order.flags & OF_NON_STOP &&
- v->current_order.station == _m[v->tile].m2 && IsTileType(v->tile, MP_STATION) ) {
+ if (_patches.new_nonstop &&
+ v->current_order.flags & OF_NON_STOP &&
+ IsTileType(v->tile, MP_STATION) &&
+ v->current_order.station == _m[v->tile].m2) {
v->cur_order_index++;
}
@@ -2456,9 +2461,10 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
}
return
- IsTileOwner(tile, v->owner) &&
- (v->subtype != TS_Front_Engine ||
- IsCompatibleRail(v->u.rail.railtype, GetRailType(tile)));
+ IsTileOwner(tile, v->owner) && (
+ v->subtype != TS_Front_Engine ||
+ IsCompatibleRail(v->u.rail.railtype, GetRailType(tile))
+ );
}
typedef struct {
@@ -2559,9 +2565,9 @@ static void SetVehicleCrashed(Vehicle *v)
InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR);
}
-static int CountPassengersInTrain(const Vehicle *v)
+static uint CountPassengersInTrain(const Vehicle* v)
{
- int num = 0;
+ uint num = 0;
BEGIN_ENUM_WAGONS(v)
if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count;
END_ENUM_WAGONS(v)
@@ -3046,8 +3052,7 @@ static void HandleBrokenTrain(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;
}
}
diff --git a/train_gui.c b/train_gui.c
index c3dde82f2..cfdb8e432 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -1461,7 +1461,7 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
- 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;
diff --git a/vehicle.c b/vehicle.c
index 266f9203f..33e94eeff 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1496,8 +1496,7 @@ int32 ReplaceVehicle(Vehicle *v)
/* Update limits of the vehicle (for when upgraded) */
switch (v->type) {
- case VEH_Train:
- {
+ case VEH_Train: {
const RailVehicleInfo *rvi = RailVehInfo(new_engine_type);
const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type);
byte capacity = rvi2->capacity;
@@ -1507,10 +1506,10 @@ int32 ReplaceVehicle(Vehicle *v)
/* rvi->image_index is the new sprite for the engine. Adding +1 makes the engine head the other way
if it is a multiheaded engine (rear engine)
(rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) is true if the engine is heading the other way, otherwise 0*/
- v->spritenum = rvi->image_index + (( rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) ? 1 : 0);
+ v->spritenum = rvi->image_index + ((rvi->flags & RVI_MULTIHEAD && sprite - rvi2->image_index) ? 1 : 0);
// turn the last engine in a multiheaded train if needed
- if ( v->next == NULL && v->u.rail.first_engine != INVALID_VEHICLE && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index )
+ if (v->next == NULL && v->u.rail.first_engine != INVALID_VEHICLE && rvi->flags & RVI_MULTIHEAD && v->spritenum == rvi->image_index)
v->spritenum++;
v->cargo_type = rvi->cargo_type;
@@ -1561,9 +1560,9 @@ int32 ReplaceVehicle(Vehicle *v)
InvalidateWindowClasses(WC_TRAINS_LIST);
UpdateTrainAcceleration(first);
break;
- }
- case VEH_Road:
- {
+ }
+
+ case VEH_Road: {
const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type);
v->spritenum = rvi->image_index;
@@ -1572,9 +1571,9 @@ int32 ReplaceVehicle(Vehicle *v)
v->max_speed = rvi->max_speed;
InvalidateWindowClasses(WC_ROADVEH_LIST);
break;
- }
- case VEH_Ship:
- {
+ }
+
+ case VEH_Ship: {
const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type);
v->spritenum = svi->image_index;
@@ -1588,9 +1587,9 @@ int32 ReplaceVehicle(Vehicle *v)
CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
InvalidateWindowClasses(WC_SHIPS_LIST);
break;
- }
- case VEH_Aircraft:
- {
+ }
+
+ case VEH_Aircraft: {
const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type);
Vehicle *u;
@@ -1609,7 +1608,8 @@ int32 ReplaceVehicle(Vehicle *v)
}
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
break;
- }
+ }
+
default: return CMD_ERROR;
}
// makes sure that the cargo is still valid compared to new capacity
@@ -2231,7 +2231,7 @@ static void Load_VEHS(void)
v = GetVehicle(index);
SlObject(v, _veh_descs[SlReadByte()]);
- /* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
+ /* Old savegames used 'last_station_visited = 0xFF' */
if (_sl_version < 5 && v->last_station_visited == 0xFF)
v->last_station_visited = INVALID_STATION;
diff --git a/vehicle_gui.c b/vehicle_gui.c
index ce28ca7fc..81231658f 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -145,13 +145,13 @@ void BuildVehicleList(vehiclelist_d* vl, int type, PlayerID owner, StationID sta
}
}
- vl->sort_list = realloc(vl->sort_list, n * sizeof(vl->sort_list[0]));
- if (n!=0 && vl->sort_list == NULL)
+ free(vl->sort_list);
+ vl->sort_list = malloc(n * sizeof(vl->sort_list[0]));
+ if (n != 0 && vl->sort_list == NULL)
error("Could not allocate memory for the vehicle-sorting-list");
vl->list_length = n;
- for (i = 0; i < n; ++i)
- vl->sort_list[i] = _vehicle_sort[i];
+ for (i = 0; i < n; ++i) vl->sort_list[i] = _vehicle_sort[i];
vl->flags &= ~VL_REBUILD;
vl->flags |= VL_RESORT;
@@ -340,26 +340,22 @@ static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b)
static int CDECL VehicleCargoSorter(const void *a, const void *b)
{
- const Vehicle *va = GetVehicle((*(const SortStruct*)a).index);
- const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index);
- const Vehicle *v;
+ const Vehicle* va = GetVehicle(((const SortStruct*)a)->index);
+ const Vehicle* vb = GetVehicle(((const SortStruct*)b)->index);
+ const Vehicle* v;
+ AcceptedCargo cargoa;
+ AcceptedCargo cargob;
int r = 0;
int i;
- uint _cargo_counta[NUM_CARGO];
- uint _cargo_countb[NUM_CARGO];
- memset(_cargo_counta, 0, sizeof(_cargo_counta));
- memset(_cargo_countb, 0, sizeof(_cargo_countb));
- for (v = va; v != NULL; v = v->next)
- _cargo_counta[v->cargo_type] += v->cargo_cap;
-
- for (v = vb; v != NULL; v = v->next)
- _cargo_countb[v->cargo_type] += v->cargo_cap;
+ memset(cargoa, 0, sizeof(cargoa));
+ memset(cargob, 0, sizeof(cargob));
+ for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap;
+ for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap;
for (i = 0; i < NUM_CARGO; i++) {
- r = _cargo_counta[i] - _cargo_countb[i];
- if (r != 0)
- break;
+ r = cargoa[i] - cargob[i];
+ if (r != 0) break;
}
VEHICLEUNITNUMBERSORTER(r, va, vb);
@@ -1058,7 +1054,7 @@ void ShowReplaceVehicleWindow(byte vehicletype)
{
Window *w;
- DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype );
+ DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
switch (vehicletype) {
case VEH_Train:
@@ -1071,7 +1067,8 @@ void ShowReplaceVehicleWindow(byte vehicletype)
w->vscroll.cap = 8;
w->resize.step_height = 14;
break;
- case VEH_Ship: case VEH_Aircraft:
+ case VEH_Ship:
+ case VEH_Aircraft:
w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
w->vscroll.cap = 4;
w->resize.step_height = 24;
diff --git a/water_cmd.c b/water_cmd.c
index c61abdbd5..a820a1fbb 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -324,14 +324,15 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags);
} else {
// ship depot
- if (flags & DC_AUTO)
- return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
+ if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
- if (m5 == 0x80 || m5 == 0x82) {}
- else if (m5 == 0x81) { tile -= TileDiffXY(1, 0); }
- else if (m5 == 0x83) { tile -= TileDiffXY(0, 1); }
- else
- return CMD_ERROR;
+ switch (m5) {
+ case 0x80: break;
+ case 0x81: tile -= TileDiffXY(1, 0); break;
+ case 0x82: break;
+ case 0x83: tile -= TileDiffXY(0, 1); break;
+ default: return CMD_ERROR;
+ }
return RemoveShipDepot(tile,flags);
}
@@ -580,7 +581,6 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
static void FloodVehicle(Vehicle *v)
{
- Vehicle *u;
if (!(v->vehstatus & VS_CRASHED)) {
uint16 pass = 0;
@@ -592,9 +592,9 @@ static void FloodVehicle(Vehicle *v)
v->vehstatus |= VS_CRASHED;
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
RebuildVehicleLists();
- }
+ } else if (v->type == VEH_Train) {
+ Vehicle* u;
- else if (v->type == VEH_Train) {
v = GetFirstVehicleInChain(v);
u = v;
if (v->subtype == TS_Front_Engine) pass = 4; // driver
@@ -608,8 +608,9 @@ static void FloodVehicle(Vehicle *v)
v = u;
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
RebuildVehicleLists();
- } else
+ } else {
return;
+ }
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
@@ -619,8 +620,8 @@ static void FloodVehicle(Vehicle *v)
NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
v->index,
0);
- CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); // show cool destruction effects
- SndPlayVehicleFx(SND_12_EXPLOSION, v); // create sound
+ CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
+ SndPlayVehicleFx(SND_12_EXPLOSION, v);
}
}
diff --git a/window.c b/window.c
index eeb3d88bb..aa59ea0d9 100644
--- a/window.c
+++ b/window.c
@@ -214,11 +214,9 @@ void CallWindowEventNP(Window *w, int event)
w->wndproc(w, &e);
}
-void SetWindowDirty(Window *w)
+void SetWindowDirty(const Window* w)
{
- if (w == NULL)
- return;
-
+ if (w == NULL) return;
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
}
@@ -1402,10 +1400,16 @@ static void MouseLoop(int click, int mousewheel)
y -= vp->top;
//here allows scrolling in both x and y axis
#define scrollspeed 3
- if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; }
- else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; }
- if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; }
- else if (15-(vp->height-y) > 0) { WP(w,vp_d).scrollpos_y += (15-(vp->height-y))*scrollspeed << vp->zoom; }
+ if (x - 15 < 0) {
+ WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
+ } else if (15 - (vp->width - x) > 0) {
+ WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom;
+ }
+ if (y - 15 < 0) {
+ WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom;
+ } else if (15 - (vp->height - y) > 0) {
+ WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom;
+ }
#undef scrollspeed
}
}
@@ -1434,8 +1438,9 @@ static void MouseLoop(int click, int mousewheel)
_cursor.sprite != SPR_CURSOR_QUERY &&
_cursor.sprite != SPR_CURSOR_SIGN &&
_pause != 0 &&
- !_cheats.build_in_pause.value)
- return;
+ !_cheats.build_in_pause.value) {
+ return;
+ }
if (_thd.place_mode == 0) {
HandleViewportClicked(vp, x, y);
diff --git a/window.h b/window.h
index 8890777c4..5bc61c665 100644
--- a/window.h
+++ b/window.h
@@ -553,7 +553,7 @@ void DispatchMouseWheelEvent(Window *w, int widget, int wheel);
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
void CallWindowEventNP(Window *w, int event);
void CallWindowTickEvent(void);
-void SetWindowDirty(Window *w);
+void SetWindowDirty(const Window* w);
void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam);
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);