1
0
Fork 0

(svn r3078) Some more stuff, which piled up:

- const, whitespace, indentation, bracing, GB/SB, pointless casts
- use the trinary operator where appropriate
- data types (uint[] -> AcceptedCargo, ...)
- if cascade -> switch
- if (ptr) -> if (ptr != NULL)
- DeMorgan's Law
- Fix some comments
- 0 -> '\0', change magic numbers to symbolic constants
release/0.4.5
tron 2005-10-23 13:04:44 +00:00
parent 2cc2154ad2
commit 47137cefb7
38 changed files with 442 additions and 453 deletions

View File

@ -229,7 +229,7 @@ int AiNew_PickVehicle(Player *p)
count = _cargoc.ai_roadveh_count[p->ainew.cargo]; count = _cargoc.ai_roadveh_count[p->ainew.cargo];
// Let's check it backwards.. we simply want to best engine available.. // 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? // Is it availiable?
// Also, check if the reliability of the vehicle is above the AI_VEHICLE_MIN_RELIABILTY // 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; 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; if (!CmdFailed(ret)) break;
} }
// We did not find a vehicle :( // We did not find a vehicle :(
if (CmdFailed(ret)) { return -1; } if (CmdFailed(ret)) return -1;
return i; return i;
} }
} }

View File

@ -506,9 +506,5 @@ static int32 AyStar_AiPathFinder_CalculateG(AyStar *aystar, AyStarNode *current,
} }
} }
// Res should never be below zero.. if so, make it zero! return (res < 0) ? 0 : res;
if (res < 0) { res = 0; }
// Return our value
return res;
} }

View File

@ -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. * This AI was created as a direct reaction to the big demand for some good AIs
* Too bad it never left alpha-stage, and it is considered dead in his current form. * in OTTD. Too bad it never left alpha-stage, and it is considered dead in its
* By the time of writing this, we, the creator of this AI and a good friend of mine, * current form.
* are designing a whole new AI-system that allows us to create AIs easier and without * By the time of writing this, we, the creator of this AI and a good friend of
* all the fuzz we encountered while I was working on this AI. By the time that system * mine, are designing a whole new AI-system that allows us to create AIs
* is finished, you can expect that this AI will dissapear, because it is pretty * easier and without all the fuzz we encountered while I was working on this
* obselete and bad programmed. * 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 * 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 * AI-developer in this AI, I advise you not stare too long to some code, some
* here really are... strange ;) But in either way: enjoy :) * things in here really are... strange ;) But in either way: enjoy :)
* *
* -- TrueLight :: 2005-09-01 * -- TrueLight :: 2005-09-01
*/ */

View File

@ -690,16 +690,16 @@ static void HelicopterTickHandler(Vehicle *v)
if (spd == 0) { if (spd == 0) {
img = SPR_ROTOR_STOPPED; img = SPR_ROTOR_STOPPED;
if (u->cur_image == img) if (u->cur_image == img) return;
return;
} else if (tick >= spd) { } else if (tick >= spd) {
u->tick_counter = 0; u->tick_counter = 0;
img = u->cur_image + 1; img = u->cur_image + 1;
if (img > SPR_ROTOR_MOVING_3) img = SPR_ROTOR_MOVING_1; if (img > SPR_ROTOR_MOVING_3) img = SPR_ROTOR_MOVING_1;
} else } else {
return; return;
}
u->cur_image=img; u->cur_image = img;
BeginVehicleMove(u); BeginVehicleMove(u);
VehiclePositionChanged(u); VehiclePositionChanged(u);
@ -767,7 +767,7 @@ static void ServiceAircraft(Vehicle *v)
InvalidateWindow(WC_VEHICLE_DETAILS, v->index); InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
} }
static void PlayAircraftSound(Vehicle *v) static void PlayAircraftSound(const Vehicle* v)
{ {
SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v); SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
} }
@ -1229,7 +1229,7 @@ static void MaybeCrashAirplane(Vehicle *v)
{ {
Station *st; Station *st;
uint16 prob; uint16 prob;
int i; uint i;
st = GetStation(v->u.air.targetairport); st = GetStation(v->u.air.targetairport);
@ -1242,7 +1242,7 @@ static void MaybeCrashAirplane(Vehicle *v)
if (GB(Random(), 0, 16) > prob) return; if (GB(Random(), 0, 16) > prob) return;
// Crash the airplane. Remove all goods stored at the station. // 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; st->goods[i].rating = 1;
SB(st->goods[i].waiting_acceptance, 0, 12, 0); SB(st->goods[i].waiting_acceptance, 0, 12, 0);
} }
@ -1425,16 +1425,18 @@ static void AircraftEventHandler_InHangar(Vehicle *v, const AirportFTAClass *Air
return; return;
// if the block of the next position is busy, stay put // 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 // We are already at the target airport, we need to find a terminal
if (v->current_order.station == v->u.air.targetairport) { if (v->current_order.station == v->u.air.targetairport) {
// FindFreeTerminal: // FindFreeTerminal:
// 1. Find a free terminal, 2. Occupy it, 3. Set the vehicle's state to that terminal // 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 if (v->subtype != 0) {
else {if(!AirportFindFreeHelipad(v, Airport)) {return;}} // helicopter if (!AirportFindFreeTerminal(v, Airport)) return; // airplane
} } else {
else { // Else prepare for launch. if (!AirportFindFreeHelipad(v, Airport)) return; // helicopter
}
} else { // Else prepare for launch.
// airplane goto state takeoff, helicopter to helitakeoff // airplane goto state takeoff, helicopter to helitakeoff
v->u.air.state = (v->subtype != 0) ? TAKEOFF : 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) static void AircraftEventHandler_EndLanding(Vehicle *v, const AirportFTAClass *Airport)
{ {
// next block busy, don't do a thing, just wait // 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 // if going to terminal (OT_GOTO_STATION) choose one
// 1. in case all terminals are busy AirportFindFreeTerminal() returns false or // 1. in case all terminals are busy AirportFindFreeTerminal() returns false or
// 2. not going for terminal (but depot, no order), // 2. not going for terminal (but depot, no order),
// --> get out of the way to the hangar. // --> get out of the way to the hangar.
if (v->current_order.type == OT_GOTO_STATION) { if (v->current_order.type == OT_GOTO_STATION) {
if (AirportFindFreeTerminal(v, Airport)) {return;} if (AirportFindFreeTerminal(v, Airport)) return;
} }
v->u.air.state = HANGAR; 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) static void AircraftEventHandler_HeliEndLanding(Vehicle *v, const AirportFTAClass *Airport)
{ {
// next block busy, don't do a thing, just wait // 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 // 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 // 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 // the reason behind this is that if an airport has a terminal, it also has a hangar. Airplanes
// must go to a hangar. // must go to a hangar.
if (v->current_order.type == OT_GOTO_STATION) { 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; 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) static void AirportGoToNextPosition(Vehicle *v, const AirportFTAClass *Airport)
{ {
// if aircraft is not in position, wait until it is // if aircraft is not in position, wait until it is
if (!AircraftController(v)) {return;} if (!AircraftController(v)) return;
AirportClearBlock(v, Airport); AirportClearBlock(v, Airport);
AirportMove(v, Airport); // move aircraft to next position 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) { if (current->heading == v->u.air.state) {
prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand 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); _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; 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 //search for all all elements in the list with the same state, and blocks != N
// this means more blocks should be checked/set // this means more blocks should be checked/set
current = current_pos; current = current_pos;
if (current == reference) { current = current->next_in_chain;} if (current == reference) current = current->next_in_chain;
while (current != NULL) { while (current != NULL) {
if (current->heading == current_pos->heading && current->block != 0) { if (current->heading == current_pos->heading && current->block != 0) {
airport_flags |= current->block; 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 // 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 // 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)) { if (HASBITS(st->airport_flags, airport_flags)) {
v->cur_speed = 0; v->cur_speed = 0;
@ -1855,14 +1857,17 @@ static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
//at what terminal does the group start? //at what terminal does the group start?
//that means, sum up all terminals of //that means, sum up all terminals of
//groups with lower number //groups with lower number
for(i = 1; i < target_group; i++) for (i = 1; i < target_group; i++)
group_start += Airport->terminals[i]; group_start += Airport->terminals[i];
group_end = group_start + Airport->terminals[target_group]; 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; temp = temp->next_in_chain;
} }
} }
@ -1888,7 +1893,7 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
AirportFTA *temp; AirportFTA *temp;
// if an airport doesn't have helipads, use terminals // 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 there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
if (Airport->helipads[0] > 1) { if (Airport->helipads[0] > 1) {
@ -1913,16 +1918,20 @@ static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
group_start += Airport->helipads[i]; group_start += Airport->helipads[i];
group_end = group_start + Airport->helipads[target_group]; 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; 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 return false; // it shouldn't get here anytime, but just to be sure
} }
@ -2000,7 +2009,7 @@ void UpdateOldAircraft(void)
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
st->airport_flags = 0; // reset airport st->airport_flags = 0; // reset airport
// type of oilrig has been moved, update it (3-5) // 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) { FOR_ALL_VEHICLES(v_oldstyle) {
@ -2021,7 +2030,7 @@ void UpdateOldAircraft(void)
v_oldstyle->tile = 0; // aircraft in air is tile=0 v_oldstyle->tile = 0; // aircraft in air is tile=0
// correct speed of helicopter-rotors // 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 // set new position x,y,z
SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle)); SetAircraftPosition(v_oldstyle, gp.x, gp.y, GetAircraftFlyingAltitude(v_oldstyle));
@ -2051,8 +2060,7 @@ void UpdateAirplanesOnNewStation(Station *st)
GetNewVehiclePos(v, &gp); GetNewVehiclePos(v, &gp);
// set new position x,y,z // set new position x,y,z
SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v)); SetAircraftPosition(v, gp.x, gp.y, GetAircraftFlyingAltitude(v));
} } else {
else {
assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF); assert(v->u.air.state == ENDTAKEOFF || v->u.air.state == HELITAKEOFF);
takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF; takeofftype = (v->subtype == 0) ? HELITAKEOFF : ENDTAKEOFF;
// search in airportdata for that heading // search in airportdata for that heading

View File

@ -1063,10 +1063,11 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
DrawVehicleProfitButton(v, x, y + 13); DrawVehicleProfitButton(v, x, y + 13);
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);
if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) if (IsAircraftHangarTile(v->tile) && (v->vehstatus & VS_HIDDEN)) {
str = STR_021F; str = STR_021F;
else } else {
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
}
DrawString(x, y + 2, str, 0); DrawString(x, y + 2, str, 0);
SetDParam(0, v->profit_this_year); SetDParam(0, v->profit_this_year);
@ -1100,7 +1101,7 @@ static void PlayerAircraftWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */ 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; 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; id_v += w->vscroll.pos;

