void talk_function::start_training( npc &p ) { int cost; time_duration time = 0_turns; std::string name; const skill_id &skill = p.chatbin.skill; const matype_id &style = p.chatbin.style; if( skill.is_valid() && g->u.get_skill_level( skill ) < p.get_skill_level( skill ) ) { cost = calc_skill_training_cost( p, skill ); time = calc_skill_training_time( p, skill ); name = skill.str(); } else if( p.chatbin.style.is_valid() && !g->u.has_martialart( style ) ) { cost = calc_ma_style_training_cost( p, style ); time = calc_ma_style_training_time( p, style ); name = p.chatbin.style.str(); } else { debugmsg( "start_training with no valid skill or style set" ); return; } mission *miss = p.chatbin.mission_selected; if( miss != nullptr && miss->get_assigned_player_id() == g->u.getID() ) { clear_mission( p ); } else if( !pay_npc( p, cost ) ) { return; } g->u.assign_activity( activity_id( "ACT_TRAIN" ), to_moves<int>( time ), p.getID(), 0, name ); p.add_effect( effect_asked_to_train, 6_hours ); }
void talk_function::follow( npc &p ) { g->add_npc_follower( p.getID() ); p.set_attitude( NPCATT_FOLLOW ); g->u.cash += p.cash; p.cash = 0; }
void talk_function::npc_die( npc &p ) { p.die( nullptr ); const std::shared_ptr<npc> guy = overmap_buffer.find_npc( p.getID() ); if( guy && !guy->is_dead() ) { guy->marked_for_death = true; } }
bool vehicle_part::set_crew( const npc &who ) { if( who.is_dead_state() || !who.is_friend() ) { return false; } if( is_broken() || ( !is_seat() && !is_turret() ) ) { return false; } crew_id = who.getID(); return true; }
bool vehicle::assign_seat( vehicle_part &pt, const npc &who ) { if( !pt.is_seat() || !pt.set_crew( who ) ) { return false; } // NPC's can only be assigned to one seat in the vehicle for( auto &e : parts ) { if( &e == &pt ) { continue; // skip this part } if( e.is_seat() ) { const npc *n = e.crew(); if( n && n->getID() == who.getID() ) { e.unset_crew(); } } } return true; }
void talk_function::clear_mission( npc &p ) { mission *miss = p.chatbin.mission_selected; if( miss == nullptr ) { debugmsg( "clear_mission: mission_selected == nullptr" ); return; } const auto it = std::find( p.chatbin.missions_assigned.begin(), p.chatbin.missions_assigned.end(), miss ); if( it == p.chatbin.missions_assigned.end() ) { debugmsg( "clear_mission: mission_selected not in assigned" ); return; } p.chatbin.missions_assigned.erase( it ); if( p.chatbin.missions_assigned.empty() ) { p.chatbin.mission_selected = nullptr; } else { p.chatbin.mission_selected = p.chatbin.missions_assigned.front(); } if( miss->has_follow_up() ) { p.add_new_mission( mission::reserve_new( miss->get_follow_up(), p.getID() ) ); } }
void talk_function::leave( npc &p ) { add_msg( _( "%s leaves." ), p.name ); g->remove_npc_follower( p.getID() ); p.set_attitude( NPCATT_NULL ); }