This repository has been archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathDISPLAY.CPP
3753 lines (3331 loc) · 161 KB
/
DISPLAY.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
/*
** Command & Conquer(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* $Header: F:\projects\c&c\vcs\code\display.cpv 2.16 16 Oct 1995 16:48:24 JOE_BOSTIC $ */
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : Command & Conquer *
* *
* File Name : DISPLAY.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : September 10, 1993 *
* *
* Last Update : August 24, 1995 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* DisplayClass::AI -- Handles the maintenance tasks for the map display. *
* DisplayClass::Calculated_Cell -- Fetch a map cell based on specified method. *
* DisplayClass::Cell_Object -- Determines what has been clicked on. *
* DisplayClass::Cell_Shadow -- Determine what shadow icon to use for the cell. *
* DisplayClass::Click_Cell_Calc -- Determines cell from screen X & Y. *
* DisplayClass::Coord_To_Pixel -- Determines X and Y pixel coordinates. *
* DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
* DisplayClass::DisplayClass -- Default constructor for display class. *
* DisplayClass::Draw_It -- Draws the tactical map. *
* DisplayClass::Flag_To_Redraw -- Flags the display so that it will be redrawn as soon as poss*
* DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
* DisplayClass::Init_Clear -- Clears the display to a known state. *
* DisplayClass::Init_IO -- Creates the map's button list *
* DisplayClass::Init_Theater -- Theater-specific initialization *
* DisplayClass::Map_Cell -- Mark specified cell as having been mapped. *
* DisplayClass::Mouse_Left_Held -- Handles the left button held down. *
* DisplayClass::Mouse_Left_Press -- Handles the left mouse button press. *
* DisplayClass::Mouse_Left_Release -- Handles the left mouse button release. *
* DisplayClass::Mouse_Left_Up -- Handles the left mouse "cruising" over the map. *
* DisplayClass::Mouse_Right_Press -- Handles the right mouse button press. *
* DisplayClass::Next_Object -- Searches for next object on display. *
* DisplayClass::One_Time -- Performs any special one time initializations. *
* DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
* DisplayClass::Pixel_To_Coord -- converts screen coord to COORDINATE *
* DisplayClass::Read_INI -- Reads map control data from INI file. *
* DisplayClass::Redraw_Icons -- Draws all terrain icons necessary. *
* DisplayClass::Redraw_Shadow -- Draw the shadow overlay. *
* DisplayClass::Refresh_Band -- Causes all cells under the rubber band to be redrawn. *
* DisplayClass::Refresh_Cells -- Redraws all cells in list. *
* DisplayClass::Remove -- Removes a game object from the rendering system. *
* DisplayClass::Repair_Mode_Control -- Controls the repair mode. *
* DisplayClass::Scroll_Map -- Scroll the tactical map in desired direction. *
* DisplayClass::Select_These -- All selectable objects in region are selected. *
* DisplayClass::Sell_Mode_Control -- Controls the sell mode. *
* DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
* DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
* DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
* DisplayClass::Submit -- Adds a game object to the map rendering system. *
* DisplayClass::TacticalClass::Action -- Processes input for the tactical map. *
* DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
* DisplayClass::Write_INI -- Writes map data into INI file. *
* DisplayClass::Set_Tactical_Position -- Sets the tactical view position. *
* DisplayClass::Center_Map -- Centers the map about the currently selected objects *
* DisplayClass::Prev_Object -- Searches for the previous object on the map. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/*
** These layer control elements are used to group the displayable objects
** so that proper overlap can be obtained.
*/
LayerClass DisplayClass::Layer[LAYER_COUNT];
/*
** Fading tables
*/
unsigned char DisplayClass::FadingBrighten[256];
unsigned char DisplayClass::FadingShade[256];
unsigned char DisplayClass::FadingLight[256];
unsigned char DisplayClass::RemapTables[HOUSE_COUNT][3][256];
unsigned char DisplayClass::FadingGreen[256];
unsigned char DisplayClass::FadingYellow[256];
unsigned char DisplayClass::FadingRed[256];
unsigned char DisplayClass::TranslucentTable[(MAGIC_COL_COUNT+1)*256];
unsigned char DisplayClass::WhiteTranslucentTable[(1+1)*256];
unsigned char DisplayClass::MouseTranslucentTable[(4+1)*256];
void const * DisplayClass::TransIconset;
unsigned char DisplayClass::UnitShadow[(USHADOW_COL_COUNT+1)*256];
unsigned char DisplayClass::SpecialGhost[2*256];
void const * DisplayClass::ShadowShapes;
unsigned char DisplayClass::ShadowTrans[(SHADOW_COL_COUNT+1)*256];
/*
** Bit array of cell redraw flags
*/
BooleanVectorClass DisplayClass::CellRedraw;
/*
** The main button that intercepts user input to the map
*/
DisplayClass::TacticalClass DisplayClass::TacButton;
/*
** Define "_RETRIEVE" if the palette morphing tables are part of the loaded data. If this
** is undefined, then the files will be created.
*/
#define _RETRIEVE
static int const TEX_X = 0;
static int const TEX_Y = 6;
static int const TEX_W = 14;
extern MixFileClass *TheaterIcons;
/***********************************************************************************************
* DisplayClass::DisplayClass -- Default constructor for display class. *
* *
* This constructor for the display class just initializes some of the display settings. *
* Most settings are initialized with the correct values at the time that the Init function *
* is called. There are some cases where default values are wise and this routine fills *
* those particular ones in. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/06/1994 JLB : Created. *
*=============================================================================================*/
DisplayClass::DisplayClass(void)
{
TacticalCoord = 0;
ShadowShapes = 0;
TransIconset = 0;
ZoneCell = 0;
ZoneOffset = 0;
CursorSize = 0;
ProximityCheck = false;
PendingObjectPtr = 0;
PendingObject = 0;
PendingHouse = HOUSE_NONE;
IsRepairMode = false;
IsTargettingMode = false;
IsToRedraw = true;
IsRubberBand = false;
IsTentative = false;
IsSellMode = false;
}
/***********************************************************************************************
* DisplayClass::One_Time -- Performs any special one time initializations. *
* *
* This routine is called from the game initialization process. It is to perform any one *
* time initializations necessary for the map display system. It allocates the staging *
* buffer needed for the radar map. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: This routine must be called ONCE and only once. *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
* 05/31/1994 JLB : Handles layer system now. *
* 06/02/1994 JLB : Takes care of misc display tables and data allocation. *
*=============================================================================================*/
void DisplayClass::One_Time(void)
{
Set_View_Dimensions(0, Map.Get_Tab_Height());
MapClass::One_Time();
/*
** Init the CellRedraw bit array. Do not do this in the constructor, since the
** BooleanVector may not have been constructed yet.
*/
CellRedraw.Resize(MAP_CELL_TOTAL);
for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
Layer[layer].One_Time();
}
/*
** Load the generic transparent icon set.
*/
TransIconset = MixFileClass::Retrieve("TRANS.ICN");
ShadowShapes = MixFileClass::Retrieve("SHADOW.SHP");
Set_View_Dimensions(0, Map.Get_Tab_Height());
/*
** Allocate and initialize the remap tables needed for each "house".
*/
HousesType hindex;
int fade;
for (fade = 0; fade < 3; fade++) {
for (hindex = HOUSE_FIRST; hindex < HOUSE_COUNT; hindex++) {
int color;
switch (fade) {
case 0:
for (color = 0; color < 256; color++) {
RemapTables[hindex][fade][color] = color;
}
break;
case 1:
Mem_Copy(FadingLight, RemapTables[hindex][fade], 256);
break;
case 2:
Mem_Copy(FadingShade, RemapTables[hindex][fade], 256);
break;
}
Mem_Copy(&RemapTables[hindex][fade][((int)hindex+11)*16], &RemapTables[hindex][fade][(0+11)*16], 16);
}
}
}
/***********************************************************************************************
* DisplayClass::Init_Clear -- clears the display to a known state *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 03/17/1995 BRR : Created. *
*=============================================================================================*/
void DisplayClass::Init_Clear(void)
{
MapClass::Init_Clear();
/*
** Clear any object being placed
*/
PendingObjectPtr = 0;
PendingObject = 0;
PendingHouse = HOUSE_NONE;
CursorSize = 0;
IsTargettingMode = false;
IsRepairMode = false;
IsRubberBand = false;
IsTentative = false;
IsSellMode = false;
/*
** Empty all the display's layers
*/
for (LayerType layer = LAYER_FIRST; layer < LAYER_COUNT; layer++) {
Layer[layer].Init();
}
}
/***********************************************************************************************
* DisplayClass::Init_IO -- clears & re-builds the map's button list *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 03/17/1995 BRR : Created. *
*=============================================================================================*/
void DisplayClass::Init_IO(void)
{
MapClass::Init_IO();
/*
** Re-attach our buttons to the main map button list, only in non-edit mode.
*/
if (!Debug_Map) {
TacButton.Zap();
Add_A_Button(TacButton);
}
}
/***********************************************************************************************
* DisplayClass::Init_Theater -- Performs theater-specific initialization (mixfiles, etc) *
* *
* INPUT: *
* theater new theater *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 03/17/1995 BRR : Created. *
*=============================================================================================*/
void DisplayClass::Init_Theater(TheaterType theater)
{
char fullname[16];
char iconname[16];
#ifndef _RETRIEVE
static TLucentType const MouseCols[4] = {
{BLACK, BLACK, 110, 0},
{WHITE, WHITE, 110, 0},
{LTGREY, LTGREY, 110, 0},
{DKGREY, DKGREY, 110, 0}
};
static TLucentType const MagicCols[MAGIC_COL_COUNT] = {
{32,32,110,0},
{33,33,110,0},
{34,34,110,0},
{35,35,110,0},
{36,36,110,0},
{37,37,110,0},
{38,38,110,0},
{39,39,110,0},
{BLACK, BLACK, 200, 0},
{WHITE, BLACK, 40, 0},
{LTGREY, BLACK, 80, 0},
{DKGREY, BLACK, 140, 0}
};
static TLucentType const WhiteCols[1] = {
{1, WHITE, 80, 0}
};
static TLucentType const ShadowCols[SHADOW_COL_COUNT] = {
{WHITE+1, BLACK,130,0},
{WHITE, BLACK,170,0},
{LTGRAY, BLACK,250,0},
{DKGRAY, BLACK,250,0}
};
static TLucentType const UShadowCols[USHADOW_COL_COUNT] = {
{LTGREEN, BLACK,130,0}
};
#endif
/*
---------------------- Invoke parent's init routine ----------------------
*/
MapClass::Init_Theater(theater);
/*
** Save the new theater value
*/
Theater = theater;
#ifndef DEMO
/*
** Unload old mixfiles, and cache the new ones
*/
sprintf(fullname, "%s.MIX", Theaters[Theater].Root);
if (Theater != LastTheater){
if (TheaterData) {
delete TheaterData;
}
TheaterData = new MixFileClass(fullname);
TheaterData->Cache();
}
#endif
/*
** Register the hi-res icons mix file now since it is theater specific
*/
sprintf(fullname, "%s.MIX", Theaters[Theater].Root);
strcpy (iconname, fullname);
strcpy (&iconname[4], "ICNH.MIX");
if (Theater != LastTheater){
if (TheaterIcons) {
delete TheaterIcons;
}
TheaterIcons = new MixFileClass(iconname);
TheaterIcons->Cache();
}
/*
** Load the custom palette associated with this theater.
** The fading palettes will have to be generated as well.
*/
sprintf(fullname, "%s.PAL", Theaters[theater].Root);
void const * ptr = MixFileClass::Retrieve(fullname);
Mem_Copy((void *)ptr, GamePalette, 768);
Mem_Copy(GamePalette, OriginalPalette, 768);
#ifndef _RETRIEVE
/*
** Make sure that remapping doesn't occur on the colors that cycle.
*/
memset(&GamePalette[CYCLE_COLOR_START*3], 0x3F, CYCLE_COLOR_COUNT*3);
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("GREEN", theater)).Read(FadingGreen, sizeof(FadingGreen));
#else
Build_Fading_Table(GamePalette, FadingGreen, GREEN, 110);
CCFileClass(Fading_Table_Name("GREEN", theater)).Write(FadingGreen, sizeof(FadingGreen));
#endif
if (theater == THEATER_DESERT) {
FadingGreen[196] = 160;
}
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("YELLOW", theater)).Read(FadingYellow, sizeof(FadingYellow));
#else
Build_Fading_Table(GamePalette, FadingYellow, YELLOW, 140);
CCFileClass(Fading_Table_Name("YELLOW", theater)).Write(FadingYellow, sizeof(FadingYellow));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("RED", theater)).Read(FadingRed, sizeof(FadingRed));
#else
Build_Fading_Table(GamePalette, FadingRed, RED, 140);
CCFileClass(Fading_Table_Name("RED", theater)).Write(FadingRed, sizeof(FadingRed));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("MOUSE", theater)).Read(MouseTranslucentTable, sizeof(MouseTranslucentTable));
#else
Build_Translucent_Table(GamePalette, &MouseCols[0], 4, MouseTranslucentTable);
CCFileClass(Fading_Table_Name("MOUSE", theater)).Write(MouseTranslucentTable, sizeof(MouseTranslucentTable));
#endif
// MouseDrawPtr = MouseTranslucentTable;
// MouseDrawPtr2 = Add_Long_To_Pointer(MouseTranslucentTable, 256L);
// MouseDrawVal = 1;
// MouseDrawFlags = (int)SHAPE_GHOST;
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("TRANS", theater)).Read(TranslucentTable, sizeof(TranslucentTable));
#else
Build_Translucent_Table(GamePalette, &MagicCols[0], MAGIC_COL_COUNT, TranslucentTable);
CCFileClass(Fading_Table_Name("TRANS", theater)).Write(TranslucentTable, sizeof(TranslucentTable));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("WHITE", theater)).Read(WhiteTranslucentTable, sizeof(WhiteTranslucentTable));
#else
Build_Translucent_Table(GamePalette, &WhiteCols[0], 1, WhiteTranslucentTable);
CCFileClass(Fading_Table_Name("WHITE", theater)).Write(WhiteTranslucentTable, sizeof(WhiteTranslucentTable));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("SHADOW", theater)).Read(ShadowTrans, sizeof(ShadowTrans));
#else
Build_Translucent_Table(GamePalette, &ShadowCols[0], SHADOW_COL_COUNT, ShadowTrans);
CCFileClass(Fading_Table_Name("SHADOW", theater)).Write(ShadowTrans, sizeof(ShadowTrans));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("UNITS", theater)).Read(UnitShadow, sizeof(UnitShadow));
#else
Conquer_Build_Translucent_Table(GamePalette, &UShadowCols[0], USHADOW_COL_COUNT, UnitShadow);
CCFileClass(Fading_Table_Name("UNITS", theater)).Write(UnitShadow, sizeof(UnitShadow));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("SHADE", theater)).Read(FadingShade, sizeof(FadingShade));
#else
Conquer_Build_Fading_Table(GamePalette, FadingShade, BLACK, 150);
CCFileClass(Fading_Table_Name("SHADE", theater)).Write(FadingShade, sizeof(FadingShade));
#endif
#ifdef _RETRIEVE
CCFileClass(Fading_Table_Name("LIGHT", theater)).Read(FadingLight, sizeof(FadingLight));
#else
Conquer_Build_Fading_Table(GamePalette, FadingLight, WHITE, 85);
CCFileClass(Fading_Table_Name("LIGHT", theater)).Write(FadingLight, sizeof(FadingLight));
#endif
/*
** Create the shadow color used by aircraft.
*/
Conquer_Build_Fading_Table(GamePalette, &SpecialGhost[256], BLACK, 100);
for (int index = 0; index < 256; index++) {
SpecialGhost[index] = 0;
}
Build_Fading_Table(GamePalette, FadingBrighten, WHITE, 25);
#ifndef _RETRIEVE
/*
** Restore the palette since it was mangled while building the fading tables.
*/
sprintf(fullname, "%s.PAL", Theaters[theater].Root);
ptr = MixFileClass::Retrieve(fullname);
Mem_Copy((void *)ptr, GamePalette, 768);
Mem_Copy(GamePalette, OriginalPalette, 768);
#endif
/*
** Adjust the palette according to the visual control option settings.
*/
Options.Fixup_Palette();
}
/***********************************************************************************************
* DisplayClass::Text_Overlap_List -- Creates cell overlap list for specified text string. *
* *
* This routine is used to create an overlap list that specifies all the cells that are *
* covered by the specified text string. This overlap list is used to handle map refresh *
* logic. *
* *
* INPUT: text -- Pointer to the text that would appear on the map and must have an *
* overlap list generated. *
* *
* x,y -- The coordinates that the text would appear (upper left corner). *
* *
* OUTPUT: Returns with a pointer to an overlap list that covers all cells "under" the text *
* if were displayed at the coordinates specified. The list is actually a series of *
* offsets from the display's upper left corner cell number. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/06/1994 JLB : Created. *
* 12/07/1994 JLB : Sidebar fixup. *
* 08/13/1995 JLB : Optimized for variable sized help text. *
*=============================================================================================*/
short const * DisplayClass::Text_Overlap_List(char const * text, int x, int y, int lines)
{
static short _list[30];
if (text) {
short * ptr = &_list[0];
int len = String_Pixel_Width(text)+CELL_PIXEL_W;
int right = TacPixelX + Lepton_To_Pixel(TacLeptonWidth);
/*
** If the help text would spill into the sidebar, then flag this fact, but
** shorten the apparent length so that the icon list calculation will
** function correctly.
*/
if (x+len >= TacPixelX+Lepton_To_Pixel(TacLeptonWidth)) {
len = right-x;
*ptr++ = REFRESH_SIDEBAR;
}
/*
** Build the list of overlap cell offset values according to the text
** coordinate and the length.
*/
int height = (((FontHeight * lines) + 23) / 24) * 24;
if (x <= right) {
CELL ul = Click_Cell_Calc(x, y-1);
CELL lr = Click_Cell_Calc(x+len-1, Bound(y+height, TacPixelY, SeenBuff.Get_Height() - 1));
if (ul == -1) ul = Click_Cell_Calc(x, y);
// if (lr == -1) lr = Click_Cell_Calc(x+len, y);
if (ul != -1 && lr != -1) {
for (int yy = Cell_Y(ul); yy <= Cell_Y(lr); yy++) {
for (int xx = Cell_X(ul); xx <= Cell_X(lr); xx++) {
*ptr++ = XY_Cell(xx, yy) - Coord_Cell(TacticalCoord);
}
}
}
}
*ptr = REFRESH_EOL;
}
return(_list);
}
/***********************************************************************************************
* DisplayClass::Set_View_Dimensions -- Sets the tactical display screen coordinates. *
* *
* Use this routine to set the tactical map screen coordinates and dimensions. This routine *
* is typically used when the screen size or position changes as a result of the sidebar *
* changing position or appearance. *
* *
* INPUT: x,y -- The X and Y pixel position on the screen for the tactical map upper left *
* corner. *
* *
* width -- The width of the tactical display (in pixels). If this parameter is *
* omitted, then the width will be as wide as the screen will allow. *
* *
* height-- The height of the tactial display (in pixels). If this parameter is *
* omitted, then the width wil be as wide as the screen will allow. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/06/1994 JLB : Created. *
* 06/27/1995 JLB : Adjusts tactical map position if necessary. *
*=============================================================================================*/
void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height)
{
if (width == -1) {
width = SeenBuff.Get_Width() - x;
}
TacLeptonWidth = Pixel_To_Lepton(width);
if (height == -1) {
height = SeenBuff.Get_Height() - y;
}
TacLeptonHeight = Pixel_To_Lepton(height);
/*
** Adjust the tactical cell if it is now in an invalid position
** because of the changed dimensions.
*/
int xx = Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W);
int yy = Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H);
Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H);
Set_Tactical_Position(XY_Coord(xx + (MapCellX * CELL_LEPTON_W), yy + (MapCellY * CELL_LEPTON_H)));
TacPixelX = x;
TacPixelY = y;
WindowList[WINDOW_TACTICAL][WINDOWX] = x >> 3;
WindowList[WINDOW_TACTICAL][WINDOWY] = y;
WindowList[WINDOW_TACTICAL][WINDOWWIDTH] = width >> 3;
WindowList[WINDOW_TACTICAL][WINDOWHEIGHT] = height;
if (Window == WINDOW_TACTICAL) {
Change_Window(0);
Change_Window(Window);
}
IsToRedraw = true;
Flag_To_Redraw(false);
TacButton.X = TacPixelX;
TacButton.Y = TacPixelY;
TacButton.Width = Lepton_To_Pixel(TacLeptonWidth);
TacButton.Height = Lepton_To_Pixel(TacLeptonHeight);
}
/***********************************************************************************************
* DisplayClass::Set_Cursor_Shape -- Changes the shape of the terrain square cursor. *
* *
* This routine is used to set up the terrain cursor according to the size of the object *
* that is to be placed down. The terrain cursor looks like an arbitrary collection of *
* hatched square overlays. Typical use is when placing buildings. *
* *
* INPUT: list -- A pointer to the list that contains offsets to the cells that are to *
* be marked. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/03/1994 JLB : Created. *
* 06/26/1995 JLB : Puts placement cursor into static buffer. *
*=============================================================================================*/
void DisplayClass::Set_Cursor_Shape(short const * list)
{
if (CursorSize) {
Cursor_Mark(ZoneCell+ZoneOffset, false);
}
ZoneOffset = 0;
if (list) {
int w,h;
static short _list[50];
memcpy(_list, list, sizeof(_list));
CursorSize = _list;
Get_Occupy_Dimensions (w, h, CursorSize);
ZoneOffset = -(((h/2)*MAP_CELL_W)+(w/2));
Cursor_Mark(ZoneCell+ZoneOffset, true);
} else {
CursorSize = 0;
}
}
/***********************************************************************************************
* DisplayClass::Passes_Proximity_Check -- Determines if building placement is near friendly sq*
* *
* This routine is used by the building placement cursor logic to determine whether the *
* at the current cursor position if the building would be adjacent to another friendly *
* building. In cases where this is not true, then the building cannot be placed at all. *
* This determination is returned by the function. *
* *
* INPUT: object -- The building object that the current placement system is examining. *
* *
* OUTPUT: bool; Can the pending building object be placed at the present cursor location *
* checking only for proximity to friendly buildings? If this isn't for a *
* building type object, then this routine always returns true. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/06/1994 JLB : Created. *
* 06/07/1994 JLB : Handles concrete check. *
*=============================================================================================*/
bool DisplayClass::Passes_Proximity_Check(ObjectTypeClass const *object)
{
short const *ptr;
/*
** In editor mode, the proximity check always passes.
*/
if (Debug_Map) {
return(true);
}
if (!object || !CursorSize || object->What_Am_I() != RTTI_BUILDINGTYPE) {
return(true);
}
/*
** Scan through all cells that the building foundation would cover. If any adjacent
** cells to these are of friendly persuasion, then consider the proximity check to
** have been a success.
*/
ptr = CursorSize;
while (*ptr != REFRESH_EOL) {
CELL cell = ZoneCell + ZoneOffset + *ptr++;
for (FacingType facing = FACING_N; facing < FACING_COUNT; facing++) {
CELL newcell = Adjacent_Cell(cell, facing);
if (!In_Radar(cell)) return(false);
TechnoClass * base = (*this)[newcell].Cell_Techno();
/*
** The special cell ownership flag allows building adjacent
** to friendly walls and bibs even though there is no official
** building located there.
*/
if ((*this)[newcell].Owner == PendingHouse) {
return(true);
}
if (base && base->What_Am_I() == RTTI_BUILDING && base->House->Class->House == PendingHouse) {
return(true);
}
}
}
return(false);
}
/***********************************************************************************************
* DisplayClass::Set_Cursor_Pos -- Controls the display and animation of the tac cursor. *
* *
* This routine controls the location, display, and animation of the *
* tactical map cursor. *
* *
* INPUT: pos -- Position to move the cursor do. If -1 is passed then *
* the cursor will just be hidden. If the position *
* passed is the same as the last position passed in, *
* then animation could occur (based on timers). *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/22/1991 JLB : Created. *
* 06/02/1994 JLB : Converted to member function. *
* 06/08/1994 JLB : If position is -1, then follow mouse. *
* 02/28/1995 JLB : Forces placement cursor to fit on map. *
*=============================================================================================*/
CELL DisplayClass::Set_Cursor_Pos(CELL pos)
{
CELL prevpos; // Last position of cursor (for jump-back reasons).
/*
** Follow the mouse position if no cell number is provided.
*/
if (pos == -1) {
pos = Click_Cell_Calc(Get_Mouse_X(), Get_Mouse_Y());
}
if (!CursorSize) {
prevpos = ZoneCell;
ZoneCell = pos;
return(prevpos);
}
/*
** Adjusts the position so that the placement cursor is never partway off the
** tactical map.
*/
int w,h;
Get_Occupy_Dimensions (w, h, CursorSize);
int x = Cell_X(pos + ZoneOffset);
int y = Cell_Y(pos + ZoneOffset);
if (x < Coord_XCell(TacticalCoord)) x = Coord_XCell(TacticalCoord);
// if (x < TacMapX) x = TacMapX;
if (y < Coord_YCell(TacticalCoord)) y = Coord_YCell(TacticalCoord);
// if (y < TacMapY) y = TacMapY;
if (x+w >= Coord_XCell(TacticalCoord) + Lepton_To_Cell(TacLeptonWidth)) x = Coord_XCell(TacticalCoord)+Lepton_To_Cell(TacLeptonWidth)-w;
// if (x+w >= TacMapX+TacWidth) x = TacMapX+TacWidth-w;
if (y+h >= Coord_YCell(TacticalCoord) + Lepton_To_Cell(TacLeptonHeight)) x = Coord_YCell(TacticalCoord)+Lepton_To_Cell(TacLeptonHeight)-h;
// if (y+h >= TacMapY+TacHeight) y = TacMapY+TacHeight-h;
pos = XY_Cell(x, y) - ZoneOffset;
/*
** This checks to see if NO animation or drawing is to occur and, if so,
** exits.
*/
if (pos == ZoneCell) return(pos);
prevpos = ZoneCell;
/*
** If the cursor is visible, then handle the graphic update.
** Otherwise, just update the global position of the cursor.
*/
if (CursorSize) {
/*
** Erase the old cursor (if it exists) AND the cursor is moving.
*/
if (pos != ZoneCell && ZoneCell != -1) {
Cursor_Mark(ZoneCell+ZoneOffset, false);
}
/*
** Render the cursor (could just be animation).
*/
if (pos != -1) {
Cursor_Mark(pos+ZoneOffset, true);
}
}
ZoneCell = pos;
ProximityCheck = Passes_Proximity_Check(PendingObject);
return(prevpos);
}
/***********************************************************************************************
* DisplayClass::Get_Occupy_Dimensions -- computes width & height of the given occupy list *
* *
* INPUT: *
* w ptr to fill in with height *
* h ptr to fill in with width *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 03/31/1995 BRR : Created. *
*=============================================================================================*/
void DisplayClass::Get_Occupy_Dimensions(int & w, int & h, short const *list)
{
int min_x = MAP_CELL_W;
int max_x = -MAP_CELL_W;
int min_y = MAP_CELL_H;
int max_y = -MAP_CELL_H;
int x,y;
w = 0;
h = 0;
if (!list) {
/*
** Loop through all cell offsets, accumulating max & min x- & y-coords
*/
while (*list != REFRESH_EOL) {
/*
** Compute x & y coords of the current cell offset. We can't use Cell_X()
** & Cell_Y(), because they use shifts to compute the values, and if the
** offset is negative we'll get a bogus coordinate!
*/
x = (*list) % MAP_CELL_W;
y = (*list) / MAP_CELL_H;
max_x = MAX(max_x, x);
min_x = MIN(min_x, x);
max_y = MAX(max_y, y);
min_y = MIN(min_y, y);
list++;
}
w = MAX(1, max_x - min_x + 1);
h = MAX(1, max_y - min_y + 1);
}
}
/***********************************************************************************************
* DisplayClass::Cursor_Mark -- Set or resets the cursor display flag bits. *
* *
* This routine will clear or set the cursor display bits on the map. *
* If the bit is set, then the cursor will be rendered on that map *
* icon. *
* *
* INPUT: pos -- Position of the upper left corner of the cursor. *
* *
* on -- Should the bit be turned on? *
* *
* OUTPUT: none *
* *
* WARNINGS: Be sure that every call to set the bits is matched by a *
* corresponding call to clear the bits. *
* *
* HISTORY: *
* 09/04/1991 JLB : Created. *
* 06/02/1994 JLB : Converted to member function. *
*=============================================================================================*/
void DisplayClass::Cursor_Mark(CELL pos, bool on)
{
CELL const *ptr;
CellClass *cellptr;
if (pos == -1) return;
/*
** For every cell in the CursorSize list, invoke its Redraw_Objects and
** toggle its IsCursorHere flag
*/
ptr = CursorSize;
while (*ptr != REFRESH_EOL) {
CELL cell = pos + *ptr++;
if (In_Radar(cell)) {
cellptr = &(*this)[cell];
cellptr->Redraw_Objects();
if (on) {
cellptr->IsCursorHere = true;
} else {
cellptr->IsCursorHere = false;
}
}
}
/*
** For every cell in the PendingObjectPtr's Overlap_List, invoke its
** Redraw_Objects routine.
*/
if (PendingObjectPtr) {
ptr = PendingObjectPtr->Overlap_List();
while (*ptr != REFRESH_EOL) {
CELL cell = pos + *ptr++;
if (In_Radar(cell)) {
cellptr = &(*this)[cell];
cellptr->Redraw_Objects();
}
}
}
}
/***********************************************************************************************
* DisplayClass::AI -- Handles the maintenance tasks for the map display. *
* *
* This routine is called once per game display frame (15 times per second). It handles *
* the mouse shape tracking and map scrolling as necessary. *
* *
* INPUT: input -- The next key just fetched from the input queue. *
* *
* x,y -- Mouse coordinates. *
* *
* OUTPUT: Modifies the input code if necessary. When the input code is consumed, it gets *
* set to 0. *