View File

@ -176,14 +176,15 @@ static void AirportFTAClass_Constructor(AirportFTAClass *Airport,
// build the state machine // build the state machine
AirportBuildAutomata(Airport, FA); 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, DEBUG(misc, 1) ("#Elements %2d; #Terminals %2d in %d group(s); #Helipads %2d in %d group(s); Entry Point %d",
nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point); Airport->nofelements, nofterminals, nofterminalgroups, nofhelipads, nofhelipadgroups, Airport->entry_point
);
{ {
byte _retval = AirportTestFTA(Airport); byte ret = AirportTestFTA(Airport);
if (_retval != MAX_ELEMENTS) {printf("ERROR with element: %d\n", _retval-1);} if (ret != MAX_ELEMENTS) printf("ERROR with element: %d\n", ret - 1);
assert(_retval == MAX_ELEMENTS); assert(ret == MAX_ELEMENTS);
} }
// print out full information // print out full information
// true -- full info including heading, block, etc // true -- full info including heading, block, etc
@ -213,12 +214,13 @@ static uint16 AirportGetNofElements(const AirportFTAbuildup *FA)
int i; int i;
uint16 nofelements = 0; uint16 nofelements = 0;
int temp = FA[0].position; int temp = FA[0].position;
for (i = 0; i < MAX_ELEMENTS; i++) { for (i = 0; i < MAX_ELEMENTS; i++) {
if (temp != FA[i].position) { if (temp != FA[i].position) {
nofelements++; nofelements++;
temp = FA[i].position; temp = FA[i].position;
} }
if (FA[i].position == MAX_ELEMENTS) {break;} if (FA[i].position == MAX_ELEMENTS) break;
} }
return nofelements; return nofelements;
} }
@ -228,7 +230,7 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
AirportFTA *FAutomata; AirportFTA *FAutomata;
AirportFTA *current; AirportFTA *current;
uint16 internalcounter, i; uint16 internalcounter, i;
FAutomata = (AirportFTA *)malloc(sizeof(AirportFTA) * Airport->nofelements); FAutomata = malloc(sizeof(AirportFTA) * Airport->nofelements);
Airport->layout = FAutomata; Airport->layout = FAutomata;
internalcounter = 0; internalcounter = 0;
@ -240,12 +242,13 @@ static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuild
current->next_position = FA[internalcounter].next_in_chain; current->next_position = FA[internalcounter].next_in_chain;
// outgoing nodes from the same position, create linked list // outgoing nodes from the same position, create linked list
while (current->position == FA[internalcounter+1].position) { while (current->position == FA[internalcounter + 1].position) {
AirportFTA *newNode = (AirportFTA *)malloc(sizeof(AirportFTA)); AirportFTA* newNode = malloc(sizeof(AirportFTA));
newNode->position = FA[internalcounter+1].position;
newNode->heading = FA[internalcounter+1].heading; newNode->position = FA[internalcounter + 1].position;
newNode->block = FA[internalcounter+1].block; newNode->heading = FA[internalcounter + 1].heading;
newNode->next_position = FA[internalcounter+1].next_in_chain; newNode->block = FA[internalcounter + 1].block;
newNode->next_position = FA[internalcounter + 1].next_in_chain;
// create link // create link
current->next_in_chain = newNode; current->next_in_chain = newNode;
current = current->next_in_chain; current = current->next_in_chain;
@ -264,14 +267,14 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
for (i = 0; i < Airport->nofelements; i++) { for (i = 0; i < Airport->nofelements; i++) {
position = Airport->layout[i].position; position = Airport->layout[i].position;
if (position != next_element) {return i;} if (position != next_element) return i;
temp = &Airport->layout[i]; temp = &Airport->layout[i];
do { do {
if (temp->heading > MAX_HEADINGS && temp->heading != 255) {return i;} if (temp->heading > MAX_HEADINGS && temp->heading != 255) return i;
if (temp->heading == 0 && temp->next_in_chain != 0) {return i;} if (temp->heading == 0 && temp->next_in_chain != 0) return i;
if (position != temp->position) {return i;} if (position != temp->position) return i;
if (temp->next_position >= Airport->nofelements) {return i;} if (temp->next_position >= Airport->nofelements) return i;
temp = temp->next_in_chain; temp = temp->next_in_chain;
} while (temp != NULL); } while (temp != NULL);
next_element++; next_element++;
@ -279,7 +282,8 @@ static byte AirportTestFTA(const AirportFTAClass *Airport)
return MAX_ELEMENTS; return MAX_ELEMENTS;
} }
static const char* const _airport_heading_strings[MAX_HEADINGS+2] = { #if 0
static const char* const _airport_heading_strings[] = {
"TO_ALL", "TO_ALL",
"HANGAR", "HANGAR",
"TERM1", "TERM1",
@ -302,7 +306,6 @@ static const char* const _airport_heading_strings[MAX_HEADINGS+2] = {
"DUMMY" // extra heading for 255 "DUMMY" // extra heading for 255
}; };
/*
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report) static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
{ {
AirportFTA *temp; 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; heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block)); _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) { while (temp->next_in_chain != NULL) {
temp = temp->next_in_chain; temp = temp->next_in_chain;
if (full_report) { if (full_report) {
heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading; heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position, printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
_airport_heading_strings[heading], AirportBlockToString(temp->block)); _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"); printf("\n");
} }
@ -341,7 +346,8 @@ static byte AirportBlockToString(uint32 block)
if (block & 0x0000000c) { block >>= 2; i += 2; } if (block & 0x0000000c) { block >>= 2; i += 2; }
if (block & 0x00000002) { i += 1; } if (block & 0x00000002) { i += 1; }
return i; return i;
}*/ }
#endif
const AirportFTAClass* GetAirport(const byte airport_type) const AirportFTAClass* GetAirport(const byte airport_type)
{ {

View File

@ -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); if (e->click.widget - 3 >= 0 && e->click.widget != 5) _build_docks_button_proc[e->click.widget - 3](w);
break; break;
case WE_KEYPRESS: { case WE_KEYPRESS:
switch(e->keypress.keycode) { switch (e->keypress.keycode) {
case '1': BuildDocksClick_Canal(w); break; case '1': BuildDocksClick_Canal(w); break;
case '2': BuildDocksClick_Lock(w); break; case '2': BuildDocksClick_Lock(w); break;
case '3': BuildDocksClick_Demolish(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 '5': BuildDocksClick_Dock(w); break;
case '6': BuildDocksClick_Buoy(w); break; case '6': BuildDocksClick_Buoy(w); break;
case 'l': BuildDocksClick_Landscaping(w); break; case 'l': BuildDocksClick_Landscaping(w); break;
default: default: return;
return;
} }
} break; break;
case WE_PLACE_OBJ: case WE_PLACE_OBJ:
_place_proc(e->place.tile); _place_proc(e->place.tile);
@ -151,8 +150,9 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
if (e->click.pt.x != -1) { if (e->click.pt.x != -1) {
if ((e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions if ((e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions
GUIPlaceProcDragXY(e); 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)); DoCommandP(e->place.tile, e->place.starttile, 0, CcBuildCanal, CMD_BUILD_CANAL | CMD_AUTO | CMD_MSG(STR_CANT_BUILD_CANALS));
}
} }
break; break;
@ -161,10 +161,10 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
SetWindowDirty(w); SetWindowDirty(w);
w = FindWindowById(WC_BUILD_STATION, 0); 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); 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; break;
case WE_PLACE_PRESIZE: { case WE_PLACE_PRESIZE: {
@ -298,7 +298,7 @@ static void UpdateDocksDirection(void)
static void BuildDocksDepotWndProc(Window *w, WindowEvent *e) static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: case WE_PAINT:
w->click_state = (1<<3) << _ship_depot_direction; w->click_state = (1<<3) << _ship_depot_direction;
DrawWindowWidgets(w); DrawWindowWidgets(w);
@ -310,7 +310,7 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
return; return;
case WE_CLICK: { case WE_CLICK: {
switch(e->click.widget) { switch (e->click.widget) {
case 3: case 3:
case 4: case 4:
_ship_depot_direction = e->click.widget - 3; _ship_depot_direction = e->click.widget - 3;

View File

@ -122,7 +122,6 @@ void ShowEnginePreviewWindow(EngineID engine)
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw) static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
{ {
const RailVehicleInfo *rvi = RailVehInfo(engine); const RailVehicleInfo *rvi = RailVehInfo(engine);
int cap;
uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0; uint multihead = (rvi->flags & RVI_MULTIHEAD) ? 1 : 0;
SetDParam(0, (_price.build_railvehicle >> 3) * rvi->base_cost >> 5); 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); SetDParam(4, rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8 << multihead);
cap = rvi->capacity; if (rvi->capacity != 0) {
SetDParam(5, STR_8838_N_A);
if (cap != 0) {
SetDParam(6, cap << multihead);
SetDParam(5, _cargoc.names_long[rvi->cargo_type]); 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); DrawStringMultiCenter(x, y, STR_885B_COST_WEIGHT_T_SPEED_POWER, maxw);
} }

4
gui.h
View File

@ -42,7 +42,7 @@ void PlaceProc_BuyLand(TileIndex tile);
void ShowPlayerTrains(PlayerID player, StationID station); void ShowPlayerTrains(PlayerID player, StationID station);
void ShowTrainViewWindow(Vehicle *v); void ShowTrainViewWindow(Vehicle *v);
void ShowTrainDetailsWindow(Vehicle *v); void ShowTrainDetailsWindow(Vehicle *v);
void ShowOrdersWindow(Vehicle *v); void ShowOrdersWindow(const Vehicle* v);
void ShowRoadVehViewWindow(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 ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y);
void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad); void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad);
void CheckRedrawStationCoverage(Window *w); void CheckRedrawStationCoverage(const Window* w);
void ShowSmallMap(void); void ShowSmallMap(void);
void ShowExtraViewPortWindow(void); void ShowExtraViewPortWindow(void);

View File

@ -1011,14 +1011,11 @@ static void PlantFarmField(TileIndex tile)
static void MaybePlantFarmField(const Industry* i) static void MaybePlantFarmField(const Industry* i)
{ {
TileIndex tile; if (CHANCE16(1, 8)) {
int x = i->width / 2 + Random() % 31 - 16;
if (CHANCE16(1,8)) { int y = i->height / 2 + Random() % 31 - 16;
int x = (i->width>>1) + Random() % 31 - 16; TileIndex tile = TileAddWrap(i->xy, x, y);
int y = (i->height>>1) + Random() % 31 - 16; if (tile != INVALID_TILE) PlantFarmField(tile);
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) static bool CheckNewIndustry_BubbleGen(TileIndex tile, int type)
{ {
if (GetTileZ(tile) > 32) { return GetTileZ(tile) <= 32;
return false;
}
return true;
} }
typedef bool CheckNewIndustryProc(TileIndex tile, int type); 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 */ /* Check if we can add a block to the pool */
if (AddBlockToPool(&_industry_pool)) return AddBlockToPool(&_industry_pool) ? AllocateIndustry() : NULL;
return AllocateIndustry();
return NULL;
} }
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, Town *t, byte owner) static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, Town *t, byte owner)

View File

@ -152,7 +152,7 @@ typedef void ToolbarButtonProc(Window *w);
static void ToolbarPauseClick(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)) if (DoCommandP(0, _pause ? 0 : 1, 0, NULL, CMD_PAUSE))
SndPlayFx(SND_15_BEEP); SndPlayFx(SND_15_BEEP);
@ -913,8 +913,10 @@ bool DoZoomInOutWindow(int how, Window *w)
// update the toolbar button too // update the toolbar button too
CLRBIT(wt->disabled_state, button); CLRBIT(wt->disabled_state, button);
CLRBIT(wt->disabled_state, button + 1); CLRBIT(wt->disabled_state, button + 1);
if (vp->zoom == 0) SETBIT(wt->disabled_state, button); switch (vp->zoom) {
else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1); case 0: SETBIT(wt->disabled_state, button); break;
case 2: SETBIT(wt->disabled_state, button + 1); break;
}
SetWindowDirty(wt); SetWindowDirty(wt);
} }

View File

@ -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) { if (_thd.dirty & 1) {
_thd.dirty&=~1; _thd.dirty &= ~1;
SetWindowDirty(w); SetWindowDirty(w);
} }
} }
@ -734,15 +734,15 @@ void UnclickSomeWindowButtons(Window *w, uint32 mask)
int i = 0; int i = 0;
w->click_state ^= x; w->click_state ^= x;
do { do {
if (x&1) InvalidateWidget(w,i); if (x & 1) InvalidateWidget(w, i);
} while(i++,x>>=1); } while (i++, x >>= 1);
} }
void UnclickWindowButtons(Window *w) void UnclickWindowButtons(Window *w)
{ {
bool sticky = false; 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); UnclickSomeWindowButtons(w, (uint32)-1);
@ -1164,10 +1164,17 @@ void BuildFileList(void)
{ {
_fios_path_changed = true; _fios_path_changed = true;
FiosFreeSavegameList(); FiosFreeSavegameList();
if (_saveload_mode == SLD_NEW_GAME || _saveload_mode == SLD_LOAD_SCENARIO || _saveload_mode == SLD_SAVE_SCENARIO) { switch (_saveload_mode) {
_fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode); case SLD_NEW_GAME:
} else case SLD_LOAD_SCENARIO:
_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode); 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) static void DrawFiosTexts(uint maxw)
@ -1258,9 +1265,8 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
item = _fios_list + pos; item = _fios_list + pos;
DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18); DoDrawStringTruncated(item->title, 4, y, _fios_colors[item->type], w->width - 18);
pos++; pos++;
y+=10; y += 10;
if (y >= w->vscroll.cap*10+w->widget[6].top+1) if (y >= w->vscroll.cap * 10 + w->widget[6].top + 1) break;
break;
} }
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { 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; pos = w->vscroll.pos;
while (pos < _fios_num) { while (pos < _fios_num) {
item = _fios_list + pos; item = _fios_list + pos;
DoDrawString(item->title, 4, y, _fios_colors[item->type] ); DoDrawString(item->title, 4, y, _fios_colors[item->type]);
pos++; pos++;
y+=10; y += 10;
if (y >= w->vscroll.cap*10+list_start) if (y >= w->vscroll.cap * 10 + list_start) break;
break;
} }
} }
break; break;
@ -1544,7 +1549,8 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
file = _fios_list + y; file = _fios_list + y;
if ((name = FiosBrowseTo(file)) != NULL) { name = FiosBrowseTo(file);
if (name != NULL) {
SetFiosType(file->type); SetFiosType(file->type);
strcpy(_file_to_saveload.name, name); strcpy(_file_to_saveload.name, name);
DeleteWindow(w); DeleteWindow(w);
@ -1571,14 +1577,19 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
void SetFiosType(const byte fiostype) void SetFiosType(const byte fiostype)
{ {
switch (fiostype) { switch (fiostype) {
case FIOS_TYPE_FILE: case FIOS_TYPE_SCENARIO: case FIOS_TYPE_FILE:
_file_to_saveload.mode = SL_LOAD; case FIOS_TYPE_SCENARIO:
break; _file_to_saveload.mode = SL_LOAD;
case FIOS_TYPE_OLDFILE: case FIOS_TYPE_OLD_SCENARIO: break;
_file_to_saveload.mode = SL_OLD_LOAD;
break; case FIOS_TYPE_OLDFILE:
default: case FIOS_TYPE_OLD_SCENARIO:
_file_to_saveload.mode = SL_INVALID; _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); DeleteWindowById(WC_CHEATS, 0);
w = AllocateWindowDesc(&_cheats_desc); w = AllocateWindowDesc(&_cheats_desc);
if (w) if (w != NULL) SetWindowDirty(w);
SetWindowDirty(w);
} }

View File

@ -642,7 +642,7 @@ uint32 GetOldTownName(uint32 townnameparts, byte old_town_name_type)
/* NUM_SILLY_1 - lower 16 bits /* NUM_SILLY_1 - lower 16 bits
* NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes) * NUM_SILLY_2 - upper 16 bits without leading 1 (first 8 bytes)
* 1000 0000 2222 2222 0000 0000 1111 1111 */ * 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; return 0;
} }

View File

@ -151,7 +151,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
cur_item = cur_item->next; cur_item = cur_item->next;
y += NET_PRC__SIZE_OF_ROW; 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 */ case 9: { /* Matrix to show networkgames */
uint32 id_v = (e->click.pt.y - NET_PRC__OFFSET_TOP_WIDGET) / NET_PRC__SIZE_OF_ROW; 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; id_v += w->vscroll.pos;
{ {

View File

@ -258,15 +258,9 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
uint32 base = grf_load_dword(&buf); uint32 base = grf_load_dword(&buf);
switch (base) { switch (base) {
case 0x4C30: case 0x4C30: rvi[i].engclass = 0; break;
rvi[i].engclass = 0; case 0x4C36: rvi[i].engclass = 1; break;
break; case 0x4C3C: rvi[i].engclass = 2; break;
case 0x4C36:
rvi[i].engclass = 1;
break;
case 0x4C3C:
rvi[i].engclass = 2;
break;
} }
dewagonize(base, engine + i); dewagonize(base, engine + i);
} }

View File

@ -351,8 +351,8 @@ static const SoundFx _news_sounds[] = {
*/ */
static inline byte GetNewsDisplayValue(byte item) static inline byte GetNewsDisplayValue(byte item)
{ {
assert(item < 10 && ((_news_display_opt >> (item * 2)) & 0x3) <= 2); assert(item < 10 && GB(_news_display_opt, item * 2, 2) <= 2);
return (_news_display_opt >> (item * 2)) & 0x3; return GB(_news_display_opt, item * 2, 2);
} }
/** Set the value of an item in the news-display settings. This is /** 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) static inline void SetNewsDisplayValue(byte item, byte val)
{ {
assert(item < 10 && val <= 2); assert(item < 10 && val <= 2);
item *= 2; SB(_news_display_opt, item * 2, 2, val);
CLRBIT(_news_display_opt, item);
CLRBIT(_news_display_opt, item + 1);
_news_display_opt |= val << item;
} }
// open up an own newspaper window for the news item // open up an own newspaper window for the news item
@ -530,15 +527,12 @@ static void ShowNewsMessage(byte i)
void ShowLastNewsMessage(void) void ShowLastNewsMessage(void)
{ {
if (_forced_news == INVALID_NEWS) if (_forced_news == INVALID_NEWS) {
ShowNewsMessage(_current_news); ShowNewsMessage(_current_news);
else if (_forced_news != 0) } else if (_forced_news != 0) {
ShowNewsMessage(_forced_news - 1); ShowNewsMessage(_forced_news - 1);
else { } else {
if (_total_news != MAX_NEWS) ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1);
ShowNewsMessage(_latest_news);
else
ShowNewsMessage(MAX_NEWS - 1);
} }
} }
@ -619,7 +613,6 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
DrawNewsString(82, y, 12, ni, w->width - 95); DrawNewsString(82, y, 12, ni, w->width - 95);
y += 12; y += 12;
} }
break; break;
} }
@ -630,8 +623,7 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
byte p, q; byte p, q;
#if 0 // === DEBUG code only #if 0 // === DEBUG code only
for (p = 0; p < _total_news; p++) for (p = 0; p < _total_news; p++) {
{
NewsItem *ni; NewsItem *ni;
byte buffer[256]; byte buffer[256];
ni = &_news_items[p]; ni = &_news_items[p];

View File

@ -851,25 +851,23 @@ int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
*/ */
bool CheckOrders(uint data_a, uint data_b) 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? */ /* Does the user wants us to check things? */
if (_patches.order_review_system == 0) if (_patches.order_review_system == 0) return false;
return false;
/* Do nothing for crashed vehicles */ /* Do nothing for crashed vehicles */
if(v->vehstatus & VS_CRASHED) if (v->vehstatus & VS_CRASHED) return false;
return false;
/* Do nothing for stopped vehicles if setting is '1' */ /* 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; return false;
/* do nothing we we're not the first vehicle in a share-chain */ /* do nothing we we're not the first vehicle in a share-chain */
if (v->next_shared != NULL) if (v->next_shared != NULL) return false;
return false;
/* Only check every 20 days, so that we don't flood the message log */ /* 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; int n_st, problem_type = -1;
const Order *order; const Order *order;
const Station *st; const Station *st;
@ -930,7 +928,7 @@ bool CheckOrders(uint data_a, uint data_b)
return true; 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);*/ /*DEBUG(misc, 3) ("Checkorder mode 0: Triggered News Item for %d", v->index);*/
SetDParam(0, v->unitnumber); SetDParam(0, v->unitnumber);

View File

@ -23,10 +23,7 @@ static int OrderGetSel(const Window* w)
const Vehicle* v = GetVehicle(w->window_number); const Vehicle* v = GetVehicle(w->window_number);
int num = WP(w,order_d).sel; int num = WP(w,order_d).sel;
if (num < 0 || num > v->num_orders) return (num >= 0 && num < v->num_orders) ? num : v->num_orders;
return v->num_orders;
return num;
} }
static StringID StationOrderStrings[] = { static StringID StationOrderStrings[] = {
@ -91,6 +88,7 @@ static void DrawOrdersWindow(Window *w)
switch (order->type) { switch (order->type) {
case OT_GOTO_STATION: case OT_GOTO_STATION:
break; break;
case OT_GOTO_DEPOT: case OT_GOTO_DEPOT:
SETBIT(w->disabled_state, 9); /* unload */ SETBIT(w->disabled_state, 9); /* unload */
SETBIT(w->disabled_state, 10); /* transfer */ SETBIT(w->disabled_state, 10); /* transfer */
@ -188,7 +186,6 @@ static void DrawOrdersWindow(Window *w)
static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile) static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
{ {
Order order; Order order;
Station *st;
int st_index; int st_index;
// check depot first // check depot first
@ -255,7 +252,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
} }
if (IsTileType(tile, MP_STATION)) { 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) { if (st->owner == _current_player || st->owner == OWNER_NONE) {
byte facil; byte facil;
@ -279,20 +276,18 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
return order; 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) if (u->type != v->type) return false;
return false;
if (u->type == VEH_Train && u->subtype != TS_Front_Engine) { if (u->type == VEH_Train && u->subtype != TS_Front_Engine) {
u = GetFirstVehicleInChain(u); u = GetFirstVehicleInChain(u);
if (u->subtype != TS_Front_Engine) if (u->subtype != TS_Front_Engine) return false;
return false;
} }
// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet // 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 // 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, 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))) { _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; return true;
} }
static void OrdersPlaceObj(Vehicle *v, TileIndex tile, Window *w) static void OrdersPlaceObj(const Vehicle* v, TileIndex tile, Window* w)
{ {
Order cmd; Order cmd;
Vehicle *u; const Vehicle* u;
// check if we're clicking on a vehicle first.. clone orders in that case. // check if we're clicking on a vehicle first.. clone orders in that case.
u = CheckMouseOverVehicle(); u = CheckMouseOverVehicle();
if (u && HandleOrderVehClick(v, u, w)) if (u != NULL && HandleOrderVehClick(v, u, w)) return;
return;
cmd = GetOrderCmdFromTile(v, tile); cmd = GetOrderCmdFromTile(v, tile);
if (cmd.type == OT_NOTHING) return; 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 (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) if (WP(w,order_d).sel != -1) WP(w,order_d).sel++;
WP(w,order_d).sel++;
ResetObjectToPlace(); ResetObjectToPlace();
} }
} }
static void OrderClick_Goto(Window *w, Vehicle *v) static void OrderClick_Goto(Window* w, const Vehicle* v)
{ {
InvalidateWidget(w, 7); InvalidateWidget(w, 7);
TOGGLEBIT(w->click_state, 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)); 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)); 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)); 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)); 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); 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)); 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_Skip,
OrderClick_Delete, OrderClick_Delete,
OrderClick_Nonstop, OrderClick_Nonstop,
@ -388,7 +381,7 @@ static const uint16 _order_keycodes[] = {
static void OrdersWndProc(Window *w, WindowEvent *e) static void OrdersWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: case WE_PAINT:
DrawOrdersWindow(w); DrawOrdersWindow(w);
break; break;
@ -502,7 +495,7 @@ static void OrdersWndProc(Window *w, WindowEvent *e)
// check if a vehicle in a depot was clicked.. // check if a vehicle in a depot was clicked..
case WE_MOUSELOOP: { case WE_MOUSELOOP: {
Vehicle *v = _place_clicked_vehicle; const Vehicle* v = _place_clicked_vehicle;
/* /*
* Check if we clicked on a vehicle * Check if we clicked on a vehicle
* and if the GOTO button of this window is pressed * and if the GOTO button of this window is pressed
@ -599,7 +592,7 @@ static const WindowDesc _other_orders_desc = {
OrdersWndProc OrdersWndProc
}; };
void ShowOrdersWindow(Vehicle *v) void ShowOrdersWindow(const Vehicle* v)
{ {
Window *w; Window *w;
VehicleID veh = v->index; VehicleID veh = v->index;
@ -610,9 +603,10 @@ void ShowOrdersWindow(Vehicle *v)
_alloc_wnd_parent_num = veh; _alloc_wnd_parent_num = veh;
if (v->owner != _local_player) { if (v->owner != _local_player) {
w = AllocateWindowDesc( &_other_orders_desc); w = AllocateWindowDesc(&_other_orders_desc);
} else } else {
w = AllocateWindowDesc( (v->type == VEH_Train) ? &_orders_train_desc : &_orders_desc); w = AllocateWindowDesc((v->type == VEH_Train) ? &_orders_train_desc : &_orders_desc);
}
if (w != NULL) { if (w != NULL) {
w->window_number = veh; w->window_number = veh;

View File

@ -228,8 +228,8 @@ static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_sti
int mode; int mode;
mode = (player != _local_player) * 2 + show_small; mode = (player != _local_player) * 2 + show_small;
w = AllocateWindowDescFront( desc_table[mode], player); w = AllocateWindowDescFront(desc_table[mode], player);
if (w) { if (w != NULL) {
w->caption_color = w->window_number; w->caption_color = w->window_number;
WP(w,def_d).data_1 = mode; WP(w,def_d).data_1 = mode;
if (show_stickied) { if (show_stickied) {
@ -484,28 +484,26 @@ static void DrawCompanyOwnerText(const Player *p)
{ {
const Player* p2; const Player* p2;
int num = -1; int num = -1;
int amt;
FOR_ALL_PLAYERS(p2) { FOR_ALL_PLAYERS(p2) {
if ((amt=GetAmountOwnedBy(p, p2->index)) != 0) { uint amt = GetAmountOwnedBy(p, p2->index);
if (amt != 0) {
num++; num++;
SetDParam(num*3+0, amt*25); SetDParam(num * 3 + 0, amt * 25);
SetDParam(num*3+1, p2->name_1); SetDParam(num * 3 + 1, p2->name_1);
SetDParam(num*3+2, p2->name_2); SetDParam(num * 3 + 2, p2->name_2);
if (num != 0) if (num != 0) break;
break;
} }
} }
if (num >= 0) if (num >= 0) DrawString(120, 124, STR_707D_OWNED_BY + num, 0);
DrawString(120, 124, STR_707D_OWNED_BY+num, 0);
} }
static void PlayerCompanyWndProc(Window *w, WindowEvent *e) static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
{ {
switch(e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
const Player* p = GetPlayer(w->window_number); const Player* p = GetPlayer(w->window_number);
uint32 dis = 0; uint32 dis = 0;
@ -562,10 +560,10 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
} break; } break;
case WE_CLICK: case WE_CLICK:
switch(e->click.widget) { switch (e->click.widget) {
case 3: { /* select face */ case 3: { /* select face */
Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number); Window *wf = AllocateWindowDescFront(&_select_player_face_desc, w->window_number);
if (wf) { if (wf != NULL) {
wf->caption_color = w->window_number; wf->caption_color = w->window_number;
WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face; WP(wf,facesel_d).face = GetPlayer(wf->window_number)->face;
WP(wf,facesel_d).gender = 0; WP(wf,facesel_d).gender = 0;
@ -574,15 +572,15 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
case 4: {/* change color */ case 4: {/* change color */
Window *wf = AllocateWindowDescFront(&_select_player_color_desc,w->window_number); Window *wf = AllocateWindowDescFront(&_select_player_color_desc,w->window_number);
if (wf) { if (wf != NULL) {
wf->caption_color = wf->window_number; wf->caption_color = wf->window_number;
wf->vscroll.cap = 8; wf->vscroll.cap = 8;
} }
} break; } break;
case 5: {/* change president name */ case 5: {/* change president name */
Player *p = GetPlayer(w->window_number); const Player* p = GetPlayer(w->window_number);
WP(w,def_d).byte_1 = 0; WP(w, def_d).byte_1 = 0;
SetDParam(0, p->president_name_2); SetDParam(0, p->president_name_2);
ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number); ShowQueryString(p->president_name_1, STR_700B_PRESIDENT_S_NAME, 31, 94, w->window_class, w->window_number);
} break; } break;
@ -649,8 +647,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT: {
char *b = e->edittext.str; char *b = e->edittext.str;
if (*b == 0 && WP(w,def_d).byte_1 != 2) // empty string is allowed for password // empty string is allowed for password
return; if (*b == '\0' && WP(w,def_d).byte_1 != 2) return;
_cmd_text = b; _cmd_text = b;
switch (WP(w,def_d).byte_1) { switch (WP(w,def_d).byte_1) {
@ -662,7 +660,7 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
break; break;
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
case 2: /* Change company password */ 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); NetworkChangeCompanyPassword(1, &b);
#endif #endif
} }
@ -673,8 +671,8 @@ static void PlayerCompanyWndProc(Window *w, WindowEvent *e)
static const WindowDesc _my_player_company_desc = { static const WindowDesc _my_player_company_desc = {
-1,-1, 360, 170, -1, -1, 360, 170,
WC_COMPANY,0, WC_COMPANY, 0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_my_player_company_widgets, _my_player_company_widgets,
PlayerCompanyWndProc PlayerCompanyWndProc

View File

@ -983,12 +983,10 @@ typedef int32 DoConvertRailProc(TileIndex tile, uint totype, bool exec);
static int32 DoConvertRail(TileIndex tile, uint totype, bool exec) static int32 DoConvertRail(TileIndex tile, uint totype, bool exec)
{ {
if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) if (!CheckTileOwnership(tile) || !EnsureNoVehicle(tile)) return CMD_ERROR;
return CMD_ERROR;
// tile is already of requested type? // tile is already of requested type?
if ( GetRailType(tile) == totype) if (GetRailType(tile) == totype) return CMD_ERROR;
return CMD_ERROR;
// change type. // change type.
if (exec) { 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 (x = sx; x <= ex; x += TILE_SIZE) {
for (y = sy; y <= ey; y += TILE_SIZE) { for (y = sy; y <= ey; y += TILE_SIZE) {
TileIndex tile = TileVirtXY(x, y); TileIndex tile = TileVirtXY(x, y);
DoConvertRailProc *proc; DoConvertRailProc* proc;
if (IsTileType(tile, MP_RAILWAY)) proc = DoConvertRail; switch (GetTileType(tile)) {
else if (IsTileType(tile, MP_STATION)) proc = DoConvertStationRail; case MP_RAILWAY: proc = DoConvertRail; break;
else if (IsTileType(tile, MP_STREET)) proc = DoConvertStreetRail; case MP_STATION: proc = DoConvertStationRail; break;
else if (IsTileType(tile, MP_TUNNELBRIDGE)) proc = DoConvertTunnelBridgeRail; case MP_STREET: proc = DoConvertStreetRail; break;
else continue; case MP_TUNNELBRIDGE: proc = DoConvertTunnelBridgeRail; break;
default: continue;
}
ret = proc(tile, p2, false); ret = proc(tile, p2, false);
if (CmdFailed(ret)) continue; if (CmdFailed(ret)) continue;
cost += ret; cost += ret;
if (flags & DC_EXEC) { 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); proc(tile, p2, true);
} }
} }
@ -1062,7 +1066,7 @@ static int32 RemoveTrainDepot(TileIndex tile, uint32 flags)
return CMD_ERROR; return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
int track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL))); Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL)));
DoDeleteDepot(tile); DoDeleteDepot(tile);
SetSignalsOnBothDir(tile, track); SetSignalsOnBothDir(tile, track);
@ -1349,15 +1353,13 @@ DetailedTrackProc * const _detailed_track_proc[16] = {
}; };
static void DrawSpecialBuilding(uint32 image, uint32 offset, static void DrawSpecialBuilding(uint32 image, uint32 offset,
TileInfo *ti, const TileInfo* ti,
byte x, byte y, byte z, byte x, byte y, byte z,
byte xsize, byte ysize, byte zsize) byte xsize, byte ysize, byte zsize)
{ {
if (image & PALETTE_MODIFIER_COLOR) if (image & PALETTE_MODIFIER_COLOR) image |= _drawtile_track_palette;
image |= _drawtile_track_palette;
image += offset; image += offset;
if (_display_opt & DO_TRANS_BUILDINGS) // show transparent depots if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
MAKE_TRANSPARENT(image);
AddSortableSpriteToDraw(image, ti->x + x, ti->y + y, xsize, ysize, zsize, ti->z + z); 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). */ * complains about it. If not, we'll remove this check. (Matthijs). */
assert(0); 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)) { if (IsRailWaypoint(m5) && HASBIT(_m[ti->tile].m3, 4)) {
// look for customization // 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) // (don't adjust for arctic depots, because snow in depots looks weird)
// type >= 4 means waypoints // type >= 4 means waypoints
if ((_m[ti->tile].m2 & RAIL_MAP2LO_GROUND_MASK) == RAIL_GROUND_ICE_DESERT && (_opt.landscape == LT_DESERT || type >= 4)) { 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 image += rti->snow_offset; // tile with tracks
else } else {
image = SPR_FLAT_SNOWY_TILE; // flat ground image = SPR_FLAT_SNOWY_TILE; // flat ground
}
} }
DrawGroundSprite(image); 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); if (pbs & TRACK_BIT_RIGHT) DrawGroundSprite(rti->base_sprites.single_e | PALETTE_CRASH);
} }
while ((image = drss->image) != 0) { for (; drss->image != 0; drss++) {
DrawSpecialBuilding(image, type < 4 ? rti->total_offset : 0, ti, DrawSpecialBuilding(drss->image, type < 4 ? rti->total_offset : 0, ti,
drss->subcoord_x, drss->subcoord_y, 0, drss->subcoord_x, drss->subcoord_y, 0,
drss->width, drss->height, 0x17); 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]; dtss = _track_depot_layout_table[image];
x+=33; x += 33;
y+=17; y += 17;
img = dtss++->image; img = dtss++->image;
/* @note This is kind of an ugly hack, as the PALETTE_MODIFIER_COLOR indicates /* @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; 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 true; // don't look further if the tile is a depot
}
} }
return false; return false;
} }
@ -1717,25 +1720,23 @@ typedef struct SignalVehicleCheckStruct {
static void *SignalVehicleCheckProc(Vehicle *v, void *data) static void *SignalVehicleCheckProc(Vehicle *v, void *data)
{ {
SignalVehicleCheckStruct *dest = data; const SignalVehicleCheckStruct* dest = data;
TileIndex tile; TileIndex tile;
if (v->type != VEH_Train) if (v->type != VEH_Train) return NULL;
return NULL;
/* Find the tile outside the tunnel, for signalling */ /* Find the tile outside the tunnel, for signalling */
if (v->u.rail.track == 0x40) if (v->u.rail.track == 0x40) {
tile = GetVehicleOutOfTunnelTile(v); tile = GetVehicleOutOfTunnelTile(v);
else } else {
tile = v->tile; tile = v->tile;
}
/* Wrong tile, or no train? Not a match */ /* Wrong tile, or no train? Not a match */
if (tile != dest->tile) if (tile != dest->tile) return NULL;
return NULL;
/* Are we on the same piece of track? */ /* Are we on the same piece of track? */
if (dest->track & (v->u.rail.track + (v->u.rail.track<<8))) if (dest->track & (v->u.rail.track + (v->u.rail.track << 8))) return v;
return v;
return NULL; 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 * 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. * 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 // It is a tunnel we're checking, we need to do some special stuff
// because VehicleFromPos will not find the vihicle otherwise // because VehicleFromPos will not find the vihicle otherwise
byte direction = GB(_m[tile].m5, 0, 2); byte direction = GB(_m[tile].m5, 0, 2);
@ -1838,14 +1839,14 @@ static void ChangeSignalStates(SetSignalsData *ssd)
// convert the block to pbs, if needed // 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 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]; TileIndex tile = ssd->pbs_tile[i];
SB(_m[tile].m4, 0, 3, SIGTYPE_PBS); SB(_m[tile].m4, 0, 3, SIGTYPE_PBS);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
}; };
// then mark the signals in the segment accordingly // 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]; TileIndex tile = ssd->tile[i];
byte bit = _signals_table[ssd->bit[i]]; byte bit = _signals_table[ssd->bit[i]];
uint16 m2 = _m[tile].m2; uint16 m2 = _m[tile].m2;
@ -1900,7 +1901,7 @@ bool UpdateSignalsOnSegment(TileIndex tile, byte direction)
int result = -1; int result = -1;
ssd.cur_stack = 0; ssd.cur_stack = 0;
direction>>=1; direction >>= 1;
for(;;) { for(;;) {
// go through one segment and update all signals pointing into that segment. // 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 * direction), we pretend them to be green. (So if
* signals are only one way, the other way will * signals are only one way, the other way will
* implicitely become `red' */ * implicitely become `red' */
if ((a & 0xC0) == 0) { b |= 0xC0; } if ((a & 0xC0) == 0) b |= 0xC0;
if ((a & 0x30) == 0) { b |= 0x30; } if ((a & 0x30) == 0) b |= 0x30;
if ( (b & 0x80) == 0) ret |= 0x10070000; if ( (b & 0x80) == 0) ret |= 0x10070000;
if ( (b & 0x40) == 0) ret |= 0x7100000; if ( (b & 0x40) == 0) ret |= 0x7100000;

View File

@ -460,7 +460,7 @@ do_clear:;
if (cost && (!_patches.build_on_slopes || _is_old_ai_player)) if (cost && (!_patches.build_on_slopes || _is_old_ai_player))
return CMD_ERROR; 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); cost += DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
} else { } else {
// Don't put the pieces that already exist // Don't put the pieces that already exist
@ -483,7 +483,7 @@ do_clear:;
SetTileOwner(tile, _current_player); SetTileOwner(tile, _current_player);
} }
_m[tile].m5 |= (byte)pieces; _m[tile].m5 |= pieces;
MarkTileDirtyByTile(tile); 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); ret = DoCommandByTile(tile, bits, 0, flags, CMD_BUILD_ROAD);
if (CmdFailed(ret)) { if (CmdFailed(ret)) {
if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR; if (_error_message != STR_1007_ALREADY_BUILT) return CMD_ERROR;
} else } else {
cost += ret; cost += ret;
}
if (tile == end_tile) break; if (tile == end_tile) break;
@ -642,24 +643,21 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tile = ti.tile; tile = ti.tile;
if (!EnsureNoVehicle(tile)) if (!EnsureNoVehicle(tile)) return CMD_ERROR;
return CMD_ERROR;
if ((ti.tileh != 0) && ( if (ti.tileh != 0 && (
!_patches.build_on_slopes || !_patches.build_on_slopes ||
IsSteepTileh(ti.tileh) || IsSteepTileh(ti.tileh) ||
!CanBuildDepotByTileh(p1, ti.tileh) !CanBuildDepotByTileh(p1, ti.tileh)
) )) {
) { return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
} }
cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); cost = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
if (CmdFailed(cost)) return CMD_ERROR; if (CmdFailed(cost)) return CMD_ERROR;
dep = AllocateDepot(); dep = AllocateDepot();
if (dep == NULL) if (dep == NULL) return CMD_ERROR;
return CMD_ERROR;
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (IsLocalPlayer()) _last_built_road_depot_tile = tile; if (IsLocalPlayer()) _last_built_road_depot_tile = tile;

