forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editmap.cpp
2163 lines (1989 loc) · 81.3 KB
/
editmap.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 "editmap.h"
#include <cstdlib>
#include <cstring>
#include <exception>
#include <iosfwd>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <typeinfo>
#include <utility>
#include <vector>
#include "avatar.h"
#include "calendar.h"
#include "cata_utility.h"
#include "colony.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "creature.h"
#include "debug.h"
#include "debug_menu.h"
#include "field.h"
#include "field_type.h"
#include "fstream_utils.h"
#include "game.h"
#include "game_constants.h"
#include "input.h"
#include "int_id.h"
#include "item.h"
#include "line.h"
#include "map.h"
#include "map_iterator.h"
#include "mapdata.h"
#include "monster.h"
#include "mtype.h"
#include "npc.h"
#include "options.h"
#include "omdata.h"
#include "output.h"
#include "overmapbuffer.h"
#include "scent_map.h"
#include "shadowcasting.h"
#include "string_formatter.h"
#include "string_id.h"
#include "string_input_popup.h"
#include "submap.h"
#include "tileray.h"
#include "translations.h"
#include "trap.h"
#include "ui.h"
#include "ui_manager.h"
#include "uistate.h"
#include "vehicle.h"
#include "vpart_position.h"
static constexpr tripoint editmap_boundary_min( 0, 0, -OVERMAP_DEPTH );
static constexpr tripoint editmap_boundary_max( MAPSIZE_X, MAPSIZE_Y, OVERMAP_HEIGHT + 1 );
static constexpr half_open_cuboid<tripoint> editmap_boundaries(
editmap_boundary_min, editmap_boundary_max );
static const ter_id undefined_ter_id( -1 );
static std::vector<std::string> fld_string( const std::string &str, int width )
{
std::vector<std::string> lines;
if( width < 1 ) {
lines.push_back( str );
return lines;
}
int linepos = width;
int linestart = 0;
int crpos = -2;
while( linepos < static_cast<int>( str.length() ) || crpos != -1 ) {
crpos = str.find( '\n', linestart );
if( crpos != -1 && crpos <= linepos ) {
lines.push_back( str.substr( linestart, crpos - linestart ) );
linepos = crpos + width + 1;
linestart = crpos + 1;
} else {
int spacepos = str.rfind( ',', linepos );
if( spacepos == -1 ) {
spacepos = str.find( ',', linepos );
}
if( spacepos < linestart ) {
spacepos = linestart + width;
if( spacepos < static_cast<int>( str.length() ) ) {
lines.push_back( str.substr( linestart, width ) );
linepos = spacepos + width;
linestart = spacepos;
}
} else {
lines.push_back( str.substr( linestart, spacepos - linestart ) );
linepos = spacepos + width;
linestart = spacepos;
}
}
}
lines.push_back( str.substr( linestart ) );
return lines;
}
template<class SAVEOBJ>
void edit_json( SAVEOBJ &it )
{
int tmret = -1;
std::string save1 = serialize( it );
std::string osave1 = save1;
std::vector<std::string> fs1 = fld_string( save1, TERMX - 10 );
do {
uilist tm;
for( auto &elem : fs1 ) {
tm.addentry( -1, false, -2, elem );
}
if( tmret == 0 ) {
try {
SAVEOBJ tmp;
deserialize( tmp, save1 );
it = std::move( tmp );
} catch( const std::exception &err ) {
popup( "Error on deserialization: %s", err.what() );
}
std::string save2 = serialize( it );
std::vector<std::string> fs2 = fld_string( save2, TERMX - 10 );
tm.addentry( -1, false, -2, "== Reloaded: =====================" );
for( size_t s = 0; s < fs2.size(); ++s ) {
tm.addentry( -1, false, -2, fs2[s] );
if( s < fs1.size() && fs2[s] != fs1[s] ) {
tm.entries.back().force_color = true;
tm.entries.back().text_color = c_light_green;
tm.entries[s].force_color = true;
tm.entries[s].text_color = c_light_red;
}
}
fs2.clear();
} else if( tmret == 1 ) {
string_input_popup popup;
std::string ret = popup
.text( save1 )
.query_string();
if( popup.confirmed() ) {
fs1 = fld_string( ret, TERMX - 10 );
save1 = ret;
tmret = -2;
}
} else if( tmret == 2 ) {
write_to_file( "save/jtest-1j.txt", [&]( std::ostream & fout ) {
fout << osave1;
}, nullptr );
write_to_file( "save/jtest-2j.txt", [&]( std::ostream & fout ) {
fout << serialize( it );
}, nullptr );
}
tm.addentry( 0, true, 'r', pgettext( "item manipulation debug menu entry", "rehash" ) );
tm.addentry( 1, true, 'e', pgettext( "item manipulation debug menu entry", "edit" ) );
tm.addentry( 2, true, 'd', pgettext( "item manipulation debug menu entry",
"dump to save/jtest-*.txt" ) );
if( tmret != -2 ) {
tm.query();
if( tm.ret < 0 ) {
tmret = 3;
} else {
tmret = tm.ret;
}
} else {
tmret = 0;
}
} while( tmret != 3 );
}
editmap::editmap()
{
sel_field = -1;
sel_field_intensity = -1;
w_info = catacurses::window();
blink = false;
altblink = false;
moveall = false;
editshape = editmap_rect;
refresh_mplans = true;
target_list.clear();
hilights.clear();
hilights["mplan"].blink_interval.push_back( true );
hilights["mplan"].blink_interval.push_back( false );
hilights["mplan"].cur_blink = 0;
hilights["mplan"].color = c_red;
hilights["mplan"].setup();
hilights["mapgentgt"].blink_interval.push_back( true );
hilights["mapgentgt"].blink_interval.push_back( false );
hilights["mapgentgt"].blink_interval.push_back( false );
hilights["mapgentgt"].cur_blink = 0;
hilights["mapgentgt"].color = c_cyan;
hilights["mapgentgt"].setup();
uberdraw = false;
}
editmap::~editmap() = default;
void editmap_hilight::draw( editmap &em, bool update )
{
cur_blink++;
if( cur_blink >= static_cast<int>( blink_interval.size() ) ) {
cur_blink = 0;
}
if( blink_interval[ cur_blink ] || update ) {
map &here = get_map();
for( auto &elem : points ) {
const tripoint &p = elem.first;
// but only if there's no vehicles/mobs/npcs on a point
if( !here.veh_at( p ) && !g->critter_at( p ) ) {
const ter_t &terrain = here.ter( p ).obj();
char t_sym = terrain.symbol();
nc_color t_col = terrain.color();
if( here.furn( p ).to_i() > 0 ) {
const furn_t &furniture_type = here.furn( p ).obj();
t_sym = furniture_type.symbol();
t_col = furniture_type.color();
}
const field &t_field = here.field_at( p );
if( t_field.field_count() > 0 ) {
field_type_id t_ftype = t_field.displayed_field_type();
const field_entry *t_fld = t_field.find_field( t_ftype );
if( t_fld != nullptr ) {
t_col = t_fld->color();
t_sym = t_fld->symbol()[0];
}
}
if( blink_interval[ cur_blink ] ) {
t_col = getbg( t_col );
}
tripoint scrpos = em.pos2screen( p );
mvwputch( g->w_terrain, scrpos.xy(), t_col, t_sym );
}
}
}
}
/*
* map position to screen position
*/
tripoint editmap::pos2screen( const tripoint &p )
{
return p + tmax / 2 - target.xy();
}
/*
* get_direction with extended moving via HJKL keys
*/
bool editmap::eget_direction( tripoint &p, const std::string &action ) const
{
p = tripoint_zero;
if( action == "CENTER" ) {
p = g->u.pos() - target;
} else if( action == "LEFT_WIDE" ) {
p.x = -tmax.x / 2;
} else if( action == "DOWN_WIDE" ) {
p.y = tmax.y / 2;
} else if( action == "UP_WIDE" ) {
p.y = -tmax.y / 2;
} else if( action == "RIGHT_WIDE" ) {
p.x = tmax.x / 2;
} else if( action == "LEVEL_DOWN" ) {
p.z = -1;
} else if( action == "LEVEL_UP" ) {
p.z = 1;
} else {
input_context ctxt( "EGET_DIRECTION" );
ctxt.set_iso( true );
const std::optional<tripoint> vec = ctxt.get_direction( action );
if( !vec ) {
return false;
}
p = *vec;
}
return true;
}
class editmap::game_draw_callback_t_container
{
public:
game_draw_callback_t_container( editmap *em ) : em( em ) {}
shared_ptr_fast<game::draw_callback_t> create_or_get();
private:
editmap *em;
weak_ptr_fast<game::draw_callback_t> cbw;
};
shared_ptr_fast<game::draw_callback_t> editmap::game_draw_callback_t_container::create_or_get()
{
shared_ptr_fast<game::draw_callback_t> cb = cbw.lock();
if( !cb ) {
cbw = cb = make_shared_fast<game::draw_callback_t>(
[this]() {
em->draw_main_ui_overlay();
} );
g->add_draw_callback( cb );
}
return cb;
}
editmap::game_draw_callback_t_container &editmap::draw_cb_container()
{
if( !draw_cb_container_ ) {
draw_cb_container_ = std::make_unique<game_draw_callback_t_container>( this );
}
return *draw_cb_container_;
}
shared_ptr_fast<ui_adaptor> editmap::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 & ui ) {
w_info = catacurses::newwin( infoHeight, width, point( offsetX, TERMY - infoHeight ) );
tmax = point( getmaxx( g->w_terrain ), getmaxy( g->w_terrain ) );
ui.position_from_window( w_info );
} );
current_ui->mark_resize();
current_ui->on_redraw( [this]( const ui_adaptor & ) {
update_view_with_help( info_txt_curr, info_title_curr );
} );
}
return current_ui;
}
std::optional<tripoint> editmap::edit()
{
restore_on_out_of_scope<tripoint> view_offset_prev( g->u.view_offset );
target = g->u.pos() + g->u.view_offset;
input_context ctxt( "EDITMAP" );
ctxt.set_iso( true );
ctxt.register_directions();
ctxt.register_action( "LEFT_WIDE" );
ctxt.register_action( "RIGHT_WIDE" );
ctxt.register_action( "UP_WIDE" );
ctxt.register_action( "DOWN_WIDE" );
ctxt.register_action( "LEVEL_UP" );
ctxt.register_action( "LEVEL_DOWN" );
ctxt.register_action( "EDIT_TRAPS" );
ctxt.register_action( "EDIT_FIELDS" );
ctxt.register_action( "EDIT_TERRAIN" );
ctxt.register_action( "EDIT_FURNITURE" );
ctxt.register_action( "EDIT_OVERMAP" );
ctxt.register_action( "EDIT_ITEMS" );
ctxt.register_action( "EDIT_MONSTER" );
ctxt.register_action( "EDITMAP_SHOW_ALL" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );
// Needed for timeout to be useful
ctxt.register_action( "ANY_INPUT" );
std::string action;
uberdraw = uistate.editmap_nsa_viewmode;
blink = true;
shared_ptr_fast<game::draw_callback_t> editmap_cb = draw_cb_container().create_or_get();
shared_ptr_fast<ui_adaptor> current_ui = create_or_get_ui_adaptor();
on_out_of_scope invalidate_current_ui( [this]() {
do_ui_invalidation();
} );
restore_on_out_of_scope<std::string> info_txt_prev( info_txt_curr );
restore_on_out_of_scope<std::string> info_title_prev( info_title_curr );
do {
if( target_list.empty() ) {
target_list.push_back( target ); // 'editmap.target_list' always has point 'editmap.target' at least
}
if( target_list.size() == 1 ) {
origin = target; // 'editmap.origin' only makes sense if we have a list of target points.
}
// \u00A0 is the non-breaking space
info_txt_curr = string_format( pgettext( "keybinding descriptions",
"%s, %s, [%s,%s,%s,%s]\u00A0fast scroll, %s, %s, %s, %s, %s, %s" ),
ctxt.describe_key_and_name( "EDIT_TRAPS" ),
ctxt.describe_key_and_name( "EDIT_FIELDS" ),
ctxt.get_desc( "LEFT_WIDE", 1 ), ctxt.get_desc( "RIGHT_WIDE", 1 ),
ctxt.get_desc( "UP_WIDE", 1 ), ctxt.get_desc( "DOWN_WIDE", 1 ),
ctxt.describe_key_and_name( "EDITMAP_SHOW_ALL" ),
ctxt.describe_key_and_name( "EDIT_TERRAIN" ),
ctxt.describe_key_and_name( "EDIT_FURNITURE" ),
ctxt.describe_key_and_name( "EDIT_OVERMAP" ),
ctxt.describe_key_and_name( "EDIT_ITEMS" ),
ctxt.describe_key_and_name( "QUIT" ) );
info_title_curr = pgettext( "map editor state", "Looking around" );
do_ui_invalidation();
ui_manager::redraw();
action = ctxt.handle_input( get_option<int>( "BLINK_SPEED" ) );
if( action == "EDIT_TERRAIN" ) {
edit_feature<ter_t>();
} else if( action == "EDIT_FURNITURE" ) {
edit_feature<furn_t>();
} else if( action == "EDIT_FIELDS" ) {
edit_fld();
} else if( action == "EDIT_ITEMS" ) {
edit_itm();
} else if( action == "EDIT_TRAPS" ) {
edit_feature<trap>();
} else if( action == "EDITMAP_SHOW_ALL" ) {
uberdraw = !uberdraw;
} else if( action == "EDIT_MONSTER" ) {
if( Creature *const critter = g->critter_at( target ) ) {
edit_critter( *critter );
} else if( get_map().veh_at( target ) ) {
edit_veh();
}
} else if( action == "EDIT_OVERMAP" ) {
edit_mapgen();
target_list.clear();
origin = target;
target_list.push_back( target );
} else if( move_target( action, 1 ) ) {
recalc_target( editshape ); // target_list must follow movement
}
blink = action == "TIMEOUT" ? !blink : true;
} while( action != "QUIT" );
blink = false;
uistate.editmap_nsa_viewmode = uberdraw;
if( action == "CONFIRM" ) {
return target;
}
return std::nullopt;
}
/*
* This is like game::draw_ter except it completely ignores line of sight, lighting, boomered, etc.
* This is a map editor after all.
*/
void editmap::uber_draw_ter( const catacurses::window &w, map *m )
{
tripoint center = target;
tripoint start = center.xy() + tripoint( -getmaxx( w ) / 2, -getmaxy( w ) / 2, target.z );
tripoint end = center.xy() + tripoint( getmaxx( w ) / 2, getmaxy( w ) / 2, target.z );
/*
// pending filter options
bool draw_furn=true;
bool draw_ter=true;
bool draw_trp=true;
bool draw_fld=true;
bool draw_veh=true;
*/
bool game_map = m == &get_map() || w == g->w_terrain;
const int msize = MAPSIZE_X;
if( refresh_mplans ) {
hilights["mplan"].points.clear();
}
drawsq_params params = drawsq_params().center( center );
for( const tripoint &p : tripoint_range<tripoint>( start, end ) ) {
int sym = game_map ? '%' : ' ';
if( p.x >= 0 && p.x < msize && p.y >= 0 && p.y < msize ) {
if( game_map ) {
Creature *critter = g->critter_at( p );
if( critter != nullptr ) {
critter->draw( w, center.xy(), false );
} else {
m->drawsq( w, p, params );
}
if( refresh_mplans ) {
monster *mon = dynamic_cast<monster *>( critter );
if( mon != nullptr && mon->pos() != mon->move_target() ) {
for( auto &location : line_to( mon->pos(), mon->move_target() ) ) {
hilights["mplan"].points[location] = 1;
}
}
}
} else {
m->drawsq( w, p, params );
}
} else {
mvwputch( w, p.xy() - start.xy(), c_dark_gray, sym );
}
}
if( refresh_mplans ) {
refresh_mplans = false;
}
}
void editmap::do_ui_invalidation()
{
g->u.view_offset = target - g->u.pos();
g->invalidate_main_ui_adaptor();
create_or_get_ui_adaptor()->invalidate_ui();
}
void editmap::draw_main_ui_overlay()
{
const Creature *critter = g->critter_at( target );
map &here = get_map();
#if !defined( TILES )
if( uberdraw ) {
uber_draw_ter( g->w_terrain, &here ); // Bypassing the usual draw methods; not versatile enough
}
#endif
// update target point
if( critter != nullptr ) {
critter->draw( g->w_terrain, target, true );
} else {
here.drawsq( g->w_terrain, target, drawsq_params().highlight( true ).center( target ) );
}
#ifdef TILES
// give some visual indication of different cursor moving modes
if( use_tiles && altblink ) {
point p[2] = { origin.xy(), target.xy() };
if( editshape == editmap_rect || editshape == editmap_rect_filled || p[0] == p[1] ) {
if( p[0] == p[1] ) {
// ensure more than one cursor is drawn to differ from resizing mode
p[0] += point_north_west;
p[1] += point_south_east;
}
for( const auto &pi : p ) {
for( const auto &pj : p ) {
g->draw_cursor( tripoint( pi.x, pj.y, target.z ) );
}
}
} else if( editshape == editmap_circle ) {
g->draw_cursor( target );
g->draw_cursor( origin * 2 - target );
} else if( editshape == editmap_line ) {
g->draw_cursor( origin );
g->draw_cursor( target );
}
} else {
#endif
g->draw_cursor( target );
#ifdef TILES
}
#endif
// hilight target_list points if blink=true
if( blink ) {
for( const auto &p : target_list ) {
#ifdef TILES
if( use_tiles ) {
if( draw_target_override ) {
draw_target_override( p );
} else {
g->draw_highlight( p );
}
} else {
#endif
// but only if there's no vehicles/mobs/npcs on a point
if( !here.veh_at( p ) && !g->critter_at( p ) ) {
const ter_t &terrain = here.ter( p ).obj();
char t_sym = terrain.symbol();
nc_color t_col = terrain.color();
if( here.has_furn( p ) ) {
const furn_t &furniture_type = here.furn( p ).obj();
t_sym = furniture_type.symbol();
t_col = furniture_type.color();
}
const field &t_field = here.field_at( p );
if( t_field.field_count() > 0 ) {
field_type_id t_ftype = t_field.displayed_field_type();
const field_entry *t_fld = t_field.find_field( t_ftype );
if( t_fld != nullptr ) {
t_col = t_fld->color();
t_sym = t_fld->symbol()[0];
}
}
t_col = altblink ? green_background( t_col ) : cyan_background( t_col );
tripoint scrpos = pos2screen( p );
mvwputch( g->w_terrain, scrpos.xy(), t_col, t_sym );
}
#ifdef TILES
}
#endif
}
}
// custom highlight.
// TODO: optimize
for( auto &elem : hilights ) {
if( !elem.second.points.empty() ) {
elem.second.draw( *this );
}
}
// draw arrows if altblink is set (ie, [m]oving a large selection
if( blink && altblink ) {
const point mp = tmax / 2 + point_south_east;
mvwputch( g->w_terrain, point( 1, mp.y ), c_yellow, '<' );
mvwputch( g->w_terrain, point( tmax.x - 1, mp.y ), c_yellow, '>' );
mvwputch( g->w_terrain, point( mp.x, 1 ), c_yellow, '^' );
mvwputch( g->w_terrain, point( mp.x, tmax.y - 1 ), c_yellow, 'v' );
}
if( tmpmap_ptr ) {
tinymap &tmpmap = *tmpmap_ptr;
#ifdef TILES
if( use_tiles ) {
const point origin_p = target.xy() + point( 1 - SEEX, 1 - SEEY );
for( int x = 0; x < SEEX * 2; x++ ) {
for( int y = 0; y < SEEY * 2; y++ ) {
const tripoint tmp_p( x, y, target.z );
const tripoint map_p = origin_p + tmp_p;
g->draw_radiation_override( map_p, tmpmap.get_radiation( tmp_p ) );
// scent is managed in `game` instead of `map`, so there's no override for it
// temperature is managed in `game` instead of `map`, so there's no override for it
// TODO: visibility could be affected by both the actual map and the preview map,
// which complicates calculation, so there's no override for it (yet)
g->draw_terrain_override( map_p, tmpmap.ter( tmp_p ) );
g->draw_furniture_override( map_p, tmpmap.furn( tmp_p ) );
g->draw_graffiti_override( map_p, tmpmap.has_graffiti_at( tmp_p ) );
g->draw_trap_override( map_p, tmpmap.tr_at( tmp_p ).loadid );
g->draw_field_override( map_p, tmpmap.field_at( tmp_p ).displayed_field_type() );
const maptile &tile = tmpmap.maptile_at( tmp_p );
if( tmpmap.sees_some_items( tmp_p, g->u.pos() - origin_p ) ) {
const item &itm = tile.get_uppermost_item();
const mtype *const mon = itm.get_mtype();
g->draw_item_override( map_p, itm.typeId(), mon ? mon->id : mtype_id::NULL_ID(),
tile.get_item_count() > 1 );
} else {
g->draw_item_override( map_p, itype_id::NULL_ID(), mtype_id::NULL_ID(),
false );
}
const optional_vpart_position vp = tmpmap.veh_at( tmp_p );
if( vp ) {
const vehicle &veh = vp->vehicle();
const int veh_part = vp->part_index();
char part_mod = 0;
const vpart_id &vp_id = veh.part_id_string( veh_part, false, part_mod );
const std::optional<vpart_reference> cargopart = vp.part_with_feature( "CARGO", true );
bool draw_highlight = cargopart && !veh.get_items( cargopart->part_index() ).empty();
units::angle veh_dir = veh.face.dir();
g->draw_vpart_override( map_p, vp_id, part_mod, veh_dir, draw_highlight, vp->mount() );
} else {
g->draw_vpart_override( map_p, vpart_id::NULL_ID(), 0, 0_degrees, false,
point_zero );
}
g->draw_below_override( map_p, here.has_zlevels() &&
tmpmap.ter( tmp_p ).obj().has_flag( TFLAG_NO_FLOOR ) );
}
}
// int: count, bool: more than 1 spawn data
std::map<tripoint, std::tuple<mtype_id, int, bool, Creature::Attitude>> spawns;
for( int x = 0; x < 2; x++ ) {
for( int y = 0; y < 2; y++ ) {
submap *sm = tmpmap.get_submap_at_grid( { x, y, target.z } );
if( sm ) {
const tripoint sm_origin = origin_p + tripoint( x * SEEX, y * SEEY, target.z );
for( const auto &sp : sm->spawns ) {
const tripoint spawn_p = sm_origin + sp.pos;
const auto spawn_it = spawns.find( spawn_p );
if( spawn_it == spawns.end() ) {
const Creature::Attitude att = sp.friendly ? Creature::A_FRIENDLY : Creature::A_ANY;
spawns.emplace( spawn_p, std::make_tuple( sp.type, sp.count, false, att ) );
} else {
std::get<2>( spawn_it->second ) = true;
}
}
}
}
}
for( const auto &it : spawns ) {
g->draw_monster_override( it.first, std::get<0>( it.second ), std::get<1>( it.second ),
std::get<2>( it.second ), std::get<3>( it.second ) );
}
} else {
#endif
hilights["mapgentgt"].draw( *this, true );
tmpmap.reset_vehicle_cache( );
drawsq_params params = drawsq_params().center( tripoint( SEEX - 1, SEEY - 1, target.z ) );
for( const tripoint &p : tmpmap.points_on_zlevel() ) {
tmpmap.drawsq( g->w_terrain, p, params );
}
#ifdef TILES
}
#endif
}
}
void editmap::update_view_with_help( const std::string &txt, const std::string &title )
{
// updating info
werase( w_info );
Character &player_character = get_player_character();
map &here = get_map();
const optional_vpart_position vp = here.veh_at( target );
std::string veh_msg;
if( !vp ) {
veh_msg = pgettext( "vehicle", "no" );
} else if( vp->is_inside() ) {
veh_msg = pgettext( "vehicle", "in" );
} else {
veh_msg = pgettext( "vehicle", "out" );
}
const ter_t &terrain_type = here.ter( target ).obj();
const furn_t &furniture_type = here.furn( target ).obj();
int off = 1;
draw_border( w_info );
mvwprintz( w_info, point( 2, 0 ), c_light_gray, "< %d,%d >", target.x, target.y );
mvwputch( w_info, point( 2, off ), terrain_type.color(), terrain_type.symbol() );
mvwprintw( w_info, point( 4, off ), _( "%d: %s; movecost %d" ), here.ter( target ).to_i(),
terrain_type.name(),
terrain_type.movecost
);
off++; // 2
if( here.furn( target ).to_i() > 0 ) {
mvwputch( w_info, point( 2, off ), furniture_type.color(), furniture_type.symbol() );
mvwprintw( w_info, point( 4, off ), _( "%d: %s; movecost %d movestr %d" ),
here.furn( target ).to_i(),
furniture_type.name(),
furniture_type.movecost,
furniture_type.move_str_req
);
off++; // 3
}
const auto &map_cache = here.get_cache( target.z );
const std::string u_see_msg = player_character.sees( target ) ? _( "yes" ) : _( "no" );
mvwprintw( w_info, point( 1, off++ ), _( "dist: %d u_see: %s veh: %s scent: %d" ),
rl_dist( player_character.pos(), target ), u_see_msg, veh_msg, g->scent.get( target ) );
mvwprintw( w_info, point( 1, off++ ), _( "sight_range: %d, daylight_sight_range: %d," ),
player_character.sight_range( g->light_level( player_character.posz() ) ),
player_character.sight_range( current_daylight_level( calendar::turn ) ) );
mvwprintw( w_info, point( 1, off++ ), _( "cache{transp:%.4f seen:%.4f cam:%.4f}" ),
map_cache.transparency_cache[target.x][target.y],
map_cache.seen_cache[target.x][target.y],
map_cache.camera_cache[target.x][target.y]
);
map::apparent_light_info al = map::apparent_light_helper( map_cache, target );
int apparent_light = static_cast<int>(
here.apparent_light_at( target, here.get_visibility_variables_cache() ) );
mvwprintw( w_info, point( 1, off++ ), _( "outside: %d obstructed: %d floor: %d" ),
static_cast<int>( here.is_outside( target ) ),
static_cast<int>( al.obstructed ),
static_cast<int>( here.has_floor( target ) )
);
mvwprintw( w_info, point( 1, off++ ), _( "light_at: %s" ),
map_cache.lm[target.x][target.y].to_string() );
mvwprintw( w_info, point( 1, off++ ), _( "apparent light: %.5f (%d)" ),
al.apparent_light, apparent_light );
std::string extras;
if( vp ) {
extras += _( " [vehicle]" );
}
if( here.has_flag( TFLAG_INDOORS, target ) ) {
extras += _( " [indoors]" );
}
if( here.has_flag( TFLAG_SUPPORTS_ROOF, target ) ) {
extras += _( " [roof]" );
}
mvwprintw( w_info, point( 1, off ), "%s %s", here.features( target ), extras );
// 9
off++;
for( auto &fld : here.get_field( target ) ) {
const field_entry &cur = fld.second;
mvwprintz( w_info, point( 1, off ), cur.color(),
_( "field: %s L:%d[%s] A:%d" ),
cur.get_field_type().id().str(),
cur.get_field_intensity(),
cur.name(),
to_turns<int>( cur.get_field_age() )
);
off++; // 10ish
}
const trap &cur_trap = here.tr_at( target );
if( cur_trap.loadid != tr_null ) {
mvwprintz( w_info, point( 1, off ), cur_trap.color, _( "trap: %s (%d)" ), cur_trap.name(),
cur_trap.loadid.to_i() );
off++; // 11
}
const Creature *critter = g->critter_at( target );
if( critter != nullptr ) {
off = critter->print_info( w_info, off, 5, 1 );
} else if( vp ) {
mvwprintw( w_info, point( 1, off ), _( "There is a %s there. Parts:" ), vp->vehicle().name );
off++;
vp->vehicle().print_part_list( w_info, off, getmaxy( w_info ) - 1, width, vp->part_index() );
off += 6;
}
map_stack target_stack = here.i_at( target );
const int target_stack_size = target_stack.size();
if( !here.has_flag( "CONTAINER", target ) && target_stack_size > 0 ) {
trim_and_print( w_info, point( 1, off ), getmaxx( w_info ), c_light_gray,
_( "There is a %s there." ),
target_stack.begin()->tname() );
off++;
if( target_stack_size > 1 ) {
mvwprintw( w_info, point( 1, off ), vgettext( "There is %d other item there as well.",
"There are %d other items there as well.",
target_stack_size - 1 ),
target_stack_size - 1 );
off++;
}
}
if( here.has_graffiti_at( target ) ) {
mvwprintw( w_info, point( 1, off ),
here.ter( target ) == t_grave_new ? _( "Graffiti: %s" ) : _( "Inscription: %s" ),
here.graffiti_at( target ) );
}
// updating help
int line = getmaxy( w_info ) - 1;
if( !title.empty() ) {
const std::string str = string_format( "< <color_cyan>%s</color> >", title );
center_print( w_info, line, BORDER_COLOR, str );
}
--line;
std::vector<std::string> folded = foldstring( txt, width - 2 );
for( auto it = folded.rbegin(); it != folded.rend(); ++it, --line ) {
nc_color dummy = c_light_gray;
print_colored_text( w_info, point( 1, line ), dummy, c_light_gray, *it );
}
wnoutrefresh( w_info );
}
static ter_id get_alt_ter( bool isvert, ter_id sel_ter )
{
std::map<std::string, std::string> alts;
alts["_v"] = "_h";
alts["_vertical"] = "_horizontal";
alts["_v_alarm"] = "_h_alarm";
const std::string tersid = sel_ter.obj().id.str();
const int sidlen = tersid.size();
for( std::map<std::string, std::string>::const_iterator it = alts.begin(); it != alts.end();
++it ) {
const std::string suffix = isvert ? it->first : it->second;
const int slen = suffix.size();
if( sidlen > slen && tersid.substr( sidlen - slen, slen ) == suffix ) {
const std::string asuffix = isvert ? it->second : it->first;
const std::string terasid = tersid.substr( 0, sidlen - slen ) + asuffix;
const ter_str_id tid( terasid );
if( tid.is_valid() ) {
return tid.id();
}
}
}
return undefined_ter_id;
}
template<typename T_t>
static std::string info_title();
template<>
std::string info_title<ter_t>()
{
return pgettext( "map editor state", "Terrain" );
}
template<>
std::string info_title<furn_t>()
{
return pgettext( "map editor state", "Furniture" );
}
template<>
std::string info_title<trap>()
{
return pgettext( "map editor: traps editing", "Traps" );
}
template<typename T_id>
static T_id feature( const tripoint &p );
template<>
ter_id feature<ter_id>( const tripoint &p )
{
return get_map().ter( p );
}
template<>
furn_id feature<furn_id>( const tripoint &p )
{
return get_map().furn( p );
}
template<>
trap_id feature<trap_id>( const tripoint &p )
{
return get_map().tr_at( p ).loadid;
}
template<typename T_t>
static int symbol( const T_t &t );
template<>
int symbol( const ter_t &t )
{
return t.symbol();
}
template<>
int symbol( const furn_t &t )
{
return t.symbol();
}
template<>
int symbol( const trap &t )
{
return t.sym;
}
template<typename T_t>
static nc_color color( const T_t &t );
template<>
nc_color color( const ter_t &t )
{
return t.color();
}
template<>
nc_color color( const furn_t &t )
{
return t.color();
}
template<>
nc_color color( const trap &t )
{
return t.color;
}
template<typename T_t>
static std::string describe( const T_t &t );
template<>
std::string describe( const ter_t &type )
{
return string_format( _( "Move cost: %d\nIndoors: %s\nRoof: %s" ), type.movecost,
type.has_flag( TFLAG_INDOORS ) ? _( "Yes" ) : _( "No" ),
type.has_flag( TFLAG_SUPPORTS_ROOF ) ? _( "Yes" ) : _( "No" ) );
}
template<>
std::string describe( const furn_t &type )
{
return string_format( _( "Move cost: %d\nIndoors: %s\nRoof: %s" ), type.movecost,
type.has_flag( TFLAG_INDOORS ) ? _( "Yes" ) : _( "No" ),
type.has_flag( TFLAG_SUPPORTS_ROOF ) ? _( "Yes" ) : _( "No" ) );
}
template<>
std::string describe( const trap &type )
{
return string_format( _( "Visible: %d\nAvoidance: %d\nDifficulty: %d\nBenign: %s" ),
type.get_visibility(), type.get_avoidance(), type.get_difficulty(),
type.is_benign() ? _( "Yes" ) : _( "No" ) );
}
template<typename T_id>
static void draw_override( const tripoint &p, const T_id &id );
template<>
void draw_override<ter_id>( const tripoint &p, const ter_id &id )
{
g->draw_terrain_override( p, id );
}
template<>
void draw_override<furn_id>( const tripoint &p, const furn_id &id )
{
g->draw_furniture_override( p, id );
}
template<>
void draw_override<trap_id>( const tripoint &p, const trap_id &id )
{
g->draw_trap_override( p, id );
}
template<typename T_t>
static void apply( const T_t &t, shapetype editshape, const tripoint &target,
const tripoint &origin, const std::vector<tripoint> &target_list );