Skip to content

Commit

Permalink
Merge pull request CleverRaven#22804 from kevingranade/astyle-whoknows
Browse files Browse the repository at this point in the history
Astyle mission.cpp and npctalk.cpp
  • Loading branch information
Rivet-the-Zombie authored Feb 3, 2018
2 parents d7badd3 + 20687ba commit ed53328
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 83 deletions.
1 change: 0 additions & 1 deletion astyle_blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ src/mapgen_functions.cpp
src/martialarts.cpp
src/melee.cpp
src/mission_companion.cpp
src/mission.cpp
src/missiondef.cpp
src/mission_start.cpp
src/mod_manager.cpp
Expand Down
158 changes: 80 additions & 78 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ mission mission_type::create( const int npc_id ) const
ret.value = value;
ret.follow_up = follow_up;

if (deadline_low != 0 || deadline_high != 0) {
ret.deadline = int(calendar::turn) + rng(deadline_low, deadline_high);
if( deadline_low != 0 || deadline_high != 0 ) {
ret.deadline = int( calendar::turn ) + rng( deadline_low, deadline_high );
} else {
ret.deadline = 0;
}
Expand All @@ -40,7 +40,7 @@ mission mission_type::create( const int npc_id ) const

std::unordered_map<int, std::unique_ptr<mission>> world_missions;

mission* mission::reserve_new( const mission_type_id type, const int npc_id )
mission *mission::reserve_new( const mission_type_id type, const int npc_id )
{
const auto tmp = mission_type::get( type )->create( npc_id );
// @todo Warn about overwrite?
Expand Down Expand Up @@ -82,9 +82,9 @@ void mission::process_all()
}
}