View File

@ -300,7 +300,7 @@ static Depot *FindClosestRoadDepot(Vehicle *v)
TileIndex tile = v->tile; TileIndex tile = v->tile;
int i; 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) { if (_patches.new_pathfinding_all) {
NPFFoundTargetData ftd; NPFFoundTargetData ftd;
@ -1034,13 +1034,14 @@ static int RoadFindPathToDest(Vehicle *v, TileIndex tile, int enterdir)
} }
if (IsTileType(tile, MP_STREET)) { if (IsTileType(tile, MP_STREET)) {
if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner)) if (GB(_m[tile].m5, 4, 4) == 2 && IsTileOwner(tile, v->owner)) {
/* Road crossing */ /* Road depot */
bitmask |= _road_veh_fp_ax_or[_m[tile].m5&3]; bitmask |= _road_veh_fp_ax_or[GB(_m[tile].m5, 0, 2)];
}
} else if (IsTileType(tile, MP_STATION)) { } else if (IsTileType(tile, MP_STATION)) {
if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) { if (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, v->owner)) {
/* Our station */ /* Our station */
Station *st = GetStation(_m[tile].m2); const Station* st = GetStation(_m[tile].m2);
byte val = _m[tile].m5; byte val = _m[tile].m5;
if (v->cargo_type != CT_PASSENGERS) { if (v->cargo_type != CT_PASSENGERS) {
if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3)) if (IS_BYTE_INSIDE(val, 0x43, 0x47) && (_patches.roadveh_queue || st->truck_stops->status&3))

View File

@ -973,7 +973,7 @@ static void PlayerRoadVehWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */ 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; 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; id_v += w->vscroll.pos;

View File

@ -1219,7 +1219,7 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
case 3: { // select a grf file case 3: { // select a grf file
int y = (e->click.pt.y - NEWGRF_WND_PROC_OFFSET_TOP_WIDGET) / NEWGRF_WND_PROC_ROWSIZE; 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; y += w->vscroll.pos;

View File

@ -1077,7 +1077,7 @@ static void PlayerShipsWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */ 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; 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; id_v += w->vscroll.pos;

View File

@ -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); void ShowAircraftDepotWindow(TileIndex tile);
extern void UpdateAirplanesOnNewStation(Station *st); extern void UpdateAirplanesOnNewStation(Station *st);
static void MarkStationDirty(Station *st) static void MarkStationDirty(const Station* st)
{ {
if (st->sign.width_1 != 0) { if (st->sign.width_1 != 0) {
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1); InvalidateWindowWidget(WC_STATION_VIEW, st->index, 1);
@ -121,16 +121,16 @@ RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type)
uint GetNumRoadStops(const Station *st, RoadStopType type) uint GetNumRoadStops(const Station *st, RoadStopType type)
{ {
int num = 0; uint num = 0;
const RoadStop *rs; const RoadStop *rs;
assert(st != NULL); 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; return num;
} }
RoadStop *AllocateRoadStop( void ) RoadStop *AllocateRoadStop(void)
{ {
RoadStop *rs; RoadStop *rs;
@ -138,7 +138,7 @@ RoadStop *AllocateRoadStop( void )
if (!rs->used) { if (!rs->used) {
uint index = rs->index; uint index = rs->index;
memset(rs, 0, sizeof(RoadStop)); memset(rs, 0, sizeof(*rs));
rs->index = index; rs->index = index;
return rs; return rs;
@ -211,15 +211,9 @@ TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
case VEH_Ship: return st->dock_tile; case VEH_Ship: return st->dock_tile;
case VEH_Road: case VEH_Road:
if (v->cargo_type == CT_PASSENGERS) { if (v->cargo_type == CT_PASSENGERS) {
if (st->bus_stops != NULL) return (st->bus_stops != NULL) ? st->bus_stops->xy : 0;
return st->bus_stops->xy;
else
return 0;
} else { } else {
if (st->truck_stops != NULL) return (st->truck_stops != NULL) ? st->truck_stops->xy : 0;
return st->truck_stops->xy;
else
return 0;
} }
default: default:
assert(false); 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; _error_message = STR_306C_STATION_TOO_SPREAD_OUT;
return false; return false;
} }
@ -519,8 +513,8 @@ static uint GetAcceptanceMask(const Station *st)
static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg) static void ShowRejectOrAcceptNews(const Station *st, uint32 items, StringID msg)
{ {
if (items) { if (items) {
SetDParam(2, items >> 16); SetDParam(2, GB(items, 16, 16));
SetDParam(1, items & 0xFFFF); SetDParam(1, GB(items, 0, 16));
SetDParam(0, st->index); SetDParam(0, st->index);
AddNewsItem(msg + ((items >> 16)?1:0), NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_TILE, NT_ACCEPTANCE, 0), st->xy, 0); 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) // City Airport (large)
static const byte _airport_map5_tiles_town[] = { static const byte _airport_map5_tiles_town[] = {
31, 9, 33, 9, 9, 32, 31, 9, 33, 9, 9, 32,
27, 36, 29, 34, 8, 10, 27, 36, 29, 34, 8, 10,
30, 11, 35, 13, 20, 21, 30, 11, 35, 13, 20, 21,
51, 12, 14, 17, 19, 28, 51, 12, 14, 17, 19, 28,
38, 13, 15, 16, 18, 39, 38, 13, 15, 16, 18, 39,
@ -1655,23 +1649,23 @@ static const byte _airport_map5_tiles_town[] = {
// Metropolitain Airport (large) - 2 runways // Metropolitain Airport (large) - 2 runways
static const byte _airport_map5_tiles_metropolitan[] = { static const byte _airport_map5_tiles_metropolitan[] = {
31, 9, 33, 9, 9, 32, 31, 9, 33, 9, 9, 32,
27, 36, 29, 34, 8, 10, 27, 36, 29, 34, 8, 10,
30, 11, 35, 13, 20, 21, 30, 11, 35, 13, 20, 21,
102, 8, 8, 8, 8, 28, 102, 8, 8, 8, 8, 28,
83, 84, 84, 84, 84, 83, 83, 84, 84, 84, 84, 83,
26, 23, 23, 23, 23, 26 26, 23, 23, 23, 23, 26
}; };
// International Airport (large) - 2 runways // International Airport (large) - 2 runways
static const byte _airport_map5_tiles_international[] = { static const byte _airport_map5_tiles_international[] = {
88, 89, 89, 89, 89, 89, 88, 88, 89, 89, 89, 89, 89, 88,
51, 8, 8, 8, 8, 8, 32, 51, 8, 8, 8, 8, 8, 32,
30, 8, 11, 27, 11, 8, 10, 30, 8, 11, 27, 11, 8, 10,
32, 8, 11, 27, 11, 8, 114, 32, 8, 11, 27, 11, 8, 114,
87, 8, 11, 85, 11, 8, 114, 87, 8, 11, 85, 11, 8, 114,
87, 8, 8, 8, 8, 8, 90, 87, 8, 8, 8, 8, 8, 90,
26, 23, 23, 23, 23, 23, 26 26, 23, 23, 23, 23, 23, 26
}; };
// Heliport // Heliport
@ -1795,16 +1789,17 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
1. airport is upgraded 1. airport is upgraded
2. airport is added to existing station (unfortunately unavoideable) 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]; 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, ModifyTile(tile_cur,
MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5, MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
st->index, *b++); st->index, *b++);
END_TILE_LOOP(tile_cur,w,h,tile) } END_TILE_LOOP(tile_cur,w,h,tile)
} }
UpdateStationVirtCoordDirty(st); UpdateStationVirtCoordDirty(st);
@ -2227,10 +2222,7 @@ void StationPickerDrawSprite(int x, int y, RailType railtype, int image)
static uint GetSlopeZ_Station(const TileInfo* ti) static uint GetSlopeZ_Station(const TileInfo* ti)
{ {
uint z = ti->z; return (ti->tileh != 0) ? ti->z + 8 : ti->z;
if (ti->tileh != 0)
z += 8;
return z;
} }
static uint GetSlopeTileh_Station(const TileInfo *ti) static uint GetSlopeTileh_Station(const TileInfo *ti)
@ -2682,14 +2674,15 @@ void StationMonthlyLoop(void)
void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius) void ModifyStationRatingAround(TileIndex tile, PlayerID owner, int amount, uint radius)
{ {
Station *st; Station *st;
GoodsEntry *ge;
int i;
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (st->xy != 0 && st->owner == owner && if (st->xy != 0 && st->owner == owner &&
DistanceManhattan(tile, st->xy) <= radius) { DistanceManhattan(tile, st->xy) <= radius) {
ge = st->goods; uint i;
for(i=0; i!=NUM_CARGO; i++,ge++) {
for (i = 0; i != NUM_CARGO; i++) {
GoodsEntry* ge = &st->goods[i];
if (ge->enroute_from != INVALID_STATION) { if (ge->enroute_from != INVALID_STATION) {
ge->rating = clamp(ge->rating + amount, 0, 255); ge->rating = clamp(ge->rating + amount, 0, 255);
} }
@ -3191,7 +3184,7 @@ static void Load_STNS(void)
_station_tick_ctr = 0; _station_tick_ctr = 0;
} }
static void Save_ROADSTOP( void ) static void Save_ROADSTOP(void)
{ {
RoadStop *rs; RoadStop *rs;
@ -3203,7 +3196,7 @@ static void Save_ROADSTOP( void )
} }
} }
static void Load_ROADSTOP( void ) static void Load_ROADSTOP(void)
{ {
int index; int index;

View File

@ -264,7 +264,7 @@ void ShowPlayerStations(PlayerID player)
Window *w; Window *w;
w = AllocateWindowDescFront(&_player_stations_desc, player); w = AllocateWindowDescFront(&_player_stations_desc, player);
if (w) { if (w != NULL) {
w->caption_color = (byte)w->window_number; w->caption_color = (byte)w->window_number;
w->vscroll.cap = 12; w->vscroll.cap = 12;
w->resize.step_height = 10; w->resize.step_height = 10;
@ -500,13 +500,13 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
} }
break; break;
case WE_ON_EDIT_TEXT: { case WE_ON_EDIT_TEXT:
if (e->edittext.str[0] != '\0') { if (e->edittext.str[0] != '\0') {
_cmd_text = e->edittext.str; _cmd_text = e->edittext.str;
DoCommandP(0, w->window_number, 0, NULL, DoCommandP(0, w->window_number, 0, NULL,
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
} }
} break; break;
case WE_DESTROY: { case WE_DESTROY: {
WindowNumber wno = WindowNumber wno =
@ -535,7 +535,7 @@ void ShowStationViewWindow(StationID station)
Window *w; Window *w;
w = AllocateWindowDescFront(&_station_view_desc, station); w = AllocateWindowDescFront(&_station_view_desc, station);
if (w) { if (w != NULL) {
PlayerID owner = GetStation(w->window_number)->owner; PlayerID owner = GetStation(w->window_number)->owner;
if (owner != OWNER_NONE) w->caption_color = owner; if (owner != OWNER_NONE) w->caption_color = owner;
w->vscroll.cap = 5; w->vscroll.cap = 5;

View File

@ -261,7 +261,7 @@ static void MoveTextEffect(TextEffect *te)
if (te->duration < 8) { if (te->duration < 8) {
te->string_id = INVALID_STRING_ID; te->string_id = INVALID_STRING_ID;
} else { } else {
te->duration-=8; te->duration -= 8;
te->y--; te->y--;
te->bottom--; te->bottom--;
} }
@ -272,9 +272,8 @@ void MoveAllTextEffects(void)
{ {
TextEffect *te; TextEffect *te;
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) if (te->string_id != INVALID_STRING_ID) MoveTextEffect(te);
MoveTextEffect(te);
} }
} }
@ -282,7 +281,7 @@ void InitTextEffects(void)
{ {
TextEffect *te; 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; te->string_id = INVALID_STRING_ID;
} }
} }
@ -292,7 +291,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
TextEffect *te; TextEffect *te;
if (dpi->zoom < 1) { 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) if (te->string_id == INVALID_STRING_ID)
continue; continue;
@ -305,7 +304,7 @@ void DrawTextEffects(DrawPixelInfo *dpi)
AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2, 0); AddStringToDraw(te->x, te->y, te->string_id, te->params_1, te->params_2, 0);
} }
} else if (dpi->zoom == 1) { } 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) if (te->string_id == INVALID_STRING_ID)
continue; continue;
@ -323,12 +322,12 @@ void DrawTextEffects(DrawPixelInfo *dpi)
void DeleteAnimatedTile(TileIndex tile) 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) { if (tile == *ti) {
/* remove the hole */ /* 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 */ /* and clear last item */
endof(_animated_tile_list)[-1] = 0; endof(_animated_tile_list)[-1] = 0;
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
@ -339,9 +338,9 @@ void DeleteAnimatedTile(TileIndex tile)
bool AddAnimatedTile(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) { if (tile == *ti || *ti == 0) {
*ti = tile; *ti = tile;
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
@ -354,11 +353,10 @@ bool AddAnimatedTile(TileIndex tile)
void AnimateAnimatedTiles(void) void AnimateAnimatedTiles(void)
{ {
TileIndex *ti; const TileIndex* ti;
TileIndex tile;
for(ti=_animated_tile_list; ti!=endof(_animated_tile_list) && (tile=*ti) != 0; ti++) { for (ti = _animated_tile_list; ti != endof(_animated_tile_list) && *ti != 0; ti++) {
AnimateTile(tile); AnimateTile(*ti);
} }
} }
@ -371,8 +369,9 @@ static void SaveLoad_ANIT(void)
{ {
if (_sl_version < 6) { if (_sl_version < 6) {
SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_FILE_U16 | SLE_VAR_U32); 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); SlArray(_animated_tile_list, lengthof(_animated_tile_list), SLE_UINT32);
}
} }

8
tile.c
View File

@ -41,10 +41,10 @@ uint GetTileSlope(TileIndex tile, uint *h)
if (min >= d) min = d; if (min >= d) min = d;
r = 0; r = 0;
if ((a -= min) != 0) { r += (--a << 4) + 8; } if ((a -= min) != 0) r += (--a << 4) + 8;
if ((c -= min) != 0) { r += (--c << 4) + 4; } if ((c -= min) != 0) r += (--c << 4) + 4;
if ((d -= min) != 0) { r += (--d << 4) + 2; } if ((d -= min) != 0) r += (--d << 4) + 2;
if ((b -= min) != 0) { r += (--b << 4) + 1; } if ((b -= min) != 0) r += (--b << 4) + 1;
if (h != NULL) if (h != NULL)
*h = min * 8; *h = min * 8;

View File

@ -1657,9 +1657,7 @@ static void TownActionBuyRights(Town *t, int action)
static void TownActionBribe(Town *t, int action) static void TownActionBribe(Town *t, int action)
{ {
if (!RandomRange(15)) { if (!RandomRange(15)) {
GoodsEntry *ge;
Station *st; Station *st;
int i, rating;
// set as unwanted for 6 months // set as unwanted for 6 months
t->unwanted[_current_player] = 6; t->unwanted[_current_player] = 6;
@ -1667,8 +1665,9 @@ static void TownActionBribe(Town *t, int action)
// set all close by station ratings to 0 // set all close by station ratings to 0
FOR_ALL_STATIONS(st) { FOR_ALL_STATIONS(st) {
if (st->town == t && st->owner == _current_player) { if (st->town == t && st->owner == _current_player) {
for (i=0, ge = st->goods; i != NUM_CARGO; i++, ge++) uint i;
ge->rating = 0;
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 * ChangeTownRating is only for stuff in demolishing. Bribe failure should
* be independent of any cheat settings * be independent of any cheat settings
*/ */
rating = t->ratings[_current_player]; if (t->ratings[_current_player] > RATING_BRIBE_DOWN_TO) {
if (rating > -50)
t->ratings[_current_player] = RATING_BRIBE_DOWN_TO; t->ratings[_current_player] = RATING_BRIBE_DOWN_TO;
}
} else { } else {
ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM); ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM);
} }

View File

@ -455,7 +455,7 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
y += 10; y += 10;
i++; 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()); SetDParam(0, GetWorldPopulation());
DrawString(3, w->height - 12 + 2, STR_TOWN_POPULATION, 0); 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 */ case 5: { /* Click on Town Matrix */
uint16 id_v = (e->click.pt.y - 28) / 10; 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; 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]); Town *t = GetTown(_town_sort[id_v]);

View File

@ -1080,14 +1080,17 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
tmp = v->next; tmp = v->next;
if (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) { if (RailVehInfo(v->engine_type)->flags & RVI_MULTIHEAD) {
/* Always delete newly encountered front-engines */
if (IS_FIRSTHEAD_SPRITE(v->spritenum)) { if (IS_FIRSTHEAD_SPRITE(v->spritenum)) {
/* Always delete newly encountered front-engines */
enf_count--; enf_count--;
/* If we have more rear engines than front engines, then that means } else if (enr_count > enf_count) {
* that this rear-engine does not belong to any front-engine; delete */ /* More rear engines than front engines means this rear-engine does
} else if (enr_count > enf_count) { enr_count--;} * not belong to any front-engine; delete */
/* Otherwise leave it alone */ enr_count--;
else continue; } else {
/* Otherwise leave it alone */
continue;
}
} }
cost -= v->value; cost -= v->value;
@ -1180,8 +1183,8 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r)
Vehicle *a, *b; Vehicle *a, *b;
/* locate vehicles to swap */ /* locate vehicles to swap */
for(a=v; l!=0; l--) { a = a->next; } for (a = v; l != 0; l--) a = a->next;
for(b=v; r!=0; r--) { b = b->next; } for (b = v; r != 0; r--) b = b->next;
if (a != b) { if (a != b) {
/* swap the hidden bits */ /* swap the hidden bits */
@ -1586,7 +1589,7 @@ static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
return tfdd; 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) { if (_patches.new_pathfinding_all) {
NPFFoundTargetData ftd; 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[] = { static const SoundFx sfx[] = {
SND_04_TRAIN, 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.. // 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 && if (_patches.new_nonstop &&
v->current_order.station == _m[v->tile].m2 && IsTileType(v->tile, MP_STATION) ) { v->current_order.flags & OF_NON_STOP &&
IsTileType(v->tile, MP_STATION) &&
v->current_order.station == _m[v->tile].m2) {
v->cur_order_index++; v->cur_order_index++;
} }
@ -2456,9 +2461,10 @@ static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
} }
return return
IsTileOwner(tile, v->owner) && IsTileOwner(tile, v->owner) && (
(v->subtype != TS_Front_Engine || v->subtype != TS_Front_Engine ||
IsCompatibleRail(v->u.rail.railtype, GetRailType(tile))); IsCompatibleRail(v->u.rail.railtype, GetRailType(tile))
);
} }
typedef struct { typedef struct {
@ -2559,9 +2565,9 @@ static void SetVehicleCrashed(Vehicle *v)
InvalidateWindowWidget(WC_VEHICLE_VIEW, u->index, STATUS_BAR); 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) BEGIN_ENUM_WAGONS(v)
if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count; if (v->cargo_type == CT_PASSENGERS) num += v->cargo_count;
END_ENUM_WAGONS(v) END_ENUM_WAGONS(v)
@ -3046,8 +3052,7 @@ static void HandleBrokenTrain(Vehicle *v)
if (!(v->vehstatus & VS_HIDDEN)) { if (!(v->vehstatus & VS_HIDDEN)) {
Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE); Vehicle *u = CreateEffectVehicleRel(v, 4, 4, 5, EV_BREAKDOWN_SMOKE);
if (u) if (u != NULL) u->u.special.unk0 = v->breakdown_delay * 2;
u->u.special.unk0 = v->breakdown_delay * 2;
} }
} }

View File

@ -1461,7 +1461,7 @@ static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
case 7: { /* Matrix to show vehicles */ 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; 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; id_v += w->vscroll.pos;

View File

@ -1496,8 +1496,7 @@ int32 ReplaceVehicle(Vehicle *v)
/* Update limits of the vehicle (for when upgraded) */ /* Update limits of the vehicle (for when upgraded) */
switch (v->type) { switch (v->type) {
case VEH_Train: case VEH_Train: {
{
const RailVehicleInfo *rvi = RailVehInfo(new_engine_type); const RailVehicleInfo *rvi = RailVehInfo(new_engine_type);
const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type); const RailVehicleInfo *rvi2 = RailVehInfo(old_engine_type);
byte capacity = rvi2->capacity; 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 /* 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) 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*/ (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 // 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->spritenum++;
v->cargo_type = rvi->cargo_type; v->cargo_type = rvi->cargo_type;
@ -1561,9 +1560,9 @@ int32 ReplaceVehicle(Vehicle *v)
InvalidateWindowClasses(WC_TRAINS_LIST); InvalidateWindowClasses(WC_TRAINS_LIST);
UpdateTrainAcceleration(first); UpdateTrainAcceleration(first);
break; break;
} }
case VEH_Road:
{ case VEH_Road: {
const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type); const RoadVehicleInfo *rvi = RoadVehInfo(new_engine_type);
v->spritenum = rvi->image_index; v->spritenum = rvi->image_index;
@ -1572,9 +1571,9 @@ int32 ReplaceVehicle(Vehicle *v)
v->max_speed = rvi->max_speed; v->max_speed = rvi->max_speed;
InvalidateWindowClasses(WC_ROADVEH_LIST); InvalidateWindowClasses(WC_ROADVEH_LIST);
break; break;
} }
case VEH_Ship:
{ case VEH_Ship: {
const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type); const ShipVehicleInfo *svi = ShipVehInfo(new_engine_type);
v->spritenum = svi->image_index; 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 ); CmdRefitShip(v->x_pos, v->y_pos, DC_EXEC, v->index , cargo_type + 0x0100 );
InvalidateWindowClasses(WC_SHIPS_LIST); InvalidateWindowClasses(WC_SHIPS_LIST);
break; break;
} }
case VEH_Aircraft:
{ case VEH_Aircraft: {
const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type); const AircraftVehicleInfo *avi = AircraftVehInfo(new_engine_type);
Vehicle *u; Vehicle *u;
@ -1609,7 +1608,8 @@ int32 ReplaceVehicle(Vehicle *v)
} }
InvalidateWindowClasses(WC_AIRCRAFT_LIST); InvalidateWindowClasses(WC_AIRCRAFT_LIST);
break; break;
} }
default: return CMD_ERROR; default: return CMD_ERROR;
} }
// makes sure that the cargo is still valid compared to new capacity // makes sure that the cargo is still valid compared to new capacity
@ -2231,7 +2231,7 @@ static void Load_VEHS(void)
v = GetVehicle(index); v = GetVehicle(index);
SlObject(v, _veh_descs[SlReadByte()]); 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) if (_sl_version < 5 && v->last_station_visited == 0xFF)
v->last_station_visited = INVALID_STATION; v->last_station_visited = INVALID_STATION;

