From 2e56ad67178d53e4752b4b4c4d644e7c7a5a8e2e Mon Sep 17 00:00:00 2001 From: Mark Langsdorf Date: Mon, 10 Dec 2018 08:59:33 -0600 Subject: [PATCH] missions: autoset monster_kill_goal for KILL_TYPE and KILL_SPEC Add monster_type as a JSON parameter, and then automatically set the kill goal for MGOAL_KILL_MONSTER_TYPE and MGOAL_KILL_MONSTER_SPEC instead of requiring a start function to do it. --- data/json/npcs/missiondef.json | 3 ++- src/mission.cpp | 10 ++++++++-- src/mission.h | 10 ++++------ src/mission_start.cpp | 11 ----------- src/missiondef.cpp | 4 +++- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/data/json/npcs/missiondef.json b/data/json/npcs/missiondef.json index 190a481103be5..cc6cbd5e0b678 100644 --- a/data/json/npcs/missiondef.json +++ b/data/json/npcs/missiondef.json @@ -509,7 +509,7 @@ "monster_kill_goal": 100, "difficulty": 5, "value": 250000, - "start": "kill_100_z", + "start": "join", "end": "leave", "origins": [ "ORIGIN_SECONDARY" ], "followup": "MISSION_KILL_HORDE_MASTER", @@ -647,6 +647,7 @@ "difficulty": 5, "value": 250000, "start": "kill_20_nightmares", + "monster_type": "mon_charred_nightmare", "monster_kill_goal": 20, "origins": [ "ORIGIN_SECONDARY" ], "dialogue": { diff --git a/src/mission.cpp b/src/mission.cpp index f314d1a657867..14d1f95e662d1 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -30,6 +30,7 @@ mission mission_type::create( const int npc_id ) const ret.value = value; ret.follow_up = follow_up; ret.monster_species = monster_species; + ret.monster_type = monster_type; ret.monster_kill_goal = monster_kill_goal; if( deadline_low != 0 || deadline_high != 0 ) { @@ -186,6 +187,11 @@ void mission::assign( player &u ) player_id = u.getID(); u.on_mission_assignment( *this ); if( status == mission_status::yet_to_start ) { + if( type->goal == MGOAL_KILL_MONSTER_TYPE && monster_type != mtype_id::NULL_ID() ) { + kill_count_to_reach = g->kill_count( monster_type ) + monster_kill_goal; + } else if( type->goal == MGOAL_KILL_MONSTER_SPEC ) { + kill_count_to_reach = g->kill_count( monster_species ) + monster_kill_goal; + } type->start( this ); status = mission_status::in_progress; } @@ -325,7 +331,7 @@ bool mission::is_complete( const int _npc_id ) const return step >= 1; case MGOAL_KILL_MONSTER_TYPE: - return g->kill_count( mtype_id( monster_type ) ) >= kill_count_to_reach; + return g->kill_count( monster_type ) >= kill_count_to_reach; case MGOAL_KILL_MONSTER_SPEC: return g->kill_count( monster_species ) >= kill_count_to_reach; @@ -544,7 +550,7 @@ mission::mission() target_id = string_id::NULL_ID(); recruit_class = NC_NONE; target_npc_id = -1; - monster_type = "mon_null"; + monster_type = mtype_id::NULL_ID(); monster_kill_goal = -1; npc_id = -1; good_fac_id = -1; diff --git a/src/mission.h b/src/mission.h index 449b6e6f4567e..7cd5b8c63f4d5 100644 --- a/src/mission.h +++ b/src/mission.h @@ -24,12 +24,14 @@ class JsonOut; struct mission_type; struct oter_type_t; struct species_type; +struct mtype; enum npc_mission : int; using npc_class_id = string_id; using mission_type_id = string_id; using species_id = string_id; +using mtype_id = string_id; namespace debug_menu { @@ -77,9 +79,6 @@ struct mission_place { /* mission_start functions are first run when a mission is accepted; this * initializes the mission's key values, like the target and description. - * These functions are also run once a turn for each active mission, to check - * if the current goal has been reached. At that point they either start the - * goal, or run the appropriate mission_end function. */ struct mission_start { static void standard( mission * ); // Standard for its goal type @@ -96,7 +95,6 @@ struct mission_start { static void place_grabber( mission * ); // For Old Guard mission static void place_bandit_camp( mission * ); // For Old Guard mission static void place_jabberwock( mission * ); // Put a jabberwok in the woods nearby - static void kill_100_z( mission * ); // Kill 100 more regular zombies static void kill_20_nightmares( mission * ); // Kill 20 more regular nightmares static void kill_horde_master( mission * ); // Kill the master zombie at the center of the horde static void place_npc_software( mission * ); // Put NPC-type-dependent software @@ -187,7 +185,7 @@ struct mission_type { int item_count = 1; npc_class_id recruit_class = npc_class_id( "NC_NONE" ); // The type of NPC you are to recruit int target_npc_id = -1; - std::string monster_type = "mon_null"; + mtype_id monster_type = mtype_id::NULL_ID(); species_id monster_species; int monster_kill_goal = -1; string_id target_id; @@ -265,7 +263,7 @@ class mission string_id target_id; // Destination type to be reached npc_class_id recruit_class;// The type of NPC you are to recruit int target_npc_id; // The ID of a specific NPC to interact with - std::string monster_type; // Monster ID that are to be killed + mtype_id monster_type; // Monster ID that are to be killed species_id monster_species; // Monster species that are to be killed int monster_kill_goal; // The number of monsters you need to kill int kill_count_to_reach; // The kill count you need to reach to complete mission diff --git a/src/mission_start.cpp b/src/mission_start.cpp index 4a2c8ac7cf3e4..f2dff95063b2c 100644 --- a/src/mission_start.cpp +++ b/src/mission_start.cpp @@ -395,20 +395,9 @@ void mission_start::place_jabberwock( mission *miss ) grove.save(); } -void mission_start::kill_100_z( mission *miss ) -{ - npc *p = g->find_npc( miss->npc_id ); - p->set_attitude( NPCATT_FOLLOW );//npc joins you - //kill count of the monsters from a given species you need to reach - miss->kill_count_to_reach = g->kill_count( miss->monster_species ) + miss->monster_kill_goal; -} - void mission_start::kill_20_nightmares( mission *miss ) { target_om_ter( "necropolis_c_44", 3, miss, false, -2 ); - miss->monster_type = mon_charred_nightmare.str(); - //kill count of the monster type you need to reach - miss->kill_count_to_reach = g->kill_count( mon_charred_nightmare ) + miss->monster_kill_goal; } void mission_start::kill_horde_master( mission *miss ) diff --git a/src/missiondef.cpp b/src/missiondef.cpp index 4081971070024..3af7ca6413ca1 100644 --- a/src/missiondef.cpp +++ b/src/missiondef.cpp @@ -105,7 +105,6 @@ static const std::map> mission_fun { "place_grabber", mission_start::place_grabber }, { "place_bandit_camp", mission_start::place_bandit_camp }, { "place_jabberwock", mission_start::place_jabberwock }, - { "kill_100_z", mission_start::kill_100_z }, { "kill_20_nightmares", mission_start::kill_20_nightmares }, { "kill_horde_master", mission_start::kill_horde_master }, { "place_npc_software", mission_start::place_npc_software }, @@ -314,6 +313,9 @@ void mission_type::load( JsonObject &jo, const std::string &src ) if( jo.has_member( "monster_species" ) ) { monster_species = species_id( jo.get_string( "monster_species" ) ); } + if( jo.has_member( "monster_type" ) ) { + monster_type = mtype_id( jo.get_string( "monster_type" ) ); + } if( jo.has_member( "monster_kill_goal" ) ) { monster_kill_goal = jo.get_int( "monster_kill_goal" );