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 #include <stdio.h>
00026 #include <malloc.h>
00027 #include <string.h>
00028
00029 #include "dice.hpp"
00030 #include "main-planet.hpp"
00031 #include "alphautils.hpp"
00032 #include "numberutils.hpp"
00033
00034
00040 void mainPlanet::calculateStarport(){
00041 switch (d2d6()){
00042 case 2:
00043 case 3:
00044 case 4:
00045 this->starport='A';
00046 return;
00047 case 5:
00048 case 6:
00049 this->starport='B';
00050 return;
00051 case 7:
00052 case 8:
00053 this->starport='C';
00054 return;
00055 case 9:
00056 this->starport='D';
00057 return;
00058 case 10:
00059 case 11:
00060 this->starport='E';
00061 return;
00062 case 12:
00063 this->starport='X';
00064 return;
00065 };
00066
00067 }
00068
00069 void mainPlanet::calculateTechlevel(){
00070 int dm;
00071
00072 switch (this->starport){
00073 case 'A':
00074 dm=6;
00075 break;
00076 case 'B':
00077 dm=4;
00078 break;
00079 case 'C':
00080 dm=2;
00081 break;
00082 case 'X':
00083 dm = -4;
00084 break;
00085 default:
00086 dm=0;
00087 };
00088
00089 dm = dm+( this->getDiameter() < 2 ? 2: 0 ) ;
00090 dm = dm+(
00091 ( ( 2 <= this->getDiameter() )
00092 &&
00093 ( this->getDiameter() <= 4) ) ? 1 : 0 );
00094
00095 dm = dm+( this->getAtmosphere() <= 3 ? 1 : 0 );
00096 dm = dm+( ( 10<= this->getAtmosphere() )
00097 && ( this->getAtmosphere() <= 14) ?1 : 0 );
00098
00099 dm = dm + ( this->getHydrosphere() == 9 ? 1 : 0 ) ;
00100 dm = dm + ( this->getHydrosphere() == 10 ? 2 : 0 ) ;
00101
00102 dm = dm + ( ( 0 < this->getPopulation() ) &&
00103 ( this->getPopulation() < 6 ) ? 1 : 0 );
00104 dm = dm + ( this->getPopulation() == 9 ? 2 : 0 );
00105 dm = dm + ( this->getPopulation() == 10? 4 : 0 );
00106
00107 dm = dm + ( (this->getGovernment() == 0) ||
00108 (this->getGovernment() == 5 ) ? 1 : 0 );
00109
00110 dm = dm - ( this->getGovernment() == 13 ? 2 : 0 );
00111
00112 this->setTechlevel( d1d6() + dm ) ;
00113
00114 }
00115
00116 int mainPlanet::checkForNavalBase(){
00117 switch (this->starport){
00118 case 'A':
00119 case 'B':
00120 return ( d2d6() > 7 ? 1 : 0 );
00121 default:
00122 return 0;
00123 };
00124 }
00125
00126 int mainPlanet::checkForScoutBase(){
00127 int dm;
00128 switch (this->starport){
00129 case 'A':
00130 dm=-3;
00131 break;
00132 case 'B':
00133 dm = -2;
00134 break;
00135 case 'C':
00136 dm = -1;
00137 break;
00138 case 'E':
00139 case 'X':
00140 return 0;
00141 default:
00142 dm=0;
00143 break;
00144 };
00145
00146 return ( d2d6() + dm > 6 ? 1 : 0 ) ;
00147
00148 }
00149
00150
00151 static int fixCalc(int x){
00152 int v = (d2d6()-7) + x;
00153 return ( v >= 0? v:0);
00154 }
00155
00156
00157
00158
00159
00160
00161 mainPlanet::mainPlanet() : planet(MAINPLANET) {
00162
00163
00164 this->calculateStarport();
00165
00166 this->setPopulation(d2d6()-2);
00167 this->setGovernment(fixCalc(this->getPopulation()));
00168 this->setLawlevel(fixCalc(this->getGovernment()));
00169
00170 this->calculateTechlevel();
00171 this->setNavalBase(checkForNavalBase());
00172 this->setScoutBase(checkForScoutBase());
00173
00174 }
00175
00176
00177 char* mainPlanet::asText(){
00178 char* buffer;
00179
00180 buffer=(char *)malloc(81);
00181
00182 buffer[0]='\0';
00183 sprintf(buffer,"%c-%s%s%s%s%s%s-%s -- ",
00184 this->starport,
00185 (this->getDiameter() == 0 ? "S" : itoan(this->getDiameter())),
00186 itoan(this->getAtmosphere()),
00187 itoan(this->getHydrosphere()),
00188 itoan(this->getPopulation()),
00189 itoan(this->getGovernment()),
00190 itoan(this->getLawlevel()),
00191 itoan(this->getTechlevel())
00192 );
00193 if ( this->getNavalBase() != 0 ) {
00194 sprintf(buffer,"%s %s",buffer,"N");
00195 } else {
00196 sprintf(buffer,"%s ",buffer);
00197 }
00198
00199 if ( this->getScoutBase() != 0 ) {
00200 sprintf(buffer,"%s %s",buffer,"S");
00201 } else {
00202 sprintf(buffer,"%s ",buffer);
00203 }
00207 if (
00208 ( ( 4 <= this->getAtmosphere() ) && ( this->getAtmosphere() <= 9 ) )
00209 &&
00210 ( ( 4 <= this->getHydrosphere() ) && ( this->getHydrosphere() <= 8 ) )
00211 &&
00212 ( ( 5 <= this->getPopulation() ) && ( this->getPopulation() <= 7) )
00213 ) {
00214 sprintf(buffer,"%s Ag",buffer);
00215 }
00216
00217 if (
00218 (this->getAtmosphere() <= 3 ) &&
00219 (this->getHydrosphere() <= 3 ) &&
00220 ( this->getPopulation() >= 6 )
00221 ) {
00222 sprintf(buffer,"%s Na",buffer);
00223 }
00224 int t1[]={0,1,2,4,7,9};
00225 if (
00226 (isInSet(this->getAtmosphere(),t1,6) == 1 )
00227 && (this->getPopulation() > 8 )
00228 ) {
00229 sprintf(buffer,"%s In",buffer);
00230
00231 }
00232
00233 if ( this-> getPopulation() <= 6 )
00234 sprintf(buffer,"%s Ni",buffer);
00235 int t2[]={6,8};
00236
00237 if ( ( isInSet(this->getAtmosphere(),t2,2) == 1 )
00238 &&
00239 ( ( 6<= this->getPopulation() ) && ( this->getPopulation() <= 8 ) )
00240 &&
00241 ( ( 4 <= this->getGovernment() ) && ( this->getGovernment() <= 9 ))
00242 )
00243 {
00244 sprintf(buffer,"%s Ri",buffer);
00245 }
00246
00247 if (
00248 ( ( 2<= this->getAtmosphere() ) && ( this->getAtmosphere() <= 5 ) )
00249 &&
00250 this->getHydrosphere() <= 3
00251 )
00252 {
00253 sprintf(buffer,"%s Po",buffer);
00254 }
00255
00256 if ( this->getHydrosphere() == 10 )
00257 sprintf(buffer,"%s Wa",buffer);
00258
00259 if ( (this->getHydrosphere() == 0 ) && ( this->getAtmosphere() >= 2 ) )
00260 sprintf(buffer,"%s De",buffer);
00261
00262 if (this->getAtmosphere() == 0 )
00263 sprintf(buffer,"%s Va",buffer);
00264
00265 if ( isInSet(this->getAtmosphere(),(int[]){0,1},2) && (this->getHydrosphere() > 1 ) )
00266 sprintf(buffer,"%s Ic",buffer);
00267
00268
00269 return buffer;
00270
00271 }
00272
00273 void mainPlanet::genWBHData(){
00274 int roll;
00275
00280 roll= d2d6() -7 ;
00281
00282 while ( roll == 5 ) {
00283 roll=d2d6()-7;
00284 }
00285 this->setSizeModifier(roll*100);
00286 this->determinePlanetDensityType();
00287
00288
00289
00290
00291
00292 }