Skip to content

Commit e280485

Browse files
authored
Merge pull request #82125 from ShnitzelX2/npc-exclude-traits-professions
2 parents a47f941 + 06b7774 commit e280485

File tree

13 files changed

+48
-34
lines changed

13 files changed

+48
-34
lines changed

data/json/mutations/mutations.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@
990990
"enchantments": [ { "values": [ { "value": "CONSUME_TIME_MOD", "multiply": 0.5 } ] } ],
991991
"description": "You've been taught proper table manners from your early childhood on; now, you can't even think about eating without being seated at a table and taking your time. Eating without a table and chair frustrates you, but eating like a civilized person gives you a bigger morale bonus.",
992992
"starting_trait": true,
993-
"random_at_chargen": false,
993+
"chargen_allow_npc": false,
994994
"valid": false
995995
},
996996
{
@@ -1325,7 +1325,7 @@
13251325
"points": 2,
13261326
"description": "For your whole life you've been forbidden from indulging in your peculiar tastes. Now the world's ended, and you'll be damned if anyone is going to tell you that you can't eat people.",
13271327
"starting_trait": true,
1328-
"random_at_chargen": false,
1328+
"chargen_allow_npc": false,
13291329
"valid": false,
13301330
"cancels": [ "VEGETARIAN", "VEGAN", "HERBIVORE", "RUMINANT", "GRAZER" ],
13311331
"flags": [ "CANNIBAL" ]
@@ -1337,7 +1337,7 @@
13371337
"points": 1,
13381338
"description": "You're convinced that these things that look vaguely human from elsewhere are definitely not people. Therefore it's okay to eat them, right?",
13391339
"starting_trait": true,
1340-
"random_at_chargen": false,
1340+
"chargen_allow_npc": false,
13411341
"valid": false,
13421342
"cancels": [ "VEGETARIAN", "VEGAN", "HERBIVORE", "RUMINANT", "GRAZER", "CANNIBAL" ],
13431343
"flags": [ "STRICT_HUMANITARIAN" ]
@@ -1349,7 +1349,7 @@
13491349
"points": 2,
13501350
"description": "You don't feel any strong feelings for your fellow man.",
13511351
"starting_trait": true,
1352-
"random_at_chargen": false,
1352+
"chargen_allow_npc": false,
13531353
"valid": false,
13541354
"social_modifiers": { "lie": -5, "persuade": -5 },
13551355
"types": [ "HUMAN_EMPATHY" ],
@@ -1914,7 +1914,7 @@
19141914
"vitamin_cost": 160,
19151915
"description": "You suffer from a minor chemical imbalance, whether mental or physical. Minor changes to your internal chemistry will manifest themselves on occasion, such as hunger, sleepiness, narcotic effects, etc.",
19161916
"starting_trait": true,
1917-
"random_at_chargen": false,
1917+
"chargen_allow_npc": false,
19181918
"category": [ "SLIME", "MEDICAL", "CHIMERA", "ELFA" ]
19191919
},
19201920
{
@@ -1961,7 +1961,7 @@
19611961
"vitamin_cost": 160,
19621962
"description": "Ever since the sky first broke, you have felt unwell, your head split by alien thoughts. You will periodically suffer from delusions, ranging from minor effects to full visual hallucinations. Some of these effects may be controlled through the use of antipsychotics.",
19631963
"starting_trait": true,
1964-
"random_at_chargen": false,
1964+
"chargen_allow_npc": false,
19651965
"category": [ "MEDICAL" ]
19661966
},
19671967
{
@@ -1972,7 +1972,7 @@
19721972
"vitamin_cost": 160,
19731973
"description": "You randomly fall asleep without any reason.",
19741974
"starting_trait": true,
1975-
"random_at_chargen": false,
1975+
"chargen_allow_npc": false,
19761976
"category": [ "MEDICAL" ]
19771977
},
19781978
{
@@ -9063,7 +9063,7 @@
90639063
"vitamin_cost": 160,
90649064
"description": "You have an unhealthy obsession with fire, and you get anxious if you don't light them every now and then or stand near them often. However, you gain a mood bonus from doing so.",
90659065
"starting_trait": true,
9066-
"random_at_chargen": false
9066+
"chargen_allow_npc": false
90679067
},
90689068
{
90699069
"type": "mutation",

data/mods/CrazyCataclysm/crazy_mutations.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"description": "You're naturally quite lucky!",
88
"starting_trait": true,
99
"valid": false,
10-
"random_at_chargen": false,
10+
"chargen_allow_npc": false,
1111
"cancels": [ "UNLUCKY" ]
1212
},
1313
{
@@ -18,7 +18,7 @@
1818
"description": "You're naturally quite unlucky.",
1919
"starting_trait": true,
2020
"valid": false,
21-
"random_at_chargen": false,
21+
"chargen_allow_npc": false,
2222
"cancels": [ "LUCKY" ]
2323
}
2424
]

