Skip to content

Commit

Permalink
Fix cabled-only pseudo-tools (CleverRaven#70323)
Browse files Browse the repository at this point in the history
* Fix cabled-only pseudo-tools

* Define variable mag outside of conditional

* Undo accidental copy-paste

* Move "mag" variable initiation outside of conditional

* Use the correct identifier for strings

* Convert string to itype_id rather than other way round

* Promote itype_id of pseudo_magazine to static instance

* Actually declare the global static pseudo_magazine itype_id

* Make weldrig_hack compatible with cabled tools

* Fix compilation bugs

* Update vehicle_use.cpp

* Hide charges of pseudo_tools from display_name

* Add missing semicolon
  • Loading branch information
physics-enthusiast authored Dec 22, 2023
1 parent 4d710e5 commit 53a609f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
25 changes: 22 additions & 3 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "iuse_actor.h"
#include "line.h"
#include "magic.h"
#include "make_static.h"
#include "map.h"
#include "map_iterator.h"
#include "map_selector.h"
Expand Down Expand Up @@ -197,6 +198,7 @@ static const itype_id itype_animal( "animal" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_burnt_out_bionic( "burnt_out_bionic" );
static const itype_id itype_muscle( "muscle" );
static const itype_id itype_pseudo_magazine( "pseudo_magazine" );

static const json_character_flag json_flag_CANNIBAL( "CANNIBAL" );
static const json_character_flag json_flag_PAIN_IMMUNE( "PAIN_IMMUNE" );
Expand Down Expand Up @@ -2346,9 +2348,26 @@ struct weldrig_hack {
// null item should be handled just fine
return null_item_reference();
}

item pseudo_magazine( pseudo.magazine_default() );
pseudo.put_in( pseudo_magazine, pocket_type::MAGAZINE_WELL );
pseudo.set_flag( STATIC( flag_id( "PSEUDO" ) ) );
item mag_mod( "pseudo_magazine_mod" );
mag_mod.set_flag( STATIC( flag_id( "IRREMOVABLE" ) ) );
if( !pseudo.put_in( mag_mod, pocket_type::MOD ).success() ) {
debugmsg( "tool %s has no space for a %s, this is likely a bug",
pseudo.typeId().str(), mag_mod.type->nname( 1 ) );
}
itype_id mag_type;
if( pseudo.can_link_up() ) {
mag_type = itype_pseudo_magazine;
} else {
mag_type = pseudo.magazine_default();
}
item mag( mag_type );
mag.clear_items(); // no initial ammo
if( !pseudo.put_in( mag, pocket_type::MAGAZINE_WELL ).success() ) {
debugmsg( "inserting %s into %s's MAGAZINE_WELL pocket failed",
mag.typeId().str(), pseudo.typeId().str() );
return null_item_reference();
}
pseudo.ammo_set( itype_battery, part->vehicle().drain( itype_battery,
pseudo.ammo_capacity( ammo_battery ) ) );
return pseudo;
Expand Down
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6978,7 +6978,7 @@ std::string item::display_name( unsigned int quantity ) const
} else {
max_amount = ammo_capacity( item_controller->find_template( ammo_default() )->ammo->type );
}
show_amt = !has_flag( flag_RELOAD_AND_SHOOT );
show_amt = ( !has_flag( flag_RELOAD_AND_SHOOT ) && !has_flag( flag_PSEUDO ) );
} else if( count_by_charges() && !has_infinite_charges() ) {
// A chargeable item
amount = charges;
Expand Down
9 changes: 8 additions & 1 deletion src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static const itype_id itype_fungal_seeds( "fungal_seeds" );
static const itype_id itype_large_repairkit( "large_repairkit" );
static const itype_id itype_marloss_seed( "marloss_seed" );
static const itype_id itype_null( "null" );
static const itype_id itype_pseudo_magazine( "pseudo_magazine" );
static const itype_id itype_small_repairkit( "small_repairkit" );
static const itype_id itype_soldering_iron( "soldering_iron" );
static const itype_id itype_water( "water" );
Expand Down Expand Up @@ -1783,7 +1784,13 @@ int vehicle::prepare_tool( item &tool ) const
debugmsg( "tool %s has no space for a %s, this is likely a bug",
tool.typeId().str(), mag_mod.type->nname( 1 ) );
}
item mag( tool.magazine_default() );
itype_id mag_type;
if( tool.can_link_up() ) {
mag_type = itype_pseudo_magazine;
} else {
mag_type = tool.magazine_default();
}
item mag( mag_type );
mag.clear_items(); // no initial ammo
if( !tool.put_in( mag, pocket_type::MAGAZINE_WELL ).success() ) {
debugmsg( "inserting %s into %s's MAGAZINE_WELL pocket failed",
Expand Down

0 comments on commit 53a609f

Please sign in to comment.