/
researchdef.h
166 lines (145 loc) · 6.62 KB
/
researchdef.h
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
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2017 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
*/
/** \file
* Definitions for research data.
*/
#ifndef __INCLUDED_RESEARCHDEF_H__
#define __INCLUDED_RESEARCHDEF_H__
#include "lib/framework/frame.h"
#include "statsdef.h"
#include "lib/framework/wzconfig.h"
struct VIEWDATA;
/* Research struct type definitions */
enum TECH_CODE
{
TC_MAJOR,
TC_MINOR,
};
struct RES_COMP_REPLACEMENT
{
COMPONENT_STATS *pOldComponent;
COMPONENT_STATS *pNewComponent;
};
struct RESEARCH : public BASE_STATS
{
UBYTE techCode;
UWORD subGroup; /* Subgroup of the item - an iconID from 'Framer' to depict in the button*/
UWORD researchPoints; /* Number of research points required to
complete the research */
UDWORD researchPower; /* Power cost to research */
UBYTE keyTopic; /* Flag to indicate whether in single player
this topic must be explicitly enabled*/
std::vector<UWORD> pPRList; ///< List of research pre-requisites
std::vector<UWORD> pStructList; ///< List of structures that when built would enable this research
std::vector<UWORD> pRedStructs; ///< List of Structures that become redundant
std::vector<COMPONENT_STATS *> pRedArtefacts; ///< List of Artefacts that become redundant
std::vector<UWORD> pStructureResults; ///< List of Structures that are possible after this research
QList<COMPONENT_STATS *> componentResults; ///< List of Components that are possible after this research
QList<RES_COMP_REPLACEMENT> componentReplacement; ///< List of Components that are automatically replaced with new onew after research
nlohmann::json results; ///< Research upgrades
VIEWDATA *pViewData; ///< Data used to display a message in the Intelligence Screen
UWORD iconID; /* the ID from 'Framer' for which graphic to draw in interface*/
BASE_STATS *psStat; /* A stat used to define which graphic is drawn instead of the two fields below */
iIMDShape *pIMD; /* the IMD to draw for this research topic */
iIMDShape *pIMD2; /* the 2nd IMD for base plates/turrets*/
int index; ///< Unique index for this research, set incrementally
RESEARCH() : pViewData(nullptr), iconID(0), psStat(nullptr), pIMD(nullptr), pIMD2(nullptr) {}
};
struct PLAYER_RESEARCH
{
UDWORD currentPoints; // If the research has been suspended then this value contains the number of points generated at the suspension/cancel point
// normally it is null
UBYTE ResearchStatus; // Bit flags ... see below
bool possible; ///< is the research possible ... so can enable topics vis scripts
};
#define STARTED_RESEARCH 0x01 // research in progress
#define CANCELLED_RESEARCH 0x02 // research has been canceled
#define RESEARCHED 0x04 // research is complete
#define CANCELLED_RESEARCH_PENDING 0x08 // research almost cancelled, waiting for GAME_RESEARCHSTATUS message to be processed.
#define STARTED_RESEARCH_PENDING 0x10 // research almost in progress, waiting for GAME_RESEARCHSTATUS message to be processed.
#define RESBITS (STARTED_RESEARCH|CANCELLED_RESEARCH|RESEARCHED)
#define RESBITS_PENDING_ONLY (STARTED_RESEARCH_PENDING|CANCELLED_RESEARCH_PENDING)
#define RESBITS_PENDING (RESBITS|RESBITS_PENDING_ONLY)
static inline bool IsResearchPossible(const PLAYER_RESEARCH *research)
{
return research->possible;
}
static inline void MakeResearchPossible(PLAYER_RESEARCH *research)
{
research->possible = true;
}
static inline bool IsResearchCompleted(PLAYER_RESEARCH const *x)
{
return (x->ResearchStatus & RESEARCHED) != 0;
}
static inline bool IsResearchCancelled(PLAYER_RESEARCH const *x)
{
return (x->ResearchStatus & CANCELLED_RESEARCH) != 0;
}
static inline bool IsResearchStarted(PLAYER_RESEARCH const *x)
{
return (x->ResearchStatus & STARTED_RESEARCH) != 0;
}
/// Pending means not yet synchronised, so only permitted to affect the UI, not the game state.
static inline bool IsResearchCancelledPending(PLAYER_RESEARCH const *x)
{
return (x->ResearchStatus & RESBITS_PENDING_ONLY) != 0 ?
(x->ResearchStatus & CANCELLED_RESEARCH_PENDING) != 0 :
(x->ResearchStatus & CANCELLED_RESEARCH) != 0;
}
static inline bool IsResearchStartedPending(PLAYER_RESEARCH const *x)
{
return (x->ResearchStatus & RESBITS_PENDING_ONLY) != 0 ?
(x->ResearchStatus & STARTED_RESEARCH_PENDING) != 0 :
(x->ResearchStatus & STARTED_RESEARCH) != 0;
}
static inline void MakeResearchCompleted(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING;
x->ResearchStatus |= RESEARCHED;
}
static inline void MakeResearchCancelled(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING;
x->ResearchStatus |= CANCELLED_RESEARCH;
}
static inline void MakeResearchStarted(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING;
x->ResearchStatus |= STARTED_RESEARCH;
}
/// Pending means not yet synchronised, so only permitted to affect the UI, not the game state.
static inline void MakeResearchCancelledPending(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING_ONLY;
x->ResearchStatus |= CANCELLED_RESEARCH_PENDING;
}
static inline void MakeResearchStartedPending(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING_ONLY;
x->ResearchStatus |= STARTED_RESEARCH_PENDING;
}
static inline void ResetPendingResearchStatus(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING_ONLY;
}
/// clear all bits in the status except for the possible bit
static inline void ResetResearchStatus(PLAYER_RESEARCH *x)
{
x->ResearchStatus &= ~RESBITS_PENDING;
}
#endif // __INCLUDED_RESEARCHDEF_H__