doc/JSON/JSON_INFO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,7 @@ The following properties (mandatory, except if noted otherwise) are supported:
19361936
"points": 0, // Point cost of profession. Positive values cost points and negative values grant points. Has no effect as of 0.G
19371937
"starting_cash": 500000, // (optional) Int value for the starting bank balance.
19381938
"npc_background": "BG_survival_story_LAB", // (optional) BG_trait_group ID, provides list of background stories. (see BG_trait_groups.json)
1939+
"chargen_allow_npc": false, // (optional) when false, removes this profession as an option for generated NPCs (default: true)
19391940
"addictions": [ { "intensity": 10, "type": "nicotine" } ], // (optional) Array of addictions. Requires "type" as the string ID of the addiction (see JSON_FLAGS.md) and "intensity"
19401941
"skills": [ { "name": "archery", "level": 2 } ], // (optional) Array of starting skills. Requires "name" as the string ID of the skill (see skills.json) and "level", which is a value added to the skill level after character creation
19411942
"missions": [ "MISSION_LAST_DELIVERY" ], // (optional) Array of starting mission IDs

doc/JSON/MUTATIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Note that **all new traits that can be obtained through mutation must be purifia
125125
"mixed_effect": false, // Whether the trait has both positive and negative effects. This is purely declarative and is only used for the user interface (default: false).
126126
"description": "Nothing gets you down!", // In-game description. Supports snippets and u/global variables
127127
"starting_trait": true, // Can be selected at character creation (default: false).
128-
"random_at_chargen": false, // (Optional) Starting traits can be randomly assigned to NPCs during chargen. This options prevents that (default: true).
128+
"chargen_allow_npc": false, // (Optional) Starting traits can be randomly assigned to NPCs during chargen. This options prevents that when false (default: true).
129129
"valid": false, // Can be mutated ingame (default: true). Note that prerequisites can even mutate invalid mutations.
130130
"purifiable": false, // Sets if the mutation be purified (default: true).
131131
"profession": true, // Trait is a starting profession special trait (default: false).

src/character.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,9 +1334,9 @@ class Character : public Creature, public visitable
13341334
int mabuff_armor_bonus( const damage_type_id &type ) const;
13351335
// --------------- Mutation Stuff ---------------
13361336
// In newcharacter.cpp
1337-
/** Returns the id of a random starting trait that costs >= 0 points */
1337+
/** Returns the id of a random starting chargen trait that costs >= 0 points */
13381338
trait_id random_good_trait();
1339-
/** Returns the id of a random starting trait that costs < 0 points */
1339+
/** Returns the id of a random starting chargen trait that costs < 0 points */
13401340
trait_id random_bad_trait();
13411341
/** Returns the id of a random trait matching the given predicate */
13421342
trait_id get_random_trait( const std::function<bool( const mutation_branch & )> &func );

src/mutation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ struct mutation_branch {
197197
// Whether it has positive as well as negative effects.
198198
bool mixed_effect = false;
199199
bool startingtrait = false;
200-
// By default startingtrait = true traits can be randomly assigned, this allows that to be reversed.
201-
bool random_at_chargen = true;
200+
// If false, NPCs cannot receive this trait during chargen
201+
bool chargen_allow_npc = true;
202202
bool activated = false;
203203
translation activation_msg;
204204
// Should it activate as soon as it is gained?

src/mutation_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void mutation_branch::load( const JsonObject &jo, std::string_view src )
307307
optional( jo, was_loaded, "visibility", visibility, 0 );
308308
optional( jo, was_loaded, "ugliness", ugliness, 0 );
309309
optional( jo, was_loaded, "starting_trait", startingtrait, false );
310-
optional( jo, was_loaded, "random_at_chargen", random_at_chargen, true );
310+
optional( jo, was_loaded, "chargen_allow_npc", chargen_allow_npc, true );
311311
optional( jo, was_loaded, "mixed_effect", mixed_effect, false );
312312
optional( jo, was_loaded, "active", activated, false );
313313
optional( jo, was_loaded, "starts_active", starts_active, false );

src/newcharacter.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void Character::randomize( const bool random_scenario, bool play_now )
460460
}
461461

