From a63e6662c055df06e02dc7aa8299d89d3ff1a724 Mon Sep 17 00:00:00 2001 From: ehughsbaird <44244083+ehughsbaird@users.noreply.github.com> Date: Sat, 21 Oct 2023 02:27:41 +0000 Subject: [PATCH] Fix skill rust One line too many was deleted in 88ed29d8227266a8c9631083251a2b70fd40b635, result in skill rust no longer functioning. Restore the accidentally deleted line and add a regression test. --- src/skill.cpp | 1 + tests/skill_test.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/skill_test.cpp diff --git a/src/skill.cpp b/src/skill.cpp index aa096a068eb28..e56b6ecc3a846 100644 --- a/src/skill.cpp +++ b/src/skill.cpp @@ -384,6 +384,7 @@ bool SkillLevel::rust( int rust_resist, float rust_multiplier ) } _rustAccumulator += rust_amount; + _exercise -= rust_amount; on_exercise_change(); return false; diff --git a/tests/skill_test.cpp b/tests/skill_test.cpp new file mode 100644 index 0000000000000..8f81f179b88b3 --- /dev/null +++ b/tests/skill_test.cpp @@ -0,0 +1,44 @@ +#include "calendar.h" +#include "cata_catch.h" +#include "character.h" +#include "player_helpers.h" +#include "skill.h" + +TEST_CASE( "skill_rust_occurs", "[character][skill]" ) +{ + Character &guy = get_player_character(); + clear_avatar(); + + // Set every skill to two, so they can rust + for( const Skill &skill : Skill::skills ) { + INFO( skill.ident().str() ); + guy.set_skill_level( skill.ident(), 2 ); + REQUIRE( guy.get_skill_level( skill.ident() ) == 2.f ); + REQUIRE( guy.get_knowledge_level( skill.ident() ) == 2 ); + REQUIRE_FALSE( guy.get_skill_level_object( skill.ident() ).isRusty() ); + } + + // Wait three days + for( int i = 0; i < to_seconds( 3_days ); ++i ) { + calendar::turn += 1_seconds; + guy.update_body(); + if( calendar::once_every( 4_hours ) ) { + // Don't starve + guy.set_stored_kcal( guy.get_healthy_kcal() ); + // Clear thirst and fatigue + guy.environmental_revert_effect(); + // And sleep deprivation + guy.set_sleep_deprivation( 0 ); + } + } + + // Ensure they have rusted + for( const Skill &skill : Skill::skills ) { + INFO( skill.ident().str() ); + // Rust is about 1% per day with a one day grace period + CHECK( guy.get_skill_level( skill.ident() ) < 2.f ); + CHECK( guy.get_knowledge_level( skill.ident() ) == 2 ); + CHECK( guy.get_skill_level_object( skill.ident() ).isRusty() ); + } +} +