Skip to content

Commit

Permalink
Consumption modifiers, tests (#73827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Venera3 authored May 17, 2024
1 parent 554b537 commit c3b29e0
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 5 deletions.
11 changes: 9 additions & 2 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
"hit_size": 0.5,
"hit_difficulty": 1.15,
"limb_type": "mouth",
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ] ],
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ], [ "consume_liquid", 1.0 ], [ "consume_solid", 1.0 ] ],
"side": "both",
"legacy_id": "MOUTH",
"stylish_bonus": 2,
Expand Down Expand Up @@ -869,7 +869,14 @@
"main_part": "debug_tail",
"hit_difficulty": 0.8,
"limb_type": "tail",
"limb_scores": [ [ "manip", 0.5, 1.0 ], [ "balance", 1.0 ], [ "swim", 0.15 ], [ "lift", 2 ], [ "block", 5 ] ],
"limb_scores": [
[ "manip", 0.5, 1.0 ],
[ "balance", 1.0 ],
[ "swim", 0.15 ],
[ "lift", 2 ],
[ "block", 5 ],
[ "consume_solid", 10.0 ]
],
"opposite_part": "debug_tail",
"side": "both",
"connected_to": "torso",
Expand Down
14 changes: 14 additions & 0 deletions data/json/character_modifiers.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
"mod_type": "x",
"value": { "limb_score": [ [ "grip", 0.2 ], [ "manip", 0.2 ], [ "lift", 0.6 ] ], "limb_score_op": "+", "min": 0.1, "max": 1.0 }
},
{
"type": "character_mod",
"id": "solid_consume_mod",
"description": "Consume time multiplier for solid foods.",
"mod_type": "x",
"value": { "limb_score": "consume_solid", "max": 10, "nominator": 1.0 }
},
{
"type": "character_mod",
"id": "liquid_consume_mod",
"description": "Consume time multiplier for drinks.",
"mod_type": "x",
"value": { "limb_score": "consume_liquid", "max": 10, "nominator": 1.0 }
},
{
"type": "character_mod",
"id": "melee_thrown_move_lift_mod",
Expand Down
14 changes: 14 additions & 0 deletions data/json/limb_scores.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@
"affected_by_wounds": true,
"affected_by_encumb": true
},
{
"type": "limb_score",
"id": "consume_solid",
"name": "Consume (Solid)",
"affected_by_encumb": false,
"affected_by_wounds": true
},
{
"type": "limb_score",
"id": "consume_liquid",
"name": "Consume (Liquid)",
"affected_by_encumb": false,
"affected_by_wounds": true
},
{
"type": "limb_score",
"id": "swim",
Expand Down
4 changes: 2 additions & 2 deletions data/mods/TEST_DATA/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "mouth",
"similar_bodyparts": [ "test_corvid_beak" ],
"limb_type": "mouth",
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ] ]
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ], [ "consume_liquid", 1.0 ], [ "consume_solid", 1.0 ] ]
},
{
"type": "sub_body_part",
Expand Down Expand Up @@ -121,7 +121,7 @@
"hit_size": 0.5,
"hit_difficulty": 1.15,
"limb_types": [ [ "mouth", 1.0 ], [ "hand", 0.1 ] ],
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ] ],
"limb_scores": [ [ "breathing", 1.0 ], [ "manip", 0.05, 0.2 ], [ "consume_liquid", 0.5 ], [ "consume_solid", 2.0 ] ],
"side": "both",
"stylish_bonus": 2,
"hot_morale_mod": 2,
Expand Down
4 changes: 3 additions & 1 deletion doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ An array of effects to add whenever the limb in question takes damage. Variables
```

### Limb scores
Limb scores act as the basis of calculating the effect of limb encumbrance and damage on the abilities of characters. They are defined using the `"limb_score"` type:
Limb scores act as the basis of calculating the effect of limb encumbrance and damage on the abilities of characters. Most limb scores affect the character via `character_modifiers`, for further information see there. They are defined using the `"limb_score"` type:

```json
{
Expand All @@ -1178,6 +1178,8 @@ Here are the currently defined limb scores:

| Limb score id | Description
|------ |------
| `consume_liquid` | Speed modifier when consuming liquids.
| `consume_solid` | Speed multiplier when consuming solids.
| `manipulator_score` | Modifies aim speed, reload speed, thrown attack speed, ranged dispersion and crafting speed. The manipulator scores of each limb type are aggregated and the best limb group is chosen for checks.
| `manipulator_max` | The upper limit of manipulator score the limb can contribute to.
| `lifting_score` | Modifies melee attack stamina and move cost, as well as a number of STR checks. A sum above 0.5 qualifies for wielding two-handed weapons and similar checks. Arms below 0.1 lift score don't count as working for the purposes of melee combat.
Expand Down
8 changes: 8 additions & 0 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ static const bionic_id bio_faulty_grossfood( "bio_faulty_grossfood" );
static const bionic_id bio_syringe( "bio_syringe" );
static const bionic_id bio_taste_blocker( "bio_taste_blocker" );

static const character_modifier_id character_modifier_liquid_consume_mod( "liquid_consume_mod" );
static const character_modifier_id character_modifier_solid_consume_mod( "solid_consume_mod" );

static const efftype_id effect_bloodworms( "bloodworms" );
static const efftype_id effect_brainworms( "brainworms" );
static const efftype_id effect_common_cold( "common_cold" );
Expand Down Expand Up @@ -1724,10 +1727,12 @@ time_duration Character::get_consume_time( const item &it ) const
time = time_duration::from_seconds( volume / 5 ); //Eat 5 mL (1 teaspoon) per second
consume_time_modifier = enchantment_cache->modify_value( enchant_vals::mod::CONSUME_TIME_MOD,
consume_time_modifier );
consume_time_modifier *= get_modifier( character_modifier_solid_consume_mod );
} else if( !eat_verb && comest_type == "DRINK" ) {
time = time_duration::from_seconds( volume / 15 ); //Drink 15 mL (1 tablespoon) per second
consume_time_modifier = enchantment_cache->modify_value( enchant_vals::mod::CONSUME_TIME_MOD,
consume_time_modifier );
consume_time_modifier *= get_modifier( character_modifier_liquid_consume_mod );
} else if( use_function const *fun = it.type->get_use( "heal" ) ) {
time = time_duration::from_moves( dynamic_cast<heal_actor const *>
( fun->get_actor_ptr() )->move_cost );
Expand Down Expand Up @@ -1765,6 +1770,9 @@ time_duration Character::get_consume_time( const item &it ) const
1 ) ); //Consume 15 mL (1 tablespoon) per second
consume_time_modifier = enchantment_cache->modify_value( enchant_vals::mod::CONSUME_TIME_MOD,
consume_time_modifier );
consume_time_modifier *= it.made_of_from_type( phase_id::LIQUID ) ? get_modifier(
character_modifier_liquid_consume_mod ) :
consume_time_modifier *= get_modifier( character_modifier_solid_consume_mod );

