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 "libs/loki/Functor.h"
00031
00032 #include "basestreaminterface.h"
00033 #include "basictypes.h"
00034 #include "typen.h"
00035
00036
00037 class Research;
00038 class Technology;
00039 class Building;
00040 class Vehicle;
00041 class Vehicletype;
00042 class GameMap;
00043
00044 enum ResearchAvailabilityStatus { Researched, Available, UnavailableNow, NeverAvailable };
00045
00046
00047 class TechDependency: public LoadableItemType {
00048 typedef vector<IntRange> RequiredTechnologies;
00050 RequiredTechnologies blockingTechnologies;
00051
00052 RequiredTechnologies requiredTechnologies;
00053 bool requireAllListedTechnologies;
00054
00055 static bool eventually_available_single( const Research& res, list<const Technology*>* dependencies, list<int>& stack, int id );
00056 public:
00057 TechDependency(){ requireAllListedTechnologies = true; };
00058
00059 bool available( const Research& research ) const;
00060 typedef Loki::Functor<bool, TYPELIST_1(int) > CheckTechAvailabilityFunctor;
00061 ResearchAvailabilityStatus available( CheckTechAvailabilityFunctor checkTechAvailability ) const;
00062
00066 bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
00067 bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
00068
00069
00070 ASCString showDebug( const Research& research ) const;
00071
00072 void read ( tnstream& stream );
00073 void write ( tnstream& stream ) const;
00074 void runTextIO ( PropertyContainer& pc);
00075 bool empty() const { return requiredTechnologies.size() == 0; } ;
00076
00078 void writeTreeOutput ( const ASCString& sourceTechName, tnstream& stream, bool reduce ) const;
00079
00080 void writeInvertTreeOutput ( const Technology* tech, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00081
00082 void writeInvertTreeOutput ( const ASCString techName, tnstream& stream, vector<int>& history, vector<pair<int,int> >& blockedPrintList, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00083
00084 int findInheritanceLevel( int id, vector<int>& stack, const ASCString& sourceTechName ) const;
00085 };
00086
00087 class TechAdapter: public LoadableItemType {
00088 ASCString name;
00089 public:
00090 TechDependency techDependency;
00091
00092 TechAdapter();
00093 bool available( const Research& research ) const;
00094 const ASCString& getName() const { return name; } ;
00095
00096 void read ( tnstream& stream );
00097 void write ( tnstream& stream ) const;
00098 void runTextIO ( PropertyContainer& pc);
00099 };
00100
00101 class TechAdapterDependency {
00102 typedef vector<ASCString> RequiredTechAdapter;
00103 RequiredTechAdapter requiredTechAdapter;
00104 bool requireAllListedTechAdapter;
00105 public:
00106 TechAdapterDependency();
00107 bool available( const Research& research ) const;
00108 ASCString showDebug( const Research& research ) const;
00109
00110 void read ( tnstream& stream );
00111 void write ( tnstream& stream ) const;
00112 void runTextIO ( PropertyContainer& pc, const ASCString& defaultTechAdapter = "");
00113
00114 void writeInvertTreeOutput ( const ASCString& tech, tnstream& stream, const vector<IntRange>* onlyWithBaseTechs = NULL ) const;
00115 };
00116
00117
00118 class Technology: public LoadableItemType {
00119 public:
00120 Technology();
00121
00122 void* icon;
00123 ASCString infotext;
00124
00125 int id;
00127 vector<int> secondaryIDs;
00128
00129
00130 int researchpoints;
00131
00132 ASCString name;
00133 int techlevel;
00134 int relatedUnitID;
00135
00136 bool requireEvent;
00137
00138 TechDependency techDependency;
00139
00140
00141 typedef vector<IntRange> BlockingOtherTechnologies;
00143 BlockingOtherTechnologies blockingOtherTechnologies;
00144
00145 bool eventually_available( const Research& res, list<const Technology*>* dependencies ) const;
00146 bool eventually_available( const Research& res, list<const Technology*>* dependencies, list<int>& stack ) const;
00147
00148
00149 void read ( tnstream& stream );
00150 void write ( tnstream& stream ) const;
00151 void runTextIO ( PropertyContainer& pc );
00152 };
00153
00154
00155
00156
00157 class Research {
00158
00159 GameMap* map;
00160 int player;
00161
00162 int ___loadActiveTech;
00163 bool ___oldVersionLoader;
00164
00165 int multiplier;
00166
00167 #ifdef karteneditor
00168 public:
00169 #endif
00170
00171 typedef std::map<ASCString,bool> TriggeredTechAdapter;
00172 TriggeredTechAdapter triggeredTechAdapter;
00173
00174
00175 vector<ASCString> predefinedTechAdapter;
00176 public:
00177
00178 vector<int> developedTechnologies;
00179
00180 ASCString listTriggeredTechAdapter() const;
00181
00182 bool techResearched ( int id ) const;
00183
00184 int progress;
00186 const Technology* activetechnology;
00187
00189 const Technology* goal;
00190
00191 bool vehicletypeavailable ( const Vehicletype* fztyp ) const;
00192
00193 void read ( tnstream& stream );
00194 void write ( tnstream& stream );
00195
00196 void read_struct ( tnstream& stream, bool merge = false );
00197 void read_techs ( tnstream& stream, bool merge = false );
00198
00199 void evalTechAdapter();
00200 bool techAdapterAvail( const ASCString& ta ) const;
00201
00202 void settechlevel ( int techlevel );
00203
00204 void chainToMap ( GameMap* _map, int _player ) { map = _map; player = _player; };
00205
00207 void addtechnology();
00208
00209 void addanytechnology ( const Technology* tech );
00210
00211 ResearchAvailabilityStatus techAvailable ( const Technology* tech ) const;
00212
00213 bool isBlocked( const Technology* tech ) const;
00214
00218 bool techsAvail;
00219
00220
00222 void cancel();
00223
00224
00225 int getResearchPerTurn() const;
00226 int currentTechAvailableIn() const;
00227
00228 void setMultiplier( int m ) { multiplier = m; };
00229 int getMultiplier() { return multiplier; };
00230
00231 Research ( );
00232 void clear();
00233 ~Research ();
00234 };
00235
00236 class ContainerBase;
00237
00239 extern Resources returnResourcenUseForResearch ( const ContainerBase* bld, int research );
00240 extern Resources returnResourcenUseForResearch ( const ContainerBase* bld );
00241
00242 #endif
00243