Skip to content

Commit 23aab34

Browse files
authored
[MOM] Farhand loots items (#82329)
* simple implementation of pickup_items eoc * basic far hand proof of concept * Pickup allows multiple arbitrary tiles * Finish pickup spell effect + demo with farhand * basic constraints implementation * remove pickup_constraints struct, just use pick_info instead * hook up pickup spell effect to pick_info fully * Set up final spell definitions * documentation * hook up eoc to extra parameters * astyle * initialization order * remove unused variable * slowly fix the errors discovered by general build * fix build * clang * IWYU * astyle * more clang
1 parent ca8f492 commit 23aab34

16 files changed

+187
-35
lines changed

data/mods/MindOverMatter/powers/telekinesis.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"//": "power ID exists for legacy reasons",
55
"type": "SPELL",
66
"name": "[Ψ]Far Hand",
7-
"description": "Move a set of items towards or away from you.",
7+
"description": "Pickup items at a distance or push them away from you.",
88
"message": "",
99
"teachable": false,
1010
"valid_targets": [ "self" ],
@@ -32,31 +32,41 @@
3232
"description": { "str": "The actual effect that causes the far hand. It's a bug if you have it.", "//~": "NO_I18N" },
3333
"message": "",
3434
"teachable": false,
35-
"valid_targets": [ "item", "ground" ],
35+
"valid_targets": [ "item", "ground", "self", "ally", "hostile" ],
3636
"skill": "metaphysics",
3737
"flags": [ "PSIONIC", "RANDOM_DAMAGE", "NO_HANDS", "NO_LEGS", "NO_EXPLOSION_SFX" ],
3838
"difficulty": 1,
3939
"max_level": { "math": [ "int_to_level(1)" ] },
40-
"effect": "directed_push",
40+
"effect": "pickup",
4141
"shape": "blast",
4242
"min_damage": {
4343
"math": [
44-
"min( (( (u_spell_level('telekinetic_pull') * 0.4) + 1) * (scaling_factor(u_val('intelligence') ) ) * u_nether_attunement_power_scaling * -1), 40)"
44+
"max( 50 - ( ( u_spell_level('telekinetic_pull') * 3 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling ), 0 )"
4545
]
4646
},
4747
"max_damage": {
4848
"math": [
49-
"min( (( (u_spell_level('telekinetic_pull') * 0.9) + 4) * (scaling_factor(u_val('intelligence') ) ) * u_nether_attunement_power_scaling * -1), 40)"
49+
"max( 100 - ( ( u_spell_level('telekinetic_pull') * 4 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling ), 0 )"
50+
]
51+
},
52+
"min_aoe": {
53+
"math": [
54+
"( u_spell_level('telekinetic_pull') * 0.2 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling"
55+
]
56+
},
57+
"max_aoe": {
58+
"math": [
59+
"( u_spell_level('telekinetic_pull') * 0.2 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling"
5060
]
5161
},
5262
"min_range": {
5363
"math": [
54-
"min( (( (u_spell_level('telekinetic_pull') * 0.9) + 2) * (scaling_factor(u_val('intelligence') ) ) * u_nether_attunement_power_scaling), 40)"
64+
"min( ( ( ( u_spell_level('telekinetic_pull') * 0.9 ) + 2 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling ), 40 )"
5565
]
5666
},
5767
"max_range": {
5868
"math": [
59-
"min( (( (u_spell_level('telekinetic_pull') * 0.9) + 2) * (scaling_factor(u_val('intelligence') ) ) * u_nether_attunement_power_scaling), 40)"
69+
"min( ( ( ( u_spell_level('telekinetic_pull') * 0.9 ) + 2 ) * ( scaling_factor( u_val('intelligence') ) ) * u_nether_attunement_power_scaling ), 40 )"
6070
]
6171
}
6272
},

