Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPC work log - for debugging and feedback #37300

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/json/npcs/TALK_COMMON_ALLY.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,11 @@
"topic": "TALK_DONE",
"condition": { "not": "npc_has_activity" },
"effect": "do_farming"
},
{
"text": "Please show me your work log, so I can see what you've been doing.",
"topic": "TALK_DONE",
"effect": "show_work_log"
}
]
},
Expand Down
42 changes: 42 additions & 0 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,48 @@ static const std::string flag_TREE( "TREE" );

using namespace activity_handlers;

namespace io
{

template<>
std::string enum_to_string<do_activity_reason>( const do_activity_reason act )
{
switch( act ) {
// *INDENT-OFF*
case CAN_DO_CONSTRUCTION: return "CAN_DO_CONSTRUCTION";
case CAN_DO_FETCH: return "CAN_DO_FETCH";
case CAN_DO_PREREQ: return "CAN_DO_PREREQ";
case CAN_DO_PREREQ_2: return "CAN_DO_PREREQ_2";
case NO_COMPONENTS: return "NO_COMPONENTS";
case NO_COMPONENTS_PREREQ: return "NO_COMPONENTS_PREREQ";
case NO_COMPONENTS_PREREQ_2: return "NO_COMPONENTS_PREREQ_2";
case DONT_HAVE_SKILL: return "DONT_HAVE_SKILL";
case NO_ZONE: return "NO_ZONE";
case ALREADY_DONE: return "ALREADY_DONE";
case UNKNOWN_ACTIVITY: return "UNKNOWN_ACTIVITY";
case NEEDS_HARVESTING: return "NEEDS_HARVESTING";
case NEEDS_PLANTING: return "NEEDS_PLANTING";
case NEEDS_TILLING: return "NEEDS_TILLING";
case BLOCKING_TILE: return "BLOCKING_TILE";
case NEEDS_CHOPPING: return "NEEDS_CHOPPING";
case NEEDS_TREE_CHOPPING: return "NEEDS_TREE_CHOPPING";
case NEEDS_BIG_BUTCHERING: return "NEEDS_BIG_BUTCHERING";
case NEEDS_BUTCHERING: return "NEEDS_BUTCHERING";
case ALREADY_WORKING: return "ALREADY_WORKING";
case NEEDS_VEH_DECONST: return "NEEDS_VEH_DECONST";
case NEEDS_VEH_REPAIR: return "NEEDS_VEH_REPAIR";
case NEEDS_FISHING: return "NEEDS_FISHING";
case NEEDS_MINING: return "NEEDS_MINING";
// *INDENT-ON*
case NUM_DO_ACTIVITY_REASON:
break;
}
debugmsg( "Invalid do_activity_reason" );
abort();
}

} // namespace io

const std::map< activity_id, std::function<void( player_activity *, player * )> >
activity_handlers::do_turn_functions = {
{ ACT_BURROW, burrow_do_turn },
Expand Down
23 changes: 19 additions & 4 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <list>

#include "activity_type.h"
#include "player_activity.h"

class player;
Expand Down Expand Up @@ -58,8 +59,14 @@ enum do_activity_reason : int {
ALREADY_WORKING, // somebody is already working there
NEEDS_VEH_DECONST, // There is a vehicle part there that we can deconstruct, given the right tools.
NEEDS_VEH_REPAIR, // There is a vehicle part there that can be repaired, given the right tools.
NEEDS_FISHING, // This spot can be fished, if the right tool is present.
NEEDS_MINING, // This spot can be mined, if the right tool is present.
NEEDS_FISHING // This spot can be fished, if the right tool is present.
NUM_DO_ACTIVITY_REASON
};

template<>
struct enum_traits<do_activity_reason> {
static constexpr do_activity_reason last = NUM_DO_ACTIVITY_REASON;
};

struct activity_reason_info {
Expand All @@ -69,12 +76,18 @@ struct activity_reason_info {
bool can_do;
//construction index
cata::optional<construction_id> con_idx;

//string usage to store specific reaosn strings.
std::string added_reason;
activity_reason_info() : reason( NUM_DO_ACTIVITY_REASON ), can_do( false ),
con_idx( cata::nullopt ), added_reason( std::string() ) {
}
activity_reason_info( do_activity_reason reason_, bool can_do_,
const cata::optional<construction_id> &con_idx_ = cata::nullopt ) :
cata::optional<construction_id> con_idx_ = cata::nullopt,
std::string added_reason_ = std::string() ) :
reason( reason_ ),
can_do( can_do_ ),
con_idx( con_idx_ )
con_idx( con_idx_ ),
added_reason( added_reason_ )
{ }

static activity_reason_info ok( const do_activity_reason &reason_ ) {
Expand All @@ -89,6 +102,8 @@ struct activity_reason_info {
static activity_reason_info fail( const do_activity_reason &reason_ ) {
return activity_reason_info( reason_, false );
}
void serialize( JsonOut &json ) const;
void deserialize( JsonIn &jsin );
};

int butcher_time_to_cut( const player &u, const item &corpse_item, butcher_type action );
Expand Down
Loading