Check failure on line 1775 in src/consumption.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Although the value stored to 'consume_time_modifier' is used in the enclosing expression, the value is never actually read from 'consume_time_modifier' [clang-analyzer-deadcode.DeadStores,-warnings-as-errors]
}

// Minimum consumption time, without mutations, is always 1 second.
Expand Down
21 changes: 21 additions & 0 deletions tests/limb_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ static const bodypart_str_id body_part_test_bird_wing_r( "test_bird_wing_r" );
static const bodypart_str_id body_part_test_corvid_beak( "test_corvid_beak" );
static const bodypart_str_id body_part_test_lizard_tail( "test_lizard_tail" );

static const character_modifier_id character_modifier_liquid_consume_mod( "liquid_consume_mod" );
static const character_modifier_id character_modifier_solid_consume_mod( "solid_consume_mod" );

static const efftype_id effect_mending( "mending" );
static const efftype_id effect_winded_arm_r( "winded_arm_r" );

Expand Down Expand Up @@ -200,6 +203,24 @@ TEST_CASE( "drying_rate", "[character][limb]" )
CHECK( low_dry == Approx( 900 ).margin( 300 ) );
}

TEST_CASE( "Limb_consumption", "[limb]" )
{
standard_npc dude( "Test NPC" );
const item solid( "test_pine_nuts" );
const item liquid( "test_liquid" );
clear_character( dude, true );
// Normal chars are normal
REQUIRE( dude.get_modifier( character_modifier_liquid_consume_mod ) == 1.0f );
REQUIRE( dude.get_modifier( character_modifier_solid_consume_mod ) == 1.0f );
const time_duration base_solid = dude.get_consume_time( solid );
const time_duration base_liquid = dude.get_consume_time( liquid );
create_bird_char( dude );
// Testbird chars are birdy
REQUIRE( dude.get_modifier( character_modifier_liquid_consume_mod ) == 2.0f );
REQUIRE( dude.get_modifier( character_modifier_solid_consume_mod ) == 0.5f );
CHECK( dude.get_consume_time( liquid ) == base_liquid * 2 );
CHECK( dude.get_consume_time( solid ) == base_solid / 2 );
}
TEST_CASE( "Limb_armor_coverage", "[character][limb][armor]" )
{
standard_npc dude( "Test NPC" );
Expand Down

0 comments on commit c3b29e0

Please sign in to comment.