462462
const scenario *scenario_from = is_avatar() ? get_scenario() : scenario::generic();
463-
prof = scenario_from->weighted_random_profession();
463+
prof = scenario_from->weighted_random_profession( is_npc() );
464464
play_name_suffix = prof->gender_appropriate_name( male );
465465
zero_all_skills();
466466

@@ -476,9 +476,11 @@ void Character::randomize( const bool random_scenario, bool play_now )
476476

477477
set_body();
478478
randomize_hobbies();
479-
const trait_id background = prof->pick_background();
480-
if( !background.is_empty() ) {
481-
set_mutation( background );
479+
if( is_npc() ) {
480+
const trait_id background = prof->pick_background();
481+
if( !background.is_empty() ) {
482+
set_mutation( background );
483+
}
482484
}
483485

484486
int num_gtraits = 0;
@@ -695,7 +697,7 @@ void Character::add_profession_items()
695697
void Character::randomize_hobbies()
696698
{
697699
hobbies.clear();
698-
std::vector<profession_id> choices = get_scenario()->permitted_hobbies();
700+
std::vector<profession_id> choices = get_scenario()->permitted_hobbies( is_npc() );
699701
choices.erase( std::remove_if( choices.begin(), choices.end(),
700702
[this]( const string_id<profession> &hobby ) {
701703
return !prof->allows_hobby( hobby );
@@ -4953,15 +4955,15 @@ void Character::add_traits()
49534955

49544956
trait_id Character::random_good_trait()
49554957
{
4956-
return get_random_trait( []( const mutation_branch & mb ) {
4957-
return mb.points > 0 && mb.random_at_chargen;
4958+
return get_random_trait( [this]( const mutation_branch & mb ) {
4959+
return mb.points > 0 && ( mb.chargen_allow_npc || is_avatar() );
49584960
} );
49594961
}
49604962

49614963
trait_id Character::random_bad_trait()
49624964
{
4963-
return get_random_trait( []( const mutation_branch & mb ) {
4964-
return mb.points < 0 && mb.random_at_chargen;
4965+
return get_random_trait( [this]( const mutation_branch & mb ) {
4966+
return mb.points < 0 && ( mb.chargen_allow_npc || is_avatar() );
49654967
} );
49664968
}
49674969

src/profession.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ void profession::load( const JsonObject &jo, std::string_view )
259259
std::string background_group_id;
260260
optional( jo, was_loaded, "npc_background", _starting_npc_background,
261261
Trait_group_BG_survival_story_UNIVERSAL );
262+
optional( jo, was_loaded, "chargen_allow_npc", _chargen_allow_npc, true );
262263
optional( jo, was_loaded, "age_lower", age_lower, 16 );
263264
optional( jo, was_loaded, "age_upper", age_upper, 55 );
264265
optional( jo, was_loaded, "starting_cash", _starting_cash );
@@ -752,6 +753,11 @@ bool profession::is_forbidden_trait( const trait_id &trait ) const
752753
return _forbidden_traits.count( trait ) != 0;
753754
}
754755

756+
bool profession::chargen_allow_npc() const
757+
{
758+
return _chargen_allow_npc;
759+
}
760+
755761
std::map<spell_id, int> profession::spells() const
756762
{
757763
return _starting_spells;

src/profession.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class profession
6969
std::optional<achievement_id> _requirement;
7070
// does this profession require the requirement even when metaprogression is disabled?
7171
bool hard_requirement = false;
72+
bool _chargen_allow_npc = true;
7273

7374
std::vector<addiction> _starting_addictions;
7475
std::vector<bionic_id> _starting_CBMs;
@@ -169,6 +170,7 @@ class profession
169170
ret_val<void> can_pick() const;
170171
bool is_locked_trait( const trait_id &trait ) const;
171172
bool is_forbidden_trait( const trait_id &trait ) const;
173+
bool chargen_allow_npc() const;
172174
std::vector<trait_and_var> get_locked_traits() const;
173175
std::set<trait_id> get_forbidden_traits() const;
174176
trait_id pick_background() const;

0 commit comments

Comments
 (0)