コード例 #1
0
ファイル: weather.script.php プロジェクト: microlefes/Game
function weather_generate()
{
    global $db;
    // get regions
    $regions = getRegions();
    // get weather
    $weather = weather_getWeatherWonders();
    foreach ($regions as $region) {
        if (!$region['startRegion']) {
            weather_log('Skipping unused region %s.', $region['name']);
            continue;
        }
        weather_log('Processing region %s.', $region['name']);
        // pick a random weather
        $regionweather = $weather[array_rand($weather)];
        weather_log('Selected Weather: %s', $regionweather->name);
        // save weather information in DB
        $sql = $db->prepare("UPDATE " . REGIONS_TABLE . "\n                         SET weather = :weather\n                         WHERE regionID = :regionID");
        $sql->bindValue('weather', $regionweather->weatherID, PDO::PARAM_INT);
        $sql->bindValue('regionID', $region['regionID'], PDO::PARAM_INT);
        if (!$sql->execute()) {
            weather_log('Failed to execute query: %s', $query);
            return -1;
        }
        $sql = $db->prepare("INSERT INTO " . EVENT_WEATHER_TABLE . "\n                         (regionID, weatherID, impactID, start, end)\n                         VALUES (:regionID, :weatherID, :impactID, :start, :end)");
        foreach ($regionweather->impactList as $impactID => $impact) {
            $delay = (int) ($impact['delay'] * WEATHER_TIME_BASE_FACTOR);
            $now = time();
            $sql->bindValue('regionID', $region['regionID'], PDO::PARAM_INT);
            $sql->bindValue('weatherID', $regionweather->weatherID, PDO::PARAM_INT);
            $sql->bindValue('impactID', $impactID, PDO::PARAM_INT);
            $sql->bindValue('start', time_toDatetime($now), PDO::PARAM_STR);
            $sql->bindValue('end', time_toDatetime($now + $delay), PDO::PARAM_STR);
            if (!$sql->execute()) {
                weather_log('Failed to execute query');
                return -1;
            }
        }
    }
}
コード例 #2
0
ファイル: weather.script.php プロジェクト: agatho/uaenhanced
function weather_generate($db)
{
    global $db;
    // get regions
    $regions = getRegions();
    // get weather
    $weather = weather_getWeatherWonders($db);
    foreach ($regions as $region) {
        if (!$region['startRegion']) {
            weather_log('Skipping unused region %s.', $region['name']);
            continue;
        }
        weather_log('Processing region %s.', $region['name']);
        // pick a random weather
        $regionweather = $weather[array_rand($weather)];
        weather_log('Selected Weather: %s', $regionweather->name);
        // save weather information in DB
        $query = "UPDATE `Regions` " . "SET `weather` = {$regionweather->weatherID} " . "WHERE `regionID` = {$region['regionID']}";
        if (!$db->query($query)) {
            weather_log('Failed to execute query: %s', $query);
            return -1;
        }
        foreach ($regionweather->impactList as $impactID => $impact) {
            $delay = (int) (($delayDelta + $impact['delay']) * WEATHER_TIME_BASE_FACTOR);
            $now = time();
            $query = sprintf("INSERT INTO Event_weather " . "(`regionID`, `weatherID`, `impactID`, `start`, `end`) " . "VALUES (%d, %d, %d, '%s', '%s')", $region['regionID'], $regionweather->weatherID, $impactID, time_toDatetime($now), time_toDatetime($now + $delay));
            if (!$db->query($query)) {
                weather_log('Failed to execute query: %s', $query);
                return -1;
            }
        }
    }
}