Exemplo n.º 1
0
/**
 *
 *  rct2: 0x006EDE88
 */
sint32 viewport_interaction_get_item_right(sint32 x, sint32 y, viewport_interaction_info *info)
{
    rct_tile_element *tileElement;
    rct_scenery_entry *sceneryEntry;
    rct_banner *banner;
    Ride *ride;
    sint32 i, stationIndex;

    // No click input for title screen or track manager
    if (gScreenFlags & (SCREEN_FLAGS_TITLE_DEMO | SCREEN_FLAGS_TRACK_MANAGER))
        return info->type = VIEWPORT_INTERACTION_ITEM_NONE;

    //
    if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) && gS6Info.editor_step != EDITOR_STEP_ROLLERCOASTER_DESIGNER)
        return info->type = VIEWPORT_INTERACTION_ITEM_NONE;

    LocationXY16 mapCoord = {};
    get_map_coordinates_from_pos(x, y, ~(VIEWPORT_INTERACTION_MASK_TERRAIN & VIEWPORT_INTERACTION_MASK_WATER), &mapCoord.x, &mapCoord.y, &info->type, &info->tileElement, nullptr);
    info->x = mapCoord.x;
    info->y = mapCoord.y;
    tileElement = info->tileElement;

    switch (info->type) {
    case VIEWPORT_INTERACTION_ITEM_SPRITE:
        if ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || tileElement->type != 0)
            return info->type = VIEWPORT_INTERACTION_ITEM_NONE;

        tileElement += 6;
        ride = get_ride(tileElement->type);
        if (ride->status == RIDE_STATUS_CLOSED) {
            set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
            set_map_tooltip_format_arg(2, rct_string_id, ride->name);
            set_map_tooltip_format_arg(4, uint32, ride->name_arguments);
        }
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_RIDE:
        if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
            return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
        if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
            return info->type = VIEWPORT_INTERACTION_ITEM_NONE;

        ride = get_ride(tile_element_get_ride_index(tileElement));
        if (ride->status != RIDE_STATUS_CLOSED)
            return info->type;

        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);

        if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE) {
            rct_string_id stringId;
            if (tileElement->properties.entrance.type == ENTRANCE_TYPE_RIDE_ENTRANCE) {
                if (ride->num_stations > 1) {
                    stringId = STR_RIDE_STATION_X_ENTRANCE;
                } else {
                    stringId = STR_RIDE_ENTRANCE;
                }
            } else {
                if (ride->num_stations > 1) {
                    stringId = STR_RIDE_STATION_X_EXIT;
                } else {
                    stringId = STR_RIDE_EXIT;
                }
            }
            set_map_tooltip_format_arg(2, rct_string_id, stringId);
        } else if (track_element_is_station(tileElement)) {
            rct_string_id stringId;
            if (ride->num_stations > 1) {
                stringId = STR_RIDE_STATION_X;
            } else {
                stringId = STR_RIDE_STATION;
            }
            set_map_tooltip_format_arg(2, rct_string_id, stringId);
        } else {
            if (!gCheatsSandboxMode && !map_is_location_owned(info->x, info->y, tileElement->base_height << 4)) {
                return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
            }

            set_map_tooltip_format_arg(2, rct_string_id, ride->name);
            set_map_tooltip_format_arg(4, uint32, ride->name_arguments);
            return info->type;
        }

        set_map_tooltip_format_arg(4, rct_string_id, ride->name);
        set_map_tooltip_format_arg(6, uint32, ride->name_arguments);
        set_map_tooltip_format_arg(10, rct_string_id, RideComponentNames[RideNameConvention[ride->type].station].capitalised);

        stationIndex = tile_element_get_station(tileElement);
        for (i = stationIndex; i >= 0; i--)
            if (ride->station_starts[i].xy == RCT_XY8_UNDEFINED)
                stationIndex--;
        stationIndex++;
        set_map_tooltip_format_arg(12, uint16, stationIndex);
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_WALL:
        sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
        if (sceneryEntry->wall.scrolling_mode != 255) {
            set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
            set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
            return info->type;
        }
        break;

    case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
        sceneryEntry = get_large_scenery_entry(scenery_large_get_type(tileElement));
        if (sceneryEntry->large_scenery.scrolling_mode != 255) {
            set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
            set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
            return info->type;
        }
        break;

    case VIEWPORT_INTERACTION_ITEM_BANNER:
        banner = &gBanners[tileElement->properties.banner.index];
        sceneryEntry = get_banner_entry(banner->type);

        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_MODIFY);
        set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
        return info->type;
    }

    if (!(input_test_flag(INPUT_FLAG_6)) || !(input_test_flag(INPUT_FLAG_TOOL_ACTIVE))) {
        if (window_find_by_class(WC_RIDE_CONSTRUCTION) == nullptr && window_find_by_class(WC_FOOTPATH) == nullptr) {
            return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
        }
    }

    switch (info->type) {
    case VIEWPORT_INTERACTION_ITEM_SCENERY:
        sceneryEntry = get_small_scenery_entry(tileElement->properties.scenery.type);
        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_FOOTPATH:
        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        set_map_tooltip_format_arg(2, rct_string_id, STR_FOOTPATH_MAP_TIP);
        if (footpath_element_is_queue(tileElement))
            set_map_tooltip_format_arg(2, rct_string_id, STR_QUEUE_LINE_MAP_TIP);
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_FOOTPATH_ITEM:
        sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tileElement));
        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        if (tileElement->flags & TILE_ELEMENT_FLAG_BROKEN) {
            set_map_tooltip_format_arg(2, rct_string_id, STR_BROKEN);
            set_map_tooltip_format_arg(4, rct_string_id, sceneryEntry->name);
        } else {
            set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
        }
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_PARK:
        if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gCheatsSandboxMode)
            break;

        if (tileElement->GetType() != TILE_ELEMENT_TYPE_ENTRANCE)
            break;

        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        set_map_tooltip_format_arg(2, rct_string_id, STR_OBJECT_SELECTION_PARK_ENTRANCE);
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_WALL:
        sceneryEntry = get_wall_entry(tileElement->properties.scenery.type);
        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
        return info->type;

    case VIEWPORT_INTERACTION_ITEM_LARGE_SCENERY:
        sceneryEntry = get_large_scenery_entry(tileElement->properties.scenery.type & 0x3FF);
        set_map_tooltip_format_arg(0, rct_string_id, STR_MAP_TOOLTIP_STRINGID_CLICK_TO_REMOVE);
        set_map_tooltip_format_arg(2, rct_string_id, sceneryEntry->name);
        return info->type;
    }

    return info->type = VIEWPORT_INTERACTION_ITEM_NONE;
}
Exemplo n.º 2
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);
        }
    }