Changeset - r4077:259c4c4aacad
[Not reviewed]
master
! ! !
tron - 18 years ago 2006-06-27 21:25:53
tron@openttd.org
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
69 files changed with 774 insertions and 760 deletions:
0 comments (0 inline, 0 general)
ai/ai.c
Show inline comments
 
@@ -30,7 +30,6 @@ static void AI_DequeueCommands(PlayerID 
 
	while ((com = entry_com) != NULL) {
 
		_current_player = player;
 

	
 
		/* Copy the DP back in place */
 
		_cmd_text = com->text;
 
		DoCommandP(com->tile, com->p1, com->p2, com->callback, com->procc);
 

	
ai/trolly/build.c
Show inline comments
 
@@ -286,9 +286,9 @@ int AiNew_Build_Vehicle(Player *p, TileI
 
int AiNew_Build_Depot(Player* p, TileIndex tile, DiagDirection direction, byte flag)
 
{
 
	int ret, ret2;
 
	if (p->ainew.tbt == AI_TRAIN)
 
	if (p->ainew.tbt == AI_TRAIN) {
 
		return AI_DoCommand(tile, 0, direction, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_TRAIN_DEPOT);
 

	
 
	} else {
 
	ret = AI_DoCommand(tile, direction, 0, flag | DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD_DEPOT);
 
	if (CmdFailed(ret)) return ret;
 
	// Try to build the road from the depot
 
@@ -297,3 +297,4 @@ int AiNew_Build_Depot(Player* p, TileInd
 
	if (CmdFailed(ret2)) return ret;
 
	return ret + ret2;
 
}
 
}
ai/trolly/pathfinder.c
Show inline comments
 
@@ -425,16 +425,17 @@ static int32 AyStar_AiPathFinder_Calcula
 
					res += AI_PATHFINDER_FOUNDATION_PENALTY;
 
				}
 
			} else {
 
				if (!(IsRoad(parent->path.node.tile) && IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE))) {
 
				if (!IsRoad(parent->path.node.tile) || !IsTileType(parent->path.node.tile, MP_TUNNELBRIDGE)) {
 
					r = GetRoadFoundation(parent_tileh, AiNew_GetRoadDirection(parent->path.parent->node.tile, parent->path.node.tile, current->tile));
 
					if (r >= 15 || r == 0)
 
					if (r >= 15 || r == 0) {
 
						res += AI_PATHFINDER_TILE_GOES_UP_PENALTY;
 
					else
 
					} else {
 
						res += AI_PATHFINDER_FOUNDATION_PENALTY;
 
				}
 
			}
 
		}
 
	}
 
	}
 

	
 
	// Are we part of a tunnel?
 
	if ((AI_PATHFINDER_FLAG_TUNNEL & current->user_data[0]) != 0) {
ai/trolly/shared.c
Show inline comments
 
@@ -16,35 +16,20 @@ int AiNew_GetRailDirection(TileIndex til
 
	// 4 = dig down-left
 
	// 5 = dig up-right
 

	
 
	int x1, x2, x3;
 
	int y1, y2, y3;
 
	uint x1 = TileX(tile_a);
 
	uint x2 = TileX(tile_b);
 
	uint x3 = TileX(tile_c);
 

	
 
	x1 = TileX(tile_a);
 
	x2 = TileX(tile_b);
 
	x3 = TileX(tile_c);
 

	
 
	y1 = TileY(tile_a);
 
	y2 = TileY(tile_b);
 
	y3 = TileY(tile_c);
 
	uint y1 = TileY(tile_a);
 
	uint y2 = TileY(tile_b);
 
	uint y3 = TileY(tile_c);
 

	
 
	if (y1 == y2 && y2 == y3) return 0;
 
	if (x1 == x2 && x2 == x3) return 1;
 
	if (y2 > y1) {
 
		if (x2 > x3) return 2;
 
		else return 4;
 
	}
 
	if (x2 > x1) {
 
		if (y2 > y3) return 2;
 
		else return 5;
 
	}
 
	if (y1 > y2) {
 
		if (x2 > x3) return 5;
 
		else return 3;
 
	}
 
	if (x1 > x2) {
 
		if (y2 > y3) return 4;
 
		else return 3;
 
	}
 
	if (y2 > y1) return x2 > x3 ? 2 : 4;
 
	if (x2 > x1) return y2 > y3 ? 2 : 5;
 
	if (y1 > y2) return x2 > x3 ? 5 : 3;
 
	if (x1 > x2) return y2 > y3 ? 4 : 3;
 

	
 
	return 0;
 
}
 
@@ -87,10 +72,13 @@ DiagDirection AiNew_GetDirection(TileInd
 
	return DIAGDIR_NE;
 
}
 

	
 

	
 
// This functions looks up if this vehicle is special for this AI
 
//  and returns his flag
 
uint AiNew_GetSpecialVehicleFlag(Player *p, Vehicle *v) {
 
	int i;
 
uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
 
{
 
	uint i;
 

	
 
	for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
 
		if (p->ainew.special_vehicles[i].veh_id == v->index) {
 
			return p->ainew.special_vehicles[i].flag;
 
@@ -101,17 +89,23 @@ uint AiNew_GetSpecialVehicleFlag(Player 
 
	return 0;
 
}
 

	
 
bool AiNew_SetSpecialVehicleFlag(Player *p, Vehicle *v, uint flag) {
 
	int i, new_id = -1;
 

	
 
bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
 
{
 
	int new_id = -1;
 
	uint i;
 

	
 
	for (i=0;i<AI_MAX_SPECIAL_VEHICLES;i++) {
 
		if (p->ainew.special_vehicles[i].veh_id == v->index) {
 
			p->ainew.special_vehicles[i].flag |= flag;
 
			return true;
 
		}
 
		if (new_id == -1 && p->ainew.special_vehicles[i].veh_id == 0 &&
 
			p->ainew.special_vehicles[i].flag == 0)
 
		if (new_id == -1 &&
 
				p->ainew.special_vehicles[i].veh_id == 0 &&
 
				p->ainew.special_vehicles[i].flag == 0) {
 
			new_id = i;
 
	}
 
	}
 

	
 
	// Out of special_vehicle spots :s
 
	if (new_id == -1) {
ai/trolly/trolly.c
Show inline comments
 
@@ -1244,9 +1244,11 @@ static void AiNew_State_StartVehicle(Pla
 
// Repays money
 
static void AiNew_State_RepayMoney(Player *p)
 
{
 
	int i;
 
	for (i=0;i<AI_LOAN_REPAY;i++)
 
	uint i;
 

	
 
	for (i = 0; i < AI_LOAN_REPAY; i++) {
 
		AI_DoCommand(0, 0, 0, DC_EXEC, CMD_DECREASE_LOAN);
 
	}
 
	p->ainew.state = AI_STATE_ACTION_DONE;
 
}
 

	
aircraft_cmd.c
Show inline comments
 
@@ -1929,16 +1929,14 @@ static uint GetNumHelipads(const Airport
 

	
 
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
 
{
 
  Station *st;
 
  AirportFTA *temp;
 

	
 
	// if an airport doesn't have helipads, use terminals
 
	if (Airport->helipads == NULL) return AirportFindFreeTerminal(v, Airport);
 

	
 
	// if there are more helicoptergroups, pick one, just as in AirportFindFreeTerminal()
 
	if (Airport->helipads[0] > 1) {
 
		st = GetStation(v->u.air.targetairport);
 
		temp = Airport->layout[v->u.air.pos].next_in_chain;
 
		const Station* st = GetStation(v->u.air.targetairport);
 
		const AirportFTA* temp = Airport->layout[v->u.air.pos].next_in_chain;
 

	
 
		while (temp != NULL) {
 
			if (temp->heading == 255) {
 
				if (!HASBITS(st->airport_flags, temp->block)) {
aircraft_gui.c
Show inline comments
 
@@ -695,8 +695,7 @@ static int GetVehicleFromAircraftDepotWn
 

	
 
	row = (y - 14) / 24;
 
	ym = (y - 14) % 24;
 
	if (row >= w->vscroll.cap)
 
		return 1;
 
	if (row >= w->vscroll.cap) return 1;
 

	
 
	pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
 

	
 
@@ -811,14 +810,14 @@ static void AircraftDepotWndProc(Window 
 
		}
 
		break;
 

	
 
	case WE_PLACE_OBJ: {
 
	case WE_PLACE_OBJ:
 
		ClonePlaceObj(w);
 
	} break;
 
		break;
 

	
 
	case WE_ABORT_PLACE_OBJ: {
 
	case WE_ABORT_PLACE_OBJ:
 
		CLRBIT(w->click_state, 8);
 
		InvalidateWidget(w, 8);
 
	} break;
 
		break;
 

	
 
	// check if a vehicle in a depot was clicked..
 
	case WE_MOUSELOOP: {
 
@@ -924,7 +923,8 @@ void ShowAircraftDepotWindow(TileIndex t
 
	}
 
}
 

	
 
static void DrawSmallOrderList(const Vehicle *v, int x, int y) {
 
static void DrawSmallOrderList(const Vehicle* v, int x, int y)
 
{
 
	const Order *order;
 
	int sel, i = 0;
 

	
 
@@ -1068,14 +1068,12 @@ static void PlayerAircraftWndProc(Window
 

	
 
		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;
 
			const Vehicle* v;
 

	
 
			if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				Vehicle *v;
 

	
 
				if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
				v = GetVehicle(vl->sort_list[id_v].index);
 
@@ -1083,7 +1081,6 @@ static void PlayerAircraftWndProc(Window
 
				assert(v->type == VEH_Aircraft && v->subtype <= 2);
 

	
 
				ShowAircraftViewWindow(v);
 
			}
 
		} break;
 

	
 
		case 9: /* Build new Vehicle */
 
@@ -1092,9 +1089,7 @@ static void PlayerAircraftWndProc(Window
 
			break;
 

	
 
		case 10:
 
			if (!IsWindowOfPrototype(w, _player_aircraft_widgets))
 
				break;
 

	
 
			if (!IsWindowOfPrototype(w, _player_aircraft_widgets)) break;
 
			ShowReplaceVehicleWindow(VEH_Aircraft);
 
			break;
 

	
airport.c
Show inline comments
 
@@ -32,8 +32,9 @@ static void AirportFTAClass_Destructor(A
 
static uint16 AirportGetNofElements(const AirportFTAbuildup *FA);
 
static void AirportBuildAutomata(AirportFTAClass *Airport, const AirportFTAbuildup *FA);
 
static byte AirportTestFTA(const AirportFTAClass *Airport);
 
/*static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report);
 
static byte AirportBlockToString(uint32 block);*/
 
#if 0
 
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report);
 
#endif
 

	
 
void InitializeAirports(void)
 
{
 
@@ -272,7 +273,9 @@ static void AirportFTAClass_Constructor(
 
	// print out full information
 
	// true  -- full info including heading, block, etc
 
	// false -- short info, only position and next position
 
	//AirportPrintOut(Airport, false);
 
#if 0
 
	AirportPrintOut(Airport, false);
 
#endif
 
}
 

	
 
static void AirportFTAClass_Destructor(AirportFTAClass *Airport)
 
@@ -393,19 +396,34 @@ static const char* const _airport_headin
 
	"DUMMY"	// extra heading for 255
 
};
 

	
 

	
 
static uint AirportBlockToString(uint32 block)
 
{
 
	uint i = 0;
 
	if (block & 0xffff0000) { block >>= 16; i += 16; }
 
	if (block & 0x0000ff00) { block >>=  8; i +=  8; }
 
	if (block & 0x000000f0) { block >>=  4; i +=  4; }
 
	if (block & 0x0000000c) { block >>=  2; i +=  2; }
 
	if (block & 0x00000002) { i += 1; }
 
	return i;
 
}
 

	
 

	
 
static void AirportPrintOut(const AirportFTAClass *Airport, const bool full_report)
 
{
 
	AirportFTA *temp;
 
	uint16 i;
 
	byte heading;
 
	uint i;
 

	
 
	printf("(P = Current Position; NP = Next Position)\n");
 
	for (i = 0; i < Airport->nofelements; i++) {
 
		temp = &Airport->layout[i];
 
		const AirportFTA* temp = &Airport->layout[i];
 

	
 
		if (full_report) {
 
			heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
 
			printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
 
						 _airport_heading_strings[heading], AirportBlockToString(temp->block));
 
			printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n",
 
				temp->position, temp->next_position,
 
				_airport_heading_strings[heading], AirportBlockToString(temp->block)
 
			);
 
		} else {
 
			printf("P:%2d NP:%2d", temp->position, temp->next_position);
 
		}
 
@@ -413,8 +431,10 @@ static void AirportPrintOut(const Airpor
 
			temp = temp->next_in_chain;
 
			if (full_report) {
 
				heading = (temp->heading == 255) ? MAX_HEADINGS+1 : temp->heading;
 
				printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n", temp->position, temp->next_position,
 
							_airport_heading_strings[heading], AirportBlockToString(temp->block));
 
				printf("Pos:%2d NPos:%2d Heading:%15s Block:%2d\n",
 
					temp->position, temp->next_position,
 
					_airport_heading_strings[heading], AirportBlockToString(temp->block)
 
				);
 
			} else {
 
				printf("P:%2d NP:%2d", temp->position, temp->next_position);
 
			}
 
@@ -422,43 +442,25 @@ static void AirportPrintOut(const Airpor
 
		printf("\n");
 
	}
 
}
 

	
 

	
 
static byte AirportBlockToString(uint32 block)
 
{
 
	byte i = 0;
 
	if (block & 0xffff0000) { block >>= 16; i += 16; }
 
	if (block & 0x0000ff00) { block >>= 8;  i += 8; }
 
	if (block & 0x000000f0) { block >>= 4;  i += 4; }
 
	if (block & 0x0000000c) { block >>= 2;  i += 2; }
 
	if (block & 0x00000002) { i += 1; }
 
	return i;
 
}
 
#endif
 

	
 
const AirportFTAClass* GetAirport(const byte airport_type)
 
{
 
	AirportFTAClass *Airport = NULL;
 
	//FIXME -- AircraftNextAirportPos_and_Order -> Needs something nicer, don't like this code
 
	// needs constant change if more airports are added
 
	switch (airport_type) {
 
		case AT_SMALL:         Airport = CountryAirport; break;
 
		case AT_LARGE:         Airport = CityAirport; break;
 
		case AT_METROPOLITAN:  Airport = MetropolitanAirport; break;
 
		case AT_HELIPORT:      Airport = Heliport; break;
 
		case AT_OILRIG:        Airport = Oilrig; break;
 
		case AT_INTERNATIONAL: Airport = InternationalAirport; break;
 
		case AT_COMMUTER:      Airport = CommuterAirport; break;
 
		case AT_HELIDEPOT:     Airport = HeliDepot; break;
 
		case AT_INTERCON:      Airport = IntercontinentalAirport; break;
 
		case AT_HELISTATION:   Airport = HeliStation; break;
 
		default:
 
			#ifdef DEBUG__
 
				printf("Airport AircraftNextAirportPos_and_Order not yet implemented\n");
 
			#endif
 
			assert(airport_type <= AT_HELISTATION);
 
		default:               NOT_REACHED();
 
		case AT_SMALL:         return CountryAirport;
 
		case AT_LARGE:         return CityAirport;
 
		case AT_METROPOLITAN:  return MetropolitanAirport;
 
		case AT_HELIPORT:      return Heliport;
 
		case AT_OILRIG:        return Oilrig;
 
		case AT_INTERNATIONAL: return InternationalAirport;
 
		case AT_COMMUTER:      return CommuterAirport;
 
		case AT_HELIDEPOT:     return HeliDepot;
 
		case AT_INTERCON:      return IntercontinentalAirport;
 
		case AT_HELISTATION:   return HeliStation;
 
	}
 
	return Airport;
 
}
 

	
 
const AirportMovingData *GetAirportMovingData(byte airport_type, byte position)
airport_gui.c
Show inline comments
 
@@ -88,10 +88,9 @@ static void BuildAirToolbWndProc(Window 
 
		_place_proc(e->place.tile);
 
		break;
 

	
 
	case WE_PLACE_DRAG: {
 
	case WE_PLACE_DRAG:
 
		VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
 
		return;
 
	}
 
		break;
 

	
 
	case WE_PLACE_MOUSEUP:
 
		if (e->place.pt.x != -1) {
console.c
Show inline comments
 
@@ -109,31 +109,35 @@ static void IConsoleWndProc(Window* w, W
 
					SetWindowDirty(w);
 
					break;
 
				case WKC_SHIFT | WKC_PAGEUP:
 
					if (_iconsole_scroll - (w->height / ICON_LINE_HEIGHT) - 1 < 0)
 
					if (_iconsole_scroll - (w->height / ICON_LINE_HEIGHT) - 1 < 0) {
 
						_iconsole_scroll = 0;
 
					else
 
					} else {
 
						_iconsole_scroll -= (w->height / ICON_LINE_HEIGHT) - 1;
 
					}
 
					SetWindowDirty(w);
 
					break;
 
				case WKC_SHIFT | WKC_PAGEDOWN:
 
					if (_iconsole_scroll + (w->height / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER)
 
					if (_iconsole_scroll + (w->height / ICON_LINE_HEIGHT) - 1 > ICON_BUFFER) {
 
						_iconsole_scroll = ICON_BUFFER;
 
					else
 
					} else {
 
						_iconsole_scroll += (w->height / ICON_LINE_HEIGHT) - 1;
 
					}
 
					SetWindowDirty(w);
 
					break;
 
				case WKC_SHIFT | WKC_UP:
 
					if (_iconsole_scroll <= 0)
 
					if (_iconsole_scroll <= 0) {
 
						_iconsole_scroll = 0;
 
					else
 
					} else {
 
						--_iconsole_scroll;
 
					}
 
					SetWindowDirty(w);
 
					break;
 
				case WKC_SHIFT | WKC_DOWN:
 
					if (_iconsole_scroll >= ICON_BUFFER)
 
					if (_iconsole_scroll >= ICON_BUFFER) {
 
						_iconsole_scroll = ICON_BUFFER;
 
					else
 
					} else {
 
						++_iconsole_scroll;
 
					}
 
					SetWindowDirty(w);
 
					break;
 
				case WKC_BACKQUOTE:
 
@@ -182,8 +186,9 @@ static void IConsoleWndProc(Window* w, W
 
						InsertTextBufferChar(&_iconsole_cmdline, e->keypress.ascii);
 
						IConsoleResetHistoryPos();
 
						SetWindowDirty(w);
 
					} else
 
					} else {
 
						e->keypress.cont = true;
 
					}
 
			break;
 
		}
 
	}
 
@@ -594,8 +599,9 @@ void IConsoleVarHookAdd(const char *name
 
                                                                                    \
 
	if (item_before == NULL) {                                                        \
 
		_base = item_new;                                                               \
 
	} else                                                                            \
 
	} else {                                                                     \
 
		item_before->next = item_new;                                                   \
 
  }                                                                            \
 
                                                                                    \
 
	item_new->next = item;                                                            \
 
	/* END - Alphabetical insert */                                                   \
 
@@ -853,12 +859,12 @@ static void IConsoleVarSetValue(const IC
 
 * @param *var the variable in question
 
 * @param *value the new value
 
 */
 
static void IConsoleVarSetStringvalue(const IConsoleVar *var, char *value)
 
static void IConsoleVarSetStringvalue(const IConsoleVar* var, const char* value)
 
{
 
	if (var->type != ICONSOLE_VAR_STRING || var->addr == NULL) return;
 

	
 
	IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_PRE_ACTION);
 
	ttd_strlcpy((char*)var->addr, (char*)value, var->size);
 
	ttd_strlcpy(var->addr, value, var->size);
 
	IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_POST_ACTION);
 
	IConsoleVarPrintSetValue(var); // print out the new value, giving feedback
 
	return;
 
@@ -1098,9 +1104,11 @@ void IConsoleCmdExec(const char *cmdstr)
 

	
 
	if (_stdlib_con_developer) {
 
		uint i;
 
		for (i = 0; tokens[i] != NULL; i++)
 

	
 
		for (i = 0; tokens[i] != NULL; i++) {
 
			IConsolePrintF(_icolour_dbg, "condbg: token %d is: '%s'", i, tokens[i]);
 
	}
 
	}
 

	
 
	if (tokens[0] == '\0') return; // don't execute empty commands
 
	/* 2. Determine type of command (cmd, alias or variable) and execute
 
@@ -1113,7 +1121,9 @@ void IConsoleCmdExec(const char *cmdstr)
 
			IConsoleHookHandle(&cmd->hook, ICONSOLE_HOOK_PRE_ACTION);
 
			if (cmd->proc(t_index, tokens)) { // index started with 0
 
				IConsoleHookHandle(&cmd->hook, ICONSOLE_HOOK_POST_ACTION);
 
  		} else cmd->proc(0, NULL); // if command failed, give help
 
			} else {
 
				cmd->proc(0, NULL); // if command failed, give help
 
			}
 
		}
 
	 	return;
 
	 }
 
@@ -1127,9 +1137,9 @@ void IConsoleCmdExec(const char *cmdstr)
 

	
 
	 var = IConsoleVarGet(tokens[0]);
 
	 if (var != NULL) {
 
	 	if (IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_ACCESS))
 
		if (IConsoleHookHandle(&var->hook, ICONSOLE_HOOK_ACCESS)) {
 
	 		IConsoleVarExec(var, t_index, &tokens[1]);
 

	
 
		}
 
	 	return;
 
	 }
 

	
console_cmds.c
Show inline comments
 
@@ -191,8 +191,9 @@ DEF_CONSOLE_CMD(ConSave)
 

	
 
		if (SaveOrLoad(buf, SL_SAVE) != SL_OK) {
 
			IConsolePrint(_icolour_err, "SaveMap failed");
 
		} else
 
		} else {
 
			IConsolePrintF(_icolour_def, "Map sucessfully saved to %s", buf);
 
		}
 
		return true;
 
	}
 

	
 
@@ -247,8 +248,9 @@ DEF_CONSOLE_CMD(ConLoad)
 
			} break;
 
			default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file);
 
		}
 
	} else
 
	} else {
 
		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
 
	}
 

	
 
	FiosFreeSavegameList();
 
	return true;
 
@@ -272,8 +274,9 @@ DEF_CONSOLE_CMD(ConRemove)
 
	if (item != NULL) {
 
		if (!FiosDelete(item->name))
 
			IConsolePrintF(_icolour_err, "%s: Failed to delete file", file);
 
	} else
 
	} else {
 
		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
 
	}
 

	
 
	FiosFreeSavegameList();
 
	return true;
 
@@ -323,8 +326,9 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
 
				break;
 
			default: IConsolePrintF(_icolour_err, "%s: Not a directory.", file);
 
		}
 
	} else
 
	} else {
 
		IConsolePrintF(_icolour_err, "%s: No such file or directory.", file);
 
	}
 

	
 
	FiosFreeSavegameList();
 
	return true;
 
@@ -408,8 +412,9 @@ DEF_CONSOLE_CMD(ConBan)
 
		banip = inet_ntoa(*(struct in_addr *)&ci->client_ip);
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
 
		IConsolePrint(_icolour_def, "Client banned");
 
	} else
 
	} else {
 
		IConsolePrint(_icolour_def, "Client not online, banned IP");
 
	}
 

	
 
	/* Add user to ban-list */
 
	for (index = 0; index < lengthof(_network_ban_list); index++) {
 
@@ -481,8 +486,9 @@ DEF_CONSOLE_CMD(ConPauseGame)
 
	if (_pause == 0) {
 
		DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
		IConsolePrint(_icolour_def, "Game paused.");
 
	} else
 
	} else {
 
		IConsolePrint(_icolour_def, "Game is already paused.");
 
	}
 

	
 
	return true;
 
}
 
@@ -497,8 +503,9 @@ DEF_CONSOLE_CMD(ConUnPauseGame)
 
	if (_pause != 0) {
 
		DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
 
		IConsolePrint(_icolour_def, "Game unpaused.");
 
	} else
 
	} else {
 
		IConsolePrint(_icolour_def, "Game is already unpaused.");
 
	}
 

	
 
	return true;
 
}
 
@@ -519,8 +526,16 @@ DEF_CONSOLE_CMD(ConRcon)
 

	
 
DEF_CONSOLE_CMD(ConStatus)
 
{
 
	static const char *stat_str[] = {"inactive", "authorized", "waiting", "loading map", "map done", "ready", "active"};
 
	const char *status;
 
	static const char* const stat_str[] = {
 
		"inactive",
 
		"authorized",
 
		"waiting",
 
		"loading map",
 
		"map done",
 
		"ready",
 
		"active"
 
	};
 

	
 
	const NetworkClientState *cs;
 

	
 
	if (argc == 0) {
 
@@ -531,8 +546,9 @@ DEF_CONSOLE_CMD(ConStatus)
 
	FOR_ALL_CLIENTS(cs) {
 
		int lag = NetworkCalculateLag(cs);
 
		const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
 
		const char* status;
 

	
 
		status = (cs->status <= STATUS_ACTIVE) ? stat_str[cs->status] : "unknown";
 
		status = (cs->status <= lengthof(stat_str) ? stat_str[cs->status] : "unknown");
 
		IConsolePrintF(8, "Client #%1d  name: '%s'  status: '%s'  frame-lag: %3d  company: %1d  IP: %s  unique-id: '%s'",
 
			cs->index, ci->client_name, status, lag, ci->client_playas, GetPlayerIP(ci), ci->unique_id);
 
	}
 
@@ -558,7 +574,8 @@ DEF_CONSOLE_CMD(ConServerInfo)
 
	return true;
 
}
 

	
 
DEF_CONSOLE_HOOK(ConHookValidateMaxClientsCount) {
 
DEF_CONSOLE_HOOK(ConHookValidateMaxClientsCount)
 
{
 
	/* XXX - hardcoded, string limiation -- TrueLight
 
	 * XXX - also see network.c:NetworkStartup ~1356 */
 
	if (_network_game_info.clients_max > 10) {
 
@@ -569,7 +586,8 @@ DEF_CONSOLE_HOOK(ConHookValidateMaxClien
 
	return true;
 
}
 

	
 
DEF_CONSOLE_HOOK(ConHookValidateMaxCompaniesCount) {
 
DEF_CONSOLE_HOOK(ConHookValidateMaxCompaniesCount)
 
{
 
	if (_network_game_info.companies_max > MAX_PLAYERS) {
 
		_network_game_info.companies_max = MAX_PLAYERS;
 
		IConsoleError("Maximum companies out of bounds, truncating to limit.");
 
@@ -578,7 +596,8 @@ DEF_CONSOLE_HOOK(ConHookValidateMaxCompa
 
	return true;
 
}
 

	
 
DEF_CONSOLE_HOOK(ConHookValidateMaxSpectatorsCount) {
 
DEF_CONSOLE_HOOK(ConHookValidateMaxSpectatorsCount)
 
{
 
	/* XXX @see ConHookValidateMaxClientsCount */
 
	if (_network_game_info.spectators_max > 10) {
 
		_network_game_info.spectators_max = 10;
 
@@ -621,8 +640,9 @@ DEF_CONSOLE_CMD(ConKick)
 

	
 
	if (ci != NULL) {
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(NetworkFindClientStateFromIndex(index), NETWORK_ERROR_KICKED);
 
	} else
 
	} else {
 
		IConsoleError("Client not found");
 
	}
 

	
 
	return true;
 
}
 
@@ -974,7 +994,9 @@ DEF_CONSOLE_CMD(ConDebugLevel)
 

	
 
	if (argc == 1) {
 
		IConsolePrintF(_icolour_def, "Current debug-level: '%s'", GetDebugString());
 
	} else SetDebugString(argv[1]);
 
	} else {
 
		SetDebugString(argv[1]);
 
	}
 

	
 
	return true;
 
}
 
@@ -1126,8 +1148,9 @@ DEF_CONSOLE_CMD(ConSay)
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]);
 
	} else
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 
@@ -1176,8 +1199,9 @@ DEF_CONSOLE_CMD(ConSayPlayer)
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2]);
 
	} else
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_PLAYER, DESTTYPE_PLAYER, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 
@@ -1194,8 +1218,9 @@ DEF_CONSOLE_CMD(ConSayClient)
 

	
 
	if (!_network_server) {
 
		SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]);
 
	} else
 
	} else {
 
		NetworkServer_HandleChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], NETWORK_SERVER_INDEX);
 
	}
 

	
 
	return true;
 
}
 
@@ -1314,8 +1339,9 @@ DEF_CONSOLE_CMD(ConPatch)
 

	
 
	if (argc == 2) {
 
		IConsoleGetPatchSetting(argv[1]);
 
	} else
 
	} else {
 
		IConsoleSetPatchSetting(argv[1], argv[2]);
 
	}
 

	
 
	return true;
 
}
depot.c
Show inline comments
 
@@ -41,8 +41,7 @@ Depot *GetDepotByTile(TileIndex tile)
 
	Depot *depot;
 

	
 
	FOR_ALL_DEPOTS(depot) {
 
		if (depot->xy == tile)
 
			return depot;
 
		if (depot->xy == tile) return depot;
 
	}
 

	
 
	return NULL;
 
@@ -67,8 +66,7 @@ Depot *AllocateDepot(void)
 
	}
 

	
 
	/* Check if we can add a block to the pool */
 
	if (AddBlockToPool(&_depot_pool))
 
		return AllocateDepot();
 
	if (AddBlockToPool(&_depot_pool)) return AllocateDepot();
 

	
 
	return NULL;
 
}
depot.h
Show inline comments
 
@@ -90,20 +90,19 @@ static inline bool IsTileDepotType(TileI
 

	
 

	
 
/**
 
	Find out if the slope of the tile is suitable to build a depot of given direction
 
	@param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
 
	@param tileh The slope of the tile in question
 
	@return true if the construction is possible
 

	
 
 * Find out if the slope of the tile is suitable to build a depot of given direction
 
 * @param direction The direction in which the depot's exit points. Starts with 0 as NE and goes Clockwise
 
 * @param tileh The slope of the tile in question
 
 * @return true if the construction is possible
 

	
 
    This is checked by the ugly 0x4C >> direction magic, which does the following:
 
      0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
 
      So: for direction (only the significant bits are shown)<p>
 
      00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
 
      01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
 
      02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
 
      03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
 
      So ((0x4C >> p2) & tileh) determines whether the depot can be built on the current tileh
 
 * This is checked by the ugly 0x4C >> direction magic, which does the following:
 
 * 0x4C is 0100 1100 and tileh has only bits 0..3 set (steep tiles are ruled out)
 
 * So: for direction (only the significant bits are shown)<p>
 
 * 00 (exit towards NE) we need either bit 2 or 3 set in tileh: 0x4C >> 0 = 1100<p>
 
 * 01 (exit towards SE) we need either bit 1 or 2 set in tileh: 0x4C >> 1 = 0110<p>
 
 * 02 (exit towards SW) we need either bit 0 or 1 set in tileh: 0x4C >> 2 = 0011<p>
 
 * 03 (exit towards NW) we need either bit 0 or 4 set in tileh: 0x4C >> 3 = 1001<p>
 
 * So ((0x4C >> direction) & tileh) determines whether the depot can be built on the current tileh
 
*/
 
static inline bool CanBuildDepotByTileh(uint32 direction, Slope tileh)
 
{
disaster_cmd.c
Show inline comments
 
@@ -599,9 +599,10 @@ static void DisasterTick_4(Vehicle *v)
 
		} while (tile != tile_org);
 
		v->dest_tile = tile;
 
		v->age = 0;
 
	} else
 
	} else {
 
		return;
 
}
 
}
 

	
 
// The plane which will shoot down the UFO
 
static void DisasterTick_4b(Vehicle *v)
 
@@ -664,8 +665,7 @@ static void DisasterTick_5_and_6(Vehicle
 
		return;
 
	}
 

	
 
	if (!(v->tick_counter&1))
 
		return;
 
	if (!(v->tick_counter & 1)) return;
 

	
 
	tile = v->tile + TileOffsByDir(DirToDiagDir(v->direction));
 
	if (IsValidTile(tile) &&
 
@@ -715,11 +715,9 @@ static void Disaster0_Init(void)
 
	Station *st;
 
	int x;
 

	
 
	if (v == NULL)
 
		return;
 
	if (v == NULL) return;
 

	
 
	/* Pick a random place, unless we find
 
	    a small airport */
 
	/* Pick a random place, unless we find a small airport */
 
	x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
 

	
 
	FOR_ALL_STATIONS(st) {
 
@@ -747,8 +745,7 @@ static void Disaster1_Init(void)
 
	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
 
	int x;
 

	
 
	if (v == NULL)
 
		return;
 
	if (v == NULL) return;
 

	
 
	x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
 

	
 
@@ -781,12 +778,10 @@ static void Disaster2_Init(void)
 
		}
 
	}
 

	
 
	if (found == NULL)
 
		return;
 
	if (found == NULL) return;
 

	
 
	v = ForceAllocateSpecialVehicle();
 
	if (v == NULL)
 
		return;
 
	if (v == NULL) return;
 

	
 
	x = (MapSizeX() + 9) * TILE_SIZE - 1;
 
	y = TileY(found->xy) * TILE_SIZE + 37;
 
@@ -817,12 +812,10 @@ static void Disaster3_Init(void)
 
		}
 
	}
 

	
 
	if (found == NULL)
 
		return;
 
	if (found == NULL) return;
 

	
 
	v = ForceAllocateSpecialVehicle();
 
	if (v == NULL)
 
		return;
 
	if (v == NULL) return;
 

	
 
	x = -16 * TILE_SIZE;
 
	y = TileY(found->xy) * TILE_SIZE + 37;
