From 9b2c3314784bf7c287e900142e1b0733e3b602b1 Mon Sep 17 00:00:00 2001 From: ZhilkinSerg Date: Wed, 24 Apr 2019 03:04:36 +0300 Subject: [PATCH 1/5] Added toggleable auto travel mode Allow faster traversing of maps with automatic obstacle avoiding --- data/raw/keybindings.json | 7 +++ src/action.cpp | 27 ++++++++ src/action.h | 8 ++- src/enums.h | 9 +++ src/game.cpp | 1 + src/game.h | 7 +++ src/handle_action.cpp | 127 ++++++++++++++------------------------ src/savegame.cpp | 2 + 8 files changed, 108 insertions(+), 80 deletions(-) diff --git a/data/raw/keybindings.json b/data/raw/keybindings.json index f7e7f9a2bb180..bdb8c6ab78c66 100644 --- a/data/raw/keybindings.json +++ b/data/raw/keybindings.json @@ -1696,6 +1696,13 @@ "id": "control_vehicle", "bindings": [ { "input_method": "keyboard", "key": "^" } ] }, + { + "type": "keybinding", + "name": "Toggle Auto Travel Mode", + "category": "DEFAULTMODE", + "id": "auto_travel_mode", + "bindings": [ { "input_method": "keyboard", "key": "" } ] + }, { "type": "keybinding", "name": "Toggle Safe Mode", diff --git a/src/action.cpp b/src/action.cpp index 0bec9049507c5..363f543a09168 100644 --- a/src/action.cpp +++ b/src/action.cpp @@ -253,6 +253,8 @@ std::string action_ident( action_id act ) return "sleep"; case ACTION_CONTROL_VEHICLE: return "control_vehicle"; + case ACTION_TOGGLE_AUTO_TRAVEL_MODE: + return "auto_travel_mode"; case ACTION_TOGGLE_SAFEMODE: return "safemode"; case ACTION_TOGGLE_AUTOSAFE: @@ -486,6 +488,30 @@ action_id get_movement_direction_from_delta( const int dx, const int dy, const i } } +point get_delta_from_movement_direction( action_id act ) +{ + switch( act ) { + case ACTION_MOVE_N: + return point_north; + case ACTION_MOVE_NE: + return point_north_east; + case ACTION_MOVE_E: + return point_east; + case ACTION_MOVE_SE: + return point_south_east; + case ACTION_MOVE_S: + return point_south; + case ACTION_MOVE_SW: + return point_south_west; + case ACTION_MOVE_W: + return point_west; + case ACTION_MOVE_NW: + return point_north_west; + default: + return point_zero; + } +} + // Get the key for an action, used in the action menu to give each action the // hotkey it is bound to. // We ignore bindings to '?' because that will already do something else in @@ -772,6 +798,7 @@ action_id handle_action_menu() REGISTER_ACTION( ACTION_THROW ); REGISTER_ACTION( ACTION_FIRE_BURST ); REGISTER_ACTION( ACTION_PICK_STYLE ); + REGISTER_ACTION( ACTION_TOGGLE_AUTO_TRAVEL_MODE ); REGISTER_ACTION( ACTION_TOGGLE_SAFEMODE ); REGISTER_ACTION( ACTION_TOGGLE_AUTOSAFE ); REGISTER_ACTION( ACTION_IGNORE_ENEMY ); diff --git a/src/action.h b/src/action.h index b413e24a3e5fe..4d467b3504b31 100644 --- a/src/action.h +++ b/src/action.h @@ -14,6 +14,7 @@ template class optional; } // namespace cata struct tripoint; +struct point; /** * Enumerates all discrete actions that can be performed by player @@ -190,6 +191,8 @@ enum action_id : int { ACTION_SLEEP, /** Open vehicle control menu */ ACTION_CONTROL_VEHICLE, + /** Turn auto travel mode on/off */ + ACTION_TOGGLE_AUTO_TRAVEL_MODE, /** Turn safemode on/off, while leaving autosafemode intact */ ACTION_TOGGLE_SAFEMODE, /** Turn automatic triggering of safemode on/off */ @@ -482,7 +485,7 @@ std::string press_x( action_id act, const std::string &key_bound_pre, // ('Z'ing|zing) (X( or Y))) std::string press_x( action_id act, const std::string &act_desc ); -// Helper function to convert co-ordinate delta to a movement direction +// Helper function to convert coordinate delta to a movement direction /** * Translate coordinate delta into movement direction * @@ -505,6 +508,9 @@ std::string press_x( action_id act, const std::string &act_desc ); */ action_id get_movement_direction_from_delta( const int dx, const int dy, const int dz = 0 ); +// Helper function to convert movement direction to coordinate delta point +point get_delta_from_movement_direction( action_id act ); + /** * Show the action menu * diff --git a/src/enums.h b/src/enums.h index 3ae01fbc19fb9..f7d199949a314 100644 --- a/src/enums.h +++ b/src/enums.h @@ -337,6 +337,15 @@ static constexpr point point_min{ tripoint_min.x, tripoint_min.y }; static constexpr point point_zero{ tripoint_zero.x, tripoint_zero.y }; static constexpr point point_max{ tripoint_max.x, tripoint_max.y }; +static constexpr point point_north{ 0, -1 }; +static constexpr point point_north_east{ 1, -1 }; +static constexpr point point_east{ 1, 0 }; +static constexpr point point_south_east{ 1, 1 }; +static constexpr point point_south{ 0, 1 }; +static constexpr point point_south_west{ -1, 1 }; +static constexpr point point_west{ -1, 0 }; +static constexpr point point_north_west{ -1, -1 }; + static constexpr box box_zero( tripoint_zero, tripoint_zero ); static constexpr rectangle rectangle_zero( point_zero, point_zero ); diff --git a/src/game.cpp b/src/game.cpp index 53ad4da2cc7b3..6d7c5a7512f72 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2281,6 +2281,7 @@ input_context get_default_mode_input_context() ctxt.register_action( "disassemble" ); ctxt.register_action( "sleep" ); ctxt.register_action( "control_vehicle" ); + ctxt.register_action( "auto_travel_mode" ); ctxt.register_action( "safemode" ); ctxt.register_action( "autosafe" ); ctxt.register_action( "autoattack" ); diff --git a/src/game.h b/src/game.h index 63d7d798d5a60..af863b881130c 100644 --- a/src/game.h +++ b/src/game.h @@ -951,6 +951,12 @@ class game // Standard movement; handles attacks, traps, &c. Returns false if auto move // should be canceled bool plmove( int dx, int dy, int dz = 0 ); + inline bool plmove( tripoint d ) { + return plmove( d.x, d.y, d.z ); + } + inline bool plmove( point d ) { + return plmove( d.x, d.y ); + } // Handle pushing during move, returns true if it handled the move bool grabbed_move( const tripoint &dp ); bool grabbed_veh_move( const tripoint &dp ); @@ -1108,6 +1114,7 @@ class game // ########################## DATA ################################ public: + bool auto_travel_mode = false; safe_mode_type safe_mode; int turnssincelastmon; // needed for auto run mode bool debug_pathfinding = false; // show NPC pathfinding on overmap ui diff --git a/src/handle_action.cpp b/src/handle_action.cpp index 6c009f3a8726a..1b58cca91e0a0 100644 --- a/src/handle_action.cpp +++ b/src/handle_action.cpp @@ -375,6 +375,11 @@ static void rcdrive( int dx, int dy ) } } +inline static void rcdrive( point d ) +{ + return rcdrive( d.x, d.y ); +} + static void pldrive( int x, int y ) { if( !g->check_safe_mode_allowed() ) { @@ -414,6 +419,11 @@ static void pldrive( int x, int y ) veh->pldrive( x, y ); } +inline static void pldrive( point d ) +{ + return pldrive( d.x, d.y ); +} + static void open() { player &u = g->u; @@ -1410,6 +1420,7 @@ bool game::handle_action() // actions allowed only while alive if( !u.is_dead_state() ) { + point dest_delta; switch( act ) { case ACTION_NULL: case NUM_ACTIONS: @@ -1435,93 +1446,15 @@ bool game::handle_action() break; case ACTION_MOVE_N: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( 0, -1 ); - } else if( veh_ctrl ) { - pldrive( 0, -1 ); - } else { - continue_auto_move = plmove( 0, -1 ); - } - break; - case ACTION_MOVE_NE: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( 1, -1 ); - } else if( veh_ctrl ) { - pldrive( 1, -1 ); - } else { - continue_auto_move = plmove( 1, -1 ); - } - break; - case ACTION_MOVE_E: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( 1, 0 ); - } else if( veh_ctrl ) { - pldrive( 1, 0 ); - } else { - continue_auto_move = plmove( 1, 0 ); - } - break; - case ACTION_MOVE_SE: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( 1, 1 ); - } else if( veh_ctrl ) { - pldrive( 1, 1 ); - } else { - continue_auto_move = plmove( 1, 1 ); - } - break; - case ACTION_MOVE_S: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( 0, 1 ); - } else if( veh_ctrl ) { - pldrive( 0, 1 ); - } else { - continue_auto_move = plmove( 0, 1 ); - } - break; - case ACTION_MOVE_SW: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( -1, 1 ); - } else if( veh_ctrl ) { - pldrive( -1, 1 ); - } else { - continue_auto_move = plmove( -1, 1 ); - } - break; - case ACTION_MOVE_W: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( -1, 0 ); - } else if( veh_ctrl ) { - pldrive( -1, 0 ); - } else { - continue_auto_move = plmove( -1, 0 ); - } - break; - case ACTION_MOVE_NW: - if( !( u.get_value( "remote_controlling" ).empty() ) && ( ( u.has_active_item( "radiocontrol" ) ) || - ( u.has_active_bionic( bio_remote ) ) ) ) { - rcdrive( -1, -1 ); - } else if( veh_ctrl ) { - pldrive( -1, -1 ); - } else { - continue_auto_move = plmove( -1, -1 ); - } + dest_delta = get_delta_from_movement_direction( act ); break; - case ACTION_MOVE_DOWN: if( !u.in_vehicle ) { vertical_move( -1, false ); @@ -1826,6 +1759,11 @@ bool game::handle_action() } break; + case ACTION_TOGGLE_AUTO_TRAVEL_MODE: + auto_travel_mode = !auto_travel_mode; + add_msg( m_info, auto_travel_mode ? _( "Auto travel mode ON!" ) : _( "Auto travel mode OFF!" ) ); + break; + case ACTION_TOGGLE_SAFEMODE: if( safe_mode == SAFE_MODE_OFF ) { set_safe_mode( SAFE_MODE_ON ); @@ -2082,6 +2020,37 @@ bool game::handle_action() default: break; } + if( dest_delta != point_zero ) { + if( !u.get_value( "remote_controlling" ).empty() && + ( u.has_active_item( "radiocontrol" ) || u.has_active_bionic( bio_remote ) ) ) { + rcdrive( dest_delta ); + } else if( veh_ctrl ) { + pldrive( dest_delta ); + } else { + if( auto_travel_mode ) { + for( int i = 0; i < SEEX; i++ ) { + tripoint auto_travel_destination( u.posx() + dest_delta.x * ( SEEX - i ), + u.posy() + dest_delta.y * ( SEEX - i ), + u.posz() ); + destination_preview = m.route( u.pos(), + auto_travel_destination, + u.get_pathfinding_settings(), + u.get_path_avoid() ); + if( !destination_preview.empty() ) { + u.set_destination( destination_preview ); + break; + } + } + act = u.get_next_auto_move_direction(); + point dest_next = get_delta_from_movement_direction( act ); + if( dest_next == point_zero ) { + u.clear_destination(); + } + dest_delta = dest_next; + } + continue_auto_move = plmove( dest_delta ); + } + } } if( !continue_auto_move ) { u.clear_destination(); diff --git a/src/savegame.cpp b/src/savegame.cpp index 666585541e0c8..494d5a36d4855 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -74,6 +74,7 @@ void game::serialize( std::ostream &fout ) json.member( "turn", static_cast( calendar::turn ) ); json.member( "calendar_start", static_cast( calendar::start ) ); json.member( "initial_season", static_cast( calendar::initial_season ) ); + json.member( "auto_travel_mode", auto_travel_mode ); json.member( "run_mode", static_cast( safe_mode ) ); json.member( "mostseen", mostseen ); // current map coordinates @@ -186,6 +187,7 @@ void game::unserialize( std::istream &fin ) data.read( "calendar_start", tmpcalstart ); calendar::initial_season = static_cast( data.get_int( "initial_season", static_cast( SPRING ) ) ); + data.read( "auto_travel_mode", auto_travel_mode ); data.read( "run_mode", tmprun ); data.read( "mostseen", mostseen ); data.read( "levx", levx ); From ade8c57c5ffd98e19ac1aede58193ef3e2e79253 Mon Sep 17 00:00:00 2001 From: MrHrulgin <6834262+MrHrulgin@users.noreply.github.com> Date: Wed, 1 May 2019 22:51:18 -0700 Subject: [PATCH 2/5] Added recipe for frostie_wheel The description already exists, there are items in the vehicle installation list that require it, but there's no recipe. I added the recipe, matching water demands to the highest tier of wheel and skill requirements to other gelacier-based items. --- data/mods/blazemod/blaze_blob_recipes.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/data/mods/blazemod/blaze_blob_recipes.json b/data/mods/blazemod/blaze_blob_recipes.json index 6fb08165efce8..35915b7cd5cf9 100644 --- a/data/mods/blazemod/blaze_blob_recipes.json +++ b/data/mods/blazemod/blaze_blob_recipes.json @@ -202,6 +202,18 @@ [ [ "mutagen", 3 ], [ "iv_mutagen", 1 ] ] ] }, + { + "result": "frostie_wheel", + "type": "recipe", + "category": "CC_OTHER", + "subcategory": "CSC_OTHER_MATERIALS", + "skill_used": "cooking", + "difficulty": 8, + "time": 15000, + "reversible": true, + "autolearn": true, + "components": [ [ [ "frostie", 1 ] ], [ [ "water", 200 ] ] ] + }, { "result": "fuzzlegrow", "type": "recipe", From afbea06d3e23384eeb4b7a7fe6a5b691be2dd24e Mon Sep 17 00:00:00 2001 From: Inglonias <2125926+Inglonias@users.noreply.github.com> Date: Thu, 2 May 2019 12:01:49 -0400 Subject: [PATCH 3/5] Swimmers have a 10% chance to drop cash. --- data/json/monster_drops.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/monster_drops.json b/data/json/monster_drops.json index dfafb1f7553db..add0145b60163 100644 --- a/data/json/monster_drops.json +++ b/data/json/monster_drops.json @@ -191,7 +191,7 @@ } ] }, - { "item": "cash_card", "charges-min": 0, "charges-max": 50000 } + { "item": "cash_card", "charges-min": 0, "charges-max": 50000, "prob": 10 } ] }, { From 263401dfbfb4be2de6d7d41b167d323a6ec77d79 Mon Sep 17 00:00:00 2001 From: Kevin Granade Date: Thu, 2 May 2019 17:49:50 -0700 Subject: [PATCH 4/5] Handle negative numbers correctly in rng --- src/rng.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rng.cpp b/src/rng.cpp index f29c908e15794..490a87a145913 100644 --- a/src/rng.cpp +++ b/src/rng.cpp @@ -46,7 +46,7 @@ bool one_in( int chance ) bool x_in_y( double x, double y ) { - return rng_float( 0, y ) <= x; + return rng_float( 0.0, 1.0 ) <= x / y; } int dice( int number, int sides ) @@ -64,8 +64,10 @@ int roll_remainder( double value ) { double integ; double frac = modf( value, &integ ); - if( value > integ && x_in_y( frac, 1.0 ) ) { + if( value > 0.0 && value > integ && x_in_y( frac, 1.0 ) ) { integ++; + } else if( value < 0.0 && value < integ && x_in_y( -frac, 1.0 ) ) { + integ--; } return integ; From 02920dbebc2563b4b91c8d318da842ab685edf96 Mon Sep 17 00:00:00 2001 From: eso Date: Thu, 2 May 2019 18:20:17 -0700 Subject: [PATCH 5/5] Correct check for warmth from sunlight --- src/player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 756442d277037..1b331522198aa 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1163,8 +1163,8 @@ void player::update_bodytemp() -1.5f * get_fatigue() ) ); // Sunlight - const int sunlight_warmth = g->is_in_sunlight( pos() ) ? 0 : - ( g->weather == WEATHER_SUNNY ? 1000 : 500 ); + const int sunlight_warmth = g->is_in_sunlight( pos() ) ? ( g->weather == WEATHER_SUNNY ? 1000 : + 500 ) : 0; const int best_fire = get_heat_radiation( pos(), true ); const int lying_warmth = use_floor_warmth ? floor_warmth( pos() ) : 0;