function showPoliciesInfo($getPage_connection2)
{
    $nationInfo = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
    $continentInfo = getContinentInfo($getPage_connection2, $nationInfo["home"]);
    $productionInfo = getProductionInfo($getPage_connection2, $_SESSION["nation_id"]);
    $authorityReport = getAuthorityReport($nationInfo["authority"]);
    $economyReport = getEconomyReport($nationInfo["economy"]);
    $rankingInfo = getRankingInfo($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=\"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=\"Change basic govermental policies.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Change Policies        <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 "                <label class=\"control-label\">Reform Government:</label> \n";
    echo "                  <form action=\"index.php?page=policies\" method=\"post\">\n";
    echo "                    <input type=\"hidden\" name=\"page\" value=\"policies\" />\n";
    if ($nationInfo["authorityChanged"] == 0) {
        echo "                    <div class=\"form-group form-group-sm\">\n";
        if ($nationInfo["authority"] > 0) {
            echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Decrease authority.  This will mean less state control of society.\" value=\"aminus\" name=\"action\" id=\"authority_decrease\" type=\"submit\" class=\"btn btn-md btn-primary\"><span class=\"glyphicon glyphicon-minus\"></span></button>\n";
        }
        // if
        echo "                Authority\n";
        if ($nationInfo["authority"] < 10) {
            echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Increase authority.  This will mean more state control of society.\" value=\"aplus\" name=\"action\" id=\"authority_increase\" type=\"submit\" class=\"btn btn-md btn-primary\"><span class=\"glyphicon glyphicon-plus\"></span></button>\n";
        }
        // if
        echo "                    </div>\n";
    } else {
        echo "                    Authority has already been reformed this turn. <br />\n";
    }
    // else
    if ($nationInfo["economyChanged"] == 0) {
        echo "                    <div class=\"form-group form-group-sm\">\n";
        if ($nationInfo["economy"] > 0) {
            echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Decrease economic control.  This will mean less state intervention in the economy.\" value=\"eminus\" name=\"action\" id=\"economy_decrease\" type=\"submit\" class=\"btn btn-md btn-primary\"><span class=\"glyphicon glyphicon-minus\"></span></button>\n";
        }
        // if
        echo "                        Economy\n";
        if ($nationInfo["economy"] < 10) {
            echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Increase economic control.  This will mean more state intervention in the economy.\" value=\"eplus\" name=\"action\" id=\"economy_increase\" type=\"submit\" class=\"btn btn-md btn-primary\"><span class=\"glyphicon glyphicon-plus\"></span></button>\n";
        }
        // if
        echo "                    </div>\n";
    } else {
        echo "                    Economy has already been reformed this turn. <br />\n";
    }
    // else
    echo "                    <div class=\"form-group form-group-sm\">\n";
    echo "                      <label class=\"control-label\" for=\"formal\">Formal Name:</label>\n";
    echo "                      <input name=\"formalname\" type=\"text\" class=\"form-control input-md\" id=\"formal\" placeholder=\"New Formal Name of Nation\" />\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change long formal name of nation.  This will not affect the regular short name of your nation!\" value=\"formal\" name=\"action\" id=\"formal_change\" type=\"submit\" class=\"btn btn-md btn-primary\">Change Formal Name</button>\n";
    echo "                    </div>\n";
    echo "                  </form>\n";
    echo "                  <form action=\"index.php?page=policies&amp;action=flag\" method=\"post\" enctype=\"multipart/form-data\">\n";
    echo "                    <div class=\"form-group form-group-sm\">\n";
    echo "                      <label class=\"control-label\" for=\"fileToUpload\">Upload New Flag:</label>\n";
    echo "                      <br />\n";
    echo "                      <span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Select an image file from your computer to be your new flag.\" class=\"btn btn-med btn-default btn-file\">\n";
    echo "                        Browse <input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\" />\n";
    echo "                      </span>\n";
    echo "                      <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Upload your new flag.\" value=\"flag\" name=\"action\" type=\"submit\" class=\"btn btn-md btn-primary\">Change Flag</button>\n";
    echo "                    </div>\n";
    echo "                  </form>\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=\"Change production expenditure and prioritization.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Production        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseProduction\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseProduction\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    echo "                <form action=\"index.php?page=policies\" method=\"post\">\n";
    echo "                  <div class=\"form-group form-group-sm\">\n";
    echo "                    <input type=\"hidden\" name=\"page\" value=\"policies\" />\n";
    echo "                    <label class=\"control-label\" for=\"slider1\">Production Spending Percentage:</label>\n";
    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change the amount of production you spend for this turn.  Remember that production does not transfer over to the next turn!\" name=\"prod-percent\" id=\"slider1\" type=\"range\" min=\"0\" max=\"100\" step=\"5\" value=\"" . $productionInfo["spending"] . "\" class=\"\" />\n";
    echo "                    <br />\n";
    $productionInfo1 = getProductionInfo($getPage_connection2, $_SESSION["nation_id"]);
    if ($productionInfo1["id"] >= 1) {
        for ($k = 0; $k < count($productionInfo1["goods"]) + 1; $k++) {
            $new_index = $k + 1;
            $goodsInfo2 = getGoodsInfo($getPage_connection2, $new_index);
            if ($goodsInfo2["id"] >= 1) {
                echo "                    <label class=\"control-label\" for=\"slider_prod-" . $goodsInfo2["name"] . "\">Emphasize " . $goodsInfo2["name"] . ":</label>\n";
                echo "                    " . round($goodsInfo2["productionRequired"], 2, PHP_ROUND_HALF_UP) . " Production, " . round($goodsInfo2["foodRequired"], 2, PHP_ROUND_HALF_UP) . " Food";
                for ($t = 0; $t < count($goodsInfo2["resourceTypesRequired"]); $t++) {
                    if ($goodsInfo2["resourceTypesRequired"][$t] >= 1) {
                        echo ", ";
                        $resourceTypeInfo1 = getResourceTypeInfo($getPage_connection2, $goodsInfo2["resourceTypesRequired"][$t]);
                        echo $goodsInfo2["resourceQuantitiesRequired"][$t] . " " . $resourceTypeInfo1["name"];
                    }
                    // if
                }
                // for
                echo "\n";
                $productionType = $goodsInfo2["id"];
                if (strlen($productionType) >= 1) {
                    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change prioritization of producing this good.\" name=\"prod[" . $k . "]\" id=\"slider_prod-" . $productionType . "\" type=\"range\" min=\"0\" max=\"3\" step=\"1\" value=\"" . $productionInfo1["goods"][$k] . "\" />\n";
                } else {
                    echo "                    <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Change prioritization of producing this good.\" name=\"prod[" . $k . "]\" id=\"slider_prod-" . $productionType . "\" type=\"range\" min=\"0\" max=\"3\" step=\"1\" value=\"0\" />\n";
                }
                // else
            }
            // if
        }
        // for
    }
    // if
    echo "                    <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Submit changes to production expenditure and prioritization.\" value=\"prod\" name=\"action\" id=\"prod_change\" type=\"submit\" class=\"btn btn-md btn-primary\">Set Production</button>\n";
    echo "                  </div>\n";
    echo "                </form>\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 goods inventory statistics of nation.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Goods        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseGoods\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseGoods\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    for ($zz = 0; $zz < count($nationInfo["goods"]); $zz++) {
        $goodsInfoK = getGoodsInfo($getPage_connection2, $zz + 1);
        echo "                " . $goodsInfoK["name"] . ": " . $nationInfo["goods"][$zz] . "\n";
        echo "                <br />\n";
    }
    // for
    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 resources inventory statistics of nation.\" class=\"panel-heading\">\n";
    echo "              <h3 class=\"panel-title\">Resources        <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseResources\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n";
    echo "            </div>\n";
    echo "            <div id=\"collapseResources\" class=\"panel-body collapse in\">\n";
    echo "              <div class=\"col-md-8 col-center\">\n";
    for ($zz = 0; $zz < count($nationInfo["resources"]); $zz++) {
        $resourceTypeInfoK = getResourceTypeInfo($getPage_connection2, $zz + 1);
        echo "                " . $resourceTypeInfoK["name"] . ": " . $nationInfo["resources"][$zz] . "\n";
        echo "                <br />\n";
    }
    // for
    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";
    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
}
Exemple #3
0
function processOffer($getPage_connection2, $offerInfo1)
{
    $payup = false;
    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);
        } else {
            $payup = true;
        }
        // else
    } else {
    }
    // else
    // if trade is not completed in full, freeze the route for the nation at fault
    if ($payup === true) {
        // who's responsible?
        // target nation's fault
        if ($notEnough[1] == "demand") {
            for ($x = 0; $x < count($toTradeInfo["offers"]); $x++) {
                $new_worth = $toTradeInfo["worth"];
                $new_worth[$x] = 0;
                setTradeInfo($getPage_connection2, $toTradeInfo["id"], $toTradeInfo["nation"], $toTradeInfo["routes"], $new_worth, $toTradeInfo["offers"], $toTradeInfo["limit"]);
            }
            // for
            // source nation's fault
        } else {
            for ($x = 0; $x < count($fromTradeInfo["offers"]); $x++) {
                $new_worth = $fromTradeInfo["worth"];
                $new_worth[$x] = 0;
                setTradeInfo($getPage_connection2, $fromTradeInfo["id"], $fromTradeInfo["nation"], $fromTradeInfo["routes"], $new_worth, $fromTradeInfo["offers"], $fromTradeInfo["limit"]);
            }
            // for
        }
        // else
    }
    // if
}
function buildImprovement($getPage_connection2)
{
    if ($_SESSION["action_id"] >= 1) {
        $improvementTypeInfoW = getImprovementTypeInfo($getPage_connection2, $_SESSION["action_id"]);
        $tileInfoW = getTileInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]);
        $validImprovement = false;
        $availableResources = array(0 => 0);
        $counter = 0;
        $using = array(0 => 0);
        $proceed = false;
        $nationInfoE = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
        // if home continent already exists, capital is built, ignore build command
        if ($improvementTypeInfoW["id"] == 1 && $nationInfoE["home"] > 0) {
            $proceed = false;
        } else {
            $proceed = true;
        }
        // else
        if ($proceed === true) {
            // loop tile's resources
            for ($q = 0; $q < count($tileInfoW["resources"]); $q++) {
                $resourceIsUsed = false;
                $resourceInfo = getResourceInfo($getPage_connection2, $tileInfoW["resources"][$q]);
                // only proceed if capacity exists above 0
                if ($resourceInfo["capacity"] >= 1) {
                    $resourceTypeInfo = getResourceTypeInfo($getPage_connection2, $resourceInfo["type"]);
                    // loop tile's improvements
                    for ($a = 0; $a < count($tileInfoW["improvements"]); $a++) {
                        $improvementInfo = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$a]);
                        // if tile improvement is currently using resource, check
                        for ($d = 0; $d < count($improvementInfo["usingResources"]); $d++) {
                            if ($improvementInfo["usingResources"][$d] == $resourceInfo["id"]) {
                                $resourceIsUsed = true;
                                break;
                            } else {
                                $resourceIsUsed = false;
                            }
                            // else
                        }
                        // for
                        if ($resourceIsUsed === true) {
                            break;
                        }
                        // if
                    }
                    // for
                } else {
                    $resourceIsUsed = true;
                }
                // else
                // set available resources not used and with capacity left
                if ($resourceIsUsed === false) {
                    $availableResources[$counter] = $resourceInfo;
                    $counter++;
                }
                // if
            }
            // for
            $terrainIsValid = false;
            // loop terrain requirements
            for ($b = 0; $b < count($improvementTypeInfoW["terrainTypeRequired"]); $b++) {
                // if tile terrain type is valid, check
                if ($improvementTypeInfoW["terrainTypeRequired"][$b] == $tileInfoW["terrain"]) {
                    $terrainIsValid = true;
                    break;
                } else {
                    $terrainIsValid = false;
                }
                // else
            }
            // for
            // if terrain is valid, check for resource requirements
            if ($terrainIsValid === true) {
                $resourceIsValid = false;
                // if no requirements just proceed, otherwise proceed to loop
                if ($improvementTypeInfoW["resourcesRequired"][0] == 0) {
                    $validImprovement = true;
                } else {
                    $checkResource = array(0 => false);
                    $using = array(0 => 0);
                    // loop resource requirements
                    for ($t = 0; $t < count($improvementTypeInfoW["resourcesRequired"]); $t++) {
                        // loop available resources
                        for ($z = 0; $z < count($availableResources); $z++) {
                            // if tile terrain type is valid, check
                            if ($improvementTypeInfoW["resourcesRequired"][$t] == $availableResources[$z]["type"]) {
                                $checkResource[$t] = true;
                                $using[$t] = $availableResources[$z]["id"];
                                break;
                            } else {
                            }
                            // else
                        }
                        // for
                    }
                    // for
                    $illegal = false;
                    for ($a = 0; $a < count($improvementTypeInfoW["resourcesRequired"]); $a++) {
                        if (isset($checkResource[$a])) {
                            if ($checkResource[$a] === false) {
                                $illegal = true;
                                break;
                            }
                            // if
                        } else {
                            $illegal = true;
                            break;
                        }
                        // else
                    }
                    // for
                    if ($illegal === false) {
                        $validImprovement = true;
                    }
                    // if
                }
                // else
            }
            // if
        }
        // if
        if ($validImprovement === true) {
            // are improvement slots maxed out?
            if (count($tileInfoW["improvements"]) < 5) {
                // is tile owned by current player?
                if ($tileInfoW["owner"] == $_SESSION["nation_id"]) {
                    $nationInfoW = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
                    $final_cost = $improvementTypeInfoW["baseCost"];
                    if ($nationInfoW["money"] >= $final_cost) {
                        $_SESSION["success_message"] = "Player's improvement has been built successfully!";
                        $new_money = $nationInfoW["money"] - $final_cost;
                        $new_owners = array(0 => $_SESSION["nation_id"]);
                        // change home continent if capital built
                        // add population if town or capital is built
                        if ($improvementTypeInfoW["id"] == 1) {
                            $new_population = $nationInfoE["population"] + 1000;
                            $new_home = $_SESSION["continent_id"];
                            setNationInfo($getPage_connection2, $nationInfoE["id"], $nationInfoE["name"], $new_home, $nationInfoE["formal"], $nationInfoE["flag"], $nationInfoE["production"], $nationInfoE["money"], $nationInfoE["debt"], $nationInfoE["happiness"], $nationInfoE["food"], $nationInfoE["authority"], $nationInfoE["authorityChanged"], $nationInfoE["economy"], $nationInfoE["economyChanged"], $nationInfoE["organizations"], $nationInfoE["invites"], $nationInfoE["goods"], $nationInfoE["resources"], $new_population, $nationInfoE["strike"]);
                        } else {
                            if ($improvementTypeInfoW["id"] == 2) {
                                $new_population = $nationInfoE["population"] + 1000;
                                setNationInfo($getPage_connection2, $nationInfoE["id"], $nationInfoE["name"], $nationInfoE["home"], $nationInfoE["formal"], $nationInfoE["flag"], $nationInfoE["production"], $nationInfoE["money"], $nationInfoE["debt"], $nationInfoE["happiness"], $nationInfoE["food"], $nationInfoE["authority"], $nationInfoE["authorityChanged"], $nationInfoE["economy"], $nationInfoE["economyChanged"], $nationInfoE["organizations"], $nationInfoE["invites"], $nationInfoE["goods"], $nationInfoE["resources"], $new_population, $nationInfoE["strike"]);
                            }
                        }
                        // else if
                        $mt_rand = mt_rand(100, 9999);
                        $new_name = "Improvement " . $mt_rand;
                        addImprovementInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"], $_SESSION["action_id"], 1, $using, $new_owners, $new_name);
                    } else {
                        $_SESSION["warning_message"] = "Cannot complete action: current player cannot afford this expense.";
                    }
                    // else
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: tile is not owned by current player.";
                }
                // else
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: this tile has its maximum capacity of improvements fulfilled.";
            }
            // else
        } else {
            if ($proceed === false) {
                $_SESSION["warning_message"] = "Cannot complete action: the construction of this improvement type has reached its limit already.";
            } else {
                if ($terrainIsValid === false) {
                    $_SESSION["warning_message"] = "Cannot complete action: terrain is incompatible with improvement type.";
                } else {
                    if ($resourceIsValid === false) {
                        $_SESSION["warning_message"] = "Cannot complete action: improvement type requires resource that is not currently available in sufficient quantity on this tile.";
                    } else {
                        $_SESSION["warning_message"] = "Cannot complete action: improvement construction cannot be completed due to zoning restrictions.";
                    }
                }
            }
            // else
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: improvement construction is not valid.";
    }
    // else
}