Exemplo n.º 1
0
/**
 *
 *  rct: 0x0069C5D0
 */
void money_effect_create(money32 value)
{
	rct_window *mainWindow;
	rct_viewport *mainViewport;
	rct_xyz16 mapPosition;

	mapPosition.x = RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16);
	mapPosition.y = RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16);
	mapPosition.z = RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16);
	if (mapPosition.x == (sint16)0x8000) {
		mainWindow = window_get_main();
		if (mainWindow == NULL)
			return;

		mainViewport = mainWindow->viewport;
		screen_get_map_xy(
			mainViewport->x + (mainViewport->width / 2),
			mainViewport->y + (mainViewport->height / 2),
			&mapPosition.x,
			&mapPosition.y,
			NULL
		);
		if (mapPosition.x == (sint16)0x8000)
			return;

		mapPosition.z = map_element_height(mapPosition.x, mapPosition.y) & 0xFFFF;
	}
	mapPosition.z += 10;
	money_effect_create_at(-value, mapPosition.x, mapPosition.y, mapPosition.z);
}
Exemplo n.º 2
0
void sub_689174(sint16* x, sint16* y, uint8 curr_rotation){
	//RCT2_CALLFUNC_X(0x00689174, (int*)&x, (int*)&y, &ecx, &curr_rotation, (int*)&window, (int*)&viewport, &ebp);

	sint16 start_x = *x;
	sint16 start_y = *y;
	sint16 height = 0;
	switch (curr_rotation){
	case 0:
		for (int i = 0; i < 6; ++i){

			*x = start_y - start_x / 2 + height;
			*y = start_y + start_x / 2 + height;

			height = map_element_height((0xFFFF) & *x, (0xFFFF) & *y);
		}
		break;
	case 1:
		for (int i = 0; i < 6; ++i){
			*x = -start_y - start_x / 2 - height;
			*y = start_y - start_x / 2 + height;

			height = map_element_height((0xFFFF) & *x, (0xFFFF) & *y);
		}
		break;
	case 2:
		for (int i = 0; i < 6; ++i){
			*x = -start_y + start_x / 2 - height;
			*y = -start_y - start_x / 2 - height;

			height = map_element_height((0xFFFF) & *x, (0xFFFF) & *y);
		}
		break;
	case 3:
		for (int i = 0; i < 6; ++i){
			*x = start_x / 2 + start_y + height;
			*y = start_x / 2 - start_y - height;

			height = map_element_height((0xFFFF) & *x, (0xFFFF) & *y);
		}
		break;
	}
}
Exemplo n.º 3
0
static void mapgen_place_tree(sint32 type, sint32 x, sint32 y)
{
	sint32 surfaceZ;
	rct_map_element *mapElement;
	rct_scenery_entry *sceneryEntry = get_small_scenery_entry(type);

	surfaceZ = map_element_height(x * 32 + 16, y * 32 + 16) / 8;
	mapElement = map_element_insert(x, y, surfaceZ, (1 | 2 | 4 | 8));
	assert(mapElement != NULL);
	mapElement->clearance_height = surfaceZ + (sceneryEntry->small_scenery.height >> 3);

	mapElement->type = MAP_ELEMENT_TYPE_SCENERY | (util_rand() & 3);
	mapElement->properties.scenery.type = type;
	mapElement->properties.scenery.age = 0;
	mapElement->properties.scenery.colour_1 = COLOUR_YELLOW;
}
Exemplo n.º 4
0
static void mapgen_place_tree(int type, int x, int y)
{
	int surfaceZ;
	rct_map_element *mapElement;
	rct_scenery_entry *sceneryEntry = g_smallSceneryEntries[type];

	surfaceZ = map_element_height(x * 32 + 16, y * 32 + 16) / 8;
	mapElement = map_element_insert(x, y, surfaceZ, (1 | 2 | 4 | 8));
	mapElement->clearance_height = surfaceZ + (sceneryEntry->small_scenery.height >> 3);

	mapElement->type = MAP_ELEMENT_TYPE_SCENERY | (util_rand() % 3);
	mapElement->properties.scenery.type = type;
	mapElement->properties.scenery.age = 0;
	mapElement->properties.scenery.colour_1 = 26;
	mapElement->properties.scenery.colour_1 = 18;
}
Exemplo n.º 5
0
/**
 * 
 *  rct2: 0x006E7A3A
 */
