This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathCELL.CPP
2316 lines (2078 loc) · 102 KB
/
CELL.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\cell.cpv 2.18 16 Oct 1995 16:49:20 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 : CELL.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : April 29, 1994 *
* *
* Last Update : August 17, 1995 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* CellClass::Adjacent_Cell -- Determines the adjacent cell according to facing. *
* CellClass::Adjust_Threat -- Allows adjustment of threat at cell level *
* CellClass::CellClass -- Constructor for cell objects. *
* CellClass::Cell_Building -- Return with building at specified cell. *
* CellClass::Cell_Color -- Determine what radar color to use for this cell. *
* CellClass::Cell_Coord -- Returns the coordinate of this cell. *
* CellClass::Cell_Find_Object -- Returns ptr to RTTI type occupying cell *
* CellClass::Cell_Infantry -- Returns with pointer of first infantry unit. *
* CellClass::Cell_Object -- Returns with clickable object in cell. *
* CellClass::Cell_Techno -- Return with the unit/building at specified cell. *
* CellClass::Cell_Terrain -- Determines terrain object in cell. *
* CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
* CellClass::Clear_Icon -- Calculates what the clear icon number should be. *
* CellClass::Closest_Free_Spot -- returns free spot closest to given coord *
* CellClass::Concrete_Calc -- Calculates the concrete icon to use for the cell. *
* CellClass::Draw_It -- Draws the cell imagery at the location specified. *
* CellClass::Flag_Place -- Places a house flag down on the cell. *
* CellClass::Flag_Remove -- Removes the house flag from the cell. *
* CellClass::Cell_Occupier -- Fetches the occupier for the cell. *
* CellClass::Get_Trigger -- retrieves reference to the cell's trigger *
* CellClass::Goodie_Check -- Performs crate discovery logic. *
* CellClass::Incoming -- Causes objects in cell to "run for cover". *
* CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
* CellClass::Occupy_Down -- Flag occupation of specified cell. *
* CellClass::Occupy_Unit -- Marks cell as unit occupied. *
* CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
* CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
* CellClass::Overlap_Unit -- Marks cell as being overlapped by unit. *
* CellClass::Overlap_Up -- Removes overlap flag for the cell. *
* CellClass::Read -- Reads a particular cell value from a save game file. *
* CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
* CellClass::Redraw_Objects -- Redraws all objects overlapping this cell. *
* CellClass::Reduce_Tiberium -- Reduces the tiberium in the cell by the amount specified. *
* CellClass::Reduce_Wall -- Damages a wall, if damage is high enough. *
* CellClass::Reserve_Cell -- Marks a cell as being occupied by the specified unit ID. *
* CellClass::Shimmer -- Causes all objects in the cell to shimmer. *
* CellClass::Spot_Index -- returns cell sub-coord index for given COORD *
* CellClass::Tiberium_Adjust -- Adjust the look of the Tiberium for smooth. *
* CellClass::Validate -- validates cell's number *
* CellClass::Wall_Update -- Updates the imagery for wall objects in cell. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
#define FIXUP 0
/***********************************************************************************************
* CellClass::Validate -- validates cell's number *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* 1 = ok, 0 = error *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 08/09/1995 BRR : Created. *
*=============================================================================================*/
#ifdef CHEAT_KEYS
int CellClass::Validate(void) const
{
int num;
num = Cell_Number();
if (num < 0 || num > 4095) {
Validate_Error("CELL");
return (0);
}
else
return (1);
}
#else
#define Validate()
#endif
/***********************************************************************************************
* CellClass::CellClass -- Constructor for cell objects. *
* *
* A cell object is constructed into an empty state. It contains no specific objects, *
* templates, or overlays. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/09/1994 JLB : Created. *
*=============================================================================================*/
CellClass::CellClass(void)
{
memset(this, 0, sizeof(CellClass));
Smudge = SMUDGE_NONE;
Overlay = OVERLAY_NONE;
Smudge = SMUDGE_NONE;
TType = TEMPLATE_NONE;
Owner = HOUSE_NONE;
InfType = HOUSE_NONE;
}
/***********************************************************************************************
* CellClass::Cell_Color -- Determine what radar color to use for this cell. *
* *
* Use this routine to determine what radar color to render a radar *
* pixel with. This routine is called many many times to render the *
* radar map, so it must be fast. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the color to display the radar pixel with. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/01/1994 JLB : Created. *
* 04/30/1994 JLB : Converted to member function. *
* 05/31/1994 JLB : Takes into account any stealth characteristics of object. *
*=============================================================================================*/
int CellClass::Cell_Color(bool override) const
{
Validate();
BuildingClass * object = Cell_Building();
if (object) {
return(object->House->Class->Color);
}
if (override) {
return(TBLACK);
}
return(::Ground[Land_Type()].Color);
}
/***********************************************************************************************
* CellClass::Cell_Techno -- Return with the unit/building at specified cell. *
* *
* Returns an object located in the cell. If there is a *
* building present, it returns a pointer to that, otherwise it returns *
* a pointer to one of the units there. If nothing is present in the *
* specified cell, then it returns NULL. *
* *
* INPUT: x,y -- Coordinate offset (from upper left corner) to use as an aid in selecting *
* the desired object within the cell. *
* *
* OUTPUT: Returns a pointer to a building or unit located in cell. If *
* nothing present, just returns NULL. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/05/1992 JLB : Created. *
* 04/30/1994 JLB : Converted to member function. *
*=============================================================================================*/
TechnoClass * CellClass::Cell_Techno(int x, int y) const
{
Validate();
ObjectClass * object;
COORDINATE click; // Coordinate of click relative to cell corner.
TechnoClass * close = NULL;
long distance = 0; // Recorded closest distance.
/*
** Create a coordinate value that represent the pixel location within the cell. This is
** actually the lower significant bits (leptons) of a regular coordinate value.
*/
click = XY_Coord(Pixel_To_Lepton(x), Pixel_To_Lepton(y));
if (Cell_Occupier()) {
object = Cell_Occupier();
while (object) {
if (object->Is_Techno()) {
COORDINATE coord; // Coordinate relative to cell corner.
long dist;
coord = object->Center_Coord() & 0x00FF00FFL;
dist = Distance(coord, click);
if (!close || dist < distance) {
close = (TechnoClass *)object;
distance = dist;
}
}
object = object->Next;
}
}
return(close);
}
/***************************************************************************
* CellClass::Cell_Find_Object -- Returns ptr to RTTI type occupying cell *
* *
* INPUT: RTTIType the RTTI type we are searching for *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/17/1995 PWG : Created. *
* 06/12/1995 JLB : Returns object class pointer. *
*=========================================================================*/
ObjectClass * CellClass::Cell_Find_Object(RTTIType rtti) const
{
Validate();
ObjectClass * object = Cell_Occupier();
while (object) {
if (object->What_Am_I() == rtti) {
return(object);
}
object = object->Next;
}
return(NULL);
}
/***********************************************************************************************
* CellClass::Cell_Building -- Return with building at specified cell. *
* *
* Given a cell, determine if there is a building associated *
* and return with a pointer to this building. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with a pointer to the building associated with the *
* cell. If there is no building associated, then NULL is *
* returned. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/05/1992 JLB : Created. *
* 04/30/1994 JLB : Converted to member function. *
*=============================================================================================*/
BuildingClass * CellClass::Cell_Building(void) const
{
Validate();
return((BuildingClass *)Cell_Find_Object(RTTI_BUILDING));
}
/***********************************************************************************************
* CellClass::Cell_Terrain -- Determines terrain object in cell. *
* *
* This routine is used to determine the terrain object (if any) that *
* overlaps this cell. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with a pointer to the terrain object that overlaps *
* this cell. If there is no terrain object present, then NULL *
* is returned. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/18/1994 JLB : Created. *
*=============================================================================================*/
TerrainClass * CellClass::Cell_Terrain(void) const
{
Validate();
return((TerrainClass *)Cell_Find_Object(RTTI_TERRAIN));
}
/***********************************************************************************************
* CellClass::Cell_Object -- Returns with clickable object in cell. *
* *
* This routine is used to determine which object is to be selected *
* by a player click upon the cell. Not all objects that overlap the *
* cell are selectable by the player. This routine sorts out which *
* is which and returns with the appropriate object pointer. *
* *
* INPUT: x,y -- Coordinate (from upper left corner of cell) to use as a guide when *
* selecting the object within the cell. This plays a role in those cases *
* where several objects (such as infantry) exist within the same cell. *
* *
* OUTPUT: Returns with pointer to the object clickable within the *
* cell. NULL is returned if there is no clickable object *
* present. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/13/1994 JLB : Created. *
*=============================================================================================*/
ObjectClass * CellClass::Cell_Object(int x, int y) const
{
Validate();
ObjectClass * ptr;
/*
** Hack so that aircraft landed on helipads can still be selected if directly
** clicked on.
*/
ptr = (ObjectClass *)Cell_Find_Object(RTTI_AIRCRAFT);
if (ptr) {
return(ptr);
}
ptr = Cell_Techno(x, y);
if (ptr) {
return(ptr);
}
ptr = Cell_Terrain();
if (ptr) return(ptr);
return(ptr);
}
/***********************************************************************************************
* CellClass::Redraw_Objects -- Redraws all objects overlapping this cell. *
* *
* This is a low level routine that marks all objects that overlap this *
* cell to be redrawn. It is necessary to call this routine whenever *
* the underlying icon has to be redrawn. *
* *
* INPUT: forced -- Should this redraw be forced even if flags *
* indicate that it would be redundant? *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/18/1994 JLB : Created. *
* 06/20/1994 JLB : Simplified to use object pointers. *
* 12/24/1994 JLB : Only checks if cell is in view and not flagged already. *
*=============================================================================================*/
void CellClass::Redraw_Objects(bool forced)
{
Validate();
CELL cell = Cell_Number();
if (Map.In_View(cell) && (forced || !Map.Is_Cell_Flagged(cell))) {
/*
** Flag the icon to be redrawn.
*/
Map.Flag_Cell(cell);
/*
** Flag the main object in the cell to be redrawn.
*/
if (Cell_Occupier()) {
ObjectClass * optr = Cell_Occupier();
while (optr) {
optr->Mark(MARK_CHANGE);
optr = optr->Next;
}
}
/*
** Flag any overlapping object in this cell to be redrawn.
*/
for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
if (Overlapper[index]) {
Overlapper[index]->Mark(MARK_CHANGE);
}
}
}
}
/***********************************************************************************************
* CellClass::Is_Generally_Clear -- Determines if cell can be built upon. *
* *
* This determines if the cell can become a proper foundation for *
* building placement. *
* *
* INPUT: none *
* *
* OUTPUT: bool; Can the cell be built upon? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/18/1994 JLB : Created. *
*=============================================================================================*/
bool CellClass::Is_Generally_Clear(void) const
{
Validate();
if (ScenarioInit) return(true);
if (Flag.Composite || IsFlagged || Cell_Occupier()) {
return(false);
}
if (Smudge != SMUDGE_NONE && SmudgeTypeClass::As_Reference(Smudge).IsBib && Owner != HOUSE_NONE) {
return(false);
}
if (Overlay != OVERLAY_NONE && OverlayTypeClass::As_Reference(Overlay).IsWall) {
return(false);
}
#ifdef ADVANCED
/*
** Building certain kinds of terrain is prohibited -- bridges in particular.
*/
switch (TType) {
case TEMPLATE_BRIDGE1:
case TEMPLATE_BRIDGE1D:
case TEMPLATE_BRIDGE2:
case TEMPLATE_BRIDGE2D:
case TEMPLATE_BRIDGE3:
case TEMPLATE_BRIDGE3D:
case TEMPLATE_BRIDGE4:
case TEMPLATE_BRIDGE4D:
case TEMPLATE_FORD1:
case TEMPLATE_FORD2:
return(false);
default:
break;
}
#endif
return(::Ground[Land_Type()].Build);
}
/***********************************************************************************************
* CellClass::Recalc_Attributes -- Recalculates the ground type attributes for the cell. *
* *
* This routine recalculates the ground type in the cell. The speeds the find path *
* algorithm and other determinations of the cell type. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/29/1994 JLB : Created. *
* 06/20/1994 JLB : Knows about template pointer in cell object. *
*=============================================================================================*/
void CellClass::Recalc_Attributes(void)
{
Validate();
/*
** Check for wall effects.
*/
if (Overlay != OVERLAY_NONE) {
Land = OverlayTypeClass::As_Reference(Overlay).Land;
if (Land != LAND_CLEAR) return;
}
/*
** If there is a template associated with this cell, then scan
** through the template exception list checking to see if this cell
** is one of the exception types. If it is, then return that ground type,
** otherwise return the template's default type.
*/
if (TType != TEMPLATE_NONE) {
TemplateTypeClass const *ttype = &TemplateTypeClass::As_Reference(TType);
/*
** If there is an exception type list for the icons of this template, then
** find out if the current icon is one of them. If so, apply the exception
** ground type to the cell.
*/
char const *ptr = ttype->AltIcons;
if (ptr) {
int icon = TIcon;
while (*ptr != -1) {
if (icon == *ptr++) {
Land = ttype->AltLand;
return;
}
}
}
/*
** No exception found, so just return the default ground type for this template.
*/
Land = ttype->Land;
return;
}
/*
** No template is the same as clear terrain.
*/
Land = TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1).Land;
}
/***********************************************************************************************
* CellClass::Occupy_Down -- Flag occupation of specified cell. *
* *
* This routine is used to mark the cell as being occupied by the specified object. *
* *
* INPUT: object -- The object that is to occupy the cell *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
* 11/29/1994 JLB : Simplified. *
*=============================================================================================*/
void CellClass::Occupy_Down(ObjectClass * object)
{
Validate();
ObjectClass * optr;
/*
** If the specified object is already part of the occupation list, then don't add
** it again -- bail instead.
*/
if (Cell_Occupier()) {
optr = Cell_Occupier();
while (optr) {
if (optr == object) {
return;
}
if (!optr->Next) break;
optr = optr->Next;
}
}
optr = Cell_Occupier();
object->Next = optr;
OccupierPtr = object;
Map.Radar_Pixel(Cell_Number());
/*
** If being placed down on a visible square, then flag this
** techno object as being revealed to the player.
*/
if (IsVisible || GameToPlay != GAME_NORMAL) {
object->Revealed(PlayerPtr);
}
/*
** Special occupy bit set.
*/
switch (object->What_Am_I()) {
case RTTI_BUILDING:
Flag.Occupy.Building = true;
break;
case RTTI_AIRCRAFT:
case RTTI_UNIT:
Flag.Occupy.Vehicle = true;
break;
case RTTI_TERRAIN:
Flag.Occupy.Monolith = true;
break;
default:
break;
}
}
/***********************************************************************************************
* CellClass::Occupy_Up -- Removes occupation flag from the specified cell. *
* *
* This routine will lift the object from the cell and free the cell to be occupied by *
* another object. Only if the cell was previously marked with the object specified, will *
* the object be lifted off. This routine is the counterpart to Occupy_Down(). *
* *
* INPUT: object -- The object that is being lifted off. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
* 11/29/1994 JLB : Fixed to handle next pointer in previous object. *
*=============================================================================================*/
void CellClass::Occupy_Up(ObjectClass * object)
{
Validate();
ObjectClass * optr = NULL; // Working pointer to the objects in the chain.
if (Cell_Occupier()) {
optr = Cell_Occupier();
}
if (optr == object) {
OccupierPtr = object->Next;
object->Next = 0;
} else {
while (optr) {
if (optr->Next == object) {
optr->Next = object->Next;
object->Next = 0;
break;
}
if (!optr->Next) break;
optr = optr->Next;
}
}
Map.Radar_Pixel(Cell_Number());
/*
** Special occupy bit clear.
*/
switch (object->What_Am_I()) {
case RTTI_BUILDING:
Flag.Occupy.Building = false;
break;
case RTTI_AIRCRAFT:
case RTTI_UNIT:
Flag.Occupy.Vehicle = false;
#ifdef NEVER
int x,y;
if (Map.Coord_To_Pixel(Cell_Coord(), x, y)) {
SeenBuff.Put_Pixel(x, y, BLUE);
}
#endif
break;
case RTTI_TERRAIN:
Flag.Occupy.Monolith = false;
break;
default:
break;
}
}
/***********************************************************************************************
* CellClass::Overlap_Down -- This routine is used to mark a cell as being spilled over (overla*
* *
* Most game objects can often have their graphic imagery spill into more than one cell *
* even though they are considered to "occupy" only one cell. All cells overlapped are *
* flagged by this routine. Using this information it is possible to keep the tactical map *
* display correct. *
* *
* INPUT: object -- The object to mark as overlapping this cell. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
* 07/04/1995 JLB : Ensures that buildings are always marked down. *
*=============================================================================================*/
void CellClass::Overlap_Down(ObjectClass * object)
{
Validate();
ObjectClass **ptr = 0;
if (!object) return;
for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
if (Overlapper[index] == object) return;
if (!Overlapper[index]) ptr = &Overlapper[index];
}
/*
** Buildings must ALWAYS succeed in marking the cell as overlapped. Bump somebody
** else out in this case.
*/
if (!ptr && object->What_Am_I() == RTTI_BUILDING) {
for (index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
switch (Overlapper[index]->What_Am_I()) {
case RTTI_BUILDING:
case RTTI_TERRAIN:
break;
default:
Overlapper[index] = object;
index = sizeof(Overlapper)/sizeof(Overlapper[0]);
break;
}
}
}
if (ptr) *ptr = object;
/*
** If being placed down on a visible square, then flag this
** techno object as being revealed to the player.
*/
if (IsVisible) {
object->Revealed(PlayerPtr);
}
}
/***********************************************************************************************
* CellClass::Overlap_Up -- Removes overlap flag for the cell. *
* *
* This is the counterpart to Overlap_Down and is used to remove the overlap flag for the *
* specified unit on the cell. *
* *
* INPUT: object -- The object to remove the overlap flag for. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
*=============================================================================================*/
void CellClass::Overlap_Up(ObjectClass *object)
{
Validate();
for (int index = 0; index < sizeof(Overlapper)/sizeof(Overlapper[0]); index++) {
if (Overlapper[index] == object) {
Overlapper[index] = 0;
break;
}
}
}
/***********************************************************************************************
* CellClass::Cell_Unit -- Returns with pointer to unit occupying cell. *
* *
* This routine will determine if a unit is occupying the cell and if so, return a pointer *
* to it. If there is no unit occupying the cell, then NULL is returned. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with pointer to unit occupying cell, else NULL. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
*=============================================================================================*/
UnitClass * CellClass::Cell_Unit(void) const
{
Validate();
return((UnitClass*)Cell_Find_Object(RTTI_UNIT));
}
/***********************************************************************************************
* CellClass::Cell_Infantry -- Returns with pointer of first infantry unit occupying the cell. *
* *
* This routine examines the cell and returns a pointer to the first infantry unit *
* that occupies it. If there is no infantry unit in the cell, then NULL is returned. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with pointer to infantry unit occupying the cell or NULL if none are *
* present. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/21/1994 JLB : Created. *
*=============================================================================================*/
InfantryClass * CellClass::Cell_Infantry(void) const
{
Validate();
return((InfantryClass*)Cell_Find_Object(RTTI_INFANTRY));
}
/***********************************************************************************************
* CellClass::Draw_It -- Draws the cell imagery at the location specified. *
* *
* This is the gruntwork cell rendering code. It draws the cell at the screen location *
* specified. This routine doesn't draw any overlapping or occupying units. It only *
* deals with the ground (cell) layer -- icon level. *
* *
* INPUT: x,y -- The screen coordinates to render the cell imagery at. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/18/1994 JLB : Created. *
* 08/21/1994 JLB : Revised for simple template objects. *
* 11/01/1994 BRR : Updated placement cursor; draws actual object *
* 11/14/1994 BRR : Added remapping code to show passable areas *
* 12/02/1994 BRR : Added trigger display *
* 12/11/1994 JLB : Mixes up clear terrain through pseudo-random table. *
* 04/25/1995 JLB : Smudges drawn BELOW overlays. *
*=============================================================================================*/
void CellClass::Draw_It(int x, int y, int draw_type) const
{
Validate();
TemplateTypeClass const *ttype = 0;
int icon; // The icon number to use from the template set.
CELL cell = Cell_Number();
void * remap = NULL;
#ifdef SCENARIO_EDITOR
TemplateTypeClass * tptr;
TriggerClass * trig;
int i;
char waypt[2];
#endif
/*
** Fetch a pointer to the template type associated with this cell.
*/
if (TType != TEMPLATE_NONE) {
ttype = &TemplateTypeClass::As_Reference(TType);
icon = TIcon;
} else {
ttype = &TemplateTypeClass::As_Reference(TEMPLATE_CLEAR1);
icon = Clear_Icon();
}
/*
** Draw the stamp of the template.
*/
if (Debug_Icon) {
LogicPage->Fill_Rect(Map.TacPixelX+x, Map.TacPixelY+y, Map.TacPixelX+x+ICON_PIXEL_W-1, Map.TacPixelY+y+ICON_PIXEL_H-1, Sim_Random_Pick(1, 254));
FontXSpacing -= 2;
Fancy_Text_Print("%d\r%2X%c\r%02X.%02X", Map.TacPixelX+x+(ICON_PIXEL_W>>1), Map.TacPixelY+y, WHITE, TBLACK, TPF_6POINT|TPF_NOSHADOW|TPF_CENTER, cell, Flag.Composite, (Cell_Occupier() ? '*' : ' '), Overlay, OverlayData);
FontXSpacing += 2;
} else {
if (!draw_type || draw_type == CELL_BLIT_ONLY){
#ifdef SCENARIO_EDITOR
/*
** Set up the remap table for this icon.
*/
if (Debug_Map && Debug_Passable) {
if (::Ground[Land].Cost[0] == 0 || (Cell_Occupier() != NULL &&
Cell_Occupier()->What_Am_I() != RTTI_INFANTRY)) { // impassable
remap = Map.FadingRed;
} else {
if (::Ground[Land].Cost[0] > 0x70) { // pretty passable
remap = Map.FadingGreen;
} else {
remap = Map.FadingYellow; // moderately passable
}
}
}
#endif
// ****** maybe this icon shouldn't be drawn if it is known that the cell will be covered
// with shadow.
/*
** This is the underlying terrain icon.
*/
if (ttype->Get_Image_Data()) {
LogicPage->Draw_Stamp(ttype->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL);
if (remap) {
LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap);
}
}
#ifdef SCENARIO_EDITOR
/*
** Draw the map editor's "current" cell. This is the cell that can be
** assigned attributes such as tag labels.
** This must be draw before the placement cursor, but after drawing the
** objects in the cell.
*/
if (Debug_Map && CurrentCell == Cell_Number()) {
LogicPage->Draw_Rect(x+Map.TacPixelX, y+Map.TacPixelY, Map.TacPixelX + x + CELL_PIXEL_W - 1, Map.TacPixelY + y + CELL_PIXEL_H - 1, YELLOW);
}
#endif
#ifdef NEVER
/*
** Special concrete render. It always renders over the underlying
** terrain unless this concrete piece will cover the entire terrain
** piece.
*/
if (Concrete) {
LogicPage->Draw_Stamp(TemplateTypeClass::As_Pointer(TEMPLATE_CONCRETE_GDI)->Get_Image_Data(), Concrete-1, x, y, NULL, WINDOW_TACTICAL);
}
#endif
}
/*
** Redraw any smudge.
*/
if (Smudge != SMUDGE_NONE) {
#ifdef NEVER
switch (Smudge) {
case SMUDGE_BIB1:
CC_Draw_Shape(Bib1, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
break;
case SMUDGE_BIB2:
CC_Draw_Shape(Bib2, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
break;
case SMUDGE_BIB3:
CC_Draw_Shape(Bib3, SmudgeData, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
break;
}
#endif
SmudgeTypeClass::As_Reference(Smudge).Draw_It(x, y, SmudgeData);
}
if (!draw_type || draw_type == CELL_DRAW_ONLY){
/*
** Draw the overlay object.
*/
if (Overlay != OVERLAY_NONE) {
OverlayTypeClass const & otype = OverlayTypeClass::As_Reference(Overlay);
IsTheaterShape = (bool)otype.IsTheater;
CC_Draw_Shape(otype.Get_Image_Data(), OverlayData, (x+(CELL_PIXEL_W>>1)), (y+(CELL_PIXEL_H>>1)), WINDOW_TACTICAL, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_GHOST, NULL, Map.UnitShadow);
IsTheaterShape = false;
}
#ifdef SCENARIO_EDITOR
if (Debug_Map) {
/*
** Draw the cell's Trigger mnemonic, if it has a trigger
*/
if (IsTrigger) {
trig = Get_Trigger();
Fancy_Text_Print(trig->Get_Name(), x+Map.TacPixelX, y+Map.TacPixelY, PINK, TBLACK, TPF_NOSHADOW|TPF_6POINT);
}
/*
** Draw the cell's Waypoint designation if there is one.
*/
if (IsWaypoint) {
for (i = 0; i < 26; i++) {
if (Waypoint[i]==Cell_Number()) {
waypt[0] = 'A' + i;
waypt[1] = 0;
Fancy_Text_Print(waypt, Map.TacPixelX + x + CELL_PIXEL_W / 2,
Map.TacPixelY + y + (CELL_PIXEL_H / 2) - 3, YELLOW, TBLACK,
TPF_NOSHADOW | TPF_6POINT | TPF_CENTER);
break;
}
}
if (Waypoint[WAYPT_HOME] == Cell_Number()) {
Fancy_Text_Print("Home", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
}
if (Waypoint[WAYPT_REINF] == Cell_Number()) {
Fancy_Text_Print("Reinf", Map.TacPixelX + x, Map.TacPixelY + y + (CELL_PIXEL_H) - 7,
WHITE, TBLACK, TPF_NOSHADOW | TPF_6POINT);
}
}
}
#endif
/*
** Draw the placement cursor:
** - First, draw the hash-mark cursor, so it will appear underneath
** any cursor being drawn
** - If the PendingObject is a template, overlay, or smudge, draw it
** - Otherwise, it's up to the Display.Refresh_Map() routine to draw it
*/
if (IsCursorHere) {
/*
** Draw the hash-mark cursor:
*/