00001
00002
00003
00004
00005
00006
00007
00008
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef researchH
00025 #define researchH
00026
00027 #include <cstring>
00028 #include <map>
00029
00030 #include "loki/Functor.h"
00031 #include "loki/Typelist.h"
00032
00033 #include "basestreaminterface.h"
00034 #include "basictypes.h"
00035 #include "typen.h"
00036
00037
00038 class Research;
00039 class Technology;
00040 class Building;
00041 class Vehicle;
00042 class VehicleType;
00043 class GameMap;
00044
00045 enum ResearchAvailabilityStatus { Researched, Available, UnavailableNow, NeverAvailable };
00046
00047
00048 class TechDependency: public LoadableItemType {
00049 typedef vector<IntRange> RequiredTechnologies;
00051 RequiredTechnologies blockingTechnologies;
00052
00053 RequiredTechnologies requiredTechnologies;
00054 bool requireAllListedTechnologies;
00055
00056 static bool eventually_available_single( const Research& res, list<const Technology*>* dependencies, list<int>& stack, int id );
00057 public:
00058 TechDependency(){ requireAllListedTechnologies = true; };
00059
00060 bool available( const Research& research ) const;
00061 typedef Loki::Functor<bool, LOKI_TYPELIST_1(int) > CheckTechAvailabilityFunctor;
00062 ResearchAvailabilityStatus available( CheckTechAvailabilityFunctor checkTechAvailability ) const;
00063
00067 bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
00068 bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
00069
00070
00071 ASCString showDebug( const Research& research ) const;
00072
00073 void read ( tnstream& stream );
00074 void write ( tnstream& stream ) const;
00075 void runTextIO ( PropertyContainer& pc);
00076 bool empty() const { return requiredTechnologies.size() == 0; } ;
00077
00079 void writeTreeOutput ( const ASCString& sourceTechName, tnstream& stream, bool reduce ) const;
00080
00081 void writeInvertTreeOutput ( const Technology* tech, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00082
00083 void writeInvertTreeOutput ( const ASCString techName, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00084
00085 int findInheritanceLevel( int id, vector<int>& stack, const ASCString& sourceTechName ) const;
00086 };
00087
00088 class TechAdapter: public LoadableItemType {
00089 ASCString name;
00090 public:
00091 TechDependency techDependency;
00092
00093 TechAdapter();
00094 bool available( const Research& research ) const;
00095 const ASCString& getName() const { return name; } ;
00096
00097 void read ( tnstream& stream );
00098 void write ( tnstream& stream ) const;
00099 void runTextIO ( PropertyContainer& pc);
00100 };
00101
00102 class TechAdapterDependency {
00103 public:
00104 typedef vector<ASCString> RequiredTechAdapter;
00105 private:
00106 RequiredTechAdapter requiredTechAdapter;
00107 bool requireAllListedTechAdapter;
00108 public:
00109 TechAdapterDependency();
00110 bool available( const Research& research ) const;
00111 ASCString showDebug( const Research& research ) const;
00112
00113 void read ( tnstream& stream );
00114 void write ( tnstream& stream ) const;
00115 void runTextIO ( PropertyContainer& pc, const ASCString& defaultTechAdapter = "");
00116
00117 void writeInvertTreeOutput ( const ASCString& tech, tnstream& stream, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00118
00119 const RequiredTechAdapter& listAdapters() const { return requiredTechAdapter; };
00120 };
00121
00122
00123 class Technology: public LoadableItemType {
00124 public:
00125 Technology();
00126
00127 void* icon;
00128 ASCString infotext;
00129
00130 int id;
00132 vector<int> secondaryIDs;
00133
00134
00135 int researchpoints;
00136
00137 ASCString name;
00138 int techlevel;
00139 int relatedUnitID;
00140
00141 bool requireEvent;
00142
00143 TechDependency techDependency;
00144
00145
00146 typedef vector<IntRange> BlockingOtherTechnologies;
00148 BlockingOtherTechnologies blockingOtherTechnologies;
00149
00150 bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
00151 bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
00152
00153
00154 void read ( tnstream& stream );
00155 void write ( tnstream& stream ) const;
00156 void runTextIO ( PropertyContainer& pc );
00157 };
00158
00159
00160
00161
00162 class Research {
00163 friend class DirectResearchCommand;
00164 GameMap* map;
00165 int player;
00166
00167 int ___loadActiveTech;
00168 bool ___oldVersionLoader;
00169
00170 int multiplier;
00171
00172 #ifdef karteneditor
00173 public:
00174 #endif
00175
00176 typedef std::set<ASCString> TriggeredTechAdapter;
00177 TriggeredTechAdapter triggeredTechAdapter;
00178
00179
00180 vector<ASCString> predefinedTechAdapter;
00181 public:
00182
00183 vector<int> developedTechnologies;
00184
00185 ASCString listTriggeredTechAdapter() const;
00186
00187 bool techResearched ( int id ) const;
00188
00189 int progress;
00191 const Technology* activetechnology;
00192
00194 const Technology* goal;
00195
00196 void read ( tnstream& stream );
00197 void write ( tnstream& stream );
00198
00199 void read_struct ( tnstream& stream, bool merge = false );
00200 void read_techs ( tnstream& stream, bool merge = false );
00201
00206 vector<ASCString> evalTechAdapter();
00207 bool techAdapterAvail( const ASCString& ta ) const;
00208
00209 void settechlevel ( int techlevel );
00210
00211 void chainToMap ( GameMap* _map, int _player ) { map = _map; player = _player; };
00212
00216 vector<ASCString> addanytechnology ( const Technology* tech );
00217
00218 ResearchAvailabilityStatus techAvailable ( const Technology* tech ) const;
00219
00220 bool isBlocked( const Technology* tech ) const;
00221
00225 bool techsAvail;
00226
00227
00228 int getResearchPerTurn() const;
00229 int currentTechAvailableIn() const;
00230
00231 void setMultiplier( int m ) { multiplier = m; };
00232 int getMultiplier() { return multiplier; };
00233
00234 const vector<ASCString>& getPredefinedTechAdapter() { return predefinedTechAdapter; };
00235 void setPredefinedTechAdapter( const set<ASCString>& adapter );
00236 void addPredefinedTechAdapter( const ASCString& techAdapter );
00237
00238 Research ( );
00239 void clear();
00240 ~Research ();
00241 };
00242
00243 class ContainerBase;
00244
00246 extern Resources returnResourcenUseForResearch ( const ContainerBase* bld, int research );
00247 extern Resources returnResourcenUseForResearch ( const ContainerBase* bld );
00248
00249 #endif
00250