From 29bc7ccc0fc2a2be03b4c0d911477d9a79747f7e Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 5 Mar 2020 20:09:42 -0500 Subject: [PATCH 1/5] rewrite fake_spell::get_spell --- src/magic.cpp | 29 +++++++++++++++++------------ src/magic.h | 7 +++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/magic.cpp b/src/magic.cpp index 791ce2006fda8..f8f961a65e221 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -430,10 +430,10 @@ spell::spell( spell_id sp, int xp ) : experience( xp ) {} -spell::spell( spell_id sp, const translation &alt_msg ) : - type( sp ), - alt_message( alt_msg ) -{} +void spell::set_message( const translation &msg ) +{ + alt_message = msg; +} spell_id spell::id() const { @@ -1972,19 +1972,24 @@ void fake_spell::deserialize( JsonIn &jsin ) load( data ); } -spell fake_spell::get_spell( int input_level ) const +spell fake_spell::get_spell( int min_level_override ) const { spell sp( id ); - int lvl = std::min( input_level, sp.get_max_level() ); - if( max_level ) { - lvl = std::min( lvl, *max_level ); - } - if( level > lvl ) { + // the max level this spell will be. can be optionally limited + int spell_limiter = max_level ? std::min( *max_level, sp.get_max_level() ) : sp.get_max_level(); + // level is the minimum level the fake_spell will output + min_level_override = std::max( min_level_override, level ); + if( min_level_override > spell_limiter ) { + // this override is for min level, and does not override max level + min_level_override = spell_limiter; + } + // the "level" of the fake spell is the goal, but needs to be clamped to min and max + int level_of_spell = clamp( level, min_level_override, std::min( sp.get_max_level(), spell_limiter ) ); + if( level > spell_limiter ) { debugmsg( "ERROR: fake spell %s has higher min_level than max_level", id.c_str() ); return sp; } - lvl = clamp( std::max( lvl, level ), level, lvl ); - while( sp.get_level() < lvl ) { + while( sp.get_level() < level_of_spell ) { sp.gain_level(); } return sp; diff --git a/src/magic.h b/src/magic.h index ec405edf52f98..ff81b13e3fbe8 100644 --- a/src/magic.h +++ b/src/magic.h @@ -102,7 +102,8 @@ struct fake_spell { const cata::optional &max_level = cata::nullopt ) : id( sp_id ), max_level( max_level ), self( hit_self ) {} - spell get_spell( int input_level ) const; + // gets the spell with an additional override for minimum level (default 0) + spell get_spell( int min_level_override = 0 ) const; void load( const JsonObject &jo ); void serialize( JsonOut &json ) const; @@ -289,7 +290,9 @@ class spell public: spell() = default; spell( spell_id sp, int xp = 0 ); - spell( spell_id sp, const translation &alt_msg ); + + // sets the message to be different than the spell_type specifies + void set_message( const translation &msg ); // how much exp you need for the spell to gain a level int exp_to_next_level() const; From c5db15d0fab20e16439a9e5179556d09f35097fb Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 5 Mar 2020 20:09:59 -0500 Subject: [PATCH 2/5] rewrite mattack spellcasting to use fake_spell --- src/mattack_actors.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index 324590a6aa011..1797dde5db5a0 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -145,18 +145,14 @@ std::unique_ptr mon_spellcasting_actor::clone() const void mon_spellcasting_actor::load_internal( const JsonObject &obj, const std::string & ) { std::string sp_id; - int spell_level = 0; - mandatory( obj, was_loaded, "spell_id", sp_id ); - optional( obj, was_loaded, "self", self, false ); - optional( obj, was_loaded, "spell_level", spell_level, 0 ); + fake_spell intermediate; + mandatory( obj, was_loaded, "spell_data", intermediate ); translation monster_message; optional( obj, was_loaded, "monster_message", monster_message, //~ " cast on !" to_translation( "%1$s casts %2$s at %3$s!" ) ); - spell_data = spell( spell_id( sp_id ), monster_message ); - for( int i = 0; i <= spell_level; i++ ) { - spell_data.gain_level(); - } + spell_data = intermediate.get_spell(); + spell_data.set_message( monster_message ); avatar fake_player; move_cost = spell_data.casting_time( fake_player ); } From 99f4ac7570e4f793bd56a024d1eb5d6f3f76c088 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 5 Mar 2020 21:48:44 -0500 Subject: [PATCH 3/5] fix up monster json --- data/json/monsters/mi-go.json | 6 +++--- data/mods/Magiclysm/monsters/demon_spider.json | 4 ++-- data/mods/Magiclysm/monsters/dragon.json | 6 +++--- data/mods/Magiclysm/monsters/golems.json | 4 ++-- data/mods/Magiclysm/monsters/lizardfolk.json | 2 +- data/mods/Magiclysm/monsters/monsters.json | 9 ++++----- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/data/json/monsters/mi-go.json b/data/json/monsters/mi-go.json index bd2c424cb13ea..bcd45a915fe74 100644 --- a/data/json/monsters/mi-go.json +++ b/data/json/monsters/mi-go.json @@ -79,7 +79,7 @@ "special_attacks": [ [ "PARROT", 0 ], { "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 23, "armor_multiplier": 0.8 } ] }, - { "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 3, "cooldown": 100 } + { "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 3 }, "cooldown": 100 } ], "death_function": [ "NORMAL" ], "flags": [ @@ -179,7 +179,7 @@ [ "SHRIEK_STUN", 4 ], [ "TAZER", 5 ], { "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 35, "armor_multiplier": 0.7 } ] }, - { "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 1, "cooldown": 100 } + { "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 1 }, "cooldown": 100 } ], "death_function": [ "NORMAL" ], "flags": [ @@ -230,7 +230,7 @@ [ "LONGSWIPE", 12 ], [ "STRETCH_ATTACK", 20 ], { "id": "scratch", "damage_max_instance": [ { "damage_type": "cut", "amount": 30, "armor_multiplier": 0.7 } ] }, - { "type": "spell", "spell_id": "mi-go_slaver_beam", "spell_level": 2, "cooldown": 100 } + { "type": "spell", "spell_data": { "id": "mi-go_slaver_beam", "min_level": 2 }, "cooldown": 100 } ], "death_function": [ "NORMAL" ], "flags": [ diff --git a/data/mods/Magiclysm/monsters/demon_spider.json b/data/mods/Magiclysm/monsters/demon_spider.json index b3039f5219060..d525b3a311e7f 100644 --- a/data/mods/Magiclysm/monsters/demon_spider.json +++ b/data/mods/Magiclysm/monsters/demon_spider.json @@ -88,7 +88,7 @@ "vision_day": 6, "vision_night": 12, "harvest": "demon_spider", - "special_attacks": [ { "type": "spell", "spell_id": "burning_hands", "spell_level": 4, "cooldown": 20 } ], + "special_attacks": [ { "type": "spell", "spell_data": { "id": "burning_hands", "min_level": 4 }, "cooldown": 20 } ], "anger_triggers": [ "FRIEND_ATTACKED", "FRIEND_DIED", "HURT", "STALK", "PLAYER_WEAK", "PLAYER_CLOSE" ], "death_function": [ "NORMAL" ], "flags": [ "SEES", "SMELLS", "HEARS", "VENOM", "WEBWALK", "CLIMBS", "HARDTOSHOOT", "PUSH_MON" ] @@ -110,6 +110,6 @@ "vision_night": 18, "harvest": "demon_spider_queen", "flags": [ "SEES", "SMELLS", "HEARS", "VENOM", "WEBWALK", "CLIMBS", "HARDTOSHOOT", "PUSH_MON", "STUN_IMMUNE" ], - "special_attacks": [ { "type": "spell", "spell_id": "mon_summon_demon_spiderlings", "cooldown": 14 } ] + "special_attacks": [ { "type": "spell", "spell_data": { "id": "mon_summon_demon_spiderlings" }, "cooldown": 14 } ] } ] diff --git a/data/mods/Magiclysm/monsters/dragon.json b/data/mods/Magiclysm/monsters/dragon.json index 351bcde817762..94518d93dfdca 100644 --- a/data/mods/Magiclysm/monsters/dragon.json +++ b/data/mods/Magiclysm/monsters/dragon.json @@ -99,7 +99,7 @@ "special_attacks": [ { "type": "bite", "cooldown": 10 }, [ "scratch", 7 ], - { "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 4, "cooldown": 20 } + { "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 4 }, "cooldown": 20 } ], "flags": [ "SEES", @@ -134,7 +134,7 @@ "special_attacks": [ { "type": "bite", "cooldown": 10 }, [ "scratch", 3 ], - { "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 12, "cooldown": 20 } + { "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 12 }, "cooldown": 20 } ] }, { @@ -159,7 +159,7 @@ "special_attacks": [ { "type": "bite", "cooldown": 10 }, [ "scratch", 3 ], - { "type": "spell", "spell_id": "dragon_breath_black", "spell_level": 22, "cooldown": 30 } + { "type": "spell", "spell_data": { "id": "dragon_breath_black", "min_level": 22 }, "cooldown": 30 } ] } ] diff --git a/data/mods/Magiclysm/monsters/golems.json b/data/mods/Magiclysm/monsters/golems.json index 1244c74070c39..6dcb10f70ca71 100644 --- a/data/mods/Magiclysm/monsters/golems.json +++ b/data/mods/Magiclysm/monsters/golems.json @@ -85,7 +85,7 @@ "dodge": 0, "vision_day": 40, "vision_night": 40, - "special_attacks": [ { "type": "spell", "spell_id": "rocket_punch", "spell_level": 5, "cooldown": 10 } ], + "special_attacks": [ { "type": "spell", "spell_data": { "id": "rocket_punch", "min_level": 5 }, "cooldown": 10 } ], "anger_triggers": [ "PLAYER_CLOSE", "HURT" ], "death_function": [ "BROKEN" ], "flags": [ "SEES", "NO_BREATHE", "ACIDPROOF", "LOUDMOVES" ] @@ -117,7 +117,7 @@ "dodge": 0, "vision_day": 40, "vision_night": 40, - "special_attacks": [ { "type": "spell", "spell_id": "gas_attack", "spell_level": 5, "cooldown": 60 } ], + "special_attacks": [ { "type": "spell", "spell_data": { "id": "gas_attack", "min_level": 5 }, "cooldown": 60 } ], "anger_triggers": [ "PLAYER_CLOSE", "HURT" ], "death_function": [ "BROKEN" ], "flags": [ "SEES", "NO_BREATHE", "ACIDPROOF", "LOUDMOVES" ] diff --git a/data/mods/Magiclysm/monsters/lizardfolk.json b/data/mods/Magiclysm/monsters/lizardfolk.json index 877d57a64c6d9..010800cc17ca9 100644 --- a/data/mods/Magiclysm/monsters/lizardfolk.json +++ b/data/mods/Magiclysm/monsters/lizardfolk.json @@ -92,7 +92,7 @@ "melee_skill": 3, "melee_dice": 2, "melee_dice_sides": 6, - "special_attacks": [ { "type": "spell", "spell_id": "spell_shaman_base", "cooldown": 5 }, [ "scratch", 5 ] ], + "special_attacks": [ { "type": "spell", "spell_data": { "id": "spell_shaman_base" }, "cooldown": 5 }, [ "scratch", 5 ] ], "death_drops": { "subtype": "distribution", "items": [ diff --git a/data/mods/Magiclysm/monsters/monsters.json b/data/mods/Magiclysm/monsters/monsters.json index f9076f9f62f0f..2d3f5f50b1f75 100644 --- a/data/mods/Magiclysm/monsters/monsters.json +++ b/data/mods/Magiclysm/monsters/monsters.json @@ -62,10 +62,9 @@ "special_attacks": [ { "type": "spell", - "spell_id": "bio_acidicspray", + "spell_data": { "id": "bio_acidicspray" }, "cooldown": 20, - "monster_message": "The black pudding burns you with acid!", - "spell_level": 0 + "monster_message": "The black pudding burns %3$s with acid!" } ], "flags": [ "HEARS", "GOODHEARING", "NOHEAD", "POISON", "NO_BREATHE", "ACIDPROOF" ] @@ -105,7 +104,7 @@ "cooldown": 1, "damage_max_instance": [ { "damage_type": "cut", "amount": 25, "armor_multiplier": 1.2 } ] }, - { "type": "spell", "spell_id": "necrotic_gaze", "cooldown": 5, "monster_message": "The krabgek gazes at %3$s!" } + { "type": "spell", "spell_data": { "id": "necrotic_gaze" }, "cooldown": 5, "monster_message": "The krabgek gazes at %3$s!" } ] }, { @@ -268,7 +267,7 @@ "vision_day": 20, "vision_night": 20, "harvest": "stirge", - "special_attacks": [ { "type": "spell", "spell_id": "blood_suck", "spell_level": 3, "cooldown": 3 } ], + "special_attacks": [ { "type": "spell", "spell_data": { "id": "blood_suck", "min_level": 3 }, "cooldown": 3 } ], "anger_triggers": [ "PLAYER_CLOSE" ], "death_function": [ "NORMAL" ], "flags": [ "SEES", "SMELLS", "HEARS", "FLIES", "HIT_AND_RUN", "PATH_AVOID_FIRE", "SWARMS" ] From 38ac0008b04396ae9b73db913d44485068805200 Mon Sep 17 00:00:00 2001 From: Curtis Merrill Date: Thu, 5 Mar 2020 21:52:21 -0500 Subject: [PATCH 4/5] astyle --- data/mods/Magiclysm/monsters/monsters.json | 7 ++++++- src/magic.cpp | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data/mods/Magiclysm/monsters/monsters.json b/data/mods/Magiclysm/monsters/monsters.json index 2d3f5f50b1f75..7c4b78554dded 100644 --- a/data/mods/Magiclysm/monsters/monsters.json +++ b/data/mods/Magiclysm/monsters/monsters.json @@ -104,7 +104,12 @@ "cooldown": 1, "damage_max_instance": [ { "damage_type": "cut", "amount": 25, "armor_multiplier": 1.2 } ] }, - { "type": "spell", "spell_data": { "id": "necrotic_gaze" }, "cooldown": 5, "monster_message": "The krabgek gazes at %3$s!" } + { + "type": "spell", + "spell_data": { "id": "necrotic_gaze" }, + "cooldown": 5, + "monster_message": "The krabgek gazes at %3$s!" + } ] }, { diff --git a/src/magic.cpp b/src/magic.cpp index f8f961a65e221..3edd6db825919 100644 --- a/src/magic.cpp +++ b/src/magic.cpp @@ -1984,7 +1984,8 @@ spell fake_spell::get_spell( int min_level_override ) const min_level_override = spell_limiter; } // the "level" of the fake spell is the goal, but needs to be clamped to min and max - int level_of_spell = clamp( level, min_level_override, std::min( sp.get_max_level(), spell_limiter ) ); + int level_of_spell = clamp( level, min_level_override, std::min( sp.get_max_level(), + spell_limiter ) ); if( level > spell_limiter ) { debugmsg( "ERROR: fake spell %s has higher min_level than max_level", id.c_str() ); return sp; From eada76efb626f872f954b33f333477a7d7deac92 Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Thu, 5 Mar 2020 21:54:11 -0500 Subject: [PATCH 5/5] mattack self --- src/mattack_actors.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mattack_actors.cpp b/src/mattack_actors.cpp index 1797dde5db5a0..d4df46666f003 100644 --- a/src/mattack_actors.cpp +++ b/src/mattack_actors.cpp @@ -147,6 +147,7 @@ void mon_spellcasting_actor::load_internal( const JsonObject &obj, const std::st std::string sp_id; fake_spell intermediate; mandatory( obj, was_loaded, "spell_data", intermediate ); + self = intermediate.self; translation monster_message; optional( obj, was_loaded, "monster_message", monster_message, //~ " cast on !"