Skip to content

Commit

Permalink
Allow NPCs to repair vehicles (#34108)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpwbrown authored and kevingranade committed Sep 25, 2019
1 parent 5e3c369 commit 1b5b501
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 88 deletions.
6 changes: 6 additions & 0 deletions data/json/npcs/TALK_COMMON_ALLY.json
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,12 @@
"condition": { "not": "npc_has_activity" },
"effect": "do_vehicle_deconstruct"
},
{
"text": "Please start repairing any vehicles in a repair zone.",
"topic": "TALK_DONE",
"condition": { "not": "npc_has_activity" },
"effect": "do_vehicle_repair"
},
{
"text": "Please chop logs into planks.",
"topic": "TALK_DONE",
Expand Down
7 changes: 7 additions & 0 deletions data/json/player_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
"verb": "deconstructing a vehicle",
"based_on": "neither"
},
{
"id": "ACT_VEHICLE_REPAIR",
"type": "activity_type",
"activity_level": "ACTIVE_EXERCISE",
"verb": "repairing a vehicle",
"based_on": "neither"
},
{
"id": "ACT_MULTIPLE_CHOP_PLANKS",
"type": "activity_type",
Expand Down
11 changes: 9 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ activity_handlers::do_turn_functions = {
{ activity_id( "ACT_BUILD" ), build_do_turn },
{ activity_id( "ACT_EAT_MENU" ), eat_menu_do_turn },
{ activity_id( "ACT_VEHICLE_DECONSTRUCTION" ), vehicle_deconstruction_do_turn },
{ activity_id( "ACT_VEHICLE_REPAIR" ), vehicle_repair_do_turn },
{ activity_id( "ACT_MULTIPLE_CHOP_TREES" ), chop_trees_do_turn },
{ activity_id( "ACT_CONSUME_FOOD_MENU" ), consume_food_menu_do_turn },
{ activity_id( "ACT_CONSUME_DRINK_MENU" ), consume_drink_menu_do_turn },
Expand Down Expand Up @@ -3196,8 +3197,9 @@ void activity_handlers::churn_finish( player_activity *act, player *p )
void activity_handlers::churn_do_turn( player_activity *act, player *p )
{
( void )act;
( void )p;
p->set_moves( 0 );
if( p->is_npc() ) {
p->set_moves( 0 );
}
}

void activity_handlers::build_do_turn( player_activity *act, player *p )
Expand Down Expand Up @@ -3285,6 +3287,11 @@ void activity_handlers::vehicle_deconstruction_do_turn( player_activity *act, pl
generic_multi_activity_handler( *act, *p );
}

void activity_handlers::vehicle_repair_do_turn( player_activity *act, player *p )
{
generic_multi_activity_handler( *act, *p );
}

void activity_handlers::chop_trees_do_turn( player_activity *act, player *p )
{
generic_multi_activity_handler( *act, *p );
Expand Down
2 changes: 2 additions & 0 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum do_activity_reason : int {
NEEDS_BUTCHERING, // THere is at least one corpse there to butcher, and theres no need for additional tools
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.
};

Expand Down Expand Up @@ -136,6 +137,7 @@ void multiple_fish_do_turn( player_activity *act, player *p );
void multiple_construction_do_turn( player_activity *act, player *p );
void multiple_butcher_do_turn( player_activity *act, player *p );
void vehicle_deconstruction_do_turn( player_activity *act, player *p );
void vehicle_repair_do_turn( player_activity *act, player *p );
void chop_trees_do_turn( player_activity *act, player *p );
void fetch_do_turn( player_activity *act, player *p );
void move_loot_do_turn( player_activity *act, player *p );
Expand Down
265 changes: 184 additions & 81 deletions src/activity_item_handling.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ class Character : public Creature, public visitable<Character>
std::shared_ptr<monster> mounted_creature;
// for loading NPC mounts
int mounted_creature_id;
// for vehicle work
int activity_vehicle_part_index = -1;

void initialize_stomach_contents();

Expand Down
3 changes: 3 additions & 0 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ zone_manager::zone_manager()
types.emplace( zone_type_id( "VEHICLE_DECONSTRUCT" ),
zone_type( translate_marker( "Vehicle Deconstruct Zone" ),
translate_marker( "Any vehicles in this area are marked for deconstruction." ) ) );
types.emplace( zone_type_id( "VEHICLE_REPAIR" ),
zone_type( translate_marker( "Vehicle Repair Zone" ),
translate_marker( "Any vehicles in this area are marked for repair work." ) ) );
types.emplace( zone_type_id( "CAMP_FOOD" ),
zone_type( translate_marker( "Basecamp: Food" ),
translate_marker( "Items in this zone will be added to a basecamp's food supply in the Distribute Food mission." ) ) );
Expand Down
1 change: 1 addition & 0 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,7 @@ void talk_effect_t::parse_string_effect( const std::string &effect_id, JsonObjec
WRAP( dismount ),
WRAP( do_chop_plank ),
WRAP( do_vehicle_deconstruct ),
WRAP( do_vehicle_repair ),
WRAP( do_chop_trees ),
WRAP( do_fishing ),
WRAP( do_construction ),
Expand Down
1 change: 1 addition & 0 deletions src/npctalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void do_construction( npc & );
void do_read( npc & );
void do_chop_plank( npc & );
void do_vehicle_deconstruct( npc & );
void do_vehicle_repair( npc & );
void do_chop_trees( npc & );
void do_fishing( npc & );
void do_farming( npc & );
Expand Down
7 changes: 7 additions & 0 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ void talk_function::do_vehicle_deconstruct( npc &p )
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_vehicle_repair( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
p.assign_activity( activity_id( "ACT_VEHICLE_REPAIR" ) );
p.set_mission( NPC_MISSION_ACTIVITY );
}

void talk_function::do_chop_trees( npc &p )
{
p.set_attitude( NPCATT_ACTIVITY );
Expand Down
1 change: 0 additions & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,6 @@ class player : public Character
player_activity activity;
std::list<player_activity> backlog;
cata::optional<tripoint> destination_point;
int activity_vehicle_part_index = -1;
int volume;
const profession *prof;

Expand Down
7 changes: 3 additions & 4 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ void Character::load( JsonObject &data )
data.read( "stored_calories", stored_calories );
data.read( "radiation", radiation );
data.read( "oxygen", oxygen );

// npc activity on vehicles.
data.read( "activity_vehicle_part_index", activity_vehicle_part_index );
// health
data.read( "healthy", healthy );
data.read( "healthy_mod", healthy_mod );
Expand Down Expand Up @@ -541,6 +542,7 @@ void Character::store( JsonOut &json ) const
json.member( "per_bonus", per_bonus );
json.member( "int_bonus", int_bonus );

json.member( "activity_vehicle_part_index", activity_vehicle_part_index ); // NPC activity
// health
json.member( "healthy", healthy );
json.member( "healthy_mod", healthy_mod );
Expand Down Expand Up @@ -642,7 +644,6 @@ void player::store( JsonOut &json ) const
json.end_array();

json.member( "worn", worn ); // also saves contents
json.member( "activity_vehicle_part_index", activity_vehicle_part_index ); // NPC activity
json.member( "inv" );
inv.json_save_items( json );

Expand Down Expand Up @@ -790,8 +791,6 @@ void player::load( JsonObject &data )
on_stat_change( "pkill", pkill );
on_stat_change( "perceived_pain", get_perceived_pain() );

data.read( "activity_vehicle_part_index", activity_vehicle_part_index );

int tmptar;
int tmptartyp = 0;

Expand Down
2 changes: 2 additions & 0 deletions src/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ struct vehicle_part {

/** Current part damage in same units as item::damage. */
int damage() const;
/** max damage of part base */
int max_damage() const;

/** Current part damage level in same units as item::damage_level */
int damage_level( int max ) const;
Expand Down
5 changes: 5 additions & 0 deletions src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ int vehicle_part::damage() const
return base.damage();
}

int vehicle_part::max_damage() const
{
return base.max_damage();
}

int vehicle_part::damage_level( int max ) const
{
return base.damage_level( max );
Expand Down

0 comments on commit 1b5b501

Please sign in to comment.