doc/JSON/MAGIC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Effect | Description
206206
`noise` | Causes damage() amount of noise at the target. Note: the noise can be described further with `sound_type`, `sound_description`, `sound_ambient`, `sound_id` and `sound_variant`.
207207
`pain_split` | Evens out all of your limbs' damage.
208208
`pull_target` | Attempts to pull the target towards the caster in a straight line. If the path is blocked by impassable furniture or terrain, the effect fails.
209+
`pickup` | Opens up the pickup menu at the target(s), allowing characters to pick up items at the area. For every 1 damage in the spell's definition, each item takes 1 extra move to pick up.
209210
`recharge_vehicle` | Increases or decreases the battery charge of a vehicle or battery-connected power grid. Damage is equal to the charge (negative decreases).
210211
`recover_energy` | Recovers an energy source equal to damage of the spell and may be one of `BIONIC`, `SLEEPINESS`, `PAIN`, `MANA` or `STAMINA`. Alternative notation can be used for spell consuming vitamins, see example below
211212
`remove_effect` | Removes `effect_str` effects from all creatures in the aoe.

src/activity_actor_definitions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ class pickup_activity_actor : public activity_actor
555555
const std::optional<tripoint_bub_ms> &starting_pos,
556556
bool autopickup ) : target_items( target_items ),
557557
quantities( quantities ), starting_pos( starting_pos ), stash_successful( true ),
558+
autopickup( autopickup ) {
559+
info = Pickup::pick_info();
560+
}
561+
pickup_activity_actor( const std::vector<item_location> &target_items,
562+
const std::vector<int> &quantities,
563+
const std::optional<tripoint_bub_ms> &starting_pos,
564+
bool autopickup, Pickup::pick_info &info ) : target_items( target_items ),
565+
quantities( quantities ), info( info ), starting_pos( starting_pos ), stash_successful( true ),
558566
autopickup( autopickup ) {}
559567

560568
/**

src/character.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ namespace catacurses
9191
{
9292
class window;
9393
} // namespace catacurses
94+
namespace Pickup
95+
{
96+
struct pick_info;
97+
} // namespace Pickup
98+
9499
enum action_id : int;
95100
enum class proficiency_bonus_type : int;
96101
enum class recipe_filter_flags : int;
@@ -2455,6 +2460,7 @@ class Character : public Creature, public visitable
24552460
* Requires sufficient storage; items cannot be wielded or worn from this activity.
24562461
*/
24572462
void pick_up( const drop_locations &what );
2463+
void pick_up( const drop_locations &what, Pickup::pick_info &info );
24582464

24592465
bool is_wielding( const item &target ) const;
24602466

src/character_inventory.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "map.h"
3535
#include "map_selector.h"
3636
#include "options.h"
37+
#include "pickup.h"
3738
#include "pimpl.h"
3839
#include "pocket_type.h"
3940
#include "ret_val.h"
@@ -623,6 +624,12 @@ void Character::drop( const drop_locations &what, const tripoint_bub_ms &target,
623624
}
624625

625626
void Character::pick_up( const drop_locations &what )
627+
{
628+
Pickup::pick_info pick_info = Pickup::pick_info();
629+
pick_up( what, pick_info );
630+
}
631+
632+
void Character::pick_up( const drop_locations &what, Pickup::pick_info &info )
626633
{
627634
if( what.empty() ) {
628635
return;
@@ -639,7 +646,7 @@ void Character::pick_up( const drop_locations &what )
639646
}
640647

641648
last_item = item( *items.back() ).typeId();
642-
assign_activity( pickup_activity_actor( items, quantities, pos_bub(), false ) );
649+
assign_activity( pickup_activity_actor( items, quantities, pos_bub(), false, info ) );
643650
}
644651

645652
invlets_bitset Character::allocated_invlets() const

src/game.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6485,7 +6485,7 @@ void game::pickup()
64856485
return;
64866486
}
64876487
// Pick up items only from the selected tile
6488-
u.pick_up( game_menus::inv::pickup( where_ ) );
6488+
u.pick_up( game_menus::inv::pickup( {where_.value()} ) );
64896489
}
64906490

64916491
void game::pickup_all()
@@ -6505,7 +6505,7 @@ void game::pickup( const tripoint_bub_ms &p )
65056505
add_draw_callback( hilite_cb );
65066506

