Skip to content

Commit

Permalink
Migrate NPC rules to a new, dedicated imgui menu
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed Jun 7, 2024
1 parent 8249ff5 commit 6109f4e
Show file tree
Hide file tree
Showing 7 changed files with 395 additions and 173 deletions.
174 changes: 1 addition & 173 deletions data/json/npcs/common_chat/TALK_COMMON_ALLY.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"responses": [
{ "text": "I want to give you some commands for combat.", "topic": "TALK_COMBAT_COMMANDS" },
{ "text": "I want to set some miscellaneous rules.", "topic": "TALK_MISC_RULES" },
{ "text": "[rules] Let's talk about how we'll work together.", "topic": "TALK_DONE", "effect": "npc_rules_menu" },
{
"text": "I'd like to know a bit more about your abilities.",
"topic": "TALK_FRIEND",
Expand Down Expand Up @@ -339,16 +340,6 @@
"responses": [
{ "text": "Change your engagement rules…", "topic": "TALK_COMBAT_ENGAGEMENT" },
{ "text": "Change your aiming rules…", "topic": "TALK_AIM_RULES" },
{
"text": "Change your bionic power reserve rules…",
"topic": "TALK_CBM_RESERVE_RULES",
"condition": { "npc_has_bionics": "ANY" }
},
{
"text": "Change your bionic power recharge rules…",
"topic": "TALK_CBM_RECHARGE_RULES",
"condition": { "npc_has_bionics": "ANY" }
},
{
"truefalsetext": {
"condition": { "npc_rule": "follow_close" },
Expand Down Expand Up @@ -486,169 +477,6 @@
{ "text": "Never mind.", "topic": "TALK_NONE" }
]
},
{
"id": "TALK_CBM_RESERVE_RULES",
"type": "talk_topic",
"dynamic_line": {
"concatenate": [
{
"npc_cbm_reserve_rule": "CBM_RESERVE_ALL",
"no": {
"npc_cbm_reserve_rule": "CBM_RESERVE_MOST",
"no": {
"npc_cbm_reserve_rule": "CBM_RESERVE_SOME",
"no": {
"npc_cbm_reserve_rule": "CBM_RESERVE_LITTLE",
"no": "*will not reserve any power for defense or utility CBMs.",
"yes": "*will reserve 25% of CBM power for defense or utility CBMs."
},
"yes": "*will reserve 50% of CBM power for defense or utility CBMs."
},
"yes": "*will reserve 75% of CBM power for defense or utility CBMs."
},
"yes": "*will reserve 100% of CBM power for defense or utility CBMs."
},
" How should much power should <mypronoun> reserve for defense or utility CBMs?"
]
},
"responses": [
{
"text": "Don't use any CBM weapons. Save all power for defense or utility CBMs.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_reserve_rule": "CBM_RESERVE_ALL" } },
"effect": { "set_npc_cbm_reserve_rule": "CBM_RESERVE_ALL" }
},
{
"text": "Use CBM weapons, but save 75% of total power for defense or utility CBMs.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_reserve_rule": "CBM_RESERVE_MOST" } },
"effect": { "set_npc_cbm_reserve_rule": "CBM_RESERVE_MOST" }
},
{
"text": "Use CBM weapons, but save 50% of total power for defense or utility CBMs.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_reserve_rule": "CBM_RESERVE_SOME" } },
"effect": { "set_npc_cbm_reserve_rule": "CBM_RESERVE_SOME" }
},
{
"text": "Use CBM weapons, but save 25% of total power for defense or utility CBMs.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_reserve_rule": "CBM_RESERVE_LITTLE" } },
"effect": { "set_npc_cbm_reserve_rule": "CBM_RESERVE_LITTLE" }
},
{
"text": "Go wild with CBM weapons. Don't reserve any power for defense or utility CBMs.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_reserve_rule": "CBM_RESERVE_NONE" } },
"effect": { "set_npc_cbm_reserve_rule": "CBM_RESERVE_NONE" }
},
{ "text": "Never mind.", "topic": "TALK_NONE" }
]
},
{
"id": "TALK_CBM_RECHARGE_RULES",
"type": "talk_topic",
"dynamic_line": {
"concatenate": [
{
"npc_cbm_recharge_rule": "CBM_RECHARGE_ALL",
"no": {
"npc_cbm_recharge_rule": "CBM_RECHARGE_MOST",
"no": {
"npc_cbm_recharge_rule": "CBM_RECHARGE_SOME",
"no": {
"npc_cbm_recharge_rule": "CBM_RECHARGE_LITTLE",
"no": "*will recharge power CBMs until <mypronoun> has 10% of total power.",
"yes": "*will recharge power CBMs until <mypronoun> has 25% of total power."
},
"yes": "*will recharge power CBMs until <mypronoun> has 50% of total power."
},
"yes": "*will recharge power CBMs until <mypronoun> has 75% of total power."
},
"yes": "*will recharge power CBMs until <mypronoun> has 90% of total power."
},
" When should <mypronoun> consume supplies to recharge power CBMs?"
]
},
"responses": [
{
"text": "We have plenty of supplies. Recharge until you have 90% of total power.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_recharge_rule": "CBM_RECHARGE_ALL" } },
"effect": { "set_npc_cbm_recharge_rule": "CBM_RECHARGE_ALL" }
},
{
"text": "We have supplies. Recharge until you have 75% of total power.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_recharge_rule": "CBM_RECHARGE_MOST" } },
"effect": { "set_npc_cbm_recharge_rule": "CBM_RECHARGE_MOST" }
},
{
"text": "We have some supplies. Recharge until you have 50% of total power.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_recharge_rule": "CBM_RECHARGE_SOME" } },
"effect": { "set_npc_cbm_recharge_rule": "CBM_RECHARGE_SOME" }
},
{
"text": "We're running low on supplies. Recharge until you have 25% of total power.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_recharge_rule": "CBM_RECHARGE_LITTLE" } },
"effect": { "set_npc_cbm_recharge_rule": "CBM_RECHARGE_LITTLE" }
},
{
"text": "We're almost out of supplies. Recharge until you have 10% of total power.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_cbm_recharge_rule": "CBM_RECHARGE_NONE" } },
"effect": { "set_npc_cbm_recharge_rule": "CBM_RECHARGE_NONE" }
},
{ "text": "Never mind.", "topic": "TALK_NONE" }
]
},
{
"id": "TALK_AIM_RULES",
"type": "talk_topic",
"dynamic_line": {
"concatenate": [
{
"npc_aim_rule": "AIM_WHEN_CONVENIENT",
"no": {
"npc_aim_rule": "AIM_STRICTLY_PRECISE",
"no": { "npc_aim_rule": "AIM_PRECISE", "no": "*will not bother to aim at all.", "yes": "*will take time and aim carefully." },
"yes": "*will only shoot after taking a long time to aim."
},
"yes": "*will aim when it's convenient."
},
" How should <mypronoun> aim?"
]
},
"responses": [
{
"text": "Aim when it's convenient.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_aim_rule": "AIM_WHEN_CONVENIENT" } },
"effect": { "set_npc_aim_rule": "AIM_WHEN_CONVENIENT" }
},
{
"text": "Go wild, you don't need to aim much.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_aim_rule": "AIM_SPRAY" } },
"effect": { "set_npc_aim_rule": "AIM_SPRAY" }
},
{
"text": "Take your time, aim carefully.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_aim_rule": "AIM_PRECISE" } },
"effect": { "set_npc_aim_rule": "AIM_PRECISE" }
},
{
"text": "Don't shoot if you can't aim really well.",
"topic": "TALK_NONE",
"condition": { "not": { "npc_aim_rule": "AIM_STRICTLY_PRECISE" } },
"effect": { "set_npc_aim_rule": "AIM_STRICTLY_PRECISE" }
},
{ "text": "Never mind.", "topic": "TALK_NONE" }
]
},
{
"id": "TALK_TRAIN_PERSUADE",
"type": "talk_topic",
Expand Down
108 changes: 108 additions & 0 deletions data/json/npcs/talk_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,114 @@
"it's a million miles away!"
]
},
{
"type": "snippet",
"category": "<ally_rule_cbm_recharge_all_text>",
"text": "<mypronoun> will recharge power CBMs until <mypronoun> has 90% of total power."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_recharge_most_text>",
"text": "<mypronoun> will recharge power CBMs until <mypronoun> has 75% of total power."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_recharge_some_text>",
"text": "<mypronoun> will recharge power CBMs until <mypronoun> has 50% of total power."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_recharge_little_text>",
"text": "<mypronoun> will recharge power CBMs until <mypronoun> has 25% of total power."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_recharge_none_text>",
"text": "<mypronoun> will recharge power CBMs until <mypronoun> has 10% of total power."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_reserve_all_text>",
"text": "<mypronoun> will reserve 100% of CBM power for defense or utility CBMs."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_reserve_most_text>",
"text": "<mypronoun> will reserve 75% of CBM power for defense or utility CBMs."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_reserve_some_text>",
"text": "<mypronoun> will reserve 50% of CBM power for defense or utility CBMs."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_reserve_little_text>",
"text": "<mypronoun> will reserve 25% of CBM power for defense or utility CBMs."
},
{
"type": "snippet",
"category": "<ally_rule_cbm_reserve_none_text>",
"text": "<mypronoun> will not reserve any power for defense or utility CBMs."
},
{
"type": "snippet",
"category": "<ally_rule_aim_when_convenient>",
"text": "<mypronoun> will aim when it's convenient."
},
{
"type": "snippet",
"category": "<ally_rule_aim_spray>",
"text": "<mypronoun> will not bother to aim at all."
},
{
"type": "snippet",
"category": "<ally_rule_aim_precise>",
"text": "<mypronoun> will take time and aim carefully."
},
{
"type": "snippet",
"category": "<ally_rule_aim_strictly_precise>",
"text": "<mypronoun> will only shoot after taking a long time to aim."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_none>",
"text": "<mypronoun> won't fight unless their life depends on it."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_close>",
"text": "<mypronoun> will attack enemies that get too close."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_weak>",
"text": "<mypronoun> will attack enemies that they can kill easily."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_hit>",
"text": "<mypronoun> will attack only enemies that you attack first."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_all>",
"text": [
{ "text": "<mypronoun> will attack anything they want.", "weight": 999 },
{ "text": "<npc_name> has permission to go <color_red>ABSOLUTELY AXE CRAZY!</color>", "weight": 1 }
]
},
{
"type": "snippet",
"category": "<ally_rule_engagement_free_fire>",
"text": "<mypronoun> will attack any enemy within range of their ranged weapon, but won't move."
},
{
"type": "snippet",
"category": "<ally_rule_engagement_no_move>",
"text": "<mypronoun> will attack only enemies they can reach without moving."
},
{
"type": "snippet",
"category": "<ally_rule_use_guns_true_text>",
Expand Down
5 changes: 5 additions & 0 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3766,6 +3766,11 @@ void npc_follower_rules::clear_overrides()
override_enable = ally_rule::DEFAULT;
}

