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&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&section=orgs&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 }
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 updateGlobe($getPage_connection2) { // change requirements of luxury and basic goods // set luxurygoods $goodsInfoW = getGoodsInfo($getPage_connection2, 5); if ($goodsInfoW["productionRequired"] - 2 > 1) { $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2); } else { $new_productionRequired = mt_rand(1, $goodsInfoW["productionRequired"] + 2); } // else if ($new_productionRequired < 1) { $new_productionRequired = 1; } // if $rand_metals = 2; $rand_wood = 1; $rand_metals = mt_rand(2, 10); $rand_wood = mt_rand(2, 10); $new_resourceTypesRequired = array(0 => 0); $new_resourceQuantitiesRequired = array(0 => 0); if ($rand_wood > 0) { $new_resourceTypesRequired[0] = 1; $new_resourceQuantitiesRequired[0] = $rand_wood; } // if if ($rand_metals > 0) { $new_resourceTypesRequired[1] = 2; $new_resourceQuantitiesRequired[1] = $rand_metals; } // if setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]); // set basicgoods $goodsInfoW = getGoodsInfo($getPage_connection2, 6); if ($goodsInfoW["productionRequired"] - 2 > 1) { $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2); } else { $new_productionRequired = mt_rand(0, $goodsInfoW["productionRequired"] + 2); } // else if ($new_productionRequired < 1) { $new_productionRequired = 1; } // if $rand_metals = 1; $rand_wood = 1; $rand_metals = mt_rand(1, 8); $rand_wood = mt_rand(1, 8); $new_resourceTypesRequired = array(0 => 0); $new_resourceQuantitiesRequired = array(0 => 0); if ($rand_wood > 0) { $new_resourceTypesRequired[0] = 1; $new_resourceQuantitiesRequired[0] = $rand_wood; } // if if ($rand_metals > 0) { $new_resourceTypesRequired[1] = 2; $new_resourceQuantitiesRequired[1] = $rand_metals; } // if setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]); // set new market rates if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_goods = $r_result; $goodsInfoW = getGoodsInfo($getPage_connection2, $next_goods); $marketInfoW = getMarketInfo($getPage_connection2, $next_goods); $rate = 0; // if buy strength is more, increase rate, otherwise decrease or remain constant if ($goodsInfoW["buyStrength"] > $goodsInfoW["sellStrength"]) { $randRateBonus = mt_rand(1, 4); $rate = $marketInfoW["rate"] + $randRateBonus; } else { if ($goodsInfoW["buyStrength"] < $goodsInfoW["sellStrength"]) { $randFlux = mt_rand(1, 4); // random drop or rise (75% more likely drop) if ($randFlux == 1) { $randRateBonus = mt_rand(1, 2); $rate = $marketInfoW["rate"] + $randRateBonus; } else { $randRateBonus = mt_rand(1, 4); $rate = $marketInfoW["rate"] - $randRateBonus; } // else } else { $randFlux = mt_rand(1, 2); // random drop or rise (50/50) if ($randFlux == 1) { $randRateBonus = mt_rand(1, 2); $rate = $marketInfoW["rate"] + $randRateBonus; } else { $randRateBonus = mt_rand(1, 2); $rate = $marketInfoW["rate"] - $randRateBonus; } // else } } // else if ($rate >= 1) { setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], $rate); } else { setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], 0); } // else // reset strength of good for next turn (no reset for now) //setGoodsInfo($getPage_connection2,$goodsInfoW["id"],$goodsInfoW["name"],$goodsInfoW["productionRequired"],$goodsInfoW["foodRequired"],$goodsInfoW["resourceTypesRequired"],$goodsInfoW["resourceQuantitiesRequired"],$goodsInfoW["improvementTypesRequired"],$goodsInfoW["improvementQuantitiesRequired"],$goodsInfoW["improvementLevelRequired"],100,100); } // while $stmt->close(); } else { } // else // add to turn counter for trade offers if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_offers = $r_result; $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers); $new_counter = $offerInfo1["counter"] + 1; setOfferInfo($getPage_connection2, $offerInfo1["id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $new_counter, $offerInfo1["status"]); } // while $stmt->close(); } else { } // else // remove empty organizations, automatically appoint new manager if there is no manager (new manager is the oldest joined member) if ($stmt = $getPage_connection2->prepare("SELECT id FROM organizations ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_organizations = $r_result; $organizationInfo1 = getOrganizationInfo($getPage_connection2, $next_organizations); $new_managers = array(0 => 0); if (count($organizationInfo1["members"]) == 1) { if ($organizationInfo1["members"][0] == 0) { deleteOrganizationInfo($getPage_connection2, $next_organizations); } // if } else { if (count($organizationInfo1["members"]) > 1) { if (count($organizationInfo1["managers"]) == 1) { if ($organizationInfo1["managers"][0] == 0) { $new_managers[0] = $organizationInfo1["members"][0]; setOrganizationInfo($getPage_connection2, $next_organizations, $organizationInfo1["name"], $organizationInfo1["members"], $new_managers, $organizationInfo1["pending"], $organizationInfo1["ranking"]); } // if } else { } // else } else { deleteOrganizationInfo($getPage_connection2, $next_organizations); } } // else } // while $stmt->close(); } else { } // else // set rankings if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); $offset = 0; while ($stmt->fetch()) { $next_nations = $r_result; $rank = $offset + 1; // production if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY production DESC LIMIT 1 OFFSET ?")) { $stmt11->bind_param("i", $offset); $stmt11->execute(); $stmt11->bind_result($r_result); $stmt11->fetch(); $next_production_nation = $r_result; $stmt11->close(); } else { } // else if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET production=? WHERE nation=?")) { $stmt11->bind_param("ii", $rank, $next_production_nation); $stmt11->execute(); $stmt11->close(); } else { } // else // money if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY money DESC LIMIT 1 OFFSET ?")) { $stmt11->bind_param("i", $offset); $stmt11->execute(); $stmt11->bind_result($r_result); $stmt11->fetch(); $next_money_nation = $r_result; $stmt11->close(); } else { } // else if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET money=? WHERE nation=?")) { $stmt11->bind_param("ii", $rank, $next_money_nation); $stmt11->execute(); $stmt11->close(); } else { } // else // happiness if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY happiness DESC LIMIT 1 OFFSET ?")) { $stmt11->bind_param("i", $offset); $stmt11->execute(); $stmt11->bind_result($r_result); $stmt11->fetch(); $next_happiness_nation = $r_result; $stmt11->close(); } else { } // else if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET happiness=? WHERE nation=?")) { $stmt11->bind_param("ii", $rank, $next_happiness_nation); $stmt11->execute(); $stmt11->close(); } else { } // else // food if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY food DESC LIMIT 1 OFFSET ?")) { $stmt11->bind_param("i", $offset); $stmt11->execute(); $stmt11->bind_result($r_result); $stmt11->fetch(); $next_food_nation = $r_result; $stmt11->close(); } else { } // else if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET food=? WHERE nation=?")) { $stmt11->bind_param("ii", $rank, $next_food_nation); $stmt11->execute(); $stmt11->close(); } else { } // else // population if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY population DESC LIMIT 1 OFFSET ?")) { $stmt11->bind_param("i", $offset); $stmt11->execute(); $stmt11->bind_result($r_result); $stmt11->fetch(); $next_population_nation = $r_result; $stmt11->close(); } else { } // else if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET population=? WHERE nation=?")) { $stmt11->bind_param("ii", $rank, $next_population_nation); $stmt11->execute(); $stmt11->close(); } else { } // else $offset++; } // while $stmt->close(); } else { $next_offers = 0; } // else }