add vehicle struct and enum labels from vehicle-update branch.

This commit is contained in:
IntelOrca 2015-10-25 21:25:54 +00:00
parent 14ec8a7fc5
commit 8d84b540ad
9 changed files with 99 additions and 43 deletions

View File

@ -899,7 +899,7 @@ void viewport_vehicle_paint_setup(rct_vehicle *vehicle, int imageDirection)
rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype);
vehicleEntry = &rideEntry->vehicles[vehicle->vehicle_type];
if (vehicle->var_48 & 0x800) {
if (vehicle->update_flags & VEHICLE_UPDATE_FLAG_11) {
vehicleEntry++;
z += 16;
}

View File

@ -2206,10 +2206,13 @@ static void peep_update_ride_sub_state_2(rct_peep* peep){
}
}
rct_vehicle *currentTrain = GET_VEHICLE(ride->vehicles[peep->current_train]);
if (ride->status == RIDE_STATUS_OPEN &&
++peep->var_AC != 0 &&
!((GET_VEHICLE(ride->vehicles[peep->current_train]))->var_48 & (1 << 4)))
!(vehicle->update_flags & VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART)
) {
return;
}
if (ride->mode != RIDE_MODE_FORWARD_ROTATION &&
ride->mode != RIDE_MODE_BACKWARD_ROTATION){
@ -2322,8 +2325,8 @@ void peep_update_ride_sub_state_7(rct_peep* peep){
if (!(RCT2_ADDRESS(RCT2_ADDRESS_RIDE_FLAGS, uint32)[ride->type * 2] & RIDE_TYPE_FLAG_16)){
for (; vehicle->is_child; vehicle = GET_VEHICLE(vehicle->prev_vehicle_on_ride)){
uint16 eax = vehicle->var_36 / 4;
if (eax == 0 || eax > 3)
uint16 trackType = vehicle->track_type >> 2;
if (trackType == 0 || trackType > 3)
continue;
rct_map_element* inner_map = map_get_first_element_at(vehicle->track_x / 32, vehicle->track_y / 32);

View File

@ -2252,7 +2252,7 @@ void ride_prepare_breakdown(int rideIndex, int breakdownReason)
}
}
if (vehicle != NULL)
vehicle->var_48 |= 0x100;
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_CAR;
break;
case BREAKDOWN_VEHICLE_MALFUNCTION:
// Choose a random train
@ -2261,7 +2261,7 @@ void ride_prepare_breakdown(int rideIndex, int breakdownReason)
// Set flag on broken train, first car
vehicle = GET_VEHICLE(ride->vehicles[ride->broken_vehicle]);
vehicle->var_48 |= 0x200;
vehicle->update_flags |= VEHICLE_UPDATE_FLAG_BROKEN_TRAIN;
break;
case BREAKDOWN_BRAKES_FAILURE:
// Original code generates a random number but does not use it
@ -2671,7 +2671,7 @@ void ride_measurement_update(rct_ride_measurement *measurement)
uint16 spriteIndex;
rct_ride *ride;
rct_vehicle *vehicle;
int unk, velocity, altitude, verticalG, lateralG;
int velocity, altitude, verticalG, lateralG;
ride = GET_RIDE(measurement->ride_index);
spriteIndex = ride->vehicles[measurement->vehicle_index];
@ -2694,8 +2694,8 @@ void ride_measurement_update(rct_ride_measurement *measurement)
return;
}
unk = (vehicle->var_36 / 4) & 0xFF;
if (unk == 216 || unk == 123 || unk == 9 || unk == 63 || unk == 147 || unk == 155)
uint8 trackType = (vehicle->track_type >> 2) & 0xFF;
if (trackType == 216 || trackType == 123 || trackType == 9 || trackType == 63 || trackType == 147 || trackType == 155)
if (vehicle->velocity == 0)
return;
@ -4159,7 +4159,7 @@ void vehicle_unset_var_48_b1(rct_vehicle *head)
uint16 spriteIndex;
rct_vehicle *vehicle = head;
while (true) {
vehicle->var_48 &= ~(1 << 1);
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_1;
spriteIndex = vehicle->next_vehicle_on_train;
if (spriteIndex == SPRITE_INDEX_NULL) {
break;
@ -4245,7 +4245,6 @@ void ride_create_vehicles_find_first_block(rct_ride *ride, rct_xy_element *outXY
*/
void loc_6DDF9C(rct_ride *ride, rct_map_element *mapElement)
{
registers regs;
rct_vehicle *train, *car;
for (int i = 0; i < ride->num_vehicles; i++) {
@ -4276,10 +4275,9 @@ void loc_6DDF9C(rct_ride *ride, rct_map_element *mapElement)
mapElement->flags |= (1 << 5);
car = train;
while (true) {
car->var_48 &= ~(1 << 1);
car->update_flags &= ~VEHICLE_UPDATE_FLAG_1;
car->status = VEHICLE_STATUS_TRAVELLING;
regs.ax = car->var_36 >> 2;
if (regs.al == 1) {
if ((car->track_type >> 2) == TRACK_ELEM_END_STATION) {
car->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION;
}
@ -6332,7 +6330,7 @@ void invalidate_test_results(int rideIndex)
uint16 spriteIndex = ride->vehicles[i];
if (spriteIndex != SPRITE_INDEX_NULL) {
rct_vehicle *vehicle = GET_VEHICLE(spriteIndex);
vehicle->var_48 &= ~(1 << 5);
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_TESTING;
}
}
}
@ -6360,9 +6358,9 @@ void ride_fix_breakdown(int rideIndex, int reliabilityIncreaseFactor)
spriteIndex = ride->vehicles[i];
while (spriteIndex != SPRITE_INDEX_NULL) {
vehicle = GET_VEHICLE(spriteIndex);
vehicle->var_48 &= ~(1 << 7);
vehicle->var_48 &= ~(1 << 8);
vehicle->var_48 &= ~(1 << 9);
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_7;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_CAR;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_TRAIN;
spriteIndex = vehicle->next_vehicle_on_train;
}
}

View File

@ -248,7 +248,7 @@ static void ride_race_init_vehicle_speeds(rct_ride *ride)
for (i = 0; i < ride->num_vehicles; i++) {
vehicle = &g_sprite_list[ride->vehicles[i]].vehicle;
vehicle->var_48 &= ~(1 << 6);
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_6;
rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype);

View File

@ -22,6 +22,7 @@
#include "../audio/audio.h"
#include "../audio/mixer.h"
#include "../config.h"
#include "../hook.h"
#include "../interface/viewport.h"
#include "../openrct2.h"
#include "../world/sprite.h"
@ -518,6 +519,16 @@ rct_vehicle *vehicle_get_head(rct_vehicle *vehicle)
return vehicle;
}
rct_vehicle *vehicle_get_tail(rct_vehicle *vehicle)
{
uint16 spriteIndex;
while ((spriteIndex = vehicle->next_vehicle_on_train) != SPRITE_INDEX_NULL) {
vehicle = GET_VEHICLE(spriteIndex);
}
return vehicle;
}
int vehicle_is_used_in_pairs(rct_vehicle *vehicle)
{
return vehicle->num_seats & VEHICLE_SEAT_PAIR_FLAG;
@ -567,7 +578,7 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d
current->var_C4 = 0;
current->var_C5 = 0;
current->var_C8 = 0;
current->var_CC = 0xFF;
current->scream_sound_id = 0xFF;
current->var_1F = 0;
current->var_20 = 0;
for (int j = 0; j < 32; j++) {
@ -583,9 +594,9 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d
z += RCT2_GLOBAL(0x0097D21A + (ride->type * 8), uint8);
sprite_move(16, 16, z, (rct_sprite*)current);
current->var_36 = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3);
current->track_type = (TRACK_ELEM_CABLE_LIFT_HILL << 2) | (current->sprite_direction >> 3);
current->var_34 = 164;
current->var_48 = 2;
current->update_flags = VEHICLE_UPDATE_FLAG_1;
current->status = VEHICLE_STATUS_MOVING_TO_END_OF_STATION;
current->var_51 = 0;
current->num_peeps = 0;
@ -593,6 +604,18 @@ rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int d
return current;
}
/**
*
* rct2: 0x006DD365
*/
bool sub_6DD365(rct_vehicle *vehicle)
{
registers regs;
regs.esi = (int)vehicle;
return RCT2_CALLFUNC_Y(0x006DD365, &regs) & 0x100;
}
/**
*
* rct2: 0x006DAB4C
@ -608,18 +631,6 @@ int sub_6DAB4C(rct_vehicle *vehicle, int *outStation)
return regs.eax;
}
/**
*
* rct2: 0x006DD365
*/
bool sub_6DD365(rct_vehicle *vehicle)
{
registers regs;
regs.esi = (int)vehicle;
return RCT2_CALLFUNC_Y(0x006DD365, &regs) & 0x100;
}
rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle)
{
rct_ride_type *rideEntry = GET_RIDE_ENTRY(vehicle->ride_subtype);

View File

@ -111,7 +111,10 @@ typedef struct {
uint8 vehicle_type; // 0x31
rct_vehicle_colour colours; // 0x32
uint16 var_34;
sint16 var_36;
union {
sint16 track_direction; // 0x36 (0000 0000 0000 0011)
sint16 track_type; // 0x36 (0000 0011 1111 1100)
};
uint16 track_x; // 0x38
uint16 track_y; // 0x3A
uint16 track_z; // 0x3C
@ -125,7 +128,7 @@ typedef struct {
uint16 var_44;
uint16 friction; // 0x46
uint16 var_48;
uint16 update_flags; // 0x48
uint8 var_4A;
uint8 current_station; // 0x4B
uint16 var_4C;
@ -153,13 +156,14 @@ typedef struct {
uint8 var_C5;
uint8 pad_C6[2];
uint32 var_C8;
uint8 var_CC;
uint8 scream_sound_id; // 0xCC
uint8 var_CD;
union {
uint8 var_CE;
uint8 num_laps; // 0xCE
};
uint8 pad_CF[0x04];
uint8 pad_CF[0x03];
sint8 var_D2;
uint8 var_D3;
uint8 var_D4;
uint8 var_D5;
@ -208,6 +212,25 @@ enum {
VEHICLE_STATUS_STOPPED_BY_BLOCK_BRAKES
};
enum{
VEHICLE_UPDATE_FLAG_0 = (1 << 0),
VEHICLE_UPDATE_FLAG_1 = (1 << 1),
VEHICLE_UPDATE_FLAG_WAIT_ON_ADJACENT = (1 << 2),
VEHICLE_UPDATE_FLAG_3 = (1 << 3),
VEHICLE_UPDATE_FLAG_TRAIN_READY_DEPART = (1 << 4),
VEHICLE_UPDATE_FLAG_TESTING = (1 << 5),
VEHICLE_UPDATE_FLAG_6 = (1 << 6),
VEHICLE_UPDATE_FLAG_7 = (1 << 7),
VEHICLE_UPDATE_FLAG_BROKEN_CAR = (1 << 8),
VEHICLE_UPDATE_FLAG_BROKEN_TRAIN = (1 << 9),
VEHICLE_UPDATE_FLAG_10 = (1 << 10),
VEHICLE_UPDATE_FLAG_11 = (1 << 11),
VEHICLE_UPDATE_FLAG_12 = (1 << 12),
VEHICLE_UPDATE_FLAG_13 = (1 << 13),
VEHICLE_UPDATE_FLAG_14 = (1 << 14),
VEHICLE_UPDATE_FLAG_15 = (1 << 15)
};
enum {
VEHICLE_SPRITE_FLAG_FLAT = (1 << 0),
VEHICLE_SPRITE_FLAG_GENTLE_SLOPES = (1 << 1),
@ -255,8 +278,8 @@ int vehicle_is_used_in_pairs(rct_vehicle *vehicle);
rct_vehicle *vehicle_get_head(rct_vehicle *vehicle);
void sub_6DEF56(rct_vehicle *cableLift);
rct_vehicle *cable_lift_segment_create(int rideIndex, int x, int y, int z, int direction, uint16 var_44, uint32 var_24, bool head);
int sub_6DAB4C(rct_vehicle *vehicle, int *outStation);
bool sub_6DD365(rct_vehicle *vehicle);
int sub_6DAB4C(rct_vehicle *vehicle, int *outStation);
rct_ride_type_vehicle *vehicle_get_vehicle_entry(rct_vehicle *vehicle);
/** Helper macro until rides are stored in this module. */

View File

@ -2110,8 +2110,8 @@ static rct_string_id window_ride_get_status_vehicle(rct_window *w, void *argumen
vehicle = &(g_sprite_list[vehicleSpriteIndex].vehicle);
if (vehicle->status != VEHICLE_STATUS_CRASHING && vehicle->status != VEHICLE_STATUS_CRASHED) {
int ax = vehicle->var_36 / 4;
if (ax == 216 || ax == 123 || ax == 9 || ax == 63 || ax == 147 || ax == 155) {
int trackType = vehicle->track_type >> 2;
if (trackType == 216 || trackType == 123 || trackType == 9 || trackType == 63 || trackType == 147 || trackType == 155) {
if ((RCT2_ADDRESS(0x01357644, uint32)[ride->type] & 0x40) && vehicle->velocity == 0) {
RCT2_GLOBAL((int)arguments + 0, uint16) = STR_STOPPED_BY_BLOCK_BRAKES;
return 1191;
@ -3462,11 +3462,11 @@ static void window_ride_maintenance_dropdown(rct_window *w, int widgetIndex, int
case BREAKDOWN_DOORS_STUCK_CLOSED:
case BREAKDOWN_DOORS_STUCK_OPEN:
vehicle = &(g_sprite_list[ride->vehicles[ride->broken_vehicle]].vehicle);
vehicle->var_48 &= ~0x100;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_CAR;
break;
case BREAKDOWN_VEHICLE_MALFUNCTION:
vehicle = &(g_sprite_list[ride->vehicles[ride->broken_vehicle]].vehicle);
vehicle->var_48 &= ~0x200;
vehicle->update_flags &= ~VEHICLE_UPDATE_FLAG_BROKEN_TRAIN;
break;
}
ride->lifecycle_flags &= ~(RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN);

View File

@ -4734,3 +4734,23 @@ rct_map_element *map_get_track_element_at(int x, int y, int z)
return NULL;
}
/**
* Gets the map element at x, y, z.
* @param x x units, not tiles.
* @param y y units, not tiles.
* @param z Base height.
*/
rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType)
{
rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5);
do {
if (map_element_get_type(mapElement) != MAP_ELEMENT_TYPE_TRACK) continue;
if (mapElement->base_height != z) continue;
if (mapElement->properties.track.type != trackType) continue;
return mapElement;
} while (!map_element_is_last_for_tile(mapElement++));
return NULL;
}

View File

@ -384,5 +384,6 @@ bool map_large_scenery_get_origin(
);
rct_map_element *map_get_track_element_at(int x, int y, int z);
rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType);
#endif