Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC vehicle steering indicator & vision #37200

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
tripoint( g->ter_view_p.xy(), center.z ), 0, 0, LL_LIT,
false );
}
if( g->u.controlling_vehicle ) {
if( g->u.controlling_vehicle || g->remoteveh() ) {
if( cata::optional<tripoint> indicator_offset = g->get_veh_dir_indicator_location( true ) ) {
draw_from_id_string( "cursor", C_NONE, empty_string, indicator_offset->xy() + tripoint( g->u.posx(),
g->u.posy(), center.z ),
Expand Down
71 changes: 64 additions & 7 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,31 @@ static int veh_lumi( vehicle &veh )
return LIGHT_RANGE( ( veh_luminance * 3 ) );
}

void game::calc_driving_offset_for_rc( vehicle *veh )
{
if ( veh == nullptr ) {
set_driving_view_offset(point_zero);
return;
}

// due to very limited RC range, no need to adjust driving_view_offset to fit maximum of visible area in game window
tripoint veh_ref_pos = u.pos();
if( g->remoteveh() ) {
if( !( veh->has_part( "CAMERA" ) && g->u.can_view_remote_video() ) ) {
set_driving_view_offset(point_zero);
return;
}

for( const vpart_reference &vp : veh->get_avail_parts( "REMOTE_CONTROLS" ) ) {
veh_ref_pos = vp.pos();
break;
}
}
tripoint offset = veh_ref_pos - u.pos();

set_driving_view_offset(point(offset.x, offset.y));
}

void game::calc_driving_offset( vehicle *veh )
{
if( veh == nullptr || !get_option<bool>( "DRIVING_VIEW_OFFSET" ) ) {
Expand Down Expand Up @@ -1496,8 +1521,12 @@ bool game::do_turn()
// or the option has been deactivated,
// might also happen when someone dives from a moving car.
// or when using the handbrake.
vehicle *veh = veh_pointer_or_null( m.veh_at( u.pos() ) );
calc_driving_offset( veh );
vehicle *veh = g->get_posessed_vehicle( g->u.pos() );
if( !g->remoteveh() ) {
g->calc_driving_offset( veh );
} else {
g->calc_driving_offset_for_rc( veh );
}
}

// No-scent debug mutation has to be processed here or else it takes time to start working
Expand Down Expand Up @@ -3286,27 +3315,55 @@ void game::draw_ter( const tripoint &center, const bool looking, const bool draw
POSY - u.posy() ), c_white, 'X' );
}

if( u.controlling_vehicle && !looking ) {
if( ( u.controlling_vehicle || g->remoteveh() ) && !looking ) {
draw_veh_dir_indicator( false );
draw_veh_dir_indicator( true );
}
// Place the cursor over the player as is expected by screen readers.
wmove( w_terrain, -center.xy() + g->u.pos().xy() + point( POSX, POSY ) );
}


vehicle* game::get_posessed_vehicle( const tripoint &character_location ) const
{
vehicle *veh = nullptr;
// Remote-controlled first. player can sit in one vehicle, and remote-control another
if( g->remoteveh() ) {
veh = g->remoteveh();
} else {
veh = veh_pointer_or_null( m.veh_at( character_location ) );
}
return veh;
}

cata::optional<tripoint> game::get_veh_dir_indicator_location( bool next ) const
{
if( !get_option<bool>( "VEHICLE_DIR_INDICATOR" ) ) {
return cata::nullopt;
}
const optional_vpart_position vp = m.veh_at( u.pos() );
if( !vp ) {

vehicle *const veh = g->get_posessed_vehicle( u.pos() );
if ( !veh )
return cata::nullopt;

tripoint veh_ref_pos = u.pos();
if( g->remoteveh() ) {
if( !( veh->has_part("CAMERA") && g->u.can_view_remote_video() ) ) {
return cata::nullopt;
}

for ( const vpart_reference &vp : veh->get_avail_parts( "REMOTE_CONTROLS" ) ) {
veh_ref_pos = vp.pos();
break;
}
}
vehicle *const veh = &vp->vehicle();

int veh_offset_x = veh_ref_pos.x - u.pos().x;
int veh_offset_y = veh_ref_pos.y - u.pos().y;

rl_vec2d face = next ? veh->dir_vec() : veh->face_vec();
float r = 10.0;
return tripoint( static_cast<int>( r * face.x ), static_cast<int>( r * face.y ), u.pos().z );
return tripoint( static_cast<int>( r * face.x ) + veh_offset_x, static_cast<int>( r * face.y ) + veh_offset_y, veh_ref_pos.z );
}

void game::draw_veh_dir_indicator( bool next )
Expand Down
3 changes: 3 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class game
* instead of the one it is currently facing.
*/
cata::optional<tripoint> get_veh_dir_indicator_location( bool next ) const;
vehicle* get_posessed_vehicle(const tripoint &character_location) const;
void draw_veh_dir_indicator( bool next );

/** Moves the player vertically. If force == true then they are falling. */
Expand Down Expand Up @@ -624,6 +625,8 @@ class game
// the function set the driving offset to (0,0)
void calc_driving_offset( vehicle *veh = nullptr );

void calc_driving_offset_for_rc( vehicle *veh );

/**@}*/

void open_gate( const tripoint &p );
Expand Down
9 changes: 4 additions & 5 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,11 +1141,10 @@ void map::build_seen_cache( const tripoint &origin, const int target_z )
seen_caches, transparency_caches, floor_caches, origin, 0, 1.0 );
}

const optional_vpart_position vp = veh_at( origin );
if( !vp ) {
const bool can_view_remote = static_cast<bool>( g->remoteveh() ) && g->u.can_view_remote_video();
vehicle *const veh = g->get_posessed_vehicle( origin );
if ( !veh )
return;
}
vehicle *const veh = &vp->vehicle();

// We're inside a vehicle. Do mirror calculations.
std::vector<int> mirrors;
Expand All @@ -1171,7 +1170,7 @@ void map::build_seen_cache( const tripoint &origin, const int target_z )

for( int mirror : mirrors ) {
bool is_camera = veh->part_info( mirror ).has_flag( "CAMERA" );
if( is_camera && cam_control < 0 ) {
if( is_camera && cam_control < 0 && !can_view_remote ) {
continue; // Player not at camera control, so cameras don't work
}

Expand Down
9 changes: 7 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,13 @@ vehicle *map::move_vehicle( vehicle &veh, const tripoint &dp, const tileray &fac
}
// If the PC is in the currently moved vehicle, adjust the
// view offset.
if( g->u.controlling_vehicle && veh_pointer_or_null( veh_at( g->u.pos() ) ) == &veh ) {
g->calc_driving_offset( &veh );
if( ( g->u.controlling_vehicle || g->remoteveh() ) && g->get_posessed_vehicle( g->u.pos() ) == &veh ) {
if( !g->remoteveh() ) {
g->calc_driving_offset( &veh );
} else {
g->calc_driving_offset_for_rc( &veh );
}

if( veh.skidding && can_move ) {
// TODO: Make skid recovery in air hard
veh.possibly_recover_from_skid();
Expand Down
6 changes: 6 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3430,6 +3430,12 @@ bool player::can_interface_armor() const
return okay;
}

bool player::can_view_remote_video() const
{
// bio_remote don't provide video feed
return g->u.has_active_item( "remotevehcontrol" );
}

bool player::has_mission_item( int mission_id ) const
{
return mission_id != -1 && has_item_with( has_mission_item_filter{ mission_id } );
Expand Down
2 changes: 2 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ class player : public Character
*/
bool can_interface_armor() const;

bool can_view_remote_video() const;

// Put corpse+inventory on map at the place where this is.
void place_corpse();
// Put corpse+inventory on defined om tile
Expand Down