From bdba046a6d9e84c66f07df58af5c0f7643eac05c Mon Sep 17 00:00:00 2001 From: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:52:53 -0400 Subject: [PATCH 1/8] Event bus for radiation mutation --- doc/EFFECT_ON_CONDITION.md | 1 + src/event.cpp | 4 +++- src/event.h | 6 +++++- src/suffer.cpp | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/EFFECT_ON_CONDITION.md b/doc/EFFECT_ON_CONDITION.md index 4a7fbecdbfff0..17d59fe1ebd23 100644 --- a/doc/EFFECT_ON_CONDITION.md +++ b/doc/EFFECT_ON_CONDITION.md @@ -1189,6 +1189,7 @@ Every event EOC passes context vars with each of their key value pairs that the | character_loses_effect | | { "character", `character_id` },
{ "effect", `efftype_id` },
{ "bodypart", `bodypart_id` } | character / NONE | | character_melee_attacks_character | | { "attacker", `character_id` },
{ "weapon", `itype_id` },
{ "hits", `bool` },
{ "victim", `character_id` },
{ "victim_name", `string` }, | character (attacker) / character (victim) | | character_melee_attacks_monster | | { "attacker", `character_id` },
{ "weapon", `itype_id` },
{ "hits", `bool` },
{ "victim_type", `mtype_id` },| character / monster | +| character_radioactively_mutates | triggered when a character mutates due to being irradiated | { "character", `character_id` }, | character / NONE | | character_ranged_attacks_character | | { "attacker", `character_id` },
{ "weapon", `itype_id` },
{ "victim", `character_id` },
{ "victim_name", `string` }, | character (attacker) / character (victim) | | character_ranged_attacks_monster | | { "attacker", `character_id` },
{ "weapon", `itype_id` },
{ "victim_type", `mtype_id` }, | character / monster | | character_smashes_tile | | { "character", `character_id` },
{ "terrain", `ter_str_id` }, { "furniture", `furn_str_id` }, | character / NONE | diff --git a/src/event.cpp b/src/event.cpp index ae050638c1aa1..8f5f4a7f3bc54 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -42,6 +42,7 @@ std::string enum_to_string( event_type data ) return "character_melee_attacks_character"; case event_type::character_melee_attacks_monster: return "character_melee_attacks_monster"; + case event_type::character_radioactively_mutates: return "character_radioactively_mutates"; case event_type::character_ranged_attacks_character: return "character_ranged_attacks_character"; case event_type::character_ranged_attacks_monster: @@ -141,7 +142,7 @@ DEFINE_EVENT_HELPER_FIELDS( event_spec_empty ) DEFINE_EVENT_HELPER_FIELDS( event_spec_character ) DEFINE_EVENT_HELPER_FIELDS( event_spec_character_item ) -static_assert( static_cast( event_type::num_event_types ) == 102, +static_assert( static_cast( event_type::num_event_types ) == 103, "This static_assert is a reminder to add a definition below when you add a new " "event_type. If your event_spec specialization inherits from another struct for " "its fields definition then you probably don't need a definition here." ); @@ -170,6 +171,7 @@ DEFINE_EVENT_FIELDS( character_learns_spell ) DEFINE_EVENT_FIELDS( character_loses_effect ) DEFINE_EVENT_FIELDS( character_melee_attacks_character ) DEFINE_EVENT_FIELDS( character_melee_attacks_monster ) +DEFINE_EVENT_FIELDS( character_radioactively_mutates ) DEFINE_EVENT_FIELDS( character_ranged_attacks_character ) DEFINE_EVENT_FIELDS( character_ranged_attacks_monster ) DEFINE_EVENT_FIELDS( character_smashes_tile ) diff --git a/src/event.h b/src/event.h index 6e2fb2990e07b..90f34b91d7ea3 100644 --- a/src/event.h +++ b/src/event.h @@ -52,6 +52,7 @@ enum class event_type : int { character_loses_effect, character_melee_attacks_character, character_melee_attacks_monster, + character_radioactively_mutates, character_ranged_attacks_character, character_ranged_attacks_monster, character_smashes_tile, @@ -186,7 +187,7 @@ struct event_spec_character_item { }; }; -static_assert( static_cast( event_type::num_event_types ) == 102, +static_assert( static_cast( event_type::num_event_types ) == 103, "This static_assert is to remind you to add a specialization for your new " "event_type below" ); @@ -406,6 +407,9 @@ struct event_spec { }; }; +template<> +struct event_spec : event_spec_character {}; + template<> struct event_spec { static constexpr std::array, 4> fields = {{ diff --git a/src/suffer.cpp b/src/suffer.cpp index 05e2626e276df..12deccc32ef40 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -1170,7 +1170,7 @@ void suffer::from_radiation( Character &you ) // 1000 rads = 900 / 10000 = 9 / 100 = 10% !!! // 2000 rads = 2000 / 10000 = 1 / 5 = 20% !!! if( get_option( "RAD_MUTATION" ) && rng( 100, 10000 ) < you.get_rad() ) { - you.mutate(); + get_event_bus().send( you.getID() ); } if( you.get_rad() > 50 && rng( 1, 3000 ) < you.get_rad() && ( you.stomach.contains() > 0_ml || radiation_increasing || !you.in_sleep_state() ) ) { From b4a65df960eedcf26c35ac89265d1112b327dfa4 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:53:34 -0500 Subject: [PATCH 2/8] Update mutation_effect_eocs.json --- .../mutation_eocs/mutation_effect_eocs.json | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json index 02d3681f226ea..3ca4c9d2b7ad6 100644 --- a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json +++ b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json @@ -366,6 +366,49 @@ } ] }, + { + "type": "effect_on_condition", + "id": "EOC_RADIATION_MUTATION", + "eoc_type": "EVENT", + "required_event": "character_radioactively_mutates", + "condition": { "or": [ { "u_is_character" }, { "u_is_npc" } ] }, + "effect": [ + { "set_string_var": "", "target_var": { "context_val": "radiation_mutation_category" }, "parse_tags": true }, + { "u_mutate_category": { "context_val": "radiation_mutation_category" }, "use_vitamins": false } + ] + }, + { + "type": "snippet", + "category": "", + "text": [ + { "text": "CHIMERA" }, + { "text": "INSECT" }, + { "text": "ALPHA" }, + { "text": "URSINE" }, + { "text": "CHIROPTERAN" }, + { "text": "BIRD" }, + { "text": "MEDICAL" }, + { "text": "LUPINE" }, + { "text": "RAT" }, + { "text": "SLIME" }, + { "text": "PLANT" }, + { "text": "BATRACHIAN" }, + { "text": "RAPTOR" }, + { "text": "MOUSE" }, + { "text": "CEPHALOPOD" }, + { "text": "ELFA" }, + { "text": "FISH" }, + { "text": "HUMAN" }, + { "text": "RABBIT" }, + { "text": "GASTROPOD" }, + { "text": "BEAST" }, + { "text": "FELINE" }, + { "text": "CATTLE" }, + { "text": "LIZARD" }, + { "text": "TROGLOBITE" }, + { "text": "CRUSTACEAN" } + ] + }, { "type": "effect_on_condition", "id": "EOC_ink_grand_spray", From b1d68152a7f42a331d29d67c8d95a5e5bf75b879 Mon Sep 17 00:00:00 2001 From: RenechCDDA <84619419+RenechCDDA@users.noreply.github.com> Date: Sun, 16 Jun 2024 22:28:33 -0400 Subject: [PATCH 3/8] Update src/event.cpp --- src/event.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/event.cpp b/src/event.cpp index 8f5f4a7f3bc54..f4b8dbd5e9e57 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -171,7 +171,6 @@ DEFINE_EVENT_FIELDS( character_learns_spell ) DEFINE_EVENT_FIELDS( character_loses_effect ) DEFINE_EVENT_FIELDS( character_melee_attacks_character ) DEFINE_EVENT_FIELDS( character_melee_attacks_monster ) -DEFINE_EVENT_FIELDS( character_radioactively_mutates ) DEFINE_EVENT_FIELDS( character_ranged_attacks_character ) DEFINE_EVENT_FIELDS( character_ranged_attacks_monster ) DEFINE_EVENT_FIELDS( character_smashes_tile ) From 5407942f7ea63a59eaff253bcba728c06222aca1 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:16:18 -0500 Subject: [PATCH 4/8] Update memorial_logger.cpp --- src/memorial_logger.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/memorial_logger.cpp b/src/memorial_logger.cpp index 0144a0f025dea..81af6c9a9c31d 100644 --- a/src/memorial_logger.cpp +++ b/src/memorial_logger.cpp @@ -1129,6 +1129,7 @@ void memorial_logger::notify( const cata::event &e ) case event_type::character_wakes_up: case event_type::character_attempt_to_fall_asleep: case event_type::character_falls_asleep: + case event_type::character_radioactively_mutates: case event_type::character_wears_item: case event_type::character_wields_item: case event_type::character_casts_spell: From d0b238fa51bfc94c682c317c1589447af17e982e Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:17:56 -0500 Subject: [PATCH 5/8] Update mutation_effect_eocs.json --- .../mutation_eocs/mutation_effect_eocs.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json index 3ca4c9d2b7ad6..a9cc747e9bb29 100644 --- a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json +++ b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json @@ -371,9 +371,13 @@ "id": "EOC_RADIATION_MUTATION", "eoc_type": "EVENT", "required_event": "character_radioactively_mutates", - "condition": { "or": [ { "u_is_character" }, { "u_is_npc" } ] }, + "condition": { "or": [ { "u_is_character": true }, { "u_is_npc": true } ] }, "effect": [ - { "set_string_var": "", "target_var": { "context_val": "radiation_mutation_category" }, "parse_tags": true }, + { + "set_string_var": "", + "target_var": { "context_val": "radiation_mutation_category" }, + "parse_tags": true + }, { "u_mutate_category": { "context_val": "radiation_mutation_category" }, "use_vitamins": false } ] }, From a1181f656f302fc73aba8ffe53a498654e03e46f Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Tue, 2 Jul 2024 16:43:20 -0400 Subject: [PATCH 6/8] Apply suggestions from code review --- src/event.cpp | 2 +- src/event.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index f4b8dbd5e9e57..16e286e3f94dc 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -142,7 +142,7 @@ DEFINE_EVENT_HELPER_FIELDS( event_spec_empty ) DEFINE_EVENT_HELPER_FIELDS( event_spec_character ) DEFINE_EVENT_HELPER_FIELDS( event_spec_character_item ) -static_assert( static_cast( event_type::num_event_types ) == 103, +static_assert( static_cast( event_type::num_event_types ) == 104, "This static_assert is a reminder to add a definition below when you add a new " "event_type. If your event_spec specialization inherits from another struct for " "its fields definition then you probably don't need a definition here." ); diff --git a/src/event.h b/src/event.h index 90f34b91d7ea3..5fb8f5060fc32 100644 --- a/src/event.h +++ b/src/event.h @@ -187,7 +187,7 @@ struct event_spec_character_item { }; }; -static_assert( static_cast( event_type::num_event_types ) == 103, +static_assert( static_cast( event_type::num_event_types ) == 104, "This static_assert is to remind you to add a specialization for your new " "event_type below" ); From 3623200aa15a28cfb611066addfd7ed301b47b36 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:16:58 -0500 Subject: [PATCH 7/8] Update data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json --- .../mutation_eocs/mutation_effect_eocs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json index a9cc747e9bb29..0fb3afed2eedf 100644 --- a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json +++ b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json @@ -371,7 +371,7 @@ "id": "EOC_RADIATION_MUTATION", "eoc_type": "EVENT", "required_event": "character_radioactively_mutates", - "condition": { "or": [ { "u_is_character": true }, { "u_is_npc": true } ] }, + "condition": "u_is_avatar", "effect": [ { "set_string_var": "", From 190d8e34d36f6a9ca66806e2a844f1f03e8ecf19 Mon Sep 17 00:00:00 2001 From: Maleclypse <54345792+Maleclypse@users.noreply.github.com> Date: Tue, 2 Jul 2024 20:18:00 -0500 Subject: [PATCH 8/8] Update data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json --- .../mutation_eocs/mutation_effect_eocs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json index 0fb3afed2eedf..9c76a81fefe99 100644 --- a/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json +++ b/data/json/effects_on_condition/mutation_eocs/mutation_effect_eocs.json @@ -371,7 +371,7 @@ "id": "EOC_RADIATION_MUTATION", "eoc_type": "EVENT", "required_event": "character_radioactively_mutates", - "condition": "u_is_avatar", + "condition": "u_is_character", "effect": [ { "set_string_var": "",