function acceptOffer($getPage_connection2)
{
    if ($_SESSION["action"] == "accept_offer") {
        if ($_SESSION["action_id"] > 0) {
            $offerInfo1 = getOfferInfo($getPage_connection2, $_SESSION["action_id"]);
            if (($offerInfo1["toNation"] == $_SESSION["nation_id"] || $offerInfo1["fromNation"] == $_SESSION["nation_id"]) && $offerInfo1["status"] == 0) {
                if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
                    // toNation: the target nation of action
                    // fromNation: the source nation of action
                    $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
                    $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
                    $notEnough = array(0 => false, 1 => "");
                    for ($zz = 0; $zz < count($toNationInfo["goods"]); $zz++) {
                        $new_to_goods = $toNationInfo["goods"][$zz];
                    }
                    // for
                    for ($zz = 0; $zz < count($toNationInfo["resources"]); $zz++) {
                        $new_to_resources = $toNationInfo["resources"][$zz];
                    }
                    // for
                    $new_to_food = $toNationInfo["food"];
                    $new_to_money = $toNationInfo["money"];
                    for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                        $new_from_goods = $fromNationInfo["goods"][$zz];
                    }
                    // for
                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                        $new_from_resources = $fromNationInfo["resources"][$zz];
                    }
                    // for
                    $new_from_food = $fromNationInfo["food"];
                    $new_from_money = $fromNationInfo["money"];
                    if ($offerInfo1["givingItems"][0] > 0) {
                        for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                            $new_bonus = 1;
                            for ($y = 0; $y * 10 > $offerInfo1["givingQuantities"][$z]; $y++) {
                                $new_bonus = $y + $new_bonus;
                            }
                            // for
                            // set new sell strength
                            if ($offerInfo1["givingTypes"][$z] == "goods") {
                                $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                $new_buyStrength = $itemInfo1["buyStrength"];
                                $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                                setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                                for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                                        $new_to_goods[$zz] = $toNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                                        $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "offer";
                                        break;
                                    }
                                    // else
                                }
                                // for
                            } else {
                                if ($offerInfo1["givingTypes"][$z] == "resources") {
                                    $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                                    $new_buyStrength = $itemInfo1["buyStrength"];
                                    $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                                    setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                            $new_to_resources[$zz] = $toNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                                            $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "offer";
                                            break;
                                        }
                                        // else
                                    }
                                    // for
                                } else {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["money"]) {
                                        $new_to_money = $toNationInfo["money"] + $offerInfo1["givingQuantities"][$z];
                                        $new_from_money = $fromNationInfo["money"] - $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "offer";
                                        break;
                                    }
                                    // else
                                }
                            }
                            // else
                        }
                        // for
                    }
                    // if
                    if ($offerInfo1["receivingItems"][0] > 0) {
                        for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                            // set new buy strength
                            if ($offerInfo1["receivingTypes"][$z] == "goods") {
                                $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                                $new_sellStrength = $itemInfo1["sellStrength"];
                                setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                                for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                                    if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                                        $new_to_goods[$zz] = $toNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                                        $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                                    } else {
                                        $notEnough[0] = true;
                                        $notEnough[1] = "demand";
                                        break;
                                    }
                                    // else
                                }
                                // for
                            } else {
                                if ($offerInfo1["receivingTypes"][$z] == "resources") {
                                    $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                                    $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                                    $new_sellStrength = $itemInfo1["sellStrength"];
                                    setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                                    for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                            $new_to_resources[$zz] = $toNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                                            $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "offer";
                                            break;
                                        }
                                        // else
                                    }
                                    // for
                                } else {
                                    if ($offerInfo1["receivingTypes"][$z] == "food") {
                                        if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["food"]) {
                                            $new_to_food = $toNationInfo["food"] - $offerInfo1["receivingQuantities"][$z];
                                            $new_from_food = $fromNationInfo["food"] + $offerInfo1["receivingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "demand";
                                            break;
                                        }
                                        // else
                                    } else {
                                        if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["money"]) {
                                            $new_to_money = $toNationInfo["money"] - $offerInfo1["receivingQuantities"][$z];
                                            $new_from_money = $fromNationInfo["money"] + $offerInfo1["receivingQuantities"][$z];
                                        } else {
                                            $notEnough[0] = true;
                                            $notEnough[1] = "demand";
                                            break;
                                        }
                                        // else
                                    }
                                }
                            }
                            // else
                        }
                        // for
                    }
                    // if
                    if ($notEnough[0] === false) {
                        // give items
                        setNationInfo($getPage_connection2, $toNationInfo["id"], $toNationInfo["name"], $toNationInfo["home"], $toNationInfo["formal"], $toNationInfo["flag"], $toNationInfo["production"], $new_to_money, $toNationInfo["debt"], $toNationInfo["happiness"], $new_to_food, $toNationInfo["authority"], $toNationInfo["authorityChanged"], $toNationInfo["economy"], $toNationInfo["economyChanged"], $toNationInfo["organizations"], $toNationInfo["invites"], $new_to_goods, $new_to_resources, $toNationInfo["population"], $toNationInfo["strike"]);
                        // receive items
                        setNationInfo($getPage_connection2, $fromNationInfo["id"], $fromNationInfo["name"], $fromNationInfo["home"], $fromNationInfo["formal"], $fromNationInfo["flag"], $fromNationInfo["production"], $new_from_money, $fromNationInfo["debt"], $fromNationInfo["happiness"], $new_from_food, $fromNationInfo["authority"], $fromNationInfo["authorityChanged"], $fromNationInfo["economy"], $fromNationInfo["economyChanged"], $fromNationInfo["organizations"], $fromNationInfo["invites"], $new_from_goods, $new_from_resources, $fromNationInfo["population"], $fromNationInfo["strike"]);
                        // set offer status
                        setOfferInfo($getPage_connection2, $_SESSION["action_id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $offerInfo1["counter"], 1);
                        $_SESSION["success_message"] = "Offer has been accepted successfully!";
                    } else {
                        $_SESSION["warning_message"] = "Cannot complete action: a requested " . $notEnough[1] . " is not possible due to insufficent supply.";
                    }
                    // else
                } else {
                    $_SESSION["warning_message"] = "Cannot complete action: offer is empty.";
                }
                // else
            } else {
                $_SESSION["warning_message"] = "Cannot complete action: current nation is not involved in selected offer.";
            }
            // else
        } else {
            $_SESSION["warning_message"] = "Cannot complete action: invalid offer selected.";
        }
        // else
    } else {
        $_SESSION["warning_message"] = "Cannot complete action: invalid action.";
    }
    // else
}
示例#2
0
function processOffer($getPage_connection2, $offerInfo1)
{
    $payup = false;
    if ($offerInfo1["givingItems"][0] > 0 || $offerInfo1["receivingItems"][0] > 0) {
        // toNation: the target nation of action
        // fromNation: the source nation of action
        $toNationInfo = getNationInfo($getPage_connection2, $offerInfo1["toNation"]);
        $fromNationInfo = getNationInfo($getPage_connection2, $offerInfo1["fromNation"]);
        $notEnough = array(0 => false, 1 => "");
        for ($zz = 0; $zz < count($toNationInfo["goods"]); $zz++) {
            $new_to_goods = $toNationInfo["goods"][$zz];
        }
        // for
        for ($zz = 0; $zz < count($toNationInfo["resources"]); $zz++) {
            $new_to_resources = $toNationInfo["resources"][$zz];
        }
        // for
        $new_to_food = $toNationInfo["food"];
        $new_to_money = $toNationInfo["money"];
        for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
            $new_from_goods = $fromNationInfo["goods"][$zz];
        }
        // for
        for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
            $new_from_resources = $fromNationInfo["resources"][$zz];
        }
        // for
        $new_from_food = $fromNationInfo["food"];
        $new_from_money = $fromNationInfo["money"];
        if ($offerInfo1["givingItems"][0] > 0) {
            for ($z = 0; $z < count($offerInfo1["givingItems"]); $z++) {
                $new_bonus = 1;
                for ($y = 0; $y * 10 > $offerInfo1["givingQuantities"][$z]; $y++) {
                    $new_bonus = $y + $new_bonus;
                }
                // for
                // set new sell strength
                if ($offerInfo1["givingTypes"][$z] == "goods") {
                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                    $new_buyStrength = $itemInfo1["buyStrength"];
                    $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                    setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                    for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                            $new_to_goods[$zz] = $toNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                            $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                        } else {
                            $notEnough[0] = true;
                            $notEnough[1] = "offer";
                            break;
                        }
                        // else
                    }
                    // for
                } else {
                    if ($offerInfo1["givingTypes"][$z] == "resources") {
                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["givingItems"][$z]);
                        $new_buyStrength = $itemInfo1["buyStrength"];
                        $new_sellStrength = $itemInfo1["sellStrength"] + $new_bonus;
                        setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                        for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                            if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                $new_to_resources[$zz] = $toNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                                $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                            } else {
                                $notEnough[0] = true;
                                $notEnough[1] = "offer";
                                break;
                            }
                            // else
                        }
                        // for
                    } else {
                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["money"]) {
                            $new_to_money = $toNationInfo["money"] + $offerInfo1["givingQuantities"][$z];
                            $new_from_money = $fromNationInfo["money"] - $offerInfo1["givingQuantities"][$z];
                        } else {
                            $notEnough[0] = true;
                            $notEnough[1] = "offer";
                            break;
                        }
                        // else
                    }
                }
                // else
            }
            // for
        }
        // if
        if ($offerInfo1["receivingItems"][0] > 0) {
            for ($z = 0; $z < count($offerInfo1["receivingItems"]); $z++) {
                // set new buy strength
                if ($offerInfo1["receivingTypes"][$z] == "goods") {
                    $itemInfo1 = getGoodsInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                    $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                    $new_sellStrength = $itemInfo1["sellStrength"];
                    setGoodsInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["productionRequired"], $itemInfo1["resourceTypesRequired"], $itemInfo1["resourceQuantitiesRequired"], $itemInfo1["improvementTypesRequired"], $itemInfo1["improvementQuantitiesRequired"], $itemInfo1["improvementLevelRequired"], $new_buyStrength, $new_sellStrength);
                    for ($zz = 0; $zz < count($fromNationInfo["goods"]); $zz++) {
                        if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["goods"][$zz]) {
                            $new_to_goods[$zz] = $toNationInfo["goods"][$zz] - $offerInfo1["givingQuantities"][$z];
                            $new_from_goods[$zz] = $fromNationInfo["goods"][$zz] + $offerInfo1["givingQuantities"][$z];
                        } else {
                            $notEnough[0] = true;
                            $notEnough[1] = "demand";
                            break;
                        }
                        // else
                    }
                    // for
                } else {
                    if ($offerInfo1["receivingTypes"][$z] == "resources") {
                        $itemInfo1 = getResourceTypeInfo($getPage_connection2, $offerInfo1["receivingItems"][$z]);
                        $new_buyStrength = $itemInfo1["buyStrength"] + $new_bonus;
                        $new_sellStrength = $itemInfo1["sellStrength"];
                        setResourceTypeInfo($getPage_connection2, $itemInfo1["id"], $itemInfo1["name"], $itemInfo1["incompatibleWith"], $itemInfo1["image"], $new_buyStrength, $new_sellStrength);
                        for ($zz = 0; $zz < count($fromNationInfo["resources"]); $zz++) {
                            if ($offerInfo1["givingQuantities"][$z] <= $fromNationInfo["resources"][$zz]) {
                                $new_to_resources[$zz] = $toNationInfo["resources"][$zz] - $offerInfo1["givingQuantities"][$z];
                                $new_from_resources[$zz] = $fromNationInfo["resources"][$zz] + $offerInfo1["givingQuantities"][$z];
                            } else {
                                $notEnough[0] = true;
                                $notEnough[1] = "offer";
                                break;
                            }
                            // else
                        }
                        // for
                    } else {
                        if ($offerInfo1["receivingTypes"][$z] == "food") {
                            if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["food"]) {
                                $new_to_food = $toNationInfo["food"] - $offerInfo1["receivingQuantities"][$z];
                                $new_from_food = $fromNationInfo["food"] + $offerInfo1["receivingQuantities"][$z];
                            } else {
                                $notEnough[0] = true;
                                $notEnough[1] = "demand";
                                break;
                            }
                            // else
                        } else {
                            if ($offerInfo1["receivingQuantities"][$z] <= $toNationInfo["money"]) {
                                $new_to_money = $toNationInfo["money"] - $offerInfo1["receivingQuantities"][$z];
                                $new_from_money = $fromNationInfo["money"] + $offerInfo1["receivingQuantities"][$z];
                            } else {
                                $notEnough[0] = true;
                                $notEnough[1] = "demand";
                                break;
                            }
                            // else
                        }
                    }
                }
                // else
            }
            // for
        }
        // if
        if ($notEnough[0] === false) {
            // give items
            setNationInfo($getPage_connection2, $toNationInfo["id"], $toNationInfo["name"], $toNationInfo["home"], $toNationInfo["formal"], $toNationInfo["flag"], $toNationInfo["production"], $new_to_money, $toNationInfo["debt"], $toNationInfo["happiness"], $new_to_food, $toNationInfo["authority"], $toNationInfo["authorityChanged"], $toNationInfo["economy"], $toNationInfo["economyChanged"], $toNationInfo["organizations"], $toNationInfo["invites"], $new_to_goods, $new_to_resources, $toNationInfo["population"], $toNationInfo["strike"]);
            // receive items
            setNationInfo($getPage_connection2, $fromNationInfo["id"], $fromNationInfo["name"], $fromNationInfo["home"], $fromNationInfo["formal"], $fromNationInfo["flag"], $fromNationInfo["production"], $new_from_money, $fromNationInfo["debt"], $fromNationInfo["happiness"], $new_from_food, $fromNationInfo["authority"], $fromNationInfo["authorityChanged"], $fromNationInfo["economy"], $fromNationInfo["economyChanged"], $fromNationInfo["organizations"], $fromNationInfo["invites"], $new_from_goods, $new_from_resources, $fromNationInfo["population"], $fromNationInfo["strike"]);
            // set offer status
            setOfferInfo($getPage_connection2, $_SESSION["action_id"], $offerInfo1["fromNation"], $offerInfo1["toNation"], $offerInfo1["givingItems"], $offerInfo1["receivingItems"], $offerInfo1["givingQuantities"], $offerInfo1["receivingQuantities"], $offerInfo1["givingTypes"], $offerInfo1["receivingTypes"], $offerInfo1["turns"], $offerInfo1["counter"], 1);
        } else {
            $payup = true;
        }
        // else
    } else {
    }
    // else
    // if trade is not completed in full, freeze the route for the nation at fault
    if ($payup === true) {
        // who's responsible?
        // target nation's fault
        if ($notEnough[1] == "demand") {
            for ($x = 0; $x < count($toTradeInfo["offers"]); $x++) {
                $new_worth = $toTradeInfo["worth"];
                $new_worth[$x] = 0;
                setTradeInfo($getPage_connection2, $toTradeInfo["id"], $toTradeInfo["nation"], $toTradeInfo["routes"], $new_worth, $toTradeInfo["offers"], $toTradeInfo["limit"]);
            }
            // for
            // source nation's fault
        } else {
            for ($x = 0; $x < count($fromTradeInfo["offers"]); $x++) {
                $new_worth = $fromTradeInfo["worth"];
                $new_worth[$x] = 0;
                setTradeInfo($getPage_connection2, $fromTradeInfo["id"], $fromTradeInfo["nation"], $fromTradeInfo["routes"], $new_worth, $fromTradeInfo["offers"], $fromTradeInfo["limit"]);
            }
            // for
        }
        // else
    }
    // if
}
示例#3
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
}