View File

@ -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])); free(vl->sort_list);
if (n!=0 && vl->sort_list == NULL) 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"); error("Could not allocate memory for the vehicle-sorting-list");
vl->list_length = n; vl->list_length = n;
for (i = 0; i < n; ++i) for (i = 0; i < n; ++i) vl->sort_list[i] = _vehicle_sort[i];
vl->sort_list[i] = _vehicle_sort[i];
vl->flags &= ~VL_REBUILD; vl->flags &= ~VL_REBUILD;
vl->flags |= VL_RESORT; 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) static int CDECL VehicleCargoSorter(const void *a, const void *b)
{ {
const Vehicle *va = GetVehicle((*(const SortStruct*)a).index); const Vehicle* va = GetVehicle(((const SortStruct*)a)->index);
const Vehicle *vb = GetVehicle((*(const SortStruct*)b).index); const Vehicle* vb = GetVehicle(((const SortStruct*)b)->index);
const Vehicle *v; const Vehicle* v;
AcceptedCargo cargoa;
AcceptedCargo cargob;
int r = 0; int r = 0;
int i; 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) memset(cargoa, 0, sizeof(cargoa));
_cargo_counta[v->cargo_type] += v->cargo_cap; 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) for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap;
_cargo_countb[v->cargo_type] += v->cargo_cap;
for (i = 0; i < NUM_CARGO; i++) { for (i = 0; i < NUM_CARGO; i++) {
r = _cargo_counta[i] - _cargo_countb[i]; r = cargoa[i] - cargob[i];
if (r != 0) if (r != 0) break;
break;
} }
VEHICLEUNITNUMBERSORTER(r, va, vb); VEHICLEUNITNUMBERSORTER(r, va, vb);
@ -1058,7 +1054,7 @@ void ShowReplaceVehicleWindow(byte vehicletype)
{ {
Window *w; Window *w;
DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype ); DeleteWindowById(WC_REPLACE_VEHICLE, vehicletype);
switch (vehicletype) { switch (vehicletype) {
case VEH_Train: case VEH_Train:
@ -1071,7 +1067,8 @@ void ShowReplaceVehicleWindow(byte vehicletype)
w->vscroll.cap = 8; w->vscroll.cap = 8;
w->resize.step_height = 14; w->resize.step_height = 14;
break; break;
case VEH_Ship: case VEH_Aircraft: case VEH_Ship:
case VEH_Aircraft:
w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype); w = AllocateWindowDescFront(&_replace_ship_aircraft_vehicle_desc, vehicletype);
w->vscroll.cap = 4; w->vscroll.cap = 4;
w->resize.step_height = 24; w->resize.step_height = 24;

View File

@ -324,14 +324,15 @@ static int32 ClearTile_Water(TileIndex tile, byte flags)
return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags); return RemoveShiplift(tile + ToTileIndexDiff(_shiplift_tomiddle_offs[m5 & 0xF]), flags);
} else { } else {
// ship depot // ship depot
if (flags & DC_AUTO) if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
if (m5 == 0x80 || m5 == 0x82) {} switch (m5) {
else if (m5 == 0x81) { tile -= TileDiffXY(1, 0); } case 0x80: break;
else if (m5 == 0x83) { tile -= TileDiffXY(0, 1); } case 0x81: tile -= TileDiffXY(1, 0); break;
else case 0x82: break;
return CMD_ERROR; case 0x83: tile -= TileDiffXY(0, 1); break;
default: return CMD_ERROR;
}
return RemoveShipDepot(tile,flags); return RemoveShipDepot(tile,flags);
} }
@ -580,7 +581,6 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
static void FloodVehicle(Vehicle *v) static void FloodVehicle(Vehicle *v)
{ {
Vehicle *u;
if (!(v->vehstatus & VS_CRASHED)) { if (!(v->vehstatus & VS_CRASHED)) {
uint16 pass = 0; uint16 pass = 0;
@ -592,9 +592,9 @@ static void FloodVehicle(Vehicle *v)
v->vehstatus |= VS_CRASHED; v->vehstatus |= VS_CRASHED;
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
RebuildVehicleLists(); RebuildVehicleLists();
} } else if (v->type == VEH_Train) {
Vehicle* u;
else if (v->type == VEH_Train) {
v = GetFirstVehicleInChain(v); v = GetFirstVehicleInChain(v);
u = v; u = v;
if (v->subtype == TS_Front_Engine) pass = 4; // driver if (v->subtype == TS_Front_Engine) pass = 4; // driver
@ -608,8 +608,9 @@ static void FloodVehicle(Vehicle *v)
v = u; v = u;
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
RebuildVehicleLists(); RebuildVehicleLists();
} else } else {
return; return;
}
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); 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), NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
v->index, v->index,
0); 0);
CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE); // show cool destruction effects CreateEffectVehicleRel(v, 4, 4, 8, EV_EXPLOSION_LARGE);
SndPlayVehicleFx(SND_12_EXPLOSION, v); // create sound SndPlayVehicleFx(SND_12_EXPLOSION, v);
} }
} }

