bridge_cmd.c
branchcustombridgeheads
changeset 5608 a0768f524071
parent 5607 5169e3e15ce9
child 5611 11da6bafbfb9
equal deleted inserted replaced
5607:5169e3e15ce9 5608:a0768f524071
   942 		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
   942 		DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
   943 	}
   943 	}
   944 }
   944 }
   945 
   945 
   946 
   946 
   947 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
   947 static uint32 VehicleEnter_Street_Bridge(Vehicle *v, TileIndex tile, int x, int y)
       
   948 {
       
   949 	int z = GetSlopeZ(x, y) - v->z_pos;
       
   950 
       
   951 	DiagDirection dir;
       
   952 
       
   953 	if (myabs(z) > 2) return 8;
       
   954 
       
   955 	if (v->type == VEH_Road) {
       
   956 		/* modify speed of vehicle */
       
   957 		uint16 spd = _bridge[GetBridgeType(tile)].speed * 2;
       
   958 		if (v->cur_speed > spd) v->cur_speed = spd;
       
   959 	}
       
   960 
       
   961 	dir = GetBridgeRampDirection(tile);
       
   962 	if (DirToDiagDir(v->direction) == dir) {
       
   963 		switch (dir) {
       
   964 			default: NOT_REACHED();
       
   965 			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
       
   966 			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
       
   967 			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
       
   968 			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
       
   969 		}
       
   970 		v->u.road.state = 0xFF;
       
   971 		return 4;
       
   972 	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
       
   973 		v->tile = tile;
       
   974 		if (v->u.road.state == 0xFF) {
       
   975 			static const byte road_exit_bridge_state[4] = {8, 9, 0, 1};
       
   976 			v->u.road.state = road_exit_bridge_state[dir];
       
   977 			v->u.road.frame = 0;
       
   978 			return 4;
       
   979 		}
       
   980 		return 0;
       
   981 	}
       
   982 	return 0;
       
   983 }
       
   984 
       
   985 static uint32 VehicleEnter_Railway_Bridge(Vehicle *v, TileIndex tile, int x, int y)
   948 {
   986 {
   949 	int z = GetSlopeZ(x, y) - v->z_pos;
   987 	int z = GetSlopeZ(x, y) - v->z_pos;
   950 
   988 
   951 	DiagDirection dir;
   989 	DiagDirection dir;
   952 
   990 
   957 		z = h + TILE_HEIGHT - v->z_pos;
   995 		z = h + TILE_HEIGHT - v->z_pos;
   958 	}
   996 	}
   959 
   997 
   960 	if (myabs(z) > 2) return 8;
   998 	if (myabs(z) > 2) return 8;
   961 
   999 
   962 	if (v->type == VEH_Road || (v->type == VEH_Train && IsFrontEngine(v))) {
  1000 	if (IsFrontEngine(v)) {
   963 		/* modify speed of vehicle */
  1001 		/* modify speed of vehicle */
   964 		uint16 spd = _bridge[GetBridgeType(tile)].speed;
  1002 		uint16 spd = _bridge[GetBridgeType(tile)].speed;
   965 
       
   966 		if (v->type == VEH_Road) spd *= 2;
       
   967 		if (v->cur_speed > spd) v->cur_speed = spd;
  1003 		if (v->cur_speed > spd) v->cur_speed = spd;
   968 	}
  1004 	}
   969 
  1005 
   970 	dir = GetBridgeRampDirection(tile);
  1006 	dir = GetBridgeRampDirection(tile);
   971 	if (DirToDiagDir(v->direction) == dir ||
  1007 	if (DirToDiagDir(v->direction) == dir ||
   975 			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
  1011 			case DIAGDIR_NE: if ((x & 0xF) != 0)             return 0; break;
   976 			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
  1012 			case DIAGDIR_SE: if ((y & 0xF) != TILE_SIZE - 1) return 0; break;
   977 			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
  1013 			case DIAGDIR_SW: if ((x & 0xF) != TILE_SIZE - 1) return 0; break;
   978 			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
  1014 			case DIAGDIR_NW: if ((y & 0xF) != 0)             return 0; break;
   979 		}
  1015 		}
   980 		if (v->type == VEH_Train) {
  1016 		v->u.rail.track = 0x40;
   981 			v->u.rail.track = 0x40;
  1017 		CLRBIT(v->u.rail.flags, VRF_GOINGUP);
   982 			CLRBIT(v->u.rail.flags, VRF_GOINGUP);
  1018 		CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
   983 			CLRBIT(v->u.rail.flags, VRF_GOINGDOWN);
       
   984 		} else {
       
   985 			v->u.road.state = 0xFF;
       
   986 		}
       
   987 		return 4;
  1019 		return 4;
   988 	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
  1020 	} else if (DirToDiagDir(v->direction) == ReverseDiagDir(dir)) {
   989 		v->tile = tile;
  1021 		v->tile = tile;
   990 		if (v->type == VEH_Train) {
  1022 		if (v->u.rail.track == 0x40) {
   991 			if (v->u.rail.track == 0x40) {
  1023 			v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
   992 				v->u.rail.track = (DiagDirToAxis(dir) == AXIS_X ? 1 : 2);
  1024 			return 4;
   993 				return 4;
       
   994 			}
       
   995 		} else {
       
   996 			if (v->u.road.state == 0xFF) {
       
   997 				static const byte road_exit_bridge_state[4] = {8, 9, 0, 1};
       
   998 				v->u.road.state = road_exit_bridge_state[dir];
       
   999 				v->u.road.frame = 0;
       
  1000 				return 4;
       
  1001 			}
       
  1002 		}
  1025 		}
  1003 		return 0;
  1026 		return 0;
  1004 	}
  1027 	}
  1005 	return 0;
  1028 	return 0;
       
  1029 }
       
  1030 
       
  1031 static uint32 VehicleEnter_Bridge(Vehicle *v, TileIndex tile, int x, int y)
       
  1032 {
       
  1033 	if (v->type == VEH_Train) return VehicleEnter_Railway_Bridge(v, tile, x, y);
       
  1034 
       
  1035 	if (v->type == VEH_Road) return VehicleEnter_Street_Bridge(v, tile, x, y);
       
  1036 
       
  1037 	NOT_REACHED();
  1006 }
  1038 }
  1007 
  1039 
  1008 const TileTypeProcs _tile_type_bridge_procs = {
  1040 const TileTypeProcs _tile_type_bridge_procs = {
  1009 	DrawTile_Bridge,           /* draw_tile_proc */
  1041 	DrawTile_Bridge,           /* draw_tile_proc */
  1010 	GetSlopeZ_Bridge,          /* get_slope_z_proc */
  1042 	GetSlopeZ_Bridge,          /* get_slope_z_proc */