Example #1
0
function game_adviceCave($db_game, $playerID, $easyStart)
{
    global $cfg;
    list($usec, $sec) = explode(' ', microtime());
    srand((double) $sec + (double) $usec * 100000);
    // count the empty caves that aren't the destination of an ongoing
    // movement and calculate a random number
    $query = "SELECT COUNT(caveID) AS n FROM Cave WHERE playerID = 0 AND " . "starting_position > 0";
    $result = $db_game->query($query);
    if (!$result) {
        return 0;
    }
    $row = $result->nextRow();
    if ($row['n'] == 0) {
        return 0;
    }
    $caveNumber = rand(0, $row['n'] - 1);
    $result->free($result);
    // get the caveID of the $caveNumber'th entry
    $query = "SELECT caveID FROM Cave WHERE playerID = 0 " . "AND starting_position > 0 LIMIT {$caveNumber}, 1";
    $result = $db_game->query($query);
    if (!$result || $result->isEmpty()) {
        return 0;
    }
    $row = $result->nextRow();
    // update cave $caveID to belong to the player with id $playerID
    // And set the start conditions
    require_once $cfg['GAME_RULES'];
    global $resourceTypeList, $buildingTypeList, $unitTypeList, $scienceTypeList, $defenseSystemTypeList;
    init_Buildings();
    init_Units();
    init_Resources();
    init_Sciences();
    init_DefenseSystems();
    $set = array();
    foreach ($resourceTypeList as $value) {
        $set[$value->dbFieldName] = "{$value->dbFieldName} = 0";
    }
    foreach ($buildingTypeList as $value) {
        $set[$value->dbFieldName] = "{$value->dbFieldName} = 0";
    }
    foreach ($unitTypeList as $value) {
        $set[$value->dbFieldName] = "{$value->dbFieldName} = 0";
    }
    foreach ($scienceTypeList as $value) {
        $set[$value->dbFieldName] = "{$value->dbFieldName} = 0";
    }
    foreach ($defenseSystemTypeList as $value) {
        $set[$value->dbFieldName] = "{$value->dbFieldName} = 0";
    }
    $set['protection_end'] = 'protection_end = (NOW() + INTERVAL ' . BEGINNER_PROTECTION_HOURS . ' HOUR)+0';
    $set['secureCave'] = 'secureCave = 1';
    if (!$easyStart) {
        foreach ($cfg['START_SETTINGS'] as $key => $value) {
            $set[$key] = "{$key} = {$value}";
        }
    } else {
        // read start values, if fail, simply don't change set array
        $query = "SELECT * FROM StartValue";
        if ($result = $db_game->query($query)) {
            while ($entry = $result->nextRow()) {
                $set[$entry[dbFieldName]] = "{$entry[dbFieldName]} = '{$entry[value]}'";
            }
        }
    }
    $setArray = $set;
    $set = implode(",", $set);
    $query = "UPDATE Cave SET playerID = {$playerID}, {$set} WHERE caveID = {$row['caveID']}";
    $result = $db_game->query($query);
    if (!$result) {
        echo $query;
        return 0;
    }
    // write science start values to the player table
    $set = array();
    foreach ($scienceTypeList as $value) {
        $set[$value->dbFieldName] = $setArray[$value->dbFieldName];
        // get all science sets
    }
    $query = "UPDATE Player SET " . implode($set, ", ") . " WHERE playerID = {$playerID}";
    if (!$db_game->query($query)) {
        echo $query;
        // not that worse, so don't delete account
    }
    return $row['caveID'];
}
Example #2
0
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */
/** ensure this file is being included by a parent file */
defined('_VALID_UA') or die('Direct Access to this location is not allowed.');
require_once 'rules/game.rules.php';
require_once 'rules/effects.list.php';
require_once 'rules/wonder.rules.php';
require_once 'rules/government.rules.php';
require_once 'rules/relation.list.php';
require_once 'rules/hero.rules.php';
require_once "config.inc.php";
init_Buildings();
init_Units();
init_Resources();
init_Sciences();
init_DefenseSystems();
init_Effects();
init_heroSkills();
function sign($value)
{
    if ($value > 0) {
        return 1;
    }
    if ($value < 0) {
        return -1;
    }
    return 0;
Example #3
0
 function _get_game_rules()
 {
     global $cfg;
     // init game rules
     require_once $cfg['cfgpath'] . "game_rules.php";
     global $resourceTypeList, $buildingTypeList, $unitTypeList, $defenseSystemTypeList;
     $resourceTypeList = $buildingTypeList = $unitTypeList = $defenseSystemTypeList = '';
     init_Resources();
     init_Buildings();
     init_Units();
     init_DefenseSystems();
     $this->resource = $resourceTypeList;
     unset($resourceTypeList);
     $this->building = $buildingTypeList;
     unset($buildingTypeList);
     $this->unit = $unitTypeList;
     unset($unitTypeList);
     $this->defense = $defenseSystemTypeList;
     unset($defenseSystemTypeList);
 }
Example #4
0
 function _get_game_rules()
 {
     global $cfg;
     // init game rules
     require_once $cfg['cfgpath'] . "rules/game.rules.php";
     init_Resources();
     init_Buildings();
     init_Units();
     init_DefenseSystems();
     init_Sciences();
     $this->resource = $GLOBALS['resourceTypeList'];
     $this->building = $GLOBALS['buildingTypeList'];
     $this->unit = $GLOBALS['unitTypeList'];
     $this->defense = $GLOBALS['defenseSystemTypeList'];
     $this->science = $GLOBALS['scienceTypeList'];
 }