Skip to content

Commit

Permalink
Fused monster transfers killing mission to fuser
Browse files Browse the repository at this point in the history
  • Loading branch information
Qrox committed Dec 24, 2020
1 parent 5b2c48c commit 04a5d26
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7564,7 +7564,7 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight )

for( int j = 0; j < i.count; j++ ) {
monster tmp( i.type );
tmp.mission_id = i.mission_id;
tmp.mission_ids = { i.mission_id };
if( i.name != "NONE" ) {
tmp.unique_name = i.name;
}
Expand Down
46 changes: 37 additions & 9 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ void mission::on_creature_death( Creature &poor_dead_dude )
}
monster *mon = dynamic_cast<monster *>( &poor_dead_dude );
if( mon != nullptr ) {
if( mon->mission_id == -1 ) {
if( mon->mission_ids.empty() ) {
return;
}
mission *found_mission = mission::find( mon->mission_id );
const mission_type *type = found_mission->type;
if( type->goal == MGOAL_FIND_MONSTER ) {
found_mission->fail();
}
if( type->goal == MGOAL_KILL_MONSTER ) {
found_mission->step_complete( 1 );
for( const int mission_id : mon->mission_ids ) {
mission *found_mission = mission::find( mission_id );
const mission_type *type = found_mission->type;
if( type->goal == MGOAL_FIND_MONSTER ) {
found_mission->fail();
}
if( type->goal == MGOAL_KILL_MONSTER ) {
found_mission->step_complete( 1 );
}
}
return;
}
Expand Down Expand Up @@ -188,6 +190,32 @@ void mission::on_creature_death( Creature &poor_dead_dude )
}
}

void mission::on_creature_fusion( Creature &fuser, Creature &fused )
{
if( fuser.is_hallucination() || fused.is_hallucination() ) {
return;
}
monster *mon_fuser = dynamic_cast<monster *>( &fuser );
if( mon_fuser == nullptr ) {
debugmsg( "Unimplemented: fuser is not a monster" );
return;
}
monster *mon_fused = dynamic_cast<monster *>( &fused );
if( mon_fused == nullptr ) {
debugmsg( "Unimplemented: fused it not a monster" );
return;
}
for( const int mission_id : mon_fused->mission_ids ) {
const mission *const found_mission = mission::find( mission_id );
const mission_type *const type = found_mission->type;
if( type->goal == MGOAL_KILL_MONSTER ) {
// the fuser has to be killed now!
mon_fuser->mission_ids.emplace( mission_id );
mon_fused->mission_ids.erase( mission_id );
}
}
}

