forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_inventory.cpp
2488 lines (2068 loc) · 93.2 KB
/
game_inventory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "game_inventory.h"
#include <algorithm>
#include <bitset>
#include <cstddef>
#include <functional>
#include <iterator>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "activity_type.h"
#include "activity_actor_definitions.h"
#include "avatar.h"
#include "bionics.h"
#include "bodypart.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "color.h"
#include "creature_tracker.h"
#include "cursesdef.h"
#include "damage.h"
#include "debug.h"
#include "display.h"
#include "enums.h"
#include "flag.h"
#include "game.h"
#include "input.h"
#include "inventory.h"
#include "inventory_ui.h"
#include "item.h"
#include "item_location.h"
#include "item_pocket.h"
#include "itype.h"
#include "iuse.h"
#include "iuse_actor.h"
#include "npctrade.h"
#include "optional.h"
#include "options.h"
#include "output.h"
#include "pimpl.h"
#include "point.h"
#include "recipe.h"
#include "recipe_dictionary.h"
#include "requirements.h"
#include "ret_val.h"
#include "skill.h"
#include "stomach.h"
#include "string_formatter.h"
#include "translations.h"
#include "type_id.h"
#include "ui_manager.h"
#include "units.h"
#include "units_utility.h"
#include "value_ptr.h"
#include "vehicle_selector.h"
#include "vpart_position.h"
static const activity_id ACT_CONSUME_DRINK_MENU( "ACT_CONSUME_DRINK_MENU" );
static const activity_id ACT_CONSUME_FOOD_MENU( "ACT_CONSUME_FOOD_MENU" );
static const activity_id ACT_CONSUME_FUEL_MENU( "ACT_CONSUME_FUEL_MENU" );
static const activity_id ACT_CONSUME_MEDS_MENU( "ACT_CONSUME_MEDS_MENU" );
static const activity_id ACT_EAT_MENU( "ACT_EAT_MENU" );
static const bionic_id bio_painkiller( "bio_painkiller" );
static const flag_id json_flag_CALORIES_INTAKE( "CALORIES_INTAKE" );
static const itype_id itype_fitness_band( "fitness_band" );
static const quality_id qual_ANESTHESIA( "ANESTHESIA" );
static const requirement_id requirement_data_anesthetic( "anesthetic" );
static const trait_id trait_DEBUG_BIONICS( "DEBUG_BIONICS" );
static const trait_id trait_NOPAIN( "NOPAIN" );
static const trait_id trait_SAPROPHAGE( "SAPROPHAGE" );
static const trait_id trait_SAPROVORE( "SAPROVORE" );
using item_filter = std::function<bool ( const item & )>;
using item_location_filter = std::function<bool ( const item_location & )>;
namespace
{
std::string good_bad_none( int value )
{
if( value > 0 ) {
return string_format( "<good>+%d</good>", value );
} else if( value < 0 ) {
return string_format( "<bad>%d</bad>", value );
}
return std::string();
}
std::string highlight_good_bad_none( int value )
{
if( value > 0 ) {
return string_format( "<color_yellow_green>+%d</color>", value );
} else if( value < 0 ) {
return string_format( "<color_yellow_red>%d</color>", value );
}
return string_format( "<color_yellow>%d</color>", value );
}
} // namespace
inventory_filter_preset::inventory_filter_preset( const item_location_filter &filter )
: filter( filter )
{}
bool inventory_filter_preset::is_shown( const item_location &location ) const
{
return filter( location );
}
static item_location_filter convert_filter( const item_filter &filter )
{
return [ &filter ]( const item_location & loc ) {
return filter( *loc );
};
}
static item_location inv_internal( Character &u, const inventory_selector_preset &preset,
const std::string &title, int radius,
const std::string &none_message,
const std::string &hint = std::string(),
item_location container = item_location() )
{
inventory_pick_selector inv_s( u, preset );
inv_s.set_title( title );
inv_s.set_hint( hint );
inv_s.set_display_stats( false );
const std::vector<activity_id> consuming {
ACT_EAT_MENU,
ACT_CONSUME_FOOD_MENU,
ACT_CONSUME_DRINK_MENU,
ACT_CONSUME_MEDS_MENU,
ACT_CONSUME_FUEL_MENU };
u.inv->restack( u );
inv_s.clear_items();
if( container ) {
// Only look inside the container.
inv_s.add_contained_items( container );
} else {
// Default behavior.
inv_s.add_character_items( u );
inv_s.add_nearby_items( radius );
}
if( u.has_activity( consuming ) ) {
if( !u.activity.str_values.empty() ) {
inv_s.set_filter( u.activity.str_values[0] );
}
// Set position after filter to keep cursor at the right position
bool position_set = false;
if( !u.activity.targets.empty() ) {
position_set = inv_s.highlight_one_of( u.activity.targets );
}
if( !position_set && u.activity.values.size() >= 2 ) {
inv_s.highlight_position( std::make_pair( u.activity.values[0], u.activity.values[1] ) );
}
}
if( inv_s.empty() ) {
const std::string msg = none_message.empty()
? _( "You don't have the necessary item at hand." )
: none_message;
popup( msg, PF_GET_KEY );
return item_location();
}
item_location location = inv_s.execute();
if( u.has_activity( consuming ) ) {
u.activity.values.clear();
const auto init_pair = inv_s.get_highlighted_position();
u.activity.values.push_back( init_pair.first );
u.activity.values.push_back( init_pair.second );
u.activity.str_values.clear();
u.activity.str_values.emplace_back( inv_s.get_filter() );
u.activity.targets = inv_s.get_highlighted().locations;
}
return location;
}
void game_menus::inv::common( avatar &you )
{
// Return to inventory menu on those inputs
static const std::set<int> loop_options = { { '\0', '=', 'f', '<', '>'}};
inventory_pick_selector inv_s( you );
inv_s.set_title( _( "Inventory" ) );
inv_s.set_hint( string_format(
_( "Item hotkeys assigned: <color_light_gray>%d</color>/<color_light_gray>%d</color>" ),
you.allocated_invlets().count(), inv_chars.size() ) );
int res = 0;
item_location location;
std::string filter;
do {
you.inv->restack( you );
inv_s.clear_items();
inv_s.add_character_items( you );
inv_s.set_filter( filter );
if( location != item_location::nowhere ) {
inv_s.highlight( location );
}
location = inv_s.execute();
filter = inv_s.get_filter();
if( location == item_location::nowhere ) {
break;
}
res = g->inventory_item_menu( location );
} while( loop_options.count( res ) != 0 );
}
void game_menus::inv::common( item_location &loc, avatar &you )
{
// Return to inventory menu on those inputs
static const std::set<int> loop_options = { { '\0', '=', 'f' } };
inventory_pick_selector inv_s( you );
inv_s.set_title( string_format( _( "Inventory of %s" ), loc->tname() ) );
inv_s.set_hint( string_format(
_( "Item hotkeys assigned: <color_light_gray>%d</color>/<color_light_gray>%d</color>" ),
you.allocated_invlets().count(), inv_chars.size() ) );
int res = 0;
item_location location;
std::string filter;
do {
inv_s.clear_items();
inv_s.add_contained_items( loc );
inv_s.set_filter( filter );
if( location != item_location::nowhere ) {
inv_s.highlight( location );
}
location = inv_s.execute();
filter = inv_s.get_filter();
if( location == item_location::nowhere ) {
break;
}
res = g->inventory_item_menu( location );
} while( loop_options.count( res ) != 0 );
}
item_location game_menus::inv::titled_filter_menu( const item_filter &filter, avatar &you,
const std::string &title, const std::string &none_message )
{
return inv_internal( you, inventory_filter_preset( convert_filter( filter ) ),
title, -1, none_message );
}
item_location game_menus::inv::titled_filter_menu( const item_location_filter &filter, avatar &you,
const std::string &title, const std::string &none_message )
{
return inv_internal( you, inventory_filter_preset( filter ),
title, -1, none_message );
}
item_location game_menus::inv::titled_menu( avatar &you, const std::string &title,
const std::string &none_message )
{
const std::string msg = none_message.empty() ? _( "Your inventory is empty." ) : none_message;
return inv_internal( you, inventory_selector_preset(), title, -1, msg );
}
class armor_inventory_preset: public inventory_selector_preset
{
public:
armor_inventory_preset( Character &pl, const std::string &color_in ) :
you( pl ), color( color_in ) {
append_cell( [ this ]( const item_location & loc ) {
return get_number_string( loc->get_avg_encumber( you ) );
}, _( "AVG ENCUMBRANCE" ) );
append_cell( [ this ]( const item_location & loc ) {
return string_format( "<%s>%d%%</color>", color, loc->get_avg_coverage() );
}, _( "AVG COVERAGE" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_number_string( loc->get_warmth() );
}, _( "WARMTH" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_decimal_string( loc->bash_resist() );
}, _( "BASH" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_decimal_string( loc->cut_resist() );
}, _( "CUT" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_decimal_string( loc->bullet_resist() );
}, _( "BULLET" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_decimal_string( loc->acid_resist() );
}, _( "ACID" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_decimal_string( loc->fire_resist() );
}, _( "FIRE" ) );
append_cell( [ this ]( const item_location & loc ) {
return get_number_string( loc->get_env_resist() );
}, _( "ENV" ) );
// Show total storage capacity in user's preferred volume units, to 2 decimal places
append_cell( [ this ]( const item_location & loc ) {
const int storage_ml = to_milliliter( loc->get_total_capacity() );
return get_decimal_string( round_up( convert_volume( storage_ml ), 2 ) );
}, string_format( _( "STORAGE (%s)" ), volume_units_abbr() ) );
}
protected:
Character &you;
private:
std::string get_number_string( int number ) const {
return number ? string_format( "<%s>%d</color>", color, number ) : std::string();
}
std::string get_decimal_string( double number ) const {
return number ? string_format( "<%s>%.2f</color>", color, number ) : std::string();
}
const std::string color;
};
class wear_inventory_preset: public armor_inventory_preset
{
public:
wear_inventory_preset( Character &you, const std::string &color, const bodypart_id &bp ) :
armor_inventory_preset( you, color ), bp( bp )
{}
bool is_shown( const item_location &loc ) const override {
return loc->is_armor() &&
( !loc.has_parent() || !is_worn_ablative( loc.parent_item(), loc ) ) &&
!you.is_worn( *loc ) &&
( bp != bodypart_id( "bp_null" ) ? loc->covers( bp ) : true );
}
std::string get_denial( const item_location &loc ) const override {
const auto ret = you.can_wear( *loc );
if( !ret.success() ) {
return trim_trailing_punctuations( ret.str() );
}
return std::string();
}
private:
const bodypart_id &bp;
};
item_location game_menus::inv::wear( Character &you, const bodypart_id &bp )
{
return inv_internal( you, wear_inventory_preset( you, "color_yellow", bp ), _( "Wear item" ), 1,
_( "You have nothing to wear." ) );
}
class take_off_inventory_preset: public armor_inventory_preset
{
public:
take_off_inventory_preset( Character &you, const std::string &color ) :
armor_inventory_preset( you, color )
{}
bool is_shown( const item_location &loc ) const override {
return loc->is_armor() && you.is_worn( *loc );
}
std::string get_denial( const item_location &loc ) const override {
const ret_val<bool> ret = you.can_takeoff( *loc );
if( !ret.success() ) {
return trim_trailing_punctuations( ret.str() );
}
return std::string();
}
};
item_location game_menus::inv::take_off( avatar &you )
{
return inv_internal( you, take_off_inventory_preset( you, "color_red" ), _( "Take off item" ), 1,
_( "You're not wearing anything." ) );
}
item_location game::inv_map_splice( const item_filter &filter, const std::string &title, int radius,
const std::string &none_message )
{
return inv_internal( u, inventory_filter_preset( convert_filter( filter ) ),
title, radius, none_message );
}
item_location game::inv_map_splice( const item_location_filter &filter, const std::string &title,
int radius, const std::string &none_message )
{
return inv_internal( u, inventory_filter_preset( filter ),
title, radius, none_message );
}
class liquid_inventory_selector_preset : public inventory_selector_preset
{
public:
explicit liquid_inventory_selector_preset( const item &liquid,
const item *const avoid ) : liquid( liquid ), avoid( avoid ) {
append_cell( []( const item_location & loc ) {
if( loc.get_item() ) {
return string_format( "%s %s", format_volume( loc.get_item()->max_containable_volume() ),
volume_units_abbr() );
}
return std::string( "" );
}, _( "Storage (L)" ) );
}
bool is_shown( const item_location &location ) const override {
if( location.get_item() == avoid ) {
return false;
}
if( location.where() == item_location::type::character ) {
Character *character = get_creature_tracker().creature_at<Character>( location.position() );
if( character == nullptr ) {
debugmsg( "Invalid location supplied to the liquid filter: no character found." );
return false;
}
return location->get_remaining_capacity_for_liquid( liquid, *character ) > 0;
}
const bool allow_buckets = location.where() == item_location::type::map;
return location->get_remaining_capacity_for_liquid( liquid, allow_buckets ) > 0;
}
private:
const item &liquid;
const item *const avoid;
};
item_location game_menus::inv::container_for( Character &you, const item &liquid, int radius,
const item *const avoid )
{
return inv_internal( you, liquid_inventory_selector_preset( liquid, avoid ),
string_format( _( "Container for %s | %s %s" ), liquid.display_name( liquid.charges ),
format_volume( liquid.volume() ), volume_units_abbr() ), radius,
string_format( _( "You don't have a suitable container for carrying %s." ),
liquid.tname() ) );
}
class pickup_inventory_preset : public inventory_selector_preset
{
public:
explicit pickup_inventory_preset( const Character &you,
bool skip_wield_check = false ) : you( you ),
skip_wield_check( skip_wield_check ) {
_pk_type = item_pocket::pocket_type::LAST;
}
std::string get_denial( const item_location &loc ) const override {
if( !you.has_item( *loc ) ) {
if( loc->made_of_from_type( phase_id::LIQUID ) ) {
if( loc.has_parent() ) {
return _( "Can't pick up liquids." );
} else {
return _( "Can't pick up spilt liquids." );
}
} else if( !you.can_pickVolume_partial( *loc, false, nullptr, false ) &&
( skip_wield_check || you.has_wield_conflicts( *loc ) ) ) {
return _( "Does not fit in any pocket!" );
} else if( !you.can_pickWeight_partial( *loc, !get_option<bool>( "DANGEROUS_PICKUPS" ) ) ) {
return _( "Too heavy to pick up!" );
}
}
return std::string();
}
bool is_shown( const item_location &loc ) const override {
return !( loc.has_parent() && loc.parent_item()->is_ammo_belt() );
}
private:
const Character &you;
bool skip_wield_check;
};
class disassemble_inventory_preset : public inventory_selector_preset
{
public:
disassemble_inventory_preset( const Character &you, const inventory &inv ) : you( you ),
inv( inv ) {
check_components = true;
append_cell( [ this ]( const item_location & loc ) {
const requirement_data &req = get_recipe( loc ).disassembly_requirements();
if( req.is_empty() ) {
return std::string();
}
const item *i = loc.get_item();
std::vector<item_comp> components = i->get_uncraft_components();
std::sort( components.begin(), components.end() );
auto it = components.begin();
while( ( it = std::adjacent_find( it, components.end() ) ) != components.end() ) {
++( it->count );
components.erase( std::next( it ) );
}
return enumerate_as_string( components.begin(), components.end(),
[]( const decltype( components )::value_type & comps ) {
return comps.to_string();
} );
}, _( "YIELD" ) );
append_cell( [ this ]( const item_location & loc ) {
return to_string_clipped( get_recipe( loc ).time_to_craft( get_player_character(),
recipe_time_flag::ignore_proficiencies ) );
}, _( "TIME" ) );
}
bool is_shown( const item_location &loc ) const override {
return !get_recipe( loc ).is_null();
}
std::string get_denial( const item_location &loc ) const override {
const auto ret = you.can_disassemble( *loc, inv );
if( !ret.success() ) {
return ret.str();
}
return std::string();
}
protected:
const recipe &get_recipe( const item_location &loc ) const {
return recipe_dictionary::get_uncraft( loc->typeId() );
}
private:
const Character &you;
const inventory &inv;
};
item_location game_menus::inv::disassemble( Character &you )
{
return inv_internal( you, disassemble_inventory_preset( you, you.crafting_inventory() ),
_( "Disassemble item" ), 1,
_( "You don't have any items you could disassemble." ) );
}
class comestible_inventory_preset : public inventory_selector_preset
{
public:
explicit comestible_inventory_preset( const Character &you ) : you( you ) {
_indent_entries = false;
append_cell( [&you]( const item_location & loc ) {
const nutrients nutr = you.compute_effective_nutrients( *loc );
return good_bad_none( nutr.kcal() );
}, _( "CALORIES" ) );
append_cell( []( const item_location & loc ) {
return good_bad_none( loc->is_comestible() ? loc->get_comestible()->quench : 0 );
}, _( "QUENCH" ) );
append_cell( [&you]( const item_location & loc ) {
int joy = you.fun_for( *loc ).first;
std::string joy_str;
if( loc->has_flag( flag_MUSHY ) ) {
joy_str = highlight_good_bad_none( joy );
} else {
joy_str = good_bad_none( joy );
}
int max_joy = you.fun_for( *loc, true ).first;
// max_joy should be 3 wide for alignment of '/'
if( max_joy == 0 ) {
// this will not be an empty string when food's joy can go below 0 by consumption (very rare)
return joy_str;
} else if( max_joy == joy ) {
return joy_str + std::string( joy > 0 ? "<good>/ =</good>" : "<bad>/ =</bad>" );
} else {
return string_format( max_joy > 0 ? "%s/<good>%+3d</good>" : "%s/<bad>%3d</bad>",
joy_str, max_joy );
}
}, _( "JOY/MAX" ) );
append_cell( []( const item_location & loc ) {
const int healthy = loc->is_comestible() ? loc->get_comestible()->healthy : 0;
return healthy_bar( healthy );
}, _( "HEALTH" ) );
append_cell( []( const item_location & loc ) {
const time_duration spoils = loc->is_comestible() ? loc->get_comestible()->spoils :
calendar::INDEFINITELY_LONG_DURATION;
if( spoils > 0_turns ) {
return to_string_clipped( spoils );
}
//~ Used for permafood shelf life in the Eat menu
return std::string( _( "indefinite" ) );
}, _( "SHELF LIFE" ) );
append_cell( []( const item_location & loc ) {
const item &it = *loc;
int converted_volume_scale = 0;
const int charges = std::max( it.charges, 1 );
const double converted_volume = round_up( convert_volume( it.volume().value() / charges,
&converted_volume_scale ), 2 );
//~ Eat menu Volume: <num><unit>
return string_format( _( "%.2f%s" ), converted_volume, volume_units_abbr() );
}, _( "VOLUME" ) );
append_cell( [&you]( const item_location & loc ) {
const item &it = *loc;
// Quit prematurely if the item is not food.
if( !it.type->comestible ) {
return std::string();
}
const int calories_per_effective_volume = you.compute_calories_per_effective_volume( it );
// Show empty cell instead of 0.
if( calories_per_effective_volume == 0 ) {
return std::string();
}
/* This is for screen readers. I will make a PR to discuss what these prerequisites could be -
bio_digestion, selfaware, high cooking skill etc*/
constexpr bool ARBITRARY_PREREQUISITES_TO_BE_DETERMINED_IN_THE_FUTURE = false;
if( ARBITRARY_PREREQUISITES_TO_BE_DETERMINED_IN_THE_FUTURE ) {
return string_format( "%d", calories_per_effective_volume );
}
return satiety_bar( calories_per_effective_volume );
}, _( "SATIETY" ) );
Character &player_character = get_player_character();
append_cell( [&player_character]( const item_location & loc ) {
time_duration time = player_character.get_consume_time( *loc );
return string_format( "%s", to_string( time, true ) );
}, _( "CONSUME TIME" ) );
append_cell( [this, &player_character]( const item_location & loc ) {
std::string sealed;
if( loc.has_parent() ) {
item_pocket *pocket = loc.parent_item()->contained_where( * loc.get_item() );
sealed = pocket->sealed() ? _( "sealed" ) : std::string();
}
if( player_character.can_estimate_rot() ) {
if( loc->is_comestible() && loc->get_comestible()->spoils > 0_turns ) {
return sealed + ( sealed.empty() ? "" : " " ) + get_freshness( loc );
}
return std::string( "---" );
}
return sealed;
}, _( "FRESHNESS" ) );
append_cell( [ this, &player_character ]( const item_location & loc ) {
if( player_character.can_estimate_rot() ) {
if( loc->is_comestible() && loc->get_comestible()->spoils > 0_turns ) {
if( !loc->rotten() ) {
return get_time_left_rounded( loc );
}
}
return std::string( "---" );
}
return std::string();
}, _( "SPOILS IN" ) );
}
bool is_shown( const item_location &loc ) const override {
return loc->is_comestible() && you.can_consume_as_is( *loc );
}
std::string get_denial( const item_location &loc ) const override {
const item &med = *loc;
if(
( loc->made_of_from_type( phase_id::LIQUID ) &&
loc.where() != item_location::type::container ) &&
!get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, loc.position() ) ) {
return _( "Can't drink spilt liquids." );
}
if( med.is_medication() && !you.can_use_heal_item( med ) && !med.is_craft() ) {
return _( "Your biology is not compatible with that item." );
}
const item &it = *loc;
const ret_val<edible_rating> res = you.can_eat( it );
if( !res.success() ) {
return res.str();
}
return inventory_selector_preset::get_denial( loc );
}
bool sort_compare( const inventory_entry &lhs, const inventory_entry &rhs ) const override {
time_duration time_a = get_time_left( lhs.any_item() );
time_duration time_b = get_time_left( rhs.any_item() );
int order_a = get_order( lhs.any_item(), time_a );
int order_b = get_order( rhs.any_item(), time_b );
return order_a < order_b
|| ( order_a == order_b && time_a < time_b )
|| ( order_a == order_b && time_a == time_b &&
inventory_selector_preset::sort_compare( lhs, rhs ) );
}
protected:
int get_order( const item_location &loc, const time_duration &time ) const {
if( loc->rotten() ) {
if( you.has_trait( trait_SAPROPHAGE ) || you.has_trait( trait_SAPROVORE ) ) {
return 1;
} else {
return 5;
}
} else if( time == 0_turns ) {
return 4;
} else if( loc.has_parent() &&
loc.parent_item()->contained_where( *loc )->spoil_multiplier() == 0.0f ) {
return 3;
} else {
return 2;
}
}
const islot_comestible &get_edible_comestible( const item &it ) const {
if( it.is_comestible() && you.can_eat( it ).success() ) {
// Ok since can_eat() returns false if is_craft() is true
return *it.type->comestible;
}
static const islot_comestible dummy {};
return dummy;
}
time_duration get_time_left( const item_location &loc ) const {
time_duration time_left = 0_turns;
const time_duration shelf_life = loc->is_comestible() ? loc->get_comestible()->spoils :
calendar::INDEFINITELY_LONG_DURATION;
if( shelf_life > 0_turns ) {
const item &it = *loc;
const double relative_rot = it.get_relative_rot();
time_left = shelf_life - shelf_life * relative_rot;
// Correct for an estimate that exceeds shelf life -- this happens especially with
// fresh items.
if( time_left > shelf_life ) {
time_left = shelf_life;
}
}
return time_left;
}
std::string get_time_left_rounded( const item_location &loc ) const {
const item &it = *loc;
if( it.is_going_bad() ) {
return _( "soon!" );
}
time_duration time_left = get_time_left( loc );
return to_string_approx( time_left );
}
std::string get_freshness( const item_location &loc ) {
const item &it = *loc;
const double rot_progress = it.get_relative_rot();
if( it.is_fresh() ) {
return _( "fresh" );
} else if( rot_progress < 0.3 ) {
return _( "quite fresh" );
} else if( rot_progress < 0.5 ) {
return _( "near midlife" );
} else if( rot_progress < 0.7 ) {
return _( "past midlife" );
} else if( rot_progress < 0.9 ) {
return _( "getting older" );
} else if( !it.rotten() ) {
return _( "old" );
} else {
return _( "rotten" );
}
}
private:
const Character &you;
};
class fuel_inventory_preset : public inventory_selector_preset
{
public:
explicit fuel_inventory_preset( const Character &you ) : you( you ) {
_indent_entries = false;
append_cell( []( const item_location & loc ) {
const time_duration spoils = loc->is_comestible() ? loc->get_comestible()->spoils :
calendar::INDEFINITELY_LONG_DURATION;
if( spoils > 0_turns ) {
return to_string_clipped( spoils );
}
//~ Used for permafood shelf life in the Eat menu
return std::string( _( "indefinite" ) );
}, _( "SHELF LIFE" ) );
append_cell( []( const item_location & loc ) {
const item &it = *loc;
int converted_volume_scale = 0;
const int charges = std::max( it.charges, 1 );
const double converted_volume = round_up( convert_volume( it.volume().value() / charges,
&converted_volume_scale ), 2 );
//~ Eat menu Volume: <num><unit>
return string_format( _( "%.2f%s" ), converted_volume, volume_units_abbr() );
}, _( "VOLUME" ) );
Character &player_character = get_player_character();
append_cell( [&player_character]( const item_location & loc ) {
time_duration time = player_character.get_consume_time( *loc );
return string_format( "%s", to_string( time, true ) );
}, _( "CONSUME TIME" ) );
append_cell( [this, &player_character]( const item_location & loc ) {
std::string sealed;
if( loc.has_parent() ) {
item_pocket *pocket = loc.parent_item()->contained_where( *loc.get_item() );
sealed = pocket->sealed() ? _( "sealed" ) : std::string();
}
if( player_character.can_estimate_rot() ) {
if( loc->is_comestible() && loc->get_comestible()->spoils > 0_turns ) {
return sealed + ( sealed.empty() ? "" : " " ) + get_freshness( loc );
}
return std::string( "---" );
}
return sealed;
}, _( "FRESHNESS" ) );
append_cell( [this, &player_character]( const item_location & loc ) {
if( player_character.can_estimate_rot() ) {
if( loc->is_comestible() && loc->get_comestible()->spoils > 0_turns ) {
if( !loc->rotten() ) {
return get_time_left_rounded( loc );
}
}
return std::string( "---" );
}
return std::string();
}, _( "SPOILS IN" ) );
append_cell( [&you]( const item_location & loc ) {
std::string cbm_name;
std::vector<bionic_id> bids = you.get_bionic_fueled_with( *loc );
if( !bids.empty() ) {
bionic_id bid = you.get_most_efficient_bionic( bids );
cbm_name = bid->name.translated();
}
if( !cbm_name.empty() ) {
return string_format( "<color_cyan>%s</color>", cbm_name );
}
return std::string();
}, _( "CBM" ) );
append_cell( [&you]( const item_location & loc ) {
return good_bad_none( you.get_acquirable_energy( *loc ) );
}, _( "ENERGY (kJ)" ) );
}
bool is_shown( const item_location &loc ) const override {
return you.can_fuel_bionic_with( *loc );
}
std::string get_denial( const item_location &loc ) const override {
if( loc->made_of_from_type( phase_id::LIQUID ) && loc.where() != item_location::type::container ) {
return _( "Can't use spilt liquids." );
}
std::string item_name = loc->tname();
material_id mat_type = loc->get_base_material().id;
if( loc->type->magazine ) {
const item ammo = item( loc->ammo_current() );
item_name = ammo.tname();
mat_type = ammo.get_base_material().id;
}
if( you.get_fuel_capacity( mat_type ) <= 0 ) {
return _( "No space to store more" );
}
return inventory_selector_preset::get_denial( loc );
}
bool sort_compare( const inventory_entry &lhs, const inventory_entry &rhs ) const override {
time_duration time_a = get_time_left( lhs.any_item() );
time_duration time_b = get_time_left( rhs.any_item() );
int order_a = get_order( lhs.any_item(), time_a );
int order_b = get_order( rhs.any_item(), time_b );
return order_a < order_b
|| ( order_a == order_b && time_a < time_b )
|| ( order_a == order_b && time_a == time_b &&
inventory_selector_preset::sort_compare( lhs, rhs ) );
}
protected:
int get_order( const item_location &loc, const time_duration &time ) const {
if( loc->rotten() || time == 0_turns ) {
return 2;
} else {
return 1;
}
}
time_duration get_time_left( const item_location &loc ) const {
time_duration time_left = 0_turns;
const time_duration shelf_life = loc->is_comestible() ? loc->get_comestible()->spoils :
calendar::INDEFINITELY_LONG_DURATION;
if( shelf_life > 0_turns ) {
const item &it = *loc;
const double relative_rot = it.get_relative_rot();
time_left = shelf_life - shelf_life * relative_rot;
// Correct for an estimate that exceeds shelf life -- this happens especially with
// fresh items.
if( time_left > shelf_life ) {
time_left = shelf_life;
}
}
return time_left;
}
std::string get_time_left_rounded( const item_location &loc ) const {
const item &it = *loc;
if( it.is_going_bad() ) {
return _( "soon!" );
}
time_duration time_left = get_time_left( loc );
return to_string_approx( time_left );
}
std::string get_freshness( const item_location &loc ) {
const item &it = *loc;
const double rot_progress = it.get_relative_rot();
if( it.is_fresh() ) {
return _( "fresh" );
} else if( rot_progress < 0.3 ) {
return _( "quite fresh" );
} else if( rot_progress < 0.5 ) {
return _( "near midlife" );
} else if( rot_progress < 0.7 ) {
return _( "past midlife" );
} else if( rot_progress < 0.9 ) {
return _( "getting older" );
} else if( !it.rotten() ) {
return _( "old" );
} else {
return _( "rotten" );
}
}
private:
const Character &you;
};
static std::string get_consume_needs_hint( Character &you )
{
auto hint = std::string();
auto desc = display::hunger_text_color( you );
hint.append( string_format( "%s %s", _( "Food:" ), colorize( desc.first, desc.second ) ) );
hint.append( string_format( " %s ", LINE_XOXO_S ) );
desc = display::thirst_text_color( you );
hint.append( string_format( "%s %s", pgettext( "inventory", "Drink:" ),