Skip to content

Commit 9eaff9b

Browse files
committed
Add u_var "bmi_permil" (BMI * 1000)
Co-authored by @dseguin
1 parent fe15810 commit 9eaff9b

File tree

6 files changed

+15
-0
lines changed

6 files changed

+15
-0
lines changed

doc/NPCs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ Example | Description
964964
`"u_val": "friendly"` | Current friendly level, only works for monsters.
965965
`"u_val": "vitamin"` | Current vitamin level. `name` must also be specified which is the vitamins id.
966966
`"u_val": "age"` | Current age in years.
967+
`"u_val": "bmi_permil"` | Current BMI per mille (Body Mass Index x 1000)
967968
`"u_val": "height"` | Current height in cm. When setting there is a range for your character size category. Setting it too high or low will use the limit instead. For tiny its 58, and 87. For small its 88 and 144. For medium its 145 and 200. For large its 201 and 250. For huge its 251 and 320.
968969
`"distance": []` | Distance between two targets. Valid targets are: "u","npc" and an object with a variable name.
969970
`"hour"` | Hours since midnight.

src/character.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ class Character : public Creature, public visitable
501501
/** Getter for need values exclusive to characters */
502502
int get_stored_kcal() const;
503503
int get_healthy_kcal() const;
504+
// Returns stored kcals as a proportion of "healthy" kcals (1.0 == healthy)
504505
float get_kcal_percent() const;
505506
int kcal_speed_penalty() const;
506507
int get_hunger() const;

src/condition.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,10 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
13841384
return [is_npc]( const T & d ) {
13851385
return d.actor( is_npc )->get_height();
13861386
};
1387+
} else if( checked_value == "bmi_permil" ) {
1388+
return [is_npc]( const T & d ) {
1389+
return d.actor( is_npc )->get_bmi_permil();
1390+
};
13871391
}
13881392
} else if( jo.has_member( "moon" ) ) {
13891393
return []( const T & ) {

src/talker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,8 @@ class talker
483483
virtual int get_height() const {
484484
return 0;
485485
}
486+
virtual int get_bmi_permil() const {
487+
return 0;
488+
}
486489
};
487490
#endif // CATA_SRC_TALKER_H

src/talker_character.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ int talker_character_const::get_age() const
564564
return me_chr_const->age();
565565
}
566566

567+
int talker_character_const::get_bmi_permil() const
568+
{
569+
return std::round( me_chr_const->get_bmi() * 1000.0f );
570+
}
571+
567572
void talker_character::set_height( int amount )
568573
{
569574
me_chr->set_base_height( amount );

src/talker_character.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class talker_character_const: public talker
117117
int get_kill_xp() const override;
118118
int get_age() const override;
119119
int get_height() const override;
120+
int get_bmi_permil() const override;
120121
protected:
121122
talker_character_const() = default;
122123
const Character *me_chr_const;

0 commit comments

Comments
 (0)