function showAdminInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    $continentInfo = getContinentInfo($getPage_connection2, $nationInfo["home"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Control Panel        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseControlPanel\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseControlPanel\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    echo "                  <form action=\"index.php?page=admin\" method=\"post\">\n";
    echo "                    <input type=\"hidden\" name=\"page\" value=\"admin\" />\n";
    echo "                    <div class=\"form-group form-group-sm\">\n";
    echo "                      <button onclick=\"loadButton(this)\" value=\"custom_script\" name=\"action\" id=\"custom_script\" type=\"submit\" class=\"btn btn-md btn-primary\">Run Custom Script</button>\n";
    echo "                    </div>\n";
    echo "                    <div class=\"form-group form-group-sm\">\n";
    echo "                      <label class=\"control-label\" for=\"reset_world\">WARNING: ALL WORLD DATA WILL BE LOST!  ADMINISTRATOR PASSWORD WILL BE RESET TO DEFAULT!</label>\n";
    echo "                      <button onclick=\"loadButton(this)\" value=\"reset_world\" name=\"action\" id=\"reset_world\" type=\"submit\" class=\"btn btn-md btn-danger\">Reset World to Defaults</button>\n";
    echo "                    </div>\n";
    echo "                  </form>\n";
    echo "                </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "        </div>\n";
}
function showDeactivateInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    $productionInfo = getProductionInfo($getPage_connection2, $_SESSION["nation_id"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change user account deactivate.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Deactivate Account Confirmation        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseChange\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseChange\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    echo "                Are you sure you want to deactivate your account?\n";
    echo "                <form action=\"index.php?page=deactivate\" method=\"post\">\n";
    echo "                  <input type=\"hidden\" name=\"page\" value=\"deactivate\" />\n";
    echo "                  <br />\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <label class=\"control-label\" for=\"currentPassword\">Current Password:</label>\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Current password of user account.  This is required to make any changes to your account.\" name=\"current_password\" type=\"password\" class=\"form-control input-md\" id=\"currentPassword\" placeholder=\"password\" />\n";
    echo "                  </div>\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <a href=\"index.php?page=settings\" onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Get me out of here and back to the game!\" value=\"no\" name=\"action\" id=\"no\" type=\"submit\" class=\"btn btn-md btn-success\">No!  Get me out of here!</a>\n";
    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Deactivate your account.  This will disable access to your account!\" value=\"yes\" name=\"action\" id=\"yes\" type=\"submit\" class=\"btn btn-md btn-danger\">Yes!  I want to deactivate!</button>\n";
    echo "                  </div>\n";
    echo "                </form>\n";
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "        </div>\n";
}
function showForumInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"well info_well\">\n";
    echo "            Click on the below link to enter the forum.\n";
    echo "            <br />\n";
    //echo "            Please note that the forum is an external entity and abides by all policies set forth by the forum host.\n";
    //echo "            <br />\n";
    echo "            Follow the rules.\n";
    echo "            <br />\n";
    echo "            <br />\n";
    echo "            <h2><a href=\"http://worldsthegame.com/phpBB3\" target=\"_blank\">ENTER</a></h2>\n";
    echo "          </div>\n";
    echo "        </div>\n";
}
function showHelpInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Table of Contents        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseHelpTC\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseHelpTC\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    if ($stmt = $getPage_connection2->prepare("SELECT id,title,text FROM helpcategories ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_id, $r_title, $r_text);
        while ($stmt->fetch()) {
            $helpCategoriesInfo1 = array("id" => $r_id, "title" => $r_title, "text" => $r_text);
            echo "                <a class=\"cat\" href=\"#collapseHelp" . $helpCategoriesInfo1["id"] . "\">" . $helpCategoriesInfo1["id"] . " - " . $helpCategoriesInfo1["title"] . "</a>\n";
            echo "                <br />\n";
            $subcategoryCounter = 0;
            if ($stmt2 = $getPage_connection2->prepare("SELECT id,category,title,text FROM helpsubcategories ORDER BY id ASC")) {
                $stmt2->execute();
                $stmt2->store_result();
                $stmt2->bind_result($r_id1, $r_category1, $r_title1, $r_text1);
                while ($stmt2->fetch()) {
                    $helpSubcategoriesInfo1 = array("id" => $r_id1, "category" => $r_category1, "title" => $r_title1, "text" => $r_text1);
                    if ($helpSubcategoriesInfo1["category"] == $helpCategoriesInfo1["id"]) {
                        $subcategoryCounter++;
                        echo "                <a class=\"subcat\" href=\"#" . $helpCategoriesInfo1["id"] . "-" . $subcategoryCounter . "\">" . $helpCategoriesInfo1["id"] . "." . $subcategoryCounter . " - " . $helpSubcategoriesInfo1["title"] . "</a>\n";
                        echo "                <br />\n";
                    }
                    // if
                }
                // while
                $stmt2->close();
            } else {
            }
            // else
            echo "                <br />\n";
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    if ($stmt = $getPage_connection2->prepare("SELECT id,title,text FROM helpcategories ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_id, $r_title, $r_text);
        while ($stmt->fetch()) {
            $helpCategoriesInfo1 = array("id" => $r_id, "title" => $r_title, "text" => $r_text);
            echo "          <div class=\"panel panel-info\">\n";
            echo "            <div class=\"panel-heading\">\n";
            echo "              <h3 class=\"panel-title\">" . $helpCategoriesInfo1["title"] . "        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseHelp1\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
            echo "            </div>\n";
            echo "            <div id=\"collapseHelp" . $helpCategoriesInfo1["id"] . "\" class=\"panel-body collapse in\">\n";
            echo "              <div class=\"col-md-8 col-center\">\n";
            echo "                <br />\n";
            echo "                <p class=\"paragraph\">\n";
            echo "                  " . $helpCategoriesInfo1["text"] . " \n";
            echo "                </p>\n";
            $subcategoryCounter = 0;
            if ($stmt2 = $getPage_connection2->prepare("SELECT id,category,title,text FROM helpsubcategories ORDER BY id ASC")) {
                $stmt2->execute();
                $stmt2->store_result();
                $stmt2->bind_result($r_id1, $r_category1, $r_title1, $r_text1);
                while ($stmt2->fetch()) {
                    $helpSubcategoriesInfo1 = array("id" => $r_id1, "category" => $r_category1, "title" => $r_title1, "text" => $r_text1);
                    if ($helpSubcategoriesInfo1["category"] == $helpCategoriesInfo1["id"]) {
                        $subcategoryCounter++;
                        echo "                <a class=\"chapter-title\" id=\"" . $helpCategoriesInfo1["id"] . "-" . $subcategoryCounter . "\" href=\"#\">" . $helpSubcategoriesInfo1["title"] . "</a>\n";
                        echo "                <br />\n";
                        echo "                <p class=\"paragraph\">\n";
                        echo "                  " . $helpSubcategoriesInfo1["text"] . " \n";
                        echo "                </p>\n";
                    }
                    // if
                }
                // while
                $stmt2->close();
            } else {
            }
            // else
            echo "              </div>\n";
            echo "            </div>\n";
            echo "          </div>\n";
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    echo "        </div>\n";
}
function declineOrganization($getPage_connection2)
{
    if (strlen($_SESSION["action"]) >= 1) {
        if ($_SESSION["action"] == "decline") {
            if ($_SESSION["nation_id"] >= 1) {
                $nationInfoSelect = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
                if ($_SESSION["org"] >= 1) {
                    $organizationInfoSelect = getOrganizationInfo($getPage_connection2, $_SESSION["org"]);
                    $new_invites = array(0 => 0);
                    $counter = 0;
                    $nationInfoM = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
                    for ($z = 0; $z < count($nationInfoM["invites"]); $z++) {
                        if ($_SESSION["org"] != $nationInfoM["invites"][$z]) {
                            $new_invites[$counter] = $nationInfoM["invites"][$z];
                            $counter++;
                        }
                        // if
                    }
                    // for
                    setNationInfo($getPage_connection2, $nationInfoSelect["id"], $nationInfoSelect["name"], $nationInfoSelect["home"], $nationInfoSelect["formal"], $nationInfoSelect["flag"], $nationInfoSelect["production"], $nationInfoSelect["money"], $nationInfoSelect["debt"], $nationInfoSelect["happiness"], $nationInfoSelect["food"], $nationInfoSelect["authority"], $nationInfoSelect["authorityChanged"], $nationInfoSelect["economy"], $nationInfoSelect["economyChanged"], $nationInfoSelect["organizations"], $new_invites, $nationInfoSelect["goods"], $nationInfoSelect["resources"], $nationInfoSelect["population"], $nationInfoSelect["strike"]);
                    $new_pending = array(0 => 0);
                    $counter = 0;
                    $organizationInfoM = getOrganizationInfo($getPage_connection2, $_SESSION["org"]);
                    for ($z = 0; $z < count($organizationInfoM["pending"]); $z++) {
                        if ($_SESSION["nation_id"] != $organizationInfoM["pending"][$z]) {
                            $new_pending[$counter] = $organizationInfoM["pending"][$z];
                            $counter++;
                        }
                        // if
                    }
                    // for
                    setOrganizationInfo($getPage_connection2, $_SESSION["org"], $organizationInfoSelect["name"], $organizationInfoSelect["members"], $organizationInfoSelect["managers"], $new_pending, $organizationInfoSelect["ranking"]);
                    $_SESSION["success_message"] = "Nation has declined organization successfully!";
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: organization is not valid.";
                }
                // else
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: nation is not valid.";
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
    }
    // else
}
function uploadFile($getPage_connection2)
{
    $returnArray = array("path" => "", "error" => "");
    $target_dir = "images/nations/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
    // Check if image file is a actual image or fake image
    if (isset($_POST["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if ($check !== false) {
            //echo "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            //echo "File is not an image.";
            $uploadOk = 0;
            $returnArray["error"] = "File is not a valid image type." . $_FILES["fileToUpload"]["name"];
        }
        // else
    }
    // if
    // Check if file already exists
    if (file_exists($target_file)) {
        //echo "Sorry, file already exists.";
        $uploadOk = 0;
        $returnArray["error"] = "File already exists, try renaming your file.";
    }
    // if
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 1500000) {
        //echo "Sorry, your file is too large.";
        $uploadOk = 0;
        $returnArray["error"] = "File is too large (must be under 1.5 MB).";
    }
    // if
    // Allow certain file formats
    if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
        //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
        $returnArray["error"] = "File must be only JPG, JPEG, PNG or GIF.";
    }
    // if
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        //echo "Sorry, your file was not uploaded.";
        $returnArray["path"] = "";
        // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
            // remove old file
            $nationInfo1 = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
            if (strlen($nationInfo1["flag"]) >= 1) {
                unlink($nationInfo1["flag"]);
            }
            // if
            $returnArray["path"] = $target_file;
        } else {
            //echo "Sorry, there was an error uploading your file.";
            $returnArray["path"] = "";
            $returnArray["error"] = "An error occured while uploading.";
        }
        // else
    }
    // else
    return $returnArray;
}
function processSearch($getPage_connection2, $searchTerms)
{
    $validSearch = false;
    $foundSomething = false;
    $output = "Results for ";
    for ($a = 0; $a < count($searchTerms); $a++) {
        $output .= " \"{$searchTerms[$a]}\" \n";
    }
    // for
    $output .= "<br /><br />\n";
    $stringSearchTerms = implode(" ", $searchTerms);
    if (strlen($stringSearchTerms) > 5 && strlen($stringSearchTerms) < 75) {
        $validSearch = true;
    } else {
        $validSearch = false;
    }
    // else
    if ($validSearch === true) {
        $stringSearchTerms = strtolower($stringSearchTerms);
        $stringSearchTerms1 = "%" . $stringSearchTerms . "%";
        // nation search
        // go through 4 possibilities
        for ($qa = 0; $qa < 4; $qa++) {
            $offset = $qa;
            $nationSearchInfo1 = array("id" => 0, "name" => "");
            // first, search for exact match
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations WHERE LOWER(name) LIKE ? OR LOWER(formal) LIKE ? LIMIT 1 OFFSET ?")) {
                $stmt->bind_param("ssi", $stringSearchTerms, $stringSearchTerms, $offset);
                $stmt->execute();
                $stmt->bind_result($r_id);
                $stmt->fetch();
                $nationSearchInfo1["id"] = $r_id;
                $stmt->close();
            } else {
            }
            // else
            // if exact match found,
            if ($nationSearchInfo1["id"] > 0) {
                $foundSomething = true;
                $resultsInfo1 = getNationInfo($getPage_connection2, $nationSearchInfo1["id"]);
                $output .= "Nation: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $resultsInfo1["id"] . "\">" . $resultsInfo1["name"] . "</a> <br />\n";
                break;
                // otherwise look for rough match,
            } else {
                // second, search for inclusive match
                if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations WHERE LOWER(name) LIKE ? OR LOWER(formal) LIKE ? LIMIT 1 OFFSET ?")) {
                    $stmt->bind_param("ssi", $stringSearchTerms1, $stringSearchTerms1, $offset);
                    $stmt->execute();
                    $stmt->bind_result($r_id);
                    $stmt->fetch();
                    $nationSearchInfo1["id"] = $r_id;
                    $stmt->close();
                } else {
                }
                // else
                // if match found,
                if ($nationSearchInfo1["id"] > 0) {
                    $foundSomething = true;
                    $resultsInfo1 = getNationInfo($getPage_connection2, $nationSearchInfo1["id"]);
                    $output .= "Nation: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $resultsInfo1["id"] . "\">" . $resultsInfo1["name"] . "</a> <br />\n";
                } else {
                }
                // else
            }
            // else
        }
        // for
        // organizations search
        // go through 4 possibilities
        for ($qb = 0; $qb < 4; $qb++) {
            $offset = $qb;
            $orgSearchInfo1 = array("id" => 0, "name" => "");
            // first, search for exact match
            if ($stmt = $getPage_connection2->prepare("SELECT id FROM organizations WHERE LOWER(name) LIKE ? LIMIT 1 OFFSET ?")) {
                $stmt->bind_param("si", $stringSearchTerms, $offset);
                $stmt->execute();
                $stmt->bind_result($r_id);
                $stmt->fetch();
                $orgSearchInfo1["id"] = $r_id;
                $stmt->close();
            } else {
            }
            // else
            // if exact match found,
            if ($orgSearchInfo1["id"] > 0) {
                $foundSomething = true;
                $resultsInfo2 = getOrganizationInfo($getPage_connection2, $orgSearchInfo1["id"]);
                $output .= "Organization: <a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $resultsInfo2["id"] . "\">" . $resultsInfo2["name"] . "</a> <br />\n";
                break;
                // otherwise look for rough match,
            } else {
                // second, search for inclusive match
                if ($stmt = $getPage_connection2->prepare("SELECT id FROM organizations WHERE LOWER(name) LIKE ? LIMIT 1 OFFSET ?")) {
                    $stmt->bind_param("si", $stringSearchTerms1, $offset);
                    $stmt->execute();
                    $stmt->bind_result($r_id);
                    $stmt->fetch();
                    $orgSearchInfo1["id"] = $r_id;
                    $stmt->close();
                } else {
                }
                // else
                // if match found,
                if ($orgSearchInfo1["id"] > 0) {
                    $foundSomething = true;
                    $resultsInfo2 = getOrganizationInfo($getPage_connection2, $orgSearchInfo1["id"]);
                    $output .= "Organization: <a href=\"index.php?page=info&amp;section=orgs&amp;info_id=" . $resultsInfo2["id"] . "\">" . $resultsInfo2["name"] . "</a> <br />\n";
                } else {
                }
                // else
            }
            // else
        }
        // for
        if ($foundSomething === false) {
            $output .= "No results found.";
        }
        // if
    } else {
        $output .= "Search length requirements are not met!  Search must be 5-75 characters long.\n";
    }
    // else
    return $output;
}
Example #8
0
function showPageTitle($getPage_connection2, $pageTitle, $showNation)
{
    if ($showNation === true) {
        $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
        echo "        <div class=\"page-header spacing-from-menu\">\n";
        echo "          <h1>" . $pageTitle . " - " . $nationInfo["name"] . "</h1>\n";
        echo "        </div>\n\n";
    } else {
        echo "        <div class=\"page-header spacing-from-menu\">\n";
        echo "          <h1>" . $pageTitle . "</h1>\n";
        echo "        </div>\n\n";
    }
}
Example #9
0
function combat($getPage_connection2, $continent, $xpos, $ypos, $attacker, $defender, $amphibian)
{
    if ($continent >= 1 && $xpos >= 1 && $ypos >= 1 && $attacker["id"] >= 1 && $defender["id"] >= 1 && $amphibian >= 0) {
        $tileInfoB = getTileInfo($getPage_connection2, $continent, $xpos, $ypos);
        $terrainInfoB = getTerrainInfo($getPage_connection2, $tileInfoB["terrain"]);
        $unitTypeInfoAttacker = getUnitTypeInfo($getPage_connection2, $attacker["type"]);
        $unitTypeInfoDefender = getUnitTypeInfo($getPage_connection2, $defender["type"]);
        $attackerA = 0.0;
        $attackerD = 0.0;
        $defenderA = 0.0;
        $defenderD = 0.0;
        $attackerReconLevel = array(0 => 0);
        $defenderReconLevel = array(0 => 0);
        $attackerReconExp = array(0 => 0);
        $defenderReconExp = array(0 => 0);
        $attackerReconBonus = 0;
        $defenderReconBonus = 0;
        $attackerArtilleryLevel = array(0 => 0);
        $defenderArtilleryLevel = array(0 => 0);
        $attackerArtilleryPower = array(0 => 0);
        $defenderArtilleryPower = array(0 => 0);
        $attackerArtilleryBonus = 0;
        $defenderArtilleryBonus = 0;
        // Experience Bonus from Recon
        $counter = 0;
        // goes through -2 to +2 x and y positions looking for attacker recon to aid attacker
        for ($x = -2; $x < 3; $x++) {
            for ($y = -2; $y < 3; $y++) {
                $unitInfoZ = getUnitInfo($getPage_connection2, $attacker["continent"], $attacker["xpos"] + $x, $attacker["ypos"] + $y);
                if ($unitInfoZ["id"] >= 1) {
                    if ($unitInfoZ["type"] == 5) {
                        $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]);
                        $attackerReconLevel[$counter] = $unitInfoZ["level"];
                        $attackerReconExp[$counter] = 2;
                        $counter++;
                    }
                    // if
                }
                // if
            }
            // for
        }
        // for
        $counter = 0;
        // goes through -2 to +2 x and y positions looking for defender recon to aid defender
        for ($x = -2; $x < 3; $x++) {
            for ($y = -2; $y < 3; $y++) {
                $unitInfoZ = getUnitInfo($getPage_connection2, $defender["continent"], $defender["xpos"] + $x, $defender["ypos"] + $y);
                if ($unitInfoZ["id"] >= 1) {
                    if ($unitInfoZ["type"] == 5) {
                        $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]);
                        $defenderReconLevel[$counter] = $unitInfoZ["level"];
                        $defenderReconExp[$counter] = 2;
                        $counter++;
                    }
                    // if
                }
                // if
            }
            // for
        }
        // for
        if ($attackerReconLevel[0] >= 1) {
            // add recon bonus
            for ($e = 0; $e < count($attackerReconLevel); $e++) {
                $attackerReconBonus += $attackerReconLevel[$e] * 0.25 + $attackerReconExp[$e];
            }
            // for
        }
        // if
        if ($defenderReconLevel[0] >= 1) {
            for ($e = 0; $e < count($defenderReconLevel); $e++) {
                $defenderReconBonus += $defenderReconLevel[$e] * 0.25 + $defenderReconExp[$e];
            }
            // for
        }
        // if
        $attackerExp = $attacker["exp"] + $attackerReconBonus;
        $defenderExp = $defender["exp"] + $defenderReconBonus;
        // Power Bonus from Artillery
        $counter = 0;
        // goes through -2 to +2 x and y positions looking for attacker artillery to aid attacker
        for ($x = -2; $x < 3; $x++) {
            for ($y = -2; $y < 3; $y++) {
                $unitInfoZ = getUnitInfo($getPage_connection2, $attacker["continent"], $attacker["xpos"] + $x, $attacker["ypos"] + $y);
                if ($unitInfoZ["id"] >= 1) {
                    if ($unitInfoZ["type"] == 4) {
                        $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]);
                        $attackerArtilleryLevel[$counter] = $unitInfoZ["level"];
                        //$attackerArtilleryPower[$counter] = $unitTypeInfoZ["attack"];
                        $attackerArtilleryPower[$counter] = 2;
                        $counter++;
                    }
                    // if
                }
                // if
            }
            // for
        }
        // for
        $counter = 0;
        // goes through -2 to +2 x and y positions looking for defender artillery to aid defender
        for ($x = -2; $x < 3; $x++) {
            for ($y = -2; $y < 3; $y++) {
                $unitInfoZ = getUnitInfo($getPage_connection2, $defender["continent"], $defender["xpos"] + $x, $defender["ypos"] + $y);
                if ($unitInfoZ["id"] >= 1) {
                    if ($unitInfoZ["type"] == 4) {
                        $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]);
                        $defenderArtilleryLevel[$counter] = $unitInfoZ["level"];
                        //$defenderArtilleryPower[$counter] = $unitTypeInfoZ["attack"];
                        $defenderArtilleryPower[$counter] = 2;
                        $counter++;
                    }
                    // if
                }
                // if
            }
            // for
        }
        // for
        if ($attackerArtilleryLevel[0] >= 1) {
            // add artillery bonus
            for ($e = 0; $e < count($attackerArtilleryLevel); $e++) {
                $attackerArtilleryBonus += $attackerArtilleryLevel[$e] * 0.25 + $attackerArtilleryPower[$e];
            }
            // for
        }
        // if
        if ($defenderArtilleryLevel[0] >= 1) {
            for ($e = 0; $e < count($defenderArtilleryLevel); $e++) {
                $defenderArtilleryBonus += $defenderArtilleryLevel[$e] * 0.25 + $defenderArtilleryPower[$e];
            }
            // for
        }
        // if
        $attackerA += $attackerArtilleryBonus;
        $attackerD += $attackerArtilleryBonus;
        $defenderA += $defenderArtilleryBonus;
        $defenderD += $defenderArtilleryBonus;
        $attackerA += $unitTypeInfoAttacker["attack"] + ($attacker["level"] * 0.25 + $attackerExp * 0.05);
        $attackerD += $unitTypeInfoAttacker["defense"] + ($attacker["level"] * 0.25 + $attackerExp * 0.05);
        $defenderA += $unitTypeInfoDefender["attack"] + ($defender["level"] * 0.25 + $defenderExp * 0.05);
        $defenderD += $unitTypeInfoDefender["defense"] + ($defender["level"] * 0.25 + $defenderExp * 0.05);
        $magnitude = 0;
        $formula = 0;
        // 1=winning,2=tie,3=losing
        $defenderModifier = 0.01 * $terrainInfoB["attackModifier"] * $defenderD;
        // add terrain modifier for defense bonus
        if ($amphibian == 1) {
            $defenderModifier = 0.25 * $defenderD;
            // add another +25% for amphibian assaults
        }
        // if
        // figure out which formula to use
        if ($attackerA > $defenderD + $defenderModifier) {
            // figure out category of combat
            if ($attackerA - ($defenderD + $defenderModifier) >= 4) {
                $magnitude = 5;
            } else {
                if ($attackerA - ($defenderD + $defenderModifier) >= 3) {
                    $magnitude = 4;
                } else {
                    if ($attackerA - ($defenderD + $defenderModifier) >= 2) {
                        $magnitude = 3;
                    } else {
                        if ($attackerA - ($defenderD + $defenderModifier) >= 1) {
                            $magnitude = 2;
                        } else {
                            $magnitude = 1;
                        }
                    }
                }
            }
            // else
            $formula = 1;
        } else {
            if ($attackerA == $defenderD + $defenderModifier) {
                $formula = 2;
            } else {
                // figure out category of combat
                if ($defenderD + $defenderModifier - $attackerA >= 4) {
                    $magnitude = 5;
                } else {
                    if ($defenderD + $defenderModifier - $attackerA >= 3) {
                        $magnitude = 4;
                    } else {
                        if ($defenderD + $defenderModifier - $attackerA >= 2) {
                            $magnitude = 3;
                        } else {
                            if ($defenderD + $defenderModifier - $attackerA >= 1) {
                                $magnitude = 2;
                            } else {
                                $magnitude = 1;
                            }
                        }
                    }
                }
                // else
                $formula = 3;
            }
        }
        // else
        $rand_attackerDamage = mt_rand(1, 100);
        $health_percent_attacker = 0;
        $health_percent_defender = 0;
        $new_defender_health = $defender["health"];
        $new_attacker_health = $attacker["health"];
        if ($formula == 1) {
            if ($magnitude == 5) {
                // 10% chance of receiving damage
                if ($rand_attackerDamage <= 10) {
                    // attacker is damaged
                    // health - 0-20% of health
                    $health_percent_attacker = $attacker["health"] * (1 - mt_rand(8, 10) * 0.1);
                    $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                }
                // if
                // defender is damaged
                // health - 80-100% of health
                $health_percent_defender = $defender["health"] * (1 - mt_rand(0, 2) * 0.1);
                $new_defender_health = $attacker["health"] - $health_percent_defender;
            } else {
                if ($magnitude == 4) {
                    // 15% chance of receiving damage
                    if ($rand_attackerDamage <= 15) {
                        // attacker is damaged
                        // health - 20-40% of health
                        $health_percent_attacker = $attacker["health"] * (1 - mt_rand(6, 8) * 0.1);
                        $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                    }
                    // if
                    // defender is damaged
                    // health - 60-80% of health
                    $health_percent_defender = $defender["health"] * (1 - mt_rand(2, 4) * 0.1);
                    $new_defender_health = $attacker["health"] - $health_percent_defender;
                } else {
                    if ($magnitude == 3) {
                        // 20% chance of receiving damage
                        if ($rand_attackerDamage <= 20) {
                            // attacker is damaged
                            // health - 40-60% of health
                            $health_percent_attacker = $attacker["health"] * (1 - mt_rand(4, 6) * 0.1);
                            $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                        }
                        // if
                        // defender is damaged
                        // health - 40-60% of health
                        $health_percent_defender = $defender["health"] * (1 - mt_rand(4, 6) * 0.1);
                        $new_defender_health = $attacker["health"] - $health_percent_defender;
                    } else {
                        if ($magnitude == 2) {
                            // 25% chance of receiving damage
                            if ($rand_attackerDamage <= 25) {
                                // attacker is damaged
                                // health - 60-80% of health
                                $health_percent_attacker = $attacker["health"] * (1 - mt_rand(2, 4) * 0.1);
                                $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                            }
                            // if
                            // defender is damaged
                            // health - 20-40% of health
                            $health_percent_defender = $defender["health"] * (1 - mt_rand(6, 8) * 0.1);
                            $new_defender_health = $attacker["health"] - $health_percent_defender;
                        } else {
                            if ($magnitude == 1) {
                                // 30% chance of receiving damage
                                if ($rand_attackerDamage <= 30) {
                                    // attacker is damaged
                                    // health - 80-100% of health
                                    $health_percent_attacker = $attacker["health"] * (1 - mt_rand(0, 2) * 0.1);
                                    $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                                }
                                // if
                                // defender is damaged
                                // health - 0-20% of health
                                $health_percent_defender = $defender["health"] * (1 - mt_rand(8, 10) * 0.1);
                                $new_defender_health = $attacker["health"] - $health_percent_defender;
                            }
                        }
                    }
                }
            }
            // else if
            // set health
            setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]);
            setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]);
        } else {
            if ($formula == 2) {
                // 50% chance of receiving or dealing damage
                if ($rand_attackerDamage <= 50) {
                    // attacker is damaged
                    // health - 10-100% of health
                    $health_percent_attacker = $attacker["health"] * (1 - mt_rand(1, 10) * 0.1);
                    $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                } else {
                    // defender is damaged
                    // health - 10-100% of health
                    $health_percent_defender = $defender["health"] * (1 - mt_rand(1, 10) * 0.1);
                    $new_defender_health = $attacker["health"] - $health_percent_defender;
                }
                // else
                // set health
                setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]);
                setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]);
            } else {
                if ($formula == 3) {
                    $rand_defenderDamage = mt_rand(1, 100);
                    if ($magnitude == 5) {
                        // 10% chance of receiving damage
                        if ($rand_defenderDamage <= 10) {
                            // defender is damaged
                            // health - 0-20% of health
                            $health_percent_defender = $defender["health"] * (1 - mt_rand(8, 10) * 0.1);
                            $new_defender_health = $attacker["health"] - $health_percent_defender;
                        }
                        // if
                        // attacker is damaged
                        // health - 80-100% of health
                        $health_percent_attacker = $attacker["health"] * (1 - mt_rand(0, 2) * 0.1);
                        $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                    } else {
                        if ($magnitude == 4) {
                            // 15% chance of receiving damage
                            if ($rand_defenderDamage <= 15) {
                                // defender is damaged
                                // health - 20-40% of health
                                $health_percent_defender = $defender["health"] * (1 - mt_rand(6, 8) * 0.1);
                                $new_defender_health = $attacker["health"] - $health_percent_defender;
                            }
                            // if
                            // attacker is damaged
                            // health - 60-80% of health
                            $health_percent_attacker = $attacker["health"] * (1 - mt_rand(2, 4) * 0.1);
                            $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                        } else {
                            if ($magnitude == 3) {
                                // 20% chance of receiving damage
                                if ($rand_defenderDamage <= 20) {
                                    // defender is damaged
                                    // health - 40-60% of health
                                    $health_percent_defender = $defender["health"] * (1 - mt_rand(4, 6) * 0.1);
                                    $new_defender_health = $attacker["health"] - $health_percent_defender;
                                }
                                // if
                                // attacker is damaged
                                // health - 40-60% of health
                                $health_percent_attacker = $attacker["health"] * (1 - mt_rand(4, 6) * 0.1);
                                $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                            } else {
                                if ($magnitude == 2) {
                                    // 25% chance of receiving damage
                                    if ($rand_defenderDamage <= 25) {
                                        // defender is damaged
                                        // health - 60-80% of health
                                        $health_percent_defender = $defender["health"] * (1 - mt_rand(2, 4) * 0.1);
                                        $new_defender_health = $attacker["health"] - $health_percent_defender;
                                    }
                                    // if
                                    // attacker is damaged
                                    // health - 20-40% of health
                                    $health_percent_attacker = $attacker["health"] * (1 - mt_rand(6, 8) * 0.1);
                                    $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                                } else {
                                    if ($magnitude == 1) {
                                        // 30% chance of receiving damage
                                        if ($rand_defenderDamage <= 30) {
                                            // defender is damaged
                                            // health - 80-100% of health
                                            $health_percent_defender = $defender["health"] * (1 - mt_rand(0, 2) * 0.1);
                                            $new_defender_health = $attacker["health"] - $health_percent_defender;
                                        }
                                        // if
                                        // attacker is damaged
                                        // health - 0-20% of health
                                        $health_percent_attacker = $attacker["health"] * (1 - mt_rand(8, 10) * 0.1);
                                        $new_attacker_health = $attacker["health"] - $health_percent_attacker;
                                    }
                                }
                            }
                        }
                    }
                    // else if
                    // set health
                    setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]);
                    setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]);
                } else {
                }
            }
        }
        // else
        $newDefender = getUnitInfoByID($getPage_connection2, $defender["id"]);
        $newAttacker = getUnitInfoByID($getPage_connection2, $attacker["id"]);
        $defeat = "";
        $attackerWins = false;
        $new_used = $newAttacker["used"] + 1;
        // if either party is killed, remove them from map
        if ($newDefender["health"] <= 0 || $newAttacker["health"] <= 0) {
            // defender dies
            if ($newDefender["health"] <= 0) {
                $defeat = "Unit " . $newDefender["name"] . " has been killed in combat!";
                $attackerWins = true;
                if ($newDefender["transport"] >= 1) {
                    $transportInfo = getTransportInfo($getPage_connection2, $newDefender["transport"]);
                    for ($a = 0; $a < count($transportInfo); $a++) {
                        deleteUnitInfo($getPage_connection2, $transportInfo["list"][$a]);
                    }
                    // for
                }
                // if
                deleteUnitInfo($getPage_connection2, $newDefender["id"]);
                // add experience
                $new_exp = 1 + $newAttacker["exp"];
                setUnitInfo($getPage_connection2, $newAttacker["id"], $newAttacker["continent"], $newAttacker["xpos"], $newAttacker["ypos"], $new_attacker_health, $newAttacker["used"], $newAttacker["name"], $newAttacker["type"], $newAttacker["owner"], $newAttacker["level"], $newAttacker["transport"], $newAttacker["created"], $new_exp);
                // if amphibian combat
                if ($amphibian == 1) {
                    $unitInfoTransport = getUnitInfo($getPage_connection2, $_SESSION["action_id"]);
                    $transportInfoTransport = getTransportInfo($getPage_connection2, $unitInfoTransport["transport"]);
                    // set new transport list
                    $new_transport_list = array(0 => 0);
                    $counterB = 0;
                    for ($b = 0; $b < count($transportInfoTransport); $b++) {
                        if ($b != 1) {
                            $new_transport_list[$counterB] = $transportInfoTransport["list"][$b];
                            $counterB++;
                        }
                        // if
                    }
                    // for
                    setTransportInfo($getPage_connection2, $unitInfoTransport["transport"], $new_transport_list);
                }
                // if
                setUnitInfo($getPage_connection2, $_SESSION["action_id"], $_SESSION["new_continent"], $_SESSION["new_xpos"], $_SESSION["new_ypos"], $newAttacker["health"], $new_used, $newAttacker["name"], $newAttacker["type"], $newAttacker["owner"], $newAttacker["level"], $newAttacker["transport"], $newAttacker["created"], $newAttacker["exp"]);
            }
            // if
            // attacker dies
            if ($newAttacker["health"] <= 0) {
                $defeat = "Unit " . $newAttacker["name"] . " has been killed in combat!";
                $attackerWins = false;
                if ($newAttacker["transport"] >= 1) {
                    $transportInfo = getTransportInfo($getPage_connection2, $newAttacker["transport"]);
                    for ($a = 0; $a < count($transportInfo); $a++) {
                        deleteUnitInfo($getPage_connection2, $transportInfo["list"][$a]);
                    }
                    // for
                }
                // if
                deleteUnitInfo($getPage_connection2, $newAttacker["id"]);
                // add experience
                $new_exp = 1 + $newDefender["exp"];
                setUnitInfo($getPage_connection2, $newDefender["id"], $newDefender["continent"], $newDefender["xpos"], $newDefender["ypos"], $new_attacker_health, $newDefender["used"], $newDefender["name"], $newDefender["type"], $newDefender["owner"], $newDefender["level"], $newDefender["transport"], $newDefender["created"], $new_exp);
            }
            // if
            // otherwise bounce!
        }
        // if
        $attackerNationInfo = getNationInfo($getPage_connection2, $newAttacker["owner"]);
        $defenderNationInfo = getNationInfo($getPage_connection2, $newDefender["owner"]);
        $br1 = "<br />";
        $enteredInto = "Unit " . $newAttacker["name"] . " of " . $attackerNationInfo["name"] . " has entered into combat with unit " . $newDefender["name"] . " of " . $defenderNationInfo["name"] . " !";
        $suffering = "Unit " . $newAttacker["name"] . " has suffered " . $health_percent_attacker . " damage.  Unit " . $newDefender["name"] . " has suffered " . $health_percent_defender . " damage!";
        $_SESSION["success_message"] = $enteredInto . $br1 . $suffering . $br1 . $defeat;
        $log_message = $enteredInto . "  " . $suffering . "  " . $defeat;
        $new_date = date("Y-m-d H:i:s");
        addCombatLogInfo($getPage_connection2, $new_date, $log_message, $attackerNationInfo["id"], $defenderNationInfo["id"]);
    }
    // if
}
function showInfoInfo($getPage_connection2)
{
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    if ($_SESSION["section"] == "nations") {
        $nationInfo = getNationInfo($getPage_connection2, $_SESSION["info_id"]);
        $continentInfo = getContinentInfo($getPage_connection2, $nationInfo["home"]);
        $authorityReport = getAuthorityReport($nationInfo["authority"]);
        $economyReport = getEconomyReport($nationInfo["economy"]);
        $rankingInfo = getRankingInfo($getPage_connection2, $_SESSION["info_id"]);
        echo "          <div class=\"panel panel-info\">\n";
        echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View basic govermental policies.\" class=\"panel-heading\">\n";
        echo "              <h3 class=\"panel-title\">Government        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseGovernment\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
        echo "            </div>\n";
        echo "            <div id=\"collapseGovernment\" class=\"panel-body collapse in\">\n";
        echo "              <div class=\"col-md-8 col-center\">\n";
        echo "                <h3>" . $nationInfo["formal"] . "</h3>\n";
        echo "                <br />\n";
        if (strlen($nationInfo["flag"]) >= 1) {
            echo "                <img class=\"info_flag\" src=\"" . $nationInfo["flag"] . "\" alt=\"Flag of " . $nationInfo["name"] . "\" />\n";
        } else {
            echo "                <img class=\"info_flag\" src=\"images/blank.png\" alt=\"Flag of " . $nationInfo["name"] . "\" />\n";
        }
        // else
        echo "                <br />\n";
        echo "                <br />\n";
        echo "                <br />\n";
        echo "                Home Continent: " . $continentInfo["name"] . " (" . $nationInfo["home"] . ") \n";
        echo "                <br />\n";
        echo "                Authority: " . $nationInfo["authority"] . "/10\n";
        echo "                <br />\n";
        echo "                " . $authorityReport . "\n";
        echo "                <br />\n";
        echo "                Economy: " . $nationInfo["economy"] . "/10\n";
        echo "                <br />\n";
        echo "                " . $economyReport . "\n";
        echo "              </div>\n";
        echo "            </div>\n";
        echo "          </div>\n";
        echo "          <div class=\"panel panel-info\">\n";
        echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View general information about nation.\" class=\"panel-heading\">\n";
        echo "              <h3 class=\"panel-title\">General        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseGeneral\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
        echo "            </div>\n";
        echo "            <div id=\"collapseGeneral\" class=\"panel-body collapse in\">\n";
        echo "              <div class=\"col-md-8 col-center\">\n";
        echo "                Production: " . $nationInfo["production"] . ", #" . $rankingInfo["production"] . " in world\n";
        echo "                <br />\n";
        echo "                Money: " . $nationInfo["money"] . ", #" . $rankingInfo["money"] . " in world\n";
        echo "                <br />\n";
        echo "                Debt: " . $nationInfo["debt"] . "\n";
        echo "                <br />\n";
        if ($nationInfo["happiness"] >= 4) {
            echo "                Happiness: <img src=\"images/happiness/4.png\" alt=\"Very Happy\" />" . $nationInfo["happiness"] . ", #" . $rankingInfo["happiness"] . " in world\n";
        } else {
            if ($nationInfo["happiness"] >= 3) {
                echo "                Happiness: <img src=\"images/happiness/3.png\" alt=\"Happy\" />" . $nationInfo["happiness"] . ", #" . $rankingInfo["happiness"] . " in world\n";
            } else {
                if ($nationInfo["happiness"] >= 2) {
                    echo "                Happiness: <img src=\"images/happiness/2.png\" alt=\"Neutral\" />" . $nationInfo["happiness"] . ", #" . $rankingInfo["happiness"] . " in world\n";
                } else {
                    echo "                Happiness: <img src=\"images/happiness/1.png\" alt=\"Unhappy\" />" . $nationInfo["happiness"] . ", #" . $rankingInfo["happiness"] . " in world\n";
                }
            }
        }
        // else
        echo "                <br />\n";
        echo "                Food: " . round($nationInfo["food"], 2, PHP_ROUND_HALF_UP) . ", #" . $rankingInfo["food"] . " in world\n";
        echo "                <br />\n";
        echo "                Population: " . $nationInfo["population"] . ", #" . $rankingInfo["population"] . " in world\n";
        echo "              </div>\n";
        echo "            </div>\n";
        echo "          </div>\n";
        echo "          <div class=\"panel panel-info\">\n";
        echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View organizations that nation is currently a member of.\" class=\"panel-heading\">\n";
        echo "              <h3 class=\"panel-title\">Organizations        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseOrganizations\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
        echo "            </div>\n";
        echo "            <div id=\"collapseOrganizations\" class=\"panel-body collapse in\">\n";
        echo "              <div class=\"col-md-8 col-center\">\n";
        echo "                ";
        $belongstoOrgs = false;
        for ($z = 0; $z < count($nationInfo["organizations"]); $z++) {
            if ($z >= 1 && $nationInfo["organizations"][0] > 0) {
                echo ", ";
            }
            // if
            if ($nationInfo["organizations"][$z] >= 1) {
                $organizationInfo1 = getOrganizationInfo($getPage_connection2, $nationInfo["organizations"][$z]);
                echo "<a href=\"index.php?page=info&amp;section=orgs&amp;info_id=" . $organizationInfo1["id"] . "\">" . $organizationInfo1["name"] . "</a>";
                if (strlen($organizationInfo1["name"]) >= 1) {
                    $belongsToOrgs = true;
                }
                // if
            }
            // if
        }
        // for
        echo "                \n";
        echo "              </div>\n";
        echo "            </div>\n";
        echo "          </div>\n";
    } else {
        $organizationInfo = getOrganizationInfo($getPage_connection2, $_SESSION["info_id"]);
        echo "          <div class=\"panel panel-info\">\n";
        echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"View general information about organization.\" class=\"panel-heading\">\n";
        echo "              <h3 class=\"panel-title\">General        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseGeneral\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
        echo "            </div>\n";
        echo "            <div id=\"collapseGeneral\" class=\"panel-body collapse in\">\n";
        echo "              <div class=\"col-md-8 col-center\">\n";
        echo "                <h3>" . $organizationInfo["name"] . "</h3>\n";
        echo "                <br />\n";
        echo "                Ranking: " . $organizationInfo["ranking"] . " \n";
        echo "                <br />\n";
        echo "                <br />\n";
        echo "                Managers: " . count($organizationInfo["managers"]) . "\n";
        echo "                <br />\n";
        for ($z = 0; $z < count($organizationInfo["managers"]); $z++) {
            if ($z >= 1) {
                echo ", ";
            }
            // if
            if ($organizationInfo["managers"][$z] >= 1) {
                $nationInfo1 = getNationInfo($getPage_connection2, $organizationInfo["managers"][$z]);
                echo "<a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $nationInfo1["id"] . "\">" . $nationInfo1["name"] . "</a>";
            }
            // if
        }
        // for
        echo "                <br />\n";
        echo "                Members: " . count($organizationInfo["members"]) . "\n";
        echo "                <br />\n";
        for ($za = 0; $z < count($organizationInfo["members"]); $za++) {
            if ($za >= 1) {
                echo ", ";
            }
            // if
            if ($organizationInfo["members"][$za] >= 1) {
                $nationInfo1 = getNationInfo($getPage_connection2, $organizationInfo["members"][$za]);
                echo "<a href=\"index.php?page=info&amp;section=nations&amp;info_id=" . $nationInfo1["id"] . "\">" . $nationInfo1["name"] . "</a>";
            }
            // if
        }
        // for
        echo "              </div>\n";
        echo "            </div>\n";
        echo "          </div>\n";
    }
    // else
    echo "        </div>\n";
}
function acceptOffer($getPage_connection2)
{
    if ($_SESSION["action"] == "accept_offer") {
        if ($_SESSION["action_id"] > 0) {
            $offerInfo1 = getOfferInfo($getPage_connection2, $_SESSION["action_id"]);
            if (($offerInfo1["toNation"] == $_SESSION["nation_id"] || $offerInfo1["fromNation"] == $_SESSION["nation_id"]) && $offerInfo1["status"] == 0) {
                if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
                    // toNation: the target nation of action
                    // fromNation: the source nation of action
                    $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
                    $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
                    $notEnough = array(0 => false, 1 => "");
                    for ($zz = 0; $zz < count($toNationInfo["goods"]); $zz++) {
                        $new_to_goods = $toNationInfo["goods"][$zz];
                    }
                    // for
                    for ($zz = 0; $zz < count($toNationInfo["resources"]); $zz++) {
                        $new_to_resources = $toNationInfo["resources"][$zz];
                    }
                    // for
                    $new_to_food = $toNationInfo["food"];
                    $new_to_money = $toNationInfo["money"];
                    for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                        $new_from_goods = $fromNationInfo["goods"][$zz];
                    }
                    // for
                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                        $new_from_resources = $fromNationInfo["resources"][$zz];
                    }
                    // for
                    $new_from_food = $fromNationInfo["food"];
                    $new_from_money = $fromNationInfo["money"];
                    if ($offerInfo1["givingItems"][0] > 0) {
                        for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                            $new_bonus = 1;
                            for ($y = 0; $y * 10 > $offerInfo1["givingQuantities"][$z]; $y++) {
                                $new_bonus = $y + $new_bonus;
                            }
                            // for
                            // set new sell strength
                            if ($offerInfo1["givingTypes"][$z] == "goods") {
                                $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                $new_buyStrength = $itemInfo1["buyStrength"];
                                $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                                setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                                for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                                        $new_to_goods[$zz] = $toNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                                        $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "offer";
                                        break;
                                    }
                                    // else
                                }
                                // for
                            } else {
                                if ($offerInfo1["givingTypes"][$z] == "resources") {
                                    $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                    $new_buyStrength = $itemInfo1["buyStrength"];
                                    $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                                    setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                            $new_to_resources[$zz] = $toNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                                            $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "offer";
                                            break;
                                        }
                                        // else
                                    }
                                    // for
                                } else {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["money"]) {
                                        $new_to_money = $toNationInfo["money"] + $offerInfo1["givingQuantities"][$z];
                                        $new_from_money = $fromNationInfo["money"] - $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "offer";
                                        break;
                                    }
                                    // else
                                }
                            }
                            // else
                        }
                        // for
                    }
                    // if
                    if ($offerInfo1["receivingItems"][0] > 0) {
                        for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                            // set new buy strength
                            if ($offerInfo1["receivingTypes"][$z] == "goods") {
                                $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                                $new_sellStrength = $itemInfo1["sellStrength"];
                                setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                                for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                                        $new_to_goods[$zz] = $toNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                                        $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "demand";
                                        break;
                                    }
                                    // else
                                }
                                // for
                            } else {
                                if ($offerInfo1["receivingTypes"][$z] == "resources") {
                                    $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                    $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                                    $new_sellStrength = $itemInfo1["sellStrength"];
                                    setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                            $new_to_resources[$zz] = $toNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                                            $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "offer";
                                            break;
                                        }
                                        // else
                                    }
                                    // for
                                } else {
                                    if ($offerInfo1["receivingTypes"][$z] == "food") {
                                        if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["food"]) {
                                            $new_to_food = $toNationInfo["food"] - $offerInfo1["receivingQuantities"][$z];
                                            $new_from_food = $fromNationInfo["food"] + $offerInfo1["receivingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "demand";
                                            break;
                                        }
                                        // else
                                    } else {
                                        if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["money"]) {
                                            $new_to_money = $toNationInfo["money"] - $offerInfo1["receivingQuantities"][$z];
                                            $new_from_money = $fromNationInfo["money"] + $offerInfo1["receivingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "demand";
                                            break;
                                        }
                                        // else
                                    }
                                }
                            }
                            // else
                        }
                        // for
                    }
                    // if
                    if ($notEnough[0] === false) {
                        // give items
                        setNationInfo($getPage_connection2, $toNationInfo["id"], $toNationInfo["name"], $toNationInfo["home"], $toNationInfo["formal"], $toNationInfo["flag"], $toNationInfo["production"], $new_to_money, $toNationInfo["debt"], $toNationInfo["happiness"], $new_to_food, $toNationInfo["authority"], $toNationInfo["authorityChanged"], $toNationInfo["economy"], $toNationInfo["economyChanged"], $toNationInfo["organizations"], $toNationInfo["invites"], $new_to_goods, $new_to_resources, $toNationInfo["population"], $toNationInfo["strike"]);
                        // receive items
                        setNationInfo($getPage_connection2, $fromNationInfo["id"], $fromNationInfo["name"], $fromNationInfo["home"], $fromNationInfo["formal"], $fromNationInfo["flag"], $fromNationInfo["production"], $new_from_money, $fromNationInfo["debt"], $fromNationInfo["happiness"], $new_from_food, $fromNationInfo["authority"], $fromNationInfo["authorityChanged"], $fromNationInfo["economy"], $fromNationInfo["economyChanged"], $fromNationInfo["organizations"], $fromNationInfo["invites"], $new_from_goods, $new_from_resources, $fromNationInfo["population"], $fromNationInfo["strike"]);
                        // set offer status
                        setOfferInfo($getPage_connection2, $_SESSION["action_id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $offerInfo1["counter"], 1);
                        $_SESSION["success_message"] = "Offer has been accepted successfully!";
                    } else {
                        $_SESSION["warning_message"] = "Cannot complete action: a requested " . $notEnough[1] . " is not possible due to insufficent supply.";
                    }
                    // else
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: offer is empty.";
                }
                // else
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: current nation is not involved in selected offer.";
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: invalid offer selected.";
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: invalid action.";
    }
    // else
}
function showSettingsInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    $productionInfo = getProductionInfo($getPage_connection2, $_SESSION["nation_id"]);
    echo "        <div class=\"spacing-from-menu well well-lg standard-text\">\n";
    echo "          <div class=\"panel panel-info\">\n";
    echo "            <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change user account settings.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Change Settings        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseChange\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseChange\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    echo "                <form action=\"index.php?page=settings\" method=\"post\">\n";
    echo "                  <input type=\"hidden\" name=\"page\" value=\"settings\" />\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <label class=\"control-label\" for=\"currentPassword\">Current Password:</label>\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Current password of user account.  This is required to make any changes to your account.\" name=\"current_password\" type=\"password\" class=\"form-control input-md\" id=\"currentPassword\" placeholder=\"password\" />\n";
    echo "                  </div>\n";
    echo "                  <br />\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <label class=\"control-label\" for=\"changePassword\">New Password:</label>\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"New password of user account.  Should be 8-35 characters.\" name=\"setting_password\" type=\"password\" class=\"form-control input-md\" id=\"changePassword\" placeholder=\"password\" />\n";
    echo "                  </div>\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <label class=\"control-label\" for=\"changePasswordConfirm\">Confirm New Password:</label>\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Confirm new password of user account.  Should be 8-35 characters.\" name=\"setting_password_confirm\" type=\"password\" class=\"form-control input-md\" id=\"changePasswordConfirm\" placeholder=\"password\" />\n";
    echo "                  </div>\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Submit changes to user account.\" value=\"change\" name=\"action\" id=\"change\" type=\"submit\" class=\"btn btn-md btn-primary\">Change Settings</button>\n";
    echo "                  </div>\n";
    echo "                </form>\n";
    echo "                <br />\n";
    echo "                <br />\n";
    echo "                ==========";
    echo "                <form action=\"index.php?page=deactivate\" method=\"get\">\n";
    echo "                  <input type=\"hidden\" name=\"page\" value=\"deactivate\" />\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Deactivate your account.  This will disable access to your account!\" value=\"deactivate\" name=\"action\" id=\"deactivate\" type=\"submit\" class=\"btn btn-md btn-danger\">Deactivate Account</button>\n";
    echo "                  </div>\n";
    echo "                </form>\n";
    echo "              </div>\n";
    echo "            </div>\n";
    echo "          </div>\n";
    echo "        </div>\n";
}
Example #13
0
require_once dirname(__FILE__) . "/../data/webinfo.php";
require_once dirname(__FILE__) . "/visa.func.php";
$typeid = 8;
//签证栏目
require_once SLINEINC . "/listview.class.php";
if (isset($totalresult)) {
    $totalresult = intval(preg_replace("/[^\\d]/", '', $totalresult));
}
//总记录数
if (isset($pageno)) {
    $pageno = intval(preg_replace("/[^\\d]/", '', $pageno));
}
//当前页
$countrypy = !empty($countrypy) ? RemoveXSS($countrypy) : 0;
$cityid = !empty($cityid) ? RemoveXSS($cityid) : 0;
$countryinfo = getNationInfo($countrypy);
$where .= " and nationid='{$countryinfo['id']}'";
//签证城市条件
if (!empty($cityid)) {
    $where .= " and cityid='{$cityid}'";
}
$sql = "select a.* from #@__visa a left join #@__allorderlist b on (a.id=b.aid and b.typeid={$typeid} and a.webid=b.webid) where a.ishidden=0 {$where} order by case when b.displayorder is null then 9999 end,b.displayorder asc,a.modtime desc,a.addtime desc";
$seoarr = array();
//seo信息数组
$seoarr['typename'] = GetTypeName($typeid);
$seoarr['pageno'] = !empty($pageno) ? '第' . $pageno . '页-' : "";
$seoarr['seotitle'] = $countryinfo['seotitle'] ? $countryinfo['seotitle'] : $countryinfo['kindname'];
$seoarr['seodescription'] = !empty($countryinfo['description']) ? "<meta name=\"description\" content=\"" . $countryinfo['description'] . "\"/>" : "";
$seoarr['seokeyword'] = !empty($countryinfo['keyword']) ? "<meta name=\"keywords\" content=\"" . $countryinfo['keyword'] . "\"/>" : "";
$seoarr['jieshao'] = $countryinfo['jieshao'];
$seoarr['litpic_guoqi'] = $countryinfo['countrypic'] ? $countryinfo['countrypic'] : getDefaultImage();
Example #14
0
function buildUnit($getPage_connection2)
{
    $tileInfoW = getTileInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]);
    $improvementValid = false;
    // go through improvements
    for ($a = 0; $a < count($tileInfoW["improvements"]); $a++) {
        $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$a]);
        // is it a depot?
        if ($improvementInfoW["type"] == 5) {
            // are any of the owners of the depot the player?
            for ($b = 0; $b < count($improvementInfoW); $b++) {
                if ($improvementInfoW["owners"][$b] == $_SESSION["nation_id"]) {
                    $improvementValid = true;
                    break;
                } else {
                    $improvementValid = false;
                }
                // else
            }
            // for
        }
        // if
        if ($improvementValid === true) {
            break;
        }
        // if
    }
    // for
    // if valid depot exists on tile, proceed
    if ($_SESSION["action_id"] >= 1 && $improvementValid === true) {
        $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $_SESSION["action_id"]);
        $nationInfoW = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
        // is it a valid entity?
        if ($unitTypeInfoW["id"] >= 1) {
            if ($unitTypeInfoW["water"] == 1) {
                if (isItCoast($getPage_connection2, $tileInfoW) === true) {
                    $coastCheck = true;
                } else {
                    $coastCheck = false;
                }
                // else
            } else {
                $coastCheck = true;
            }
            // else
            // can player afford this expense?
            if ($coastCheck === true) {
                if ($unitTypeInfoW["baseCost"] <= $nationInfoW["money"]) {
                    $notEnough = false;
                    for ($zz = 0; $zz < count($unitTypeInfoW["goodsRequired"]); $zz++) {
                        if ($unitTypeInfoW["goodsRequired"][$zz] > $nationInfoW["goods"][$zz]) {
                            $notEnough = true;
                            break;
                        }
                        // if
                    }
                    // for
                    if ($notEnough === false) {
                        $unitInfoD = getUnitInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"]);
                        if ($unitInfoD["id"] < 1) {
                            $_SESSION["success_message"] = "Unit has been trained successfully!";
                            $new_money = $nationInfoW["money"] - $unitTypeInfoW["baseCost"];
                            $new_goods = array(0 => 0);
                            for ($zz = 0; $zz < count($nationInfoW["goods"]); $zz++) {
                                $new_goods[$zz] = $nationInfoW["goods"][$zz] - $unitTypeInfoW["goodsRequired"][$zz];
                            }
                            // for
                            $new_food = $nationInfoW["food"] - $unitTypeInfoW["foodRequired"];
                            setNationInfo($getPage_connection2, $_SESSION["nation_id"], $nationInfoW["name"], $nationInfoW["home"], $nationInfoW["formal"], $nationInfoW["flag"], $nationInfoW["production"], $new_money, $nationInfoW["debt"], $nationInfoW["happiness"], $new_food, $nationInfoW["authority"], $nationInfoW["authorityChanged"], $nationInfoW["economy"], $nationInfoW["economyChanged"], $nationInfoW["organizations"], $nationInfoW["invites"], $new_goods, $nationInfoW["resources"], $nationInfoW["population"], $nationInfoW["strike"]);
                            $mt_rand = mt_rand(100, 9999);
                            $new_name = "Unit " . $mt_rand;
                            // if transport, add to transport list
                            if ($_SESSION["action_id"] == 10) {
                                addTransportInfo($getPage_connection2, "0");
                                $new_transport_id = $getPage_connection2->insert_id;
                            } else {
                                $new_transport_id = 0;
                            }
                            // else
                            $tileInfoX = getTileInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]);
                            addUnitInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"], $unitTypeInfoW["health"], $unitTypeInfoW["movement"], $new_name, $_SESSION["action_id"], $_SESSION["nation_id"], 1, $new_transport_id, $tileInfoX["id"], 0.0);
                        } else {
                            $_SESSION["warning_message"] = "Cannot complete action: there is already a unit on that current tile.";
                        }
                        // else
                    }
                    // if
                }
                // if
            } else {
                if ($coastCheck === true) {
                    $_SESSION["warning_message"] = "Cannot complete action: player cannot afford this unit.";
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: unit type requires coast to train.";
                }
                // else
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: unit is not valid.";
        }
        // else
    } else {
        if ($improvementValid === true) {
            $_SESSION["warning_message"] = "Cannot complete action: unit requires depot for training.";
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: unit is not valid.";
        }
        // else
    }
    // else
}
Example #15
0
function deleteOrganizationInfo($s_connection, $s_id)
{
    if ($stmt = $s_connection->prepare("DELETE FROM organizations WHERE id=?")) {
        $stmt->bind_param("i", $s_id);
        $stmt->execute();
        $stmt->close();
    } else {
    }
    // else
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_nations = $r_result;
            $nationInfo2 = getNationInfo($s_connection, $next_nations);
            $new_organizations = array(0 => 0);
            $counter1 = 0;
            for ($xx = 0; $xx < count($nationInfo2["organizations"]); $xx++) {
                if ($nationInfo2["organizations"][$xx] != $s_id) {
                    $new_organizations[$counter1] = $nationInfo2["organizations"][$xx];
                    $counter1++;
                }
                // if
            }
            // for
            setNationInfo($s_connection, $nationInfo2["id"], $nationInfo2["name"], $nationInfo2["home"], $nationInfo2["formal"], $nationInfo2["flag"], $nationInfo2["production"], $nationInfo2["money"], $nationInfo2["debt"], $nationInfo2["happiness"], $nationInfo2["food"], $nationInfo2["authority"], $nationInfo2["authorityChanged"], $nationInfo2["economy"], $nationInfo2["economyChanged"], $new_organizations, $nationInfo2["invites"], $nationInfo2["goods"], $nationInfo2["resources"], $nationInfo2["population"], $nationInfo2["strike"]);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
}
Example #16
0
function updateNations($getPage_connection2)
{
    // main player sequence
    $_SESSION["scriptOutput"] = "<br /><br />Running main sequence...<br />";
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_nations = $r_result;
            $_SESSION["scriptOutput"] .= "<br />Setup nation...<br />";
            $nationInfoW = getNationInfo($getPage_connection2, $next_nations);
            $tradeInfoW = getTradeInfo($getPage_connection2, $next_nations);
            $formula = 0.0;
            $tax = 0.0;
            $new_production = 0;
            $new_money = $nationInfoW["money"];
            $new_food = $nationInfoW["food"];
            $new_happiness = 0.0;
            $new_goods = $nationInfoW["goods"];
            $new_resources = $nationInfoW["resources"];
            $new_limit = $tradeInfoW["limit"];
            $new_routes = array(0 => 0);
            $new_worth = array(0 => 0);
            $old_population = $nationInfoW["population"];
            $new_population = 0.0;
            $foreignTradePercent = 0.0;
            $productionPercent = 0.0;
            $efficiencyPercent = 0.0;
            $happinessPenalty = 0.0;
            $money_upkeep = 0.0;
            $food_upkeep = 0.0;
            $new_debt = $nationInfoW["debt"];
            $money_debt = 0.0;
            $food_debt = 0.0;
            $productionPercent = $nationInfoW["economy"] * 10;
            $foreignTradePercent = 100 - $productionPercent;
            $efficiencyPercent = $nationInfoW["authority"] * 10;
            $happinessPenalty = $nationInfoW["authority"] * 5;
            $productionInfoW = getProductionInfo($getPage_connection2, $next_nations);
            $using_production = 0.0;
            $used_production = $using_production;
            $new_prod = $new_goods;
            $new_strike = $nationInfoW["strike"];
            $new_tilesOwned = 0;
            $tradeCount = 0;
            $limit_allTilesOwned = 0;
            if ($stmt1 = $getPage_connection2->prepare("SELECT COUNT(id) FROM tilesmap WHERE owner=?")) {
                $stmt1->bind_param("i", $next_nations);
                $stmt1->execute();
                $stmt1->bind_result($r_result);
                $stmt1->fetch();
                $limit_allTilesOwned = $r_result;
                $stmt1->close();
            } else {
                $endTurnFailed = "failed";
            }
            // else
            $limit_allImprovements = 0;
            if ($stmt1 = $getPage_connection2->prepare("SELECT COUNT(id) FROM improvementsmap")) {
                $stmt1->execute();
                $stmt1->bind_result($r_result);
                $stmt1->fetch();
                $limit_allImprovements = $r_result;
                $stmt1->close();
            } else {
                $endTurnFailed = "failed";
            }
            // else
            /********************************
            		 Base Additions (including revenue) from improvements, tiles, etc.
            		 ********************************/
            // get tiles info for production/claims/bonus addition
            $_SESSION["scriptOutput"] .= "Get tiles info for production/claims/bonus addition...<br />";
            if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                $stmt1->execute();
                $stmt1->store_result();
                $stmt1->bind_result($r_result);
                while ($stmt1->fetch()) {
                    $next_tiles = $r_result;
                    $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles);
                    if ($tileInfoW["owner"] == $next_nations) {
                        // add claim strength if claim is dominant and tile is controlled
                        $claimsStateW = checkClaimsState($getPage_connection2, $tileInfoW, $next_nations);
                        if ($claimsStateW == 1) {
                            for ($e = 0; $e < count($tileInfoW["claims"]); $e++) {
                                $claimInfoW = getClaimInfo($getPage_connection2, $tileInfoW["claims"][$e]);
                                if ($claimInfoW["owner"] == $next_nations) {
                                    if ($claimInfoW["strength"] > 0) {
                                        $bonus_new_strength = 0;
                                        for ($c = 0; $c < count($tileInfoW["improvements"]); $c++) {
                                            $improvementInfoV = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$c]);
                                            if ($improvementInfoV["type"] == 1) {
                                                $bonus_new_strength = 3;
                                            }
                                            // if
                                        }
                                        // for
                                        $new_strength = $bonus_new_strength + $claimInfoW["strength"] + 2;
                                    }
                                    // if
                                    setClaimInfo($getPage_connection2, $claimInfoW["id"], $new_strength, $claimInfoW["owner"]);
                                }
                                // if
                            }
                            // for
                        }
                        // if
                        // trade
                        $_SESSION["scriptOutput"] .= "Trade Count adjust...<br />";
                        for ($ss = 0; $ss < count($tileInfoW["improvements"]); $ss++) {
                            $improvementInfoF = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$ss]);
                            if ($improvementInfoF["type"] == 1 || $improvementInfoF["type"] == 2) {
                                for ($cc = 0; $cc < count($improvementInfoF["owners"]); $cc++) {
                                    if ($improvementInfoF["owners"] == $next_nations) {
                                        if ($improvementInfoF["type"] == 1) {
                                            $tradeCount++;
                                        } else {
                                            if ($improvementInfoF["type"] == 2) {
                                                $tradeCount = $tradeCount + 2;
                                            }
                                        }
                                        // else if
                                    }
                                    // if
                                }
                                // for
                            }
                            // if
                        }
                        // for
                        // claims for happiness
                        $_SESSION["scriptOutput"] .= "Happiness+Claims adjust...<br />";
                        $claimsStateW = checkClaimsState($getPage_connection2, $tileInfoW, $next_nations);
                        // set happiness addition dependent on claim to tile
                        // if current nation claims successfully
                        if ($claimsStateW == 1) {
                            $new_happiness = $new_happiness + 5;
                            // if enemy nation claims successfully
                        } else {
                            if ($claimsStateW == 2) {
                                $new_happiness = $new_happiness + 1;
                                // if claim is contested and player is involved
                            } else {
                                if ($claimsStateW == 3) {
                                    $new_happiness = $new_happiness + 2;
                                    // if claim is contested and player is not involved
                                } else {
                                    if ($claimsStateW == 4) {
                                        // default to enemy claim
                                    } else {
                                        // bad
                                        $new_happiness = $new_happiness + 1;
                                    }
                                }
                            }
                        }
                        // else
                        // terrain production modifiers
                        $_SESSION["scriptOutput"] .= "Terrain production modifiers...<br />";
                        $terrainInfoW = array("productionModifier" => 0);
                        if ($stmt100 = $getPage_connection2->prepare("SELECT productionModifier FROM terrain WHERE id=? LIMIT 1")) {
                            $stmt100->bind_param("i", $tileInfoW["terrain"]);
                            $stmt100->execute();
                            $stmt100->bind_result($r_productionModifier);
                            $stmt100->fetch();
                            $terrainInfoW["productionModifier"] = $r_productionModifier;
                            $stmt100->close();
                        } else {
                        }
                        // else
                        if ($terrainInfoW["productionModifier"] >= 1) {
                            $mod = 0.01;
                            $new_production = $new_production + $terrainInfoW["productionModifier"] * $mod * 2.0;
                        } else {
                            $new_production = $new_production + 2;
                        }
                        // else
                    }
                    // if
                }
                // while
                $stmt1->close();
            } else {
            }
            // else
            // add to nation variables based on tile number
            $new_money = $new_money + 2 * $limit_allTilesOwned;
            //  get improvements
            $_SESSION["scriptOutput"] .= "Get improvements info for production, money, population mods...<br />";
            if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) {
                $stmt1->execute();
                $stmt1->store_result();
                $stmt1->bind_result($r_result);
                while ($stmt1->fetch()) {
                    $next_improvements = $r_result;
                    $improvementInfoW = getImprovementInfo($getPage_connection2, $next_improvements);
                    for ($z = 0; $z < count($improvementInfoW["owners"]); $z++) {
                        if ($improvementInfoW["owners"][$z] == $next_nations) {
                            // capital
                            if ($improvementInfoW["type"] == 1) {
                                $new_money = $new_money + 60.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                $new_production = $new_production + 20.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                $tileInfoG = getTileInfo($getPage_connection2, $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"]);
                                $generate_population = mt_rand(200.0 * (0.25 * $improvementInfoW["level"]), 800.0 * (0.25 * $improvementInfoW["level"]));
                                $new_tile_population = $tileInfoG["population"] + $generate_population / count($improvementInfoW["owners"]);
                                setTileInfo($getPage_connection2, $tileInfoG["id"], $tileInfoG["continent"], $tileInfoG["xpos"], $tileInfoG["ypos"], $tileInfoG["terrain"], $tileInfoG["resources"], $tileInfoG["improvements"], $tileInfoG["owner"], $tileInfoG["claims"], $new_tile_population);
                                // town
                            } else {
                                if ($improvementInfoW["type"] == 2) {
                                    $new_money = $new_money + 30.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                    $tileInfoG = getTileInfo($getPage_connection2, $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"]);
                                    $generate_population = mt_rand(200.0 * (0.25 * $improvementInfoW["level"]), 400.0 * (0.25 * $improvementInfoW["level"]));
                                    $new_tile_population = $tileInfoG["population"] + $generate_population / count($improvementInfoW["owners"]);
                                    setTileInfo($getPage_connection2, $tileInfoG["id"], $tileInfoG["continent"], $tileInfoG["xpos"], $tileInfoG["ypos"], $tileInfoG["terrain"], $tileInfoG["resources"], $tileInfoG["improvements"], $tileInfoG["owner"], $tileInfoG["claims"], $new_tile_population);
                                    // industry
                                } else {
                                    if ($improvementInfoW["type"] == 3) {
                                        $new_production = $new_production + 20.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                        // farm
                                    } else {
                                        if ($improvementInfoW["type"] == 4) {
                                            $generate_food = mt_rand(1000.0 * (0.25 * $improvementInfoW["level"]), 6000.0 * (0.25 * $improvementInfoW["level"]));
                                            $new_food = $new_food + $generate_food / count($improvementInfoW["owners"]);
                                            // depot
                                        } else {
                                            if ($improvementInfoW["type"] == 5) {
                                                // mill
                                            } else {
                                                if ($improvementInfoW["type"] == 6) {
                                                    for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) {
                                                        $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]);
                                                        if ($resourceInfoW["type"] == 1 && $resourceInfoW["capacity"] >= 5) {
                                                            $initialExtract = 0.02 * $resourceInfoW["capacity"];
                                                            $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                                            $new_resources[0] = $new_resources[0] + $extractAmount;
                                                            $new_capacity = $resourceInfoW["capacity"] - $extractAmount;
                                                            setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity);
                                                            break;
                                                        }
                                                        // if
                                                    }
                                                    // for
                                                    // reserve
                                                } else {
                                                    if ($improvementInfoW["type"] == 7) {
                                                        $new_happiness = $new_happiness + 0.01 / count($improvementInfoW["owners"]);
                                                        // mine
                                                    } else {
                                                        if ($improvementInfoW["type"] == 8) {
                                                            for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) {
                                                                $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]);
                                                                if ($resourceInfoW["type"] == 2 && $resourceInfoW["capacity"] >= 5) {
                                                                    $initialExtract = 0.02 * $resourceInfoW["capacity"];
                                                                    $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                                                    $new_resources[1] = $new_resources[1] + $extractAmount;
                                                                    $new_capacity = $resourceInfoW["capacity"] - $extractAmount;
                                                                    setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity);
                                                                    break;
                                                                }
                                                                // if
                                                            }
                                                            // for
                                                            // well
                                                        } else {
                                                            if ($improvementInfoW["type"] == 9) {
                                                                for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) {
                                                                    $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]);
                                                                    if ($resourceInfoW["type"] == 3 && $resourceInfoW["capacity"] >= 5) {
                                                                        $initialExtract = 0.02 * $resourceInfoW["capacity"];
                                                                        $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                                                        $new_resources[2] = $new_resources[2] + $extractAmount;
                                                                        $new_capacity = $resourceInfoW["capacity"] - $extractAmount;
                                                                        setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity);
                                                                        break;
                                                                    }
                                                                    // if
                                                                }
                                                                // for
                                                                // dam
                                                            } else {
                                                                if ($improvementInfoW["type"] == 10) {
                                                                    for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) {
                                                                        $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]);
                                                                        if ($resourceInfoW["type"] == 4 && $resourceInfoW["capacity"] >= 5) {
                                                                            $new_production = $new_production + 22.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]);
                                                                            setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity);
                                                                            break;
                                                                        }
                                                                        // if
                                                                    }
                                                                    // for
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // else if
                        }
                        // if
                    }
                    // for
                }
                // while
                $stmt1->close();
            } else {
            }
            // else
            /********************************
            		 HAPPINESS EFFECTS
            		 ********************************/
            $_SESSION["scriptOutput"] .= "Change happiness...<br />";
            // penalty for lack of consumer goods (basic and luxury), less penalty with more goods
            // luxury goods provide bigger boost
            $consumptionPenalty = 3.25 * $limit_allTilesOwned;
            $goodsPenalty = 0.0;
            if ($consumptionPenalty >= $new_goods[4] * 3.0E-5 * $limit_allTilesOwned + $new_goods[5] * 5.0E-5 * $limit_allTilesOwned) {
                $goodsPenalty = $consumptionPenalty - $new_goods[4] * 3.0E-5 * $limit_allTilesOwned + $new_goods[5] * 5.0E-5 * $limit_allTilesOwned;
            } else {
                $goodsPenalty = 0.0;
            }
            // else
            // happiness
            $new_happiness = ($new_happiness - ($happinessPenalty + $goodsPenalty) * $new_happiness / 100) / $limit_allTilesOwned;
            // set the rate of effect of happiness on production,taxation
            // Happiest
            if ($new_happiness >= 4) {
                $new_production = $new_production + $new_production * 0.25;
                $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.25;
                // Very Happy
            } else {
                if ($new_happiness >= 3) {
                    $new_production = $new_production + $new_production * 0.1;
                    $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.1;
                    // Happy
                } else {
                    if ($new_happiness >= 2) {
                        $new_production = $new_production + $new_production * 0.05;
                        $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.05;
                        // Content (nothing happens)
                    } else {
                        if ($new_happiness >= 1) {
                            // Unhappy
                        } else {
                            $new_production = $new_production - $new_production * 0.25;
                            $efficiencyPercent = $efficiencyPercent - $efficiencyPercent * 0.25;
                        }
                    }
                }
            }
            // else
            /********************************
            		 TRADE
            		 ********************************/
            $_SESSION["scriptOutput"] .= "Update trade routes, worth, offers...<br />";
            // cut off trade routes to the limit that exists and update trade info
            // this limits trade routes to currently controlled tiles
            $new_limit = $tradeCount;
            if (count($tradeInfoW["routes"]) < $new_limit) {
                for ($r = 0; $r < $new_limit; $r++) {
                    $new_routes[$r] = $tradeInfoW["routes"][$r];
                }
                // for
            } else {
                for ($r = 0; $r < count($tradeInfoW["routes"]); $r++) {
                    $new_routes[$r] = $tradeInfoW["routes"][$r];
                }
                // for
            }
            // else
            setTradeInfo($getPage_connection2, $tradeInfoW["id"], $next_nations, $new_routes, $new_limit);
            // do individual trades action if current nation involved
            if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
                $stmt1->execute();
                $stmt1->store_result();
                $stmt1->bind_result($r_result);
                while ($stmt1->fetch()) {
                    $next_offers = $r_result;
                    $offerInfoW = getOfferInfo($getPage_connection2, $next_offers);
                    if ($offerInfoW["fromNation"] == $next_nations) {
                        if ($offerInfoW["turns"] > $offerInfoW["counter"]) {
                            if ($offerInfoW["status"] == 1) {
                                processOffer($getPage_connection2, $offersInfoW);
                                $new_offer = $offerInfoW["counter"] + 1;
                                // remove if trade offer has expired
                                if ($new_counter > $offerInfoW["turns"]) {
                                    deleteOfferInfo($getPage_connection2, $offerInfoW["id"]);
                                } else {
                                    setOfferInfo($getPage_connection2, $offerInfoW["id"], $offerInfoW["fromNation"], $offerInfoW["toNation"], $offerInfoW["givingItems"], $offerInfoW["receivingItems"], $offerInfoW["givingQuantities"], $offerInfoW["receivingQuantities"], $offerInfoW["givingTypes"], $offerInfoW["receivingTypes"], $offerInfoW["turns"], $new_counter, $offerInfoW["status"]);
                                }
                                // else
                            }
                            // if
                        }
                        // if
                    }
                    // if
                }
                // while
                $stmt1->close();
            } else {
            }
            // else
            // trade agreements
            $tradeBonus = 0.0;
            $productionBonus = 0.0;
            $happinessPenaltyFromTrade = 0.0;
            for ($v = 0; $v < count($tradeInfoW["routes"]); $v++) {
                $agreementInfoQ = getAgreementInfo($getPage_connection2, $tradeInfoW["routes"][$v]);
                if ($agreementInfoQ["fromNation"] == $next_nations) {
                    if ($offerInfoW["status"] == 1) {
                        // receive money/production
                        $worth1 = 0.0;
                        // total worth of trade
                        $nationFrom1 = getNationInfo($getPage_connection2, $agreementInfoQ["fromNation"]);
                        $nationTo1 = getNationInfo($getPage_connection2, $agreementInfoQ["toNation"]);
                        // figure out wealth and production worth
                        $totalWealth = $nationFrom1["money"] + $nationTo1["money"];
                        $totalProduction = $nationFrom1["production"] + $nationTo1["production"];
                        // high policy number = protectionism, low policy number = free trade
                        // max 25% bonus from policy for either production or wealth
                        $tradeBonus = $tradeBonus + $totalWealth * (0.01 + 0.025 * (10 - $agreementInfoQ["policy"])) / 2;
                        $productionBonus = $productionBonus + $totalProduction * (0.008 + 0.025 * $agreementInfoQ["policy"]) / 2;
                        // happiness penalty for clashing ideologies
                        if ($agreementInfoQ["policy"] > $nationInfoW["economy"]) {
                            if ($agreementInfoQ["policy"] - $nationInfoW["economy"] > 0 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 1) {
                                $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.005;
                            } else {
                                if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 2 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 3) {
                                    $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.01;
                                } else {
                                    if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 4 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 5) {
                                        $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.02;
                                    } else {
                                        if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 6 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 7) {
                                            $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.03;
                                        } else {
                                            if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 8 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 9) {
                                                $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.04;
                                            } else {
                                                if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 10) {
                                                    $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.05;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // else if
                        } else {
                            if ($agreementInfoQ["policy"] < $nationInfoW["economy"]) {
                                if ($agreementInfoQ["economy"] - $nationInfoW["policy"] > 0 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 1) {
                                    $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.005;
                                } else {
                                    if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 2 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 3) {
                                        $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.01;
                                    } else {
                                        if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 4 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 5) {
                                            $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.02;
                                        } else {
                                            if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 6 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 7) {
                                                $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.03;
                                            } else {
                                                if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 8 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 9) {
                                                    $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.04;
                                                } else {
                                                    if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 10) {
                                                        $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.05;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                // else if
                            } else {
                            }
                        }
                        $new_counter = $agreementInfoQ["counter"] + 1;
                        // remove if trade agreement has expired
                        if ($new_counter > $agreementInfoQ["turns"]) {
                            deleteAgreementInfo($getPage_connection2, $agreementInfoQ["id"]);
                        } else {
                            setAgreementInfo($getPage_connection2, $agreementInfoQ["id"], $agreementInfoQ["policy"], $agreementInfoQ["turns"], $new_counter, $agreementInfoQ["toNation"], $agreementInfoQ["fromNation"], $agreementInfoQ["status"]);
                        }
                        // else
                    }
                    // if
                }
                // if
            }
            // for
            $new_happiness = $new_happiness - $happinessPenaltyFromTrade;
            $new_production = $new_production + $productionBonus;
            /********************************
            			 PRODUCTION COSTS
            			********************************/
            $_SESSION["scriptOutput"] .= "Produce stuff...<br />";
            // figure out spending percentage
            $using_production = $new_production * ($productionInfoW["spending"] * 0.01);
            // set production used to new spending amount
            $used_production = $using_production;
            // percentage of expenditure
            $ratios = $productionInfoW["ratios"];
            for ($t = 0; $t < count($ratios); $t++) {
                $ratio_id = $t + 1;
                $goodsInfoW = getGoodsInfo($getPage_connection2, $ratio_id);
                if ($goodsInfoW["id"] >= 1) {
                    $availableProduction = $used_production * ($ratios[$t] * 0.01);
                    // problem with this while loop: it's endless
                    while ($availableProduction > 0) {
                        $canProduce = false;
                        if ($goodsInfoW["productionRequired"] <= $availableProduction) {
                            if ($goodsInfoW["foodRequired"] <= $new_food) {
                                $checkForResourceTypes = true;
                                if (count($goodsInfoW["resourceTypesRequired"]) <= 1) {
                                    if ($goodsInfoW["resourceTypesRequired"][0] == 0) {
                                        $checkForResourceTypes = false;
                                    }
                                    // if
                                }
                                // if
                                if ($checkForResourceTypes === true) {
                                    for ($h = 0; $h < count($goodsInfoW["resourceTypesRequired"]); $h++) {
                                        // if resources are required
                                        if ($goodsInfoW["resourceTypesRequired"][$h] >= 1) {
                                            $resourceArraySlot1 = $goodsInfoW["resourceTypesRequired"][$h] - 1;
                                            if ($new_resources[$resourceArraySlot1] >= $goodsInfoW["resourceQuantitiesRequired"][$h]) {
                                                $canProduce = true;
                                            } else {
                                                $canProduce = false;
                                                break;
                                            }
                                            // else
                                        } else {
                                            $canProduce = true;
                                        }
                                        // else
                                    }
                                    // for
                                } else {
                                    $canProduce = true;
                                }
                                // else
                            } else {
                                $canProduce = false;
                            }
                            // else
                        } else {
                            $canProduce = false;
                        }
                        // else
                        if ($canProduce === true) {
                            for ($j = 0; $j < count($goodsInfoW["improvementTypesRequired"]); $j++) {
                                $typeCount = 0;
                                // if improvements are required
                                if ($goodsInfoW["improvementTypesRequired"][$j] >= 1) {
                                    if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) {
                                        $stmt2->execute();
                                        $stmt2->store_result();
                                        $stmt2->bind_result($r_result);
                                        while ($stmt2->fetch()) {
                                            $next_improvements2 = $r_result;
                                            $improvementInfoY = getImprovementInfo($getPage_connection2, $next_improvements2);
                                            if ($improvementInfoY["type"] == $goodsInfoW["improvementTypesRequired"][$j]) {
                                                for ($f = 0; $f < count($improvementInfoY["owners"]); $f++) {
                                                    if ($improvementInfoY["owners"][$f] == $next_nations) {
                                                        $typeCount++;
                                                    }
                                                    // if
                                                }
                                                // for
                                            }
                                            // if
                                            if ($typeCount >= $goodsInfoW["improvementQuantitiesRequired"][$j]) {
                                                $canProduce = true;
                                                break;
                                            }
                                            // if
                                        }
                                        // while
                                        $stmt2->close();
                                    } else {
                                    }
                                    // else
                                    if ($typeCount < $goodsInfoW["improvementQuantitiesRequired"][$j]) {
                                        $canProduce = false;
                                        break;
                                    }
                                    // if
                                }
                                // if
                            }
                            // for
                        }
                        // if
                        // able to produce good, proceed
                        if ($canProduce === true) {
                            // subtract from available production, nation's food total, nation's resources totals
                            $availableProduction = $availableProduction - $goodsInfoW["productionRequired"];
                            $new_food = $new_food - $goodsInfoW["foodRequired"];
                            if ($checkForResourceTypes === true) {
                                for ($k = 0; $k < count($goodsInfoW["resourceTypesRequired"]); $k++) {
                                    // if resources are required
                                    if ($goodsInfoW["resourceTypesRequired"][$k] >= 1) {
                                        $resourceArraySlot = $goodsInfoW["resourceTypesRequired"][$k] - 1;
                                        $new_resources[$resourceArraySlot] = $new_resources[$resourceArraySlot] - $goodsInfoW["resourceQuantitiesRequired"][$k];
                                    }
                                    // if
                                }
                                // for
                            }
                            // if
                            // add new good
                            $new_goods[$t] = $new_goods[$t] + 1;
                        } else {
                            break;
                        }
                        // else
                    }
                    // while
                }
                // if
            }
            // for
            $new_production = $new_production - $used_production;
            // tax
            $tax = $old_population * 0.11 * ($efficiencyPercent * 0.01);
            // trade and production bonus formula
            $formula = $productionPercent * 0.01 * ($new_production * 14);
            $_SESSION["scriptOutput"] .= "prod: " . $new_production . "<br />";
            $_SESSION["scriptOutput"] .= "formula: " . $formula . "<br />";
            $_SESSION["scriptOutput"] .= "tax: " . $tax . "<br />";
            $_SESSION["scriptOutput"] .= "money: " . $new_money . "<br />";
            // final money calculation
            $new_money = $new_money + $formula + $tax;
            /********************************
            		 COSTS AND UPKEEP
            		 ********************************/
            $_SESSION["scriptOutput"] .= "Unit upkeep...<br />";
            // unit upkeep
            if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM unitsmap ORDER BY id ASC")) {
                $stmt1->execute();
                $stmt1->store_result();
                $stmt1->bind_result($r_result);
                while ($stmt1->fetch()) {
                    $next_units = $r_result;
                    $unitInfoW = getUnitInfoByID($getPage_connection2, $next_units);
                    if ($unitInfoW["owner"] == $next_nations) {
                        $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $unitInfoW["type"]);
                        $tileInfoW = getTileInfo($getPage_connection2, $unitInfoW["continent"], $unitInfoW["xpos"], $unitInfoW["ypos"]);
                        $terrainInfoW = getTerrainInfo($getPage_connection2, $tileInfoW["terrain"]);
                        // figure out nearest supply depot for supply line distance
                        $best_difference = 9999;
                        $best_continent = 0;
                        if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) {
                            $stmt2->execute();
                            $stmt2->bind_result($r_result);
                            while ($stmt2->fetch()) {
                                $next_improvements1 = $r_result;
                                $improvementInfoWA = getImprovementInfo($getPage_connection2, $next_improvements1);
                                if ($improvementInfoWA["id"] >= 1) {
                                    for ($v = 0; $v < count($improvementInfoWA["owners"]); $v++) {
                                        if ($improvementInfoWA["owners"][$v] == $next_nations) {
                                            if ($improvementInfoWA["type"] == 5) {
                                                $current_difference = 0;
                                                if ($improvementInfoWA["continent"] == $unitInfoW["continent"]) {
                                                    $best_difference = 0;
                                                    $best_continent = $improvementInfoWA["continent"];
                                                    break;
                                                } else {
                                                    if ($improvementInfoWA["continent"] > $unitInfoW["continent"]) {
                                                        $current_difference = $improvementInfoWA["continent"] - $unitInfoW["continent"];
                                                    } else {
                                                        if ($improvementInfoWA["continent"] < $unitInfoW["continent"]) {
                                                            $current_difference = $unitInfoW["continent"] - $improvementInfoWA["continent"];
                                                        }
                                                    }
                                                }
                                                // else if
                                                if ($current_difference < $best_difference) {
                                                    $best_difference = $current_difference;
                                                    $best_continent = $improvementInfoWA["continent"];
                                                }
                                                // if
                                            }
                                            // if
                                        }
                                        // if
                                    }
                                    // for
                                }
                                // if
                            }
                            // while
                            $stmt2->close();
                        } else {
                        }
                        // else
                        $distance = $best_difference;
                        $distanceModifier = 5 * $distance;
                        if ($terrainInfoW["upkeepModifier"] >= 1) {
                            $mod = 0.01;
                            $food_upkeep = $food_upkeep + $unitTypeInfoW["foodRequired"] / 4 + $unitTypeInfoW["foodRequired"] / 4 * (($terrainInfoW["upkeepModifier"] + $distanceModifier) * $mod);
                            $money_upkeep = $money_upkeep + $unitTypeInfoW["baseCost"] / 4 + $unitTypeInfoW["baseCost"] / 4 * (($terrainInfoW["upkeepModifier"] + $distanceModifier) * $mod);
                        } else {
                            $food_upkeep = $food_upkeep + $unitTypeInfoW["foodRequired"] / 4;
                            $money_upkeep = $money_upkeep + $unitTypeInfoW["baseCost"] / 4;
                        }
                        // else
                    }
                    // if
                }
                // while
                $stmt1->close();
            } else {
            }
            // else
            $_SESSION["scriptOutput"] .= "Improvement upkeep...<br />";
            // improvement upkeep and nation's population update
            if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                $stmt2->execute();
                $stmt2->store_result();
                $stmt2->bind_result($r_result);
                while ($stmt2->fetch()) {
                    $next_tiles = $r_result;
                    $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles);
                    $terrainInfoW = getTerrainInfo($getPage_connection2, $tileInfoW["terrain"]);
                    for ($y = 0; $y < count($tileInfoW["improvements"]); $y++) {
                        $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$y]);
                        $improvementTypeInfoW = getImprovementTypeInfo($getPage_connection2, $improvementInfoW["type"]);
                        for ($z = 0; $z < count($improvementInfoW["owners"]); $z++) {
                            if ($improvementInfoW["owners"][$z] == $next_nations) {
                                // figure out distance costs
                                if ($nationInfoW["home"] > $tileInfoW["continent"]) {
                                    $distanceModifier = $nationInfoW["home"] - $tileInfoW["continent"];
                                } else {
                                    $distanceModifier = $tileInfoW["continent"] - $nationInfoW["home"];
                                }
                                $mod = 0.01;
                                $money_upkeep = $money_upkeep + $improvementTypeInfoW["baseCost"] / 4 / count($improvementInfoW["owners"]) + $improvementTypeInfoW["baseCost"] / 4 / count($improvementInfoW["owners"]) * (($distanceModifier + $terrainInfoW["upkeepModifier"]) * $mod);
                            }
                            // if
                        }
                        // for
                    }
                    // for
                    if ($tileInfoW["owner"] == $next_nations) {
                        $new_population = $new_population + $tileInfoW["population"];
                    }
                    // if
                }
                // while
                $stmt2->close();
            } else {
            }
            // else
            /********************************
            			FOOD
            			********************************/
            $_SESSION["scriptOutput"] .= "Feeding time...<br />";
            $_SESSION["scriptOutput"] .= "food: " . $new_food . "<br />";
            // food debt
            if ($new_food < $food_upkeep) {
                $food_debt = $food_upkeep - $new_food;
                $new_food = 0;
            } else {
                $new_food = $new_food - $food_upkeep;
            }
            // else
            // if food can feed new population, then allow for the growth
            if ($new_food >= $new_population) {
                $surplus = $new_food - $new_population;
                $popGrowth = 0.1 * ($surplus / $limit_allTilesOwned);
                $popGrowthInt = round($popGrowth, 0, PHP_ROUND_HALF_UP);
                $new_population = 0;
                // reset population to assign new value based on pop changes
                $next_tiles = 1;
                if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                    $stmt2->execute();
                    $stmt2->store_result();
                    $stmt2->bind_result($r_result);
                    while ($stmt2->fetch()) {
                        $next_tiles = $r_result;
                        $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles);
                        $new_tile_population = 0;
                        if ($tileInfoD["owner"] == $next_nations) {
                            $new_tile_population = $tileInfoD["population"] + $popGrowthInt;
                            setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population);
                            $new_population = $new_population + $new_tile_population;
                        }
                        // if
                    }
                    // while
                    $stmt2->close();
                } else {
                    $next_tiles = 0;
                }
                // else
                // if food cannot even sustain the population, it shrinks
            } else {
                if ($new_food < $new_population) {
                    // if there is food debt, then set food debt + random number to be deficit
                    if ($food_debt >= 1) {
                        $rand = mt_rand(1, 50);
                        $deficit = $food_debt + $rand;
                        $popShrink = 0.15 * ($deficit / $limit_allTilesOwned);
                        $popShrinkInt = round($popShrink, 0, PHP_ROUND_HALF_DOWN);
                        $new_population = 0;
                        // reset population to assign new value based on pop changes
                        if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                            $stmt2->execute();
                            $stmt2->store_result();
                            $stmt2->bind_result($r_result);
                            while ($stmt2->fetch()) {
                                $next_tiles = $r_result;
                                $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles);
                                $new_tile_population = 0;
                                if ($tileInfoD["owner"] == $next_nations) {
                                    $new_tile_population = $tileInfoD["population"] - $popShrinkInt;
                                    if ($new_tile_population < 0) {
                                        $new_tile_population = 0;
                                    }
                                    // if
                                    setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population);
                                    $new_population = $new_population + $new_tile_population;
                                }
                                // if
                            }
                            // while
                            $stmt2->close();
                        } else {
                        }
                        // else
                        // otherwise just use difference between population and food and random number to be deficit
                    } else {
                        $rand = mt_rand(1, 100);
                        $deficit = $new_population - $new_food + $rand;
                        $popShrink = 0.25 * ($deficit / $limit_allTilesOwned);
                        $popShrinkInt = round($popShrink, 0, PHP_ROUND_HALF_DOWN);
                        $new_population = 0;
                        // reset population to assign new value based on pop changes
                        if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
                            $stmt2->execute();
                            $stmt2->store_result();
                            $stmt2->bind_result($r_result);
                            while ($stmt2->fetch()) {
                                $next_tiles = $r_result;
                                $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles);
                                $new_tile_population = 0;
                                if ($tileInfoD["owner"] == $next_nations) {
                                    $new_tile_population = $tileInfoD["population"] - $popShrinkInt;
                                    if ($new_tile_population < 0) {
                                        $new_tile_population = 0;
                                    }
                                    // if
                                    setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population);
                                    $new_population = $new_population + $new_tile_population;
                                }
                                // if
                            }
                            // while
                            $stmt2->close();
                        } else {
                        }
                        // else
                    }
                    // else
                }
            }
            // else if
            /********************************
            			 DEBT COLLECTION
            			********************************/
            $_SESSION["scriptOutput"] .= "Money and Debts...<br />";
            // pay off debt before anything else
            if ($new_debt > 0) {
                if ($new_money < $new_debt) {
                    $money_debt = $new_debt - $new_money;
                    // reduce the debt if nothing else
                    $new_debt = $money_debt;
                    $new_money = 0;
                } else {
                    $new_money = $new_money - $new_debt;
                    $new_debt = 0;
                }
                // else
            }
            // if
            if ($new_money < $money_upkeep) {
                $money_debt = $money_upkeep - $new_money;
                $new_debt = $money_debt;
                $new_money = 0;
            } else {
                $new_money = $new_money - $money_upkeep;
            }
            // else
            $_SESSION["scriptOutput"] .= "Debt collecting...<br />";
            // money debt collecting
            // increase strike counter if debt is owed
            if ($new_debt > 0) {
                $new_strike = $new_strike + 1;
            }
            // if
            if ($new_food < 0) {
                $new_food = 0;
            }
            // if
            /********************************
            		 SET NEW VARIABLES
            		 ********************************/
            $_SESSION["scriptOutput"] .= "Update database...<br />";
            setNationInfo($getPage_connection2, $next_nations, $nationInfoW["name"], $nationInfoW["home"], $nationInfoW["formal"], $nationInfoW["flag"], $new_production, $new_money, $new_debt, $new_happiness, $new_food, $nationInfoW["authority"], 0, $nationInfoW["economy"], 0, $nationInfoW["organizations"], $nationInfoW["invites"], $new_goods, $new_resources, $new_population, $new_strike);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    $_SESSION["scriptOutput"] .= "That's a wrap, script complete.<br />";
}