train_cmd.c
changeset 1977 37bbebf94434
parent 1969 b7d014a74c0a
child 1980 6c5917cfcb78
equal deleted inserted replaced
1976:2eb82bb3cb2d 1977:37bbebf94434
   413 	}
   413 	}
   414 	DrawStringMultiCenter(x, y, STR_885B_COST_WEIGHT_T_SPEED_POWER, maxw);
   414 	DrawStringMultiCenter(x, y, STR_885B_COST_WEIGHT_T_SPEED_POWER, maxw);
   415 }
   415 }
   416 
   416 
   417 
   417 
   418 static int32 CmdBuildRailWagon(uint engine, uint tile, uint32 flags)
   418 static int32 CmdBuildRailWagon(uint engine, TileIndex tile, uint32 flags)
   419 {
   419 {
   420 	int32 value;
   420 	int32 value;
   421 	Vehicle *v;
   421 	Vehicle *v;
   422 	const RailVehicleInfo *rvi;
   422 	const RailVehicleInfo *rvi;
   423 	int dir;
   423 	int dir;
  1504 	return cost;
  1504 	return cost;
  1505 }
  1505 }
  1506 
  1506 
  1507 typedef struct TrainFindDepotData {
  1507 typedef struct TrainFindDepotData {
  1508 	uint best_length;
  1508 	uint best_length;
  1509 	uint tile;
  1509 	TileIndex tile;
  1510 	byte owner;
  1510 	byte owner;
  1511 	/**
  1511 	/**
  1512 	 * true if reversing is necesarry for the train to get to this depot This
  1512 	 * true if reversing is necesarry for the train to get to this depot This
  1513 	 * value is unused when new depot finding and NPF are both disabled
  1513 	 * value is unused when new depot finding and NPF are both disabled
  1514 	 */
  1514 	 */
  1515 	bool reverse;
  1515 	bool reverse;
  1516 } TrainFindDepotData;
  1516 } TrainFindDepotData;
  1517 
  1517 
  1518 static bool TrainFindDepotEnumProc(uint tile, TrainFindDepotData *tfdd, int track, uint length, byte *state)
  1518 static bool TrainFindDepotEnumProc(TileIndex tile, TrainFindDepotData *tfdd, int track, uint length, byte *state)
  1519 {
  1519 {
  1520 	if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
  1520 	if (IsTileType(tile, MP_RAILWAY) && IsTileOwner(tile, tfdd->owner)) {
  1521 		if ((_map5[tile] & ~0x3) == 0xC0) {
  1521 		if ((_map5[tile] & ~0x3) == 0xC0) {
  1522 			if (length < tfdd->best_length) {
  1522 			if (length < tfdd->best_length) {
  1523 				tfdd->best_length = length;
  1523 				tfdd->best_length = length;
  1541 // crashed!
  1541 // crashed!
  1542 static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
  1542 static TrainFindDepotData FindClosestTrainDepot(Vehicle *v)
  1543 {
  1543 {
  1544 	int i;
  1544 	int i;
  1545 	TrainFindDepotData tfdd;
  1545 	TrainFindDepotData tfdd;
  1546 	uint tile = v->tile;
  1546 	TileIndex tile = v->tile;
  1547 
  1547 
  1548 	assert(!(v->vehstatus & VS_CRASHED));
  1548 	assert(!(v->vehstatus & VS_CRASHED));
  1549 
  1549 
  1550 	tfdd.owner = v->owner;
  1550 	tfdd.owner = v->owner;
  1551 	tfdd.best_length = (uint)-1;
  1551 	tfdd.best_length = (uint)-1;
  1805 	uint best_bird_dist;
  1805 	uint best_bird_dist;
  1806 	uint best_track_dist;
  1806 	uint best_track_dist;
  1807 	byte best_track;
  1807 	byte best_track;
  1808 } TrainTrackFollowerData;
  1808 } TrainTrackFollowerData;
  1809 
  1809 
  1810 static bool TrainTrackFollower(uint tile, TrainTrackFollowerData *ttfd, int track, uint length, byte *state){
  1810 static bool TrainTrackFollower(TileIndex tile, TrainTrackFollowerData *ttfd, int track, uint length, byte *state)
       
  1811 {
  1811 	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile]&0xC0) == 0x40) {
  1812 	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile]&0xC0) == 0x40) {
  1812 		// the tile has a signal
  1813 		// the tile has a signal
  1813 		byte m3 = _map3_lo[tile];
  1814 		byte m3 = _map3_lo[tile];
  1814 		if (!(m3 & SignalAlongTrackdir(track))) {
  1815 		if (!(m3 & SignalAlongTrackdir(track))) {
  1815 			// if one way signal not pointing towards us, stop going in this direction.
  1816 			// if one way signal not pointing towards us, stop going in this direction.
  1905 }
  1906 }
  1906 #endif
  1907 #endif
  1907 
  1908 
  1908 
  1909 
  1909 /* choose a track */
  1910 /* choose a track */
  1910 static byte ChooseTrainTrack(Vehicle *v, uint tile, int enterdir, TrackdirBits trackdirbits)
  1911 static byte ChooseTrainTrack(Vehicle *v, TileIndex tile, int enterdir, TrackdirBits trackdirbits)
  1911 {
  1912 {
  1912 	TrainTrackFollowerData fd;
  1913 	TrainTrackFollowerData fd;
  1913 	uint best_track;
  1914 	uint best_track;
  1914 #if PF_BENCHMARK
  1915 #if PF_BENCHMARK
  1915 	int time = rdtsc();
  1916 	int time = rdtsc();
  2382 	0, 7, 6, 0,
  2383 	0, 7, 6, 0,
  2383 	1, 0, 5, 0,
  2384 	1, 0, 5, 0,
  2384 	2, 3, 4,
  2385 	2, 3, 4,
  2385 };
  2386 };
  2386 
  2387 
  2387 static int GetNewVehicleDirectionByTile(uint new_tile, uint old_tile)
  2388 static int GetNewVehicleDirectionByTile(TileIndex new_tile, TileIndex old_tile)
  2388 {
  2389 {
  2389 	uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
  2390 	uint offs = (TileY(new_tile) - TileY(old_tile) + 1) * 4 +
  2390 							TileX(new_tile) - TileX(old_tile) + 1;
  2391 							TileX(new_tile) - TileX(old_tile) + 1;
  2391 	assert(offs < 11);
  2392 	assert(offs < 11);
  2392 	return _new_vehicle_direction_table[offs];
  2393 	return _new_vehicle_direction_table[offs];
  2504 static const byte _otherside_signal_directions[14] = {
  2505 static const byte _otherside_signal_directions[14] = {
  2505 	1, 3, 1, 3, 5, 3, 0, 0,
  2506 	1, 3, 1, 3, 5, 3, 0, 0,
  2506 	5, 7, 7, 5, 7, 1,
  2507 	5, 7, 7, 5, 7, 1,
  2507 };
  2508 };
  2508 
  2509 
  2509 static void TrainMovedChangeSignals(uint tile, int dir)
  2510 static void TrainMovedChangeSignals(TileIndex tile, int dir)
  2510 {
  2511 {
  2511 	int i;
  2512 	int i;
  2512 	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) {
  2513 	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) {
  2513 		i = FindFirstBit2x64((_map5[tile]+(_map5[tile]<<8)) & _reachable_tracks[dir]);
  2514 		i = FindFirstBit2x64((_map5[tile]+(_map5[tile]<<8)) & _reachable_tracks[dir]);
  2514 		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
  2515 		UpdateSignalsOnSegment(tile, _otherside_signal_directions[i]);
  3003 	225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15
  3004 	225, 210, 195, 180, 165, 150, 135, 120, 105, 90, 75, 60, 45, 30, 15, 15
  3004 };
  3005 };
  3005 
  3006 
  3006 static bool TrainCheckIfLineEnds(Vehicle *v)
  3007 static bool TrainCheckIfLineEnds(Vehicle *v)
  3007 {
  3008 {
  3008 	uint tile;
  3009 	TileIndex tile;
  3009 	uint x,y;
  3010 	uint x,y;
  3010 	int t;
  3011 	int t;
  3011 	uint32 ts;
  3012 	uint32 ts;
  3012 
  3013 
  3013 	if ((uint)(t=v->breakdown_ctr) > 1) {
  3014 	if ((uint)(t=v->breakdown_ctr) > 1) {
  3206 {
  3207 {
  3207 	Vehicle *v = GetVehicle(data_a);
  3208 	Vehicle *v = GetVehicle(data_a);
  3208 	return  (v->u.rail.track == 0x80 && (v->vehstatus | VS_STOPPED));
  3209 	return  (v->u.rail.track == 0x80 && (v->vehstatus | VS_STOPPED));
  3209 }
  3210 }
  3210 
  3211 
  3211 void TrainEnterDepot(Vehicle *v, uint tile)
  3212 void TrainEnterDepot(Vehicle *v, TileIndex tile)
  3212 {
  3213 {
  3213 	SetSignalsOnBothDir(tile, _depot_track_ind[_map5[tile]&3]);
  3214 	SetSignalsOnBothDir(tile, _depot_track_ind[_map5[tile]&3]);
  3214 
  3215 
  3215 	if (v->subtype != TS_Front_Engine)
  3216 	if (v->subtype != TS_Front_Engine)
  3216 		v = GetFirstVehicleInChain(v);
  3217 		v = GetFirstVehicleInChain(v);