65076507
// Pick up items only from the selected tile
6508-
u.pick_up( game_menus::inv::pickup( p ) );
6508+
u.pick_up( game_menus::inv::pickup( {p} ) );
65096509
}
65106510

65116511
//Shift player by one tile, look_around(), then restore previous position.

src/game_inventory.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "npctrade.h"
4949
#include "options.h"
5050
#include "output.h"
51+
#include "pickup.h"
5152
#include "pimpl.h"
5253
#include "player_activity.h"
5354
#include "pocket_type.h"
@@ -2426,26 +2427,41 @@ drop_locations game_menus::inv::multidrop( Character &you )
24262427
return inv_s.execute();
24272428
}
24282429

2429-
drop_locations game_menus::inv::pickup( const std::optional<tripoint_bub_ms> &target,
2430+
drop_locations game_menus::inv::pickup( const std::set<tripoint_bub_ms> &targets )
2431+
{
2432+
return pickup( targets, {} );
2433+
}
2434+
2435+
drop_locations game_menus::inv::pickup( const std::set<tripoint_bub_ms> &targets,
24302436
const std::vector<drop_location> &selection )
2437+
{
2438+
Pickup::pick_info pickup_info = Pickup::pick_info();
2439+
return pickup( targets, selection, pickup_info );
2440+
}
2441+
2442+
drop_locations game_menus::inv::pickup( const std::set<tripoint_bub_ms> &targets,
2443+
const std::vector<drop_location> &selection,
2444+
Pickup::pick_info &info )
24312445
{
24322446
avatar &you = get_avatar();
24332447
pickup_inventory_preset preset( you, /*skip_wield_check=*/true, /*ignore_liquidcont=*/true );
24342448
preset.save_state = &pickup_ui_default_state;
24352449

2436-
pickup_selector pick_s( you, preset, _( "ITEMS TO PICK UP" ), target );
2450+
pickup_selector pick_s( you, preset, _( "ITEMS TO PICK UP" ), targets );
24372451

24382452
// Add items from the selected tile, or from current and all surrounding tiles
2439-
if( target ) {
2440-
pick_s.add_vehicle_items( *target );
2441-
pick_s.add_map_items( *target );
2453+
if( !targets.empty() ) {
2454+
for( tripoint_bub_ms target : targets ) {
2455+
pick_s.add_vehicle_items( target );
2456+
pick_s.add_map_items( target );
2457+
}
24422458
} else {
24432459
pick_s.add_nearby_items();
24442460
}
24452461
pick_s.set_title( _( "Pickup" ) );
24462462

24472463
if( pick_s.empty() ) {
2448-
if( target ) {
2464+
if( !targets.empty() ) {
24492465
add_msg( _( "There is nothing to pick up." ) );
24502466
} else {
24512467
add_msg( _( "There is nothing to pick up nearby." ) );
@@ -2457,6 +2473,12 @@ drop_locations game_menus::inv::pickup( const std::optional<tripoint_bub_ms> &ta
24572473
pick_s.apply_selection( selection );
24582474
}
24592475

2476+
if( info.max_volume != -1_ml ) {
2477+
pick_s.overriden_volume = info.max_volume;
2478+
}
2479+
if( info.max_mass != -1_gram ) {
2480+
pick_s.overriden_mass = info.max_mass;
2481+
}
24602482
return pick_s.execute();
24612483
}
24622484

src/game_inventory.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ enum efile_action : int;
2727
using item_filter = std::function<bool( const item & )>;
2828
using item_location_filter = std::function<bool ( const item_location & )>;
2929

30+
namespace Pickup
31+
{
32+
struct pick_info;
33+
} // namespace Pickup
34+
3035
/**
3136
* A boiled-down shortcut for inventory_selector_preset.
3237
* @param filter - function solely determines what is shown in the item list.
@@ -113,8 +118,12 @@ drop_locations multidrop( Character &you );
113118
* Otherwise, pick up items from the avatar's current location and all adjacent tiles.
114119
* @return A list of pairs of item_location, quantity.
115120
*/
116-
drop_locations pickup( const std::optional<tripoint_bub_ms> &target = std::nullopt,
117-
const std::vector<drop_location> &selection = {} );
121+
drop_locations pickup( const std::set<tripoint_bub_ms> &targets = {} );
122+
drop_locations pickup( const std::set<tripoint_bub_ms> &targets,
123+
const std::vector<drop_location> &selection );
124+
drop_locations pickup( const std::set<tripoint_bub_ms> &targets,
125+
const std::vector<drop_location> &selection,
126+
Pickup::pick_info &info );
118127

119128
drop_locations smoke_food( Character &you, units::volume total_capacity,
120129
units::volume used_capacity );

src/inventory_ui.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,7 +4239,7 @@ inventory_selector::stats inventory_insert_selector::get_raw_stats() const
42394239
}
42404240

42414241
pickup_selector::pickup_selector( Character &p, const inventory_selector_preset &preset,
4242-
const std::string &selection_column_title, const std::optional<tripoint_bub_ms> &where ) :
4242+
const std::string &selection_column_title, const std::set<tripoint_bub_ms> &where ) :
42434243
inventory_multiselector( p, preset, selection_column_title ), where( where )
42444244
{
42454245
ctxt.register_action( "WEAR" );
@@ -4362,11 +4362,7 @@ void pickup_selector::reopen_menu()
43624362
{
43634363
// copy the member variables to still be valid on call
43644364
uistate.open_menu = [where = where, to_use = to_use]() {
4365-
std::optional<tripoint_bub_ms> temp;
4366-
if( where.has_value() ) {
4367-
temp = tripoint_bub_ms( where.value() );
4368-
}
4369-
get_player_character().pick_up( game_menus::inv::pickup( temp, to_use ) );
4365+
get_player_character().pick_up( game_menus::inv::pickup( where, to_use ) );
43704366
};
43714367
}
43724368

@@ -4409,9 +4405,9 @@ inventory_selector::stats pickup_selector::get_raw_stats() const
44094405

44104406
return get_weight_and_volume_and_holster_stats(
44114407
u.weight_carried() + weight,
4412-
u.weight_capacity(),
4408+
overriden_mass.has_value() ? overriden_mass.value() : u.weight_capacity(),
44134409
u.volume_carried() + volume,
4414-
u.volume_capacity(),
4410+
overriden_volume.has_value() ? overriden_volume.value() : u.volume_capacity(),
44154411
u.max_single_item_length(),
44164412
u.max_single_item_volume(),
44174413
u.free_holster_volume(),

src/inventory_ui.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <list>
1212
#include <memory>
1313
#include <optional>
14+
#include <set>
1415
#include <string>
1516
#include <string_view>
1617
#include <utility>
@@ -28,7 +29,7 @@
2829
#include "pocket_type.h"
2930
#include "point.h"
3031
#include "translations.h"
31-
#include "units_fwd.h"
32+
#include "units.h"
3233

3334
class Character;
3435
class JsonObject;
@@ -1086,9 +1087,12 @@ class pickup_selector : public inventory_multiselector
10861087
public:
10871088
explicit pickup_selector( Character &p, const inventory_selector_preset &preset = default_preset,
10881089
const std::string &selection_column_title = _( "ITEMS TO PICK UP" ),
1089-
const std::optional<tripoint_bub_ms> &where = std::nullopt );
1090+
const std::set<tripoint_bub_ms> &where = {} );
10901091
drop_locations execute();
10911092
void apply_selection( std::vector<drop_location> selection );
1093+
1094+
std::optional<units::volume> overriden_volume;
1095+
std::optional<units::mass> overriden_mass;
10921096
protected:
10931097
stats get_raw_stats() const override;
10941098
void reassign_custom_invlets() override;
@@ -1097,7 +1101,7 @@ class pickup_selector : public inventory_multiselector
10971101
bool wear();
10981102
void remove_from_to_use( item_location &it );
10991103
void reopen_menu();
1100-
const std::optional<tripoint_bub_ms> where;
1104+
const std::set<tripoint_bub_ms> where;
11011105
};
11021106

11031107
class unload_selector : public inventory_pick_selector

0 commit comments

Comments
 (0)