Skip to content

Commit 6a95266

Browse files
committed
Add age and height
1 parent 1d4f464 commit 6a95266

File tree

10 files changed

+95
-24
lines changed

10 files changed

+95
-24
lines changed

data/json/mutations/mutations.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
{
146146
"condition": {
147147
"or": [
148-
{ "compare_int": [ { "u_val": "hour" }, { "const": 6 } ], "op": "<" },
149-
{ "compare_int": [ { "u_val": "hour" }, { "const": 21 } ], "op": ">" }
148+
{ "compare_int": [ "hour", { "const": 6 } ], "op": "<" },
149+
{ "compare_int": [ "hour", { "const": 21 } ], "op": ">" }
150150
]
151151
},
152152
"msg_on": { "text": "Everything is terrible and this makes you so ANGRY!", "rating": "mixed" }
@@ -169,8 +169,8 @@
169169
{
170170
"condition": {
171171
"and": [
172-
{ "compare_int": [ { "u_val": "hour" }, { "const": 6 } ], "op": ">" },
173-
{ "compare_int": [ { "u_val": "hour" }, { "const": 21 } ], "op": "<" }
172+
{ "compare_int": [ "hour", { "const": 6 } ], "op": ">" },
173+
{ "compare_int": [ "hour", { "const": 21 } ], "op": "<" }
174174
]
175175
},
176176
"msg_on": { "text": "As the morning comes, you return back to normal.", "rating": "good" }

data/mods/TEST_DATA/mutations.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
{
5151
"condition": {
5252
"and": [
53-
{ "compare_int": [ { "u_val": "hour" }, { "const": 1 } ], "op": ">" },
54-
{ "compare_int": [ { "u_val": "hour" }, { "const": 3 } ], "op": "<" }
53+
{ "compare_int": [ "hour", { "const": 1 } ], "op": ">" },
54+
{ "compare_int": [ "hour", { "const": 3 } ], "op": "<" }
5555
]
5656
},
5757
"msg_on": { "text": "It's 2 am and it triggers the trigger.", "rating": "mixed" }
@@ -101,8 +101,8 @@
101101
{
102102
"condition": {
103103
"or": [
104-
{ "compare_int": [ { "u_val": "hour" }, { "const": 1 } ], "op": "<" },
105-
{ "compare_int": [ { "u_val": "hour" }, { "const": 2 } ], "op": ">" }
104+
{ "compare_int": [ "hour", { "const": 1 } ], "op": "<" },
105+
{ "compare_int": [ "hour", { "const": 2 } ], "op": ">" }
106106
]
107107
},
108108
"msg_on": { "text": "It's no longer 2 am and it triggers the trigger.", "rating": "mixed" }

doc/JSON_INFO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,8 +2210,8 @@ The `id` must be exact as it is hardcoded to look for that.
22102210
{
22112211
"condition": { //dialog condition(see NPCs.md)
22122212
"or": [
2213-
{ "compare_int": [ { "u_val": "hour" }, { "const": 2 } ], "op": "<" },
2214-
{ "compare_int": [ { "u_val": "hour" }, { "const": 20 } ], "op": ">" }
2213+
{ "compare_int": [ { "hour", { "const": 2 } ], "op": "<" },
2214+
{ "compare_int": [ { "hour", { "const": 20 } ], "op": ">" }
22152215
]
22162216
},
22172217
"msg_on": { "text": "Everything is terrible and this makes you so ANGRY!", "rating": "mixed" } // message displayed when the trigger activates

doc/NPCs.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,6 @@ Example | Description
934934
`"u_val": "strength_base"` | Player character's strength. Replace `"strength_base"` with `"dexterity_base"`, `"intelligence_base"`, or `"perception_base"` to get such values.
935935
`"u_val": "var"` | Custom variable. `"var_name"`, `"type"`, and `"context"` must also be specified. If `global_val` is used then a global variable will be used. If `default` is given as either an int or a variable_object then that value will be used if the variable is empty. If `default_time` is the same thing will happen, but it will be parsed as a time string aka "10 hours". Otherwise 0 will be used if the variable is empty.
936936
`"u_val": "time_since_var"` | Time since a custom variable was set. Unit used is turns. `"var_name"`, `"type"`, and `"context"` must also be specified.
937-
`"u_val": "hour"` | Hours since midnight.
938-
`"u_val": "moon"` | Phase of the moon. MOON_NEW =0, WAXING_CRESCENT =1, HALF_MOON_WAXING =2, WAXING_GIBBOUS =3, FULL =4, WANING_GIBBOUS =5, HALF_MOON_WANING =6, WANING_CRESCENT =7
939937
`"u_val": "allies"` | Number of allies the character has. Only supported for the player character. Can be read but not written to.
940938
`"u_val": "cash"` | Amount of money the character has. Only supported for the player character. Can be read but not written to.
941939
`"u_val": "owed"` | Owed money to the NPC you're talking to.
@@ -965,7 +963,11 @@ Example | Description
965963
`"u_val": "anger"` | Current anger level, only works for monsters.
966964
`"u_val": "friendly"` | Current friendly level, only works for monsters.
967965
`"u_val": "vitamin"` | Current vitamin level. `name` must also be specified which is the vitamins id.
966+
`"u_val": "age"` | Current age in years.
967+
`"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.
968968
`"distance": []` | Distance between two targets. Valid targets are: "u","npc" and an object with a variable name.
969+
`"hour"` | Hours since midnight.
970+
`"moon"` | Phase of the moon. MOON_NEW =0, WAXING_CRESCENT =1, HALF_MOON_WAXING =2, WAXING_GIBBOUS =3, FULL =4, WANING_GIBBOUS =5, HALF_MOON_WANING =6, WANING_CRESCENT =7
969971
```
970972
"condition": { "compare_int": [ { "distance": [ "u",{ "u_val": "stuck", "type": "ps", "context": "teleport" } ] }, { "const": 5 } ], "op": ">" }
971973
```

src/condition.cpp

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,8 @@ void conditional_t<T>::set_compare_int( const JsonObject &jo, const std::string
992992
};
993993
return;
994994
}
995-
std::function<int( const T & )> get_first_int = get_get_int( objects.get_object( 0 ) );
996-
std::function<int( const T & )> get_second_int = get_get_int( objects.get_object( 1 ) );
995+
std::function<int( const T & )> get_first_int = objects.has_object(0) ? get_get_int( objects.get_object( 0 ) ) : get_get_int( objects.get_string( 0 ), jo );
996+
std::function<int( const T & )> get_second_int = objects.has_object(1) ? get_get_int( objects.get_object( 1 ) ) : get_get_int( objects.get_string( 1 ), jo );
997997
const std::string &op = jo.get_string( "op" );
998998

999999
if( op == "==" || op == "=" ) {
@@ -1314,14 +1314,6 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
13141314
return [is_npc]( const T & d ) {
13151315
return d.actor( is_npc )->get_friendly();
13161316
};
1317-
} else if( checked_value == "moon" ) {
1318-
return []( const T & ) {
1319-
return static_cast<int>( get_moon_phase( calendar::turn ) );
1320-
};
1321-
} else if( checked_value == "hour" ) {
1322-
return []( const T & ) {
1323-
return to_hours<int>( time_past_midnight( calendar::turn ) );
1324-
};
13251317
} else if( checked_value == "vitamin" ) {
13261318
std::string vitamin_name = jo.get_string( "name" );
13271319
return [is_npc, vitamin_name]( const T & d ) {
@@ -1332,7 +1324,23 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
13321324
return 0;
13331325
}
13341326
};
1327+
} else if( checked_value == "age" ) {
1328+
return [is_npc]( const T & d ) {
1329+
return d.actor( is_npc )->get_age();
1330+
};
1331+
} else if( checked_value == "height" ) {
1332+
return [is_npc]( const T & d ) {
1333+
return d.actor( is_npc )->get_height();
1334+
};
13351335
}
1336+
} else if( jo.has_member( "moon" ) ) {
1337+
return []( const T & ) {
1338+
return static_cast<int>( get_moon_phase( calendar::turn ) );
1339+
};
1340+
} else if( jo.has_member( "hour" ) ) {
1341+
return []( const T & ) {
1342+
return to_hours<int>( time_past_midnight( calendar::turn ) );
1343+
};
13361344
} else if( jo.has_array( "distance" ) ) {
13371345
JsonArray objects = jo.get_array( "distance" );
13381346
if( objects.size() != 2 ) {
@@ -1352,6 +1360,24 @@ std::function<int( const T & )> conditional_t<T>::get_get_int( const JsonObject
13521360
};
13531361
}
13541362

1363+
template<class T>
1364+
std::function<int( const T & )> conditional_t<T>::get_get_int( std::string value, const JsonObject &jo )
1365+
{
1366+
if( value == "moon" ) {
1367+
return []( const T & ) {
1368+
return static_cast<int>( get_moon_phase( calendar::turn ) );
1369+
};
1370+
} else if (value == "hour") {
1371+
return [](const T&) {
1372+
return to_hours<int>( time_past_midnight(calendar::turn) );
1373+
};
1374+
}
1375+
jo.throw_error( "unrecognized integer source in " + value );
1376+
return []( const T & ) {
1377+
return 0;
1378+
};
1379+
}
1380+
13551381
template<class T>
13561382
void conditional_t<T>::set_u_has_camp()
13571383
{
@@ -1385,7 +1411,8 @@ void conditional_t<T>::set_has_reason()
13851411
}
13861412

13871413
template<class T>
1388-
void conditional_t<T>::set_has_skill( const JsonObject &jo, const std::string &member, bool is_npc )
1414+
void conditional_t<T>::set_has_skill( const JsonObject &jo, const std::string &member,
1415+
bool is_npc )
13891416
{
13901417
JsonObject has_skill = jo.get_object( member );
13911418
if( !has_skill.has_string( "skill" ) || !has_skill.has_int( "level" ) ) {

src/condition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct conditional_t {
164164
void set_can_see( bool is_npc = false );
165165
void set_compare_int( const JsonObject &jo, const std::string &member );
166166
static std::function<int( const T & )> get_get_int( const JsonObject &jo );
167-
167+
static std::function<int(const T&)> get_get_int(std::string value, const JsonObject &jo );
168168
bool operator()( const T &d ) const {
169169
if( !condition ) {
170170
return false;

src/npctalk.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,6 +3114,14 @@ static std::function<void( const dialogue &, int )> get_set_int( const JsonObjec
31143114
you->vitamin_set( vitamin_id( vitamin_name ), handle_min_max( d, input, min, max ) );
31153115
}
31163116
};
3117+
} else if( checked_value == "age" ) {
3118+
return [is_npc, min, max]( const dialogue & d, int input ) {
3119+
d.actor( is_npc )->set_age( handle_min_max( d, input, min, max ) );
3120+
};
3121+
} else if( checked_value == "height" ) {
3122+
return [is_npc, min, max]( const dialogue & d, int input ) {
3123+
d.actor( is_npc )->set_height( handle_min_max( d, input, min, max ) );
3124+
};
31173125
}
31183126
}
31193127
jo.throw_error( "error setting integer destination in " + jo.str() );

src/talker.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,13 @@ class talker
469469
virtual int get_kill_xp() const {
470470
return 0;
471471
}
472+
virtual void set_age( int ) {}
473+
virtual int get_age() const {
474+
return 0;
475+
}
476+
virtual void set_height( int ) {}
477+
virtual int get_height() const {
478+
return 0;
479+
}
472480
};
473481
#endif // CATA_SRC_TALKER_H

src/talker_character.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,28 @@ int talker_character_const::get_kill_xp() const
542542
return me_chr_const->kill_xp;
543543
}
544544

545+
void talker_character::set_age( int amount )
546+
{
547+
int years_since_cataclysm = to_turns<int>( calendar::turn - calendar::turn_zero ) /
548+
to_turns<int>( calendar::year_length() );
549+
me_chr->set_base_age( amount + years_since_cataclysm );
550+
}
551+
552+
int talker_character_const::get_age() const
553+
{
554+
return me_chr_const->age();
555+
}
556+
557+
void talker_character::set_height( int amount )
558+
{
559+
me_chr->set_base_height( amount );
560+
}
561+
562+
int talker_character_const::get_height() const
563+
{
564+
return me_chr_const->height();
565+
}
566+
545567
void talker_character::add_bionic( const bionic_id &new_bionic )
546568
{
547569
me_chr->add_bionic( new_bionic );

src/talker_character.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class talker_character_const: public talker
113113
int get_stamina() const override;
114114
int get_sleep_deprivation() const override;
115115
int get_kill_xp() const override;
116+
int get_age() const override;
117+
int get_height() const override;
116118
protected:
117119
talker_character_const() = default;
118120
const Character *me_chr_const;
@@ -187,6 +189,8 @@ class talker_character: public talker_character_const
187189
void set_stamina( int ) override;
188190
void set_sleep_deprivation( int ) override;
189191
void set_kill_xp( int ) override;
192+
void set_age( int ) override;
193+
void set_height( int ) override;
190194
void add_bionic( const bionic_id &new_bionic ) override;
191195
void remove_bionic( const bionic_id &old_bionic ) override;
192196
std::vector<skill_id> skills_teacheable() const override;

0 commit comments

Comments
 (0)