예제 #1
0
function AddToPlanet($CurrentPlanet, $element, $mode, $charge = false)
{
    global $resources, $resource, $reslist;
    //Well, we need to work out the cost for the points and edit the planets table
    //Standard construction
    //Get the cost
    $cost = BuildingCost($element, $CurrentPlanet[$resource[$element]] + $mode);
    $chargestr = '';
    if ($charge) {
        //If we are changine
        foreach ($resources as $res) {
            //loop through resources
            //Now add to query
            $chargestr .= ", `" . $res . "` = `" . $res . "` - '" . $cost[$res] . "' ";
        }
    }
    //And we will want a + in the query
    $p_sign = "+";
    //If its deconstruction though..
    if ($mode < 0) {
        //Deconstructon
        //Get the cost
        $cost = BuildingCost($element, $CurrentPlanet[$resource[$element]]);
        //And we will want a - in the query
        $p_sign = "-";
    }
    //start total cost
    $tcost = 0;
    //Now the resources which count towards points
    foreach ($resources as $res) {
        //Add them to the total
        $tcost += $cost[$res];
    }
    //Now update the table
    $qry = "UPDATE {{table}} SET `" . $resource[$element] . "` = `" . $resource[$element] . "` " . $p_sign . " " . idstring(abs($mode)) . " " . $chargestr . " WHERE `id` = '" . $CurrentPlanet['id'] . "' LIMIT 1 ;";
    $return = doquery($qry, 'planets', false);
    //If it is less than 100, update slots used
    if ($element < 100) {
        doquery("UPDATE {{table}} SET `field_current` = `field_current` " . $p_sign . " " . idstring(abs($mode)) . " WHERE `id` = '" . $CurrentPlanet['id'] . "' LIMIT 1 ;", 'planets', false);
    }
    //Now update the users stats
    //	Are we making fleet?
    $fleet_points = 0;
    if (in_array($element, $reslist['fleet'])) {
        $fleet_points += $mode;
    }
    //Update in database
    doquery("UPDATE {{table}} SET `total_points` = `total_points` + '" . $tcost . "', `fleet_points` = `fleet_points` + '" . $fleet_points . "' WHERE `id` = '" . $CurrentPlanet['id_owner'] . "' LIMIT 1 ;", 'users');
    //Return the result
    return $return;
}
예제 #2
0
function BuildingTime($element, $level, $CurrentPlanet, $CurrentUser = array())
{
    global $game_config, $reslist, $resource;
    //note that betweem $CurrentSet and $CurrentPLanet, all thats needed is...
    /*
    buildings
    	$resource[14]
    	$resource[15]
    shipyard
    	$resource[21]
    	$resource[15]
    research
    	id_owner
    	current_planet
    	$resource[31]
    	$resource[123]
    */
    //Merge the user and planet
    $CurrentSet = array();
    $need = array($resource[14], $resource[15], $resource[21], 'id_owner', 'current_planet', $resource[31], $resource[123]);
    foreach ($need as $key) {
        $CurrentSet[$key] = $CurrentUser[$key] + $CurrentPlanet[$key];
    }
    //We need to work out multiplier
    //Is it a building?
    if (in_array($element, $reslist['build'])) {
        // For buildings
        $multiplier = 1 / ($CurrentSet[$resource['14']] + 1) * pow(0.5, $CurrentSet[$resource['15']]);
        //Else if its a ship or defense
    } elseif (in_array($element, $reslist['defense']) || in_array($element, $reslist['fleet'])) {
        // For shipyard / defense
        $multiplier = 1 / ($CurrentSet[$resource['21']] + 1) * pow(1 / 2, $CurrentSet[$resource['15']]);
        //Else if its a research
    } elseif (in_array($element, $reslist['tech'])) {
        // For research
        //Intergalactic Research Network
        $lablevel = $CurrentSet[$resource['31']];
        //If we have IRN
        if ($CurrentSet[$resource[123]] > 0) {
            $empire = doquery("SELECT `" . $resource['31'] . "` FROM {{table}} WHERE `id_owner` ='" . $CurrentSet['id_owner'] . "' AND `id` <>'" . $CurrentSet['current_planet'] . "' ORDER BY `" . $resource['31'] . "` DESC LIMIT 0 , " . $CurrentSet[$resource[123]] . " ;", 'planets');
            //Loop through colonies
            while ($colonie = mysql_fetch_array($empire)) {
                //Add there lab level to combined lab level
                $lablevel += $colonie[$resource['31']];
            }
        }
        //End IRN
        $multiplier = 1 / (($lablevel + 1) * 2);
    } else {
        //Its not one of the above
        $multiplier = 1;
    }
    //Now work out the cost
    $cost = BuildingCost($element, $level);
    //Now work out time
    $time = ($cost['metal'] + $cost['crystal']) / $game_config['game_speed'];
    //Base time in hours
    $time *= $multiplier;
    //Use the multiplier
    $time = floor($time * 3600);
    //Convert to seconds
    //Return time
    return $time;
}
예제 #3
0
function UpdateQueue()
{
    global $planetrow, $resource, $resources;
    //We need to get queue into an array
    $q = explode(";", $planetrow['build_queue']);
    if ($planetrow['build_queue'] == '') {
        $q = array();
    }
    //The first item is already paid for
    $chargefor = false;
    //Loop through the queue
    foreach ($q as $id => $row) {
        //Explode the row
        $row = explode(",", $row);
        //Are we being charged?
        if ($chargefor) {
            //How much?
            $cost = BuildingCost($row[0], $planetrow[$resource[$row[0]]] + $row[1]);
            //Can we afford that
            $canafford = true;
            foreach ($cost as $res => $need) {
                if ($planetrow[$res] < $need && $res != 'sum') {
                    //We don't have enough
                    $canafford = false;
                }
            }
            //So can we afford it?
            if ($canafford) {
                //OK, we can afford it, remove the resources
                $remove = array();
                foreach ($resources as $res) {
                    $remove[] = "`" . $res . "` = `" . $res . "` - '" . $cost[$res] . "'";
                }
                doquery("UPDATE {{table}} SET " . implode(" , ", $remove) . " WHERE `id` = '" . $planetrow['id'] . "' LIMIT 1 ;", 'planets', false);
                //How long will it take?
                $willtake = BuildingTime($row[0], $planetrow[$resource[$row[0]]] + $row[1], $planetrow, $user);
                //Do we have that time?
                if ($planetrow['build_queue_start'] + $willtake > time()) {
                    //Stop now
                    break;
                } else {
                    //we have time, build it.
                    AddToPlanet($planetrow, $row[0], $row[1]);
                    //Add that to the time?
                    $planetrow['build_queue_start'] += $willtake;
                    //Remove from the queue
                    unset($q[$id]);
                    //Next one is new so we should charge for it.
                    $chargefor = true;
                }
            } else {
                //We can't afford it, remove from queue and send a message to the user.
                //Remove from queue
                unset($q[$id]);
                //Charge for next one too
                $chargefor = true;
                //Actually don't send coz those messages are annoying.
            }
        } else {
            //First tiem already paid for, try and build
            //How long will it take?
            $willtake = BuildingTime($row[0], $planetrow[$resource[$row[0]]] + $row[1], $planetrow, $user);
            //Do we have that time?
            if ($planetrow['build_queue_start'] + $willtake > time()) {
                //Stop now
                $chargefor = false;
                break;
            } else {
                //we have time, build it.
                AddToPlanet($planetrow, $row[0], $row[1]);
                //Add that to the time?
                $planetrow['build_queue_start'] += $willtake;
                //Remove from the queue
                unset($q[$id]);
                //Next one is new so we should charge for it.
                $chargefor = true;
            }
        }
    }
    //Implode queue back into a string
    $planetrow['build_queue'] = implode(";", $q);
    //Update the table and return the result
    return doquery("UPDATE {{table}} SET `build_queue` = '" . $planetrow['build_queue'] . "', `build_queue_start` = '" . $planetrow['build_queue_start'] . "' WHERE `id` = '" . $planetrow['id'] . "' LIMIT 1 ;", 'planets', false);
}