View File

@ -214,11 +214,9 @@ void CallWindowEventNP(Window *w, int event)
w->wndproc(w, &e); w->wndproc(w, &e);
} }
void SetWindowDirty(Window *w) void SetWindowDirty(const Window* w)
{ {
if (w == NULL) if (w == NULL) return;
return;
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); 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; y -= vp->top;
//here allows scrolling in both x and y axis //here allows scrolling in both x and y axis
#define scrollspeed 3 #define scrollspeed 3
if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; } if (x - 15 < 0) {
else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; } WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; } } else if (15 - (vp->width - x) > 0) {
else if (15-(vp->height-y) > 0) { WP(w,vp_d).scrollpos_y += (15-(vp->height-y))*scrollspeed << vp->zoom; } 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 #undef scrollspeed
} }
} }
@ -1434,8 +1438,9 @@ static void MouseLoop(int click, int mousewheel)
_cursor.sprite != SPR_CURSOR_QUERY && _cursor.sprite != SPR_CURSOR_QUERY &&
_cursor.sprite != SPR_CURSOR_SIGN && _cursor.sprite != SPR_CURSOR_SIGN &&
_pause != 0 && _pause != 0 &&
!_cheats.build_in_pause.value) !_cheats.build_in_pause.value) {
return; return;
}
if (_thd.place_mode == 0) { if (_thd.place_mode == 0) {
HandleViewportClicked(vp, x, y); HandleViewportClicked(vp, x, y);

View File

@ -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 DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom);
void CallWindowEventNP(Window *w, int event); void CallWindowEventNP(Window *w, int event);
void CallWindowTickEvent(void); void CallWindowTickEvent(void);
void SetWindowDirty(Window *w); void SetWindowDirty(const Window* w);
void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam); void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam);
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam); void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam);