Merge pull request #6319 from OpenRCT2/network-version

Network version
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2017-09-28 17:38:56 +02:00
commit ffaa3403d0
6 files changed
+149 -70

No files matched your search

+4 -4
View File
@@ -231,7 +231,7 @@ void research_finish_item(sint32 entryIndex)
{
availabilityString = STR_NEWS_ITEM_RESEARCH_NEW_RIDE_AVAILABLE;
if (rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME)
if (rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE)
{
set_format_arg(0, rct_string_id, rideEntry->naming.name);
}
@@ -432,7 +432,7 @@ void research_remove_non_separate_vehicle_types()
researchItem->entryIndex >= RESEARCH_ENTRY_RIDE_MASK
) {
rct_ride_entry *rideEntry = get_ride_entry(researchItem->entryIndex & 0xFF);
if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE | RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME))) {
if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE))) {
// Check if ride type already exists further up for a vehicle type that isn't displayed as a ride
researchItem2 = researchItem - 1;
do {
@@ -441,7 +441,7 @@ void research_remove_non_separate_vehicle_types()
researchItem2->entryIndex >= RESEARCH_ENTRY_RIDE_MASK
) {
rideEntry = get_ride_entry(researchItem2->entryIndex & 0xFF);
if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE | RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME))) {
if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE))) {
if (research_get_ride_base_type(researchItem->entryIndex) == research_get_ride_base_type(researchItem2->entryIndex)) {
// Remove item
@@ -731,7 +731,7 @@ rct_string_id research_item_get_name(uint32 researchItem)
{
return 0;
}
else if (rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME)
else if (rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE)
{
return rideEntry->naming.name;
}
+1 -1
View File
@@ -49,7 +49,7 @@ enum {
// This define specifies which version of network stream current build uses.
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
#define NETWORK_STREAM_VERSION "2"
#define NETWORK_STREAM_VERSION "3"
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
#ifdef __cplusplus
+20 -12
View File
@@ -6004,7 +6004,7 @@ static money32 ride_create(sint32 type, sint32 subType, sint32 flags, sint32 *ou
continue;
}
if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
subType = *rei;
goto foundRideEntry;
}
@@ -6216,7 +6216,7 @@ foundRideEntry:
void ride_set_name_to_default(Ride * ride, rct_ride_entry * rideEntry)
{
if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
ride_set_name_to_track_default(ride, rideEntry);
} else {
ride_set_name_to_vehicle_default(ride, rideEntry);
@@ -6292,7 +6292,7 @@ rct_ride_name get_ride_naming(uint8 rideType, rct_ride_entry * rideEntry)
const ride_group * rideGroup = get_ride_group(rideType, rideEntry);
return rideGroup->naming;
}
else if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
else if (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) || rideTypeShouldLoseSeparateFlag(rideEntry)) {
return RideNaming[rideType];
}
else {
@@ -8476,16 +8476,24 @@ rct_map_element *get_station_platform(sint32 x, sint32 y, sint32 z, sint32 z_tol
/**
* Check for an adjacent station to x,y,z in direction.
*/
static bool check_for_adjacent_station(sint32 x, sint32 y, sint32 z, uint8 direction) {
static bool check_for_adjacent_station(sint32 x, sint32 y, sint32 z, uint8 direction)
{
bool found = false;
sint32 adjX = x + TileDirectionDelta[direction].x;
sint32 adjY = y + TileDirectionDelta[direction].y;
rct_map_element *stationElement = get_station_platform(adjX, adjY, z, 2);
if (stationElement != NULL) {
sint32 rideIndex = stationElement->properties.track.ride_index;
Ride *ride = get_ride(rideIndex);
if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS) {
found = true;
sint32 adjX = x;
sint32 adjY = y;
for (uint32 i = 0; i <= RIDE_ADJACENCY_CHECK_DISTANCE; i++)
{
adjX += TileDirectionDelta[direction].x;
adjY += TileDirectionDelta[direction].y;
rct_map_element * stationElement = get_station_platform(adjX, adjY, z, 2);
if (stationElement != NULL)
{
sint32 rideIndex = stationElement->properties.track.ride_index;
Ride * ride = get_ride(rideIndex);
if (ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS)
{
found = true;
}
}
}
return found;
+2 -2
View File
@@ -40,7 +40,7 @@
#define RIDE_MEASUREMENT_MAX_ITEMS 4800
#define MAX_RIDES 255
#define RIDE_ID_NULL 255
#define RIDE_ADJACENCY_CHECK_DISTANCE 5
#pragma pack(push, 1)
@@ -444,7 +444,7 @@ enum {
RIDE_ENTRY_FLAG_PLAY_SPLASH_SOUND_SLIDE = 1 << 9,
RIDE_ENTRY_FLAG_COVERED_RIDE = 1 << 10,
RIDE_ENTRY_FLAG_LIMIT_AIRTIME_BONUS = 1 << 11,
RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME = 1 << 12,
RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME_DEPRECATED = 1 << 12, // Always set with SEPARATE_RIDE, and deprecated in favour of it.
RIDE_ENTRY_FLAG_SEPARATE_RIDE = 1 << 13,
RIDE_ENTRY_FLAG_CANNOT_BREAK_DOWN = 1 << 14,
RIDE_ENTRY_DISABLE_LAST_OPERATING_MODE = 1 << 15,
+121 -50
View File
@@ -2332,16 +2332,24 @@ static rct_synchronised_vehicle* _lastSynchronisedVehicle = NULL;
*/
static bool try_add_synchronised_station(sint32 x, sint32 y, sint32 z)
{
rct_map_element *mapElement = get_station_platform(x, y, z, 2);
if (mapElement == NULL) {
// make sure we are in map bounds
if (x < 0 || y < 0 || (x >> 5) > (MAXIMUM_MAP_SIZE_TECHNICAL - 1) || (y >> 5) > (MAXIMUM_MAP_SIZE_TECHNICAL - 1))
{
return false;
}
rct_map_element * mapElement = get_station_platform(x, y, z, 2);
if (mapElement == NULL)
{
/* No station platform element found,
* so no station to synchronise */
return false;
}
sint32 rideIndex = mapElement->properties.track.ride_index;
Ride *ride = get_ride(rideIndex);
if (!(ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS)) {
Ride * ride = get_ride(rideIndex);
if (!(ride->depart_flags & RIDE_DEPART_SYNCHRONISE_WITH_ADJACENT_STATIONS))
{
/* Ride is not set to synchronise with adjacent stations. */
return false;
}
@@ -2352,7 +2360,7 @@ static bool try_add_synchronised_station(sint32 x, sint32 y, sint32 z)
sint32 stationIndex = map_element_get_station(mapElement);
rct_synchronised_vehicle *sv = _lastSynchronisedVehicle;
rct_synchronised_vehicle * sv = _lastSynchronisedVehicle;
sv->ride_id = rideIndex;
sv->station_id = stationIndex;
sv->vehicle_id = SPRITE_INDEX_NULL;
@@ -2361,26 +2369,44 @@ static bool try_add_synchronised_station(sint32 x, sint32 y, sint32 z)
/* Ride vehicles are not on the track (e.g. ride is/was under
* construction), so just return; vehicle_id for this station
* is SPRITE_INDEX_NULL. */
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) {
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK))
{
return true;
}
/* Station is not ready to depart, so just return;
* vehicle_id for this station is SPRITE_INDEX_NULL. */
if (!(ride->station_depart[stationIndex] & STATION_DEPART_FLAG)) {
if (!(ride->station_depart[stationIndex] & STATION_DEPART_FLAG))
{
return true;
}
// Look for a vehicle on this station waiting to depart.
for (sint32 i = 0; i < ride->num_vehicles; i++) {
for (sint32 i = 0; i < ride->num_vehicles; i++)
{
uint16 spriteIndex = ride->vehicles[i];
if (spriteIndex == SPRITE_INDEX_NULL) continue;
if (spriteIndex == SPRITE_INDEX_NULL)
{
continue;
}
rct_vehicle *vehicle = GET_VEHICLE(spriteIndex);
if (vehicle->status != VEHICLE_STATUS_WAITING_TO_DEPART) continue;
if (vehicle->sub_state != 0) continue;
if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT)) continue;
if (vehicle->current_station != stationIndex) continue;
rct_vehicle * vehicle = GET_VEHICLE(spriteIndex);
if (vehicle->status != VEHICLE_STATUS_WAITING_TO_DEPART)
{
continue;
}
if (vehicle->sub_state != 0)
{
continue;
}
if (!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT))
{
continue;
}
if (vehicle->current_station != stationIndex)
{
continue;
}
sv->vehicle_id = spriteIndex;
return true;
@@ -2405,30 +2431,42 @@ static bool try_add_synchronised_station(sint32 x, sint32 y, sint32 z)
*/
static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
{
Ride *ride = get_ride(vehicle->ride);
Ride * ride = get_ride(vehicle->ride);
sint32 station = vehicle->current_station;
rct_xy8 location = ride->station_starts[station];
sint32 x = location.x * 32;
sint32 y = location.y * 32;
sint32 z = ride->station_heights[station];
rct_map_element *mapElement = map_get_track_element_at(x, y, z);
if (mapElement == NULL) {
rct_map_element * mapElement = map_get_track_element_at(x, y, z);
if (mapElement == NULL){
return false;
}
// Reset the list of synchronised vehicles to empty.
_lastSynchronisedVehicle = _synchronisedVehicles;
// Search for stations to sync in both directions from the current tile.
/* Search for stations to sync in both directions from the current tile.
* We allow for some space between stations, and every time a station
* is found we allow for space between that and the next.
*/
// First search direction.
sint32 direction = (mapElement->type + 1) & 3;
sint32 spaceBetween;
sint32 maxCheckDistance = RIDE_ADJACENCY_CHECK_DISTANCE;
while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1]) {
spaceBetween = maxCheckDistance;
while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1])
{
x += TileDirectionDelta[direction].x;
y += TileDirectionDelta[direction].y;
if (!try_add_synchronised_station(x, y, z)) {
if (try_add_synchronised_station(x, y, z))
{
spaceBetween = maxCheckDistance;
continue;
}
if (spaceBetween-- == 0)
{
break;
}
}
@@ -2439,33 +2477,50 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
// Other search direction.
direction = (direction ^ 2) & 3;
while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1]) {
spaceBetween = maxCheckDistance;
while (_lastSynchronisedVehicle < &_synchronisedVehicles[SYNCHRONISED_VEHICLE_COUNT - 1])
{
x += TileDirectionDelta[direction].x;
y += TileDirectionDelta[direction].y;
if (!try_add_synchronised_station(x, y, z)) {
if (try_add_synchronised_station(x, y, z))
{
spaceBetween = maxCheckDistance;
continue;
}
if (spaceBetween-- == 0)
{
break;
}
}
if (_lastSynchronisedVehicle == _synchronisedVehicles) {
if (_lastSynchronisedVehicle == _synchronisedVehicles)
{
// No adjacent stations, allow depart
return true;
}
for (rct_synchronised_vehicle *sv = _synchronisedVehicles; sv < _lastSynchronisedVehicle; sv++) {
Ride *sv_ride = get_ride(sv->ride_id);
for (rct_synchronised_vehicle * sv = _synchronisedVehicles; sv < _lastSynchronisedVehicle; sv++)
{
Ride * sv_ride = get_ride(sv->ride_id);
if (!(sv_ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)) {
if (sv_ride->status != RIDE_STATUS_CLOSED) {
if (ride_is_block_sectioned(sv_ride)) {
if (!(sv_ride->station_depart[sv->station_id] & STATION_DEPART_FLAG)) {
if (!(sv_ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN))
{
if (sv_ride->status != RIDE_STATUS_CLOSED)
{
if (ride_is_block_sectioned(sv_ride))
{
if (!(sv_ride->station_depart[sv->station_id] & STATION_DEPART_FLAG))
{
sv = _synchronisedVehicles;
uint8 rideId = 0xFF;
for (; sv < _lastSynchronisedVehicle; sv++) {
if (rideId == 0xFF) {
for (; sv < _lastSynchronisedVehicle; sv++)
{
if (rideId == 0xFF)
{
rideId = sv->ride_id;
}
if (rideId != sv->ride_id) {
if (rideId != sv->ride_id)
{
// Here the sync-ed stations are not all from the same ride.
return false;
}
@@ -2473,9 +2528,11 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
/* Here all the of sync-ed stations are from the same ride */
ride = get_ride(rideId);
for (sint32 i = 0; i < ride->num_vehicles; i++) {
rct_vehicle *v = GET_VEHICLE(ride->vehicles[i]);
if (v->status != VEHICLE_STATUS_WAITING_TO_DEPART && v->velocity != 0) {
for (sint32 i = 0; i < ride->num_vehicles; i++)
{
rct_vehicle * v = GET_VEHICLE(ride->vehicles[i]);
if (v->status != VEHICLE_STATUS_WAITING_TO_DEPART && v->velocity != 0)
{
// Here at least one vehicle on the ride is moving.
return false;
}
@@ -2486,15 +2543,18 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
}
}
// There is no vehicle waiting at this station to sync with.
if (sv->vehicle_id == SPRITE_INDEX_NULL) {
if (sv->vehicle_id == SPRITE_INDEX_NULL)
{
// Check conditions for departing without all stations being in sync.
if (_lastSynchronisedVehicle > &_synchronisedVehicles[1]) {
if (_lastSynchronisedVehicle > &_synchronisedVehicles[1])
{
// Sync condition: there are at least 3 stations to sync
return false;
}
uint8 someRideIndex = _synchronisedVehicles[0].ride_id;
// uint8 currentStation = _synchronisedVehicles[0].station_id
if (someRideIndex != vehicle->ride) {
if (someRideIndex != vehicle->ride)
{
// Sync condition: the first station to sync is a different ride
return false;
}
@@ -2502,33 +2562,42 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
sint32 numTrainsAtStation = 0;
sint32 numTravelingTrains = 0;
sint32 currentStation = sv->station_id;
for (sint32 i = 0; i < sv_ride->num_vehicles; i++) {
for (sint32 i = 0; i < sv_ride->num_vehicles; i++)
{
uint16 spriteIndex = sv_ride->vehicles[i];
if (spriteIndex != SPRITE_INDEX_NULL) {
if (spriteIndex != SPRITE_INDEX_NULL)
{
rct_vehicle *otherVehicle = GET_VEHICLE(spriteIndex);
if (otherVehicle->status != VEHICLE_STATUS_TRAVELLING) {
if (currentStation == otherVehicle->current_station) {
if (otherVehicle->status != VEHICLE_STATUS_TRAVELLING)
{
if (currentStation == otherVehicle->current_station)
{
if (otherVehicle->status == VEHICLE_STATUS_WAITING_TO_DEPART ||
otherVehicle->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION
) {
otherVehicle->status == VEHICLE_STATUS_MOVING_TO_END_OF_STATION)
{
numTrainsAtStation++;
}
}
} else {
}
else
{
numTravelingTrains++;
}
}
}
sint32 totalTrains = numTrainsAtStation + numTravelingTrains;
if (totalTrains != sv_ride->num_vehicles || numTravelingTrains >= sv_ride->num_vehicles / 2) {
if (totalTrains != sv_ride->num_vehicles || numTravelingTrains >= sv_ride->num_vehicles / 2)
{
//if (numArrivingTrains > 0 || numTravelingTrains >= sv_ride->num_vehicles / 2) {
/* Sync condition: If there are trains arriving at the
* station or half or more of the ride trains are
* travelling, this station must be sync-ed before the
* trains can depart! */
return false;
} else {
}
else
{
/* Sync exception - train is not arriving at the station
* and there are less than half the trains for the ride
* travelling. */
@@ -2540,8 +2609,10 @@ static bool vehicle_can_depart_synchronised(rct_vehicle *vehicle)
}
// At this point all vehicles in _snychronisedVehicles can depart.
for (rct_synchronised_vehicle *sv = _synchronisedVehicles; sv < _lastSynchronisedVehicle; sv++) {
if (sv->vehicle_id != SPRITE_INDEX_NULL) {
for (rct_synchronised_vehicle *sv = _synchronisedVehicles; sv < _lastSynchronisedVehicle; sv++)
{
if (sv->vehicle_id != SPRITE_INDEX_NULL)
{
rct_vehicle *v = GET_VEHICLE(sv->vehicle_id);
v->update_flags &= ~VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT;
}
+1 -1
View File
@@ -2714,7 +2714,7 @@ static void window_ride_vehicle_mousedown(rct_window *w, rct_widgetindex widgetI
rideEntryIndex = *currentRideEntryIndex;
currentRideEntry = get_ride_entry(rideEntryIndex);
// Skip if vehicle wants to be separate, unless subtype switching is enabled
if ((currentRideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE | RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME)) && !(gConfigInterface.select_by_track_type || selectionShouldBeExpanded))
if ((currentRideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE)) && !(gConfigInterface.select_by_track_type || selectionShouldBeExpanded))
continue;
// Skip if vehicle type is not invented yet