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