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