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