Advanced Strategic Command
research.h
Go to the documentation of this file.
1 /***************************************************************************
2  research.h - description
3  -------------------
4  begin : Tue Jan 23 2001
5  copyright : (C) 2001 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 
24 #ifndef researchH
25  #define researchH
26 
27  #include <cstring>
28  #include <map>
29 
30  #include "loki/Functor.h"
31  #include "loki/Typelist.h"
32 
33  #include "basestreaminterface.h"
34  #include "basictypes.h"
35  #include "typen.h"
36 
37 
38 class Research;
39 class Technology;
40 class Building;
41 class Vehicle;
42 class VehicleType;
43 class GameMap;
44 
46 
47 
49  typedef vector<IntRange> RequiredTechnologies;
51  RequiredTechnologies blockingTechnologies;
52 
53  RequiredTechnologies requiredTechnologies;
54  bool requireAllListedTechnologies;
55 
56  static bool eventually_available_single( const Research& res, list<const Technology*>* dependencies, list<int>& stack, int id );
57  public:
58  TechDependency(){ requireAllListedTechnologies = true; };
59 
60  bool available( const Research& research ) const;
61  typedef Loki::Functor<bool, LOKI_TYPELIST_1(int) > CheckTechAvailabilityFunctor;
63 
67  bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
68  bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
69 
70 
71  ASCString showDebug( const Research& research ) const;
72 
73  void read ( tnstream& stream );
74  void write ( tnstream& stream ) const;
75  void runTextIO ( PropertyContainer& pc);
76  bool empty() const { return requiredTechnologies.size() == 0; } ;
77 
79  void writeTreeOutput ( const ASCString& sourceTechName, tnstream& stream, bool reduce ) const;
80 
81  void writeInvertTreeOutput ( const Technology* tech, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
82 
83  void writeInvertTreeOutput ( const ASCString techName, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
84 
85  int findInheritanceLevel( int id, vector<int>& stack, const ASCString& sourceTechName ) const;
86 };
87 
89  ASCString name;
90  public:
92 
93  TechAdapter();
94  bool available( const Research& research ) const;
95  const ASCString& getName() const { return name; } ;
96 
97  void read ( tnstream& stream );
98  void write ( tnstream& stream ) const;
99  void runTextIO ( PropertyContainer& pc);
100 };
101 
103  public:
104  typedef vector<ASCString> RequiredTechAdapter;
105  private:
106  RequiredTechAdapter requiredTechAdapter;
107  bool requireAllListedTechAdapter;
108  public:
110  bool available( const Research& research ) const;
111  ASCString showDebug( const Research& research ) const;
112 
113  void read ( tnstream& stream );
114  void write ( tnstream& stream ) const;
115  void runTextIO ( PropertyContainer& pc, const ASCString& defaultTechAdapter = "");
116 
117  void writeInvertTreeOutput ( const ASCString& tech, tnstream& stream, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
118 
119  const RequiredTechAdapter& listAdapters() const { return requiredTechAdapter; };
120 };
121 
122 
123  class Technology: public LoadableItemType {
124  public:
125  Technology();
126 
127  void* icon;
129 
130  int id;
132  vector<int> secondaryIDs;
133 
134 
136 
140 
142 
144 
145 
146  typedef vector<IntRange> BlockingOtherTechnologies;
149 
150  bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
151  bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
152 
153 
154  void read ( tnstream& stream );
155  void write ( tnstream& stream ) const;
156  void runTextIO ( PropertyContainer& pc );
157 };
158 
159 
160 
161 
162  class Research {
163  friend class DirectResearchCommand;
164  GameMap* map;
165  int player;
166 
167  int ___loadActiveTech;
168  bool ___oldVersionLoader;
169 
170  int multiplier;
171 
172  #ifdef karteneditor
173  public:
174  #endif
175 
176  typedef std::set<ASCString> TriggeredTechAdapter;
177  TriggeredTechAdapter triggeredTechAdapter;
178 
179 
180  vector<ASCString> predefinedTechAdapter;
181  public:
182 
184 
186 
187  bool techResearched ( int id ) const;
188 
189  int progress;
192 
194  const Technology* goal;
195 
196  void read ( tnstream& stream );
197  void write ( tnstream& stream );
198 
199  void read_struct ( tnstream& stream, bool merge = false );
200  void read_techs ( tnstream& stream, bool merge = false );
201 
206  vector<ASCString> evalTechAdapter();
207  bool techAdapterAvail( const ASCString& ta ) const;
208 
209  void settechlevel ( int techlevel );
210 
211  void chainToMap ( GameMap* _map, int _player ) { map = _map; player = _player; };
212 
216  vector<ASCString> addanytechnology ( const Technology* tech );
217 
219 
220  bool isBlocked( const Technology* tech ) const;
221 
226 
227 
228  int getResearchPerTurn() const;
229  int currentTechAvailableIn() const;
230 
231  void setMultiplier( int m ) { multiplier = m; };
232  int getMultiplier() { return multiplier; };
233 
234  const vector<ASCString>& getPredefinedTechAdapter() { return predefinedTechAdapter; };
235  void setPredefinedTechAdapter( const set<ASCString>& adapter );
236  void addPredefinedTechAdapter( const ASCString& techAdapter );
237 
238  Research ( );
239  void clear();
240  ~Research ();
241  };
242 
243  class ContainerBase;
244 
246 extern Resources returnResourcenUseForResearch ( const ContainerBase* bld, int research );
248 
249 #endif
250 
void read(tnstream &stream)
read the binary representation of this item from the given stream
Definition: research.cpp:511
bool techAdapterAvail(const ASCString &ta) const
Definition: research.cpp:766
const vector< ASCString > & getPredefinedTechAdapter()
Definition: research.h:234
int relatedUnitID
Definition: research.h:139
void writeInvertTreeOutput(const Technology *tech, tnstream &stream, vector< int > &history, vector< pair< int, int > > &blockedPrintList, const vector< IntRange > *onlyWithBaseTechs=NULL) const
Definition: research.cpp:237
void write(tnstream &stream) const
write the binary representation of this item to the given stream
Definition: research.cpp:536
void read_techs(tnstream &stream, bool merge=false)
Definition: research.cpp:717
bool requireEvent
Definition: research.h:141
void clear()
Definition: research.cpp:747
vector< ASCString > evalTechAdapter()
checks for TechAdapters whose preconditions are now satisfied.
Definition: research.cpp:774
ASCString showDebug(const Research &research) const
Definition: research.cpp:331
int currentTechAvailableIn() const
Definition: research.cpp:908
const RequiredTechAdapter & listAdapters() const
Definition: research.h:119
void setPredefinedTechAdapter(const set< ASCString > &adapter)
Definition: research.cpp:920
bool eventually_available(const Research &res, list< const Technology * > *dependencies) const
Definition: research.cpp:574
const ASCString & getName() const
Definition: research.h:95
vector< int > developedTechnologies
Definition: research.h:183
void write(tnstream &stream)
Definition: research.cpp:698
vector< ASCString > addanytechnology(const Technology *tech)
adds the technology to the list of available technologies
Definition: research.cpp:849
void * icon
Definition: research.h:127
The interface for all kinds of IO stream.
void write(tnstream &stream) const
write the binary representation of this item to the given stream
Definition: research.cpp:388
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ResearchAvailabilityStatus
Definition: research.h:45
void runTextIO(PropertyContainer &pc, const ASCString &defaultTechAdapter="")
Definition: research.cpp:454
bool available(const Research &research) const
Definition: research.cpp:61
TechDependency techDependency
Definition: research.h:91
bool techsAvail
is used by the chooseTechnology dialog: the first time no techs are available this variable is still ...
Definition: research.h:225
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
TechDependency techDependency
Definition: research.h:143
void runTextIO(PropertyContainer &pc)
registers the properties of this item for loading/writing into asctxt files
Definition: research.cpp:53
void read(tnstream &stream)
Definition: research.cpp:621
An abstract base class that provides the interface for all kinds of items that ASC loads from disk...
Definition: typen.h:287
const Technology * activetechnology
the technology that is currently being researched
Definition: research.h:191
void setMultiplier(int m)
Definition: research.h:231
ASCString infotext
Definition: research.h:128
const Technology * goal
the technology that is defined as long-term goal
Definition: research.h:194
void read(tnstream &stream)
read the binary representation of this item from the given stream
Definition: research.cpp:33
cancels the research on the current technology, losing all research points
void write(tnstream &stream) const
write the binary representation of this item to the given stream
Definition: research.cpp:45
ResearchAvailabilityStatus techAvailable(const Technology *tech) const
Definition: research.cpp:834
void chainToMap(GameMap *_map, int _player)
Definition: research.h:211
void read(tnstream &stream)
read the binary representation of this item from the given stream
Definition: research.cpp:379
Loki::Functor< bool, LOKI_TYPELIST_1(int) > CheckTechAvailabilityFunctor
Definition: research.h:61
int getResearchPerTurn() const
Definition: research.cpp:896
BlockingOtherTechnologies blockingOtherTechnologies
if this Technology has been researched, it will not be possible to research the technologies given he...
Definition: research.h:148
vector< int > secondaryIDs
when loading a file and these IDs are encountered, this object will be used.
Definition: research.h:132
void writeInvertTreeOutput(const ASCString &tech, tnstream &stream, const vector< IntRange > *onlyWithBaseTechs=NULL) const
Definition: research.cpp:469
bool isBlocked(const Technology *tech) const
Definition: research.cpp:818
int techlevel
Definition: research.h:138
ASCString showDebug(const Research &research) const
Definition: research.cpp:479
void runTextIO(PropertyContainer &pc)
registers the properties of this item for loading/writing into asctxt files
Definition: research.cpp:551
vector< IntRange > BlockingOtherTechnologies
Definition: research.h:146
void settechlevel(int techlevel)
Definition: research.cpp:861
ASCString name
Definition: research.h:137
void runTextIO(PropertyContainer &pc)
registers the properties of this item for loading/writing into asctxt files
Definition: research.cpp:395
void read_struct(tnstream &stream, bool merge=false)
Definition: research.cpp:634
bool techResearched(int id) const
Definition: research.cpp:757
vector< ASCString > RequiredTechAdapter
Definition: research.h:104
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
int researchpoints
Definition: research.h:135
An actual building on the map, which references a BuildingType Buildings have an owner,.
Definition: buildings.h:38
void read(tnstream &stream)
Definition: research.cpp:434
Resources are basically the currency of ASC.
Definition: typen.h:97
bool available(const Research &research) const
Definition: research.cpp:412
void addPredefinedTechAdapter(const ASCString &techAdapter)
Definition: research.cpp:926
Resources returnResourcenUseForResearch(const ContainerBase *bld, int research)
Calculates the resources that are needed to research the given number of research.
Definition: research.cpp:937
void writeTreeOutput(const ASCString &sourceTechName, tnstream &stream, bool reduce) const
outputs the dependencies in text format for processing by GraphViz
Definition: research.cpp:173
bool eventually_available(const Research &res, list< const Technology * > *dependencies) const
this will recursively scan through the tech tree to check if this item will be available sometime...
Definition: research.cpp:122
bool empty() const
Definition: research.h:76
int progress
Definition: research.h:189
int findInheritanceLevel(int id, vector< int > &stack, const ASCString &sourceTechName) const
Definition: research.cpp:130
The standard interface for ASC streams. This is the parent class for all kinds of streams: normal fil...
int getMultiplier()
Definition: research.h:232
bool available(const Research &research) const
Definition: research.cpp:402
ASCString listTriggeredTechAdapter() const
Definition: research.cpp:790
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
void write(tnstream &stream) const
Definition: research.cpp:445