Skip to content

Commit

Permalink
Add use action for bringing up gun cleaning mend menu (cataclysmbntea…
Browse files Browse the repository at this point in the history
…m#2954)

* Add use action for brining up gun cleaning mend menu

* Update iuse.cpp
  • Loading branch information
chaosvolt committed Jul 20, 2023
1 parent af6183e commit e806674
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions data/json/item_actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
"id": "GUNMOD_ATTACH",
"name": { "str": "Attach as gunmod" }
},
{
"type": "item_action",
"id": "GUN_CLEAN",
"name": { "str": "Repair/mend a gun" }
},
{
"type": "item_action",
"id": "GUN_REPAIR",
Expand Down
3 changes: 2 additions & 1 deletion data/json/items/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,8 @@
"price_postapoc": 50,
"material": [ "steel", "cotton" ],
"symbol": ";",
"color": "light_gray"
"color": "light_gray",
"use_action": "GUN_CLEAN"
},
{
"type": "GENERIC",
Expand Down
4 changes: 2 additions & 2 deletions data/json/items/tool/workshop.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
[ "SCREW", 1 ],
[ "CHISEL", 3 ]
],
"use_action": [ "GUN_REPAIR", "CROWBAR", "HAMMER" ],
"use_action": [ "GUN_CLEAN", "GUN_REPAIR", "CROWBAR", "HAMMER" ],
"magazines": [
[
"battery",
Expand Down Expand Up @@ -839,7 +839,7 @@
[ "SCREW", 1 ],
[ "CHISEL", 3 ]
],
"use_action": [ "GUN_REPAIR", "CROWBAR", "HAMMER" ],
"use_action": [ "GUN_CLEAN", "GUN_REPAIR", "CROWBAR", "HAMMER" ],
"magazines": [
[
"battery",
Expand Down
1 change: 1 addition & 0 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ void Item_factory::init()
add_iuse( "GRANADE", &iuse::granade );
add_iuse( "GRANADE_ACT", &iuse::granade_act );
add_iuse( "GRENADE_INC_ACT", &iuse::grenade_inc_act );
add_iuse( "GUN_CLEAN", &iuse::gun_clean );
add_iuse( "GUN_REPAIR", &iuse::gun_repair );
add_iuse( "GUNMOD_ATTACH", &iuse::gunmod_attach );
add_iuse( "TOOLMOD_ATTACH", &iuse::toolmod_attach );
Expand Down
20 changes: 20 additions & 0 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5844,6 +5844,26 @@ int iuse::talking_doll( player *p, item *it, bool, const tripoint & )
return it->type->charges_to_use();
}

int iuse::gun_clean( player *p, item *, bool, const tripoint & )
{
item_location loc = game_menus::inv::titled_menu( g->u, ( "Select the firearm to clean or mend" ) );
if( !loc ) {
p->add_msg_if_player( m_info, _( "You do not have that item!" ) );
return 0;
}
item &fix = *loc;
if( !fix.is_firearm() ) {
p->add_msg_if_player( m_info, _( "That isn't a firearm!" ) );
return 0;
}
if( fix.faults.empty() ) {
p->add_msg_if_player( m_info, _( "There's nothing you can clean or mend with this." ) );
return 0;
}
avatar_funcs::mend_item( *p->as_avatar(), std::move( loc ) );
return 0;
}

int iuse::gun_repair( player *p, item *it, bool, const tripoint & )
{
if( !it->units_sufficient( *p ) ) {
Expand Down
1 change: 1 addition & 0 deletions src/iuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ int radio_mod( player *, item *, bool, const tripoint & );
int remove_all_mods( player *, item *, bool, const tripoint & );
int fishing_rod( player *, item *, bool, const tripoint & );
int fish_trap( player *, item *, bool, const tripoint & );
int gun_clean( player *, item *, bool, const tripoint & );
int gun_repair( player *, item *, bool, const tripoint & );
int gunmod_attach( player *, item *, bool, const tripoint & );
int toolmod_attach( player *, item *, bool, const tripoint & );
Expand Down

0 comments on commit e806674

Please sign in to comment.