economy.c
Show inline comments
 
@@ -102,8 +102,7 @@ int UpdateCompanyRatingAndValue(Player *
 
		uint num = 0;
 

	
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->owner != owner)
 
				continue;
 
			if (v->owner != owner) continue;
 
			if ((v->type == VEH_Train && IsFrontEngine(v)) ||
 
					 v->type == VEH_Road ||
 
					(v->type == VEH_Aircraft && v->subtype <= 2) ||
 
@@ -114,11 +113,12 @@ int UpdateCompanyRatingAndValue(Player *
 
					if (min_profit_first == true) {
 
						min_profit = v->profit_last_year;
 
						min_profit_first = false;
 
					} else if (min_profit > v->profit_last_year)
 
					} else if (min_profit > v->profit_last_year) {
 
						min_profit = v->profit_last_year;
 
				}
 
			}
 
		}
 
		}
 

	
 
		_score_part[owner][SCORE_VEHICLES] = num;
 
		/* Don't allow negative min_profit to show */
 
@@ -249,8 +249,7 @@ void ChangeOwnershipOfPlayerItems(Player
 

	
 
		for (s = _subsidies; s != endof(_subsidies); s++) {
 
			if (s->cargo_type != CT_INVALID && s->age >= 12) {
 
				if (GetStation(s->to)->owner == old_player)
 
					s->cargo_type = CT_INVALID;
 
				if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID;
 
			}
 
		}
 
	}
 
@@ -290,18 +289,10 @@ void ChangeOwnershipOfPlayerItems(Player
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->owner == new_player) {
 
				switch (v->type) {
 
					case VEH_Train:
 
						if (IsFrontEngine(v)) num_train++;
 
						break;
 
					case VEH_Road:
 
						num_road++;
 
						break;
 
					case VEH_Ship:
 
						num_ship++;
 
						break;
 
					case VEH_Aircraft:
 
						if (v->subtype <= 2) num_aircraft++;
 
						break;
 
					case VEH_Train:    if (IsFrontEngine(v)) num_train++; break;
 
					case VEH_Road:     num_road++; break;
 
					case VEH_Ship:     num_ship++; break;
 
					case VEH_Aircraft: if (v->subtype <= 2) num_aircraft++; break;
 
					default: break;
 
				}
 
			}
 
@@ -339,8 +330,7 @@ void ChangeOwnershipOfPlayerItems(Player
 
	if (new_player != OWNER_SPECTATOR) {
 
		Window *w;
 
		for (w = _windows; w != _last_window; w++) {
 
			if (w->caption_color == old_player)
 
				w->caption_color = new_player;
 
			if (w->caption_color == old_player) w->caption_color = new_player;
 
		}
 
	}
 

	
 
@@ -352,10 +342,11 @@ void ChangeOwnershipOfPlayerItems(Player
 
		FOR_ALL_PLAYERS(p) {
 
			for (i = 0; i < 4; i++) {
 
				/* 'Sell' the share if this player has any */
 
				if (p->share_owners[i] == _current_player)
 
				if (p->share_owners[i] == _current_player) {
 
					p->share_owners[i] = OWNER_SPECTATOR;
 
			}
 
		}
 
		}
 
		p = GetPlayer(_current_player);
 
		/* Sell all the shares that people have on this company */
 
		for (i = 0; i < 4; i++)
economy.h
Show inline comments
 
@@ -43,7 +43,7 @@ enum {
 

	
 
    NUM_SCORE = 10, // How many scores are there..
 

	
 
    SCORE_MAX = 1000, 	// The max score that can be in the performance history
 
	SCORE_MAX = 1000 // The max score that can be in the performance history
 
    					//  the scores together of score_info is allowed to be more!
 
};
 

	
elrail.c
Show inline comments
 
@@ -84,6 +84,7 @@ static TrackBits GetRailTrackBitsUnivers
 
					return 0;
 
			}
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			if (IsTunnel(t)) {
 
				if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
 
@@ -104,15 +105,18 @@ static TrackBits GetRailTrackBitsUnivers
 
					return DiagDirToAxis(GetBridgeRampDirection(t)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y;
 
				}
 
			}
 

	
 
		case MP_STREET:
 
			if (GetRoadTileType(t) != ROAD_TILE_CROSSING) return 0;
 
			if (GetRailTypeCrossing(t) != RAILTYPE_ELECTRIC) return 0;
 
			return GetCrossingRailBits(t);
 

	
 
		case MP_STATION:
 
			if (!IsRailwayStation(t)) return 0;
 
			if (GetRailType(t) != RAILTYPE_ELECTRIC) return 0;
 
			if (!IsStationTileElectrifiable(t)) return 0;
 
			return TrackToTrackBits(GetRailStationTrack(t));
 

	
 
		default:
 
			return 0;
 
	}
 
@@ -124,8 +128,11 @@ static TrackBits GetRailTrackBitsUnivers
 
  */
 
static void AdjustTileh(TileIndex tile, Slope* tileh)
 
