// get difference between timestamps $sql = "SELECT TIMESTAMPDIFF(MINUTE, '{$prev_timestamp}', '{$curr_timestamp}')"; $stmt = $conn->prepare($sql); $stmt->execute(); $record = $stmt->fetch(); $minutes_elapsed = $record[0]; // determine number of blocks grown $prevGrowth = $cityInfo->sectorBlocks[$prevSector] + $minutes_elapsed; // cap value if it is larger than number of blocks $prevGrowth = min($prevGrowth, $nBlocks - $nUsedBlocks); // update blocks value $sql = "UPDATE CityBlocks SET nBlocks={$prevGrowth} WHERE cityID={$cityID} AND sector='{$prevSector}'"; $conn->exec($sql); } // update stuff $cityInfo = CityData::getCityInfo($cityName, $username); $nUsedBlocks = CityData::getUsedBlocksCount($cityInfo); // update current with growth if ($currentSector != SECTOR_NONE && $nBlocks > $nUsedBlocks) { // determine growth level $nBlocks = min($cityInfo->sectorBlocks[$currentSector] + $growth, $nBlocks - $nUsedBlocks); // update blocks value $sql = "UPDATE CityBlocks SET nBlocks={$nBlocks} WHERE cityID={$cityID} AND sector='{$currentSector}'"; $conn->exec($sql); } // make current sector name into mysql form if ($currentSector == SECTOR_NONE) { $currentSector = "NULL"; } else { $currentSector = "'{$currentSector}'"; }
if (!$userOwnsCities) { $elementShownName = "#NoCitiesContent"; } else { // retrieve current city define("CURRCITY", "CityBuilder_currCity"); $currCity = 0; if (!array_key_exists(CURRCITY, $_SESSION)) { $_SESSION[CURRCITY] = $currCity; } else { $currCity = $_SESSION[CURRCITY]; } // retrieve current city info if ($currCity == null) { $currCity = 0; } $currCityInfo = CityData::getCityInfo($cities[$currCity], $username); } } ?> <script> function loadPage() { // get name of element to show var visibleElement = <?php echo "\"{$elementShownName}\""; ?> ; // load game stuff if(visibleElement == "#GameContent") {