void viewport_update_position(rct_window *window)
{
	//RCT2_CALLPROC_X(0x006E7A3A, 0, 0, 0, 0, (int)window, 0, 0);

	RCT2_CALLPROC_X(window->event_handlers[WE_RESIZE], 0, 0, 0, 0, (int)window, 0, 0);

	rct_viewport* viewport = window->viewport;
	if (!viewport)return;

	if (window->viewport_target_sprite != -1){
		rct_sprite* sprite = &g_sprite_list[window->viewport_target_sprite];

		int height = map_element_height(sprite->unknown.x, sprite->unknown.y) - 16;
		int underground = sprite->unknown.z < height;

		RCT2_CALLPROC_X(0x6E7A15, sprite->unknown.x, sprite->unknown.y, sprite->unknown.z, underground, (int)window, (int)viewport, 0);

		int center_x, center_y;
		center_2d_coordinates(sprite->unknown.x, sprite->unknown.y, sprite->unknown.z, &center_x, &center_y, window->viewport);

		RCT2_CALLPROC_X(0x6E7DE1, center_x, center_y, 0, 0, (int)window, (int)viewport, 0);
		window_invalidate(window);//Added to force a redraw.
		return;
	}


	sint16 x = viewport->view_width / 2 + window->saved_view_x;
	sint16 y = viewport->view_height / 2 + window->saved_view_y;

	int curr_rotation = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32);
	sub_689174(&x, &y, curr_rotation);
	
	RCT2_CALLPROC_X(0x006E7A15, x, y, 0, 0, (int)window, (int)viewport, 0);

	//Clamp to the map minimum value
	int at_map_edge = 0;
	if (x < MAP_MINIMUM_X_Y){
		x = MAP_MINIMUM_X_Y;
		at_map_edge = 1;
	}
	if (y < MAP_MINIMUM_X_Y){
		y = MAP_MINIMUM_X_Y;
		at_map_edge = 1;
	}

	//Clamp to the map maximum value (scenario specific)
	if (x > RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAXIMUM_X_Y, sint16)){
		x = RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAXIMUM_X_Y, sint16);
		at_map_edge = 1;
	}
	if (y > RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAXIMUM_X_Y, sint16)){
		y = RCT2_GLOBAL(RCT2_ADDRESS_MAP_MAXIMUM_X_Y, sint16);
		at_map_edge = 1;
	}

	if (at_map_edge) {
		// The &0xFFFF is to prevent the sign extension messing the
		// function up.
		int z = map_element_height(x & 0xFFFF, y & 0xFFFF);
		int _2d_x, _2d_y;
		center_2d_coordinates(x, y, z, &_2d_x, &_2d_y, viewport);
	
		if (window->saved_view_x > 0){
			_2d_x = min(_2d_x, window->saved_view_x);
		}
		else{
			_2d_x = max(_2d_x, window->saved_view_x);
		}

		if (window->saved_view_y > 0){
			_2d_y = min(_2d_y, window->saved_view_y);
		}
		else{
			_2d_y = max(_2d_y, window->saved_view_y);
		}

		window->saved_view_x = _2d_x;
		window->saved_view_y = _2d_y;
	}

	x = window->saved_view_x;
	y = window->saved_view_y;
	if (window->flags & WF_SCROLLING_TO_LOCATION){
		// Moves the viewport if focusing in on an item
		uint8 flags = 0;
		x -= viewport->view_x;
		if (x < 0){
			x = -x;
			flags |= 1;
		}
		y -= viewport->view_y;
		if (y < 0){
			y = -y;
			flags |= 2;
		}
		x = (x + 7)/8;
		y = (y + 7)/8;

		//If we are at the final zoom position
		if (!x && !y){
			window->flags &= ~WF_SCROLLING_TO_LOCATION;
		}
		if (flags & 1){
			x = -x;
		}
		if (flags & 2){
			y = -y;
		}
		x += viewport->view_x;
		y += viewport->view_y;
	}

	RCT2_CALLPROC_X(0x6E7DE1, x, y, 0, 0, (int)window, (int)viewport, 0);
}
Exemplo n.º 6
0
/**
 * Get the (x,y,z) coordinates of the subject of a news item.
 * If the new item is no longer valid, return SPRITE_LOCATION_NULL in the x-coordinate
 *
 *  rct2: 0x0066BA74
 */
