function combat($getPage_connection2, $continent, $xpos, $ypos, $attacker, $defender, $amphibian) { if ($continent >= 1 && $xpos >= 1 && $ypos >= 1 && $attacker["id"] >= 1 && $defender["id"] >= 1 && $amphibian >= 0) { $tileInfoB = getTileInfo($getPage_connection2, $continent, $xpos, $ypos); $terrainInfoB = getTerrainInfo($getPage_connection2, $tileInfoB["terrain"]); $unitTypeInfoAttacker = getUnitTypeInfo($getPage_connection2, $attacker["type"]); $unitTypeInfoDefender = getUnitTypeInfo($getPage_connection2, $defender["type"]); $attackerA = 0.0; $attackerD = 0.0; $defenderA = 0.0; $defenderD = 0.0; $attackerReconLevel = array(0 => 0); $defenderReconLevel = array(0 => 0); $attackerReconExp = array(0 => 0); $defenderReconExp = array(0 => 0); $attackerReconBonus = 0; $defenderReconBonus = 0; $attackerArtilleryLevel = array(0 => 0); $defenderArtilleryLevel = array(0 => 0); $attackerArtilleryPower = array(0 => 0); $defenderArtilleryPower = array(0 => 0); $attackerArtilleryBonus = 0; $defenderArtilleryBonus = 0; // Experience Bonus from Recon $counter = 0; // goes through -2 to +2 x and y positions looking for attacker recon to aid attacker for ($x = -2; $x < 3; $x++) { for ($y = -2; $y < 3; $y++) { $unitInfoZ = getUnitInfo($getPage_connection2, $attacker["continent"], $attacker["xpos"] + $x, $attacker["ypos"] + $y); if ($unitInfoZ["id"] >= 1) { if ($unitInfoZ["type"] == 5) { $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]); $attackerReconLevel[$counter] = $unitInfoZ["level"]; $attackerReconExp[$counter] = 2; $counter++; } // if } // if } // for } // for $counter = 0; // goes through -2 to +2 x and y positions looking for defender recon to aid defender for ($x = -2; $x < 3; $x++) { for ($y = -2; $y < 3; $y++) { $unitInfoZ = getUnitInfo($getPage_connection2, $defender["continent"], $defender["xpos"] + $x, $defender["ypos"] + $y); if ($unitInfoZ["id"] >= 1) { if ($unitInfoZ["type"] == 5) { $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]); $defenderReconLevel[$counter] = $unitInfoZ["level"]; $defenderReconExp[$counter] = 2; $counter++; } // if } // if } // for } // for if ($attackerReconLevel[0] >= 1) { // add recon bonus for ($e = 0; $e < count($attackerReconLevel); $e++) { $attackerReconBonus += $attackerReconLevel[$e] * 0.25 + $attackerReconExp[$e]; } // for } // if if ($defenderReconLevel[0] >= 1) { for ($e = 0; $e < count($defenderReconLevel); $e++) { $defenderReconBonus += $defenderReconLevel[$e] * 0.25 + $defenderReconExp[$e]; } // for } // if $attackerExp = $attacker["exp"] + $attackerReconBonus; $defenderExp = $defender["exp"] + $defenderReconBonus; // Power Bonus from Artillery $counter = 0; // goes through -2 to +2 x and y positions looking for attacker artillery to aid attacker for ($x = -2; $x < 3; $x++) { for ($y = -2; $y < 3; $y++) { $unitInfoZ = getUnitInfo($getPage_connection2, $attacker["continent"], $attacker["xpos"] + $x, $attacker["ypos"] + $y); if ($unitInfoZ["id"] >= 1) { if ($unitInfoZ["type"] == 4) { $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]); $attackerArtilleryLevel[$counter] = $unitInfoZ["level"]; //$attackerArtilleryPower[$counter] = $unitTypeInfoZ["attack"]; $attackerArtilleryPower[$counter] = 2; $counter++; } // if } // if } // for } // for $counter = 0; // goes through -2 to +2 x and y positions looking for defender artillery to aid defender for ($x = -2; $x < 3; $x++) { for ($y = -2; $y < 3; $y++) { $unitInfoZ = getUnitInfo($getPage_connection2, $defender["continent"], $defender["xpos"] + $x, $defender["ypos"] + $y); if ($unitInfoZ["id"] >= 1) { if ($unitInfoZ["type"] == 4) { $unitTypeInfoZ = getUnitTypeInfo($getPage_connection2, $unitInfoZ["type"]); $defenderArtilleryLevel[$counter] = $unitInfoZ["level"]; //$defenderArtilleryPower[$counter] = $unitTypeInfoZ["attack"]; $defenderArtilleryPower[$counter] = 2; $counter++; } // if } // if } // for } // for if ($attackerArtilleryLevel[0] >= 1) { // add artillery bonus for ($e = 0; $e < count($attackerArtilleryLevel); $e++) { $attackerArtilleryBonus += $attackerArtilleryLevel[$e] * 0.25 + $attackerArtilleryPower[$e]; } // for } // if if ($defenderArtilleryLevel[0] >= 1) { for ($e = 0; $e < count($defenderArtilleryLevel); $e++) { $defenderArtilleryBonus += $defenderArtilleryLevel[$e] * 0.25 + $defenderArtilleryPower[$e]; } // for } // if $attackerA += $attackerArtilleryBonus; $attackerD += $attackerArtilleryBonus; $defenderA += $defenderArtilleryBonus; $defenderD += $defenderArtilleryBonus; $attackerA += $unitTypeInfoAttacker["attack"] + ($attacker["level"] * 0.25 + $attackerExp * 0.05); $attackerD += $unitTypeInfoAttacker["defense"] + ($attacker["level"] * 0.25 + $attackerExp * 0.05); $defenderA += $unitTypeInfoDefender["attack"] + ($defender["level"] * 0.25 + $defenderExp * 0.05); $defenderD += $unitTypeInfoDefender["defense"] + ($defender["level"] * 0.25 + $defenderExp * 0.05); $magnitude = 0; $formula = 0; // 1=winning,2=tie,3=losing $defenderModifier = 0.01 * $terrainInfoB["attackModifier"] * $defenderD; // add terrain modifier for defense bonus if ($amphibian == 1) { $defenderModifier = 0.25 * $defenderD; // add another +25% for amphibian assaults } // if // figure out which formula to use if ($attackerA > $defenderD + $defenderModifier) { // figure out category of combat if ($attackerA - ($defenderD + $defenderModifier) >= 4) { $magnitude = 5; } else { if ($attackerA - ($defenderD + $defenderModifier) >= 3) { $magnitude = 4; } else { if ($attackerA - ($defenderD + $defenderModifier) >= 2) { $magnitude = 3; } else { if ($attackerA - ($defenderD + $defenderModifier) >= 1) { $magnitude = 2; } else { $magnitude = 1; } } } } // else $formula = 1; } else { if ($attackerA == $defenderD + $defenderModifier) { $formula = 2; } else { // figure out category of combat if ($defenderD + $defenderModifier - $attackerA >= 4) { $magnitude = 5; } else { if ($defenderD + $defenderModifier - $attackerA >= 3) { $magnitude = 4; } else { if ($defenderD + $defenderModifier - $attackerA >= 2) { $magnitude = 3; } else { if ($defenderD + $defenderModifier - $attackerA >= 1) { $magnitude = 2; } else { $magnitude = 1; } } } } // else $formula = 3; } } // else $rand_attackerDamage = mt_rand(1, 100); $health_percent_attacker = 0; $health_percent_defender = 0; $new_defender_health = $defender["health"]; $new_attacker_health = $attacker["health"]; if ($formula == 1) { if ($magnitude == 5) { // 10% chance of receiving damage if ($rand_attackerDamage <= 10) { // attacker is damaged // health - 0-20% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(8, 10) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } // if // defender is damaged // health - 80-100% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(0, 2) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } else { if ($magnitude == 4) { // 15% chance of receiving damage if ($rand_attackerDamage <= 15) { // attacker is damaged // health - 20-40% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(6, 8) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } // if // defender is damaged // health - 60-80% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(2, 4) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } else { if ($magnitude == 3) { // 20% chance of receiving damage if ($rand_attackerDamage <= 20) { // attacker is damaged // health - 40-60% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(4, 6) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } // if // defender is damaged // health - 40-60% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(4, 6) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } else { if ($magnitude == 2) { // 25% chance of receiving damage if ($rand_attackerDamage <= 25) { // attacker is damaged // health - 60-80% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(2, 4) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } // if // defender is damaged // health - 20-40% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(6, 8) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } else { if ($magnitude == 1) { // 30% chance of receiving damage if ($rand_attackerDamage <= 30) { // attacker is damaged // health - 80-100% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(0, 2) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } // if // defender is damaged // health - 0-20% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(8, 10) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } } } } } // else if // set health setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]); setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]); } else { if ($formula == 2) { // 50% chance of receiving or dealing damage if ($rand_attackerDamage <= 50) { // attacker is damaged // health - 10-100% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(1, 10) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } else { // defender is damaged // health - 10-100% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(1, 10) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // else // set health setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]); setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]); } else { if ($formula == 3) { $rand_defenderDamage = mt_rand(1, 100); if ($magnitude == 5) { // 10% chance of receiving damage if ($rand_defenderDamage <= 10) { // defender is damaged // health - 0-20% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(8, 10) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // if // attacker is damaged // health - 80-100% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(0, 2) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } else { if ($magnitude == 4) { // 15% chance of receiving damage if ($rand_defenderDamage <= 15) { // defender is damaged // health - 20-40% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(6, 8) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // if // attacker is damaged // health - 60-80% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(2, 4) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } else { if ($magnitude == 3) { // 20% chance of receiving damage if ($rand_defenderDamage <= 20) { // defender is damaged // health - 40-60% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(4, 6) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // if // attacker is damaged // health - 40-60% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(4, 6) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } else { if ($magnitude == 2) { // 25% chance of receiving damage if ($rand_defenderDamage <= 25) { // defender is damaged // health - 60-80% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(2, 4) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // if // attacker is damaged // health - 20-40% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(6, 8) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } else { if ($magnitude == 1) { // 30% chance of receiving damage if ($rand_defenderDamage <= 30) { // defender is damaged // health - 80-100% of health $health_percent_defender = $defender["health"] * (1 - mt_rand(0, 2) * 0.1); $new_defender_health = $attacker["health"] - $health_percent_defender; } // if // attacker is damaged // health - 0-20% of health $health_percent_attacker = $attacker["health"] * (1 - mt_rand(8, 10) * 0.1); $new_attacker_health = $attacker["health"] - $health_percent_attacker; } } } } } // else if // set health setUnitInfo($getPage_connection2, $defender["id"], $defender["continent"], $defender["xpos"], $defender["ypos"], $new_defender_health, $defender["used"], $defender["name"], $defender["type"], $defender["owner"], $defender["level"], $defender["transport"], $defender["created"], $defender["exp"]); setUnitInfo($getPage_connection2, $attacker["id"], $attacker["continent"], $attacker["xpos"], $attacker["ypos"], $new_attacker_health, $attacker["used"], $attacker["name"], $attacker["type"], $attacker["owner"], $attacker["level"], $attacker["transport"], $attacker["created"], $attacker["exp"]); } else { } } } // else $newDefender = getUnitInfoByID($getPage_connection2, $defender["id"]); $newAttacker = getUnitInfoByID($getPage_connection2, $attacker["id"]); $defeat = ""; $attackerWins = false; $new_used = $newAttacker["used"] + 1; // if either party is killed, remove them from map if ($newDefender["health"] <= 0 || $newAttacker["health"] <= 0) { // defender dies if ($newDefender["health"] <= 0) { $defeat = "Unit " . $newDefender["name"] . " has been killed in combat!"; $attackerWins = true; if ($newDefender["transport"] >= 1) { $transportInfo = getTransportInfo($getPage_connection2, $newDefender["transport"]); for ($a = 0; $a < count($transportInfo); $a++) { deleteUnitInfo($getPage_connection2, $transportInfo["list"][$a]); } // for } // if deleteUnitInfo($getPage_connection2, $newDefender["id"]); // add experience $new_exp = 1 + $newAttacker["exp"]; setUnitInfo($getPage_connection2, $newAttacker["id"], $newAttacker["continent"], $newAttacker["xpos"], $newAttacker["ypos"], $new_attacker_health, $newAttacker["used"], $newAttacker["name"], $newAttacker["type"], $newAttacker["owner"], $newAttacker["level"], $newAttacker["transport"], $newAttacker["created"], $new_exp); // if amphibian combat if ($amphibian == 1) { $unitInfoTransport = getUnitInfo($getPage_connection2, $_SESSION["action_id"]); $transportInfoTransport = getTransportInfo($getPage_connection2, $unitInfoTransport["transport"]); // set new transport list $new_transport_list = array(0 => 0); $counterB = 0; for ($b = 0; $b < count($transportInfoTransport); $b++) { if ($b != 1) { $new_transport_list[$counterB] = $transportInfoTransport["list"][$b]; $counterB++; } // if } // for setTransportInfo($getPage_connection2, $unitInfoTransport["transport"], $new_transport_list); } // if setUnitInfo($getPage_connection2, $_SESSION["action_id"], $_SESSION["new_continent"], $_SESSION["new_xpos"], $_SESSION["new_ypos"], $newAttacker["health"], $new_used, $newAttacker["name"], $newAttacker["type"], $newAttacker["owner"], $newAttacker["level"], $newAttacker["transport"], $newAttacker["created"], $newAttacker["exp"]); } // if // attacker dies if ($newAttacker["health"] <= 0) { $defeat = "Unit " . $newAttacker["name"] . " has been killed in combat!"; $attackerWins = false; if ($newAttacker["transport"] >= 1) { $transportInfo = getTransportInfo($getPage_connection2, $newAttacker["transport"]); for ($a = 0; $a < count($transportInfo); $a++) { deleteUnitInfo($getPage_connection2, $transportInfo["list"][$a]); } // for } // if deleteUnitInfo($getPage_connection2, $newAttacker["id"]); // add experience $new_exp = 1 + $newDefender["exp"]; setUnitInfo($getPage_connection2, $newDefender["id"], $newDefender["continent"], $newDefender["xpos"], $newDefender["ypos"], $new_attacker_health, $newDefender["used"], $newDefender["name"], $newDefender["type"], $newDefender["owner"], $newDefender["level"], $newDefender["transport"], $newDefender["created"], $new_exp); } // if // otherwise bounce! } // if $attackerNationInfo = getNationInfo($getPage_connection2, $newAttacker["owner"]); $defenderNationInfo = getNationInfo($getPage_connection2, $newDefender["owner"]); $br1 = "<br />"; $enteredInto = "Unit " . $newAttacker["name"] . " of " . $attackerNationInfo["name"] . " has entered into combat with unit " . $newDefender["name"] . " of " . $defenderNationInfo["name"] . " !"; $suffering = "Unit " . $newAttacker["name"] . " has suffered " . $health_percent_attacker . " damage. Unit " . $newDefender["name"] . " has suffered " . $health_percent_defender . " damage!"; $_SESSION["success_message"] = $enteredInto . $br1 . $suffering . $br1 . $defeat; $log_message = $enteredInto . " " . $suffering . " " . $defeat; $new_date = date("Y-m-d H:i:s"); addCombatLogInfo($getPage_connection2, $new_date, $log_message, $attackerNationInfo["id"], $defenderNationInfo["id"]); } // if }
function transportUnit($getPage_connection2) { $validTransport = false; if ($_SESSION["action_id"] >= 1) { $unitInfoW = getUnitInfoByID($getPage_connection2, $_SESSION["action_id"]); // is it a valid entity? if ($unitInfoW["continent"] == $_SESSION["continent_id"] && $unitInfoW["xpos"] == $_SESSION["xpos"] && $unitInfoW["ypos"] == $_SESSION["ypos"]) { // is it owned by current player? if ($unitInfoW["owner"] == $_SESSION["nation_id"]) { $unitTypeInfoW = getUnitTypeInfo($getPage_connection2, $unitInfoW["type"]); // does unit have movement left? if ($unitInfoW["used"] < $unitTypeInfoW["movement"]) { $tileInfoW = getTileInfo($getPage_connection2, $_SESSION["new_continent"], $_SESSION["new_xpos"], $_SESSION["new_ypos"]); // land if ($unitTypeInfoW["water"] == 0) { // only water is applicable if ($tileInfoW["terrain"] == 2) { if ($_SESSION["new_continent"] == $_SESSION["continent_id"] && ($_SESSION["new_xpos"] >= $_SESSION["xpos"] - 1 && $_SESSION["new_xpos"] <= $_SESSION["xpos"] + 1) && ($_SESSION["new_ypos"] >= $_SESSION["ypos"] - 1 && $_SESSION["new_ypos"] <= $_SESSION["ypos"] + 1)) { $validTransport = true; } // if } // if // water units can't transport other water units! } else { $validTransport = false; } // else // transport is valid, move on to processing if ($validTransport === true) { $unitInfoC = getUnitInfo($getPage_connection2, $_SESSION["new_continent"], $_SESSION["new_xpos"], $_SESSION["new_ypos"]); // if friendly unit is found on destination tile, current unit does not move if ($unitInfoC["id"] >= 1) { // if transport is owned by player proceed if ($unitInfoC["owner"] == $_SESSION["nation_id"]) { $transportInfoC = getTransportInfo($getPage_connection2, $unitInfoC["transport"]); if ($transportInfoC["id"] >= 1) { if (count($transportInfoC["list"]) < 5) { $new_index = count($transportInfoC) + 1; $transportInfoC["list"][$new_index] = $_SESSION["action_id"]; setTransportInfo($getPage_connection2, $unitInfoC["transport"], $transportInfoC["list"]); $new_used = $unitInfoW["used"] + 1; $_SESSION["success_message"] = "Player's unit " . $unitInfoW["name"] . " has been transported successfully!"; setUnitInfo($getPage_connection2, $_SESSION["action_id"], $_SESSION["new_continent"], -1, -1, $unitInfoW["health"], $new_used, $unitInfoW["name"], $unitInfoW["type"], $unitInfoW["owner"], $unitInfoW["level"], $unitInfoW["transport"], $unitInfoW["created"], $unitInfoW["exp"]); } else { $_SESSION["warning_message"] = "Cannot complete action: transport is at full capacity."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: transport is invalid."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: transport not owned by player."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit cannot move to specified tile."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit cannot move to specified tile."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit does not have enough movement."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit is not owned by current player."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit is not valid."; } // else } else { $_SESSION["warning_message"] = "Cannot complete action: unit is not valid."; } // else }