00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #if !defined(Rules_h)
00031 #define Rules_h
00032
00033 #include <deque>
00034 #include <string>
00035 #include <map>
00036
00037 using namespace std;
00038
00039 class Location;
00040 class Player;
00041 class Planet;
00042 class Fleet;
00043 class Ship;
00044 class Component;
00045 class CargoHolder;
00046 class Hull;
00047
00048 typedef long CargoType;
00049
00050 template <class Type> class Array {
00051 public:
00052 Array(int start) : First(start) {}
00053 virtual ~Array() {}
00054 void AddItem(Type item) { Items.push_back(item); }
00055 Type operator [] (unsigned int pos) const {
00056 if (pos <= First)
00057 return Items[0];
00058 else if (pos > Items.size() + First)
00059 return Items.back();
00060 else
00061 return Items[pos-First];
00062 }
00063
00064 private:
00065 deque<Type> Items;
00066 int First;
00067 };
00068
00073 class Rules {
00074 public:
00075 static void Init();
00076 static void Cleanup();
00077
00078 static deque<unsigned long> TechCost;
00079 static unsigned long MaxTechLevel;
00080 static long MaxTechType;
00081 static long MaxMinType;
00082 static long MaxHabType;
00083 static long MaxMineType;
00084 static unsigned long MaxFleets;
00085 static long PopEQ1kT;
00086
00087 static TechType TechFleet(const Player * player, const Fleet * fleet);
00088 static double ScrapRecover(const Planet * planet, bool colonize);
00089 static long ScrapResource(const Planet * planet);
00090 static bool TechScrap(const Planet * planet);
00091 static TechType TechInvasion(Player * invader, const Player * owner);
00092 static bool Stealable(CargoType ct);
00093 static long CloakValue(long Cloaking, long Mass);
00094 static double CalcScanning(double base, long newscan, long count);
00095
00096 static void ReadCargo(const TiXmlNode * node, deque<long> & q, long * pop);
00097 static TiXmlElement * WriteCargo(TiXmlNode * node, const char * name, const deque<long> &q, long pop);
00098
00099 static bool LoadRules(const TiXmlNode * node, const char * file, const char * verify, double version);
00100 static void WriteRulesFile(TiXmlNode * node);
00101 static long GetConstant(const string name, long Default = 0);
00102 static double GetFloat(const string name, double Default = 0.0);
00103 static long GetArrayValue(const string name, int position);
00104 static double GetArrayFloat(const string name, int position);
00105
00106 static long TechID(const char * name);
00107 static long MineralID(const char * name);
00108 static long HabID(const char * name);
00109 static long MineID(const char * name);
00110 static long GetCargoType(const char * name);
00111
00112 static double OverGateRange(long range, long dist);
00113 static double OverGateMass(long cap1, long cap2, long mass);
00114
00115 static const string GetCargoName(long type);
00116 static const string GetHabName(long type)
00117 { if (type < MaxHabType)
00118 return HabName[type];
00119 else
00120 return "BadName";
00121 }
00122 static const string GetTechName(long type);
00123
00124 static TiXmlElement * WriteArray(const char * node, const deque<long> & q, long Type);
00125 static TiXmlElement * WriteArrayFloat(const char * node, const deque<double> & q, long Type);
00126 static bool ParseArray(const TiXmlNode * node, deque<long> & q, long Type);
00127 static bool ParseArrayFloat(const TiXmlNode * node, deque<double> & q, long Type);
00128
00129 static TiXmlElement * WriteArrayBool(const char * node, const char * name, const char * Attrib, const deque<bool> & arr, const deque<string> * desc = NULL);
00130 static TiXmlElement * WriteArray(const char * node, const char * name, const char * Attrib, const deque<long> & arr, const deque<string> * desc = NULL);
00131 static TiXmlElement * WriteArrayFloat(const char * node, const char * name, const char * Attrib, const deque<double> & arr, const deque<string> * desc = NULL);
00132 static bool ParseArrayBool(const TiXmlNode * node, const char * name, const char * Attrib, deque<bool> & arr, const deque<string> * desc = NULL);
00133 static bool ParseArray(const TiXmlNode * node, const char * name, const char * Attrib, deque<long> & arr, const deque<string> * desc = NULL);
00134 static bool ParseArrayFloat(const TiXmlNode * node, const char * name, const char * Attrib, deque<double> & arr, const deque<string> * desc = NULL);
00135
00136 static long RandomHab(HabType ht);
00137 static long GetSecondHab(HabType ht, const Player * owner);
00138 static bool ParseMinSettings(const TiXmlNode * node);
00139 static void WriteMinSettings(TiXmlNode * node);
00140 static long MinMC(long i) { return mMinMC[i]; }
00141 static long MaxMC(long i) { return mMaxMC[i]; }
00142 static long HWMinMC(long i) { return mHWMinMC[i]; }
00143 static long HWMaxMC(long i) { return mHWMaxMC[i]; }
00144 static long HWFloorMC(long i) { return mHWFloorMC[i]; }
00145 static deque<long> * GetHabOddArray(HabType ht, bool Create = false);
00146 static long GetHWMC(long mintype);
00147 static long GetHWStartMinerals(long mintype);
00148 static long GetSWStartMinerals(long mintype);
00149
00150 private:
00151 static deque<string> TechName;
00152 static deque<string> HabName;
00153 static deque<string> MinName;
00154 static deque<string> MineName;
00155 static map<string, long, less<string> > Consts;
00156 static map<string, double, less<string> > Floats;
00157 static map<string, Array<long> *, less<string> > Arrays;
00158 static map<string, Array<double> *, less<string> > FloatArrays;
00159 static string * ModFileName;
00160 static double ModFileVersion;
00161 static string * ModFileCRC;
00162
00163
00164 static deque<deque<long> *> mHabOdds;
00165 static deque<long> mMinMC;
00166 static deque<long> mMaxMC;
00167 static deque<long> mHWMinMC;
00168 static deque<long> mHWMaxMC;
00169 static deque<long> mHWFloorMC;
00170 static deque<long> mHWSetupMC;
00171 static deque<long> mHWSetupSM;
00172 };
00173
00174
00175 const long MINERALS = 1;
00176 const long TECHS = 2;
00177 const long HABS = 3;
00178 const long MINES = 4;
00179
00180
00181 const long POPULATION = -1;
00182 const long FUEL = -2;
00183 const long RESOURCES = -2;
00184
00185 #endif // !defined(Rules_h)