void mission::on_talk_with_npc( const character_id &npc_id )
{
switch( type->goal ) {
Expand Down Expand Up @@ -468,7 +496,7 @@ bool mission::is_complete( const character_id &_npc_id ) const
}
return g->get_creature_if( [&]( const Creature & critter ) {
const monster *const mon_ptr = dynamic_cast<const monster *>( &critter );
return mon_ptr && mon_ptr->mission_id == uid;
return mon_ptr && mon_ptr->mission_ids.count( uid );
} );

case MGOAL_RECRUIT_NPC: {
Expand Down
1 change: 1 addition & 0 deletions src/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ class mission
*/
/*@{*/
static void on_creature_death( Creature &poor_dead_dude );
static void on_creature_fusion( Creature &fuser, Creature &fused );
/*@}*/

// Serializes and unserializes all missions
Expand Down
5 changes: 5 additions & 0 deletions src/monattack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "material.h"
#include "memorial_logger.h"
#include "messages.h"
#include "mission.h"
#include "mondefense.h"
#include "monfaction.h"
#include "monster.h"
Expand Down Expand Up @@ -5750,6 +5751,10 @@ bool mattack::zombie_fuse( monster *z )
z->add_effect( effect_grown_of_fuse, 10_days, true,
critter->get_hp_max() + z->get_effect( effect_grown_of_fuse ).get_intensity() );
z->heal( critter->get_hp(), true );
z->mission_fused.emplace_back( critter->name() );
z->mission_fused.insert( z->mission_fused.end(),
critter->mission_fused.begin(), critter->mission_fused.end() );
mission::on_creature_fusion( *z, *critter );
critter->death_drops = false;
critter->die( z );
return true;
Expand Down
19 changes: 18 additions & 1 deletion src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ monster::monster()
anger = 0;
morale = 2;
faction = mfaction_id( 0 );
mission_id = -1;
no_extra_death_drops = false;
dead = false;
death_drops = true;
Expand Down Expand Up @@ -673,6 +672,17 @@ int monster::print_info( const catacurses::window &w, int vStart, int vLines, in
mvwprintz( w, point( column, ++vStart ), c_light_gray, lines[i] );
}

if( !mission_fused.empty() ) {
// Mission monsters fused into this monster
const std::string fused_desc = string_format( _( "Parts of %s extrude from its body." ),
enumerate_as_string( mission_fused ) );
lines = foldstring( fused_desc, max_width );
numlines = lines.size();
for( int i = 0; i < numlines && vStart < vEnd; i++ ) {
mvwprintz( w, point( column, ++vStart ), c_light_gray, lines[i] );
}
}

// Riding indicator on next line after description.
if( has_effect( effect_ridden ) && mounted_player ) {
mvwprintz( w, point( column, ++vStart ), c_white, _( "Rider: %s" ), mounted_player->disp_name() );
Expand Down Expand Up @@ -732,6 +742,13 @@ std::string monster::extended_description() const
ss += "--\n";
ss += string_format( "<dark>%s</dark>", type->get_description() ) + "\n";
ss += "--\n";
if( !mission_fused.empty() ) {
// Mission monsters fused into this monster
const std::string fused_desc = string_format( _( "Parts of %s extrude from its body." ),
enumerate_as_string( mission_fused ) );
ss += string_format( "<dark>%s</dark>", fused_desc ) + "\n";
ss += "--\n";
}

ss += string_format( _( "It is %s in size." ),
size_names.at( get_size() ) ) + "\n";
Expand Down
4 changes: 3 additions & 1 deletion src/monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ class monster : public Creature
// Our faction (species, for most monsters)
mfaction_id faction;
// If we're related to a mission
int mission_id = 0;
std::set<int> mission_ids;
// Names of mission monsters fused with this monster
std::vector<std::string> mission_fused;
const mtype *type;
// If true, don't spawn loot items as part of death.
bool no_extra_death_drops = false;
Expand Down
2 changes: 1 addition & 1 deletion src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ void overmap::move_hordes()
type.id == mtype_id( "mon_jabberwock" ) || // Jabberwockies are an exception.
this_monster.get_speed() <= 30 || // So are very slow zombies, like crawling zombies.
!this_monster.will_join_horde( INT_MAX ) || // So are zombies who won't join a horde of any size.
this_monster.mission_id != -1 // We mustn't delete monsters that are related to missions.
!this_monster.mission_ids.empty() // We mustn't delete monsters that are related to missions.
) {
// Don't delete the monster, just increment the iterator.
monster_map_it++;
Expand Down
10 changes: 8 additions & 2 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,12 @@ void monster::load( const JsonObject &data )
}

data.read( "friendly", friendly );
data.read( "mission_id", mission_id );
if( data.has_member( "mission_ids" ) ) {
data.read( "mission_ids", mission_ids );
} else if( data.has_member( "mission_id" ) ) {
mission_ids = { data.get_int( "mission_id" ) };
}
data.read( "mission_fused", mission_fused );
data.read( "no_extra_death_drops", no_extra_death_drops );
data.read( "dead", dead );
data.read( "anger", anger );
Expand Down Expand Up @@ -2211,7 +2216,8 @@ void monster::store( JsonOut &json ) const
json.member( "friendly", friendly );
json.member( "fish_population", fish_population );
json.member( "faction", faction.id().str() );
json.member( "mission_id", mission_id );
json.member( "mission_ids", mission_ids );
json.member( "mission_fused", mission_fused );
json.member( "no_extra_death_drops", no_extra_death_drops );
json.member( "dead", dead );
json.member( "anger", anger );
Expand Down

0 comments on commit 04a5d26

Please sign in to comment.