Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

source/globals.c

Go to the documentation of this file.
00001 
00008 #include <config.h>
00009 
00010 #include <zakdef.h>
00011 #if defined(PALM)
00012 #include <StringMgr.h>
00013 #include <unix_stdio.h>
00014 #else
00015 #include <stdio.h>
00016 #endif
00017 #include <mem_compat.h>
00018 #include <logging.h>
00019 #include <locking.h>
00020 #include <ui.h>
00021 #include <stack.h>
00022 #include <globals.h>
00023 
00024 #define MILLION 1000000
00025 
00034 stat_to_value statvalues[] = {
00035         { st_cashflow, bc_cashflow },
00036         { st_pollution, bc_pollution },
00037         { st_crime, bc_crime },
00038         { st_residential, bc_value_residential },
00039         { st_commercial, bc_value_commercial }, 
00040         { st_industrial, bc_value_industrial },
00041         { st_tail, 0 }
00042 };
00043 
00045 GameStruct game;
00047 vGameStruct vgame;
00048 
00050 vGameVisuals visuals;
00051 
00053 void *worldPtr;
00055 void *flagPtr;
00056 
00058 void *growablePtr;
00059 
00061 AppConfig_t gameConfig = {
00062         CONFIG_VERSION,
00063         DEFAULT_APPCONFIG
00064 };
00065 
00067 static UInt16 needchange;
00068 
00073 void
00074 addGraphicUpdate(graphicupdate_t entity)
00075 {
00076         if (entity != gu_all)
00077                 needchange |= (UInt16)entity;
00078         else
00079                 needchange = ~(UInt16)0;
00080 }
00081 
00086 void
00087 removeGraphicUpdate(graphicupdate_t entity)
00088 {
00089         needchange &= ~((UInt16)entity);
00090 }
00091 
00097 UInt8
00098 checkGraphicUpdate(graphicupdate_t entity)
00099 {
00100         return ((UInt8)(needchange & entity ? 1 : 0));
00101 }
00102 
00107 UInt8
00108 checkAnyGraphicUpdate(void)
00109 {
00110         return ((UInt8)(needchange ? 1 : 0));
00111 }
00112 
00116 void
00117 clearGraphicUpdate(void)
00118 {
00119         needchange = 0;
00120 }
00121 
00128 char *
00129 getDate(char *temp)
00130 {
00131         char month[10];
00132 
00133         sprintf(temp, "%s %ld", getMonthString(
00134             (UInt16)(getMonthsElapsed() % 12),
00135             month, (UInt16)9),
00136             (long)((getMonthsElapsed() / 12) + 2000));
00137         return ((char *)temp);
00138 }
00139 
00150 void *
00151 getIndexOf(char *ary, Int16 addit, Int16 key)
00152 {
00153         while (*(Int16 *)ary) {
00154                 if (key == *(Int16 *)ary)
00155                         return (ary);
00156                 ary += addit;
00157         }
00158         return (NULL);
00159 }
00160 
00165 UInt8
00166 getDisasterLevel(void)
00167 {
00168         return ((UInt8)(GG.diff_disaster & 0xF));
00169 }
00170 
00175 void
00176 setDisasterLevel(UInt8 value)
00177 {
00178         GG.diff_disaster &= 0xf0;
00179         GG.diff_disaster |= (UInt8)(value & 0x0f);
00180 }
00181 
00186 UInt8
00187 getDifficultyLevel(void)
00188 {
00189         return ((UInt8)((GG.diff_disaster >> 4) & 0x0f));
00190 }
00191 
00196 void
00197 setDifficultyLevel(UInt8 value)
00198 {
00199         GG.diff_disaster &= (UInt8)0x0f;
00200         GG.diff_disaster |= (UInt8)((value & 0x0f) << 4);
00201 }
00202 
00211 Int16
00212 ResizeWorld(UInt32 size)
00213 {
00214         WriteLog("Resize World = %ld\n", (long)size);
00215         LockZone(lz_world);
00216         LockZone(lz_flags);
00217         worldPtr = gRealloc(worldPtr, size);
00218         flagPtr = gRealloc(flagPtr, size);
00219 
00220         if (worldPtr == NULL) {
00221                 UISystemErrorNotify(seOutOfMemory);
00222                 WriteLog("realloc failed - resizeworld\n");
00223                 return (0);
00224         }
00225         if (flagPtr == NULL) {
00226                 UISystemErrorNotify(seOutOfMemory);
00227                 WriteLog("realloc failed - resizeworldflags\n");
00228                 return (0);
00229         }
00230 
00231         gMemSet(worldPtr, (Int32)size, 0);
00232         gMemSet(flagPtr, (Int32)size, 0);
00233         UnlockZone(lz_world);
00234         UnlockZone(lz_flags);
00235         return (1);
00236 }
00237 
00242 Int16
00243 InitWorld(void)
00244 {
00245         return (1);
00246 }
00247 
00253 welem_t
00254 getWorld(UInt32 pos)
00255 {
00256         if (pos > MapMul())
00257                 return (0);
00258                 
00259         return (((welem_t *)worldPtr)[pos]);
00260 }
00261 
00267 void
00268 setWorld(UInt32 pos, welem_t value)
00269 {
00270         if (pos > MapMul())
00271                 return;
00272 
00273         ((welem_t *)worldPtr)[pos] = value;
00274 }
00275 
00282 void
00283 setWorldAndFlag(UInt32 pos, welem_t value, selem_t status)
00284 {
00285         if (pos > MapMul())
00286                 return;
00287 
00288         ((welem_t *)worldPtr)[pos] = value;
00289         ((selem_t *)flagPtr)[pos] = status;
00290 }
00291 
00297 selem_t
00298 getWorldFlags(UInt32 pos)
00299 {
00300         if (pos > MapMul())
00301                 return (0);
00302         return (((selem_t *)flagPtr)[pos]);
00303 }
00304 
00310 void
00311 setWorldFlags(UInt32 pos, selem_t value)
00312 {
00313         if (pos > MapMul())
00314                 return;
00315         ((selem_t *)flagPtr)[pos] = value;
00316 }
00317 
00323 void
00324 andWorldFlags(UInt32 pos, selem_t value)
00325 {
00326         if (pos > MapMul())
00327                 return;
00328         ((selem_t *)flagPtr)[pos] &= value;
00329 }
00330 
00336 void
00337 orWorldFlags(UInt32 pos, selem_t value)
00338 {
00339         if (pos > MapMul())
00340                 return;
00341         ((selem_t *)flagPtr)[pos] |= value;
00342 }
00343 
00350 void
00351 getWorldAndFlag(UInt32 pos, welem_t *world, selem_t *flag)
00352 {
00353         if (pos > MapMul())
00354                 return;
00355         *world = ((welem_t *)worldPtr)[pos];
00356         *flag = ((selem_t *)flagPtr)[pos];
00357 }
00358 
00362 void
00363 PurgeWorld(void)
00364 {
00365         ReleaseZone(lz_world);
00366         ReleaseZone(lz_flags);
00367 }
00368 
00377 UInt32
00378 scaleNumber(UInt32 old_value, Char *scale)
00379 {
00380         const char si_scale[] = " KMBTQ";
00381         const char *at_scale = si_scale;
00382         while (old_value > MILLION) {
00383                 at_scale++;
00384                 old_value /= 1000;
00385         }
00386         *scale = *at_scale;
00387         return (old_value);
00388 }
00389 
00397 void
00398 setGameBit(gamestatusbit_t bit, UInt8 value)
00399 {
00400         GG.gas_bits &= (~bit & 0xff);
00401         if (value) GG.gas_bits |= bit;
00402 }
00403 
00409 UInt8
00410 getGameBit(gamestatusbit_t bit)
00411 {
00412         return (GG.gas_bits & bit);
00413 }

Generated on Mon Aug 30 19:44:16 2004 for pocketcity by doxygen1.2.18