protected function OnInput() { parent::OnInput(); $this->title = 'Заявка'; $this->id = $_GET['id']; $this->user = $_SESSION['uid']; makeopen($this->user, $this->id); $this->claiminfo = getClaimInfo($this->id); if (isset($_POST['submit']) && isClosed($this->id)) { closeThisClaim($this->id); } if (isset($_POST['submit']) && ($_SESSION['role'] == '2' || $_SESSION['role'] == '5')) { $comment = $_POST['comment']; $str = $_POST['manager']; $n = strlen($str); if ($n >= 4) { $manager = substr($str, 3, $n - 1); } else { $m = getManagerFromSection($_POST['manager']); $manager = $m->id; } if ($comment != '') { addcomment($this->user, $this->id, $manager, $comment); } makestate($_SESSION['uid'], $this->id); sendtouser($manager, $this->id, $this->user); } if (isset($_POST['submit']) && $_SESSION['role'] == '3') { $comment = $_POST['comment']; $user = $_POST['user']; if ($comment != '') { addcomment($this->user, $this->id, $user, $comment); } makestate($_SESSION['uid'], $this->id); sendtouser($user, $this->id, $this->user); } if (isset($_POST['submit']) && $_SESSION['role'] == '4') { move_uploaded_file($_FILES["filename"]['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/dt/uploads/act/" . $_FILES["filename"]["name"]); makestate($_SESSION['uid'], $this->id); closeClaim($this->id, $_SESSION['uid'], $_FILES['filename']['name']); if ($comment != '') { addcomment($this->user, $this->id, $user, $comment); } } }
function checkClaimsState($getPage_connection2, $tileInfoZ, $ref_nation) { $returnClaimInfo = 0; // state returned // 1 = player successfully claims // 2 = enemy successfully claims // 3 = player's, contested // 4 = enemy's, contested $validClaimsPresent = true; $claimInfo1 = getClaimInfo($getPage_connection2, $tileInfoZ["claims"][0]); // figure out if any claims actually exist if (count($tileInfoZ["claims"]) > 1) { if ($tileInfoZ["claims"][1] > 0) { $validClaimsPresent = true; } else { $validClaimsPresent = false; } // else } else { if ($tileInfoZ["claims"][0] > 0) { $validClaimsPresent = true; } else { $validClaimsPresent = false; } // else } // else $claim_id = 0; $playerContesting = false; $claimIsContested = false; if ($validClaimsPresent === true) { if (count($tileInfoZ["claims"]) <= 1) { $claim_id = $claimInfo1["owner"]; $playerContesting = false; $claimIsContested = false; } else { $currentClaim = 0; $greatestClaim = 0; // gets the greatest claim and returns the id of the greatest claimant for ($z = 0; $z < count($tileInfoZ["claims"]); $z++) { $claimInfo2 = getClaimInfo($getPage_connection2, $tileInfoZ["claims"][$z]); $currentClaim = $claimInfo2["strength"]; if ($z == 0) { $greatestClaim = $claimInfo2["strength"]; $currentClaim = $greatestClaim; $claim_id = $claimInfo2["owner"]; } else { // if current claim is greater than the greatest claim plus 10%, it is now the greatest claim if ($currentClaim > $greatestClaim + 0.1 * $greatestClaim) { $greatestClaim = $currentClaim; $claim_id = $claimInfo2["owner"]; } // if } // else } // for if (count($tileInfoZ["claims"]) >= 2) { $currentClaim = 0; for ($z = 0; $z < count($tileInfoZ["claims"]); $z++) { $claimInfo2 = getClaimInfo($getPage_connection2, $tileInfoZ["claims"][$z]); $currentClaim = $claimInfo2["strength"]; // if current claim is greater than or equal to the greatest claim minus 10%, the claim is now contested if ($currentClaim >= $greatestClaim - 0.1 * $greatestClaim) { if ($claimInfo2["owner"] == $claim_id) { $claimIsContested = false; } else { $claimIsContested = true; if ($claimInfo2["owner"] == $ref_nation || $claim_id == $ref_nation) { $playerContesting = true; } // if $claim_id = 0; break; } // else } else { $claimIsContested = false; } // else } // for } // if } // else // if current nation claims successfully if ($claim_id == $ref_nation) { $returnClaimInfo = 1; // if enemy nation claims successfully } else { if ($claim_id != $ref_nation && $claim_id >= 1) { $returnClaimInfo = 2; // if claim is contested and player is involved } else { if ($claimIsContested === true && $playerContesting === true) { $returnClaimInfo = 3; // if claim is contested and player is not involved } else { if ($claimIsContested === true && $playerContesting === false) { $returnClaimInfo = 4; // default to enemy claim } else { $returnClaimInfo = 0; } } } } // else } else { $returnClaimInfo = 0; } // else return $returnClaimInfo; }
function addClaimInfo($s_connection, $s_strength, $s_owner, $s_tile) { if ($stmt = $s_connection->prepare("INSERT INTO claims (strength,owner) VALUES (?,?)")) { $stmt->bind_param("di", $s_strength, $s_owner); $stmt->execute(); $stmt->close(); } else { } // else $new_id = $s_connection->insert_id; $claimInfoDD = getClaimInfo($s_connection, $new_id); $tileInfoDD = getTileInfoByID($s_connection, $s_tile); $new_claims = $tileInfoDD["claims"]; $new_index = count($new_claims) + 1; $new_claims[$new_index] = $claimInfoDD["id"]; setTileInfo($s_connection, $tileInfoDD["id"], $tileInfoDD["continent"], $tileInfoDD["xpos"], $tileInfoDD["ypos"], $tileInfoDD["terrain"], $tileInfoDD["resources"], $tileInfoDD["improvements"], $tileInfoDD["owner"], $new_claims, $tileInfoDD["population"]); }
function showMapInfo($getPage_connection2) { echo " <div class=\"well well-lg info_well row\">\n"; // Command Module $unitInfo = getUnitInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]); echo " <div class=\"col-sm-4 info_panels\">\n"; echo " <div class=\"panel panel-danger\">\n"; echo " <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Command your units on the present tile.\" class=\"panel-heading\">\n"; echo " <h3 class=\"panel-title\">Command <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseCommand\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n"; echo " </div>\n"; echo " <div id=\"collapseCommand\" class=\"panel-body standard-text collapse in\">\n"; if ($unitInfo["id"] >= 1) { $unitTypeInfo = getUnitTypeInfo($getPage_connection2, $unitInfo["type"]); $currentPlayer = false; $nationInfoX = getNationInfo($getPage_connection2, $unitInfo["owner"]); if ($unitInfo["owner"] == $_SESSION["nation_id"]) { $currentPlayer = true; } // if echo " <ul class=\"list-group\">\n"; echo " <li class=\"list-group-item\">\n"; echo " " . $unitInfo["name"] . "\n"; echo " <br />\n"; echo " " . $unitTypeInfo["name"] . "\n"; echo " <br />\n"; echo " " . $unitInfo["health"] . " / " . $unitTypeInfo["health"] . " HP\n"; echo " <br />\n"; echo " Moves: " . ($unitTypeInfo["movement"] - $unitInfo["used"]) . " / " . $unitTypeInfo["movement"] . "\n"; echo " <br />\n"; echo " Level " . $unitInfo["level"] . "\n"; echo " <br />\n"; echo " Experience: " . $unitInfo["exp"] . "\n"; echo " <br />\n"; echo " Owned by <a href=\"index.php?page=info&section=nations&info_id=" . $nationInfoX["id"] . "\">" . $nationInfoX["name"] . "</a>\n"; echo " </li>\n"; if ($currentPlayer === true) { echo " <li class=\"list-group-item\">\n"; echo " <div class=\"row\">\n"; echo " Modify/Abilities\n <br />\n <br />\n"; echo " </div>\n"; echo " <div class=\"row\">\n"; if ($unitInfo["level"] < 20) { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-upgrade\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Upgrade unit. Cost: " . $unitTypeInfo["baseCost"] * ($unitInfo["level"] + 1) . "\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_upgrade.png\" alt=\"Upgrade\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-remove\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Remove unit.\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_remove.png\" alt=\"Remove\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; echo " <div class=\"col-xs-3\">\n\n"; echo " <span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Rename unit.\">\n"; $rand_modal = mt_rand(1, 100); echo " <button type=\"button\" data-toggle=\"modal\" data-target=\"#renameUnitModal" . $rand_modal . "\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_rename.png\" alt=\"Rename\" /></button>\n\n"; echo " <!-- Modal -->\n"; echo " <div id=\"renameUnitModal" . $rand_modal . "\" class=\"modal fade\" role=\"dialog\">\n"; echo " <div class=\"modal-dialog\">\n"; echo " <!-- Modal content-->\n"; echo " <div class=\"modal-content\">\n"; echo " <div class=\"modal-header\">\n"; echo " <button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button>\n"; echo " <h4 class=\"modal-title\">Rename Unit</h4>\n"; echo " </div>\n"; echo " <div class=\"modal-body\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " \t <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-rename\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <div class=\"form-group form-group-sm\">\n"; echo " <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Your unit's new name.\" name=\"rename\" type=\"text\" class=\"form-control\" id=\"rename_unit\" placeholder=\"Bravo Regiment\" />\n"; echo " </div>\n"; echo " <div class=\"form-group form-group-sm\">\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Rename unit.\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-md\">Rename</button>\n"; echo " </div>\n"; echo " </form>\n"; echo " </div>\n"; echo " <div class=\"modal-footer\">\n"; echo " <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n"; echo " </div>\n"; echo " </div>\n"; echo " </div>\n"; echo " </div>\n\n"; echo " </span>\n"; echo " </div>\n"; echo " </div>\n"; echo " </li>\n"; } // if $directionsX = array(0 => -1, 1 => 0, 2 => 1, 3 => -1, 4 => 0, 5 => 1, 6 => -1, 7 => 0, 8 => 1); $directionsY = array(0 => -1, 1 => -1, 2 => -1, 3 => 0, 4 => 0, 5 => 0, 6 => 1, 7 => 1, 8 => 1); $directionsName = array(0 => "Northwest", 1 => "North", 2 => "Northeast", 3 => "West", 4 => "Hold", 5 => "East", 6 => "Southwest", 7 => "South", 8 => "Southeast"); // unloading if ($currentPlayer === true) { $notTransport = false; $notUnload = false; // land units: can't move out of continent if ($unitInfo["transport"] >= 1) { $transportInfo = getTransportInfo($getPage_connection2, $unitInfo["transport"]); if ($transportInfo["id"] >= 1) { if (count($transportInfo["list"]) >= 2) { $unitInfoI = getUnitInfoByID($getPage_connection2, $transportInfo["list"][1]); echo " <li class=\"list-group-item\">\n"; echo " <div class=\"row\">\n"; $carrying = count($transportInfo["list"]) - 1; echo " Carrying " . $carrying . " of 4\n <br />\n <br />\n"; echo " Unload unit " . $unitInfoI["name"] . ": \n <br />\n <br />\n"; } else { $notUnload = true; } // else } else { $notTransport = true; } // else } else { $notTransport = true; } // else // if the unit is transport, if ($notTransport === false) { // if units can be unloaded if ($notUnload === false) { $unitTypeInfoI = getUnitTypeInfo($getPage_connection2, $unitInfoI["type"]); if ($unitInfoI["used"] < $unitTypeInfoI["movement"]) { for ($hh = 0; $hh < count($directionsX); $hh++) { $newcontinent = $_SESSION["continent_id"]; $newxpos = $_SESSION["xpos"] + $directionsX[$hh]; $newypos = $_SESSION["ypos"] + $directionsY[$hh]; $tileInfoQ = getTileInfo($getPage_connection2, $newcontinent, $newxpos, $newypos); $grey = false; $unload = false; if ($tileInfoQ["terrain"] == 2) { $unload = false; } else { $unload = true; } // else if ($unload === true) { if ($directionsName[$hh] == "Northwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "North") { if ($_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Northeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "West") { if ($_SESSION["xpos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Hold") { $grey = true; } else { if ($directionsName[$hh] == "East") { if ($_SESSION["xpos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "South") { if ($_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { $grey = true; } } } } } } } } } // else } else { $grey = true; } // else if ($hh == 0) { echo " <div class=\"row\">\n"; } else { if ($hh == 3 || $hh == 6) { echo " </div>\n <div class=\"row\">\n"; } } // else if if ($grey === true) { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <button disabled value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_greyed.png\" alt=\"\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; } else { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-unload\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <input type=\"hidden\" name=\"newcontinent\" value=\"" . $newcontinent . "\" />\n"; echo " <input type=\"hidden\" name=\"newxpos\" value=\"" . $newxpos . "\" />\n"; echo " <input type=\"hidden\" name=\"newypos\" value=\"" . $newypos . "\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Unload unit.\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_unload_" . strtolower($directionsName[$hh]) . ".png\" alt=\"" . $directionsName[$hh] . " Unload\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; } // else if ($hh == 8) { echo " </div>\n"; } // if } // for } else { echo " Unit can move no further this turn.\n"; echo " </div>\n"; } // else } // if echo " </li>\n"; } // if } // if // transport/move if ($currentPlayer === true) { echo " <li class=\"list-group-item\">\n"; echo " <div class=\"row\">\n"; echo " Move\n <br />\n <br />\n"; echo " </div>\n"; if ($unitInfo["used"] < $unitTypeInfo["movement"]) { // land units if ($unitTypeInfo["water"] == 0) { for ($hh = 0; $hh < count($directionsX); $hh++) { $newcontinent = $_SESSION["continent_id"]; $newxpos = $_SESSION["xpos"] + $directionsX[$hh]; $newypos = $_SESSION["ypos"] + $directionsY[$hh]; $tileInfoQ = getTileInfo($getPage_connection2, $newcontinent, $newxpos, $newypos); $grey = false; $load = false; $transport = false; $verb = "move"; if ($tileInfoQ["terrain"] == 2) { $load = true; } else { $load = false; } // else if ($load === true) { $transport = false; $unitInfoTemp1 = getUnitInfo($getPage_connection2, $newcontinent, $newxpos, $newypos); if ($unitInfoTemp1["id"] >= 1) { if ($unitInfoTemp1["type"] == 10 && $unitInfoTemp1["owner"] == $_SESSION["nation_id"]) { if ($unitInfoTemp1["transport"] >= 1) { $transportInfoTemp1 = getTransportInfo($getPage_connection2, $unitInfoTemp1["transport"]); if ($transportInfoTemp1["id"] >= 1) { if (count($transportInfoTemp1["list"]) >= 1 && count($transportInfoTemp1["list"]) < 5) { $transport = true; } else { $transport = false; } // else } else { $transport = false; } // else } else { $transport = false; } // else } else { $transport = false; } // else } else { $transport = false; } // else if ($transport === true) { if ($directionsName[$hh] == "Northwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] > 1) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "North") { if ($_SESSION["ypos"] > 1) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Northeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] > 1) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "West") { if ($_SESSION["xpos"] > 1) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Hold") { $grey = true; } else { if ($directionsName[$hh] == "East") { if ($_SESSION["xpos"] < 20) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] < 20) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "South") { if ($_SESSION["ypos"] < 20) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] < 20) { $grey = false; $verb = "transport"; } else { $grey = true; } // else } else { $grey = true; } } } } } } } } } // else } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Northwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "North") { if ($_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Northeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "West") { if ($_SESSION["xpos"] > 1) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Hold") { $grey = true; } else { if ($directionsName[$hh] == "East") { if ($_SESSION["xpos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "South") { if ($_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { if ($directionsName[$hh] == "Southeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] < 20) { $grey = false; } else { $grey = true; } // else } else { $grey = true; } } } } } } } } } // else } // else if ($hh == 0) { echo " <div class=\"row\">\n"; } else { if ($hh == 3 || $hh == 6) { echo " </div>\n <div class=\"row\">\n"; } } // else if if ($grey === true) { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <button disabled value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_greyed.png\" alt=\"\" /></button>\n"; echo " </form>\n"; echo " </div>\n\n"; } else { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-" . $verb . "\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <input type=\"hidden\" name=\"newcontinent\" value=\"" . $newcontinent . "\" />\n"; echo " <input type=\"hidden\" name=\"newxpos\" value=\"" . $newxpos . "\" />\n"; echo " <input type=\"hidden\" name=\"newypos\" value=\"" . $newypos . "\" />\n"; if ($verb == "transport") { echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Transport " . $directionsName[$hh] . ".\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_unload_" . strtolower($directionsName[$hh]) . ".png\" alt=\"" . $directionsName[$hh] . " Transport\" /></button>\n"; } else { echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Move " . $directionsName[$hh] . ".\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_" . strtolower($directionsName[$hh]) . ".png\" alt=\"" . $directionsName[$hh] . " Move\" /></button>\n"; } // else echo " </form>\n"; echo " </div>\n"; } // else if ($hh == 8) { echo " </div>\n\n"; } // if } // for // water units } else { for ($hh = 0; $hh < count($directionsX); $hh++) { $newcontinent = $_SESSION["continent_id"]; $newxpos = $_SESSION["xpos"] + $directionsX[$hh]; $newypos = $_SESSION["ypos"] + $directionsY[$hh]; $tileInfoQ = getTileInfo($getPage_connection2, $newcontinent, $newxpos, $newypos); $grey = false; $isWater = false; $coastBool = isItCoast($getPage_connection2, $tileInfoQ); if ($coastBool === true) { $coastCheck = true; } else { $coastCheck = false; } // else if ($tileInfoQ["terrain"] == 2) { $isWater = true; } else { $isWater = false; } // else if ($isWater === true || $coastCheck === true) { if ($directionsName[$hh] == "Northwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] > 1) { $grey = false; } else { if ($_SESSION["continent_id"] >= 2) { $newcontinent = $_SESSION["continent_id"] - 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "North") { if ($_SESSION["ypos"] > 1) { $grey = false; } else { if ($_SESSION["continent_id"] >= 2) { $newcontinent = $_SESSION["continent_id"] - 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "Northeast") { if ($_SESSION["xpos"] < 20 && $_SESSION["ypos"] > 1) { $grey = false; } else { $nextContinent = getContinentInfo($getPage_connection2, $_SESSION["continent_id"] + 1); if ($nextContinent["id"] >= 1) { $newcontinent = $_SESSION["continent_id"] + 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "West") { if ($_SESSION["xpos"] > 1) { $grey = false; } else { if ($_SESSION["continent_id"] >= 2) { $newcontinent = $_SESSION["continent_id"] - 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "Hold") { $grey = true; } else { if ($directionsName[$hh] == "East") { if ($_SESSION["xpos"] > 20) { $grey = false; } else { $nextContinent = getContinentInfo($getPage_connection2, $_SESSION["continent_id"] + 1); if ($nextContinent["id"] >= 1) { $newcontinent = $_SESSION["continent_id"] + 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "Southwest") { if ($_SESSION["xpos"] > 1 && $_SESSION["ypos"] < 20) { $grey = false; } else { if ($_SESSION["continent_id"] >= 2) { $newcontinent = $_SESSION["continent_id"] - 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "South") { if ($_SESSION["xpos"] > 20) { $grey = false; } else { $nextContinent = getContinentInfo($getPage_connection2, $_SESSION["continent_id"] + 1); if ($nextContinent["id"] >= 1) { $newcontinent = $_SESSION["continent_id"] + 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { if ($directionsName[$hh] == "Southeast") { if ($_SESSION["xpos"] > 20 && $_SESSION["ypos"] < 20) { $grey = false; } else { $nextContinent = getContinentInfo($getPage_connection2, $_SESSION["continent_id"] + 1); if ($nextContinent["id"] >= 1) { $newcontinent = $_SESSION["continent_id"] + 1; } else { $newcontinent = $_SESSION["continent_id"]; } // else $grey = false; } // else } else { $grey = true; } } } } } } } } } // else } else { $grey = true; } // else if ($hh == 0) { echo " <div class=\"row\">\n"; } else { if ($hh == 3 || $hh == 6) { echo " </div>\n <div class=\"row\">\n"; } } // else if if ($grey === true) { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <button disabled value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_greyed.png\" alt=\"\" /></button>\n"; echo " </form>\n"; echo " </div>\n\n"; } else { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-move\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <input type=\"hidden\" name=\"newcontinent\" value=\"" . $newcontinent . "\" />\n"; echo " <input type=\"hidden\" name=\"newxpos\" value=\"" . $newxpos . "\" />\n"; echo " <input type=\"hidden\" name=\"newypos\" value=\"" . $newypos . "\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Move " . $directionsName[$hh] . ".\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_" . strtolower($directionsName[$hh]) . ".png\" alt=\"" . $directionsName[$hh] . " Move\" /></button>\n"; echo " </form>\n"; echo " </div>\n\n"; } // else if ($hh == 8) { echo " </div>\n\n"; } // if } // for } // else } else { echo " Unit can move no further this turn.\n"; } // else echo " </li>\n"; echo " </ul>\n"; } // if } // if echo " </div>\n"; echo " </div>\n"; echo " </div><!-- /.col-sm-4 -->\n\n"; // Improve Module echo " <div class=\"col-sm-4 info_panels\">\n"; echo " <div class=\"panel panel-success\">\n"; echo " <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Add and modify your improvements on the present tile.\" class=\"panel-heading\">\n"; echo " <h3 class=\"panel-title\">Improve <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseImprove\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n"; echo " </div>\n"; echo " <div id=\"collapseImprove\" class=\"panel-body standard-text collapse in\">\n"; for ($q = 0; $q < count($_SESSION["tileInfo"]["improvements"]); $q++) { $improvementInfo = getImprovementInfo($getPage_connection2, $_SESSION["tileInfo"]["improvements"][$q]); if ($improvementInfo["id"] >= 1) { echo " <ul class=\"list-group\">\n"; $improvementTypeInfo = getImprovementTypeInfo($getPage_connection2, $improvementInfo["type"]); $currentPlayer = false; echo " <li class=\"list-group-item\">\n"; echo " " . $improvementInfo["name"] . "\n"; echo " <br />\n"; echo " " . $improvementTypeInfo["name"] . "\n"; echo " <br />\n"; echo " Level " . $improvementInfo["level"] . "\n"; echo " <br />\n"; if ($improvementInfo["usingResources"][0] > 0) { echo " Using Resources: "; for ($u = 0; $u < count($improvementInfo["usingResources"]); $u++) { if ($improvementInfo["usingResources"][$u] > 0) { if ($u > 0) { echo ", "; } // if $resourceInfoQ = getResourceInfo($getPage_connection2, $improvementInfo["usingResources"][$u]); $resourceTypeInfoQ = getResourceTypeInfo($getPage_connection2, $resourceInfoQ["type"]); echo $resourceTypeInfoQ["name"]; } // if } // for } // if echo "\n <br />\n"; echo " Owned by "; for ($z = 0; $z < count($improvementInfo["owners"]); $z++) { $nationInfoY = getNationInfo($getPage_connection2, $improvementInfo["owners"][$z]); if ($z >= 1) { echo ", <a href=\"index.php?page=info&section=nations&info_id=" . $nationInfoY["id"] . "\">" . $nationInfoY["name"] . "</a>"; } else { echo "<a href=\"index.php?page=info&section=nations&info_id=" . $nationInfoY["id"] . "\">" . $nationInfoY["name"] . "</a>"; } // else if ($improvementInfo["owners"][$z] == $_SESSION["nation_id"]) { $currentPlayer = true; } // if } // for echo "\n </li>\n"; if ($currentPlayer === true) { echo " <li class=\"list-group-item\">\n"; echo " <div class=\"row\">\n"; echo " Modify/Abilities\n <br />\n <br />\n"; echo " </div>\n"; echo " <div class=\"row\">\n"; if ($improvementInfo["level"] < 20) { echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=terrain\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $improvementInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-upgrade\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"control\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Upgrade improvement. Cost: " . $improvementTypeInfo["baseCost"] * ($improvementInfo["level"] + 1) . "\"\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_upgrade.png\" alt=\"Upgrade\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=terrain\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $improvementInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-remove\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"control\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Remove improvement.\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_remove.png\" alt=\"Remove\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; echo " <div class=\"col-xs-3\">\n\n"; echo " <span data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Rename improvement.\">\n"; $rand_modal = mt_rand(1, 100); echo " <button type=\"button\" data-toggle=\"modal\" data-target=\"#renameImprovementModal" . $rand_modal . "\" class=\"btn btn-primary btn-sm\"><img src=\"images/buttons/btn_rename.png\" alt=\"Rename\" /></button>\n\n"; echo " <!-- Modal -->\n"; echo " <div id=\"renameImprovementModal" . $rand_modal . "\" class=\"modal fade\" role=\"dialog\">\n"; echo " <div class=\"modal-dialog\">\n"; echo " <!-- Modal content-->\n"; echo " <div class=\"modal-content\">\n"; echo " <div class=\"modal-header\">\n"; echo " <button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button>\n"; echo " <h4 class=\"modal-title\">Rename Improvement</h4>\n"; echo " </div>\n"; echo " <div class=\"modal-body\">\n"; echo " <form action=\"index.php?page=map&overlay=control\" method=\"post\">\n"; echo " \t <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $improvementInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-rename\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"control\" />\n"; echo " <div class=\"form-group form-group-sm\">\n"; echo " <input data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Your improvement's new name.\" name=\"rename\" type=\"text\" class=\"form-control\" id=\"rename_improvement\" placeholder=\"Moscow\" />\n"; echo " </div>\n"; echo " <div class=\"form-group form-group-sm\">\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Rename improvement.\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-md\">Rename</button>\n"; echo " </div>\n"; echo " </form>\n"; echo " </div>\n"; echo " <div class=\"modal-footer\">\n"; echo " <button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">Close</button>\n"; echo " </div>\n"; echo " </div>\n"; echo " </div>\n"; echo " </div>\n\n"; echo " </span>\n"; echo " </div>\n"; echo " </div>\n"; echo " </li>\n"; // if it is a depot, allow construction of military units if ($improvementInfo["type"] == 5) { echo " <li class=\"list-group-item\">\n"; echo " <div class=\"row\">\n"; echo " Train\n <br />\n <br />\n"; echo " </div>\n"; $nationInfoZ = getNationInfo($getPage_connection2, $_SESSION["nation_id"]); $wrapCounter = 0; if ($stmt = $getPage_connection2->prepare("SELECT id FROM units ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_unitTypes = $r_result; $unitTypeInfo = getUnitTypeInfo($getPage_connection2, $next_unitTypes); if ($unitTypeInfo["water"] == 1) { $coastBool = isItCoast($getPage_connection2, $_SESSION["tileInfo"]); if ($coastBool === true) { $coastCheck = true; } else { $coastCheck = false; } // else } else { $coastCheck = true; } // else if ($coastCheck === true) { if ($unitTypeInfo["baseCost"] <= $nationInfoZ["money"]) { $notEnough = false; for ($zz = 0; $zz < count($unitTypeInfo["goodsRequired"]); $zz++) { if ($unitTypeInfo["goodsRequired"][$zz] > $nationInfoZ["goods"][$zz]) { $notEnough = true; break; } // if } // for if ($notEnough === false) { $wrapCounter++; if ($wrapCounter == 1) { echo " <div class=\"row\">\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $unitTypeInfo["id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"unit-build\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Train " . $unitTypeInfo["name"] . ". Cost: " . round($unitTypeInfo["baseCost"], 2, PHP_ROUND_HALF_UP) . "\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"" . $unitTypeInfo["image"] . "\" alt=\"Train " . $unitTypeInfo["name"] . "\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; if ($wrapCounter == 3) { $wrapCounter = 0; echo " </div>\n"; } // if } // if } // if } // if if ($next_unitTypes < 1 && $wrapCounter != 0) { echo " </div>\n"; } // if } // while $stmt->close(); } else { } // else echo " </li>\n"; } // if } // if echo " </ul>\n"; } // if } // for $currentPlayer = false; if ($_SESSION["tileInfo"]["owner"] == $_SESSION["nation_id"]) { $currentPlayer = true; } // if if ($currentPlayer === true) { echo " <ul class=\"list-group\">\n"; echo " <li class=\"list-group-item\">\n"; echo " Build\n <br />\n <br />\n"; $availableResources = array(0 => 0); $counter = 1; // loop tile's resources for ($q = 0; $q < count($_SESSION["tileInfo"]["resources"]); $q++) { $resourceIsUsed = false; $resourceInfo = getResourceInfo($getPage_connection2, $_SESSION["tileInfo"]["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($_SESSION["tileInfo"]["improvements"]); $a++) { $improvementInfo = getImprovementInfo($getPage_connection2, $_SESSION["tileInfo"]["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 // loop improvement types $wrapCounter = 0; if ($stmt = $getPage_connection2->prepare("SELECT id FROM improvements ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_improvementTypes = $r_result; $improvementTypeInfo1 = getImprovementTypeInfo($getPage_connection2, $next_improvementTypes); $addToCounter = false; $terrainIsValid = false; // loop terrain requirements for ($b = 0; $b < count($improvementTypeInfo1["terrainTypeRequired"]); $b++) { // if tile terrain type is valid, check if ($improvementTypeInfo1["terrainTypeRequired"][$b] == $_SESSION["tileInfo"]["terrain"]) { $terrainIsValid = true; break; } else { $terrainIsValid = false; } // else } // for // if terrain is valid, check for resource requirements if ($terrainIsValid === true) { // if no requirements just post it, otherwise proceed to loop if ($improvementTypeInfo1["resourcesRequired"][0] == 0) { if (count($_SESSION["tileInfo"]["improvements"]) < 5) { // capital: only 1 can be built, check for home continent, if one is set then capital exists if ($improvementTypeInfo1["id"] == 1) { $nationInfoC = getNationInfo($getPage_connection2, $_SESSION["nation_id"]); if ($nationInfoC["home"] == 0) { $wrapCounter++; if ($wrapCounter == 1) { echo " <div class=\"row\">\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $next_improvementTypes . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-build\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Build " . $improvementTypeInfo1["name"] . ". Cost: " . round($improvementTypeInfo1["baseCost"], 2, PHP_ROUND_HALF_UP) . "\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"" . $improvementTypeInfo1["image"] . "\" alt=\"Build " . $improvementTypeInfo1["name"] . "\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; if ($wrapCounter == 3) { $wrapCounter = 0; echo " </div>\n"; } // if } // if } else { $wrapCounter++; if ($wrapCounter == 1) { echo " <div class=\"row\">\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $next_improvementTypes . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-build\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Build " . $improvementTypeInfo1["name"] . ". Cost: " . round($improvementTypeInfo1["baseCost"], 2, PHP_ROUND_HALF_UP) . "\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"" . $improvementTypeInfo1["image"] . "\" alt=\"Build " . $improvementTypeInfo1["name"] . "\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; if ($wrapCounter == 3) { $wrapCounter = 0; echo " </div>\n"; } // if } // else } // if } else { $checkResource = array(0 => false); // loop resource requirements for ($t = 0; $t < count($improvementTypeInfo1["resourcesRequired"]); $t++) { // loop available resources for ($z = 0; $z < count($availableResources); $z++) { // if tile terrain type is valid, check if ($improvementTypeInfo1["resourcesRequired"][$t] == $availableResources[$z]["type"]) { $checkResource[$t] = true; break; } else { } // else } // for } // for $illegal = false; for ($a = 0; $a < count($improvementTypeInfo1["resourcesRequired"]); $a++) { if (isset($checkResource[$a])) { if ($checkResource[$a] === false) { $illegal = true; break; } // if } else { $illegal = true; break; } // else } // for if ($illegal === false) { if (count($_SESSION["tileInfo"]["improvements"]) < 5) { $wrapCounter++; if ($wrapCounter == 1) { echo " <div class=\"row\">\n"; } // if echo " <div class=\"col-xs-3\">\n"; echo " <form action=\"index.php?page=map&overlay=units\" method=\"post\">\n"; echo " <input type=\"hidden\" name=\"continent\" value=\"" . $_SESSION["continent_id"] . "\" />\n"; echo " <input type=\"hidden\" name=\"xpos\" value=\"" . $_SESSION["xpos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"ypos\" value=\"" . $_SESSION["ypos"] . "\" />\n"; echo " <input type=\"hidden\" name=\"actionid\" value=\"" . $next_improvementTypes . "\" />\n"; echo " <input type=\"hidden\" name=\"action\" value=\"improvement-build\" />\n"; echo " <input type=\"hidden\" name=\"overlay\" value=\"units\" />\n"; echo " <button onclick=\"loadButton(this)\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Build " . $improvementTypeInfo1["name"] . ". Cost: " . round($improvementTypeInfo1["baseCost"], 2, PHP_ROUND_HALF_UP) . "\" value=\"map\" name=\"page\" type=\"submit\" class=\"btn btn-primary btn-sm\"><img src=\"" . $improvementTypeInfo1["image"] . "\" alt=\"Build " . $improvementTypeInfo1["name"] . "\" /></button>\n"; echo " </form>\n"; echo " </div>\n"; if ($wrapCounter == 3) { $wrapCounter = 0; echo " </div>\n"; } // if } // if } // if } // else } // if if ($next_improvementTypes < 1 && $wrapCounter != 0) { echo " </div>\n"; } // if } // while $stmt->close(); } else { } // else echo " </li>\n"; echo " </ul>\n"; } // if echo " </div>\n"; echo " </div>\n"; echo " </div><!-- /.col-sm-4 -->\n\n"; // Info Module echo " <div class=\"col-sm-4 info_panels\">\n"; echo " <div class=\"panel panel-info\">\n"; echo " <div data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Check out more information about the present tile.\" class=\"panel-heading\">\n"; echo " <h3 class=\"panel-title\">Info <button type=\"button\" class=\"btn btn-default btn-md collapsed\" data-toggle=\"collapse\" data-target=\"#collapseInfo\"><span class=\"glyphicon glyphicon-plus\"></span>/<span class=\"glyphicon glyphicon-minus\"></span></button></h3>\n"; echo " </div>\n"; echo " <div id=\"collapseInfo\" class=\"panel-body standard-text collapse in\">\n"; $nationInfoN = getNationInfo($getPage_connection2, $_SESSION["tileInfo"]["owner"]); echo " <ul class=\"list-group\">\n"; echo " <li class=\"list-group-item\">\n"; echo " Continent: " . $_SESSION["continent_id"] . "\n"; echo " </li>\n"; echo " <li class=\"list-group-item\">\n"; echo " Position: " . $_SESSION["xpos"] . ", " . $_SESSION["ypos"] . "\n"; echo " </li>\n"; echo " <li class=\"list-group-item\">\n"; echo " Population: " . $_SESSION["tileInfo"]["population"] . "\n"; echo " </li>\n"; echo " <li class=\"list-group-item\">\n"; echo " Improvement Slots: " . (count($_SESSION["tileInfo"]["improvements"]) - 1) . " / 4\n"; echo " </li>\n"; echo " <li class=\"list-group-item\">\n"; if (isset($nationInfoN["name"])) { if (strlen($nationInfoN["name"]) >= 1) { echo " Owner: <a href=\"index.php?page=info&section=nations&info_id=" . $nationInfoN["id"] . "\">" . $nationInfoN["name"] . "</a>\n"; } else { echo " Owner: None\n"; } // else } else { echo " Owner: None\n"; } // else echo " </li>\n"; echo " </ul>\n"; echo " <ul class=\"list-group\">\n"; $hasResourceInfo = false; for ($q = 0; $q < count($_SESSION["tileInfo"]["resources"]); $q++) { $resourceInfo = getResourceInfo($getPage_connection2, $_SESSION["tileInfo"]["resources"][$q]); if ($resourceInfo["id"] >= 1) { if ($hasResourceInfo === false) { echo " Resources:\n"; $hasResourceInfo = true; } // if $resourceTypeInfo = getResourceTypeInfo($getPage_connection2, $resourceInfo["type"]); echo " <li class=\"list-group-item\">\n"; echo " " . $resourceTypeInfo["name"] . ", Capacity: " . $resourceInfo["capacity"] . "\n"; echo " </li>\n"; } // if } // for echo " </ul>\n"; echo " <ul class=\"list-group\">\n"; $hasClaimInfo = false; for ($q = 0; $q < count($_SESSION["tileInfo"]["claims"]); $q++) { $claimInfoV = getClaimInfo($getPage_connection2, $_SESSION["tileInfo"]["claims"][$q]); if ($claimInfoV["id"] >= 1) { if ($hasClaimInfo === false) { echo " Claims:\n"; $hasClaimInfo = true; } // if $nationInfoV = getNationInfo($getPage_connection2, $claimInfoV["owner"]); echo " <li class=\"list-group-item\">\n"; echo " " . $nationInfoV["name"] . " Claim: " . $claimInfoV["strength"] . "\n"; echo " </li>\n"; } // if } // for echo " </ul>\n"; echo " <ul class=\"list-group\">\n"; $hasImprovementInfo = false; for ($q = 0; $q < count($_SESSION["tileInfo"]["improvements"]); $q++) { $improvementInfoH = getImprovementInfo($getPage_connection2, $_SESSION["tileInfo"]["improvements"][$q]); if ($improvementInfoH["id"] >= 1) { if ($hasImprovementInfo === false) { echo " Improvements:\n"; $hasImprovementInfo = true; } // if $improvementTypeInfoH = getImprovementTypeInfo($getPage_connection2, $improvementInfoH["type"]); echo " <li class=\"list-group-item\">\n"; echo " " . $improvementTypeInfoH["name"] . ", Level: " . $improvementInfoH["level"] . "\n"; echo " </li>\n"; } // if } // for echo " </ul>\n"; echo " </div>\n"; echo " </div>\n"; echo " </div><!-- /.col-sm-4 -->\n"; echo " </div>\n"; echo " </div>\n"; }
function updateNations($getPage_connection2) { // main player sequence $_SESSION["scriptOutput"] = "<br /><br />Running main sequence...<br />"; if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) { $stmt->execute(); $stmt->store_result(); $stmt->bind_result($r_result); while ($stmt->fetch()) { $next_nations = $r_result; $_SESSION["scriptOutput"] .= "<br />Setup nation...<br />"; $nationInfoW = getNationInfo($getPage_connection2, $next_nations); $tradeInfoW = getTradeInfo($getPage_connection2, $next_nations); $formula = 0.0; $tax = 0.0; $new_production = 0; $new_money = $nationInfoW["money"]; $new_food = $nationInfoW["food"]; $new_happiness = 0.0; $new_goods = $nationInfoW["goods"]; $new_resources = $nationInfoW["resources"]; $new_limit = $tradeInfoW["limit"]; $new_routes = array(0 => 0); $new_worth = array(0 => 0); $old_population = $nationInfoW["population"]; $new_population = 0.0; $foreignTradePercent = 0.0; $productionPercent = 0.0; $efficiencyPercent = 0.0; $happinessPenalty = 0.0; $money_upkeep = 0.0; $food_upkeep = 0.0; $new_debt = $nationInfoW["debt"]; $money_debt = 0.0; $food_debt = 0.0; $productionPercent = $nationInfoW["economy"] * 10; $foreignTradePercent = 100 - $productionPercent; $efficiencyPercent = $nationInfoW["authority"] * 10; $happinessPenalty = $nationInfoW["authority"] * 5; $productionInfoW = getProductionInfo($getPage_connection2, $next_nations); $using_production = 0.0; $used_production = $using_production; $new_prod = $new_goods; $new_strike = $nationInfoW["strike"]; $new_tilesOwned = 0; $tradeCount = 0; $limit_allTilesOwned = 0; if ($stmt1 = $getPage_connection2->prepare("SELECT COUNT(id) FROM tilesmap WHERE owner=?")) { $stmt1->bind_param("i", $next_nations); $stmt1->execute(); $stmt1->bind_result($r_result); $stmt1->fetch(); $limit_allTilesOwned = $r_result; $stmt1->close(); } else { $endTurnFailed = "failed"; } // else $limit_allImprovements = 0; if ($stmt1 = $getPage_connection2->prepare("SELECT COUNT(id) FROM improvementsmap")) { $stmt1->execute(); $stmt1->bind_result($r_result); $stmt1->fetch(); $limit_allImprovements = $r_result; $stmt1->close(); } else { $endTurnFailed = "failed"; } // else /******************************** Base Additions (including revenue) from improvements, tiles, etc. ********************************/ // get tiles info for production/claims/bonus addition $_SESSION["scriptOutput"] .= "Get tiles info for production/claims/bonus addition...<br />"; if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) { $stmt1->execute(); $stmt1->store_result(); $stmt1->bind_result($r_result); while ($stmt1->fetch()) { $next_tiles = $r_result; $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles); if ($tileInfoW["owner"] == $next_nations) { // add claim strength if claim is dominant and tile is controlled $claimsStateW = checkClaimsState($getPage_connection2, $tileInfoW, $next_nations); if ($claimsStateW == 1) { for ($e = 0; $e < count($tileInfoW["claims"]); $e++) { $claimInfoW = getClaimInfo($getPage_connection2, $tileInfoW["claims"][$e]); if ($claimInfoW["owner"] == $next_nations) { if ($claimInfoW["strength"] > 0) { $bonus_new_strength = 0; for ($c = 0; $c < count($tileInfoW["improvements"]); $c++) { $improvementInfoV = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$c]); if ($improvementInfoV["type"] == 1) { $bonus_new_strength = 3; } // if } // for $new_strength = $bonus_new_strength + $claimInfoW["strength"] + 2; } // if setClaimInfo($getPage_connection2, $claimInfoW["id"], $new_strength, $claimInfoW["owner"]); } // if } // for } // if // trade $_SESSION["scriptOutput"] .= "Trade Count adjust...<br />"; for ($ss = 0; $ss < count($tileInfoW["improvements"]); $ss++) { $improvementInfoF = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$ss]); if ($improvementInfoF["type"] == 1 || $improvementInfoF["type"] == 2) { for ($cc = 0; $cc < count($improvementInfoF["owners"]); $cc++) { if ($improvementInfoF["owners"] == $next_nations) { if ($improvementInfoF["type"] == 1) { $tradeCount++; } else { if ($improvementInfoF["type"] == 2) { $tradeCount = $tradeCount + 2; } } // else if } // if } // for } // if } // for // claims for happiness $_SESSION["scriptOutput"] .= "Happiness+Claims adjust...<br />"; $claimsStateW = checkClaimsState($getPage_connection2, $tileInfoW, $next_nations); // set happiness addition dependent on claim to tile // if current nation claims successfully if ($claimsStateW == 1) { $new_happiness = $new_happiness + 5; // if enemy nation claims successfully } else { if ($claimsStateW == 2) { $new_happiness = $new_happiness + 1; // if claim is contested and player is involved } else { if ($claimsStateW == 3) { $new_happiness = $new_happiness + 2; // if claim is contested and player is not involved } else { if ($claimsStateW == 4) { // default to enemy claim } else { // bad $new_happiness = $new_happiness + 1; } } } } // else // terrain production modifiers $_SESSION["scriptOutput"] .= "Terrain production modifiers...<br />"; $terrainInfoW = array("productionModifier" => 0); if ($stmt100 = $getPage_connection2->prepare("SELECT productionModifier FROM terrain WHERE id=? LIMIT 1")) { $stmt100->bind_param("i", $tileInfoW["terrain"]); $stmt100->execute(); $stmt100->bind_result($r_productionModifier); $stmt100->fetch(); $terrainInfoW["productionModifier"] = $r_productionModifier; $stmt100->close(); } else { } // else if ($terrainInfoW["productionModifier"] >= 1) { $mod = 0.01; $new_production = $new_production + $terrainInfoW["productionModifier"] * $mod * 2.0; } else { $new_production = $new_production + 2; } // else } // if } // while $stmt1->close(); } else { } // else // add to nation variables based on tile number $new_money = $new_money + 2 * $limit_allTilesOwned; // get improvements $_SESSION["scriptOutput"] .= "Get improvements info for production, money, population mods...<br />"; if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) { $stmt1->execute(); $stmt1->store_result(); $stmt1->bind_result($r_result); while ($stmt1->fetch()) { $next_improvements = $r_result; $improvementInfoW = getImprovementInfo($getPage_connection2, $next_improvements); for ($z = 0; $z < count($improvementInfoW["owners"]); $z++) { if ($improvementInfoW["owners"][$z] == $next_nations) { // capital if ($improvementInfoW["type"] == 1) { $new_money = $new_money + 60.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $new_production = $new_production + 20.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $tileInfoG = getTileInfo($getPage_connection2, $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"]); $generate_population = mt_rand(200.0 * (0.25 * $improvementInfoW["level"]), 800.0 * (0.25 * $improvementInfoW["level"])); $new_tile_population = $tileInfoG["population"] + $generate_population / count($improvementInfoW["owners"]); setTileInfo($getPage_connection2, $tileInfoG["id"], $tileInfoG["continent"], $tileInfoG["xpos"], $tileInfoG["ypos"], $tileInfoG["terrain"], $tileInfoG["resources"], $tileInfoG["improvements"], $tileInfoG["owner"], $tileInfoG["claims"], $new_tile_population); // town } else { if ($improvementInfoW["type"] == 2) { $new_money = $new_money + 30.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $tileInfoG = getTileInfo($getPage_connection2, $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"]); $generate_population = mt_rand(200.0 * (0.25 * $improvementInfoW["level"]), 400.0 * (0.25 * $improvementInfoW["level"])); $new_tile_population = $tileInfoG["population"] + $generate_population / count($improvementInfoW["owners"]); setTileInfo($getPage_connection2, $tileInfoG["id"], $tileInfoG["continent"], $tileInfoG["xpos"], $tileInfoG["ypos"], $tileInfoG["terrain"], $tileInfoG["resources"], $tileInfoG["improvements"], $tileInfoG["owner"], $tileInfoG["claims"], $new_tile_population); // industry } else { if ($improvementInfoW["type"] == 3) { $new_production = $new_production + 20.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); // farm } else { if ($improvementInfoW["type"] == 4) { $generate_food = mt_rand(1000.0 * (0.25 * $improvementInfoW["level"]), 6000.0 * (0.25 * $improvementInfoW["level"])); $new_food = $new_food + $generate_food / count($improvementInfoW["owners"]); // depot } else { if ($improvementInfoW["type"] == 5) { // mill } else { if ($improvementInfoW["type"] == 6) { for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) { $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]); if ($resourceInfoW["type"] == 1 && $resourceInfoW["capacity"] >= 5) { $initialExtract = 0.02 * $resourceInfoW["capacity"]; $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $new_resources[0] = $new_resources[0] + $extractAmount; $new_capacity = $resourceInfoW["capacity"] - $extractAmount; setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity); break; } // if } // for // reserve } else { if ($improvementInfoW["type"] == 7) { $new_happiness = $new_happiness + 0.01 / count($improvementInfoW["owners"]); // mine } else { if ($improvementInfoW["type"] == 8) { for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) { $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]); if ($resourceInfoW["type"] == 2 && $resourceInfoW["capacity"] >= 5) { $initialExtract = 0.02 * $resourceInfoW["capacity"]; $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $new_resources[1] = $new_resources[1] + $extractAmount; $new_capacity = $resourceInfoW["capacity"] - $extractAmount; setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity); break; } // if } // for // well } else { if ($improvementInfoW["type"] == 9) { for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) { $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]); if ($resourceInfoW["type"] == 3 && $resourceInfoW["capacity"] >= 5) { $initialExtract = 0.02 * $resourceInfoW["capacity"]; $extractAmount = $initialExtract * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); $new_resources[2] = $new_resources[2] + $extractAmount; $new_capacity = $resourceInfoW["capacity"] - $extractAmount; setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity); break; } // if } // for // dam } else { if ($improvementInfoW["type"] == 10) { for ($d = 0; $d < count($improvementInfoW["usingResources"]); $d++) { $resourceInfoW = getResourceInfo($getPage_connection2, $improvementInfoW["usingResources"][$d]); if ($resourceInfoW["type"] == 4 && $resourceInfoW["capacity"] >= 5) { $new_production = $new_production + 22.0 * (0.25 * $improvementInfoW["level"]) / count($improvementInfoW["owners"]); setResourceInfo($getPage_connection2, $resourceInfoW["id"], $resourceInfoW["type"], $new_capacity); break; } // if } // for } } } } } } } } } } // else if } // if } // for } // while $stmt1->close(); } else { } // else /******************************** HAPPINESS EFFECTS ********************************/ $_SESSION["scriptOutput"] .= "Change happiness...<br />"; // penalty for lack of consumer goods (basic and luxury), less penalty with more goods // luxury goods provide bigger boost $consumptionPenalty = 3.25 * $limit_allTilesOwned; $goodsPenalty = 0.0; if ($consumptionPenalty >= $new_goods[4] * 3.0E-5 * $limit_allTilesOwned + $new_goods[5] * 5.0E-5 * $limit_allTilesOwned) { $goodsPenalty = $consumptionPenalty - $new_goods[4] * 3.0E-5 * $limit_allTilesOwned + $new_goods[5] * 5.0E-5 * $limit_allTilesOwned; } else { $goodsPenalty = 0.0; } // else // happiness $new_happiness = ($new_happiness - ($happinessPenalty + $goodsPenalty) * $new_happiness / 100) / $limit_allTilesOwned; // set the rate of effect of happiness on production,taxation // Happiest if ($new_happiness >= 4) { $new_production = $new_production + $new_production * 0.25; $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.25; // Very Happy } else { if ($new_happiness >= 3) { $new_production = $new_production + $new_production * 0.1; $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.1; // Happy } else { if ($new_happiness >= 2) { $new_production = $new_production + $new_production * 0.05; $efficiencyPercent = $efficiencyPercent + $efficiencyPercent * 0.05; // Content (nothing happens) } else { if ($new_happiness >= 1) { // Unhappy } else { $new_production = $new_production - $new_production * 0.25; $efficiencyPercent = $efficiencyPercent - $efficiencyPercent * 0.25; } } } } // else /******************************** TRADE ********************************/ $_SESSION["scriptOutput"] .= "Update trade routes, worth, offers...<br />"; // cut off trade routes to the limit that exists and update trade info // this limits trade routes to currently controlled tiles $new_limit = $tradeCount; if (count($tradeInfoW["routes"]) < $new_limit) { for ($r = 0; $r < $new_limit; $r++) { $new_routes[$r] = $tradeInfoW["routes"][$r]; } // for } else { for ($r = 0; $r < count($tradeInfoW["routes"]); $r++) { $new_routes[$r] = $tradeInfoW["routes"][$r]; } // for } // else setTradeInfo($getPage_connection2, $tradeInfoW["id"], $next_nations, $new_routes, $new_limit); // do individual trades action if current nation involved if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) { $stmt1->execute(); $stmt1->store_result(); $stmt1->bind_result($r_result); while ($stmt1->fetch()) { $next_offers = $r_result; $offerInfoW = getOfferInfo($getPage_connection2, $next_offers); if ($offerInfoW["fromNation"] == $next_nations) { if ($offerInfoW["turns"] > $offerInfoW["counter"]) { if ($offerInfoW["status"] == 1) { processOffer($getPage_connection2, $offersInfoW); $new_offer = $offerInfoW["counter"] + 1; // remove if trade offer has expired if ($new_counter > $offerInfoW["turns"]) { deleteOfferInfo($getPage_connection2, $offerInfoW["id"]); } else { setOfferInfo($getPage_connection2, $offerInfoW["id"], $offerInfoW["fromNation"], $offerInfoW["toNation"], $offerInfoW["givingItems"], $offerInfoW["receivingItems"], $offerInfoW["givingQuantities"], $offerInfoW["receivingQuantities"], $offerInfoW["givingTypes"], $offerInfoW["receivingTypes"], $offerInfoW["turns"], $new_counter, $offerInfoW["status"]); } // else } // if } // if } // if } // while $stmt1->close(); } else { } // else // trade agreements $tradeBonus = 0.0; $productionBonus = 0.0; $happinessPenaltyFromTrade = 0.0; for ($v = 0; $v < count($tradeInfoW["routes"]); $v++) { $agreementInfoQ = getAgreementInfo($getPage_connection2, $tradeInfoW["routes"][$v]); if ($agreementInfoQ["fromNation"] == $next_nations) { if ($offerInfoW["status"] == 1) { // receive money/production $worth1 = 0.0; // total worth of trade $nationFrom1 = getNationInfo($getPage_connection2, $agreementInfoQ["fromNation"]); $nationTo1 = getNationInfo($getPage_connection2, $agreementInfoQ["toNation"]); // figure out wealth and production worth $totalWealth = $nationFrom1["money"] + $nationTo1["money"]; $totalProduction = $nationFrom1["production"] + $nationTo1["production"]; // high policy number = protectionism, low policy number = free trade // max 25% bonus from policy for either production or wealth $tradeBonus = $tradeBonus + $totalWealth * (0.01 + 0.025 * (10 - $agreementInfoQ["policy"])) / 2; $productionBonus = $productionBonus + $totalProduction * (0.008 + 0.025 * $agreementInfoQ["policy"]) / 2; // happiness penalty for clashing ideologies if ($agreementInfoQ["policy"] > $nationInfoW["economy"]) { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] > 0 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 1) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.005; } else { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 2 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 3) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.01; } else { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 4 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 5) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.02; } else { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 6 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 7) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.03; } else { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 8 && $agreementInfoQ["policy"] - $nationInfoW["economy"] <= 9) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.04; } else { if ($agreementInfoQ["policy"] - $nationInfoW["economy"] >= 10) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.05; } } } } } } // else if } else { if ($agreementInfoQ["policy"] < $nationInfoW["economy"]) { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] > 0 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 1) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.005; } else { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 2 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 3) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.01; } else { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 4 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 5) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.02; } else { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 6 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 7) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.03; } else { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 8 && $agreementInfoQ["economy"] - $nationInfoW["policy"] <= 9) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.04; } else { if ($agreementInfoQ["economy"] - $nationInfoW["policy"] >= 10) { $happinessPenaltyFromTrade = $happinessPenaltyFromTrade + 0.05; } } } } } } // else if } else { } } $new_counter = $agreementInfoQ["counter"] + 1; // remove if trade agreement has expired if ($new_counter > $agreementInfoQ["turns"]) { deleteAgreementInfo($getPage_connection2, $agreementInfoQ["id"]); } else { setAgreementInfo($getPage_connection2, $agreementInfoQ["id"], $agreementInfoQ["policy"], $agreementInfoQ["turns"], $new_counter, $agreementInfoQ["toNation"], $agreementInfoQ["fromNation"], $agreementInfoQ["status"]); } // else } // if } // if } // for $new_happiness = $new_happiness - $happinessPenaltyFromTrade; $new_production = $new_production + $productionBonus; /******************************** PRODUCTION COSTS ********************************/ $_SESSION["scriptOutput"] .= "Produce stuff...<br />"; // figure out spending percentage $using_production = $new_production * ($productionInfoW["spending"] * 0.01); // set production used to new spending amount $used_production = $using_production; // percentage of expenditure $ratios = $productionInfoW["ratios"]; for ($t = 0; $t < count($ratios); $t++) { $ratio_id = $t + 1; $goodsInfoW = getGoodsInfo($getPage_connection2, $ratio_id); if ($goodsInfoW["id"] >= 1) { $availableProduction = $used_production * ($ratios[$t] * 0.01); // problem with this while loop: it's endless while ($availableProduction > 0) { $canProduce = false; if ($goodsInfoW["productionRequired"] <= $availableProduction) { if ($goodsInfoW["foodRequired"] <= $new_food) { $checkForResourceTypes = true; if (count($goodsInfoW["resourceTypesRequired"]) <= 1) { if ($goodsInfoW["resourceTypesRequired"][0] == 0) { $checkForResourceTypes = false; } // if } // if if ($checkForResourceTypes === true) { for ($h = 0; $h < count($goodsInfoW["resourceTypesRequired"]); $h++) { // if resources are required if ($goodsInfoW["resourceTypesRequired"][$h] >= 1) { $resourceArraySlot1 = $goodsInfoW["resourceTypesRequired"][$h] - 1; if ($new_resources[$resourceArraySlot1] >= $goodsInfoW["resourceQuantitiesRequired"][$h]) { $canProduce = true; } else { $canProduce = false; break; } // else } else { $canProduce = true; } // else } // for } else { $canProduce = true; } // else } else { $canProduce = false; } // else } else { $canProduce = false; } // else if ($canProduce === true) { for ($j = 0; $j < count($goodsInfoW["improvementTypesRequired"]); $j++) { $typeCount = 0; // if improvements are required if ($goodsInfoW["improvementTypesRequired"][$j] >= 1) { if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_improvements2 = $r_result; $improvementInfoY = getImprovementInfo($getPage_connection2, $next_improvements2); if ($improvementInfoY["type"] == $goodsInfoW["improvementTypesRequired"][$j]) { for ($f = 0; $f < count($improvementInfoY["owners"]); $f++) { if ($improvementInfoY["owners"][$f] == $next_nations) { $typeCount++; } // if } // for } // if if ($typeCount >= $goodsInfoW["improvementQuantitiesRequired"][$j]) { $canProduce = true; break; } // if } // while $stmt2->close(); } else { } // else if ($typeCount < $goodsInfoW["improvementQuantitiesRequired"][$j]) { $canProduce = false; break; } // if } // if } // for } // if // able to produce good, proceed if ($canProduce === true) { // subtract from available production, nation's food total, nation's resources totals $availableProduction = $availableProduction - $goodsInfoW["productionRequired"]; $new_food = $new_food - $goodsInfoW["foodRequired"]; if ($checkForResourceTypes === true) { for ($k = 0; $k < count($goodsInfoW["resourceTypesRequired"]); $k++) { // if resources are required if ($goodsInfoW["resourceTypesRequired"][$k] >= 1) { $resourceArraySlot = $goodsInfoW["resourceTypesRequired"][$k] - 1; $new_resources[$resourceArraySlot] = $new_resources[$resourceArraySlot] - $goodsInfoW["resourceQuantitiesRequired"][$k]; } // if } // for } // if // add new good $new_goods[$t] = $new_goods[$t] + 1; } else { break; } // else } // while } // if } // for $new_production = $new_production - $used_production; // tax $tax = $old_population * 0.11 * ($efficiencyPercent * 0.01); // trade and production bonus formula $formula = $productionPercent * 0.01 * ($new_production * 14); $_SESSION["scriptOutput"] .= "prod: " . $new_production . "<br />"; $_SESSION["scriptOutput"] .= "formula: " . $formula . "<br />"; $_SESSION["scriptOutput"] .= "tax: " . $tax . "<br />"; $_SESSION["scriptOutput"] .= "money: " . $new_money . "<br />"; // final money calculation $new_money = $new_money + $formula + $tax; /******************************** COSTS AND UPKEEP ********************************/ $_SESSION["scriptOutput"] .= "Unit upkeep...<br />"; // unit upkeep if ($stmt1 = $getPage_connection2->prepare("SELECT id FROM unitsmap ORDER BY id ASC")) { $stmt1->execute(); $stmt1->store_result(); $stmt1->bind_result($r_result); while ($stmt1->fetch()) { $next_units = $r_result; $unitInfoW = getUnitInfoByID($getPage_connection2, $next_units); if ($unitInfoW["owner"] == $next_nations) { $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $unitInfoW["type"]); $tileInfoW = getTileInfo($getPage_connection2, $unitInfoW["continent"], $unitInfoW["xpos"], $unitInfoW["ypos"]); $terrainInfoW = getTerrainInfo($getPage_connection2, $tileInfoW["terrain"]); // figure out nearest supply depot for supply line distance $best_difference = 9999; $best_continent = 0; if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM improvementsmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_improvements1 = $r_result; $improvementInfoWA = getImprovementInfo($getPage_connection2, $next_improvements1); if ($improvementInfoWA["id"] >= 1) { for ($v = 0; $v < count($improvementInfoWA["owners"]); $v++) { if ($improvementInfoWA["owners"][$v] == $next_nations) { if ($improvementInfoWA["type"] == 5) { $current_difference = 0; if ($improvementInfoWA["continent"] == $unitInfoW["continent"]) { $best_difference = 0; $best_continent = $improvementInfoWA["continent"]; break; } else { if ($improvementInfoWA["continent"] > $unitInfoW["continent"]) { $current_difference = $improvementInfoWA["continent"] - $unitInfoW["continent"]; } else { if ($improvementInfoWA["continent"] < $unitInfoW["continent"]) { $current_difference = $unitInfoW["continent"] - $improvementInfoWA["continent"]; } } } // else if if ($current_difference < $best_difference) { $best_difference = $current_difference; $best_continent = $improvementInfoWA["continent"]; } // if } // if } // if } // for } // if } // while $stmt2->close(); } else { } // else $distance = $best_difference; $distanceModifier = 5 * $distance; if ($terrainInfoW["upkeepModifier"] >= 1) { $mod = 0.01; $food_upkeep = $food_upkeep + $unitTypeInfoW["foodRequired"] / 4 + $unitTypeInfoW["foodRequired"] / 4 * (($terrainInfoW["upkeepModifier"] + $distanceModifier) * $mod); $money_upkeep = $money_upkeep + $unitTypeInfoW["baseCost"] / 4 + $unitTypeInfoW["baseCost"] / 4 * (($terrainInfoW["upkeepModifier"] + $distanceModifier) * $mod); } else { $food_upkeep = $food_upkeep + $unitTypeInfoW["foodRequired"] / 4; $money_upkeep = $money_upkeep + $unitTypeInfoW["baseCost"] / 4; } // else } // if } // while $stmt1->close(); } else { } // else $_SESSION["scriptOutput"] .= "Improvement upkeep...<br />"; // improvement upkeep and nation's population update if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_tiles = $r_result; $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles); $terrainInfoW = getTerrainInfo($getPage_connection2, $tileInfoW["terrain"]); for ($y = 0; $y < count($tileInfoW["improvements"]); $y++) { $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$y]); $improvementTypeInfoW = getImprovementTypeInfo($getPage_connection2, $improvementInfoW["type"]); for ($z = 0; $z < count($improvementInfoW["owners"]); $z++) { if ($improvementInfoW["owners"][$z] == $next_nations) { // figure out distance costs if ($nationInfoW["home"] > $tileInfoW["continent"]) { $distanceModifier = $nationInfoW["home"] - $tileInfoW["continent"]; } else { $distanceModifier = $tileInfoW["continent"] - $nationInfoW["home"]; } $mod = 0.01; $money_upkeep = $money_upkeep + $improvementTypeInfoW["baseCost"] / 4 / count($improvementInfoW["owners"]) + $improvementTypeInfoW["baseCost"] / 4 / count($improvementInfoW["owners"]) * (($distanceModifier + $terrainInfoW["upkeepModifier"]) * $mod); } // if } // for } // for if ($tileInfoW["owner"] == $next_nations) { $new_population = $new_population + $tileInfoW["population"]; } // if } // while $stmt2->close(); } else { } // else /******************************** FOOD ********************************/ $_SESSION["scriptOutput"] .= "Feeding time...<br />"; $_SESSION["scriptOutput"] .= "food: " . $new_food . "<br />"; // food debt if ($new_food < $food_upkeep) { $food_debt = $food_upkeep - $new_food; $new_food = 0; } else { $new_food = $new_food - $food_upkeep; } // else // if food can feed new population, then allow for the growth if ($new_food >= $new_population) { $surplus = $new_food - $new_population; $popGrowth = 0.1 * ($surplus / $limit_allTilesOwned); $popGrowthInt = round($popGrowth, 0, PHP_ROUND_HALF_UP); $new_population = 0; // reset population to assign new value based on pop changes $next_tiles = 1; if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_tiles = $r_result; $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles); $new_tile_population = 0; if ($tileInfoD["owner"] == $next_nations) { $new_tile_population = $tileInfoD["population"] + $popGrowthInt; setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population); $new_population = $new_population + $new_tile_population; } // if } // while $stmt2->close(); } else { $next_tiles = 0; } // else // if food cannot even sustain the population, it shrinks } else { if ($new_food < $new_population) { // if there is food debt, then set food debt + random number to be deficit if ($food_debt >= 1) { $rand = mt_rand(1, 50); $deficit = $food_debt + $rand; $popShrink = 0.15 * ($deficit / $limit_allTilesOwned); $popShrinkInt = round($popShrink, 0, PHP_ROUND_HALF_DOWN); $new_population = 0; // reset population to assign new value based on pop changes if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_tiles = $r_result; $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles); $new_tile_population = 0; if ($tileInfoD["owner"] == $next_nations) { $new_tile_population = $tileInfoD["population"] - $popShrinkInt; if ($new_tile_population < 0) { $new_tile_population = 0; } // if setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population); $new_population = $new_population + $new_tile_population; } // if } // while $stmt2->close(); } else { } // else // otherwise just use difference between population and food and random number to be deficit } else { $rand = mt_rand(1, 100); $deficit = $new_population - $new_food + $rand; $popShrink = 0.25 * ($deficit / $limit_allTilesOwned); $popShrinkInt = round($popShrink, 0, PHP_ROUND_HALF_DOWN); $new_population = 0; // reset population to assign new value based on pop changes if ($stmt2 = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) { $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($r_result); while ($stmt2->fetch()) { $next_tiles = $r_result; $tileInfoD = getTileInfoByID($getPage_connection2, $next_tiles); $new_tile_population = 0; if ($tileInfoD["owner"] == $next_nations) { $new_tile_population = $tileInfoD["population"] - $popShrinkInt; if ($new_tile_population < 0) { $new_tile_population = 0; } // if setTileInfo($getPage_connection2, $tileInfoD["id"], $tileInfoD["continent"], $tileInfoD["xpos"], $tileInfoD["ypos"], $tileInfoD["terrain"], $tileInfoD["resources"], $tileInfoD["improvements"], $tileInfoD["owner"], $tileInfoD["claims"], $new_tile_population); $new_population = $new_population + $new_tile_population; } // if } // while $stmt2->close(); } else { } // else } // else } } // else if /******************************** DEBT COLLECTION ********************************/ $_SESSION["scriptOutput"] .= "Money and Debts...<br />"; // pay off debt before anything else if ($new_debt > 0) { if ($new_money < $new_debt) { $money_debt = $new_debt - $new_money; // reduce the debt if nothing else $new_debt = $money_debt; $new_money = 0; } else { $new_money = $new_money - $new_debt; $new_debt = 0; } // else } // if if ($new_money < $money_upkeep) { $money_debt = $money_upkeep - $new_money; $new_debt = $money_debt; $new_money = 0; } else { $new_money = $new_money - $money_upkeep; } // else $_SESSION["scriptOutput"] .= "Debt collecting...<br />"; // money debt collecting // increase strike counter if debt is owed if ($new_debt > 0) { $new_strike = $new_strike + 1; } // if if ($new_food < 0) { $new_food = 0; } // if /******************************** SET NEW VARIABLES ********************************/ $_SESSION["scriptOutput"] .= "Update database...<br />"; setNationInfo($getPage_connection2, $next_nations, $nationInfoW["name"], $nationInfoW["home"], $nationInfoW["formal"], $nationInfoW["flag"], $new_production, $new_money, $new_debt, $new_happiness, $new_food, $nationInfoW["authority"], 0, $nationInfoW["economy"], 0, $nationInfoW["organizations"], $nationInfoW["invites"], $new_goods, $new_resources, $new_population, $new_strike); } // while $stmt->close(); } else { } // else $_SESSION["scriptOutput"] .= "That's a wrap, script complete.<br />"; }