Example #1
0
/**
 * This file is part of XNova:Legacies
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @see http://www.xnova-ng.org/
 *
 * Copyright (c) 2009-2010, XNova Support Team <http://www.xnova-ng.org>
 * All rights reserved.
 *
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *                                --> NOTICE <--
 *  This file is part of the core development branch, changing its contents will
 * make you unable to use the automatic updates manager. Please refer to the
 * documentation for further information about customizing XNova.
 *
 */
function DefensesBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $dpath, $_POST;
    if (isset($_POST['fmenge'])) {
        // On vient de Cliquer ' Construire '
        // Et y a une liste de doléances
        // Ici, on sait precisement ce qu'on aimerait bien construire ...
        // Gestion de la place disponible dans les silos !
        $Missiles[502] = $CurrentPlanet[$resource[502]];
        $Missiles[503] = $CurrentPlanet[$resource[503]];
        $SiloSize = $CurrentPlanet[$resource[44]];
        $MaxMissiles = $SiloSize * 10;
        // On prend les missiles deja dans la queue de fabrication aussi (ca aide)
        $BuildQueue = $CurrentPlanet['b_hangar_id'];
        $BuildArray = explode(";", $BuildQueue);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode(",", $BuildArray[$QElement]);
            if ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }
        }
        foreach ($_POST['fmenge'] as $Element => $Count) {
            // Construction d'Element recuperés sur la page de Flotte ...
            // ATTENTION ! La file d'attente Flotte est Commune a celle des Defenses
            // Dans fmenge, on devrait trouver un tableau des elements constructibles etdu nombre d'elements souhaités
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                // Cas particulier (Petit Bouclier et Grand Bouclier
                // ne peuvent exister qu'une seule et unique fois
                $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                $IsBuild = $CurrentPlanet[$resource[407]] >= 1 ? true : false;
                if ($Element == 407 || $Element == 408) {
                    if ($InQueue === false && !$IsBuild) {
                        $Count = 1;
                    }
                }
                // On verifie si on a les technologies necessaires a la construction de l'element
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    // On verifie combien on sait faire de cet element au max
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    // Testons si on a de la place pour ces nouveaux missiles !
                    if ($Element == 502 || $Element == 503) {
                        // Cas particulier des missiles
                        $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                        $MissilesSpace = $MaxMissiles - $ActuMissiles;
                        if ($Element == 502) {
                            if ($Count > $MissilesSpace) {
                                $Count = $MissilesSpace;
                            }
                        } else {
                            if ($Count > floor($MissilesSpace / 2)) {
                                $Count = floor($MissilesSpace / 2);
                            }
                        }
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Missiles[$Element] += $Count;
                    } else {
                        // Si pas assez de ressources, on ajuste le nombre d'elements
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        // Veuillez avoir l'obligeance de construire le Chantier Spacial !!
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    // -------------------------------------------------------------------------------------------------------
    // Construction de la page du Chantier (car si j'arrive ici ... c'est que j'ai tout ce qu'il faut pour ...
    $TabIndex = 0;
    $PageTable = "";
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 400 && $Element <= 599) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                // Disponible à la construction
                // On regarde si on peut en acheter au moins 1
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                // On regarde combien de temps il faut pour construire l'element
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                // Disponibilité actuelle
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                // Construction des 3 cases de la ligne d'un element dans la page d'achat !
                // Début de ligne
                $PageTable .= "\n<tr>";
                // Imagette + Link vers la page d'info
                $PageTable .= "<th class=l>";
                $PageTable .= "<a href=infos." . PHPEXT . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                // Description
                $PageTable .= "<td class=l>";
                $PageTable .= "<a href=infos." . PHPEXT . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                // On affiche le 'prix' avec eventuellement ce qui manque en ressource
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                // On affiche le temps de construction (c'est toujours tellement plus joli)
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                // Case nombre d'elements a construire
                $PageTable .= "<th class=k>";
                // Si ... Et Seulement si je peux construire je mets la p'tite zone de saisie
                if ($CanBuildOne) {
                    if ($Element == Legacies_Empire::ID_DEFENSE_SMALL_SHIELD_DOME || $Element == Legacies_Empire::ID_DEFENSE_LARGE_SHIELD_DOME) {
                        $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                        $IsBuild = $CurrentPlanet[$resource[$Element]] >= 1 ? true : false;
                        $BuildIt = $InQueue === false && !$IsBuild ? true : false;
                    } else {
                        $BuildIt = true;
                    }
                    if (!$BuildIt) {
                        $PageTable .= "<font color=\"red\">" . $lang['only_one'] . "</font>";
                    } else {
                        $TabIndex++;
                        $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=5 maxlength=5 value=0 tabindex=" . $TabIndex . ">";
                        $PageTable .= "</th>";
                    }
                } else {
                    $PageTable .= $lang['no_enought_res'] . "</th>";
                }
                // Fin de ligne (les 3 cases sont construites !!
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    // La page se trouve dans $PageTable;
    $parse['buildlist'] = $PageTable;
    // Et la liste de constructions en cours dans $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    // fragmento de template
    $page .= parsetemplate(gettemplate('buildings_defense'), $parse);
    display($page, $lang['Defense']);
}
Example #2
0
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $phpEx, $dpath, $_POST;
    if ($CurrentUser['urlaubs_modus'] == 0) {
        if (isset($_POST['fmenge'])) {
            // Es wurde 'Bauen' geklickt
            // Und hat auch eine Liste von [?]
            $AddedInQueue = false;
            // Gut, hier weiss man was und wieviel gebaut werden soll.
            foreach ($_POST['fmenge'] as $Element => $Count) {
                // Bau der Flotte auf der Flottenseite
                // ACHTUNG ! Die Warteschlange der Flotte und Verteidigung werden zusammen verarbeitet.
                // In fmenge, sollte man eine Tabelle der Elemente Baugrundstücke und der Anzahl der Elemente haben
                $Element = intval($Element);
                $Count = intval($Count);
                if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                    $Count = MAX_FLEET_OR_DEFS_PER_ROW;
                }
                if ($Count != 0) {
                    // Verified, wenn man die notwendige Technologie hat für den Bau des aktuellen Elements
                    if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                        // Verified, hole maximal mögliche Anzahl
                        $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                        // Wenn nicht genügend Ressourcen vorhanden sind, wird eine Anpassung der Anzahl der Elemente vorgenommen
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Ressource = GetElementRessources($Element, $Count);
                        $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                        if ($Count >= 1) {
                            $CurrentPlanet['metal'] -= $Ressource['metal'];
                            $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                            $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                            $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                        }
                    }
                }
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // Wenn nix gebaut wird / werden kann
    if ($CurrentPlanet[$resource[21]] == 0) {
        // Veuillez avoir l'obligeance de construire le Chantier Spacial !!
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    // -------------------------------------------------------------------------------------------------------
    // Bau der Seite der Baustelle (denn wenn ich hier ... ist, dass ich alles, was Sie brauchen, um ...
    $TabIndex = 0;
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 201 && $Element <= 399) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                // Disponible à la construction
                // On regarde si on peut en acheter au moins 1
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                // On regarde combien de temps il faut pour construire l'element
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                // Disponibilité actuelle
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                // Construction des 3 cases de la ligne d'un element dans la page d'achat !
                // Début de ligne
                $PageTable .= "\n<tr>";
                // Imagette + Link vers la page d'info
                $PageTable .= "<th class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                // Description
                $PageTable .= "<td class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                // On affiche le 'prix' avec eventuellement ce qui manque en ressource
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                // On affiche le temps de construction (c'est toujours tellement plus joli)
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                // Case nombre d'elements a construire
                $PageTable .= "<th class=k>";
                // Si ... Et Seulement si je peux construire je mets la p'tite zone de saisie
                if ($CanBuildOne) {
                    $TabIndex++;
                    $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=5 maxlength=8 value=0 tabindex=" . $TabIndex . ">";
                }
                $PageTable .= "</th>";
                // Fin de ligne (les 3 cases sont construites !!
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    // La page se trouve dans $PageTable;
    $parse['buildlist'] = $PageTable;
    // Et la liste de constructions en cours dans $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_fleet'), $parse);
    display($page, $lang['Fleet']);
}
Example #3
0
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $phpEx, $dpath, $_POST;
    if (isset($_POST['fmenge'])) {
        // On vient de Cliquer ' Construire '
        // Et y a une liste de dol&eacute;ances
        $AddedInQueue = false;
        // Ici, on sait precisement ce qu'on aimerait bien construire ...
        foreach ($_POST['fmenge'] as $Element => $Count) {
            // Construction d'Element recuperés sur la page de Flotte ...
            // ATTENTION ! La file d'attente Flotte est Commune a celle des Defenses
            // Dans fmenge, on devrait trouver un tableau des elements constructibles et du nombre d'elements souhaités
            $Element = floatval($Element);
            $Count = floatval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                // On verifie si on a les technologies necessaires a la construction de l'element
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    // On verifie combien on sait faire de cet element au max
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    // Si pas assez de ressources, on ajuste le nombre d'elements
                    if ($Count > $MaxElements) {
                        $Count = $MaxElements;
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        if ($BuildTime > 0) {
                            $CurrentPlanet['metal'] -= $Ressource['metal'];
                            $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                            $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                            if ($Element == 214) {
                                $requete = doquery("SELECT rpg_destructeur FROM {{table}} WHERE id = " . $CurrentUser['id'] . ";", 'users', true);
                                if ($requete['rpg_destructeur'] == 1) {
                                    $Count = 2 * $Count;
                                }
                            }
                            $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                        } else {
                            $CurrentPlanet['metal'] -= $Ressource['metal'];
                            $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                            $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                            if ($Element == 214) {
                                $requete = doquery("SELECT rpg_destructeur FROM {{table}} WHERE id = " . $CurrentUser['id'] . ";", 'users', true);
                                if ($requete['rpg_destructeur'] == 1) {
                                    $Count = 2 * $Count;
                                }
                            }
                            $NewFleetNumber = $CurrentPlanet[$resource[$Element]] + $Count;
                            $QryUpdatefleet = "UPDATE {{table}} SET ";
                            $QryUpdatefleet .= "`{$resource[$Element]}` = '" . $NewFleetNumber . "' ";
                            $QryUpdatefleet .= "WHERE ";
                            $QryUpdatefleet .= "`id` = '" . $CurrentPlanet['id'] . "'";
                            doquery($QryUpdatefleet, 'planets');
                        }
                    }
                }
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        // Veuillez avoir l'obligeance de construire le Chantier Spacial !!
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    // -------------------------------------------------------------------------------------------------------
    // Construction de la page du Chantier (car si j'arrive ici ... c'est que j'ai tout ce qu'il faut pour ...
    $TabIndex = 0;
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 201 && $Element <= 399) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                // Disponible à la construction
                // On regarde si on peut en acheter au moins 1
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                // On regarde combien de temps il faut pour construire l'element
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                // Disponibilité actuelle
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                // Construction des 3 cases de la ligne d'un element dans la page d'achat !
                // Début de ligne
                $PageTable .= "\n<tr>";
                // Imagette + Link vers la page d'info
                $PageTable .= "<th class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                // Description
                $PageTable .= "<td class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                // On affiche le 'prix' avec eventuellement ce qui manque en ressource
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                // On affiche le temps de construction (c'est toujours tellement plus joli)
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                // Case nombre d'elements a construire
                $PageTable .= "<th class=k>";
                // Si ... Et Seulement si je peux construire je mets la p'tite zone de saisie
                if ($CanBuildOne) {
                    $TabIndex++;
                    $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=12 maxlength=12 value=0 tabindex=" . $TabIndex . ">";
                    $maxElement = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    if ($maxElement > MAX_FLEET_OR_DEFS_PER_ROW) {
                        $maxElement = MAX_FLEET_OR_DEFS_PER_ROW;
                    }
                    $PageTable .= "<br><a href='javascript:' onclick=\"document.getElementsByName('fmenge[" . $Element . "]')[0].value = '{$maxElement}';\">(Max : {$maxElement})</a>";
                }
                $PageTable .= "</th>";
                // Fin de ligne (les 3 cases sont construites !!
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    // La page se trouve dans $PageTable;
    $parse['buildlist'] = $PageTable;
    // Et la liste de constructions en cours dans $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_fleet'), $parse);
    display($page, $lang['Fleet']);
}
Example #4
0
function DefensesBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $planetrow, $lang, $pricelist, $resource, $phpEx, $dpath, $_POST;
    if (isset($_GET[action])) {
        switch ($_GET[action]) {
            case "cancelqueue":
                $ElementQueue = explode(';', $CurrentPlanet['b_hangar_id']);
                foreach ($ElementQueue as $ElementLine => $Element) {
                    if ($Element != '') {
                        $Element = explode(',', $Element);
                        $ResourcesToUpd[metal] += floor($pricelist[$Element[0]][metal] * $Element[1]);
                        $ResourcesToUpd[crystal] += floor($pricelist[$Element[0]][crystal] * $Element[1]);
                        $ResourcesToUpd[deuterium] += floor($pricelist[$Element[0]][deuterium] * $Element[1]);
                        $ResourcesToUpd[tachyon] += floor($pricelist[$Element[0]][tachyon] * $Element[1]);
                    }
                }
                $SetRes = "UPDATE {{table}} SET ";
                $SetRes .= "`metal` = metal + '" . $ResourcesToUpd[metal] . "', ";
                $SetRes .= "`crystal` = crystal + '" . $ResourcesToUpd[crystal] . "', ";
                $SetRes .= "`deuterium` = deuterium + '" . $ResourcesToUpd[deuterium] . "', ";
                $SetRes .= "`tachyon` = tachyon + '" . $ResourcesToUpd[tachyon] . "', ";
                $SetRes .= "`b_hangar` = '', ";
                $SetRes .= "`b_hangar_id` = ''";
                $SetRes .= " WHERE `id` = '" . $CurrentPlanet['id'] . "'";
                doquery($SetRes, 'planets');
                header("location: " . $_SERVER['PHP_SELF'] . "?mode=" . $_GET[mode]);
                exit;
                break;
        }
    }
    if (isset($_POST['fmenge'])) {
        $Missiles[502] = $CurrentPlanet[$resource[502]];
        $Missiles[503] = $CurrentPlanet[$resource[503]];
        $SiloSize = $CurrentPlanet[$resource[44]];
        $MaxMissiles = $SiloSize * 10;
        $BuildQueue = $CurrentPlanet['b_hangar_id'];
        $BuildArray = explode(";", $BuildQueue);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode(",", $BuildArray[$QElement]);
            if ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }
        }
        foreach ($_POST['fmenge'] as $Element => $Count) {
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                $IsBuild = $CurrentPlanet[$resource[407]] >= 1 ? true : false;
                if ($Element == 407 || $Element == 408) {
                    if ($InQueue === false && !$IsBuild) {
                        $Count = 1;
                    }
                }
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    if ($Element == 502 || $Element == 503) {
                        $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                        $MissilesSpace = $MaxMissiles - $ActuMissiles;
                        if ($Element == 502) {
                            if ($Count > $MissilesSpace) {
                                $Count = $MissilesSpace;
                            }
                        } else {
                            if ($Count > floor($MissilesSpace / 2)) {
                                $Count = floor($MissilesSpace / 2);
                            }
                        }
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Missiles[$Element] += $Count;
                    } else {
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['tachyon'] -= $Ressource['tachyon'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    if ($CurrentPlanet[$resource[21]] == 0) {
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    $TabIndex = 0;
    $PageTable = "";
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 400 && $Element <= 599) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                $PageTable .= "\n<tr>";
                $PageTable .= "<th class=k>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                $PageTable .= "<td class=k>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                $PageTable .= "<th class=k>";
                if ($CanBuildOne) {
                    $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                    $IsBuild = $CurrentPlanet[$resource[407]] >= 1 ? true : false;
                    $BuildIt = true;
                    if ($Element == 407 || $Element == 408) {
                        $BuildIt = false;
                        if ($InQueue === false && !$IsBuild) {
                            $BuildIt = true;
                        }
                    }
                    if (!$BuildIt) {
                        $PageTable .= "<font color=\"red\">" . $lang['only_one'] . "</font>";
                    } else {
                        $TabIndex++;
                        $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=7 maxlength=7 value=0 tabindex=" . $TabIndex . ">";
                        $PageTable .= "</th>";
                    }
                } else {
                    $PageTable .= "</th>";
                }
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    $parse['buildlist'] = $PageTable;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_defense'), $parse);
    display($page, $lang['Defense']);
}
Example #5
0
/**
 * This file is part of XNova:Legacies
 *
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @see http://www.xnova-ng.org/
 *
 * Copyright (c) 2009-2010, XNova Support Team <http://www.xnova-ng.org>
 * All rights reserved.
 *
 * 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 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *                                --> NOTICE <--
 *  This file is part of the core development branch, changing its contents will
 * make you unable to use the automatic updates manager. Please refer to the
 * documentation for further information about customizing XNova.
 *
 */
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $pricelist, $lang, $resource, $dpath, $reslist;
    if (isset($_POST['fmenge'])) {
        // On vient de Cliquer ' Construire '
        // Ici, on sait precisement ce qu'on aimerait bien construire ...
        foreach ($_POST['fmenge'] as $Element => $Count) {
            // Construction d'Element recuper�s sur la page de Flotte ...
            // ATTENTION ! La file d'attente Flotte est Commune a celle des Defenses
            // Dans fmenge, on devrait trouver un tableau des elements constructibles et du nombre d'elements souhait�s
            $Element = (int) $Element;
            $Count = (int) $Count;
            $Count = $Count > MAX_FLEET_OR_DEFS_PER_ROW ? MAX_FLEET_OR_DEFS_PER_ROW : $Count;
            if (!in_array($Element, $reslist[Legacies_Empire::TYPE_SHIP]) || $Count < 1 || !IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                continue;
            }
            // On verifie combien on sait faire de cet element au max
            $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
            // Si pas assez de ressources, on ajuste le nombre d'elements
            $Count = $Count > $MaxElements ? $MaxElements : $Count;
            $Ressource = GetElementRessources($Element, $Count);
            $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
            //Correctif en attendant mieux.
            if ($CurrentPlanet['b_hangar_id'] == '') {
                $CurrentPlanet['b_hangar'] = 0;
            }
            if ($BuildTime > 0) {
                $CurrentPlanet['metal'] -= $Ressource['metal'];
                $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                if ($Element == 214 && $CurrentUser['rpg_destructeur'] == 1) {
                    $Count = $Count * 2;
                    //On multiplie les EDLM par 2
                }
                $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
            } else {
                $res = doquery("SELECT " . $resource[$Element] . " FROM {{table}} WHERE id = '" . $CurrentPlanet['id'] . "'  ;", 'planets');
                $NombreVaisseauxActuel = mysql_result($res, 0, $resource[$Element]);
                $CurrentPlanet['metal'] -= $Ressource['metal'];
                $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                $NewFleetNumber = $CurrentPlanet[$resource[$Element]] + $Count;
                if ($Element == 214 && $CurrentUser['rpg_destructeur'] == 1) {
                    $Count = $Count * 2;
                    //On multiplie les EDLM par 2
                }
                $QryUpdatefleet = "UPDATE {{table}} SET ";
                $QryUpdatefleet .= "`{$resource[$Element]}` = '" . $NombreVaisseauxActuel . "' + '" . $Count . "' ";
                $QryUpdatefleet .= "WHERE ";
                $QryUpdatefleet .= "`id` = '" . $CurrentPlanet['id'] . "'";
                doquery($QryUpdatefleet, 'planets');
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        // Veuillez avoir l'obligeance de construire le Chantier Spacial !!
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    // -------------------------------------------------------------------------------------------------------
    // Construction de la page du Chantier (car si j'arrive ici ... c'est que j'ai tout ce qu'il faut pour ...
    $TabIndex = 0;
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 201 && $Element <= 399) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                // Disponible à la construction
                // On regarde si on peut en acheter au moins 1
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                // On regarde combien de temps il faut pour construire l'element
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                // Disponibilité actuelle
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                // Construction des 3 cases de la ligne d'un element dans la page d'achat !
                // Début de ligne
                $PageTable .= "\n<tr>";
                // Imagette + Link vers la page d'info
                $PageTable .= "<th class=l>";
                $PageTable .= "<a href=infos." . PHPEXT . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                // Description
                $PageTable .= "<td class=l>";
                $PageTable .= "<a href=infos." . PHPEXT . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                // On affiche le 'prix' avec eventuellement ce qui manque en ressource
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                // On affiche le temps de construction (c'est toujours tellement plus joli)
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                // Case nombre d'elements a construire
                $PageTable .= "<th class=k>";
                // Si ... Et Seulement si je peux construire je mets la p'tite zone de saisie
                if ($CanBuildOne) {
                    $TabIndex++;
                    $PageTable .= "<input type=text id=fmenge[" . $Element . "] name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' value=0 tabindex=" . $TabIndex . ">";
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    if ($MaxElements > MAX_FLEET_OR_DEFS_PER_ROW) {
                        $MaxElements = MAX_FLEET_OR_DEFS_PER_ROW;
                    }
                    $PageTable .= '<BR><BR><A ONCLICK="document.getElementById(\'fmenge[' . $Element . ']\').value=\'' . intval($MaxElements) . '\';" STYLE="cursor:pointer;">Nombre max (' . intval($MaxElements) . ')</A></th>';
                } else {
                    $PageTable .= $lang['no_enought_res'] . '</th>';
                }
                $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                if ($MaxElements > MAX_FLEET_OR_DEFS_PER_ROW) {
                    $MaxElements = MAX_FLEET_OR_DEFS_PER_ROW;
                }
                // Fin de ligne (les 3 cases sont construites !!
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    // La page se trouve dans $PageTable;
    $parse['buildlist'] = $PageTable;
    // Et la liste de constructions en cours dans $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_fleet'), $parse);
    display($page, $lang['Fleet']);
}
Example #6
0
function DefensesBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $dpath, $_POST;
    if (isset($_POST['fmenge'])) {
        // Wenn man auf "Bauen" klickt
        // Raketen
        $Missiles[502] = $CurrentPlanet[$resource[502]];
        $Missiles[503] = $CurrentPlanet[$resource[503]];
        $SiloSize = $CurrentPlanet[$resource[44]];
        $MaxMissiles = $SiloSize * 10;
        $BuildQueue = $CurrentPlanet['b_hangar_id'];
        $BuildArray = explode(";", $BuildQueue);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode(",", $BuildArray[$QElement]);
            if ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }
        }
        foreach ($_POST['fmenge'] as $Element => $Count) {
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                //Die Kuppeln können nur einmal gebaut werden.
                $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                $IsBuildp = $CurrentPlanet[$resource[407]] >= 1 ? TRUE : FALSE;
                $IsBuildg = $CurrentPlanet[$resource[408]] >= 1 ? TRUE : FALSE;
                if ($Element == 407 && !$IsBuildp && $InQueue === FALSE) {
                    $Count = 1;
                }
                if ($Element == 408 && !$IsBuildg && $InQueue === FALSE) {
                    $Count = 1;
                }
                //Prüfen, ob man die nötige Technologie für den Bau hat
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    //Festlegen, wieviele Elemente maximal gebaut werden können
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    //Prüfen, ob in den Silos noch Platz für Raketen ist
                    if ($Element == 502 || $Element == 503) {
                        $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                        $MissilesSpace = $MaxMissiles - $ActuMissiles;
                        if ($Element == 502) {
                            if ($Count > $MissilesSpace) {
                                $Count = $MissilesSpace;
                            }
                        } else {
                            if ($Count > floor($MissilesSpace / 2)) {
                                $Count = floor($MissilesSpace / 2);
                            }
                        }
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Missiles[$Element] += $Count;
                    } else {
                        // Hat man micht genug Ress, wird die Anzahl der Schiffe entsprechend angepasst
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    //Wenn man keine Raumschiffswerft hat
    if ($CurrentPlanet[$resource[21]] == 0) {
        //Kann man acuh nichts bauen^^
        message($lang['need_hangar'], $lang['tech'][21]);
        //Und bekommt ne Fehlermeldung
    }
    // Beginn der eigentlichen Bauseite ( Also das, was der User nachher sieht )
    $TabIndex = 0;
    $PageTable = "";
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 400 && $Element <= 599) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                // Wenn man bauen kann...
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                $BuildOneElementTimeWithoutTechs = GetBuildingTimeWithoutTechs($CurrentUser, $CurrentPlanet, $Element);
                //ursprüngliche Bauzeit ermitteln
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                //benötigte Bauzeit ermitteln
                // aktuell verfügbar
                $baubar = GetMaxConstructibleShips($CurrentPlanet, $Element);
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "({$lang['builtable']}{$baubar})" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . " {$lang['builtable']} {$baubar})";
                $PageTable .= "\n<tr>";
                $PageTable .= "\r\n\t<th class=\"l\" rowspan=\"2\" width=\"120\">\r\n\t\t<a href=\"?action=internalInformations&amp;gid=" . $Element . "\"><img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top alt=" . $Element . ".gif width=120 height=120></a>\r\n\t</th>\r\n    <td class=\"c\">\r\n    \t<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n    \t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td width=\"15\"><img src=\"images/transparent.gif\" alt=\"transparent\" width=\"0\" height=\"21\"></td>\r\n\t\t\t\t\t<td><a href=\"?action=internalInformations&amp;gid=" . $Element . "\">" . $ElementName . "</a> " . $ElementNbre . "</td>\r\n\t\t\t\t\t<td width=\"100\">&nbsp;</td>\r\n    \t\t\t</tr>\r\n    \t\t</tbody>\r\n\t\t</table>\r\n    </td>\r\n</tr>\r\n<tr>\r\n    <td colspan=\"1\">\r\n    \t<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n    \t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td class=\"rechtsohneborder\" width=\"10\"><img src=\"images/transparent.gif\" alt=\"transparent\" width=\"0\" height=\"100\"></td>\r\n\t\t\t\t\t<td class=\"linksundrechtsohneborder\" width=\"80%\">" . $lang['res']['descriptions'][$Element] . "<br>&nbsp;<br>";
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                $PageTable .= "\r\n\t\t\t\t\t<br><br>\r\n        \t\t\t<td class=\"linksohneborder\" width=\"100\">";
                if ($CanBuildOne) {
                    if ($Element == 407 && $CurrentPlanet[$resource[407]] >= "1" || $Element == 407 && $CurrentPlanet['b_hangar_id'] == "407,1;" || $Element == 408 && $CurrentPlanet[$resource[408]] >= "1" || $Element == 408 && $CurrentPlanet['b_hangar_id'] == "408,1;") {
                        $PageTable .= "<p align=\"center\"><br>&nbsp;<br><font color=\"orange\">" . $lang['only_one'] . "</font></p>";
                    } else {
                        $TabIndex++;
                        $PageTable .= "<p align=\"center\"><br>&nbsp;<br><a href=\"javascript:setL(" . $Element . ");\"><img src=\"images/back.gif\" width=\"17\" style=\"vertical-align:bottom\" border=\"0\" height=\"15\" alt=\"back\"></a><input name=fmenge[" . $Element . "] size=\"5\" maxlength=\"5\" style=\"text-align: center;\" value=\"0\" onClick=\"if(this.value=='0') this.value='';\" onBlur=\"if(this.value=='') this.value='0';\" type=\"text\" tabindex=\"" . $TabIndex . "\"><a href=\"javascript:setN(" . $Element . ");\"><img src=\"images/forward.gif\" width=\"17\" style=\"vertical-align:bottom\" border=\"0\" height=\"15\" alt=\"forward\"></a><br>&nbsp;<br><a href=\"javascript:setMax(" . $Element . "," . $baubar . ")\">max</a></p>";
                        $PageTable .= "</th>";
                    }
                } else {
                    $PageTable .= "</th>";
                }
                $PageTable .= "\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</tbody>\r\n\t\t</table>\r\n    </td>\r\n</tr>\r\n<tr>\r\n    <td colspan=\"2\">\r\n    \r\n        <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n        <tbody><tr>\r\n       \r\n             <td class=\"b\">\r\n                <table width=\"100%\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">\r\n                <tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t<a class=\"b\">" . $lang['NeededRess'] . "</a><br><br>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td colspan=\"2\">\r\n\t\t\t\t\t\t<a class=\"b\">" . $lang['BuildingTime'] . "</a><br>\r\n\t\t\t\t\t\t<br>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\t\t\r\n\t\t\t\t\t<td width=\"68%\" rowspan=\"3\">";
                $PageTable .= GetRestPrice($CurrentUser, $CurrentPlanet, $Element);
                $PageTable .= "</td>\r\n                    <td width=\"20%\">" . $lang['ConstructionTimeWithoutTechs'] . "</td>\r\n                    <td width=\"12%\" align=\"right\">";
                $PageTable .= ShowBuildTimeWithoutTechs($BuildOneElementTimeWithoutTechs);
                $PageTable .= "</td>\r\n                </tr>\r\n                <tr>\r\n                    <td>\r\n                        " . $lang['TechBonus'] . ":\r\n                    </td>\r\n                                \r\n                    <td align=\"right\">";
                $PageTable .= ShowTechBonus($BuildOneElementTimeWithoutTechs - $BuildOneElementTime);
                $PageTable .= "</td>\r\n                </tr>\r\n\t\t\t\t\r\n\t\t\t\t<tr>\r\n                    <td>&nbsp;</td>          \r\n                    <td align=\"right\">&nbsp;</td>\r\n                </tr>\r\n\t\t\t\t\r\n                 <tr>\r\n                    <td colspan=\"2\" height=\"5\"></td>          \r\n                </tr>\r\n                <tr>\r\n\t\t\t\t\t<td>&nbsp;</td>\r\n                    <td>" . $lang['ConstructionTime'] . "</td>\r\n                    <td align=\"right\">";
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>\r\n                </tr>\r\n                </tbody></table>\r\n            </td>\r\n        </tr>\r\n        </tbody></table><br>";
                // Fin de ligne (les 3 cases sont construites !!
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    // La page se trouve dans $PageTable;
    $parse['buildlist'] = $PageTable;
    // Et la liste de constructions en cours dans $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    // fragmento de template
    $page .= parsetemplate(gettemplate('buildings_defense'), $parse);
    display($page, $lang['Defense']);
}
Example #7
0
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $planetrow, $lang, $pricelist, $resource, $phpEx, $dpath, $_POST;
    if (isset($_GET[action])) {
        switch ($_GET[action]) {
            case "cancelqueue":
                $ElementQueue = explode(';', $CurrentPlanet['b_hangar_id']);
                foreach ($ElementQueue as $ElementLine => $Element) {
                    if ($Element != '') {
                        $Element = explode(',', $Element);
                        $ResourcesToUpd[metal] += floor($pricelist[$Element[0]][metal] * $Element[1]);
                        $ResourcesToUpd[crystal] += floor($pricelist[$Element[0]][crystal] * $Element[1]);
                        $ResourcesToUpd[deuterium] += floor($pricelist[$Element[0]][deuterium] * $Element[1]);
                        $ResourcesToUpd[tachyon] += floor($pricelist[$Element[0]][tachyon] * $Element[1]);
                    }
                }
                $SetRes = "UPDATE {{table}} SET ";
                $SetRes .= "`metal` = metal + '" . $ResourcesToUpd[metal] . "', ";
                $SetRes .= "`crystal` = crystal + '" . $ResourcesToUpd[crystal] . "', ";
                $SetRes .= "`deuterium` = deuterium + '" . $ResourcesToUpd[deuterium] . "', ";
                $SetRes .= "`tachyon` = tachyon + '" . $ResourcesToUpd[tachyon] . "', ";
                $SetRes .= "`b_hangar` = '', ";
                $SetRes .= "`b_hangar_id` = ''";
                $SetRes .= " WHERE `id` = '" . $CurrentPlanet['id'] . "'";
                doquery($SetRes, 'planets');
                header("location: " . $_SERVER['PHP_SELF'] . "?mode=" . $_GET[mode]);
                exit;
                break;
        }
    }
    if (isset($_POST['fmenge'])) {
        $AddedInQueue = false;
        foreach ($_POST['fmenge'] as $Element => $Count) {
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    if ($Count > $MaxElements) {
                        $Count = $MaxElements;
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['tachyon'] -= $Ressource['tachyon'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    if ($CurrentPlanet[$resource[21]] == 0) {
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    $TabIndex = 0;
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 201 && $Element <= 399) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                $PageTable .= "\n<tr>";
                $PageTable .= "<th class=k>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                $PageTable .= "<td class=k>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                $PageTable .= "<th class=k>";
                if ($CanBuildOne) {
                    $TabIndex++;
                    $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=7 maxlength=7 value=0 tabindex=" . $TabIndex . ">";
                }
                $PageTable .= "</th>";
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    $parse['buildlist'] = $PageTable;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_fleet'), $parse);
    display($page, $lang['Fleet']);
}
Example #8
0
function DefensesBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $phpEx, $dpath, $_POST, $reslist, $pricelist;
    if (isset($_POST['fmenge'])) {
        // On vient de Cliquer ' Construire '
        // Et y a une liste de doléances
        // Ici, on sait precisement ce qu'on aimerait bien construire ...
        // Gestion de la place disponible dans les silos !
        $Missiles[502] = $CurrentPlanet[$resource[502]];
        $Missiles[503] = $CurrentPlanet[$resource[503]];
        $SiloSize = $CurrentPlanet[$resource[44]];
        $MaxMissiles = $SiloSize * 10;
        // On prend les missiles deja dans la queue de fabrication aussi (ca aide)
        $BuildQueue = $CurrentPlanet['b_hangar_id'];
        $BuildArray = explode(";", $BuildQueue);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode(",", $BuildArray[$QElement]);
            if ($ElmentArray[502] != 0) {
                $Missiles[502] += $ElmentArray[502];
            } elseif ($ElmentArray[503] != 0) {
                $Missiles[503] += $ElmentArray[503];
            }
        }
        foreach ($_POST as $Element => $Count) {
            $Element = idstring($Element);
            if (in_array($Element, $reslist['fleet'])) {
                $Element = intval($Element);
                $Count = intval($Count);
                if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                    $Count = MAX_FLEET_OR_DEFS_PER_ROW;
                }
                if ($Count != 0) {
                    // Cas particulier (Petit Bouclier et Grand Bouclier
                    // ne peuvent exister qu'une seule et unique fois
                    $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                    $IsBuild = $CurrentPlanet[$resource[407]] >= 1 ? true : false;
                    if ($Element == 407 || $Element == 408) {
                        if ($InQueue === false && !$IsBuild) {
                            $Count = 1;
                        }
                    }
                    // On verifie si on a les technologies necessaires a la construction de l'element
                    if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                        // On verifie combien on sait faire de cet element au max
                        $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                        // Testons si on a de la place pour ces nouveaux missiles !
                        if ($Element == 502 || $Element == 503) {
                            // Cas particulier des missiles
                            $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                            $MissilesSpace = $MaxMissiles - $ActuMissiles;
                            if ($Element == 502) {
                                if ($Count > $MissilesSpace) {
                                    $Count = $MissilesSpace;
                                }
                            } else {
                                if ($Count > floor($MissilesSpace / 2)) {
                                    $Count = floor($MissilesSpace / 2);
                                }
                            }
                            if ($Count > $MaxElements) {
                                $Count = $MaxElements;
                            }
                            $Missiles[$Element] += $Count;
                        } else {
                            // Si pas assez de ressources, on ajuste le nombre d'elements
                            if ($Count > $MaxElements) {
                                $Count = $MaxElements;
                            }
                        }
                        $Ressource = GetElementRessources($Element, $Count);
                        $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                        if ($Count >= 1) {
                            $CurrentPlanet['metal'] -= $Ressource['metal'];
                            $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                            $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                            $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                        }
                    }
                }
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        $shipyard = false;
    } else {
        $shipyard = true;
    }
    // -------------------------------------------------------------------------------------------------------
    // Construction de la page du Chantier (car si j'arrive ici ... c'est que j'ai tout ce qu'il faut pour ...
    $TabIndex = 0;
    $PageTable = "";
    $SubTemplate = gettemplate('buildings/defense_buttonz');
    $parse = array();
    $infopg = array();
    foreach ($lang['tech'] as $Element => $ElementName) {
        if (in_array($Element, $reslist['defense'])) {
            if (!IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                $parse['state_' . $Element] = "off";
                $parse['mes_' . $Element] = "Requirements are not met";
            } elseif (!IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
                $parse['state_' . $Element] = "disabled";
                $parse['mes_' . $Element] = "Not enough resources!";
            } else {
                $parse['state_' . $Element] = "on";
                $parse['mes_' . $Element] = "";
            }
            $parse['name_' . $Element] = $ElementName;
            $parse['count_' . $Element] = $CurrentPlanet[$resource[$Element]];
        } else {
            $parse['state_' . $Element] = "off";
            $parse['mes_' . $Element] = "Not availble";
        }
    }
    $Buttonz = parsetemplate($SubTemplate, $parse);
    $parse = $lang;
    $Element = idstring($_GET['id']);
    $ElementName = $lang['tech'][$Element];
    if (!$Element) {
        $parse['bg'] = "../img/headerCache/station/" . $parse['type'] . ".png";
    } else {
        if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element) && IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
            $infopg['build_link'] = '#" onclick="document.forms.shipyard.submit()';
        }
        //Building Info
        if ($infopg['build_link']) {
            $infopg['buildit_class'] = "build-it";
            $infopg['build_text'] = "Build";
        } else {
            $infopg['buildit_class'] = "build-it_disabled";
            $infopg['build_text'] = "Build";
        }
        $infopg['id'] = $Element;
        $infopg['name'] = $ElementName;
        $infopg['level'] = $CurrentPlanet[$resource[$Element]];
        if ($CurrentPlanet[$resource[$Element]] < 1) {
            $infopg['display_destroy'] = "style=\"display:none;\"";
        }
        $infopg['td_url'] = "./?page=" . $_GET['page'] . "&cmd=destroy&id=" . $Element . "&building=" . $Element;
        $infopg['title'] = "Tear down";
        $infopg['level1'] = $infopg['level'] + 1;
        $infopg['duration'] = pretty_time(GetBuildingTime($CurrentUser, $CurrentPlanet, $Element));
        $infopg['shortdesc'] = $lang['res']['descriptions'][$Element];
        $infopg['skin'] = $CurrentUser['skin'];
        $infopg['cost_m'] = $pricelist[$Element]['metal'];
        $infopg['cost_c'] = $pricelist[$Element]['crystal'];
        $infopg['cost_d'] = $pricelist[$Element]['deuterium'];
        if ($infopg['cost_m'] > $CurrentPlanet['metal'] && $infopg['cost_m'] > 0) {
            $infopg['missing_resource_m'] = "missing_resource";
        }
        if ($infopg['cost_c'] > $CurrentPlanet['crystal'] && $infopg['cost_c'] > 0) {
            $infopg['missing_resource_c'] = "missing_resource";
        }
        if ($infopg['cost_d'] > $CurrentPlanet['deuterium'] && $infopg['cost_d'] > 0) {
            $infopg['missing_resource_d'] = "missing_resource";
        }
        $infopg['sh_cost_m'] = KMnumber($infopg['cost_m'], 0, 'up');
        $infopg['sh_cost_c'] = KMnumber($infopg['cost_c'], 0, 'up');
        $infopg['sh_cost_d'] = KMnumber($infopg['cost_d'], 0, 'up');
        $infopg['cost_m'] = pretty_number($infopg['cost_m']);
        $infopg['cost_c'] = pretty_number($infopg['cost_c']);
        $infopg['cost_d'] = pretty_number($infopg['cost_d']);
        $infopg['page'] = $_GET['page'];
        $parse['info'] = parsetemplate(gettemplate('buildings/sy_info'), $infopg);
        $parse['extra'] = "style=\"display:none\"";
    }
    $parse['buttonz'] = $Buttonz;
    $page = parsetemplate(gettemplate('buildings/shipyard'), $parse);
    displaypage($page, $lang['Defense']);
}
Example #9
0
function eco_build_hangar($que_type, $user, &$planet, $que)
{
    global $sn_data, $lang, $dpath, $debug, $time_now;
    $GET_action = sys_get_param_str('action');
    $GET_mode = sys_get_param_str('mode');
    $POST_fmenge = $_POST['fmenge'];
    if (isset($GET_action)) {
        switch ($GET_action) {
            case 'trim':
                $ElementQueue = explode(';', $planet['b_hangar_id']);
                while (!empty($ElementQueue) && $ElementLine == '') {
                    $ElementIndex = count($ElementQueue) - 1;
                    $ElementLine = $ElementQueue[$ElementIndex];
                    unset($ElementQueue[$ElementIndex]);
                }
                if ($ElementLine) {
                    $Element = explode(',', $ElementLine);
                    $ResourcesToUpd[metal] += floor($sn_data[$Element[0]]['metal'] * $Element[1]);
                    $ResourcesToUpd[crystal] += floor($sn_data[$Element[0]]['crystal'] * $Element[1]);
                    $ResourcesToUpd[deuterium] += floor($sn_data[$Element[0]]['deuterium'] * $Element[1]);
                    doquery("UPDATE `{{planets}}` SET\r\n              `metal` = metal + '{$ResourcesToUpd['metal']}', `crystal` = crystal + '{$ResourcesToUpd['crystal']}', `deuterium` = deuterium + '{$ResourcesToUpd['deuterium']}'," . (empty($ElementQueue) ? '`b_hangar` = 0,' : '') . "`b_hangar_id` = '" . implode(';', $ElementQueue) . "' WHERE `id` = '{$planet['id']}' LIMIT 1;");
                }
                // PREVENT SUBMITS?
                header("location: {$_SERVER['PHP_SELF']}?mode={$GET_mode}");
                exit;
                break;
            case 'clear':
                $ElementQueue = explode(';', $planet['b_hangar_id']);
                foreach ($ElementQueue as $ElementLine => $Element) {
                    if ($Element != '') {
                        $Element = explode(',', $Element);
                        $ResourcesToUpd[metal] += floor($sn_data[$Element[0]]['metal'] * $Element[1]);
                        $ResourcesToUpd[crystal] += floor($sn_data[$Element[0]]['crystal'] * $Element[1]);
                        $ResourcesToUpd[deuterium] += floor($sn_data[$Element[0]]['deuterium'] * $Element[1]);
                    }
                }
                doquery("UPDATE `{{planets}}` SET\r\n            `metal` = metal + '{$ResourcesToUpd['metal']}', `crystal` = crystal + '{$ResourcesToUpd['crystal']}', `deuterium` = deuterium + '{$ResourcesToUpd['deuterium']}',\r\n            `b_hangar` = '', `b_hangar_id` = '' WHERE `id` = '{$planet['id']}' LIMIT 1;");
                // PREVENT SUBMITS?
                header("location: {$_SERVER['PHP_SELF']}?mode={$GET_mode}");
                exit;
                break;
        }
    }
    $page_error = '';
    $page_mode = $que_type == SUBQUE_FLEET ? 'fleet' : 'defense';
    $sn_data_group = $sn_data['groups'][$page_mode];
    if (isset($POST_fmenge) && !eco_hangar_is_building($que)) {
        doquery('START TRANSACTION;');
        $planet = doquery("SELECT * FROM {{planets}} WHERE `id` = '{$planet['id']}' LIMIT 1 FOR UPDATE;", '', true);
        $units_cost = array();
        $hangar = $planet['b_hangar_id'];
        $built = GetRestrictedConstructionNum($planet);
        $SiloSpace = max(0, $planet[$sn_data[44]['name']] * 10 - $built[502] - $built[503] * 2);
        foreach ($POST_fmenge as $Element => $Count) {
            $Element = intval($Element);
            $Count = min(max(0, intval($Count)), MAX_FLEET_OR_DEFS_PER_ROW);
            if (!($Count && $Element && in_array($Element, $sn_data_group) && eco_can_build_unit($user, $planet, $Element))) {
                continue;
            }
            // On verifie combien on sait faire de cet element au max
            $MaxElements = GetMaxConstructibleElements($Element, $planet);
            switch ($Element) {
                case 502:
                    $Count = min($SiloSpace, $Count, $MaxElements);
                    $SiloSpace -= $Count;
                    break;
                case 503:
                    $Count = min(floor($SiloSpace / 2), $Count, $MaxElements);
                    $SiloSpace -= $Count * 2;
                    break;
                case 407:
                case 408:
                case 409:
                    $Count = $built[$Element] >= 1 ? 0 : 1;
                    break;
                default:
                    $Count = min($Count, $MaxElements);
                    break;
            }
            $unit_resources = GetElementRessources($Element, $Count);
            foreach ($unit_resources as $res_name => $res_amount) {
                $units_cost[$res_name] += $res_amount;
            }
            $hangar .= "{$Element},{$Count};";
        }
        if ($hangar != $planet['b_hangar_id']) {
            $new_planet_data = $planet;
            $can_build_def = true;
            $query_string = '';
            foreach ($units_cost as $res_name => $res_amount) {
                if ($res_amount <= 0) {
                    continue;
                }
                if ($planet[$res_name] < $res_amount) {
                    $can_build_def = false;
                    $page_error = $lang['eco_bld_resources_not_enough'];
                    break;
                }
                $new_planet_data[$res_name] -= $res_amount;
                $query_string .= "`{$res_name}` = `{$res_name}` - {$res_amount},";
            }
            if ($can_build_def && $query_string) {
                $planet = $new_planet_data;
                $planet['b_hangar_id'] = $hangar;
                $query_string .= "`b_hangar_id` = '{$hangar}'";
                doquery("UPDATE {{planets}} SET {$query_string} WHERE `id` = '{$planet['id']}' LIMIT 1;");
            }
        }
        doquery('COMMIT');
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($planet[$sn_data[21]['name']] == 0) {
        // Veuillez avoir l'obligeance de construire le Chantier Spacial !!
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    $built = GetRestrictedConstructionNum($planet);
    $SiloSpace = max(0, $planet[$sn_data[44]['name']] * 10 - $built[502] - $built[503] * 2);
    $template = gettemplate("buildings_hangar", true);
    // -------------------------------------------------------------------------------------------------------
    // Construction de la page du Chantier (car si j'arrive ici ... c'est que j'ai tout ce qu'il faut pour ...
    $TabIndex = 0;
    foreach ($sn_data_group as $Element) {
        $unit_message = '';
        if (eco_can_build_unit($user, $planet, $Element)) {
            // On regarde si on peut en acheter au moins 1
            $CanBuildOne = IsElementBuyable($user, $planet, $Element, false);
            // Disponibilité actuelle
            $ElementCount = $planet[$sn_data[$Element]['name']];
            // On affiche le temps de construction (c'est toujours tellement plus joli)
            $baubar = GetMaxConstructibleElements($Element, $planet);
            switch ($Element) {
                case 502:
                    $baubar = min($SiloSpace, $baubar);
                    $restrict = 1;
                    break;
                case 503:
                    $baubar = min(floor($SiloSpace / 2), $baubar);
                    $restrict = 1;
                    break;
                case 407:
                case 408:
                case 409:
                    $baubar = $built[$Element] >= 1 ? 0 : min(1, $baubar);
                    $restrict = 2;
                    break;
                default:
                    $restrict = 0;
                    break;
            }
            // Case nombre d'elements a construire
            if ($CanBuildOne) {
                if (!eco_hangar_is_building($que)) {
                    if ($restrict == 2 and $baubar == 0) {
                        $unit_message .= $lang['only_one'];
                    } elseif ($restrict == 1 and !$baubar) {
                        $unit_message .= $lang['b_no_silo_space'];
                    } else {
                        $TabIndex++;
                    }
                } else {
                    $unit_message = $lang['fleet_on_update'];
                }
            }
            $build_data = eco_get_build_data($user, $planet, $Element, 0);
            $temp[RES_METAL] = floor($planet['metal'] - $build_data[BUILD_CREATE][RES_METAL]);
            // + $fleet_list['own']['total'][RES_METAL]
            $temp[RES_CRYSTAL] = floor($planet['crystal'] - $build_data[BUILD_CREATE][RES_CRYSTAL]);
            // + $fleet_list['own']['total'][RES_CRYSTAL]
            $temp[RES_DEUTERIUM] = floor($planet['deuterium'] - $build_data[BUILD_CREATE][RES_DEUTERIUM]);
            // + $fleet_list['own']['total'][RES_DEUTERIUM]
            $template->assign_block_vars('production', array('ID' => $Element, 'NAME' => $lang['tech'][$Element], 'DESCRIPTION' => $lang['info'][$Element]['description_short'], 'LEVEL' => $ElementCount, 'LEVEL_OLD' => $CurentPlanet[$sn_data[$Element]['name']], 'LEVEL_CHANGE' => $que['in_que'][$Element], 'BUILD_CAN' => min($baubar, $build_data['CAN'][BUILD_CREATE]), 'TIME' => pretty_time($build_data[BUILD_CREATE][RES_TIME]), 'METAL' => $build_data[BUILD_CREATE][RES_METAL], 'CRYSTAL' => $build_data[BUILD_CREATE][RES_CRYSTAL], 'DEUTERIUM' => $build_data[BUILD_CREATE][RES_DEUTERIUM], 'METAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_METAL], true, $planet['metal']), 'CRYSTAL_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_CRYSTAL], true, $planet['crystal']), 'DEUTERIUM_PRINT' => pretty_number($build_data[BUILD_CREATE][RES_DEUTERIUM], true, $planet['deuterium']), 'DESTROY_CAN' => $build_data['CAN'][BUILD_DESTROY], 'DESTROY_TIME' => pretty_time($build_data[BUILD_DESTROY][RES_TIME]), 'DESTROY_METAL' => $build_data[BUILD_DESTROY][RES_METAL], 'DESTROY_CRYSTAL' => $build_data[BUILD_DESTROY][RES_CRYSTAL], 'DESTROY_DEUTERIUM' => $build_data[BUILD_DESTROY][RES_DEUTERIUM], 'METAL_REST' => pretty_number($temp[RES_METAL], true, true), 'CRYSTAL_REST' => pretty_number($temp[RES_CRYSTAL], true, true), 'DEUTERIUM_REST' => pretty_number($temp[RES_DEUTERIUM], true, true), 'METAL_REST_NUM' => $temp[RES_METAL], 'CRYSTAL_REST_NUM' => $temp[RES_CRYSTAL], 'DEUTERIUM_REST_NUM' => $temp[RES_DEUTERIUM], 'METAL_BALANCE' => $caps['metal_perhour'][$Element], 'CRYSTAL_BALANCE' => $caps['crystal_perhour'][$Element], 'DEUTERIUM_BALANCE' => $caps['deuterium_perhour'][$Element], 'ENERGY_BALANCE' => $energy_balance, 'ARMOR' => pretty_number($sn_data[$Element]['armor']), 'SHIELD' => pretty_number($sn_data[$Element]['shield']), 'WEAPON' => pretty_number($sn_data[$Element]['attack']), 'TABINDEX' => $TabIndex, 'MESSAGE' => $unit_message));
        }
    }
    $template->assign_vars(array('noresearch' => $NoFleetMessage, 'error_msg' => $page_error, 'MODE' => $que_type, 'QUE_ID' => $que_type, 'TIME_NOW' => $time_now));
    tpl_assign_hangar($que_type, $planet, $template);
    display(parsetemplate($template), $lang[$page_mode]);
}
Example #10
0
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $phpEx, $dpath, $_POST, $reslist, $pricelist;
    echo "[";
    print_r($_POST);
    echo "]";
    if (isset($_POST['fmenge'])) {
        // On vient de Cliquer ' Construire '
        // Et y a une liste de dol�ances
        $AddedInQueue = false;
        // Ici, on sait precisement ce qu'on aimerait bien construire ...
        foreach ($_POST as $Element => $Count) {
            $Element = idstring($Element);
            if (in_array($Element, $reslist['fleet'])) {
                $Element = intval($Element);
                $Count = intval($Count);
                if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                    $Count = MAX_FLEET_OR_DEFS_PER_ROW;
                }
                if ($Count > 0) {
                    // On verifie si on a les technologies necessaires a la construction de l'element
                    if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                        // On verifie combien on sait faire de cet element au max
                        $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                        // Si pas assez de ressources, on ajuste le nombre d'elements
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Ressource = GetElementRessources($Element, $Count);
                        $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                        if ($Count >= 1) {
                            $CurrentPlanet['metal'] -= $Ressource['metal'];
                            $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                            $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                            $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                        }
                    }
                }
            }
        }
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        $shipyard = false;
    } else {
        $shipyard = true;
    }
    // -------------------------------------------------------------------------------------------------------
    // Now for the building part.
    $TabIndex = 0;
    $SubTemplate = gettemplate('buildings/shipyard_buttonz');
    $parse = array();
    $infopg = array();
    foreach ($lang['tech'] as $Element => $ElementName) {
        if (in_array($Element, $reslist['fleet'])) {
            if (!IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                $parse['state_' . $Element] = "off";
                $parse['mes_' . $Element] = "Requirements are not met";
            } elseif (!IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
                $parse['state_' . $Element] = "disabled";
                $parse['mes_' . $Element] = "Not enough resources!";
            } else {
                $parse['state_' . $Element] = "on";
                $parse['mes_' . $Element] = "";
            }
            $parse['name_' . $Element] = $ElementName;
            $parse['count_' . $Element] = KMnumber($CurrentPlanet[$resource[$Element]]);
        } else {
            $parse['state_' . $Element] = "off";
            $parse['mes_' . $Element] = "Not availble";
        }
    }
    $Buttonz = parsetemplate($SubTemplate, $parse);
    $parse = $lang;
    $Element = idstring($_GET['id']);
    $ElementName = $lang['tech'][$Element];
    if (!$Element) {
        $parse['bg'] = "../img/headerCache/station/" . $parse['type'] . ".png";
    } else {
        if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element) && IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
            $infopg['build_link'] = '#" onclick="Javascript: document.getElementById(\'shipyard\').submit()';
        }
        die("!!!!!!!!!!!!!");
        //Building Info
        if ($infopg['build_link']) {
            $infopg['buildit_class'] = "build-it";
            $infopg['build_text'] = "Build";
        } else {
            $infopg['buildit_class'] = "build-it_disabled";
            $infopg['build_text'] = "Build";
        }
        $infopg['id'] = $Element;
        $infopg['name'] = $ElementName;
        $infopg['level'] = $CurrentPlanet[$resource[$Element]];
        if ($CurrentPlanet[$resource[$Element]] < 1) {
            $infopg['display_destroy'] = "style=\"display:none;\"";
        }
        $infopg['td_url'] = "./?page=" . $_GET['page'] . "&cmd=destroy&id=" . $Element . "&building=" . $Element;
        $infopg['title'] = "Tear down";
        $infopg['level1'] = $infopg['level'] + 1;
        $infopg['duration'] = pretty_time(GetBuildingTime($CurrentUser, $CurrentPlanet, $Element));
        $infopg['shortdesc'] = $lang['res']['descriptions'][$Element];
        $infopg['skin'] = $CurrentUser['skin'];
        $infopg['cost_m'] = $pricelist[$Element]['metal'];
        $infopg['cost_c'] = $pricelist[$Element]['crystal'];
        $infopg['cost_d'] = $pricelist[$Element]['deuterium'];
        if ($infopg['cost_m'] > $CurrentPlanet['metal'] && $infopg['cost_m'] > 0) {
            $infopg['missing_resource_m'] = "missing_resource";
        }
        if ($infopg['cost_c'] > $CurrentPlanet['crystal'] && $infopg['cost_c'] > 0) {
            $infopg['missing_resource_c'] = "missing_resource";
        }
        if ($infopg['cost_d'] > $CurrentPlanet['deuterium'] && $infopg['cost_d'] > 0) {
            $infopg['missing_resource_d'] = "missing_resource";
        }
        $infopg['sh_cost_m'] = KMnumber($infopg['cost_m'], 0, 'up');
        $infopg['sh_cost_c'] = KMnumber($infopg['cost_c'], 0, 'up');
        $infopg['sh_cost_d'] = KMnumber($infopg['cost_d'], 0, 'up');
        $infopg['cost_m'] = pretty_number($infopg['cost_m']);
        $infopg['cost_c'] = pretty_number($infopg['cost_c']);
        $infopg['cost_d'] = pretty_number($infopg['cost_d']);
        $infopg['page'] = $_GET['page'];
        $parse['info'] = parsetemplate(gettemplate('buildings/sy_info'), $infopg);
        $parse['extra'] = "style=\"display:none\"";
    }
    $parse['buttonz'] = $Buttonz;
    $page = parsetemplate(gettemplate('buildings/shipyard'), $parse);
    displaypage($page, $lang['Fleet']);
}
Example #11
0
function DefensesBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $phpEx, $dpath, $_POST;
    if (isset($_POST['fmenge'])) {
        $Missiles[502] = $CurrentPlanet[$resource[502]];
        $Missiles[503] = $CurrentPlanet[$resource[503]];
        $SiloSize = $CurrentPlanet[$resource[44]];
        $MaxMissiles = $SiloSize * 10;
        $BuildQueueList = $CurrentPlanet['b_hangar_id'];
        $BuildArray = explode(";", $BuildQueueList);
        for ($QElement = 0; $QElement < count($BuildArray); $QElement++) {
            $ElmentArray = explode(",", $BuildArray[$QElement]);
            if ($ElmentArray[0] == 502 && $ElmentArray[1] >= 0) {
                $Missiles[502] += $ElmentArray[1];
            } elseif ($ElmentArray[0] == 503 && $ElmentArray[1] >= 0) {
                $Missiles[503] += $ElmentArray[1];
            }
        }
        foreach ($_POST['fmenge'] as $Element => $Count) {
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                $IsBuildp = $CurrentPlanet[$resource[407]] >= 1 ? TRUE : FALSE;
                $IsBuildg = $CurrentPlanet[$resource[408]] >= 1 ? TRUE : FALSE;
                if ($Element == 407 && !$IsBuildp && $InQueue === FALSE) {
                    $Count = 1;
                }
                if ($Element == 408 && !$IsBuildg && $InQueue === FALSE) {
                    $Count = 1;
                }
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    if ($Element == 502 || $Element == 503) {
                        $ActuMissiles = $Missiles[502] + 2 * $Missiles[503];
                        $MissilesSpace = $MaxMissiles - $ActuMissiles;
                        if ($Element == 502) {
                            if ($Count > $MissilesSpace) {
                                $Count = $MissilesSpace;
                            }
                        } else {
                            if ($Count > floor($MissilesSpace / 2)) {
                                $Count = floor($MissilesSpace / 2);
                            }
                        }
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                        $Missiles[$Element] += $Count;
                    } else {
                        if ($Count > $MaxElements) {
                            $Count = $MaxElements;
                        }
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    if ($CurrentPlanet[$resource[21]] == 0) {
        message($lang['need_hangar'], $lang['tech'][21]);
    }
    $TabIndex = 0;
    $PageTable = "";
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 400 && $Element <= 599) {
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . ")";
                $PageTable .= "\n<tr>";
                $PageTable .= "<th class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">";
                $PageTable .= "<img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top width=120 height=120></a>";
                $PageTable .= "</th>";
                $PageTable .= "<td class=l>";
                $PageTable .= "<a href=infos." . $phpEx . "?gid=" . $Element . ">" . $ElementName . "</a> " . $ElementNbre . "<br>";
                $PageTable .= "" . $lang['res']['descriptions'][$Element] . "<br>";
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>";
                $PageTable .= "<th class=k>";
                if ($CanBuildOne) {
                    $InQueue = strpos($CurrentPlanet['b_hangar_id'], $Element . ",");
                    $IsBuild = $CurrentPlanet[$resource[407]] >= 1 ? true : false;
                    $BuildIt = true;
                    if ($Element == 407 || $Element == 408) {
                        $BuildIt = false;
                        if ($InQueue === false && !$IsBuild) {
                            $BuildIt = true;
                        }
                    }
                    if (!$BuildIt) {
                        $PageTable .= "<font color=\"red\">" . $lang['only_one'] . "</font>";
                    } else {
                        $TabIndex++;
                        $PageTable .= "<input type=text name=fmenge[" . $Element . "] alt='" . $lang['tech'][$Element] . "' size=5 maxlength=5 value=0 tabindex=" . $TabIndex . ">";
                        $PageTable .= "</th>";
                    }
                } else {
                    $PageTable .= "</th>";
                }
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    $parse['buildlist'] = $PageTable;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_defense'), $parse);
    display($page, $lang['Defense']);
}
Example #12
0
function FleetBuildingPage(&$CurrentPlanet, $CurrentUser)
{
    global $lang, $resource, $dpath, $_POST;
    if (isset($_POST['fmenge'])) {
        //fmenge muss zum Bauen gefüllt sein
        $AddedInQueue = false;
        foreach ($_POST['fmenge'] as $Element => $Count) {
            $Element = intval($Element);
            $Count = intval($Count);
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            if ($Count != 0) {
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    //prüfen, ob die nötigen Techs vohanden sind
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    //maximal baubare Schiffe herausfinden
                    if ($Count > $MaxElements) {
                        //wenn nicht genügend ress vorhanden sind
                        $Count = $MaxElements;
                        //wird die Anzahl der Schiffe entsprechend angepasst
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
    }
    if ($CurrentPlanet[$resource[21]] == 0) {
        // Wenn es keine Raumschiffwerft auf dem Plani gibt...
        message($lang['need_hangar'], $lang['tech'][21]);
        //Dann gib nen Fehler aus
    }
    $TabIndex = 0;
    foreach ($lang['tech'] as $Element => $ElementName) {
        if ($Element > 201 && $Element <= 399) {
            //ID des Elements muss zwischen diesen beiden Werten liegen
            if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                //Wenn verfügbar
                $CanBuildOne = IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, false);
                $BuildOneElementTimeWithoutTechs = GetBuildingTimeWithoutTechs($CurrentUser, $CurrentPlanet, $Element);
                //ursprüngliche Bauzeit ermitteln
                $BuildOneElementTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                //benötigte Bauzeit ermitteln
                //aktuell verfügbar
                $baubar = GetMaxConstructibleShips($CurrentPlanet, $Element);
                $ElementCount = $CurrentPlanet[$resource[$Element]];
                $ElementNbre = $ElementCount == 0 ? "({$lang['builtable']}{$baubar})" : " (" . $lang['dispo'] . ": " . pretty_number($ElementCount) . " {$lang['builtable']} {$baubar})";
                $PageTable .= "\n<tr>\n";
                $PageTable .= "\r\n\t<th class=\"l\" rowspan=\"2\" width=\"120\">\r\n\t\t<a href=\"?action=internalInformations&amp;gid=" . $Element . "\"><img border=0 src=\"" . $dpath . "gebaeude/" . $Element . ".gif\" align=top alt=" . $Element . ".gif width=120 height=120></a>\r\n\t</th>\r\n    <td class=\"c\">\r\n    \t<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n    \t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td width=\"15\"><img src=\"images/transparent.gif\" alt=\"transparent\" width=\"0\" height=\"21\"></td>\r\n\t\t\t\t\t<td><a href=\"?action=internalInformations&amp;gid=" . $Element . "\">" . $ElementName . "</a> " . $ElementNbre . "</td>\r\n\t\t\t\t\t<td width=\"100\">&nbsp;</td>\r\n    \t\t\t</tr>\r\n    \t\t</tbody>\r\n\t\t</table>\r\n    </td>\r\n</tr>\r\n<tr>\r\n    <td colspan=\"1\">\r\n    \t<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n    \t\t<tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td class=\"rechtsohneborder\" width=\"10\"><img src=\"images/transparent.gif\" alt=\"transparent\" width=\"0\" height=\"100\"></td>\r\n\t\t\t\t\t<td class=\"linksundrechtsohneborder\" width=\"80%\">" . $lang['res']['descriptions'][$Element] . "<br>&nbsp;<br>";
                $PageTable .= GetElementPrice($CurrentUser, $CurrentPlanet, $Element, false);
                $PageTable .= "\r\n\t\t\t\t\t<br><br>\r\n\t\t\t\t\t\r\n\t\t\t\t\t<a href=\"javascript:void(0);\" onmouseover=\"return overlib('";
                //$PageTable .= ShowTechs ($user, $planetrow, $Element);
                $PageTable .= "', BGCOLOR, 'red', FGCOLOR, '#000000', TEXTCOLOR, 'white', WIDTH, '120');\" onmouseout=\"return nd();\">" . $lang['TechnicalData'] . "</a>\r\n\t\t\t\t\t\r\n\t\t\t\t\t\r\n        \t\t\t<td class=\"linksohneborder\" width=\"100\">\r\n        \t\t\t<p align=\"center\"><br>&nbsp;<br><a href=\"javascript:setL(" . $Element . ");\"><img src=\"images/back.gif\" width=\"17\" style=\"vertical-align:bottom\" border=\"0\" height=\"15\" alt=\"back\"></a><input name=\"fmenge[" . $Element . "]\" size=\"5\" maxlength=\"5\" style=\"text-align: center;\" value=\"0\" onClick=\"if(this.value=='0') this.value='';\" onBlur=\"if(this.value=='') this.value='0';\" type=\"text\" tabindex=\"" . $TabIndex . "\"><a href=\"javascript:setN(" . $Element . ");\"><img src=\"images/forward.gif\" width=\"17\" style=\"vertical-align:bottom\" border=\"0\" height=\"15\" alt=\"forward\"></a><br>&nbsp;<br><a href=\"javascript:setMax(" . $Element . "," . $baubar . ")\">max</a>\r\n                \t</p>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t</tbody>\r\n\t\t</table>\r\n    </td>\r\n</tr>\r\n<tr>\r\n    <td colspan=\"2\">\r\n    \r\n        <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n        <tbody><tr>\r\n       \r\n            <td class=\"b\">\r\n                <table width=\"100%\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">\r\n                <tbody>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td>\r\n\t\t\t\t\t\t<a class=\"b\">" . $lang['NeededRess'] . "</a><br><br>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t\t<td colspan=\"2\">\r\n\t\t\t\t\t\t<a class=\"b\">" . $lang['BuildingTime'] . "</a><br>\r\n\t\t\t\t\t\t<br>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\r\n\t\t\t\t<tr>\t\t\r\n\t\t\t\t\t<td width=\"68%\" rowspan=\"3\">";
                $PageTable .= GetRestPrice($CurrentUser, $CurrentPlanet, $Element);
                $PageTable .= "</td>\r\n                    <td width=\"20%\">" . $lang['ConstructionTimeWithoutTechs'] . "</td>\r\n                    <td width=\"12%\" align=\"right\">";
                $PageTable .= ShowBuildTimeWithoutTechs($BuildOneElementTimeWithoutTechs);
                $PageTable .= "</td>\r\n                </tr>\r\n                <tr>\r\n                    <td>\r\n                        " . $lang['TechBonus'] . ":\r\n                    </td>\r\n                                \r\n                    <td align=\"right\">";
                $PageTable .= ShowTechBonus($BuildOneElementTimeWithoutTechs - $BuildOneElementTime);
                $PageTable .= "</td>\r\n                </tr>\r\n\t\t\t\t\r\n\t\t\t\t<tr>\r\n                    <td>&nbsp;</td>          \r\n                    <td align=\"right\">&nbsp;</td>\r\n                </tr>\r\n\t\t\t\t\r\n                 <tr>\r\n                    <td colspan=\"2\" height=\"5\"></td>          \r\n                </tr>\r\n                <tr>\r\n\t\t\t\t\t<td>&nbsp;</td>\r\n                    <td>" . $lang['ConstructionTime'] . "</td>\r\n                    <td align=\"right\">";
                $PageTable .= ShowBuildTime($BuildOneElementTime);
                $PageTable .= "</td>\r\n                </tr>\r\n                </tbody></table>\r\n            </td>\r\n        </tr>\r\n        </tbody></table><br>";
                $PageTable .= "</tr>";
            }
        }
    }
    if ($CurrentPlanet['b_hangar_id'] != '') {
        $BuildQueue .= ElementBuildListBox($CurrentUser, $CurrentPlanet);
    }
    $parse = $lang;
    //die HTML Seite lieht nun in $PageTable
    $parse['buildlist'] = $PageTable;
    // Und die Liste der noch laufenden Elemente liegt in $BuildQueue;
    $parse['buildinglist'] = $BuildQueue;
    $page .= parsetemplate(gettemplate('buildings_fleet'), $parse);
    display($page, $lang['Fleet']);
}
Example #13
0
/**
 * ShipyardBuildingPage.php
 *
 * @version 1.0
 * @copyright 2009 By MadnessRed for XNova Redesigned
 */
function ShipyardPage(&$CurrentPlanet, $CurrentUser, $area)
{
    global $lang, $resource, $phpEx, $dpath, $_GET, $reslist, $pricelist;
    if ($_GET['fmenge'] > 0) {
        // On vient de Cliquer ' Construire '
        // Et y a une liste de dol�ances
        $AddedInQueue = false;
        // What an how much are they making?
        $Element = intval(idstring($_GET['fmenge']));
        $Count = intval(idstring($_GET[$Element]));
        if (in_array($Element, $reslist[$area])) {
            //Check if it exaceeds the max amount we allow them to build in one go (XNova code)
            if ($Count > MAX_FLEET_OR_DEFS_PER_ROW) {
                $Count = MAX_FLEET_OR_DEFS_PER_ROW;
            }
            $InQueue = 0;
            $QueueSize = 0;
            foreach (explode(";", $CurrentPlanet['b_hangar_id']) as $temp) {
                if (strlen($temp) > 0) {
                    $q = explode(",", $temp);
                    $QueueSize += $q[1];
                    if ($q[0] = $Element) {
                        $InQueue += $q[1];
                    }
                }
            }
            //If there is a maximum allowed
            if ($pricelist[$Element]['max'] > 0) {
                if ($Count + $InQueue + $CurrentPlanet[$resource[$Element]] > $pricelist[$Element]['max']) {
                    $Count = $pricelist[$Element]['max'] - $CurrentPlanet[$resource[$Element]] - $InQueue;
                }
            }
            //And missiles...
            if ($Element == 502 || $Element == 503) {
            }
            if ($Count > 0) {
                // On verifie si on a les technologies necessaires a la construction de l'element
                if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    // On verifie combien on sait faire de cet element au max
                    $MaxElements = GetMaxConstructibleElements($Element, $CurrentPlanet);
                    // Si pas assez de ressources, on ajuste le nombre d'elements
                    if ($Count > $MaxElements) {
                        $Count = $MaxElements;
                    }
                    $Ressource = GetElementRessources($Element, $Count);
                    $BuildTime = GetBuildingTime($CurrentUser, $CurrentPlanet, $Element);
                    if ($Count >= 1) {
                        //echo "". $Element .",". $Count .";";
                        $CurrentPlanet['metal'] -= $Ressource['metal'];
                        $CurrentPlanet['crystal'] -= $Ressource['crystal'];
                        $CurrentPlanet['deuterium'] -= $Ressource['deuterium'];
                        $CurrentPlanet['b_hangar_id'] .= "" . $Element . "," . $Count . ";";
                    }
                }
            }
        }
        if ($QueueSize == 0) {
            $CurrentPlanet['b_hangar_lastupdate'] = time();
            $CurrentPlanet['b_hangar'] = 0;
        }
        //now do those changes...
        doquery("UPDATE {{table}} SET `metal` = '" . $CurrentPlanet['metal'] . "', `crystal` = '" . $CurrentPlanet['crystal'] . "', `deuterium` = '" . $CurrentPlanet['deuterium'] . "', `b_hangar_id` = '" . $CurrentPlanet['b_hangar_id'] . "', `b_hangar` = '" . $CurrentPlanet['b_hangar'] . "', `b_hangar_lastupdate` = '" . $CurrentPlanet['b_hangar_lastupdate'] . "' WHERE `id` = '" . $CurrentPlanet['id'] . "' ;", 'planets');
    }
    // -------------------------------------------------------------------------------------------------------
    // S'il n'y a pas de Chantier ...
    if ($CurrentPlanet[$resource[21]] == 0) {
        $shipyard = false;
    } else {
        $shipyard = true;
    }
    // -------------------------------------------------------------------------------------------------------
    // Now for the building part.
    $TabIndex = 0;
    if ($area == 'fleet') {
        $SubTemplate = gettemplate('buildings/shipyard_buttonz');
        $Template = gettemplate('buildings/shipyard');
        $Title = $lang['Shipyard'];
    } elseif ($area == 'defense') {
        $SubTemplate = gettemplate('buildings/defense_buttonz');
        $Template = gettemplate('buildings/defense');
        $Title = $lang['Defense'];
    }
    $parse = array();
    $infopg = array();
    if (!in_array($Element, $reslist[$area]) || $_GET['axah_section'] != '1') {
        foreach ($lang['tech'] as $Element => $ElementName) {
            if (in_array($Element, $reslist[$area])) {
                if (!IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element)) {
                    $parse['state_' . $Element] = "off";
                    $parse['mes_' . $Element] = "Requirements are not met";
                } elseif (!IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
                    $parse['state_' . $Element] = "disabled";
                    $parse['mes_' . $Element] = "Not enough resources!";
                } else {
                    $parse['state_' . $Element] = "on";
                    $parse['mes_' . $Element] = "";
                }
                $parse['name_' . $Element] = $ElementName;
                $parse['count_' . $Element] = $CurrentPlanet[$resource[$Element]];
            } else {
                $parse['state_' . $Element] = "off";
                $parse['mes_' . $Element] = "Not availble";
            }
        }
        $Buttonz = parsetemplate($SubTemplate, $parse);
    }
    $parse = $lang;
    $Element = idstring($_GET['id']);
    $ElementName = $lang['tech'][$Element];
    if (in_array($Element, $reslist[$area])) {
        if (IsTechnologieAccessible($CurrentUser, $CurrentPlanet, $Element) && IsElementBuyable($CurrentUser, $CurrentPlanet, $Element, true, false)) {
            $infopg['build_link'] = './?page=' . $_GET['page'] . '&id=' . $Element . '&fmenge=' . $Element . '&' . $Element . '=';
            //$infopg['build_link'] = '#" onclick="document.forms.shipyard.submit()';
        }
        //Building Info
        if ($infopg['build_link']) {
            $infopg['buildit_class'] = "build-it";
            $infopg['build_text'] = "Build";
        } else {
            $infopg['buildit_class'] = "build-it_disabled";
            $infopg['build_text'] = "Build";
        }
        $infopg['id'] = $Element;
        $infopg['name'] = $ElementName;
        $infopg['level'] = $CurrentPlanet[$resource[$Element]];
        $infopg['duration'] = pretty_time(GetBuildingTime($CurrentUser, $CurrentPlanet, $Element));
        $infopg['shortdesc'] = $lang['res']['descriptions'][$Element];
        $infopg['skin'] = $CurrentUser['skin'];
        $infopg['cost_m'] = $pricelist[$Element]['metal'];
        $infopg['cost_c'] = $pricelist[$Element]['crystal'];
        $infopg['cost_d'] = $pricelist[$Element]['deuterium'];
        if ($infopg['cost_m'] > $CurrentPlanet['metal'] && $infopg['cost_m'] > 0) {
            $infopg['missing_resource_m'] = "missing_resource";
        }
        if ($infopg['cost_c'] > $CurrentPlanet['crystal'] && $infopg['cost_c'] > 0) {
            $infopg['missing_resource_c'] = "missing_resource";
        }
        if ($infopg['cost_d'] > $CurrentPlanet['deuterium'] && $infopg['cost_d'] > 0) {
            $infopg['missing_resource_d'] = "missing_resource";
        }
        $infopg['sh_cost_m'] = KMnumber($infopg['cost_m'], 0, 'up');
        $infopg['sh_cost_c'] = KMnumber($infopg['cost_c'], 0, 'up');
        $infopg['sh_cost_d'] = KMnumber($infopg['cost_d'], 0, 'up');
        $infopg['cost_m'] = pretty_number($infopg['cost_m']);
        $infopg['cost_c'] = pretty_number($infopg['cost_c']);
        $infopg['cost_d'] = pretty_number($infopg['cost_d']);
        $infopg['page'] = $_GET['page'];
        $parse['info'] = parsetemplate(gettemplate('buildings/sy_info'), $infopg);
        $parse['extra'] = "style=\"display:none\"";
        if ($_GET['axah_section'] == '1') {
            makeAXAH($parse['info']);
            die;
        }
    }
    $parse['buttonz'] = $Buttonz;
    $parse['planetname'] = $CurrentPlanet['name'];
    $page = parsetemplate($Template, $parse);
    if ($_GET['axah']) {
        makeAXAH($page);
    } else {
        displaypage($page, $Title);
    }
}