forked from CleverRaven/Cataclysm-DDA
/
veh_interact.cpp
1288 lines (1244 loc) · 43.2 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 <string>
#include "veh_interact.h"
#include "vehicle.h"
#include "keypress.h"
#include "game.h"
#include "output.h"
#include "catacharset.h"
#include "crafting.h"
#include "options.h"
#include "debug.h"
/**
* Creates a blank veh_interact window.
*/
veh_interact::veh_interact ()
{
cursor_x = 0;
cursor_y = 0;
cpart = -1;
ddx = 0;
ddy = 0;
sel_cmd = ' ';
sel_type=0;
sel_vpart_info = NULL;
sel_vehicle_part = NULL;
}
/**
* Creates a veh_interact window based on the given parameters.
* @param v The vehicle the player is interacting with.
* @param x The x-coordinate of the square the player is 'e'xamining.
* @param y The y-coordinate of the square the player is 'e'xamining.
*/
void veh_interact::exec (game *gm, vehicle *v, int x, int y)
{
g = gm;
veh = v;
// x1 x2
// y1 ----+------+--
// | |
// y2 ----+------+
// |
// |
winw1 = 12;
winw2 = 35;
winh1 = 3;
winh2 = 12;
winw12 = winw1 + winw2 + 1;
winw3 = FULL_SCREEN_WIDTH - winw1 - winw2 - 2;
winh3 = FULL_SCREEN_HEIGHT - winh1 - winh2 - 2;
winh23 = winh2 + winh3 + 1;
winx1 = winw1;
winx2 = winw1 + winw2 + 1;
winy1 = winh1;
winy2 = winh1 + winh2 + 1;
// changed FALSE value to 1, to keep w_border from starting at a negative x,y
const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 1;
const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 1;
page_size = winh23;
// h w y x
WINDOW *w_border= newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, -1 + iOffsetY, -1 + iOffsetX);
w_grid = newwin(FULL_SCREEN_HEIGHT -2, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX);
w_mode = newwin(1, FULL_SCREEN_WIDTH-2, iOffsetY, iOffsetX);
w_msg = newwin(winh1 - 1, FULL_SCREEN_WIDTH-2, 1 + iOffsetY, iOffsetX);
w_disp = newwin(winh2-1, winw1, winy1 + 1 + iOffsetY, iOffsetX);
w_parts = newwin(winh2-1, winw2, winy1 + 1 + iOffsetY, winx1 + 1 + iOffsetX);
w_stats = newwin(winh3-1, winw12, winy2 + iOffsetY, iOffsetX);
w_list = newwin(winh23, winw3, winy1 + 1 + iOffsetY, winx2 + 1 + iOffsetX);
wborder(w_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwputch(w_border, 16, 0, c_ltgray, LINE_XXXO); // |-
mvwputch(w_border, 4, 0, c_ltgray, LINE_XXXO); // |-
mvwputch(w_border, 4, FULL_SCREEN_WIDTH-1, c_ltgray, LINE_XOXX); // -|
mvwputch(w_border, 24, 49, c_ltgray, LINE_XXOX);
wrefresh(w_border);
for (int i = 0; i < FULL_SCREEN_HEIGHT; i++)
{
mvwputch(w_grid, i, winx2, c_ltgray, i == winy1 || i == winy2-1? LINE_XOXX : LINE_XOXO);
if (i >= winy1 && i < winy2) {
mvwputch(w_grid, i, winx1, c_ltgray, LINE_XOXO);
}
}
for (int i = 0; i < FULL_SCREEN_WIDTH; i++)
{
mvwputch(w_grid, winy1, i, c_ltgray,
i == winx1? LINE_OXXX : (i == winx2? LINE_OXXX : LINE_OXOX));
if (i < winx2) {
mvwputch(w_grid, winy2-1, i, c_ltgray, i == winx1? LINE_XXOX : LINE_OXOX);
}
}
wrefresh(w_grid);
crafting_inv = gm->crafting_inventory(&gm->u);
int charges = static_cast<it_tool *>(g->itypes["welder"])->charges_per_use;
int charges_crude = static_cast<it_tool *>(g->itypes["welder_crude"])->charges_per_use;
has_wrench = crafting_inv.has_amount("wrench", 1) ||
crafting_inv.has_amount("toolset", 1);
has_hacksaw = crafting_inv.has_amount("hacksaw", 1) ||
crafting_inv.has_amount("toolset", 1);
has_welder = (crafting_inv.has_amount("welder", 1) &&
crafting_inv.has_charges("welder", charges)) ||
(crafting_inv.has_amount("welder_crude", 1) &&
crafting_inv.has_charges("welder_crude", charges_crude)) ||
(crafting_inv.has_amount("toolset", 1) &&
crafting_inv.has_charges("toolset", charges/20));
has_jack = crafting_inv.has_amount("jack", 1);
has_siphon = crafting_inv.has_amount("hose", 1);
has_wheel = crafting_inv.has_amount( "wheel", 1 ) ||
crafting_inv.has_amount( "wheel_wide", 1 ) ||
crafting_inv.has_amount( "wheel_bicycle", 1 ) ||
crafting_inv.has_amount( "wheel_motorbike", 1 ) ||
crafting_inv.has_amount( "wheel_small", 1 );
display_stats ();
display_veh ();
move_cursor (0, 0);
bool finish = false;
while (!finish)
{
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if (ch == KEY_ESCAPE || ch == 'q' )
{
finish = true;
}
else
{
if (dx != -2 && (dx || dy) &&
cursor_x + dx >= -6 && cursor_x + dx < 6 &&
cursor_y + dy >= -6 && cursor_y + dy < 6)
{
move_cursor(dx, dy);
}
else
{
int mval = cant_do(ch);
display_mode (ch);
switch (ch)
{
case 'i': do_install(mval); break;
case 'r': do_repair(mval); break;
case 'f': do_refill(mval); break;
case 'o': do_remove(mval); break;
case 'e': do_rename(mval); break;
case 's': do_siphon(mval); break;
case 'c': do_tirechange(mval); break;
case 'd': do_drain(mval); break;
}
if (sel_cmd != ' ')
{
finish = true;
}
display_mode (' ');
}
}
}
werase(w_grid);
werase(w_mode);
werase(w_msg);
werase(w_disp);
werase(w_parts);
werase(w_stats);
werase(w_list);
delwin(w_grid);
delwin(w_mode);
delwin(w_msg);
delwin(w_disp);
delwin(w_parts);
delwin(w_stats);
delwin(w_list);
erase();
}
/**
* 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 (ie 'r' for repair).
* @return 0 if the player has everything they need,
* 1 if the command can't target that square,
* 2 if the player lacks tools,
* 3 if something else obstructs the action,
* 4 if the player's skill isn't high enough.
*/
int veh_interact::cant_do (char mode)
{
bool valid_target = false;
bool has_tools = false;
bool part_free = true;
bool has_skill = true;
switch (mode)
{
case 'i': // install mode
valid_target = can_mount.size() > 0 && 0 == veh->tags.count("convertible");
has_tools = has_wrench && has_welder;
break;
case 'r': // repair mode
valid_target = need_repair.size() > 0 && cpart >= 0;
has_tools = has_welder;
break;
case 'f': // refill mode
valid_target = ptank != NULL;
has_tools = has_fuel;
break;
case 'o': // remove mode
valid_target = cpart >= 0 && 0 == veh->tags.count("convertible");
has_tools = has_wrench && has_hacksaw;
part_free = parts_here.size() > 1 || (cpart >= 0 && veh->can_unmount(cpart));
has_skill = g->u.skillLevel("mechanics") >= 2;
break;
case 's': // siphon mode
valid_target = veh->fuel_left("gasoline") > 0;
has_tools = has_siphon;
break;
case 'c': // Change tire
valid_target = wheel != NULL;
has_tools = has_wrench && has_jack && has_wheel;
break;
case 'd': //drain tank
valid_target = veh->fuel_left("water") > 0;
has_tools = has_siphon;
break;
default:
return -1;
}
if( !valid_target ) {
return 1;
}
if( !has_tools ) {
return 2;
}
if( !part_free ) {
return 3;
}
if( !has_skill ) {
return 4;
}
return 0;
}
/**
* Handles installing a new part.
* @param reason 1 if the square can't have anything installed,
* 2 if the player is lacking tools.
*/
void veh_interact::do_install(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
if (g->u.morale_level() < MIN_MORALE_CRAFT)
{ // See morale.h
mvwprintz(w_msg, 0, 1, c_ltred, _("Your morale is too low to construct..."));
wrefresh (w_msg);
return;
}
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("Cannot install any part here."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need a <color_%1$s>wrench</color> and a <color_%2$s>powered welder</color> to install parts."),
has_wrench ? "ltgreen" : "red",
has_welder ? "ltgreen" : "red");
wrefresh (w_msg);
return;
}
mvwprintz(w_mode, 0, 1, c_ltgray, _("Choose new part to install here:"));
wrefresh (w_mode);
int pos = 0;
int engines = 0;
int dif_eng = 0;
for (int p = 0; p < veh->parts.size(); p++)
{
if (veh->part_flag (p, "ENGINE"))
{
engines++;
dif_eng = dif_eng / 2 + 12;
}
}
while (true)
{
sel_vpart_info = &(can_mount[pos]);
display_list (pos);
itype_id itm = sel_vpart_info->item;
bool has_comps = crafting_inv.has_amount(itm, 1);
bool has_skill = g->u.skillLevel("mechanics") >= sel_vpart_info->difficulty;
bool has_tools = has_welder && has_wrench;
bool eng = sel_vpart_info->has_flag("ENGINE");
bool has_skill2 = !eng || (g->u.skillLevel("mechanics") >= dif_eng);
std::string engine_string = "";
if (engines && eng) // already has engine
{
engine_string = string_format(_(" You also need level <color_%1$s>%2$d</color> skill in mechanics to install additional engines."),
has_skill2 ? "ltgreen" : "red",
dif_eng);
}
werase (w_msg);
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("Needs <color_%1$s>%2$s</color>, a <color_%3$s>wrench</color>, a <color_%4$s>powered_welder</color>, and level <color_%5$s>%6$d</color> skill in mechanics.%7$s"),
has_comps ? "ltgreen" : "red",
g->itypes[itm]->name.c_str(),
has_wrench ? "ltgreen" : "red",
has_welder ? "ltgreen" : "red",
has_skill ? "ltgreen" : "red",
sel_vpart_info->difficulty,
engine_string.c_str());
wrefresh (w_msg);
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if ((ch == '\n' || ch == ' ') && has_comps && has_tools && has_skill && has_skill2)
{
sel_cmd = 'i';
return;
}
else
{
if (ch == KEY_ESCAPE || ch == 'q' )
{
werase (w_list);
wrefresh (w_list);
werase (w_msg);
break;
}
}
if (dy == -1 || dy == 1)
{
pos += dy;
if (pos < 0)
{
pos = can_mount.size()-1;
}
else if (pos >= can_mount.size())
{
pos = 0;
}
}
}
}
/**
* Handles repairing a vehicle part.
* @param reason 1 if there's no damaged parts in the selected square,
* 2 if the player is lacking tools.
*/
void veh_interact::do_repair(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
if (g->u.morale_level() < MIN_MORALE_CRAFT)
{ // See morale.h
mvwprintz(w_msg, 0, 1, c_ltred, _("Your morale is too low to construct..."));
wrefresh (w_msg);
return;
}
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("There are no damaged parts here."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need a <color_%s>powered welder</color> to repair."),
has_welder ? "ltgreen" : "red");
wrefresh (w_msg);
return;
}
mvwprintz(w_mode, 0, 1, c_ltgray, _("Choose a part here to repair:"));
wrefresh (w_mode);
int pos = 0;
while (true)
{
sel_vehicle_part = &veh->parts[parts_here[need_repair[pos]]];
werase (w_parts);
veh->print_part_desc (w_parts, 0, winw2, cpart, need_repair[pos]);
wrefresh (w_parts);
werase (w_msg);
bool has_comps = true;
int dif = vehicle_part_types[sel_vehicle_part->id].difficulty + (sel_vehicle_part->hp <= 0? 0 : 2);
bool has_skill = g->u.skillLevel("mechanics") >= dif;
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need level <color_%1$s>%2$d</color> skill in mechanics."),
has_skill ? "ltgreen" : "red",
dif);
if (sel_vehicle_part->hp <= 0)
{
itype_id itm = vehicle_part_types[sel_vehicle_part->id].item;
has_comps = crafting_inv.has_amount(itm, 1);
fold_and_print(w_msg, 1, 1, msg_width-2, c_ltgray,
_("You also need a <color_%1$s>wrench</color> and <color_%2$s>%3$s</color> to replace broken one."),
has_wrench ? "ltgreen" : "red",
has_comps ? "ltgreen" : "red",
g->itypes[itm]->name.c_str());
}
wrefresh (w_msg);
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if ((ch == '\n' || ch == ' ') &&
has_comps &&
(sel_vehicle_part->hp > 0 || has_wrench) && has_skill)
{
sel_cmd = 'r';
return;
}
else
if (ch == KEY_ESCAPE || ch == 'q' )
{
werase (w_parts);
veh->print_part_desc (w_parts, 0, winw2, cpart, -1);
wrefresh (w_parts);
werase (w_msg);
break;
}
if (dy == -1 || dy == 1)
{
pos += dy;
if(pos >= need_repair.size())
{
pos = 0;
}
else if(pos < 0)
{
pos = need_repair.size() - 1;
}
}
}
}
/**
* Handles refilling a vehicle's fuel tank.
* @param reason 1 if there's no fuel tank in the spot,
* 2 if the player has nothing to fill the tank with.
*/
void veh_interact::do_refill(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("There's no fuel tank here."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need <color_red>%s</color>."),
ammo_name(vehicle_part_types[ptank->id].fuel_type).c_str());
wrefresh (w_msg);
return;
}
sel_cmd = 'f';
sel_vehicle_part = ptank;
}
/**
* Handles removing a part from the vehicle.
* @param reason 1 if there are no parts to remove,
* 2 if the player is lacking tools,
* 3 if there's something attached that needs to be removed first,
* 4 if the player's mechanics skill isn't high enough.
*/
void veh_interact::do_remove(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
if (g->u.morale_level() < MIN_MORALE_CRAFT)
{ // See morale.h
mvwprintz(w_msg, 0, 1, c_ltred, _("Your morale is too low to construct..."));
wrefresh (w_msg);
return;
}
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("No parts here."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need a <color_%1$s>wrench</color> and a <color_%2$s>hacksaw</color> to remove parts."),
has_wrench ? "ltgreen" : "red",
has_hacksaw ? "ltgreen" : "red");
if(wheel) {
fold_and_print(w_msg, 1, 1, msg_width-2, c_ltgray,
_("To change a wheel you need a <color_%1$s>wrench</color> and a <color_%2$s>jack</color>."),
has_wrench ? "ltgreen" : "red",
has_jack ? "ltgreen" : "red");
}
wrefresh (w_msg);
return;
case 3:
mvwprintz(w_msg, 0, 1, c_ltred,
_("You cannot remove mount point while something is attached to it."));
wrefresh (w_msg);
return;
case 4:
mvwprintz(w_msg, 0, 1, c_ltred, _("You need level 2 mechanics skill to remove parts."));
wrefresh (w_msg);
return;
}
mvwprintz(w_mode, 0, 1, c_ltgray, _("Choose a part here to remove:"));
wrefresh (w_mode);
int first = parts_here.size() > 1? 1 : 0;
int pos = first;
while (true)
{
sel_vehicle_part = &veh->parts[parts_here[pos]];
werase (w_parts);
veh->print_part_desc (w_parts, 0, winw2, cpart, pos);
wrefresh (w_parts);
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if (ch == '\n' || ch == ' ')
{
sel_cmd = 'o';
return;
}
else
if (ch == KEY_ESCAPE || ch == 'q' )
{
werase (w_parts);
veh->print_part_desc (w_parts, 0, winw2, cpart, -1);
wrefresh (w_parts);
werase (w_msg);
break;
}
if (dy == -1 || dy == 1)
{
pos += dy;
if (pos < first)
{
pos = parts_here.size()-1;
}
else if (pos >= parts_here.size())
{
pos = first;
}
}
}
}
/**
* Handles siphoning gas.
* @param reason 1 if the vehicle has no gas, 2 if the player has no hose.
*/
void veh_interact::do_siphon(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("The vehicle has no gasoline to siphon."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need a <color_red>hose</color> to siphon fuel."));
wrefresh (w_msg);
return;
}
sel_cmd = 's';
}
/**
* Handles changing a tire.
* @param reason 1 if there's no wheel in the selected square,
* 2 if the player is missing a tool.
*/
void veh_interact::do_tirechange(int reason)
{
werase( w_msg );
int msg_width = getmaxx(w_msg);
switch( reason ) {
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("There is no wheel to change here."));
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("To change a wheel you need a <color_%1$s>wrench</color> and a <color_%2$s>jack</color>."),
has_wrench ? "ltgreen" : "red",
has_jack ? "ltgreen" : "red");
return;
}
mvwprintz(w_mode, 0, 1, c_ltgray, _("Choose wheel to use as replacement:"));
wrefresh (w_mode);
int pos = 0;
while (true)
{
sel_vpart_info = &(can_mount[pos]);
bool is_wheel = sel_vpart_info->has_flag("WHEEL");
display_list (pos);
itype_id itm = sel_vpart_info->item;
bool has_comps = crafting_inv.has_amount(itm, 1);
bool has_tools = has_jack && has_wrench;
werase (w_msg);
wrefresh (w_msg);
char ch = input(); // See keypress.h
int dx, dy;
get_direction (dx, dy, ch);
if ((ch == '\n' || ch == ' ') && has_comps && has_tools && is_wheel)
{
sel_cmd = 'c';
return;
}
else
{
if (ch == KEY_ESCAPE || ch == 'q' )
{
werase (w_list);
wrefresh (w_list);
werase (w_msg);
break;
}
}
if (dy == -1 || dy == 1)
{
pos += dy;
if (pos < 0)
{
pos = can_mount.size()-1;
}
else if (pos >= can_mount.size())
{
pos = 0;
}
}
}
}
/**
* Handles draining water from a vehicle.
* @param reason 1 if the vehicle has no water, 2 if the player has no hose.
*/
void veh_interact::do_drain(int reason)
{
werase (w_msg);
int msg_width = getmaxx(w_msg);
switch (reason)
{
case 1:
mvwprintz(w_msg, 0, 1, c_ltred, _("The vehicle has no water to siphon.") );
wrefresh (w_msg);
return;
case 2:
fold_and_print(w_msg, 0, 1, msg_width-2, c_ltgray,
_("You need a <color_red>hose</color> to siphon water.") );
wrefresh (w_msg);
return;
}
sel_cmd = 'd';
}
/**
* Handles renaming a vehicle.
* @param reason Unused.
*/
void veh_interact::do_rename(int reason)
{
std::string name = string_input_popup(_("Enter new vehicle name:"), 20);
if(name.length() > 0) {
(veh->name = name);
}
werase(w_stats);
werase(w_grid);
display_stats ();
display_veh ();
}
/**
* Returns the first (external) part on the vehicle at the given position.
* @param dx The x-coordinate, relative to the viewport's 0-point (?)
* @param dy The y-coordinate, relative to the viewport's 0-point (?)
* @return The external vehicle part at the specified coordinates.
*/
int veh_interact::part_at (int dx, int dy)
{
int vdx = -ddx - dy;
int vdy = dx - ddy;
for (int ep = 0; ep < veh->external_parts.size(); ep++)
{
int p = veh->external_parts[ep];
if (veh->parts[p].mount_dx == vdx && veh->parts[p].mount_dy == vdy)
{
return p;
}
}
return -1;
}
/**
* Moves the cursor on the vehicle editing window.
* @param dx How far to move the cursor on the x-axis.
* @param dy How far to move the cursor on the y-axis.
*/
void veh_interact::move_cursor (int dx, int dy)
{
mvwputch (w_disp, cursor_y + 6, cursor_x + 6, cpart >= 0 ? veh->part_color (cpart) : c_black,
special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' '));
cursor_x += dx;
cursor_y += dy;
cpart = part_at (cursor_x, cursor_y);
int vdx = -ddx - cursor_y;
int vdy = cursor_x - ddy;
int vx, vy;
veh->coord_translate (vdx, vdy, vx, vy);
int vehx = veh->global_x() + vx;
int vehy = veh->global_y() + vy;
bool obstruct = g->m.move_cost_ter_furn (vehx, vehy) == 0;
vehicle *oveh = g->m.veh_at (vehx, vehy);
if (oveh && oveh != veh)
{
obstruct = true;
}
nc_color col = cpart >= 0 ? veh->part_color (cpart) : c_black;
mvwputch (w_disp, cursor_y + 6, cursor_x + 6, obstruct ? red_background(col) : hilite(col),
special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' '));
wrefresh (w_disp);
werase (w_parts);
veh->print_part_desc (w_parts, 0, winw2, cpart, -1);
wrefresh (w_parts);
can_mount.clear();
if (!obstruct)
{
for (std::map<std::string, vpart_info>::iterator
part_type_iterator = vehicle_part_types.begin();
part_type_iterator != vehicle_part_types.end();
++part_type_iterator) {
if (veh->can_mount (vdx, vdy, part_type_iterator->first))
{
can_mount.push_back (part_type_iterator->second);
}
}
}
need_repair.clear();
parts_here.clear();
ptank = NULL;
wheel = NULL;
if (cpart >= 0)
{
//Misleading, internal_parts actually returns all parts at that square
parts_here = veh->internal_parts(cpart);
parts_here.insert (parts_here.begin(), cpart);
for (int i = 0; i < parts_here.size(); i++)
{
int p = parts_here[i];
if (veh->parts[p].hp < veh->part_info(p).durability)
{
need_repair.push_back (i);
}
if (veh->part_flag(p, "FUEL_TANK") && veh->parts[p].amount < veh->part_info(p).size)
{
ptank = &veh->parts[p];
}
if (veh->part_flag(p, "WHEEL") && veh->parts[p].amount < veh->part_info(p).size)
{
wheel = &veh->parts[p];
}
}
}
has_fuel = ptank != NULL ? g->refill_vehicle_part(*veh, ptank, true) : false;
werase (w_msg);
wrefresh (w_msg);
display_mode (' ');
}
/**
* Draws the viewport with the vehicle in it on the left side of the window.
*/
void veh_interact::display_veh ()
{
int x1 = 12, y1 = 12, x2 = -12, y2 = -12;
for (int ep = 0; ep < veh->external_parts.size(); ep++)
{
int p = veh->external_parts[ep];
if (veh->parts[p].mount_dx < x1)
{
x1 = veh->parts[p].mount_dx;
}
if (veh->parts[p].mount_dy < y1)
{
y1 = veh->parts[p].mount_dy;
}
if (veh->parts[p].mount_dx > x2)
{
x2 = veh->parts[p].mount_dx;
}
if (veh->parts[p].mount_dy > y2)
{
y2 = veh->parts[p].mount_dy;
}
}
ddx = 0;
ddy = 0;
if (x2 - x1 < 11) { x1--; x2++; }
if (y2 - y1 < 11 ) { y1--; y2++; }
if (x1 < -5)
{
ddx = -5 - x1;
}
else
{
if (x2 > 6)
{
ddx = 6 - x2;
}
}
if (y1 < -6)
{
ddy = -6 - y1;
}
else
{
if (y2 > 5)
{
ddy = 5 - y2;
}
}
for (int ep = 0; ep < veh->external_parts.size(); ep++)
{
int p = veh->external_parts[ep];
long sym = veh->part_sym (p);
nc_color col = veh->part_color (p);
int y = -(veh->parts[p].mount_dx + ddx);
int x = veh->parts[p].mount_dy + ddy;
mvwputch (w_disp, 6+y, 6+x, cursor_x == x && cursor_y == y? hilite(col) : col, special_symbol(sym));
if (cursor_x == x && cursor_y == y)
{
cpart = p;
}
}
wrefresh (w_disp);
}
/**
* Displays the vehicle's stats at the bottom of the window.
*/
void veh_interact::display_stats ()
{
bool conf = veh->valid_wheel_config();
int stat_width = getmaxx(w_stats);
mvwprintz(w_stats, 0, 1, c_ltgray, _("Name: "));
mvwprintz(w_stats, 0, 1+utf8_width(_("Name: ")), c_ltgreen, veh->name.c_str());
if(OPTIONS["USE_METRIC_SPEEDS"] == "km/h") {
fold_and_print(w_stats, 1, 1, stat_width-2, c_ltgray,
_("Safe speed: <color_ltgreen>%3d</color> km/h"),
int(veh->safe_velocity(false) * 0.0161f));
fold_and_print(w_stats, 2, 1, stat_width-2, c_ltgray,
_("Top speed: <color_ltred>%3d</color> km/h"),
int(veh->max_velocity(false) * 0.0161f));
fold_and_print(w_stats, 3, 1, stat_width-2, c_ltgray,
_("Accel.: <color_ltblue>%3d</color> kmh/t"),
int(veh->acceleration(false) * 0.0161f));
} else {
fold_and_print(w_stats, 1, 1, stat_width-2, c_ltgray,
_("Safe speed: <color_ltgreen>%3d</color> mph"),
veh->safe_velocity(false) / 100);
fold_and_print(w_stats, 2, 1, stat_width-2, c_ltgray,
_("Top speed: <color_ltred>%3d</color> mph"),
veh->max_velocity(false) / 100);
fold_and_print(w_stats, 3, 1, stat_width-2, c_ltgray,
_("Accel.: <color_ltblue>%3d</color> mph/t"),
veh->acceleration(false) / 100);
}
if (OPTIONS["USE_METRIC_WEIGHTS"] == "kg"){
fold_and_print(w_stats, 4, 1, stat_width-2, c_ltgray,
_("Mass: <color_ltblue>%5d</color> kg"),
int(veh->total_mass()));
} else {
fold_and_print(w_stats, 4, 1, stat_width-2, c_ltgray,
_("Mass: <color_ltblue>%5d</color> lbs"),
int(veh->total_mass() * 2.2));
}
if (conf) {
fold_and_print(w_stats, 5, 1, stat_width-2, c_ltgray,
_("Wheels: <color_ltgreen>enough</color>"));
} else {
fold_and_print(w_stats, 5, 1, stat_width-2, c_ltgray,
_("Wheels: <color_ltred> lack</color>"));
}
fold_and_print(w_stats, 3, 26, stat_width-2, c_ltgray,
_("K dynamics: <color_ltblue>%3d</color> %%"),
int(veh->k_dynamics() * 100));
fold_and_print(w_stats, 4, 26, stat_width-2, c_ltgray,
_("K mass: <color_ltblue>%3d</color> %%"),
int(veh->k_mass() * 100));
mvwprintz(w_stats, 6, 1, c_ltgray, _("Fuel usage (safe): "));
int fuel_usage_x = 1 + utf8_width(_("Fuel usage (safe): "));
ammotype fuel_types[3] = { "gasoline", "battery", "plasma" };
nc_color fuel_colors[3] = { c_ltred, c_yellow, c_ltblue };
bool first = true;
for (int i = 0; i < 3; ++i) {
int fuel_usage = veh->basic_consumption (fuel_types[i]);
if (fuel_usage > 0) {
fuel_usage = fuel_usage / 100;
if (fuel_usage < 1) {
fuel_usage = 1;
}
if (!first) {
mvwprintz(w_stats, 6, fuel_usage_x++, c_ltgray, "/");
}
mvwprintz(w_stats, 6, fuel_usage_x++, fuel_colors[i], "%d", fuel_usage);
if (fuel_usage > 9) {
fuel_usage_x++;
}
if (fuel_usage > 99) {
fuel_usage_x++;
}
first = false;
}
}
veh->print_fuel_indicator (w_stats, 0, 26, true, true);
wrefresh (w_stats);
}
/**
* Prints the list of usable commands at the top of the window, and highlights
* the hotkeys used to activate them.
* @param mode What command we are currently using. ' ' for no command.
*/
void veh_interact::display_mode (char mode)
{
werase (w_mode);
int x = 1;
if (mode == ' ')
{
bool mi = !cant_do('i');
bool mr = !cant_do('r');
bool mf = !cant_do('f');
bool mo = !cant_do('o');
bool ms = !cant_do('s');
bool mc = !cant_do('c');
x += shortcut_print(w_mode, 0, x, mi? c_ltgray : c_dkgray, mi? c_ltgreen : c_green, _("<i>nstall"))+1;
x += shortcut_print(w_mode, 0, x, mr? c_ltgray : c_dkgray, mr? c_ltgreen : c_green, _("<r>epair"))+1;
x += shortcut_print(w_mode, 0, x, mf? c_ltgray : c_dkgray, mf? c_ltgreen : c_green, _("re<f>ill"))+1;
x += shortcut_print(w_mode, 0, x, mo? c_ltgray : c_dkgray, mo? c_ltgreen : c_green, _("rem<o>ve"))+1;
x += shortcut_print(w_mode, 0, x, ms? c_ltgray : c_dkgray, ms? c_ltgreen : c_green, _("<s>iphon"))+1;
x += shortcut_print(w_mode, 0, x, ms? c_ltgray : c_dkgray, ms? c_ltgreen : c_green, _("<d>rain water"))+1;
x += shortcut_print(w_mode, 0, x, mc? c_ltgray : c_dkgray, mc? c_ltgreen : c_green, _("<c>hange tire"))+1;
}
x += shortcut_print(w_mode, 0, x, c_ltgray, c_ltgreen, _("r<e>name"))+1;
std::string backstr = _("<ESC>-back");
int w = utf8_width(backstr.c_str())-2;
x = 78-w; // right text align
shortcut_print(w_mode, 0, x, c_ltgray, c_ltgreen, _("<ESC>-back"));
wrefresh (w_mode);
}
/**
* Draws the list of parts that can be mounted in the selected square. Used
* when installing new parts or changing tires.
* @param pos The current cursor position in the list.
*/
void veh_interact::display_list (int pos)
{
werase (w_list);
int page = pos / page_size;
for (int i = page * page_size; i < (page + 1) * page_size && i < can_mount.size(); i++)
{
int y = i - page * page_size;
itype_id itm = can_mount[i].item;
bool has_comps = crafting_inv.has_amount(itm, 1);
bool has_skill = g->u.skillLevel("mechanics") >= can_mount[i].difficulty;
bool is_wheel = can_mount[i].has_flag("WHEEL");
nc_color col = has_comps && (has_skill || is_wheel) ? c_white : c_dkgray;
mvwprintz(w_list, y, 3, pos == i? hilite (col) : col, can_mount[i].name.c_str());
mvwputch (w_list, y, 1, can_mount[i].color, special_symbol(can_mount[i].sym));
}
wrefresh (w_list);
}
/** Used by consume_vpart_item to track items that could be consumed. */
struct candidate_vpart {
bool in_inventory;
int mapx;
int mapy;
union
{
signed char invlet;