{
 
	if (IsTunnelTile(tile)) *tileh = SLOPE_FLAT;
 
	if (IsBridgeTile(tile) && IsBridgeRamp(tile)) {
 
	if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
		if (IsTunnel(tile)) {
 
			*tileh = SLOPE_FLAT;
 
		} else {
 
			if (IsBridgeRamp(tile)) {
 
		if (*tileh != SLOPE_FLAT) {
 
			*tileh = SLOPE_FLAT;
 
		} else {
 
@@ -139,6 +146,8 @@ static void AdjustTileh(TileIndex tile, 
 
		}
 
	}
 
}
 
	}
 
}
 

	
 
/** Draws wires and, if required, pylons on a given tile
 
  * @param ti The Tileinfo to draw the tile for
 
@@ -251,6 +260,7 @@ static void DrawCatenaryRailway(const Ti
 
		if (PPPallowed[i] != 0 && HASBIT(PCPstatus, i) && !HASBIT(OverridePCP, i)) {
 
			for (k = 0; k < DIR_END; k++) {
 
				byte temp = PPPorder[i][GetTLG(ti->tile)][k];
 

	
 
				if (HASBIT(PPPallowed[i], temp)) {
 
					uint x  = ti->x + x_pcp_offsets[i] + x_ppp_offsets[temp];
 
					uint y  = ti->y + y_pcp_offsets[i] + y_ppp_offsets[temp];
fileio.c
Show inline comments
 
@@ -133,9 +133,9 @@ bool FiosCheckFileExists(const char *fil
 
	}
 
#endif
 

	
 
	if (f == NULL)
 
	if (f == NULL) {
 
		return false;
 
	else {
 
	} else {
 
		fclose(f);
 
		return true;
 
	}
intro_gui.c
Show inline comments
 
@@ -87,8 +87,9 @@ static void SelectGameWndProc(Window *w,
 
#ifdef ENABLE_NETWORK
 
			if (!_network_available) {
 
				ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
 
			} else
 
			} else {
 
				ShowNetworkGameWindow();
 
			}
 
#else
 
			ShowErrorMessage(INVALID_STRING_ID ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
 
#endif
main_gui.c
Show inline comments
 
@@ -90,10 +90,11 @@ void HandleOnEditText(WindowEvent *e)
 
		// Inform the player of this action
 
		snprintf(msg, sizeof(msg), "%d", money);
 

	
 
		if (!_network_server)
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);
 
		else
 
		} else {
 
			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX);
 
		}
 
		break;
 
	}
 
	case 4: /* Game-Password and Company-Password */
 
@@ -2273,7 +2274,8 @@ static WindowDesc _main_status_desc = {
 

	
 
extern void UpdateAllStationVirtCoord(void);
 

	
 
static void MainWindowWndProc(Window *w, WindowEvent *e) {
 
static void MainWindowWndProc(Window* w, WindowEvent* e)
 
{
 
	int off_x;
 

	
 
	switch (e->event) {
misc_cmd.c
Show inline comments
 
@@ -146,8 +146,9 @@ int32 CmdChangeCompanyName(TileIndex til
 
		DeleteName(p->name_1);
 
		p->name_1 = str;
 
		MarkWholeScreenDirty();
 
	} else
 
	} else {
 
		DeleteName(str);
 
	}
 

	
 
	return 0;
 
}
 
@@ -180,8 +181,9 @@ int32 CmdChangePresidentName(TileIndex t
 
			DoCommand(0, 0, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
 
		}
 
		MarkWholeScreenDirty();
 
	} else
 
	} else {
 
		DeleteName(str);
 
	}
 

	
 
	return 0;
 
}
 
@@ -269,8 +271,9 @@ int32 CmdChangeDifficultyLevel(TileIndex
 
		if (p1 != (uint32)-1L) {
 
			((int*)&_opt_ptr->diff)[p1] = p2;
 
			_opt_ptr->diff_level = 3; // custom difficulty level
 
		} else
 
		} else {
 
			_opt_ptr->diff_level = p2;
 
		}
 

	
 
		/* If we are a network-client, update the difficult setting (if it is open).
 
		 * Use this instead of just dirtying the window because we need to load in
misc_gui.c
Show inline comments
 
@@ -920,9 +920,10 @@ int HandleEditBoxKey(Window *w, querystr
 
		if (IsValidAsciiChar(we->keypress.ascii)) {
 
			if (InsertTextBufferChar(&string->text, we->keypress.ascii))
 
				InvalidateWidget(w, wid);
 
		} else // key wasn't caught
 
		} else { // key wasn't caught
 
			we->keypress.cont = true;
 
	}
 
	}
 

	
 
	return 0;
 
}
 
@@ -1507,8 +1508,7 @@ static void SelectScenarioWndProc(Window
 
	const int list_start = 45;
 

	
 
	switch (e->event) {
 
	case WE_PAINT:
 
	{
 
	case WE_PAINT: {
 
		int y,pos;
 
		const FiosItem *item;
 

	
 
@@ -1556,15 +1556,14 @@ static void SelectScenarioWndProc(Window
 
			break;
 

	
 
		case 6: /* Click the listbox */
 
			if (e->click.pt.y < list_start)
 
			if (e->click.pt.y < list_start) {
 
				GenRandomNewGame(Random(), InteractiveRandom());
 
			else {
 
				char *name;
 
			} else {
 
				int y = (e->click.pt.y - list_start) / 10;
 
				const char* name;
 
				const FiosItem *file;
 

	
 
				if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count)
 
					return;
 
				if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) return;
 

	
 
				file = _fios_list + y;
 

	
 
@@ -1578,8 +1577,6 @@ static void SelectScenarioWndProc(Window
 
			}
 
			break;
 
		}
 
	case WE_DESTROY:
 
		break;
 

	
 
	case WE_RESIZE: {
 
		/* Widget 3 and 4 have to go with halve speed, make it so obiwan */
music/qtmidi.h
Show inline comments
 
/*
 
 * qtmidi.h
 
 *
 
 * $Id$
 
 */
 
/* $Id$ */
 

	
 
#ifndef MUSIC_MACOSX_QUICKTIME_H
 
#define MUSIC_MACOSX_QUICKTIME_H
namegen.c
Show inline comments
 
@@ -279,11 +279,10 @@ static byte MakeFinnishTownName(char *bu
 
	// Select randomly if town name should consists of one or two parts.
 
	if (SeedChance(0, 15, seed) >= 10) {
 
		strcat(buf, name_finnish_real[SeedChance( 2, lengthof(name_finnish_real), seed)]);
 
	}
 
	} else if (SeedChance(0, 15, seed) >= 5) {
 
	// A two-part name by combining one of name_finnish_1 + "la"/"lä"
 
	// The reason for not having the contents of name_finnish_{1,2} in the same table is
 
	// that the ones in name_finnish_2 are not good for this purpose.
 
	else if (SeedChance(0, 15, seed) >= 5) {
 
		uint sel = SeedChance( 0, lengthof(name_finnish_1), seed);
 
		char *last;
 
		strcat(buf, name_finnish_1[sel]);
 
@@ -297,10 +296,9 @@ static byte MakeFinnishTownName(char *bu
 
		} else {
 
			strcat(buf, "lä");
 
		}
 
	}
 
	} else {
 
	// A two-part name by combining one of name_finnish_{1,2} + name_finnish_3.
 
	// Why aren't name_finnish_{1,2} just one table? See above.
 
	else {
 
		uint sel = SeedChance(2,
 
			lengthof(name_finnish_1) + lengthof(name_finnish_2), seed);
 
		if (sel >= lengthof(name_finnish_1)) {
 
@@ -424,10 +422,11 @@ static byte MakeCzechTownName(char *buf,
 
			// Always drop a postfix.
 
			postfix += lengthof(name_czech_subst_postfix);
 
		}
 
		if (postfix < lengthof(name_czech_subst_postfix))
 
		if (postfix < lengthof(name_czech_subst_postfix)) {
 
			choose |= CZC_POSTFIX;
 
		else
 
		} else {
 
			choose |= CZC_NOPOSTFIX;
 
		}
 

	
 
		// Localize the array segment containing a good gender
 
		for (ending = 0; ending < (int) lengthof(name_czech_subst_ending); ending++) {
network.c
Show inline comments
 
@@ -54,9 +54,9 @@ NetworkClientInfo *NetworkFindClientInfo
 
{
 
	NetworkClientInfo *ci;
 

	
 
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++)
 
		if (ci->client_index == client_index)
 
			return ci;
 
	for (ci = _network_client_info; ci != &_network_client_info[MAX_CLIENT_INFO]; ci++) {
 
		if (ci->client_index == client_index) return ci;
 
	}
 

	
 
	return NULL;
 
}
 
@@ -81,9 +81,9 @@ NetworkClientState *NetworkFindClientSta
 
{
 
	NetworkClientState *cs;
 

	
 
	for (cs = _clients; cs != &_clients[MAX_CLIENT_INFO]; cs++)
 
		if (cs->index == client_index)
 
			return cs;
 
	for (cs = _clients; cs != &_clients[MAX_CLIENT_INFO]; cs++) {
 
		if (cs->index == client_index) return cs;
 
	}
 

	
 
	return NULL;
 
}
 
@@ -93,11 +93,13 @@ NetworkClientState *NetworkFindClientSta
 
void NetworkGetClientName(char *client_name, size_t size, const NetworkClientState *cs)
 
{
 
	const NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
 
	if (*ci->client_name == '\0')
 

	
 
	if (ci->client_name[0] == '\0') {
 
		snprintf(client_name, size, "Client #%4d", cs->index);
 
	else
 
	} else {
 
		ttd_strlcpy(client_name, ci->client_name, size);
 
}
 
}
 

	
 
byte NetworkSpectatorCount(void)
 
{
 
@@ -218,7 +220,8 @@ static void ServerStartError(const char 
 
	NetworkError(STR_NETWORK_ERR_SERVER_START);
 
}
 

	
 
static void NetworkClientError(byte res, NetworkClientState *cs) {
 
static void NetworkClientError(byte res, NetworkClientState* cs)
 
{
 
	// First, send a CLIENT_ERROR to the server, so he knows we are
 
	//  disconnection (and why!)
 
	NetworkErrorCode errorno;
 
@@ -236,7 +239,7 @@ static void NetworkClientError(byte res,
 
	switch (res) {
 
		case NETWORK_RECV_STATUS_DESYNC: errorno = NETWORK_ERROR_DESYNC; break;
 
		case NETWORK_RECV_STATUS_SAVEGAME: errorno = NETWORK_ERROR_SAVEGAME_FAILED; break;
 
		default: errorno = NETWORK_ERROR_GENERAL;
 
		default:                           errorno = NETWORK_ERROR_GENERAL; break;
 
	}
 
	// This means we fucked up and the server closed the connection
 
	if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL &&
 
@@ -254,7 +257,7 @@ static void NetworkClientError(byte res,
 

	
 
/** Retrieve a string representation of an internal error number
 
 * @param buf buffer where the error message will be stored
 
 * @param err NetworkErrorCode (integer)
 
 * @param err NetworkErrorCode
 
 * @return returns a pointer to the error message (buf) */
 
char *GetNetworkErrorMsg(char *buf, NetworkErrorCode err)
 
{
 
@@ -274,7 +277,7 @@ char *GetNetworkErrorMsg(char *buf, Netw
 
		STR_NETWORK_ERR_CLIENT_PLAYER_MISMATCH,
 
		STR_NETWORK_ERR_CLIENT_KICKED,
 
		STR_NETWORK_ERR_CLIENT_CHEATER,
 
		STR_NETWORK_ERR_CLIENT_SERVER_FULL,
 
		STR_NETWORK_ERR_CLIENT_SERVER_FULL
 
	};
 

	
 
	if (err >= lengthof(network_error_strings)) err = 0;
 
@@ -992,10 +995,11 @@ static void NetworkInitGameInfo(void)
 
	memset(ci, 0, sizeof(*ci));
 

	
 
	ci->client_index = NETWORK_SERVER_INDEX;
 
	if (_network_dedicated)
 
	if (_network_dedicated) {
 
		ci->client_playas = OWNER_SPECTATOR;
 
	else
 
	} else {
 
		ci->client_playas = _local_player + 1;
 
	}
 
	ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
 
	ttd_strlcpy(ci->unique_id, _network_unique_id, sizeof(ci->unique_id));
 
}
 
@@ -1127,23 +1131,26 @@ static bool NetworkReceive(void)
 
	if (n == -1 && !_network_server) NetworkError(STR_NETWORK_ERR_LOSTCONNECTION);
 

	
 
	// accept clients..
 
	if (_network_server && FD_ISSET(_listensocket, &read_fd))
 
	if (_network_server && FD_ISSET(_listensocket, &read_fd)) {
 
		NetworkAcceptClients();
 
	}
 

	
 
	// read stuff from clients
 
	FOR_ALL_CLIENTS(cs) {
 
		cs->writable = !!FD_ISSET(cs->socket, &write_fd);
 
		if (FD_ISSET(cs->socket, &read_fd)) {
 
			if (_network_server)
 
			if (_network_server) {
 
				NetworkServer_ReadPackets(cs);
 
			else {
 
			} else {
 
				byte res;
 

	
 
				// The client already was quiting!
 
				if (cs->quited) return false;
 
				if ((res = NetworkClient_ReadPackets(cs)) != NETWORK_RECV_STATUS_OKAY) {
 

	
 
				res = NetworkClient_ReadPackets(cs);
 
				if (res != NETWORK_RECV_STATUS_OKAY) {
 
					// The client made an error of which we can not recover
 
					//   close the client and drop back to main menu
 

	
 
					NetworkClientError(res, cs);
 
					return false;
 
				}
 
@@ -1341,9 +1348,9 @@ void NetworkStartUp(void)
 
	 *  IMPORTANT NOTE: SocketBase needs to be initialized before we use _any_
 
	 *  network related function, else: crash.
 
	 */
 
	{
 
		DEBUG(misc,3) ("[NET][Core] Loading bsd socket library");
 
		if (!(SocketBase = OpenLibrary("bsdsocket.library", 4))) {
 
	SocketBase = OpenLibrary("bsdsocket.library", 4);
 
	if (SocketBase == NULL) {
 
			DEBUG(net, 0) ("[NET][Core] Error: couldn't open bsdsocket.library version 4. Network not available.");
 
			_network_available = false;
 
			return;
 
@@ -1351,10 +1358,13 @@ void NetworkStartUp(void)
 

	
 
		#if defined(__AMIGA__)
 
		// for usleep() implementation (only required for legacy AmigaOS builds)
 
		if ( (TimerPort = CreateMsgPort()) ) {
 
			if ( (TimerRequest = (struct timerequest *) CreateIORequest(TimerPort, sizeof(struct timerequest))) ) {
 
	TimerPort = CreateMsgPort();
 
	if (TimerPort != NULL) {
 
		TimerRequest = (struct timerequest*)CreateIORequest(TimerPort, sizeof(struct timerequest);
 
		if (TimerRequest != NULL) {
 
				if ( OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *) TimerRequest, 0) == 0 ) {
 
					if ( !(TimerBase = TimerRequest->tr_node.io_Device) ) {
 
				TimerBase = TimerRequest->tr_node.io_Device;
 
				if (TimerBase == NULL) {
 
						// free ressources...
 
						DEBUG(net, 0) ("[NET][Core] Error: couldn't initialize timer. Network not available.");
 
						_network_available = false;
 
@@ -1364,7 +1374,6 @@ void NetworkStartUp(void)
 
			}
 
		}
 
		#endif // __AMIGA__
 
	}
 
	#endif // __MORPHOS__ / __AMIGA__
 

	
 
    // Network is available
 
@@ -1413,24 +1422,18 @@ void NetworkShutDown(void)
 
	_network_available = false;
 

	
 
	#if defined(__MORPHOS__) || defined(__AMIGA__)
 
	{
 
		// free allocated ressources
 
		#if defined(__AMIGA__)
 
			if (TimerBase)    { CloseDevice((struct IORequest *) TimerRequest); }
 
			if (TimerRequest) { DeleteIORequest(TimerRequest); }
 
			if (TimerPort)    { DeleteMsgPort(TimerPort); }
 
	if (TimerBase    != NULL) CloseDevice((struct IORequest*)TimerRequest); // XXX This smells wrong
 
	if (TimerRequest != NULL) DeleteIORequest(TimerRequest);
 
	if (TimerPort    != NULL) DeleteMsgPort(TimerPort);
 
		#endif
 

	
 
		if (SocketBase) {
 
			CloseLibrary(SocketBase);
 
		}
 
	}
 
	if (SocketBase != NULL) CloseLibrary(SocketBase);
 
	#endif
 

	
 
	#if defined(WIN32)
 
	{
 
		WSACleanup();
 
	}
 
	#endif
 
}
 

	
network_data.c
Show inline comments
 
@@ -178,9 +178,10 @@ bool NetworkSend_Packets(NetworkClientSt
 
			cs->packet_queue = p->next;
 
			free(p);
 
			p = cs->packet_queue;
 
		} else
 
		} else {
 
			return true;
 
	}
 
	}
 

	
 
	return true;
 
}
 
@@ -192,8 +193,7 @@ bool NetworkSend_Packets(NetworkClientSt
 
uint8 NetworkRecv_uint8(NetworkClientState *cs, Packet *packet)
 
{
 
	/* Don't allow reading from a closed socket */
 
	if (cs->quited)
 
		return 0;
 
	if (cs->quited) return 0;
 

	
 
	/* Check if variable is within packet-size */
 
	if (packet->pos + 1 > packet->size) {
 
@@ -209,8 +209,7 @@ uint16 NetworkRecv_uint16(NetworkClientS
 
	uint16 n;
 

	
 
	/* Don't allow reading from a closed socket */
 
	if (cs->quited)
 
		return 0;
 
	if (cs->quited) return 0;
 

	
 
	/* Check if variable is within packet-size */
 
	if (packet->pos + 2 > packet->size) {
 
@@ -228,8 +227,7 @@ uint32 NetworkRecv_uint32(NetworkClientS
 
	uint32 n;
 

	
 
	/* Don't allow reading from a closed socket */
 
	if (cs->quited)
 
		return 0;
 
	if (cs->quited) return 0;
 

	
 
	/* Check if variable is within packet-size */
 
	if (packet->pos + 4 > packet->size) {
 
@@ -249,8 +247,7 @@ uint64 NetworkRecv_uint64(NetworkClientS
 
	uint64 n;
 

	
 
	/* Don't allow reading from a closed socket */
 
	if (cs->quited)
 
		return 0;
 
	if (cs->quited) return 0;
 

	
 
	/* Check if variable is within packet-size */
 
	if (packet->pos + 8 > packet->size) {
 
@@ -388,13 +385,13 @@ Packet *NetworkRecv_Packet(NetworkClient
 
// Add a command to the local command queue
 
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp)
 
{
 
	CommandPacket *new_cp = malloc(sizeof(CommandPacket));
 
	CommandPacket* new_cp = malloc(sizeof(*new_cp));
 

	
 
	*new_cp = *cp;
 

	
 
	if (cs->command_queue == NULL)
 
	if (cs->command_queue == NULL) {
 
		cs->command_queue = new_cp;
 
	else {
 
	} else {
 
		CommandPacket *c = cs->command_queue;
 
		while (c->next != NULL) c = c->next;
 
		c->next = new_cp;
 
@@ -443,9 +440,7 @@ void NetworkSend_Command(TileIndex tile,
 

	
 
		// And we queue it for delivery to the clients
 
		FOR_ALL_CLIENTS(cs) {
 
			if (cs->status > STATUS_AUTH) {
 
				NetworkAddCommandQueue(cs, c);
 
			}
 
			if (cs->status > STATUS_AUTH) NetworkAddCommandQueue(cs, c);
 
		}
 

	
 
		// Only the server gets the callback, because clients should not get them
network_gamelist.c
Show inline comments
 
@@ -6,7 +6,6 @@
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
//
 
// This file handles the GameList
 
// Also, it handles the request to a server for data about the server
 

	
 
@@ -33,8 +32,11 @@ NetworkGameList *NetworkGameListAddItem(
 
	item->ip = ip;
 
	item->port = port;
 

	
 
	if (prev_item == NULL) {_network_game_list = item;}
 
	else {prev_item->next = item;}
 
	if (prev_item == NULL) {
 
		_network_game_list = item;
 
	} else {
 
		prev_item->next = item;
 
	}
 
	DEBUG(net, 4) ("[NET][GameList] Added server to list");
 

	
 
	UpdateNetworkGameWindow(false);
 
@@ -51,8 +53,11 @@ void NetworkGameListRemoveItem(NetworkGa
 
	prev_item = NULL;
 
	for (item = _network_game_list; item != NULL; item = item->next) {
 
		if (remove == item) {
 
			if (prev_item == NULL) {_network_game_list = remove->next;}
 
			else {prev_item->next = remove->next;}
 
			if (prev_item == NULL) {
 
				_network_game_list = remove->next;
 
			} else {
 
				prev_item->next = remove->next;
 
			}
 

	
 
			free(remove);
 
			DEBUG(net, 4) ("[NET][GameList] Removed server from list");
network_gui.c
Show inline comments
 
@@ -628,8 +628,11 @@ static void NetworkStartServerWindowWndP
 
			if (item == nd->map || (pos == 0 && nd->map == NULL))
 
				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
 

	
 
			if (pos == 0) DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
 
			else DoDrawString(item->title, 14, y, _fios_colors[item->type] );
 
			if (pos == 0) {
 
				DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
 
			} else {
 
				DoDrawString(item->title, 14, y, _fios_colors[item->type] );
 
			}
 
			pos++;
 
			y += NSSWND_ROWSIZE;
 

	
 
@@ -1262,7 +1265,9 @@ static void ClientListPopupWndProc(Windo
 
			if (sel-- == 0) { // Selected item, highlight it
 
				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
 
				colour = 0xC;
 
			} else colour = 0x10;
 
			} else {
 
				colour = 0x10;
 
			}
 

	
 
			DoDrawString(_clientlist_action[i], 4, y, colour);
 
		}
 
@@ -1320,8 +1325,9 @@ static void ClientListWndProc(Window *w,
 
			if (_selected_clientlist_item == i++) { // Selected item, highlight it
 
				GfxFillRect(1, y, 248, y + CLNWND_ROWSIZE - 1, 0);
 
				colour = 0xC;
 
			} else
 
			} else {
 
				colour = 0x10;
 
			}
 

	
 
			if (ci->client_index == NETWORK_SERVER_INDEX) {
 
				DrawString(4, y, STR_NETWORK_SERVER, colour);
 
@@ -1362,8 +1368,9 @@ static void ClientListWndProc(Window *w,
 
		_selected_clientlist_y = e->mouseover.pt.y;
 
		if (e->mouseover.pt.y > CLNWND_OFFSET) {
 
			_selected_clientlist_item = (e->mouseover.pt.y - CLNWND_OFFSET) / CLNWND_ROWSIZE;
 
		} else
 
		} else {
 
			_selected_clientlist_item = 255;
 
		}
 

	
 
		// Repaint
 
		SetWindowDirty(w);
network_server.c
Show inline comments
 
@@ -84,8 +84,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_CO
 
	NetworkPopulateCompanyInfo();
 

	
 
	FOR_ALL_PLAYERS(player) {
 
		if (!player->is_active)
 
			continue;
 
		if (!player->is_active) continue;
 

	
 
		p = NetworkSend_Init(PACKET_SERVER_COMPANY_INFO);
 

	
 
@@ -107,16 +106,19 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_CO
 
			NetworkSend_uint8 (p, 0);
 
		}
 

	
 
		for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
 
		for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
 
			NetworkSend_uint16(p, _network_player_info[player->index].num_vehicle[i]);
 
		}
 

	
 
		for (i = 0; i < NETWORK_STATION_TYPES; i++)
 
		for (i = 0; i < NETWORK_STATION_TYPES; i++) {
 
			NetworkSend_uint16(p, _network_player_info[player->index].num_station[i]);
 
		}
 

	
 
		if (_network_player_info[player->index].players[0] == '\0')
 
		if (_network_player_info[player->index].players[0] == '\0') {
 
			NetworkSend_string(p, "<none>");
 
		else
 
		} else {
 
			NetworkSend_string(p, _network_player_info[player->index].players);
 
		}
 

	
 
		NetworkSend_Packet(p, cs);
 
	}
 
@@ -240,8 +242,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WA
 

	
 
	// Count how many players are waiting in the queue
 
	FOR_ALL_CLIENTS(new_cs) {
 
		if (new_cs->status == STATUS_MAP_WAIT)
 
			waiting++;
 
		if (new_cs->status == STATUS_MAP_WAIT) waiting++;
 
	}
 

	
 
	p = NetworkSend_Init(PACKET_SERVER_WAIT);
 
@@ -578,14 +579,12 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
#if defined(WITH_REV) || defined(WITH_REV_HACK)
 
	// Check if the client has revision control enabled
 
	if (strcmp(NOREV_STRING, client_revision) != 0) {
 
		if (strcmp(_network_game_info.server_revision, client_revision) != 0) {
 
	if (strcmp(NOREV_STRING, client_revision) != 0 &&
 
			strcmp(_network_game_info.server_revision, client_revision) != 0) {
 
			// Different revisions!!
 
			SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_REVISION);
 

	
 
			return;
 
		}
 
	}
 
#endif
 

	
 
	NetworkRecv_string(cs, p, name, sizeof(name));
 
@@ -629,21 +628,21 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
	// We now want a password from the client
 
	//  else we do not allow him in!
 
	if (_network_game_info.use_password)
 
	if (_network_game_info.use_password) {
 
		SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD);
 
	else {
 
	} else {
 
		if (ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS && _network_player_info[ci->client_playas - 1].password[0] != '\0') {
 
			SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
 
		}
 
		else {
 
		} else {
 
			SEND_COMMAND(PACKET_SERVER_WELCOME)(cs);
 
		}
 
	}
 

	
 
	/* Make sure companies to who people try to join are not autocleaned */
 
	if (playas >= 1 && playas <= MAX_PLAYERS)
 
	if (playas >= 1 && playas <= MAX_PLAYERS) {
 
		_network_player_info[playas-1].months_empty = 0;
 
}
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
 
{
 
@@ -1113,8 +1112,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	char pass[NETWORK_PASSWORD_LENGTH];
 
	char command[NETWORK_RCONCOMMAND_LENGTH];
 

	
 
	if (_network_game_info.rcon_password[0] == '\0')
 
		return;
 
	if (_network_game_info.rcon_password[0] == '\0') return;
 

	
 
	NetworkRecv_string(cs, p, pass, sizeof(pass));
 
	NetworkRecv_string(cs, p, command, sizeof(command));
 
@@ -1209,13 +1207,16 @@ void NetworkPopulateCompanyInfo(void)
 
		GetString(_network_player_info[p->index].company_name, STR_JUST_STRING);
 

	
 
		// Check the income
 
		if (_cur_year - 1 == p->inaugurated_year)
 
		if (_cur_year - 1 == p->inaugurated_year) {
 
			// The player is here just 1 year, so display [2], else display[1]
 
			for (i = 0; i < 13; i++)
 
			for (i = 0; i < 13; i++) {
 
				_network_player_info[p->index].income -= p->yearly_expenses[2][i];
 
		else
 
			for (i = 0; i < 13; i++)
 
			}
 
		} else {
 
			for (i = 0; i < 13; i++) {
 
				_network_player_info[p->index].income -= p->yearly_expenses[1][i];
 
			}
 
		}
 

	
 
		// Set some general stuff
 
		_network_player_info[p->index].inaugurated_year = p->inaugurated_year;
 
@@ -1226,25 +1227,32 @@ void NetworkPopulateCompanyInfo(void)
 

	
 
	// Go through all vehicles and count the type of vehicles
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->owner < MAX_PLAYERS)
 
		if (v->owner >= MAX_PLAYERS) continue;
 
			switch (v->type) {
 
				case VEH_Train:
 
					if (IsFrontEngine(v))
 
				if (IsFrontEngine(v)) {
 
						_network_player_info[v->owner].num_vehicle[0]++;
 
				}
 
					break;
 

	
 
				case VEH_Road:
 
					if (v->cargo_type != CT_PASSENGERS)
 
				if (v->cargo_type != CT_PASSENGERS) {
 
						_network_player_info[v->owner].num_vehicle[1]++;
 
					else
 
				} else {
 
						_network_player_info[v->owner].num_vehicle[2]++;
 
				}
 
					break;
 

	
 
				case VEH_Aircraft:
 
					if (v->subtype <= 2)
 
				if (v->subtype <= 2) {
 
						_network_player_info[v->owner].num_vehicle[3]++;
 
				}
 
					break;
 

	
 
				case VEH_Ship:
 
					_network_player_info[v->owner].num_vehicle[4]++;
 
					break;
 

	
 
				case VEH_Special:
 
				case VEH_Disaster:
 
					break;
 
@@ -1254,16 +1262,13 @@ void NetworkPopulateCompanyInfo(void)
 
	// Go through all stations and count the types of stations
 
	FOR_ALL_STATIONS(s) {
 
		if (s->owner < MAX_PLAYERS) {
 
			if ((s->facilities & FACIL_TRAIN))
 
				_network_player_info[s->owner].num_station[0]++;
 
			if ((s->facilities & FACIL_TRUCK_STOP))
 
				_network_player_info[s->owner].num_station[1]++;
 
			if ((s->facilities & FACIL_BUS_STOP))
 
				_network_player_info[s->owner].num_station[2]++;
 
			if ((s->facilities & FACIL_AIRPORT))
 
				_network_player_info[s->owner].num_station[3]++;
 
			if ((s->facilities & FACIL_DOCK))
 
				_network_player_info[s->owner].num_station[4]++;
 
			NetworkPlayerInfo* npi = &_network_player_info[s->owner];
 

	
 
			if (s->facilities & FACIL_TRAIN)      npi->num_station[0]++;
 
			if (s->facilities & FACIL_TRUCK_STOP) npi->num_station[1]++;
 
			if (s->facilities & FACIL_BUS_STOP)   npi->num_station[2]++;
 
			if (s->facilities & FACIL_AIRPORT)    npi->num_station[3]++;
 
			if (s->facilities & FACIL_DOCK)       npi->num_station[4]++;
 
		}
 
	}
 

	
 
@@ -1295,8 +1300,7 @@ void NetworkUpdateClientInfo(uint16 clie
 

	
 
	ci = NetworkFindClientInfoFromIndex(client_index);
 

	
 
	if (ci == NULL)
 
		return;
 
	if (ci == NULL) return;
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci);
 
@@ -1330,8 +1334,7 @@ static void NetworkAutoCleanCompanies(vo
 
	Player *p;
 
	bool clients_in_company[MAX_PLAYERS];
 

	
 
	if (!_network_autoclean_companies)
 
		return;
 
	if (!_network_autoclean_companies) return;
 

	
 
	memset(clients_in_company, 0, sizeof(clients_in_company));
 

	
 
@@ -1352,8 +1355,7 @@ static void NetworkAutoCleanCompanies(vo
 
	/* Go through all the comapnies */
 
	FOR_ALL_PLAYERS(p) {
 
		/* Skip the non-active once */
 
		if (!p->is_active || p->is_ai)
 
			continue;
 
		if (!p->is_active || p->is_ai) continue;
 

	
 
		if (!clients_in_company[p->index]) {
 
			/* The company is empty for one month more */
 
@@ -1430,10 +1432,11 @@ bool NetworkServer_ReadPackets(NetworkCl
 
	NetworkRecvStatus res;
 
	while ((p = NetworkRecv_Packet(cs, &res)) != NULL) {
 
		byte type = NetworkRecv_uint8(cs, p);
 
		if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->quited)
 
		if (type < PACKET_END && _network_server_packet[type] != NULL && !cs->quited) {
 
			_network_server_packet[type](cs, p);
 
		else
 
		} else {
 
			DEBUG(net, 0)("[NET][Server] Received invalid packet type %d", type);
 
		}
 
		free(p);
 
	}
 

	
network_udp.c
Show inline comments
 
@@ -141,10 +141,9 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVE
 
				snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr));
 

	
 
			/* Check if we are allowed on this server based on the revision-match */
 
			item->info.compatible = (
 
			item->info.compatible =
 
			strcmp(item->info.server_revision, _openttd_revision) == 0 ||
 
			strcmp(item->info.server_revision, NOREV_STRING) == 0) ? true : false;
 

	
 
				strcmp(item->info.server_revision, NOREV_STRING) == 0;
 
			break;
 
	}
 

	
 
@@ -163,8 +162,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	int i;
 

	
 
	// Just a fail-safe.. should never happen
 
	if (!_network_udp_server)
 
		return;
 
	if (!_network_udp_server) return;
 

	
 
	packet = NetworkSend_Init(PACKET_UDP_SERVER_DETAIL_INFO);
 

	
 
@@ -178,8 +176,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	/* Go through all the players */
 
	FOR_ALL_PLAYERS(player) {
 
		/* Skip non-active players */
 
		if (!player->is_active)
 
			continue;
 
		if (!player->is_active) continue;
 

	
 
		current++;
 

	
 
@@ -209,7 +206,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
		/* Find the clients that are connected to this player */
 
		FOR_ALL_CLIENTS(cs) {
 
			ci = DEREF_CLIENT_INFO(cs);
 
			if ((ci->client_playas - 1) == player->index) {
 
			if (ci->client_playas - 1 == player->index) {
 
				/* The uint8 == 1 indicates that a client is following */
 
				NetworkSend_uint8(packet, 1);
 
				NetworkSend_string(packet, ci->client_name);
 
@@ -219,7 +216,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
		}
 
		/* Also check for the server itself */
 
		ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
		if ((ci->client_playas - 1) == player->index) {
 
		if (ci->client_playas - 1 == player->index) {
 
			/* The uint8 == 1 indicates that a client is following */
 
			NetworkSend_uint8(packet, 1);
 
			NetworkSend_string(packet, ci->client_name);
 
@@ -234,7 +231,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	/* And check if we have any spectators */
 
	FOR_ALL_CLIENTS(cs) {
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if ((ci->client_playas - 1) > MAX_PLAYERS) {
 
		if (ci->client_playas - 1 > MAX_PLAYERS) {
 
			/* The uint8 == 1 indicates that a client is following */
 
			NetworkSend_uint8(packet, 1);
 
			NetworkSend_string(packet, ci->client_name);
 
@@ -244,7 +241,7 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	}
 
	/* Also check for the server itself */
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
	if ((ci->client_playas - 1) > MAX_PLAYERS) {
 
	if (ci->client_playas - 1 > MAX_PLAYERS) {
 
		/* The uint8 == 1 indicates that a client is following */
 
		NetworkSend_uint8(packet, 1);
 
		NetworkSend_string(packet, ci->client_name);
 
@@ -260,7 +257,8 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
 
	free(packet);
 
}
 

	
 
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST) {
 
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST)
 
{
 
	int i;
 
	struct in_addr ip;
 
	uint16 port;
 
@@ -286,14 +284,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTE
 
	}
 
}
 

	
 
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER) {
 
DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER)
 
{
 
	_network_advertise_retries = 0;
 
	DEBUG(net, 2)("[NET][UDP] We are advertised on the master-server!");
 

	
 
	if (!_network_advertise)
 
	if (!_network_advertise) {
 
		/* We are advertised, but we don't want to! */
 
		NetworkUDPRemoveAdvertise();
 
}
 
}
 

	
 

	
 
// The layout for the receive-functions by UDP
 
@@ -440,8 +440,7 @@ void NetworkUDPReceive(SOCKET udp)
 
	int packet_len;
 

	
 
	// If p is NULL, malloc him.. this prevents unneeded mallocs
 
	if (p == NULL)
 
		p = malloc(sizeof(Packet));
 
	if (p == NULL) p = malloc(sizeof(*p));
 

	
 
	packet_len = sizeof(p->buffer);
 
	client_len = sizeof(client_addr);
 
@@ -470,15 +469,12 @@ void NetworkUDPReceive(SOCKET udp)
 
// Broadcast to all ips
 
static void NetworkUDPBroadCast(SOCKET udp)
 
{
 
	int i;
 
	struct sockaddr_in out_addr;
 
	Packet *p;
 
	Packet* p = NetworkSend_Init(PACKET_UDP_CLIENT_FIND_SERVER);
 
	uint i;
 

	
 
	// Init the packet
 
	p = NetworkSend_Init(PACKET_UDP_CLIENT_FIND_SERVER);
 
	for (i = 0; _broadcast_list[i] != 0; i++) {
 
		struct sockaddr_in out_addr;
 

	
 
	i = 0;
 
	while (_broadcast_list[i] != 0) {
 
		out_addr.sin_family = AF_INET;
 
		out_addr.sin_port = htons(_network_server_port);
 
		out_addr.sin_addr.s_addr = _broadcast_list[i];
 
@@ -486,8 +482,6 @@ static void NetworkUDPBroadCast(SOCKET u
 
		DEBUG(net, 6)("[NET][UDP] Broadcasting to %s", inet_ntoa(out_addr.sin_addr));
 

	
 
		NetworkSendUDP_Packet(udp, p, &out_addr);
 

	
 
		i++;
 
	}
 

	
 
	free(p);
newgrf.c
Show inline comments
 
@@ -2467,17 +2467,19 @@ static void ParamSet(byte *buf, int len)
 
			break;
 

	
 
		case 0x05:
 
			if ((int32)src2 < 0)
 
			if ((int32)src2 < 0) {
 
				res = src1 >> -(int32)src2;
 
			else
 
			} else {
 
				res = src1 << src2;
 
			}
 
			break;
 

	
 
		case 0x06:
 
			if ((int32)src2 < 0)
 
			if ((int32)src2 < 0) {
 
				res = (int32)src1 >> -(int32)src2;
 
			else
 
			} else {
 
				res = (int32)src1 << src2;
 
			}
 
			break;
 

	
 
		case 0x07: /* Bitwise AND */
npf.c
Show inline comments
 
@@ -213,9 +213,7 @@ static uint NPFSlopeCost(AyStarNode* cur
 
 */
 
static void NPFMarkTile(TileIndex tile)
 
{
 
#ifdef NO_DEBUG_MESSAGES
 
	return;
 
#else
 
#ifndef NO_DEBUG_MESSAGES
 
	if (_debug_npf_level < 1 || _networking) return;
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY:
 
@@ -806,14 +804,12 @@ NPFFoundTargetData NPFRouteToDepotTrialE
 
	_npf_aystar.EndNodeCheck = NPFFindStationOrTile;
 
	_npf_aystar.FoundEndNode = NPFSaveTargetData;
 
	_npf_aystar.GetNeighbours = NPFFollowTrack;
 
	if (type == TRANSPORT_RAIL)
 
		_npf_aystar.CalculateG = NPFRailPathCost;
 
	else if (type == TRANSPORT_ROAD)
 
		_npf_aystar.CalculateG = NPFRoadPathCost;
 
	else if (type == TRANSPORT_WATER)
 
		_npf_aystar.CalculateG = NPFWaterPathCost;
 
	else
 
		assert(0);
 
	switch (type) {
 
		default: NOT_REACHED();
 
		case TRANSPORT_RAIL:  _npf_aystar.CalculateG = NPFRailPathCost;  break;
 
		case TRANSPORT_ROAD:  _npf_aystar.CalculateG = NPFRoadPathCost;  break;
 
		case TRANSPORT_WATER: _npf_aystar.CalculateG = NPFWaterPathCost; break;
 
	}
 

	
 
	/* Initialize target */
 
	target.station_index = INVALID_STATION; /* We will initialize dest_coords inside the loop below */
openttd.c
Show inline comments
 
@@ -335,11 +335,11 @@ int ttd_main(int argc, char* argv[])
 
	//   a letter means: it accepts that param (e.g.: -h)
 
	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
 
	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
 
	optformat = "bm:s:v:hDn::eit:d::r:g::G:c:"
 
	#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
 
		optformat = "bm:s:v:hDfn::eit:d::r:g::G:c:";
 
	#else
 
		optformat = "bm:s:v:hDn::eit:d::r:g::G:c:"; // no fork option
 
		"f"
 
	#endif
 
	;
 

	
 
	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
 
	while ((i = MyGetOpt(&mgo)) != -1) {
 
@@ -373,8 +373,9 @@ int ttd_main(int argc, char* argv[])
 
			if (mgo.opt != NULL) {
 
				strcpy(_file_to_saveload.name, mgo.opt);
 
				_switch_mode = SM_LOAD;
 
			} else
 
			} else {
 
				_switch_mode = SM_NEWGAME;
 
			}
 
			break;
 
		case 'G': _random_seeds[0][0] = atoi(mgo.opt); break;
 
		case 'c': _config_file = strdup(mgo.opt); break;
 
@@ -1339,9 +1340,7 @@ bool AfterLoadGame(void)
 
	 * replaced, shall keep their old length. In all prior versions, just default
 
	 * to false */
 
	if (CheckSavegameVersionOldStyle(16, 1)) {
 
		FOR_ALL_PLAYERS(p) {
 
			p->renew_keep_length = false;
 
		}
 
		FOR_ALL_PLAYERS(p) p->renew_keep_length = false;
 
	}
 

	
 
	/* In version 17, ground type is moved from m2 to m4 for depots and
 
@@ -1396,11 +1395,12 @@ bool AfterLoadGame(void)
 
				}
 

	
 
				// Clear PBS reservation on track
 
				if (!IsTileDepotType(tile, TRANSPORT_RAIL))
 
				if (!IsTileDepotType(tile, TRANSPORT_RAIL)) {
 
					SB(_m[tile].m4, 4, 4, 0);
 
				else
 
				} else {
 
					CLRBIT(_m[tile].m3, 6);
 
			}
 
			}
 

	
 
			// Clear PBS reservation on crossing
 
			if (IsTileType(tile, MP_STREET) && IsLevelCrossing(tile))
order.h
Show inline comments
 
@@ -72,9 +72,10 @@ enum {
 

	
 

	
 
/* If you change this, keep in mind that it is saved on 3 places:
 
    - Load_ORDR, all the global orders
 
    - Vehicle -> current_order
 
    - REF_SHEDULE (all REFs are currently limited to 16 bits!!) */
 
 * - Load_ORDR, all the global orders
 
 * - Vehicle -> current_order
 
 * - REF_SHEDULE (all REFs are currently limited to 16 bits!!)
 
 */
 
typedef struct Order {
 
	uint8  type;
 
	uint8  flags;
order_cmd.c
Show inline comments
 
@@ -569,8 +569,9 @@ int32 CmdModifyOrder(TileIndex tile, uin
 
	order = GetVehicleOrder(v, sel_ord);
 
	if (order->type != OT_GOTO_STATION &&
 
		 (order->type != OT_GOTO_DEPOT || p2 == OFB_UNLOAD) &&
 
		 (order->type != OT_GOTO_WAYPOINT || p2 != OFB_NON_STOP))
 
			(order->type != OT_GOTO_WAYPOINT || p2 != OFB_NON_STOP)) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		switch (p2) {
 
@@ -902,11 +903,15 @@ void CheckOrders(const Vehicle* v)
 
		}
 

	
 
		/* Check if the last and the first order are the same */
 
		if (v->num_orders > 1 &&
 
				v->orders->type    == GetLastVehicleOrder(v)->type &&
 
				v->orders->flags   == GetLastVehicleOrder(v)->flags &&
 
				v->orders->station == GetLastVehicleOrder(v)->station)
 
		if (v->num_orders > 1) {
 
			const Order* last = GetLastVehicleOrder(v);
 

	
 
			if (v->orders->type    == last->type &&
 
					v->orders->flags   == last->flags &&
 
					v->orders->station == last->station) {
 
			problem_type = 2;
 
			}
 
		}
 

	
 
		/* Do we only have 1 station in our order list? */
 
		if (n_st < 2 && problem_type == -1) problem_type = 0;
order_gui.c
Show inline comments
 
@@ -398,31 +398,24 @@ static void OrdersWndProc(Window *w, Win
 
		Vehicle *v = GetVehicle(w->window_number);
 
		switch (e->click.widget) {
 
		case 2: { /* orders list */
 
			int sel;
 
			sel = (e->click.pt.y - 15) / 10;
 
			int sel = (e->click.pt.y - 15) / 10;
 

	
 
			if ((uint)sel >= w->vscroll.cap)
 
				return;
 
			if ((uint)sel >= w->vscroll.cap) return;
 

	
 
			sel += w->vscroll.pos;
 

	
 
			if (_ctrl_pressed && sel < v->num_orders) {
 
				const Order *ord = GetVehicleOrder(v, sel);
 
				int xy = 0;
 
				TileIndex xy;
 

	
 
				switch (ord->type) {
 
				case OT_GOTO_STATION:			/* station order */
 
					xy = GetStation(ord->station)->xy ;
 
					break;
 
				case OT_GOTO_DEPOT:				/* goto depot order */
 
					xy = GetDepot(ord->station)->xy;
 
					break;
 
				case OT_GOTO_WAYPOINT:	/* goto waypoint order */
 
					xy = GetWaypoint(ord->station)->xy;
 
					case OT_GOTO_STATION:  xy = GetStation(ord->station)->xy ; break;
 
					case OT_GOTO_DEPOT:    xy = GetDepot(ord->station)->xy;    break;
 
					case OT_GOTO_WAYPOINT: xy = GetWaypoint(ord->station)->xy; break;
 
					default:               xy = 0; break;
 
				}
 

	
 
				if (xy)
 
					ScrollMainWindowToTile(xy);
 

	
 
				if (xy != 0) ScrollMainWindowToTile(xy);
 
				return;
 
			}
 

	
 
@@ -518,7 +511,6 @@ static void OrdersWndProc(Window *w, Win
 
		w->vscroll.cap = (w->widget[2].bottom - w->widget[2].top) / 10;
 
		break;
 
	}
 

	
 
}
 

	
 
static const Widget _orders_train_widgets[] = {
os2.c
Show inline comments
 
@@ -64,11 +64,12 @@ int compare_FiosItems(const void *a, con
 

	
 
static void append_path(char *out, const char *path, const char *file)
 
{
 
	if (path[2] == '\\' && path[3] == '\0')
 
	if (path[2] == '\\' && path[3] == '\0') {
 
		sprintf(out, "%s%s", path, file);
 
	else
 
	} else {
 
		sprintf(out, "%s\\%s", path, file);
 
}
 
}
 

	
 
// Get a list of savegames
 
FiosItem *FiosGetSavegameList(int *num, int mode)
 
@@ -347,10 +348,11 @@ char *FiosBrowseTo(const FiosItem *item)
 

	
 
		case FIOS_TYPE_PARENT:
 
			s = strrchr(path, '\\');
 
			if (s != path + 2)
 
			if (s != path + 2) {
 
				s[0] = '\0';
 
			else
 
			} else {
 
				s[1] = '\0';
 
			}
 
			break;
 

	
 
		case FIOS_TYPE_DIR:
 
@@ -406,10 +408,7 @@ void FiosMakeSavegameName(char *buf, con
 
	const char* extension;
 
	const char* period;
 

	
 
	if (_game_mode == GM_EDITOR)
 
		extension = ".scn";
 
	else
 
		extension = ".sav";
 
	extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
 

	
 
	// Don't append the extension, if it is already there
 
	period = strrchr(name, '.');
player.h
Show inline comments
 
@@ -238,9 +238,8 @@ static inline bool HasRailtypeAvail(cons
 
static inline bool ValParamRailtype(uint32 rail) { return HASBIT(GetPlayer(_current_player)->avail_railtypes, rail);}
 

	
 
/** Returns the "best" railtype a player can build.
 
  * As the AI doesn't know what the BEST one is, we
 
  * have our own priority list here. When adding
 
  * new railtypes, modify this function
 
 * As the AI doesn't know what the BEST one is, we have our own priority list
 
 * here. When adding new railtypes, modify this function
 
  * @param p the player "in action"
 
  * @return The "best" railtype a player has available
 
  */
player_gui.c
Show inline comments
 
@@ -79,9 +79,9 @@ static void DrawPlayerEconomyStats(const
 
		// draw max loan aligned to loan below (y += 10)
 
		SetDParam64(0, (uint64)_economy.max_loan);
 
		DrawString(202, y+10, STR_MAX_LOAN, 0);
 

	
 
	} else
 
	} else {
 
		y = 15;
 
	}
 

	
 
	DrawString(2, y, STR_7026_BANK_BALANCE, 0);
 
	SetDParam64(0, p->money64);
 
@@ -524,9 +524,10 @@ static void PlayerCompanyWndProc(Window 
 

	
 
				/* Spectators cannot do anything of course */
 
				if (_local_player == OWNER_SPECTATOR) dis |= (1 << 9) | (1 << 10);
 
			} else /* shares are not allowed, disable buy/sell buttons */
 
			} else { /* shares are not allowed, disable buy/sell buttons */
 
				dis |= (1 << 9) | (1 << 10);
 
		}
 
		}
 

	
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
players.c
Show inline comments
 
@@ -220,10 +220,11 @@ static void SubtractMoneyFromAnyPlayer(P
 

	
 
	p->yearly_expenses[0][_yearly_expenses_type] += cost;
 

	
 
	if ( ( 1 << _yearly_expenses_type ) & (1<<7|1<<8|1<<9|1<<10))
 
	if (HASBIT(1<<7|1<<8|1<<9|1<<10, _yearly_expenses_type)) {
 
		p->cur_economy.income -= cost;
 
	else if (( 1 << _yearly_expenses_type ) & (1<<2|1<<3|1<<4|1<<5|1<<6|1<<11))
 
	} else if (HASBIT(1<<2|1<<3|1<<4|1<<5|1<<6|1<<11, _yearly_expenses_type)) {
 
		p->cur_economy.expenses -= cost;
 
	}
 

	
 
	InvalidatePlayerWindows(p);
 
}
 
@@ -231,47 +232,49 @@ static void SubtractMoneyFromAnyPlayer(P
 
void SubtractMoneyFromPlayer(int32 cost)
 
{
 
	PlayerID pid = _current_player;
 
	if (pid < MAX_PLAYERS)
 
		SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 

	
 
	if (pid < MAX_PLAYERS) SubtractMoneyFromAnyPlayer(GetPlayer(pid), cost);
 
}
 

	
 
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost)
 
{
 
	Player *p = GetPlayer(player);
 
	byte m = p->player_money_fraction;
 

	
 
	p->player_money_fraction = m - (byte)cost;
 
	cost >>= 8;
 
	if (p->player_money_fraction > m)
 
		cost++;
 
	if (cost != 0)
 
		SubtractMoneyFromAnyPlayer(p, cost);
 
	if (p->player_money_fraction > m) cost++;
 
	if (cost != 0) SubtractMoneyFromAnyPlayer(p, cost);
 
}
 

	
 
// the player_money field is kept as it is, but money64 contains the actual amount of money.
 
void UpdatePlayerMoney32(Player *p)
 
{
 
	if (p->money64 < -2000000000)
 
	if (p->money64 < -2000000000) {
 
		p->player_money = -2000000000;
 
	else if (p->money64 > 2000000000)
 
	} else if (p->money64 > 2000000000) {
 
		p->player_money = 2000000000;
 
	else
 
	} else {
 
		p->player_money = (int32)p->money64;
 
}
 
}
 

	
 
void GetNameOfOwner(PlayerID owner, TileIndex tile)
 
{
 
	SetDParam(2, owner);
 

	
 
	if (owner != OWNER_TOWN) {
 
		if (owner >= 8)
 
		if (owner >= MAX_PLAYERS) {
 
			SetDParam(0, STR_0150_SOMEONE);
 
		else {
 
		} else {
 
			const Player* p = GetPlayer(owner);
 

	
 
			SetDParam(0, p->name_1);
 
			SetDParam(1, p->name_2);
 
		}
 
	} else {
 
		Town *t = ClosestTownFromTile(tile, (uint)-1);
 
		const Town* t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
		SetDParam(0, STR_TOWN);
 
		SetDParam(1, t->index);
 
	}
 
@@ -282,8 +285,7 @@ bool CheckOwnership(PlayerID owner)
 
{
 
	assert(owner <= OWNER_WATER);
 

	
 
	if (owner == _current_player)
 
		return true;
 
	if (owner == _current_player) return true;
 
	_error_message = STR_013B_OWNED_BY;
 
	GetNameOfOwner(owner, 0);
 
	return false;
 
@@ -295,8 +297,7 @@ bool CheckTileOwnership(TileIndex tile)
 

	
 
	assert(owner <= OWNER_WATER);
 

	
 
	if (owner == _current_player)
 
		return true;
 
	if (owner == _current_player) return true;
 
	_error_message = STR_013B_OWNED_BY;
 

	
 
	// no need to get the name of the owner unless we're the local player (saves some time)
 
@@ -313,12 +314,10 @@ static void GenerateCompanyName(Player *
 
	uint32 strp;
 
	char buffer[100];
 

	
 
	if (p->name_1 != STR_SV_UNNAMED)
 
		return;
 
	if (p->name_1 != STR_SV_UNNAMED) return;
 

	
 
	tile = p->last_build_coordinate;
 
	if (tile == 0)
 
		return;
 
	if (tile == 0) return;
 

	
 
	t = ClosestTownFromTile(tile, (uint)-1);
 

	
 
@@ -329,8 +328,7 @@ static void GenerateCompanyName(Player *
 
verify_name:;
 
		// No player must have this name already
 
		FOR_ALL_PLAYERS(pp) {
 
			if (pp->name_1 == str && pp->name_2 == strp)
 
				goto bad_town_name;
 
			if (pp->name_1 == str && pp->name_2 == strp) goto bad_town_name;
 
		}
 

	
 
		GetString(buffer, str);
 
@@ -423,11 +421,8 @@ static byte GeneratePlayerColor(void)
 
	}
 

	
 
	// Return the first available color
 
	i = 0;
 
	for (;;) {
 
		if (colors[i] != 0xFF)
 
			return colors[i];
 
		i++;
 
	for (i = 0;; i++) {
 
		if (colors[i] != 0xFF) return colors[i];
 
	}
 
}
 

	
 
@@ -851,8 +846,9 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
			}
 
#ifdef ENABLE_NETWORK
 
			if (_network_server) {
 
				/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at server-side
 
				 * in network_server.c:838, function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
 
				/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at
 
				 * server-side in network_server.c:838, function
 
				 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
 
				NetworkClientInfo *ci = &_network_client_info[pid];
 
				ci->client_playas = p->index + 1;
 
				NetworkUpdateClientInfo(ci->client_index);
 
@@ -878,16 +874,16 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
					_local_player = player_backup;
 
				}
 
			}
 
		} else if (_network_server) { // Creating player failed, defer client to spectator
 
				/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at server-side
 
				* in network_server.c:838, function DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
 
		} else if (_network_server) {
 
			// Creating player failed, defer client to spectator
 
			/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at
 
			 * server-side in network_server.c:838, function
 
			 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
 
			NetworkClientInfo *ci = &_network_client_info[pid];
 
			ci->client_playas = OWNER_SPECTATOR;
 
			NetworkUpdateClientInfo(ci->client_index);
 
#endif /* ENABLE_NETWORK */
 
		}
 
#else
 
		}
 
#endif /* ENABLE_NETWORK */
 
	} break;
 

	
 
	case 1: /* Make a new AI player */
 
@@ -941,7 +937,7 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
	return 0;
 
}
 

	
 
static const StringID _endgame_perf_titles[16] = {
 
static const StringID _endgame_perf_titles[] = {
 
	STR_0213_BUSINESSMAN,
 
	STR_0213_BUSINESSMAN,
 
	STR_0213_BUSINESSMAN,
 
@@ -957,13 +953,12 @@ static const StringID _endgame_perf_titl
 
	STR_0217_MAGNATE,
 
	STR_0218_MOGUL,
 
	STR_0218_MOGUL,
 
	STR_0219_TYCOON_OF_THE_CENTURY,
 
	STR_0219_TYCOON_OF_THE_CENTURY
 
};
 

	
 
StringID EndGameGetPerformanceTitleFromValue(uint value)
 
{
 
	value = minu(value, 1000) >> 6;
 
	if (value >= lengthof(_endgame_perf_titles)) value = lengthof(_endgame_perf_titles) - 1;
 
	value = minu(value / 64, lengthof(_endgame_perf_titles) - 1);
 

	
 
	return _endgame_perf_titles[value];
 
}
 
@@ -975,8 +970,7 @@ static bool CheatHasBeenUsed(void)
 
	const Cheat* cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
 

	
 
	for (; cht != cht_last; cht++) {
 
		if (cht->been_used)
 
			return true;
 
		if (cht->been_used) return true;
 
	}
 

	
 
	return false;
rail.h
Show inline comments
 
@@ -263,20 +263,28 @@ static inline Trackdir TrackToTrackdir(T
 
 * Returns a TrackdirBit mask that contains the two TrackdirBits that
 
 * correspond with the given Track (one for each direction).
 
 */
 
static inline TrackdirBits TrackToTrackdirBits(Track track) { Trackdir td = TrackToTrackdir(track); return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));}
 
static inline TrackdirBits TrackToTrackdirBits(Track track)
 
{
 
	Trackdir td = TrackToTrackdir(track);
 
	return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
 
}
 

	
 
/**
 
 * Discards all directional information from the given TrackdirBits. Any
 
 * Track which is present in either direction will be present in the result.
 
 */
 
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits) { return (TrackBits)(bits | (bits >> 8)); }
 
static inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
 
{
 
	return (TrackBits)(bits | (bits >> 8));
 
}
 

	
 
/**
 
 * Maps a trackdir to the trackdir that you will end up on if you go straight
 
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
 
 * different (alternating) one for straight trackdirs
 
 */
 
static inline Trackdir NextTrackdir(Trackdir trackdir) {
 
static inline Trackdir NextTrackdir(Trackdir trackdir)
 
{
 
	extern const Trackdir _next_trackdir[TRACKDIR_END];
 
	return _next_trackdir[trackdir];
 
}
 
@@ -284,7 +292,8 @@ static inline Trackdir NextTrackdir(Trac
 
/**
 
 * Maps a track to all tracks that make 90 deg turns with it.
 
 */
 
static inline TrackBits TrackCrossesTracks(Track track) {
 
static inline TrackBits TrackCrossesTracks(Track track)
 
{
 
	extern const TrackBits _track_crosses_tracks[TRACK_END];
 
	return _track_crosses_tracks[track];
 
}
 
@@ -293,7 +302,8 @@ static inline TrackBits TrackCrossesTrac
 
 * Maps a trackdir to the (4-way) direction the tile is exited when following
 
 * that trackdir.
 
 */
 
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir) {
 
static inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
 
{
 
	extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
 
	return _trackdir_to_exitdir[trackdir];
 
}
 
@@ -302,7 +312,8 @@ static inline DiagDirection TrackdirToEx
 
 * Maps a track and an (4-way) dir to the trackdir that represents the track
 
 * with the exit in the given direction.
 
 */
 
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir) {
 
static inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
 
{
 
	extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
 
	return _track_exitdir_to_trackdir[track][diagdir];
 
}
 
@@ -311,7 +322,8 @@ static inline Trackdir TrackExitdirToTra
 
 * Maps a track and an (4-way) dir to the trackdir that represents the track
 
 * with the exit in the given direction.
 
 */
 
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir) {
 
static inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
 
{
 
	extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
 
	return _track_enterdir_to_trackdir[track][diagdir];
 
}
 
@@ -320,7 +332,8 @@ static inline Trackdir TrackEnterdirToTr
 
 * Maps a track and a full (8-way) direction to the trackdir that represents
 
 * the track running in the given direction.
 
 */
 
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir) {
 
static inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
 
{
 
	extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
 
	return _track_direction_to_trackdir[track][dir];
 
}
 
@@ -329,7 +342,8 @@ static inline Trackdir TrackDirectionToT
 
 * Maps a (4-way) direction to the diagonal trackdir that runs in that
 
 * direction.
 
 */
 
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir) {
 
static inline Trackdir DiagdirToDiagTrackdir(DiagDirection diagdir)
 
{
 
	extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
 
	return _dir_to_diag_trackdir[diagdir];
 
}
rail_cmd.c
Show inline comments
 
@@ -467,9 +467,10 @@ static int32 ValidateAutoDrag(Trackdir *
 
			SETBIT(*trackdir, 3); // reverse the direction
 
			trdx = -trdx;
 
			trdy = -trdy;
 
		} else // other direction is invalid too, invalid drag
 
		} else { // other direction is invalid too, invalid drag
 
			return CMD_ERROR;
 
	}
 
	}
 

	
 
	// (for diagonal tracks, this is already made sure of by above test), but:
 
	// for non-diagonal tracks, check if the start and end tile are on 1 line
 
@@ -517,8 +518,9 @@ static int32 CmdRailTrackHelper(TileInde
 
		if (CmdFailed(ret)) {
 
			if ((_error_message != STR_1007_ALREADY_BUILT) && (mode == 0)) break;
 
			_error_message = INVALID_STRING_ID;
 
		} else
 
		} else {
 
			total_cost += ret;
 
		}
 

	
 
		if (tile == end_tile) break;
 

	
 
@@ -648,10 +650,10 @@ int32 CmdBuildSingleSignal(TileIndex til
 
 		TrackBits trackbits = GetTrackBits(tile);
 
		if (KILL_FIRST_BIT(trackbits) != 0 && /* More than one track present */
 
				trackbits != TRACK_BIT_HORZ &&
 
				trackbits != TRACK_BIT_VERT
 
		)
 
				trackbits != TRACK_BIT_VERT) {
 
			return CMD_ERROR;
 
	}
 
	}
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
@@ -740,8 +742,7 @@ static int32 CmdSignalTrackHelper(TileIn
 

	
 
	/* for vertical/horizontal tracks, double the given signals density
 
	* since the original amount will be too dense (shorter tracks) */
 
	if (!IsDiagonalTrack(track))
 
		signal_density *= 2;
 
	if (!IsDiagonalTrack(track)) signal_density *= 2;
 

	
 
	if (CmdFailed(ValidateAutoDrag(&trackdir, tile, end_tile))) return CMD_ERROR;
 

	
 
@@ -754,8 +755,9 @@ static int32 CmdSignalTrackHelper(TileIn
 

	
 
		// copy signal/semaphores style (independent of CTRL)
 
		semaphores = (GetSignalVariant(tile) == SIG_ELECTRIC ? 0 : 8);
 
	} else // no signals exist, drag a two-way signal stretch
 
	} else { // no signals exist, drag a two-way signal stretch
 
		signals = SignalOnTrack(track);
 
	}
 

	
 
	/* signal_ctr         - amount of tiles already processed
 
	 * signals_density    - patch setting to put signal on every Nth tile (double space on |, -- tracks)
 
@@ -768,7 +770,7 @@ static int32 CmdSignalTrackHelper(TileIn
 
	signal_ctr = total_cost = 0;
 
	for (;;) {
 
		// only build/remove signals with the specified density
 
		if ((signal_ctr % signal_density) == 0 ) {
 
		if (signal_ctr % signal_density == 0) {
 
			ret = DoCommand(tile, TrackdirToTrack(trackdir) | semaphores, signals, flags, (mode == 1) ? CMD_REMOVE_SIGNALS : CMD_BUILD_SIGNALS);
 

	
 
			/* Abort placement for any other error than NOT_SUITABLE_TRACK
 
@@ -811,11 +813,12 @@ int32 CmdRemoveSingleSignal(TileIndex ti
 
{
 
	Track track = (Track)(p1 & 0x7);
 

	
 
	if (!ValParamTrackOrientation(track) || !IsTileType(tile, MP_RAILWAY) || !EnsureNoVehicle(tile))
 
	if (!ValParamTrackOrientation(track) ||
 
			!IsTileType(tile, MP_RAILWAY) ||
 
			!EnsureNoVehicle(tile) ||
 
			!HasSignalOnTrack(tile, track)) {
 
		return CMD_ERROR;
 

	
 
	if (!HasSignalOnTrack(tile, track)) // no signals on track?
 
		return CMD_ERROR;
 
	}
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_player != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
 
@@ -1238,8 +1241,7 @@ static void DrawTrackBits(TileInfo* ti, 
 
			foundation = GetRailFoundation(ti->tileh, track);
 
		}
 

	
 
		if (foundation != 0)
 
			DrawFoundation(ti, foundation);
 
		if (foundation != 0) DrawFoundation(ti, foundation);
 

	
 
		// DrawFoundation() modifies ti.
 
		// Default sloped sprites..
 
@@ -1317,7 +1319,6 @@ static void DrawTile_Track(TileInfo *ti)
 

	
 
		/* draw signals also? */
 
		if (GetRailTileType(ti->tile) == RAIL_TILE_SIGNALS) DrawSignals(ti->tile, rails);
 

	
 
	} else {
 
		/* draw depots / waypoints */
 
		const DrawTrackSeqStruct *drss;
 
@@ -1531,7 +1532,7 @@ static void *SignalVehicleCheckProc(Vehi
 
	if (tile != dest->tile) return NULL;
 

	
 
	/* Are we on the same piece of track? */
 
	if (dest->track & (v->u.rail.track + (v->u.rail.track << 8))) return v;
 
	if (dest->track & v->u.rail.track * 0x101) return v;
 

	
 
	return NULL;
 
}
rail_gui.c
Show inline comments
 
@@ -147,9 +147,9 @@ void CcStation(bool success, TileIndex t
 

	
 
static void PlaceRail_Station(TileIndex tile)
 
{
 
	if (_remove_button_clicked)
 
	if (_remove_button_clicked) {
 
		DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION));
 
	else if (_railstation.dragdrop) {
 
	} else if (_railstation.dragdrop) {
 
		VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED);
 
		VpSetPlaceSizingLimit(_patches.station_spread);
 
	} else {
 
@@ -470,9 +470,10 @@ static void BuildRailToolbWndProc(Window
 
					DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL));
 
			} else if (e->place.userdata == VPM_X_AND_Y_LIMITED) {
 
				HandleStationPlacement(start_tile, end_tile);
 
			} else
 
			} else {
 
				DoRailroadTrack(e->place.userdata & 1);
 
		}
 
		}
 
		break;
 

	
 
	case WE_ABORT_PLACE_OBJ:
rail_map.h
Show inline comments
 
@@ -272,7 +272,6 @@ RailType GetTileRailType(TileIndex tile,
 

	
 

	
 
typedef enum RailGroundType {
 
	RAIL_MAP2LO_GROUND_MASK = 0xF,
 
	RAIL_GROUND_BARREN = 0,
 
	RAIL_GROUND_GRASS = 1,
 
	RAIL_GROUND_FENCE_NW = 2,
road_cmd.c
Show inline comments
 
@@ -254,7 +254,7 @@ static uint32 CheckRoadSlope(Slope tileh
 

	
 
	// foundation is used. Whole tile is leveled up
 
	if ((~_valid_tileh_slopes_road[1][tileh] & road_bits) == 0) {
 
		return existing ? 0 : _price.terraform;
 
		return existing != 0 ? 0 : _price.terraform;
 
	}
 

	
 
	// partly leveled up tile, only if there's no road on that tile
 
@@ -802,7 +802,8 @@ static void DrawTile_Road(TileInfo *ti)
 
				if (image & PALETTE_MODIFIER_COLOR) image |= ormod;
 
				if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
 

	
 
				AddSortableSpriteToDraw(image, ti->x | drss->subcoord_x,
 
				AddSortableSpriteToDraw(
 
					image, ti->x | drss->subcoord_x,
 
					ti->y | drss->subcoord_y, drss->width, drss->height, 0x14, ti->z
 
				);
 
			}
 
@@ -894,9 +895,6 @@ static const Roadside _town_road_types_2
 

	
 
static void TileLoop_Road(TileIndex tile)
 
{
 
	Town *t;
 
	int grp;
 

	
 
	switch (_opt.landscape) {
 
		case LT_HILLY:
 
			if (IsOnSnow(tile) != (GetTileZ(tile) > _opt.snow_line)) {
 
@@ -916,15 +914,15 @@ static void TileLoop_Road(TileIndex tile
 
	if (GetRoadTileType(tile) == ROAD_TILE_DEPOT) return;
 

	
 
	if (!HasRoadWorks(tile)) {
 
		t = ClosestTownFromTile(tile, (uint)-1);
 
		const Town* t = ClosestTownFromTile(tile, (uint)-1);
 
		int grp = 0;
 

	
 
		grp = 0;
 
		if (t != NULL) {
 
			grp = GetTownRadiusGroup(t, tile);
 

	
 
			// Show an animation to indicate road work
 
			if (t->road_build_months != 0 &&
 
					!(DistanceManhattan(t->xy, tile) >= 8 && grp == 0) &&
 
					(DistanceManhattan(t->xy, tile) < 8 || grp != 0) &&
 
					GetRoadTileType(tile) == ROAD_TILE_NORMAL && (GetRoadBits(tile) == ROAD_X || GetRoadBits(tile) == ROAD_Y)) {
 
				if (GetTileSlope(tile, NULL) == SLOPE_FLAT && EnsureNoVehicle(tile) && CHANCE16(1, 20)) {
 
					StartRoadWorks(tile);
 
@@ -1001,7 +999,6 @@ static uint32 GetTileTrackStatus_Road(Ti
 
				default:
 
				case ROAD_TILE_DEPOT:
 
					return (DiagDirToAxis(GetRoadDepotDirection(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 
					break;
 
			}
 
			break;
 

	
 
@@ -1048,12 +1045,12 @@ static uint32 VehicleEnter_Road(Vehicle 
 
			break;
 

	
 
		case ROAD_TILE_DEPOT:
 
			if (v->type == VEH_Road && v->u.road.frame == 11) {
 
				if (_roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) {
 
			if (v->type == VEH_Road &&
 
					v->u.road.frame == 11 &&
 
					_roadveh_enter_depot_unk0[GetRoadDepotDirection(tile)] == v->u.road.state) {
 
					RoadVehEnterDepot(v);
 
					return 4;
 
				}
 
			}
 
			break;
 

	
 
		default: break;
road_gui.c
Show inline comments
 
@@ -418,8 +418,9 @@ static void RoadStationPickerWndProc(Win
 
		if (_station_show_coverage) {
 
			int rad = _patches.modified_catchment ? CA_TRUCK /* = CA_BUS */ : 4;
 
			SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
 
		} else
 
		} else {
 
			SetTileSelectSize(1, 1);
 
		}
 

	
 
		image = (w->window_class == WC_BUS_STATION) ? 0x47 : 0x43;
 

	
roadveh_cmd.c
Show inline comments
 
@@ -1625,7 +1625,6 @@ static void CheckIfRoadVehNeedsService(V
 
void OnNewDay_RoadVeh(Vehicle *v)
 
{
 
	int32 cost;
 
	Station *st;
 

	
 
	if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v);
 
	if (v->u.road.blocked_ctr == 0) CheckVehicleBreakdown(v);
 
@@ -1646,19 +1645,19 @@ void OnNewDay_RoadVeh(Vehicle *v)
 

	
 
	/* update destination */
 
	if (v->current_order.type == OT_GOTO_STATION && v->u.road.slot == NULL && !(v->vehstatus & VS_CRASHED)) {
 
		RoadStop *rs;
 
		Station* st = GetStation(v->current_order.station);
 
		RoadStop* rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK);
 
		RoadStop *best = NULL;
 

	
 
		st = GetStation(v->current_order.station);
 
		rs = GetPrimaryRoadStop(st, v->cargo_type == CT_PASSENGERS ? RS_BUS : RS_TRUCK);
 

	
 
		if (rs != NULL) {
 
			if (DistanceManhattan(v->tile, st->xy) < 16) {
 
				uint dist, badness;
 
				uint minbadness = UINT_MAX;
 

	
 
				DEBUG(ms, 2) ("Multistop: Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)", v->unitnumber,
 
						v->index, st->index, st->xy);
 
				DEBUG(ms, 2) (
 
					"Multistop: Attempting to obtain a slot for vehicle %d (index %d) at station %d (0x%X)",
 
					v->unitnumber, v->index, st->index, st->xy
 
				);
 
				/* Now we find the nearest road stop that has a free slot */
 
				for (; rs != NULL; rs = rs->next) {
 
					dist = RoadFindPathToStop(v, rs->xy);
roadveh_gui.c
Show inline comments
 
@@ -109,7 +109,6 @@ static void RoadVehRefitWndProc(Window *
 
						WP(w,refit_d).sel = y / 10;
 
						SetWindowDirty(w);
 
					}
 

	
 
					break;
 
				}
 

	
 
@@ -163,8 +162,8 @@ static void RoadVehDetailsWndProc(Window
 
		StringID str;
 

	
 
		w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
 
		if (!_patches.servint_roadveh) // disable service-scroller when interval is set to disabled
 
			w->disabled_state |= (1 << 5) | (1 << 6);
 
		// disable service-scroller when interval is set to disabled
 
		if (!_patches.servint_roadveh) w->disabled_state |= (1 << 5) | (1 << 6);
 

	
 
		SetDParam(0, v->string_id);
 
		SetDParam(1, v->unitnumber);
 
@@ -352,8 +351,9 @@ static void RoadVehViewWndProc(Window *w
 
				if (v->num_orders == 0) {
 
					str = STR_NO_ORDERS + _patches.vehicle_speed;
 
					SetDParam(0, v->cur_speed / 2);
 
				} else
 
				} else {
 
					str = STR_EMPTY;
 
				}
 
				break;
 
			}
 
		}
 
@@ -565,8 +565,7 @@ static void NewRoadVehWndProc(Window *w,
 
		break;
 

	
 
	case WE_RESIZE: {
 
		if (e->sizing.diff.y == 0)
 
			break;
 
		if (e->sizing.diff.y == 0) break;
 

	
 
		w->vscroll.cap += e->sizing.diff.y / 14;
 
		w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
 
@@ -632,8 +631,7 @@ static void DrawRoadDepotWindow(Window *
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile)
 
			num++;
 
		if (v->type == VEH_Road && IsRoadVehInDepot(v) && v->tile == tile) num++;
 
	}
 
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 

	
 
@@ -675,12 +673,10 @@ static int GetVehicleFromRoadDepotWndPt(
 

	
 
	xt = x / 56;
 
	xm = x % 56;
 
	if (xt >= w->hscroll.cap)
 
		return 1;
 
	if (xt >= w->hscroll.cap) return 1;
 

	
 
	row = (y - 14) / 14;
 
	if (row >= w->vscroll.cap)
 
		return 1;
 
	if (row >= w->vscroll.cap) return 1;
 

	
 
	pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
 

	
 
@@ -707,7 +703,10 @@ static void RoadDepotClickVeh(Window *w,
 
	if (mode > 0) return;
 

	
 
	// share / copy orders
 
	if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; }
 
	if (_thd.place_mode && mode <= 0) {
 
		_place_clicked_vehicle = v;
 
		return;
 
	}
 

	
 
	switch (mode) {
 
	case 0: // start dragging of vehicle
 
@@ -791,14 +790,14 @@ static void RoadDepotWndProc(Window *w, 
 
		}
 
	} break;
 

	
 
	case WE_PLACE_OBJ: {
 
	case WE_PLACE_OBJ:
 
		ClonePlaceObj(w);
 
	} break;
 
		break;
 

	
 
	case WE_ABORT_PLACE_OBJ: {
 
	case WE_ABORT_PLACE_OBJ:
 
		CLRBIT(w->click_state, 8);
 
		InvalidateWidget(w, 8);
 
	} break;
 
		break;
 

	
 
	// check if a vehicle in a depot was clicked..
 
	case WE_MOUSELOOP: {
 
@@ -848,22 +847,21 @@ static void RoadDepotWndProc(Window *w, 
 
					_backup_orders_tile = 0;
 
			}
 
			break;
 

	
 
		default:
 
			WP(w,traindepot_d).sel = INVALID_VEHICLE;
 
			SetWindowDirty(w);
 
		}
 
		break;
 

	
 
	case WE_RESIZE: {
 
	case WE_RESIZE:
 
		/* Update the scroll + matrix */
 
		w->vscroll.cap += e->sizing.diff.y / 14;
 
		w->hscroll.cap += e->sizing.diff.x / 56;
 
		w->widget[5].unkA = (w->vscroll.cap << 8) + w->hscroll.cap;
 

	
 
	} break;
 
		break;
 

	
 
	}
 

	
 
}
 

	
 
static const Widget _road_depot_widgets[] = {
 
@@ -893,10 +891,9 @@ static const WindowDesc _road_depot_desc
 

	
 
void ShowRoadDepotWindow(TileIndex tile)
 
{
 
	Window *w;
 
	Window* w = AllocateWindowDescFront(&_road_depot_desc, tile);
 

	
 
	w = AllocateWindowDescFront(&_road_depot_desc, tile);
 
	if (w) {
 
	if (w != NULL) {
 
		w->caption_color = GetTileOwner(w->window_number);
 
		w->hscroll.cap = 5;
 
		w->vscroll.cap = 3;
 
@@ -959,13 +956,12 @@ static void PlayerRoadVehWndProc(Window 
 
		SetVScrollCount(w, vl->list_length);
 

	
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 
		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
		if (station == INVALID_STATION) {
 
			const Player *p = GetPlayer(owner);
 
			if (station == INVALID_STATION) {
 

	
 
				/* Company Name -- (###) Road vehicles */
 
				SetDParam(0, p->name_1);
 
				SetDParam(1, p->name_2);
 
@@ -978,7 +974,6 @@ static void PlayerRoadVehWndProc(Window 
 
				w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES;
 
			}
 
			DrawWindowWidgets(w);
 
		}
 
		/* draw sorting criteria string */
 
		DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
 
		/* draw arrow pointing up/down for ascending/descending sorting */
 
@@ -1029,14 +1024,12 @@ static void PlayerRoadVehWndProc(Window 
 
			return;
 
		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;
 
			const Vehicle* v;
 

	
 
			if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				Vehicle *v;
 

	
 
				if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
				v	= GetVehicle(vl->sort_list[id_v].index);
 
@@ -1044,7 +1037,6 @@ static void PlayerRoadVehWndProc(Window 
 
				assert(v->type == VEH_Road && v->owner == owner);
 

	
 
				ShowRoadVehViewWindow(v);
 
			}
 
		} break;
 

	
 
		case 9: /* Build new Vehicle */
 
@@ -1053,9 +1045,7 @@ static void PlayerRoadVehWndProc(Window 
 
			break;
 

	
 
		case 10: {
 
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets))
 
				break;
 

	
 
			if (!IsWindowOfPrototype(w, _player_roadveh_widgets)) break;
 
			ShowReplaceVehicleWindow(VEH_Road);
 
			break;
 
		}
 
@@ -1070,8 +1060,7 @@ static void PlayerRoadVehWndProc(Window 
 
			_sorting.roadveh.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				CLRBIT(w->disabled_state, 3);
 
			if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
saveload.c
Show inline comments
 
@@ -1408,8 +1408,11 @@ static void* SaveFileToDisk(void *arg)
 
		_sl.excpt_uninit();
 

	
 
		fprintf(stderr, "Save game failed: %s.", _sl.excpt_msg);
 
		if (arg != NULL) OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_ERROR);
 
		else SaveFileError();
 
		if (arg != NULL) {
 
			OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_ERROR);
 
		} else {
 
			SaveFileError();
 
		}
 
		return NULL;
 
	}
 

	
 
@@ -1633,8 +1636,7 @@ int GetSavegameType(char *file)
 
	if (fread(&hdr, sizeof(hdr), 1, f) != 1) {
 
		printf("Savegame is obsolete or invalid format.\n");
 
		mode = SL_LOAD; // don't try to get filename, just show name as it is written
 
	}
 
	else {
 
	} else {
 
		// see if we have any loader for this type.
 
		for (fmt = _saveload_formats; fmt != endof(_saveload_formats); fmt++) {
 
			if (fmt->tag == hdr) {
settings.c
Show inline comments
 
@@ -238,10 +238,11 @@ static IniFile *ini_load(const char *fil
 

	
 
		// it's a group?
 
		if (s[0] == '[') {
 
			if (e[-1] != ']')
 
			if (e[-1] != ']') {
 
				ShowInfoF("ini: invalid group name '%s'\n", buffer);
 
			else
 
			} else {
 
				e--;
 
			}
 
			s++; // skip [
 
			group = ini_group_alloc(ini, s, e - s);
 
			if (comment_size) {
 
@@ -341,10 +342,11 @@ static bool ini_save(const char *filenam
 
			//*Don't give an equal sign to list items that don't have a parameter */
 
			if (group->type == IGT_LIST && *item->value == '\0') {
 
				fprintf(f, "%s\n", item->name);
 
			} else
 
			} else {
 
				fprintf(f, "%s = %s\n", item->name, item->value);
 
		}
 
	}
 
	}
 
	if (ini->comment) fputs(ini->comment, f);
 

	
 
	fclose(f);
 
@@ -609,8 +611,12 @@ static void Write_ValidateSetting(void *
 
{
 
	const SettingDescBase *sdb = &sd->desc;
 

	
 
	if (sdb->cmd != SDT_BOOLX && sdb->cmd != SDT_NUMX &&
 
		  sdb->cmd != SDT_ONEOFMANY && sdb->cmd != SDT_MANYOFMANY) return;
 
	if (sdb->cmd != SDT_BOOLX &&
 
			sdb->cmd != SDT_NUMX &&
 
			sdb->cmd != SDT_ONEOFMANY &&
 
			sdb->cmd != SDT_MANYOFMANY) {
 
		return;
 
	}
 

	
 
	/* We cannot know the maximum value of a bitset variable, so just have faith */
 
	if (sdb->cmd != SDT_MANYOFMANY) {
ship_gui.c
Show inline comments
 
@@ -159,8 +159,8 @@ static void ShipDetailsWndProc(Window *w
 
		StringID str;
 

	
 
		w->disabled_state = v->owner == _local_player ? 0 : (1 << 2);
 
		if (!_patches.servint_ships) // disable service-scroller when interval is set to disabled
 
			w->disabled_state |= (1 << 5) | (1 << 6);
 
		// disable service-scroller when interval is set to disabled
 
		if (!_patches.servint_ships) w->disabled_state |= (1 << 5) | (1 << 6);
 

	
 
		SetDParam(0, v->string_id);
 
		SetDParam(1, v->unitnumber);
 
@@ -448,7 +448,8 @@ static void ShowBuildShipWindow(TileInde
 
}
 

	
 

	
 
static void ShipViewWndProc(Window *w, WindowEvent *e) {
 
static void ShipViewWndProc(Window* w, WindowEvent* e)
 
{
 
	switch (e->event) {
 
		case WE_PAINT: {
 
			Vehicle *v = GetVehicle(w->window_number);
 
@@ -460,8 +461,7 @@ static void ShipViewWndProc(Window *w, W
 
				disabled = 0;
 
			}
 

	
 
			if (v->owner != _local_player)
 
				disabled |= 1<<8 | 1<<7;
 
			if (v->owner != _local_player) disabled |= 1<<8 | 1<<7;
 
			w->disabled_state = disabled;
 

	
 
			/* draw widgets & caption */
 
@@ -497,8 +497,9 @@ static void ShipViewWndProc(Window *w, W
 
						if (v->num_orders == 0) {
 
							str = STR_NO_ORDERS + _patches.vehicle_speed;
 
							SetDParam(0, v->cur_speed / 2);
 
						} else
 
						} else {
 
							str = STR_EMPTY;
 
						}
 
						break;
 
				}
 
			}
 
@@ -616,8 +617,7 @@ static void DrawShipDepotWindow(Window *
 
	/* determine amount of items for scroller */
 
	num = 0;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Ship && IsShipInDepot(v) && v->tile == tile)
 
			num++;
 
		if (v->type == VEH_Ship && IsShipInDepot(v) && v->tile == tile) num++;
 
	}
 
	SetVScrollCount(w, (num + w->hscroll.cap - 1) / w->hscroll.cap);
 

	
 
@@ -659,13 +659,11 @@ static int GetVehicleFromShipDepotWndPt(
 

	
 
	xt = x / 90;
 
	xm = x % 90;
 
	if (xt >= w->hscroll.cap)
 
		return 1;
 
	if (xt >= w->hscroll.cap) return 1;
 

	
 
	row = (y - 14) / 24;
 
	ym = (y - 14) % 24;
 
	if (row >= w->vscroll.cap)
 
		return 1;
 
	if (row >= w->vscroll.cap) return 1;
 

	
 
	pos = (row + w->vscroll.pos) * w->hscroll.cap + xt;
 

	
 
@@ -681,7 +679,6 @@ static int GetVehicleFromShipDepotWndPt(
 
	}
 

	
 
	return 1; /* outside */
 

	
 
}
 

	
 
static void ShipDepotClick(Window *w, int x, int y)
 
@@ -690,7 +687,10 @@ static void ShipDepotClick(Window *w, in
 
	int mode = GetVehicleFromShipDepotWndPt(w, x, y, &v);
 

	
 
	// share / copy orders
 
	if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = v; return; }
 
	if (_thd.place_mode && mode <= 0) {
 
		_place_clicked_vehicle = v;
 
		return;
 
	}
 

	
 
	switch (mode) {
 
	case 1: // invalid
 
@@ -1035,14 +1035,12 @@ static void PlayerShipsWndProc(Window *w
 
			return;
 
		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;
 
			const Vehicle* v;
 

	
 
			if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				Vehicle *v;
 

	
 
				if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
				v	= GetVehicle(vl->sort_list[id_v].index);
 
@@ -1050,7 +1048,6 @@ static void PlayerShipsWndProc(Window *w
 
				assert(v->type == VEH_Ship);
 

	
 
				ShowShipViewWindow(v);
 
			}
 
		} break;
 

	
 
		case 9: /* Build new Vehicle */
 
@@ -1075,8 +1072,7 @@ static void PlayerShipsWndProc(Window *w
 
			_sorting.ship.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				CLRBIT(w->disabled_state, 3);
 
			if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
sound/cocoa_s.c
Show inline comments
 
@@ -83,29 +83,35 @@ static const char *CocoaSoundStart(const
 
	desc.componentFlagsMask = 0;
 

	
 
	comp = FindNextComponent (NULL, &desc);
 
	if (comp == NULL)
 
	if (comp == NULL) {
 
		return "cocoa_s: Failed to start CoreAudio: FindNextComponent returned NULL";
 
	}
 

	
 
	/* Open & initialize the default output audio unit */
 
	if (OpenAComponent(comp, &_outputAudioUnit) != noErr)
 
	if (OpenAComponent(comp, &_outputAudioUnit) != noErr) {
 
		return "cocoa_s: Failed to start CoreAudio: OpenAComponent";
 
	}
 

	
 
	if (AudioUnitInitialize(_outputAudioUnit) != noErr)
 
	if (AudioUnitInitialize(_outputAudioUnit) != noErr) {
 
		return "cocoa_s: Failed to start CoreAudio: AudioUnitInitialize";
 
	}
 

	
 
	/* Set the input format of the audio unit. */
 
	if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &requestedDesc, sizeof(requestedDesc)) != noErr)
 
	if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &requestedDesc, sizeof(requestedDesc)) != noErr) {
 
		return "cocoa_s: Failed to start CoreAudio: AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)";
 
	}
 

	
 
	/* Set the audio callback */
 
	callback.inputProc = audioCallback;
 
	callback.inputProcRefCon = NULL;
 
	if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_SetInputCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback)) != noErr)
 
	if (AudioUnitSetProperty(_outputAudioUnit, kAudioUnitProperty_SetInputCallback, kAudioUnitScope_Input, 0, &callback, sizeof(callback)) != noErr) {
 
		return "cocoa_s: Failed to start CoreAudio: AudioUnitSetProperty (kAudioUnitProperty_SetInputCallback)";
 
	}
 

	
 
	/* Finally, start processing of the audio unit */
 
	if (AudioOutputUnitStart(_outputAudioUnit) != noErr)
 
	if (AudioOutputUnitStart(_outputAudioUnit) != noErr) {
 
		return "cocoa_s: Failed to start CoreAudio: AudioOutputUnitStart";
 
	}
 

	
 
	/* We're running! */
 
	return NULL;
station_cmd.c
Show inline comments
 
@@ -2204,23 +2204,20 @@ static uint32 GetTileTrackStatus_Station
 
{
 
	switch (mode) {
 
		case TRANSPORT_RAIL:
 
			if (IsRailwayStation(tile)) {
 
				if (IsStationTileBlocked(tile)) return 0;
 

	
 
			if (IsRailwayStation(tile) && !IsStationTileBlocked(tile)) {
 
				return TrackToTrackBits(GetRailStationTrack(tile)) * 0x101;
 
			}
 
			break;
 

	
 
		case TRANSPORT_WATER:
 
			// buoy is coded as a station, it is always on open water
 
			// (0x3F, all tracks available)
 
			if (IsBuoy_(tile)) return 0x3F * 0x101;
 
			if (IsBuoy_(tile)) return TRACK_BIT_ALL * 0x101;
 
			break;
 

	
 
		case TRANSPORT_ROAD:
 
			if (IsRoadStopTile(tile))
 
			if (IsRoadStopTile(tile)) {
 
				return (DiagDirToAxis(GetRoadStopDir(tile)) == AXIS_X ? TRACK_BIT_X : TRACK_BIT_Y) * 0x101;
 

	
 
			}
 
			break;
 

	
 
		default:
 
@@ -2549,11 +2546,12 @@ static void UpdateStationRating(Station 
 

	
 
	index = st->index;
 

	
 
	if (waiting_changed)
 
	if (waiting_changed) {
 
		InvalidateWindow(WC_STATION_VIEW, index);
 
	else
 
	} else {
 
		InvalidateWindowWidget(WC_STATION_VIEW, index, 5);
 
}
 
}
 

	
 
/* called for every station each tick */
 
static void StationHandleSmallTick(Station *st)
strgen/strgen.c
Show inline comments
 
@@ -890,7 +890,7 @@ static uint32 MyHashStr(uint32 hash, con
 
{
 
	for (; *s != '\0'; s++) {
 
		hash = ROL(hash, 3) ^ *s;
 
		if (hash & 1) hash = (hash >> 1) ^ 0xDEADBEEF; else hash >>= 1;
 
		hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
 
	}
 
	return hash;
 
}
 
@@ -914,7 +914,7 @@ static void MakeHashOfStrings(void)
 

	
 
			s = ls->name;
 
			hash ^= i * 0x717239;
 
			if (hash & 1) hash = (hash >> 1) ^ 0xDEADBEEF; else hash >>= 1;
 
			hash = (hash & 1 ? hash >> 1 ^ 0xDEADBEEF : hash >> 1);
 
			hash = MyHashStr(hash, s + 1);
 

	
 
			s = ls->english;
 
@@ -922,7 +922,7 @@ static void MakeHashOfStrings(void)
 
				if (cs->flags & C_DONTCOUNT) continue;
 

	
 
				hash ^= (cs - _cmd_structs) * 0x1234567;
 
				if (hash & 1) hash = (hash >> 1) ^ 0xF00BAA4; else hash >>= 1;
 
				hash = (hash & 1 ? hash >> 1 ^ 0xF00BAA4 : hash >> 1);
 
			}
 
		}
 
	}
terraform_gui.c
Show inline comments
 
@@ -235,8 +235,8 @@ static void TerraformToolbWndProc(Window
 
		break;
 

	
 
	case WE_PLACE_MOUSEUP:
 
		if (e->click.pt.x != -1) {
 
			if ((e->place.userdata & 0xF) == VPM_X_AND_Y) // dragged actions
 
		if (e->click.pt.x != -1 &&
 
				(e->place.userdata & 0xF) == VPM_X_AND_Y) { // dragged actions
 
				GUIPlaceProcDragXY(e);
 
		}
 
		break;
tile.h
Show inline comments
 
@@ -46,7 +46,7 @@ static inline void SetTileHeight(TileInd
 

	
 
static inline uint TilePixelHeight(TileIndex tile)
 
{
 
	return TileHeight(tile) * 8;
 
	return TileHeight(tile) * TILE_HEIGHT;
 
}
 

	
 
static inline TileType GetTileType(TileIndex tile)
town_cmd.c
Show inline comments
 
@@ -697,9 +697,9 @@ static int GrowTownAtRoad(Town *t, TileI
 

	
 
		if (IsTileType(tile, MP_STREET)) {
 
			/* Don't allow building over roads of other cities */
 
			if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t)
 
			if (IsTileOwner(tile, OWNER_TOWN) && GetTownByTile(tile) != t) {
 
				_grow_town_result = -1;
 
			else if (_game_mode == GM_EDITOR) {
 
			} else if (_game_mode == GM_EDITOR) {
 
				/* If we are in the SE, and this road-piece has no town owner yet, it just found an
 
				*  owner :) (happy happy happy road now) */
 
				SetTileOwner(tile, OWNER_TOWN);
train_gui.c
Show inline comments
 
@@ -134,8 +134,7 @@ void CcBuildWagon(bool success, TileInde
 
{
 
	Vehicle *v,*found;
 

	
 
	if (!success)
 
		return;
 
	if (!success) return;
 

	
 
	// find a locomotive in the depot.
 
	found = NULL;
 
@@ -143,8 +142,7 @@ void CcBuildWagon(bool success, TileInde
 
		if (v->type == VEH_Train && IsFrontEngine(v) &&
 
				v->tile == tile &&
 
				v->u.rail.track == 0x80) {
 
			if (found != NULL) // must be exactly one.
 
				return;
 
			if (found != NULL) return; // must be exactly one.
 
			found = v;
 
		}
 
	}
 
@@ -191,8 +189,7 @@ static void engine_drawing_loop(int *x, 
 
				!HASBIT(e->player_avail, _local_player))
 
			continue;
 

	
 
		if (*sel == 0)
 
			*selected_id = i;
 
		if (*sel == 0) *selected_id = i;
 

	
 
		if (IS_INT_INSIDE(--*pos, -show_max, 0)) {
 
			DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10);
 
@@ -208,8 +205,7 @@ static void NewRailVehicleWndProc(Window
 
	switch (e->event) {
 
	case WE_PAINT:
 

	
 
		if (w->window_number == 0)
 
			SETBIT(w->disabled_state, 5);
 
		if (w->window_number == 0) SETBIT(w->disabled_state, 5);
 

	
 
		{
 
			int count = 0;
 
@@ -218,10 +214,11 @@ static void NewRailVehicleWndProc(Window
 

	
 
			for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
 
				const Engine *e = GetEngine(i);
 
				if (HasPowerOnRail(e->railtype, railtype)
 
				    && HASBIT(e->player_avail, _local_player))
 
				if (HasPowerOnRail(e->railtype, railtype) &&
 
						HASBIT(e->player_avail, _local_player)) {
 
					count++;
 
			}
 
			}
 
			SetVScrollCount(w, count);
 
		}
 

	
 
@@ -562,20 +559,16 @@ static void TrainDepotMoveVehicle(Vehicl
 

	
 
	v = GetVehicle(sel);
 

	
 
	if (v == wagon)
 
		return;
 
	if (v == wagon) return;
 

	
 
	if (wagon == NULL) {
 
		if (head != NULL)
 
			wagon = GetLastVehicleInChain(head);
 
		if (head != NULL) wagon = GetLastVehicleInChain(head);
 
	} else  {
 
		wagon = GetPrevVehicleInChain(wagon);
 
		if (wagon == NULL)
 
			return;
 
		if (wagon == NULL) return;
 
	}
 

	
 
	if (wagon == v)
 
		return;
 
	if (wagon == v) return;
 

	
 
	DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE));
 
}
 
@@ -589,7 +582,10 @@ static void TrainDepotClickTrain(Window 
 
	mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp);
 

	
 
	// share / copy orders
 
	if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; }
 
	if (_thd.place_mode && mode <= 0) {
 
		_place_clicked_vehicle = gdvp.head;
 
		return;
 
	}
 

	
 
	v = gdvp.wagon;
 

	
 
@@ -683,14 +679,14 @@ static void TrainDepotWndProc(Window *w,
 
 		}
 
 	} break;
 

	
 
	case WE_PLACE_OBJ: {
 
	case WE_PLACE_OBJ:
 
		ClonePlaceObj(w);
 
	} break;
 
		break;
 

	
 
	case WE_ABORT_PLACE_OBJ: {
 
	case WE_ABORT_PLACE_OBJ:
 
		CLRBIT(w->click_state, 9);
 
		InvalidateWidget(w, 9);
 
	} break;
 
		break;
 

	
 
	// check if a vehicle in a depot was clicked..
 
	case WE_MOUSELOOP: {
 
@@ -994,8 +990,9 @@ static void TrainViewWndProc(Window *w, 
 
				if (v->num_orders == 0) {
 
					str = STR_NO_ORDERS + _patches.vehicle_speed;
 
					SetDParam(0, v->u.rail.last_speed);
 
				} else
 
				} else {
 
					str = STR_EMPTY;
 
				}
 
				break;
 
			}
 
		}
 
@@ -1308,8 +1305,7 @@ do_change_service_int:
 
		break;
 

	
 
	case WE_RESIZE:
 
		if (e->sizing.diff.y == 0)
 
			break;
 
		if (e->sizing.diff.y == 0) break;
 

	
 
		w->vscroll.cap += e->sizing.diff.y / 14;
 
		w->widget[4].unkA = (w->vscroll.cap << 8) + 1;
 
@@ -1418,8 +1414,7 @@ static void PlayerTrainsWndProc(Window *
 
		SetVScrollCount(w, vl->list_length);
 

	
 
		// disable 'Sort By' tooltip on Unsorted sorting criteria
 
		if (vl->sort_type == SORT_BY_UNSORTED)
 
			w->disabled_state |= (1 << 3);
 
		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
 

	
 
		/* draw the widgets */
 
		{
 
@@ -1454,10 +1449,11 @@ static void PlayerTrainsWndProc(Window *
 
			DrawVehicleProfitButton(v, x, y + 13);
 

	
 
			SetDParam(0, v->unitnumber);
 
			if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN))
 
			if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) {
 
				str = STR_021F;
 
			else
 
			} else {
 
				str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
 
			}
 
			DrawString(x, y + 2, str, 0);
 

	
 
			SetDParam(0, v->profit_this_year);
 
@@ -1489,14 +1485,12 @@ static void PlayerTrainsWndProc(Window *
 

	
 
		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;
 
			const Vehicle* v;
 

	
 
			if (id_v >= w->vscroll.cap) return; // click out of bounds
 

	
 
			id_v += w->vscroll.pos;
 

	
 
			{
 
				Vehicle *v;
 

	
 
				if (id_v >= vl->list_length) return; // click out of list bound
 

	
 
				v = GetVehicle(vl->sort_list[id_v].index);
 
@@ -1504,7 +1498,6 @@ static void PlayerTrainsWndProc(Window *
 
				assert(v->type == VEH_Train && IsFrontEngine(v) && v->owner == owner);
 

	
 
				ShowTrainViewWindow(v);
 
			}
 
		} break;
 

	
 
		case 9: /* Build new Vehicle */
 
@@ -1512,13 +1505,10 @@ static void PlayerTrainsWndProc(Window *
 
			ShowBuildTrainWindow(0);
 
			break;
 

	
 
		case 10: {
 
			if (!IsWindowOfPrototype(w, _player_trains_widgets))
 
				break;
 

	
 
		case 10:
 
			if (IsWindowOfPrototype(w, _player_trains_widgets)) break;
 
			ShowReplaceVehicleWindow(VEH_Train);
 
			break;
 
 		}
 

	
 
		}
 
	}	break;
 
@@ -1531,8 +1521,7 @@ static void PlayerTrainsWndProc(Window *
 
			_sorting.train.criteria = vl->sort_type;
 

	
 
			// enable 'Sort By' if a sorter criteria is chosen
 
			if (vl->sort_type != SORT_BY_UNSORTED)
 
				CLRBIT(w->disabled_state, 3);
 
			if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
 
		}
 
		SetWindowDirty(w);
 
		break;
 
@@ -1592,7 +1581,7 @@ void ShowPlayerTrains(PlayerID player, S
 
	} else {
 
		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
 
	}
 
	if (w) {
 
	if (w != NULL) {
 
		w->caption_color = player;
 
		w->hscroll.cap = 10 * 29;
 
		w->vscroll.cap = 7; // maximum number of vehicles shown
tunnelbridge_cmd.c
Show inline comments
 
@@ -142,8 +142,9 @@ static uint32 CheckBridgeSlope(Axis dire
 
	}
 

	
 
	// slope foundations
 
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION | BRIDGE_PARTLY_LEVELED_FOUNDATION, tileh))
 
	if (HASBIT(BRIDGE_FULL_LEVELED_FOUNDATION | BRIDGE_PARTLY_LEVELED_FOUNDATION, tileh)) {
 
		return _price.terraform;
 
	}
 

	
 
	return CMD_ERROR;
 
}
unix.c
Show inline comments
 
@@ -302,10 +302,11 @@ char *FiosBrowseTo(const FiosItem *item)
 
	switch (item->type) {
 
		case FIOS_TYPE_PARENT:
 
			s = strrchr(path, '/');
 
			if (s != path)
 
			if (s != path) {
 
				s[0] = '\0';
 
			else
 
			} else {
 
				s[1] = '\0';
 
			}
 
			break;
 

	
 
		case FIOS_TYPE_DIR:
 
@@ -351,9 +352,10 @@ StringID FiosGetDescText(const char **pa
 

	
 
		if (statvfs(*path, &s) == 0) {
 
			free = (uint64)s.f_frsize * s.f_bavail >> 20;
 
		} else
 
		} else {
 
			return STR_4006_UNABLE_TO_READ_DRIVE;
 
	}
 
	}
 
#endif
 
	if (tot != NULL) *tot = free;
 
	return STR_4005_BYTES_FREE;
 
@@ -364,10 +366,7 @@ void FiosMakeSavegameName(char *buf, con
 
	const char* extension;
 
	const char* period;
 

	
 
	if (_game_mode == GM_EDITOR)
 
		extension = ".scn";
 
	else
 
		extension = ".sav";
 
	extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
 

	
 
	// Don't append the extension, if it is already there
 
	period = strrchr(name, '.');
unmovable_cmd.c
Show inline comments
 
@@ -51,8 +51,7 @@ void UpdateCompanyHQ(Player *p, uint sco
 
	byte val;
 
	TileIndex tile = p->location_of_house;
 

	
 
	if (tile == 0)
 
		return;
 
	if (tile == 0) return;
 

	
 
	(val = 0, score < 170) ||
 
	(val++, score < 350) ||
 
@@ -110,8 +109,7 @@ static void DrawTile_Unmovable(TileInfo 
 

	
 
	switch (GetUnmovableType(ti->tile)) {
 
		case UNMOVABLE_TRANSMITTER:
 
		case UNMOVABLE_LIGHTHOUSE:
 
			{
 
		case UNMOVABLE_LIGHTHOUSE: {
 
				const DrawTileUnmovableStruct *dtus;
 

	
 
				if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, ti->tileh);
 
@@ -122,9 +120,13 @@ static void DrawTile_Unmovable(TileInfo 
 
				image = dtus->image;
 
				if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
 

	
 
				AddSortableSpriteToDraw(image, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
 
					dtus->width, dtus->height, dtus->z_size, ti->z);
 
			} break;
 
			AddSortableSpriteToDraw(
 
				image, ti->x | dtus->subcoord_x, ti->y | dtus->subcoord_y,
 
				dtus->width, dtus->height, dtus->z_size, ti->z
 
			);
 
			break;
 
		}
 

	
 
		case UNMOVABLE_STATUE:
 
			DrawGroundSprite(SPR_CONCRETE_GROUND);
 

	
 
@@ -133,6 +135,7 @@ static void DrawTile_Unmovable(TileInfo 
 
			if (_display_opt & DO_TRANS_BUILDINGS) MAKE_TRANSPARENT(image);
 
			AddSortableSpriteToDraw(image, ti->x, ti->y, 16, 16, 25, ti->z);
 
			break;
 

	
 
		case UNMOVABLE_OWNED_LAND:
 
			DrawClearLandTile(ti, 0);
 

	
 
@@ -140,10 +143,9 @@ static void DrawTile_Unmovable(TileInfo 
 
				PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)) + PALETTE_MODIFIER_COLOR + SPR_BOUGHT_LAND,
 
				ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, 10, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2)
 
			);
 
			break;
 

	
 
			break;
 
		default:
 
			{
 
		default: {
 
				const DrawTileSeqStruct *dtss;
 
				const DrawTileSprites *t;
 

	
 
@@ -162,10 +164,13 @@ static void DrawTile_Unmovable(TileInfo 
 
					} else {
 
						image |= ormod;
 
					}
 
					AddSortableSpriteToDraw(image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
						dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z);
 
				AddSortableSpriteToDraw(
 
					image, ti->x + dtss->delta_x, ti->y + dtss->delta_y,
 
					dtss->width, dtss->height, dtss->unk, ti->z + dtss->delta_z
 
				);
 
				}
 
			} break;
 
			break;
 
		}
 
	}
 
}
 

	
vehicle.c
Show inline comments
 
@@ -637,7 +637,9 @@ static bool CanFillVehicle_FullLoadAny(V
 

	
 
	//if the aircraft carries passengers and is NOT full, then
 
	//continue loading, no matter how much mail is in
 
	if ((v->type == VEH_Aircraft) && (v->cargo_type == CT_PASSENGERS) && (v->cargo_cap != v->cargo_count)) {
 
	if (v->type == VEH_Aircraft &&
 
			v->cargo_type == CT_PASSENGERS &&
 
			v->cargo_cap != v->cargo_count) {
 
		return true;
 
	}
 

	
 
@@ -648,7 +650,12 @@ static bool CanFillVehicle_FullLoadAny(V
 

	
 
		if (v->cargo_cap != 0) {
 
			uint32 mask = 1 << v->cargo_type;
 
			if (v->cargo_cap == v->cargo_count) full |= mask; else not_full |= mask;
 

	
 
			if (v->cargo_cap == v->cargo_count) {
 
				full |= mask;
 
			} else {
 
				not_full |= mask;
 
			}
 
		}
 
	} while ( (v=v->next) != NULL);
 

	
 
@@ -670,12 +677,10 @@ bool CanFillVehicle(Vehicle *v)
 
			))) {
 

	
 
		// If patch is active, use alternative CanFillVehicle-function
 
		if (_patches.full_load_any)
 
			return CanFillVehicle_FullLoadAny(v);
 
		if (_patches.full_load_any) return CanFillVehicle_FullLoadAny(v);
 

	
 
		do {
 
			if (v->cargo_count != v->cargo_cap)
 
				return true;
 
			if (v->cargo_count != v->cargo_cap) return true;
 
		} while ( (v=v->next) != NULL);
 
	}
 
	return false;
 
@@ -754,14 +759,12 @@ void ViewportAddVehicles(DrawPixelInfo *
 
				veh = v->next_hash;
 
			}
 

	
 
			if (x == x2)
 
				break;
 
			if (x == x2) break;
 
			x = (x + 1) & 0x3F;
 
		}
 
		x = xb;
 

	
 
		if (y == y2)
 
			break;
 
		if (y == y2) break;
 
		y = (y + 0x40) & ((0x3F) << 6);
 
	}
 
}
video/sdl_v.c
Show inline comments
 
@@ -362,18 +362,21 @@ static int PollEvent(void)
 
			if (_patches.autosave_on_exit) {
 
				DoExitSave();
 
				return 0;
 
			} else
 
			} else {
 
				AskExitGame();
 
		} else
 
			}
 
		} else {
 
			return 0;
 
		}
 
		break;
 

	
 
		case SDL_KEYDOWN: /* Toggle full-screen on ALT + ENTER/F */
 
		if ((ev.key.keysym.mod & (KMOD_ALT | KMOD_META)) &&
 
				(ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) {
 
			ToggleFullScreen(!_fullscreen);
 
		} else
 
		} else {
 
			_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym);
 
		}
 

	
 
		break;
 

	
video/win32_v.c
Show inline comments
 
@@ -252,8 +252,7 @@ static LRESULT CALLBACK WndProcGdi(HWND 
 
		UINT nChanged = RealizePalette(hDC);
 
		SelectPalette(hDC, hOldPalette, TRUE);
 
		ReleaseDC(hwnd, hDC);
 
		if (nChanged)
 
			InvalidateRect(hwnd, NULL, FALSE);
 
		if (nChanged) InvalidateRect(hwnd, NULL, FALSE);
 
		return 0;
 
	}
 

	
 
@@ -263,9 +262,9 @@ static LRESULT CALLBACK WndProcGdi(HWND 
 
		} else if (_patches.autosave_on_exit) {
 
			DoExitSave();
 
			_exit_game = true;
 
		} else
 
		} else {
 
			AskExitGame();
 

	
 
		}
 
		return 0;
 

	
 
	case WM_LBUTTONDOWN:
 
@@ -787,8 +786,9 @@ static void Win32GdiMainLoop(void)
 
#endif
 
			    !_networking && _game_mode != GM_MENU)
 
				_fast_forward |= 2;
 
		} else if (_fast_forward & 2)
 
		} else if (_fast_forward & 2) {
 
			_fast_forward = 0;
 
		}
 

	
 
		cur_ticks = GetTickCount();
 
		if ((_fast_forward && !_pause) || cur_ticks > next_tick)
 
@@ -809,14 +809,14 @@ static void Win32GdiMainLoop(void)
 
					(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
 
					(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
 
					(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
 
			} else
 
			} else {
 
				_dirkeys = 0;
 
			}
 

	
 
			GameLoop();
 
			_cursor.delta.x = _cursor.delta.y = 0;
 

	
 
			if (_force_full_redraw)
 
				MarkWholeScreenDirty();
 
			if (_force_full_redraw) MarkWholeScreenDirty();
 

	
 
			GdiFlush();
 
			_screen.dst_ptr = _wnd.buffer_bits;
viewport.c
Show inline comments
 
@@ -1955,25 +1955,28 @@ static void CalcRaildirsDrawstyle(TileHi
 
	h = myabs(dy) + 16;
 

	
 
	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
 
		if (method == VPM_RAILDIRS)
 
		if (method == VPM_RAILDIRS) {
 
			b = GetAutorailHT(x, y);
 
		else // rect for autosignals on one tile
 
		} else { // rect for autosignals on one tile
 
			b = HT_RECT;
 
		}
 
	} else if (h == 16) { // Is this in X direction?
 
		if (dx == 16) // 2x1 special handling
 
		if (dx == 16) { // 2x1 special handling
 
			b = (Check2x1AutoRail(3)) | HT_LINE;
 
		else if (dx == -16)
 
		} else if (dx == -16) {
 
			b = (Check2x1AutoRail(2)) | HT_LINE;
 
		else
 
		} else {
 
			b = HT_LINE | HT_DIR_X;
 
		}
 
		y = thd->selstart.y;
 
	} else if (w == 16) { // Or Y direction?
 
		if (dy == 16) // 2x1 special handling
 
		if (dy == 16) { // 2x1 special handling
 
			b = (Check2x1AutoRail(1)) | HT_LINE;
 
		else if (dy == -16) // 2x1 other direction
 
		} else if (dy == -16) { // 2x1 other direction
 
			b = (Check2x1AutoRail(0)) | HT_LINE;
 
		else
 
		} else {
 
			b = HT_LINE | HT_DIR_Y;
 
		}
 
		x = thd->selstart.x;
 
	} else if (w > h * 2) { // still count as x dir?
 
		b = HT_LINE | HT_DIR_X;
 
@@ -2082,7 +2085,11 @@ void VpSelectTilesWithMethod(int x, int 
 
			break;
 

	
 
		case VPM_X_OR_Y:
 
			if (myabs(sy - y) < myabs(sx - x)) y = sy; else x = sx;
 
			if (myabs(sy - y) < myabs(sx - x)) {
 
				y = sy;
 
			} else {
 
				x = sx;
 
			}
 
			break;
 

	
 
		case VPM_X_AND_Y:
 
@@ -2196,5 +2203,5 @@ void SetObjectToPlace(CursorID icon, byt
 

	
 
void ResetObjectToPlace(void)
 
{
 
	SetObjectToPlace(SPR_CURSOR_MOUSE, 0, 0, 0);
 
	SetObjectToPlace(SPR_CURSOR_MOUSE, VHM_NONE, 0, 0);
 
}
water_cmd.c
Show inline comments
 
@@ -337,7 +337,6 @@ static int32 ClearTile_Water(TileIndex t
 

	
 
		case WATER_DEPOT:
 
			if (flags & DC_AUTO) return_cmd_error(STR_2004_BUILDING_MUST_BE_DEMOLISHED);
 

	
 
			return RemoveShipDepot(tile, flags);
 

	
 
		default:
waypoint.c
Show inline comments
 
@@ -34,8 +34,7 @@ static void WaypointPoolNewBlock(uint st
 
{
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS_FROM(wp, start_item)
 
		wp->index = start_item++;
 
	FOR_ALL_WAYPOINTS_FROM(wp, start_item) wp->index = start_item++;
 
}
 

	
 
/* Initialize the town-pool */
 
@@ -50,7 +49,7 @@ static Waypoint* AllocateWaypoint(void)
 
		if (wp->xy == 0) {
 
			uint index = wp->index;
 

	
 
			memset(wp, 0, sizeof(Waypoint));
 
			memset(wp, 0, sizeof(*wp));
 
			wp->index = index;
 

	
 
			return wp;
 
@@ -58,8 +57,7 @@ static Waypoint* AllocateWaypoint(void)
 
	}
 

	
 
	/* Check if we can add a block to the pool */
 
	if (AddBlockToPool(&_waypoint_pool))
 
		return AllocateWaypoint();
 
	if (AddBlockToPool(&_waypoint_pool)) return AllocateWaypoint();
 

	
 
	return NULL;
 
}
 
@@ -88,8 +86,7 @@ void UpdateAllWaypointSigns(void)
 
	Waypoint *wp;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->xy)
 
			UpdateWaypointSign(wp);
 
		if (wp->xy != 0) UpdateWaypointSign(wp);
 
	}
 
}
 

	
 
@@ -106,8 +103,7 @@ static void MakeDefaultWaypointName(Wayp
 

	
 
	/* Find an unused waypoint number belonging to this town */
 
	FOR_ALL_WAYPOINTS(local_wp) {
 
		if (wp == local_wp)
 
			continue;
 
		if (wp == local_wp) continue;
 

	
 
		if (local_wp->xy && local_wp->string == STR_NULL && local_wp->town_index == wp->town_index)
 
			used_waypoint[local_wp->town_cn] = true;
 
@@ -124,11 +120,12 @@ static void MakeDefaultWaypointName(Wayp
 
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile)
 
{
 
	Waypoint *wp, *best = NULL;
 
	uint thres = 8, cur_dist;
 
	uint thres = 8;
 

	
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->deleted && wp->xy) {
 
			cur_dist = DistanceManhattan(tile, wp->xy);
 
		if (wp->deleted && wp->xy != 0) {
 
			uint cur_dist = DistanceManhattan(tile, wp->xy);
 

	
 
			if (cur_dist < thres) {
 
				thres = cur_dist;
 
				best = wp;
 
@@ -190,14 +187,12 @@ int32 CmdBuildTrainWaypoint(TileIndex ti
 
		return_cmd_error(STR_1005_NO_SUITABLE_RAILROAD_TRACK);
 
	}
 

	
 
	if (!CheckTileOwnership(tile))
 
		return CMD_ERROR;
 

	
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
 

	
 
	tileh = GetTileSlope(tile, NULL);
 
	if (tileh != SLOPE_FLAT) {
 
		if (!_patches.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))
 
	if (tileh != SLOPE_FLAT &&
 
			(!_patches.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
 
			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
 
	}
 

	
 
@@ -255,8 +250,7 @@ static void DoDeleteWaypoint(Waypoint *w
 
	order.station = wp->index;
 
	DeleteDestinationFromVehicleOrder(order);
 

	
 
	if (wp->string != STR_NULL)
 
		DeleteName(wp->string);
 
	if (wp->string != STR_NULL) DeleteName(wp->string);
 

	
 
	RedrawWaypointSign(wp);
 
}
 
@@ -268,9 +262,7 @@ void WaypointsDailyLoop(void)
 

	
 
	/* Check if we need to delete a waypoint */
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->deleted && !--wp->deleted) {
 
			DoDeleteWaypoint(wp);
 
		}
 
		if (wp->deleted != 0 && --wp->deleted == 0) DoDeleteWaypoint(wp);
 
	}
 
}
 

	
 
@@ -280,14 +272,12 @@ int32 RemoveTrainWaypoint(TileIndex tile
 
	Waypoint *wp;
 

	
 
	/* Make sure it's a waypoint */
 
	if (!IsTileType(tile, MP_RAILWAY) || !IsRailWaypoint(tile))
 
	if (!IsTileType(tile, MP_RAILWAY) ||
 
			!IsRailWaypoint(tile) ||
 
			(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) ||
 
			!EnsureNoVehicle(tile)) {
 
		return CMD_ERROR;
 

	
 
	if (!CheckTileOwnership(tile) && !(_current_player == OWNER_WATER))
 
		return CMD_ERROR;
 

	
 
	if (!EnsureNoVehicle(tile))
 
		return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		wp = GetWaypointByTile(tile);
 
@@ -327,19 +317,17 @@ int32 CmdRemoveTrainWaypoint(TileIndex t
 
int32 CmdRenameWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Waypoint *wp;
 
	StringID str;
 

	
 
	if (!IsWaypointIndex(p1)) return CMD_ERROR;
 

	
 
	if (_cmd_text[0] != '\0') {
 
		str = AllocateNameUnique(_cmd_text, 0);
 
		if (str == 0)
 
			return CMD_ERROR;
 
		StringID str = AllocateNameUnique(_cmd_text, 0);
 

	
 
		if (str == 0) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			wp = GetWaypoint(p1);
 
			if (wp->string != STR_NULL)
 
				DeleteName(wp->string);
 
			if (wp->string != STR_NULL) DeleteName(wp->string);
 

	
 
			wp->string = str;
 
			wp->town_cn = 0;
 
@@ -352,8 +340,7 @@ int32 CmdRenameWaypoint(TileIndex tile, 
 
	} else {
 
		if (flags & DC_EXEC) {
 
			wp = GetWaypoint(p1);
 
			if (wp->string != STR_NULL)
 
				DeleteName(wp->string);
 
			if (wp->string != STR_NULL) DeleteName(wp->string);
 

	
 
			MakeDefaultWaypointName(wp);
 
			UpdateWaypointSign(wp);
 
@@ -395,8 +382,7 @@ void FixOldWaypoints(void)
 

	
 
	/* Convert the old 'town_or_string', to 'string' / 'town' / 'town_cn' */
 
	FOR_ALL_WAYPOINTS(wp) {
 
		if (wp->xy == 0)
 
			continue;
 
		if (wp->xy == 0) continue;
 

	
 
		wp->town_index = ClosestTownFromTile(wp->xy, (uint)-1)->index;
 
		wp->town_cn = 0;
win32.c
Show inline comments
 
@@ -50,7 +50,7 @@ bool LoadLibraryList(Function proc[], co
 
		HMODULE lib = LoadLibrary(dll);
 

	
 
		if (lib == NULL) return false;
 
		while (true) {
 
		for (;;) {
 
		  	FARPROC p;
 

	
 
			while (*dll++ != '\0');
 
@@ -108,10 +108,7 @@ static void MakeCRCTable(uint32 *table) 
 
	for (i = 0; i != 256; i++) {
 
		crc = i;
 
		for (j = 8; j != 0; j--) {
 
			if (crc & 1)
 
				crc = (crc >> 1) ^ poly;
 
			else
 
				crc >>= 1;
 
			src = (crc & 1 ? (crc >> 1) ^ poly : crc >> 1);
 
		}
 
		table[i] = crc;
 
	}
 
@@ -369,10 +366,11 @@ static INT_PTR CALLBACK CrashDialogFunc(
 
		case 12: // Close
 
			ExitProcess(0);
 
		case 13: { // Emergency save
 
			if (DoEmergencySave(wnd))
 
			if (DoEmergencySave(wnd)) {
 
				MessageBoxA(wnd, _save_succeeded, "Save successful", MB_ICONINFORMATION);
 
			else
 
			} else {
 
				MessageBoxA(wnd, "Save failed", "Save failed", MB_ICONINFORMATION);
 
			}
 
			break;
 
		}
 
		case 14: { // Submit crash report
 
@@ -904,10 +902,11 @@ char *FiosBrowseTo(const FiosItem *item)
 

	
 
		case FIOS_TYPE_PARENT:
 
			s = strrchr(path, '\\');
 
			if (s != path + 2)
 
			if (s != path + 2) {
 
				s[0] = '\0';
 
			else
 
			} else {
 
				s[1] = '\0';
 
			}
 
			break;
 

	
 
		case FIOS_TYPE_DIR:
 
@@ -955,8 +954,9 @@ StringID FiosGetDescText(const char **pa
 
	if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
 
		*tot = ((spc * bps) * (uint64)nfc) >> 20;
 
		sid = STR_4005_BYTES_FREE;
 
	} else
 
	} else {
 
		sid = STR_4006_UNABLE_TO_READ_DRIVE;
 
	}
 

	
 
	SetErrorMode(sem); // reset previous setting
 
	return sid;
 
@@ -967,10 +967,7 @@ void FiosMakeSavegameName(char *buf, con
 
	const char* extension;
 
	const char* period;
 

	
 
	if (_game_mode == GM_EDITOR)
 
		extension = ".scn";
 
	else
 
		extension = ".sav";
 
	extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
 

	
 
	// Don't append the extension, if it is already there
 
	period = strrchr(name, '.');
 
@@ -1091,9 +1088,9 @@ void CreateConsole(void)
 

	
 
void ShowInfo(const char *str)
 
{
 
	if (_has_console)
 
	if (_has_console) {
 
		puts(str);
 
	else {
 
	} else {
 
		bool old;
 

	
 
		ReleaseCapture();
window.c
Show inline comments
 
@@ -43,8 +43,7 @@ static void DispatchLeftClickEvent(Windo
 
		wi = &w->widget[e.click.widget];
 

	
 
		/* don't allow any interaction if the button has been disabled */
 
		if (HASBIT(w->disabled_state, e.click.widget))
 
			return;
 
		if (HASBIT(w->disabled_state, e.click.widget)) return;
 

	
 
		if (wi->type & 0xE0) {
 
			/* special widget handling for buttons*/
 
@@ -230,13 +229,14 @@ void DeleteWindow(Window *w)
 
{
 
	WindowClass wc;
 
	WindowNumber wn;
 
	ViewPort *vp;
 
	Window *v;
 
	int count;
 

	
 
	if (w == NULL) return;
 

	
 
	if (_thd.place_mode != 0 && _thd.window_class == w->window_class && _thd.window_number == w->window_number) {
 
	if (_thd.place_mode != VHM_NONE &&
 
			_thd.window_class == w->window_class &&
 
			_thd.window_number == w->window_number) {
 
		ResetObjectToPlace();
 
	}
 

	
 
@@ -247,11 +247,10 @@ void DeleteWindow(Window *w)
 

	
 
	w = FindWindowById(wc, wn);
 

	
 
	vp = w->viewport;
 
	if (w->viewport != NULL) {
 
		CLRBIT(_active_viewports, w->viewport - _viewports);
 
		w->viewport->width = 0;
 
	w->viewport = NULL;
 
	if (vp != NULL) {
 
		_active_viewports &= ~(1 << (vp - _viewports));
 
		vp->width = 0;
 
	}
 

	
 
	SetWindowDirty(w);
 
@@ -647,8 +646,11 @@ Window *AllocateWindowDesc(const WindowD
 
			pt = GetAutoPlacePosition(desc->width, desc->height);
 
		} else {
 
			if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1;
 
			if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1;
 
			else if(pt.y < 0) pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen
 
			if (pt.y == WDP_CENTER) {
 
				pt.y = (_screen.height - desc->height) >> 1;
 
			} else if (pt.y < 0) {
 
				pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen
 
			}
 
		}
 
	}
 

	
 
@@ -1618,10 +1620,11 @@ void DeleteAllNonVitalWindows(void)
 
		if (w->flags4 & WF_STICKY) {
 
			DeleteWindow(w);
 
			w = _windows;
 
		} else
 
		} else {
 
			w++;
 
	}
 
}
 
}
 

	
 
/* Delete all always on-top windows to get an empty screen */
 
void HideVitalWindows(void)
 
@@ -1634,8 +1637,9 @@ int PositionMainToolbar(Window *w)
 
{
 
	DEBUG(misc, 1) ("Repositioning Main Toolbar...");
 

	
 
	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR)
 
	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
 
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
 
	}
 

	
 
	switch (_patches.toolbar_pos) {
 
		case 1:  w->left = (_screen.width - w->width) >> 1; break;
0 comments (0 inline, 0 general)