From b85c65bac2b709676f4dc5fc5635ad997dc72fb7 Mon Sep 17 00:00:00 2001 From: anothersimulacrum <42699974+anothersimulacrum@users.noreply.github.com> Date: Tue, 5 May 2020 23:23:03 -0700 Subject: [PATCH] Add flags to prevent modification of vehicle parts --- data/json/vehicleparts/rotor.json | 14 +------------- doc/JSON_FLAGS.md | 3 +++ src/veh_interact.cpp | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/data/json/vehicleparts/rotor.json b/data/json/vehicleparts/rotor.json index a9fd7eb4caab7..c61122327dd8a 100644 --- a/data/json/vehicleparts/rotor.json +++ b/data/json/vehicleparts/rotor.json @@ -7,7 +7,7 @@ "color": "light_blue", "broken_symbol": "O", "broken_color": "light_gray", - "flags": [ "ROTOR" ], + "flags": [ "ROTOR", "NO_INSTALL_PLAYER", "NO_UNINSTALL", "NO_REPAIR" ], "description": "A set of aerofoil helicopter rotors, when spun at high speed, they generate thrust via lift." }, { @@ -18,12 +18,6 @@ "item": "heavy_duty_military_rotor", "//": "rotor diameter is in meters", "rotor_diameter": 15, - "//": "difficulty is artificially high to prevent homemade helicopters - for the moment", - "requirements": { - "install": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "welding_standard", 20 ] ] }, - "removal": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "vehicle_weld_removal", 4 ] ] }, - "repair": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "welding_standard", 20 ] ] } - }, "durability": 450, "description": "A set of four military-grade helicopter rotor blades, used to provide lift by rotation.", "damage_modifier": 80, @@ -38,12 +32,6 @@ "item": "small_helicopter_rotor", "//": "rotor diameter is in meters", "rotor_diameter": 8, - "//": "difficulty is artificially high to prevent homemade helicopters - for the moment", - "requirements": { - "install": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "welding_standard", 20 ] ] }, - "removal": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "vehicle_weld_removal", 4 ] ] }, - "repair": { "skills": [ [ "mechanics", 30 ] ], "time": "2 h", "using": [ [ "welding_standard", 20 ] ] } - }, "durability": 100, "description": "A set of four military-grade helicopter rotor blades, used to provide lift by rotation.", "damage_modifier": 80, diff --git a/doc/JSON_FLAGS.md b/doc/JSON_FLAGS.md index 97a8e86e8708a..96b4c489ce610 100644 --- a/doc/JSON_FLAGS.md +++ b/doc/JSON_FLAGS.md @@ -1384,6 +1384,9 @@ Those flags are added by the game code to specific items (that specific welder, - ```NAILABLE``` Attached with nails - ```NEEDS_BATTERY_MOUNT``` - ```NOINSTALL``` Cannot be installed. +- ```NO_INSTALL_PLAYER``` Cannot be installed by a player, but can be installed on vehicles. +- ```NO_UNINSTALL``` Cannot be unintalled +- ```NO_REPAIR``` Cannot be repaired - ```NO_JACK``` - ```OBSTACLE``` Cannot walk through part, unless the part is also ```OPENABLE```. - ```ODDTURN``` Only on during odd turns. diff --git a/src/veh_interact.cpp b/src/veh_interact.cpp index e8aa26b8dc740..682763fc18d88 100644 --- a/src/veh_interact.cpp +++ b/src/veh_interact.cpp @@ -674,6 +674,15 @@ bool veh_interact::can_install_part() if( is_drive_conflict() ) { return false; } + if( sel_vpart_info->has_flag( "NO_INSTALL_PLAYER" ) ) { + werase( w_msg ); + // NOLINTNEXTLINE(cata-use-named-point-constants) + fold_and_print( w_msg, point( 1, 0 ), getmaxx( w_msg ) - 2, c_light_red, + _( "This part cannot be installed.\n" ) ); + wrefresh( w_msg ); + return false; + } + if( sel_vpart_info->has_flag( "FUNNEL" ) ) { if( std::none_of( parts_here.begin(), parts_here.end(), [&]( const int e ) { return veh->parts[e].is_tank(); @@ -1180,11 +1189,12 @@ bool veh_interact::do_repair( std::string &msg ) if( pt.is_broken() ) { ok = format_reqs( nmsg, vp.install_requirements(), vp.install_skills, vp.install_time( g->u ) ); } else { - if( !vp.repair_requirements().is_empty() && pt.base.max_damage() > 0 ) { + if( !vp.has_flag( "NO_REPAIR" ) && !vp.repair_requirements().is_empty() && + pt.base.max_damage() > 0 ) { ok = format_reqs( nmsg, vp.repair_requirements() * pt.base.damage_level( 4 ), vp.repair_skills, vp.repair_time( g->u ) * pt.base.damage() / pt.base.max_damage() ); } else { - nmsg += colorize( _( "This part cannot be repaired" ), c_light_red ); + nmsg += colorize( _( "This part cannot be repaired.\n" ), c_light_red ); ok = false; } } @@ -1718,6 +1728,15 @@ bool veh_interact::can_remove_part( int idx, const player &p ) sel_vpart_info = &sel_vehicle_part->info(); std::string msg; + if( sel_vpart_info->has_flag( "NO_UNINSTALL" ) ) { + werase( w_msg ); + // NOLINTNEXTLINE(cata-use-named-point-constants) + fold_and_print( w_msg, point( 1, 0 ), getmaxx( w_msg ) - 2, c_light_red, + _( "This part cannot be uninstalled.\n" ) ); + wrefresh( w_msg ); + return false; + } + if( sel_vehicle_part->is_broken() ) { msg += string_format( _( "Removing the broken %1$s may yield some fragments.\n" ),