forked from electronicarts/CnC_Remastered_Collection
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHOUSE.CPP
9016 lines (7966 loc) · 366 KB
/
HOUSE.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
//
// Copyright 2020 Electronic Arts Inc.
//
// TiberianDawn.DLL and RedAlert.dll and corresponding source code 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.
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted supplemental terms
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted supplemental terms
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
/* $Header: F:\projects\c&c\vcs\code\house.cpv 2.13 02 Aug 1995 17:03:50 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 : HOUSE.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : May 21, 1994 *
* *
* Last Update : August 12, 1995 [JLB] *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* HouseClass::AI -- Process house logic. *
* HouseClass::Abandon_Production -- Abandons production of item type specified. *
* HouseClass::Add_Nuke_Piece -- Add a nuclear piece to the collection. *
* HouseClass::Adjust_Capacity -- Adjusts the house Tiberium storage capacity. *
* HouseClass::Adjust_Threat -- Adjust threat for the region specified. *
* HouseClass::As_Pointer -- Converts a house number into a house object pointer. *
* HouseClass::Assign_Handicap -- Assigns the specified handicap rating to the house. *
* HouseClass::Attacked -- Lets player know if base is under attack. *
* HouseClass::Available_Money -- Fetches the total credit worth of the house. *
* HouseClass::Begin_Production -- Starts production of the specified object type. *
* HouseClass::Blowup_All -- blows up everything *
* HouseClass::Can_Build -- Determines if the aircraft type can be built. *
* HouseClass::Can_Build -- Determines if the building type can be built. *
* HouseClass::Can_Build -- Determines if the infantry unit can be built by this house. *
* HouseClass::Can_Build -- Determines if the unit can be built by this house. *
* HouseClass::Can_Build -- General purpose build legality checker. *
* HouseClass::Clobber_All -- removes house & all its objects *
* HouseClass::Debug_Dump -- Dumps the house status data to the mono screen. *
* HouseClass::Detach -- Removes specified object from house tracking systems. *
* HouseClass::Does_Enemy_Building_Exist -- Checks for enemy building of specified type. *
* HouseClass::Flag_Attach -- Attach flag to specified cell (or thereabouts). *
* HouseClass::Flag_Attach -- Attaches the house flag the specified unit. *
* HouseClass::Flag_Remove -- Removes the flag from the specified target. *
* HouseClass::Flag_To_Die -- Flags the house to blow up soon. *
* HouseClass::Flag_To_Lose -- Flags the house to die soon. *
* HouseClass::Flag_To_Win -- Flags the house to win soon. *
* HouseClass::Harvested -- Adds Tiberium to the harvest storage. *
* HouseClass::Has_Nuke_Device -- Deteremines if the house has a nuclear device. *
* HouseClass::HouseClass -- Constructor for a house object. *
* HouseClass::Init -- init's in preparation for new scenario *
* HouseClass::Init_Air_Strike -- Add (or reset) the air strike sidebar button. *
* HouseClass::Init_Data -- Initializes the multiplayer color data. *
* HouseClass::Init_Ion_Cannon -- Initialize the ion cannon countdown. *
* HouseClass::Init_Nuke_Bomb -- Adds (if necessary) the atom bomb to the sidebar. *
* HouseClass::Is_Ally -- Checks to see if the object is an ally. *
* HouseClass::Is_Ally -- Determines if the specified house is an ally. *
* HouseClass::Is_Ally -- Determines if the specified house is an ally. *
* HouseClass::MPlayer_Defeated -- multiplayer; house is defeated *
* HouseClass::Make_Air_Strike_Available -- Make the airstrike available. *
* HouseClass::Make_Ally -- Make the specified house an ally. *
* HouseClass::Make_Enemy -- Make an enemy of the house specified. *
* HouseClass::Manual_Place -- Inform display system of building placement mode. *
* HouseClass::One_Time -- Handles one time initialization of the house array. *
* HouseClass::Place_Object -- Places the object (building) at location specified. *
* HouseClass::Place_Special_Blast -- Place a special blast effect at location specified. *
* HouseClass::Power_Fraction -- Fetches the current power output rating. *
* HouseClass::Read_INI -- Reads house specific data from INI. *
* HouseClass::Refund_Money -- Refunds money to back to the house. *
* HouseClass::Remap_Table -- Fetches the remap table for this house object. *
* HouseClass::Remove_Air_Strike -- Removes the air strike button from the sidebar. *
* HouseClass::Remove_Ion_Cannon -- Disables the ion cannon. *
* HouseClass::Remove_Nuke_Bomb -- Removes the nuclear bomb from the sidebar. *
* HouseClass::Sell_Wall -- Tries to sell the wall at the specified location. *
* HouseClass::Silo_Redraw_Check -- Flags silos to be redrawn if necessary. *
* HouseClass::Special_Weapon_AI -- Fires special weapon. *
* HouseClass::Spend_Money -- Removes money from the house. *
* HouseClass::Suggest_New_Object -- Determine what would the next buildable object be. *
* HouseClass::Suggested_New_Team -- Determine what team should be created. *
* HouseClass::Suspend_Production -- Temporarily puts production on hold. *
* HouseClass::Validate -- validates house pointer *
* HouseClass::Write_INI -- Writes house specific data into INI file. *
* HouseClass::delete -- Deallocator function for a house object. *
* HouseClass::new -- Allocator for a house class. *
* HouseClass::operator HousesType -- Conversion to HousesType operator. *
* HouseClass::~HouseClass -- Default destructor for a house object. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/*
** New sidebar for GlyphX multiplayer. ST - 3/26/2019 12:24PM
*/
#include "SidebarGlyphx.h"
#include "defines.h"
//#include "CFEDEBUG.H"
extern void On_Sound_Effect(const HouseClass* player_ptr, int sound_effect_index, const char* extension, int variation, COORDINATE coord);
/***********************************************************************************************
* HouseClass::Validate -- validates house pointer *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* 1 = ok, 0 = error *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 08/09/1995 BRR : Created. *
*=============================================================================================*/
#ifdef CHEAT_KEYS
int HouseClass::Validate(void) const
{
int num;
num = Houses.ID(this);
if (num < 0 || num >= HOUSE_MAX) {
Validate_Error("HOUSE");
return (0);
}
else
return (1);
}
#else
#define Validate()
#endif
/***********************************************************************************************
* HouseClass::operator HousesType -- Conversion to HousesType operator. *
* *
* This operator will automatically convert from a houses class object into the HousesType *
* enumerated value. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the object's HousesType value. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/23/1995 JLB : Created. *
*=============================================================================================*/
HouseClass::operator HousesType(void) const
{
Validate();
return(Class->House);
}
/***********************************************************************************************
* HouseClass::As_Pointer -- Converts a house number into a house object pointer. *
* *
* Use this routine to convert a house number into the house pointer that it represents. *
* A simple index into the Houses template array is not sufficient, since the array order *
* is arbitrary. An actual scan through the house object is required in order to find the *
* house object desired. *
* *
* INPUT: house -- The house type number to look up. *
* *
* OUTPUT: Returns with a pointer to the house object that the house number represents. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 01/23/1995 JLB : Created. *
*=============================================================================================*/
HouseClass * HouseClass::As_Pointer(HousesType house)
{
for (int index = 0; index < Houses.Count(); index++) {
if (Houses.Ptr(index)->Class->House == house) {
return(Houses.Ptr(index));
}
}
return(0);
}
/***********************************************************************************************
* HouseClass::One_Time -- Handles one time initialization of the house array. *
* *
* This basically calls the constructor for each of the houses in the game. All other *
* data specific to the house is initialized when the scenario is loaded. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Only call this ONCE at the beginning of the game. *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
*=============================================================================================*/
void HouseClass::One_Time(void)
{
// for (HousesType index = HOUSE_FIRST; index < HOUSE_COUNT; index++) {
// new(index) HouseClass;
// }
#ifdef USE_RA_AI
/*
** Required for Red Alert AI. ST - 7/23/2019 3:21PM
*/
BuildChoice.Set_Heap(STRUCT_COUNT);
#endif
}
/***********************************************************************************************
* HouseClass::Assign_Handicap -- Assigns the specified handicap rating to the house. *
* *
* The handicap rating will affect combat, movement, and production for the house. It can *
* either make it more or less difficult for the house (controlled by the handicap value). *
* *
* INPUT: handicap -- The handicap value to assign to this house. The default value for *
* a house is DIFF_NORMAL. *
* *
* OUTPUT: Returns with the old handicap value. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/09/1996 JLB : Created. *
* 10/22/1996 JLB : Uses act like value for multiplay only. *
*=============================================================================================*/
DiffType HouseClass::Assign_Handicap(DiffType handicap)
{
DiffType old = Difficulty;
Difficulty = handicap;
if (GameToPlay != GAME_NORMAL) {
HouseTypeClass const * hptr = &HouseTypeClass::As_Reference(ActLike);
FirepowerBias = hptr->FirepowerBias * Rule.Diff[handicap].FirepowerBias;
GroundspeedBias = hptr->GroundspeedBias * Rule.Diff[handicap].GroundspeedBias;
AirspeedBias = hptr->AirspeedBias * Rule.Diff[handicap].AirspeedBias;
ArmorBias = hptr->ArmorBias * Rule.Diff[handicap].ArmorBias;
ROFBias = hptr->ROFBias * Rule.Diff[handicap].ROFBias;
CostBias = hptr->CostBias * Rule.Diff[handicap].CostBias;
RepairDelay = Rule.Diff[handicap].RepairDelay;
BuildDelay = Rule.Diff[handicap].BuildDelay;
BuildSpeedBias = hptr->BuildSpeedBias * Rule.Diff[handicap].BuildSpeedBias;
} else {
FirepowerBias = Rule.Diff[handicap].FirepowerBias;
GroundspeedBias = Rule.Diff[handicap].GroundspeedBias;
AirspeedBias = Rule.Diff[handicap].AirspeedBias;
ArmorBias = Rule.Diff[handicap].ArmorBias;
ROFBias = Rule.Diff[handicap].ROFBias;
CostBias = Rule.Diff[handicap].CostBias;
RepairDelay = Rule.Diff[handicap].RepairDelay;
BuildDelay = Rule.Diff[handicap].BuildDelay;
BuildSpeedBias = Rule.Diff[handicap].BuildSpeedBias;
}
return(old);
}
#ifdef CHEAT_KEYS
/***********************************************************************************************
* HouseClass::Debug_Dump -- Dumps the house status data to the mono screen. *
* *
* This utility function will output the current status of the house class to the mono *
* screen. Through this information bugs may be fixed or detected. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void HouseClass::Debug_Dump(MonoClass *) const
{
Validate();
}
#endif
/***********************************************************************************************
* HouseClass::new -- Allocator for a house class. *
* *
* This is the allocator for a house class. Since there can be only *
* one of each type of house, this is allocator has restricted *
* functionality. Any attempt to allocate a house structure for a *
* house that already exists, just returns a pointer to the previously *
* allocated house. *
* *
* INPUT: house -- The house to allocate a class object for. *
* *
* OUTPUT: Returns with a pointer to the allocated class object. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/22/1994 JLB : Created. *
*=============================================================================================*/
void * HouseClass::operator new(size_t)
{
void * ptr = Houses.Allocate();
if (ptr) {
((HouseClass *)ptr)->IsActive = true;
}
return(ptr);
}
/***********************************************************************************************
* HouseClass::delete -- Deallocator function for a house object. *
* *
* This function marks the house object as "deallocated". Such a *
* house object is available for reallocation later. *
* *
* INPUT: ptr -- Pointer to the house object to deallocate. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/22/1994 JLB : Created. *
*=============================================================================================*/
void HouseClass::operator delete(void *ptr)
{
if (ptr) {
((HouseClass *)ptr)->IsActive = false;
}
Houses.Free((HouseClass *)ptr);
}
/***********************************************************************************************
* HouseClass::HouseClass -- Constructor for a house object. *
* *
* This function is the constructor and it marks the house object *
* as being allocated. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/22/1994 JLB : Created. *
*=============================================================================================*/
HouseClass::HouseClass(HousesType house) :
Class(&HouseTypeClass::As_Reference(house)),
IonCannon(ION_CANNON_GONE_TIME, VOX_ION_READY, VOX_ION_CHARGING, VOX_ION_CHARGING, VOX_NO_POWER),
AirStrike(AIR_CANNON_GONE_TIME, VOX_AIRSTRIKE_READY, VOX_NONE, VOX_NOT_READY, VOX_NOT_READY),
NukeStrike(NUKE_GONE_TIME, VOX_NUKE_AVAILABLE, VOX_NONE, VOX_NOT_READY, VOX_NO_POWER)
{
for (HousesType i = HOUSE_FIRST; i < HOUSE_COUNT; i++) {
UnitsKilled[i] = 0;
BuildingsKilled[i] = 0;
}
WhoLastHurtMe = house; // init this to myself
IsVisionary = false;
IsFreeHarvester = false;
Blockage = 0;
UnitsLost = 0;
BuildingsLost = 0;
NewActiveBScan = 0;
ActiveBScan = 0;
NewActiveUScan = 0;
ActiveUScan = 0;
NewActiveIScan = 0;
ActiveIScan = 0;
NewActiveAScan = 0;
ActiveAScan = 0;
strcpy((char *)Name, "Computer"); // Default computer name.
JustBuilt = STRUCT_NONE;
AlertTime = 0;
IsAlerted = false;
IsAirstrikePending = false;
AircraftFactory = -1;
AircraftFactories = 0;
ActLike = Class->House;
Allies = 0;
AScan = 0;
NukeDest = 0;
BlitzTime.Clear();
ScreenShakeTime.Clear();
BScan = 0;
BuildingFactories = 0;
BuildingFactory = -1;
Capacity = 0;
Credits = 0;
CreditsSpent = 0;
CurBuildings = 0;
CurUnits = 0;
DamageTime = DAMAGE_DELAY;
Drain = 0;
Edge = SOURCE_NORTH;
FlagHome = 0;
FlagLocation = TARGET_NONE;
HarvestedCredits = 0;
HouseTriggers[house].Clear();
IGaveUp = false;
InfantryFactories = 0;
InfantryFactory = -1;
InitialCredits = 0;
InitialCredits = 0;
IScan = 0;
IsRecalcNeeded = true;
IsCivEvacuated = false;
IsDefeated = false;
IsDiscovered = false;
IsHuman = false;
WasHuman = false;
IsMaxedOut = false;
IsStarted = false;
IsToDie = false;
IsToLose = false;
IsToWin = false;
Make_Ally(house);
MaxBuilding = 0;
MaxUnit = 0;
NewAScan = 0;
NewBScan = 0;
NewIScan = 0;
NewUScan = 0;
NukePieces = 0x07;
Power = 0;
Radar = RADAR_NONE;
RemapTable = Class->RemapTable;
RemapColor = Class->RemapColor;
Resigned = false;
SpeakAttackDelay = 1;
SpeakMaxedDelay = 1;
SpeakMoneyDelay = 1;
SpeakMoneyDelay.Set(Options.Normalize_Delay(SPEAK_DELAY)); // 2 minutes
SpeakPowerDelay = 1;
SpecialFactories = 0;
SpecialFactory = -1;
TeamTime = TEAM_DELAY;
Tiberium = 0;
TriggerTime = 0;
UnitFactories = 0;
UnitFactory = -1;
UScan = 0;
memset((void *)&Regions[0], 0x00, sizeof(Regions));
Init_Unit_Trackers();
DebugUnlockBuildables = false;
StartLocationOverride = -1;
/*
** New AI variables from RA. Need to add to save/load?
*/
#ifdef USE_RA_AI
IsBaseBuilding = true;
Center = 0;
Radius = 0;
for (ZoneType zone = ZONE_FIRST; zone < ZONE_COUNT; zone++) {
ZoneInfo[zone].AirDefense = 0;
ZoneInfo[zone].ArmorDefense = 0;
ZoneInfo[zone].InfantryDefense = 0;
}
LATime = 0;
LAType = RTTI_NONE;
LAZone = ZONE_NONE;
LAEnemy = HOUSE_NONE;
ToCapture = TARGET_NONE;
RadarSpied = 0;
PointTotal = 0;
memset(BQuantity, '\0', sizeof(BQuantity));
memset(UQuantity, '\0', sizeof(UQuantity));
memset(IQuantity, '\0', sizeof(IQuantity));
memset(AQuantity, '\0', sizeof(AQuantity));
Attack = 0;
Enemy = HOUSE_NONE;
AITimer = 0;
BuildStructure = STRUCT_NONE;
BuildUnit = UNIT_NONE;
BuildInfantry = INFANTRY_NONE;
BuildAircraft = AIRCRAFT_NONE;
State = STATE_BUILDUP;
IsTiberiumShort = false;
IQ = Rule.MaxIQ;
IsParanoid = false;
OldBScan = 0;
Assign_Handicap(DIFF_NORMAL);
// Chthon CFE Note: Q-Move port
IsQueuedMovementToggle = false;
QueuedMovementToggleTimeout = 0;
#endif
}
HouseClass::~HouseClass (void)
{
Free_Unit_Trackers();
}
/***********************************************************************************************
* HouseClass::Can_Build -- General purpose build legality checker. *
* *
* This routine is called when it needs to be determined if the specified object type can *
* be built by this house. Production and sidebar maintenance use this routine heavily. *
* *
* INPUT: type -- Pointer to the type of object that legality is to be checked for. *
* *
* house -- This is the house to check for legality against. Note that this might *
* not be 'this' house since the check could be from a captured factory. *
* Captured factories build what the original owner of them could build. *
* *
* OUTPUT: Can the specified object be built? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 07/04/1995 JLB : Created. *
* 08/12/1995 JLB : Updated for GDI building sandbag walls in #9. *
*=============================================================================================*/
bool HouseClass::Can_Build(TechnoTypeClass const * type, HousesType house) const
{
Validate();
if (!type || !type->IsBuildable || !((1L << house) & type->Ownable)) return(false);
/*
** The computer can always build everthing.
*/
#ifdef USE_RA_AI
if (!IsHuman && GameToPlay == GAME_NORMAL) return(true); // Added game type check for AI from RA. ST - 7/25/2019 3:25PM
#else
if (!IsHuman) return(true);
#endif
/*
** Perform some equivalency fixups for the building existance flags.
*/
long flags = ActiveBScan;
// Chthon CFE Note: save the flags before dirtying them up
long memoflags = flags;
/*
** AI players update flags using building quantity tracker.
** Ensures consistent logic when determining building choices.
*/
if (!IsHuman) {
flags = 0;
for (int i = 0; i < 32; i++) {
if (BQuantity[i] > 0) {
flags |= (1 << i);
}
}
}
int pre = type->Pre;
if (flags & STRUCTF_ADVANCED_POWER) flags |= STRUCTF_POWER;
if (flags & STRUCTF_HAND) flags |= STRUCTF_BARRACKS;
if (flags & STRUCTF_OBELISK) flags |= STRUCTF_ATOWER;
if (flags & STRUCTF_TEMPLE) flags |= STRUCTF_EYE;
if (flags & STRUCTF_AIRSTRIP) flags |= STRUCTF_WEAP;
if (flags & STRUCTF_SAM) flags |= STRUCTF_HELIPAD;
// Chthon CFE Note: Special logic for dummy helipad types.
// These should only be buildable by a human player who's captured a MCV of the opposite faction
// (And in the case of the Nod helipad, only if Nod could build helipads.)
if (type->What_Am_I() == RTTI_BUILDINGTYPE){
if (((BuildingTypeClass const *)type)->Type == STRUCT_GDI_HELIPAD){
if (!ActiveCFEPatchConfig.SplitDualCapturables || !IsHuman || (ActLike == HOUSE_GOOD)){
return false;
}
}
else if (((BuildingTypeClass const *)type)->Type == STRUCT_NOD_HELIPAD){
if (!ActiveCFEPatchConfig.SplitDualCapturables || !IsHuman || (ActLike == HOUSE_BAD) || ((GameToPlay == GAME_NORMAL) && !(Special.IsJurassic && AreThingiesEnabled) && !ActiveCFEPatchConfig.MPUnitsInSP)){
return false;
}
}
// disable the regular helipad for dino missions so the player doesn't have 3 types
else if (((BuildingTypeClass const *)type)->Type == STRUCT_HELIPAD){
if (ActiveCFEPatchConfig.SplitDualCapturables && IsHuman && (GameToPlay == GAME_NORMAL) && Special.IsJurassic && AreThingiesEnabled){
return false;
}
}
}
// and MCVs
// MCVs must have appropriate capstone building
else if (type->What_Am_I() == RTTI_UNITTYPE){
if (((UnitTypeClass const *)type)->Type == UNIT_GMCV){
if (!ActiveCFEPatchConfig.SplitDualCapturables || !IsHuman || (ActLike == HOUSE_GOOD) || !(memoflags & STRUCTF_EYE)){
return false;
}
}
else if (((UnitTypeClass const *)type)->Type == UNIT_NMCV){
if (!ActiveCFEPatchConfig.SplitDualCapturables || !IsHuman || (ActLike == HOUSE_BAD) || !(memoflags & STRUCTF_TEMPLE)){
return false;
}
}
else if (((UnitTypeClass const *)type)->Type == UNIT_MCV){
if (ActiveCFEPatchConfig.SplitDualCapturables){
// disable the regular MCV for dino missions so the player doesn't have 3 types
if (IsHuman && (GameToPlay == GAME_NORMAL) && Special.IsJurassic && AreThingiesEnabled){
return false;
}
// if SplitDualCapturables is on, you need to have your own capstone building to build your own MCV
// (e.g., GDI player with War Factory + captured Temple cannot make GDI MCV)
if (((ActLike == HOUSE_GOOD) && !(memoflags & STRUCTF_EYE)) || ((ActLike == HOUSE_BAD) && !(memoflags & STRUCTF_TEMPLE))){
return false;
}
}
}
}
/*
** Multiplayer game uses a different legality check for building.
*/
if (GameToPlay != GAME_NORMAL || (Special.IsJurassic && AreThingiesEnabled)) {
if (DebugUnlockBuildables) {
return true;
}
return((pre & flags) == pre && type->Level <= BuildLevel);
}
#ifdef NEWMENU
int level = BuildLevel;
#else
int level = Scenario;
#endif
/*
** Special check to make the mission objective buildings the prerequisite
** for the stealth tank in mission #11 only.
*/
if (house == HOUSE_BAD &&
type->What_Am_I() == RTTI_UNITTYPE &&
((UnitTypeClass const *)type)->Type == UNIT_STANK &&
level == 11) {
pre = STRUCTF_MISSION;
level = type->Scenario;
}
/*
** Special case check to ensure that GDI doesn't get the bazooka guy
** until mission #8.
*/
// J_D: until mission 7, they mean; changed so if "Extra Adjustments to Buildables" is on, it's until mission 5 only
int gdiE3thresh = (ActiveCFEPatchConfig.JDExtraAdjustments) ? 5 : 7;
if (house == HOUSE_GOOD &&
type->What_Am_I() == RTTI_INFANTRYTYPE &&
((InfantryTypeClass const *)type)->Type == INFANTRY_E3 &&
level < gdiE3thresh) {
return(false);
}
/*
** Special check to allow GDI to build the MSAM by mission #9
** and no sooner.
*/
if (house == HOUSE_GOOD &&
type->What_Am_I() == RTTI_UNITTYPE &&
((UnitTypeClass const *)type)->Type == UNIT_MLRS &&
level < 9) {
return(false);
}
/*
** Special case to disable the APC from the Nod player.
*/
if (house == HOUSE_BAD &&
type->What_Am_I() == RTTI_UNITTYPE &&
((UnitTypeClass const *)type)->Type == UNIT_APC) {
return(false);
}
/*
** Ensure that the Temple of Nod cannot be built by GDI even
** if GDI has captured the Nod construction yard.
*/
if (type->What_Am_I() == RTTI_BUILDINGTYPE &&
(((BuildingTypeClass const *)type)->Type == STRUCT_TEMPLE || ((BuildingTypeClass const *)type)->Type == STRUCT_OBELISK) &&
Class->House == HOUSE_GOOD &&
!ActiveCFEPatchConfig.BuildForbiddenSPCapturables
) {
return(false);
}
/*
** Ensure that the rocket launcher tank cannot be built by Nod.
*/
if (type->What_Am_I() == RTTI_UNITTYPE &&
((UnitTypeClass const *)type)->Type == UNIT_MLRS &&
Class->House == HOUSE_BAD) {
return(false);
}
/*
** Ensure that the ion cannon cannot be built if
** Nod has captured the GDI construction yard.
*/
if (type->What_Am_I() == RTTI_BUILDINGTYPE &&
(((BuildingTypeClass const *)type)->Type == STRUCT_EYE) &&
Class->House == HOUSE_BAD &&
!ActiveCFEPatchConfig.BuildForbiddenSPCapturables
) {
return(false);
}
/*
** Nod can build the advanced power plant at scenario #12.
*/
if (house == HOUSE_BAD &&
level >= 12 &&
type->What_Am_I() == RTTI_BUILDINGTYPE &&
((BuildingTypeClass const *)type)->Type == STRUCT_ADVANCED_POWER) {
level = type->Scenario;
}
/*
** Nod cannot build a helipad in the normal game.
*/
if ((house == HOUSE_BAD) &&
(type->What_Am_I() == RTTI_BUILDINGTYPE) &&
(((BuildingTypeClass const *)type)->Type == STRUCT_HELIPAD) &&
!ActiveCFEPatchConfig.MPUnitsInSP // Chthon CFE Note: allow helipads in SP if enabled via mod
) {
return(false);
}
/*
** GDI can build the sandbag wall only from scenario #9 onwards.
*/
// J_D: scenario 8 onwards, they mean; changed so if "Extra Adjustments to Buildables" is on, this GoodGuy-only restriction doesn't apply
if (!ActiveCFEPatchConfig.JDExtraAdjustments &&
(house == HOUSE_GOOD) &&
(level < 8) &&
(type->What_Am_I() == RTTI_BUILDINGTYPE) &&
(((BuildingTypeClass const *)type)->Type == STRUCT_SANDBAG_WALL)
) {
return(false);
}
/*
** GDI has a special second training mission. Adjust the scenario level so that
** scenario two will still feel like scenario #1.
*/
if (house == HOUSE_GOOD && Scenario == 2) { // J_D: Scenario instead of level so that GDI build level 2 is available to mission-makers
level = 1;
}
// ST - 8/23/2019 4:53PM
if (DebugUnlockBuildables) {
level = 98;
pre = 0;
}
if (Debug_Cheat) level = 98;
return((pre & flags) == pre && type->Scenario <= level);
}
/***********************************************************************************************
* HouseClass::Can_Build -- Determines if the building type can be built. *
* *
* This routine is used by the construction preparation code to building a list of building *
* types that can be built. It determines if a building can be built by checking if the *
* prerequisite buildings have been built (and still exist) as well as checking to see if *
* the house can build the specified structure. *
* *
* INPUT: s -- The structure type number that is being checked. *
* *
* house -- The house number to use when determining if the object can be built. *
* This is necessary because the current owner of the factory doesn't *
* control what the factory can produce. Rather, the original builder of *
* the factory controls this. *
* *
* OUTPUT: bool; Can this structure type be built at this time? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/08/1994 JLB : Created. *
* 05/31/1995 JLB : Handles specified ownership override. *
*=============================================================================================*/
bool HouseClass::Can_Build(StructType s, HousesType house) const
{
Validate();
return(Can_Build(&BuildingTypeClass::As_Reference(s), house));
}
/***********************************************************************************************
* HouseClass::Can_Build -- Determines if the infantry unit can be built by this house. *
* *
* Use this routine to determine if the infantry type specified can be built by this *
* house. It determines this by checking the ownership allowed bits in the infantry *
* type class. *
* *
* INPUT: infantry -- The infantry type to check against this house. *
* *
* house -- The house number to use when determining if the object can be built. *
* This is necessary because the current owner of the factory doesn't *
* control what the factory can produce. Rather, the original builder of *
* the factory controls this. *
* *
* OUTPUT: bool; Can the infantry be produced by this house? *
* *
* WARNINGS: It does not check to see if there is a functional barracks available, but *
* merely checks to see if it is legal for this house to build that infantry *
* type. *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
* 05/31/1995 JLB : Handles specified ownership override. *
*=============================================================================================*/
bool HouseClass::Can_Build(InfantryType infantry, HousesType house) const
{
Validate();
return(Can_Build(&InfantryTypeClass::As_Reference(infantry), house));
}
/***********************************************************************************************
* HouseClass::Can_Build -- Determines if the unit can be built by this house. *
* *
* This routine is used to determine if the unit type specified can in fact be built by *
* this house. It checks the ownable bits in the unit's type to determine this. *
* *
* INPUT: unit -- The unit type to check against this house. *
* *
* house -- The house number to use when determining if the object can be built. *
* This is necessary because the current owner of the factory doesn't *
* control what the factory can produce. Rather, the original builder of *
* the factory controls this. *
* *
* OUTPUT: bool; Can the unit be built by this house? *
* *
* WARNINGS: This doesn't check to see if there is a functional factory that can build *
* this unit, but merely if the unit can be built according to ownership rules. *
* *
* HISTORY: *
* 12/09/1994 JLB : Created. *
* 05/31/1995 JLB : Handles specified ownership override. *
*=============================================================================================*/
bool HouseClass::Can_Build(UnitType unit, HousesType house) const
{
Validate();
return(Can_Build(&UnitTypeClass::As_Reference(unit), house));
}
/***********************************************************************************************
* HouseClass::Can_Build -- Determines if the aircraft type can be built. *
* *
* Use this routine to determine if the specified aircraft type can be built. This routine *
* is used by the sidebar and factory to determine what can be built. *
* *
* INPUT: aircraft -- The aircraft type to check for build legality. *
* *
* house -- The house that is performing the check. This is typically the house *
* of the original building of the factory rather than the current *
* owner. *
* *
* OUTPUT: Can this aircraft type be built by the house specified? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/24/1995 JLB : Created. *
*=============================================================================================*/
bool HouseClass::Can_Build(AircraftType aircraft, HousesType house) const
{
Validate();
return(Can_Build(&AircraftTypeClass::As_Reference(aircraft), house));
}
/***************************************************************************
* HouseClass::Init -- init's in preparation for new scenario *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* none. *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 12/07/1994 BR : Created. *
* 12/17/1994 JLB : Resets tracker bits. *
*=========================================================================*/
void HouseClass::Init(void)
{
Houses.Free_All();
for (HousesType index = HOUSE_FIRST; index < HOUSE_COUNT; index++) {
HouseTriggers[index].Clear();
}
}
// Object selection list is switched with player context for GlyphX. ST - 4/17/2019 9:42AM
extern void Logic_Switch_Player_Context(HouseClass *house);
/***********************************************************************************************
* HouseClass::AI -- Process house logic. *
* *
* This handles the AI for the house object. It should be called once per house per game *
* tick. It processes all house global tasks such as low power damage accumulation and *
* house specific trigger events. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/27/1994 JLB : Created. *
* 07/17/1995 JLB : Limits EVA speaking unless the player can do something. *
*=============================================================================================*/
extern void Recalculate_Placement_Distances();
extern void On_Message(const char* message, float timeout_seconds, long long message_id);
void HouseClass::AI(void)
{
Validate();
// Set PlayerPtr to be this house. Not really keen on this solution but it means I have to make fewer code changes to the original code. ST - 4/17/2019 4:32PM
Logic_Switch_Player_Context(this);
// Chthon CFE Note: Announce mod version for all players
if ((Frame == 75) && IsHuman && ActiveCFEPatchConfig.EnableVersionAnnounce){
#ifdef CFE_TEST_BUILD
char text[] = "CFE Patch Redux version 1.9 TEST BUILD 9";
#else
char text[] = "CFE Patch Redux version 1.9";
#endif
On_Message(text, 20.0f, TXT_YOURGAME_OUTDATED);
}
/*
** Reset the scan accumulation bits for the next logic pass.
*/
IScan = NewIScan;
BScan = NewBScan;
UScan = NewUScan;
AScan = NewAScan;
ActiveIScan = NewActiveIScan;
ActiveBScan = NewActiveBScan;