-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathveh_interact.cpp
3317 lines (2946 loc) · 122 KB
/
veh_interact.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 "veh_interact.h"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <memory>
#include <numeric>
#include <optional>
#include <set>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <utility>
#include "activity_handlers.h"
#include "avatar.h"
#include "avatar_functions.h"
#include "calendar.h"
#include "cata_utility.h"
#include "catacharset.h"
#include "character.h"
#include "character_functions.h"
#include "character_id.h"
#include "clzones.h"
#include "debug.h"
#include "enums.h"
#include "faction.h"
#include "fault.h"
#include "game.h"
#include "game_constants.h"
#include "handle_liquid.h"
#include "item.h"
#include "item_contents.h"
#include "itype.h"
#include "locations.h"
#include "map.h"
#include "map_selector.h"
#include "math_defines.h"
#include "messages.h"
#include "monster.h"
#include "npc.h"
#include "options.h"
#include "output.h"
#include "overmapbuffer.h"
#include "pimpl.h"
#include "player.h"
#include "player_activity.h"
#include "point.h"
#include "ranged.h"
#include "requirements.h"
#include "skill.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_input_popup.h"
#include "string_utils.h"
#include "tileray.h"
#include "translations.h"
#include "ui.h"
#include "ui_manager.h"
#include "units.h"
#include "units_utility.h"
#include "value_ptr.h"
#include "veh_type.h"
#include "veh_utils.h"
#include "vehicle.h"
#include "vehicle_part.h"
#include "vehicle_selector.h"
#include "vpart_position.h"
#include "vpart_range.h"
static const itype_id fuel_type_battery( "battery" );
static const itype_id itype_battery( "battery" );
static const itype_id itype_plut_cell( "plut_cell" );
static const skill_id skill_mechanics( "mechanics" );
static const quality_id qual_HOSE( "HOSE" );
static const quality_id qual_JACK( "JACK" );
static const quality_id qual_LIFT( "LIFT" );
static const quality_id qual_SELF_JACK( "SELF_JACK" );
static const trait_id trait_DEBUG_HS( "DEBUG_HS" );
static const activity_id ACT_VEHICLE( "ACT_VEHICLE" );
static const std::string flag_MOUNTABLE( "MOUNTABLE" );
static inline std::string status_color( bool status )
{
return status ? "<color_green>" : "<color_red>";
}
static inline std::string health_color( bool status )
{
return status ? "<color_light_green>" : "<color_light_red>";
}
// cap JACK requirements to support arbitrarily large vehicles
static double jack_quality( const vehicle &veh )
{
const units::quantity<double, units::mass::unit_type> mass = std::min( veh.total_mass(),
JACK_LIMIT );
return std::ceil( mass / TOOL_LIFT_FACTOR );
}
/** Can part currently be reloaded with anything? */
static auto can_refill = []( const vehicle_part &pt )
{
return pt.can_reload();
};
void act_vehicle_siphon( vehicle *veh );
void act_vehicle_unload_fuel( vehicle *veh );
std::unique_ptr<player_activity> veh_interact::serialize_activity()
{
const auto &here = get_map();
const auto &you = get_avatar();
const auto *pt = sel_vehicle_part;
const auto *vp = sel_vpart_info;
if( sel_cmd == 'q' || sel_cmd == ' ' || !vp ) {
return std::make_unique<player_activity>();
}
int time = 1000;
switch( sel_cmd ) {
case 'i':
time = vp->install_time( you );
break;
case 'r':
if( pt != nullptr ) {
if( pt->is_broken() ) {
time = vp->install_time( you );
} else if( pt->base->max_damage() > 0 ) {
time = vp->repair_time( you ) * pt->base->damage() / pt->base->max_damage();
}
}
break;
case 'o':
time = vp->removal_time( you );
break;
default:
break;
}
if( you.has_trait( trait_DEBUG_HS ) ) {
time = 1;
}
std::unique_ptr<player_activity> res = std::make_unique<player_activity>( ACT_VEHICLE, time,
static_cast<int>( sel_cmd ) );
// if we're working on an existing part, use that part as the reference point
// otherwise (e.g. installing a new frame), just use part 0
const tripoint q = here.getabs( veh->global_part_pos3( pt ? *pt : veh->part( 0 ) ) );
const vehicle_part *vpt = pt ? pt : &veh->part( 0 );
for( const tripoint &p : veh->get_points( true ) ) {
res->coord_set.insert( here.getabs( p ) );
}
res->values.push_back( q.x ); // values[0]
res->values.push_back( q.y ); // values[1]
res->values.push_back( dd.x ); // values[2]
res->values.push_back( dd.y ); // values[3]
res->values.push_back( -dd.x ); // values[4]
res->values.push_back( -dd.y ); // values[5]
res->values.push_back( veh->index_of_part( vpt ) ); // values[6]
res->values.push_back( q.z ); // values[7]
res->str_values.push_back( vp->get_id().str() );
res->targets.emplace_back( target );
return res;
}
std::unique_ptr<player_activity> veh_interact::run( vehicle &veh, point p )
{
veh_interact vehint( veh, p );
vehint.do_main_loop();
return vehint.serialize_activity();
}
vehicle_part &veh_interact::select_part( const vehicle &veh, const part_selector &sel,
const std::string &title )
{
static vehicle_part null_part;
vehicle_part *res = &null_part;
auto act = [&]( const vehicle_part & pt ) {
res = const_cast<vehicle_part *>( &pt );
};
std::function<bool( const vpart_reference & )> sel_wrapper = [sel]( const vpart_reference & vpr ) {
return sel( vpr.part() );
};
const vehicle_part_range vpr = veh.get_all_parts();
int opts = std::count_if( vpr.begin(), vpr.end(), sel_wrapper );
if( opts == 1 ) {
act( std::find_if( vpr.begin(), vpr.end(), sel_wrapper )->part() );
} else if( opts != 0 ) {
veh_interact vehint( const_cast<vehicle &>( veh ) );
vehint.title = title.empty() ? _( "Select part" ) : title;
vehint.overview( sel, act );
}
return *res;
}
/**
* Creates a blank veh_interact window.
*/
veh_interact::veh_interact( vehicle &veh, point p )
: dd( p ), veh( &veh ), main_context( "VEH_INTERACT" )
{
// Only build the shapes map and the wheel list once
for( const auto &e : vpart_info::all() ) {
const vpart_info &vp = e.second;
vpart_shapes[ vp.name() + vp.item.str() ].push_back( &vp );
if( vp.has_flag( "WHEEL" ) ) {
wheel_types.push_back( &vp );
}
}
main_context.register_directions();
main_context.register_action( "QUIT" );
main_context.register_action( "INSTALL" );
main_context.register_action( "REPAIR" );
main_context.register_action( "MEND" );
main_context.register_action( "REFILL" );
main_context.register_action( "REMOVE" );
main_context.register_action( "RENAME" );
main_context.register_action( "SIPHON" );
main_context.register_action( "UNLOAD" );
main_context.register_action( "ASSIGN_CREW" );
main_context.register_action( "CHANGE_SHAPE" );
main_context.register_action( "RELABEL" );
main_context.register_action( "PREV_TAB" );
main_context.register_action( "NEXT_TAB" );
main_context.register_action( "OVERVIEW_DOWN" );
main_context.register_action( "OVERVIEW_UP" );
main_context.register_action( "FUEL_LIST_DOWN" );
main_context.register_action( "FUEL_LIST_UP" );
main_context.register_action( "DESC_LIST_DOWN" );
main_context.register_action( "DESC_LIST_UP" );
main_context.register_action( "CONFIRM" );
main_context.register_action( "HELP_KEYBINDINGS" );
main_context.register_action( "FILTER" );
main_context.register_action( "ANY_INPUT" );
count_durability();
cache_tool_availability();
// Initialize info of selected parts
move_cursor( point_zero );
}
veh_interact::~veh_interact() = default;
void veh_interact::allocate_windows()
{
// grid window
const point grid( point_south_east );
const int grid_w = TERMX - 2; // exterior borders take 2
const int grid_h = TERMY - 2; // exterior borders take 2
const int mode_h = 1;
const int name_h = 1;
page_size = grid_h - ( mode_h + stats_h + name_h ) - 2;
const int pane_y = grid.y + mode_h + 1;
const int pane_w = ( grid_w / 3 ) - 1;
const int disp_w = grid_w - ( pane_w * 2 ) - 2;
const int disp_h = page_size * 0.45;
const int parts_h = page_size - disp_h;
const int parts_y = pane_y + disp_h;
const int name_y = pane_y + page_size + 1;
const int stats_y = name_y + name_h;
const int list_x = grid.x + disp_w + 1;
const int msg_x = list_x + pane_w + 1;
// covers right part of w_name and w_stats in vertical/hybrid
const int details_y = name_y;
const int details_x = list_x;
const int details_h = 7;
const int details_w = grid.x + grid_w - details_x;
// make the windows
w_border = catacurses::newwin( TERMY, TERMX, point_zero );
w_mode = catacurses::newwin( mode_h, grid_w, grid );
w_msg = catacurses::newwin( page_size, pane_w, point( msg_x, pane_y ) );
w_disp = catacurses::newwin( disp_h, disp_w, point( grid.x, pane_y ) );
w_parts = catacurses::newwin( parts_h, disp_w, point( grid.x, parts_y ) );
w_list = catacurses::newwin( page_size, pane_w, point( list_x, pane_y ) );
w_stats = catacurses::newwin( stats_h, grid_w, point( grid.x, stats_y ) );
w_name = catacurses::newwin( name_h, grid_w, point( grid.x, name_y ) );
w_details = catacurses::newwin( details_h, details_w, point( details_x, details_y ) );
}
bool veh_interact::format_reqs( std::string &msg, const requirement_data &reqs,
const std::map<skill_id, int> &skills, int moves ) const
{
auto &you = get_avatar();
const inventory &inv = you.crafting_inventory();
bool ok = reqs.can_make_with_inventory( inv, is_crafting_component );
msg += _( "<color_white>Time required:</color>\n" );
// TODO: better have a from_moves function
msg += "> " + to_string_approx( time_duration::from_turns( moves / 100 ) ) + "\n";
msg += _( "<color_white>Skills required:</color>\n" );
for( const auto &e : skills ) {
bool hasSkill = you.get_skill_level( e.first ) >= e.second;
if( !hasSkill ) {
ok = false;
}
//~ %1$s represents the internal color name which shouldn't be translated, %2$s is skill name, and %3$i is skill level
msg += string_format( _( "> %1$s%2$s %3$i</color>\n" ), status_color( hasSkill ),
e.first.obj().name(), e.second );
}
if( skills.empty() ) {
//~ %1$s represents the internal color name which shouldn't be translated, %2$s is the word "NONE"
msg += string_format( "> %1$s%2$s</color>", status_color( true ), _( "NONE" ) ) + "\n";
}
auto comps = reqs.get_folded_components_list( getmaxx( w_msg ) - 2, c_white, inv,
is_crafting_component );
for( const std::string &line : comps ) {
msg += line + "\n";
}
auto tools = reqs.get_folded_tools_list( getmaxx( w_msg ) - 2, c_white, inv );
for( const std::string &line : tools ) {
msg += line + "\n";
}
return ok;
}
struct veh_interact::install_info_t {
int pos;
size_t tab;
std::vector<const vpart_info *> tab_vparts;
std::array<std::string, 8> tab_list;
std::array<std::string, 8> tab_list_short;
};
shared_ptr_fast<ui_adaptor> veh_interact::create_or_get_ui_adaptor()
{
shared_ptr_fast<ui_adaptor> current_ui = ui.lock();
if( !current_ui ) {
ui = current_ui = make_shared_fast<ui_adaptor>();
current_ui->on_screen_resize( [this]( ui_adaptor & current_ui ) {
if( ui_hidden ) {
current_ui.position( point_zero, point_zero );
return;
}
allocate_windows();
current_ui.position_from_window( catacurses::stdscr );
} );
current_ui->mark_resize();
current_ui->on_redraw( [this]( const ui_adaptor & ) {
if( ui_hidden ) {
return;
}
display_grid();
display_name();
display_stats();
display_veh();
werase( w_parts );
veh->print_part_list( w_parts, 0, getmaxy( w_parts ) - 1, getmaxx( w_parts ), cpart, highlight_part,
true );
wnoutrefresh( w_parts );
werase( w_msg );
if( !msg.has_value() ) {
veh->print_vparts_descs( w_msg, getmaxy( w_msg ), getmaxx( w_msg ), cpart, start_at, start_limit );
} else {
// NOLINTNEXTLINE(cata-use-named-point-constants)
fold_and_print( w_msg, point( 1, 0 ), getmaxx( w_msg ) - 2, c_light_red, msg.value() );
}
wnoutrefresh( w_msg );
if( install_info ) {
display_list( install_info->pos, install_info->tab_vparts, 2 );
display_details( sel_vpart_info );
} else {
display_overview();
}
display_mode();
} );
}
return current_ui;
}
void veh_interact::hide_ui( const bool hide )
{
if( hide != ui_hidden ) {
ui_hidden = hide;
create_or_get_ui_adaptor()->mark_resize();
}
}
void veh_interact::do_main_loop()
{
avatar &you = get_avatar();
bool finish = false;
const bool owned_by_player = veh->handle_potential_theft( you, true );
faction *owner_fac;
if( veh->has_owner() ) {
owner_fac = g->faction_manager_ptr->get( veh->get_owner() );
} else {
owner_fac = g->faction_manager_ptr->get( faction_id( "no_faction" ) );
}
shared_ptr_fast<ui_adaptor> current_ui = create_or_get_ui_adaptor();
while( !finish ) {
calc_overview();
ui_manager::redraw();
const std::string action = main_context.handle_input();
msg.reset();
if( const std::optional<tripoint> vec = main_context.get_direction( action ) ) {
move_cursor( vec->xy() );
} else if( action == "QUIT" ) {
finish = true;
} else if( action == "INSTALL" ) {
if( veh->handle_potential_theft( you ) ) {
do_install();
}
} else if( action == "REPAIR" ) {
if( veh->handle_potential_theft( you ) ) {
do_repair();
}
} else if( action == "MEND" ) {
if( veh->handle_potential_theft( you ) ) {
do_mend();
}
} else if( action == "REFILL" ) {
if( veh->handle_potential_theft( you ) ) {
do_refill();
}
} else if( action == "REMOVE" ) {
if( veh->handle_potential_theft( you ) ) {
do_remove();
}
} else if( action == "RENAME" ) {
if( owned_by_player ) {
do_rename();
} else {
if( owner_fac ) {
popup( _( "You cannot rename this vehicle as it is owned by: %s." ), _( owner_fac->name ) );
}
}
} else if( action == "SIPHON" ) {
if( veh->handle_potential_theft( you ) ) {
do_siphon();
// Siphoning may have started a player activity. If so, we should close the
// vehicle dialog and continue with the activity.
finish = !you.activity->is_null();
if( !finish ) {
// it's possible we just invalidated our crafting inventory
cache_tool_availability();
}
}
} else if( action == "UNLOAD" ) {
if( veh->handle_potential_theft( you ) ) {
finish = do_unload();
}
} else if( action == "CHANGE_SHAPE" ) {
// purely cosmetic
do_change_shape();
} else if( action == "ASSIGN_CREW" ) {
if( owned_by_player ) {
do_assign_crew();
} else {
if( owner_fac ) {
popup( _( "You cannot assign crew on this vehicle as it is owned by: %s." ),
_( owner_fac->name ) );
}
}
} else if( action == "RELABEL" ) {
if( owned_by_player ) {
do_relabel();
} else {
if( owner_fac ) {
popup( _( "You cannot relabel this vehicle as it is owned by: %s." ), _( owner_fac->name ) );
}
}
} else if( action == "FUEL_LIST_DOWN" ) {
move_fuel_cursor( 1 );
} else if( action == "FUEL_LIST_UP" ) {
move_fuel_cursor( -1 );
} else if( action == "OVERVIEW_DOWN" ) {
move_overview_line( 1 );
} else if( action == "OVERVIEW_UP" ) {
move_overview_line( -1 );
} else if( action == "DESC_LIST_DOWN" ) {
move_cursor( point_zero, 1 );
} else if( action == "DESC_LIST_UP" ) {
move_cursor( point_zero, -1 );
}
if( sel_cmd != ' ' ) {
finish = true;
}
}
}
void veh_interact::cache_tool_availability()
{
auto &you = get_avatar();
crafting_inv = you.crafting_inventory();
cache_tool_availability_update_lifting( you.pos() );
int mech_jack = 0;
if( you.is_mounted() ) {
mech_jack = you.mounted_creature->mech_str_addition() + 10;
}
max_jack = std::max( { you.max_quality( qual_JACK ), mech_jack,
map_selector( you.pos(), PICKUP_RANGE, false ).max_quality( qual_JACK ),
vehicle_selector( you.pos(), PICKUP_RANGE, false, *veh ).max_quality( qual_JACK )
} );
}
void veh_interact::cache_tool_availability_update_lifting( const tripoint &world_cursor_pos )
{
max_lift = get_avatar().best_nearby_lifting_assist( world_cursor_pos );
}
/**
* Checks if the player is able to perform some command, and returns a nonzero
* error code if they are unable to perform it. The return from this function
* should be passed into the various do_whatever functions further down.
* @param mode The command the player is trying to perform (i.e. 'r' for repair).
* @return CAN_DO if the player has everything they need,
* INVALID_TARGET if the command can't target that square,
* LACK_TOOLS if the player lacks tools,
* NOT_FREE if something else obstructs the action,
* LACK_SKILL if the player's skill isn't high enough,
* LOW_MORALE if the player's morale is too low while trying to perform
* an action requiring a minimum morale,
* UNKNOWN_TASK if the requested operation is unrecognized.
*/
task_reason veh_interact::cant_do( char mode )
{
const avatar &you = get_avatar();
bool enough_morale = true;
bool valid_target = false;
bool has_tools = false;
bool part_free = true;
bool has_skill = true;
bool enough_light = true;
const vehicle_part_range vpr = veh->get_all_parts();
switch( mode ) {
case 'i':
// install mode
enough_morale = you.has_morale_to_craft();
valid_target = !can_mount.empty() && 0 == veh->tags.count( "convertible" );
//tool checks processed later
enough_light = character_funcs::can_see_fine_details( you );
has_tools = true;
break;
case 'r':
// repair mode
enough_morale = you.has_morale_to_craft();
valid_target = !need_repair.empty() && cpart >= 0;
// checked later
has_tools = true;
enough_light = character_funcs::can_see_fine_details( you );
break;
case 'm': {
// mend mode
enough_morale = you.has_morale_to_craft();
const bool toggling = you.has_trait( trait_DEBUG_HS );
valid_target = std::any_of( vpr.begin(), vpr.end(), [toggling]( const vpart_reference & pt ) {
if( toggling ) {
return pt.part().is_available() && !pt.part().faults_potential().empty();
} else {
return pt.part().is_available() && !pt.part().faults().empty();
}
} );
enough_light = character_funcs::can_see_fine_details( you );
// checked later
has_tools = true;
}
break;
case 'f':
valid_target = std::any_of( vpr.begin(), vpr.end(), []( const vpart_reference & pt ) {
return can_refill( pt.part() );
} );
has_tools = true;
break;
case 'o':
// remove mode
enough_morale = you.has_morale_to_craft();
valid_target = cpart >= 0 && 0 == veh->tags.count( "convertible" );
part_free = parts_here.size() > 1 || ( cpart >= 0 && veh->can_unmount( cpart ) );
//tool and skill checks processed later
has_tools = true;
has_skill = true;
enough_light = character_funcs::can_see_fine_details( you );
break;
case 's':
// siphon mode
valid_target = false;
for( const vpart_reference &vp : veh->get_any_parts( VPFLAG_FLUIDTANK ) ) {
if( vp.part().base->contents_made_of( LIQUID ) ) {
valid_target = true;
break;
}
}
has_tools = you.has_quality( qual_HOSE );
break;
case 'd':
// unload mode
valid_target = false;
has_tools = true;
for( auto &e : veh->fuels_left() ) {
if( e.first != fuel_type_battery && e.first->phase == SOLID ) {
valid_target = true;
break;
}
}
break;
case 'w':
// assign crew
if( g->allies().empty() ) {
return INVALID_TARGET;
}
return std::any_of( vpr.begin(), vpr.end(), []( const vpart_reference & e ) {
return e.part().is_seat();
} ) ? CAN_DO : INVALID_TARGET;
case 'p': {
// Change part shape
has_tools = true;
if( cpart >= 0 ) {
const int displayed_part = veh->part_displayed_at( veh->part( cpart ).mount );
const vpart_info &displayed_vpart = veh->part( displayed_part ).info();
// Does the displayed part have different shapes?
valid_target = vpart_shapes[displayed_vpart.name() + displayed_vpart.item.str()].size() > 1;
}
break;
}
case 'a':
// relabel
valid_target = cpart >= 0;
has_tools = true;
break;
default:
return UNKNOWN_TASK;
}
if( std::abs( veh->velocity ) > 100 || you.controlling_vehicle ) {
return MOVING_VEHICLE;
}
if( !valid_target ) {
return INVALID_TARGET;
}
if( !enough_morale ) {
return LOW_MORALE;
}
if( !enough_light ) {
return LOW_LIGHT;
}
if( !has_tools ) {
return LACK_TOOLS;
}
if( !part_free ) {
return NOT_FREE;
}
// TODO: that is always false!
if( !has_skill ) {
return LACK_SKILL;
}
return CAN_DO;
}
bool veh_interact::is_drive_conflict()
{
std::string conflict_type;
bool has_conflict = veh->has_engine_conflict( sel_vpart_info, conflict_type );
if( has_conflict ) {
//~ %1$s is fuel_type
msg = string_format( _( "Only one %1$s powered engine can be installed." ),
conflict_type );
}
return has_conflict;
}
bool veh_interact::can_self_jack()
{
int lvl = jack_quality( *veh );
for( const vpart_reference &vp : veh->get_avail_parts( "SELF_JACK" ) ) {
if( vp.part().base->has_quality( qual_SELF_JACK, lvl ) ) {
return true;
}
}
return false;
}
bool veh_interact::update_part_requirements()
{
if( sel_vpart_info == nullptr ) {
return false;
}
if( is_drive_conflict() ) {
return false;
}
if( sel_vpart_info->has_flag( "FUNNEL" ) ) {
if( std::none_of( parts_here.begin(), parts_here.end(), [&]( const int e ) {
return veh->part( e ).is_tank();
} ) ) {
msg = _( "Funnels need to be installed over a tank." );
return false;
}
}
if( sel_vpart_info->has_flag( "TURRET" ) ) {
if( std::any_of( parts_here.begin(), parts_here.end(), [&]( const int e ) {
return veh->part( e ).is_turret();
} ) ) {
msg = _( "Can't install turret on another turret." );
return false;
}
}
const auto get_rq_mechanics = []( const vpart_info & vpi ) {
for( const std::pair<const skill_id, int> &it : vpi.install_skills ) {
if( it.first == skill_mechanics ) {
return it.second;
}
}
return 0;
};
// Difficulty of installing additional engines depends on most complex
// installed engine and # of installed engines,
// but can never be less than 6 or more than 10.
// Engines without E_HIGHER_SKILL flag are excluded from the check.
bool is_engine = sel_vpart_info->has_flag( "ENGINE" );
int dif_eng = 0;
if( is_engine && sel_vpart_info->has_flag( "E_HIGHER_SKILL" ) ) {
int engines = 0;
int dif_max = get_rq_mechanics( *sel_vpart_info );
for( const vpart_reference &vp : veh->get_avail_parts( "ENGINE" ) ) {
if( vp.has_feature( "E_HIGHER_SKILL" ) ) {
engines++;
dif_max = std::max( dif_max, get_rq_mechanics( vp.info() ) );
}
}
if( engines > 0 ) {
int lvl = std::max( 6, dif_max + 3 );
dif_eng = std::min( 10, lvl + ( engines - 1 ) * 2 );
}
}
int dif_steering = 0;
if( sel_vpart_info->has_flag( "STEERABLE" ) ) {
std::set<int> axles;
for( auto &p : veh->steering ) {
if( !veh->part_flag( p, "TRACKED" ) ) {
// tracked parts don't contribute to axle complexity
axles.insert( veh->part( p ).mount.x );
}
}
if( !axles.empty() && axles.count( -dd.x ) == 0 ) {
// Installing more than one steerable axle is hard
// (but adding a wheel to an existing axle isn't)
// As with engines, cap at the actual maximum skill.
dif_steering = axles.size() + 5;
dif_steering = std::min( 10, dif_steering );
}
}
const auto reqs = sel_vpart_info->install_requirements();
Character &you = get_player_character();
std::string nmsg;
bool ok = format_reqs( nmsg, reqs, sel_vpart_info->install_skills,
sel_vpart_info->install_time( *you.as_player() ) );
std::string additional_requirements;
bool lifting_or_jacking_required = false;
if( dif_eng > 0 ) {
if( you.get_skill_level( skill_mechanics ) < dif_eng ) {
ok = false;
}
additional_requirements += string_format(
//~ %1$s represents the internal color name which shouldn't be translated,
//~ %2$s is skill name, and %3$i is skill level
_( "> %1$s%2$s %3$i</color> to install alongside other engines." ),
status_color( you.get_skill_level( skill_mechanics ) >= dif_eng ),
skill_mechanics.obj().name(), dif_eng ) + "\n";
}
if( dif_steering > 0 ) {
if( you.get_skill_level( skill_mechanics ) < dif_steering ) {
ok = false;
}
//~ %1$s represents the internal color name which shouldn't be translated, %2$s is skill name, and %3$i is skill level
additional_requirements += string_format( _( "> %1$s%2$s %3$i</color> for extra steering axles." ),
status_color( you.get_skill_level( skill_mechanics ) >= dif_steering ),
skill_mechanics.obj().name(), dif_steering ) + "\n";
}
int lvl = 0;
int str = 0;
quality_id qual;
bool use_aid = false;
bool use_str = false;
//TODO!: push this up?
item &base = *item::spawn_temporary( sel_vpart_info->item );
if( sel_vpart_info->has_flag( "NEEDS_JACKING" ) ) {
lifting_or_jacking_required = true;
qual = qual_JACK;
lvl = jack_quality( *veh );
str = veh->lift_strength();
use_aid = ( max_jack >= lvl ) || can_self_jack();
use_str = character_funcs::can_lift_with_helpers( you, str );
} else if( get_option<bool>( "DISABLE_LIFTING" ) || sel_vpart_info->has_flag( "NO_LIFT_REQ" ) ) {
use_aid = true;
use_str = true;
} else {
lifting_or_jacking_required = true;
qual = qual_LIFT;
lvl = std::ceil( units::quantity<double, units::mass::unit_type>( base.weight() ) /
TOOL_LIFT_FACTOR );
str = base.lift_strength();
use_aid = max_lift >= lvl;
use_str = character_funcs::can_lift_with_helpers( you, base.lift_strength() );
}
if( !( use_aid || use_str ) ) {
ok = false;
}
nc_color aid_color = use_aid ? c_green : ( use_str ? c_dark_gray : c_red );
nc_color str_color = use_str ? c_green : ( use_aid ? c_dark_gray : c_red );
const auto helpers = character_funcs::get_crafting_helpers( you );
std::string str_string;
if( lifting_or_jacking_required ) {
if( !helpers.empty() ) {
str_string = string_format( _( "strength ( assisted ) %d" ), str );
} else {
str_string = string_format( _( "strength %d" ), str );
}
//~ %1$s is quality name, %2$d is quality level
std::string aid_string = string_format( _( "1 tool with %1$s %2$d" ),
qual.obj().name, lvl );
additional_requirements += string_format( _( "> %1$s <color_white>OR</color> %2$s" ),
colorize( aid_string, aid_color ),
colorize( str_string, str_color ) ) + "\n";
}
if( !additional_requirements.empty() ) {
nmsg += _( "<color_white>Additional requirements:</color>\n" );
nmsg += additional_requirements;
}
sel_vpart_info->format_description( nmsg, c_light_gray, getmaxx( w_msg ) - 4 );
msg = colorize( nmsg, c_light_gray );
return ok || you.has_trait( trait_DEBUG_HS );
}
/**
* Moves list of fuels up or down.
* @param delta -1 if moving up,
* 1 if moving down
*/
void veh_interact::move_fuel_cursor( int delta )
{
int max_fuel_indicators = static_cast<int>( veh->get_printable_fuel_types().size() );
int height = 5;
fuel_index += delta;
if( fuel_index < 0 ) {
fuel_index = 0;
} else if( fuel_index > max_fuel_indicators - height ) {
fuel_index = std::max( max_fuel_indicators - height, 0 );
}
}
static void sort_uilist_entries_by_line_drawing( std::vector<uilist_entry> &shape_ui_entries )
{
// An ordering of the line drawing symbols that does not result in
// connecting when placed adjacent to each other vertically.
const static std::map<int, int> symbol_order = {
{ LINE_XOXO, 0 }, { LINE_OXOX, 1 },
{ LINE_XOOX, 2 }, { LINE_XXOO, 3 },
{ LINE_XXXX, 4 }, { LINE_OXXO, 5 },
{ LINE_OOXX, 6 }
};
std::sort( shape_ui_entries.begin(), shape_ui_entries.end(),
[]( const uilist_entry & a, const uilist_entry & b ) {
auto a_iter = symbol_order.find( a.extratxt.sym );
auto b_iter = symbol_order.find( b.extratxt.sym );
if( a_iter != symbol_order.end() ) {
if( b_iter != symbol_order.end() ) {
return a_iter->second < b_iter->second;
} else {
return true;
}
} else if( b_iter != symbol_order.end() ) {
return false;
} else {
return a.extratxt.sym < b.extratxt.sym;
}
} );
}
void veh_interact::do_install()
{
task_reason reason = cant_do( 'i' );
if( reason == INVALID_TARGET ) {
msg = _( "Cannot install any part here." );
return;
}
restore_on_out_of_scope<std::optional<std::string>> prev_title( title );
title = _( "Choose new part to install here:" );
restore_on_out_of_scope<std::unique_ptr<install_info_t>> prev_install_info( std::move(
install_info ) );
install_info = std::make_unique<install_info_t>();
std::array<std::string, 8> &tab_list = install_info->tab_list = { {
pgettext( "Vehicle Parts|", "All" ),
pgettext( "Vehicle Parts|", "Cargo" ),
pgettext( "Vehicle Parts|", "Light" ),
pgettext( "Vehicle Parts|", "Util" ),
pgettext( "Vehicle Parts|", "Hull" ),
pgettext( "Vehicle Parts|", "Internal" ),
pgettext( "Vehicle Parts|", "Other" ),
pgettext( "Vehicle Parts|", "Filter" )
}
};
install_info->tab_list_short = { {
pgettext( "Vehicle Parts|", "A" ),
pgettext( "Vehicle Parts|", "C" ),
pgettext( "Vehicle Parts|", "L" ),
pgettext( "Vehicle Parts|", "U" ),
pgettext( "Vehicle Parts|", "H" ),
pgettext( "Vehicle Parts|", "I" ),
pgettext( "Vehicle Parts|", "O" ),
pgettext( "Vehicle Parts|", "F" )
}
};
std::array <std::function<bool( const vpart_info * )>, 8>
tab_filters; // filter for each tab, last one
tab_filters[0] = [&]( const vpart_info * ) {
return true;
}; // All
tab_filters[1] = [&]( const vpart_info * p ) {
auto &part = *p;
return part.has_flag( VPFLAG_CARGO ) && // Cargo
!part.has_flag( "TURRET" );
};
tab_filters[2] = [&]( const vpart_info * p ) {
auto &part = *p;
return part.has_flag( VPFLAG_LIGHT ) || // Light
part.has_flag( VPFLAG_CONE_LIGHT ) ||
part.has_flag( VPFLAG_WIDE_CONE_LIGHT ) ||
part.has_flag( VPFLAG_CIRCLE_LIGHT ) ||
part.has_flag( VPFLAG_DOME_LIGHT ) ||
part.has_flag( VPFLAG_AISLE_LIGHT ) ||
part.has_flag( VPFLAG_ATOMIC_LIGHT );
};
tab_filters[3] = [&]( const vpart_info * p ) {
auto &part = *p;
return part.has_flag( "TRACK" ) || //Util
part.has_flag( VPFLAG_FRIDGE ) ||
part.has_flag( VPFLAG_FREEZER ) ||