forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresearch.cpp
2079 lines (1897 loc) · 56.9 KB
/
research.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
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 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 2 of the License, or
(at your option) any later version.
Warzone 2100 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 Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Research.c
*
* Research tree and functions!
*
*/
#include <string.h>
#include "lib/framework/frame.h"
#include "lib/framework/strres.h"
#include "lib/framework/frameresource.h"
#include "objects.h"
#include "lib/gamelib/gtime.h"
#include "research.h"
#include "message.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
#include "lib/script/script.h"
#include "scripttabs.h"
#include "hci.h"
#include "console.h"
#include "cmddroid.h"
#include "power.h"
#include "mission.h"
#include "frend.h" // frontend ids.
#include "intimage.h"
#include "multiplay.h"
#include "template.h"
#include "qtscript.h"
//used to calc the research power
#define RESEARCH_FACTOR 32
#define RESEARCH_MAX_POWER 450
// The stores for the research stats
std::vector<RESEARCH> asResearch;
//used for Callbacks to say which topic was last researched
RESEARCH *psCBLastResearch;
STRUCTURE *psCBLastResStructure;
SDWORD CBResFacilityOwner;
//List of pointers to arrays of PLAYER_RESEARCH[numResearch] for each player
std::vector<PLAYER_RESEARCH> asPlayerResList[MAX_PLAYERS];
/* Default level of sensor, Repair and ECM */
UDWORD aDefaultSensor[MAX_PLAYERS];
UDWORD aDefaultECM[MAX_PLAYERS];
UDWORD aDefaultRepair[MAX_PLAYERS];
//set the iconID based on the name read in in the stats
static UWORD setIconID(char *pIconName, char *pName);
static COMPONENT_STATS * getComponentDetails(char *pName, char *pCompName);
static void replaceComponent(COMPONENT_STATS *pNewComponent, COMPONENT_STATS *pOldComponent,
UBYTE player);
static bool checkResearchName(RESEARCH *psRes, UDWORD numStats);
static const char *getResearchName(RESEARCH *pResearch)
{
return(getName(pResearch->pName));
}
//flag that indicates whether the player can self repair
static UBYTE bSelfRepair[MAX_PLAYERS];
static void replaceDroidComponent(DROID *pList, UDWORD oldType, UDWORD oldCompInc,
UDWORD newCompInc);
static void replaceStructureComponent(STRUCTURE *pList, UDWORD oldType, UDWORD oldCompInc,
UDWORD newCompInc, UBYTE player);
static void switchComponent(DROID *psDroid,UDWORD oldType, UDWORD oldCompInc,
UDWORD newCompInc);
static void replaceTransDroidComponents(DROID *psTransporter, UDWORD oldType,
UDWORD oldCompInc, UDWORD newCompInc);
bool researchInitVars(void)
{
psCBLastResearch = NULL;
psCBLastResStructure = NULL;
CBResFacilityOwner = -1;
asResearch.clear();
for (int i = 0; i < MAX_PLAYERS; i++)
{
bSelfRepair[i] = false;
aDefaultSensor[i] = 0;
aDefaultECM[i] = 0;
aDefaultRepair[i] = 0;
}
return true;
}
/** Load the research stats */
bool loadResearch(const char *pResearchData, UDWORD bufferSize)
{
unsigned int researchCount = numCR(pResearchData, bufferSize);
COMPONENT_STATS *psComp;
SDWORD structID;
UDWORD i, keyTopic, techCode, resPoints;
char ResearchName[MAX_STR_LENGTH];
char msgName[MAX_STR_LENGTH], iconID[MAX_STR_LENGTH];
char imdName[MAX_STR_LENGTH], imdName2[MAX_STR_LENGTH];
char structName[MAX_STR_LENGTH], compName[MAX_STR_LENGTH],
compType[MAX_STR_LENGTH];
PLAYER_RESEARCH dummy;
memset(&dummy, 0, sizeof(dummy));
// Skip descriptive header
if (strncmp(pResearchData,"Research ",9)==0)
{
pResearchData = strchr(pResearchData,'\n') + 1;
researchCount--;
}
for (i = 0; i < researchCount; i++)
{
// HACK FIXME: the code assumes we have empty PLAYER_RESEARCH entries to throw around
for (int j = 0; j < MAX_PLAYERS; j++)
{
asPlayerResList[j].push_back(dummy);
}
RESEARCH research;
research.index = i;
//read the data into the storage - the data is delimeted using comma's
ResearchName[0] = '\0';
sscanf(pResearchData,"%255[^,'\r\n],", ResearchName);
//allocate storage for the name
research.pName = allocateName(ResearchName);
ASSERT_OR_RETURN(false, research.pName != NULL, "Failed allocating research name");
//check the name hasn't been used already
ASSERT_OR_RETURN(false, checkResearchName(&research, i), "Research name %s used already", research.pName);
pResearchData += (strlen(ResearchName)+1);
research.ref = REF_RESEARCH_START + i;
//determine the tech level (unused, so we don't use the resulting string)
ResearchName[0] = '\0';
sscanf(pResearchData,"%255[^,'\r\n],", ResearchName);
pResearchData += (strlen(ResearchName)+1);
ResearchName[0] = '\0';
sscanf(pResearchData,"%255[^,'\r\n],", ResearchName);
if (strcmp(ResearchName, "0"))
{
research.subGroup = setIconID(ResearchName, research.pName);
}
else
{
research.subGroup = NO_RESEARCH_ICON;
}
pResearchData += (strlen(ResearchName)+1);
iconID[0] = '\0';
imdName[0] = '\0';
imdName2[0] = '\0';
msgName[0] = '\0';
structName[0] = '\0';
compName[0] = '\0';
compType[0] = '\0';
{
UDWORD numPRRequired;
UDWORD numFunctions;
UDWORD numStructures;
UDWORD numRedStructs;
UDWORD numStructResults;
UDWORD numRedArtefacts;
UDWORD numArteResults;
sscanf(pResearchData,"%d,%255[^,'\r\n],%255[^,'\r\n],%255[^,'\r\n],%255[^,'\r\n],%255[^,'\r\n], \
%255[^,'\r\n],%255[^,'\r\n],%d,%d,%d,%d,%d,%d,%d,%d,%d",
&techCode, iconID, imdName, imdName2, msgName,
structName, compName, compType,
&resPoints, &keyTopic, &numPRRequired,
&numFunctions, &numStructures,
&numRedStructs, &numStructResults,
&numRedArtefacts, &numArteResults);
}
//set keytopic flag
if (keyTopic)
{
research.keyTopic = true;
}
else
{
research.keyTopic = false;
}
//check the tech code is valid
ASSERT_OR_RETURN(false, techCode <= 1, "Invalid tech code for research topic - %s ", getResearchName(&research));
if (techCode == 0)
{
research.techCode = TC_MAJOR;
}
else
{
research.techCode = TC_MINOR;
}
//set the iconID
if (strcmp(iconID, "0"))
{
research.iconID = setIconID(iconID, research.pName);
}
else
{
research.iconID = NO_RESEARCH_ICON;
}
//get the IMDs used in the interface
if (strcmp(structName, "0"))
{
//find the structure stat
structID = getStructStatFromName(structName);
ASSERT_OR_RETURN(false, structID >= 0, "Cannot find the structure Stat for Research %s", getResearchName(&research));
research.psStat = (BASE_STATS *)(asStructureStats + structID);
}
else if (strcmp(compName, "0"))
{
//find the component stat
psComp = getComponentDetails(compType, compName);
ASSERT_OR_RETURN(false, psComp != NULL, "Cannot find the component Stat for Research %s", getResearchName(&research));
research.psStat = (BASE_STATS *)psComp;
}
else
{
research.psStat = NULL;
}
if (strcmp(imdName, "0"))
{
research.pIMD = (iIMDShape *) resGetData("IMD", imdName);
ASSERT_OR_RETURN(false, research.pIMD != NULL, "Cannot find the research PIE for record %s", getResearchName(&research));
}
else
{
research.pIMD = NULL;
}
if (strcmp(imdName2, "0"))
{
research.pIMD2 = (iIMDShape *) resGetData("IMD", imdName2);
ASSERT_OR_RETURN(false, research.pIMD2 != NULL, "Cannot find the 2nd research PIE for record %s", getResearchName(&research));
}
else
{
research.pIMD2 = NULL;
}
//get the message viewdata - if any
if (strcmp(msgName, "0"))
{
//check its a major tech code
ASSERT(research.techCode == TC_MAJOR, "This research should not have a message associated with it, %s the message will be ignored!", getResearchName(&research));
if (research.techCode == TC_MAJOR)
{
research.pViewData = getViewData(msgName);
}
}
//set the researchPoints
ASSERT_OR_RETURN(false, resPoints <= UWORD_MAX, "Research Points too high for research topic - %s ", getResearchName(&research));
research.researchPoints = (UWORD)resPoints;
//set the research power
research.researchPower = research.researchPoints / RESEARCH_FACTOR;
if (research.researchPower > RESEARCH_MAX_POWER)
{
research.researchPower = RESEARCH_MAX_POWER;
}
//increment the pointer to the start of the next record
pResearchData = strchr(pResearchData,'\n') + 1;
asResearch.push_back(research);
}
return true;
}
//Load the pre-requisites for a research list
bool loadResearchPR(const char *pPRData, UDWORD bufferSize)
{
unsigned NumToAlloc = numCR(pPRData, bufferSize);
char ResearchName[MAX_STR_LENGTH], PRName[MAX_STR_LENGTH];
for (int i = 0; i < NumToAlloc; i++)
{
bool recFound = false;
//read the data into the storage - the data is delimited using commas
ResearchName[0] = '\0';
PRName[0] = '\0';
sscanf(pPRData,"%255[^,'\r\n],%255[^,'\r\n],%*d", ResearchName, PRName);
//loop through each Research to compare the name
for (int incR = 0; incR < asResearch.size(); incR++)
{
if (!(strcmp(ResearchName, asResearch[incR].pName)))
{
//Research found
for (int incPR = 0; incPR < asResearch.size(); incPR++)
{
if (!(strcmp(PRName, asResearch[incPR].pName)))
{
//PRresearch found alloc this to the current Research
asResearch[incR].pPRList.push_back(incPR);
recFound = true;
break;
}
}
ASSERT_OR_RETURN(false, recFound, "Unable to find Pre-requisite %s for research %s", PRName, ResearchName);
break;
}
}
ASSERT_OR_RETURN(false, recFound, "Unable to find Research %s", ResearchName);
// increment the pointer to the start of the next record
pPRData = strchr(pPRData,'\n') + 1;
}
return true;
}
//Load the artefacts for a research list
bool loadResearchArtefacts(const char *pArteData, UDWORD bufferSize, UDWORD listNumber)
{
unsigned NumToAlloc = numCR(pArteData, bufferSize);
char ResearchName[MAX_STR_LENGTH], ArteName[MAX_STR_LENGTH], TypeName[MAX_STR_LENGTH];
COMPONENT_STATS *pArtefact;
UDWORD newType;
// Skip descriptive header
if (strncmp(pArteData, "Research ", 9) == 0)
{
pArteData = strchr(pArteData, '\n') + 1;
NumToAlloc--;
}
for (int i = 0; i < NumToAlloc; i++)
{
//read the data into the storage - the data is delimited using commas
ResearchName[0] = '\0';
ArteName[0] = '\0';
TypeName[0] = '\0';
sscanf(pArteData,"%255[^,'\r\n],%255[^,'\r\n],%255[^,'\r\n]", ResearchName, ArteName, TypeName);
//increment the data pointer
pArteData += (strlen(ResearchName)+1+strlen(ArteName)+1+strlen(TypeName)+1);
pArtefact = getComponentDetails(TypeName, ArteName);
if (pArtefact == NULL)
{
return false;
}
//get the type for comparison later
newType = statType(pArtefact->ref);
RESEARCH *pResearch = getResearch(ResearchName);
if (pResearch == NULL)
{
return false;
}
//ArtefactResearch found - alloc the artefact to the current Research topic
switch (listNumber)
{
case RED_LIST:
pResearch->pRedArtefacts.push_back(pArtefact);
break;
case RES_LIST:
pResearch->pArtefactResults.push_back(pArtefact);
break;
default:
debug( LOG_ERROR, "Unknown research list" );
abort();
return false;
}
//deal with extra data
switch (listNumber)
{
case RED_LIST:
//ignore the last character
sscanf(pArteData,",%*d");
break;
case RES_LIST:
ArteName[0] = '\0';
TypeName[0] = '\0';
sscanf(pArteData, "%255[^,'\r\n],%255[^,'\r\n],%*d", ArteName, TypeName);
if (!strcmp(ArteName, "0"))
{
pResearch->pReplacedArtefacts.push_back(NULL);
}
else
{
pArtefact = getComponentDetails(TypeName, ArteName);
if (pArtefact == NULL)
{
return false;
}
//check the old and new types are the same
if (statType(pArtefact->ref) != newType)
{
debug( LOG_ERROR, "You are trying to replace one type of component with a different type for research %s in ResultComponents.txt", ResearchName );
abort();
return false;
}
// ArtefactResearch found - alloc the artefact to the current Research topic
pResearch->pReplacedArtefacts.push_back(pArtefact);
}
break;
default:
debug( LOG_ERROR, "Unknown research list" );
abort();
return false;
}
//increment the pointer to the start of the next record
pArteData = strchr(pArteData,'\n') + 1;
}
return true;
}
//Load the Structures for a research list
bool loadResearchStructures(const char *pStructData, UDWORD bufferSize,UDWORD listNumber)
{
unsigned NumToAlloc = numCR(pStructData, bufferSize);
unsigned int i = 0;
char ResearchName[MAX_STR_LENGTH], StructureName[MAX_STR_LENGTH];
UWORD incR, incS;
STRUCTURE_STATS *pStructure = asStructureStats;
bool recFound;
// Skip descriptive header
if (strncmp(pStructData, "Research ", 9) == 0)
{
pStructData = strchr(pStructData, '\n') + 1;
NumToAlloc--;
}
for (i = 0; i < NumToAlloc; i++)
{
recFound = false;
//read the data into the storage - the data is delimited using comma's
ResearchName[0] = '\0';
StructureName[0] = '\0';
sscanf(pStructData,"%255[^,'\r\n],%255[^,'\r\n],%*d,%*d", ResearchName, StructureName);
//loop through each Research to compare the name
for (incR = 0; incR < asResearch.size(); incR++)
{
if (!(strcmp(ResearchName, asResearch[incR].pName)))
{
//Research found
for (incS = 0; incS < numStructureStats; incS++)
{
if (!(strcmp(StructureName, pStructure[incS].pName)))
{
//Structure found - alloc this to the current Research
switch (listNumber)
{
case REQ_LIST:
asResearch[incR].pStructList.push_back(incS);
break;
case RED_LIST:
asResearch[incR].pRedStructs.push_back(incS);
break;
case RES_LIST:
asResearch[incR].pStructureResults.push_back(incS);
break;
default:
/* NO DEFAULT CASE? Alex.... Here ya go - just for you...*/
debug( LOG_FATAL, "Unknown research list" );
abort();
return false;
}
recFound = true;
break;
}
}
//if Structure not found - error
if (!recFound)
{
debug(LOG_FATAL, "Unable to find Structure %s for research %s", StructureName, ResearchName);
return false;
}
else
{
break;
}
}
}
//if Research not found - error
if (!recFound)
{
debug(LOG_FATAL, "Unable to allocate all Research Structures for %s", ResearchName);
return false;
}
//increment the pointer to the start of the next record
pStructData = strchr(pStructData,'\n') + 1;
}
return true;
}
//Load the pre-requisites for a research list
bool loadResearchFunctions(const char *pFunctionData, UDWORD bufferSize)
{
unsigned NumToAlloc = numCR(pFunctionData, bufferSize);
unsigned int i = 0;
char ResearchName[MAX_STR_LENGTH], FunctionName[MAX_STR_LENGTH];
UDWORD incR, incF;
FUNCTION **pFunction = asFunctions;
bool recFound;
// Skip descriptive header
if (strncmp(pFunctionData, "Research ", 9) == 0)
{
pFunctionData = strchr(pFunctionData, '\n') + 1;
NumToAlloc--;
}
for (i=0; i < NumToAlloc; i++)
{
recFound = false;
//read the data into the storage - the data is delimited using comma's
ResearchName[0] = '\0';
FunctionName[0] = '\0';
sscanf(pFunctionData,"%255[^,'\r\n],%255[^,'\r\n],%*d", ResearchName, FunctionName);
//loop through each Research to compare the name
for (incR=0; incR < asResearch.size(); incR++)
{
if (!(strcmp(ResearchName, asResearch[incR].pName)))
{
//Research found
for (incF=0; incF < numFunctions; incF++)
{
if (!(strcmp(FunctionName, (*pFunction[incF]).pName)))
{
// Function found alloc this to the current Research
asResearch[incR].pFunctionList.push_back(pFunction[incF]);
recFound = true;
break;
}
}
//if Function not found - error
if (!recFound)
{
debug( LOG_ERROR, "Unable to find Function %s for research %s", FunctionName, ResearchName );
abort();
return false;
}
else
{
break;
}
}
}
//if Research not found - error
if (!recFound)
{
debug( LOG_ERROR, "Unable to allocate all research Functions for %s", ResearchName );
abort();
return false;
}
//increment the pointer to the start of the next record
pFunctionData = strchr(pFunctionData,'\n') + 1;
}
return true;
}
bool researchAvailable(int inc, int playerID)
{
UDWORD incPR, incS;
bool bPRFound, bStructFound;
// if its a cancelled topic - add to list
if (IsResearchCancelledPending(&asPlayerResList[playerID][inc]))
{
return true;
}
// if the topic is possible and has not already been researched - add to list
if ((IsResearchPossible(&asPlayerResList[playerID][inc])))
{
if (!IsResearchCompleted(&asPlayerResList[playerID][inc])
&& !IsResearchStartedPending(&asPlayerResList[playerID][inc]))
{
return true;
}
}
// if single player mode and key topic, then ignore cos can't do it!
if (!bMultiPlayer && asResearch[inc].keyTopic)
{
return false;
}
// make sure that the research is not completed or started by another researchfac
if (!IsResearchCompleted(&asPlayerResList[playerID][inc]) && !IsResearchStartedPending(&asPlayerResList[playerID][inc]))
{
// Research is not completed ... also it has not been started by another researchfac
// if there aren't any PR's - go to next topic
if (asResearch[inc].pPRList.empty())
{
return false;
}
// check for pre-requisites
bPRFound = true;
for (incPR = 0; incPR < asResearch[inc].pPRList.size(); incPR++)
{
if (IsResearchCompleted(&(asPlayerResList[playerID][asResearch[inc].pPRList[incPR]]))==0)
{
// if haven't pre-requisite - quit checking rest
bPRFound = false;
break;
}
}
if (!bPRFound)
{
// if haven't pre-requisites, skip the rest of the checks
return false;
}
// check for structure effects
bStructFound = true;
for (incS = 0; incS < asResearch[inc].pStructList.size(); incS++)
{
if (!checkSpecificStructExists(asResearch[inc].pStructList[incS], playerID))
{
//if not built, quit checking
bStructFound = false;
break;
}
}
if (!bStructFound)
{
// if haven't all structs built, skip to next topic
return false;
}
return true;
}
return false;
}
/*
Function to check what can be researched for a particular player at any one
instant.
A topic can be researched if the playerRes 'possible' flag has been set (by script)
or if the research pre-req topics have been researched. A check is made for any
structures that are required to have been built for topics that do not have
the 'possible' flag set.
**NB** A topic with zero PR's can ONLY be researched once the 'possible' flag
has been set.
There can only be 'limit' number of entries
'topic' is the currently researched topic
*/
// NOTE by AJL may 99 - skirmish now has it's own version of this, skTopicAvail.
UWORD fillResearchList(UWORD *plist, UDWORD playerID, UWORD topic, UWORD limit)
{
UWORD inc, count=0;
for (inc=0; inc < asResearch.size(); inc++)
{
// if the inc matches the 'topic' - automatically add to the list
if (inc == topic || researchAvailable(inc, playerID))
{
*plist++ = inc;
count++;
if (count == limit)
{
return count;
}
}
}
return count;
}
/* process the results of a completed research topic */
void researchResult(UDWORD researchIndex, UBYTE player, bool bDisplay, STRUCTURE *psResearchFacility, bool bTrigger)
{
RESEARCH * pResearch = &asResearch[researchIndex];
UDWORD type, inc;
STRUCTURE *psCurr;
DROID *psDroid;
FUNCTION *pFunction;
UDWORD compInc;
MESSAGE *pMessage;
//the message gets sent to console
char consoleMsg[MAX_RESEARCH_MSG_SIZE];
ASSERT_OR_RETURN( , researchIndex < asResearch.size(), "Invalid research index %u", researchIndex);
MakeResearchCompleted(&asPlayerResList[player][researchIndex]);
//check for structures to be made available
for (inc = 0; inc < pResearch->pStructureResults.size(); inc++)
{
if (apStructTypeLists[player][pResearch->pStructureResults[inc]] != REDUNDANT)
{
apStructTypeLists[player][pResearch->pStructureResults[inc]] = AVAILABLE;
}
}
//check for structures to be made redundant
for (inc = 0; inc < pResearch->pRedStructs.size(); inc++)
{
apStructTypeLists[player][pResearch->pRedStructs[inc]] = REDUNDANT;
}
//check for artefacts to be made available
for (inc = 0; inc < pResearch->pArtefactResults.size(); inc++)
{
//determine the type of artefact
type = statType(pResearch->pArtefactResults[inc]->ref);
//set the component state to AVAILABLE
compInc = pResearch->pArtefactResults[inc]->ref - statRefStart(type);
if (apCompLists[player][type][compInc] != REDUNDANT)
{
apCompLists[player][type][compInc] = AVAILABLE;
}
//check for default sensor
if (type == COMP_SENSOR)
{
if ((asSensorStats + compInc)->location == LOC_DEFAULT)
{
aDefaultSensor[player] = compInc;
}
}
//check for default ECM
if (type == COMP_ECM)
{
if ((asECMStats + compInc)->location == LOC_DEFAULT)
{
aDefaultECM[player] = compInc;
}
}
//check for default Repair
if (type == COMP_REPAIRUNIT)
{
if ((asRepairStats + compInc)->location == LOC_DEFAULT)
{
aDefaultRepair[player] = compInc;
}
}
//check if this component replaces an 'older' component
if (pResearch->pReplacedArtefacts[inc] != NULL)
{
replaceComponent(pResearch->pArtefactResults[inc], pResearch->pReplacedArtefacts[inc], player);
//set the 'old' component to unavailable
type = statType(pResearch->pReplacedArtefacts[inc]->ref);
//set the component state to REDUNDANT
compInc = pResearch->pReplacedArtefacts[inc]->ref - statRefStart(type);
apCompLists[player][type][compInc] = REDUNDANT;
}
//check if self repair has come on line
if (type == COMP_REPAIRUNIT)
{
if (asRepairStats[compInc].location == LOC_DEFAULT)
{
enableSelfRepair(player);
}
}
}
//check for artefacts to be made redundant
for (inc = 0; inc < pResearch->pRedArtefacts.size(); inc++)
{
// determine the type of artefact
type = statType(pResearch->pRedArtefacts[inc]->ref);
// set the component state to REDUNDANT
apCompLists[player][type][pResearch->pRedArtefacts[inc]->ref - statRefStart(type)] = REDUNDANT;
}
//check for technology effects
for (inc = 0; inc < pResearch->pFunctionList.size(); inc++)
{
pFunction = pResearch->pFunctionList[inc];
switch (pFunction->type)
{
case(PRODUCTION_UPGRADE_TYPE):
productionUpgrade(pFunction, player);
// search the list of players structures for a Factory
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if ((psCurr->pStructureType->type == REF_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->factory) ||
(psCurr->pStructureType->type == REF_CYBORG_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->cyborgFactory) ||
(psCurr->pStructureType->type == REF_VTOL_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->vtolFactory))
{
// upgrade the Output for the structure
structureProductionUpgrade(psCurr);
}
}
// and the mission structures
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if ((psCurr->pStructureType->type == REF_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->factory) ||
(psCurr->pStructureType->type == REF_CYBORG_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->cyborgFactory) ||
(psCurr->pStructureType->type == REF_VTOL_FACTORY &&
((PRODUCTION_UPGRADE_FUNCTION *)pFunction)->vtolFactory))
{
// upgrade the Output for the structure
structureProductionUpgrade(psCurr);
}
}
// message/sound in here for production boost
break;
case(RESEARCH_UPGRADE_TYPE):
researchUpgrade(pFunction, player);
//search the list of players structures for a Research Facility
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_RESEARCH)
{
// upgrade the research points
structureResearchUpgrade(psCurr);
}
}
// and the mission structures
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_RESEARCH)
{
// upgrade the research points
structureResearchUpgrade(psCurr);
}
}
// Stuff a message in here/sound whatever for research boost.
break;
case(POWER_UPGRADE_TYPE):
powerUpgrade(pFunction, player);
// search the list of players structures for a Power Gens
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_POWER_GEN)
{
// upgrade the power points
structurePowerUpgrade(psCurr);
}
}
// and the mission structure
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_POWER_GEN)
{
// upgrade the power points
structurePowerUpgrade(psCurr);
}
}
break;
case(REARM_UPGRADE_TYPE):
reArmUpgrade(pFunction, player);
// search the list of players structures for a ReArm pad
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_REARM_PAD)
{
// upgrade the rearm points
structureReArmUpgrade(psCurr);
}
}
// and the mission structure
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_REARM_PAD)
{
// upgrade the rearm points
structureReArmUpgrade(psCurr);
}
}
break;
case(REPAIR_UPGRADE_TYPE):
repairFacUpgrade(pFunction, player);
// search the list of players structures for a Power Gens
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_REPAIR_FACILITY)
{
// upgrade the repair points
structureRepairUpgrade(psCurr);
}
}
// and the mission structure
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
if (psCurr->pStructureType->type == REF_REPAIR_FACILITY)
{
// upgrade the repair points
structureRepairUpgrade(psCurr);
}
}
break;
case(WEAPON_UPGRADE_TYPE):
// for the current player, upgrade the weapon stats
weaponUpgrade(pFunction, player);
// message/sound for weapon upgrade
break;
case(DROIDSENSOR_UPGRADE_TYPE):
// for the current player, upgrade the sensor stats
sensorUpgrade(pFunction, player);
// for each structure in the player's list, upgrade the sensor stat
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
structureSensorUpgrade(psCurr);
}
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
structureSensorUpgrade(psCurr);
}
// for each droid in the player's list, upgrade the sensor stat
for (psDroid = apsDroidLists[player]; psDroid != NULL; psDroid = psDroid->psNext)
{
droidSensorUpgrade(psDroid);
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{
upgradeTransporterDroids(psDroid, droidSensorUpgrade);
}
}
for (psDroid = mission.apsDroidLists[player]; psDroid != NULL; psDroid = psDroid->psNext)
{
droidSensorUpgrade(psDroid);
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{
upgradeTransporterDroids(psDroid, droidSensorUpgrade);
}
}
for (psDroid = apsLimboDroids[player]; psDroid != NULL; psDroid = psDroid->psNext)
{
droidSensorUpgrade(psDroid);
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{
upgradeTransporterDroids(psDroid, droidSensorUpgrade);
}
}
// message/sound for sensor upgrade
break;
case(DROIDECM_UPGRADE_TYPE):
// for the current player, upgrade the ecm stats
ecmUpgrade(pFunction, player);
// for each structure in the player's list, upgrade the ecm stat
for (psCurr = apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
structureECMUpgrade(psCurr);
}
for (psCurr = mission.apsStructLists[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
structureECMUpgrade(psCurr);
}
// for each droid in the player's list, upgrade the ecm stat
for (psDroid = apsDroidLists[player]; psDroid != NULL; psDroid = psDroid->psNext)
{
droidECMUpgrade(psDroid);
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{
upgradeTransporterDroids(psDroid, droidECMUpgrade);
}
}
for (psDroid = mission.apsDroidLists[player]; psDroid != NULL; psDroid = psDroid->psNext)
{
droidECMUpgrade(psDroid);
if (psDroid->droidType == DROID_TRANSPORTER || psDroid->droidType == DROID_SUPERTRANSPORTER)
{