Changeset - r193:6aa65dc5a4b4
[Not reviewed]
master
! ! !
truelight - 20 years ago 2004-09-10 19:02:27
truelight@openttd.org
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
54 files changed:
0 comments (0 inline, 0 general)
ai.c
Show inline comments
 
@@ -68,7 +68,7 @@ static void AiCase1(Player *p)
 
static void AiStateVehLoop(Player *p)
 
{
 
	Vehicle *v;
 
	
 

	
 
	v = p->ai.cur_veh == NULL ? _vehicles : p->ai.cur_veh+1;
 

	
 
	for (;v != endof(_vehicles); v++) {
 
@@ -79,7 +79,7 @@ static void AiStateVehLoop(Player *p)
 
				v->type == VEH_Road ||
 
				(v->type == VEH_Aircraft && v->subtype <= 2) ||
 
				v->type == VEH_Ship) {
 
			
 

	
 
			/* replace engine? */
 
			if (v->type == VEH_Train && v->engine_type < 3 &&
 
					(_price.build_railvehicle >> 3) < p->player_money) {
 
@@ -115,7 +115,7 @@ static void AiStateVehLoop(Player *p)
 

	
 
// XXX
 
static const byte _rail_locos_count[3] = {
 
	27, 3, 5		
 
	27, 3, 5
 
};
 
extern const byte _rail_engines_start[3];
 

	
 
@@ -130,14 +130,14 @@ static int AiChooseTrainToBuild(byte rai
 
	Engine *e = &_engines[i];
 
	do {
 
		assert(!(_rail_vehicle_info[i].flags & RVI_WAGON));
 
		
 

	
 
		if (!HASBIT(e->player_avail, _current_player) || e->reliability < 0x8A3D)
 
			continue;
 

	
 
		r = DoCommandByTile(0, i, 0, 0, CMD_BUILD_RAIL_VEHICLE);
 
		if (r != CMD_ERROR && 
 
					(!(_cmd_build_rail_veh_var1&1) || !(flag&1)) && 
 
					r <= money && 
 
		if (r != CMD_ERROR &&
 
					(!(_cmd_build_rail_veh_var1&1) || !(flag&1)) &&
 
					r <= money &&
 
				_cmd_build_rail_veh_score >= best_veh_score) {
 
			best_veh_score = _cmd_build_rail_veh_score;
 
			best_veh_index = i;
 
@@ -206,7 +206,7 @@ static int32 AiGetBasePrice(Player *p)
 
	// adjust base price when more expensive vehicles are available
 
	if (p->ai.railtype_to_use == 1) base = (base * 3) >> 1;
 
	else if (p->ai.railtype_to_use == 2) base *= 2;
 
	
 

	
 
	return base;
 
}
 

	
 
@@ -266,7 +266,7 @@ static void AiHandleGotoDepot(Player *p,
 
		p->ai.cur_veh->next_order = OT_DUMMY;
 
		InvalidateWindow(WC_VEHICLE_VIEW, p->ai.cur_veh->index);
 
	}
 
} 
 
}
 

	
 
static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
 
{
 
@@ -296,7 +296,7 @@ static void AiHandleReplaceTrain(Player 
 
	if (veh != -1) {
 
		BackupVehicleOrders(v, orderbak);
 
		tile = v->tile;
 
		
 

	
 
		if (DoCommandByTile(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON) != CMD_ERROR &&
 
			 DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE) != CMD_ERROR) {
 
			veh = _new_train_id;
 
@@ -324,7 +324,7 @@ static void AiHandleReplaceRoadVeh(Playe
 
	if (veh != -1) {
 
		BackupVehicleOrders(v, orderbak);
 
		tile = v->tile;
 
		
 

	
 
		if (DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_SELL_ROAD_VEH) != CMD_ERROR &&
 
			 DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_ROAD_VEH) != CMD_ERROR) {
 
			veh = _new_roadveh_id;
 
@@ -437,7 +437,7 @@ static void AiFindSubsidyIndustryRoute(F
 
	// initially error
 
	fr->distance = -1;
 

	
 
	// Randomize subsidy index.. 
 
	// Randomize subsidy index..
 
	i = RandomRange(lengthof(_subsidies) * 3);
 
	if (i >= lengthof(_subsidies))
 
		return;
 
@@ -476,7 +476,7 @@ static void AiFindSubsidyPassengerRoute(
 
	// initially error
 
	fr->distance = -1;
 

	
 
	// Randomize subsidy index.. 
 
	// Randomize subsidy index..
 
	i = RandomRange(lengthof(_subsidies) * 3);
 
	if (i >= lengthof(_subsidies))
 
		return;
 
@@ -512,7 +512,7 @@ static void AiFindRandomIndustryRoute(Fo
 

	
 
	// pick a source
 
	fr->from = i = AiFindRandomIndustry();
 
	if (i == NULL)	
 
	if (i == NULL)
 
		return;
 

	
 
	// pick a random produced cargo
 
@@ -539,7 +539,7 @@ static void AiFindRandomIndustryRoute(Fo
 
		t = AiFindRandomTown();
 
		if (t == NULL || t->population < (uint32)(cargo == CT_FOOD ? 200 : 900))
 
			return;
 
		
 

	
 
		fr->to = t;
 
		fr->distance = GetTileDist(i->xy, t->xy);
 
	}
 
@@ -558,7 +558,7 @@ static void AiFindRandomPassengerRoute(F
 
	fr->from = source = AiFindRandomTown();
 
	if (source == NULL || source->population < 400)
 
		return;
 
	
 

	
 
	fr->to = dest = AiFindRandomTown();
 
	if (dest == NULL || source == dest || dest->population < 400)
 
		return;
 
@@ -589,7 +589,7 @@ static bool AiCheckIfRouteIsGood(Player 
 
		if (to_tile == from_tile && st->xy == to_tile)
 
		    same_station++;
 
	}
 
	
 

	
 
	// To prevent the AI from building ten busstations in the same town, do some calculations
 
	//  For each road or airport station, we want 350 of population!
 
	if ((bitmask == 2 || bitmask == 4) && same_station > 2 && ((Town *)(fr->from))->population < same_station * 350)
 
@@ -612,8 +612,8 @@ static bool AiCheckIfRouteIsGood(Player 
 
			return false;
 
	} else {
 
		Industry *i = (Industry*)fr->from;
 
		
 
		if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 || 
 

	
 
		if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
 
				i->total_production[fr->cargo != i->produced_cargo[0]] == 0)
 
			return false;
 
	}
 
@@ -680,7 +680,7 @@ static void AiWantLongIndustryRoute(Play
 
	p->ai.src.cargo = fr.cargo | 0x80;
 

	
 
	// Fill the dest field
 
	
 

	
 
	p->ai.dst.use_tile = 0;
 
	p->ai.dst.rand_rng = 9;
 
	p->ai.dst.cur_building_rule = 0xFF;
 
@@ -751,7 +751,7 @@ static void AiWantMediumIndustryRoute(Pl
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyIndustryRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 40, 60+1))
 
@@ -824,7 +824,7 @@ static void AiWantShortIndustryRoute(Pla
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyIndustryRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 15, 40+1))
 
@@ -897,7 +897,7 @@ static void AiWantMailRoute(Player *p)
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyPassengerRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 60, 110+1))
 
@@ -1003,7 +1003,7 @@ static void AiWantPassengerRoute(Player 
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyPassengerRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 0, 55+1))
 
@@ -1075,7 +1075,7 @@ static void AiWantTrainRoute(Player *p)
 
	uint16 r;
 
	p->ai.railtype_to_use = p->max_railtype - 1;
 
	r = (uint16)Random();
 
	
 

	
 
	if (r > 0xD000) {
 
		AiWantLongIndustryRoute(p);
 
	} else if (r > 0x6000) {
 
@@ -1096,7 +1096,7 @@ static void AiWantLongRoadIndustryRoute(
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyIndustryRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 35, 55+1))
 
@@ -1157,7 +1157,7 @@ static void AiWantMediumRoadIndustryRout
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyIndustryRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 15, 40+1))
 
@@ -1218,7 +1218,7 @@ static void AiWantLongRoadPassengerRoute
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyPassengerRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance, 55, 180+1))
 
@@ -1356,7 +1356,7 @@ static void AiWantPassengerAircraftRoute
 

	
 
	i = 60;
 
	for(;;) {
 
		
 

	
 
		// look for one from the subsidy list
 
		AiFindSubsidyPassengerRoute(&fr);
 
		if (IS_INT_INSIDE(fr.distance,0,95+1))
 
@@ -1401,7 +1401,7 @@ static void AiWantPassengerAircraftRoute
 
	p->ai.order_list_blocks[0] = 0;
 
	p->ai.order_list_blocks[1] = 1;
 
	p->ai.order_list_blocks[2] = 255;
 
	
 

	
 
	p->ai.state = AIS_AIRPORT_STUFF;
 
	p->ai.timeout_counter = 0;
 
}
 
@@ -1498,11 +1498,11 @@ static void AiStateWantNewRoute(Player *
 
	i = 200;
 
	for(;;) {
 
		r = (uint16)Random();
 
		
 

	
 
		if (_patches.ai_disable_veh_train && _patches.ai_disable_veh_roadveh &&
 
			_patches.ai_disable_veh_aircraft && _patches.ai_disable_veh_ship)
 
			return;
 
		
 

	
 
		if (r < 0x7626) {
 
			if (_patches.ai_disable_veh_train) continue;
 
			AiWantTrainRoute(p);
 
@@ -1516,7 +1516,7 @@ static void AiStateWantNewRoute(Player *
 
			if (_patches.ai_disable_veh_ship) continue;
 
			AiWantShipRoute(p);
 
		}
 
		
 

	
 
		// got a route?
 
		if (p->ai.state != AIS_WANT_NEW_ROUTE)
 
			break;
 
@@ -1598,7 +1598,7 @@ clear_town_stuff:;
 

	
 
			j = p->attr;
 
			k = 0;
 
			
 

	
 
			// Build the rail
 
			for(i=0; i!=6; i++,j>>=1) {
 
				if (j&1) {
 
@@ -1608,7 +1608,7 @@ clear_town_stuff:;
 
					total_cost += r;
 
				}
 
			}
 
			
 

	
 
			/* signals too? */
 
			if (j&3) {
 
				// Can't build signals on a road.
 
@@ -1643,7 +1643,7 @@ clear_town_stuff:;
 
			// Unk
 
			break;
 
		}
 
		
 

	
 
		p++;
 
	}
 

	
 
@@ -1663,7 +1663,7 @@ static int AiBuildDefaultRailTrack(TileI
 
	const AiDefaultRailBlock *p;
 

	
 
	for(i=0; (p = _default_rail_track_data[i]) != NULL; i++) {
 
		if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 && 
 
		if (p->p0 == p0 && p->p1 == p1 && p->p2 == p2 && p->p3 == p3 &&
 
				(p->dir == 0xFF || p->dir == dir || ((p->dir-1)&3) == dir)) {
 
			*cost = AiDoBuildDefaultRailTrack(tile, p->data, DC_NO_TOWN_RATING);
 
			if (*cost != CMD_ERROR && AiCheckTrackResources(tile, p->data, cargo))
 
@@ -1723,7 +1723,7 @@ static void AiDoTerraformLand(TileIndex 
 
	} while (--unk >= 0);
 

	
 
	slope = GetTileSlope(tile, &h);
 
	
 

	
 
	if (slope != 0) {
 
		if (mode > 0 || (mode == 0 && !(r&0xC))) {
 
			// Terraform up
 
@@ -1731,9 +1731,9 @@ static void AiDoTerraformLand(TileIndex 
 
				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
		} else if (h != 0) {
 
			// Terraform down
 
			DoCommandByTile(tile, _terraform_down_flags[slope-1], 0, 
 
			DoCommandByTile(tile, _terraform_down_flags[slope-1], 0,
 
				DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_TERRAFORM_LAND);
 
		}				
 
		}
 
	}
 

	
 
	_current_player = old_player;
 
@@ -1850,7 +1850,7 @@ static bool AiDoFollowTrack(Player *p)
 
	arpfd.tile2 = p->ai.cur_tile_a;
 
	arpfd.flag = false;
 
	arpfd.count = 0;
 
	FollowTrack(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a], 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2, 
 
	FollowTrack(p->ai.cur_tile_a + _tileoffs_by_dir[p->ai.cur_dir_a], 0x2000 | TRANSPORT_RAIL, p->ai.cur_dir_a^2,
 
		(TPFEnumProc*)AiEnumFollowTrack, NULL, &arpfd);
 
	return arpfd.count > 8;
 
}
 
@@ -1888,7 +1888,7 @@ static bool AiIsTileBanned(Player *p, Ti
 
	int i;
 

	
 
	for(i=0; i!=p->ai.banned_tile_count; i++)
 
		if (p->ai.banned_tiles[i] == tile && 
 
		if (p->ai.banned_tiles[i] == tile &&
 
				p->ai.banned_val[i] == val)
 
					return true;
 
	return false;
 
@@ -1924,7 +1924,7 @@ static bool AiCheckRailPathBetter(AiRail
 
			arf->best_ptr = p;
 
			arf->best_tile = arf->cur_best_tile;
 
			better = true;
 
		}	
 
		}
 
	} else if (arf->recursive_mode > 1) {
 
		// Mode is 2.
 
		if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) {
 
@@ -1948,7 +1948,7 @@ static void FORCEINLINE AiCheckBuildRail
 
	bool flag;
 

	
 
	int dir2 = p[0] & 3;
 
	
 

	
 
	FindLandscapeHeightByTile(&arf->ti, tile);
 

	
 
	if (arf->ti.tileh == _dir_table_1[dir2] || (arf->ti.tileh==0 && arf->ti.z!=0)) {
 
@@ -1969,11 +1969,11 @@ static void FORCEINLINE AiCheckBuildRail
 
		}
 

	
 
		// Is building a (rail)bridge possible at this place (type doesn't matter)?
 
		if (DoCommandByTile(tile_new, tile, arf->player->ai.railtype_to_use<<8, 
 
		if (DoCommandByTile(tile_new, tile, arf->player->ai.railtype_to_use<<8,
 
			DC_AUTO, CMD_BUILD_BRIDGE) == CMD_ERROR)
 
				return;
 
		AiBuildRailRecursive(arf, tile_new, dir2);
 
		
 

	
 
		// At the bottom depth, check if the new path is better than the old one.
 
		if (arf->depth == 1) {
 
			if (AiCheckRailPathBetter(arf, p))
 
@@ -1986,7 +1986,7 @@ static void FORCEINLINE AiCheckBuildRail
 
{
 
	FindLandscapeHeightByTile(&arf->ti, tile);
 

	
 
	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) { 
 
	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) {
 
		int32 cost = DoCommandByTile(tile, arf->player->ai.railtype_to_use, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 

	
 
		if (cost != CMD_ERROR && cost <= (arf->player->player_money>>4)) {
 
@@ -2004,7 +2004,7 @@ static void AiBuildRailRecursive(AiRailF
 
	const byte *p;
 

	
 
	tile = TILE_MASK(tile + _tileoffs_by_dir[dir]);
 
	
 

	
 
	// Reached destination?
 
	if (tile == arf->final_tile) {
 
		if (arf->final_dir != (dir^2)) {
 
@@ -2067,7 +2067,7 @@ static void AiBuildRailRecursive(AiRailF
 
}
 

	
 

	
 
static const byte _dir_table_3[]= {0x25, 0x2A, 0x19, 0x16};	
 
static const byte _dir_table_3[]= {0x25, 0x2A, 0x19, 0x16};
 

	
 
static void AiBuildRailConstruct(Player *p)
 
{
 
@@ -2078,7 +2078,7 @@ static void AiBuildRailConstruct(Player 
 
	if (AiDoFollowTrack(p)) {
 
		p->ai.state_counter = (Random()&0xE)+6; // Destruct this amount of blocks
 
		p->ai.state_mode = 1; // Start destruct
 
		
 

	
 
		// Ban this tile and don't reach it for a while.
 
		AiBanTile(p, p->ai.cur_tile_a, FindFirstBit(GetRailTrackStatus(p->ai.cur_tile_a)));
 
		return;
 
@@ -2097,7 +2097,7 @@ static void AiBuildRailConstruct(Player 
 
	arf.best_depth = 0xff;
 
	arf.cur_best_tile = 0;
 
	arf.best_tile = 0;
 
	AiBuildRailRecursive(&arf, p->ai.cur_tile_a, p->ai.cur_dir_a);		
 
	AiBuildRailRecursive(&arf, p->ai.cur_tile_a, p->ai.cur_dir_a);
 

	
 
	// Reached destination?
 
	if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) {
 
@@ -2114,19 +2114,19 @@ static void AiBuildRailConstruct(Player 
 
		if (++p->ai.state_counter == 21) {
 
			p->ai.state_counter = 40;
 
			p->ai.state_mode = 1;
 
			
 

	
 
			// Ban this tile
 
			AiBanTile(p, p->ai.cur_tile_a, FindFirstBit(GetRailTrackStatus(p->ai.cur_tile_a)));
 
		}
 
		return;
 
	}
 
	
 

	
 
	p->ai.cur_tile_a += _tileoffs_by_dir[p->ai.cur_dir_a];
 

	
 
	if (arf.best_ptr[0]&0x80) {
 
		int i;
 
		int32 bridge_len = GetBridgeLength(arf.bridge_end_tile, p->ai.cur_tile_a);
 
		
 

	
 
		/*	Figure out what (rail)bridge type to build
 
				start with best bridge, then go down to worse and worse bridges
 
				unnecessary to check for worse bridge (i=0), since AI will always build that.
 
@@ -2153,7 +2153,7 @@ static void AiBuildRailConstruct(Player 
 
	} else {
 
		// rail
 
		p->ai.cur_dir_a = arf.best_ptr[1];
 
		DoCommandByTile(p->ai.cur_tile_a, p->ai.railtype_to_use, arf.best_ptr[0], 
 
		DoCommandByTile(p->ai.cur_tile_a, p->ai.railtype_to_use, arf.best_ptr[0],
 
			DC_EXEC | DC_AUTO | DC_NO_WATER | DC_NO_RAIL_OVERLAP, CMD_BUILD_SINGLE_RAIL);
 
		p->ai.state_counter = 0;
 
	}
 
@@ -2183,7 +2183,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
		}
 

	
 
		if (!(_map5[tile] & 0x40)) {
 
			
 

	
 
			// Check if the bridge points in the right direction.
 
			// This is not really needed the first place AiRemoveTileAndGoForward is called.
 
			if ((_map5[tile]&1) != (p->ai.cur_dir_a&1))
 
@@ -2194,7 +2194,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
			do {
 
				tile = TILE_MASK(tile - offs);
 
			} while (_map5[tile] & 0x40);
 
			
 

	
 
			tilenew = TILE_MASK(tile - offs);
 
			// And clear the bridge.
 
			if (DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR) == CMD_ERROR)
 
@@ -2217,7 +2217,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
			(_map5[tile]&0xC0) == 0x40) {
 
		DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_SIGNALS);
 
	}
 
	
 

	
 
	// And also remove the rail.
 
	if (DoCommandByTile(tile, 0, bit, DC_EXEC, CMD_REMOVE_SINGLE_RAIL) == CMD_ERROR)
 
		return false;
 
@@ -2226,7 +2226,7 @@ static bool AiRemoveTileAndGoForward(Pla
 
	ptr = _ai_table_15[p->ai.cur_dir_a^2];
 
	while (ptr[0] != bit) ptr+=2;
 
	p->ai.cur_dir_a = ptr[1] ^ 2;
 
	
 

	
 
	// And then also switch tile.
 
	p->ai.cur_tile_a = TILE_MASK(p->ai.cur_tile_a - _tileoffs_by_dir[p->ai.cur_dir_a]);
 

	
 
@@ -2246,7 +2246,7 @@ static void AiBuildRailDestruct(Player *
 
	if (p->ai.cur_tile_a == p->ai.start_tile_a)
 
		return;
 

	
 
	AiRemoveTileAndGoForward(p);	
 
	AiRemoveTileAndGoForward(p);
 
}
 

	
 

	
 
@@ -2256,9 +2256,9 @@ static void AiBuildRail(Player *p)
 

	
 
	if (p->ai.state_mode < 1) {
 
		// Construct mode, build new rail.
 
		AiBuildRailConstruct(p);		
 
		AiBuildRailConstruct(p);
 
	} else if (p->ai.state_mode == 1) {
 
		
 

	
 
		// Destruct mode, destroy the rail currently built.
 
		AiBuildRailDestruct(p);
 
	} else if (p->ai.state_mode == 2) {
 
@@ -2291,7 +2291,7 @@ static void AiStateBuildRail(Player *p)
 
	// Currently building a rail between two points?
 
	if (p->ai.state_mode != 255) {
 
		AiBuildRail(p);
 
		
 

	
 
		// Alternate between edges
 
		swap_tile(&p->ai.start_tile_a, &p->ai.start_tile_b);
 
		swap_tile(&p->ai.cur_tile_a, &p->ai.cur_tile_b);
 
@@ -2425,7 +2425,7 @@ handle_nocash:
 
		bool is_pass = (p->ai.cargo_type == CT_PASSENGERS ||
 
							p->ai.cargo_type == CT_MAIL ||
 
							(_opt.landscape==LT_NORMAL && p->ai.cargo_type == CT_VALUABLES));
 
		
 

	
 
		if (!is_pass && i == 1) flags |= OF_UNLOAD;
 
		if (p->ai.num_want_fullload != 0 && (is_pass || i == 0)) flags |= OF_FULL_LOAD;
 

	
 
@@ -2453,7 +2453,7 @@ static void AiStateDeleteRailBlocks(Play
 
	AiBuildRec *aib;
 
	const AiDefaultBlockData *b;
 

	
 
	num = p->ai.num_build_rec;	
 
	num = p->ai.num_build_rec;
 
	aib = &p->ai.src;
 
	do {
 
		if (aib->cur_building_rule != 255) {
 
@@ -2521,13 +2521,13 @@ static int32 AiDoBuildDefaultRoadBlock(T
 
		uint c = TILE_MASK(tile+ p->tileoffs);
 

	
 
		_cleared_town = NULL;
 
	
 

	
 
		if (p->mode == 2) {
 
			if (IS_TILETYPE(c, MP_STREET) &&
 
					(_map5[c]&0xF0)==0 &&
 
					(_map5[c]&p->attr)!=0) {
 
				roadflag |= 2;
 
				
 

	
 
				// all bits are already built?
 
				if ((_map5[c]&p->attr)==p->attr)
 
					continue;
 
@@ -2575,7 +2575,7 @@ clear_town_stuff:;
 
				r = DoCommandByTile(c, 0, 0, flag | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, CMD_LANDSCAPE_CLEAR);
 
				if (r == CMD_ERROR) return CMD_ERROR;
 
			}
 
		
 

	
 
		}
 
	}
 

	
 
@@ -2595,9 +2595,9 @@ static bool AiCheckBlockDistances(Player
 
{
 
	AiBuildRec *aib;
 
	int num;
 
	
 

	
 
	num = p->ai.num_build_rec;
 
	aib = &p->ai.src;	
 
	aib = &p->ai.src;
 

	
 
	do {
 
		if (aib->cur_building_rule != 255) {
 
@@ -2720,7 +2720,7 @@ static bool AiCheckRoadPathBetter(AiRoad
 
	if (arf->recursive_mode < 1) {
 
		// Mode is 0. This means destination has not been found yet.
 
		// If the found path is shorter than the current one, remember it.
 
		if (arf->cur_best_dist < arf->best_dist || 
 
		if (arf->cur_best_dist < arf->best_dist ||
 
			(arf->cur_best_dist == arf->best_dist && arf->cur_best_depth < arf->best_depth)) {
 
			arf->best_depth = arf->cur_best_depth;
 
			arf->best_dist = arf->cur_best_dist;
 
@@ -2728,7 +2728,7 @@ static bool AiCheckRoadPathBetter(AiRoad
 
			arf->best_ptr = p;
 
			arf->best_tile = arf->cur_best_tile;
 
			better = true;
 
		}	
 
		}
 
	} else if (arf->recursive_mode > 1) {
 
		// Mode is 2.
 
		if (arf->best_dist != 0 || arf->cur_best_depth < arf->best_depth) {
 
@@ -2825,14 +2825,14 @@ static void FORCEINLINE AiCheckBuildRoad
 
	bool flag;
 

	
 
	int dir2 = p[0] & 3;
 
	
 

	
 
	FindLandscapeHeightByTile(&arf->ti, tile);
 
	if (arf->ti.tileh == _dir_table_1[dir2] || (arf->ti.tileh==0 && arf->ti.z!=0)) {
 
		tile_new = tile;
 
		// Allow bridges directly over bottom tiles
 
		flag = arf->ti.z == 0;
 
		for(;;) {
 
			if (tile_new < -_tileoffs_by_dir[dir2]) return; // Wraping around map, no bridge possible!		
 
			if (tile_new < -_tileoffs_by_dir[dir2]) return; // Wraping around map, no bridge possible!
 
			tile_new = TILE_MASK(tile_new + _tileoffs_by_dir[dir2]);
 
			FindLandscapeHeightByTile(&arf->ti, tile_new);
 
			if (arf->ti.tileh != 0 || arf->ti.type == MP_CLEAR || arf->ti.type == MP_TREES) {
 
@@ -2850,7 +2850,7 @@ static void FORCEINLINE AiCheckBuildRoad
 
		if (DoCommandByTile(tile_new, tile, 0x8000, DC_AUTO, CMD_BUILD_BRIDGE) == CMD_ERROR)
 
			return;
 
		AiBuildRoadRecursive(arf, tile_new, dir2);
 
		
 

	
 
		// At the bottom depth, check if the new path is better than the old one.
 
		if (arf->depth == 1) {
 
			if (AiCheckRoadPathBetter(arf, p))
 
@@ -2863,7 +2863,7 @@ static void FORCEINLINE AiCheckBuildRoad
 
{
 
	FindLandscapeHeightByTile(&arf->ti, tile);
 

	
 
	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) { 
 
	if (arf->ti.tileh == _dir_table_2[p[0]&3] && arf->ti.z!=0) {
 
		int32 cost = DoCommandByTile(tile, 0x200, 0, DC_AUTO, CMD_BUILD_TUNNEL);
 

	
 
		if (cost != CMD_ERROR && cost <= (arf->player->player_money>>4)) {
 
@@ -2882,13 +2882,13 @@ static void AiBuildRoadRecursive(AiRoadF
 
	const byte *p;
 

	
 
	tile = TILE_MASK(tile + _tileoffs_by_dir[dir]);
 
	
 

	
 
	// Reached destination?
 
	if (tile == arf->final_tile) {
 
		if ((arf->final_dir^2) == dir) {
 
			arf->recursive_mode = 2;
 
			arf->cur_best_depth = arf->depth;
 
		} 
 
		}
 
		return;
 
	}
 

	
 
@@ -2965,7 +2965,7 @@ static void AiBuildRoadConstruct(Player 
 
	arf.best_depth =  0xff;
 
	arf.cur_best_tile = 0;
 
	arf.best_tile = 0;
 
	AiBuildRoadRecursive(&arf, p->ai.cur_tile_a, p->ai.cur_dir_a);		
 
	AiBuildRoadRecursive(&arf, p->ai.cur_tile_a, p->ai.cur_dir_a);
 

	
 
	// Reached destination?
 
	if (arf.recursive_mode == 2 && arf.cur_best_depth == 0) {
 
@@ -3003,7 +3003,7 @@ do_some_terraform:
 
				unnecessary to check for worse bridge (i=0), since AI will always build that.
 
				AI is so fucked up that fixing this small thing will probably not solve a thing
 
		*/
 
		for(i = 10; i != 0; i--) {                      
 
		for(i = 10; i != 0; i--) {
 
			if (CheckBridge_Stuff(i, bridge_len)) {
 
				int32 cost = DoCommandByTile(tile, p->ai.cur_tile_a, i + (0x80 << 8), DC_AUTO, CMD_BUILD_BRIDGE);
 
				if (cost != CMD_ERROR && cost < (p->player_money >> 5))
 
@@ -3021,7 +3021,7 @@ do_some_terraform:
 
		p->ai.cur_tile_a = _build_tunnel_endtile;
 
		p->ai.state_counter = 0;
 
	} else {
 
		
 

	
 
		// road
 
		if (!AiBuildRoadHelper(tile, DC_EXEC | DC_AUTO | DC_NO_WATER | DC_AI_BUILDING, arf.best_ptr[0]))
 
			goto do_some_terraform;
 
@@ -3044,7 +3044,7 @@ static void AiBuildRoad(Player *p)
 

	
 
	if (p->ai.state_mode < 1) {
 
		// Construct mode, build new road.
 
		AiBuildRoadConstruct(p);		
 
		AiBuildRoadConstruct(p);
 
	} else if (p->ai.state_mode == 1) {
 
		// Destruct mode, not implemented for roads.
 
		p->ai.state_mode = 2;
 
@@ -3088,7 +3088,7 @@ static void AiStateBuildRoad(Player *p)
 
	// Currently building a road between two points?
 
	if (p->ai.state_mode != 255) {
 
		AiBuildRoad(p);
 
		
 

	
 
		// Alternate between edges
 
		swap_tile(&p->ai.start_tile_a, &p->ai.start_tile_b);
 
		swap_tile(&p->ai.cur_tile_a, &p->ai.cur_tile_b);
 
@@ -3149,7 +3149,7 @@ static void AiStateBuildRoadVehicles(Pla
 
	uint tile,loco_id;
 
	int veh, i;
 
	int32 cost;
 
	
 

	
 
	ptr = _road_default_block_data[p->ai.src.cur_building_rule]->data;
 
	for(;ptr->mode != 0;ptr++) {}
 
	tile = TILE_ADD(p->ai.src.use_tile, ptr->tileoffs);
 
@@ -3197,7 +3197,7 @@ static void AiStateDeleteRoadBlocks(Play
 
	AiBuildRec *aib;
 
	const AiDefaultBlockData *b;
 

	
 
	num = p->ai.num_build_rec;	
 
	num = p->ai.num_build_rec;
 
	aib = &p->ai.src;
 
	do {
 
		if (aib->cur_building_rule != 255) {
 
@@ -3379,7 +3379,7 @@ static void AiStateBuildDefaultAirportBl
 
	// do the following 8 times
 
	i = 8;
 
	do {
 
		// check if we can build the default 
 
		// check if we can build the default
 
		aib = &p->ai.src;
 
		j = p->ai.num_build_rec;
 
		do {
 
@@ -3399,7 +3399,7 @@ static void AiStateBuildDefaultAirportBl
 
					!IS_TILETYPE(aib->use_tile, MP_RAILWAY) &&
 
					!IS_TILETYPE(aib->use_tile, MP_STATION)
 
					) {
 
				
 

	
 
				_map_type_and_height[aib->use_tile] = 0xa1;
 
				_map5[aib->use_tile] = 0x80;
 
				MarkTileDirtyByTile(aib->use_tile);
 
@@ -3460,7 +3460,7 @@ static void AiStateBuildAircraftVehicles
 
	int32 cost;
 
	int i;
 
	uint loco_id;
 
	
 

	
 
	ptr = _airport_default_block_data[p->ai.src.cur_building_rule];
 
	for(;ptr->mode!=0;ptr++) {}
 

	
 
@@ -3523,7 +3523,7 @@ static void AiStateSellVeh(Player *p)
 

	
 
	if (v->owner == _current_player) {
 
		if (v->type == VEH_Train) {
 
			
 

	
 
			if (!IsTrainDepotTile(v->tile) || v->u.rail.track != 0x80 || !(v->vehstatus&VS_STOPPED)) {
 
				if ((v->next_order & OT_MASK) != OT_GOTO_DEPOT)
 
					DoCommandByTile(0, v->index, 0, DC_EXEC, CMD_TRAIN_GOTO_DEPOT);
 
@@ -3532,7 +3532,7 @@ static void AiStateSellVeh(Player *p)
 

	
 
			// Sell whole train
 
			DoCommandByTile(v->tile, v->index, 1, DC_EXEC, CMD_SELL_RAIL_WAGON);
 
			
 

	
 
		} else if (v->type == VEH_Road) {
 
			if (!IsRoadDepotTile(v->tile) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED)) {
 
				if ((v->next_order & OT_MASK) != OT_GOTO_DEPOT)
 
@@ -3613,7 +3613,7 @@ static void AiRemovePlayerRailOrRoad(Pla
 
		if ((m5&~0x3) != 0xC0) {
 
is_rail_crossing:;
 
			m5 = GetRailTrackStatus(tile);
 
			
 

	
 
			if (m5 == 0xC || m5 == 0x30)
 
				return;
 

	
 
@@ -3662,7 +3662,7 @@ pos_3:
 
			m5 &= 3;
 
			if (GetRailTrackStatus(tile + _tileoffs_by_dir[m5]) & _depot_bits[m5])
 
				return;
 
			
 

	
 
			DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
 
		}
 
	} else if (IS_TILETYPE(tile, MP_STREET)) {
 
@@ -3707,7 +3707,7 @@ pos_3:
 

	
 
		if (_map_owner[tile] != _current_player || (_map5[tile] & 0xC6) != 0x80)
 
			return;
 
		
 

	
 
		m5 = 0;
 

	
 
		b = _map5[tile] & 0x21;
 
@@ -3721,7 +3721,7 @@ pos_3:
 
static void AiStateRemoveTrack(Player *p)
 
{
 
	int num = 1000;
 
	
 

	
 
	do {
 
		uint tile = ++p->ai.state_counter;
 

	
 
@@ -3775,7 +3775,7 @@ static AiStateAction * const _ai_actions
 
	AiStateSellVeh,
 
	AiStateRemoveStation,
 
	AiStateRemoveTrack,
 
	
 

	
 
	AiStateRemoveSingleRailTile
 
};
 

	
 
@@ -3875,10 +3875,10 @@ static void AiBuildCompanyHQ(Player *p)
 
}
 

	
 

	
 
void AiDoGameLoop(Player *p) 
 
void AiDoGameLoop(Player *p)
 
{
 
	_cur_ai_player = p;
 
	
 

	
 
	if (p->bankrupt_asked != 0) {
 
		AiHandleTakeover(p);
 
		return;
 
@@ -3913,7 +3913,7 @@ void AiDoGameLoop(Player *p)
 
					return;
 
			}
 
		}
 
	} 
 
	}
 
#if 0
 
	{
 
		static byte old_state = 99;
ai_build.c
Show inline comments
 
@@ -85,8 +85,8 @@ int AiNew_Build_RoutePart(Player *p, Ai_
 
	if (part < 1) part = 1;
 
	// When we are done, stop it
 
	if (part >= PathFinderInfo->route_length - 1) { PathFinderInfo->position = -2; return 0; }
 
	
 
	
 

	
 

	
 
	if (PathFinderInfo->rail_or_road) {
 
		// Tunnel code
 
     	if ((AI_PATHFINDER_FLAG_TUNNEL & route_extra[part]) != 0) {
 
@@ -198,7 +198,7 @@ int AiNew_Build_RoutePart(Player *p, Ai_
 
	    if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--;
 
     	PathFinderInfo->position = part;
 
    }
 
    
 

	
 
    return cost;
 
}
 

	
 
@@ -232,7 +232,7 @@ int AiNew_PickVehicle(Player *p) {
 
int AiNew_Build_Vehicle(Player *p, uint tile, byte flag) {
 
	int i = AiNew_PickVehicle(p);
 
	if (i == -1) return CMD_ERROR;
 
	
 

	
 
	if (p->ainew.tbt == AI_TRAIN) {
 
		return CMD_ERROR;
 
	} else {
ai_pathfinder.c
Show inline comments
 
@@ -38,7 +38,7 @@ int32 AyStar_AiPathFinder_EndNodeCheck(A
 
		if (IS_TILETYPE(current->path.node.tile, MP_CLEAR) || IS_TILETYPE(current->path.node.tile, MP_TREES))
 
			if (current->path.parent == NULL || TestCanBuildStationHere(current->path.node.tile,AiNew_GetDirection(current->path.parent->node.tile, current->path.node.tile)))
 
    			return AYSTAR_FOUND_END_NODE;
 
		
 

	
 
	return AYSTAR_DONE;
 
}
 

	
 
@@ -103,7 +103,7 @@ AyStar *new_AyStar_AiPathFinder(int max_
 
void clean_AyStar_AiPathFinder(AyStar *aystar, Ai_PathFinderInfo *PathFinderInfo) {
 
	PathNode start_node;
 
	uint x,y;
 
	
 

	
 
	aystar->clear(aystar);
 

	
 
	// Set the user_data to the PathFinderInfo
 
@@ -149,7 +149,7 @@ static void AyStar_AiPathFinder_FoundEnd
 
	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
 
	int i = 0;
 
	PathNode *parent = &current->path;
 
	
 

	
 
	do {
 
     	PathFinderInfo->route_extra[i] = parent->node.user_data[0];
 
		PathFinderInfo->route[i++] = parent->node.tile;
 
@@ -169,16 +169,16 @@ static void AyStar_AiPathFinder_FoundEnd
 
static void AyStar_AiPathFinder_GetNeighbours(AyStar *aystar, OpenListNode *current) {
 
    int i, r, dir;
 
   	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
 
    
 

	
 
    aystar->num_neighbours = 0;
 
    
 

	
 
  	// Go through all surrounding tiles and check if they are within the limits
 
   	for (i=0;i<4;i++) {
 
   		if (GET_TILE_X(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_X(_tiles_around[i] + current->path.node.tile) < TILE_X_MAX - 1 &&
 
       		GET_TILE_Y(_tiles_around[i] + current->path.node.tile) > 1 && GET_TILE_Y(_tiles_around[i] + current->path.node.tile) < TILE_Y_MAX - 1) {
 
       		// We also directly test if the current tile can connect to this tile..
 
       		//  We do this simply by just building the tile!
 
       		
 

	
 
       		// If the next step is a bridge, we have to enter it the right way
 
       		if (!PathFinderInfo->rail_or_road && AI_PATHFINDER_IS_ROAD(current->path.node.tile + _tiles_around[i])) {
 
       			if (IS_TILETYPE(current->path.node.tile + _tiles_around[i], MP_TUNNELBRIDGE)) {
 
@@ -198,7 +198,7 @@ static void AyStar_AiPathFinder_GetNeigh
 
       				if ((_map5[current->path.node.tile] & 1) != (i & 1)) continue;
 
       			}
 
       		}
 
       		
 

	
 
       		if ((AI_PATHFINDER_FLAG_BRIDGE & current->path.node.user_data[0]) != 0 ||
 
       			(AI_PATHFINDER_FLAG_TUNNEL & current->path.node.user_data[0]) != 0) {
 
       			// We are a bridge/tunnel, how cool!!
 
@@ -206,7 +206,7 @@ static void AyStar_AiPathFinder_GetNeigh
 
       			if (i != (current->path.node.user_data[0] >> 8)) continue;
 
       		}
 
       		dir = 0;
 
       		
 

	
 
       		// First, check if we have a parent
 
       		if (current->path.parent == NULL && current->path.node.user_data[0] == 0) {
 
       			// If not, this means we are at the starting station
 
@@ -254,16 +254,16 @@ static void AyStar_AiPathFinder_GetNeigh
 
       					if (r == CMD_ERROR) continue;
 
       				}
 
       			}
 
       			
 

	
 
       		}
 
       		
 

	
 
			// The tile can be connected
 
   			aystar->neighbours[aystar->num_neighbours].tile = _tiles_around[i] + current->path.node.tile;
 
   			aystar->neighbours[aystar->num_neighbours].user_data[0] = 0;
 
   			aystar->neighbours[aystar->num_neighbours++].direction = 0;
 
       	}
 
    }
 
    
 

	
 
    // Next step, check for bridges and tunnels
 
    if (current->path.parent != NULL && current->path.node.user_data[0] == 0) {
 

	
 
@@ -273,9 +273,9 @@ static void AyStar_AiPathFinder_GetNeigh
 
    	// It means we can only walk with the track, so the bridge has to be in the same direction
 
    	TileIndex tile = current->path.node.tile;
 
    	TileIndex new_tile = tile;
 
    	
 

	
 
    	FindLandscapeHeightByTile(&ti, tile);
 
    	
 

	
 
   		// Bridges can only be build on land that is not flat
 
   		//  And if there is a road or rail blocking
 
   		if (ti.tileh != 0 ||
 
@@ -284,10 +284,10 @@ static void AyStar_AiPathFinder_GetNeigh
 

	
 
    		for (;;) {
 
    			new_tile += _tiles_around[dir];
 
    	
 

	
 
    	    	// Precheck, is the length allowed?
 
    	    	if (!CheckBridge_Stuff(0,GetBridgeLength(tile, new_tile))) break;
 
    	    	
 

	
 
    	    	// Check if we hit the station-tile.. we don't like that!
 
    	    	if (TILES_BETWEEN(new_tile,PathFinderInfo->end_tile_tl,PathFinderInfo->end_tile_br)) break;
 

	
 
@@ -302,7 +302,7 @@ static void AyStar_AiPathFinder_GetNeigh
 
				if (aystar->num_neighbours == 11) break;
 
			}
 
    	}
 
    	
 

	
 
    	// Next, check for tunnels!
 
    	// Tunnels can only be build with tileh of 3, 6, 9 or 12, depending on the direction
 
    	//  For now, we check both sides for this tile.. terraforming gives fuzzy result
 
@@ -334,11 +334,11 @@ static int32 AyStar_AiPathFinder_Calcula
 
	Ai_PathFinderInfo *PathFinderInfo = (Ai_PathFinderInfo*)aystar->user_target;
 
	int r, res = 0;
 
	TileInfo ti, parent_ti;
 
	
 

	
 
	// Gather some information about the tile..
 
	FindLandscapeHeightByTile(&ti, current->tile);
 
	FindLandscapeHeightByTile(&parent_ti, parent->path.node.tile);
 
	
 

	
 
	// Check if we hit the end-tile
 
	if (TILES_BETWEEN(current->tile,PathFinderInfo->end_tile_tl,PathFinderInfo->end_tile_br)) {
 
		// We are at the end-tile, check if we had a direction or something...
 
@@ -348,7 +348,7 @@ static int32 AyStar_AiPathFinder_Calcula
 
		// If it was valid, drop out.. we don't build on the endtile
 
		return 0;
 
	}
 
	
 

	
 
	// Give everything a small penalty
 
	res += AI_PATHFINDER_PENALTY;
 

	
 
@@ -359,7 +359,7 @@ static int32 AyStar_AiPathFinder_Calcula
 
			res -= AI_PATHFINDER_ROAD_ALREADY_EXISTS_BONUS;
 
		}
 
	}
 
	
 

	
 
	// We should give a penalty when the tile is going up or down.. this is one way to do so!
 
	//  Too bad we have to count it from the parent.. but that is not so bad
 
	if (parent_ti.tileh != 0 && parent->path.parent != NULL) {
 
@@ -380,7 +380,7 @@ static int32 AyStar_AiPathFinder_Calcula
 
			}
 
		}
 
	}
 
	
 

	
 
	// Are we part of a tunnel?
 
	if ((AI_PATHFINDER_FLAG_TUNNEL & current->user_data[0]) != 0) {
 
		// Tunnels are very expensive when build on long routes..
 
@@ -409,7 +409,7 @@ static int32 AyStar_AiPathFinder_Calcula
 
		if (ti.tileh == 0)
 
			res += AI_PATHFINDER_BRIDGE_GOES_UP_PENALTY;
 
	}
 
	
 

	
 
	//  To prevent the AI from taking the fastest way in tiles, but not the fastest way
 
	//    in speed, we have to give a good penalty to direction changing
 
	//  This way, we get almost the fastest way in tiles, and a very good speed on the track
 
@@ -448,7 +448,7 @@ static int32 AyStar_AiPathFinder_Calcula
 
			}
 
		}
 
	}
 
	
 

	
 
	// Res should never be below zero.. if so, make it zero!
 
	if (res < 0) { res = 0; }
 

	
aircraft_cmd.c
Show inline comments
 
@@ -275,8 +275,8 @@ int32 CmdBuildAircraft(int x, int y, uin
 
		// On hold for NewAI
 
		v->u.air.pos = (!_patches.ainew_active && _is_ai_player) ? 0:MAX_ELEMENTS;
 

	
 
		/* When we click on hangar we know the tile (it is in var 'tile')it is on. By that we know 
 
			its position in the array of depots the airport has.....we can search 
 
		/* When we click on hangar we know the tile (it is in var 'tile')it is on. By that we know
 
			its position in the array of depots the airport has.....we can search
 
			->layout for #th position of depot. Since layout must start with depots, it is simple
 
		*/
 
		{
 
@@ -542,7 +542,7 @@ static void CheckIfAircraftNeedsService(
 

	
 
 	if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr))
 
 		return;
 
 
 

	
 
	st = DEREF_STATION(v->next_order_param);
 
	// only goto depot if the target airport has terminals (eg. it is airport)
 
	if (st->xy != 0 && st->airport_tile != 0 && GetAirport(st->airport_type)->nofterminals != 0) {
 
@@ -621,7 +621,7 @@ static void HelicopterTickHandler(Vehicl
 
	if (u->vehstatus & VS_HIDDEN)
 
		return;
 

	
 
	// if true, helicopter rotors do not rotate. This should only be the case if a helicopter is 
 
	// if true, helicopter rotors do not rotate. This should only be the case if a helicopter is
 
	// loading/unloading at a terminal or stopped
 
	if ((v->next_order&OT_MASK) == OT_LOADING || (v->vehstatus&VS_STOPPED)) {
 
		if (u->cur_speed != 0) {
 
@@ -735,7 +735,7 @@ static bool UpdateAircraftSpeed(Vehicle 
 

	
 
	v->subspeed = (t=v->subspeed) + (byte)spd;
 
	spd = min( v->cur_speed + (spd >> 8) + (v->subspeed < t), v->max_speed);
 
		   
 

	
 
	// adjust speed for broken vehicles
 
	if(v->vehstatus&VS_AIRCRAFT_BROKEN) spd = min(spd, 27);
 

	
 
@@ -875,7 +875,7 @@ static bool Aircraft_5(Vehicle *v)
 

	
 
		// Change direction smoothly to final direction.
 
		dirdiff = amd->direction - v->direction;
 
		// if distance is 0, and plane points in right direction, no point in calling 
 
		// if distance is 0, and plane points in right direction, no point in calling
 
		// UpdateAircraftSpeed(). So do it only afterwards
 
		if (dirdiff == 0) {
 
			v->cur_speed = 0;
 
@@ -1061,7 +1061,7 @@ static void ProcessAircraftOrder(Vehicle
 
 		if ((v->next_order & (OT_MASK|OF_UNLOAD)) != (OT_GOTO_DEPOT|OF_UNLOAD))
 
 			return;
 
 	}
 
 
 

	
 
 	if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) &&
 
 			SERVICE_INTERVAL) {
 
 		v->cur_order_index++;
 
@@ -1217,7 +1217,7 @@ static void AircraftEnterHangar(Vehicle 
 
	byte old_order;
 

	
 
	ServiceAircraft(v);
 
	
 

	
 
	MaybeRenewVehicle(v, EstimateAircraftCost(v->engine_type));
 

	
 
	if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) {
 
@@ -1227,7 +1227,7 @@ static void AircraftEnterHangar(Vehicle 
 
		v->next_order = OT_NOTHING;
 

	
 
 			if (old_order & OF_UNLOAD) { v->cur_order_index++; }
 
 
 

	
 
 			else if (old_order & OF_FULL_LOAD) { // force depot visit
 
			v->vehstatus |= VS_STOPPED;
 

	
 
@@ -1692,7 +1692,7 @@ static bool FreeTerminal(Vehicle *v, byt
 
	return false;
 
}
 

	
 
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport) 
 
static bool AirportFindFreeTerminal(Vehicle *v, const AirportFTAClass *Airport)
 
{
 
	byte nofterminalspergroup, i;
 
	AirportFTA *temp;
 
@@ -1703,9 +1703,9 @@ static bool AirportFindFreeTerminal(Vehi
 
		Heading 255 denotes a group. We see 2 groups here:
 
		1. group 0 -- TERM_GROUP1_block (check block)
 
		2. group 1 -- TERM_GROUP2_ENTER_block (check block)
 
		First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it 
 
		looks	at the corresponding terminals of that group. If no free ones are found, other 
 
		possible groups are checked	(in this case group 1, since that is after group 0). If that 
 
		First in line is checked first, group 0. If the block (TERM_GROUP1_block) is free, it
 
		looks	at the corresponding terminals of that group. If no free ones are found, other
 
		possible groups are checked	(in this case group 1, since that is after group 0). If that
 
		fails, then attempt fails and plane waits
 
	*/
 
	if (Airport->nofterminalgroups > 1) {
 
@@ -1731,7 +1731,7 @@ static bool AirportFindFreeTerminal(Vehi
 
	return FreeTerminal(v, 0, Airport->nofterminals);
 
}
 

	
 
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport) 
 
static bool AirportFindFreeHelipad(Vehicle *v, const AirportFTAClass *Airport)
 
{
 
  Station *st;
 
  byte nofhelipadspergroup,  i;
 
@@ -1847,7 +1847,7 @@ void UpdateOldAircraft()
 
			AircraftNextAirportPos_and_Order(v_oldstyle); // move it to the entry point of the airport
 
			GetNewVehiclePos(v_oldstyle, &gp); // get the position of the plane (to be used for setting)
 
			v_oldstyle->tile = 0; // aircraft in air is tile=0
 
			
 

	
 
			// correct speed of helicopter-rotors
 
			if (v_oldstyle->subtype == 0) {v_oldstyle->next->next->cur_speed = 32;}
 

	
 
@@ -1857,7 +1857,7 @@ void UpdateOldAircraft()
 
	}
 
}
 

	
 
void UpdateAirplanesOnNewStation(Station *st) 
 
void UpdateAirplanesOnNewStation(Station *st)
 
{
 
	GetNewVehiclePosResult gp;
 
	Vehicle *v;
aircraft_gui.c
Show inline comments
 
@@ -891,7 +891,7 @@ static void MakeSortedAircraftList(byte 
 
		// aircraft are stored as a cummulative index, eg 25, 41, 43. This means
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
 
		for (i = &_num_aircraft_sort[1]; i != endof(_num_aircraft_sort); i++) {*i += *(i-1);}
 
	
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_aircraft_sort, n, sizeof(_aircraft_sort[0]), GeneralOwnerSorter);
 

	
 
@@ -936,7 +936,7 @@ static void PlayerAircraftWndProc(Window
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 aircraft
 
		i = (window_number == 0) ? 0 : _num_aircraft_sort[window_number-1];
 
		SetVScrollCount(w, _num_aircraft_sort[window_number] - i);
 
		
 

	
 
		/* draw the widgets */
 
		{
 
			Player *p = DEREF_PLAYER(window_number);
 
@@ -980,7 +980,7 @@ static void PlayerAircraftWndProc(Window
 
				SET_DPARAM32(0, v->profit_this_year);
 
				SET_DPARAM32(1, v->profit_last_year);
 
				DrawString(x+19, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
 
				
 

	
 
				if (v->string_id != STR_SV_AIRCRAFT_NAME) {
 
					SET_DPARAM16(0, v->string_id);
 
					DrawString(x+19, y, STR_01AB, 0);
 
@@ -1007,7 +1007,7 @@ static void PlayerAircraftWndProc(Window
 
			return;
 
		case 6: { /* Matrix to show vehicles */
 
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
 
			
 

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

	
 
			id_v += w->vscroll.pos;
airport_gui.c
Show inline comments
 
@@ -77,12 +77,12 @@ static void BuildAirToolbWndProc(Window 
 

	
 
	case WE_CLICK:
 
		if (e->click.widget-2 >= 0)
 
			_build_air_button_proc[e->click.widget - 2](w);		
 
			_build_air_button_proc[e->click.widget - 2](w);
 
		break;
 

	
 
	case WE_PLACE_OBJ:
 
		_place_proc(e->place.tile);
 
		break;	
 
		break;
 

	
 
	case WE_PLACE_DRAG: {
 
		VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
 
@@ -160,7 +160,7 @@ static void BuildAirportPickerWndProc(Wi
 
    // strings such as 'Size' and 'Coverage Area'
 
		DrawStringCentered(74, 16, STR_305B_SIZE, 0);
 
		DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0);
 
		DrawStationCoverageAreaText(2, 104, (uint)-1);		
 
		DrawStationCoverageAreaText(2, 104, (uint)-1);
 
		break;
 
	}
 

	
aystar.c
Show inline comments
 
@@ -5,7 +5,7 @@
 
 *  For more information about AyStar (A* Algorithm), you can look at
 
 *    http://en.wikipedia.org/wiki/A-star_search_algorithm
 
 */
 
 
 

	
 
/*
 
 * Friendly reminder:
 
 *  Call (AyStar).free() when you are done with Aystar. It reserves a lot of memory
 
@@ -46,7 +46,7 @@ OpenListNode *AyStarMain_OpenList_Pop(Ay
 
	OpenListNode* res = (OpenListNode*)aystar->OpenListQueue.pop(&aystar->OpenListQueue);
 
	if (res != NULL)
 
		Hash_Delete(&aystar->OpenListHash, res->path.node.tile, res->path.node.direction);
 
	
 

	
 
	return res;
 
}
 

	
 
@@ -76,29 +76,29 @@ int AyStarMain_CheckTile(AyStar *aystar,
 

	
 
	// Check the new node against the ClosedList
 
	if (AyStarMain_ClosedList_IsInList(aystar, current) != NULL) return AYSTAR_DONE;
 
	
 

	
 
	// Calculate the G-value for this node
 
	new_g = aystar->CalculateG(aystar, current, parent);
 
	// If the value was INVALID_NODE, we don't do anything with this node
 
	if (new_g == AYSTAR_INVALID_NODE) return AYSTAR_DONE;
 
	
 

	
 
	// There should not be given any other error-code..
 
	assert(new_g >= 0);
 
	// Add the parent g-value to the new g-value
 
	new_g += parent->g;
 
	if (aystar->max_path_cost != 0 && (uint)new_g > aystar->max_path_cost) return AYSTAR_DONE;
 
	
 

	
 
	// Calculate the h-value
 
	new_h = aystar->CalculateH(aystar, current, parent);
 
	// There should not be given any error-code..
 
	assert(new_h >= 0);
 
	
 

	
 
	// The f-value if g + h
 
	new_f = new_g + new_h;
 
	
 

	
 
	// Get the pointer to the parent in the ClosedList (the currentone is to a copy of the one in the OpenList)
 
	closedlist_parent = AyStarMain_ClosedList_IsInList(aystar, &parent->path.node);
 
	
 

	
 
	// Check if this item is already in the OpenList
 
	if ((check = AyStarMain_OpenList_IsInList(aystar, current)) != NULL) {
 
		int i;
 
@@ -117,7 +117,7 @@ int AyStarMain_CheckTile(AyStar *aystar,
 
		// A new node, add him to the OpenList
 
		AyStarMain_OpenList_Add(aystar, closedlist_parent, current, new_f, new_g, 0);
 
	}
 
	
 

	
 
	return AYSTAR_DONE;
 
}
 

	
 
@@ -134,12 +134,12 @@ int AyStarMain_CheckTile(AyStar *aystar,
 
 */
 
int AyStarMain_Loop(AyStar *aystar) {
 
	int i, r;
 
	
 

	
 
	// Get the best node from OpenList
 
	OpenListNode *current = AyStarMain_OpenList_Pop(aystar);
 
	// If empty, drop an error
 
	if (current == NULL) return AYSTAR_EMPTY_OPENLIST;
 
	
 

	
 
	// Check for end node and if found, return that code
 
	if (aystar->EndNodeCheck(aystar, current) == AYSTAR_FOUND_END_NODE) {
 
		if (aystar->FoundEndNode != NULL)
 
@@ -147,22 +147,22 @@ int AyStarMain_Loop(AyStar *aystar) {
 
		free(current);
 
		return AYSTAR_FOUND_END_NODE;
 
	}
 
	
 

	
 
	// Add the node to the ClosedList
 
	AyStarMain_ClosedList_Add(aystar, &current->path);
 

	
 
	// Load the neighbours
 
	aystar->GetNeighbours(aystar, current);
 
	
 

	
 
	// Go through all neighbours
 
	for (i=0;i<aystar->num_neighbours;i++) {
 
		// Check and add them to the OpenList if needed
 
		r = aystar->checktile(aystar, &aystar->neighbours[i], current);
 
	}
 
	
 

	
 
	// Free the node
 
	free(current);
 
	
 

	
 
	if (aystar->max_search_nodes != 0 && Hash_Size(&aystar->ClosedListHash) >= aystar->max_search_nodes)
 
		/* We've expanded enough nodes */
 
		return AYSTAR_LIMIT_REACHED;
 
@@ -228,7 +228,7 @@ int AyStarMain_Main(AyStar *aystar) {
 
	if (r != AYSTAR_STILL_BUSY)
 
		/* We're done, clean up */
 
		aystar->clear(aystar);
 
		
 

	
 
	// Check result-value
 
	if (r == AYSTAR_FOUND_END_NODE) return AYSTAR_FOUND_END_NODE;
 
	// Check if we have some left in the OpenList
 
@@ -242,7 +242,7 @@ int AyStarMain_Main(AyStar *aystar) {
 
 * Adds a node from where to start an algorithm. Multiple nodes can be added
 
 * if wanted. You should make sure that clear() is called before adding nodes
 
 * if the AyStar has been used before (though the normal main loop calls
 
 * clear() automatically when the algorithm finishes 
 
 * clear() automatically when the algorithm finishes
 
 */
 
void AyStarMain_AddStartNode(AyStar *aystar, AyStarNode *start_node) {
 
#ifdef AYSTAR_DEBUG
aystar.h
Show inline comments
 
@@ -107,7 +107,7 @@ struct AyStar {
 
	AyStar_GetNeighbours* GetNeighbours;
 
	AyStar_EndNodeCheck* EndNodeCheck;
 
	AyStar_FoundEndNode* FoundEndNode;
 
	
 

	
 
	/* These are completely untouched by AyStar, they can be accesed by
 
	 * the application specific routines to input and output data.
 
	 * user_path should typically contain data about the resulting path
 
@@ -117,7 +117,7 @@ struct AyStar {
 
	void *user_path;
 
	void *user_target;
 
	uint user_data[10];
 
	
 

	
 
	/* How many loops are there called before AyStarMain_Main gives
 
	 * control back to the caller. 0 = until done */
 
	byte loops_per_tick;
 
@@ -125,7 +125,7 @@ struct AyStar {
 
	 *  0 = infinite */
 
	uint max_path_cost;
 
	/* The maximum amount of nodes that will be expanded, 0 = infinite */
 
	uint max_search_nodes; 
 
	uint max_search_nodes;
 

	
 
	/* These should be filled with the neighbours of a tile by
 
	 * GetNeighbours */
 
@@ -140,7 +140,7 @@ struct AyStar {
 
	AyStar_Free* free;
 
	AyStar_Clear* clear;
 
	AyStar_CheckTile* checktile;
 
	
 

	
 
	/* These will contain the open and closed lists */
 

	
 
	/* The actual closed list */
 
@@ -164,6 +164,6 @@ void AyStarMain_Clear(AyStar *aystar);
 
 * callling init_AyStar (see the declaration of AyStar for which fields are
 
 * internal */
 
void init_AyStar(AyStar* aystar, Hash_HashProc hash, uint num_buckets);
 
	
 

	
 

	
 
#endif
bridge_gui.c
Show inline comments
 
@@ -30,7 +30,7 @@ static void CcBuildBridge(bool success, 
 
static void BuildBridge(Window *w, int i)
 
{
 
	DeleteWindow(w);
 
	DoCommandP(_bridge.end_tile, _bridge.start_tile, _bridge.indexes[i] | (_bridge.type << 8), CcBuildBridge, 
 
	DoCommandP(_bridge.end_tile, _bridge.start_tile, _bridge.indexes[i] | (_bridge.type << 8), CcBuildBridge,
 
		CMD_BUILD_BRIDGE | CMD_AUTO | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE));
 
}
 

	
 
@@ -60,11 +60,11 @@ static void BuildBridgeWndProc(Window *w
 
			e->keypress.cont = false;
 
			BuildBridge(w, i);
 
		}
 
		
 

	
 
		break;
 
	}
 

	
 
	case WE_CLICK: 
 
	case WE_CLICK:
 
	 if (e->click.widget == 2) {
 
			uint ind = ((int)e->click.pt.y - 14) / 22;
 
			if (ind < 4 && (ind += w->vscroll.pos) < (uint)_bridge.count)
 
@@ -136,7 +136,7 @@ void ShowBuildBridgeWindow(uint start, u
 

	
 
		// get absolute bridge length
 
		bridge_len = GetBridgeLength(start, end);
 
		tot_bridge_len = bridge_len + 2;		
 
		tot_bridge_len = bridge_len + 2;
 

	
 
		tot_bridge_len = CalcBridgeLenCostFactor(tot_bridge_len);
 

	
 
@@ -155,7 +155,7 @@ void ShowBuildBridgeWindow(uint start, u
 
	_bridge.count = j;
 

	
 
	if (j != 0) {
 
		Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);	
 
		Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
 
		w->vscroll.cap = 4;
 
		w->vscroll.count = (byte)j;
 
	} else {
clear_cmd.c
Show inline comments
 
@@ -15,7 +15,7 @@ typedef struct TerraformerState {
 
	int direction;
 
	int modheight_count;
 
	int tile_table_count;
 
	
 

	
 
	int32 cost;
 

	
 
	TileIndex *tile_table;
 
@@ -44,7 +44,7 @@ static int TerraformGetHeightOfTile(Terr
 
{
 
	TerraformerHeightMod *mod = ts->modheight;
 
	int count;
 
	
 

	
 
	for(count = ts->modheight_count; count != 0; count--, mod++) {
 
		if (mod->tile == tile)
 
			return mod->height;
 
@@ -85,10 +85,10 @@ static int TerraformProc(TerraformerStat
 
	int32 ret;
 

	
 
	assert(tile < TILES_X * TILES_Y);
 
	
 

	
 
	if ((r=TerraformAllowTileProcess(ts, tile)) <= 0)
 
		return r;
 
	
 

	
 
	if ((_map_type_and_height[tile] >> 4) == MP_RAILWAY) {
 
		static const byte _railway_modes[4] = {8, 0x10, 4, 0x20};
 
		static const byte _railway_dangslopes[4] = {0xd, 0xe, 7, 0xb};
 
@@ -128,7 +128,7 @@ static bool TerraformTileHeight(Terrafor
 
	int nh;
 
	TerraformerHeightMod *mod;
 
	int count;
 
	
 

	
 
	assert(tile < TILES_X * TILES_Y);
 

	
 
	if (height < 0) {
 
@@ -140,11 +140,11 @@ static bool TerraformTileHeight(Terrafor
 

	
 
	if (height > 0xF)
 
		return false;
 
	
 

	
 
	nh = TerraformGetHeightOfTile(ts, tile);
 
	if (nh < 0 || height == nh)
 
		return false; 
 
	
 
		return false;
 

	
 
	if (TerraformProc(ts, tile, 0)<0)
 
		return false;
 

	
 
@@ -227,7 +227,7 @@ int32 CmdTerraformLand(int x, int y, uin
 
	tile = TILE_FROM_XY(x,y);
 

	
 
	if (p1 & 1) {
 
		if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),	
 
		if (!TerraformTileHeight(&ts, tile+TILE_XY(1,0),
 
				(_map_type_and_height[tile+TILE_XY(1,0)]&0xF) + direction))
 
					return CMD_ERROR;
 
	}
 
@@ -254,7 +254,7 @@ int32 CmdTerraformLand(int x, int y, uin
 
		/* Check if tunnel would take damage */
 
		int count;
 
		TileIndex *ti = ts.tile_table;
 
		
 

	
 
		for(count = ts.tile_table_count; count != 0; count--, ti++) {
 
			uint z, t;
 
			uint tile = *ti;
 
@@ -280,7 +280,7 @@ int32 CmdTerraformLand(int x, int y, uin
 
			for(count = ts.tile_table_count; count != 0; count--, ti++) {
 
				DoCommandByTile(*ti, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			}
 
		}	
 
		}
 

	
 
		/* change the height */
 
		{
 
@@ -291,10 +291,10 @@ int32 CmdTerraformLand(int x, int y, uin
 
			mod = ts.modheight;
 
			for(count = ts.modheight_count; count != 0; count--, mod++) {
 
				til = mod->tile;
 
				
 

	
 
				// Change tile height
 
				_map_type_and_height[til] = (_map_type_and_height[til]&~0x0F)|mod->height;
 
				
 

	
 
				TerraformAddDirtyTileAround(&ts, til);
 
			}
 
		}
 
@@ -306,7 +306,7 @@ int32 CmdTerraformLand(int x, int y, uin
 
			for(count = ts.tile_table_count; count != 0; count--, ti++) {
 
				MarkTileDirtyByTile(*ti);
 
			}
 
		}	
 
		}
 
	}
 
	return ts.cost;
 
}
 
@@ -374,9 +374,9 @@ int32 CmdPurchaseLandArea(int x, int y, 
 
{
 
	uint tile;
 
	int32 cost;
 
	
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 
		
 

	
 
	tile = TILE_FROM_XY(x,y);
 

	
 
	if (!EnsureNoVehicle(tile))
 
@@ -426,7 +426,7 @@ int32 ClearTile_Clear(uint tile, byte fl
 
int32 CmdSellLandArea(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	uint tile;
 
	
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	tile = TILE_FROM_XY(x,y);
 
@@ -464,7 +464,7 @@ void DrawHillyLandTile(TileInfo *ti)
 
void DrawClearLandFence(TileInfo *ti, byte img)
 
{
 
	byte z = ti->z;
 
	
 

	
 
	if (ti->tileh & 2) {
 
		z += 8;
 
		if (ti->tileh == 0x17)
 
@@ -508,7 +508,7 @@ static void DrawTile_Clear(TileInfo *ti)
 
		DrawGroundSprite( _clear_land_sprites_3[ti->map5&3] + _tileh_to_sprite[ti->tileh]);
 
		break;
 
	}
 
	
 

	
 
	DrawClearLandFence(ti, _map3_hi[ti->tile] >> 2);
 
}
 

	
 
@@ -521,7 +521,7 @@ uint GetSlopeTileh_Clear(TileInfo *ti)
 

	
 
static void GetAcceptedCargo_Clear(uint tile, AcceptedCargo *ac)
 
{
 
	/* unused */	
 
	/* unused */
 
}
 

	
 
static void AnimateTile_Clear(uint tile)
 
@@ -553,7 +553,7 @@ void TileLoopClearHelper(uint tile)
 
		if ( (img_1&2) != (img_2&2) ) {
 
			_map3_hi[tile] |= 3 << 5;
 
			dirty = tile;
 
		} 
 
		}
 
	} else {
 
		if (img_1 == 1 && img_2 == 1) {
 
			_map3_hi[tile] &= ~(3 << 5);
 
@@ -572,7 +572,7 @@ void TileLoopClearHelper(uint tile)
 
		if ( (img_1&2) != (img_2&2) ) {
 
			_map3_hi[tile] |= 3 << 2;
 
			dirty = tile;
 
		} 
 
		}
 
	} else {
 
		if (img_1 == 1 && img_2 == 1) {
 
			_map3_hi[tile] &= ~(3 << 2);
 
@@ -596,7 +596,7 @@ static void TileLoopClearAlps(uint tile)
 

	
 
	m5 = _map5[tile] & 0x1C;
 
	tmp = _map5[tile] & 3;
 
	
 

	
 
	if (k < -8) {
 
		/* snow_m2_down */
 
		if (m5 != 0x10)
 
@@ -671,7 +671,7 @@ static void TileLoop_Clear(uint tile)
 
	byte m5,m3;
 

	
 
	TileLoopClearHelper(tile);
 
	
 

	
 
	if (_opt.landscape == LT_DESERT) {
 
		TileLoopClearDesert(tile);
 
	} else if (_opt.landscape == LT_HILLY) {
 
@@ -685,7 +685,7 @@ static void TileLoop_Clear(uint tile)
 
	if ( (m5 & 0x1C) != 0xC) {
 
		if ( (m5 & 3) == 3)
 
			return;
 
		
 

	
 
		if (_game_mode != GM_EDITOR) {
 
			m5 += 0x20;
 
			if (m5 >= 0x20) {
 
@@ -727,7 +727,7 @@ void GenerateClearTile()
 
	/* add hills */
 
	i = (Random() & 0x3FF) | 0x400;
 
	do {
 
		tile = TILE_MASK(Random());	
 
		tile = TILE_MASK(Random());
 
		if (IS_TILETYPE(tile, MP_CLEAR))
 
			_map5[tile] = (byte)((_map5[tile] & ~(3<<2)) | (1<<2));
 
	} while (--i);
 
@@ -736,7 +736,7 @@ void GenerateClearTile()
 
	i = (Random() & 0x7F) | 0x80;
 
	do {
 
		r = Random();
 
		tile = TILE_MASK(r);	
 
		tile = TILE_MASK(r);
 
		if (IS_TILETYPE(tile, MP_CLEAR)) {
 
			j = ((r >> 16) & 0xF) + 5;
 
			for(;;) {
command.c
Show inline comments
 
@@ -305,7 +305,7 @@ static CommandProc * const _command_proc
 
int32 DoCommandByTile(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc)
 
{
 
	return DoCommand(GET_TILE_X(tile)*16, GET_TILE_Y(tile)*16, p1, p2, flags, procc);
 
} 
 
}
 

	
 

	
 
//extern void _stdcall Sleep(int s);
 
@@ -314,7 +314,7 @@ int32 DoCommand(int x, int y, uint32 p1,
 
{
 
	int32 res;
 
	CommandProc *proc;
 
	
 

	
 
	proc = _command_proc_table[procc];
 

	
 
	if (_docommand_recursive == 0) {
 
@@ -383,7 +383,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	int x = GET_TILE_X(tile)*16;
 
	int y = GET_TILE_Y(tile)*16;
 

	
 
	assert(_docommand_recursive == 0);	
 
	assert(_docommand_recursive == 0);
 

	
 
	_error_message = INVALID_STRING_ID;
 
	_error_message_2 = cmd >> 16;
 
@@ -404,9 +404,9 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	proc = _command_proc_table[cmd & 0xFF];
 

	
 
	// this command is a notest command?
 
	notest = 
 
		(cmd & 0xFF) == CMD_CLEAR_AREA || 
 
		(cmd & 0xFF) == CMD_CONVERT_RAIL || 
 
	notest =
 
		(cmd & 0xFF) == CMD_CLEAR_AREA ||
 
		(cmd & 0xFF) == CMD_CONVERT_RAIL ||
 
		(cmd & 0xFF) == CMD_LEVEL_LAND ||
 
		(cmd & 0xFF) == CMD_TRAIN_GOTO_DEPOT;
 

	
 
@@ -429,7 +429,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
		return false;
 
	}
 

	
 
	
 

	
 

	
 
	// unless the command is a notest command, check if it can be executed.
 
	if (!notest) {
 
@@ -456,7 +456,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	// actually try and execute the command.
 
	_yearly_expenses_type = 0;
 
	res2 = proc(x,y, flags|DC_EXEC, p1, p2);
 
	
 

	
 
	if (!notest) {
 
		assert(res == res2); // sanity check
 
	} else {
 
@@ -479,7 +479,7 @@ bool DoCommandP(TileIndex tile, uint32 p
 
	}
 

	
 
	_docommand_recursive = 0;
 
	
 

	
 
	if (callback) callback(true, tile, p1, p2);
 
	return true;
 

	
 
@@ -490,7 +490,7 @@ show_error:
 

	
 
callb_err:
 
	_docommand_recursive = 0;
 
	
 

	
 
	if (callback) callback(false, tile, p1, p2);
 
	return false;
 
}
command.h
Show inline comments
 
@@ -140,7 +140,7 @@ enum {
 
	CMD_REFIT_RAIL_VEHICLE = 106,
 
	CMD_RESTORE_ORDER_INDEX = 107,
 
	CMD_BUILD_LOCK = 108,
 
	
 

	
 
	CMD_START_SCENARIO = 109,
 
	CMD_BUILD_MANY_SIGNALS = 110,
 

	
 
@@ -157,7 +157,7 @@ enum {
 
	DC_AI_BUILDING = 0x20,			// special building rules for AI
 
	DC_NO_TOWN_RATING = 0x40,		// town rating does not disallow you from building
 
	DC_FORCETEST = 0x80,				// force test too.
 
	
 

	
 
	CMD_ERROR = ((int32)0x80000000),
 
};
 

	
console.c
Show inline comments
 
@@ -44,7 +44,7 @@ static const WindowDesc _iconsole_window
 
static _iconsole_cmd * _iconsole_cmds; // list of registred commands
 
static _iconsole_var * _iconsole_vars; // list of registred vars
 

	
 
// ** console std lib ** // 
 
// ** console std lib ** //
 
static byte _stdlib_developer=1;
 
static bool _stdlib_con_developer=false;
 
static void IConsoleStdLibRegister();
 
@@ -96,7 +96,7 @@ static void IConsoleWndProc(Window *w, W
 
				GfxFillRect(posx,posy,posx+5,posy+1,color);
 
				_video_driver->make_dirty(posx,posy,5,1);
 
			}
 
			_icursor_counter=0;			
 
			_icursor_counter=0;
 
			}
 
		break;
 

	
 
@@ -157,14 +157,14 @@ static void IConsoleWndProc(Window *w, W
 
			{
 
			IConsoleSwitch();
 
			} else
 
		if (e->keypress.keycode == WKC_RETURN) 
 
		if (e->keypress.keycode == WKC_RETURN)
 
			{
 
			IConsolePrintF(_iconsole_color_commands, "] %s", _iconsole_cmdline);
 
			IConsoleCmdBufferAdd(_iconsole_cmdline);
 
			IConsoleCmdExec((byte *) _iconsole_cmdline);
 
			IConsoleClearCommand();
 
			} else
 
		if (e->keypress.keycode == WKC_BACKSPACE) 
 
		if (e->keypress.keycode == WKC_BACKSPACE)
 
			{
 
			if (_iconsole_cmdpos!=0) _iconsole_cmdpos--;
 
			_iconsole_cmdline[_iconsole_cmdpos]=0;
 
@@ -175,10 +175,10 @@ static void IConsoleWndProc(Window *w, W
 
			{
 
			_iconsole_scroll=79;
 
			_iconsole_cmdline[_iconsole_cmdpos]=e->keypress.ascii;
 
			if (_iconsole_cmdpos!=255) _iconsole_cmdpos++;	
 
			if (_iconsole_cmdpos!=255) _iconsole_cmdpos++;
 
			SetWindowDirty(w);
 
			_iconsole_cmdbufferpos=19;
 
			} else e->keypress.cont=true;	
 
			} else e->keypress.cont=true;
 
		break;
 

	
 
	}
 
@@ -211,9 +211,9 @@ for (i=0;i<80;i++) {
 
	}
 
IConsoleStdLibRegister();
 
#if defined(WITH_REV)
 
IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision);	
 
IConsolePrintF(13,"OpenTTD Game Console Revision 3 - %s",_openttd_revision);
 
#else
 
IConsolePrint(13,"OpenTTD Game Console Revision 3");	
 
IConsolePrint(13,"OpenTTD Game Console Revision 3");
 
#endif
 
IConsolePrint(12,"---------------------------------");
 
IConsolePrint(12,"use \"help\" for more info");
 
@@ -386,7 +386,7 @@ void* IConsoleCmdGetAddr(byte * name) {
 
_iconsole_cmd * item;
 

	
 
item = _iconsole_cmds;
 
while (item != NULL) { 
 
while (item != NULL) {
 
	if (strcmp(item->name,name)==0) return item->addr;
 
	item = item->_next;
 
	}
 
@@ -455,7 +455,7 @@ if (item == NULL) {
 
_iconsole_var * item;
 

	
 
item = _iconsole_vars;
 
while (item != NULL) { 
 
while (item != NULL) {
 
	if (strcmp(item->name,name)==0) return item;
 
	item = item->_next;
 
	}
 
@@ -733,7 +733,7 @@ tokenstream--;
 
if (!(*tokenstream==0)) {
 
	c++;
 
	tokenstream++;
 
	*tokenstream = 0;	
 
	*tokenstream = 0;
 
	}
 

	
 
//** interpreting **//
 
@@ -790,7 +790,7 @@ if (function != NULL) {
 
//** executing **//
 
if (_stdlib_con_developer) IConsolePrintF(_iconsole_color_debug,"CONDEBUG: execution_mode: %i",execution_mode);
 
switch (execution_mode) {
 
case 0: 
 
case 0:
 
	{
 
	// not found
 
	IConsoleError("command or variable not found");
 
@@ -830,7 +830,7 @@ case 2:
 
				else if (strcmp(tokens[1],"--")==0) {
 
					*(bool *)var->addr=!*(bool *)var->addr;
 
					IConsoleVarDump(var,NULL);
 
					}	 
 
					}
 
				else { IConsoleError("operation not supported"); }
 
				}
 
				break;
 
@@ -852,7 +852,7 @@ case 2:
 
				else if (strcmp(tokens[1],"--")==0) {
 
					(*(byte *)var->addr)--;
 
					IConsoleVarDump(var,NULL);
 
					}	 
 
					}
 
				else { IConsoleError("operation not supported"); }
 
				}
 
				break;
 
@@ -1083,7 +1083,7 @@ case 4:
 
			result = NULL;
 
			}
 
		}
 
	
 

	
 
	}
 
	break;
 
default:
 
@@ -1129,7 +1129,7 @@ static _iconsole_var * IConsoleStdLibPri
 
}
 

	
 
static _iconsole_var * IConsoleStdLibScreenShot(byte argc, byte* argv[], byte argt[]) {
 
	
 

	
 
	if (argc<2) {
 
		_make_screenshot=1;
 
	} else {
 
@@ -1201,7 +1201,7 @@ int l = 0;
 
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
 

	
 
item = _iconsole_cmds;
 
while (item != NULL) { 
 
while (item != NULL) {
 
	if (argv[1]!=NULL) {
 

	
 
		if (memcmp((void *) item->name, (void *) argv[1],l)==0)
 
@@ -1225,7 +1225,7 @@ int l = 0;
 
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
 

	
 
item = _iconsole_vars;
 
while (item != NULL) { 
 
while (item != NULL) {
 
	if (argv[1]!=NULL) {
 

	
 
		if (memcmp((void *) item->name, (void *) argv[1],l)==0)
 
@@ -1249,7 +1249,7 @@ int l = 0;
 
if (argv[1]!=NULL) l = strlen((char *) argv[1]);
 

	
 
item = _iconsole_vars;
 
while (item != NULL) { 
 
while (item != NULL) {
 
	if (argv[1]!=NULL) {
 

	
 
		if (memcmp((void *) item->name, (void *) argv[1],l)==0)
disaster_cmd.c
Show inline comments
 
@@ -13,7 +13,7 @@
 
static void DisasterClearSquare(uint tile)
 
{
 
	int type;
 
		
 

	
 
	if (!EnsureNoVehicle(tile))
 
		return;
 

	
 
@@ -107,7 +107,7 @@ static void SetDisasterVehiclePos(Vehicl
 

	
 
	if ( (u=v->next) != NULL) {
 
		BeginVehicleMove(u);
 
	
 

	
 
		u->x_pos = x;
 
		u->y_pos = yt = y - 1 - (max(z - GetSlopeZ(x, y-1), 0) >> 3);
 
		u->z_pos = GetSlopeZ(x,yt);
 
@@ -144,7 +144,7 @@ static void DisasterTick_Zeppeliner(Vehi
 
			return;
 

	
 
		GetNewVehiclePos(v, &gp);
 
		
 

	
 
		SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
		if (v->next_order == 1) {
 
@@ -162,7 +162,7 @@ static void DisasterTick_Zeppeliner(Vehi
 
			if (IS_TILETYPE(tile, MP_STATION) &&
 
				IS_BYTE_INSIDE(_map5[tile], 8, 0x43) &&
 
				IS_HUMAN_PLAYER(_map_owner[tile])) {
 
				
 

	
 
				v->next_order = 1;
 
				v->age = 0;
 

	
 
@@ -176,12 +176,12 @@ static void DisasterTick_Zeppeliner(Vehi
 
		if (v->y_pos >= (TILES_Y+9) * 16 - 1)
 
			DeleteDisasterVeh(v);
 
		return;
 
	} 
 
	
 
	}
 

	
 
	if (v->next_order > 2) {
 
		if (++v->age <= 13320)
 
			return;
 
		
 

	
 
		tile = v->tile; /**/
 

	
 
		if (IS_TILETYPE(tile, MP_STATION) &&
 
@@ -245,9 +245,9 @@ static void DisasterTick_UFO(Vehicle *v)
 
	byte z;
 

	
 
	v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44;
 
	
 

	
 
	if (v->next_order == 0) {
 
// fly around randomly 
 
// fly around randomly
 
		int x = GET_TILE_X(v->dest_tile)*16;
 
		int y = GET_TILE_Y(v->dest_tile)*16;
 
		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
 
@@ -288,11 +288,11 @@ static void DisasterTick_UFO(Vehicle *v)
 

	
 
		v->direction = GetDirectionTowards(v, u->x_pos, u->y_pos);
 
		GetNewVehiclePos(v, &gp);
 
		
 

	
 
		z = v->z_pos;
 
		if (dist <= 16 && z > u->z_pos) z--;
 
		SetDisasterVehiclePos(v, gp.x, gp.y, z);
 
			
 

	
 
		if (z <= u->z_pos && (u->vehstatus&VS_HIDDEN)==0) {
 
			v->age++;
 
			if (u->u.road.crashed_ctr == 0) {
 
@@ -332,10 +332,10 @@ static void DestructIndustry(Industry *i
 
static void DisasterTick_2(Vehicle *v)
 
{
 
	GetNewVehiclePosResult gp;
 
	
 

	
 
	v->tick_counter++;
 
	v->u.disaster.image_override = (v->next_order == 1 && v->tick_counter&4) ? 0xF4F : 0;
 
	
 

	
 
	GetNewVehiclePos(v, &gp);
 
	SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
 

	
 
@@ -386,7 +386,7 @@ static void DisasterTick_2(Vehicle *v)
 
			return;
 

	
 
		tile = TILE_FROM_XY(x,y);
 
		if (!IS_TILETYPE(tile, MP_INDUSTRY))	
 
		if (!IS_TILETYPE(tile, MP_INDUSTRY))
 
			return;
 

	
 
		v->dest_tile = ind = _map2[tile];
 
@@ -456,7 +456,7 @@ static void DisasterTick_3(Vehicle *v)
 
			return;
 

	
 
		tile = TILE_FROM_XY(x,y);
 
		if (!IS_TILETYPE(tile, MP_INDUSTRY))	
 
		if (!IS_TILETYPE(tile, MP_INDUSTRY))
 
			return;
 

	
 
		v->dest_tile = ind = _map2[tile];
 
@@ -546,7 +546,7 @@ static void DisasterTick_4(Vehicle *v)
 
		InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12);
 
		w->vehstatus |= VS_DISASTER;
 
	} else if (v->next_order < 1) {
 
		
 

	
 
		int x = GET_TILE_X(v->dest_tile)*16;
 
		int y = GET_TILE_Y(v->dest_tile)*16;
 
		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
 
@@ -593,7 +593,7 @@ static void DisasterTick_4b(Vehicle *v)
 
	}
 

	
 
	if (v->next_order == 0) {
 
		u = &_vehicles[v->u.disaster.unk2];	
 
		u = &_vehicles[v->u.disaster.unk2];
 
		if (abs(v->x_pos - u->x_pos) > 16)
 
			return;
 
		v->next_order = 1;
 
@@ -685,7 +685,7 @@ void OnNewDay_DisasterVehicle(Vehicle *v
 
typedef void DisasterInitProc();
 

	
 
// Zeppeliner which crashes on a small airport
 
static void Disaster0_Init() 
 
static void Disaster0_Init()
 
{
 
	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
 
	Station *st;
 
@@ -695,7 +695,7 @@ static void Disaster0_Init()
 
		return;
 

	
 
	for(st=_stations;;) {
 
		if (st->xy && st->airport_tile != 0 && 
 
		if (st->xy && st->airport_tile != 0 &&
 
				st->airport_type <= 1 &&
 
				IS_HUMAN_PLAYER(st->owner)) {
 
			x = (GET_TILE_X(st->xy) + 2) * 16;
 
@@ -714,12 +714,12 @@ static void Disaster0_Init()
 
	u = ForceAllocateSpecialVehicle();
 
	if (u != NULL) {
 
		v->next = u;
 
		InitializeDisasterVehicle(u,x,0,0,3,1); 
 
		InitializeDisasterVehicle(u,x,0,0,3,1);
 
		u->vehstatus |= VS_DISASTER;
 
	}
 
}
 

	
 
static void Disaster1_Init() 
 
static void Disaster1_Init()
 
{
 
	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
 
	int x;
 
@@ -737,12 +737,12 @@ static void Disaster1_Init()
 
	u = ForceAllocateSpecialVehicle();
 
	if (u != NULL) {
 
		v->next = u;
 
		InitializeDisasterVehicle(u,x,0,0,3,3); 
 
		InitializeDisasterVehicle(u,x,0,0,3,3);
 
		u->vehstatus |= VS_DISASTER;
 
	}
 
}
 

	
 
static void Disaster2_Init() 
 
static void Disaster2_Init()
 
{
 
	Industry *i, *found;
 
	Vehicle *v,*u;
 
@@ -750,7 +750,7 @@ static void Disaster2_Init()
 

	
 
	for(found=NULL,i=_industries; i != endof(_industries); i++) {
 
		if (i->xy != 0 &&
 
				i->type == IT_OIL_REFINERY && 
 
				i->type == IT_OIL_REFINERY &&
 
				(found==NULL || CHANCE16(1,2))) {
 
			found = i;
 
		}
 
@@ -771,12 +771,12 @@ static void Disaster2_Init()
 
	u = ForceAllocateSpecialVehicle();
 
	if (u != NULL) {
 
		v->next = u;
 
		InitializeDisasterVehicle(u,x,y,0,3,5); 
 
		InitializeDisasterVehicle(u,x,y,0,3,5);
 
		u->vehstatus |= VS_DISASTER;
 
	}
 
}
 

	
 
static void Disaster3_Init() 
 
static void Disaster3_Init()
 
{
 
	Industry *i, *found;
 
	Vehicle *v,*u,*w;
 
@@ -784,7 +784,7 @@ static void Disaster3_Init()
 

	
 
	for(found=NULL,i=_industries; i != endof(_industries); i++) {
 
		if (i->xy != 0 &&
 
				i->type == IT_FACTORY && 
 
				i->type == IT_FACTORY &&
 
				(found==NULL || CHANCE16(1,2))) {
 
			found = i;
 
		}
 
@@ -805,18 +805,18 @@ static void Disaster3_Init()
 
	u = ForceAllocateSpecialVehicle();
 
	if (u != NULL) {
 
		v->next = u;
 
		InitializeDisasterVehicle(u,x,y,0,5,7); 
 
		InitializeDisasterVehicle(u,x,y,0,5,7);
 
		u->vehstatus |= VS_DISASTER;
 

	
 
		w = ForceAllocateSpecialVehicle();
 
		if (w != NULL) {
 
			u->next = w;
 
			InitializeDisasterVehicle(w,x,y,140,5,8); 
 
			InitializeDisasterVehicle(w,x,y,140,5,8);
 
		}
 
	}
 
}
 

	
 
static void Disaster4_Init() 
 
static void Disaster4_Init()
 
{
 
	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
 
	int x,y;
 
@@ -835,13 +835,13 @@ static void Disaster4_Init()
 
	u = ForceAllocateSpecialVehicle();
 
	if (u != NULL) {
 
		v->next = u;
 
		InitializeDisasterVehicle(u,x,y,0,7,10); 
 
		InitializeDisasterVehicle(u,x,y,0,7,10);
 
		u->vehstatus |= VS_DISASTER;
 
	}
 
}
 

	
 
// Submarine type 1
 
static void Disaster5_Init() 
 
static void Disaster5_Init()
 
{
 
	Vehicle *v = ForceAllocateSpecialVehicle();
 
	int x,y;
 
@@ -862,7 +862,7 @@ static void Disaster5_Init()
 
}
 

	
 
// Submarine type 2
 
static void Disaster6_Init() 
 
static void Disaster6_Init()
 
{
 
	Vehicle *v = ForceAllocateSpecialVehicle();
 
	int x,y;
 
@@ -882,20 +882,20 @@ static void Disaster6_Init()
 
	v->age = 0;
 
}
 

	
 
static void Disaster7_Init() 
 
static void Disaster7_Init()
 
{
 
	Industry *i;
 
	int maxloop = 15;
 
	int index = Random() & 0xF;
 
	
 

	
 
	do {
 
		for(i=_industries; i != endof(_industries); i++) {
 
			if (i->xy != 0 && i->type == IT_COAL_MINE	&& --index < 0) {
 
				
 

	
 
				SET_DPARAM16(0, i->town->index);
 
				AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES, 
 
				AddNewsItem(STR_B005_COAL_MINE_SUBSIDENCE_LEAVES,
 
					NEWS_FLAGS(NM_THIN,NF_VIEWPORT|NF_TILE,NT_ACCIDENT,0), i->xy + TILE_XY(1,1), 0);
 
				
 

	
 
				{
 
					uint tile = i->xy;
 
					int step = _tileoffs_by_dir[Random() & 3];
dock_gui.c
Show inline comments
 
@@ -129,7 +129,7 @@ static void BuildDocksToolbWndProc(Windo
 

	
 
	case WE_PLACE_OBJ:
 
		_place_proc(e->place.tile);
 
		break;	
 
		break;
 

	
 
	case WE_PLACE_DRAG: {
 
		VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
 
@@ -155,7 +155,7 @@ static void BuildDocksToolbWndProc(Windo
 
		w = FindWindowById(WC_BUILD_DEPOT, 0);
 
		if (w != NULL) WP(w,def_d).close=true;
 
		break;
 
	
 

	
 
	case WE_PLACE_PRESIZE: {
 
		uint tile_from, tile_to;
 

	
 
@@ -225,7 +225,7 @@ static void BuildDockStationWndProc(Wind
 
		CheckRedrawStationCoverage(w);
 
		break;
 
	}
 
	}	
 
	}
 
}
 

	
 
static const Widget _build_dock_station_widgets[] = {
economy.c
Show inline comments
 
@@ -44,11 +44,11 @@ void UpdatePlayerHouse(Player *p, uint s
 
uint32 CalculateCompanyValue(Player *p) {
 
	byte owner = p->index;
 
	uint32 value;
 
	
 

	
 
	{
 
		Station *st;
 
		uint num = 0;
 
		
 

	
 
		FOR_ALL_STATIONS(st) {
 
			if (st->xy != 0 && st->owner == owner) {
 
				uint facil = st->facilities;
 
@@ -194,7 +194,7 @@ int UpdateCompanyRatingAndValue(Player *
 
	{
 
		_score_part[owner][SCORE_LOAN] = score_info[SCORE_LOAN].needed - p->current_loan;
 
	}
 
	
 

	
 
	// Now we calculate the score for each item..
 
	{
 
		int i;
 
@@ -210,9 +210,9 @@ int UpdateCompanyRatingAndValue(Player *
 
			score += s;
 
			total_score += score_info[i].score;
 
		}
 
		
 

	
 
		_score_part[owner][SCORE_TOTAL] = score;
 
		
 

	
 
		// We always want the score scaled to SCORE_MAX (1000)
 
		if (total_score != SCORE_MAX)
 
			score = score * SCORE_MAX / total_score;
 
@@ -223,7 +223,7 @@ int UpdateCompanyRatingAndValue(Player *
 
    	UpdatePlayerHouse(p, score);
 
    	p->old_economy[0].company_value = CalculateCompanyValue(p);
 
    }
 
	
 

	
 
	InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
 
	return score;
 
}
 
@@ -236,7 +236,7 @@ void ChangeOwnershipOfPlayerItems(byte o
 

	
 
	if (new_player == 255) {
 
		Subsidy *s;
 
		
 

	
 
		for(s=_subsidies; s != endof(_subsidies); s++) {
 
			if (s->cargo_type != 0xff && s->age >= 12) {
 
				Station *st = DEREF_STATION(s->to);
 
@@ -249,7 +249,7 @@ void ChangeOwnershipOfPlayerItems(byte o
 
	// take care of rating in towns
 
	{
 
		Town *t;
 
		
 

	
 
		// if a player takes over, give the ratings to that player.
 
		if (new_player != 255) {
 
			FOR_ALL_TOWNS(t) if (t->xy && HASBIT(t->have_ratings, old_player)) {
 
@@ -269,7 +269,7 @@ void ChangeOwnershipOfPlayerItems(byte o
 
			CLRBIT(t->have_ratings, old_player);
 
		}
 
	}
 
	
 

	
 
	{
 
		int num_train = 0;
 
		int num_road = 0;
 
@@ -353,7 +353,7 @@ static void PlayersCheckBankrupt(Player 
 

	
 
	if (p->quarters_of_bankrupcy == 2) {
 
year_2:
 
		AddNewsItem( (StringID)(owner + 16), 
 
		AddNewsItem( (StringID)(owner + 16),
 
			NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
 

	
 
	} else if (p->quarters_of_bankrupcy == 3) {
 
@@ -396,7 +396,7 @@ void DrawNewsBankrupcy(Window *w)
 
{
 
	Player *p;
 

	
 
	DrawNewsBorder(w);		
 
	DrawNewsBorder(w);
 

	
 
	p = DEREF_PLAYER(WP(w,news_d).ni->string_id & 15);
 
	DrawPlayerFace(p->face, p->player_color, 2, 23);
 
@@ -446,7 +446,7 @@ void DrawNewsBankrupcy(Window *w)
 
			90,
 
			STR_705D_HAS_BEEN_CLOSED_DOWN_BY,
 
			w->width - 101);
 
		break;		
 
		break;
 

	
 
	case 4:
 
		DrawStringCentered(w->width>>1, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, 0);
 
@@ -499,7 +499,7 @@ StringID GetNewsStringBankrupcy(NewsItem
 
	default:
 
		NOT_REACHED();
 
	}
 
  
 

	
 
	/* useless, but avoids compiler warning this way */
 
	return 0;
 
}
 
@@ -563,13 +563,13 @@ static void AddInflation()
 
	}
 

	
 
	_economy.max_loan_unround += BIGMULUS(_economy.max_loan_unround, inf, 16);
 
	
 

	
 
	if (_economy.max_loan + 50000 <= _economy.max_loan_unround)
 
		_economy.max_loan += 50000;
 

	
 
	inf = _economy.infl_amount_pr * 54;
 
	for(i=0; i!=NUM_CARGO; i++) {
 
		AddSingleInflation( 
 
		AddSingleInflation(
 
			_cargo_payment_rates + i,
 
			_cargo_payment_rates_frac + i,
 
			inf
 
@@ -592,7 +592,7 @@ static void PlayersPayInterest()
 

	
 
		_current_player = p->index;
 
		SET_EXPENSES_TYPE(EXPENSES_LOAN_INT);
 
		
 

	
 
		SubtractMoneyFromPlayer(BIGMULUS(p->current_loan, interest, 16));
 

	
 
		SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
@@ -767,28 +767,28 @@ Pair SetupSubsidyDecodeParam(Subsidy *s,
 
void DeleteSubsidyWithIndustry(byte index)
 
{
 
	Subsidy *s;
 
	
 

	
 
	for(s=_subsidies; s != endof(_subsidies); s++) {
 
		if (s->cargo_type != 0xFF && s->age < 12 &&
 
				s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
 
				(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
 
			s->cargo_type = 0xFF;
 
		}
 
	}	
 
	}
 
}
 

	
 
void DeleteSubsidyWithStation(byte index) 
 
void DeleteSubsidyWithStation(byte index)
 
{
 
	Subsidy *s;
 
	bool dirty = false;
 
	
 

	
 
	for(s=_subsidies; s != endof(_subsidies); s++) {
 
		if (s->cargo_type != 0xFF && s->age >= 12 &&
 
				(s->from == index || s->to == index)) {
 
			s->cargo_type = 0xFF;
 
			dirty = true;
 
		}
 
	}	
 
	}
 

	
 
	if (dirty)
 
		InvalidateWindow(WC_SUBSIDIES_LIST, 0);
 
@@ -852,7 +852,7 @@ static void FindSubsidyCargoRoute(FoundR
 
	if (cargo == CT_GOODS || cargo == CT_FOOD) {
 
		// The destination is a town
 
		Town *t = DEREF_TOWN(RandomRange(_total_towns));
 
		
 

	
 
		// Only want big towns
 
		if (t->xy == 0 || t->population < 900)
 
			return;
 
@@ -861,9 +861,9 @@ static void FindSubsidyCargoRoute(FoundR
 
	} else {
 
		// The destination is an industry
 
		Industry *i2 = DEREF_INDUSTRY(RandomRange(_total_industries));
 
		
 

	
 
		// The industry must accept the cargo
 
		if (i == i2 || i2->xy == 0 || 
 
		if (i == i2 || i2->xy == 0 ||
 
				(cargo != i2->accepts_cargo[0] &&
 
				cargo != i2->accepts_cargo[1] &&
 
				cargo != i2->accepts_cargo[2]))
 
@@ -873,15 +873,15 @@ static void FindSubsidyCargoRoute(FoundR
 
	}
 
}
 

	
 
static bool CheckSubsidyDuplicate(Subsidy *s) 
 
static bool CheckSubsidyDuplicate(Subsidy *s)
 
{
 
	Subsidy *ss;
 

	
 
	for(ss=_subsidies; ss != endof(_subsidies); ss++) {
 
		if (s != ss && 
 
//				ss->age < 12 && 
 
				ss->from == s->from && 
 
				ss->to == s->to && 
 
		if (s != ss &&
 
//				ss->age < 12 &&
 
				ss->from == s->from &&
 
				ss->to == s->to &&
 
				ss->cargo_type == s->cargo_type) {
 
			s->cargo_type = 0xFF;
 
			return true;
 
@@ -929,7 +929,7 @@ static void SubsidyMonthlyHandler()
 
			if (++s == endof(_subsidies))
 
				goto no_add;
 
		}
 
		
 

	
 
		n = 1000;
 
		do {
 
			FindSubsidyPassengerRoute(&fr);
 
@@ -1002,7 +1002,7 @@ int32 GetTransportedGoodsIncome(uint num
 
	if (transit_days > _cargoc.transit_days_1[cargo]) {
 
		transit_days -= _cargoc.transit_days_1[cargo];
 
		f -= transit_days;
 
		
 

	
 
		if (transit_days > _cargoc.transit_days_2[cargo]) {
 
			transit_days -= _cargoc.transit_days_2[cargo];
 

	
 
@@ -1019,7 +1019,7 @@ int32 GetTransportedGoodsIncome(uint num
 

	
 
static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces)
 
{
 
	Industry *ind, *best;	
 
	Industry *ind, *best;
 
	int t, u;
 

	
 
	/* Check if there's an industry close to the station that accepts
 
@@ -1031,7 +1031,7 @@ static void DeliverGoodsToIndustry(TileI
 
				 == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
 
				 ind->produced_cargo[0] != 0xFF &&
 
				 ind->produced_cargo[0] != cargo_type &&
 
				 (t=GetTileDist(ind->xy, xy)) < u) {			
 
				 (t=GetTileDist(ind->xy, xy)) < u) {
 
			u = t;
 
			best = ind;
 
		}
 
@@ -1063,7 +1063,7 @@ static bool CheckSubsidised(Station *fro
 
	/* check if there's a new subsidy that applies.. */
 
	for(s=_subsidies; s != endof(_subsidies); s++) {
 
		if (s->cargo_type == cargo_type && s->age < 12) {
 
		
 

	
 
			/* Check distance from source */
 
			if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL) {
 
				xy = DEREF_TOWN(s->from)->xy;
 
@@ -1072,7 +1072,7 @@ static bool CheckSubsidised(Station *fro
 
			}
 
			if (GetTileDist1D(xy, from->xy) > 9)
 
				continue;
 
			
 

	
 
			/* Check distance from dest */
 
			if (cargo_type == CT_PASSENGERS || cargo_type == CT_MAIL || cargo_type == CT_GOODS || cargo_type == CT_FOOD) {
 
				xy = DEREF_TOWN(s->to)->xy;
 
@@ -1096,7 +1096,7 @@ static bool CheckSubsidised(Station *fro
 
			SET_DPARAM16(0, p->name_1);
 
			SET_DPARAM32(1, p->name_2);
 
			AddNewsItem(
 
				STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier, 
 
				STR_2031_SERVICE_SUBSIDY_AWARDED + _opt.diff.subsidy_multiplier,
 
				NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0),
 
				pair.a, pair.b);
 

	
 
@@ -1138,7 +1138,7 @@ static int32 DeliverGoods(int num_pieces
 

	
 
	// Give the goods to the industry.
 
	DeliverGoodsToIndustry(s_to->xy, cargo_type, num_pieces);
 
	
 

	
 
	// Determine profit
 
	{
 
		int t = GetTileDist(s_from->xy, s_to->xy);
 
@@ -1197,7 +1197,7 @@ int LoadUnloadVehicle(Vehicle *v)
 
	for(;;) {
 
		if (v->cargo_cap == 0)
 
			goto next_vehicle;
 
		
 

	
 
		ge = &st->goods[v->cargo_type];
 

	
 
		/* unload? */
 
@@ -1211,7 +1211,7 @@ int LoadUnloadVehicle(Vehicle *v)
 
			} else if (u->next_order & OF_UNLOAD) {
 
				/* unload goods and let it wait at the station */
 
				st->time_since_unload = 0;
 
				
 

	
 
				if ((t=ge->waiting_acceptance & 0xFFF) == 0) {
 
					// No goods waiting at station
 
					ge->enroute_time = v->cargo_days;
 
@@ -1229,7 +1229,7 @@ int LoadUnloadVehicle(Vehicle *v)
 
				v->cargo_count = 0;
 
			}
 
		}
 
	
 

	
 
		/* don't pick up goods that we unloaded */
 
		if (u->next_order & OF_UNLOAD)
 
			goto next_vehicle;
 
@@ -1238,7 +1238,7 @@ int LoadUnloadVehicle(Vehicle *v)
 
		ge->days_since_pickup = 0;
 
		t = u->max_speed;
 
		if (u->type == VEH_Road) t >>=1;
 
		
 

	
 
		// if last speed is 0, we treat that as if no vehicle has ever visited the station.
 
		ge->last_speed = t < 255 ? t : 255;
 
		ge->last_age = _cur_year - v->build_year;
 
@@ -1252,7 +1252,7 @@ int LoadUnloadVehicle(Vehicle *v)
 
			ge->waiting_acceptance -= cap;
 
			unloading_time += cap;
 
			st->time_since_load = 0;
 
			
 

	
 
			// And record the source of the cargo, and the days in travel.
 
			v->cargo_source = ge->enroute_from;
 
			v->cargo_days = ge->enroute_time;
economy.h
Show inline comments
 
@@ -36,7 +36,7 @@ enum {
 
    SCORE_TOTAL = 9, // This must always be the last entry
 

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

	
 
    SCORE_MAX = 1000, 	// The max score that can be in the performance history
 
    					//  the scores together of score_info is allowed to be more!
 
};
engine.c
Show inline comments
 
@@ -124,7 +124,7 @@ void StartupEngines()
 
		e->railtype = ei->railtype_climates >> 4;
 
		e->flags = 0;
 
		e->player_avail = 0;
 
		
 

	
 
		r = Random();
 
		e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro);
 
		if (e->intro_date <= _date) {
 
@@ -191,7 +191,7 @@ void SetWagonOverrideSprites(byte engine
 
	wos->overrides_count++;
 
	wos->overrides = realloc(wos->overrides,
 
	                         wos->overrides_count * sizeof(struct WagonOverride));
 
	
 

	
 
	wo = &wos->overrides[wos->overrides_count - 1];
 
	wo->superset = *superset;
 
	wo->trains = trains;
 
@@ -246,7 +246,7 @@ int GetCustomEngineSprite(byte engine, u
 
		overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
 
		if (overset) superset = overset;
 
	}
 
	
 

	
 
	if (!superset->sprites_per_set && cargo != 29) {
 
		// This superset is empty but perhaps there'll be a default one.
 
		superset = &_engine_custom_sprites[engine][29];
 
@@ -307,7 +307,7 @@ void AcceptEnginePreview(Engine *e, int 
 
	SETBIT(e->player_avail, player);
 

	
 
	p = DEREF_PLAYER(player);
 
	
 

	
 
	UPDATE_PLAYER_RAILTYPE(e,p);
 

	
 
	e->preview_player = 0xFF;
 
@@ -333,7 +333,7 @@ void EnginesDailyLoop()
 
					e->flags &= ~ENGINE_PREVIEWING;
 
					DeleteWindowById(WC_ENGINE_PREVIEW, i);
 
					e->preview_player++;
 
				}	
 
				}
 
			} else if (e->preview_player != 0xFF) {
 
				num = e->preview_player;
 
				mask = 0;
 
@@ -341,7 +341,7 @@ void EnginesDailyLoop()
 
					best_hist = -1;
 
					best_player = -1;
 
					FOR_ALL_PLAYERS(p) {
 
						if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) && 
 
						if (p->is_active && p->block_preview == 0 && !HASBIT(mask,p->index) &&
 
								p->old_economy[0].performance_history > best_hist) {
 
							best_hist = p->old_economy[0].performance_history;
 
							best_player = p->index;
 
@@ -353,7 +353,7 @@ void EnginesDailyLoop()
 
					}
 
					mask |= (1 << best_player);
 
				} while (--num != 0);
 
				
 

	
 
				if (!IS_HUMAN_PLAYER(best_player)) {
 
					/* TTDBUG: TTD has a bug here */
 
					AcceptEnginePreview(e, best_player);
 
@@ -361,7 +361,7 @@ void EnginesDailyLoop()
 
					e->flags |= ENGINE_PREVIEWING;
 
					e->preview_wait = 20;
 
					if (IS_INTERACTIVE_PLAYER(best_player)) {
 
						ShowEnginePreviewWindow(i);					
 
						ShowEnginePreviewWindow(i);
 
					}
 
				}
 
			}
 
@@ -390,7 +390,7 @@ void NewVehicleAvailable(Engine *e)
 
		FOR_ALL_PLAYERS(p) {
 
			if (!HASBIT(e->player_avail,p->index))
 
				continue;
 
		
 

	
 
			for(v=_vehicles;;) {
 
				if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship ||
 
						(v->type == VEH_Aircraft && v->subtype <= 2)) {
 
@@ -466,7 +466,7 @@ int32 CmdRenameEngine(int x, int y, uint
 
	str = AllocateName((byte*)_decode_parameters, 0);
 
	if (str == 0)
 
		return CMD_ERROR;
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		StringID old_str = _engine_name_strings[p1];
 
		_engine_name_strings[p1] = str;
engine_gui.c
Show inline comments
 
@@ -88,7 +88,7 @@ static void EnginePreviewWndProc(Window 
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 3: DeleteWindow(w); break;
 
		case 4: 
 
		case 4:
 
			DoCommandP(0, w->window_number, 0, NULL, CMD_WANT_ENGINE_PREVIEW);
 
			DeleteWindow(w);
 
			break;
 
@@ -150,7 +150,7 @@ void DrawNewsNewAircraftAvail(Window *w)
 
	DrawNewsBorder(w);
 

	
 
	engine = WP(w,news_d).ni->string_id;
 
	
 

	
 
	DrawStringMultiCenter(w->width >> 1, 20, STR_A02C_NEW_AIRCRAFT_NOW_AVAILABLE, w->width - 2);
 
	GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
 

	
 
@@ -203,7 +203,7 @@ void DrawNewsNewShipAvail(Window *w)
 
	DrawNewsBorder(w);
 

	
 
	engine = WP(w,news_d).ni->string_id;
 
	
 

	
 
	DrawStringMultiCenter(w->width >> 1, 20, STR_982C_NEW_SHIP_NOW_AVAILABLE, w->width - 2);
 
	GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
 

	
fileio.c
Show inline comments
 
@@ -101,7 +101,7 @@ void FioOpenFile(int slot, const char *f
 
	char buf[MAX_PATH];
 

	
 
	sprintf(buf, "%s%s", _path.data_dir, filename);
 
	
 

	
 
	f = fopen(buf, "rb");
 
#if !defined(WIN32)
 
	if (f == NULL) {
 
@@ -115,7 +115,7 @@ void FioOpenFile(int slot, const char *f
 

	
 
	if (f == NULL)
 
		error("Cannot open file '%s'", buf);
 
	
 

	
 
	_fio.handles[slot] = f;
 
	FioSeekToFile(slot << 24);
 
}
gfx.c
Show inline comments
 
@@ -242,17 +242,17 @@ void GfxDrawLine(int x, int y, int x2, i
 
// 0 - end of string
 
// 1 - SETX <BYTE>
 
// 2 - SETXY <BYTE> <BYTE>
 
// 3-7 - 
 
// 3-7 -
 
// 8 - TINYFONT
 
// 9 - BIGFONT
 
// 10 - newline
 
// 11-14 - 
 
// 11-14 -
 
// 15-31 - 17 colors
 

	
 

	
 
enum {
 
	ASCII_LETTERSTART = 32,
 
	
 

	
 
	ASCII_SETX = 1,
 
	ASCII_SETXY = 2,
 

	
 
@@ -510,7 +510,7 @@ check_bounds:
 
skip_char:;
 
		for(;;) {
 
			c = *string++;
 
			if (c < ASCII_LETTERSTART) goto skip_cont;			
 
			if (c < ASCII_LETTERSTART) goto skip_cont;
 
		}
 
	}
 

	
 
@@ -586,7 +586,7 @@ static void GfxBlitTileZoomIn(BlitterPar
 

	
 
	if (bp->mode & 1) {
 
		src_o += READ_LE_UINT16(src_o + bp->start_y * 2);
 
		
 

	
 
		do {
 
			do {
 
				done = src_o[0];
 
@@ -1351,7 +1351,7 @@ static void GfxMainBlitter(byte *sprite,
 

	
 
		if (dpi->zoom > 0) {
 
			start_y += bp.height &~ zoom_mask;
 
			bp.height &= zoom_mask; 
 
			bp.height &= zoom_mask;
 
			if (bp.height == 0) return;
 
			y&=zoom_mask;
 
		}
 
@@ -1622,7 +1622,7 @@ void UndrawMouseCursor()
 
			_screen.dst_ptr + _cursor.draw_pos.x + _cursor.draw_pos.y * _screen.pitch,
 
			_cursor_backup,
 
			_cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x, _screen.pitch);
 
		
 

	
 
		_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
	}
 
}
 
@@ -1920,9 +1920,9 @@ void SetAnimatedMouseCursor(const uint16
 
}
 

	
 
bool ChangeResInGame(int w, int h)
 
{	
 
{
 
	if ((_screen.width != w || _screen.height != h) && !_video_driver->change_resolution(w, h))
 
		return false;
 
		return false;
 

	
 
	_cur_resolution[0] = w;
 
	_cur_resolution[1] = h;
gfx.h
Show inline comments
 
@@ -13,7 +13,7 @@ struct DrawPixelInfo {
 
	byte *dst_ptr;
 
	int left, top, width, height;
 
	int pitch;
 
	uint16 zoom;	
 
	uint16 zoom;
 
};
 

	
 

	
 
@@ -47,8 +47,8 @@ int DrawString(int x, int y, uint16 str,
 
void DrawStringCenterUnderline(int x, int y, uint16 str, byte color);
 
int DoDrawString(const byte *string, int x, int y, byte color);
 
void DrawStringRightAligned(int x, int y, uint16 str, byte color);
 
void GfxFillRect(int left, int top, int right, int bottom, int color);	
 
void GfxDrawLine(int left, int top, int right, int bottom, int color);	
 
void GfxFillRect(int left, int top, int right, int bottom, int color);
 
void GfxDrawLine(int left, int top, int right, int bottom, int color);
 
void DrawFrameRect(int left, int top, int right, int bottom, int color, int flags);
 

	
 
int GetStringWidth(const byte *str);
graph_gui.c
Show inline comments
 
@@ -33,7 +33,7 @@ typedef struct GraphDrawer {
 

	
 
void DrawGraph(GraphDrawer *gw)
 
{
 
	
 

	
 
	int i,j,k;
 
	int x,y,old_x,old_y;
 
	int color;
 
@@ -57,7 +57,7 @@ void DrawGraph(GraphDrawer *gw)
 
		GfxFillRect(x, gw->top, x, bottom, color);
 
		x += 22;
 
	} while (--i);
 
	
 

	
 
	/* draw the horizontal lines */
 
	i = 9;
 
	x = gw->left + 44;
 
@@ -95,7 +95,7 @@ void DrawGraph(GraphDrawer *gw)
 
			}
 
		} while (col_ptr++, --num_x);
 
	} while (row_ptr+=24, --num_dataset);
 
	
 

	
 
	/* setup scaling */
 
	y_scaling = 0x80000000;
 
	value = adj_height * 2;
 
@@ -271,10 +271,10 @@ static void SetupGraphDrawerForPlayers(G
 
	int nums;
 
	int mo,yr;
 

	
 
	// Exclude the players which aren't valid	
 
	// Exclude the players which aren't valid
 
	FOR_ALL_PLAYERS(p) {
 
		if (!p->is_active) CLRBIT(showbits,p->index);
 
	}	
 
	}
 
	gd->sel = showbits;
 
	gd->num_vert_lines = 24;
 

	
 
@@ -305,7 +305,7 @@ static void OperatingProfitWndProc(Windo
 
		int numd;
 

	
 
		DrawWindowWidgets(w);
 
		
 

	
 
		gd.left = 2;
 
		gd.top = 18;
 
		gd.height = 136;
 
@@ -314,7 +314,7 @@ static void OperatingProfitWndProc(Windo
 
		gd.color_3 = 0x10;
 
		gd.color_2 = 0xD7;
 
		gd.bg_line_color = 0xE;
 
		
 

	
 
		SetupGraphDrawerForPlayers(&gd);
 

	
 
		numd = 0;
 
@@ -528,13 +528,13 @@ static void PerformanceRatingDetailWndPr
 
		uint16 y=14;
 
		int total_score = 0;
 
		int color_done, color_notdone;
 
		
 

	
 
		// Draw standard stuff
 
		DrawWindowWidgets(w);
 
		
 

	
 
		// The player of which we check the detail performance rating
 
		owner = FindFirstBit(w->click_state) - 13;
 
		
 

	
 
		// Paint the player icons
 
		for (i=0;i<MAX_PLAYERS;i++) {
 
       		if (!DEREF_PLAYER(i)->is_active) {
 
@@ -550,7 +550,7 @@ static void PerformanceRatingDetailWndPr
 
                }
 
               	continue;
 
            }
 
			
 

	
 
			// Check if we have the player marked as inactive
 
			if ((w->disabled_state & (1 << (i+13)))) {
 
				// New player! Yippie :p
 
@@ -558,11 +558,11 @@ static void PerformanceRatingDetailWndPr
 
               	// We need a repaint
 
               	SetWindowDirty(w);
 
            }
 
				
 

	
 
			if (i == owner) x = 1; else x = 0;
 
			DrawPlayerIcon(i, i*33+11+x, 16+x);
 
		}
 
		
 

	
 
		// The colors used to show how the progress is going
 
		color_done = _color_list[6].window_color_1b;
 
		color_notdone = _color_list[4].window_color_1b;
 
@@ -579,44 +579,44 @@ static void PerformanceRatingDetailWndPr
 
    			score = SCORE_MAX;
 
    		} else
 
    			total_score += score;
 
    			
 

	
 
    		DrawString(7, y, STR_PERFORMANCE_DETAIL_VEHICLES + i, 0);
 

	
 
    		// Draw the score
 
    		SET_DPARAM32(0, score);
 
    		DrawStringRightAligned(107, y, SET_PERFORMANCE_DETAIL_INT, 0);
 
    		
 

	
 
    		// Calculate the %-bar
 
    		if (val > needed) x = 50;
 
    		else if (val == 0) x = 0;
 
    		else x = ((val * 50) / needed);
 
    		
 

	
 
    		// SCORE_LOAN is inversed
 
    		if (val < 0 && i == SCORE_LOAN)
 
    			x = 0;
 
    		
 

	
 
    		// Draw the bar
 
    		if (x != 0)
 
    			GfxFillRect(112, y-2, x + 112, y+10, color_done);
 
    		if (x != 50)
 
    			GfxFillRect(x + 112, y-2, 50 + 112, y+10, color_notdone);
 
    			
 

	
 
   			// Calculate the %
 
    		if (val > needed) x = 100;
 
    		else x = ((val * 100) / needed);
 
    		
 

	
 
    		// SCORE_LOAN is inversed
 
    		if (val < 0 && i == SCORE_LOAN)
 
    			x = 0;
 
    		
 

	
 
    		// Draw it
 
    		SET_DPARAM32(0, x);
 
    		DrawStringCentered(137, y, STR_PERFORMANCE_DETAIL_PERCENT, 0);
 
    		
 

	
 
    		// SCORE_LOAN is inversed
 
    		if (i == SCORE_LOAN)
 
				val = needed - val;
 
    		
 

	
 
    		// Draw the amount we have against what is needed
 
    		//  For some of them it is in currency format
 
    		SET_DPARAM32(0, val);
 
@@ -666,12 +666,12 @@ static void PerformanceRatingDetailWndPr
 
        	FOR_ALL_PLAYERS(p2)
 
        		if (p2->is_active)
 
        			UpdateCompanyRatingAndValue(p2, false);
 
        		
 

	
 
        	w->custom[0] = DAY_TICKS;
 
        	w->custom[1] = 5;
 
        	
 

	
 
        	w->click_state = 1 << 13;
 
        	
 

	
 
			SetWindowDirty(w);
 
        }
 
    	break;
 
@@ -927,7 +927,7 @@ static void CargoPaymentRatesWndProc(Win
 
		gd.month = 0xFF;
 
		gd.unk61A = 10;
 
		gd.unk61C = 10;
 
		
 

	
 
		for(i=0; i!=NUM_CARGO; i++) {
 
			gd.colors[i] = _cargo_legend_colors[i];
 
			for(j=0; j!=20; j++) {
 
@@ -1031,14 +1031,14 @@ static void CompanyLeagueWndProc(Window 
 
		size_t pl_num, i;
 

	
 
		DrawWindowWidgets(w);
 
		
 

	
 
		pl_num=0;
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active)
 
				plist[pl_num++] = p;
 
		}
 
		assert(pl_num > 0);
 
		
 

	
 
		qsort(plist, pl_num, sizeof(Player*), _perf_hist_comp);
 

	
 
		i = 0;
 
@@ -1047,12 +1047,12 @@ static void CompanyLeagueWndProc(Window 
 
			p = plist[i];
 
			SET_DPARAM16(1, p->name_1);
 
			SET_DPARAM32(2, p->name_2);
 
			
 

	
 
			SET_DPARAM16(3, GetPlayerNameString(p->index, 4));
 
			/*	WARNING ugly hack!
 
					GetPlayerNameString sets up (Player #) if the player is human in an extra DPARAM16
 
					It seems that if player is non-human, nothing is set up, so param is 0. GetString doesn't like
 
					that because there is another param after it. 
 
					that because there is another param after it.
 
					So we'll just shift the rating one back if player is AI and all is fine
 
				*/
 
			SET_DPARAM16((IS_HUMAN_PLAYER(p->index) ? 5 : 4), GetPerformanceTitleFromValue(p->old_economy[1].performance_history));
grfspecial.c
Show inline comments
 
@@ -465,20 +465,20 @@ static void VehicleChangeInfo(byte *buf,
 
			uint8 prop = grf_load_byte(&buf);
 

	
 
			switch (prop) {
 
			case 0x00: {	
 
			case 0x00: {
 
				/* Introduction date */
 
				foreach_engine {
 
					uint16 date = grf_load_word(&buf);
 
					
 

	
 
					ei[i].base_intro = date;
 
				}
 
				break;
 
			}
 
			case 0x02: {	
 
			case 0x02: {
 
				/* Decay speed */
 
				foreach_engine {
 
					uint8 decay = grf_load_byte(&buf);
 
									
 

	
 
					ei[i].unk2 &= 0x80;
 
					ei[i].unk2 |= decay & 0x7f;
 
				}
 
@@ -493,7 +493,7 @@ static void VehicleChangeInfo(byte *buf,
 
				}
 
				break;
 
			}
 
			case 0x04: {	
 
			case 0x04: {
 
				/* Model life */
 
				foreach_engine {
 
					uint8 life = grf_load_byte(&buf);
 
@@ -512,7 +512,7 @@ static void VehicleChangeInfo(byte *buf,
 
				}
 
				break;
 
			}
 
			case 0x07: {	
 
			case 0x07: {
 
				/* Loading speed */
 
				/* Hyronymus explained me what does
 
				 * this mean and insists on having a
 
@@ -636,7 +636,7 @@ static void SpriteNewSuperset(byte *buf,
 
			uint8 nvar = buf[7];
 
			//uint32 val;
 
			uint16 def;
 
			
 

	
 
			grfmsg(GMS_WARN, "SpriteNewSuperset(0x81): Unsupported variable %x. Using default cid.", var);
 

	
 
			//val = (0xff << shiftnum) & andmask;
hal.h
Show inline comments
 
@@ -65,7 +65,7 @@ extern const HalVideoDriver _sdl_video_d
 

	
 
#if defined(UNIX)
 
extern const HalMusicDriver _extmidi_music_driver;
 
#endif 
 
#endif
 

	
 
#if defined(__BEOS__)
 
extern const HalMusicDriver _bemidi_music_driver;
industry_gui.c
Show inline comments
 
@@ -42,7 +42,7 @@ static void BuildIndustryWndProc(Window 
 
		if (DoCommandP(e->place.tile, _build_industry_types[_opt.landscape][WP(w,def_d).data_1], 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY)))
 
			ResetObjectToPlace();
 
		break;
 
		
 

	
 
	case WE_ABORT_PLACE_OBJ:
 
		w->click_state = 0;
 
		SetWindowDirty(w);
 
@@ -259,7 +259,7 @@ static const WindowDesc * const _industr
 
};
 

	
 
void ShowBuildIndustryWindow()
 
{	
 
{
 
	AllocateWindowDescFront(_industry_window_desc[_patches.build_rawmaterial_ind][_opt.landscape],0);
 
}
 

	
 
@@ -291,20 +291,20 @@ static void IndustryViewWndProc(Window *
 
			}
 
			DrawString(2, 107, str, 0);
 
		}
 
		
 

	
 
		if (i->produced_cargo[0] != 0xFF) {
 
			DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
 

	
 
			SET_DPARAM16(1, i->total_production[0]);
 
			SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5)); 
 
			SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
 
			SET_DPARAM16(2, i->pct_transported[0] * 100 >> 8);
 
			DrawString(4, 127, STR_482B_TRANSPORTED, 0);
 

	
 
			if (i->produced_cargo[1] != 0xFF) {
 
				SET_DPARAM16(1, i->total_production[1]);
 
				SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5)); 
 
				SET_DPARAM16(0, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
 
				SET_DPARAM16(2, i->pct_transported[1] * 100 >> 8);
 
				DrawString(4, 137, STR_482B_TRANSPORTED, 0);				
 
				DrawString(4, 137, STR_482B_TRANSPORTED, 0);
 
			}
 
		}
 

	
 
@@ -323,7 +323,7 @@ static void IndustryViewWndProc(Window *
 
			/*	passing only i->xy is not safe if industry has a weird shape like:
 
					_ X X
 
					X X X
 
					_ <--- grass, no industry, but i->xy points there (first top-left tile)!, 
 
					_ <--- grass, no industry, but i->xy points there (first top-left tile)!,
 
					so passing i->xy to destroy industry will fail in called procedure
 
			*/
 
			//DoCommandP(i->xy, w->window_number, 0, CcPlaySound10,  CMD_DESTROY_INDUSTRY | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
 
@@ -399,7 +399,7 @@ static int CDECL GeneralIndustrySorter(c
 
	switch (_industry_sort_order >> 1) {
 
	/* case 0: Sort by Name (handled later) */
 
	case 1: /* Sort by Type */
 
		r = i->type - j->type; 
 
		r = i->type - j->type;
 
		break;
 
	// FIXME - Production & Transported sort need to be inversed...but, WTF it does not wanna!
 
	// FIXME - And no simple --> "if (!(_industry_sort_order & 1)) r = -r;" hack at the bottom!!
 
@@ -407,7 +407,7 @@ static int CDECL GeneralIndustrySorter(c
 
		if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
 
				if (i->produced_cargo[1] == 0xFF) // producing one or two things?
 
					r = j->total_production[0] - i->total_production[0];
 
				else	
 
				else
 
					r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2;
 
		} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
 
			r = 0;
 
@@ -421,7 +421,7 @@ static int CDECL GeneralIndustrySorter(c
 
		if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
 
				if (i->produced_cargo[1] == 0xFF) // producing one or two things?
 
					r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8);
 
				else 
 
				else
 
					r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2;
 
		} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
 
			r = 0;
 
@@ -444,8 +444,8 @@ static int CDECL GeneralIndustrySorter(c
 
		}
 
		r = strcmp(buf1, _bufcache);
 
	}
 
	
 
	if (_industry_sort_order & 1) r = -r;	
 

	
 
	if (_industry_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
@@ -496,7 +496,7 @@ static void IndustryDirectoryWndProc(Win
 
			if (i->produced_cargo[0] != 0xFF) {
 
				SET_DPARAM16(3, i->total_production[0] * 100 >> 8);
 
				SET_DPARAM16(2, _cargoc.names_long_s[i->produced_cargo[0]] + ((i->total_production[0]!=1)<<5));
 
				
 

	
 
				if (i->produced_cargo[1] != 0xFF) {
 
					SET_DPARAM16(5, i->total_production[1] * 100 >> 8);
 
					SET_DPARAM16(4, _cargoc.names_long_s[i->produced_cargo[1]] + ((i->total_production[1]!=1)<<5));
 
@@ -541,7 +541,7 @@ static void IndustryDirectoryWndProc(Win
 
			_industry_sort_dirty = true;
 
			SetWindowDirty(w);
 
		} break;
 
		
 

	
 
		case 7: {
 
			int y = (e->click.pt.y - 28) / 10;
 
			byte p;
 
@@ -561,7 +561,7 @@ static void IndustryDirectoryWndProc(Win
 
	case WE_4:
 
		SetWindowDirty(w);
 
		break;
 
	}  
 
	}
 
}
 

	
 

	
intro_gui.c
Show inline comments
 
@@ -54,7 +54,7 @@ static void SelectGameWndProc(Window *w,
 
		case 3: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
 
		case 4: ShowPatchesSelection(); break;
 
		case 5: DoCommandP(0, InteractiveRandom(), 0, NULL, CMD_CREATE_SCENARIO); break;
 
		case 6: 
 
		case 6:
 
			if (_networking)
 
				DoCommandP(0, 0, 0, NULL, CMD_SET_SINGLE_PLAYER);
 
			break;
 
@@ -113,7 +113,7 @@ int32 CmdStartNewGame(int x, int y, uint
 
		DeleteWindowById(WC_SAVELOAD, 0);
 
		break;
 
	}
 
	
 

	
 
	return 0;
 
}
 

	
 
@@ -216,7 +216,7 @@ static void AskAbandonGameWndProc(Window
 
	case WE_KEYPRESS: /* Exit game on pressing 'Enter' */
 
		if (e->keypress.keycode == WKC_RETURN)
 
			_exit_game = true;
 
		break; 
 
		break;
 
	}
 
}
 

	
 
@@ -247,9 +247,9 @@ static void AskQuitGameWndProc(Window *w
 
	switch(e->event) {
 
	case WE_PAINT:
 
		DrawWindowWidgets(w);
 
		DrawStringMultiCenter(0x5A, 0x26, 
 
			_game_mode != GM_EDITOR ? STR_0160_ARE_YOU_SURE_YOU_WANT_TO : 
 
				STR_029B_ARE_YOU_SURE_YOU_WANT_TO, 
 
		DrawStringMultiCenter(0x5A, 0x26,
 
			_game_mode != GM_EDITOR ? STR_0160_ARE_YOU_SURE_YOU_WANT_TO :
 
				STR_029B_ARE_YOU_SURE_YOU_WANT_TO,
 
			178);
 
		return;
 

	
macros.h
Show inline comments
 
@@ -3,7 +3,7 @@
 

	
 
#define MAX_INT 0x7FFFFFFF
 

	
 
#ifdef min 
 
#ifdef min
 
#undef min
 
#endif
 

	
 
@@ -35,7 +35,7 @@ static INLINE bool str_eq(const byte *a,
 
}
 

	
 
// Will crash if strings are equal
 
static INLINE bool str_is_below(byte *a, byte *b) {		
 
static INLINE bool str_is_below(byte *a, byte *b) {
 
	while (*a <= *b) {
 
		if (*a < *b) return true;
 
		a++;
 
@@ -152,7 +152,7 @@ static INLINE int FindFirstBit2x64(int v
 

	
 

	
 
#if TILE_X_BITS + TILE_Y_BITS <= 16
 
	typedef uint16 TileIndex;	
 
	typedef uint16 TileIndex;
 
	typedef int16 TileIndexDiff;
 
#else
 
	typedef uint32 TileIndex;
 
@@ -210,7 +210,7 @@ static INLINE void swap_tile(TileIndex *
 
	static INLINE uint16 READ_LE_UINT16(const void *b) {
 
		return ((byte*)b)[0] + (((byte*)b)[1] << 8);
 
	}
 
#	define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF 
 
#	define ADD_WORD(x) ((x) >> 8)&0xFF, (x)&0xFF
 
#	define ADD_DWORD(x) ((x) >> 24)&0xFF, ((x) >> 16)&0xFF, ((x) >> 8)&0xFF,  (x)&0xFF
 
#endif
 

	
main_gui.c
Show inline comments
 
@@ -36,7 +36,7 @@ static void HandleOnEditText(WindowEvent
 
	memcpy(_decode_parameters, b, 32);
 

	
 
	id = _rename_id;
 
	
 

	
 
	switch(_rename_what) {
 
	case 0:
 
		// for empty string send "remove sign" parameter
 
@@ -188,7 +188,7 @@ void MenuClickCompany(int index)
 
{
 
	ShowPlayerCompany(index);
 
}
 
	
 

	
 

	
 
void MenuClickGraphs(int index)
 
{
 
@@ -403,11 +403,11 @@ static void MenuWndProc(Window *w, Windo
 
			SetWindowDirty(v);
 
			return;
 
		}
 
		
 

	
 
	case WE_POPUPMENU_SELECT: {
 
		int index = GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y);
 
		int action_id;
 
		
 

	
 

	
 
		if (index < 0) {
 
			Window *w2 = FindWindowById(WC_MAIN_TOOLBAR,0);
 
@@ -417,10 +417,10 @@ static void MenuWndProc(Window *w, Windo
 

	
 
		action_id = WP(w,menu_d).action_id;
 
		DeleteWindow(w);
 
		
 

	
 
		if (index >= 0)
 
			_menu_clicked_procs[action_id](index);
 
	
 

	
 
		break;
 
		}
 
	case WE_POPUPMENU_OVER: {
 
@@ -458,7 +458,7 @@ static int GetPlayerIndexFromMenu(int in
 
				if (--index < 0)
 
					return p->index;
 
			}
 
		} 
 
		}
 
	}
 
	return -1;
 
}
 
@@ -472,7 +472,7 @@ static void UpdatePlayerMenuHeight(Windo
 
		if (p->is_active)
 
			num++;
 
	}
 
	
 

	
 
	if (WP(w,menu_d).item_count != num) {
 
		WP(w,menu_d).item_count = num;
 
		SetWindowDirty(w);
 
@@ -499,25 +499,25 @@ static void PlayerMenuWndProc(Window *w,
 
		y = 1;
 
		sel = WP(w,menu_d).sel_index;
 
		chk = WP(w,menu_d).checked_items; // let this mean gray items.
 
		
 

	
 
		FOR_ALL_PLAYERS(p) {
 
			if (p->is_active) {
 
				if (p->index == sel) {
 
					GfxFillRect(x, y, x + 0xEE, y + 9, 0);
 
				}
 
				DrawSprite( ((p->player_color + 0x307)<<16)+0x82EB, x+2, y+1);
 
			
 

	
 
				SET_DPARAM16(0, p->name_1);
 
				SET_DPARAM32(1, p->name_2);
 
				SET_DPARAM16(2, GetPlayerNameString(p->index, 3));
 
							
 

	
 
				color = (byte)((p->index==sel) ? 0xC : 0x10);
 
				if (chk&1) color = 14;
 
				DrawString(x+0x13, y, STR_7021, color);
 
				
 

	
 
				y += 10;
 
			}	
 
			chk >>= 1;		
 
			}
 
			chk >>= 1;
 
		}
 
		break;
 
		}
 
@@ -528,7 +528,7 @@ static void PlayerMenuWndProc(Window *w,
 
		SetWindowDirty(v);
 
		return;
 
		}
 
		
 

	
 
	case WE_POPUPMENU_SELECT: {
 
		int index = GetPlayerIndexFromMenu(GetMenuItemIndex(w, e->popupmenu.pt.x, e->popupmenu.pt.y));
 
		int action_id = WP(w,menu_d).action_id;
 
@@ -540,7 +540,7 @@ static void PlayerMenuWndProc(Window *w,
 
		}
 

	
 
		DeleteWindow(w);
 
		
 

	
 
		if (index >= 0) {
 
			assert(index >= 0 && index < 30);
 
			_menu_clicked_procs[action_id](index);
 
@@ -576,7 +576,7 @@ static Window *PopupMainToolbMenu(Window
 
	_menu_widgets[0].bottom = h = item_count * 10 + 1;
 
	w = AllocateWindow(x, 0x16, 0xA0, h+1, MenuWndProc, WC_TOOLBAR_MENU, _menu_widgets);
 
	w->flags4 &= ~WF_WHITE_BORDER_MASK;
 
	
 

	
 
	WP(w,menu_d).item_count = item_count;
 
	WP(w,menu_d).sel_index = 0;
 
	WP(w,menu_d).main_button = main_button;
 
@@ -585,7 +585,7 @@ static Window *PopupMainToolbMenu(Window
 
	WP(w,menu_d).checked_items = 0;
 

	
 
	_popup_menu_active = true;
 
	
 

	
 
	SndPlayFx(0x13);
 

	
 
	return w;
 
@@ -594,7 +594,7 @@ static Window *PopupMainToolbMenu(Window
 
static Window *PopupMainPlayerToolbMenu(Window *w, int x, int main_button, int gray)
 
{
 
	x += w->left;
 
	
 

	
 
	SETBIT(w->click_state, main_button);
 
	InvalidateWidget(w, main_button);
 

	
 
@@ -703,7 +703,7 @@ bool DoZoomInOutWindow(int how, Window *
 
{
 
	ViewPort *vp;
 
	int button;
 
	
 

	
 
	switch(_game_mode) {
 
	case GM_EDITOR: button = 9; break;
 
	case GM_NORMAL: button = 17; break;
 
@@ -758,7 +758,7 @@ bool DoZoomInOutWindow(int how, Window *
 
		else if (vp->zoom == 2) SETBIT(wt->disabled_state, button + 1);
 
		SetWindowDirty(wt);
 
	}
 
	
 

	
 
	return true;
 
}
 

	
 
@@ -855,7 +855,7 @@ static void ToolbarScenDateBackward(Wind
 
	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
 
		HandleButtonClick(w, 6);
 
		InvalidateWidget(w, 5);
 
		
 

	
 
		if (_date > 0x2ACE) {
 
			SetDate(ConvertYMDToDay(_cur_year - 1, 0, 1));
 
		}
 
@@ -898,7 +898,7 @@ static void ToolbarScenZoomOut(Window *w
 
	}
 
}
 

	
 
void ZoomInOrOutToCursorWindow(bool in, Window *w) 
 
void ZoomInOrOutToCursorWindow(bool in, Window *w)
 
{
 
	ViewPort * vp;
 
	Point pt;
 
@@ -924,10 +924,10 @@ void ResetLandscape()
 
{
 
	_random_seed_1 = InteractiveRandom();
 
	_random_seed_2 = InteractiveRandom();
 
	
 

	
 
	GenerateWorld(1);
 
	MarkWholeScreenDirty();
 
} 
 
}
 

	
 
static const Widget _ask_reset_landscape_widgets[] = {
 
{    WWT_TEXTBTN,     4,     0,    10,     0,    13, STR_00C5,									STR_NULL},
 
@@ -961,7 +961,7 @@ static void AskResetLandscapeWndProc(Win
 
				SndPlayFx(0x13);
 
				_switch_mode = SM_GENRANDLAND;
 
			}
 
			
 

	
 
			break;
 
		}
 
	}
 
@@ -1131,7 +1131,7 @@ static void ScenEditLandGenWndProc(Windo
 
	case WE_PAINT:
 
		// XXX: only show reset button when nothing was built
 
		DrawWindowWidgets(w);
 
		
 

	
 
		{
 
			int n = _terraform_size * _terraform_size;
 
			const int8 *coords = &_multi_terraform_coords[0][0];
 
@@ -1190,7 +1190,7 @@ terraform_size_common:;
 
		case 10: /* place rocky areas */
 
			HandlePlacePushButton(w, 10, 0xFF7, 1, PlaceProc_RockyArea);
 
			break;
 
			
 

	
 
		case 11: /* place lighthouse */
 
			HandlePlacePushButton(w, 11, 0xFF8, 1, _opt.landscape == LT_DESERT ? PlaceProc_Desert : PlaceProc_LightHouse);
 
			break;
 
@@ -1493,7 +1493,7 @@ static void ScenEditIndustryWndProc(Wind
 
		break;
 

	
 
	case WE_CLICK:
 
		if ((button=e->click.widget) == 3) { 
 
		if ((button=e->click.widget) == 3) {
 
			HandleButtonClick(w, 3);
 

	
 
		if (!AnyTownExists()) {
 
@@ -1505,7 +1505,7 @@ static void ScenEditIndustryWndProc(Wind
 
			GenerateIndustries();
 
			_generating_world = false;
 
		}
 
	
 

	
 
		if ((button=e->click.widget) >= 4) {
 
			if (HandlePlacePushButton(w, button, 0xFF1, 1, NULL))
 
				_industry_type_to_place = _industry_type_list[_opt.landscape][button - 4];
 
@@ -1705,7 +1705,7 @@ static void MainToolbarWndProc(Window *w
 
		case WKC_CTRL | WKC_ALT | 'C': if(!_networking) ShowCheatWindow(); break;
 
		}
 
	} break;
 
	
 

	
 
	case WE_PLACE_OBJ: {
 
		_place_proc(e->place.tile);
 
	} break;
 
@@ -1718,12 +1718,12 @@ static void MainToolbarWndProc(Window *w
 
	case WE_ON_EDIT_TEXT: HandleOnEditText(e); break;
 

	
 
	case WE_MOUSELOOP:
 
		
 

	
 
		if (((w->click_state) & 1) != (uint)!!_pause) {
 
			w->click_state ^= (1 << 0);
 
			SetWindowDirty(w);
 
		}
 
		
 

	
 
		if (((w->click_state >> 1) & 1) != (uint)!!_fast_forward) {
 
			w->click_state ^= (1 << 1);
 
			SetWindowDirty(w);
 
@@ -1900,7 +1900,7 @@ static void ScenEditToolbarWndProc(Windo
 
		}
 
		break;
 
	}
 
	
 

	
 
	case WE_PLACE_OBJ: {
 
		_place_proc(e->place.tile);
 
	} break;
 
@@ -1950,7 +1950,7 @@ static bool DrawScrollingStatusText(News
 
		str = _get_news_string_callback[ni->callback](ni);
 
	} else {
 
		COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
 
		str = ni->string_id;	
 
		str = ni->string_id;
 
	}
 

	
 
	GetString(str_buffr, str);
 
@@ -1992,7 +1992,7 @@ void StatusBarWndProc(Window *w, WindowE
 
		DrawWindowWidgets(w);
 
		SET_DPARAM16(0, _date);
 
		DrawStringCentered(70, 1, ((_pause||_patches.status_long_date)?STR_00AF:STR_00AE), 0);
 
		
 

	
 
		p = _local_player == OWNER_SPECTATOR ? NULL : DEREF_PLAYER(_local_player);
 

	
 
		if (p) {
 
@@ -2092,7 +2092,7 @@ static void MainWindowWndProc(Window *w,
 
			DrawSprite(0x12EA, off_x+275,50); // o
 
			DrawSprite(0x12E5, off_x+307,50); // r
 
			DrawSprite(0x12E4, off_x+337,50); // t
 
			
 

	
 
			DrawSprite(0x12E4, off_x+390,50); // t
 
			DrawSprite(0x12EB, off_x+417,50); // y
 
			DrawSprite(0x12EC, off_x+447,50); // c
 
@@ -2146,7 +2146,7 @@ static void MainWindowWndProc(Window *w,
 
			}
 
			break;
 
		}
 
		
 

	
 
		case WKC_ESC: ResetObjectToPlace(); break;
 
		case WKC_DELETE: DeleteNonVitalWindows(); break;
 
		case 'Q' | WKC_CTRL: AskExitGame(); break;
 
@@ -2185,7 +2185,7 @@ static void MainWindowWndProc(Window *w,
 
		}
 
		e->keypress.cont = false;
 
		break;
 
				
 

	
 
	}
 
}
 

	
 
@@ -2224,7 +2224,7 @@ void SetupColorsAndInitialWindow()
 
		w = AllocateWindowDesc(&_toolb_normal_desc);
 
		w->disabled_state = 1 << 17;
 
		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 
		
 

	
 
		PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_normal_desc)
 

	
 
		_main_status_desc.top = height - 12;
 
@@ -2241,7 +2241,7 @@ void SetupColorsAndInitialWindow()
 
		w = AllocateWindowDesc(&_toolb_scen_desc);
 
		w->disabled_state = 1 << 9;
 
		w->flags4 &= ~WF_WHITE_BORDER_MASK;
 
		
 

	
 
		PositionMainToolbar(w); // already WC_MAIN_TOOLBAR passed (&_toolb_scen_desc)
 
		break;
 
	default:
misc_cmd.c
Show inline comments
 
@@ -39,7 +39,7 @@ int32 CmdSetPlayerColor(int x, int y, ui
 
		if (pp->is_active && pp != p && pp->player_color == (byte)p2)
 
			return CMD_ERROR;
 
	}
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		_player_colors[p1] = (byte)p2;
 
		p->player_color = (byte)p2;
 
@@ -126,7 +126,7 @@ int32 CmdChangeCompanyName(int x, int y,
 
	str = AllocateName((byte*)_decode_parameters, 4);
 
	if (str == 0)
 
		return CMD_ERROR;
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		p = DEREF_PLAYER(p1);
 
		old_str = p->name_1;
 
@@ -148,7 +148,7 @@ int32 CmdChangePresidentName(int x, int 
 
	str = AllocateName((byte*)_decode_parameters, 4);
 
	if (str == 0)
 
		return CMD_ERROR;
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		p = DEREF_PLAYER(p1);
 
		old_str = p->president_name_1;
 
@@ -161,13 +161,13 @@ int32 CmdChangePresidentName(int x, int 
 
			d--; do d++; while (*d);
 
			do *d++ = b = *s++; while(d != (byte*)endof(_decode_parameters) && b != 0);
 
			DoCommandByTile(0, p1, 0, DC_EXEC, CMD_CHANGE_COMPANY_NAME);
 
		} 
 
		}
 
		MarkWholeScreenDirty();
 
	} else {
 
		DeleteName(str);
 
	}
 

	
 
	return 0;	
 
	return 0;
 
}
 

	
 
static void UpdateSignVirtCoords(SignStruct *ss)
 
@@ -200,7 +200,7 @@ static void MarkSignDirty(SignStruct *ss
 
int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SignStruct *ss;
 
	
 

	
 
	for(ss=_sign_list; ss != endof(_sign_list); ss++) {
 
		if (ss->str == 0) {
 
			if (flags & DC_EXEC) {
 
@@ -213,7 +213,7 @@ int32 CmdPlaceSign(int x, int y, uint32 
 
				_new_sign_struct = ss;
 
			}
 
			return 0;
 
		}	
 
		}
 
	}
 

	
 
	return_cmd_error(STR_2808_TOO_MANY_SIGNS);
 
@@ -275,7 +275,7 @@ int32 CmdResume(int x, int y, uint32 fla
 

	
 
int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);	
 
	SET_EXPENSES_TYPE(EXPENSES_OTHER);
 
	return (int32)p1;
 
}
 

	
 
@@ -290,7 +290,7 @@ int32 CmdChangeDifficultyLevel(int x, in
 
		}
 
		InvalidateWindow(WC_GAME_OPTIONS, 0);
 
	}
 
	return 0;	
 
	return 0;
 
}
 

	
 
static const byte _sign_desc[] = {
misc_gui.c
Show inline comments
 
@@ -45,7 +45,7 @@ static void LandInfoWndProc(Window *w, W
 

	
 
		str = STR_01A4_COST_TO_CLEAR_N_A;
 
		if (lid->costclear != CMD_ERROR) {
 
			SET_DPARAM32(0, lid->costclear);	
 
			SET_DPARAM32(0, lid->costclear);
 
			str = STR_01A5_COST_TO_CLEAR;
 
		}
 
		DrawStringCentered(140, 38, str, 0);
 
@@ -102,7 +102,7 @@ static void LandInfoWndProc(Window *w, W
 

	
 
		if (str != (STR_01CE_CARGO_ACCEPTED - 1))
 
			DrawStringMultiCenter(140, 76, str, 276);
 
			
 

	
 
		if (lid->td.build_date != 0) {
 
			SET_DPARAM16(0,lid->td.build_date);
 
			DrawStringCentered(140,71, STR_BUILD_DATE, 0);
 
@@ -136,7 +136,7 @@ static void Place_LandInfo(uint tile)
 

	
 
	w = AllocateWindowDesc(&_land_info_desc);
 
	WP(w,void_d).data = &lid;
 
	
 

	
 
	lid.tile = tile;
 
	lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority);
 

	
 
@@ -150,13 +150,13 @@ static void Place_LandInfo(uint tile)
 
	lid.costclear = DoCommandByTile(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR);
 
	p->money64 = old_money;
 
	UpdatePlayerMoney32(p);
 
	
 

	
 
	// Becuase build_date is not set yet in every TileDesc, we make sure it is empty
 
	lid.td.build_date = 0;
 
	
 

	
 
	GetAcceptedCargo(tile, &lid.ac);
 
	GetTileDesc(tile, &lid.td);
 
	
 

	
 
	#if defined(_DEBUG)
 
		DEBUG(misc, 0) ("TILE: %#x (%i,%i)", tile, GET_TILE_X(tile), GET_TILE_Y(tile));
 
		DEBUG(misc, 0) ("TILE: %d ", tile);
 
@@ -273,7 +273,7 @@ static void BuildTreesWndProc(Window *w,
 
		case 11:case 12: case 13: case 14:
 
			if ( (uint)(wid-3) >= (uint)WP(w,tree_d).count)
 
				return;
 
		
 

	
 
			if (HandlePlacePushButton(w, wid, 0x7DA, 1, NULL))
 
				_tree_to_plant = WP(w,tree_d).base + wid - 3;
 
			break;
 
@@ -292,7 +292,7 @@ static void BuildTreesWndProc(Window *w,
 
			break;
 
		}
 
	} break;
 
		
 

	
 
	case WE_PLACE_OBJ:
 
		VpStartPlaceSizing(e->place.tile, VPM_X_AND_Y_LIMITED);
 
		VpSetPlaceSizingLimit(20);
 
@@ -304,7 +304,7 @@ static void BuildTreesWndProc(Window *w,
 

	
 
	case WE_PLACE_MOUSEUP:
 
		if (e->click.pt.x != -1) {
 
			DoCommandP(e->place.tile, _tree_to_plant, e->place.starttile, NULL, 
 
			DoCommandP(e->place.tile, _tree_to_plant, e->place.starttile, NULL,
 
				CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE));
 
		}
 
		break;
 
@@ -377,7 +377,7 @@ static const WindowDesc _build_trees_sce
 
	BuildTreesWndProc
 
};
 

	
 
	
 

	
 
void ShowBuildTreesToolbar()
 
{
 
	DeleteWindowById(WC_BUILD_TOOLBAR, 0);
 
@@ -418,7 +418,7 @@ static void ErrmsgWndProc(Window *w, Win
 
		if (w->widget != _errmsg_face_widgets) {
 
			DrawStringMultiCenter(
 
				120,
 
				(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15), 
 
				(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15),
 
				_errmsg_message_2,
 
				238);
 
			if (_errmsg_message_1 != INVALID_STRING_ID)
 
@@ -433,7 +433,7 @@ static void ErrmsgWndProc(Window *w, Win
 

	
 
			DrawStringMultiCenter(
 
				214,
 
				(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45), 
 
				(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45),
 
				_errmsg_message_2,
 
				238);
 
			if (_errmsg_message_1 != INVALID_STRING_ID)
 
@@ -490,7 +490,7 @@ void ShowErrorMessage(StringID msg_1, St
 
	_errmsg_duration = _patches.errmsg_duration;
 
	if (!_errmsg_duration)
 
		return;
 
	
 

	
 
	if (_errmsg_message_1 != STR_013B_OWNED_BY || GET_DPARAMX8(_errmsg_decode_params,2) >= 8) {
 

	
 
		if ( (x|y) != 0) {
 
@@ -501,11 +501,11 @@ void ShowErrorMessage(StringID msg_1, St
 
			// move x pos to opposite corner
 
			pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left;
 
			pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20;
 
			
 

	
 
			// move y pos to opposite corner
 
			pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top;
 
			pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100;
 
			
 

	
 
		} else {
 
			pt.x = (_screen.width - 240) >> 1;
 
			pt.y = (_screen.height - 46) >> 1;
 
@@ -566,7 +566,7 @@ static void TooltipsWndProc(Window *w, W
 

	
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);	
 
		GfxFillRect(0, 0, w->width - 1, w->height - 1, 0);
 
		GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44);
 
		DrawStringMultiCenter((w->width>>1), (w->height>>1)-5, WP(w,tooltips_d).string_id, 197);
 
		break;
 
@@ -583,7 +583,7 @@ void GuiShowTooltips(StringID string_id)
 
	Window *w;
 
	int right,bottom;
 
	int x,y;
 
	
 

	
 
	if (string_id == 0)
 
		return;
 

	
 
@@ -628,7 +628,7 @@ static void DrawStationCoverageText(cons
 
{
 
	int i;
 
	byte *b;
 
	
 

	
 
	b = _userstring;
 
	b[0] = 0x81;
 
	b[1] = STR_000D_ACCEPTS;
 
@@ -734,7 +734,7 @@ int HandleEditBoxKey(Window *w, int wid,
 
			count++;
 
			width += _stringwidth_table[*p - 32];
 
		} while (1);
 
		
 

	
 
		if (we->keypress.keycode == WKC_BACKSPACE) {
 
			if (count != 0) {
 
				WP(w,querystr_d).buf[count-1] = 0;
 
@@ -1067,7 +1067,7 @@ static void SaveLoadDlgWndProc(Window *w
 
				return;
 

	
 
			file = _fios_list + y;
 
			
 

	
 
			if ((name = FiosBrowseTo(file)) != NULL) {
 
				if (_saveload_mode == SLD_LOAD_GAME) {
 
					_switch_mode = SM_LOAD;
 
@@ -1120,7 +1120,7 @@ static void SaveLoadDlgWndProc(Window *w
 
		_query_string_active = false;
 
		FiosFreeSavegameList();
 
		break;
 
	}	
 
	}
 
}
 

	
 
static const WindowDesc _load_dialog_desc = {
 
@@ -1226,7 +1226,7 @@ static void SelectScenarioWndProc(Window
 
			_savegame_sort_dirty = false;
 
			MakeSortedSaveGameList();
 
		}
 
		
 

	
 
		SetVScrollCount(w, _fios_num);
 

	
 
		DrawWindowWidgets(w);
 
@@ -1272,7 +1272,7 @@ static void SelectScenarioWndProc(Window
 
					return;
 

	
 
				file = _fios_list + y;
 
			
 

	
 
				if ((name = FiosBrowseTo(file)) != NULL) {
 
					SetFiosType(file->type);
 
					strcpy(_file_to_saveload.name, name);
 
@@ -1410,7 +1410,7 @@ static int32 ReadCE(const CheatEntry*ce)
 
	default:
 
		NOT_REACHED();
 
	}
 
  
 

	
 
	/* useless, but avoids compiler warning this way */
 
	return 0;
 
}
 
@@ -1490,7 +1490,7 @@ static void CheatsWndProc(Window *w, Win
 
				DrawFrameRect(x+30, y+1, x+30+9, y+9, 3, clk == i*2+2 ? 0x20 : 0);
 
				DrawStringCentered(x+25, y+1, STR_6819, 0);
 
				DrawStringCentered(x+35, y+1, STR_681A, 0);
 
				
 

	
 
				val = ReadCE(ce);
 

	
 
				// set correct string for switch climate cheat
 
@@ -1502,7 +1502,7 @@ static void CheatsWndProc(Window *w, Win
 
				// display date for change date cheat
 
				if(ce->str==STR_CHEAT_CHANGE_DATE)
 
					SET_DPARAM16(0, _date);
 
				
 

	
 
				// draw colored flag for change player cheat
 
				if(ce->str==STR_CHEAT_CHANGE_PLAYER)
 
					DrawPlayerIcon(_current_player, 156, y+2);
 
@@ -1579,7 +1579,7 @@ static void CheatsWndProc(Window *w, Win
 
		WP(w,def_d).data_1 = 0;
 
		SetWindowDirty(w);
 
		break;
 
	}	
 
	}
 
}
 
static const WindowDesc _cheats_desc = {
 
	240, 22, 400, 148,
 
@@ -1593,7 +1593,7 @@ static const WindowDesc _cheats_desc = {
 
void ShowCheatWindow()
 
{
 
	Window *w;
 
	
 

	
 
	DeleteWindowById(WC_CHEATS, 0);
 
	w = AllocateWindowDesc(&_cheats_desc);
 

	
music_gui.c
Show inline comments
 
@@ -44,7 +44,7 @@ static void SkipToPrevSong()
 
	// empty playlist
 
	if (b[0] == 0)
 
		return;
 
	
 

	
 
	// find the end
 
	do p++; while (p[0] != 0);
 

	
 
@@ -132,7 +132,7 @@ static void PlayPlaylistSong()
 
	_music_wnd_cursong = _cur_playlist[0];
 
	DoPlaySong();
 
	_song_is_active = true;
 
	
 

	
 
	InvalidateWindowWidget(WC_MUSIC_WINDOW, 0, 9);
 
}
 

	
 
@@ -190,7 +190,7 @@ static void MusicTrackSelectionWndProc(W
 
			DrawStringCentered(216, 45 + i*8, STR_01D5_ALL + i, (i==msf.playlist) ? 0xC : 0x10);
 
		}
 

	
 
		DrawStringCentered(216, 45+8*6+16, STR_01F0_CLEAR, 0); 
 
		DrawStringCentered(216, 45+8*6+16, STR_01F0_CLEAR, 0);
 
		DrawStringCentered(216, 45+8*6+16*2, STR_01F1_SAVE, 0);
 

	
 
		y = 23;
 
@@ -203,7 +203,7 @@ static void MusicTrackSelectionWndProc(W
 
		}
 
		break;
 
	}
 
	
 

	
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 3: { /* add to playlist */
 
@@ -321,7 +321,7 @@ static void MusicWindowWndProc(Window *w
 

	
 

	
 
		DrawString(60, 38, STR_01E8_TRACK_XTITLE, 0);
 
		
 

	
 
		for(i=0; i!=6; i++) {
 
			DrawStringCentered(25+i*50, 59, STR_01D5_ALL+i, msf.playlist == i ? 0xC : 0x10);
 
		}
 
@@ -336,14 +336,14 @@ static void MusicWindowWndProc(Window *w
 
		DrawFrameRect(108, 23, 174, 26, 14, 0x20);
 
		DrawFrameRect(214, 23, 280, 26, 14, 0x20);
 

	
 
		DrawFrameRect(108 + (msf.music_vol>>1), 
 
		DrawFrameRect(108 + (msf.music_vol>>1),
 
									22,
 
									111 + (msf.music_vol>>1),
 
									28,
 
									14,
 
									0);
 

	
 
		DrawFrameRect(214 + (msf.effect_vol>>1), 
 
		DrawFrameRect(214 + (msf.effect_vol>>1),
 
									22,
 
									217 + (msf.effect_vol>>1),
 
									28,
 
@@ -371,7 +371,7 @@ static void MusicWindowWndProc(Window *w
 
			break;
 
		case 6:{ // volume sliders
 
			byte *vol,new_vol;
 
			int x = e->click.pt.x - 88; 
 
			int x = e->click.pt.x - 88;
 

	
 
			if (x < 0)
 
				return;
namegen.c
Show inline comments
 
@@ -11,7 +11,7 @@ static void AppendPart(byte **buf, int n
 
	while (--num>=0) {
 
		do names++; while (names[-1]);
 
	}
 
	
 

	
 
	for(s=*buf; (*s++ = *names++) != 0;) {}
 
	*buf = s - 1;
 
}
 
@@ -19,14 +19,14 @@ static void AppendPart(byte **buf, int n
 
#define MK(x) x "\x0"
 

	
 
#define NUM_ENGLISH_1 4
 
static const char english_1[] = 
 
static const char english_1[] =
 
	MK("Great ")
 
	MK("Little ")
 
	MK("New ")
 
	MK("Fort ")
 
;
 

	
 
#define NUM_ENGLISH_2 26 
 
#define NUM_ENGLISH_2 26
 
static const char english_2[] =
 
	MK("Wr")
 
	MK("B")
 
@@ -57,7 +57,7 @@ static const char english_2[] =
 
;
 

	
 
#define NUM_ENGLISH_3 8
 
static const char english_3[] = 
 
static const char english_3[] =
 
	MK("ar")
 
	MK("a")
 
	MK("e")
 
@@ -69,7 +69,7 @@ static const char english_3[] =
 
;
 

	
 
#define NUM_ENGLISH_4 7
 
static const char english_4[] = 
 
static const char english_4[] =
 
	MK("n")
 
	MK("ning")
 
	MK("ding")
 
@@ -80,7 +80,7 @@ static const char english_4[] =
 
;
 

	
 
#define NUM_ENGLISH_5 23
 
static const char english_5[] = 
 
static const char english_5[] =
 
	MK("ville")
 
	MK("ham")
 
	MK("field")
 
@@ -107,7 +107,7 @@ static const char english_5[] =
 
;
 

	
 
#define NUM_ENGLISH_6 9
 
static const char english_6[] = 
 
static const char english_6[] =
 
	MK("-on-sea")
 
	MK(" Bay")
 
	MK(" Market")
 
@@ -130,7 +130,7 @@ static byte MakeEnglishTownName(byte *bu
 
	i = GETNUM(0, 54) - 50;
 
	if (i >= 0)
 
		AppendPart(&buf, i, english_1);
 
	
 

	
 
	start = buf;
 

	
 
	AppendPart(&buf, GETNUM(4, NUM_ENGLISH_2), english_2);
 
@@ -141,14 +141,14 @@ static byte MakeEnglishTownName(byte *bu
 
	i = GETNUM(15, NUM_ENGLISH_6 + 60) - 60;
 

	
 
	result = 0;
 
	
 

	
 
	if (i >= 0) {
 
		if (i <= 1) result = NG_EDGE;
 
		AppendPart(&buf, i, english_6);
 
	}
 

	
 
	if (start[0]=='C' && (start[1] == 'e' || start[1] == 'i'))
 
		start[0] = 'K'; 
 
		start[0] = 'K';
 

	
 
	/* Replace certain words (routine identical to TTD now) */
 

	
 
@@ -167,7 +167,7 @@ static byte MakeEnglishTownName(byte *bu
 
}
 

	
 
#define NUM_AUSTRIAN_A1 6
 
static const char austrian_a1[] = 
 
static const char austrian_a1[] =
 
	MK("Bad ")
 
	MK("Deutsch ")
 
	MK("Gross ")
 
@@ -177,7 +177,7 @@ static const char austrian_a1[] =
 
;
 

	
 
#define NUM_AUSTRIAN_A2 42
 
static const char austrian_a2[] = 
 
static const char austrian_a2[] =
 
	MK("Aus")
 
	MK("Alten")
 
	MK("Braun")
 
@@ -223,7 +223,7 @@ static const char austrian_a2[] =
 
;
 

	
 
#define NUM_AUSTRIAN_A3 16
 
static const char austrian_a3[] = 
 
static const char austrian_a3[] =
 
	MK("see")
 
	MK("bach")
 
	MK("dorf")
 
@@ -371,8 +371,8 @@ static byte MakeAustrianTownName(byte *b
 
}
 

	
 
#define NUM_GERMAN_1 114
 
#define NUM_GERMAN_1_HARDCODED 21 
 
static const char german_1[] = 
 
#define NUM_GERMAN_1_HARDCODED 21
 
static const char german_1[] =
 
	/* hardcoded names */
 
	MK("Berlin")
 
	MK("Bonn")
 
@@ -531,14 +531,14 @@ static const char german_4[] =
 
	MK("Elbe")
 
	/* use "am" */
 
	MK("Main")
 
	
 

	
 
;
 

	
 
static byte MakeGermanTownName(byte *buf, uint32 seed)
 
{
 
	int i;
 
	int ext;
 
	
 

	
 
	ext=GETNUM(7, 28); /* Extension - Prefix / Suffix */
 

	
 
	if ((ext==12) || (ext==19)) {
 
@@ -571,7 +571,7 @@ static byte MakeGermanTownName(byte *buf
 
}
 

	
 
#define NUM_SPANISH_1 86
 
static const char spanish_1[] = 
 
static const char spanish_1[] =
 
	MK("Caracas")
 
	MK("Maracay")
 
	MK("Maracaibo")
 
@@ -662,11 +662,11 @@ static const char spanish_1[] =
 
static byte MakeSpanishTownName(byte *buf, uint32 seed)
 
{
 
	AppendPart(&buf, GETNUM(0, NUM_SPANISH_1), spanish_1);
 
	return 0;	
 
	return 0;
 
}
 

	
 
#define NUM_FRENCH_1 70
 
static const char french_1[] = 
 
static const char french_1[] =
 
	MK("Agincourt")
 
	MK("Lille")
 
	MK("Dinan")
 
@@ -684,7 +684,7 @@ static const char french_1[] =
 
	MK("St. Tropez")
 
	MK("Marseilles")
 
	MK("Narbonne")
 
	MK("Sète") 
 
	MK("Sète")
 
	MK("Aurillac")
 
	MK("Gueret")
 
	MK("Le Creusot")
 
@@ -751,7 +751,7 @@ static byte MakeAmericanTownName(byte *b
 
}
 

	
 
#define NUM_SILLY_1 88
 
static const char silly_1[] = 
 
static const char silly_1[] =
 
	MK("Binky")
 
	MK("Blubber")
 
	MK("Bumble")
 
@@ -851,7 +851,7 @@ static const char silly_1[] =
 
;
 

	
 
#define NUM_SILLY_2 15
 
static const char silly_2[] = 
 
static const char silly_2[] =
 
	MK("ton")
 
	MK("bury")
 
	MK("bottom")
 
@@ -862,7 +862,7 @@ static const char silly_2[] =
 
	MK("wig")
 
	MK("wick")
 
	MK("wood")
 
	
 

	
 
	MK("pool")
 
	MK("head")
 
	MK("burg")
 
@@ -872,7 +872,7 @@ static const char silly_2[] =
 

	
 

	
 
static byte MakeSillyTownName(byte *buf, uint32 seed)
 
{		
 
{
 
	AppendPart(&buf, GETNUM(0, NUM_SILLY_1), silly_1);
 
	AppendPart(&buf, GETNUM(16, NUM_SILLY_2),silly_2);
 
	return 0;
 
@@ -1081,7 +1081,7 @@ static const char dutch_1[] =
 
	MK("Klein ");
 

	
 
#define NUM_DUTCH_2 57
 
static const char dutch_2[] = 
 
static const char dutch_2[] =
 
	MK("Hoog")
 
	MK("Laag")
 
	MK("Klein")
 
@@ -1141,7 +1141,7 @@ static const char dutch_2[] =
 
	MK("Hil");
 

	
 
#define NUM_DUTCH_3 20
 
static const char dutch_3[] = 
 
static const char dutch_3[] =
 
	MK("Drog")
 
	MK("Nat")
 
	MK("Valk")
 
@@ -1162,10 +1162,10 @@ static const char dutch_3[] =
 
	MK("Wams")
 
	MK("Heerhug")
 
	MK("Koning");
 
	
 

	
 

	
 
#define NUM_DUTCH_4 6
 
static const char dutch_4[] = 
 
static const char dutch_4[] =
 
	MK("e")
 
	MK("er")
 
	MK("el")
 
@@ -1174,7 +1174,7 @@ static const char dutch_4[] =
 
	MK("s");
 

	
 
#define NUM_DUTCH_5 56
 
static const char dutch_5[] = 
 
static const char dutch_5[] =
 
	MK("stad")
 
	MK("vorst")
 
	MK("dorp")
 
@@ -1231,13 +1231,13 @@ static const char dutch_5[] =
 
	MK("schede")
 
	MK("mere")
 
	MK("end");
 
	
 

	
 
static byte MakeDutchTownName(byte *buf, uint32 seed)
 
{
 
	int i;
 

	
 
	i = GETNUM(0, 50 + NUM_DUTCH_1) - 50;
 
	if (i >= 0) 
 
	if (i >= 0)
 
		AppendPart(&buf, i, dutch_1);
 

	
 
	i = GETNUM(6, 9);
 
@@ -1253,7 +1253,7 @@ static byte MakeDutchTownName(byte *buf,
 
}
 

	
 
#define NUM_FINNISH_1 25
 
static const char finnish_1[] = 
 
static const char finnish_1[] =
 
	MK("Aijala")
 
	MK("Kisko")
 
	MK("Espoo")
 
@@ -1279,9 +1279,9 @@ static const char finnish_1[] =
 
	MK("Imatra")
 
	MK("Tapanila")
 
	MK("Pasila");
 
 
 

	
 
#define NUM_FINNISH_2a 26
 
static const char finnish_2a[] = 
 
static const char finnish_2a[] =
 
	MK("Hiekka")
 
	MK("Haapa")
 
	MK("Mylly")
 
@@ -1310,7 +1310,7 @@ static const char finnish_2a[] =
 
	MK("Koivu");
 

	
 
#define NUM_FINNISH_2b 18
 
static const char finnish_2b[] = 
 
static const char finnish_2b[] =
 
	MK("harju")
 
	MK("linna")
 
	MK("järvi")
 
@@ -1576,7 +1576,7 @@ MK(" Malopolski")
 
MK(" Podlaski")
 
MK(" Lesny")
 
;
 
static const char polish_3_f[] = 
 
static const char polish_3_f[] =
 
MK(" Wybudowanie")
 
MK(" Swietokrzyska")
 
MK(" Gorska")
 
@@ -1692,7 +1692,7 @@ static byte MakePolishTownName(byte *buf
 
}
 

	
 
#define NUM_CZECH_1 82
 
static const char czech_1[] = 
 
static const char czech_1[] =
 
MK("As")
 
MK("Benesov")
 
MK("Beroun")
 
@@ -1780,7 +1780,7 @@ MK("Znojmo")
 
static byte MakeCzechTownName(byte *buf, uint32 seed)
 
{
 
	AppendPart(&buf, GETNUM(0, NUM_CZECH_1), czech_1);
 
	return 0;	
 
	return 0;
 
}
 

	
 

	
 
@@ -1879,12 +1879,12 @@ MK("Zvolen")
 
static byte MakeSlovakishTownName(byte *buf, uint32 seed)
 
{
 
	AppendPart(&buf, GETNUM(0, NUM_SLOVAKISH_1), slovakish_1);
 
	return 0;	
 
	return 0;
 
}
 

	
 
// Modifiers
 
#define NUM_HUNGARIAN_1 5
 
static const char hungarian_1[] = 
 
static const char hungarian_1[] =
 
	MK("Nagy-")
 
	MK("Kis-")
 
	MK("Felsõ-")
 
@@ -1893,7 +1893,7 @@ static const char hungarian_1[] =
 
;
 

	
 
#define NUM_HUNGARIAN_2 54
 
static const char hungarian_2[] = 
 
static const char hungarian_2[] =
 
// River modifiers
 
// 1 - 10
 
	MK("Bodrog")
 
@@ -1971,7 +1971,7 @@ static const char hungarian_2[] =
 
;
 

	
 
#define NUM_HUNGARIAN_3 16
 
static const char hungarian_3[] = 
 
static const char hungarian_3[] =
 
	MK("apáti")
 
	MK("bába")
 
	MK("bikk")
 
@@ -1991,7 +1991,7 @@ static const char hungarian_3[] =
 
;
 

	
 
#define NUM_HUNGARIAN_4 5
 
static const char hungarian_4[] = 
 
static const char hungarian_4[] =
 
	MK("alja")
 
	MK("egyháza")
 
	MK("háza")
 
@@ -2054,7 +2054,7 @@ static byte MakeHungarianTownName(byte *
 

	
 
		AppendPart(&buf, GETNUM(3, NUM_HUNGARIAN_2), hungarian_2);
 
		AppendPart(&buf, GETNUM(6, NUM_HUNGARIAN_3), hungarian_3);
 
		
 

	
 
		i = GETNUM(10, NUM_HUNGARIAN_4 * 3);
 
		if (i < NUM_HUNGARIAN_4) AppendPart(&buf, i, hungarian_4);
 
	}
network.c
Show inline comments
 
@@ -232,7 +232,7 @@ static size_t _transmit_file_size;
 

	
 
static FILE *_recv_file;
 

	
 
typedef struct NetworkGameInfo {	
 
typedef struct NetworkGameInfo {
 
	char server_name[40];			// name of the game
 
	char server_revision[8];	// server game version
 
	byte server_lang;					// langid
 
@@ -263,17 +263,17 @@ void CSleep(int milliseconds) {
 
Sleep(milliseconds);
 
#endif
 
#if defined(UNIX)
 
#if !defined(__BEOS__) && !defined(__MORPHOS__) && !defined(__AMIGAOS__) 
 
#if !defined(__BEOS__) && !defined(__MORPHOS__) && !defined(__AMIGAOS__)
 
usleep(milliseconds*1000);
 
#endif
 
#ifdef __BEOS__
 
snooze(milliseconds*1000);
 
#endif
 
#if defined(__MORPHOS__) 
 
#if defined(__MORPHOS__)
 
usleep(milliseconds*1000);
 
#endif
 
#if defined(__AMIGAOS__) && !defined(__MORPHOS__) 
 
{ 
 
#if defined(__AMIGAOS__) && !defined(__MORPHOS__)
 
{
 
	ULONG signals;
 
	ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
 

	
 
@@ -826,7 +826,7 @@ void NetworkSendReadyPacket()
 
		rp->packet_type = 5;
 
		rp->packet_length = sizeof(rp);
 
		SendBytes(c, rp, sizeof(rp));
 
		_network_ready_sent = true;	
 
		_network_ready_sent = true;
 
	}
 
}
 

	
 
@@ -955,7 +955,7 @@ bool NetworkConnect(const char *hostname
 

	
 
	b = 1;
 
	setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b));
 
	
 

	
 
	sin.sin_family = AF_INET;
 
	sin.sin_addr.s_addr = NetworkResolveHost(hostname);
 
	sin.sin_port = htons(port);
 
@@ -980,7 +980,7 @@ bool NetworkConnect(const char *hostname
 

	
 
void NetworkListen()
 
{
 
		
 

	
 
	SOCKET ls;
 
	struct sockaddr_in sin;
 
	int port;
 
@@ -992,7 +992,7 @@ void NetworkListen()
 
	ls = socket(AF_INET, SOCK_STREAM, 0);
 
	if (ls == INVALID_SOCKET)
 
		error("socket() on listen socket failed");
 
	
 

	
 
	// reuse the socket
 
	{
 
		int reuse = 1; if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse, sizeof(reuse)) == -1)
 
@@ -1021,7 +1021,7 @@ void NetworkReceive()
 
	int n;
 
	fd_set read_fd, write_fd;
 
	struct timeval tv;
 
	
 

	
 
	FD_ZERO(&read_fd);
 
	FD_ZERO(&write_fd);
 

	
 
@@ -1119,13 +1119,13 @@ void NetworkSend()
 
					CSleep(5);
 
					}
 
			}
 
				
 

	
 
			_not_packet = 0;
 

	
 
			new_max = max(_frame_counter + (int)_network_ahead_frames, _frame_counter_max);
 
			
 

	
 
			DEBUG(net,3) ("net: serv: sync max=%i, seed1=%i, seed2=%i",new_max,_sync_seed_1,_sync_seed_2);
 
			
 

	
 
			sp.packet_length = sizeof(sp);
 
			sp.packet_type = 1;
 
			sp.frames = new_max - _frame_counter_max;
 
@@ -1196,7 +1196,7 @@ void NetworkClose(bool client) {
 

	
 
void NetworkShutdown()
 
{
 
	_networking_server = false;	
 
	_networking_server = false;
 
	_networking = false;
 
	_networking_sync = false;
 
	_frame_counter = 0;
 
@@ -1255,10 +1255,10 @@ void NetworkUDPListen(bool client)
 
	DEBUG(net, 1) ("[NET][UDP] listening on port %i", port);
 

	
 
	udp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
	
 

	
 
	// this disables network
 
	_network_available = !(udp == INVALID_SOCKET);
 
	
 

	
 
	// set nonblocking mode for socket
 
	{ unsigned long blocking = 1; ioctlsocket(udp, FIONBIO, &blocking); }
 

	
 
@@ -1268,7 +1268,7 @@ void NetworkUDPListen(bool client)
 

	
 
	if (bind(udp, (struct sockaddr*)&sin, sizeof(sin)) != 0)
 
		DEBUG(net, 1) ("[NET][UDP] error: bind failed on port %i", port);
 
		
 

	
 

	
 
	// enable broadcasting
 
	{ unsigned long val=1; setsockopt(udp, SOL_SOCKET, SO_BROADCAST, (char *) &val , sizeof(val)); }
 
@@ -1280,7 +1280,7 @@ void NetworkUDPListen(bool client)
 
}
 

	
 
void NetworkUDPClose(bool client) {
 
	if (client) { 
 
	if (client) {
 
		DEBUG(net, 1) ("[NET][UDP] closed listener on port %i", _network_client_port);
 
		closesocket(_udp_client_socket);
 
		_udp_client_socket = INVALID_SOCKET;
 
@@ -1301,17 +1301,17 @@ void NetworkUDPReceive(bool client) {
 
	int nbytes;
 
	struct UDPPacket packet;
 
	int packet_len;
 
	
 

	
 
	SOCKET udp;
 
	if (client) udp=_udp_client_socket; else udp=_udp_server_socket;
 

	
 
	packet_len = sizeof(packet);
 
	client_len = sizeof(client_addr);	
 
	
 
	client_len = sizeof(client_addr);
 

	
 
	nbytes = recvfrom(udp, (char *) &packet, packet_len , 0, (struct sockaddr *) &client_addr, &client_len);
 
	if (nbytes>0) {
 
		if (packet.command_code==packet.command_check) switch (packet.command_code) {
 
		
 

	
 
 		case NET_UDPCMD_SERVERSEARCH:
 
 			if (!client) {
 
				packet.command_check=packet.command_code=NET_UDPCMD_SERVERINFO;
 
@@ -1335,7 +1335,7 @@ void NetworkUDPReceive(bool client) {
 
				item = (NetworkGameList *) NetworkGameListAdd();
 
				item -> ip = inet_addr(inet_ntoa(client_addr.sin_addr));
 
				item -> port = ntohs(client_addr.sin_port);
 
				
 

	
 
				memcpy(item,&packet.data,packet.data_len);
 
 			}
 
 			break;
 
@@ -1365,14 +1365,14 @@ void NetworkUDPBroadCast(bool client, st
 
		if (res==-1) DEBUG(net, 1)("udp: broadcast error: %i",GET_LAST_ERROR());
 
		i++;
 
	}
 
	
 

	
 
}
 

	
 
void NetworkUDPSend(bool client, struct sockaddr_in recv,struct UDPPacket packet) {
 

	
 
	SOCKET udp;
 
	if (client) udp=_udp_client_socket; else udp=_udp_server_socket;
 
	
 

	
 
	sendto(udp,(char *) &packet,sizeof(packet),0,(struct sockaddr *) &recv,sizeof(recv));
 
}
 

	
 
@@ -1380,13 +1380,13 @@ void NetworkUDPSend(bool client, struct 
 
bool NetworkUDPSearchGame(const byte ** _network_detected_serverip, unsigned short * _network_detected_serverport) {
 
	struct UDPPacket packet;
 
	int timeout=3000;
 
	
 

	
 
	NetworkGameListClear();
 

	
 
	DEBUG(net, 0) ("[NET][UDP] searching server");
 
	*_network_detected_serverip = "255.255.255.255";
 
	*_network_detected_serverport = 0;
 
	
 

	
 
	packet.command_check=packet.command_code=NET_UDPCMD_SERVERSEARCH;
 
	packet.data_len=0;
 
	NetworkUDPBroadCast(true, packet);
 
@@ -1403,11 +1403,11 @@ bool NetworkUDPSearchGame(const byte ** 
 
 			timeout=-1;
 
 			DEBUG(net, 0) ("[NET][UDP] server found on %s", *_network_detected_serverip);
 
 			}
 
	
 

	
 
		}
 

	
 
	return (*_network_detected_serverport>0);
 
		
 

	
 
}
 

	
 

	
 
@@ -1420,7 +1420,7 @@ void NetworkIPListInit() {
 
	char hostname[250];
 
	uint32 bcaddr;
 
	int i=0;
 
		
 

	
 
	gethostname(hostname,250);
 
	DEBUG(net, 2) ("[NET][IP] init for host %s", hostname);
 
	he=gethostbyname((char *) hostname);
 
@@ -1428,7 +1428,7 @@ void NetworkIPListInit() {
 
	if (he == NULL) {
 
		he = gethostbyname("localhost");
 
		}
 
	
 

	
 
	if (he == NULL) {
 
		bcaddr = inet_addr("127.0.0.1");
 
		he = gethostbyaddr(inet_ntoa(*(struct in_addr *) &bcaddr), sizeof(bcaddr), AF_INET);
 
@@ -1437,7 +1437,7 @@ void NetworkIPListInit() {
 
	if (he == NULL) {
 
		DEBUG(net, 2) ("[NET][IP] cannot resolve %s", hostname);
 
	} else {
 
		while(he->h_addr_list[i]) { 
 
		while(he->h_addr_list[i]) {
 
			bcaddr = inet_addr(inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
 
			_network_ip_list[i]=bcaddr;
 
			DEBUG(net, 2) ("[NET][IP] add %s",inet_ntoa(*(struct in_addr *) he->h_addr_list[i]));
 
@@ -1446,7 +1446,7 @@ void NetworkIPListInit() {
 

	
 
	}
 
	_network_ip_list[i]=0;
 
	
 

	
 
}
 

	
 
/* *************************************************** */
 
@@ -1468,7 +1468,7 @@ DEBUG(net, 3) ("[NET][Core] init()");
 
		_network_available=false;
 
		}
 
}
 
#else 
 
#else
 

	
 
// [morphos/amigaos] bsd-socket startup
 

	
 
@@ -1486,14 +1486,14 @@ DEBUG(net, 3) ("[NET][Core] init()");
 
		if ( (TimerRequest = (struct timerequest *) CreateIORequest(TimerPort, sizeof(struct timerequest))) ) {
 
			if ( OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *) TimerRequest, 0) == 0 ) {
 
				if ( !(TimerBase = TimerRequest->tr_node.io_Device) ) {
 
					// free ressources... 
 
					// free ressources...
 
					DEBUG(net, 3) ("[NET][Core] Couldn't initialize timer.");
 
					_network_available=false;
 
				}
 
			}
 
		}
 
	}
 
	#endif 
 
	#endif
 

	
 
}
 
#else
 
@@ -1527,9 +1527,9 @@ void NetworkCoreShutdown() {
 
DEBUG(net, 3) ("[NET][Core] shutdown()");
 

	
 
#if defined(__MORPHOS__) || defined(__AMIGA__)
 
{	
 
{
 
	// free allocated ressources
 
	#if !defined(__MORPHOS__) 
 
	#if !defined(__MORPHOS__)
 
  if (TimerBase)    { CloseDevice((struct IORequest *) TimerRequest); }
 
  if (TimerRequest) { DeleteIORequest(TimerRequest); }
 
  if (TimerPort)    { DeleteMsgPort(TimerPort); }
 
@@ -1574,9 +1574,9 @@ bool NetworkCoreConnectGame(const byte* 
 
	if (_networking) {
 
		NetworkLobbyShutdown();
 
	} else {
 
		if (_networking_override) 
 
		if (_networking_override)
 
			NetworkLobbyShutdown();
 
		
 

	
 
		ShowErrorMessage(-1, STR_NETWORK_ERR_NOCONNECTION,0,0);
 
		_switch_mode_errorstr = STR_NETWORK_ERR_NOCONNECTION;
 
	}
 
@@ -1607,13 +1607,13 @@ void NetworkCoreDisconnect()
 
	if (_networking_server) {
 
		NetworkUDPClose(false);
 
		NetworkClose(false);
 
		} 
 
		}
 

	
 
	/* terminate client connection */
 
	else if (_networking) {
 
		NetworkClose(true);
 
		}
 
	
 

	
 
	NetworkShutdown();
 
}
 

	
 
@@ -1670,7 +1670,7 @@ void NetworkLobbyShutdown() {
 

	
 
void NetworkGameListClear() {
 
NetworkGameList * item;
 
NetworkGameList * next; 
 
NetworkGameList * next;
 

	
 
DEBUG(net, 4) ("[NET][G-List] cleared server list");
 

	
 
@@ -1686,7 +1686,7 @@ while (item != NULL) {
 

	
 
char * NetworkGameListAdd() {
 
NetworkGameList * item;
 
NetworkGameList * before; 
 
NetworkGameList * before;
 

	
 
DEBUG(net, 4) ("[NET][G-List] added server to list");
 

	
 
@@ -1726,7 +1726,7 @@ void NetworkGameListFromInternet() {
 

	
 
char * NetworkGameListItem(uint16 index) {
 
NetworkGameList * item;
 
NetworkGameList * next; 
 
NetworkGameList * next;
 
uint16 cnt = 0;
 

	
 
item = _network_game_list;
 
@@ -1749,7 +1749,7 @@ void NetworkGameFillDefaults() {
 
#if defined(WITH_REV)
 
	extern char _openttd_revision[];
 
#endif
 
	
 

	
 
	DEBUG(net, 4) ("[NET][G-Info] setting defaults");
 

	
 
	ttd_strlcpy(game->server_name,"OpenTTD Game",13);
 
@@ -1768,7 +1768,7 @@ void NetworkGameFillDefaults() {
 

	
 
	game->players_max=8;
 
	game->players_on=0;
 
	
 

	
 
	game->server_lang=_dynlang.curr;
 
}
 

	
network_gui.c
Show inline comments
 
@@ -23,12 +23,12 @@ static const StringID _connection_types_
 
};
 

	
 
/* Should be _network_game->players_max but since network is not yet really done
 
* we'll just use some dummy here 
 
* we'll just use some dummy here
 
* network.c -->> static NetworkGameInfo _network_game;
 
*/
 
static byte _players_max;
 
/* Should be ??????????? (something) but since network is not yet really done
 
* we'll just use some dummy here 
 
* we'll just use some dummy here
 
*/
 
static byte _network_connection;
 

	
 
@@ -36,20 +36,20 @@ static void NetworkGameWindowWndProc(Win
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
	
 

	
 
		SET_DPARAM16(0, 0x00);
 
		SET_DPARAM16(2, STR_NETWORK_LAN + _network_connection);
 
		DrawWindowWidgets(w);
 
		
 

	
 
		DrawEditBox(w, 6);
 
		
 

	
 
		DrawString(9, 43, STR_NETWORK_PLAYER_NAME, 2);
 
		DrawString(9, 63, STR_NETWORK_SELECT_CONNECTION, 2);
 

	
 
		DrawString(15, 82, STR_NETWORK_GAME_NAME, 2);
 
		DrawString(238, 82, STR_NETWORK_PLAYERS, 2);
 
		DrawString(288, 82, STR_NETWORK_MAP_SIZE, 2);
 
		
 

	
 
	}	break;
 

	
 
	case WE_CLICK:
 
@@ -65,7 +65,7 @@ static void NetworkGameWindowWndProc(Win
 
		case 4: { /* Connect via direct ip */
 
				StringID str;
 
				str = AllocateName((byte*)_decode_parameters, 0);
 
				
 

	
 
				ShowQueryString(
 
				str,
 
				STR_NETWORK_ENTER_IP,
 
@@ -93,7 +93,7 @@ static void NetworkGameWindowWndProc(Win
 
	case WE_MOUSELOOP:
 
		if (_selected_field == 6)
 
			HandleEditBox(w, 6);
 
		
 

	
 
		break;
 

	
 
	case WE_KEYPRESS:
 
@@ -160,11 +160,11 @@ void ShowNetworkGameWindow()
 
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
 

	
 
	NetworkLobbyInit();
 
	
 

	
 
	w = AllocateWindowDesc(&_network_game_window_desc);
 
	strcpy(_edit_str_buf, "Your name");
 

	
 
	
 

	
 
	WP(w,querystr_d).caret = 1;
 
	WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
 
	WP(w,querystr_d).maxwidth = 240;
 
@@ -186,7 +186,7 @@ static void NetworkStartServerWindowWndP
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
	
 

	
 
		SET_DPARAM16(7, STR_NETWORK_2_PLAYERS + _players_max);
 
		DrawWindowWidgets(w);
 

	
 
@@ -194,13 +194,13 @@ static void NetworkStartServerWindowWndP
 

	
 
		DrawEditBox(w, 3);
 
		DrawEditBox(w, 4);
 
		
 

	
 
		DrawString(10, 22, STR_NETWORK_NEW_GAME_NAME, 2);
 
		DrawString(210, 22, STR_NETWORK_PASSWORD, 2);
 

	
 
		DrawString(10, 43, STR_NETWORK_SELECT_MAP, 2);
 
		DrawString(260, 63, STR_NETWORK_NUMBER_OF_PLAYERS, 2);
 
		
 

	
 
	}	break;
 

	
 
	case WE_CLICK:
 
@@ -251,7 +251,7 @@ static void NetworkStartServerWindowWndP
 
			break;
 
		}
 
		break;
 
		
 

	
 
	}
 
}
 

	
 
@@ -288,10 +288,10 @@ static void ShowNetworkStartServerWindow
 
{
 
	Window *w;
 
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
 
	
 

	
 
	w = AllocateWindowDesc(&_network_start_server_window_desc);
 
	strcpy(_edit_str_buf, "");
 
	
 

	
 
	WP(w,querystr_d).caret = 1;
 
	WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
 
	WP(w,querystr_d).maxwidth = 240;
 
@@ -303,7 +303,7 @@ static void NetworkLobbyWindowWndProc(Wi
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
	
 

	
 
		SET_DPARAM16(7, STR_NETWORK_2_PLAYERS + _opt_mod_ptr->road_side);
 
		DrawWindowWidgets(w);
 

	
 
@@ -312,7 +312,7 @@ static void NetworkLobbyWindowWndProc(Wi
 

	
 
		DrawEditBox(w, 5);
 
		DrawEditBox(w, 7);
 
		
 

	
 
		DrawString(10, 255, STR_NETWORK_COMPANY_NAME, 2);
 

	
 
		break;
 
@@ -340,7 +340,7 @@ static void NetworkLobbyWindowWndProc(Wi
 
			HandleEditBox(w, 7);
 
			break;
 
		}
 
			
 

	
 
		break;
 

	
 
	case WE_KEYPRESS:
 
@@ -352,7 +352,7 @@ static void NetworkLobbyWindowWndProc(Wi
 
			break;
 
		}
 
		break;
 
		
 

	
 
	}
 
}
 

	
 
@@ -398,11 +398,11 @@ static void ShowNetworkLobbyWindow()
 
{
 
	Window *w;
 
	DeleteWindowById(WC_NETWORK_WINDOW, 0);
 
	
 

	
 
	w = AllocateWindowDesc(&_network_lobby_window_desc);
 
	strcpy(_edit_str_buf, "");
 

	
 
	
 

	
 
	WP(w,querystr_d).caret = 1;
 
	WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN;
 
	WP(w,querystr_d).maxwidth = 240;
news_gui.c
Show inline comments
 
@@ -12,7 +12,7 @@
 
News system is realized as a FIFO queue (in an array)
 
The positions in the queue can't be rearranged, we only access
 
the array elements through pointers to the elements. Once the
 
array is full, the oldest entry (_oldest_news) is being overwritten 
 
array is full, the oldest entry (_oldest_news) is being overwritten
 
by the newest (_latest news).
 

	
 
oldest                   current   lastest
 
@@ -28,7 +28,7 @@ static NewsItem _news_items[MAX_NEWS];
 
static byte _current_news = 255; // points to news item that should be shown next
 
static byte _oldest_news = 0;    // points to first item in fifo queue
 
static byte _latest_news = 255;  // points to last item in fifo queue
 
static byte _forced_news = 255;  // if the message being shown was forced by the user, its index is stored in _forced_news. 
 
static byte _forced_news = 255;  // if the message being shown was forced by the user, its index is stored in _forced_news.
 
																 //forced_news is 255 otherwise. (Users can force messages through history or "last message")
 

	
 
static byte _total_news = 0; // total news count
 
@@ -80,13 +80,13 @@ void DrawNewsBorder(Window *w)
 
	int bottom = w->height - 1;
 

	
 
	GfxFillRect(left, top, right, bottom, 0xF);
 
	
 

	
 
	GfxFillRect(left, top, left, bottom, 0xD7);
 
	GfxFillRect(right, top, right, bottom, 0xD7);
 
	GfxFillRect(left, top, right, top, 0xD7);
 
	GfxFillRect(left, bottom, right, bottom, 0xD7);
 
	
 
	DrawString(left + 2, top + 1, STR_00C6, 0);	
 

	
 
	DrawString(left + 2, top + 1, STR_00C6, 0);
 
}
 

	
 
static void NewsWindowProc(Window *w, WindowEvent *e)
 
@@ -115,7 +115,7 @@ static void NewsWindowProc(Window *w, Wi
 

	
 
				/* Shade the viewport into gray, or color*/
 
				vp = w->viewport;
 
				GfxFillRect(vp->left - w->left, vp->top - w->top, vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1, 
 
				GfxFillRect(vp->left - w->left, vp->top - w->top, vp->left - w->left + vp->width - 1, vp->top - w->top + vp->height - 1,
 
					ni->flags & NF_INCOLOR ? 0x4322:0x4323
 
				);
 

	
 
@@ -208,7 +208,7 @@ void AddNewsItem(StringID string, uint32
 

	
 
	_forced_news = 255;
 
	if(_total_news < MAX_NEWS) _total_news++;
 
	
 

	
 
	// make sure our pointer isn't overflowing
 
	_latest_news = increaseIndex(_latest_news);
 

	
 
@@ -431,7 +431,7 @@ void ShowLastNewsMessage()
 
	else if(_forced_news!=0)
 
		ShowNewsMessage(_forced_news-1);
 
	else {
 
		if(_total_news != MAX_NEWS) 
 
		if(_total_news != MAX_NEWS)
 
			ShowNewsMessage(_latest_news);
 
		else
 
			ShowNewsMessage(MAX_NEWS-1);
 
@@ -443,7 +443,7 @@ void ShowLastNewsMessage()
 
recent news. Returns 255 if end of queue reached. */
 
static byte getNews(byte i)
 
{
 
	if(i>=_total_news) 
 
	if(i>=_total_news)
 
		return 255;
 

	
 
	if(_latest_news < i)
 
@@ -459,17 +459,17 @@ static void GetNewsString(NewsItem *ni, 
 
{
 
	StringID str;
 
	byte *s, *d;
 
	
 

	
 
	if (ni->display_mode == 3) {
 
		str = _get_news_string_callback[ni->callback](ni);
 
	} else {
 
		COPY_IN_DPARAM(0, ni->params, lengthof(ni->params));
 
		str = ni->string_id;	
 
		str = ni->string_id;
 
	}
 

	
 
	GetString(str_buffr, str);
 
	assert(strlen(str_buffr) < sizeof(str_buffr) - 1);
 
	
 

	
 
	s = str_buffr;
 
	d = buffer;
 

	
 
@@ -611,7 +611,7 @@ static void MessageOptionsWndProc(Window
 
		for(i=STR_0206_ARRIVAL_OF_FIRST_VEHICLE; i <= STR_020F_GENERAL_INFORMATION; i++) {
 
			DrawString(124, y, i, 0);
 
			y += 12;
 
		}		
 
		}
 

	
 
		break;
 
		}
oldloader.c
Show inline comments
 
@@ -314,7 +314,7 @@ typedef struct {
 
	byte owner;
 
	uint16 tile;
 
	uint16 cur_image;
 
	
 

	
 
	int16 left_coord, right_coord, top_coord, bottom_coord; // NOLOAD, calculated automatically.
 
	uint16 vehstatus;
 
	uint16 cur_speed;
 
@@ -420,21 +420,21 @@ typedef struct {
 
	uint16 age_cargo_skip_counter;
 
	uint16 tick_counter;
 
	uint16 cur_tileloop_tile;
 
	
 

	
 
	OldPrice prices[49];
 
	OldPaymentRate cargo_payment_rates[12];
 
	
 

	
 
	byte map_owner[256*256];
 
	byte map2[256*256];
 
	uint16 map3[256*256];
 
	byte map_extra[256*256/4];
 
	
 

	
 
	OldStation stations[250];
 
	OldIndustry industries[90];
 
	OldPlayer players[8];
 
	OldVehicle vehicles[850];
 
	OldName names[500];
 
		
 

	
 
	uint16 vehicle_position_hash[0x1000]; // NOLOAD, calculated automatically.
 

	
 
	OldSign signs[40];
 
@@ -455,7 +455,7 @@ typedef struct {
 
	uint16 cargo_sprites[12];
 

	
 
	uint16 engine_name_strings[256];
 
	
 

	
 
	//NOLOAD. These are calculated from InitializeLandscapeVariables
 
	uint16 railveh_by_cargo_1[12], railveh_by_cargo_2[12], railveh_by_cargo_3[12];
 
	uint16 roadveh_by_cargo_start[12];
 
@@ -486,9 +486,9 @@ typedef struct {
 
	byte snow_line_height;
 

	
 
	byte new_industry_randtable[32]; // NOLOAD. Not needed due to different code design.
 
	
 

	
 
	//NOLOAD. Initialized by InitializeLandscapeVariables
 
	byte cargo_weights[12]; 
 
	byte cargo_weights[12];
 
	byte transit_days_table_1[12];
 
	byte transit_days_table_2[12];
 

	
 
@@ -557,7 +557,7 @@ static byte DecodeSavegameByte()
 
			return GetSavegameByteFromBuffer();
 
		}
 
	}
 
	
 

	
 
	x = GetSavegameByteFromBuffer();
 
	if (x >= 0) {
 
		lss->count = x;
 
@@ -568,7 +568,7 @@ static byte DecodeSavegameByte()
 
		lss->count = -x;
 
		lss->rep_char = GetSavegameByteFromBuffer();
 
		return lss->rep_char;
 
	}	
 
	}
 
}
 

	
 
static void LoadSavegameBytes(void *p, size_t count)
 
@@ -642,7 +642,7 @@ static void FixIndustry(Industry *i, Old
 
		i->prod_level = o->prod_level;
 
		i->last_mo_production[0] = o->last_mo_production[0];
 
		i->last_mo_production[1] = o->last_mo_production[1];
 
		
 

	
 
		i->last_mo_transported[0] = o->last_mo_transported[0];
 
		i->last_mo_transported[1] = o->last_mo_transported[1];
 
		i->last_mo_transported[2] = o->last_mo_transported[2];
 
@@ -652,7 +652,7 @@ static void FixIndustry(Industry *i, Old
 

	
 
		i->total_production[0] = o->total_production[0];
 
		i->total_production[1] = o->total_production[1];
 
		
 

	
 
		i->total_transported[0] = i->total_transported[0];
 
		i->total_transported[1] = i->total_transported[1];
 

	
 
@@ -688,7 +688,7 @@ static void FixStation(Station *s, OldSt
 
		s->train_tile = o->train_tile;
 
		s->airport_tile = o->airport_tile;
 
		s->dock_tile = o->dock_tile;
 
		
 

	
 
		if (o->train_tile) {
 
			int w = (o->platforms >> 3) & 0x7;
 
			int h = (o->platforms & 0x7);
 
@@ -696,7 +696,7 @@ static void FixStation(Station *s, OldSt
 
			s->trainst_w = w;
 
			s->trainst_h = h;
 
		}
 
		
 

	
 
		s->string_id = RemapOldStringID(o->string_id);
 
		s->had_vehicle_of_type = o->had_vehicle_of_type;
 
		FixGoodsEntry(s->goods, o->goods, lengthof(o->goods));
 
@@ -727,7 +727,7 @@ static void FixVehicle(Vehicle *n, OldVe
 
	do {
 
		n->type = o->type;
 
		n->subtype = o->subtype;
 
		
 

	
 
		if (o->schedule_ptr == 0xFFFFFFFF || o->schedule_ptr == 0) {
 
			n->schedule_ptr = NULL;
 
		} else {
 
@@ -758,7 +758,7 @@ static void FixVehicle(Vehicle *n, OldVe
 
		n->owner = o->owner;
 
		n->tile = o->tile;
 
		n->cur_image = o->cur_image;
 
	
 

	
 
		n->vehstatus = o->vehstatus;
 
		n->cur_speed = o->cur_speed;
 
		n->subspeed = o->subspeed;
 
@@ -787,7 +787,7 @@ static void FixVehicle(Vehicle *n, OldVe
 
		n->next = o->next_in_chain == 0xffff ? NULL : &_vehicles[o->next_in_chain];
 
		n->value = o->value;
 
		n->string_id = RemapOldStringID(o->string_id);
 
		
 

	
 
		switch(o->type) {
 
		case VEH_Train:
 
			n->u.rail.track = o->u.rail.track;
 
@@ -864,7 +864,7 @@ static void FixPlayer(Player *n, OldPlay
 
{
 
	int i, j;
 
	int x = 0;
 
	
 

	
 
	do {
 
		n->name_1 = RemapOldStringID(o->name_1);
 
		n->name_2 = o->name_2;
 
@@ -882,15 +882,15 @@ static void FixPlayer(Player *n, OldPlay
 

	
 
		if (o->name_1 != 0)
 
			n->is_active = true;
 
		
 

	
 
		n->face = o->face;
 
		n->president_name_1 = o->pres_name_1;
 
		n->president_name_2 = o->pres_name_2;
 
		
 

	
 
		n->money64 = n->player_money = o->money;
 
		n->current_loan = o->loan;
 
		
 
		// Correct money for scenario loading. 
 

	
 
		// Correct money for scenario loading.
 
		// It's always 893288 pounds (and no loan), if not corrected
 
		if(o->money==0xda168)
 
			n->money64 = n->player_money = n->current_loan =100000;
 
@@ -905,7 +905,7 @@ static void FixPlayer(Player *n, OldPlay
 
		n->bankrupt_value = o->bankrupt_value;
 
		n->bankrupt_timeout = o->bankrupt_timeout;
 
		n->cargo_types = o->cargo_types;
 
		
 

	
 
		for(i=0; i!=3; i++)
 
			for(j=0; j!=13; j++)
 
				n->yearly_expenses[i][j] = o->expenses[i].cost[j];
 
@@ -916,7 +916,7 @@ static void FixPlayer(Player *n, OldPlay
 
		n->last_build_coordinate = o->last_build_coordinate;
 
		n->num_valid_stat_ent = o->num_valid_stat_ent;
 

	
 
		/*	Not good, since AI doesn't have a vehicle assigned as 
 
		/*	Not good, since AI doesn't have a vehicle assigned as
 
		 *	in p->ai.cur_veh and thus will crash on certain actions.
 
		 *	Best is to set state to AiStateVehLoop (2)
 
		 *	n->ai.state = o->ai_state;
 
@@ -927,18 +927,18 @@ static void FixPlayer(Player *n, OldPlay
 
		n->ai.timeout_counter = o->ai_timeout_counter;
 
		n->ai.banned_tile_count = o->ai_banned_tile_count;
 
		n->ai.railtype_to_use = o->ai_railtype_to_use;
 
		
 

	
 
		FixAiBuildRec(&n->ai.src, &o->ai_src);
 
		FixAiBuildRec(&n->ai.dst, &o->ai_dst);
 
		FixAiBuildRec(&n->ai.mid1, &o->ai_mid1);
 
		FixAiBuildRec(&n->ai.mid2, &o->ai_mid2);
 
		
 

	
 
		n->ai.cargo_type = o->ai_cargo_type;
 
		n->ai.num_wagons = o->ai_num_wagons;
 
		n->ai.num_build_rec = o->ai_num_build_rec;
 
		n->ai.num_loco_to_build = o->ai_num_loco_to_build;
 
		n->ai.num_want_fullload = o->ai_num_want_fullload;
 
		
 

	
 
		for(i=0; i!=9; i++) n->ai.wagon_list[i] = o->ai_wagonlist[i];
 
		memcpy(n->ai.order_list_blocks, o->ai_order_list_blocks, 20);
 
		n->ai.start_tile_a = o->ai_start_tile_a;
 
@@ -949,7 +949,7 @@ static void FixPlayer(Player *n, OldPlay
 
		n->ai.start_dir_b = o->ai_start_dir_b;
 
		n->ai.cur_dir_a = o->ai_cur_dir_a;
 
		n->ai.cur_dir_b = o->ai_cur_dir_b;
 
		
 

	
 
		for(i=0; i!=16; i++) {
 
			n->ai.banned_tiles[i] = o->banned_tiles[i].tile;
 
			n->ai.banned_val[i] = o->banned_tiles[i].data;
 
@@ -1081,7 +1081,7 @@ bool LoadOldSaveGame(const char *file)
 
	for(i=0; i!=256*256; i++) {
 
		if (IS_TILETYPE(i, MP_RAILWAY) && (_map5[i] & 0xC0) == 0x40) {
 
			// this byte is always zero in real ttd.
 
			if (_map3_hi[i]) { 
 
			if (_map3_hi[i]) {
 
				// convert ttdpatch presignal format to openttd presignal format.
 
				_map3_hi[i] = (_map3_hi[i] >> 1) & 7;
 
			}
 
@@ -1098,7 +1098,7 @@ bool LoadOldSaveGame(const char *file)
 
	FixDepot(_depots, m->depots, lengthof(m->depots));
 
	FixVehicle(_vehicles, m->vehicles, lengthof(m->vehicles));
 
	FixSubsidy(_subsidies, m->subsidies, lengthof(m->subsidies));
 
	
 

	
 
	FixPlayer(_players, m->players, lengthof(m->players), m->town_name_type);
 
	FixName(m->names, lengthof(m->names));
 
	FixSign(_sign_list, m->signs, lengthof(m->signs));
 
@@ -1154,7 +1154,7 @@ bool LoadOldSaveGame(const char *file)
 
		_cargo_payment_rates[i] = -(int32)m->cargo_payment_rates[i].price;
 
		_cargo_payment_rates_frac[i] = m->cargo_payment_rates[i].frac;
 
	}
 
	
 

	
 
	free(m);
 
	fclose(lss.fin);
 
	return true;
order_cmd.c
Show inline comments
 
@@ -23,7 +23,7 @@ int32 CmdInsertOrder(int x, int y, uint3
 
	// for ships, make sure that the station is not too far away from the previous destination.
 
	if (v->type == VEH_Ship && IS_HUMAN_PLAYER(v->owner) &&
 
			sel != 0 && ((t=v->schedule_ptr[sel-1])&OT_MASK) == OT_GOTO_STATION) {
 
		
 

	
 
		int dist = GetTileDist(DEREF_STATION(t >> 8)->xy, DEREF_STATION(p2 >> 8)->xy);
 
		if (dist >= 130)
 
			return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
 
@@ -39,7 +39,7 @@ int32 CmdInsertOrder(int x, int y, uint3
 
		s1[0] = (uint16)p2;
 

	
 
		s1 = v->schedule_ptr;
 
		
 

	
 
		FOR_ALL_VEHICLES(u) {
 
			if (u->type != 0 && u->schedule_ptr != NULL) {
 
				if (s1 < u->schedule_ptr) {
 
@@ -69,10 +69,10 @@ static int32 DecloneOrder(Vehicle *dst, 
 

	
 
	if (flags & DC_EXEC) {
 
		DeleteVehicleSchedule(dst);
 
		
 

	
 
		dst->num_orders = 0;
 
		*(dst->schedule_ptr = _ptr_to_next_order++) = 0;
 
		
 

	
 
		InvalidateWindow(WC_VEHICLE_ORDERS, dst->index);
 
	}
 
	return 0;
 
@@ -92,7 +92,7 @@ int32 CmdDeleteOrder(int x, int y, uint3
 

	
 
	if (flags & DC_EXEC) {
 
		uint16 *s1;
 
		
 

	
 
		s1 = &v->schedule_ptr[sel];
 

	
 
		// copy all orders to get rid of the hole
 
@@ -119,7 +119,7 @@ int32 CmdDeleteOrder(int x, int y, uint3
 
			}
 
		}
 
	}
 
	
 

	
 
	return 0;
 
}
 

	
 
@@ -133,7 +133,7 @@ int32 CmdSkipOrder(int x, int y, uint32 
 
			byte b = v->cur_order_index + 1;
 
			if (b >= v->num_orders) b = 0;
 
			v->cur_order_index = b;
 
			
 

	
 
			if (v->type == VEH_Train)
 
				v->u.rail.days_since_order_progr = 0;
 
		}
 
@@ -160,7 +160,7 @@ int32 CmdModifyOrder(int x, int y, uint3
 
		return CMD_ERROR;
 

	
 
	sched = &v->schedule_ptr[sel];
 
	if (!((*sched & OT_MASK) == OT_GOTO_STATION || 
 
	if (!((*sched & OT_MASK) == OT_GOTO_STATION ||
 
			((*sched & OT_MASK) == OT_GOTO_DEPOT &&  (p2>>8) != 1)))
 
		return CMD_ERROR;
 

	
 
@@ -185,9 +185,9 @@ int32 CmdModifyOrder(int x, int y, uint3
 
			if (v->schedule_ptr == sched)
 
				InvalidateWindow(WC_VEHICLE_ORDERS, v->index);
 
		}
 
		
 

	
 
	}
 
	
 

	
 
	return 0;
 
}
 

	
 
@@ -204,12 +204,12 @@ int32 CmdModifyOrder(int x, int y, uint3
 
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	Vehicle *dst = &_vehicles[p1 & 0xFFFF];
 
	
 

	
 
	if (!(dst->type && dst->owner == _current_player))
 
		return CMD_ERROR;
 

	
 
	switch(p2) {
 
	
 

	
 
	// share vehicle orders?
 
	case 0: {
 
		Vehicle *src = &_vehicles[p1 >> 16];
 
@@ -217,7 +217,7 @@ int32 CmdCloneOrder(int x, int y, uint32
 
		// sanity checks
 
		if (!(src->owner == _current_player && dst->type == src->type && dst != src))
 
			return CMD_ERROR;
 
			
 

	
 
		// let's see what happens with road vehicles
 
		if (src->type == VEH_Road) {
 
			if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS))
 
@@ -243,14 +243,14 @@ int32 CmdCloneOrder(int x, int y, uint32
 
		// sanity checks
 
		if (!(src->owner == _current_player && dst->type == src->type && dst != src))
 
			return CMD_ERROR;
 
			
 

	
 
		// let's see what happens with road vehicles
 
		if (src->type == VEH_Road) {
 
			uint16 ord;
 
			int i;
 
			Station *st;
 
			TileIndex required_dst;
 
			
 

	
 
			for (i=0; (ord = src->schedule_ptr[i]) != 0; i++) {
 
				if ( ( ord & OT_MASK ) == OT_GOTO_STATION ) {
 
					st = DEREF_STATION(ord >> 8);
 
@@ -292,7 +292,7 @@ void BackupVehicleOrders(Vehicle *v, Bac
 

	
 
	bak->orderindex = v->cur_order_index;
 
	bak->service_interval = v->service_interval;
 
	
 

	
 
	if ((v->string_id & 0xF800) != 0x7800) {
 
		bak->name[0] = 0;
 
	} else {
 
@@ -306,7 +306,7 @@ void BackupVehicleOrders(Vehicle *v, Bac
 
		os[1] = u->index;
 
		return;
 
	}
 
	
 

	
 
	sched = v->schedule_ptr;
 
	do {
 
		ord = *sched++;
 
@@ -325,7 +325,7 @@ void RestoreVehicleOrders(Vehicle *v, Ba
 
	}
 

	
 
	DoCommandP(0, v->index, bak->orderindex|(bak->service_interval<<16) , NULL, CMD_RESTORE_ORDER_INDEX | CMD_ASYNC);
 
	
 

	
 
	os = bak->order;
 
	if (os[0] == 0xFFFF) {
 
		DoCommandP(0, v->index | os[1]<<16, 0, NULL, CMD_CLONE_ORDER);
 
@@ -359,7 +359,7 @@ int CheckOrders(Vehicle *v)
 
{
 
	if (!_patches.order_review_system)	//User doesn't want things to be checked
 
		return 0;
 
		
 

	
 
	if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) )
 
		return 0;
 

	
 
@@ -401,17 +401,17 @@ int CheckOrders(Vehicle *v)
 
		if ( (v->schedule_ptr[0] == v->schedule_ptr[i-2]) && ( i-2 != 0 ) ) {
 
			problem_type = 2;
 
		}
 
		
 

	
 
		if (n_st < 2) problem_type = 0;
 
		
 

	
 
		if (!required_tile) problem_type = 3;
 

	
 
		SET_DPARAM16(0, v->unitnumber);
 
		
 

	
 
		message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type;
 
	
 

	
 
		if (problem_type < 0) return 0;
 
		
 

	
 
		AddNewsItem(
 
			message,
 
			NEWS_FLAGS(NM_SMALL, NF_VIEWPORT|NF_VEHICLE, NT_ADVICE, 0),
order_gui.c
Show inline comments
 
@@ -58,7 +58,7 @@ static void DrawOrdersWindow(Window *w)
 
	SetVScrollCount(w, num+1);
 

	
 
	sel = OrderGetSel(w);
 
	
 

	
 
	SET_DPARAM16(2,STR_8827_FULL_LOAD);
 
	switch(v->schedule_ptr[sel] & 0x1F) {
 
	case OT_GOTO_STATION:
 
@@ -70,7 +70,7 @@ static void DrawOrdersWindow(Window *w)
 
	default:
 
		SETBIT(w->disabled_state, 6); /* nonstop */
 
		SETBIT(w->disabled_state, 8);	/* full load */
 
		SETBIT(w->disabled_state, 9);	/* unload */				
 
		SETBIT(w->disabled_state, 9);	/* unload */
 
	}
 

	
 
	SET_DPARAM16(0, v->string_id);
 
@@ -82,11 +82,11 @@ static void DrawOrdersWindow(Window *w)
 
	i = 0;
 
	for(;;) {
 
		str = ((byte)v->cur_order_index == i) ? STR_8805 : STR_8804;
 
		
 

	
 
		ord = v->schedule_ptr[i];
 

	
 
		if ( (uint)(i - w->vscroll.pos) < 6) {
 
			
 

	
 
			if (ord == 0) {
 
				str = shared_schedule ? STR_END_OF_SHARED_ORDERS : STR_882A_END_OF_ORDERS;
 
			} else {
 
@@ -149,7 +149,7 @@ static void *FindVehicleCallb(Vehicle *v
 
{
 
	if (v->tile != f->tile || v->owner != f->owner || v->vehstatus & VS_HIDDEN ) return NULL;
 
	return v;
 
} 
 
}
 

	
 
Vehicle *GetVehicleOnTile(TileIndex tile, byte owner)
 
{
 
@@ -231,7 +231,7 @@ static bool HandleOrderVehClick(Vehicle 
 
	// v is vehicle getting orders. Only copy/clone orders if vehicle doesn't have any orders yet
 
	// obviously if you press CTRL on a non-empty orders vehicle you know what you are doing
 
	if (v->num_orders != 0 && _ctrl_pressed == 0) {return false;}
 
	
 

	
 
	if (DoCommandP(v->tile, v->index | (u->index << 16), _ctrl_pressed ? 0 : 1, NULL,
 
		_ctrl_pressed ? CMD_CLONE_ORDER | CMD_MSG(STR_CANT_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_CANT_COPY_ORDER_LIST))) {
 
		WP(w,order_d).sel = -1;
 
@@ -245,7 +245,7 @@ static void OrdersPlaceObj(Vehicle *v, u
 
{
 
	uint cmd;
 
	Vehicle *u;
 
	
 

	
 
	// check if we're clicking on a vehicle first.. clone orders in that case.
 
	u = CheckMouseOverVehicle();
 
	if (u && HandleOrderVehClick(v, u, w))
 
@@ -273,7 +273,7 @@ static void OrdersWndProc(Window *w, Win
 
		Vehicle *v = &_vehicles[w->window_number];
 
		int mode;
 
		switch(e->click.widget) {
 
		case 2:	{/* orders list */	
 
		case 2:	{/* orders list */
 
			int sel;
 
			sel = (e->click.pt.y - 15) / 10;
 

	
 
@@ -298,7 +298,7 @@ static void OrdersWndProc(Window *w, Win
 

	
 
				if (xy)
 
					ScrollMainWindowToTile(xy);
 
				
 

	
 
				return;
 
			}
 

	
 
@@ -383,7 +383,7 @@ static void OrdersWndProc(Window *w, Win
 
			HandleOrderVehClick(&_vehicles[w->window_number], v, w);
 
		}
 
	} break;
 
		
 

	
 
	}
 
}
 

	
 
@@ -556,7 +556,7 @@ void ShowOrdersWindow(Vehicle *v)
 

	
 
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
 
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
 
	
 

	
 
	_alloc_wnd_parent_num = veh;
 
	w = AllocateWindowDesc(
 
		_order_window_desc[(v->type - VEH_Train)*2 + (v->owner != _local_player)]);
pathfind.c
Show inline comments
 
@@ -37,7 +37,7 @@ static bool TPFSetTileBit(TrackPathFinde
 
			return true;
 
		} else {
 
			/* two tiles with the same hash, need to make a link */
 
			
 

	
 
			/* allocate a link. if out of links, handle this by returning
 
			 * that a tile was already visisted. */
 
			if (tpf->num_links_left == 0)
 
@@ -51,7 +51,7 @@ static bool TPFSetTileBit(TrackPathFinde
 
			tpf->hash_tile[hash] = PATHFIND_GET_LINK_OFFS(tpf, link);
 

	
 
			link->flags = tpf->hash_head[hash];
 
			tpf->hash_head[hash] = 0xFFFF; /* multi link */ 
 
			tpf->hash_head[hash] = 0xFFFF; /* multi link */
 

	
 
			link->next = 0xFFFF;
 
		}
 
@@ -59,7 +59,7 @@ static bool TPFSetTileBit(TrackPathFinde
 
		/* a linked list of many tiles,
 
		 * find the one corresponding to the tile, if it exists.
 
		 * otherwise make a new link */
 
		
 

	
 
		offs = tpf->hash_tile[hash];
 
		do {
 
			link = PATHFIND_GET_LINK_PTR(tpf, offs);
 
@@ -74,7 +74,7 @@ static bool TPFSetTileBit(TrackPathFinde
 
			}
 
		} while ((offs=link->next) != 0xFFFF);
 
	}
 
	
 

	
 
	/* get here if we need to add a new link to link,
 
	 * first, allocate a new link, in the same way as before */
 
	if (tpf->num_links_left == 0)
 
@@ -130,12 +130,12 @@ void TPFMode2(TrackPathFinder *tpf, uint
 

	
 
	// This addition will sometimes overflow by a single tile.
 
	// The use of TILE_MASK here makes sure that we still point at a valid
 
	// tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. 
 
	// tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail.
 
	tile = TILE_MASK(tile + _tileoffs_by_dir[direction]);
 

	
 
	if (++tpf->rd.cur_length > 50)
 
		return;
 
	
 

	
 
	bits = GetTileTrackStatus(tile, tpf->tracktype);
 
	bits = (byte)((bits | (bits >> 8)) & _bits_mask[direction]);
 
	if (bits == 0)
 
@@ -161,7 +161,7 @@ void TPFMode2(TrackPathFinder *tpf, uint
 
		// Change direction 4 times only
 
		if ((byte)i != tpf->rd.pft_var6) {
 
			if(++tpf->rd.depth > 4) {
 
				tpf->rd = rd;		
 
				tpf->rd = rd;
 
				return;
 
			}
 
			tpf->rd.pft_var6 = (byte)i;
 
@@ -169,7 +169,7 @@ void TPFMode2(TrackPathFinder *tpf, uint
 

	
 
continue_here:;
 
		tpf->the_dir = HASBIT(_otherdir_mask[direction],i) ? (i+8) : i;
 
		
 

	
 
#ifdef DEBUG_TILE_PUSH
 
		dbg_push_tile(tile, tpf->the_dir);
 
#endif
 
@@ -265,7 +265,7 @@ void TPFMode1(TrackPathFinder *tpf, uint
 
	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile] & 0xF0)==0) {
 
		if ((_map5[tile] & 3) != direction || ((_map5[tile]>>1)&6) != tpf->tracktype)
 
			return;
 
		tile = SkipToEndOfTunnel(tpf, tile, direction);		
 
		tile = SkipToEndOfTunnel(tpf, tile, direction);
 
	}
 
	tile += _tileoffs_by_dir[direction];
 
	tpf->rd.cur_length++;
 
@@ -286,7 +286,7 @@ void TPFMode1(TrackPathFinder *tpf, uint
 

	
 
				tpf->the_dir = (_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i;
 
				rd = tpf->rd;
 
				
 

	
 
#ifdef DEBUG_TILE_PUSH
 
		dbg_push_tile(tile, tpf->the_dir);
 
#endif
 
@@ -304,12 +304,12 @@ void TPFMode1(TrackPathFinder *tpf, uint
 

	
 
	/* the next is only used when signals are checked.
 
	 * seems to go in 2 directions simultaneously */
 
	 
 

	
 
	/* if i can get rid of this, tail end recursion can be used to minimize
 
	 * stack space dramatically. */	
 
	 * stack space dramatically. */
 
	if (tpf->hasbit_13)
 
		return;
 
	
 

	
 
	tile = tile_org;
 
	direction ^= 2;
 

	
 
@@ -327,7 +327,7 @@ void TPFMode1(TrackPathFinder *tpf, uint
 
	do {
 
		i = FIND_FIRST_BIT(bits);
 
		bits = KILL_FIRST_BIT(bits);
 
		
 

	
 
		tpf->the_dir = (_otherdir_mask[direction] & (byte)(1 << i)) ? (i+8) : i;
 
		rd = tpf->rd;
 
		if (TPFSetTileBit(tpf, tile, tpf->the_dir) &&
 
@@ -344,16 +344,16 @@ void FollowTrack(uint tile, uint16 flags
 

	
 
	assert(direction < 4);
 

	
 
	/* initialize path finder variables */	
 
	/* initialize path finder variables */
 
	tpf->userdata = data;
 
	tpf->enum_proc = enum_proc;	
 
	tpf->enum_proc = enum_proc;
 
	tpf->new_link = tpf->links;
 
	tpf->num_links_left = 0x400;
 

	
 
	tpf->rd.cur_length = 0;
 
	tpf->rd.depth = 0;
 
	tpf->rd.pft_var6 = 0;
 
	
 

	
 
	tpf->var2 = HASBIT(flags, 15) ? 0x43 : 0xFF; /* 0x8000 */
 

	
 
	tpf->disable_tile_hash = HASBIT(flags, 12) != 0;     /* 0x1000 */
 
@@ -362,10 +362,10 @@ void FollowTrack(uint tile, uint16 flags
 

	
 
	tpf->tracktype = (byte)flags;
 

	
 
	if (HASBIT(flags, 11)) {	
 
	if (HASBIT(flags, 11)) {
 
		tpf->rd.pft_var6 = 0xFF;
 
		tpf->enum_proc(tile, data, 0, 0, 0);
 
		TPFMode2(tpf, tile, direction);	
 
		TPFMode2(tpf, tile, direction);
 
	} else {
 
		/* clear the hash_heads */
 
		memset(tpf->hash_head, 0, sizeof(tpf->hash_head));
 
@@ -373,7 +373,7 @@ void FollowTrack(uint tile, uint16 flags
 
	}
 

	
 
	if (after_proc != NULL)
 
		after_proc(tpf);	
 
		after_proc(tpf);
 
}
 

	
 
typedef struct {
 
@@ -439,10 +439,10 @@ static void INLINE HeapifyUp(NewTrackPat
 
{
 
	StackedItem si;
 
	int i = ++tpf->nstack;
 
	
 

	
 
	while (i != 1 && ARR(i).cur_length < ARR(i>>1).cur_length) {
 
		// the child element is larger than the parent item.
 
		// swap the child item and the parent item. 
 
		// swap the child item and the parent item.
 
		si = ARR(i); ARR(i) = ARR(i>>1); ARR(i>>1) = si;
 
		i>>=1;
 
	}
 
@@ -462,13 +462,13 @@ static void INLINE HeapifyDown(NewTrackP
 

	
 
	while ((j=i*2) <= n) {
 
		// figure out which is smaller of the children.
 
		if (j != n && ARR(j).cur_length > ARR(j+1).cur_length) 
 
		if (j != n && ARR(j).cur_length > ARR(j+1).cur_length)
 
			j++; // right item is smaller
 

	
 
		assert(i <= n && j <= n);
 
		if (ARR(i).cur_length <= ARR(j).cur_length)
 
			break; // base elem smaller than smallest, done!
 
	
 

	
 
		// swap parent with the child
 
		si = ARR(i); ARR(i) = ARR(j); ARR(j) = si;
 
		i = j;
 
@@ -484,7 +484,7 @@ static bool NtpVisit(NewTrackPathFinder 
 
	HashLink *link, *new_link;
 

	
 
	assert(length < 1024);
 
	
 

	
 
	hash = PATHFIND_HASH_TILE(tile);
 

	
 
	// never visited before?
 
@@ -496,10 +496,10 @@ static bool NtpVisit(NewTrackPathFinder 
 

	
 
	if (head != 0xffff) {
 
		if ( (TileIndex)tile == tpf->hash_tile[hash] && (head & 0x3) == dir ) {
 
			
 

	
 
			// longer length
 
			if (length >= (head >> 2)) return false;
 
			
 

	
 
			tpf->hash_head[hash] = dir | (length << 2);
 
			return true;
 
		}
 
@@ -517,13 +517,13 @@ static bool NtpVisit(NewTrackPathFinder 
 
		tpf->hash_tile[hash] = NTP_GET_LINK_OFFS(tpf, link);
 

	
 
		link->typelength = tpf->hash_head[hash];
 
		tpf->hash_head[hash] = 0xFFFF; /* multi link */ 
 
		tpf->hash_head[hash] = 0xFFFF; /* multi link */
 
		link->next = 0xFFFF;
 
	} else {
 
		// a linked list of many tiles,
 
		// find the one corresponding to the tile, if it exists.
 
		// otherwise make a new link
 
		
 

	
 
		uint offs = tpf->hash_tile[hash];
 
		do {
 
			link = NTP_GET_LINK_PTR(tpf, offs);
 
@@ -534,7 +534,7 @@ static bool NtpVisit(NewTrackPathFinder 
 
			}
 
		} while ((offs=link->next) != 0xFFFF);
 
	}
 
	
 

	
 
	/* get here if we need to add a new link to link,
 
	 * first, allocate a new link, in the same way as before */
 
	if (tpf->num_links_left == 0)
 
@@ -613,7 +613,7 @@ restart:
 

	
 
	for(;;) {
 
		tile += _tileoffs_by_dir[direction];
 
		
 

	
 
		// too long search length? bail out.
 
		if (++si.cur_length >= tpf->maxlength)
 
			goto popnext;
 
@@ -628,7 +628,7 @@ restart:
 
		// regular rail tile, determine the tracks that are actually reachable.
 
		bits &= _bits_mask[direction];
 
		if (bits == 0) goto popnext; // no tracks there? stop searching.
 
		
 

	
 
		// complex tile?, let the generic handler handle that..
 
		if (KILL_FIRST_BIT(bits) != 0) break;
 

	
 
@@ -656,16 +656,16 @@ restart:
 
	// too high recursion depth.. bail out..
 
	if (si.depth >= _patches.pf_maxdepth)
 
		goto popnext;
 
	
 

	
 
	si.depth++; // increase recursion depth.
 

	
 
	// see if this tile was already visited..?
 
	if (NtpVisit(tpf, tile, direction, si.cur_length)) {
 
		// push all possible alternatives	
 
		// push all possible alternatives
 
		si.tile = tile;
 
		do {
 
			si.track = _new_track[FIND_FIRST_BIT(bits)][direction];
 
			
 

	
 
			// out of stack items, bail out?
 
			if (tpf->nstack >= lengthof(tpf->stack))
 
				break;
 
@@ -678,11 +678,11 @@ restart:
 
		// also randomize the order in which we search through them.
 
		if (si.depth == 1) {
 
			uint32 r = Random();
 
			assert(tpf->nstack == 2 || tpf->nstack == 3);			
 
			if (r&1) swap_byte(&tpf->stack[0].track, &tpf->stack[1].track);	
 
			assert(tpf->nstack == 2 || tpf->nstack == 3);
 
			if (r&1) swap_byte(&tpf->stack[0].track, &tpf->stack[1].track);
 
			if (tpf->nstack != 2) {
 
				byte t = tpf->stack[2].track;
 
				if (r&2) swap_byte(&tpf->stack[0].track, &t);	
 
				if (r&2) swap_byte(&tpf->stack[0].track, &t);
 
				if (r&4) swap_byte(&tpf->stack[1].track, &t);
 
				tpf->stack[2].first_track = tpf->stack[2].track = t;
 
			}
 
@@ -702,7 +702,7 @@ popnext:
 
		!NtpCheck(tpf, tile, _tpf_prev_direction[si.track], si.cur_length) || // already have better path to that tile?
 
		tpf->enum_proc(tile, tpf->userdata, si.track, si.cur_length, &si.state)
 
	);
 
	
 

	
 
	direction = _tpf_new_direction[si.track];
 
	goto restart;
 
}
 
@@ -718,7 +718,7 @@ void NewTrainPathfind(uint tile, byte di
 

	
 
		tpf  = alloca(sizeof(NewTrackPathFinder));
 
		tpf->userdata = data;
 
		tpf->enum_proc = enum_proc;	
 
		tpf->enum_proc = enum_proc;
 
		tpf->tracktype = 0;
 
		tpf->maxlength = _patches.pf_maxlength;
 
		tpf->nstack = 0;
road_gui.c
Show inline comments
 
@@ -128,17 +128,17 @@ static void BuildRoadClick_Raise(Window 
 

	
 
static void BuildRoadClick_Depot(Window *w)
 
{
 
	if (HandlePlacePushButton(w, 7, 0x511, 1, PlaceRoad_Depot)) ShowRoadDepotPicker();	
 
	if (HandlePlacePushButton(w, 7, 0x511, 1, PlaceRoad_Depot)) ShowRoadDepotPicker();
 
}
 

	
 
static void BuildRoadClick_BusStation(Window *w)
 
{
 
	if (HandlePlacePushButton(w, 8, 0xAA5, 1, PlaceRoad_BusStation)) ShowBusStationPicker();	
 
	if (HandlePlacePushButton(w, 8, 0xAA5, 1, PlaceRoad_BusStation)) ShowBusStationPicker();
 
}
 

	
 
static void BuildRoadClick_TruckStation(Window *w)
 
{
 
	if (HandlePlacePushButton(w, 9, 0xAA6, 1, PlaceRoad_TruckStation)) ShowTruckStationPicker();	
 
	if (HandlePlacePushButton(w, 9, 0xAA6, 1, PlaceRoad_TruckStation)) ShowTruckStationPicker();
 
}
 

	
 
static void BuildRoadClick_Bridge(Window *w)
 
@@ -244,7 +244,7 @@ static void BuildRoadToolbWndProc(Window
 
		} else {
 
			sel_method = VPM_X_OR_Y;
 
		}
 
		
 

	
 
		VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, sel_method);
 
		return;
 
	}
 
@@ -257,8 +257,8 @@ static void BuildRoadToolbWndProc(Window
 
				ResetObjectToPlace();
 
				ShowBuildBridgeWindow(start_tile, end_tile, 0x80);
 
			} else if (e->place.userdata != 4) {
 
				DoCommandP(end_tile, start_tile, _place_road_flag, CcPlaySound1D, 
 
					_remove_button_clicked ? 
 
				DoCommandP(end_tile, start_tile, _place_road_flag, CcPlaySound1D,
 
					_remove_button_clicked ?
 
					CMD_REMOVE_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1805_CAN_T_REMOVE_ROAD_FROM) :
 
					CMD_BUILD_LONG_ROAD | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1804_CAN_T_BUILD_ROAD_HERE));
 
			} else {
 
@@ -363,9 +363,9 @@ static void BuildRoadDepotWndProc(Window
 
			SndPlayFx(0x13);
 
			SetWindowDirty(w);
 
			break;
 
		}	
 
		}
 
	}	break;
 
	
 

	
 
	case WE_MOUSELOOP:
 
		if (WP(w,def_d).close)
 
			DeleteWindow(w);
 
@@ -445,7 +445,7 @@ static void RoadStationPickerWndProc(Win
 
			break;
 
		}
 
	} break;
 
	
 

	
 
	case WE_MOUSELOOP: {
 
		if (WP(w,def_d).close) {
 
			DeleteWindow(w);
 
@@ -454,7 +454,7 @@ static void RoadStationPickerWndProc(Win
 

	
 
		CheckRedrawStationCoverage(w);
 
	} break;
 
	}		
 
	}
 
}
 

	
 
static const Widget _bus_station_picker_widgets[] = {
roadveh_cmd.c
Show inline comments
 
@@ -38,7 +38,7 @@ static const byte _roadveh_spritenum[88]
 
	0, 17, 17, 34, 51, 51, 51, 1,
 
	18, 35, 2, 19, 36, 57, 57, 57,
 
	3, 20, 37, 4, 21, 38, 5, 22,
 
	
 

	
 
	39, 6, 23, 40, 7, 24, 41, 8,
 
	25, 42, 9, 26, 43, 10, 27, 44,
 
	11, 28, 45, 12, 29, 46, 13, 30,
 
@@ -47,7 +47,7 @@ static const byte _roadveh_spritenum[88]
 
	33, 50, 52, 52, 52, 53, 53, 53,
 
	54, 54, 54, 55, 55, 55, 56, 56,
 
	56, 58, 58, 58, 59, 59, 59, 60,
 
	60, 60, 61, 61, 61, 62, 62, 62,	
 
	60, 60, 61, 61, 61, 62, 62, 62,
 
};
 

	
 
const byte _roadveh_speed[88] = {
 
@@ -164,7 +164,7 @@ int GetRoadVehImage(Vehicle *v, byte dir
 
		img = _engine_original_sprites[v->engine_type];
 
	}
 
#endif
 
	
 

	
 
	image = direction + _roadveh_images[img];
 
	if (v->cargo_count >= (v->cargo_cap >> 1))
 
		image += _roadveh_full_adder[img];
 
@@ -186,7 +186,7 @@ void DrawRoadVehEngineInfo(int engine, i
 

	
 
	SET_DPARAM16(4, _roadveh_capacity[engine]);
 
	SET_DPARAM16(3, _cargoc.names_long_p[_roadveh_cargo_type[engine]]);
 
		
 

	
 
	DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
 
}
 

	
 
@@ -202,7 +202,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint
 
	byte unit_num;
 
	uint tile = TILE_FROM_XY(x,y);
 
	Engine *e;
 
	
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	cost = EstimateRoadVehCost(p1);
 
@@ -256,7 +256,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint
 
		v->reliability_spd_dec = e->reliability_spd_dec;
 
		v->max_age = e->lifelength * 366;
 
		_new_roadveh_id = v->index;
 
		
 

	
 
		v->string_id = STR_SV_ROADVEH_NAME;
 
		*(v->schedule_ptr = _ptr_to_next_order++) = 0;
 

	
 
@@ -303,7 +303,7 @@ int32 CmdSellRoadVeh(int x, int y, uint3
 
	Vehicle *v;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
	
 

	
 
	v = &_vehicles[p1];
 

	
 
	if (v->type != VEH_Road || !CheckOwnership(v->owner))
 
@@ -311,7 +311,7 @@ int32 CmdSellRoadVeh(int x, int y, uint3
 

	
 
	if (!IsRoadDepotTile(v->tile) || v->u.road.state != 254 || !(v->vehstatus&VS_STOPPED))
 
		return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		// Invalidate depot
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
@@ -321,7 +321,7 @@ int32 CmdSellRoadVeh(int x, int y, uint3
 
		DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
		DeleteVehicle(v);
 
	}
 
	
 

	
 
	return -(int32)v->value;
 
}
 

	
 
@@ -351,7 +351,7 @@ static bool EnumRoadSignalFindDepot(uint
 
	if (IS_TILETYPE(tile, MP_STREET) &&
 
			(_map5[tile] & 0xF0) == 0x20 &&
 
			_map_owner[tile] == rfdd->owner) {
 
			
 

	
 
		if (length < rfdd->best_length) {
 
			rfdd->best_length = length;
 
			rfdd->tile = tile;
 
@@ -365,7 +365,7 @@ static int FindClosestRoadDepot(Vehicle 
 
	uint tile = v->tile;
 
	int i;
 
	RoadFindDepotData rfdd;
 
		
 

	
 
	if (v->u.road.state == 255) { tile = GetVehicleOutOfTunnelTile(v); }
 

	
 
	rfdd.owner = v->owner;
 
@@ -409,7 +409,7 @@ int32 CmdSendRoadVehToDepot(int x, int y
 
		v->dest_tile = _depots[depot].xy;
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
	}
 
	
 

	
 
	return 0;
 
}
 

	
 
@@ -430,10 +430,10 @@ int32 CmdTurnRoadVeh(int x, int y, uint3
 
		_error_message = STR_EMPTY;
 
		return CMD_ERROR;
 
	}
 
				
 

	
 
	if (flags & DC_EXEC) {
 
		v->u.road.reverse_ctr = 180;
 
	}		
 
	}
 

	
 
	return 0;
 
}
 
@@ -495,10 +495,10 @@ static void ClearCrashedStation(Vehicle 
 

	
 
	// mark station as not busy
 
	bb &= ~0x80;
 
	
 

	
 
	// free parking bay
 
	bb |= (v->u.road.state&0x02)?2:1;
 
	
 

	
 
	*b = bb;
 
}
 

	
 
@@ -506,17 +506,17 @@ static void RoadVehDelete(Vehicle *v)
 
{
 
	DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
	InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		
 

	
 
	_vehicle_sort_dirty[VEHROAD] = true; // delete bus/truck (eg. crash for example)
 
	InvalidateWindow(WC_ROADVEH_LIST, v->owner);
 
	InvalidateWindow(WC_COMPANY, v->owner);
 

	
 
	if(IS_TILETYPE(v->tile, MP_STATION))
 
		ClearCrashedStation(v);
 
	
 

	
 
	BeginVehicleMove(v);
 
	EndVehicleMove(v);
 
	
 

	
 
	DeleteVehicle(v);
 
}
 

	
 
@@ -531,7 +531,7 @@ static byte SetRoadVehPosition(Vehicle *
 

	
 
	old_z = v->z_pos;
 
	v->z_pos = new_z;
 
	
 

	
 
	VehiclePositionChanged(v);
 
	EndVehicleMove(v);
 
	return old_z;
 
@@ -621,10 +621,10 @@ static void HandleBrokenRoadVeh(Vehicle 
 

	
 
		if (v->breakdowns_since_last_service != 255)
 
			v->breakdowns_since_last_service++;
 
		
 

	
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		
 

	
 
		SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? 0xD : 0x34, v);
 

	
 
		if (!(v->vehstatus & VS_HIDDEN)) {
 
@@ -693,7 +693,7 @@ static void HandleRoadVehLoading(Vehicle
 
{
 
	if (v->next_order == OT_NOTHING)
 
		return;
 
	
 

	
 
	if (v->next_order != OT_DUMMY) {
 
		if ((v->next_order&OT_MASK) != OT_LOADING)
 
			return;
 
@@ -709,7 +709,7 @@ static void HandleRoadVehLoading(Vehicle
 
			}
 
			return;
 
		}
 
		
 

	
 
		{
 
			byte b = v->next_order;
 
			v->next_order = OT_LEAVESTATION;
 
@@ -737,16 +737,16 @@ typedef struct RoadVehFindData {
 

	
 
void *EnumCheckRoadVehClose(Vehicle *v, RoadVehFindData *rvf)
 
{
 
	static const short _dists[] = { 
 
	static const short _dists[] = {
 
		-4, -8, -4, -1, 4, 8, 4, 1,
 
		-4, -1, 4, 8, 4, 1, -4, -8,
 
	};
 
	
 

	
 
	short x_diff = v->x_pos - rvf->x;
 
	short y_diff = v->y_pos - rvf->y;
 

	
 
	if (rvf->veh == v || 
 
			v->type != VEH_Road || 
 
	if (rvf->veh == v ||
 
			v->type != VEH_Road ||
 
			v->u.road.state == 254 ||
 
			myabs(v->z_pos - rvf->veh->z_pos) > 6 ||
 
			v->direction != rvf->dir ||
 
@@ -766,13 +766,13 @@ static Vehicle *RoadVehFindCloseTo(Vehic
 

	
 
	if (v->u.road.reverse_ctr != 0)
 
		return NULL;
 
	
 

	
 
	rvf.x = x;
 
	rvf.y = y;
 
	rvf.dir = dir;
 
	rvf.veh = v;
 
	u = VehicleFromPos(TILE_FROM_XY(x,y), &rvf, (VehicleFromPosProc*)EnumCheckRoadVehClose);
 
	
 

	
 
	// This code protects a roadvehicle from being blocked for ever
 
	//  If more then 1480 / 74 days a road vehicle is blocked, it will
 
	//  drive just through it. The ultimate backup-code of TTD.
 
@@ -784,7 +784,7 @@ static Vehicle *RoadVehFindCloseTo(Vehic
 

	
 
	if (++v->u.road.unk2 > 1480)
 
		return NULL;
 
	
 

	
 
	return u;
 
}
 

	
 
@@ -825,13 +825,13 @@ static bool RoadVehAccelerate(Vehicle *v
 
{
 
	uint spd = v->cur_speed + 1 + ((v->u.road.overtaking != 0)?1:0);
 
	byte t;
 
	
 

	
 
	// Clamp
 
	spd = min(spd, v->max_speed);
 

	
 
	//updates statusbar only if speed have changed to save CPU time
 
	if (spd != v->cur_speed) {
 
		v->cur_speed = spd;	
 
		v->cur_speed = spd;
 
		if (_patches.vehicle_speed)
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
	}
 
@@ -858,7 +858,7 @@ static byte RoadVehGetNewDirection(Vehic
 
		1, 0, 5, 0,
 
		2, 3, 4
 
	};
 
	
 

	
 
	x = x - v->x_pos + 1;
 
	y = y - v->y_pos + 1;
 

	
 
@@ -878,7 +878,7 @@ static byte RoadVehGetSlidingDirection(V
 
	if (b==d) return d;
 
	if (b==((d-1)&7)) return d;
 
	if (b==((d-2)&7)) return d;
 
	return (d+2)&7;	
 
	return (d+2)&7;
 
}
 

	
 
typedef struct OvertakeData {
 
@@ -890,11 +890,11 @@ typedef struct OvertakeData {
 
void *EnumFindVehToOvertake(Vehicle *v, OvertakeData *od)
 
{
 
	if (v->tile != (TileIndex)od->tile ||
 
			v->type != VEH_Road || 
 
			v == od->u || 
 
			v->type != VEH_Road ||
 
			v == od->u ||
 
			v == od->v)
 
				return NULL;
 
	return v; 
 
	return v;
 
}
 

	
 
static bool FindRoadVehToOvertake(OvertakeData *od)
 
@@ -1078,7 +1078,7 @@ do_it:;
 
			if (desttile == tile && bitmask&_road_pf_table_3[m5&3]) {
 
				return_track(FindFirstBit2x64(bitmask&_road_pf_table_3[m5&3]));
 
			}
 
		}		
 
		}
 
	}
 
	// do pathfind
 
	frd.dest = desttile;
 
@@ -1107,7 +1107,7 @@ found_best_track:;
 
	if (HASBIT(signal, best_track))
 
		return -1;
 

	
 
	return best_track;		
 
	return best_track;
 
}
 

	
 
typedef struct RoadDriveEntry {
 
@@ -1173,13 +1173,13 @@ static void RoadVehEventHandler(Vehicle 
 
		byte rd2;
 

	
 
		v->cur_speed = 0;
 
		
 

	
 
		dir = _map5[v->tile]&3;
 
		v->direction = dir*2+1;
 

	
 
		rd2 = _roadveh_data_2[dir];
 
		rdp = _road_drive_data[(_opt.road_side<<4) + rd2];
 
		
 

	
 
		x = GET_TILE_X(v->tile)*16 + (rdp[6].x&0xF);
 
		y = GET_TILE_Y(v->tile)*16 + (rdp[6].y&0xF);
 

	
 
@@ -1193,7 +1193,7 @@ static void RoadVehEventHandler(Vehicle 
 
		v->vehstatus &= ~VS_HIDDEN;
 
		v->u.road.state = rd2;
 
		v->u.road.frame = 6;
 
		
 

	
 
		v->cur_image = GetRoadVehImage(v, v->direction);
 
		UpdateRoadVehDeltaXY(v);
 
		SetRoadVehPosition(v,x,y);
 
@@ -1223,7 +1223,7 @@ static void RoadVehEventHandler(Vehicle 
 
		if (IS_TILETYPE(gp.new_tile, MP_TUNNELBRIDGE) &&
 
				(_map5[gp.new_tile]&0xF0) == 0 &&
 
				(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y)&4)) {
 
			
 

	
 
			//new_dir = RoadGetNewDirection(v, gp.x, gp.y)
 
			v->cur_image = GetRoadVehImage(v, v->direction);
 
			UpdateRoadVehDeltaXY(v);
 
@@ -1353,7 +1353,7 @@ again:
 

	
 
	x = (v->x_pos&~15)+(rd.x&15);
 
	y = (v->y_pos&~15)+(rd.y&15);
 
	
 

	
 
	new_dir = RoadVehGetSlidingDirection(v, x, y);
 

	
 
	if (!IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && (u=RoadVehFindCloseTo(v, x, y, new_dir)) != NULL) {
 
@@ -1383,7 +1383,7 @@ again:
 

	
 
		if ( (v->next_order&OT_MASK) != OT_LEAVESTATION &&
 
				(v->next_order&OT_MASK) != OT_GOTO_DEPOT) {
 
			
 

	
 
			*b &= ~0x80;
 

	
 
			v->last_station_visited = _map2[v->tile];
 
@@ -1393,7 +1393,7 @@ again:
 
			old_order = v->next_order;
 
			v->next_order = OT_LOADING;
 

	
 
			if ((old_order & OT_MASK) == OT_GOTO_STATION && 
 
			if ((old_order & OT_MASK) == OT_GOTO_STATION &&
 
					v->next_order_param == v->last_station_visited) {
 
				v->next_order = OT_LOADING | OF_NON_STOP | (old_order & (OF_FULL_LOAD|OF_UNLOAD));
 
			}
 
@@ -1449,10 +1449,10 @@ void RoadVehEnterDepot(Vehicle *v)
 

	
 
	MaybeRenewVehicle(v, EstimateRoadVehCost(v->engine_type));
 

	
 
	
 

	
 
	if ((v->next_order&OT_MASK) == OT_GOTO_DEPOT) {
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
	
 

	
 
		t = v->next_order;
 
		v->next_order = OT_DUMMY;
 

	
 
@@ -1504,7 +1504,7 @@ static void CheckIfRoadVehNeedsService(V
 

	
 
	if (_patches.gotodepot && ScheduleHasDepotOrders(v->schedule_ptr))
 
		return;
 
	
 

	
 
	// Don't interfere with a depot visit scheduled by the user, or a
 
	// depot visit by the order list.
 
	if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT &&
 
@@ -1527,7 +1527,7 @@ static void CheckIfRoadVehNeedsService(V
 
	v->next_order = OT_GOTO_DEPOT | OF_NON_STOP;
 
	v->next_order_param = (byte)i;
 
	v->dest_tile = (&_depots[i])->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);		
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
}
 

	
 
void OnNewDay_RoadVeh(Vehicle *v)
roadveh_gui.c
Show inline comments
 
@@ -51,7 +51,7 @@ static void RoadVehDetailsWndProc(Window
 
			StringID str;
 

	
 
			SET_DPARAM16(1, year);
 
			
 

	
 
			str = STR_0199_YEAR;
 
			if (year != 1) {
 
				str++;
 
@@ -97,7 +97,7 @@ static void RoadVehDetailsWndProc(Window
 
		SET_DPARAM16(1, 1920 + v->build_year);
 
		SET_DPARAM32(2, v->value);
 
		DrawString(34, 57, STR_9011_BUILT_VALUE, 0);
 
		
 

	
 
		SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]);
 
		SET_DPARAM16(1, v->cargo_cap);
 
		DrawString(34, 67, STR_9012_CAPACITY, 0);
 
@@ -180,7 +180,7 @@ static void ShowRoadVehDetailsWindow(Veh
 
	VehicleID veh = v->index;
 
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
 
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
 
	_alloc_wnd_parent_num = veh;	
 
	_alloc_wnd_parent_num = veh;
 
	w = AllocateWindowDesc(&_roadveh_details_desc);
 
	w->window_number = veh;
 
	w->caption_color = v->owner;
 
@@ -242,13 +242,13 @@ static void RoadVehViewWndProc(Window *w
 
		DrawStringCentered(125, 105, str, 0);
 
		DrawWindowViewport(w);
 
	} break;
 
		
 

	
 
	case WE_CLICK: {
 
		Vehicle *v = &_vehicles[w->window_number];
 

	
 
		switch(e->click.widget) {
 
		case 4: /* start stop */
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE)); 
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_ROADVEH | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE));
 
			break;
 
		case 5: /* center main view */
 
			ScrollMainWindowTo(v->x_pos, v->y_pos);
 
@@ -267,11 +267,11 @@ static void RoadVehViewWndProc(Window *w
 
			break;
 
		}
 
	} break;
 
		
 

	
 
	case WE_DESTROY:
 
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
 
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
 
		break;	
 
		break;
 
	}
 
}
 

	
 
@@ -348,7 +348,7 @@ static void DrawNewRoadVehWindow(Window 
 
					DrawRoadVehEngine(x+29, y+6, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
 
					y += 14;
 
				}
 
				sel--; 
 
				sel--;
 
			}
 
		} while (++engine_id, ++e,--num);
 

	
 
@@ -362,12 +362,12 @@ static void DrawNewRoadVehWindow(Window 
 
			SET_DPARAM16(4, _roadveh_capacity[selected_id - ROAD_ENGINES_INDEX]);
 
			SET_DPARAM16(3, _cargoc.names_long_p[_roadveh_cargo_type[selected_id - ROAD_ENGINES_INDEX]]);
 

	
 
			e = &_engines[selected_id];	
 
			e = &_engines[selected_id];
 
			SET_DPARAM16(6, e->lifelength);
 
			SET_DPARAM8(7, e->reliability * 100 >> 16);
 
			ConvertDayToYMD(&ymd, e->intro_date);
 
			SET_DPARAM16(5, ymd.year + 1920);
 
			
 

	
 
			DrawString(2, 127, STR_9008_COST_SPEED_RUNNING_COST, 0);
 
		}
 
	}
 
@@ -419,7 +419,7 @@ static void NewRoadVehWndProc(Window *w,
 
				160,
 
				w->window_class,
 
				w->window_number);
 
			break;		
 
			break;
 
		}
 
		break;
 

	
 
@@ -436,8 +436,8 @@ static void NewRoadVehWndProc(Window *w,
 
		memcpy(_decode_parameters, b, 32);
 
		DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_9037_CAN_T_RENAME_ROAD_VEHICLE));
 
	} break;
 
		
 
	}	
 

	
 
	}
 
}
 

	
 
static const Widget _new_road_veh_widgets[] = {
 
@@ -468,7 +468,7 @@ static void ShowBuildRoadVehWindow(TileI
 
	w = AllocateWindowDesc(&_new_road_veh_desc);
 
	w->window_number = tile;
 
	w->vscroll.cap = 8;
 
	
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
	} else {
 
@@ -509,17 +509,17 @@ static void DrawRoadDepotWindow(Window *
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road &&
 
				v->u.road.state == 254 && 
 
				v->u.road.state == 254 &&
 
				v->tile == (TileIndex)tile &&
 
				--num < 0 && num >=	-15) {
 

	
 
			DrawRoadVehImage(v, x+24, y, WP(w,traindepot_d).sel);
 
			
 

	
 
			SET_DPARAM16(0, v->unitnumber);
 
			DrawString(x, y+2, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
 

	
 
			DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x + 16, y);
 
			
 

	
 
			if ((x+=56) == 2+56*5) {
 
				x = 2;
 
				y += 14;
 
@@ -534,7 +534,7 @@ static int GetVehicleFromRoadDepotWndPt(
 
	TileIndex tile;
 
	Vehicle *v;
 
	int pos;
 
		
 

	
 
	xt = x / 56;
 
	xm = x % 56;
 
	if (xt >= 5)
 
@@ -549,7 +549,7 @@ static int GetVehicleFromRoadDepotWndPt(
 
	tile = w->window_number;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Road &&
 
				v->u.road.state == 254 && 
 
				v->u.road.state == 254 &&
 
				v->tile == (TileIndex)tile &&
 
				--pos < 0) {
 
					*veh = v;
 
@@ -611,7 +611,7 @@ static void RoadDepotWndProc(Window *w, 
 
		case 2:
 
			RoadDepotClickVeh(w, e->click.pt.x, e->click.pt.y);
 
			break;
 
			
 

	
 
		case 5:
 
			ShowBuildRoadVehWindow(w->window_number);
 
			break;
 
@@ -621,7 +621,7 @@ static void RoadDepotWndProc(Window *w, 
 
			break;
 
		}
 
	} break;
 
	
 

	
 
	case WE_DESTROY:
 
		DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
 
		break;
 
@@ -641,12 +641,12 @@ static void RoadDepotWndProc(Window *w, 
 
				ShowRoadVehViewWindow(v);
 
			}
 
		} break;
 
					
 

	
 
		case 3:
 
			if (!HASBIT(w->disabled_state, 3) &&
 
					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
 
				Vehicle *v;
 
				
 

	
 
				HandleButtonClick(w, 3);
 

	
 
				v = &_vehicles[WP(w,traindepot_d).sel];
 
@@ -654,7 +654,7 @@ static void RoadDepotWndProc(Window *w, 
 

	
 
				_backup_orders_tile = v->tile;
 
				BackupVehicleOrders(v, _backup_orders_data);
 
	
 

	
 
				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE)))
 
					_backup_orders_tile = 0;
 
			}
 
@@ -693,7 +693,7 @@ static const WindowDesc _road_depot_desc
 
void ShowRoadDepotWindow(uint tile)
 
{
 
	Window *w;
 
	
 

	
 
	w = AllocateWindowDescFront(&_road_depot_desc, tile);
 
	if (w) {
 
		w->caption_color = _map_owner[w->window_number];
 
@@ -730,7 +730,7 @@ static void MakeSortedRoadList(byte owne
 
		// roads are stored as a cummulative index, eg 25, 41, 43. This means
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
 
		for (i = &_num_road_sort[1]; i != endof(_num_road_sort); i++) {*i += *(i-1);}
 
	
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_road_sort, n, sizeof(_road_sort[0]), GeneralOwnerSorter);
 

	
 
@@ -775,7 +775,7 @@ static void PlayerRoadVehWndProc(Window 
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 roads
 
		i = (window_number == 0) ? 0 : _num_road_sort[window_number-1];
 
		SetVScrollCount(w, _num_road_sort[window_number] - i);
 
		
 

	
 
		/* draw the widgets */
 
		{
 
			Player *p = DEREF_PLAYER(window_number);
 
@@ -818,7 +818,7 @@ static void PlayerRoadVehWndProc(Window 
 
				SET_DPARAM32(0, v->profit_this_year);
 
				SET_DPARAM32(1, v->profit_last_year);
 
				DrawString(x + 24, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
 
				
 

	
 
				if (v->string_id != STR_SV_ROADVEH_NAME) {
 
					SET_DPARAM16(0, v->string_id);
 
					DrawString(x+24, y, STR_01AB, 0);
 
@@ -843,7 +843,7 @@ static void PlayerRoadVehWndProc(Window 
 
			return;
 
		case 6: { /* Matrix to show vehicles */
 
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
 
			
 

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

	
 
			id_v += w->vscroll.pos;
 
@@ -868,15 +868,15 @@ static void PlayerRoadVehWndProc(Window 
 

	
 
			tile = _last_built_road_depot_tile;
 
			do {
 
				if (_map_owner[tile] == _local_player && IsRoadDepotTile(tile)) {					
 
				if (_map_owner[tile] == _local_player && IsRoadDepotTile(tile)) {
 
					ShowRoadDepotWindow(tile);
 
					ShowBuildRoadVehWindow(tile);
 
					return;
 
				}
 
				
 

	
 
				tile = TILE_MASK(tile + 1);
 
			} while(tile != _last_built_road_depot_tile);
 
			
 

	
 
			ShowBuildRoadVehWindow(0);
 
		} break;
 
		}
saveload.c
Show inline comments
 
@@ -88,7 +88,7 @@ static void SlWriteFill()
 
		_sl.offs_base += len;
 
		if (len) _sl.write_bytes(len);
 
	}
 
	
 

	
 
	// setup next buffer
 
	_sl.bufp = _sl.buf;
 
	_sl.bufe = _sl.buf + _sl.bufsize;
 
@@ -203,7 +203,7 @@ int SlIterateArray()
 
{
 
	int ind;
 
	static uint32 next_offs;
 
	
 

	
 
	// Must be at end of current block.
 
	assert(next_offs == 0 || SlGetOffs() == next_offs);
 

	
 
@@ -224,7 +224,7 @@ int SlIterateArray()
 
			DEBUG(misc, 0) ("SlIterateArray: error\n");
 
			return -1; // error
 
		}
 
		
 

	
 
		if (len != 0)
 
			return ind;
 
	}
 
@@ -300,7 +300,7 @@ uint SlGetFieldLength()
 
static void SlSaveLoadConv(void *ptr, uint conv)
 
{
 
	int64 x = 0;
 
	
 

	
 
	if (_sl.save) {
 
		// Read a value from the struct. These ARE endian safe.
 
		switch((conv >> 4)&0xf) {
 
@@ -310,7 +310,7 @@ static void SlSaveLoadConv(void *ptr, ui
 
		case SLE_VAR_U16>>4: x = *(uint16*)ptr; break;
 
		case SLE_VAR_I32>>4: x = *(int32*)ptr; break;
 
		case SLE_VAR_U32>>4: x = *(uint32*)ptr; break;
 
		case SLE_VAR_I64>>4: x = *(int64*)ptr; break; 
 
		case SLE_VAR_I64>>4: x = *(int64*)ptr; break;
 
		case SLE_VAR_U64>>4: x = *(uint64*)ptr; break;
 
		case SLE_VAR_NULL>>4: x = 0; break;
 
		default:
 
@@ -333,7 +333,7 @@ static void SlSaveLoadConv(void *ptr, ui
 
			NOT_REACHED();
 
		}
 
	} else {
 
		
 

	
 
		// Read a value from the file
 
		switch(conv & 0xF) {
 
		case SLE_FILE_I8: x = (int8)SlReadByte();	break;
 
@@ -441,7 +441,7 @@ static size_t SlCalcObjLength(void *obje
 

	
 
			switch(cmd&3) {
 
			// Normal variable
 
			case 0: length += SlCalcConvLen(conv, NULL);break;			
 
			case 0: length += SlCalcConvLen(conv, NULL);break;
 
			// Reference
 
			case 1: length += 2; break;
 
			// Array
 
@@ -509,7 +509,7 @@ void SlObject(void *object, const void *
 
			case 2:	SlArray(ptr, *d++, conv); break;
 
			default:NOT_REACHED();
 
			}
 
	
 

	
 
		// Write byte.
 
		} else if (cmd == 8) {
 
			if (_sl.save) {
 
@@ -592,7 +592,7 @@ static void SlLoadChunk(const ChunkHandl
 

	
 
	_sl.block_mode = m;
 
	_sl.obj_len = 0;
 
	
 

	
 
	switch(m) {
 
	case CH_ARRAY:
 
		_sl.array_index = 0;
 
@@ -641,7 +641,7 @@ static void SlSaveChunk(const ChunkHandl
 
		_tmp_proc_1 = proc;
 
		proc = SlStubSaveProc;
 
	}
 
	
 

	
 
	_sl.block_mode = ch->flags & CH_TYPE_MASK;
 
	switch(ch->flags & CH_TYPE_MASK) {
 
	case CH_RIFF:
 
@@ -674,7 +674,7 @@ void SlSaveChunks()
 
		for(chsc=_sl.chs;(ch=*chsc++) != NULL;) {
 
			while(true) {
 
				if (((ch->flags >> CH_PRI_SHL) & (CH_NUM_PRI_LEVELS - 1)) == p)
 
					SlSaveChunk(ch);	
 
					SlSaveChunk(ch);
 
				if (ch->flags & CH_LAST)
 
					break;
 
				ch++;
 
@@ -741,7 +741,7 @@ static uint ReadLZO()
 

	
 
	// Check if size is bad
 
	((uint32*)out)[0] = size = tmp[1];
 
	
 

	
 
	if (_sl.version != 0) {
 
		tmp[0] = TO_BE32(tmp[0]);
 
		size = TO_BE32(size);
 
@@ -754,7 +754,7 @@ static uint ReadLZO()
 

	
 
	// Verify checksum
 
	if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlError("bad checksum");
 
	
 

	
 
	// Decompress
 
	lzo1x_decompress(out + sizeof(uint32)*1, size, _sl.buf, &len, NULL);
 
	return len;
 
@@ -767,7 +767,7 @@ static void WriteLZO(uint size)
 
	byte out[LZO_SIZE + LZO_SIZE / 64 + 16 + 3 + 8];
 
	byte wrkmem[sizeof(byte*)*4096];
 
	uint outlen;
 
	
 

	
 
	lzo1x_1_compress(_sl.buf, size, out + sizeof(uint32)*2, &outlen, wrkmem);
 
	((uint32*)out)[1] = TO_BE32(outlen);
 
	((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out + sizeof(uint32), outlen + sizeof(uint32)));
 
@@ -821,7 +821,7 @@ static bool InitReadZlib()
 
{
 
	memset(&_z, 0, sizeof(_z));
 
	if (inflateInit(&_z) != Z_OK) return false;
 
	
 

	
 
	_sl.bufsize = 4096;
 
	_sl.buf = (byte*)malloc(4096 + 4096); // also contains fread buffer
 
	return true;
 
@@ -845,7 +845,7 @@ static uint ReadZlib()
 
		if (r == Z_STREAM_END)
 
			break;
 

	
 
		if (r != Z_OK) 
 
		if (r != Z_OK)
 
			SlError("inflate() failed");
 
	} while (_z.avail_out);
 

	
 
@@ -1020,7 +1020,7 @@ int SaveOrLoad(const char *filename, int
 
	uint32 hdr[2];
 
	const SaveLoadFormat *fmt;
 
  uint version;
 
		
 

	
 
	// old style load
 
	if (mode == SL_OLD_LOAD) {
 
		InitializeGame();
 
@@ -1028,11 +1028,11 @@ int SaveOrLoad(const char *filename, int
 
		AfterLoadGame(0);
 
		return SL_OK;
 
	}
 
	
 

	
 
	_sl.fh = fopen(filename, mode?"wb":"rb");
 
	if (_sl.fh == NULL)
 
		return SL_ERROR;
 
	
 

	
 
	_sl.bufe = _sl.bufp = NULL;
 
	_sl.offs_base = 0;
 
	_sl.int_to_ref_proc = IntToReference;
 
@@ -1060,23 +1060,23 @@ int SaveOrLoad(const char *filename, int
 
		}
 
	}
 

	
 
  // we first initialize here to avoid: "warning: variable `version' might 
 
  // we first initialize here to avoid: "warning: variable `version' might
 
  // be clobbered by `longjmp' or `vfork'"
 
	version = 0;
 

	
 
	if (mode != SL_LOAD) {
 
		fmt = GetSavegameFormat(_savegame_format);
 
		
 

	
 
		_sl.write_bytes = fmt->writer;
 
		_sl.excpt_uninit = fmt->uninit_write;
 
		if (!fmt->init_write()) goto init_err;
 
		
 

	
 
		hdr[0] = fmt->tag;
 
		hdr[1] = TO_BE32((SAVEGAME_MAJOR_VERSION<<16) + (SAVEGAME_MINOR_VERSION << 8));
 
		if (fwrite(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError("file write failed");
 
		
 

	
 
		_sl.version = SAVEGAME_MAJOR_VERSION;
 
		
 

	
 
		BeforeSaveGame();
 
		SlSaveChunks();
 
		SlWriteFill(); // flush the save buffer
 
@@ -1104,7 +1104,7 @@ init_err:
 
			if (fmt->tag == hdr[0]) {
 
				// check version number
 
				version = TO_BE32(hdr[1]) >> 8;
 
				
 

	
 
				// incompatible version?
 
				if (version > SAVEGAME_LOADABLE_VERSION) goto read_err;
 
				_sl.version = (version>>8);
screenshot.c
Show inline comments
 
@@ -23,7 +23,7 @@ typedef struct {
 
#pragma pack(push, 1)
 
#endif
 

	
 
typedef struct BitmapFileHeader { 
 
typedef struct BitmapFileHeader {
 
	uint16 type;
 
	uint32 size;
 
	uint32 reserved;
 
@@ -113,12 +113,12 @@ static bool MakeBmpImage(const char *nam
 
		// determine # lines
 
		n = min(h, maxlines);
 
		h -= n;
 
		
 

	
 
		// render the pixels
 
		callb(userdata, buff, h, padw, n);
 
		
 
		// write each line 
 
		while (n) 
 

	
 
		// write each line
 
		while (n)
 
			fwrite(buff + (--n) * padw, 1, padw, f);
 
	} while (h);
 

	
 
@@ -182,10 +182,10 @@ static bool MakePNGImage(const char *nam
 
	}
 

	
 
	png_init_io(png_ptr, f);
 
	
 

	
 
	png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
 

	
 
	png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, 
 
	png_set_IHDR(png_ptr, info_ptr, w, h, pixelformat, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
 
		PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
 

	
 
	// convert the palette to the .PNG format.
 
@@ -215,7 +215,7 @@ static bool MakePNGImage(const char *nam
 
	do {
 
		// determine # lines to write
 
		n = min(h - y, maxlines);
 
		
 

	
 
		// render the pixels into the buffer
 
		callb(userdata, buff, y, w, n);
 
		y += n;
 
@@ -272,7 +272,7 @@ static bool MakePCXImage(const char *nam
 
	if (f == NULL) return false;
 

	
 
	memset(&pcx, 0, sizeof(pcx));
 
	
 

	
 
	// setup pcx header
 
	pcx.manufacturer = 10;
 
	pcx.version = 5;
 
@@ -287,7 +287,7 @@ static bool MakePCXImage(const char *nam
 
	pcx.cpal = TO_LE16(1);
 
	pcx.width = pcx.pitch = TO_LE16(w);
 
	pcx.height = TO_LE16(h);
 
	
 

	
 
	// write pcx header
 
	fwrite(&pcx, sizeof(pcx), 1, f);
 

	
 
@@ -302,7 +302,7 @@ static bool MakePCXImage(const char *nam
 
	do {
 
		// determine # lines to write
 
		uint n = min(h - y, maxlines), i;
 
		
 

	
 
		// render the pixels into the buffer
 
		callb(userdata, buff, y, w, n);
 
		y += n;
 
@@ -314,7 +314,7 @@ static bool MakePCXImage(const char *nam
 
			byte runchar = buff[0];
 
			uint left = w - 1;
 

	
 
			// for each pixel... 
 
			// for each pixel...
 
			while (left) {
 
				byte ch = *bufp++;
 
				if (ch != runchar || runcount >= 0x3f) {
 
@@ -334,7 +334,7 @@ static bool MakePCXImage(const char *nam
 
	} while (y != h);
 

	
 
	// write 8-bit color palette
 
	fputc(12, f); 
 
	fputc(12, f);
 
	fwrite(palette, 256*3, 1, f);
 
	fclose(f);
 

	
 
@@ -404,8 +404,8 @@ void LargeWorldCallback(void *userdata, 
 
	while (vp->width - left != 0) {
 
		wx = min(vp->width - left, 1600);
 
		left += wx;
 
		
 
		ViewportDoDraw(vp, 
 

	
 
		ViewportDoDraw(vp,
 
			((left - wx - vp->left) << vp->zoom) + vp->virtual_left,
 
			((y - vp->top) << vp->zoom) + vp->virtual_top,
 
			((left - vp->left) << vp->zoom) + vp->virtual_left,
 
@@ -437,7 +437,7 @@ static char *MakeScreenshotName(const ch
 

	
 
	serial = 0;
 
	for(;;) {
 
		snprintf(filename, sizeof(filename), "%s%s", _path.personal_dir, _screenshot_name);	
 
		snprintf(filename, sizeof(filename), "%s%s", _path.personal_dir, _screenshot_name);
 
		if (!FileExists(filename))
 
			break;
 
		sprintf(base, " #%d.%s", ++serial, ext);
 
@@ -451,7 +451,7 @@ extern byte _cur_palette[768];
 
bool MakeScreenshot()
 
{
 
	const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
 
	return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette); 
 
	return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette);
 
}
 

	
 
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom)
sdl.c
Show inline comments
 
@@ -23,7 +23,7 @@ static bool _all_modes;
 
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
 
static int _num_dirty_rects;
 

	
 
#define SDL_CALL    
 
#define SDL_CALL
 

	
 
#if defined(DYNAMICALLY_LOADED_SDL) && defined(WIN32)
 

	
 
@@ -60,7 +60,7 @@ typedef struct {
 
} SDLProcs;
 

	
 
#define M(x) x "\0"
 
static const char sdl_files[] = 
 
static const char sdl_files[] =
 
	M("sdl.dll")
 
	M("SDL_Init")
 
	M("SDL_InitSubSystem")
 
@@ -97,7 +97,7 @@ static SDLProcs _proc;
 

	
 
static char *LoadSdlDLL()
 
{
 
	if (_proc.SDL_Init != NULL) 
 
	if (_proc.SDL_Init != NULL)
 
		return NULL;
 
	if (!LoadLibraryList((void**)&_proc, sdl_files))
 
		return "Unable to load sdl.dll";
 
@@ -247,7 +247,7 @@ static void GetVideoModes(void) {
 
		for(i = 0; modes[i]; i++) {
 
			int w = modes[i]->w;
 
			int h = modes[i]->h;
 
			if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH+1) && 
 
			if (IS_INT_INSIDE(w, 640, MAX_SCREEN_WIDTH+1) &&
 
					IS_INT_INSIDE(h, 480, MAX_SCREEN_HEIGHT+1) &&
 
					w%8 == 0 && h%8 == 0) { // disable screen resolutions which are not multiples of 8
 
				int j;
 
@@ -363,7 +363,7 @@ static const VkMapping _vk_mapping[] = {
 
	AS(SDLK_KP_PLUS,			WKC_NUM_PLUS),
 
	AS(SDLK_KP_ENTER,			WKC_NUM_ENTER),
 
	AS(SDLK_KP_PERIOD,		WKC_NUM_DECIMAL),
 
	{0, 0, 0}	
 
	{0, 0, 0}
 
};
 

	
 
static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym)
 
@@ -376,7 +376,7 @@ static uint32 ConvertSdlKeyIntoMy(SDL_ke
 
		from = map->vk_from;
 
		if (from == 0) {
 
			key = 0;
 
			break;		
 
			break;
 
		}
 
		if ((uint)(key - from) <= map->vk_count) {
 
			key = key - from + map->map_to;
 
@@ -444,7 +444,7 @@ static int PollEvent() {
 
			_right_button_down = true;
 
			_right_button_clicked = true;
 
		}
 
#if !defined(WIN32)		
 
#if !defined(WIN32)
 
		 else if (ev.button.button == SDL_BUTTON_WHEELUP) {
 
			_cursor.wheel--;
 
		} else if (ev.button.button == SDL_BUTTON_WHEELDOWN) {
 
@@ -479,17 +479,17 @@ static int PollEvent() {
 
			_pressed_key = ConvertSdlKeyIntoMy(&ev.key.keysym);
 
		}
 
		break;
 
		
 

	
 
	case SDL_VIDEORESIZE: {
 
			int w, h;
 
			w = ev.resize.w;
 
			h = ev.resize.h;
 
			
 

	
 
			w = clamp(w & ~0x7, 64, MAX_SCREEN_WIDTH);
 
			h = clamp(h & ~0x7, 64, MAX_SCREEN_HEIGHT);
 
			
 

	
 
			ChangeResInGame(w, h);
 
			
 

	
 
			break;
 
		}
 
	}
 
@@ -529,14 +529,14 @@ static int SdlVideoMainLoop()
 

	
 
	while (true) {
 
		InteractiveRandom(); // randomness
 
		
 

	
 
		while ((i=PollEvent()) == -1) {}
 
		if (i>=0) return i;
 

	
 
		if (_exit_game)	return ML_QUIT;
 

	
 
		mod = SDL_CALL SDL_GetModState();
 
		keys = SDL_CALL SDL_GetKeyState(&numkeys);		
 
		keys = SDL_CALL SDL_GetKeyState(&numkeys);
 
#if defined(_DEBUG)
 
		if (_shift_pressed) {
 
#else
 
@@ -556,12 +556,12 @@ static int SdlVideoMainLoop()
 

	
 
			_ctrl_pressed = !!(mod & (KMOD_LCTRL | KMOD_RCTRL));
 
			_shift_pressed = !!(mod & (KMOD_LSHIFT | KMOD_RSHIFT));
 
			
 

	
 
			// determine which directional keys are down
 
			_dirkeys = 
 
			    (keys[SDLK_LEFT] ? 1 : 0) + 
 
			    (keys[SDLK_UP] ? 2 : 0) + 
 
			    (keys[SDLK_RIGHT] ? 4 : 0) + 
 
			_dirkeys =
 
			    (keys[SDLK_LEFT] ? 1 : 0) +
 
			    (keys[SDLK_UP] ? 2 : 0) +
 
			    (keys[SDLK_RIGHT] ? 4 : 0) +
 
			    (keys[SDLK_DOWN] ? 8 : 0);
 
			GameLoop();
 

	
 
@@ -607,7 +607,7 @@ static void CDECL fill_sound_buffer(void
 
static char *SdlSoundStart(char **parm)
 
{
 
	SDL_AudioSpec spec;
 
	
 

	
 
	{char *s;if ((s = SdlOpen(SDL_INIT_AUDIO)) != NULL) return s;}
 
	spec.freq = GetDriverParamInt(parm, "hz", 11025);
 
	spec.format = AUDIO_S16SYS;
settings.c
Show inline comments
 
@@ -50,7 +50,7 @@ static MemoryPool *pool_new(uint minsize
 
{
 
	MemoryPool *p;
 
	if (minsize < 4096 - 12) minsize = 4096 - 12;
 
	
 

	
 
	p = malloc(sizeof(MemoryPool) - 1 + minsize);
 
	p->pos = 0;
 
	p->size = minsize;
 
@@ -78,7 +78,7 @@ static void *pool_alloc(MemoryPool **poo
 
		MemoryPool *n = pool_new(size);
 
		*pool = n;
 
		n->next = p;
 
		p = n;		
 
		p = n;
 
	}
 

	
 
	pos = p->pos;
 
@@ -188,7 +188,7 @@ static IniFile *ini_load(const char *fil
 

	
 
	// for each line in the file
 
	while (fgets(buffer, sizeof(buffer), in)) {
 
		
 

	
 
		// trim whitespace from the left side
 
		for(s=buffer; *s == ' ' || *s == '\t'; s++);
 

	
 
@@ -230,7 +230,7 @@ static IniFile *ini_load(const char *fil
 
		} else if (group) {
 
			// find end of keyname
 
			for(t=s; *t != 0 && *t != '=' && *t != '\t' && *t != ' '; t++) {}
 
						
 

	
 
			// it's an item in an existing group
 
			item = ini_item_alloc(group, s, t-s);
 
			if (comment_size) {
 
@@ -285,7 +285,7 @@ static IniItem *ini_getitem(IniGroup *gr
 
	for(item = group->item; item; item = item->next)
 
		if (!strcmp(item->name, name))
 
			return item;
 
	
 

	
 
	if (!create) return NULL;
 

	
 
	// otherwise make a new one
 
@@ -299,7 +299,7 @@ static bool ini_save(const char *filenam
 
	FILE *f;
 
	IniGroup *group;
 
	IniItem *item;
 
	
 

	
 
	f = fopen(filename, "w");
 
	if (f == NULL) return false;
 

	
 
@@ -328,7 +328,7 @@ struct SettingDesc {
 
	void *def;
 
	void *ptr;
 
	void *b;
 
	
 

	
 
};
 

	
 
static int lookup_oneofmany(const char *many, const char *one, int onelen)
 
@@ -341,7 +341,7 @@ static int lookup_oneofmany(const char *
 
	// check if it's an integer
 
	if (*one >= '0' && *one <= '9')
 
		return strtoul(one, NULL, 0);
 
		
 

	
 
	idx = 0;
 
	for(;;) {
 
		// find end of item
 
@@ -400,7 +400,7 @@ static bool load_intlist(const char *str
 
{
 
	int items[64];
 
	int i,nitems;
 
	
 

	
 
	if (str == NULL) {
 
		memset(items, 0, sizeof(items));
 
		nitems = nelems;
 
@@ -522,7 +522,7 @@ static void *string_to_val(const Setting
 
			return (void*)false;
 
		ShowInfoF("ini: invalid setting value '%s' for '%s'", str, desc->name);
 
		break;
 
	
 

	
 
	case SDT_STRING:
 
	case SDT_STRINGBUF:
 
	case SDT_INTLIST:
 
@@ -549,14 +549,14 @@ static void load_setting_desc(IniFile *i
 
			s = desc->name;
 
			group = group_def;
 
		}
 
		
 

	
 
		item = ini_getitem(group, s, false);
 
		if (!item) {
 
			p = desc->def;
 
		} else {
 
			p = string_to_val(desc, item->value);
 
		}
 
		
 

	
 
		// get ptr to array
 
		ptr = desc->ptr;
 
		if ( (uint32)ptr < 0x10000)
 
@@ -600,7 +600,7 @@ static void load_setting_desc(IniFile *i
 
		default:
 
			NOT_REACHED();
 
		}
 
	}	
 
	}
 
}
 

	
 
static void save_setting_desc(IniFile *ini, const SettingDesc *desc, void *grpname, void *base)
 
@@ -615,7 +615,7 @@ static void save_setting_desc(IniFile *i
 
	for (;desc->name;desc++) {
 
		if (desc->flags & SDT_NOSAVE)
 
			continue;
 
		
 

	
 
		// group override?
 
		s = strchr(desc->name, '.');
 
		if (s) {
 
@@ -627,16 +627,16 @@ static void save_setting_desc(IniFile *i
 
			s = desc->name;
 
			group = group_def;
 
		}
 
		
 

	
 
		item = ini_getitem(group, s, true);
 

	
 
		// get ptr to array
 
		ptr = desc->ptr;
 
		if ( (uint32)ptr < 0x10000)
 
			ptr = (byte*)base + (uint32)ptr;
 
		
 

	
 
		if (item->value != NULL) {
 
			// check if the value is the same as the old value	
 
			// check if the value is the same as the old value
 
			p = string_to_val(desc, item->value);
 

	
 
			switch(desc->flags & 0xF) {
 
@@ -658,7 +658,7 @@ static void save_setting_desc(IniFile *i
 
				case SDT_INT32 >> 4:
 
				case SDT_UINT32 >> 4:
 
					if (*(uint32*)ptr == (uint32)p)
 
						continue;	
 
						continue;
 
					break;
 
				default:
 
					NOT_REACHED();
 
@@ -717,7 +717,7 @@ static void save_setting_desc(IniFile *i
 
		}
 
		// the value is different, that means we have to write it to the ini
 
		item->value = pool_strdup(&ini->pool, buf, strlen(buf));
 
	}	
 
	}
 
}
 

	
 
//***************************
 
@@ -826,7 +826,7 @@ static const SettingDesc patch_settings[
 
	{"nonuniform_stations",	SDT_BOOL,		(void*)false, (void*)offsetof(Patches, nonuniform_stations),	NULL},
 
	{"always_small_airport",SDT_BOOL,		(void*)false, (void*)offsetof(Patches, always_small_airport),	NULL},
 
	{"realistic_acceleration",SDT_BOOL, (void*)false, (void*)offsetof(Patches, realistic_acceleration),	NULL},
 
	
 

	
 
	{"toolbar_pos",					SDT_UINT8,	(void*)0,			(void*)offsetof(Patches, toolbar_pos),					NULL},
 

	
 
	{"max_trains",					SDT_UINT8,	(void*)80,		(void*)offsetof(Patches, max_trains),						NULL},
 
@@ -848,7 +848,7 @@ static const SettingDesc patch_settings[
 
	{"pf_maxlength",				SDT_UINT16, (void*)512,		(void*)offsetof(Patches, pf_maxlength),					NULL},
 
	{"pf_maxdepth",					SDT_UINT8,	(void*)16,		(void*)offsetof(Patches, pf_maxdepth),					NULL},
 

	
 
	
 

	
 
	{"ai_disable_veh_train",SDT_BOOL,		(void*)false, (void*)offsetof(Patches, ai_disable_veh_train),	NULL},
 
	{"ai_disable_veh_roadveh",SDT_BOOL,	(void*)false, (void*)offsetof(Patches, ai_disable_veh_roadveh),	NULL},
 
	{"ai_disable_veh_aircraft",SDT_BOOL,(void*)false, (void*)offsetof(Patches, ai_disable_veh_aircraft),NULL},
 
@@ -875,7 +875,7 @@ static const SettingDesc patch_settings[
 

	
 
	{"wait_oneway_signal",	SDT_UINT8,	(void*)15,		(void*)offsetof(Patches, wait_oneway_signal),		NULL},
 
	{"wait_twoway_signal",	SDT_UINT8,	(void*)41,		(void*)offsetof(Patches, wait_twoway_signal),		NULL},
 
	
 

	
 
	{"ainew_active",				SDT_BOOL,		(void*)false, (void*)offsetof(Patches, ainew_active),					NULL},
 

	
 
	{"drag_signals_density",SDT_UINT8,	(void*)4,			(void*)offsetof(Patches, drag_signals_density), NULL},
settings_gui.c
Show inline comments
 
@@ -117,11 +117,11 @@ static void GameOptionsWndProc(Window *w
 
			// setup screenshot format dropdown
 
			ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, e->click.widget, 0);
 
			return;
 
			
 

	
 
		}
 
		break;
 

	
 
	case WE_DROPDOWN_SELECT: 
 
	case WE_DROPDOWN_SELECT:
 
		switch(e->dropdown.button) {
 
		case 20:
 
			if (e->dropdown.index == 0) {
 
@@ -220,7 +220,7 @@ static const Widget _game_options_widget
 
{   WWT_CLOSEBOX,    14,   130,   349,   202,   213, STR_02C0_SAVE_CUSTOM_NAMES_TO_DISK,	STR_02C2_SAVE_CUSTOMIZED_VEHICLE},
 

	
 
{      WWT_FRAME,    14,   190,   359,   104,   139, STR_OPTIONS_LANG,				STR_NULL},
 
{          WWT_6,    14,   200,   349,   118,   129, STR_OPTIONS_LANG_CBO,		STR_OPTIONS_LANG_TIP}, 
 
{          WWT_6,    14,   200,   349,   118,   129, STR_OPTIONS_LANG_CBO,		STR_OPTIONS_LANG_TIP},
 
{   WWT_CLOSEBOX,    14,   338,   348,   119,   128, STR_0225,								STR_OPTIONS_LANG_TIP},
 
{      WWT_FRAME,    14,    10,   179,   146,   181, STR_OPTIONS_RES,					STR_NULL},
 
{          WWT_6,    14,    20,   169,   160,   171, STR_OPTIONS_RES_CBO,			STR_OPTIONS_RES_TIP},
 
@@ -354,7 +354,7 @@ static void GameDifficultyWndProc(Window
 
			uint btn, dis;
 
			int val;
 
			const GameSettingData *info;
 
			
 

	
 
			x = e->click.pt.x - 5;
 
			if (!IS_INT_INSIDE(x, 0, 21))
 
				return;
 
@@ -470,7 +470,7 @@ void ShowGameDifficulty()
 
	 */
 
	memcpy(&_opt_mod_temp, _opt_mod_ptr, sizeof(GameOptions));
 
	AllocateWindowDesc(&_game_difficulty_desc);
 
}	
 
}
 

	
 
void ShowHighscoreTable(int tbl)
 
{
 
@@ -490,7 +490,7 @@ int32 AiNew_PatchActive_Warning(int32 p1
 
{
 
  if (p1 == 1)
 
    ShowErrorMessage(-1, TEMP_AI_ACTIVATED, 0, 0);
 
    
 

	
 
  return 0;
 
}
 

	
 
@@ -511,14 +511,14 @@ int32 CheckInterval(int32 p1)
 
{
 
	bool warning;
 
	if (p1) {
 
		warning = ( (IS_INT_INSIDE(_patches.servint_trains,   5, 90+1) || _patches.servint_trains   == 0) && 
 
		warning = ( (IS_INT_INSIDE(_patches.servint_trains,   5, 90+1) || _patches.servint_trains   == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_roadveh,  5, 90+1) || _patches.servint_roadveh  == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_aircraft, 5, 90+1) || _patches.servint_aircraft == 0) && 
 
								(IS_INT_INSIDE(_patches.servint_aircraft, 5, 90+1) || _patches.servint_aircraft == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_ships,    5, 90+1) || _patches.servint_ships    == 0) );
 
	} else {
 
		warning = ( (IS_INT_INSIDE(_patches.servint_trains,   30, 800+1) || _patches.servint_trains   == 0) && 
 
		warning = ( (IS_INT_INSIDE(_patches.servint_trains,   30, 800+1) || _patches.servint_trains   == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_roadveh,  30, 800+1) || _patches.servint_roadveh  == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_aircraft, 30, 800+1) || _patches.servint_aircraft == 0) && 
 
								(IS_INT_INSIDE(_patches.servint_aircraft, 30, 800+1) || _patches.servint_aircraft == 0) &&
 
								(IS_INT_INSIDE(_patches.servint_ships,    30, 800+1) || _patches.servint_ships    == 0) );
 
	}
 

	
 
@@ -560,7 +560,7 @@ static const PatchEntry _patches_ui[] = 
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_AUTOSCROLL,				&_patches.autoscroll,								0,  0,  0, NULL},
 

	
 
	{PE_UINT8,	0, STR_CONFIG_PATCHES_ERRMSG_DURATION,	&_patches.errmsg_duration,					0, 20,  1, NULL},
 
	
 

	
 
	{PE_UINT8,	PF_MULTISTRING, STR_CONFIG_PATCHES_TOOLBAR_POS, &_patches.toolbar_pos,			0,  2,  1, &v_PositionMainToolbar},
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_INVISIBLE_TREES,	&_patches.invisible_trees,					0,  1,  1, &InvisibleTreesActive},
 
};
 
@@ -570,7 +570,7 @@ static const PatchEntry _patches_constru
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_EXTRADYNAMITE,		&_patches.extra_dynamite,						0,  0,  0, NULL},
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_LONGBRIDGES,			&_patches.longbridges,							0,  0,  0, NULL},
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_SIGNALSIDE,				&_patches.signal_side,							0,  0,  0, NULL},
 
	
 

	
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_SMALL_AIRPORTS,		&_patches.always_small_airport,			0,  0,  0, NULL},
 
	{PE_UINT8,	0, STR_CONFIG_PATCHES_DRAG_SIGNALS_DENSITY, &_patches.drag_signals_density, 1, 20,  1, NULL},
 

	
 
@@ -622,7 +622,7 @@ static const PatchEntry _patches_economy
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_SAMEINDCLOSE,			&_patches.same_industry_close,			0,  0,  0, NULL},
 
	{PE_BOOL,		0, STR_CONFIG_PATCHES_BRIBE,						&_patches.bribe,										0,  0,  0, NULL},
 
	{PE_UINT8,	0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT,	&_patches.snow_line_height,					2, 13,  1, NULL},
 
	
 

	
 
	{PE_INT32,	PF_NOCOMMA, STR_CONFIG_PATCHES_COLORED_NEWS_DATE, &_patches.colored_news_date, 1900, 2200, 5, NULL},
 
	{PE_INT32,	PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, &_patches.starting_date,	 1920,2100, 1, NULL},
 

	
 
@@ -666,7 +666,7 @@ static int32 ReadPE(const PatchEntry*pe)
 
	default:
 
		NOT_REACHED();
 
	}
 
  
 

	
 
	/* useless, but avoids compiler warning this way */
 
	return 0;
 
}
 
@@ -682,36 +682,36 @@ static void WritePE(const PatchEntry *pe
 
	switch(pe->type) {
 
	case PE_BOOL: *(bool*)pe->variable = (bool)val; break;
 

	
 
	case PE_UINT8: if ((uint8)val > (uint8)pe->max) 
 
	case PE_UINT8: if ((uint8)val > (uint8)pe->max)
 
									*(uint8*)pe->variable = (uint8)pe->max;
 
								else if ((uint8)val < (uint8)pe->min)
 
									*(uint8*)pe->variable = (uint8)pe->min;
 
								else
 
									*(uint8*)pe->variable = (uint8)val; 
 
									*(uint8*)pe->variable = (uint8)val;
 
								break;
 

	
 
	case PE_INT16: if ((int16)val > (int16)pe->max) 
 
	case PE_INT16: if ((int16)val > (int16)pe->max)
 
									*(int16*)pe->variable = (int16)pe->max;
 
								else if ((int16)val < (int16)pe->min)
 
									*(int16*)pe->variable = (int16)pe->min;
 
								else
 
									*(int16*)pe->variable = (int16)val; 
 
									*(int16*)pe->variable = (int16)val;
 
								break;
 

	
 
	case PE_UINT16: if ((uint16)val > (uint16)pe->max) 
 
	case PE_UINT16: if ((uint16)val > (uint16)pe->max)
 
									*(uint16*)pe->variable = (uint16)pe->max;
 
								else if ((uint16)val < (uint16)pe->min)
 
									*(uint16*)pe->variable = (uint16)pe->min;
 
								else
 
									*(uint16*)pe->variable = (uint16)val; 
 
									*(uint16*)pe->variable = (uint16)val;
 
								break;
 

	
 
	case PE_INT32: if ((int32)val > (int32)pe->max) 
 
	case PE_INT32: if ((int32)val > (int32)pe->max)
 
									*(int32*)pe->variable = (int32)pe->max;
 
								else if ((int32)val < (int32)pe->min)
 
									*(int32*)pe->variable = (int32)pe->min;
 
								else
 
									*(int32*)pe->variable = val; 
 
									*(int32*)pe->variable = val;
 
								break;
 

	
 
	case PE_CURRENCY: val /= GetCurrentCurrencyRate();
 
@@ -791,7 +791,7 @@ static void PatchesSelectionWndProc(Wind
 

	
 
			y = e->click.pt.y - 46 - 1;
 
			if (y < 0) return;
 
			
 

	
 
			btn = y / 11;
 
			if (y % 11 > 9) return;
 

	
 
@@ -836,13 +836,13 @@ static void PatchesSelectionWndProc(Wind
 
							if (val < pe->min) val = pe->min;
 
						}
 
					}
 
					
 

	
 
					if (val != oval) {
 
						WP(w,def_d).data_2 = btn * 2 + 1 + ((x>=10) ? 1 : 0);
 
						w->flags4 |= 5 << WF_TIMEOUT_SHL;
 
						_left_button_clicked = false;
 
					}
 
					break;				
 
					break;
 
				}
 
				if (val != oval) {
 
					WritePE(pe, val);
 
@@ -858,7 +858,7 @@ static void PatchesSelectionWndProc(Wind
 
					ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, WC_GAME_OPTIONS, 0);
 
				}
 
			}
 
			
 

	
 
			break;
 
		}
 
		case 4: case 5: case 6: case 7: case 8: case 9:
 
@@ -878,7 +878,7 @@ static void PatchesSelectionWndProc(Wind
 
		if (*e->edittext.str) {
 
			const PatchPage *page = &_patches_page[WP(w,def_d).data_1];
 
			const PatchEntry *pe = &page->entries[WP(w,def_d).data_3];
 
			WritePE(pe, atoi(e->edittext.str)); 
 
			WritePE(pe, atoi(e->edittext.str));
 
			SetWindowDirty(w);
 

	
 
			if (pe->click_proc != NULL) // call callback function
ship_cmd.c
Show inline comments
 
@@ -93,7 +93,7 @@ static void CheckIfShipNeedsService(Vehi
 

	
 
	if (v->vehstatus & VS_STOPPED)
 
		return;
 
	
 

	
 
	if ((v->next_order & (OT_MASK | OF_FULL_LOAD)) == (OT_GOTO_DEPOT | OF_FULL_LOAD))
 
		return;
 

	
 
@@ -113,7 +113,7 @@ static void CheckIfShipNeedsService(Vehi
 
	v->next_order = OT_GOTO_DEPOT | OF_NON_STOP;
 
	v->next_order_param = (byte)i;
 
	v->dest_tile = (&_depots[i])->xy;
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);		
 
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
}
 

	
 
void OnNewDay_Ship(Vehicle *v)
 
@@ -128,11 +128,11 @@ void OnNewDay_Ship(Vehicle *v)
 
	CheckIfShipNeedsService(v);
 

	
 
	CheckOrders(v);
 
	
 

	
 
	if (v->vehstatus & VS_STOPPED)
 
		return;
 

	
 
	
 

	
 

	
 
	cost = ship_vehicle_info(v->engine_type).running_cost * _price.ship_running / 364;
 
	v->profit_this_year -= cost >> 8;
 
@@ -152,10 +152,10 @@ static void HandleBrokenShip(Vehicle *v)
 

	
 
		if (v->breakdowns_since_last_service != 255)
 
			v->breakdowns_since_last_service++;
 
		
 

	
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		
 

	
 
		SndPlayVehicleFx((_opt.landscape != LT_CANDY) ? 0xE : 0x3A, v);
 

	
 
		if (!(v->vehstatus & VS_HIDDEN)) {
 
@@ -231,7 +231,7 @@ static void ProcessShipOrder(Vehicle *v)
 
	if ((order & OT_MASK) == OT_GOTO_STATION) {
 
		if ( (byte)(order >> 8) == v->last_station_visited)
 
			v->last_station_visited = 0xFF;
 
		
 

	
 
		st = DEREF_STATION(order >> 8);
 
		if (st->dock_tile != 0) {
 
			v->dest_tile = TILE_ADD(st->dock_tile, _dock_offs[_map5[st->dock_tile]-0x4B]);
 
@@ -248,7 +248,7 @@ static void HandleShipLoading(Vehicle *v
 
{
 
	if (v->next_order == OT_NOTHING)
 
		return;
 
	
 

	
 
	if (v->next_order != OT_DUMMY) {
 
		if ((v->next_order&OT_MASK) != OT_LOADING)
 
			return;
 
@@ -265,7 +265,7 @@ static void HandleShipLoading(Vehicle *v
 
			return;
 
		}
 
		PlayShipSound(v);
 
		
 

	
 
		{
 
			byte b = v->next_order;
 
			v->next_order = OT_LEAVESTATION;
 
@@ -352,7 +352,7 @@ static bool ShipAccelerate(Vehicle *v)
 

	
 
	//updates statusbar only if speed have changed to save CPU time
 
	if (spd != v->cur_speed) {
 
		v->cur_speed = spd;	
 
		v->cur_speed = spd;
 
		if (_patches.vehicle_speed)
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
	}
 
@@ -384,7 +384,7 @@ static void ShipEnterDepot(Vehicle *v)
 
	v->vehstatus |= VS_HIDDEN;
 
	v->cur_speed = 0;
 
	RecalcShipStuff(v);
 
	
 

	
 
	v->date_of_last_service = _date;
 
	v->breakdowns_since_last_service = 0;
 
	v->reliability = _engines[v->engine_type].reliability;
 
@@ -394,7 +394,7 @@ static void ShipEnterDepot(Vehicle *v)
 

	
 
	if ((v->next_order&OT_MASK) == OT_GOTO_DEPOT) {
 
		InvalidateWindow(WC_VEHICLE_VIEW, v->index);
 
	
 

	
 
		t = v->next_order;
 
		v->next_order = OT_DUMMY;
 

	
 
@@ -444,7 +444,7 @@ static bool ShipTrackFollower(uint tile,
 
	// Found dest?
 
	if (tile == pfs->dest_coords) {
 
		pfs->best_bird_dist = 0;
 
		
 

	
 
//		if (length < pfs->best_length)
 
//			dbg_store_path();
 

	
 
@@ -456,7 +456,7 @@ static bool ShipTrackFollower(uint tile,
 
	if (tile != pfs->skiptile) {
 
		pfs->best_bird_dist = minu(pfs->best_bird_dist, GetTileDist1Db(pfs->dest_coords, tile));
 
	}
 
	
 

	
 
	return false;
 
}
 

	
 
@@ -488,12 +488,12 @@ static uint FindShipTrack(Vehicle *v, ui
 
	do {
 
		i = FIND_FIRST_BIT(bits);
 
		bits = KILL_FIRST_BIT(bits);
 
		
 

	
 
		pfs.best_bird_dist = (uint)-1;
 
		pfs.best_length = (uint)-1;
 

	
 
		FollowTrack(tile, 0x3800 | TRANSPORT_WATER, _ship_search_directions[i][dir], (TPFEnumProc*)ShipTrackFollower, NULL, &pfs);
 
		
 

	
 
		if (best_track >= 0) {
 
			if (pfs.best_bird_dist != 0) {
 
				/* neither reached the destination, pick the one with the smallest bird dist */
 
@@ -503,8 +503,8 @@ static uint FindShipTrack(Vehicle *v, ui
 
				if (pfs.best_length > best_length) goto bad;
 
				if (pfs.best_length < best_length) goto good;
 
			}
 
			
 
			/* if we reach this position, there's two paths of equal value so far. 
 

	
 
			/* if we reach this position, there's two paths of equal value so far.
 
			 * pick one randomly. */
 
			r = (byte)Random();
 
			if (_pick_shiptrack_table[i] == ship_dir) r += 80;
 
@@ -554,7 +554,7 @@ static const byte _new_vehicle_direction
 

	
 
static int ShipGetNewDirectionFromTiles(uint new_tile, uint old_tile)
 
{
 
	uint offs = (GET_TILE_Y(new_tile) - GET_TILE_Y(old_tile) + 1) * 4 + 
 
	uint offs = (GET_TILE_Y(new_tile) - GET_TILE_Y(old_tile) + 1) * 4 +
 
							GET_TILE_X(new_tile) - GET_TILE_X(old_tile) + 1;
 
	assert(offs < 11 && offs != 3 && offs != 7);
 
	return _new_vehicle_direction_table[offs];
 
@@ -707,7 +707,7 @@ static void ShipController(Vehicle *v)
 
			goto reverse_direction;
 

	
 
		b = _ship_subcoord[dir][track];
 
	
 

	
 
		gp.x = (gp.x&~0xF) | b[0];
 
		gp.y = (gp.y&~0xF) | b[1];
 

	
 
@@ -794,7 +794,7 @@ int32 CmdBuildShip(int x, int y, uint32 
 
	uint unit_num;
 
	uint tile = TILE_FROM_XY(x,y);
 
	Engine *e;
 
	
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 

	
 
	value = EstimateShipCost(p1);
 
@@ -802,10 +802,10 @@ int32 CmdBuildShip(int x, int y, uint32 
 
		return value;
 

	
 
	v = AllocateVehicle();
 
	if (v == NULL || _ptr_to_next_order >= endof(_order_array) || 
 
	if (v == NULL || _ptr_to_next_order >= endof(_order_array) ||
 
			(unit_num = GetFreeUnitNumber(VEH_Ship)) > _patches.max_ships)
 
		return_cmd_error(STR_00E1_TOO_MANY_VEHICLES_IN_GAME);
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		v->unitnumber = unit_num;
 

	
 
@@ -823,12 +823,12 @@ int32 CmdBuildShip(int x, int y, uint32 
 
		v->x_offs = -3;
 
		v->y_offs = -3;
 
		v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
 
		
 

	
 
		v->spritenum = ship_vehicle_info(p1).image_index;
 
		v->cargo_type = ship_vehicle_info(p1).cargo_type;
 
		v->cargo_cap = ship_vehicle_info(p1).capacity;
 
		v->value = value;
 
		
 

	
 
		v->last_station_visited = 255;
 
		v->max_speed = ship_vehicle_info(p1).max_speed;
 
		v->engine_type = (byte)p1;
 
@@ -856,7 +856,7 @@ int32 CmdBuildShip(int x, int y, uint32 
 
		InvalidateWindow(WC_SHIPS_LIST, v->owner);
 
		InvalidateWindow(WC_COMPANY, v->owner);
 
	}
 
	
 

	
 
	return value;
 
}
 

	
 
@@ -865,7 +865,7 @@ int32 CmdSellShip(int x, int y, uint32 f
 
	Vehicle *v;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 
	
 

	
 
	v = &_vehicles[p1];
 

	
 
	if (!CheckOwnership(v->owner))
 
@@ -873,7 +873,7 @@ int32 CmdSellShip(int x, int y, uint32 f
 

	
 
	if (!IsShipDepotTile(v->tile) || v->u.road.state != 0x80 || !(v->vehstatus&VS_STOPPED))
 
		return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		_vehicle_sort_dirty[VEHSHIP] = true; // sell a ship
 
@@ -882,7 +882,7 @@ int32 CmdSellShip(int x, int y, uint32 f
 
		DeleteWindowById(WC_VEHICLE_VIEW, v->index);
 
		DeleteVehicle(v);
 
	}
 
	
 

	
 
	return -(int32)v->value;
 
}
 

	
 
@@ -919,7 +919,7 @@ int32 CmdSendShipToDepot(int x, int y, u
 
		if (flags & DC_EXEC) {
 
			if (v->next_order&OF_UNLOAD) {v->cur_order_index++;}
 
			v->next_order = OT_DUMMY;
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);			
 
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
 
		}
 
	} else {
 
		depot = FindClosestShipDepot(v);
 
@@ -963,7 +963,7 @@ int32 CmdRefitShip(int x, int y, uint32 
 
	int32 cost;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN);
 
	
 

	
 
	v = &_vehicles[p1];
 
	if (!CheckOwnership(v->owner))
 
		return CMD_ERROR;
ship_gui.c
Show inline comments
 
@@ -26,7 +26,7 @@ static void ShipRefitWndProc(Window *w, 
 
{
 
	switch(e->event) {
 
	case WE_PAINT: {
 
		Vehicle *v = &_vehicles[w->window_number];	
 
		Vehicle *v = &_vehicles[w->window_number];
 
		const byte *b;
 
		int sel;
 
		int x,y;
 
@@ -38,7 +38,7 @@ static void ShipRefitWndProc(Window *w, 
 
		DrawWindowWidgets(w);
 

	
 
		DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
 
		
 

	
 
		cargo = -1;
 
		x = 6;
 
		y = 25;
 
@@ -103,7 +103,7 @@ static void ShipRefitWndProc(Window *w, 
 
			} break;
 
		case 4: /* refit button */
 
			if (WP(w,refit_d).cargo != 0xFF) {
 
				Vehicle *v = &_vehicles[w->window_number];	
 
				Vehicle *v = &_vehicles[w->window_number];
 
				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_SHIP | CMD_MSG(STR_9841_CAN_T_REFIT_SHIP)))
 
					DeleteWindow(w);
 
			}
 
@@ -136,8 +136,8 @@ static void ShowShipRefitWindow(Vehicle 
 
	Window *w;
 

	
 
	DeleteWindowById(WC_VEHICLE_REFIT, v->index);
 
	
 
	_alloc_wnd_parent_num = v->index;	
 

	
 
	_alloc_wnd_parent_num = v->index;
 
	w = AllocateWindowDesc(&_ship_refit_desc);
 
	w->window_number = v->index;
 
	w->caption_color = v->owner;
 
@@ -166,7 +166,7 @@ static void ShipDetailsWndProc(Window *w
 
			StringID str;
 

	
 
			SET_DPARAM16(1, year);
 
			
 

	
 
			str = STR_0199_YEAR;
 
			if (year != 1) {
 
				str++;
 
@@ -212,7 +212,7 @@ static void ShipDetailsWndProc(Window *w
 
		SET_DPARAM16(0, GetCustomEngineName(v->engine_type));
 
		SET_DPARAM32(2, v->value);
 
		DrawString(74, 57, STR_9816_BUILT_VALUE, 0);
 
		
 

	
 
		SET_DPARAM16(0, _cargoc.names_long_p[v->cargo_type]);
 
		SET_DPARAM16(1, v->cargo_cap);
 
		DrawString(74, 67, STR_9817_CAPACITY, 0);
 
@@ -295,7 +295,7 @@ static void ShowShipDetailsWindow(Vehicl
 
	VehicleID veh = v->index;
 
	DeleteWindowById(WC_VEHICLE_ORDERS, veh);
 
	DeleteWindowById(WC_VEHICLE_DETAILS, veh);
 
	_alloc_wnd_parent_num = veh;	
 
	_alloc_wnd_parent_num = veh;
 
	w = AllocateWindowDesc(&_ship_details_desc);
 
	w->window_number = veh;
 
	w->caption_color = v->owner;
 
@@ -314,7 +314,7 @@ static void CcBuildShip(bool success, ui
 
	ShowShipViewWindow(v);
 
}
 

	
 
static void NewShipWndProc(Window *w, WindowEvent *e) 
 
static void NewShipWndProc(Window *w, WindowEvent *e)
 
{
 
	YearMonthDay ymd;
 
	switch(e->event) {
 
@@ -354,7 +354,7 @@ static void NewShipWndProc(Window *w, Wi
 
						DrawShipEngine(x+35, y+10, engine_id, SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
 
						y += 24;
 
					}
 
					sel--; 
 
					sel--;
 
				}
 
			} while (++engine_id, ++e,--num);
 

	
 
@@ -370,12 +370,12 @@ static void NewShipWndProc(Window *w, Wi
 
				SET_DPARAM16(4, ship_vehicle_info(selected_id).refittable ? STR_9842_REFITTABLE : STR_EMPTY);
 
				SET_DPARAM32(5, ship_vehicle_info(selected_id).running_cost * _price.ship_running >> 8);
 

	
 
				e = &_engines[selected_id];	
 
				e = &_engines[selected_id];
 
				SET_DPARAM16(7, e->lifelength);
 
				SET_DPARAM8(8, e->reliability * 100 >> 16);
 
				ConvertDayToYMD(&ymd, e->intro_date);
 
				SET_DPARAM16(6, ymd.year + 1920);
 
				
 

	
 
				DrawString(2, 111, STR_980A_COST_SPEED_CAPACITY_RUNNING, 0);
 
			}
 
		}
 
@@ -456,13 +456,13 @@ static void ShowBuildShipWindow(TileInde
 
	w = AllocateWindowDesc(&_new_ship_desc);
 
	w->window_number = tile;
 
	w->vscroll.cap = 4;
 
	
 

	
 
	if (tile != 0) {
 
		w->caption_color = _map_owner[tile];
 
	} else {
 
		w->caption_color = _local_player;
 
	}
 
	
 

	
 
}
 

	
 

	
 
@@ -479,7 +479,7 @@ static void ShipViewWndProc(Window *w, W
 
				v->u.ship.state == 0x80 &&
 
				IsShipDepotTile(v->tile))
 
			disabled = 0;
 
					
 

	
 
		if (v->owner != _local_player)
 
			disabled |= 1<<7 | 1<<6;
 
		w->disabled_state = disabled;
 
@@ -535,13 +535,13 @@ static void ShipViewWndProc(Window *w, W
 

	
 
		switch(e->click.widget) {
 
		case 4: /* start stop */
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP)); 
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_SHIP | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP));
 
			break;
 
		case 5: /* center main view */
 
			ScrollMainWindowTo(v->x_pos, v->y_pos);
 
			break;
 
		case 6: /* goto hangar */
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT)); 
 
			DoCommandP(v->tile, v->index, 0, NULL, CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_9819_CAN_T_SEND_SHIP_TO_DEPOT));
 
			break;
 
		case 7: /* refit */
 
			ShowShipRefitWindow(v);
 
@@ -557,7 +557,7 @@ static void ShipViewWndProc(Window *w, W
 

	
 
	case WE_DESTROY:
 
		DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
 
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);		
 
		DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
 
		DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
 
		break;
 
	}
 
@@ -641,17 +641,17 @@ static void DrawShipDepotWindow(Window *
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Ship &&
 
				v->u.ship.state == 0x80 && 
 
				v->u.ship.state == 0x80 &&
 
				v->tile == (TileIndex)tile &&
 
				--num < 0 && num >=	-6) {
 

	
 
			DrawShipImage(v, x+19, y, WP(w,traindepot_d).sel);
 
			
 

	
 
			SET_DPARAM16(0, v->unitnumber);
 
			DrawString(x, y, (uint16)(v->max_age-366) >= v->age ? STR_00E2 : STR_00E3, 0);
 

	
 
			DrawSprite( (v->vehstatus & VS_STOPPED) ? 0xC12 : 0xC13, x, y + 9);
 
			
 

	
 
			if ((x+=90) == 2+90*3) {
 
				x = 2;
 
				y += 24;
 
@@ -666,7 +666,7 @@ static int GetVehicleFromShipDepotWndPt(
 
	TileIndex tile;
 
	Vehicle *v;
 
	int pos;
 
		
 

	
 
	xt = x / 90;
 
	xm = x % 90;
 
	if (xt >= 5)
 
@@ -682,7 +682,7 @@ static int GetVehicleFromShipDepotWndPt(
 
	tile = w->window_number;
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type == VEH_Ship &&
 
				v->vehstatus&VS_HIDDEN && 
 
				v->vehstatus&VS_HIDDEN &&
 
				v->tile == (TileIndex)tile &&
 
				--pos < 0) {
 
					*veh = v;
 
@@ -695,7 +695,7 @@ static int GetVehicleFromShipDepotWndPt(
 
	}
 

	
 
	return 1; /* outside */
 
	
 

	
 
}
 

	
 
static void ShipDepotClick(Window *w, int x, int y)
 
@@ -714,7 +714,7 @@ static void ShipDepotClick(Window *w, in
 
		if (v != NULL) {
 
			WP(w,traindepot_d).sel = v->index;
 
			SetWindowDirty(w);
 
			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + 
 
			SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) +
 
				GetShipImage(v, 6), 4, w);
 
		}
 
		break;
 
@@ -743,7 +743,7 @@ static void ShipDepotWndProc(Window *w, 
 
		case 2:
 
			ShipDepotClick(w, e->click.pt.x, e->click.pt.y);
 
			break;
 
			
 

	
 
		case 5:
 
			ShowBuildShipWindow(w->window_number);
 
			break;
 
@@ -773,12 +773,12 @@ static void ShipDepotWndProc(Window *w, 
 
				ShowShipViewWindow(v);
 
			}
 
		} break;
 
					
 

	
 
		case 3:
 
			if (!HASBIT(w->disabled_state, 3) &&
 
					WP(w,traindepot_d).sel != INVALID_VEHICLE)	{
 
				Vehicle *v;
 
				
 

	
 
				HandleButtonClick(w, 3);
 

	
 
				v = &_vehicles[WP(w,traindepot_d).sel];
 
@@ -786,7 +786,7 @@ static void ShipDepotWndProc(Window *w, 
 

	
 
				_backup_orders_tile = v->tile;
 
				BackupVehicleOrders(v, _backup_orders_data);
 
	
 

	
 
				if (!DoCommandP(v->tile, v->index, 0, NULL, CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP)))
 
					_backup_orders_tile = 0;
 
			}
 
@@ -854,7 +854,7 @@ static void DrawSmallShipSchedule(Vehicl
 

	
 
		if ((ord & OT_MASK) == OT_GOTO_STATION) {
 
			st = DEREF_STATION(ord >> 8);
 
			
 

	
 
			if (!(st->had_vehicle_of_type & HVOT_BUOY)) {
 
				SET_DPARAM16(0, ord >> 8);
 
				DrawString(x, y, STR_A036, 0);
 
@@ -894,7 +894,7 @@ static void MakeSortedShiptList(byte own
 
		// ships are stored as a cummulative index, eg 25, 41, 43. This means
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2
 
		for (i = &_num_ship_sort[1]; i != endof(_num_ship_sort); i++) {*i += *(i-1);}
 
	
 

	
 
		// sort by owner, then only subsort the requested owner-vehicles
 
		qsort(_ship_sort, n, sizeof(_ship_sort[0]), GeneralOwnerSorter);
 

	
 
@@ -939,7 +939,7 @@ static void PlayerShipsWndProc(Window *w
 
		// Player0: 25; Player1: (41-25) 16; Player2: (43-41) 2 ships
 
		i = (window_number == 0) ? 0 : _num_ship_sort[window_number-1];
 
		SetVScrollCount(w, _num_ship_sort[window_number] - i);
 
		
 

	
 
		/* draw the widgets */
 
		{
 
			Player *p = DEREF_PLAYER(window_number);
 
@@ -982,7 +982,7 @@ static void PlayerShipsWndProc(Window *w
 
				SET_DPARAM32(0, v->profit_this_year);
 
				SET_DPARAM32(1, v->profit_last_year);
 
				DrawString(x + 12, y + 28, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
 
				
 

	
 
				if (v->string_id != STR_SV_SHIP_NAME) {
 
					SET_DPARAM16(0, v->string_id);
 
					DrawString(x+12, y, STR_01AB, 0);
 
@@ -1010,7 +1010,7 @@ static void PlayerShipsWndProc(Window *w
 
			return;
 
		case 6: { /* Matrix to show vehicles */
 
			uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_BIG;
 
			
 

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

	
 
			id_v += w->vscroll.pos;
 
@@ -1035,15 +1035,15 @@ static void PlayerShipsWndProc(Window *w
 

	
 
			tile = _last_built_ship_depot_tile;
 
			do {
 
				if (_map_owner[tile] == _local_player && IsShipDepotTile(tile)) {					
 
				if (_map_owner[tile] == _local_player && IsShipDepotTile(tile)) {
 
					ShowShipDepotWindow(tile);
 
					ShowBuildShipWindow(tile);
 
					return;
 
				}
 
				
 

	
 
				tile = TILE_MASK(tile + 1);
 
			} while(tile != _last_built_ship_depot_tile);
 
			
 

	
 
			ShowBuildShipWindow(0);
 
		} break;
 
		}
smallmap_gui.c
Show inline comments
 
@@ -78,7 +78,7 @@ static const uint16 _legend_land_contour
 
	MK(0x5E,STR_00F2_300M),
 
	MK(0x1F,STR_00F3_400M),
 
	MK(0x27,STR_00F4_500M),
 
	
 

	
 
	MS(0xD7,STR_00EB_ROADS),
 
	MK(0x0A,STR_00EC_RAILROADS),
 
	MK(0x98,STR_00ED_STATIONS_AIRPORTS_DOCKS),
 
@@ -509,7 +509,7 @@ static uint32 INLINE GetSmallMapVegetati
 
		if (i >= 0) i = (i >> 2);
 
		bits = _vegetation_clear_bits[i + 4];
 
	} else if (t == MP_INDUSTRY) {
 
		bits = IS_BYTE_INSIDE(_map5[tile], 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5); 
 
		bits = IS_BYTE_INSIDE(_map5[tile], 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
 
	} else if (t == MP_TREES) {
 
		bits = MKCOLOR(0x54575754);
 
		if ((_map2[tile] & 0x30) == 0x20)
 
@@ -550,7 +550,7 @@ static uint32 INLINE GetSmallMapOwnerPix
 

	
 
	t = GET_TILETYPE(tile);
 
	if (t == MP_HOUSE || _map_owner[tile] == OWNER_TOWN) {
 
		t = 0x80;				
 
		t = 0x80;
 
	} else if (t == MP_INDUSTRY) {
 
		t = 0xff;
 
	} else {
 
@@ -641,10 +641,10 @@ static void DrawSmallMap(DrawPixelInfo *
 

	
 
		/* setup owners ptr */
 
		_owner_colors = tbl = alloca(256 * sizeof(*_owner_colors));
 
		
 

	
 
		/* clear the town colors */
 
		memset(tbl + 128, 0xB4, 128 * sizeof(*_owner_colors));
 
		
 

	
 
		/* fill with some special colors */
 
		tbl[0x10] = MKCOLOR(0x54545454);
 
		tbl[0x11] = MKCOLOR(0xCACACACA);
 
@@ -655,7 +655,7 @@ static void DrawSmallMap(DrawPixelInfo *
 
			if (p->is_active) {
 
				tbl[p->index] = dup_byte32(GetSpritePtr(0x307 + p->player_color)[0xCB]);
 
			}
 
		}	
 
		}
 
	}
 

	
 
	tile_x = (int)WP(w,smallmap_d).scroll_x >> 4;
 
@@ -712,7 +712,7 @@ static void DrawSmallMap(DrawPixelInfo *
 
			proc(ptr, tile_x, tile_y, dpi->pitch*2, reps, mask);
 
		}
 

	
 
skip_column:		
 
skip_column:
 
		if (y == 0) {
 
			tile_y++;
 
			y++;
 
@@ -736,7 +736,7 @@ skip_column:
 
			if (v->type != 0 && v->type != 0x14 && (v->vehstatus & (VS_HIDDEN|VS_UNCLICKABLE)) == 0) {
 
				// Remap into flat coordinates.
 
				Point pt = RemapCoords(
 
					(int)(v->x_pos - WP(w,smallmap_d).scroll_x) >> 4, 
 
					(int)(v->x_pos - WP(w,smallmap_d).scroll_x) >> 4,
 
					(int)(v->y_pos - WP(w,smallmap_d).scroll_y) >> 4,
 
					0);
 
				x = pt.x;
 
@@ -765,11 +765,11 @@ skip_column:
 
						continue;
 
					skip = true;
 
				}
 
				
 

	
 
				// Calculate pointer to pixel and the color
 
				ptr = dpi->dst_ptr + y * dpi->pitch + x;
 
				color = (type == 1) ? _vehicle_type_colors[v->type-0x10] : 0xF;
 
				
 

	
 
				// And draw either one or two pixels depending on clipping
 
				ptr[0] = color;
 
				if (!skip)
 
@@ -789,11 +789,11 @@ skip_column:
 
					0);
 
				x = pt.x - WP(w,smallmap_d).subscroll + 3 - (t->sign.width_2 >> 1);
 
				y = pt.y;
 
								
 

	
 
				// Check if the town sign is within bounds
 
				if (x + t->sign.width_2 > dpi->left &&
 
						x < dpi->left + dpi->width &&
 
						y + 6 > dpi->top && 
 
						y + 6 > dpi->top &&
 
						y < dpi->top + dpi->height) {
 
					// And draw it.
 
					SET_DPARAM16(0, t->index);
 
@@ -801,7 +801,7 @@ skip_column:
 
				}
 
			}
 
		}
 
	} 
 
	}
 

	
 
	// Draw map indicators
 
	{
 
@@ -809,7 +809,7 @@ skip_column:
 

	
 
		// Find main viewport.
 
		vp = FindWindowById(WC_MAIN_WINDOW,0)->viewport;
 
		
 

	
 
		pt = RemapCoords(
 
			WP(w,smallmap_d).scroll_x,
 
			WP(w,smallmap_d).scroll_y,
 
@@ -846,7 +846,7 @@ static void SmallMapWindowProc(Window *w
 
		/* draw the window */
 
		SET_DPARAM16(0, STR_00E5_CONTOURS + _smallmap_type);
 
		DrawWindowWidgets(w);
 
		
 

	
 
		/* draw the legend */
 
		tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)];
 
		x = 4;
 
@@ -877,7 +877,7 @@ static void SmallMapWindowProc(Window *w
 
	case WE_CLICK:
 
		switch(e->click.widget) {
 
		case 2: {/* big/small size */
 
			// const Widget *wi = w->widget; 
 
			// const Widget *wi = w->widget;
 
			DeleteWindow(w);
 
			SndPlayFx(0x13);
 
			{
 
@@ -903,7 +903,7 @@ static void SmallMapWindowProc(Window *w
 
		case 5: /* show land contours */
 
		case 6: /* show vehicles */
 
		case 7: /* show industries */
 
		case 8: /* show transport routes */			
 
		case 8: /* show transport routes */
 
		case 9: /* show vegetation */
 
		case 10: /* show land owners */
 
			w->click_state &= ~(1<<5|1<<6|1<<7|1<<8|1<<9|1<<10);
 
@@ -978,7 +978,7 @@ static void DoShowSmallMap(int big)
 
	int x,y;
 

	
 
	_smallmap_size = big;
 
	
 

	
 
	w = AllocateWindowDescFront(_smallmap_descs[big], 0);
 
	if (w) {
 
		w->click_state = (1<<5) << _smallmap_type | _smallmap_show_towns << 11;
 
@@ -1039,7 +1039,7 @@ static void ExtraViewPortWndProc(Window 
 

	
 
			// set this view to same location. Based on the center, adjusting for zoom
 
			WP(w2,vp_d).scrollpos_x =  x - (w2->viewport->virtual_width - (294 <<vp->zoom) )/2;
 
			WP(w2,vp_d).scrollpos_y =  y - (w2->viewport->virtual_height - (214 << vp->zoom) )/2;			
 
			WP(w2,vp_d).scrollpos_y =  y - (w2->viewport->virtual_height - (214 << vp->zoom) )/2;
 
		} break;
 
		case 7: { /* inverse location button (move this view to same spot as main view) */
 
			Window * w2 = FindWindowById(WC_MAIN_WINDOW, 0);
 
@@ -1047,9 +1047,9 @@ static void ExtraViewPortWndProc(Window 
 
			int y = WP(w2,vp_d).scrollpos_y;
 

	
 
			WP(w,vp_d).scrollpos_x =  x + (w2->viewport->virtual_width - (294 <<vp->zoom) )/2;
 
			WP(w,vp_d).scrollpos_y =  y + (w2->viewport->virtual_height - (214 << vp->zoom) )/2;			
 
			WP(w,vp_d).scrollpos_y =  y + (w2->viewport->virtual_height - (214 << vp->zoom) )/2;
 
		} break;
 
		}	
 
		}
 
	} break;
 
	}
 
}
 
@@ -1066,7 +1066,7 @@ void ShowExtraViewPortWindow()
 
{
 
	Window *w, *v;
 
	int i = 0;
 
	
 

	
 
	// find next free window number for extra viewport
 
	while (FindWindowById(WC_EXTRA_VIEW_PORT,i) ) {
 
		i++;
 
@@ -1078,8 +1078,8 @@ void ShowExtraViewPortWindow()
 
		// disable zoom in button
 
		w->disabled_state = 1 << 4;
 
		// the main window with the main view
 
		v = FindWindowById(WC_MAIN_WINDOW, 0); 
 
		// New viewport start ats (zero,zero) 
 
		v = FindWindowById(WC_MAIN_WINDOW, 0);
 
		// New viewport start ats (zero,zero)
 
		AssignWindowViewport(w, 3, 17, 294, 214, 0 , 0);
 

	
 
		// center on same place as main window (zoom is maximum, no adjustment needed)
sound.c
Show inline comments
 
@@ -73,7 +73,7 @@ static void mix_int8_to_int16(MixerChann
 
	volume_left = sc->volume_left;
 
	volume_right = sc->volume_right;
 

	
 
	if (frac_speed == 0x10000) { 
 
	if (frac_speed == 0x10000) {
 
		// Special case when frac_speed is 0x10000
 
		do {
 
			buffer[0]+= *b * volume_left >> 8;
 
@@ -110,10 +110,10 @@ void MxMixSamples(Mixer *mx, void *buffe
 
{
 
	int i;
 
	MixerChannel *mc;
 
	
 

	
 
	// Clear the buffer
 
	memset(buffer, 0, sizeof(int16)*2*samples);
 
	
 

	
 
	// Mix each channel
 
	for(i=0,mc=mx->channels; i!=lengthof(mx->channels); i++,mc++) {
 
		if (mc->active) {
 
@@ -154,7 +154,7 @@ static void MxSetChannelRawSrc(MixerChan
 
	// adjust the magnitude to prevent overflow
 
	while (size & 0xFFFF0000)
 
		size >>= 1, rate = (rate >> 1) + 1;
 
	
 

	
 
	mc->samples_left = size * mc->mx->play_rate / rate;
 
}
 

	
 
@@ -180,7 +180,7 @@ static void MxOpenBankFile(Mixer *mx, co
 
		fe->file_offset = FioReadDword();
 
		fe->file_size = FioReadDword();
 
	}
 
	
 

	
 
	fe = mx->files;
 
	for(i=0; i!=count; i++,fe++) {
 
		FioSeekTo(fe->file_offset, SEEK_SET);
 
@@ -221,7 +221,7 @@ static bool MxSetBankSource(MixerChannel
 

	
 
	if (fe->file_size == 0)
 
		return false;
 
		
 

	
 
	mem = malloc(fe->file_size);
 
	FioSeekToFile(fe->file_offset);
 
	FioReadBlock(mem, fe->file_size);
 
@@ -229,7 +229,7 @@ static bool MxSetBankSource(MixerChannel
 
	for(i=0; i!=fe->file_size; i++) {
 
		((byte*)mem)[i] ^= 0x80;
 
	}
 
	
 

	
 
	assert(fe->bits_per_sample == 8 && fe->channels == 1 && fe->file_size != 0 && fe->rate != 0);
 

	
 
	MxSetChannelRawSrc(mc, mem, fe->file_size, fe->rate, MX_AUTOFREE | MX_UNSIGNED);
 
@@ -302,10 +302,10 @@ void SndPlayScreenCoordFx(int sound, int
 
		if ((vp=w->viewport) &&
 
				IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) &&
 
				IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) {
 
		
 

	
 
			left = ((x - vp->virtual_left) >> vp->zoom) + vp->left;
 
			StartSound(
 
				_sound_idx[sound], 
 
				_sound_idx[sound],
 
				clamp(left / 71, 0, 8),
 
				(_sound_base_vol[sound] * msf.effect_vol * _vol_factor_by_zoom[vp->zoom]) >> 15
 
			);
 
@@ -334,8 +334,8 @@ void SndPlayVehicleFx(int sound, Vehicle
 
void SndPlayFx(int sound)
 
{
 
	StartSound(
 
		_sound_idx[sound], 
 
		4, 
 
		_sound_idx[sound],
 
		4,
 
		(_sound_base_vol[sound] * msf.effect_vol) >> 7
 
	);
 
}
station.h
Show inline comments
 
@@ -28,7 +28,7 @@ struct Station {
 
	ViewportSign sign;
 

	
 
	uint16 had_vehicle_of_type;
 
	
 

	
 
	byte time_since_load;
 
	byte time_since_unload;
 
	byte delete_ctr;
station_cmd.c
Show inline comments
 
@@ -126,7 +126,7 @@ static Station *AllocateStation()
 
		return NULL;
 
	}
 

	
 
	i = a_free->index;	
 
	i = a_free->index;
 
	memset(a_free, 0, sizeof(Station));
 
	a_free->index = i;
 
	return a_free;
 
@@ -143,7 +143,7 @@ static int CountMapSquareAround(uint til
 
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
 
		TILE_XY(-6,1),  1, 1, 1, 1, 1, 1,
 
		0,
 
	};	
 
	};
 
	int j;
 
	const TileIndexDiff *p = _count_square_table;
 
	int num = 0;
 
@@ -189,9 +189,9 @@ static bool GenerateStationName(Station 
 
					CLRBIT(free_names, str);
 
				}
 
			}
 
		}	
 
		}
 
	}
 
	
 

	
 
	/* check default names */
 
	tmp = free_names & _gen_station_name_bits[flag];
 
	if (tmp != 0) {
 
@@ -255,9 +255,9 @@ static bool GenerateStationName(Station 
 
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_EAST)) | (1<<M(STR_SV_STNAME_NORTH)) ),
 
			~( (1<<M(STR_SV_STNAME_SOUTH)) | (1<<M(STR_SV_STNAME_WEST)) | (1<<M(STR_SV_STNAME_EAST)) ),
 
		};
 
		
 
		free_names &= _direction_and_table[ 
 
			(GET_TILE_X(tile) < GET_TILE_X(t->xy)) + 
 

	
 
		free_names &= _direction_and_table[
 
			(GET_TILE_X(tile) < GET_TILE_X(t->xy)) +
 
			(GET_TILE_Y(tile) < GET_TILE_Y(t->xy))*2];
 
	}
 

	
 
@@ -335,7 +335,7 @@ void UpdateAllStationVirtCoord()
 
	Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		if (st->xy != 0)
 
			UpdateStationVirtCoord(st);			
 
			UpdateStationVirtCoord(st);
 
	}
 
}
 

	
 
@@ -488,7 +488,7 @@ static void UpdateStationAcceptance(Stat
 
	}
 
	span[4] = st->airport_tile;
 
	if (st->airport_tile != 0) {
 
		span[5] = st->airport_tile + TILE_XY(_airport_size_x[st->airport_type]-1, _airport_size_y[st->airport_type]-1); 
 
		span[5] = st->airport_tile + TILE_XY(_airport_size_x[st->airport_type]-1, _airport_size_y[st->airport_type]-1);
 
	}
 
	span[6] = st->dock_tile;
 

	
 
@@ -529,7 +529,7 @@ static void UpdateStationAcceptance(Stat
 
	new_acc = GetAcceptanceMask(st);
 
	if (old_acc == new_acc)
 
		return;
 
	
 

	
 
	// show a message to report that the acceptance was changed?
 
	if (show_msg && st->owner == _local_player && st->facilities) {
 
		uint32 accept=0, reject=0; /* these contain two string ids each */
 
@@ -537,7 +537,7 @@ static void UpdateStationAcceptance(Stat
 

	
 
		do {
 
			if (new_acc & 1) {
 
				if (!(old_acc & 1)) accept = (accept << 16) | *str; 
 
				if (!(old_acc & 1)) accept = (accept << 16) | *str;
 
			} else {
 
				if (old_acc & 1) reject = (reject << 16) | *str;
 
			}
 
@@ -595,7 +595,7 @@ int32 CheckFlatLandBelow(uint tile, uint
 
			cost += _price.terraform;
 
			flat_z += 8;
 
		}
 
		
 

	
 
		// get corresponding flat level and make sure that all parts of the station have the same level.
 
		if (allowed_z == -1) {
 
			// first tile
 
@@ -605,7 +605,7 @@ int32 CheckFlatLandBelow(uint tile, uint
 
			return CMD_ERROR;
 
		}
 

	
 
		// if station is set, then we have special handling to allow building on top of already existing stations. 
 
		// if station is set, then we have special handling to allow building on top of already existing stations.
 
		// so station points to -1 if we can build on any station. or it points to a station if we're only allowed to build
 
		// on exactly that station.
 
		if (station && IS_TILETYPE(tile_cur, MP_STATION)) {
 
@@ -795,7 +795,7 @@ int32 CmdBuildRailroadStation(int x_org,
 
		st = AllocateStation();
 
		if (st == NULL)
 
			return CMD_ERROR;
 
		
 

	
 
		st->town = ClosestTownFromTile(tile_org, (uint)-1);
 
		if (_current_player < MAX_PLAYERS && flags&DC_EXEC)
 
			SETBIT(st->town->have_ratings, _current_player);
 
@@ -819,20 +819,20 @@ int32 CmdBuildRailroadStation(int x_org,
 

	
 
		st->trainst_w = finalvalues[1];
 
		st->trainst_h = finalvalues[2];
 
		
 

	
 
		st->build_date = _date;
 
		
 

	
 
		tile_delta = direction ? TILE_XY(0,1) : TILE_XY(1,0);
 
		
 

	
 
		layout_ptr = alloca(numtracks * plat_len);
 
		GetStationLayout(layout_ptr, numtracks, plat_len);
 
		
 

	
 
		do {
 
			int tile = tile_org;
 
			int w = plat_len;
 
			do {
 

	
 
				ModifyTile(tile, 
 
				ModifyTile(tile,
 
					MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
					MP_MAP2 | MP_MAP5 | MP_MAP3LO | MP_MAP3HI_CLEAR,
 
					station_index, /* map2 parameter */
 
@@ -866,7 +866,7 @@ static void MakeRailwayStationAreaSmalle
 
	uint i;
 

	
 
restart:
 
	
 

	
 
	// too small?
 
	if (w != 0 && h != 0) {
 
		// check the left side, x = constant, y changes
 
@@ -966,7 +966,7 @@ static int32 RemoveRailroadStation(Stati
 
	tile = st->train_tile;
 
	w = st->trainst_w;
 
	h = st->trainst_h;
 
	
 

	
 
	assert(w != 0 && h != 0);
 

	
 
	/* cost is area * constant */
 
@@ -996,7 +996,7 @@ static int32 RemoveRailroadStation(Stati
 
		UpdateStationVirtCoordDirty(st);
 
		DeleteStationIfEmpty(st);
 
	}
 
	
 

	
 
	return cost;
 
}
 

	
 
@@ -1056,7 +1056,7 @@ int32 CmdBuildBusStation(int x, int y, u
 
	if (st != NULL) {
 
		if (st->owner != OWNER_NONE && st->owner != _current_player)
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		
 

	
 
		if (!CheckStationSpreadOut(st, tile, 1, 1))
 
			return CMD_ERROR;
 

	
 
@@ -1091,10 +1091,10 @@ int32 CmdBuildBusStation(int x, int y, u
 
		st->facilities |= FACIL_BUS_STOP;
 
		st->bus_stop_status = 3;
 
		st->owner = _current_player;
 
		
 

	
 
		st->build_date = _date;
 

	
 
		ModifyTile(tile, 
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
			MP_MAP2 | MP_MAP5 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,
 
			st->index,			/* map2 parameter */
 
@@ -1117,7 +1117,7 @@ static int32 RemoveBusStation(Station *s
 
		return CMD_ERROR;
 

	
 
	tile = st->bus_tile;
 
	
 

	
 
	if (!EnsureNoVehicle(tile))
 
		return CMD_ERROR;
 

	
 
@@ -1131,7 +1131,7 @@ static int32 RemoveBusStation(Station *s
 
		DeleteStationIfEmpty(st);
 
	}
 

	
 
	return _price.remove_bus_station;	
 
	return _price.remove_bus_station;
 
}
 

	
 

	
 
@@ -1168,7 +1168,7 @@ int32 CmdBuildTruckStation(int x, int y,
 
	if (st != NULL) {
 
		if (st->owner != OWNER_NONE && st->owner != _current_player)
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		
 

	
 
		if (!CheckStationSpreadOut(st, tile, 1, 1))
 
			return CMD_ERROR;
 

	
 
@@ -1206,8 +1206,8 @@ int32 CmdBuildTruckStation(int x, int y,
 

	
 
		st->build_date = _date;
 

	
 
		ModifyTile(tile, 
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | 
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
 
			st->index,			/* map2 parameter */
 
			p1 + 0x43       /* map5 parameter */
 
@@ -1227,7 +1227,7 @@ static int32 RemoveTruckStation(Station 
 

	
 
	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 
		return CMD_ERROR;
 
	
 

	
 
	tile = st->lorry_tile;
 

	
 
	if (!EnsureNoVehicle(tile))
 
@@ -1235,7 +1235,7 @@ static int32 RemoveTruckStation(Station 
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
 
		
 

	
 
		st->lorry_tile = 0;
 
		st->facilities &= ~FACIL_TRUCK_STOP;
 

	
 
@@ -1243,7 +1243,7 @@ static int32 RemoveTruckStation(Station 
 
		DeleteStationIfEmpty(st);
 
	}
 

	
 
	return _price.remove_truck_station;	
 
	return _price.remove_truck_station;
 
}
 

	
 
// FIXME -- need to move to its corresponding Airport variable
 
@@ -1294,7 +1294,7 @@ static const byte * const _airport_map5_
 
	_airport_map5_tiles_country,				// Country Airfield (small)
 
	_airport_map5_tiles_town,						// City Airport (large)
 
	_airport_map5_tiles_heliport,				// Heliport
 
	_airport_map5_tiles_metropolitan,   // Metropolitain Airport (large) 
 
	_airport_map5_tiles_metropolitan,   // Metropolitain Airport (large)
 
	_airport_map5_tiles_international,	// International Airport (xlarge)
 
};
 

	
 
@@ -1309,12 +1309,12 @@ int32 CmdBuildAirport(int x, int y, uint
 
	Station *st;
 
	int32 cost;
 
	int w,h;
 
	bool airport_upgrade = true;	
 
	bool airport_upgrade = true;
 

	
 
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
 

	
 
	tile = TILE_FROM_XY(x,y);
 
	
 

	
 
	if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile))
 
		return CMD_ERROR;
 

	
 
@@ -1353,7 +1353,7 @@ int32 CmdBuildAirport(int x, int y, uint
 
	if (st != NULL) {
 
		if (st->owner != OWNER_NONE && st->owner != _current_player)
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		
 

	
 
		if (!CheckStationSpreadOut(st, tile, 1, 1))
 
			return CMD_ERROR;
 

	
 
@@ -1397,7 +1397,7 @@ int32 CmdBuildAirport(int x, int y, uint
 
		st->facilities |= FACIL_AIRPORT;
 
		st->airport_type = (byte)p1;
 
		st->airport_flags = 0;
 
		
 

	
 
		st->build_date = _date;
 

	
 
		/*	if airport was demolished while planes were en-route to it, the positions can no longer
 
@@ -1407,11 +1407,11 @@ int32 CmdBuildAirport(int x, int y, uint
 
				2. airport is added to existing station (unfortunately unavoideable)
 
		*/
 
		if (airport_upgrade) {UpdateAirplanesOnNewStation(st);}
 
	
 

	
 
		{
 
			const byte *b = _airport_map5_tiles[p1];
 
BEGIN_TILE_LOOP(tile_cur,w,h,tile)
 
				ModifyTile(tile_cur, 
 
				ModifyTile(tile_cur,
 
					MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
					MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAP5,
 
					st->index, *b++);
 
@@ -1467,7 +1467,7 @@ END_TILE_LOOP(tile_cur, w,h,tile)
 
	return cost;
 
}
 

	
 
/* Build a buoy 
 
/* Build a buoy
 
 * p1,p2 unused
 
 */
 

	
 
@@ -1499,7 +1499,7 @@ int32 CmdBuildBuoy(int x, int y, uint32 
 
		st->facilities |= FACIL_DOCK;
 
		st->had_vehicle_of_type |= HVOT_BUOY;
 
		st->owner = OWNER_NONE;
 
		
 

	
 
		st->build_date = _date;
 

	
 
		ModifyTile(ti.tile,
 
@@ -1511,7 +1511,7 @@ int32 CmdBuildBuoy(int x, int y, uint32 
 
		);
 

	
 
		UpdateStationVirtCoordDirty(st);
 
		
 

	
 
		UpdateStationAcceptance(st, false);
 
		InvalidateWindow(WC_STATION_LIST, st->owner);
 
	}
 
@@ -1538,7 +1538,7 @@ static int32 RemoveBuoy(Station *st, uin
 
		st->facilities &= ~FACIL_DOCK;
 
		st->had_vehicle_of_type &= ~HVOT_BUOY;
 

	
 
		ModifyTile(tile, 
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_WATER) |
 
			MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR,
 
			OWNER_WATER, /* map_owner */
 
@@ -1602,13 +1602,13 @@ int32 CmdBuildDock(int x, int y, uint32 
 
	FindLandscapeHeightByTile(&ti, tile_cur);
 
	if (ti.tileh != 0 || ti.type != MP_WATER)
 
		return_cmd_error(STR_304B_SITE_UNSUITABLE);
 
	
 

	
 
	/* middle */
 
	st = GetStationAround(tile + _dock_tileoffs_chkaround[direction], 
 
	st = GetStationAround(tile + _dock_tileoffs_chkaround[direction],
 
		_dock_w_chk[direction], _dock_h_chk[direction], -1);
 
	if (st == CHECK_STATIONS_ERR)
 
		return CMD_ERROR;
 
	
 

	
 
	/* Find a station close to us */
 
	if (st == NULL) {
 
		st = GetClosestStationFromTile(tile, 8, _current_player);
 
@@ -1618,7 +1618,7 @@ int32 CmdBuildDock(int x, int y, uint32 
 
	if (st != NULL) {
 
		if (st->owner != OWNER_NONE && st->owner != _current_player)
 
			return_cmd_error(STR_3009_TOO_CLOSE_TO_ANOTHER_STATION);
 
		
 

	
 
		if (!CheckStationSpreadOut(st, tile, 1, 1))
 
			return CMD_ERROR;
 

	
 
@@ -1650,23 +1650,23 @@ int32 CmdBuildDock(int x, int y, uint32 
 
		if (!st->facilities) st->xy = tile;
 
		st->facilities |= FACIL_DOCK;
 
		st->owner = _current_player;
 
		
 

	
 
		st->build_date = _date;
 

	
 
		ModifyTile(tile, 
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | 
 
		ModifyTile(tile,
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR |
 
			MP_MAP5,
 
			st->index,
 
			direction + 0x4C);
 

	
 
		ModifyTile(tile + _tileoffs_by_dir[direction], 
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT | 
 
		ModifyTile(tile + _tileoffs_by_dir[direction],
 
			MP_SETTYPE(MP_STATION) | MP_MAPOWNER_CURRENT |
 
			MP_MAP2 | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR |
 
			MP_MAP5,
 
			st->index,
 
			(direction&1) + 0x50);
 
		
 

	
 
		UpdateStationVirtCoordDirty(st);
 
		UpdateStationAcceptance(st, false);
 
		InvalidateWindow(WC_STATION_LIST, st->owner);
 
@@ -1747,13 +1747,13 @@ static void DrawTile_Station(TileInfo *t
 
	t += sizeof(uint32);
 
	if (image & 0x8000)
 
		image |= image_or_modificator;
 
	DrawGroundSprite(image + base_img);	
 
	DrawGroundSprite(image + base_img);
 

	
 
	for(dtss = (DrawTileSeqStruct *)t; (byte)dtss->delta_x != 0x80; dtss++) {
 
		if ((byte)dtss->delta_z != 0x80) {
 
			image =	dtss->image + base_img;
 
			if (_display_opt & DO_TRANS_BUILDINGS) {
 
				if (image&0x8000) image |= image_or_modificator;	
 
				if (image&0x8000) image |= image_or_modificator;
 
			} else {
 
				image = (image & 0x3FFF) | 0x03224000;
 
			}
 
@@ -1763,7 +1763,7 @@ static void DrawTile_Station(TileInfo *t
 
			image = *(uint32*)&dtss->height + base_img; /* endian ok */
 

	
 
			if (_display_opt & DO_TRANS_BUILDINGS) {
 
				if (image&0x8000) image |= image_or_modificator;	
 
				if (image&0x8000) image |= image_or_modificator;
 
			} else {
 
				image = (image & 0x3FFF) | 0x03224000;
 
			}
 
@@ -1852,7 +1852,7 @@ static uint32 GetTileTrackStatus_Station
 
		(IS_BYTE_INSIDE(i, 0x47, 0x4B) && (_patches.roadveh_queue || st->bus_stop_status&3)) ) {
 
			/* This is a bus/truck stop, and there is free space
 
			 * (or we allow queueing) */
 
			
 

	
 
			/* We reverse the dir because it points out of the
 
			 * exit, and we want to get in. Maybe we should return
 
			 * both dirs here? */
 
@@ -1878,7 +1878,7 @@ static void TileLoop_Station(uint tile)
 
  // 0x3A - flag small airport (58)
 
	if (_map5[tile] == 39 || _map5[tile] == 58 || _map5[tile] == 90 || _map5[tile] == 102)
 
		AddAnimatedTile(tile);
 
	
 

	
 
	// treat a bouy tile as water.
 
	else if (_map5[tile] == 0x52)
 
		TileLoop_Water(tile);
 
@@ -1900,7 +1900,7 @@ static void AnimateTile_Station(uint til
 
	if (m5 >= 39 && m5 <= 50) { // turning radar (39 - 50)
 
		if (_tick_counter & 3)
 
			return;
 
		
 

	
 
		if (++m5 == 50+1)
 
			m5 = 39;
 

	
 
@@ -1910,14 +1910,14 @@ static void AnimateTile_Station(uint til
 
	} else if (m5 >= 90 && m5 <= 113) { // turning radar with ground under it (different fences) (90 - 101 | 102 - 113)
 
		if (_tick_counter & 3)
 
			return;
 
		
 

	
 
		m5++;
 
		
 

	
 
		if (m5 == 101+1) {m5 = 90;}  // radar with fences in south
 
		else if (m5 == 113+1) {m5 = 102;} // radar with fences in north
 

	
 
		_map5[tile] = m5;
 
		MarkTileDirtyByTile(tile);		
 
		MarkTileDirtyByTile(tile);
 
	//added - end
 
	} else if (m5 >= 0x3A && m5 <= 0x3D) {  // windsack (58 - 61)
 
		if (_tick_counter & 1)
 
@@ -1925,7 +1925,7 @@ static void AnimateTile_Station(uint til
 

	
 
		if (++m5 == 0x3D+1)
 
			m5 = 0x3A;
 
		
 

	
 
		_map5[tile] = m5;
 
		MarkTileDirtyByTile(tile);
 
	}
 
@@ -1957,17 +1957,17 @@ static uint32 VehicleEnter_Station(Vehic
 
	uint16 spd;
 

	
 
	if (v->type == VEH_Train) {
 
		if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == 0 && 
 
		if (IS_BYTE_INSIDE(_map5[tile], 0, 8) && v->subtype == 0 &&
 
			!IsTrainStationTile(tile + _tileoffs_by_dir[v->direction >> 1])) {
 
			
 

	
 
			station_id = _map2[tile];
 
			if ((!(v->next_order & OF_NON_STOP) && !_patches.new_nonstop) || 
 
			if ((!(v->next_order & OF_NON_STOP) && !_patches.new_nonstop) ||
 
					 (((v->next_order & OT_MASK) == OT_GOTO_STATION && v->next_order_param == station_id))) {
 

	
 
				if (!(_patches.new_nonstop && (v->next_order & OF_NON_STOP)) && v->next_order != OT_LEAVESTATION && v->last_station_visited != station_id) {
 
					x &= 0xF;
 
					y &= 0xF;
 
					
 

	
 
					dir = v->direction & 6;
 
					if (dir & 2) intswap(x,y);
 
					if (y == 8) {
 
@@ -1983,7 +1983,7 @@ static uint32 VehicleEnter_Station(Vehic
 
						}
 
					}
 
				}
 
			}	
 
			}
 
		}
 
	} else if (v->type == VEH_Road) {
 
		if (v->u.road.state < 16 && (v->u.road.state&4)==0 && v->u.road.frame==0) {
 
@@ -2015,7 +2015,7 @@ static uint32 VehicleEnter_Station(Vehic
 
			}
 
		}
 
	}
 
	
 

	
 
	return 0;
 
}
 

	
 
@@ -2041,7 +2041,7 @@ void DeleteAllPlayerStations()
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->xy && st->owner < MAX_PLAYERS)
 
			DeleteStation(st);		
 
			DeleteStation(st);
 
	}
 
}
 

	
 
@@ -2111,7 +2111,7 @@ static void UpdateStationRating(Station 
 
				(rating += 45, days > 3) ||
 
				(rating += 35, true);
 
			}
 
			
 

	
 
			{
 
				waiting = ge->waiting_acceptance & 0xFFF;
 
				(rating -= 90, waiting > 1500) ||
 
@@ -2127,7 +2127,7 @@ static void UpdateStationRating(Station 
 

	
 
				// only modify rating in steps of -2, -1, 0, 1 or 2
 
				ge->rating = rating = or + clamp(clamp(rating, 0, 255) - or, -2, 2);
 
				
 

	
 
				// if rating is <= 64 and more than 200 items waiting, remove some random amount of goods from the station
 
				if (rating <= 64 && waiting >= 200) {
 
					int dec = Random() & 0x1F;
 
@@ -2150,7 +2150,7 @@ static void UpdateStationRating(Station 
 
			}
 
		}
 
	} while (++ge != endof(st->goods));
 
	
 

	
 
	index = st->index;
 

	
 
	if (waiting_changed)
 
@@ -2223,8 +2223,8 @@ void ModifyStationRatingAround(TileIndex
 

	
 
static void UpdateStationWaiting(Station *st, int type, uint amount)
 
{
 
	st->goods[type].waiting_acceptance = 
 
		(st->goods[type].waiting_acceptance & ~0xFFF) + 
 
	st->goods[type].waiting_acceptance =
 
		(st->goods[type].waiting_acceptance & ~0xFFF) +
 
			min(0xFFF, (st->goods[type].waiting_acceptance & 0xFFF) + amount);
 

	
 
	st->goods[type].enroute_time = 0;
 
@@ -2240,7 +2240,7 @@ int32 CmdRenameStation(int x, int y, uin
 
	str = AllocateName((byte*)_decode_parameters, 6);
 
	if (str == 0)
 
		return CMD_ERROR;
 
	
 

	
 
	if (flags & DC_EXEC) {
 
		st = DEREF_STATION(p1);
 
		old_str = st->string_id;
 
@@ -2282,11 +2282,11 @@ uint MoveGoodsToStation(uint tile, int w
 
					st = DEREF_STATION(st_index);
 
					if ((st->had_vehicle_of_type & HVOT_BUOY) == 0 &&
 
							( !st->town->exclusive_counter || (st->town->exclusivity == st->owner) ) && // check exclusive transport rights
 
							st->goods[type].rating != 0 && 
 
							st->goods[type].rating != 0 &&
 
							(!_patches.selectgoods || st->goods[type].last_speed) && // if last_speed is 0, no vehicle has been there.
 
							((st->facilities & (byte)~FACIL_BUS_STOP)!=0 || type==CT_PASSENGERS) && // if we have other fac. than a bus stop, or the cargo is passengers
 
							((st->facilities & (byte)~FACIL_TRUCK_STOP)!=0 || type!=CT_PASSENGERS)) { // if we have other fac. than a cargo bay or the cargo is not passengers
 
						
 

	
 
						around[i] = st_index;
 
						around_ptr[i] = st;
 
					}
 
@@ -2320,10 +2320,10 @@ uint MoveGoodsToStation(uint tile, int w
 
			st1 = around_ptr[i];
 
		} else if (around_ptr[i]->goods[type].rating >= best_rating2) {
 
			best_rating2 = around_ptr[i]->goods[type].rating;
 
			st2 = around_ptr[i];			
 
			st2 = around_ptr[i];
 
		}
 
	}
 
	
 

	
 
	assert(st1 != NULL);
 
	assert(st2 != NULL);
 
	assert(best_rating != 0 || best_rating2 != 0);
 
@@ -2338,7 +2338,7 @@ uint MoveGoodsToStation(uint tile, int w
 
	if (t != 0) {
 
		moved = (t * best_rating >> 8) + 1;
 
		amount -= t;
 
		UpdateStationWaiting(st1, type, moved); 
 
		UpdateStationWaiting(st1, type, moved);
 
	}
 

	
 
	assert(amount >= 0);
 
@@ -2398,7 +2398,7 @@ void BuildOilRig(uint tile)
 

	
 
			UpdateStationVirtCoordDirty(st);
 
			UpdateStationAcceptance(st, false);
 
			return;		
 
			return;
 
		}
 
	}
 
}
 
@@ -2456,10 +2456,10 @@ static int32 ClearTile_Station(uint tile
 
	// original airports < 67, new airports between 83 - 114
 
	if (m5 < 0x43 || ( m5 >= 83 && m5 <= 114) )
 
		return RemoveAirport(st, flags);
 
		
 

	
 
	if (m5 < 0x47)
 
		return RemoveTruckStation(st, flags);
 
	
 

	
 
	if (m5 < 0x4B)
 
		return RemoveBusStation(st, flags);
 

	
 
@@ -2527,7 +2527,7 @@ static const byte _station_desc[] = {
 
	SLE_VAR(Station,airport_type,				SLE_UINT8),
 
	SLE_VAR(Station,truck_stop_status,	SLE_UINT8),
 
	SLE_VAR(Station,bus_stop_status,		SLE_UINT8),
 
			
 

	
 
	// blocked_months was stored here in savegame format 0 - 4.0
 
	SLE_CONDVAR(Station,blocked_months_obsolete,	SLE_UINT8, 0, 4),
 

	

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)