std::vector<mission*> mission::to_ptr_vector( const std::vector<int> &vec )
std::vector<mission *> mission::to_ptr_vector( const std::vector<int> &vec )
{
std::vector<mission*> result;
std::vector<mission *> result;
for( auto &id : vec ) {
const auto miss = find( id );
if( miss != nullptr ) {
Expand All @@ -94,7 +94,7 @@ std::vector<mission*> mission::to_ptr_vector( const std::vector<int> &vec )
return result;
}

std::vector<int> mission::to_uid_vector( const std::vector<mission*> &vec )
std::vector<int> mission::to_uid_vector( const std::vector<mission *> &vec )
{
std::vector<int> result;
for( auto &miss : vec ) {
Expand Down Expand Up @@ -141,7 +141,7 @@ void mission::on_creature_death( Creature &poor_dead_dude )
return;
}
const auto dead_guys_id = p->getID();
for( auto & e : world_missions ) {
for( auto &e : world_missions ) {
auto &i = *e.second;
if( !i.in_progress() ) {
continue;
Expand All @@ -161,7 +161,7 @@ void mission::on_creature_death( Creature &poor_dead_dude )
}
}

mission* mission::reserve_random( const mission_origin origin, const tripoint &p, const int npc_id )
mission *mission::reserve_random( const mission_origin origin, const tripoint &p, const int npc_id )
{
const auto type = mission_type::get_random_id( origin, p );
if( type.is_null() ) {
Expand All @@ -177,7 +177,8 @@ void mission::assign( player &u )
return;
}
if( player_id != -1 ) {
debugmsg( "tried to assign mission %d to player, but mission is already assigned to %d", uid, player_id );
debugmsg( "tried to assign mission %d to player, but mission is already assigned to %d", uid,
player_id );
return;
}
player_id = u.getID();
Expand Down Expand Up @@ -232,16 +233,17 @@ void mission::wrap_up()
if( u.getID() != player_id ) {
// This is called from npctalk.cpp, the npc should only offer the option to wrap up mission
// that have been assigned to the current player.
debugmsg( "mission::wrap_up called, player %d was assigned, but current player is %d", player_id, u.getID() );
debugmsg( "mission::wrap_up called, player %d was assigned, but current player is %d", player_id,
u.getID() );
}

status = mission_status::success;
u.on_mission_finished( *this );
std::vector<item_comp> comps;
switch( type->goal ) {
case MGOAL_FIND_ITEM:
comps.push_back(item_comp(type->item_id, item_count));
u.consume_items(comps);
comps.push_back( item_comp( type->item_id, item_count ) );
u.consume_items( comps );
break;
case MGOAL_FIND_ANY_ITEM:
u.remove_mission_items( uid );
Expand All @@ -262,32 +264,29 @@ bool mission::is_complete( const int _npc_id ) const

auto &u = g->u;
switch( type->goal ) {
case MGOAL_GO_TO:
{
const tripoint cur_pos = g->u.global_omt_location();
return ( rl_dist( cur_pos, target ) <= 1 );
}
break;
case MGOAL_GO_TO: {
const tripoint cur_pos = g->u.global_omt_location();
return ( rl_dist( cur_pos, target ) <= 1 );
}
break;

case MGOAL_GO_TO_TYPE:
{
const auto cur_ter = overmap_buffer.ter( g->u.global_omt_location() );
return is_ot_type( type->target_id.str(), cur_ter );
}
break;
case MGOAL_GO_TO_TYPE: {
const auto cur_ter = overmap_buffer.ter( g->u.global_omt_location() );
return is_ot_type( type->target_id.str(), cur_ter );
}
break;

case MGOAL_FIND_ITEM:
{
case MGOAL_FIND_ITEM: {
inventory tmp_inv = u.crafting_inventory();
// TODO: check for count_by_charges and use appropriate player::has_* function
if (!tmp_inv.has_amount(type->item_id, item_count)) {
if( !tmp_inv.has_amount( type->item_id, item_count ) ) {
return tmp_inv.has_amount( type->item_id, 1 ) && tmp_inv.has_charges( type->item_id, item_count );
}
if( npc_id != -1 && npc_id != _npc_id ) {
return false;
}
}
return true;
return true;

case MGOAL_FIND_ANY_ITEM:
return u.has_mission_item( uid ) && ( npc_id == -1 || npc_id == _npc_id );
Expand All @@ -296,27 +295,25 @@ bool mission::is_complete( const int _npc_id ) const
if( npc_id != -1 && npc_id != _npc_id ) {
return false;
}
return g->get_creature_if( [&]( const Creature &critter ) {
const monster *const mon_ptr = dynamic_cast<const monster*>( &critter );
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;
} );

case MGOAL_RECRUIT_NPC:
{
npc *p = g->find_npc( target_npc_id );
return p != nullptr && p->attitude == NPCATT_FOLLOW;
}
case MGOAL_RECRUIT_NPC: {
npc *p = g->find_npc( target_npc_id );
return p != nullptr && p->attitude == NPCATT_FOLLOW;
}

case MGOAL_RECRUIT_NPC_CLASS:
{
const auto npcs = overmap_buffer.get_npcs_near_player( 100 );
for( auto & npc : npcs ) {
if( npc->myclass == recruit_class && npc->attitude == NPCATT_FOLLOW ) {
return true;
}
case MGOAL_RECRUIT_NPC_CLASS: {
const auto npcs = overmap_buffer.get_npcs_near_player( 100 );
for( auto &npc : npcs ) {
if( npc->myclass == recruit_class && npc->attitude == NPCATT_FOLLOW ) {
return true;
}
return false;
}
return false;
}

case MGOAL_FIND_NPC:
return npc_id == _npc_id;
Expand Down Expand Up @@ -454,21 +451,21 @@ void mission::set_player_id_legacy_0c( int id )

std::string mission::name()
{
if (type == NULL) {
if( type == NULL ) {
return "NULL";
}
return _( type->name.c_str() );
}

mission_type_id mission::mission_id()
{
if (type == NULL) {
if( type == NULL ) {
return mission_type_id( "NULL" );
}
return type->id;
}

void mission::load_info(std::istream &data)
void mission::load_info( std::istream &data )
{
int type_id, rewtype, reward_id, rew_skill, tmpfollow, item_num, target_npc_id;
std::string rew_item, itemid;
Expand All @@ -477,38 +474,39 @@ void mission::load_info(std::istream &data)
std::string tmpdesc;
do {
data >> tmpdesc;
if (tmpdesc != "<>") {
if( tmpdesc != "<>" ) {
description += tmpdesc + " ";
}
} while (tmpdesc != "<>");
} while( tmpdesc != "<>" );
description = description.substr( 0, description.size() - 1 ); // Ending ' '
bool failed; // Dummy, no one has saves this old
data >> failed >> value >> rewtype >> reward_id >> rew_item >> rew_skill >>
uid >> target.x >> target.y >> itemid >> item_num >> deadline >> npc_id >>
good_fac_id >> bad_fac_id >> step >> tmpfollow >> target_npc_id;
target.z = 0;
follow_up = mission_type::from_legacy(tmpfollow);
reward.type = npc_favor_type(reward_id);
follow_up = mission_type::from_legacy( tmpfollow );
reward.type = npc_favor_type( reward_id );
reward.item_id = itype_id( rew_item );
reward.skill = Skill::from_legacy_int( rew_skill );
item_id = itype_id(itemid);
item_count = int(item_num);
item_id = itype_id( itemid );
item_count = int( item_num );
}

std::string mission::dialogue_for_topic( const std::string &in_topic ) const
{
// The internal keys are pretty ugly, it's better to translate them here than globally
static const std::map<std::string, std::string> topic_translation = {{
{ "TALK_MISSION_DESCRIBE", "describe" },
{ "TALK_MISSION_OFFER", "offer" },
{ "TALK_MISSION_ACCEPTED", "accepted" },
{ "TALK_MISSION_REJECTED", "rejected" },
{ "TALK_MISSION_ADVICE", "advice" },
{ "TALK_MISSION_INQUIRE", "inquire" },
{ "TALK_MISSION_SUCCESS", "success" },
{ "TALK_MISSION_SUCCESS_LIE", "success_lie" },
{ "TALK_MISSION_FAILURE", "failure" }
}};
{ "TALK_MISSION_DESCRIBE", "describe" },
{ "TALK_MISSION_OFFER", "offer" },
{ "TALK_MISSION_ACCEPTED", "accepted" },
{ "TALK_MISSION_REJECTED", "rejected" },
{ "TALK_MISSION_ADVICE", "advice" },
{ "TALK_MISSION_INQUIRE", "inquire" },
{ "TALK_MISSION_SUCCESS", "success" },
{ "TALK_MISSION_SUCCESS_LIE", "success_lie" },
{ "TALK_MISSION_FAILURE", "failure" }
}
};

const auto &replacement = topic_translation.find( in_topic );
const std::string &topic = replacement != topic_translation.end() ? replacement->second : in_topic;
Expand All @@ -518,7 +516,8 @@ std::string mission::dialogue_for_topic( const std::string &in_topic ) const
return _( response->second.c_str() );
}

return string_format( "Someone forgot to code this message id is %s, topic is %s!", type->id.c_str(), topic.c_str() );
return string_format( "Someone forgot to code this message id is %s, topic is %s!",
type->id.c_str(), topic.c_str() );
}

mission::mission()
Expand All @@ -528,7 +527,7 @@ mission::mission()
status = mission_status::yet_to_start;
value = 0;
uid = -1;
target = tripoint(INT_MIN, INT_MIN, INT_MIN);
target = tripoint( INT_MIN, INT_MIN, INT_MIN );
item_id = "null";
item_count = 1;
target_id = string_id<oter_type_t>::NULL_ID();
Expand All @@ -544,24 +543,27 @@ mission::mission()
player_id = -1;
}

mission_type::mission_type(mission_type_id ID, std::string NAME, mission_goal GOAL, int DIF, int VAL,
bool URGENT,
std::function<bool(const tripoint &)> PLACE,
std::function<void(mission *)> START,
std::function<void(mission *)> END,
std::function<void(mission *)> FAIL) :
id (ID), name (NAME), goal (GOAL), difficulty (DIF), value (VAL),
urgent(URGENT), place (PLACE), start (START), end (END), fail (FAIL)
mission_type::mission_type( mission_type_id ID, std::string NAME, mission_goal GOAL, int DIF,
int VAL,
bool URGENT,
std::function<bool( const tripoint & )> PLACE,
std::function<void( mission * )> START,
std::function<void( mission * )> END,
std::function<void( mission * )> FAIL ) :
id( ID ), name( NAME ), goal( GOAL ), difficulty( DIF ), value( VAL ),
urgent( URGENT ), place( PLACE ), start( START ), end( END ), fail( FAIL )
{
};

namespace io {
namespace io
{
static const std::map<std::string, mission::mission_status> status_map = {{
{ "yet_to_start", mission::mission_status::yet_to_start },
{ "in_progress", mission::mission_status::in_progress },
{ "success", mission::mission_status::success },
{ "failure", mission::mission_status::failure }
}};
{ "yet_to_start", mission::mission_status::yet_to_start },
{ "in_progress", mission::mission_status::in_progress },
{ "success", mission::mission_status::success },
{ "failure", mission::mission_status::failure }
}
};
template<>
mission::mission_status string_to_enum<mission::mission_status>( const std::string &data )
{
Expand Down
9 changes: 5 additions & 4 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ void npc::talk_to_u()
decide_needs();

d.win = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH,
( TERMY > FULL_SCREEN_HEIGHT ) ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0,
( TERMX > FULL_SCREEN_WIDTH ) ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 );
( TERMY > FULL_SCREEN_HEIGHT ) ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0,
( TERMX > FULL_SCREEN_WIDTH ) ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 );

// Main dialogue loop
do {
Expand Down Expand Up @@ -3791,7 +3791,8 @@ TAB key to switch lists, letters to pick items, Enter to finalize, Esc to quit,\
cost_string.c_str(), ( double )std::abs( cash ) / 100 );

if( !deal.empty() ) {
mvwprintz( w_head, 3, ( TERMX - deal.length() ) / 2, cost < 0 ? c_light_red : c_light_green, deal.c_str() );
mvwprintz( w_head, 3, ( TERMX - deal.length() ) / 2, cost < 0 ? c_light_red : c_light_green,
deal.c_str() );
}
draw_border( w_them, ( focus_them ? c_yellow : BORDER_COLOR ) );
draw_border( w_you, ( !focus_them ? c_yellow : BORDER_COLOR ) );
Expand Down Expand Up @@ -3871,7 +3872,7 @@ TAB key to switch lists, letters to pick items, Enter to finalize, Esc to quit,\
case '?':
update = true;
w_tmp = catacurses::newwin( 3, 21, 1 + ( TERMY - FULL_SCREEN_HEIGHT ) / 2,
30 + ( TERMX - FULL_SCREEN_WIDTH ) / 2 );
30 + ( TERMX - FULL_SCREEN_WIDTH ) / 2 );
mvwprintz( w_tmp, 1, 1, c_red, _( "Examine which item?" ) );
draw_border( w_tmp );
wrefresh( w_tmp );
Expand Down

0 comments on commit ed53328

Please sign in to comment.