function buildUnit($getPage_connection2)
{
    $tileInfoW = getTileInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]);
    $improvementValid = false;
    // go through improvements
    for ($a = 0; $a < count($tileInfoW["improvements"]); $a++) {
        $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$a]);
        // is it a depot?
        if ($improvementInfoW["type"] == 5) {
            // are any of the owners of the depot the player?
            for ($b = 0; $b < count($improvementInfoW); $b++) {
                if ($improvementInfoW["owners"][$b] == $_SESSION["nation_id"]) {
                    $improvementValid = true;
                    break;
                } else {
                    $improvementValid = false;
                }
                // else
            }
            // for
        }
        // if
        if ($improvementValid === true) {
            break;
        }
        // if
    }
    // for
    // if valid depot exists on tile, proceed
    if ($_SESSION["action_id"] >= 1 && $improvementValid === true) {
        $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $_SESSION["action_id"]);
        $nationInfoW = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
        // is it a valid entity?
        if ($unitTypeInfoW["id"] >= 1) {
            if ($unitTypeInfoW["water"] == 1) {
                if (isItCoast($getPage_connection2, $tileInfoW) === true) {
                    $coastCheck = true;
                } else {
                    $coastCheck = false;
                }
                // else
            } else {
                $coastCheck = true;
            }
            // else
            // can player afford this expense?
            if ($coastCheck === true) {
                if ($unitTypeInfoW["baseCost"] <= $nationInfoW["money"]) {
                    $notEnough = false;
                    for ($zz = 0; $zz < count($unitTypeInfoW["goodsRequired"]); $zz++) {
                        if ($unitTypeInfoW["goodsRequired"][$zz] > $nationInfoW["goods"][$zz]) {
                            $notEnough = true;
                            break;
                        }
                        // if
                    }
                    // for
                    if ($notEnough === false) {
                        $unitInfoD = getUnitInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"]);
                        if ($unitInfoD["id"] < 1) {
                            $_SESSION["success_message"] = "Unit has been trained successfully!";
                            $new_money = $nationInfoW["money"] - $unitTypeInfoW["baseCost"];
                            $new_goods = array(0 => 0);
                            for ($zz = 0; $zz < count($nationInfoW["goods"]); $zz++) {
                                $new_goods[$zz] = $nationInfoW["goods"][$zz] - $unitTypeInfoW["goodsRequired"][$zz];
                            }
                            // for
                            $new_food = $nationInfoW["food"] - $unitTypeInfoW["foodRequired"];
                            setNationInfo($getPage_connection2, $_SESSION["nation_id"], $nationInfoW["name"], $nationInfoW["home"], $nationInfoW["formal"], $nationInfoW["flag"], $nationInfoW["production"], $new_money, $nationInfoW["debt"], $nationInfoW["happiness"], $new_food, $nationInfoW["authority"], $nationInfoW["authorityChanged"], $nationInfoW["economy"], $nationInfoW["economyChanged"], $nationInfoW["organizations"], $nationInfoW["invites"], $new_goods, $nationInfoW["resources"], $nationInfoW["population"], $nationInfoW["strike"]);
                            $mt_rand = mt_rand(100, 9999);
                            $new_name = "Unit " . $mt_rand;
                            // if transport, add to transport list
                            if ($_SESSION["action_id"] == 10) {
                                addTransportInfo($getPage_connection2, "0");
                                $new_transport_id = $getPage_connection2->insert_id;
                            } else {
                                $new_transport_id = 0;
                            }
                            // else
                            $tileInfoX = getTileInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"]);
                            addUnitInfo($getPage_connection2, $_SESSION["continent_id"], $_SESSION["xpos"], $_SESSION["ypos"], $unitTypeInfoW["health"], $unitTypeInfoW["movement"], $new_name, $_SESSION["action_id"], $_SESSION["nation_id"], 1, $new_transport_id, $tileInfoX["id"], 0.0);
                        } else {
                            $_SESSION["warning_message"] = "Cannot complete action: there is already a unit on that current tile.";
                        }
                        // else
                    }
                    // if
                }
                // if
            } else {
                if ($coastCheck === true) {
                    $_SESSION["warning_message"] = "Cannot complete action: player cannot afford this unit.";
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: unit type requires coast to train.";
                }
                // else
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: unit is not valid.";
        }
        // else
    } else {
        if ($improvementValid === true) {
            $_SESSION["warning_message"] = "Cannot complete action: unit requires depot for training.";
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: unit is not valid.";
        }
        // else
    }
    // else
}
Example #2
0
function preliminaryUpdates($getPage_connection2)
{
    $limit_allUnits = 0;
    if ($stmt = $getPage_connection2->prepare("SELECT COUNT(id) FROM unitsmap")) {
        $stmt->execute();
        $stmt->bind_result($r_result);
        $stmt->fetch();
        $limit_allUnits = $r_result;
        $stmt->close();
    } else {
        $endTurnFailed = "failed";
    }
    // else
    $limit_allTiles = 0;
    if ($stmt = $getPage_connection2->prepare("SELECT COUNT(id) FROM tilesmap")) {
        $stmt->execute();
        $stmt->bind_result($r_result);
        $stmt->fetch();
        $limit_allTiles = $r_result;
        $stmt->close();
    } else {
        $endTurnFailed = "failed";
    }
    // else
    $limit_allOffers = 0;
    if ($stmt = $getPage_connection2->prepare("SELECT COUNT(id) FROM offers")) {
        $stmt->execute();
        $stmt->bind_result($r_result);
        $stmt->fetch();
        $limit_allOffers = $r_result;
        $stmt->close();
    } else {
        $endTurnFailed = "failed";
    }
    // else
    // Illegal Conflicts and Table Cleanup
    // removed declined offers and empty or invalid offers and offers which have reached the turn limit
    if ($limit_allOffers >= 1) {
        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 = array("id" => 0, "fromNation" => 0, "toNation" => 0, "givingItems" => "", "receivingItems" => "", "turns" => 0, "counter" => 0, "status" => 0);
                if ($stmt10 = $getPage_connection2->prepare("SELECT id,fromNation,toNation,givingItems,receivingItems,turns,counter,status FROM offers WHERE id=? LIMIT 1")) {
                    $stmt10->bind_param("i", $next_offers);
                    $stmt10->execute();
                    $stmt10->bind_result($r_id, $r_fromNation, $r_toNation, $r_givingItems, $r_receivingItems, $r_turns, $r_counter, $r_status);
                    $stmt10->fetch();
                    $offerInfo1["id"] = $r_id;
                    $offerInfo1["fromNation"] = $r_fromNation;
                    $offerInfo1["toNation"] = $r_toNation;
                    if (stripos($r_givingItems, ",")) {
                        $offerInfo1["givingItems"] = explode(",", $r_givingItems);
                    } else {
                        $offerInfo1["givingItems"] = array(0 => $r_givingItems);
                    }
                    // else
                    if (stripos($r_receivingItems, ",")) {
                        $offerInfo1["receivingItems"] = explode(",", $r_receivingItems);
                    } else {
                        $offerInfo1["receivingItems"] = array(0 => $r_receivingItems);
                    }
                    // else
                    $offerInfo1["turns"] = $r_turns;
                    $offerInfo1["counter"] = $r_counter;
                    $offerInfo1["status"] = $r_status;
                    $stmt10->close();
                } else {
                }
                if ($offerInfo1["status"] == 2 || $offerInfo1["givingItems"][0] < 1 && $offerInfo1["receivingItems"][0] < 1 || $offerInfo1["toNation"] < 1 && $offerInfo1["fromNation"] < 1) {
                    deleteOfferInfo($getPage_connection2, $next_offers);
                }
                // if
                if ($offerInfo1["counter"] == $offerInfo1["turns"]) {
                    deleteOfferInfo($getPage_connection2, $next_offers);
                }
                // if
            }
            // while
            $stmt->close();
        } else {
        }
        // else
    }
    // if
    // search through all units and look for illegally placed, dead, invalid level, or striking units remove them
    // also reset used movement
    if ($limit_allUnits >= 1) {
        if ($stmt = $getPage_connection2->prepare("SELECT id FROM unitsmap ORDER BY id ASC")) {
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($r_result);
            while ($stmt->fetch()) {
                $next_units = $r_result;
                $illegal = false;
                $unitInfoW = getUnitInfoByID($getPage_connection2, $next_units);
                $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $unitInfoW["type"]);
                $tileInfoW = getTileInfo($getPage_connection2, $unitInfoW["continent"], $unitInfoW["xpos"], $unitInfoW["ypos"]);
                $coastal = isItCoast($getPage_connection2, $tileInfoW);
                // reset used movement
                setUnitInfo($getPage_connection2, $unitInfoW["id"], $unitInfoW["continent"], $unitInfoW["xpos"], $unitInfoW["ypos"], $unitInfoW["health"], 0, $unitInfoW["name"], $unitInfoW["type"], $unitInfoW["owner"], $unitInfoW["level"], $unitInfoW["transport"], $unitInfoW["created"], 0.0);
                // land unit
                if ($unitTypeInfoW["water"] != 1 && $tileInfoW["terrain"] == 2) {
                    $illegal = true;
                    // water unit
                } else {
                    if ($unitTypeInfoW["water"] == 1 && $tileInfoW["terrain"] != 2 && $coastal === false) {
                        $illegal = true;
                    } else {
                        $illegal = false;
                    }
                }
                // else
                if ($unitInfoW["health"] < 1 || $unitInfoW["level"] < 1) {
                    $illegal = true;
                } else {
                    $illegal = false;
                }
                // else
                $nationInfoA = getNationInfo($getPage_connection2, $unitInfoW["owner"]);
                if ($nationInfoA["strike"] > 1) {
                    $new_strike = $nationInfoA["strike"] - 1;
                    $illegal = true;
                } else {
                    $new_strike = $nationInfoA["strike"];
                }
                // else
                if ($illegal === true) {
                    deleteUnitInfo($getPage_connection2, $next_units);
                    setNationInfo($getPage_connection2, $nationInfoA["id"], $nationInfoA["name"], $nationInfoA["home"], $nationInfoA["formal"], $nationInfoA["flag"], $nationInfoA["production"], $nationInfoA["money"], $nationInfoA["debt"], $nationInfoA["happiness"], $nationInfoA["food"], $nationInfoA["authority"], $nationInfoA["authorityChanged"], $nationInfoA["economy"], $nationInfoA["economyChanged"], $nationInfoA["organizations"], $nationInfoA["invites"], $nationInfoA["goods"], $nationInfoA["resources"], $nationInfoA["population"], $new_strike);
                }
                // if
            }
            // while
            $stmt->close();
        } else {
        }
        // else
    }
    // if
    if ($limit_allTiles >= 1) {
        // search through all tiles and look for illegally placed improvements or dead or invalid level improvements and remove them
        if ($stmt = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($r_result);
            while ($stmt->fetch()) {
                $next_tiles = $r_result;
                $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles);
                for ($w = 0; $w < count($tileInfoW["improvements"]); $w++) {
                    $illegal = false;
                    $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$w]);
                    $improvementTypeInfoW = getImprovementTypeInfo($getPage_connection2, $improvementInfoW["type"]);
                    $resourceCheck = array(0 => true);
                    // are any resources actually required
                    if (count($improvementTypeInfoW["resourcesRequired"]) > 1) {
                        if ($improvementTypeInfoW["resourcesRequired"][1] > 0) {
                            $validResourcesRequired = true;
                        } else {
                            $validResourcesRequired = false;
                        }
                        // else
                    } else {
                        if ($improvementTypeInfoW["resourcesRequired"][0] > 0) {
                            $validResourcesRequired = true;
                        } else {
                            $validResourcesRequired = false;
                        }
                        // else
                    }
                    // else
                    if ($validResourcesRequired === true) {
                        for ($a = 0; $a < count($improvementTypeInfoW["resourcesRequired"]); $a++) {
                            for ($b = 0; $b < count($tileInfoW["resources"]); $b++) {
                                $resourceCheck[$a] = false;
                                $resourceInfoWW = getResourceInfo($getPage_connection2, $tileInfoW["resources"][$b]);
                                if ($resourceInfoWW["type"] == $improvementTypeInfoW["resourcesRequired"][$a]) {
                                    $resourceCheck[$a] = true;
                                    break;
                                }
                                // if
                            }
                            // for
                        }
                        // for
                        for ($a = 0; $a < count($improvementTypeInfoW["resourcesRequired"]); $a++) {
                            if ($resourceCheck[$a] === false) {
                                $illegal = true;
                                break;
                            }
                            // if
                        }
                        // for
                    }
                    // if
                    $terrainCheck = false;
                    for ($a = 0; $a < count($improvementTypeInfoW["terrainTypeRequired"]); $a++) {
                        if ($tileInfoW["terrain"] == $improvementTypeInfoW["terrainTypeRequired"][$a]) {
                            $terrainCheck = true;
                            break;
                        }
                        // if
                    }
                    // for
                    if ($terrainCheck === false) {
                        $illegal = true;
                    }
                    // if
                    if ($improvementInfoW["level"] < 1) {
                        $illegal = true;
                    }
                    // if
                    if ($illegal === true) {
                        deleteImprovementInfo($getPage_connection2, $improvementInfoW["id"], $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"]);
                    }
                    // if
                }
                // for
            }
            // while
            $stmt->close();
        } else {
        }
        // else
        // setup new claims and change control if needed
        if ($stmt = $getPage_connection2->prepare("SELECT id FROM tilesmap ORDER BY id ASC")) {
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($r_result);
            while ($stmt->fetch()) {
                $next_tiles1 = $r_result;
                $tileInfoW = getTileInfoByID($getPage_connection2, $next_tiles1);
                $unitInfoW = getUnitInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"]);
                $alreadyClaimed = false;
                if ($unitInfoW["id"] >= 1) {
                    // remove improvement ownership from old player who lost tile control
                    if ($unitInfoW["owner"] != $tileInfoW["owner"]) {
                        for ($r = 0; $r < count($tileInfoW["improvements"]); $r++) {
                            $improvementInfoW = getImprovementInfo($getPage_connection2, $tileInfoW["improvements"][$r]);
                            if ($improvementInfoW["id"] >= 1) {
                                $new_owners = array(0 => 0);
                                $alreadyOwned = false;
                                $counter = 0;
                                for ($s = 0; $s < count($improvementInfoW["owners"]); $s++) {
                                    if ($improvementInfoW["owners"][$s] != $tileInfoW["owner"]) {
                                        $new_owners[$counter] = $improvementInfoW["owners"][$s];
                                        $counter++;
                                    }
                                    // if
                                    if ($improvementInfoW["owners"][$s] == $unitInfoW["owner"]) {
                                        $alreadyOwned = true;
                                    }
                                    // if
                                }
                                // for
                                if ($alreadyOwned === false) {
                                    $new_index = count($new_owners) + 1;
                                    $new_owners[$new_index] = $unitInfoW["owner"];
                                }
                                // if
                                setImprovementInfo($getPage_connection2, $improvementInfoW["id"], $improvementInfoW["continent"], $improvementInfoW["xpos"], $improvementInfoW["ypos"], $improvementInfoW["type"], $improvementInfoW["level"], $improvementInfoW["usingResources"], $new_owners, $improvementInfoW["name"]);
                            }
                            // if
                        }
                        // for
                    }
                    // if
                    setTileInfo($getPage_connection2, $tileInfoW["id"], $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"], $tileInfoW["terrain"], $tileInfoW["resources"], $tileInfoW["improvements"], $unitInfoW["owner"], $tileInfoW["claims"], $tileInfoW["population"]);
                    for ($v = 0; $v < count($tileInfoW["claims"]); $v++) {
                        $claimsInfoW = getClaimInfo($getPage_connection2, $tileInfoW["claims"][$v]);
                        if ($claimsInfoW["owner"] == $unitInfoW["owner"]) {
                            $alreadyClaimed = true;
                            break;
                        }
                        // if
                    }
                    // for
                    if ($alreadyClaimed === false) {
                        addClaimInfo($getPage_connection2, 10, $unitInfoW["owner"], $tileInfoW["id"]);
                    }
                    // if
                    // Claims leaking for dominant bordering tiles
                    // check for dominant claimed tiles
                    $claimState1 = checkClaimsState($getPage_connection2, $tileInfoW, $tileInfoW["owner"]);
                    // if dominant, bleed claim to neighbouring tiles
                    if ($claimState1 == 1) {
                        // add to left
                        if ($tileInfoW["xpos"] > 1) {
                            // West
                            $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] - 1, $tileInfoW["ypos"]);
                            $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                            if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                $claimFound = false;
                                for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                    $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                    if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                        setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                        $claimFound = true;
                                        break;
                                    }
                                    // if
                                }
                                // for
                                if ($claimFound === false) {
                                    addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                }
                                // if
                            }
                            // if
                            if ($tileInfoW["ypos"] > 1) {
                                // Northwest
                                $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] - 1, $tileInfoW["ypos"] - 1);
                                $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                                if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                    $claimFound = false;
                                    for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                        $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                        if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                            setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                            $claimFound = true;
                                            break;
                                        }
                                        // if
                                    }
                                    // for
                                    if ($claimFound === false) {
                                        addClaimInfo($getPage_connection2, 3, $tileInfoT["owner"], $tileInfoT["id"]);
                                    }
                                    // if
                                }
                                // if
                            }
                            // if
                            if ($tileInfoW["ypos"] < 20) {
                                // Southwest
                                $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] - 1, $tileInfoW["ypos"] + 1);
                                $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                                if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                    $claimFound = false;
                                    for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                        $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                        if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                            setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                            $claimFound = true;
                                            break;
                                        }
                                        // if
                                    }
                                    // for
                                    if ($claimFound === false) {
                                        addClaimInfo($getPage_connection2, 3, $tileInfoT["owner"], $tileInfoT["id"]);
                                    }
                                    // if
                                }
                                // if
                            }
                            // if
                        }
                        // if
                        // add to right
                        if ($tileInfoW["xpos"] < 20) {
                            // East
                            $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] + 1, $tileInfoW["ypos"]);
                            $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                            if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                $claimFound = false;
                                for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                    $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                    if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                        setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                        $claimFound = true;
                                        break;
                                    }
                                    // if
                                }
                                // for
                                if ($claimFound === false) {
                                    addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                }
                                // if
                            }
                            // if
                            if ($tileInfoW["ypos"] > 1) {
                                // Northeast
                                $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] + 1, $tileInfoW["ypos"] - 1);
                                $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                                if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                    $claimFound = false;
                                    for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                        $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                        if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                            setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                            $claimFound = true;
                                            break;
                                        }
                                        // if
                                    }
                                    // for
                                    if ($claimFound === false) {
                                        addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                    }
                                    // if
                                }
                                // if
                            }
                            // if
                            if ($tileInfoW["ypos"] < 20) {
                                // Southeast
                                $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"] + 1, $tileInfoW["ypos"] + 1);
                                $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                                if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                    $claimFound = false;
                                    for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                        $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                        if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                            setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                            $claimFound = true;
                                            break;
                                        }
                                        // if
                                    }
                                    // for
                                    if ($claimFound === false) {
                                        addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                    }
                                    // if
                                }
                                // if
                            }
                            // if
                        }
                        // if
                        if ($tileInfoW["ypos"] > 1) {
                            // North
                            $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"] - 1);
                            $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                            if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                $claimFound = false;
                                for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                    $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                    if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                        setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                        $claimFound = true;
                                        break;
                                    }
                                    // if
                                }
                                // for
                                if ($claimFound === false) {
                                    addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                }
                                // if
                            }
                            // if
                        }
                        // if
                        if ($tileInfoW["ypos"] < 20) {
                            // South
                            $tileInfoT = getTileInfo($getPage_connection2, $tileInfoW["continent"], $tileInfoW["xpos"], $tileInfoW["ypos"] + 1);
                            $claimStateT = checkClaimsState($getPage_connection2, $tileInfoT, $tileInfoW["owner"]);
                            if ($claimStateT != 1 && $claimStateT > 1 && $tileInfoT["owner"] > 0) {
                                $claimFound = false;
                                for ($j = 0; $j < count($tileInfoT["claims"]); $j++) {
                                    $claimInfoT = getClaimInfo($getPage_connection2, $tileInfoT["claims"][$j]);
                                    if ($claimInfoT["owner"] == $tileInfoW["owner"]) {
                                        setClaimInfo($getPage_connection2, $claimInfoT["id"], $claimInfoT["strength"] + 3, $claimInfoT["owner"]);
                                        $claimFound = true;
                                        break;
                                    }
                                    // if
                                }
                                // for
                                if ($claimFound === false) {
                                    addClaimInfo($getPage_connection2, 3, $tileInfoW["owner"], $tileInfoT["id"]);
                                }
                                // if
                            }
                            // if
                        }
                        // if
                    }
                    // if
                }
                // if
            }
            // while
            $stmt->close();
        } else {
        }
        // else
    }
    // if
    // Update claims strengths
    $limit_allClaims = 0;
    if ($stmt = $getPage_connection2->prepare("SELECT COUNT(id) FROM claims")) {
        $stmt->execute();
        $stmt->bind_result($r_result);
        $stmt->fetch();
        $limit_allClaims = $r_result;
        $stmt->close();
    } else {
        $endTurnFailed = "failed";
    }
    // else
    if ($limit_allClaims >= 1) {
        if ($stmt = $getPage_connection2->prepare("SELECT id FROM claims ORDER BY id ASC")) {
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($r_result);
            while ($stmt->fetch()) {
                $next_claims = $r_result;
                $claimInfoW = getClaimInfo($getPage_connection2, $next_claims);
                $nationInfoC = getNationInfo($getPage_connection2, $claimInfoW["owner"]);
                // start removing claim strength if the strike is still going on above 3
                if ($nationInfoC["strike"] > 3) {
                    if ($claimInfoW["strength"] - 10 >= 0) {
                        $new_strength = $claimInfoW["strength"] - 10;
                    } else {
                        $new_strength = 0;
                    }
                    // else
                    $new_strike = $nationInfoC["strike"] - 1;
                    setNationInfo($getPage_connection2, $nationInfoC["id"], $nationInfoC["name"], $nationInfoC["home"], $nationInfoC["formal"], $nationInfoC["flag"], $nationInfoC["production"], $nationInfoC["money"], $nationInfoC["debt"], $nationInfoC["happiness"], $nationInfoC["food"], $nationInfoC["authority"], $nationInfoC["authorityChanged"], $nationInfoC["economy"], $nationInfoC["economyChanged"], $nationInfoC["organizations"], $nationInfoC["invites"], $nationInfoC["goods"], $nationInfoC["resources"], $nationInfoC["population"], $new_strike);
                } else {
                    if ($claimInfoW["strength"] + 5 <= 1000) {
                        $new_strength = $claimInfoW["strength"] + 5;
                    } else {
                        $new_strength = 1000;
                    }
                    // else
                }
                // else
                setClaimInfo($getPage_connection2, $next_claims, $new_strength, $claimInfoW["owner"]);
            }
            // while
            $stmt->close();
        } else {
        }
        // else
    }
    // if
}