roadveh_cmd.c
changeset 2823 d4be8420b41c
parent 2819 f25fb6ee397f
child 2854 b3527fde3ff7
equal deleted inserted replaced
2822:3685b5c83c57 2823:d4be8420b41c
  1241 	if (!RoadVehAccelerate(v))
  1241 	if (!RoadVehAccelerate(v))
  1242 		return;
  1242 		return;
  1243 
  1243 
  1244 	if (v->u.road.overtaking != 0)  {
  1244 	if (v->u.road.overtaking != 0)  {
  1245 		if (++v->u.road.overtaking_ctr >= 35)
  1245 		if (++v->u.road.overtaking_ctr >= 35)
  1246 			v->u.road.overtaking = 0;
  1246 			/* If overtaking just aborts at a random moment, we can have a out-of-bound problem,
       
  1247 			 *  if the vehicle started a corner. To protect that, only allow an abort of
       
  1248 			 *  overtake if we are on straight road, which are the 8 states below */
       
  1249 			if (v->u.road.state == 0  || v->u.road.state == 1  ||
       
  1250 					v->u.road.state == 8  || v->u.road.state == 9  ||
       
  1251 					v->u.road.state == 16 || v->u.road.state == 17 ||
       
  1252 					v->u.road.state == 24 || v->u.road.state == 25)
       
  1253 				v->u.road.overtaking = 0;
  1247 	}
  1254 	}
  1248 
  1255 
  1249 	BeginVehicleMove(v);
  1256 	BeginVehicleMove(v);
  1250 
  1257 
  1251 	if (v->u.road.state == 255) {
  1258 	if (v->u.road.state == 255) {
  1277 
  1284 
  1278 // switch to another tile
  1285 // switch to another tile
  1279 	if (rd.x & 0x80) {
  1286 	if (rd.x & 0x80) {
  1280 		TileIndex tile = v->tile + TileOffsByDir(rd.x & 3);
  1287 		TileIndex tile = v->tile + TileOffsByDir(rd.x & 3);
  1281 		int dir = RoadFindPathToDest(v, tile, rd.x&3);
  1288 		int dir = RoadFindPathToDest(v, tile, rd.x&3);
  1282 		int tmp;
       
  1283 		uint32 r;
  1289 		uint32 r;
  1284 		byte newdir;
  1290 		byte newdir;
  1285 		const RoadDriveEntry *rdp;
  1291 		const RoadDriveEntry *rdp;
  1286 
  1292 
  1287 		if (dir == -1) {
  1293 		if (dir == -1) {
  1293 		if ((dir & 7) >= 6) {
  1299 		if ((dir & 7) >= 6) {
  1294 			/* Turning around */
  1300 			/* Turning around */
  1295 			tile = v->tile;
  1301 			tile = v->tile;
  1296 		}
  1302 		}
  1297 
  1303 
  1298 		tmp = (dir+(_opt.road_side<<4))^v->u.road.overtaking;
  1304 		rdp = _road_drive_data[(dir + (_opt.road_side << 4)) ^ v->u.road.overtaking];
  1299 		rdp = _road_drive_data[tmp];
       
  1300 
       
  1301 		tmp &= ~0x10;
       
  1302 
  1305 
  1303 		x = TileX(tile) * 16 + rdp[0].x;
  1306 		x = TileX(tile) * 16 + rdp[0].x;
  1304 		y = TileY(tile) * 16 + rdp[0].y;
  1307 		y = TileY(tile) * 16 + rdp[0].y;
  1305 
  1308 
  1306 		if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
  1309 		if (RoadVehFindCloseTo(v, x, y, newdir=RoadVehGetSlidingDirection(v, x, y)))
  1315 			dir = _road_reverse_table[rd.x&3];
  1318 			dir = _road_reverse_table[rd.x&3];
  1316 			goto again;
  1319 			goto again;
  1317 		}
  1320 		}
  1318 
  1321 
  1319 		if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) {
  1322 		if (IS_BYTE_INSIDE(v->u.road.state, 0x20, 0x30) && IsTileType(v->tile, MP_STATION)) {
  1320 			if ((tmp&7) >= 6) { v->cur_speed = 0; return; }
  1323 			if ((dir & 7) >= 6) { v->cur_speed = 0; return; }
  1321 			if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
  1324 			if (IS_BYTE_INSIDE(_m[v->tile].m5, 0x43, 0x4B)) {
  1322 				RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
  1325 				RoadStop *rs = GetRoadStopByTile(v->tile, GetRoadStopType(v->tile));
  1323 				byte *b = &rs->status;
  1326 				byte *b = &rs->status;
  1324 
  1327 
  1325 				//we have reached a loading bay, mark it as used
  1328 				//we have reached a loading bay, mark it as used
  1328 			}
  1331 			}
  1329 		}
  1332 		}
  1330 
  1333 
  1331 		if (!(r & 4)) {
  1334 		if (!(r & 4)) {
  1332 			v->tile = tile;
  1335 			v->tile = tile;
  1333 			v->u.road.state = (byte)tmp;
  1336 			v->u.road.state = (byte)dir;
  1334 			v->u.road.frame = 0;
  1337 			v->u.road.frame = 0;
  1335 		}
  1338 		}
  1336 		if (newdir != v->direction) {
  1339 		if (newdir != v->direction) {
  1337 			v->direction = newdir;
  1340 			v->direction = newdir;
  1338 			v->cur_speed -= v->cur_speed >> 2;
  1341 			v->cur_speed -= v->cur_speed >> 2;