function declineOrganization($getPage_connection2)
{
    if (strlen($_SESSION["action"]) >= 1) {
        if ($_SESSION["action"] == "decline") {
            if ($_SESSION["nation_id"] >= 1) {
                $nationInfoSelect = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
                if ($_SESSION["org"] >= 1) {
                    $organizationInfoSelect = getOrganizationInfo($getPage_connection2, $_SESSION["org"]);
                    $new_invites = array(0 => 0);
                    $counter = 0;
                    $nationInfoM = getNationInfo($getPage_connection2, $_SESSION["nation_id"]);
                    for ($z = 0; $z < count($nationInfoM["invites"]); $z++) {
                        if ($_SESSION["org"] != $nationInfoM["invites"][$z]) {
                            $new_invites[$counter] = $nationInfoM["invites"][$z];
                            $counter++;
                        }
                        // if
                    }
                    // for
                    setNationInfo($getPage_connection2, $nationInfoSelect["id"], $nationInfoSelect["name"], $nationInfoSelect["home"], $nationInfoSelect["formal"], $nationInfoSelect["flag"], $nationInfoSelect["production"], $nationInfoSelect["money"], $nationInfoSelect["debt"], $nationInfoSelect["happiness"], $nationInfoSelect["food"], $nationInfoSelect["authority"], $nationInfoSelect["authorityChanged"], $nationInfoSelect["economy"], $nationInfoSelect["economyChanged"], $nationInfoSelect["organizations"], $new_invites, $nationInfoSelect["goods"], $nationInfoSelect["resources"], $nationInfoSelect["population"], $nationInfoSelect["strike"]);
                    $new_pending = array(0 => 0);
                    $counter = 0;
                    $organizationInfoM = getOrganizationInfo($getPage_connection2, $_SESSION["org"]);
                    for ($z = 0; $z < count($organizationInfoM["pending"]); $z++) {
                        if ($_SESSION["nation_id"] != $organizationInfoM["pending"][$z]) {
                            $new_pending[$counter] = $organizationInfoM["pending"][$z];
                            $counter++;
                        }
                        // if
                    }
                    // for
                    setOrganizationInfo($getPage_connection2, $_SESSION["org"], $organizationInfoSelect["name"], $organizationInfoSelect["members"], $organizationInfoSelect["managers"], $new_pending, $organizationInfoSelect["ranking"]);
                    $_SESSION["success_message"] = "Nation has declined organization successfully!";
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: organization is not valid.";
                }
                // else
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: nation is not valid.";
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: action is not valid.";
    }
    // else
}
예제 #2
0
function updateGlobe($getPage_connection2)
{
    // change requirements of luxury and basic goods
    // set luxurygoods
    $goodsInfoW = getGoodsInfo($getPage_connection2, 5);
    if ($goodsInfoW["productionRequired"] - 2 > 1) {
        $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2);
    } else {
        $new_productionRequired = mt_rand(1, $goodsInfoW["productionRequired"] + 2);
    }
    // else
    if ($new_productionRequired < 1) {
        $new_productionRequired = 1;
    }
    // if
    $rand_metals = 2;
    $rand_wood = 1;
    $rand_metals = mt_rand(2, 10);
    $rand_wood = mt_rand(2, 10);
    $new_resourceTypesRequired = array(0 => 0);
    $new_resourceQuantitiesRequired = array(0 => 0);
    if ($rand_wood > 0) {
        $new_resourceTypesRequired[0] = 1;
        $new_resourceQuantitiesRequired[0] = $rand_wood;
    }
    // if
    if ($rand_metals > 0) {
        $new_resourceTypesRequired[1] = 2;
        $new_resourceQuantitiesRequired[1] = $rand_metals;
    }
    // if
    setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]);
    // set basicgoods
    $goodsInfoW = getGoodsInfo($getPage_connection2, 6);
    if ($goodsInfoW["productionRequired"] - 2 > 1) {
        $new_productionRequired = mt_rand($goodsInfoW["productionRequired"] - 2, $goodsInfoW["productionRequired"] + 2);
    } else {
        $new_productionRequired = mt_rand(0, $goodsInfoW["productionRequired"] + 2);
    }
    // else
    if ($new_productionRequired < 1) {
        $new_productionRequired = 1;
    }
    // if
    $rand_metals = 1;
    $rand_wood = 1;
    $rand_metals = mt_rand(1, 8);
    $rand_wood = mt_rand(1, 8);
    $new_resourceTypesRequired = array(0 => 0);
    $new_resourceQuantitiesRequired = array(0 => 0);
    if ($rand_wood > 0) {
        $new_resourceTypesRequired[0] = 1;
        $new_resourceQuantitiesRequired[0] = $rand_wood;
    }
    // if
    if ($rand_metals > 0) {
        $new_resourceTypesRequired[1] = 2;
        $new_resourceQuantitiesRequired[1] = $rand_metals;
    }
    // if
    setGoodsInfo($getPage_connection2, $goodsInfoW["id"], $goodsInfoW["name"], $new_productionRequired, $goodsInfoW["foodRequired"], $new_resourceTypesRequired, $new_resourceQuantitiesRequired, $goodsInfoW["improvementTypesRequired"], $goodsInfoW["improvementQuantitiesRequired"], $goodsInfoW["improvementLevelRequired"], $goodsInfoW["buyStrength"], $goodsInfoW["sellStrength"]);
    // set new market rates
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM goods ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_goods = $r_result;
            $goodsInfoW = getGoodsInfo($getPage_connection2, $next_goods);
            $marketInfoW = getMarketInfo($getPage_connection2, $next_goods);
            $rate = 0;
            // if buy strength is more, increase rate, otherwise decrease or remain constant
            if ($goodsInfoW["buyStrength"] > $goodsInfoW["sellStrength"]) {
                $randRateBonus = mt_rand(1, 4);
                $rate = $marketInfoW["rate"] + $randRateBonus;
            } else {
                if ($goodsInfoW["buyStrength"] < $goodsInfoW["sellStrength"]) {
                    $randFlux = mt_rand(1, 4);
                    // random drop or rise (75% more likely drop)
                    if ($randFlux == 1) {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] + $randRateBonus;
                    } else {
                        $randRateBonus = mt_rand(1, 4);
                        $rate = $marketInfoW["rate"] - $randRateBonus;
                    }
                    // else
                } else {
                    $randFlux = mt_rand(1, 2);
                    // random drop or rise (50/50)
                    if ($randFlux == 1) {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] + $randRateBonus;
                    } else {
                        $randRateBonus = mt_rand(1, 2);
                        $rate = $marketInfoW["rate"] - $randRateBonus;
                    }
                    // else
                }
            }
            // else
            if ($rate >= 1) {
                setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], $rate);
            } else {
                setMarketInfo($getPage_connection2, $next_goods, $marketInfoW["name"], 0);
            }
            // else
            // reset strength of good for next turn (no reset for now)
            //setGoodsInfo($getPage_connection2,$goodsInfoW["id"],$goodsInfoW["name"],$goodsInfoW["productionRequired"],$goodsInfoW["foodRequired"],$goodsInfoW["resourceTypesRequired"],$goodsInfoW["resourceQuantitiesRequired"],$goodsInfoW["improvementTypesRequired"],$goodsInfoW["improvementQuantitiesRequired"],$goodsInfoW["improvementLevelRequired"],100,100);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // add to turn counter for trade offers
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM offers ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_offers = $r_result;
            $offerInfo1 = getOfferInfo($getPage_connection2, $next_offers);
            $new_counter = $offerInfo1["counter"] + 1;
            setOfferInfo($getPage_connection2, $offerInfo1["id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $new_counter, $offerInfo1["status"]);
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // remove empty organizations, automatically appoint new manager if there is no manager (new manager is the oldest joined member)
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM organizations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        while ($stmt->fetch()) {
            $next_organizations = $r_result;
            $organizationInfo1 = getOrganizationInfo($getPage_connection2, $next_organizations);
            $new_managers = array(0 => 0);
            if (count($organizationInfo1["members"]) == 1) {
                if ($organizationInfo1["members"][0] == 0) {
                    deleteOrganizationInfo($getPage_connection2, $next_organizations);
                }
                // if
            } else {
                if (count($organizationInfo1["members"]) > 1) {
                    if (count($organizationInfo1["managers"]) == 1) {
                        if ($organizationInfo1["managers"][0] == 0) {
                            $new_managers[0] = $organizationInfo1["members"][0];
                            setOrganizationInfo($getPage_connection2, $next_organizations, $organizationInfo1["name"], $organizationInfo1["members"], $new_managers, $organizationInfo1["pending"], $organizationInfo1["ranking"]);
                        }
                        // if
                    } else {
                    }
                    // else
                } else {
                    deleteOrganizationInfo($getPage_connection2, $next_organizations);
                }
            }
            // else
        }
        // while
        $stmt->close();
    } else {
    }
    // else
    // set rankings
    if ($stmt = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY id ASC")) {
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($r_result);
        $offset = 0;
        while ($stmt->fetch()) {
            $next_nations = $r_result;
            $rank = $offset + 1;
            // production
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY production DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_production_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET production=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_production_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // money
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY money DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_money_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET money=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_money_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // happiness
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY happiness DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_happiness_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET happiness=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_happiness_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // food
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY food DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_food_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET food=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_food_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            // population
            if ($stmt11 = $getPage_connection2->prepare("SELECT id FROM nations ORDER BY population DESC LIMIT 1 OFFSET ?")) {
                $stmt11->bind_param("i", $offset);
                $stmt11->execute();
                $stmt11->bind_result($r_result);
                $stmt11->fetch();
                $next_population_nation = $r_result;
                $stmt11->close();
            } else {
            }
            // else
            if ($stmt11 = $getPage_connection2->prepare("UPDATE rankings SET population=? WHERE nation=?")) {
                $stmt11->bind_param("ii", $rank, $next_population_nation);
                $stmt11->execute();
                $stmt11->close();
            } else {
            }
            // else
            $offset++;
        }
        // while
        $stmt->close();
    } else {
        $next_offers = 0;
    }
    // else
}