00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "commercialsim.h"
00021
00022 #include "buildinglayer.h"
00023 #include "structure.h"
00024
00025
00026
00027 CommercialSim::CommercialSim(
00028 SDL_mutex* mutex,
00029 BuildingLayer* pblayer,
00030 Map* pmap ):
00031 Simulator( mutex, pblayer, pmap )
00032 {
00033 OPENCITY_DEBUG( "CSim param ctor" );
00034 }
00035
00036
00037
00038 CommercialSim::~CommercialSim()
00039 {
00040 OPENCITY_DEBUG( "CSim dtor" );
00041 }
00042
00043
00044
00045 int
00046 CommercialSim::Main()
00047 {
00048 static uint w, l;
00049 static Structure* pstruct;
00050 static bool boolLevelUp;
00051 static int iRandom;
00052 static OPENCITY_GRAPHIC_CODE oldGC;
00053
00054
00055 if (this->enumSimState == SIMULATOR_RUNNING) {
00056
00057 pstruct = pbuildlayer->GetRandomStructure(
00058 w, l, OC_STRUCTURE_COM );
00059
00060 if (pstruct != NULL) {
00061 boolLevelUp = false;
00062
00063
00064
00065
00066 SDL_LockMutex( this->mutexMain );
00067
00068 pstruct->Unset(
00069 OC_STRUCTURE_W | OC_STRUCTURE_G |
00070 OC_STRUCTURE_R | OC_STRUCTURE_C | OC_STRUCTURE_I |
00071 OC_STRUCTURE_P );
00072 pstruct->Set( OC_STRUCTURE_C );
00073
00074
00075 if (CheckRange(
00076 w, l, OC_C_P_RANGE, OC_STRUCTURE_ROAD ) == true)
00077 pstruct->Set( OC_STRUCTURE_P );
00078
00079 if (CheckRange(
00080 w, l, OC_C_R_RANGE, OC_STRUCTURE_RES ) == true)
00081 pstruct->Set( OC_STRUCTURE_R );
00082
00083 if (CheckRange(
00084 w, l, OC_C_I_RANGE, OC_STRUCTURE_IND ) == true)
00085 pstruct->Set( OC_STRUCTURE_I );
00086
00087 if (pstruct->IsSet(
00088 OC_STRUCTURE_E |
00089 OC_STRUCTURE_R | OC_STRUCTURE_C | OC_STRUCTURE_I |
00090 OC_STRUCTURE_P ) == true )
00091 boolLevelUp = true;
00092
00093
00094
00095
00096
00097 iRandom = rand() % 100;
00098 oldGC = pstruct->GetGraphicCode();
00099 if (boolLevelUp == true) {
00100
00101 if (iRandom < OC_SIMULATOR_UP) {
00102 if ((this->CheckLevelUp(w, l, pstruct) == true)
00103 && (pstruct->LevelUp() == true)) {
00104 pbuildlayer->ResizeStructure( w, l, oldGC );
00105 _iValue++;
00106 }
00107 }
00108 }
00109 else {
00110
00111 if (iRandom < OC_SIMULATOR_DOWN)
00112 if ((this->CheckLevelDown(w, l, pstruct) == true)
00113 && (pstruct->LevelDown() == true)) {
00114 pbuildlayer->ResizeStructure( w, l, oldGC );
00115 _iValue--;
00116 }
00117 }
00118
00119 SDL_UnlockMutex( this->mutexMain );
00120 }
00121 }
00122
00123 return 0;
00124 }
00125
00126
00127
00128 void
00129 CommercialSim::RemoveStructure(
00130 const uint & w1,
00131 const uint & h1,
00132 const uint & w2,
00133 const uint & h2 )
00134 {
00135 Structure* pstruct = pbuildlayer->GetStructure( w1, h1 );
00136
00137
00138
00139
00140
00141 if (pstruct != NULL)
00142 if (pstruct->GetCode() == OC_STRUCTURE_COM)
00143 if (pstruct->GetLevel() - 1 > 0)
00144 _iValue -= pstruct->GetLevel()-1;
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177