Skip to content

Commit

Permalink
enable barrel swabbing (#73468)
Browse files Browse the repository at this point in the history
* enable barrel swabbing

quick way to prevent rusting

* Update activity_handlers.cpp

* Update toolsets.json

* Update activity_handlers.cpp

* update

* adjustments - made cpp work finally

* Update fixes_gun.json

* Update item.cpp

* fix cpp error

* Update src/activity_handlers.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/item.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/fault.h

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/fault.h

Co-authored-by: anothersimulacrum <[email protected]>

* Update src/activity_handlers.cpp

Co-authored-by: anothersimulacrum <[email protected]>

* Update src/activity_handlers.cpp

Co-authored-by: anothersimulacrum <[email protected]>

* explanation changes

* previously committed suggestions broke the game; I think there must be a reason it was done as a string by the set_variables command immediately prior to the change that I used as a template for my MULTIPLY entry

* fix max/min error I made in my initial upload

* json fix string -> double

* Update data/json/faults/fixes_gun.json

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update src/fault.h

Co-authored-by: anothersimulacrum <[email protected]>

* resolve conflicts in faults.cpp

* Update fault.cpp

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: anothersimulacrum <[email protected]>
  • Loading branch information
3 people authored May 21, 2024
1 parent a81f340 commit 1321414
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
15 changes: 15 additions & 0 deletions data/json/faults/fixes_gun.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
"time_save_profs": { "prof_gun_cleaning": 0.5 },
"time_save_flags": { "EASY_CLEAN": 0.5 }
},
{
"type": "fault_fix",
"id": "mend_gun_fouling_quick",
"name": "Swab gun",
"success_msg": "You quickly swab your %s to remove black powder residue and prevent further corrosion.",
"time": "1 m",
"faults_removed": [ "fault_gun_blackpowder" ],
"faults_added": [ "fault_gun_blackpowder" ],
"skills": { "mechanics": 1 },
"set_variables": { "rust_timer": "0" },
"adjust_variables_multiply": { "dirt": 0.8 },
"requirements": [ [ "gun_cleaning_quick", 1 ] ],
"time_save_profs": { "prof_gun_cleaning": 0.5 },
"time_save_flags": { "EASY_CLEAN": 0.5 }
},
{
"type": "fault_fix",
"id": "mend_gun_fouling_clean_and_lube",
Expand Down
7 changes: 7 additions & 0 deletions data/json/requirements/toolsets.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
[ [ "cotton_patchwork", 1 ], [ "fur", 1 ], [ "faux_fur", 1 ], [ "felt_patch", 1 ], [ "cotton_ball", 2 ] ]
]
},
{
"id": "gun_cleaning_quick",
"type": "requirement",
"//": "Requires a rod/wire and cloth patch or similar item.",
"tools": [ [ [ "pipe_cleaner", -1 ], [ "small_repairkit", -1 ], [ "large_repairkit", -1 ] ] ],
"components": [ [ [ "cotton_patchwork", 1 ], [ "fur", 1 ], [ "faux_fur", 1 ], [ "felt_patch", 1 ], [ "cotton_ball", 2 ] ] ]
},
{
"id": "gun_lubrication",
"type": "requirement",
Expand Down
1 change: 1 addition & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ Fault fixes are methods to fix faults, the fixes can optionally add other faults
"faults_added": [ "fault_gun_unlubricated" ], // faults added when fix is applied
"skills": { "mechanics": 1 }, // skills required to apply fix
"set_variables": { "dirt": "0" }, // sets the variables on the item when fix is applied
"adjust_variables_multiply": { "dirt": ".8" }, // adjusts the variables on the item when fix is applied using MULTIPLICATION
"requirements": [ [ "gun_cleaning", 1 ] ], // requirements array, see below
"mod_damage": 1000, // damage to modify on item when fix is applied, can be negative to repair
"mod_degradation": 50, // degradation to modify on item when fix is applied, can be negative to reduce degradation
Expand Down
5 changes: 5 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,11 @@ void activity_handlers::mend_item_finish( player_activity *act, Character *you )
for( const auto &[var_name, var_value] : fix.set_variables ) {
target.set_var( var_name, var_value );
}
for( const auto &[var_name, var_value] : fix.adjust_variables_multiply ) {
const double var_value_multiplier = var_value;
const double var_oldvalue = target.get_var( var_name, 0.0 );
target.set_var( var_name, std::round( var_oldvalue * var_value_multiplier ) );
}

const std::string start_durability = target.durability_indicator( true );

Expand Down
2 changes: 2 additions & 0 deletions src/fault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ const requirement_data &fault_fix::get_requirements() const

void fault_fix::load( const JsonObject &jo, std::string_view )
{
fault_fix f;
mandatory( jo, was_loaded, "name", name );
optional( jo, was_loaded, "success_msg", success_msg );
optional( jo, was_loaded, "time", time );
optional( jo, was_loaded, "set_variables", set_variables );
optional( jo, was_loaded, "adjust_variables_multiply", adjust_variables_multiply );
optional( jo, was_loaded, "skills", skills );
optional( jo, was_loaded, "faults_removed", faults_removed );
optional( jo, was_loaded, "faults_added", faults_added );
Expand Down
2 changes: 2 additions & 0 deletions src/fault.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class fault_fix
translation success_msg; // message to print on applying successfully
time_duration time = 0_seconds;
std::map<std::string, std::string> set_variables; // item vars applied to item
// item vars adjustment(s) applied to item via multiplication; // item vars adjustment(s) applied to item via multiplication
std::map<std::string, double> adjust_variables_multiply;
std::map<skill_id, int> skills; // map of skill_id to required level
std::set<fault_id> faults_removed; // which faults are removed on applying
std::set<fault_id> faults_added; // which faults are added on applying
Expand Down
7 changes: 4 additions & 3 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14025,9 +14025,10 @@ bool item::process_tool( Character *carrier, const tripoint &pos )

bool item::process_blackpowder_fouling( Character *carrier )
{
// rust is deterministic. 12 hours for first rust, then 24 (36 total), then 36 (72 total) and finally 48 (120 hours to go to XX)
// this speeds up by the amount the gun is dirty, 2-6x as fast depending on dirt level.
set_var( "rust_timer", get_var( "rust_timer", 0 ) + 1 + get_var( "dirt", 0 ) / 2000 );
// Rust is deterministic. At a total modifier of 1 (the max): 12 hours for first rust, then 24 (36 total), then 36 (72 total) and finally 48 (120 hours to go to XX)
// this speeds up by the amount the gun is dirty, 2-6x as fast depending on dirt level. At minimum dirt, the modifier is 0.3x the speed of the above mentioned figures.
set_var( "rust_timer", get_var( "rust_timer", 0 ) + std::min( 0.3 + get_var( "dirt", 0 ) / 200,
1.0 ) );
double time_mult = 1.0 + ( 4.0 * static_cast<double>( damage() ) ) / static_cast<double>
( max_damage() );
if( damage() < max_damage() && get_var( "rust_timer", 0 ) > 43200.0 * time_mult ) {
Expand Down

0 comments on commit 1321414

Please sign in to comment.