void npc_follower_rules::clear_flags()
{
flags = ally_rule::DEFAULT;
}

int npc::get_thirst() const
{
return Character::get_thirst() - units::to_milliliter<int>( stomach.get_water() ) / 5;
Expand Down
1 change: 1 addition & 0 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ struct npc_follower_rules {
void clear_override( ally_rule clearit );

void set_danger_overrides();
void clear_flags();
void clear_overrides();
};

Expand Down
13 changes: 13 additions & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "mutation.h"
#include "npc.h"
#include "npctalk.h"
#include "npctalk_rules.h"
#include "npctrade.h"
#include "output.h"
#include "overmapbuffer.h"
Expand Down Expand Up @@ -3480,6 +3481,14 @@ talk_effect_fun_t::func f_add_debt( const JsonObject &jo, std::string_view membe
};
}

talk_effect_fun_t::func f_npc_rules_menu()
{
return []( dialogue const & d ) {
follower_rules_ui new_ui;
new_ui.draw_follower_rules_ui( d.actor( true )->get_npc() );
};
}

talk_effect_fun_t::func f_toggle_npc_rule( const JsonObject &jo, std::string_view member )
{
str_or_var rule = get_str_or_var( jo.get_member( member ), member, true );
Expand Down Expand Up @@ -6674,6 +6683,10 @@ void talk_effect_t::parse_string_effect( const std::string &effect_id, const Jso
set_effect( talk_effect_fun_t( talk_effect_fun::f_wants_to_talk( true ) ) );
return;
}
if( effect_id == "npc_rules_menu" ) {
set_effect( talk_effect_fun_t( talk_effect_fun::f_npc_rules_menu() ) );
return;
}
jo.throw_error_at( effect_id, "unknown effect string" );
}

Expand Down
Loading

0 comments on commit 6109f4e

Please sign in to comment.