void news_item_get_subject_location(sint32 type, sint32 subject, sint32 *x, sint32 *y, sint32 *z)
{
    sint32 i;
    rct_ride *ride;
    rct_peep *peep;
    rct_vehicle *vehicle;

    switch (type) {
    case NEWS_ITEM_RIDE:
        ride = get_ride(subject);
        if (ride->overall_view.xy == RCT_XY8_UNDEFINED) {
            *x = SPRITE_LOCATION_NULL;
            break;
        }
        *x = ride->overall_view.x * 32 + 16;
        *y = ride->overall_view.y * 32 + 16;
        *z = map_element_height(*x, *y);
        break;
    case NEWS_ITEM_PEEP_ON_RIDE:
        peep = GET_PEEP(subject);
        *x = peep->x;
        *y = peep->y;
        *z = peep->z;
        if (*x != SPRITE_LOCATION_NULL)
            break;

        if (peep->state != 3 && peep->state != 7) {
            *x = SPRITE_LOCATION_NULL;
            break;
        }

        // Find which ride peep is on
        ride = get_ride(peep->current_ride);
        if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) {
            *x = SPRITE_LOCATION_NULL;
            break;
        }

        // Find the first car of the train peep is on
        vehicle = &(get_sprite(ride->vehicles[peep->current_train])->vehicle);
        // Find the actual car peep is on
        for (i = 0; i < peep->current_car; i++)
            vehicle = &(get_sprite(vehicle->next_vehicle_on_train)->vehicle);
        *x = vehicle->x;
        *y = vehicle->y;
        *z = vehicle->z;
        break;
    case NEWS_ITEM_PEEP:
        peep = GET_PEEP(subject);
        *x = peep->x;
        *y = peep->y;
        *z = peep->z;
        break;
    case NEWS_ITEM_BLANK:
        *x = subject;
        *y = subject >> 16;
        *z = map_element_height(*x, *y);
         break;
    default:
        *x = SPRITE_LOCATION_NULL;
        break;
    }
}
Exemplo n.º 7
0
/**
 *
 *  rct2: 0x00678761
 */
