-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdFcns.cpp
executable file
·7231 lines (6431 loc) · 234 KB
/
EdFcns.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 "stdafx.h"
#include "Resource.h"
#include "global.h"
#define MAX_RECURSION_DEPTH 200
// bit definition of scroll direction
enum {
eSCRL_NoScrl = 0,
eSCRL_Top = 0x08,
eSCRL_Left = 0x04,
eSCRL_Bottom = 0x02,
eSCRL_Right = 0x01,
};
// Edit screen coordinates
/*const RECT kRect3DEditScrn = {
TERRAIN_BORDER_WIDTH + TER_RECT_UL_X - 15,
TERRAIN_BORDER_WIDTH + TER_RECT_UL_Y - 15,
TERRAIN_BORDER_WIDTH + BIG_SPACE_SIZE * 9 + TER_RECT_UL_X + 15,
TERRAIN_BORDER_WIDTH + BIG_SPACE_SIZE * 9 + TER_RECT_UL_Y + 15
};*/
const RECT kRect3DEditScrn = {
0 + TER_RECT_UL_Y,
0 + TER_RECT_UL_X,
496 + TER_RECT_UL_Y,
415 + TER_RECT_UL_X
};
extern const RECT terrain_viewport_3d;
// scroll speed limit: duration / cycle
const DWORD kScrollLimitTime = 100; // msec
// Global variables
// border rects order: top, left, bottom, right //
RECT border_rect[4];
RECT terrain_rects[330];
// RECT terrain_rect_base = {0,0,16,16};
RECT terrain_rects_3D[330];
// RECT terrain_rect_base_3D = {0,0,16,16};
RECT palette_buttons[9][6];
// These are the rects of the terrain spots INSIDE the terrain GWORLD, NOT the screen.
RECT small_edit_ter_rects[MAX_TOWN_SIZE][MAX_TOWN_SIZE];
RECT medium_edit_ter_rects[32][32];
RECT large_edit_ter_rects[9][9];
// Bottom text rectangles
RECT left_text_lines[14];
// right_text_lines rects are for INSIDE the buttons GWORLD, NOT the screen.
RECT right_text_lines[7];
location spot_hit;
bool object_sticky_draw;
short current_floor_drawn = 0;
short current_terrain_drawn = 0;
Boolean shft_key,alt_key,ctrl_key;
extern char hintbook_mode0;
extern char hintbook_mode1;
extern char hintbook_mode2;
extern char hintbook_mode3;
extern char hintbook_mode4;
extern char hintbook_mode5;
extern char hintbook_mode6;
extern char hintbook_mode7;
extern char hintbook_mode8;
extern char hintbook_mode9;
extern char grid_mode;
extern short last_large_mode;
extern Boolean r1_in_r2(macRECT r1,macRECT r2);
// if a terrain type has special property from 19-30, it is a slope. this
// array says what corners for these 12 terrain types are elevated.
// first field is nw corner
// 2nd field is sw corner
// 3rd field is se corner
// 4th field is ne corner
// if 1, is elevated
short hill_c_heights[12][4] = {{1,1,0,0},{0,1,0,0},{0,1,1,0},
{0,0,1,0},{0,0,1,1},{0,0,0,1},
{1,0,0,1},{1,0,0,0},{1,1,0,1},
{1,1,1,0},{0,1,1,1},{1,0,1,1}};
// external global variables
extern scenario_data_type scenario;
extern town_record_type town;
extern big_tr_type t_d;
big_tr_type clipboard;
RECT clipboardSize;
Boolean dataOnClipboard=false;
extern outdoor_record_type current_terrain;
extern scen_item_data_type scen_data;
// extern short borders[4][50];
// extern unsigned char border_floor[4][50];
// extern unsigned char border_height[4][50];
extern outdoor_record_type border_terrains[3][3];
extern short cur_town;
extern location cur_out;
extern short current_drawing_mode;
extern short town_type ;
extern short current_height_mode ;
extern Boolean editing_town;
extern short cur_viewing_mode;
extern short overall_mode;
extern short ulx,uly;
extern Boolean small_any_drawn;
extern Boolean file_is_loaded;
extern Boolean mouse_button_held;
extern short cen_x, cen_y;
extern short mode_count;
extern short current_height_mode;
extern Boolean change_made_town;
extern Boolean change_made_outdoors;
extern HWND mainPtr;
extern short selected_item_number;
extern item_type copied_item;
extern creature_start_type copied_creature;
extern short max_dim[4];
extern HWND right_sbar;
extern in_town_on_ter_script_type copied_ter_script;
extern Boolean kill_next_win_char;
extern short current_cursor;
// local variables
short current_terrain_type = 0;
location last_spot_hit = kINVAL_LOC;
macRECT working_rect;
Boolean erasing_mode;
struct corner_and_sight_on_space {
unsigned nw_corner : 2;
unsigned sw_corner : 2;
unsigned se_corner : 2;
unsigned ne_corner : 2;
unsigned see_in : 1;
unsigned see_to : 1;
} corner_and_sight_map[88][88];
typedef struct corner_and_sight_on_space *temp_space_info_ptr;
short recursive_depth = 0; // used for recursive hill/terrain correcting function
short recursive_hill_up_depth = 0;
short recursive_hill_down_depth = 0;
linkedList undo;
linkedList redo;
short last_selected_item_number;
short store_control_value = 0;
short sign_terrain;
location selected_square;
// function prototype
int check_scroller( POINT the_point );
int check_scroller_2D( POINT the_point );
int check_scroller_3D( POINT the_point );
bool process_scroll_click( int map_size, POINT thePoint );
bool handle_scroll( int map_size, int scrl, bool ctrl_key, bool shft_key );
Boolean clean_up_from_scrolling( int map_size, int dx, int dy );
void handle_ter_spot_press(location spot_hit,Boolean option_hit,Boolean right_click);
// void play_press_snd();
void set_new_terrain(short selected_terrain);
void set_new_floor(short selected_terrain);
// Boolean is_hill(short i,short j);
Boolean is_rocks(short i,short j);
Boolean is_water(short i,short j);
void shy_change_circle_terrain(location center,short radius,short terrain_type,short probability);
void change_circle_terrain(location center,short radius,short terrain_type,short probability);
void change_rect_terrain(macRECT r,short terrain_type,short probability,Boolean hollow);
void copy_rect_terrain(macRECT r);
void paste_terrain(location l,Boolean shft_key,Boolean alt_key,Boolean ctrl_key);
Boolean town_fix_grass_rocks(location l);
Boolean out_fix_grass_rocks(location l);
Boolean town_fix_rocks_water(location l);
Boolean out_fix_rocks_water(location l);
Boolean town_fix_hills(location l);
Boolean out_fix_hills(location l);
// short get_corner_height(short x, short y,short out_or_town,short which_corner) ;
short adjust_get_ter(short x, short y,short out_or_town);
void adjust_space(location l);
// short coord_to_ter(short x,short y);
void change_height(location l,short lower_or_raise);
void adjust_space_height(location l,short lower_or_raise);
void adjust_space_height_lower(location l);
void adjust_space_height_raise(location l);
short locs_to_dir(location l1,location l2);
void paste_selected_instance(location create_loc);
void check_selected_item_number();
void shift_selected_instance(short dx,short dy);
void create_navpoint(location spot_hit);
void delete_navpoint(location spot_hit);
void create_new_creature(short c_to_create,location create_loc,creature_start_type *c_to_make);
void shift_item_locs(location spot_hit);
void create_town_entry(macRECT rect_hit);
void edit_town_entry(location spot_hit);
void set_rect_height(macRECT r);
void add_rect_height(macRECT r);
void shy_put_terrain(short i,short j,short ter);
void transform_walls(macRECT working_rect);
Boolean is_not_darkness_floor(short i,short j);
void place_bounding_walls(macRECT working_rect);
Boolean is_wall(short x, short y);
Boolean is_dumb_terrain(short ter);
short get_height(short x, short y,short out_or_town);
Boolean old_can_see_in(location p1,location p2, /* short check_light,*/ short check_travel);
void old_can_see(location p1,location p2,/* short check_light,*/ short check_travel,Boolean *see_to,Boolean *see_in);
// Boolean can_see_to(location p1,location p2,short check_light,short check_travel);
Boolean can_see_in(location p1,location p2,short check_light,short check_travel);
void can_see(location p1,location p2,short check_light,short check_travel,Boolean *see_to,Boolean *see_in);
Boolean can_see_single(location p1,location p2,short check_light,short check_travel,Boolean *see_to);
Boolean no_block(location l, short direction,short check_light,short check_travel);
Boolean look_block(location l, short direction);
Boolean move_block(location l, short direction);
void set_drawing_mode(short new_mode);
void recursive_clean_terrain(location l);
void recursive_adjust_space_height_raise(location l);
void recursive_adjust_space_height_lower(location l);
Boolean control_key_down();
void set_see_in(short sector_offset_x, short sector_offset_y, short x, short y, Boolean value);
void set_see_to(short sector_offset_x, short sector_offset_y, short x, short y, Boolean value);
void set_nw_corner(short sector_offset_x, short sector_offset_y, short x, short y, short value);
void set_sw_corner(short sector_offset_x, short sector_offset_y, short x, short y, short value);
void set_se_corner(short sector_offset_x, short sector_offset_y, short x, short y, short value);
void set_ne_corner(short sector_offset_x, short sector_offset_y, short x, short y, short value);
void find_out_about_corner_walls(outdoor_record_type *drawing_terrain, short x, short y, short current_size, short *nw_corner, short *ne_corner, short *se_corner, short *sw_corner);
void find_out_about_corner_walls_being_hidden(outdoor_record_type *drawing_terrain, short sector_offset_x, short sector_offset_y,short x, short y, /* short current_size,*/
Boolean see_in_neighbors[3][3],/* Boolean see_to_neighbors[3][3], Boolean see_to, */
short *nw_corner, short *ne_corner, short *se_corner, short *sw_corner);
Boolean is_wall_drawn(outdoor_record_type *drawing_terrain, short sector_offset_x, short sector_offset_y, short x, short y);
int flood_fill_floor(short new_floor, short old_floor, int x, int y);
int flood_fill_terrain(short new_terrain, short old_terrain, int x, int y);
location selected_instance_location();
void shift_square_contents(short dx,short dy);
void init_screen_locs()
{
int i;
for (i = 0; i < 14; i++)
SetRECT(left_text_lines[i],LEFT_TEXT_LINE_WIDTH * (i / 7) + LEFT_TEXT_LINE_ULX,
LEFT_TEXT_LINE_ULY + (i % 7) * TEXT_LINE_HEIGHT,
LEFT_TEXT_LINE_WIDTH * (i / 7) + LEFT_TEXT_LINE_ULX + LEFT_TEXT_LINE_WIDTH,
LEFT_TEXT_LINE_ULY + (i % 7) * TEXT_LINE_HEIGHT + TEXT_LINE_HEIGHT);
// right_text_lines rects are for INSIDE the buttons GWORLD, NOT the screen.
for (i = 0; i < 7; i++)
SetRECT(right_text_lines[i], RIGHT_TEXT_LINE_ULX,
RIGHT_TEXT_LINE_ULY + (i % 7) * TEXT_LINE_HEIGHT,
RIGHT_TEXT_LINE_ULX + 235,
RIGHT_TEXT_LINE_ULY + (i % 7) * TEXT_LINE_HEIGHT + TEXT_LINE_HEIGHT);
}
// "Outdoor: drawing mode failure after moving section" fix
// rewrite mouse click handling for the scroller buttons (bars)
// to an orthodox mouse tracker method
// In this method, the event loop is handled in process_scroll_click()
// and no other command dispatcher is concerned.
// Thus this structure constrains the mouse command only to the scroller
// and minimizes unexpected changes to the other part.
// detect on which scroll area mouse click drops
int check_scroller( POINT the_point )
{
if ((cur_viewing_mode == 0) || (cur_viewing_mode == 2))
return check_scroller_2D( the_point );
if (cur_viewing_mode == 10 || cur_viewing_mode == 11)
return check_scroller_3D( the_point );
return eSCRL_NoScrl;
}
// check four rectangle side bars
int check_scroller_2D( POINT the_point )
{
int scrl = eSCRL_NoScrl;
if ( POINTInRECT( the_point, border_rect[0] )) scrl |= eSCRL_Top;
if ( POINTInRECT( the_point, border_rect[1] )) scrl |= eSCRL_Left;
if ( POINTInRECT( the_point, border_rect[2] )) scrl |= eSCRL_Bottom;
if ( POINTInRECT( the_point, border_rect[3] )) scrl |= eSCRL_Right;
return scrl;
}
// check four triangle corners
int check_scroller_3D( POINT the_point )
{
int scrl = eSCRL_NoScrl;
if( POINTInRECT( the_point, kRect3DEditScrn )) {
if ( abs(the_point.y - kRect3DEditScrn.top) + abs(the_point.x - kRect3DEditScrn.left) < 32 )
scrl |= eSCRL_Left;
if ( abs(the_point.y - kRect3DEditScrn.top) + abs(the_point.x - (kRect3DEditScrn.right - 1)) < 32 )
scrl |= eSCRL_Top;
if ( abs(the_point.y - (kRect3DEditScrn.bottom - 1)) + abs(the_point.x - (kRect3DEditScrn.right - 1)) < 32 )
scrl |= eSCRL_Right;
if ( abs(the_point.y - (kRect3DEditScrn.bottom - 1)) + abs(the_point.x - kRect3DEditScrn.left) < 32 )
scrl |= eSCRL_Bottom;
}
return scrl;
}
// track mouse click until its button is released
bool process_scroll_click( int map_size, POINT thePoint )
{
int scrl;
bool alt_key;
bool ctrl_key;
bool shft_key;
POINT currPt;
if ( check_scroller( thePoint ) == eSCRL_NoScrl )
return false;
// Track mouse while it is down
DWORD nextTick;
DWORD prevTick = GetTickCount();
bool still_down = true;
while ( still_down ) {
// handle movement
if ( GetCursorPos( &currPt ) ) {
ScreenToClient( mainPtr, &currPt );
ctrl_key = (GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0; // check MSB for current key state
alt_key = (GetAsyncKeyState( VK_MENU ) & 0x8000) != 0;
shft_key = (GetAsyncKeyState(0xC0) & 0x8000) != 0;
if ( (scrl = check_scroller( currPt )) != eSCRL_NoScrl )
if ( handle_scroll( map_size, scrl, ctrl_key, shft_key ) )
return true;
}
MSG msg;
if ( PeekMessage(&msg, NULL, WM_MOUSEFIRST , WM_MOUSELAST, PM_REMOVE) != 0 ) {
switch (msg.message) {
// handle accept messages
case WM_LBUTTONUP:
still_down = false;
break;
// ignore these messages
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
break;
// just dispatch rest of the messages
default:
DispatchMessage(&msg);
break;
}
}
// limit too fast scroll
nextTick = prevTick + kScrollLimitTime;
// if ( nextTick < prevTick ) // take care of the wrap around case - 49 days
// while ( nextTick < GetTickCount() );
while ( nextTick > GetTickCount() );
prevTick = GetTickCount();
}
return true;
}
// execute scroll
bool handle_scroll( int map_size, int scrl, bool ctrl_key, bool shft_key )
{
int dx = 0; // displacement
int dy = 0;
if (hintbook_mode0 == 1) {
if (ctrl_key) {
if ( scrl & eSCRL_Top ) dy = -cen_y; // go to the limb
if ( scrl & eSCRL_Left ) dx = -cen_x;
if ( scrl & eSCRL_Bottom ) dy = map_size - 1 - cen_y;
if ( scrl & eSCRL_Right ) dx = map_size - 1 - cen_x;
}
else if (shft_key) {
if ( scrl & eSCRL_Top ) dy = -8;
if ( scrl & eSCRL_Left ) dx = -8;
if ( scrl & eSCRL_Bottom ) dy = 8;
if ( scrl & eSCRL_Right ) dx = 8;
}
else {
if ( scrl & eSCRL_Top ) dy = -1;
if ( scrl & eSCRL_Left ) dx = -1;
if ( scrl & eSCRL_Bottom ) dy = 1;
if ( scrl & eSCRL_Right ) dx = 1;
}
if(clean_up_from_scrolling( map_size, dx, dy ))
return true;
if ( scrl != eSCRL_NoScrl )
draw_main_screen();
return false;
}
else {
if (ctrl_key) {
if (cur_viewing_mode == 2) {
if ( scrl & eSCRL_Top ) dy = 16 - cen_y; // go to the limb
if ( scrl & eSCRL_Left ) dx = 16 - cen_x;
if ( scrl & eSCRL_Bottom ) dy = map_size - 16 - cen_y;
if ( scrl & eSCRL_Right ) dx = map_size - 16 - cen_x;
}
else {
if ( scrl & eSCRL_Top ) dy = -cen_y; // go to the limb
if ( scrl & eSCRL_Left ) dx = -cen_x;
if ( scrl & eSCRL_Bottom ) dy = map_size - 1 - cen_y;
if ( scrl & eSCRL_Right ) dx = map_size - 1 - cen_x;
}
}
else if (shft_key) {
if ((cur_viewing_mode == 2) && (cen_x <= 23)) {
if ( scrl & eSCRL_Left ) dx = 0;
}
else {
if ( scrl & eSCRL_Left ) dx = -8;
}
if ((cur_viewing_mode == 2) && (cen_y <= 23)) {
if ( scrl & eSCRL_Top ) dy = 0;
}
else {
if ( scrl & eSCRL_Top ) dy = -8;
}
if ((cur_viewing_mode == 2) && (cen_x >= map_size - 23)) {
if ( scrl & eSCRL_Right ) dx = 0;
}
else {
if ( scrl & eSCRL_Right ) dx = 8;
}
if ((cur_viewing_mode == 2) && (cen_y >= map_size - 23)) {
if ( scrl & eSCRL_Bottom ) dy = 0;
}
else {
if ( scrl & eSCRL_Bottom ) dy = 8;
}
}
else {
if ((cur_viewing_mode == 2) && (cen_x <= 16)) {
if ( scrl & eSCRL_Left ) dx = 0;
}
else {
if ( scrl & eSCRL_Left ) dx = -1;
}
if ((cur_viewing_mode == 2) && (cen_y <= 16)) {
if ( scrl & eSCRL_Top ) dy = 0;
}
else {
if ( scrl & eSCRL_Top ) dy = -1;
}
if ((cur_viewing_mode == 2) && (cen_x >= map_size - 16)) {
if ( scrl & eSCRL_Right ) dx = 0;
}
else {
if ( scrl & eSCRL_Right ) dx = 1;
}
if ((cur_viewing_mode == 2) && (cen_y >= map_size - 16)) {
if ( scrl & eSCRL_Bottom ) dy = 0;
}
else {
if ( scrl & eSCRL_Bottom ) dy = 1;
}
}
if(clean_up_from_scrolling( map_size, dx, dy ))
return true;
if ( scrl != eSCRL_NoScrl )
draw_main_screen();
return false;
}
}
// "Outdoor: drawing mode failure after moving section" fix
// returns TRUE when "save change" dialog is displayed
// if dialog is displayed, mouse tracking should be stopped
Boolean clean_up_from_scrolling( int map_size, int dx, int dy )
{
int sector_x_overflow = 0;
int sector_y_overflow = 0;
char sector_offset_x = 0;
char sector_offset_y = 0;
short cen_x_save = cen_x;
short cen_y_save = cen_y;
cen_x = cen_x + (short)dx;
cen_y = cen_y + (short)dy;
sector_x_overflow = cen_x % map_size;
if(cen_x < 0) {
sector_offset_x = -1;
sector_x_overflow += map_size;
}
else if(cen_x >= map_size) {
sector_offset_x = 1;
}
sector_y_overflow = cen_y % map_size;
if(cen_y < 0) {
sector_offset_y = -1;
sector_y_overflow += map_size;
}
else if(cen_y >= map_size) {
sector_offset_y = 1;
}
// limit center position
cen_x = minmax( 0, (short)map_size - 1, cen_x );
cen_y = minmax( 0, (short)map_size - 1, cen_y );
if( !editing_town && ((sector_offset_x != 0) || (sector_offset_y != 0)) ) {
// change outdoor sector
location sector_move_to = {cur_out.x + sector_offset_x,cur_out.y + sector_offset_y};
if((sector_move_to.x < 0) || (sector_move_to.y < 0)
|| (sector_move_to.x >= scenario.out_width)
|| (sector_move_to.y >= scenario.out_height))
return FALSE;
bool save_dlg_displayed = false;
if (change_made_outdoors == TRUE) {
save_dlg_displayed = true;
if ( save_check(990) == FALSE ) { // canceled
cen_x = cen_x_save; // recover center position
cen_y = cen_y_save;
return TRUE; // stop mouse tracking
}
}
clear_selected_copied_objects();
load_outdoor_and_borders( sector_move_to );
set_up_terrain_buttons();
cen_x = (short)sector_x_overflow;
cen_y = (short)sector_y_overflow;
// reset_drawing_mode();
check_selected_item_number(); // maybe need?
if (current_drawing_mode == 0)
set_new_floor(current_floor_drawn);
else
set_new_terrain(current_terrain_drawn);
small_any_drawn = TRUE;
// redraw by WM_PAINT on main WndProc, because dialog area is invalidated
// if ( change_made_outdoors == TRUE ) // if dialog is displayed
// redraw_screen(); // redraw full screen
// else // else
// draw_main_screen(); // only edit screen and terrain palette
change_made_outdoors = FALSE;
return save_dlg_displayed;
}
return FALSE;
}
// "Outdoor: drawing mode failure after moving section" fix
// mouse click to the scroller is handled on separate routines.
Boolean handle_action(POINT the_point, WPARAM wparam, LPARAM lparam )
{
short i,j;
Boolean are_done = FALSE;
char str_response[256] = "";
Boolean need_redraw = FALSE, option_hit = FALSE, right_click = FALSE;
location spot_hit;
POINT cur_point,cur_point2;
short old_mode,choice;
if (file_is_loaded == FALSE)
return are_done;
Boolean ctrl_key = FALSE;
Boolean shift_key = FALSE;
if (MK_CONTROL & wparam)
option_hit = ctrl_key = TRUE;
if (MK_SHIFT & wparam)
shift_key = TRUE;
if (lparam == -2)
option_hit = TRUE;
if (lparam != -1)
the_point.x -= ulx; the_point.y -= uly;
right_click = (GetKeyState( VK_RBUTTON ) & 0x8000) != 0;
int map_size = (editing_town) ? max_dim[town_type] : 48;
cur_point = the_point;
// scroller on edit screen
if ( process_scroll_click( map_size, the_point ) ){
mouse_button_held = FALSE;
return are_done;
}
// clicking in terrain spots, big icon mode
if (cur_viewing_mode == 0) {
cur_point2 = cur_point;
cur_point2.x -= TER_RECT_UL_X; cur_point2.y -= TER_RECT_UL_Y;
for (i = 0; i < 9; i++)
for (j = 0; j < 9; j++)
if (POINTInRECT(cur_point2,large_edit_ter_rects[i][j])) {
spot_hit.x = (t_coord)(cen_x + i - 4);
spot_hit.y = (t_coord)(cen_y + j - 4);
if ((mouse_button_held == TRUE) && (spot_hit.x == last_spot_hit.x) &&
(spot_hit.y == last_spot_hit.y))
return are_done;
else last_spot_hit = spot_hit;
if (mouse_button_held == FALSE)
last_spot_hit = spot_hit;
old_mode = overall_mode;
if(editing_town)
change_made_town = TRUE;
else
change_made_outdoors = TRUE;
handle_ter_spot_press(spot_hit,option_hit,right_click);
need_redraw = TRUE;
}
}
// clicking in terrain spots, small icon mode
if (cur_viewing_mode == 1) {
cur_point2 = cur_point;
cur_point2.x -= TER_RECT_UL_X; cur_point2.y -= TER_RECT_UL_Y;
for (i = 0; i < MAX_TOWN_SIZE; i++)
for (j = 0; j < MAX_TOWN_SIZE; j++)
if (POINTInRECT(cur_point2,small_edit_ter_rects[i][j])) {
spot_hit.x = (t_coord)i;
spot_hit.y = (t_coord)j;
if ((mouse_button_held == TRUE) && (spot_hit.x == last_spot_hit.x) &&
(spot_hit.y == last_spot_hit.y))
return are_done;
else last_spot_hit = spot_hit;
if (mouse_button_held == FALSE)
last_spot_hit = spot_hit;
old_mode = overall_mode;
if(editing_town)
change_made_town = TRUE;
else
change_made_outdoors = TRUE;
handle_ter_spot_press(spot_hit,option_hit,right_click);
need_redraw = TRUE;
}
}
// clicking in terrain spots, medium icon mode
if (cur_viewing_mode == 2) {
cur_point2 = cur_point;
cur_point2.x -= TER_RECT_UL_X; cur_point2.y -= TER_RECT_UL_Y;
for (i = 0; i < 32; i++)
for (j = 0; j < 32; j++)
if (POINTInRECT(cur_point2,medium_edit_ter_rects[i][j])) {
spot_hit.x = (t_coord)(cen_x + i - 16);
spot_hit.y = (t_coord)(cen_y + j - 16);
if ((mouse_button_held == TRUE) && (spot_hit.x == last_spot_hit.x) &&
(spot_hit.y == last_spot_hit.y))
return are_done;
else last_spot_hit = spot_hit;
if (mouse_button_held == FALSE)
last_spot_hit = spot_hit;
old_mode = overall_mode;
if(editing_town)
change_made_town = TRUE;
else
change_made_outdoors = TRUE;
handle_ter_spot_press(spot_hit,option_hit,right_click);
need_redraw = TRUE;
}
}
// clicking in terrain spots, big 3D icon mode
else if (cur_viewing_mode == 10 || cur_viewing_mode == 11) {
if( POINTInRECT(cur_point, kRect3DEditScrn)) {
//detect click on terrain spot (possibilities: that <-, hit a cliff, or hit outside the map. last two do nothing)
cur_point2 = cur_point;
cur_point2.x -= TER_RECT_UL_X; cur_point2.y -= TER_RECT_UL_Y;
short done = FALSE;
short x = 0, y = 0;
long mid_tenth_x, mid_tenth_y, result, x_off_from_center, y_off_from_center;
short height_to_draw;
graphic_id_type a;
short current_size = ((editing_town) ? max_dim[town_type] : 48);
short center_area_x, center_area_y;
short center_of_current_square_x, center_of_current_square_y;
short center_height;
short rel_x, rel_y;
RECT whole_area_rect = terrain_viewport_3d;
/*= {large_edit_ter_rects[0][0].left,large_edit_ter_rects[0][0].top,
large_edit_ter_rects[8][8].right,large_edit_ter_rects[8][8].bottom};*/
//MacInsetRect(&whole_area_rect,-15,-15);
ZeroRectCorner(&whole_area_rect);
center_area_x = (short)(whole_area_rect.right / 2);
center_area_y = (short)(whole_area_rect.bottom / 2);
center_height = (editing_town) ? t_d.height[cen_x][cen_y] : current_terrain.height[cen_x][cen_y];
for(x = current_size - 1; x >= 0; x--) {
for(y = current_size - 1; y >= 0; y--) {
height_to_draw = (editing_town) ? t_d.height[x][y] : current_terrain.height[x][y];
rel_x = x - cen_x;
rel_y = y - cen_y;
center_of_current_square_x = (rel_x - rel_y) * SPACE_X_DISPLACEMENT_3D + center_area_x;
center_of_current_square_y = (rel_x + rel_y) * SPACE_Y_DISPLACEMENT_3D + center_area_y
- (height_to_draw - center_height) * ELEVATION_Y_DISPLACEMENT_3D;
//convert the center
center_of_current_square_y += 11 + 2;//I thought 11 was the right amount...
//ugly click detection
mid_tenth_x = center_of_current_square_x * 10 + 5;
mid_tenth_y = center_of_current_square_y * 10 + 5;
result = abs(mid_tenth_x - cur_point2.x * 10L) * SPACE_Y_DISPLACEMENT_3D +
abs(mid_tenth_y - cur_point2.y * 10L) * SPACE_X_DISPLACEMENT_3D;
//this is distance for 2D - in case anyone wants to implement BetterEditor's "wall drawing" in 3D
//divide this number by a lot if you want
//( / about 200 if you want to get back to anything near pixel size, I think)
//A warning, however: I haven't tested this code. If you try something and it goes wrong, consider this.
x_off_from_center = (mid_tenth_x - cur_point2.x * 10L) * SPACE_Y_DISPLACEMENT_3D +
(mid_tenth_y - cur_point2.y * 10L) * SPACE_X_DISPLACEMENT_3D;
y_off_from_center = -(mid_tenth_x - cur_point2.x * 10L) * SPACE_Y_DISPLACEMENT_3D +
(mid_tenth_y - cur_point2.y * 10L) * SPACE_X_DISPLACEMENT_3D;
if(result >= 0 && result <= SPACE_X_DISPLACEMENT_3D * SPACE_Y_DISPLACEMENT_3D * 10) {
done = TRUE;
/*Str255 draw_str;
Rect the_rect = {200,200,400,400};
sprintf((char *) draw_str,"%d,%d,%d,%d,%d,%d,%d",(long)cur_point2.h,(long)cur_point2.v,
(long)center_of_current_square_x,(long)center_of_current_square_y,(long)mid_tenth_x,
(long)mid_tenth_y,(long)result);
char_win_draw_string(GetWindowPort(mainPtr),the_rect,(char *) draw_str,2,12);*/
break;
}
//cliff checking (anything within the square's width and below its center)
if(cur_point2.y > center_of_current_square_y &&
cur_point2.x > center_of_current_square_x - SPACE_X_DISPLACEMENT_3D + 1 &&
cur_point2.x < center_of_current_square_x + SPACE_X_DISPLACEMENT_3D) {
done = 2;
/*Str255 draw_str;
Rect the_rect = {200,200,400,400};
sprintf((char *) draw_str,"%d,%d,%d,%d,%d,%d,%d",(long)cur_point2.h,(long)cur_point2.v,
(long)center_of_current_square_x,(long)center_of_current_square_y,(long)mid_tenth_x,
(long)mid_tenth_y,(long)result);
char_win_draw_string(GetWindowPort(mainPtr),the_rect,(char *) draw_str,2,12);*/
beep();//this might actually be a good idea permanently
break;
}
/*if(q + 1 == current_num_diagonals && r + 1 == current_diagonal_length){
Str255 draw_str;
Rect the_rect = {200,200,400,400};
sprintf((char *) draw_str,"%d,%d,%d,%d,%d,%d,%d",(long)cur_point2.h,(long)cur_point2.v,
(long)center_of_current_square_x,(long)center_of_current_square_y,(long)mid_tenth_x,
(long)mid_tenth_y,(long)result);
char_win_draw_string(GetWindowPort(mainPtr),the_rect,(char *) draw_str,2,12);
}*/
}
if(done != FALSE)
break;
}
if(done == TRUE) {
spot_hit.x = (char)x;
spot_hit.y = (char)y;
if ((mouse_button_held == TRUE) && (spot_hit.x == last_spot_hit.x) && (spot_hit.y == last_spot_hit.y))
return are_done;
else
last_spot_hit = spot_hit;
old_mode = overall_mode;
if(editing_town)
change_made_town = TRUE;
else
change_made_outdoors = TRUE;
//erasing_mode = TRUE;
//mouse_button_held = TRUE;
handle_ter_spot_press(spot_hit,option_hit,right_click);
need_redraw = TRUE;
}
else if(done == FALSE) {
beep();
}
}
}
// q_3DModEnd
// TERRAIN BUTTONS TO RIGHT
if (mouse_button_held == FALSE) {
cur_point = the_point;
cur_point.x -= RIGHT_BUTTONS_X_SHIFT;
if (current_drawing_mode == 0) { // floor mode
for (i = 0; i < 256; i++)
// q_3DModStart
// if (point_in_rect(cur_point,&terrain_rects[i])) {
if (POINTInRECT(cur_point,((cur_viewing_mode >= 10 && current_drawing_mode > 0) ? terrain_rects_3D[i] : terrain_rects[i]))) {
reset_drawing_mode();
set_new_floor(i);
}
// q_3DModEnd
}
else { // terrain/height mode
short sbar_pos = GetControlValue(right_sbar);
for (i = 0; i < 330; i++)
if (sbar_pos * 15 + i < 512) {
// q_3DModStart
// if (point_in_rect(cur_point,&terrain_rects[i])) {
if (POINTInRECT(cur_point,((cur_viewing_mode >= 10 && current_drawing_mode > 0) ? terrain_rects_3D[i] : terrain_rects[i]))) {
if (current_drawing_mode != 1)
set_drawing_mode(1);
reset_drawing_mode();
set_new_terrain(sbar_pos * 15 + i);
}
}
// q_3DModEnd
}
//place_right_buttons(0);
}
// PRESSING MAIN BUTTONS
for (i = 0; i < 9; i++)
for (j = 0; j < ((editing_town) ? 6 : 4); j++) {
cur_point2 = the_point;
cur_point2.x -= RIGHT_BUTTONS_X_SHIFT;
if ((mouse_button_held == FALSE) && (POINTInRECT(cur_point2,palette_buttons[i][j]))) {
play_sound(34);
switch (i + 100 * j) {
case 0: // Pencil
//pre-emptive support for creature and item placement modes
if(current_drawing_mode==3){
overall_mode = 46;
object_sticky_draw = shift_key;
}
else if(current_drawing_mode==4){
overall_mode = 47;
object_sticky_draw = shift_key;
}
else
reset_drawing_mode();
break;
case 1: // Paintbrush (Large)
set_string("Paintbrush (large)","");
overall_mode = 1;
set_cursor(2);
break;
case 2: // Paintbrush (Small)
set_string("Paintbrush (small)","");
overall_mode = 2;
set_cursor(2);
break;
case 3: // Spraycan (Large)
set_string("Spraycan (large)","");
overall_mode = 3;
set_cursor(3);
break;
case 4: // Spraycan (Small)
set_string("Spraycan (small)","");
overall_mode = 4;
set_cursor(3);
break;
case 5: // Change Height
set_string("Set Height","Select rectangle to set");
mode_count = 2;
set_cursor(5);
overall_mode = (shift_key?24:20); //if shift is on, add height
need_redraw = TRUE;
break;
case 6: // Paint Rectangle (Hollow)
case 7: // Paint Rectangle (Full)
overall_mode = (i == 6) ? 11 : 10;
mode_count = 2;
set_cursor(5);
if (i == 6)
set_string("Fill rectangle (hollow)","Select upper left corner");
else set_string("Fill rectangle (solid)","Select upper left corner");
break;
case 8: // Eyedropper
set_cursor(1);
set_string("Click on terrain/floor to select it."," ");
overall_mode = 6;
break;
case 100: // Zoom In/Zoom Out
// q_3DModStart
if ((cur_viewing_mode == 1) || (cur_viewing_mode == 2))
cur_viewing_mode = 0;
else if(cur_viewing_mode == 0)
cur_viewing_mode = 1;
else if(cur_viewing_mode == 10) {
cur_viewing_mode = 11;
set_up_lights();
}
else if(cur_viewing_mode == 11)
cur_viewing_mode = 10;
set_up_terrain_buttons();
// q_3DModEnd
reset_small_drawn();
redraw_screen();
break;
// q_3DModStart
case 101: // 2D/3D
if(cur_viewing_mode >= 10) {
cur_viewing_mode = 0;
if(current_cursor == 8)
set_cursor(5);
if(current_cursor == 9)
set_cursor(6);
// do proper modifications of scroll bar
if (current_drawing_mode != 0) {
//SetControlMinimum(right_sbar,0);
// SetControlMaximum(right_sbar,22);
SetScrollRange(right_sbar,SB_CTL,0,22,TRUE);
//SetControlValue(right_sbar,store_control_value);
}
}
else {
cur_viewing_mode = 10;
if(current_cursor == 5)
set_cursor(8);
if(current_cursor == 6)
set_cursor(9);
// do proper modifications of scroll bar
if (current_drawing_mode != 0) {
//SetControlMinimum(right_sbar,0);
// SetControlMaximum(right_sbar,25);
SetScrollRange(right_sbar,SB_CTL,0,25,TRUE);
//SetControlValue(right_sbar,store_control_value);
}
}
set_up_terrain_buttons();
reset_small_drawn();