1 /*
2 	This file is part of Warzone 2100.
3 	Copyright (C) 1999-2004  Eidos Interactive
4 	Copyright (C) 2005-2020  Warzone 2100 Project
5 
6 	Warzone 2100 is free software; you can redistribute it and/or modify
7 	it under the terms of the GNU General Public License as published by
8 	the Free Software Foundation; either version 2 of the License, or
9 	(at your option) any later version.
10 
11 	Warzone 2100 is distributed in the hope that it will be useful,
12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 	GNU General Public License for more details.
15 
16 	You should have received a copy of the GNU General Public License
17 	along with Warzone 2100; if not, write to the Free Software
18 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /** @file
21  *  structures required for research stats
22  */
23 
24 #ifndef __INCLUDED_SRC_RESEARCH_H__
25 #define __INCLUDED_SRC_RESEARCH_H__
26 
27 #include <optional-lite/optional.hpp>
28 
29 #include "lib/framework/wzconfig.h"
30 
31 #include "objectdef.h"
32 
33 struct VIEWDATA;
34 
35 #define NO_RESEARCH_ICON 0
36 //max 'research complete' console message length
37 #define MAX_RESEARCH_MSG_SIZE 200
38 
39 //used for loading in the research stats into the appropriate list
40 enum
41 {
42 	REQ_LIST,
43 	RED_LIST,
44 	RES_LIST
45 };
46 
47 enum
48 {
49 	RID_ROCKET,
50 	RID_CANNON,
51 	RID_HOVERCRAFT,
52 	RID_ECM,
53 	RID_PLASCRETE,
54 	RID_TRACKS,
55 	RID_DROIDTECH,
56 	RID_WEAPONTECH,
57 	RID_COMPUTERTECH,
58 	RID_POWERTECH,
59 	RID_SYSTEMTECH,
60 	RID_STRUCTURETECH,
61 	RID_CYBORGTECH,
62 	RID_DEFENCE,
63 	RID_QUESTIONMARK,
64 	RID_GRPACC,
65 	RID_GRPUPG,
66 	RID_GRPREP,
67 	RID_GRPROF,
68 	RID_GRPDAM,
69 	RID_MAXRID
70 };
71 
72 /* The store for the research stats */
73 extern std::vector<RESEARCH> asResearch;
74 
75 //List of pointers to arrays of PLAYER_RESEARCH[numResearch] for each player
76 extern std::vector<PLAYER_RESEARCH> asPlayerResList[MAX_PLAYERS];
77 
78 //used for Callbacks to say which topic was last researched
79 extern RESEARCH				*psCBLastResearch;
80 extern STRUCTURE			*psCBLastResStructure;
81 extern SDWORD				CBResFacilityOwner;
82 
83 /* Default level of sensor, repair and ECM */
84 extern UDWORD	aDefaultSensor[MAX_PLAYERS];
85 extern UDWORD	aDefaultECM[MAX_PLAYERS];
86 extern UDWORD	aDefaultRepair[MAX_PLAYERS];
87 
88 bool loadResearch(WzConfig &ini);
89 
90 /*function to check what can be researched for a particular player at any one
91   instant. Returns the number to research*/
92 std::vector<uint16_t> fillResearchList(UDWORD playerID, nonstd::optional<UWORD> topic, UWORD limit);
93 
94 /* process the results of a completed research topic */
95 void researchResult(UDWORD researchIndex, UBYTE player, bool bDisplay, STRUCTURE *psResearchFacility, bool bTrigger);
96 
97 //this just inits all the research arrays
98 bool ResearchShutDown();
99 //this free the memory used for the research
100 void ResearchRelease();
101 
102 /* For a given view data get the research this is related to */
103 RESEARCH *getResearch(const char *pName);
104 
105 /* sets the status of the topic to cancelled and stores the current research
106    points accquired */
107 void cancelResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);
108 
109 /* For a given view data get the research this is related to */
110 RESEARCH *getResearchForMsg(const VIEWDATA *pViewData);
111 
112 /* Sets the 'possible' flag for a player's research so the topic will appear in
113 the research list next time the Research Facility is selected */
114 bool enableResearch(RESEARCH *psResearch, UDWORD player);
115 
116 /*find the last research topic of importance that the losing player did and
117 'give' the results to the reward player*/
118 void researchReward(UBYTE losingPlayer, UBYTE rewardPlayer);
119 
120 /*check to see if any research has been completed that enables self repair*/
121 bool selfRepairEnabled(UBYTE player);
122 
123 SDWORD	mapIconToRID(UDWORD iconID);
124 
125 /*puts research facility on hold*/
126 void holdResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);
127 /*release a research facility from hold*/
128 void releaseResearch(STRUCTURE *psBuilding, QUEUE_MODE mode);
129 
130 void enableSelfRepair(UBYTE player);
131 
132 void CancelAllResearch(UDWORD pl);
133 
134 bool researchInitVars();
135 
136 bool researchAvailable(int inc, int playerID, QUEUE_MODE mode);
137 
138 struct AllyResearch
139 {
140 	unsigned player;
141 	int completion;
142 	int powerNeeded;
143 	int timeToResearch;
144 	bool active;
145 };
146 std::vector<AllyResearch> const &listAllyResearch(unsigned ref);
147 
148 #endif // __INCLUDED_SRC_RESEARCH_H__
149