static void title_update_showcase()
{
	rct_window* w;
	uint8 script_opcode, script_operand;
	short x, y, z;
	int i;

	if (_scriptWaitCounter <= 0) {
		do {
			script_opcode = *_currentScript++;
			switch (script_opcode) {
			case TITLE_SCRIPT_WAIT:
				_scriptWaitCounter = (*_currentScript++) * 32;
				break;
			case TITLE_SCRIPT_LOAD:
				if (!scenario_load(get_file_path(PATH_ID_SIXFLAGS_MAGICMOUNTAIN))) {
					log_fatal("OpenRCT2 can not currently cope when unable to load title screen scenario.");
					exit(-1);
				}

				w = window_get_main();
				w->viewport_target_sprite = -1;
				w->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16);
				w->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16);

				{
					char _cl = (RCT2_GLOBAL(0x0138869E, sint16) & 0xFF) - w->viewport->zoom;
					w->viewport->zoom = RCT2_GLOBAL(0x0138869E, sint16) & 0xFF;
					*((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(0x0138869E, sint16) >> 8;
					if (_cl != 0) {
						if (_cl < 0) {
							_cl = -_cl;
							w->viewport->view_width >>= _cl;
							w->viewport->view_height >>= _cl;
						} else {
							w->viewport->view_width <<= _cl;
							w->viewport->view_height <<= _cl;
						}
					}
					w->saved_view_x -= w->viewport->view_width >> 1;
					w->saved_view_y -= w->viewport->view_height >> 1;
				}

				window_invalidate(w);
				sub_69E9A7();
				window_new_ride_init_vars();
				sub_684AC3();
				RCT2_CALLPROC_EBPSAFE(0x006DFEE4);
				news_item_init_queue();
				gfx_invalidate_screen();
				RCT2_GLOBAL(0x009DEA66, sint16) = 0;
				RCT2_GLOBAL(0x009DEA5C, sint16) = 0x0D6D8;
				break;
			case TITLE_SCRIPT_LOCATION:
				x = (*_currentScript++) * 32 + 16;
				y = (*_currentScript++) * 32 + 16;
				z = map_element_height(x, y);

				// Update viewport
				w = window_get_main();
				if (w != NULL) {
					window_scroll_to_location(w, x, y, z);
					w->flags &= ~0x08;
					viewport_update_position(w);
				}
				break;
			case TITLE_SCRIPT_ROTATE:
				script_operand = (*_currentScript++);
				w = window_get_main();
				if (w != NULL)
					for (i = 0; i < script_operand; i++)
						window_rotate_camera(w);
				break;
			case TITLE_SCRIPT_RESTART:
				_currentScript = _magicMountainScript;
				if (gRandomShowcase) {
					if (_currentScript != NULL)
						free((uint8*)_currentScript);
					_currentScript = generate_random_script();
				}
				break;
			}
		} while (_scriptWaitCounter == 0);
Exemplo n.º 8
0
static money32 RideEntranceExitPlace(sint16 x, 
    sint16 y, 
    sint16 z, 
    uint8 direction, 
    uint8 flags, 
    uint8 rideIndex, 
    uint8 stationNum, 
    bool isExit)
{
    // Remember when in Unknown station num mode rideIndex is unknown and z is set
    // When in known station num mode rideIndex is known and z is unknown

    money32 cost = 0;
    gCommandPosition.x = x;
    gCommandPosition.y = y;

    if (!map_check_free_elements_and_reorganise(1)) 
    {
        return MONEY32_UNDEFINED;
    }

    if (!(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) && game_is_paused() && !gCheatsBuildInPauseMode)
    {
        gGameCommandErrorText = STR_CONSTRUCTION_NOT_POSSIBLE_WHILE_GAME_IS_PAUSED;
        return MONEY32_UNDEFINED;
    }

    if (stationNum == 0xFF) 
    {
        z *= 16;
        if (flags & GAME_COMMAND_FLAG_APPLY)
        {
            return MONEY32_UNDEFINED;
        }

        if (!gCheatsSandboxMode && !map_is_location_owned(x, y, z))
        {
            return MONEY32_UNDEFINED;
        }

        sint16 clear_z = z / 8 + (isExit ? 5 : 7);

        if (!gCheatsDisableClearanceChecks && 
            !map_can_construct_with_clear_at(x, y, z / 8, clear_z, &map_place_non_scenery_clear_func, 0xF, flags, &cost))
        {
            return MONEY32_UNDEFINED;
        }

        if (gMapGroundFlags & ELEMENT_IS_UNDERWATER) 
        {
            gGameCommandErrorText = STR_RIDE_CANT_BUILD_THIS_UNDERWATER;
            return MONEY32_UNDEFINED;
        }

        if (z / 8 > 244)
        {
            gGameCommandErrorText = STR_TOO_HIGH;
            return MONEY32_UNDEFINED;
        }
    }
    else
    {
        if (rideIndex >= MAX_RIDES)
        {
            log_warning("Invalid game command for ride %u", rideIndex);
            return MONEY32_UNDEFINED;
        }

        rct_ride* ride = get_ride(rideIndex);
        if (ride->type == RIDE_TYPE_NULL)
        {
            log_warning("Invalid game command for ride %u", rideIndex);
            return MONEY32_UNDEFINED;
        }

        if (ride->status != RIDE_STATUS_CLOSED)
        {
            gGameCommandErrorText = STR_MUST_BE_CLOSED_FIRST;
            return MONEY32_UNDEFINED;
        }

        if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK)
        {
            gGameCommandErrorText = STR_NOT_ALLOWED_TO_MODIFY_STATION;
            return MONEY32_UNDEFINED;
        }

        ride_clear_for_construction(rideIndex);
        ride_remove_peeps(rideIndex);

        bool requiresRemove = false;
        rct_xy16 removeCoord = { 0, 0 };

        if (isExit)
        {
            if (ride->exits[stationNum] != 0xFFFF)
            {
                if (flags & GAME_COMMAND_FLAG_GHOST)
                {
                    gGameCommandErrorText = 0;
                    return MONEY32_UNDEFINED;
                }

                removeCoord.x = (ride->exits[stationNum] & 0xFF) * 32;
                removeCoord.y = ((ride->exits[stationNum] >> 8) & 0xFF) * 32;
                requiresRemove = true;
            }
        }
        else if (ride->entrances[stationNum] != 0xFFFF) 
        {
            if (flags & GAME_COMMAND_FLAG_GHOST)
            {
                gGameCommandErrorText = 0;
                return MONEY32_UNDEFINED;
            }

            removeCoord.x = (ride->entrances[stationNum] & 0xFF) * 32;
            removeCoord.y = ((ride->entrances[stationNum] >> 8) & 0xFF) * 32;
            requiresRemove = true;
        }

        if (requiresRemove)
        {
            money32 success = game_do_command(
                removeCoord.x,
                flags,
                removeCoord.y,
                rideIndex,
                GAME_COMMAND_REMOVE_RIDE_ENTRANCE_OR_EXIT,
                stationNum,
                0
            );

            if (success == MONEY32_UNDEFINED)
            {
                return MONEY32_UNDEFINED;
            }
        }

        z = ride->station_heights[stationNum] * 8;
        gCommandPosition.z = z;

        if ((flags & GAME_COMMAND_FLAG_APPLY) &&
            !(flags & GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED) &&
            !(flags & GAME_COMMAND_FLAG_GHOST))
        {
            footpath_remove_litter(x, y, z);
            wall_remove_at_z(x, y, z);
        }

        if (!gCheatsSandboxMode && !map_is_location_owned(x, y, z))
        {
            return MONEY32_UNDEFINED;
        }

        sint8 clear_z = (z / 8) + (isExit ? 5 : 7);

        if (!gCheatsDisableClearanceChecks && 
            !map_can_construct_with_clear_at(x, y, z / 8, clear_z, &map_place_non_scenery_clear_func, 0xF, flags, &cost))
        {
            return MONEY32_UNDEFINED;
        }

        if (gMapGroundFlags & ELEMENT_IS_UNDERWATER)
        {
            gGameCommandErrorText = STR_RIDE_CANT_BUILD_THIS_UNDERWATER;
            return MONEY32_UNDEFINED;
        }

        if (z / 8 > 244)
        {
            gGameCommandErrorText = STR_TOO_HIGH;
            return MONEY32_UNDEFINED;
        }

        if (flags & GAME_COMMAND_FLAG_APPLY)
        {
            rct_xyz16 coord;
            coord.x = x + 16;
            coord.y = y + 16;
            coord.z = map_element_height(coord.x, coord.y);
            network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord);

            rct_map_element* mapElement = map_element_insert(x / 32, y / 32, z / 8, 0xF);
            assert(mapElement != NULL);
            mapElement->clearance_height = clear_z;
            mapElement->properties.entrance.type = isExit;
            mapElement->properties.entrance.index = stationNum << 4;
            mapElement->properties.entrance.ride_index = rideIndex;
            mapElement->type = MAP_ELEMENT_TYPE_ENTRANCE | direction;

            if (flags & GAME_COMMAND_FLAG_GHOST)
            {
                mapElement->flags |= MAP_ELEMENT_FLAG_GHOST;
            }

            if (isExit)
            {
                ride->exits[stationNum] = (x / 32) | (y / 32 << 8);
            }
            else
            {
                ride->entrances[stationNum] = (x / 32) | (y / 32 << 8);
                ride->last_peep_in_queue[stationNum] = SPRITE_INDEX_NULL;
                ride->queue_length[stationNum] = 0;

                map_animation_create(MAP_ANIMATION_TYPE_RIDE_ENTRANCE, x, y, z / 8);
            }

            footpath_queue_chain_reset();

            if (!(flags & GAME_COMMAND_FLAG_GHOST))
            {
                maze_entrance_hedge_removal(x, y, mapElement);
            }

            footpath_connect_edges(x, y, mapElement, flags);
            sub_6A759F();

            map_invalidate_tile_full(x, y);
        }
    }