function xenobetoplanet($planet_id)
{
    // Xenobe planet attack code
    global $playerinfo, $planetinfo, $torp_dmg_rate, $level_factor;
    global $rating_combat_factor, $upgrade_cost, $upgrade_factor, $sector_max, $xenobeisdead, $db;
    $resh = $db->Execute("LOCK TABLES {$db->prefix}ships WRITE, {$db->prefix}universe WRITE, {$db->prefix}planets WRITE, {$db->prefix}news WRITE, {$db->prefix}logs WRITE");
    db_op_result($db, $resh, __LINE__, __FILE__);
    $resultp = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=?", array($planet_id));
    // Get target planet information
    db_op_result($db, $resultp, __LINE__, __FILE__);
    $planetinfo = $resultp->fields;
    $resulto = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?", array($planetinfo['owner']));
    // Get target player information
    db_op_result($db, $resulto, __LINE__, __FILE__);
    $ownerinfo = $resulto->fields;
    $base_factor = $planetinfo['base'] == 'Y' ? $basedefense : 0;
    // Planet beams
    $targetbeams = NUM_BEAMS($ownerinfo['beams'] + $base_factor);
    if ($targetbeams > $planetinfo['energy']) {
        $targetbeams = $planetinfo['energy'];
    }
    $planetinfo['energy'] -= $targetbeams;
    // Planet shields
    $targetshields = NUM_SHIELDS($ownerinfo['shields'] + $base_factor);
    if ($targetshields > $planetinfo['energy']) {
        $targetshields = $planetinfo['energy'];
    }
    $planetinfo['energy'] -= $targetshields;
    // Planet torps
    $torp_launchers = round(pow($level_factor, $ownerinfo['torp_launchers'] + $base_factor)) * 10;
    $torps = $planetinfo['torps'];
    $targettorps = $torp_launchers;
    if ($torp_launchers > $torps) {
        $targettorps = $torps;
    }
    $planetinfo['torps'] -= $targettorps;
    $targettorpdmg = $torp_dmg_rate * $targettorps;
    // Planet fighters
    $targetfighters = $planetinfo['fighters'];
    // Attacker beams
    $attackerbeams = NUM_BEAMS($playerinfo['beams']);
    if ($attackerbeams > $playerinfo['ship_energy']) {
        $attackerbeams = $playerinfo['ship_energy'];
    }
    $playerinfo['ship_energy'] -= $attackerbeams;
    // Attacker shields
    $attackershields = NUM_SHIELDS($playerinfo['shields']);
    if ($attackershields > $playerinfo['ship_energy']) {
        $attackershields = $playerinfo['ship_energy'];
    }
    $playerinfo['ship_energy'] -= $attackershields;
    // Attacker torps
    $attackertorps = round(pow($level_factor, $playerinfo['torp_launchers'])) * 2;
    if ($attackertorps > $playerinfo['torps']) {
        $attackertorps = $playerinfo['torps'];
    }
    $playerinfo['torps'] -= $attackertorps;
    $attackertorpdamage = $torp_dmg_rate * $attackertorps;
    // Attacker fighters
    $attackerfighters = $playerinfo['ship_fighters'];
    // Attacker armor
    $attackerarmor = $playerinfo['armor_pts'];
    // Begin combat
    if ($attackerbeams > 0 && $targetfighters > 0) {
        if ($attackerbeams > $targetfighters) {
            $lost = $targetfighters;
            $targetfighters = 0;
            // Target loses all fighters
            $attackerbeams = $attackerbeams - $lost;
            // Attacker loses beams equal to Target fighters
        } else {
            $targetfighters = $targetfighters - $attackerbeams;
            // Target loses fighters equal to attacker beams
            $attackerbeams = 0;
            // Attacker loses all beams
        }
    }
    if ($attackerfighters > 0 && $targetbeams > 0) {
        if ($targetbeams > round($attackerfighters / 2)) {
            $lost = $attackerfighters - round($attackerfighters / 2);
            // Attacker loses half of all fighters
            $attackerfighters = $attackerfighters - $lost;
            $targetbeams = $targetbeams - $lost;
            // Target loses beams equal to half of attackers fighters
        } else {
            // Target beams are less than half of attackers fighters
            $attackerfighters = $attackerfighters - $targetbeams;
            // Attacker loses fighters equal to target beams
            $targetbeams = 0;
            // Target loses all beams
        }
    }
    if ($attackerbeams > 0) {
        if ($attackerbeams > $targetshields) {
            $attackerbeams = $attackerbeams - $targetshields;
            // Attacker loses beams equal to target shields
            $targetshields = 0;
            // Target loses all shields
        } else {
            $targetshields = $targetshields - $attackerbeams;
            // Target loses shields equal to attacker beams
            $attackerbeams = 0;
            // Attacker loses all beams
        }
    }
    if ($targetbeams > 0) {
        if ($targetbeams > $attackershields) {
            $targetbeams = $targetbeams - $attackershields;
            // Target loses beams equal to attacker shields
            $attackershields = 0;
            // Attacker loses all shields
        } else {
            $attackershields = $attackershields - $targetbeams;
            // Attacker loses sheilds equal to target beams
            $targetbeams = 0;
            // Target loses all beams
        }
    }
    if ($targetbeams > 0) {
        if ($targetbeams > $attackerarmor) {
            $targetbeams = $targetbeams - $attackerarmor;
            // Target loses beams equal to attacker armor
            $attackerarmor = 0;
            // Attacker loses all armor (attacker destroyed)
        } else {
            $attackerarmor = $attackerarmor - $targetbeams;
            // Attacker loses armor equal to target beams
            $targetbeams = 0;
            // Target loses all beams
        }
    }
    if ($targetfighters > 0 && $attackertorpdamage > 0) {
        if ($attackertorpdamage > $targetfighters) {
            $lost = $targetfighters;
            $targetfighters = 0;
            // Target loses all fighters
            $attackertorpdamage = $attackertorpdamage - $lost;
            // Attacker loses fired torpedoes equal to target fighters
        } else {
            $targetfighters = $targetfighters - $attackertorpdamage;
            // Target loses fighters equal to attacker torpedoes fired
            $attackertorpdamage = 0;
            // Attacker loses all torpedoes fired
        }
    }
    if ($attackerfighters > 0 && $targettorpdmg > 0) {
        if ($targettorpdmg > round($attackerfighters / 2)) {
            $lost = $attackerfighters - round($attackerfighters / 2);
            $attackerfighters = $attackerfighters - $lost;
            // Attacker loses half of all fighters
            $targettorpdmg = $targettorpdmg - $lost;
            // Target loses fired torpedoes equal to half of attacker fighters
        } else {
            // Target fired torpedoes less than or equal to half of attacker fighters
            $attackerfighters = $attackerfighters - $targettorpdmg;
            // Attacker loses fighters equal to target torpedoes fired
            $targettorpdmg = 0;
            // Tartget loses all torpedoes fired
        }
    }
    if ($targettorpdmg > 0) {
        if ($targettorpdmg > $attackerarmor) {
            $targettorpdmg = $targettorpdmg - $attackerarmor;
            // Target loses fired torpedoes equal to attacker armor
            $attackerarmor = 0;
            // Attacker loses all armor (Attacker destroyed)
        } else {
            // Target fired torpedoes less than or equal to half attacker armor
            $attackerarmor = $attackerarmor - $targettorpdmg;
            // Attacker loses armor equal to the target torpedoes fired
            $targettorpdmg = 0;
            // Target loses all torpedoes fired
        }
    }
    if ($attackerfighters > 0 && $targetfighters > 0) {
        if ($attackerfighters > $targetfighters) {
            $temptargfighters = 0;
            // Target will lose all fighters
        } else {
            // Attackers fighters less than or equal to target fighters
            $temptargfighters = $targetfighters - $attackerfighters;
            // Target will loose fighters equal to attacker fighters
        }
        if ($targetfighters > $attackerfighters) {
            // Target fighters greater than attackers fighters
            $tempplayfighters = 0;
            // Attackerwill loose ALL fighters
        } else {
            // Target fighters less than or equal to attackers fighters
            $tempplayfighters = $attackerfighters - $targetfighters;
            // Attacker will loose fighters equal to target fighters
        }
        $attackerfighters = $tempplayfighters;
        $targetfighters = $temptargfighters;
    }
    if ($targetfighters > 0) {
        if ($targetfighters > $attackerarmor) {
            // Target fighters greater than attackers armor
            $attackerarmor = 0;
            // attacker loses all armor (attacker destroyed)
        } else {
            // Target fighters less than or equal to attackers armor
            $attackerarmor = $attackerarmor - $targetfighters;
            // attacker loses armor equal to target fighters
        }
    }
    // Fix negative values
    if ($attackerfighters < 0) {
        $attackerfighters = 0;
    }
    if ($attackertorps < 0) {
        $attackertorps = 0;
    }
    if ($attackershields < 0) {
        $attackershields = 0;
    }
    if ($attackerbeams < 0) {
        $attackerbeams = 0;
    }
    if ($attackerarmor < 0) {
        $attackerarmor = 0;
    }
    if ($targetfighters < 0) {
        $targetfighters = 0;
    }
    if ($targettorps < 0) {
        $targettorps = 0;
    }
    if ($targetshields < 0) {
        $targetshields = 0;
    }
    if ($targetbeams < 0) {
        $targetbeams = 0;
    }
    if (!$attackerarmor > 0) {
        playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Ship destroyed by planetary defenses on planet {$planetinfo['name']}");
        db_kill_player($playerinfo['ship_id']);
        $xenobeisdead = 1;
        $free_ore = round($playerinfo['ship_ore'] / 2);
        $free_organics = round($playerinfo['ship_organics'] / 2);
        $free_goods = round($playerinfo['ship_goods'] / 2);
        $ship_value = $upgrade_cost * (round(pow($upgrade_factor, $playerinfo['hull'])) + round(pow($upgrade_factor, $playerinfo['engines'])) + round(pow($upgrade_factor, $playerinfo['power'])) + round(pow($upgrade_factor, $playerinfo['computer'])) + round(pow($upgrade_factor, $playerinfo['sensors'])) + round(pow($upgrade_factor, $playerinfo['beams'])) + round(pow($upgrade_factor, $playerinfo['torp_launchers'])) + round(pow($upgrade_factor, $playerinfo['shields'])) + round(pow($upgrade_factor, $playerinfo['armor'])) + round(pow($upgrade_factor, $playerinfo['cloak'])));
        $ship_salvage_rate = mt_rand(10, 20);
        $ship_salvage = $ship_value * $ship_salvage_rate / 100;
        $fighters_lost = $planetinfo['fighters'] - $targetfighters;
        // Log attack to planet owner
        playerlog($db, $planetinfo['owner'], LOG_PLANET_NOT_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|Xenobe {$playerinfo['character_name']}|{$free_ore}|{$free_organics}|{$free_goods}|{$ship_salvage_rate}|{$ship_salvage}");
        // Update planet
        $resi = $db->Execute("UPDATE {$db->prefix}planets SET energy=?, fighters=fighters-?, torps=torps-?, ore=ore+?, goods=goods+?, organics=organics+?, credits=credits+? WHERE planet_id=?", array($planetinfo['energy'], $fighters_lost, $targettorps, $free_ore, $free_goods, $free_organics, $ship_salvage, $planetinfo['planet_id']));
        db_op_result($db, $resi, __LINE__, __FILE__);
    } else {
        $armor_lost = $playerinfo['armor_pts'] - $attackerarmor;
        $fighters_lost = $playerinfo['ship_fighters'] - $attackerfighters;
        $target_fighters_lost = $planetinfo['ship_fighters'] - $targetfighters;
        playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Made it past defenses on planet {$planetinfo['name']}");
        // Update attackers
        $resj = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy=?, ship_fighters=ship_fighters-?, torps=torps-?, armor_pts=armor_pts-? WHERE ship_id=?", array($playerinfo['ship_energy'], $fighters_lost, $attackertorps, $armor_lost, $playerinfo['ship_id']));
        db_op_result($db, $resj, __LINE__, __FILE__);
        $playerinfo['ship_fighters'] = $attackerfighters;
        $playerinfo['torps'] = $attackertorps;
        $playerinfo['armor_pts'] = $attackerarmor;
        // Update planet
        $resk = $db->Execute("UPDATE {$db->prefix}planets SET energy=?, fighters=?, torps=torps-? WHERE planet_id=?", array($planetinfo['energy'], $targetfighters, $targettorps, $planetinfo['planet_id']));
        db_op_result($db, $resk, __LINE__, __FILE__);
        $planetinfo['fighters'] = $targetfighters;
        $planetinfo['torps'] = $targettorps;
        // Now we must attack all ships on the planet one by one
        $resultps = $db->Execute("SELECT ship_id,ship_name FROM {$db->prefix}ships WHERE planet_id=? AND on_planet='Y'", array($planetinfo['planet_id']));
        db_op_result($db, $resultps, __LINE__, __FILE__);
        $shipsonplanet = $resultps->RecordCount();
        if ($shipsonplanet > 0) {
            while (!$resultps->EOF && $xenobeisdead < 1) {
                $onplanet = $resultps->fields;
                xenobetoship($onplanet['ship_id']);
                $resultps->MoveNext();
            }
        }
        $resultps = $db->Execute("SELECT ship_id,ship_name FROM {$db->prefix}ships WHERE planet_id=? AND on_planet='Y'", array($planetinfo['planet_id']));
        db_op_result($db, $resultps, __LINE__, __FILE__);
        $shipsonplanet = $resultps->RecordCount();
        if ($shipsonplanet == 0 && $xenobeisdead < 1) {
            // Must have killed all ships on the planet
            playerlog($db, $playerinfo['ship_id'], LOG_RAW, "Defeated all ships on planet {$planetinfo['name']}");
            // Log attack to planet owner
            playerlog($db, $planetinfo['owner'], LOG_PLANET_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|{$playerinfo['character_name']}");
            // Update planet
            $resl = $db->Execute("UPDATE {$db->prefix}planets SET fighters=0, torps=0, base='N', owner=0, corp=0 WHERE planet_id=?", array($planetinfo['planet_id']));
            db_op_result($db, $resl, __LINE__, __FILE__);
            calc_ownership($planetinfo['sector_id']);
        } else {
            // Must have died trying
            playerlog($db, $playerinfo['ship_id'], LOG_RAW, "We were KILLED by ships defending planet {$planetinfo['name']}");
            // Log attack to planet owner
            playerlog($db, $planetinfo['owner'], LOG_PLANET_NOT_DEFEATED, "{$planetinfo['name']}|{$playerinfo['sector']}|Xenobe {$playerinfo['character_name']}|0|0|0|0|0");
            // No salvage for planet because it went to the ship that won
        }
    }
    $resx = $db->Execute("UNLOCK TABLES");
    db_op_result($db, $resx, __LINE__, __FILE__);
}
示例#2
0
 message_defence_owner($db, $sector, $l_chm_hehitminesinsector);
 // If the player has enough mine deflectors then subtract the ammount and continue
 if ($playerinfo['dev_minedeflector'] >= $roll) {
     $l_chm_youlostminedeflectors = str_replace("[chm_roll]", $roll, $l_chm_youlostminedeflectors);
     echo $l_chm_youlostminedeflectors . "<br>";
     $result2 = $db->Execute("UPDATE {$db->prefix}ships SET dev_minedeflector=dev_minedeflector-? WHERE ship_id=?;", array($roll, $playerinfo['ship_id']));
     db_op_result($db, $result2, __LINE__, __FILE__, $db_logging);
 } else {
     if ($playerinfo['dev_minedeflector'] > 0) {
         echo $l_chm_youlostallminedeflectors . "<br>";
     } else {
         echo $l_chm_youhadnominedeflectors . "<br>";
     }
     // Shields up
     $mines_left = $roll - $playerinfo['dev_minedeflector'];
     $playershields = NUM_SHIELDS($playerinfo['shields']);
     if ($playershields > $playerinfo['ship_energy']) {
         $playershields = $playerinfo['ship_energy'];
     }
     if ($playershields >= $mines_left) {
         $l_chm_yourshieldshitforminesdmg = str_replace("[chm_mines_left]", $mines_left, $l_chm_yourshieldshitforminesdmg);
         echo $l_chm_yourshieldshitforminesdmg . "<br>";
         $result2 = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy=ship_energy-?, dev_minedeflector=0 WHERE ship_id=?;", array($mines_left, $playerinfo['ship_id']));
         db_op_result($db, $result2, __LINE__, __FILE__, $db_logging);
         if ($playershields == $mines_left) {
             echo $l_chm_yourshieldsaredown . "<br>";
         }
     } else {
         // Direct hit
         echo $l_chm_youlostallyourshields . "<br>";
         $mines_left = $mines_left - $playershields;
示例#3
0
         echo "$l_chm_youlostminedeflectors<BR>";
         $result2 = $db->Execute("UPDATE $dbtables[ships] set dev_minedeflector=dev_minedeflector-$roll where player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");

      } else {
            if($shipinfo[dev_minedeflector] > 0)
            {
               echo "$l_chm_youlostallminedeflectors<BR>";
            }
            else
            {
               echo "$l_chm_youhadnominedeflectors<BR>";
            }
         
            // Shields up sir!
            $mines_left = $roll - $shipinfo[dev_minedeflector];
            $playershields = NUM_SHIELDS($shipinfo[shields]);
            if($playershields > $shipinfo[ship_energy])
            {
               $playershields=$shipinfo[ship_energy];
            }
            if($playershields >= $mines_left)
            {
               $l_chm_yourshieldshitforminesdmg = str_replace("[chm_mines_left]", $mines_left, $l_chm_yourshieldshitforminesdmg);
               echo "$l_chm_yourshieldshitforminesdmg<BR>";

               $result2 = $db->Execute("UPDATE $dbtables[ships] set ship_energy=ship_energy-$mines_left, dev_minedeflector=0 where player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");
               if($playershields == $mines_left)
                  echo "$l_chm_yourshieldsaredown<BR>";
            }
            else
            {
示例#4
0
        $targetbeams=$targetshipinfo[ship_energy];
      }
      $targetshipinfo[ship_energy]=$targetshipinfo[ship_energy]-$targetbeams;
      $playerbeams = NUM_BEAMS($shipinfo[beams]);
      if($playerbeams>$shipinfo[ship_energy])
      {
        $playerbeams=$shipinfo[ship_energy];
      }
      $shipinfo[ship_energy]=$shipinfo[ship_energy]-$playerbeams;
      $playershields = NUM_SHIELDS($shipinfo[shields]);
      if($playershields>$shipinfo[ship_energy])
      {
        $playershields=$shipinfo[ship_energy];
      }
      $shipinfo[ship_energy]=$shipinfo[ship_energy]-$playershields;
      $targetshields = NUM_SHIELDS($targetshipinfo[shields]);
      if($targetshields>$targetshipinfo[ship_energy])
      {
        $targetshields=$targetshipinfo[ship_energy];
      }
      $targetshipinfo[ship_energy]=$targetshipinfo[ship_energy]-$targetshields;

      $playertorpnum = floor(mypw($level_factor,$shipinfo[torp_launchers]))*2;
      if($playertorpnum > $shipinfo[torps])
      {
        $playertorpnum = $shipinfo[torps];
      }
      $targettorpnum = floor(mypw($level_factor,$targetshipinfo[torp_launchers]))*2;
      if($targettorpnum > $targetshipinfo[torps])
      {
        $targettorpnum = $targetshipinfo[torps];
示例#5
0
function shiptoship($target_id)
{
	global $upgrade_cost, $upgrade_factor;
    global $attackerbeams;
    global $attackerfighters;
    global $attackershields;
    global $attackertorps;
    global $attackerarmor;
    global $attackertorpdamage;
    global $start_energy;
    global $playerinfo;
    global $l_cmb_attackershields, $l_cmb_attackertorps, $l_cmb_attackerarmor, $l_cmb_attackertorpdamage;
    global $l_cmb_startingstats, $l_cmb_statattackerbeams, $l_cmb_statattackerfighters, $l_cmb_statattackershields, $l_cmb_statattackertorps;
    global $l_cmb_statattackerarmor, $l_cmb_statattackertorpdamage, $l_cmb_isattackingyou, $l_cmb_beamexchange, $l_cmb_beamsdestroy;
    global $l_cmb_beamsdestroy2, $l_cmb_nobeamsareleft, $l_cmb_beamshavenotarget, $l_cmb_fighterdestroyedbybeams, $l_cmb_beamsdestroystillhave;
    global $l_cmb_fighterunhindered, $l_cmb_youhavenofightersleft, $l_cmb_breachedsomeshields, $l_cmb_shieldsarehitbybeams, $l_cmb_nobeamslefttoattack;
    global $l_cmb_yourshieldsbreachedby, $l_cmb_yourshieldsarehit, $l_cmb_hehasnobeamslefttoattack, $l_cmb_yourbeamsbreachedhim;
    global $l_cmb_yourbeamshavedonedamage, $l_cmb_nobeamstoattackarmor, $l_cmb_yourarmorbreachedbybeams, $l_cmb_yourarmorhitdamaged;
    global $l_cmb_torpedoexchange, $l_cmb_hehasnobeamslefttoattackyou, $l_cmb_yourtorpsdestroy, $l_cmb_yourtorpsdestroy2;
    global $l_cmb_youhavenotorpsleft, $l_cmb_hehasnofighterleft, $l_cmb_torpsdestroyyou, $l_cmb_someonedestroyedfighters, $l_cmb_hehasnotorpsleftforyou;
    global $l_cmb_youhavenofightersanymore, $l_cmb_youbreachedwithtorps, $l_cmb_hisarmorishitbytorps, $l_cmb_notorpslefttoattackarmor;
    global $l_cmb_yourarmorbreachedbytorps, $l_cmb_yourarmorhitdmgtorps, $l_cmb_hehasnotorpsforyourarmor, $l_cmb_fightersattackexchange;
    global $l_cmb_enemylostallfighters, $l_cmb_helostsomefighters, $l_cmb_youlostallfighters, $l_cmb_youalsolostsomefighters, $l_cmb_hehasnofightersleftattack;
    global $l_cmb_younofightersattackleft, $l_cmb_youbreachedarmorwithfighters, $l_cmb_youhitarmordmgfighters, $l_cmb_youhavenofighterstoarmor;
    global $l_cmb_hasbreachedarmorfighters, $l_cmb_yourarmorishitfordmgby, $l_cmb_nofightersleftheforyourarmor, $l_cmb_hehasbeendestroyed;
    global $l_cmb_escapepodlaunched, $l_cmb_yousalvaged, $l_cmb_youdidntdestroyhim, $l_cmb_shiptoshipcombatstats;
    global $db, $dbtables;

    //$db->Execute("LOCK TABLES $dbtables[players] WRITE, $dbtables[ships] WRITE, $dbtables[universe] WRITE, $dbtables[zones] READ");
    $result2 = $db->Execute ("SELECT * FROM $dbtables[ships] WHERE ship_id=$target_id");
    $targetshipinfo=$result2->fields;
    $result2 = $db->Execute ("SELECT * FROM $dbtables[players] WHERE player_id=$targetshipinfo[player_id]");
    $targetinfo=$result2->fields;

    $targetbeams = NUM_BEAMS($targetshipinfo[beams]);
    if($targetbeams>$targetshipinfo[ship_energy])
    {
        $targetbeams=$targetshipinfo[ship_energy];
    }
    $targetshipinfo[ship_energy]=$targetshipinfo[ship_energy]-$targetbeams;
    $targetshields = NUM_SHIELDS($targetshipinfo[shields]);
    if($targetshields>$targetshipinfo[ship_energy])
    {
        $targetshields=$targetshipinfo[ship_energy];
    }
    $targetshipinfo[ship_energy]=$targetshipinfo[ship_energy]-$targetshields;

    $targettorpnum = round(mypw($level_factor,$targetshipinfo[torp_launchers]))*2;
    if($targettorpnum > $targetshipinfo[torps])
    {
        $targettorpnum = $targetshipinfo[torps];
    }
    $targettorpdmg = $torp_dmg_rate*$targettorpnum;
    $targetarmor = $targetshipinfo[armour_pts];
    $targetfighters = $targetshipinfo[ship_fighters];
    $targetdestroyed = 0;
    $playerdestroyed = 0;
    echo "-->$targetshipinfo[ship_name] $l_cmb_isattackingyou<BR><BR>";
	// ***************** BEAM EXCHANGE *************************
    echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_beamexchange</font><BR>";
    if($targetfighters > 0 && $attackerbeams > 0)
    {
        if($attackerbeams > round($targetfighters / 2))
        {
            $temp = round($targetfighters/2);
            $lost = $targetfighters-$temp;
            $targetfighters = $temp;
            $attackerbeams = $attackerbeams-$lost;
            $l_cmb_beamsdestroy = str_replace("[cmb_lost]", $lost, $l_cmb_beamsdestroy);
            echo "<-- $l_cmb_beamsdestroy<BR>";
        }
        else
        {
            $targetfighters = $targetfighters-$attackerbeams;
            $l_cmb_beamsdestroy2 = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_beamsdestroy2);
            echo "--> $l_cmb_beamsdestroy2<BR>";
            $attackerbeams = 0;
        }
    }
    elseif ($targetfighters > 0 && $attackerbeams < 1)
    echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_nobeamsareleft</font><BR>";
    else
        echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_beamshavenotarget</font><BR>";
    if($attackerfighters > 0 && $targetbeams > 0)
    {
        if($targetbeams > round($attackerfighters / 2))
        {
            $temp=round($attackerfighters/2);
            $lost=$attackerfighters-$temp;
            $attackerfighters=$temp;
            $targetbeams=$targetbeams-$lost;
            $l_cmb_fighterdestroyedbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_fighterdestroyedbybeams);
            $l_cmb_fighterdestroyedbybeams = str_replace("[cmb_lost]", $lost, $l_cmb_fighterdestroyedbybeams);
            echo "--> $l_cmb_fighterdestroyedbybeams";
        }
        else
        {
            $attackerfighters=$attackerfighters-$targetbeams;
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_beamsdestroystillhave);
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_beamsdestroystillhave);
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_beamsdestroystillhave);
            echo "<-- $l_cmb_beamsdestroystillhave<BR>";
            $targetbeams=0;
        }
    }
    elseif ($attackerfighters > 0 && $targetbeams < 1)
    echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_fighterunhindered</font><BR>";
    else
        echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_youhavenofightersleft</font><BR>";
    if($attackerbeams > 0)
    {
        if($attackerbeams > $targetshields)
        {
            $attackerbeams=$attackerbeams-$targetshields;
            $targetshields=0;
            $l_cmb_breachedsomeshields = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_breachedsomeshields);
            echo "<-- $l_cmb_breachedsomeshields<BR>";
        }
        else
        {
            $l_cmb_shieldsarehitbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_shieldsarehitbybeams);
            $l_cmb_shieldsarehitbybeams = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_shieldsarehitbybeams);
            echo "$l_cmb_shieldsarehitbybeams<BR>";
            $targetshields=$targetshields-$attackerbeams;
            $attackerbeams=0;
        }
    }
    else
    {
        $l_cmb_nobeamslefttoattack = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_nobeamslefttoattack);
        echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_nobeamslefttoattack</font><BR>";
    }
    if($targetbeams > 0)
    {
        if($targetbeams > $attackershields)
        {
            $targetbeams=$targetbeams-$attackershields;
            $attackershields=0;
            $l_cmb_yourshieldsbreachedby = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourshieldsbreachedby);
            echo "--> $l_cmb_yourshieldsbreachedby<BR>";
        }
        else
        {
            $l_cmb_yourshieldsarehit = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourshieldsarehit);
            $l_cmb_yourshieldsarehit = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_yourshieldsarehit);
            echo "<-- $l_cmb_yourshieldsarehit<BR>";
            $attackershields=$attackershields-$targetbeams;
            $targetbeams=0;
        }
    }
    else
    {
        $l_cmb_hehasnobeamslefttoattack = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnobeamslefttoattack);
        echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_hehasnobeamslefttoattack</font><BR>";
    }
    if($attackerbeams > 0)
    {
        if($attackerbeams > $targetarmor)
        {
            $targetarmor=0;
            $l_cmb_yourbeamsbreachedhim = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourbeamsbreachedhim);
            echo "--> $l_cmb_yourbeamsbreachedhim<BR>";
        }
        else
        {
            $targetarmor=$targetarmor-$attackerbeams;
            $l_cmb_yourbeamshavedonedamage = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_yourbeamshavedonedamage);
            $l_cmb_yourbeamshavedonedamage = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourbeamshavedonedamage);
            echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_yourbeamshavedonedamage</font><BR>";
        }
    }
    else
    {
        $l_cmb_nobeamstoattackarmor = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_nobeamstoattackarmor);
        echo "<FONT SIZE='+2' COLOR='RED'>$l_cmb_nobeamstoattackarmor</font><BR>";
    }
    if($targetbeams > 0)
    {
        if($targetbeams > $attackerarmor)
        {
            $attackerarmor=0;
            $l_cmb_yourarmorbreachedbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourarmorbreachedbybeams);
            echo "--> $l_cmb_yourarmorbreachedbybeams<BR>";
        }
        else
        {
            $attackerarmor=$attackerarmor-$targetbeams;
            $l_cmb_yourarmorhitdamaged = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourarmorhitdamaged);
            $l_cmb_yourarmorhitdamaged = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_yourarmorhitdamaged);
            echo "<-- $l_cmb_yourarmorhitdamaged<BR>";
        }
    }
    else
    {
        $l_cmb_hehasnobeamslefttoattackyou = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnobeamslefttoattackyou);
        echo "$l_cmb_hehasnobeamslefttoattackyou<BR>";
    }
	// ****************** TORPEDO EXCHANGE ***********************
    echo "<BR><FONT SIZE='+2' COLOR='RED'>$l_cmb_torpedoexchange</font><BR>";
    if($targetfighters > 0 && $attackertorpdamage > 0)
    {
        if($attackertorpdamage > round($targetfighters / 2))
        {
            $temp=round($targetfighters/2);
            $lost=$targetfighters-$temp;
            $targetfighters=$temp;
            $attackertorpdamage=$attackertorpdamage-$lost;
            $l_cmb_yourtorpsdestroy = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourtorpsdestroy);
            $l_cmb_yourtorpsdestroy = str_replace("[cmb_lost]", $lost, $l_cmb_yourtorpsdestroy);
            echo "--> $l_cmb_yourtorpsdestroy<BR>";
        }
        else
        {
            $targetfighters=$targetfighters-$attackertorpdamage;
            $l_cmb_yourtorpsdestroy2 = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourtorpsdestroy2);
            $l_cmb_yourtorpsdestroy2 = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $l_cmb_yourtorpsdestroy2);
            echo "<-- $l_cmb_yourtorpsdestroy2<BR>";
            $attackertorpdamage=0;
        }
    }
    elseif ($targetfighters > 0 && $attackertorpdamage < 1)
    {
        $l_cmb_youhavenotorpsleft = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youhavenotorpsleft);
        echo "$l_cmb_youhavenotorpsleft<BR>";
    }
    else
    {
        $l_cmb_hehasnofighterleft = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnofighterleft);
        echo "$_cmb_hehasnofighterleft<BR>";
    }
    if($attackerfighters > 0 && $targettorpdmg > 0)
    {
        if($targettorpdmg > round($attackerfighters / 2))
        {
            $temp=round($attackerfighters/2);
            $lost=$attackerfighters-$temp;
            $attackerfighters=$temp;
            $targettorpdmg=$targettorpdmg-$lost;
            $l_cmb_torpsdestroyyou = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_torpsdestroyyou);
            $l_cmb_torpsdestroyyou = str_replace("[cmb_lost]", $lost, $l_cmb_torpsdestroyyou);
            echo "--> $l_cmb_torpsdestroyyou<BR>";
        }
        else
        {
            $attackerfighters=$attackerfighters-$targettorpdmg;
            $l_cmb_someonedestroyedfighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_someonedestroyedfighters);
            $l_cmb_someonedestroyedfighters = str_replace("[cmb_targettorpdmg]", $targettorpdmg, $l_cmb_someonedestroyedfighters);
            echo "<-- $l_cmb_someonedestroyedfighters<BR>";
            $targettorpdmg=0;
        }
    }
    elseif ($attackerfighters > 0 && $targettorpdmg < 1)
    {
        $l_cmb_hehasnotorpsleftforyou = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnotorpsleftforyou);
        echo "$l_cmb_hehasnotorpsleftforyou<BR>";
    }
    else
    {
        $l_cmb_youhavenofightersanymore = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youhavenofightersanymore);
        echo "$l_cmb_youhavenofightersanymore<BR>";
    }
    if($attackertorpdamage > 0)
    {
        if($attackertorpdamage > $targetarmor)
        {
            $targetarmor=0;
            $l_cmb_youbreachedwithtorps = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youbreachedwithtorps);
            echo "--> $l_cmb_youbreachedwithtorps<BR>";
        }
        else
        {
            $targetarmor=$targetarmor-$attackertorpdamage;
            $l_cmb_hisarmorishitbytorps = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hisarmorishitbytorps);
            $l_cmb_hisarmorishitbytorps = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $l_cmb_hisarmorishitbytorps);
            echo "<-- $l_cmb_hisarmorishitbytorps<BR>";
        }
    }
    else
    {
        $l_cmb_notorpslefttoattackarmor = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_notorpslefttoattackarmor);
        echo "$l_cmb_notorpslefttoattackarmor<BR>";
    }
    if($targettorpdmg > 0)
    {
        if($targettorpdmg > $attackerarmor)
        {
            $attackerarmor=0;
            $l_cmb_yourarmorbreachedbytorps = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourarmorbreachedbytorps);
            echo "<-- $l_cmb_yourarmorbreachedbytorps<BR>";
        }
        else
        {
            $attackerarmor=$attackerarmor-$targettorpdmg;
            $l_cmb_yourarmorhitdmgtorps = str_replace("[cmb_targettorpdmg]", $targettorpdmg, $l_cmb_yourarmorhitdmgtorps);
            $l_cmb_yourarmorhitdmgtorps = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourarmorhitdmgtorps);
            echo "<-- $l_cmb_yourarmorhitdmgtorps<BR>";
        }
    }
    else
    {
        $l_cmb_hehasnotorpsforyourarmor = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnotorpsforyourarmor);
        echo "$l_cmb_hehasnotorpsforyourarmor<BR>";
    }
	// *******************8 FIGHTERS EXCHANGE ******************	
    echo "<BR><FONT SIZE='+2' COLOR='RED'>$l_cmb_fightersattackexchange</FONT><BR>";
    if($attackerfighters > 0 && $targetfighters > 0)
    {
        if($attackerfighters > $targetfighters)
        {
            $l_cmb_enemylostallfighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_enemylostallfighters);
            echo "--> $l_cmb_enemylostallfighters<BR>";
            $temptargfighters=0;
        }
        else
        {
            $l_cmb_helostsomefighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_helostsomefighters);
            $l_cmb_helostsomefighters = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_helostsomefighters);
            echo "$l_cmb_helostsomefighters<BR>";
            $temptargfighters=$targetfighters-$attackerfighters;
        }
        if($targetfighters > $attackerfighters)
        {
            echo "<-- $l_cmb_youlostallfighters<BR>";
            $tempplayfighters=0;
        }
        else
        {
            $l_cmb_youalsolostsomefighters = str_replace("[cmb_targetfighters]", $targetfighters, $l_cmb_youalsolostsomefighters);
            echo "<-- $l_cmb_youalsolostsomefighters<BR>";
            $tempplayfighters=$attackerfighters-$targetfighters;
        }
        $attackerfighters=$tempplayfighters;
        $targetfighters=$temptargfighters;
    }
    elseif ($attackerfighters > 0 && $targetfighters < 1)
    {
        $l_cmb_hehasnofightersleftattack = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasnofightersleftattack);
        echo "$l_cmb_hehasnofightersleftattack<BR>";
    }
    else
    {
        $l_cmb_younofightersattackleft = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_younofightersattackleft);
        echo "$l_cmb_younofightersattackleft<BR>";
    }
    if($attackerfighters > 0)
    {
        if($attackerfighters > $targetarmor)
        {
            $targetarmor=0;
            $l_cmb_youbreachedarmorwithfighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youbreachedarmorwithfighters);
            echo "--> $l_cmb_youbreachedarmorwithfighters<BR>";
        }
        else
        {
            $targetarmor=$targetarmor-$attackerfighters;
            $l_cmb_youhitarmordmgfighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youhitarmordmgfighters);
            $l_cmb_youhitarmordmgfighters = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_youhitarmordmgfighters);
            echo "<-- $l_cmb_youhitarmordmgfighters<BR>";
        }
    }
    else
    {
        $l_cmb_youhavenofighterstoarmor = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youhavenofighterstoarmor);
        echo "$l_cmb_youhavenofighterstoarmor<BR>";
    }
    if($targetfighters > 0)
    {
        if($targetfighters > $attackerarmor)
        {
            $attackerarmor=0;
            $l_cmb_hasbreachedarmorfighters = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hasbreachedarmorfighters);
            echo "<-- $l_cmb_hasbreachedarmorfighters<BR>";
        }
        else
        {
            $attackerarmor=$attackerarmor-$targetfighters;
            $l_cmb_yourarmorishitfordmgby = str_replace("[cmb_targetfighters]", $targetfighters, $l_cmb_yourarmorishitfordmgby);
            $l_cmb_yourarmorishitfordmgby = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_yourarmorishitfordmgby);
            echo "--> $l_cmb_yourarmorishitfordmgby<BR>";
        }
    }
    else
    {
        $l_cmb_nofightersleftheforyourarmor = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_nofightersleftheforyourarmor);
        echo "$l_cmb_nofightersleftheforyourarmor<BR>";
    }
    if($targetarmor < 1)
    {
        $l_cmb_hehasbeendestroyed = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_hehasbeendestroyed);
        echo "<BR>$l_cmb_hehasbeendestroyed<BR>";
		// news
		$headline="Ship blown up on planet!";
		$newstext="The ship ".$targetshipinfo[ship_name]." was destroyed today by ".$playerinfo[character_name]." during a planet attack. ";
        if($targetshipinfo[dev_escapepod] == "Y")
        {
            $rating=round($targetinfo[rating]/2);
            echo "$l_cmb_escapepodlaunched<BR><BR>";
            echo "<BR><BR>player_id=$targetinfo[player_id]<BR><BR>";
            $test = $db->Execute("UPDATE $dbtables[players] SET on_planet='N',rating='$rating',sector=0 WHERE player_id=$targetinfo[player_id]");
			// Immediately release any ships being towed 
    		if ($targetshipinfo[tow] > 0) {
				$db->Execute("UPDATE $dbtables[ships] SET player_id=0,on_planet='N',sector=$targetshipinfo[sector] WHERE ship_id=$targetshipinfo[tow]");
  			}
			$db->Execute("UPDATE $dbtables[ships] SET ship_destroyed ='Y', sector=0, tow=0 WHERE player_id=$targetinfo[player_id] AND ship_id=$targetinfo[currentship]");
            playerlog($targetinfo[player_id],LOG_ATTACK_LOSE, "$playerinfo[character_name]|Y");
            collect_bounty($playerinfo[player_id],$targetinfo[player_id]);
			$newstext = $newstext.$targetinfo[character_name]." survived and podded off to Sector 0.";
        }
        else
        {
            playerlog($targetinfo[player_id], LOG_ATTACK_LOSE, "$playerinfo[character_name]|N");
            db_kill_player($targetinfo[player_id],$targetinfo[currentship],$playerinfo[player_id]);
            collect_bounty($playerinfo[player_id],$targetinfo[player_id]);
			$newstext .= $targetinfo[character_name]." did not survive the attack.";
        }
		$newstext = addslashes($newstext);
		$player_id = $playerinfo[player_id];
		$news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'attack')");
		
        if($attackerarmor > 0)
        {
            $rating_change=round($targetinfo[rating]*$rating_combat_factor);
            $free_ore = round($targetshipinfo[ship_ore]/2);
            $free_organics = round($targetshipinfo[ship_organics]/2);
            $free_goods = round($targetshipinfo[ship_goods]/2);
            $free_holds = NUM_HOLDS($shipinfo[hull]) - $shipinfo[ship_ore] - $shipinfo[ship_organics] - $shipinfo[ship_goods] - $shipinfo[ship_colonists];
            if($free_holds > $free_goods)
            {
                $salv_goods=$free_goods;
                $free_holds=$free_holds-$free_goods;
            }
            elseif($free_holds > 0)
            {
                $salv_goods=$free_holds;
                $free_holds=0;
            }
            else
            {
                $salv_goods=0;
            }
            if($free_holds > $free_ore)
            {
                $salv_ore=$free_ore;
                $free_holds=$free_holds-$free_ore;
            }
            elseif($free_holds > 0)
            {
                $salv_ore=$free_holds;
                $free_holds=0;
            }
            else
            {
                $salv_ore=0;
            }
            if($free_holds > $free_organics)
            {
                $salv_organics=$free_organics;
                $free_holds=$free_holds-$free_organics;
            }
            elseif($free_holds > 0)
            {
                $salv_organics=$free_holds;
                $free_holds=0;
            }
            else
            {
                $salv_organics=0;
            }
            $ship_value=$upgrade_cost*(round(mypw($upgrade_factor, $targetshipinfo[hull]))+round(mypw($upgrade_factor, $targetshipinfo[engines]))+round(mypw($upgrade_factor, $targetshipinfo[power]))+round(mypw($upgrade_factor, $targetshipinfo[computer]))+round(mypw($upgrade_factor, $targetshipinfo[sensors]))+round(mypw($upgrade_factor, $targetshipinfo[beams]))+round(mypw($upgrade_factor, $targetshipinfo[torp_launchers]))+round(mypw($upgrade_factor, $targetshipinfo[shields]))+round(mypw($upgrade_factor, $targetshipinfo[armor]))+round(mypw($upgrade_factor, $targetshipinfo[cloak])));
            $ship_salvage_rate=rand(10,20);
            $ship_salvage=$ship_value*$ship_salvage_rate/100;
			// Triple salvage if this is an outlaw
		  	$result3 = $db->Execute ("SELECT amount FROM $dbtables[bounty] WHERE placed_by=0 AND bounty_on=$targetinfo[player_id]");
		  	if (!$result3->EOF) {
		  		$ship_salvage *=3;
				echo "You destroyed a Federation fugitive! Triple hull salvage!<br>";
		  	}
            $l_cmb_yousalvaged = str_replace("[cmb_salv_ore]", NUMBER($salv_ore), $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salv_organics]", NUMBER($salv_organics), $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salv_goods]", NUMBER($salv_goods), $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salvage_rate]", $ship_salvage_rate, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salvage]", NUMBER($ship_salvage), $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_number_rating_change]", NUMBER(abs($rating_change)), $l_cmb_yousalvaged);
            echo "$l_cmb_yousalvaged";
            $update3 = $db->Execute ("UPDATE $dbtables[players] SET credits=credits+$ship_salvage WHERE player_id=$playerinfo[player_id]");
			$update3 = $db->Execute ("UPDATE $dbtables[ships] SET ship_ore=ship_ore+$salv_ore, ship_organics=ship_organics+$salv_organics, ship_goods=ship_goods+$salv_goods WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");
        }
    }
    else
    {
        $l_cmb_youdidntdestroyhim = str_replace("[cmb_targetinfo_ship_name]", $targetshipinfo[ship_name], $l_cmb_youdidntdestroyhim);
        echo "$l_cmb_youdidntdestroyhim<BR>";
        $target_rating_change=round($targetinfo[rating]*.1);
        $target_armor_lost=$targetshipinfo[armour_pts]-$targetarmor;
        $target_fighters_lost=$targetshipinfo[ship_fighters]-$targetfighters;
        $target_energy=$targetshipinfo[ship_energy];
        playerlog($targetinfo[player_id], LOG_ATTACKED_WIN, "$playerinfo[character_name]|$target_armor_lost|$target_fighters_lost");
        $update4 = $db->Execute ("UPDATE $dbtables[ships] SET ship_energy=$target_energy,ship_fighters=ship_fighters-$target_fighters_lost, armour_pts=armour_pts-$target_armor_lost, torps=torps-$targettorpnum WHERE player_id=$targetinfo[player_id] AND ship_id=$targetinfo[currentship]");
	}
    $db->Execute("UNLOCK TABLES");
}
示例#6
0
function shiptoship($ship_id)
{
    global $attackerbeams, $attackerfighters, $attackershields, $attackertorps, $attackerarmor, $attackertorpdamage, $start_energy, $level_factor;
    global $torp_dmg_rate, $rating_combat_factor, $upgrade_factor, $upgrade_cost, $armor_lost, $fighters_lost, $playerinfo;
    global $db, $db_logging;
    global $l_cmb_startingstats, $l_cmb_statattackerbeams, $l_cmb_statattackerfighters, $l_cmb_statattackershields, $l_cmb_statattackertorps;
    global $l_cmb_statattackerarmor, $l_cmb_statattackertorpdamage, $l_cmb_isattackingyou, $l_cmb_beamexchange, $l_cmb_beamsdestroy;
    global $l_cmb_beamsdestroy2, $l_cmb_nobeamsareleft, $l_cmb_beamshavenotarget, $l_cmb_fighterdestroyedbybeams, $l_cmb_beamsdestroystillhave;
    global $l_cmb_fighterunhindered, $l_cmb_youhavenofightersleft, $l_cmb_breachedsomeshields, $l_cmb_shieldsarehitbybeams, $l_cmb_nobeamslefttoattack;
    global $l_cmb_yourshieldsbreachedby, $l_cmb_yourshieldsarehit, $l_cmb_hehasnobeamslefttoattack, $l_cmb_yourbeamsbreachedhim;
    global $l_cmb_yourbeamshavedonedamage, $l_cmb_nobeamstoattackarmor, $l_cmb_yourarmorbreachedbybeams, $l_cmb_yourarmorhitdamaged;
    global $l_cmb_torpedoexchange, $l_cmb_hehasnobeamslefttoattackyou, $l_cmb_yourtorpsdestroy, $l_cmb_yourtorpsdestroy2;
    global $l_cmb_youhavenotorpsleft, $l_cmb_hehasnofighterleft, $l_cmb_torpsdestroyyou, $l_cmb_someonedestroyedfighters, $l_cmb_hehasnotorpsleftforyou;
    global $l_cmb_youhavenofightersanymore, $l_cmb_youbreachedwithtorps, $l_cmb_hisarmorishitbytorps, $l_cmb_notorpslefttoattackarmor;
    global $l_cmb_yourarmorbreachedbytorps, $l_cmb_yourarmorhitdmgtorps, $l_cmb_hehasnotorpsforyourarmor, $l_cmb_fightersattackexchange;
    global $l_cmb_enemylostallfighters, $l_cmb_helostsomefighters, $l_cmb_youlostallfighters, $l_cmb_youalsolostsomefighters, $l_cmb_hehasnofightersleftattack;
    global $l_cmb_younofightersattackleft, $l_cmb_youbreachedarmorwithfighters, $l_cmb_youhitarmordmgfighters, $l_cmb_youhavenofighterstoarmor;
    global $l_cmb_hasbreachedarmorfighters, $l_cmb_yourarmorishitfordmgby, $l_cmb_nofightersleftheforyourarmor, $l_cmb_hehasbeendestroyed;
    global $l_cmb_escapepodlaunched, $l_cmb_yousalvaged, $l_cmb_yousalvaged2, $l_cmb_youdidntdestroyhim, $l_cmb_shiptoshipcombatstats;
    $resx = $db->Execute("LOCK TABLES {$db->prefix}ships WRITE, {$db->prefix}universe WRITE, {$db->prefix}zones READ");
    db_op_result($db, $resx, __LINE__, __FILE__, $db_logging);
    $result2 = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id='{$ship_id}'");
    db_op_result($db, $result2, __LINE__, __FILE__, $db_logging);
    $targetinfo = $result2->fields;
    echo "<br><br>-=-=-=-=-=-=-=--<br>\n    {$l_cmb_startingstats}:<br>\n    <br>\n    {$l_cmb_statattackerbeams}: {$attackerbeams}<br>\n    {$l_cmb_statattackerfighters}: {$attackerfighters}<br>\n    {$l_cmb_statattackershields}: {$attackershields}<br>\n    {$l_cmb_statattackertorps}: {$attackertorps}<br>\n    {$l_cmb_statattackerarmor}: {$attackerarmor}<br>\n    {$l_cmb_statattackertorpdamage}: {$attackertorpdamage}<br>";
    $targetbeams = NUM_BEAMS($targetinfo['beams']);
    if ($targetbeams > $targetinfo['ship_energy']) {
        $targetbeams = $targetinfo['ship_energy'];
    }
    $targetinfo['ship_energy'] = $targetinfo['ship_energy'] - $targetbeams;
    $targetshields = NUM_SHIELDS($targetinfo['shields']);
    if ($targetshields > $targetinfo['ship_energy']) {
        $targetshields = $targetinfo['ship_energy'];
    }
    $targetinfo['ship_energy'] = $targetinfo['ship_energy'] - $targetshields;
    $targettorpnum = round(pow($level_factor, $targetinfo['torp_launchers'])) * 2;
    if ($targettorpnum > $targetinfo['torps']) {
        $targettorpnum = $targetinfo['torps'];
    }
    $targettorpdmg = $torp_dmg_rate * $targettorpnum;
    $targetarmor = $targetinfo['armor_pts'];
    $targetfighters = $targetinfo['ship_fighters'];
    $targetdestroyed = 0;
    $playerdestroyed = 0;
    echo "-->{$targetinfo['ship_name']} {$l_cmb_isattackingyou}<br><br>";
    echo "{$l_cmb_beamexchange}<br>";
    if ($targetfighters > 0 && $attackerbeams > 0) {
        if ($attackerbeams > round($targetfighters / 2)) {
            $temp = round($targetfighters / 2);
            $lost = $targetfighters - $temp;
            $targetfighters = $temp;
            $attackerbeams = $attackerbeams - $lost;
            $l_cmb_beamsdestroy = str_replace("[cmb_lost]", $lost, $l_cmb_beamsdestroy);
            echo "<-- {$l_cmb_beamsdestroy}<br>";
        } else {
            $targetfighters = $targetfighters - $attackerbeams;
            $l_cmb_beamsdestroy2 = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_beamsdestroy2);
            echo "--> {$l_cmb_beamsdestroy2}<br>";
            $attackerbeams = 0;
        }
    } elseif ($targetfighters > 0 && $attackerbeams < 1) {
        echo "{$l_cmb_nobeamsareleft}<br>";
    } else {
        echo "{$l_cmb_beamshavenotarget}<br>";
    }
    if ($attackerfighters > 0 && $targetbeams > 0) {
        if ($targetbeams > round($attackerfighters / 2)) {
            $temp = round($attackerfighters / 2);
            $lost = $attackerfighters - $temp;
            $attackerfighters = $temp;
            $targetbeams = $targetbeams - $lost;
            $l_cmb_fighterdestroyedbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_fighterdestroyedbybeams);
            $l_cmb_fighterdestroyedbybeams = str_replace("[cmb_lost]", $lost, $l_cmb_fighterdestroyedbybeams);
            echo "--> {$l_cmb_fighterdestroyedbybeams}<br>";
        } else {
            $attackerfighters = $attackerfighters - $targetbeams;
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_beamsdestroystillhave);
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_beamsdestroystillhave);
            $l_cmb_beamsdestroystillhave = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_beamsdestroystillhave);
            echo "<-- {$l_cmb_beamsdestroystillhave}<br>";
            $targetbeams = 0;
        }
    } elseif ($attackerfighters > 0 && $targetbeams < 1) {
        echo "{$l_cmb_fighterunhindered}<br>";
    } else {
        echo "{$l_cmb_youhavenofightersleft}<br>";
    }
    if ($attackerbeams > 0) {
        if ($attackerbeams > $targetshields) {
            $attackerbeams = $attackerbeams - $targetshields;
            $targetshields = 0;
            $l_cmb_breachedsomeshields = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_breachedsomeshields);
            echo "<-- {$l_cmb_breachedsomeshields}<br>";
        } else {
            $l_cmb_shieldsarehitbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_shieldsarehitbybeams);
            $l_cmb_shieldsarehitbybeams = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_shieldsarehitbybeams);
            echo "{$l_cmb_shieldsarehitbybeams}<br>";
            $targetshields = $targetshields - $attackerbeams;
            $attackerbeams = 0;
        }
    } else {
        $l_cmb_nobeamslefttoattack = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_nobeamslefttoattack);
        echo "{$l_cmb_nobeamslefttoattack}<br>";
    }
    if ($targetbeams > 0) {
        if ($targetbeams > $attackershields) {
            $targetbeams = $targetbeams - $attackershields;
            $attackershields = 0;
            $l_cmb_yourshieldsbreachedby = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourshieldsbreachedby);
            echo "--> {$l_cmb_yourshieldsbreachedby}<br>";
        } else {
            $l_cmb_yourshieldsarehit = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourshieldsarehit);
            $l_cmb_yourshieldsarehit = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_yourshieldsarehit);
            echo "<-- {$l_cmb_yourshieldsarehit}<br>";
            $attackershields = $attackershields - $targetbeams;
            $targetbeams = 0;
        }
    } else {
        $l_cmb_hehasnobeamslefttoattack = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnobeamslefttoattack);
        echo "{$l_cmb_hehasnobeamslefttoattack}<br>";
    }
    if ($attackerbeams > 0) {
        if ($attackerbeams > $targetarmor) {
            $targetarmor = 0;
            $l_cmb_yourbeamsbreachedhim = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourbeamsbreachedhim);
            echo "--> {$l_cmb_yourbeamsbreachedhim}<br>";
        } else {
            $targetarmor = $targetarmor - $attackerbeams;
            $l_cmb_yourbeamshavedonedamage = str_replace("[cmb_attackerbeams]", $attackerbeams, $l_cmb_yourbeamshavedonedamage);
            $l_cmb_yourbeamshavedonedamage = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourbeamshavedonedamage);
            echo "{$l_cmb_yourbeamshavedonedamage}<br>";
        }
    } else {
        $l_cmb_nobeamstoattackarmor = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_nobeamstoattackarmor);
        echo "{$l_cmb_nobeamstoattackarmor}<br>";
    }
    if ($targetbeams > 0) {
        if ($targetbeams > $attackerarmor) {
            $attackerarmor = 0;
            $l_cmb_yourarmorbreachedbybeams = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourarmorbreachedbybeams);
            echo "--> {$l_cmb_yourarmorbreachedbybeams}<br>";
        } else {
            $attackerarmor = $attackerarmor - $targetbeams;
            $l_cmb_yourarmorhitdamaged = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourarmorhitdamaged);
            $l_cmb_yourarmorhitdamaged = str_replace("[cmb_targetbeams]", $targetbeams, $l_cmb_yourarmorhitdamaged);
            echo "<-- {$l_cmb_yourarmorhitdamaged}<br>";
        }
    } else {
        $l_cmb_hehasnobeamslefttoattackyou = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnobeamslefttoattackyou);
        echo "{$l_cmb_hehasnobeamslefttoattackyou}<br>";
    }
    echo "<br>{$l_cmb_torpedoexchange}<br>";
    if ($targetfighters > 0 && $attackertorpdamage > 0) {
        if ($attackertorpdamage > round($targetfighters / 2)) {
            $temp = round($targetfighters / 2);
            $lost = $targetfighters - $temp;
            $targetfighters = $temp;
            $attackertorpdamage = $attackertorpdamage - $lost;
            $l_cmb_yourtorpsdestroy = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourtorpsdestroy);
            $l_cmb_yourtorpsdestroy = str_replace("[cmb_lost]", $lost, $l_cmb_yourtorpsdestroy);
            echo "--> {$l_cmb_yourtorpsdestroy}<br>";
        } else {
            $targetfighters = $targetfighters - $attackertorpdamage;
            $l_cmb_yourtorpsdestroy2 = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourtorpsdestroy2);
            $l_cmb_yourtorpsdestroy2 = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $l_cmb_yourtorpsdestroy2);
            echo "<-- {$l_cmb_yourtorpsdestroy2}<br>";
            $attackertorpdamage = 0;
        }
    } elseif ($targetfighters > 0 && $attackertorpdamage < 1) {
        $l_cmb_youhavenotorpsleft = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youhavenotorpsleft);
        echo "{$l_cmb_youhavenotorpsleft}<br>";
    } else {
        $l_cmb_hehasnofighterleft = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnofighterleft);
        echo "{$l_cmb_hehasnofighterleft}<br>";
    }
    if ($attackerfighters > 0 && $targettorpdmg > 0) {
        if ($targettorpdmg > round($attackerfighters / 2)) {
            $temp = round($attackerfighters / 2);
            $lost = $attackerfighters - $temp;
            $attackerfighters = $temp;
            $targettorpdmg = $targettorpdmg - $lost;
            $l_cmb_torpsdestroyyou = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_torpsdestroyyou);
            $l_cmb_torpsdestroyyou = str_replace("[cmb_lost]", $lost, $l_cmb_torpsdestroyyou);
            echo "--> {$l_cmb_torpsdestroyyou}<br>";
        } else {
            $attackerfighters = $attackerfighters - $targettorpdmg;
            $l_cmb_someonedestroyedfighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_someonedestroyedfighters);
            $l_cmb_someonedestroyedfighters = str_replace("[cmb_targettorpdmg]", $targettorpdmg, $l_cmb_someonedestroyedfighters);
            echo "<-- {$l_cmb_someonedestroyedfighters}<br>";
            $targettorpdmg = 0;
        }
    } elseif ($attackerfighters > 0 && $targettorpdmg < 1) {
        $l_cmb_hehasnotorpsleftforyou = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnotorpsleftforyou);
        echo "{$l_cmb_hehasnotorpsleftforyou}<br>";
    } else {
        $l_cmb_youhavenofightersanymore = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youhavenofightersanymore);
        echo "{$l_cmb_youhavenofightersanymore}<br>";
    }
    if ($attackertorpdamage > 0) {
        if ($attackertorpdamage > $targetarmor) {
            $targetarmor = 0;
            $l_cmb_youbreachedwithtorps = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youbreachedwithtorps);
            echo "--> {$l_cmb_youbreachedwithtorps}<br>";
        } else {
            $targetarmor = $targetarmor - $attackertorpdamage;
            $l_cmb_hisarmorishitbytorps = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hisarmorishitbytorps);
            $l_cmb_hisarmorishitbytorps = str_replace("[cmb_attackertorpdamage]", $attackertorpdamage, $l_cmb_hisarmorishitbytorps);
            echo "<-- {$l_cmb_hisarmorishitbytorps}<br>";
        }
    } else {
        $l_cmb_notorpslefttoattackarmor = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_notorpslefttoattackarmor);
        echo "{$l_cmb_notorpslefttoattackarmor}<br>";
    }
    if ($targettorpdmg > 0) {
        if ($targettorpdmg > $attackerarmor) {
            $attackerarmor = 0;
            $l_cmb_yourarmorbreachedbytorps = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourarmorbreachedbytorps);
            echo "<-- {$l_cmb_yourarmorbreachedbytorps}<br>";
        } else {
            $attackerarmor = $attackerarmor - $targettorpdmg;
            $l_cmb_yourarmorhitdmgtorps = str_replace("[cmb_targettorpdmg]", $targettorpdmg, $l_cmb_yourarmorhitdmgtorps);
            $l_cmb_yourarmorhitdmgtorps = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourarmorhitdmgtorps);
            echo "<-- {$l_cmb_yourarmorhitdmgtorps}<br>";
        }
    } else {
        $l_cmb_hehasnotorpsforyourarmor = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnotorpsforyourarmor);
        echo "{$l_cmb_hehasnotorpsforyourarmor}<br>";
    }
    echo "<br>{$l_cmb_fightersattackexchange}<br>";
    if ($attackerfighters > 0 && $targetfighters > 0) {
        if ($attackerfighters > $targetfighters) {
            $l_cmb_enemylostallfighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_enemylostallfighters);
            echo "--> {$l_cmb_enemylostallfighters}<br>";
            $temptargfighters = 0;
        } else {
            $l_cmb_helostsomefighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_helostsomefighters);
            $l_cmb_helostsomefighters = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_helostsomefighters);
            echo "{$l_cmb_helostsomefighters}<br>";
            $temptargfighters = $targetfighters - $attackerfighters;
        }
        if ($targetfighters > $attackerfighters) {
            echo "<-- {$l_cmb_youlostallfighters}<br>";
            $tempplayfighters = 0;
        } else {
            $l_cmb_youalsolostsomefighters = str_replace("[cmb_targetfighters]", $targetfighters, $l_cmb_youalsolostsomefighters);
            echo "<-- {$l_cmb_youalsolostsomefighters}<br>";
            $tempplayfighters = $attackerfighters - $targetfighters;
        }
        $attackerfighters = $tempplayfighters;
        $targetfighters = $temptargfighters;
    } elseif ($attackerfighters > 0 && $targetfighters < 1) {
        $l_cmb_hehasnofightersleftattack = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasnofightersleftattack);
        echo "{$l_cmb_hehasnofightersleftattack}<br>";
    } else {
        $l_cmb_younofightersattackleft = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_younofightersattackleft);
        echo "{$l_cmb_younofightersattackleft}<br>";
    }
    if ($attackerfighters > 0) {
        if ($attackerfighters > $targetarmor) {
            $targetarmor = 0;
            $l_cmb_youbreachedarmorwithfighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youbreachedarmorwithfighters);
            echo "--> {$l_cmb_youbreachedarmorwithfighters}<br>";
        } else {
            $targetarmor = $targetarmor - $attackerfighters;
            $l_cmb_youhitarmordmgfighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youhitarmordmgfighters);
            $l_cmb_youhitarmordmgfighters = str_replace("[cmb_attackerfighters]", $attackerfighters, $l_cmb_youhitarmordmgfighters);
            echo "<-- {$l_cmb_youhitarmordmgfighters}<br>";
        }
    } else {
        $l_cmb_youhavenofighterstoarmor = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youhavenofighterstoarmor);
        echo "{$l_cmb_youhavenofighterstoarmor}<br>";
    }
    if ($targetfighters > 0) {
        if ($targetfighters > $attackerarmor) {
            $attackerarmor = 0;
            $l_cmb_hasbreachedarmorfighters = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hasbreachedarmorfighters);
            echo "<-- {$l_cmb_hasbreachedarmorfighters}<br>";
        } else {
            $attackerarmor = $attackerarmor - $targetfighters;
            $l_cmb_yourarmorishitfordmgby = str_replace("[cmb_targetfighters]", $targetfighters, $l_cmb_yourarmorishitfordmgby);
            $l_cmb_yourarmorishitfordmgby = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_yourarmorishitfordmgby);
            echo "--> {$l_cmb_yourarmorishitfordmgby}<br>";
        }
    } else {
        $l_cmb_nofightersleftheforyourarmor = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_nofightersleftheforyourarmor);
        echo "{$l_cmb_nofightersleftheforyourarmor}<br>";
    }
    if ($targetarmor < 1) {
        $l_cmb_hehasbeendestroyed = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_hehasbeendestroyed);
        echo "<br>{$l_cmb_hehasbeendestroyed}<br>";
        if ($attackerarmor > 0) {
            $rating_change = round($targetinfo['rating'] * $rating_combat_factor);
            $free_ore = round($targetinfo['ship_ore'] / 2);
            $free_organics = round($targetinfo['ship_organics'] / 2);
            $free_goods = round($targetinfo['ship_goods'] / 2);
            $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists'];
            if ($free_holds > $free_goods) {
                $salv_goods = $free_goods;
                $free_holds = $free_holds - $free_goods;
            } elseif ($free_holds > 0) {
                $salv_goods = $free_holds;
                $free_holds = 0;
            } else {
                $salv_goods = 0;
            }
            if ($free_holds > $free_ore) {
                $salv_ore = $free_ore;
                $free_holds = $free_holds - $free_ore;
            } elseif ($free_holds > 0) {
                $salv_ore = $free_holds;
                $free_holds = 0;
            } else {
                $salv_ore = 0;
            }
            if ($free_holds > $free_organics) {
                $salv_organics = $free_organics;
                $free_holds = $free_holds - $free_organics;
            } elseif ($free_holds > 0) {
                $salv_organics = $free_holds;
                $free_holds = 0;
            } else {
                $salv_organics = 0;
            }
            $ship_value = $upgrade_cost * (round(pow($upgrade_factor, $targetinfo['hull'])) + round(pow($upgrade_factor, $targetinfo['engines'])) + round(pow($upgrade_factor, $targetinfo['power'])) + round(pow($upgrade_factor, $targetinfo['computer'])) + round(pow($upgrade_factor, $targetinfo['sensors'])) + round(pow($upgrade_factor, $targetinfo['beams'])) + round(pow($upgrade_factor, $targetinfo['torp_launchers'])) + round(pow($upgrade_factor, $targetinfo['shields'])) + round(pow($upgrade_factor, $targetinfo['armor'])) + round(pow($upgrade_factor, $targetinfo['cloak'])));
            $ship_salvage_rate = mt_rand(10, 20);
            $ship_salvage = $ship_value * $ship_salvage_rate / 100;
            $l_cmb_yousalvaged = str_replace("[cmb_salv_ore]", $salv_ore, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salv_organics]", $salv_organics, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salv_goods]", $salv_goods, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salvage_rate]", $ship_salvage_rate, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged = str_replace("[cmb_salvage]", $ship_salvage, $l_cmb_yousalvaged);
            $l_cmb_yousalvaged2 = str_replace("[cmb_number_rating_change]", NUMBER(abs($rating_change)), $l_cmb_yousalvaged2);
            echo $l_cmb_yousalvaged . "<br>" . $l_cmb_yousalvaged2;
            $update3 = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=ship_ore+{$salv_ore}, ship_organics=ship_organics+{$salv_organics}, ship_goods=ship_goods+{$salv_goods}, credits=credits+{$ship_salvage} WHERE ship_id={$playerinfo['ship_id']}");
            db_op_result($db, $update3, __LINE__, __FILE__, $db_logging);
        }
        if ($targetinfo[dev_escapepod] == "Y") {
            $rating = round($targetinfo['rating'] / 2);
            echo "{$l_cmb_escapepodlaunched}<br><br>";
            echo "<br><br>ship_id={$targetinfo['ship_id']}<br><br>";
            $test = $db->Execute("UPDATE {$db->prefix}ships SET hull=0,engines=0,power=0,sensors=0,computer=0,beams=0,torp_launchers=0,torps=0,armor=0,armor_pts=100,cloak=0,shields=0,sector=0,ship_organics=0,ship_ore=0,ship_goods=0,ship_energy={$start_energy},ship_colonists=0,ship_fighters=100,dev_warpedit=0,dev_genesis=0,dev_beacon=0,dev_emerwarp=0,dev_escapepod='N',dev_fuelscoop='N',dev_minedeflector=0,on_planet='N',rating='{$rating}',dev_lssd='N' WHERE ship_id={$targetinfo['ship_id']}");
            db_op_result($db, $test, __LINE__, __FILE__, $db_logging);
            playerlog($db, $targetinfo['ship_id'], LOG_ATTACK_LOSE, "{$playerinfo['character_name']}|Y");
            collect_bounty($playerinfo['ship_id'], $targetinfo['ship_id']);
        } else {
            playerlog($db, $targetinfo['ship_id'], LOG_ATTACK_LOSE, "{$playerinfo['character_name']}|N");
            db_kill_player($targetinfo['ship_id']);
            collect_bounty($playerinfo['ship_id'], $targetinfo['ship_id']);
        }
    } else {
        $l_cmb_youdidntdestroyhim = str_replace("[cmb_targetinfo_ship_name]", $targetinfo['ship_name'], $l_cmb_youdidntdestroyhim);
        echo "{$l_cmb_youdidntdestroyhim}<br>";
        $target_rating_change = round($targetinfo['rating'] * 0.1);
        $target_armor_lost = $targetinfo['armor_pts'] - $targetarmor;
        $target_fighters_lost = $targetinfo['ship_fighters'] - $targetfighters;
        $target_energy = $targetinfo['ship_energy'];
        playerlog($db, $targetinfo['ship_id'], LOG_ATTACKED_WIN, "{$playerinfo['character_name']} {$armor_lost} {$fighters_lost}");
        $update4 = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy={$target_energy},ship_fighters=ship_fighters-{$target_fighters_lost}, armor_pts=armor_pts-{$target_armor_lost}, torps=torps-{$targettorpnum} WHERE ship_id={$targetinfo['ship_id']}");
        db_op_result($db, $update4, __LINE__, __FILE__, $db_logging);
    }
    echo "<br>_+_+_+_+_+_+_<br>";
    echo "{$l_cmb_shiptoshipcombatstats}<br>";
    echo "{$l_cmb_statattackerbeams}: {$attackerbeams}<br>";
    echo "{$l_cmb_statattackerfighters}: {$attackerfighters}<br>";
    echo "{$l_cmb_statattackershields}: {$attackershields}<br>";
    echo "{$l_cmb_statattackertorps}: {$attackertorps}<br>";
    echo "{$l_cmb_statattackerarmor}: {$attackerarmor}<br>";
    echo "{$l_cmb_statattackertorpdamage}: {$attackertorpdamage}<br>";
    echo "_+_+_+_+_+_+<br>";
    $resx = $db->Execute("UNLOCK TABLES");
    db_op_result($db, $resx, __LINE__, __FILE__, $db_logging);
}
function xenobetosecdef()
{
    include_once "destroy_fighters.php";
    include_once "explode_mines.php";
    include_once "cancel_bounty.php";
    // Xenobe to sector defense
    global $playerinfo, $targetlink, $xenobeisdead, $db, $l;
    // Check for sector defenses
    if ($targetlink > 0) {
        $resultf = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? and defence_type ='F' ORDER BY quantity DESC", array($targetlink));
        db_op_result($db, $resultf, __LINE__, __FILE__);
        $i = 0;
        $total_sector_fighters = 0;
        if ($resultf > 0) {
            while (!$resultf->EOF) {
                $defences[$i] = $resultf->fields;
                $total_sector_fighters += $defences[$i]['quantity'];
                $i++;
                $resultf->MoveNext();
            }
        }
        $resultm = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id=? and defence_type ='M'", array($targetlink));
        db_op_result($db, $resultm, __LINE__, __FILE__);
        $i = 0;
        $total_sector_mines = 0;
        if ($resultm > 0) {
            while (!$resultm->EOF) {
                $defences[$i] = $resultm->fields;
                $total_sector_mines += $defences[$i]['quantity'];
                $i++;
                $resultm->MoveNext();
            }
        }
        if ($total_sector_fighters > 0 || $total_sector_mines > 0 || $total_sector_fighters > 0 && $total_sector_mines > 0) {
            playerlog($db, $playerinfo['ship_id'], LOG_RAW, "ATTACKING SECTOR DEFENCES {$total_sector_fighters} fighters and {$total_sector_mines} mines.");
            $targetfighters = $total_sector_fighters;
            $playerbeams = NUM_BEAMS($playerinfo['beams']);
            if ($playerbeams > $playerinfo['ship_energy']) {
                $playerbeams = $playerinfo['ship_energy'];
            }
            $playerinfo['ship_energy'] = $playerinfo['ship_energy'] - $playerbeams;
            $playershields = NUM_SHIELDS($playerinfo['shields']);
            if ($playershields > $playerinfo['ship_energy']) {
                $playershields = $playerinfo['ship_energy'];
            }
            $playertorpnum = round(pow($level_factor, $playerinfo['torp_launchers'])) * 2;
            if ($playertorpnum > $playerinfo['torps']) {
                $playertorpnum = $playerinfo['torps'];
            }
            $playertorpdmg = $torp_dmg_rate * $playertorpnum;
            $playerarmor = $playerinfo['armor_pts'];
            $playerfighters = $playerinfo['ship_fighters'];
            $totalmines = $total_sector_mines;
            if ($totalmines > 1) {
                $roll = mt_rand(1, $totalmines);
            } else {
                $roll = 1;
            }
            $totalmines = $totalmines - $roll;
            $playerminedeflect = $playerinfo['ship_fighters'];
            // Xenobe keep as many deflectors as fighters
            // Combat - Beams v fighters
            if ($targetfighters > 0 && $playerbeams > 0) {
                if ($playerbeams > round($targetfighters / 2)) {
                    $temp = round($targetfighters / 2);
                    $targetfighters = $temp;
                    $playerbeams = $playerbeams - $temp;
                } else {
                    $targetfighters = $targetfighters - $playerbeams;
                    $playerbeams = 0;
                }
            }
            // Torpedoes v. fighters
            if ($targetfighters > 0 && $playertorpdmg > 0) {
                if ($playertorpdmg > round($targetfighters / 2)) {
                    $temp = round($targetfighters / 2);
                    $targetfighters = $temp;
                    $playertorpdmg = $playertorpdmg - $temp;
                } else {
                    $targetfighters = $targetfighters - $playertorpdmg;
                    $playertorpdmg = 0;
                }
            }
            // Fighters v. fighters
            if ($playerfighters > 0 && $targetfighters > 0) {
                if ($playerfighters > $targetfighters) {
                    echo $l->get('l_sf_destfightall');
                    $temptargfighters = 0;
                } else {
                    $temptargfighters = $targetfighters - $playerfighters;
                }
                if ($targetfighters > $playerfighters) {
                    $tempplayfighters = 0;
                } else {
                    $tempplayfighters = $playerfighters - $targetfighters;
                }
                $playerfighters = $tempplayfighters;
                $targetfighters = $temptargfighters;
            }
            // There are still fighters, so armor v. fighters
            if ($targetfighters > 0) {
                if ($targetfighters > $playerarmor) {
                    $playerarmor = 0;
                } else {
                    $playerarmor = $playerarmor - $targetfighters;
                }
            }
            // Get rid of the sector fighters that died
            $fighterslost = $total_sector_fighters - $targetfighters;
            destroy_fighters($db, $targetlink, $fighterslost);
            // Message the defence owner with what happened
            $l_sf_sendlog = str_replace("[player]", "Xenobe {$playerinfo['character_name']}", $l->get('l_sf_sendlog'));
            $l_sf_sendlog = str_replace("[lost]", $fighterslost, $l_sf_sendlog);
            $l_sf_sendlog = str_replace("[sector]", $targetlink, $l_sf_sendlog);
            message_defence_owner($db, $targetlink, $l_sf_sendlog);
            // Update Xenobe after comnbat
            $armor_lost = $playerinfo['armor_pts'] - $playerarmor;
            $fighters_lost = $playerinfo['ship_fighters'] - $playerfighters;
            $energy = $playerinfo['ship_energy'];
            $update1 = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy=?, ship_fighters=ship_fighters-?, armor_pts=armor_pts-?,torps=torps-? WHERE ship_id=?", array($energy, $fighters_lost, $armor_lost, $playertorpnum, $playerinfo['ship_id']));
            db_op_result($db, $update1, __LINE__, __FILE__);
            // Check to see if Xenobe is dead
            if ($playerarmor < 1) {
                $l_sf_sendlog2 = str_replace("[player]", "Xenobe " . $playerinfo['character_name'], $l->get('l_sf_sendlog2'));
                $l_sf_sendlog2 = str_replace("[sector]", $targetlink, $l_sf_sendlog2);
                message_defence_owner($db, $targetlink, $l_sf_sendlog2);
                cancel_bounty($db, $playerinfo['ship_id']);
                db_kill_player($playerinfo['ship_id']);
                $xenobeisdead = 1;
                return;
            }
            // Xenobe is still alive, so he hits mines, and logs it
            $l_chm_hehitminesinsector = str_replace("[chm_playerinfo_character_name]", "Xenobe " . $playerinfo['character_name'], $l->get('l_chm_hehitminesinsector'));
            $l_chm_hehitminesinsector = str_replace("[chm_roll]", $roll, $l_chm_hehitminesinsector);
            $l_chm_hehitminesinsector = str_replace("[chm_sector]", $targetlink, $l_chm_hehitminesinsector);
            message_defence_owner($db, $targetlink, "{$l_chm_hehitminesinsector}");
            // Deflectors v. mines
            if ($playerminedeflect >= $roll) {
                // Took no mine damage due to virtual mine deflectors
            } else {
                $mines_left = $roll - $playerminedeflect;
                // Shields v. mines
                if ($playershields >= $mines_left) {
                    $update2 = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy=ship_energy-? WHERE ship_id=?", array($mines_left, $playerinfo['ship_id']));
                    db_op_result($db, $update2, __LINE__, __FILE__);
                } else {
                    $mines_left = $mines_left - $playershields;
                    // Armor v. mines
                    if ($playerarmor >= $mines_left) {
                        $update2 = $db->Execute("UPDATE {$db->prefix}ships SET armor_pts=armor_pts-?, ship_energy=0 WHERE ship_id=?", array($mines_left, $playerinfo['ship_id']));
                        db_op_result($db, $update2, __LINE__, __FILE__);
                    } else {
                        // Xenobe dies, logs the fact that he died
                        $l_chm_hewasdestroyedbyyourmines = str_replace("[chm_playerinfo_character_name]", "Xenobe " . $playerinfo['character_name'], $l->get('l_chm_hewasdestroyedbyyourmines'));
                        $l_chm_hewasdestroyedbyyourmines = str_replace("[chm_sector]", $targetlink, $l_chm_hewasdestroyedbyyourmines);
                        message_defence_owner($db, $targetlink, "{$l_chm_hewasdestroyedbyyourmines}");
                        // Actually kill the Xenobe now
                        cancel_bounty($db, $playerinfo['ship_id']);
                        db_kill_player($playerinfo['ship_id']);
                        $xenobeisdead = 1;
                        // Lets get rid of the mines now and return out of this function
                        explode_mines($db, $targetlink, $roll);
                        return;
                    }
                }
            }
            explode_mines($db, $targetlink, $roll);
            // Dispose of the mines now
        } else {
            // This was called without any sector defences to attack
            return;
        }
    }
}
示例#8
0
function xenobetoship($ship_id)
{
    // SETUP GENERAL VARIABLES
    global $attackerbeams;
    global $attackerfighters;
    global $attackershields;
    global $attackertorps;
    global $attackerarmor;
    global $attackertorpdamage;
    global $start_energy;
    global $playerinfo;
    global $rating_combat_factor;
    global $upgrade_cost;
    global $upgrade_factor;
    global $sector_max;
    global $xenobeisdead;
    global $db, $db_logging;
    // LOOKUP TARGET DETAILS
    $resa = $db->Execute("LOCK TABLES {$db->prefix}ships WRITE, {$db->prefix}universe WRITE, {$db->prefix}zones READ, {$db->prefix}planets READ, {$db->prefix}news WRITE, {$db->prefix}logs WRITE");
    db_op_result($db, $resa, __LINE__, __FILE__, $db_logging);
    $resultt = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id='{$ship_id}'");
    db_op_result($db, $resultt, __LINE__, __FILE__, $db_logging);
    $targetinfo = $resultt->fields;
    // VERIFY NOT ATTACKING ANOTHER XENOBE
    // Added because the xenobe were killing each other off
    if (strstr($targetinfo[email], '@xenobe')) {
        $resb = $db->Execute("UNLOCK TABLES");
        db_op_result($db, $resb, __LINE__, __FILE__, $db_logging);
        return;
    }
    // VERIFY SECTOR ALLOWS ATTACK
    $sectres = $db->Execute("SELECT sector_id,zone_id FROM {$db->prefix}universe WHERE sector_id='{$targetinfo['sector']}'");
    db_op_result($db, $sectres, __LINE__, __FILE__, $db_logging);
    $sectrow = $sectres->fields;
    $zoneres = $db->Execute("SELECT zone_id,allow_attack FROM {$db->prefix}zones WHERE zone_id={$sectrow['zone_id']}");
    db_op_result($db, $zoneres, __LINE__, __FILE__, $db_logging);
    $zonerow = $zoneres->fields;
    if ($zonerow[allow_attack] == "N") {
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Attack failed, you are in a sector that prohibits attacks.");
        return;
    }
    // USE EMERGENCY WARP DEVICE
    if ($targetinfo[dev_emerwarp] > 0) {
        playerlog($db, $targetinfo[ship_id], LOG_ATTACK_EWD, "Xenobe {$playerinfo['character_name']}");
        $dest_sector = mt_rand(0, $sector_max);
        $result_warp = $db->Execute("UPDATE {$db->prefix}ships SET sector={$dest_sector}, dev_emerwarp=dev_emerwarp-1 WHERE ship_id={$targetinfo['ship_id']}");
        db_op_result($db, $result_warp, __LINE__, __FILE__, $db_logging);
        return;
    }
    // SETUP ATTACKER VARIABLES
    $attackerbeams = NUM_BEAMS($playerinfo[beams]);
    if ($attackerbeams > $playerinfo[ship_energy]) {
        $attackerbeams = $playerinfo[ship_energy];
    }
    $playerinfo[ship_energy] = $playerinfo[ship_energy] - $attackerbeams;
    $attackershields = NUM_SHIELDS($playerinfo[shields]);
    if ($attackershields > $playerinfo[ship_energy]) {
        $attackershields = $playerinfo[ship_energy];
    }
    $playerinfo[ship_energy] = $playerinfo[ship_energy] - $attackershields;
    $attackertorps = round(pow($level_factor, $playerinfo['torp_launchers'])) * 2;
    if ($attackertorps > $playerinfo[torps]) {
        $attackertorps = $playerinfo[torps];
    }
    $playerinfo[torps] = $playerinfo[torps] - $attackertorps;
    $attackertorpdamage = $torp_dmg_rate * $attackertorps;
    $attackerarmor = $playerinfo[armor_pts];
    $attackerfighters = $playerinfo[ship_fighters];
    $playerdestroyed = 0;
    // SETUP TARGET VARIABLES
    $targetbeams = NUM_BEAMS($targetinfo[beams]);
    if ($targetbeams > $targetinfo[ship_energy]) {
        $targetbeams = $targetinfo[ship_energy];
    }
    $targetinfo[ship_energy] = $targetinfo[ship_energy] - $targetbeams;
    $targetshields = NUM_SHIELDS($targetinfo[shields]);
    if ($targetshields > $targetinfo[ship_energy]) {
        $targetshields = $targetinfo[ship_energy];
    }
    $targetinfo[ship_energy] = $targetinfo[ship_energy] - $targetshields;
    $targettorpnum = round(pow($level_factor, $targetinfo['torp_launchers'])) * 2;
    if ($targettorpnum > $targetinfo[torps]) {
        $targettorpnum = $targetinfo[torps];
    }
    $targetinfo[torps] = $targetinfo[torps] - $targettorpnum;
    $targettorpdmg = $torp_dmg_rate * $targettorpnum;
    $targetarmor = $targetinfo[armor_pts];
    $targetfighters = $targetinfo[ship_fighters];
    $targetdestroyed = 0;
    // BEGIN COMBAT PROCEDURES
    if ($attackerbeams > 0 && $targetfighters > 0) {
        // ATTACKER HAS BEAMS - TARGET HAS FIGHTERS - BEAMS VS FIGHTERS
        if ($attackerbeams > round($targetfighters / 2)) {
            // ATTACKER BEAMS GT HALF TARGET FIGHTERS
            $lost = $targetfighters - round($targetfighters / 2);
            $targetfighters = $targetfighters - $lost;
            // T LOOSES HALF ALL FIGHTERS
            $attackerbeams = $attackerbeams - $lost;
            // A LOOSES BEAMS EQ TO HALF T FIGHTERS
        } else {
            // ATTACKER BEAMS LE HALF TARGET FIGHTERS
            $targetfighters = $targetfighters - $attackerbeams;
            // T LOOSES FIGHTERS EQ TO A BEAMS
            $attackerbeams = 0;
            // A LOOSES ALL BEAMS
        }
    }
    if ($attackerfighters > 0 && $targetbeams > 0) {
        // TARGET HAS BEAMS - ATTACKER HAS FIGHTERS - BEAMS VS FIGHTERS
        if ($targetbeams > round($attackerfighters / 2)) {
            // TARGET BEAMS GT HALF ATTACKER FIGHTERS
            $lost = $attackerfighters - round($attackerfighters / 2);
            $attackerfighters = $attackerfighters - $lost;
            // A LOOSES HALF ALL FIGHTERS
            $targetbeams = $targetbeams - $lost;
            // T LOOSES BEAMS EQ TO HALF A FIGHTERS
        } else {
            // TARGET BEAMS LE HALF ATTACKER FIGHTERS
            $attackerfighters = $attackerfighters - $targetbeams;
            // A LOOSES FIGHTERS EQ TO T BEAMS
            $targetbeams = 0;
            // T LOOSES ALL BEAMS
        }
    }
    if ($attackerbeams > 0) {
        // ATTACKER HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS SHIELDS
        if ($attackerbeams > $targetshields) {
            // ATTACKER BEAMS GT TARGET SHIELDS
            $attackerbeams = $attackerbeams - $targetshields;
            // A LOOSES BEAMS EQ TO T SHIELDS
            $targetshields = 0;
            // T LOOSES ALL SHIELDS
        } else {
            // ATTACKER BEAMS LE TARGET SHIELDS
            $targetshields = $targetshields - $attackerbeams;
            // T LOOSES SHIELDS EQ TO A BEAMS
            $attackerbeams = 0;
            // A LOOSES ALL BEAMS
        }
    }
    if ($targetbeams > 0) {
        // TARGET HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS SHIELDS
        if ($targetbeams > $attackershields) {
            // TARGET BEAMS GT ATTACKER SHIELDS
            $targetbeams = $targetbeams - $attackershields;
            // T LOOSES BEAMS EQ TO A SHIELDS
            $attackershields = 0;
            // A LOOSES ALL SHIELDS
        } else {
            // TARGET BEAMS LE ATTACKER SHIELDS
            $attackershields = $attackershields - $targetbeams;
            // A LOOSES SHIELDS EQ TO T BEAMS
            $targetbeams = 0;
            // T LOOSES ALL BEAMS
        }
    }
    if ($attackerbeams > 0) {
        // ATTACKER HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS ARMOR
        if ($attackerbeams > $targetarmor) {
            // ATTACKER BEAMS GT TARGET ARMOR
            $attackerbeams = $attackerbeams - $targetarmor;
            // A LOOSES BEAMS EQ TO T ARMOR
            $targetarmor = 0;
            // T LOOSES ALL ARMOR (T DESTROYED)
        } else {
            // ATTACKER BEAMS LE TARGET ARMOR
            $targetarmor = $targetarmor - $attackerbeams;
            // T LOOSES ARMORS EQ TO A BEAMS
            $attackerbeams = 0;
            // A LOOSES ALL BEAMS
        }
    }
    if ($targetbeams > 0) {
        // TARGET HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS ARMOR
        if ($targetbeams > $attackerarmor) {
            // TARGET BEAMS GT ATTACKER ARMOR
            $targetbeams = $targetbeams - $attackerarmor;
            // T LOOSES BEAMS EQ TO A ARMOR
            $attackerarmor = 0;
            // A LOOSES ALL ARMOR (A DESTROYED)
        } else {
            // TARGET BEAMS LE ATTACKER ARMOR
            $attackerarmor = $attackerarmor - $targetbeams;
            // A LOOSES ARMOR EQ TO T BEAMS
            $targetbeams = 0;
            // T LOOSES ALL BEAMS
        }
    }
    if ($targetfighters > 0 && $attackertorpdamage > 0) {
        // ATTACKER FIRES TORPS - TARGET HAS FIGHTERS - TORPS VS FIGHTERS
        if ($attackertorpdamage > round($targetfighters / 2)) {
            // ATTACKER FIRED TORPS GT HALF TARGET FIGHTERS
            $lost = $targetfighters - round($targetfighters / 2);
            $targetfighters = $targetfighters - $lost;
            // T LOOSES HALF ALL FIGHTERS
            $attackertorpdamage = $attackertorpdamage - $lost;
            // A LOOSES FIRED TORPS EQ TO HALF T FIGHTERS
        } else {
            // ATTACKER FIRED TORPS LE HALF TARGET FIGHTERS
            $targetfighters = $targetfighters - $attackertorpdamage;
            // T LOOSES FIGHTERS EQ TO A TORPS FIRED
            $attackertorpdamage = 0;
            // A LOOSES ALL TORPS FIRED
        }
    }
    if ($attackerfighters > 0 && $targettorpdmg > 0) {
        // TARGET FIRES TORPS - ATTACKER HAS FIGHTERS - TORPS VS FIGHTERS
        if ($targettorpdmg > round($attackerfighters / 2)) {
            // TARGET FIRED TORPS GT HALF ATTACKER FIGHTERS
            $lost = $attackerfighters - round($attackerfighters / 2);
            $attackerfighters = $attackerfighters - $lost;
            // A LOOSES HALF ALL FIGHTERS
            $targettorpdmg = $targettorpdmg - $lost;
            // T LOOSES FIRED TORPS EQ TO HALF A FIGHTERS
        } else {
            // TARGET FIRED TORPS LE HALF ATTACKER FIGHTERS
            $attackerfighters = $attackerfighters - $targettorpdmg;
            // A LOOSES FIGHTERS EQ TO T TORPS FIRED
            $targettorpdmg = 0;
            // T LOOSES ALL TORPS FIRED
        }
    }
    if ($attackertorpdamage > 0) {
        // ATTACKER FIRES TORPS - CONTINUE COMBAT - TORPS VS ARMOR
        if ($attackertorpdamage > $targetarmor) {
            // ATTACKER FIRED TORPS GT HALF TARGET ARMOR
            $attackertorpdamage = $attackertorpdamage - $targetarmor;
            // A LOOSES FIRED TORPS EQ TO T ARMOR
            $targetarmor = 0;
            // T LOOSES ALL ARMOR (T DESTROYED)
        } else {
            // ATTACKER FIRED TORPS LE HALF TARGET ARMOR
            $targetarmor = $targetarmor - $attackertorpdamage;
            // T LOOSES ARMOR EQ TO A TORPS FIRED
            $attackertorpdamage = 0;
            // A LOOSES ALL TORPS FIRED
        }
    }
    if ($targettorpdmg > 0) {
        // TARGET FIRES TORPS - CONTINUE COMBAT - TORPS VS ARMOR
        if ($targettorpdmg > $attackerarmor) {
            // TARGET FIRED TORPS GT HALF ATTACKER ARMOR
            $targettorpdmg = $targettorpdmg - $attackerarmor;
            // T LOOSES FIRED TORPS EQ TO A ARMOR
            $attackerarmor = 0;
            // A LOOSES ALL ARMOR (A DESTROYED)
        } else {
            // TARGET FIRED TORPS LE HALF ATTACKER ARMOR
            $attackerarmor = $attackerarmor - $targettorpdmg;
            // A LOOSES ARMOR EQ TO T TORPS FIRED
            $targettorpdmg = 0;
            // T LOOSES ALL TORPS FIRED
        }
    }
    if ($attackerfighters > 0 && $targetfighters > 0) {
        // ATTACKER HAS FIGHTERS - TARGET HAS FIGHTERS - FIGHTERS VS FIGHTERS
        if ($attackerfighters > $targetfighters) {
            // ATTACKER FIGHTERS GT TARGET FIGHTERS
            $temptargfighters = 0;
            // T WILL LOOSE ALL FIGHTERS
        } else {
            // ATTACKER FIGHTERS LE TARGET FIGHTERS
            $temptargfighters = $targetfighters - $attackerfighters;
            // T WILL LOOSE FIGHTERS EQ TO A FIGHTERS
        }
        if ($targetfighters > $attackerfighters) {
            // TARGET FIGHTERS GT ATTACKER FIGHTERS
            $tempplayfighters = 0;
            // A WILL LOOSE ALL FIGHTERS
        } else {
            // TARGET FIGHTERS LE ATTACKER FIGHTERS
            $tempplayfighters = $attackerfighters - $targetfighters;
            // A WILL LOOSE FIGHTERS EQ TO T FIGHTERS
        }
        $attackerfighters = $tempplayfighters;
        $targetfighters = $temptargfighters;
    }
    if ($attackerfighters > 0) {
        // ATTACKER HAS FIGHTERS - CONTINUE COMBAT - FIGHTERS VS ARMOR
        if ($attackerfighters > $targetarmor) {
            // ATTACKER FIGHTERS GT TARGET ARMOR
            $targetarmor = 0;
            // T LOOSES ALL ARMOR (T DESTROYED)
        } else {
            // ATTACKER FIGHTERS LE TARGET ARMOR
            $targetarmor = $targetarmor - $attackerfighters;
            // T LOOSES ARMOR EQ TO A FIGHTERS
        }
    }
    if ($targetfighters > 0) {
        // TARGET HAS FIGHTERS - CONTINUE COMBAT - FIGHTERS VS ARMOR
        if ($targetfighters > $attackerarmor) {
            // TARGET FIGHTERS GT ATTACKER ARMOR
            $attackerarmor = 0;
            // A LOOSES ALL ARMOR (A DESTROYED)
        } else {
            // TARGET FIGHTERS LE ATTACKER ARMOR
            $attackerarmor = $attackerarmor - $targetfighters;
            // A LOOSES ARMOR EQ TO T FIGHTERS
        }
    }
    // FIX NEGATIVE VALUE VARS
    if ($attackerfighters < 0) {
        $attackerfighters = 0;
    }
    if ($attackertorps < 0) {
        $attackertorps = 0;
    }
    if ($attackershields < 0) {
        $attackershields = 0;
    }
    if ($attackerbeams < 0) {
        $attackerbeams = 0;
    }
    if ($attackerarmor < 0) {
        $attackerarmor = 0;
    }
    if ($targetfighters < 0) {
        $targetfighters = 0;
    }
    if ($targettorpnum < 0) {
        $targettorpnum = 0;
    }
    if ($targetshields < 0) {
        $targetshields = 0;
    }
    if ($targetbeams < 0) {
        $targetbeams = 0;
    }
    if ($targetarmor < 0) {
        $targetarmor = 0;
    }
    // DEAL WITH DESTROYED SHIPS
    // TARGET SHIP WAS DESTROYED
    if (!$targetarmor > 0) {
        if ($targetinfo[dev_escapepod] == "Y") {
            $rating = round($targetinfo[rating] / 2);
            $resc = $db->Execute("UPDATE {$db->prefix}ships SET hull=0, engines=0, power=0, computer=0,sensors=0, beams=0, torp_launchers=0, torps=0, armor=0, armor_pts=100, cloak=0, shields=0, sector=0, ship_ore=0, ship_organics=0, ship_energy=1000, ship_colonists=0, ship_goods=0, ship_fighters=100, ship_damage=0, on_planet='N', planet_id=0, dev_warpedit=0, dev_genesis=0, dev_beacon=0, dev_emerwarp=0, dev_escapepod='N', dev_fuelscoop='N', dev_minedeflector=0, ship_destroyed='N', rating='{$rating}',dev_lssd='N' WHERE ship_id={$targetinfo['ship_id']}");
            db_op_result($db, $resc, __LINE__, __FILE__, $db_logging);
            playerlog($db, $targetinfo[ship_id], LOG_ATTACK_LOSE, "Xenobe {$playerinfo['character_name']}|Y");
        } else {
            playerlog($db, $targetinfo[ship_id], LOG_ATTACK_LOSE, "Xenobe {$playerinfo['character_name']}|N");
            db_kill_player($targetinfo['ship_id']);
        }
        if ($attackerarmor > 0) {
            // ATTACKER STILL ALIVE TO SALVAGE TRAGET
            $rating_change = round($targetinfo[rating] * $rating_combat_factor);
            $free_ore = round($targetinfo[ship_ore] / 2);
            $free_organics = round($targetinfo[ship_organics] / 2);
            $free_goods = round($targetinfo[ship_goods] / 2);
            $free_holds = NUM_HOLDS($playerinfo[hull]) - $playerinfo[ship_ore] - $playerinfo[ship_organics] - $playerinfo[ship_goods] - $playerinfo[ship_colonists];
            if ($free_holds > $free_goods) {
                // FIGURE OUT WHAT WE CAN CARRY
                $salv_goods = $free_goods;
                $free_holds = $free_holds - $free_goods;
            } elseif ($free_holds > 0) {
                $salv_goods = $free_holds;
                $free_holds = 0;
            } else {
                $salv_goods = 0;
            }
            if ($free_holds > $free_ore) {
                $salv_ore = $free_ore;
                $free_holds = $free_holds - $free_ore;
            } elseif ($free_holds > 0) {
                $salv_ore = $free_holds;
                $free_holds = 0;
            } else {
                $salv_ore = 0;
            }
            if ($free_holds > $free_organics) {
                $salv_organics = $free_organics;
                $free_holds = $free_holds - $free_organics;
            } elseif ($free_holds > 0) {
                $salv_organics = $free_holds;
                $free_holds = 0;
            } else {
                $salv_organics = 0;
            }
            $ship_value = $upgrade_cost * (round(pow($upgrade_factor, $targetinfo['hull'])) + round(pow($upgrade_factor, $targetinfo['engines'])) + round(pow($upgrade_factor, $targetinfo['power'])) + round(pow($upgrade_factor, $targetinfo['computer'])) + round(pow($upgrade_factor, $targetinfo['sensors'])) + round(pow($upgrade_factor, $targetinfo['beams'])) + round(pow($upgrade_factor, $targetinfo['torp_launchers'])) + round(pow($upgrade_factor, $targetinfo['shields'])) + round(pow($upgrade_factor, $targetinfo['armor'])) + round(pow($upgrade_factor, $targetinfo['cloak'])));
            $ship_salvage_rate = mt_rand(10, 20);
            $ship_salvage = $ship_value * $ship_salvage_rate / 100;
            playerlog($db, $playerinfo[ship_id], LOG_RAW, "Attack successful, {$targetinfo['character_name']} was defeated and salvaged for {$ship_salvage} credits.");
            $resd = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=ship_ore+{$salv_ore}, ship_organics=ship_organics+{$salv_organics}, ship_goods=ship_goods+{$salv_goods}, credits=credits+{$ship_salvage} WHERE ship_id={$playerinfo['ship_id']}");
            db_op_result($db, $resd, __LINE__, __FILE__, $db_logging);
            $armor_lost = $playerinfo[armor_pts] - $attackerarmor;
            $fighters_lost = $playerinfo[ship_fighters] - $attackerfighters;
            $energy = $playerinfo[ship_energy];
            $rese = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy={$energy},ship_fighters=ship_fighters-{$fighters_lost}, torps=torps-{$attackertorps},armor_pts=armor_pts-{$armor_lost}, rating=rating-{$rating_change} WHERE ship_id={$playerinfo['ship_id']}");
            db_op_result($db, $rese, __LINE__, __FILE__, $db_logging);
        }
    }
    // TARGET AND ATTACKER LIVE
    if ($targetarmor > 0 && $attackerarmor > 0) {
        $rating_change = round($targetinfo[rating] * 0.1);
        $armor_lost = $playerinfo[armor_pts] - $attackerarmor;
        $fighters_lost = $playerinfo[ship_fighters] - $attackerfighters;
        $energy = $playerinfo[ship_energy];
        $target_rating_change = round($targetinfo[rating] / 2);
        $target_armor_lost = $targetinfo[armor_pts] - $targetarmor;
        $target_fighters_lost = $targetinfo[ship_fighters] - $targetfighters;
        $target_energy = $targetinfo[ship_energy];
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "Attack failed, {$targetinfo['character_name']} survived.");
        playerlog($db, $targetinfo[ship_id], LOG_ATTACK_WIN, "Xenobe {$playerinfo['character_name']}|{$target_armor_lost}|{$target_fighters_lost}");
        $resf = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy={$energy},ship_fighters=ship_fighters-{$fighters_lost}, torps=torps-{$attackertorps},armor_pts=armor_pts-{$armor_lost}, rating=rating-{$rating_change} WHERE ship_id={$playerinfo['ship_id']}");
        db_op_result($db, $resf, __LINE__, __FILE__, $db_logging);
        $resg = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy={$target_energy},ship_fighters=ship_fighters-{$target_fighters_lost}, armor_pts=armor_pts-{$target_armor_lost}, torps=torps-{$targettorpnum}, rating={$target_rating_change} WHERE ship_id={$targetinfo['ship_id']}");
        db_op_result($db, $resg, __LINE__, __FILE__, $db_logging);
    }
    // ATTACKER SHIP DESTROYED
    if (!$attackerarmor > 0) {
        playerlog($db, $playerinfo[ship_id], LOG_RAW, "{$targetinfo['character_name']} destroyed your ship!");
        db_kill_player($playerinfo['ship_id']);
        $xenobeisdead = 1;
        if ($targetarmor > 0) {
            // TARGET STILL ALIVE TO SALVAGE ATTACKER
            $rating_change = round($playerinfo[rating] * $rating_combat_factor);
            $free_ore = round($playerinfo[ship_ore] / 2);
            $free_organics = round($playerinfo[ship_organics] / 2);
            $free_goods = round($playerinfo[ship_goods] / 2);
            $free_holds = NUM_HOLDS($targetinfo[hull]) - $targetinfo[ship_ore] - $targetinfo[ship_organics] - $targetinfo[ship_goods] - $targetinfo[ship_colonists];
            if ($free_holds > $free_goods) {
                // FIGURE OUT WHAT TARGET CAN CARRY
                $salv_goods = $free_goods;
                $free_holds = $free_holds - $free_goods;
            } elseif ($free_holds > 0) {
                $salv_goods = $free_holds;
                $free_holds = 0;
            } else {
                $salv_goods = 0;
            }
            if ($free_holds > $free_ore) {
                $salv_ore = $free_ore;
                $free_holds = $free_holds - $free_ore;
            } elseif ($free_holds > 0) {
                $salv_ore = $free_holds;
                $free_holds = 0;
            } else {
                $salv_ore = 0;
            }
            if ($free_holds > $free_organics) {
                $salv_organics = $free_organics;
                $free_holds = $free_holds - $free_organics;
            } elseif ($free_holds > 0) {
                $salv_organics = $free_holds;
                $free_holds = 0;
            } else {
                $salv_organics = 0;
            }
            $ship_value = $upgrade_cost * (round(pow($upgrade_factor, $playerinfo[hull])) + round(pow($upgrade_factor, $playerinfo[engines])) + round(pow($upgrade_factor, $playerinfo[power])) + round(pow($upgrade_factor, $playerinfo[computer])) + round(pow($upgrade_factor, $playerinfo[sensors])) + round(pow($upgrade_factor, $playerinfo[beams])) + round(pow($upgrade_factor, $playerinfo[torp_launchers])) + round(pow($upgrade_factor, $playerinfo[shields])) + round(pow($upgrade_factor, $playerinfo[armor])) + round(pow($upgrade_factor, $playerinfo[cloak])));
            $ship_salvage_rate = mt_rand(10, 20);
            $ship_salvage = $ship_value * $ship_salvage_rate / 100;
            playerlog($db, $targetinfo[ship_id], LOG_ATTACK_WIN, "Xenobe {$playerinfo['character_name']}|{$armor_lost}|{$fighters_lost}");
            playerlog($db, $targetinfo[ship_id], LOG_RAW, "You destroyed the Xenobe ship and salvaged {$salv_ore} units of ore, {$salv_organics} units of organics, {$salv_goods} units of goods, and salvaged {$ship_salvage_rate}% of the ship for {$ship_salvage} credits.");
            $resh = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=ship_ore+{$salv_ore}, ship_organics=ship_organics+{$salv_organics}, ship_goods=ship_goods+{$salv_goods}, credits=credits+{$ship_salvage} WHERE ship_id={$targetinfo['ship_id']}");
            db_op_result($db, $resh, __LINE__, __FILE__, $db_logging);
            $armor_lost = $targetinfo[armor_pts] - $targetarmor;
            $fighters_lost = $targetinfo[ship_fighters] - $targetfighters;
            $energy = $targetinfo[ship_energy];
            $resi = $db->Execute("UPDATE {$db->prefix}ships SET ship_energy={$energy},ship_fighters=ship_fighters-{$fighters_lost}, torps=torps-{$targettorpnum},armor_pts=armor_pts-{$armor_lost}, rating=rating-{$rating_change} WHERE ship_id={$targetinfo['ship_id']}");
            db_op_result($db, $resi, __LINE__, __FILE__, $db_logging);
        }
    }
    $resj = $db->Execute("UNLOCK TABLES");
    db_op_result($db, $resj, __LINE__, __FILE__, $db_logging);
}
function furangeetoplanet($planet_id)
{
  // ***********************************
  // *** Furangee Planet Attack Code ***
  // ***********************************

  // *********************************
  // *** SETUP GENERAL VARIABLES  ****
  // *********************************
  global $playerinfo;
  global $shipinfo;
  global $planetinfo;

  global $torp_dmg_rate;
  global $level_factor;
  global $rating_combat_factor;
  global $upgrade_cost;
  global $upgrade_factor;
  global $sector_max;
  global $furangeeisdead;
  global $db, $dbtables;

  // *** LOCKING TABLES ****
  //$db->Execute("LOCK TABLES $dbtables[players] WRITE, $dbtables[ships] WRITE, $dbtables[universe] WRITE, $dbtables[planets] WRITE, $dbtables[news] WRITE, $dbtables[logs] WRITE");

  // ********************************
  // *** LOOKUP PLANET DETAILS   ****
  // ********************************
  //$resultp = $db->Execute ("SELECT * FROM $dbtables[planets] WHERE planet_id='$planet_id'");
  echo "The planet ID (ship id) = $planet_id<br>";
  $resultp = $db->Execute ("SELECT * FROM $dbtables[planets] WHERE owner='$planet_id'");
  if ($resultp->EOF) {
  	echo "Asked to get info on $planet_id and failed<br>";
	return;
  }
  $planetinfo=$resultp->fields;

  // ********************************
  // *** LOOKUP OWNER DETAILS    ****
  // ********************************
  $resulto = $db->Execute ("SELECT * FROM $dbtables[players] WHERE player_id='$planet_id'");
  $ownerinfo=$resulto->fields;

  // **********************************
  // *** SETUP PLANETARY VARIABLES ****
  // **********************************
  $base_factor = ($planetinfo[base] == 'Y') ? $basedefense : 0;

  // *** PLANET BEAMS ***
  $targetbeams = NUM_BEAMS($ownerinfo[beams] + $base_factor);
  if ($targetbeams > $planetinfo[energy]) $targetbeams = $planetinfo[energy];
  $planetinfo[energy] -= $targetbeams;
    
  // *** PLANET SHIELDS ***
  $targetshields = NUM_SHIELDS($ownerinfo[shields] + $base_factor);
  if ($targetshields > $planetinfo[energy]) $targetshields = $planetinfo[energy];
  $planetinfo[energy] -= $targetshields;
    
  // *** PLANET TORPS ***
  $torp_launchers = round(mypw($level_factor, ($ownerinfo[torp_launchers])+ $base_factor)) * 10;
  $torps = $planetinfo[torps];
  $targettorps = $torp_launchers;
  if ($torp_launchers > $torps) $targettorps = $torps;
  $planetinfo[torps] -= $targettorps;
  $targettorpdmg = $torp_dmg_rate * $targettorps;

  // *** PLANET FIGHTERS ***
  $targetfighters = $planetinfo[fighters];

  // *********************************
  // *** SETUP ATTACKER VARIABLES ****
  // *********************************

  // *** ATTACKER BEAMS ***
  $attackerbeams = NUM_BEAMS($shipinfo[beams]);
  if ($attackerbeams > $shipinfo[ship_energy]) $attackerbeams = $shipinfo[ship_energy];
  $shipinfo[ship_energy] -= $attackerbeams;

  // *** ATTACKER SHIELDS ***
  $attackershields = NUM_SHIELDS($shipinfo[shields]);
  if ($attackershields > $shipinfo[ship_energy]) $attackershields = $shipinfo[ship_energy];
  $shipinfo[ship_energy] -= $attackershields;

  // *** ATTACKER TORPS ***
  $attackertorps = round(mypw($level_factor, $shipinfo[torp_launchers])) * 2;
  if ($attackertorps > $shipinfo[torps]) $attackertorps = $shipinfo[torps]; 
  $shipinfo[torps] -= $attackertorps;
  $attackertorpdamage = $torp_dmg_rate * $attackertorps;

  // *** ATTACKER FIGHTERS ***
  $attackerfighters = $shipinfo[ship_fighters];

  // *** ATTACKER ARMOUR ***
  $attackerarmor = $shipinfo[armour_pts];

  // *********************************
  // **** BEGIN COMBAT PROCEDURES ****
  // *********************************
  if($attackerbeams > 0 && $targetfighters > 0)
  {                         //******** ATTACKER HAS BEAMS - TARGET HAS FIGHTERS - BEAMS VS FIGHTERS ********
    if($attackerbeams > $targetfighters)
    {                                  //****** ATTACKER BEAMS GT TARGET FIGHTERS ******
      $lost = $targetfighters;
      $targetfighters = 0;                                     //**** T LOOSES ALL FIGHTERS ****
      $attackerbeams = $attackerbeams-$lost;                   //**** A LOOSES BEAMS EQ TO T FIGHTERS ****
    } else
    {                                  //****** ATTACKER BEAMS LE TARGET FIGHTERS ******
      $targetfighters = $targetfighters-$attackerbeams;        //**** T LOOSES FIGHTERS EQ TO A BEAMS ****
      $attackerbeams = 0;                                      //**** A LOOSES ALL BEAMS ****
    }   
  }
  if($attackerfighters > 0 && $targetbeams > 0)
  {                         //******** TARGET HAS BEAMS - ATTACKER HAS FIGHTERS - BEAMS VS FIGHTERS ********
    if($targetbeams > round($attackerfighters / 2))
    {                                  //****** TARGET BEAMS GT HALF ATTACKER FIGHTERS ******
      $lost=$attackerfighters-(round($attackerfighters/2));
      $attackerfighters=$attackerfighters-$lost;               //**** A LOOSES HALF ALL FIGHTERS ****
      $targetbeams=$targetbeams-$lost;                         //**** T LOOSES BEAMS EQ TO HALF A FIGHTERS ****
    } else
    {                                  //****** TARGET BEAMS LE HALF ATTACKER FIGHTERS ******
      $attackerfighters=$attackerfighters-$targetbeams;        //**** A LOOSES FIGHTERS EQ TO T BEAMS **** 
      $targetbeams=0;                                          //**** T LOOSES ALL BEAMS ****
    }
  }
  if($attackerbeams > 0)
  {                         //******** ATTACKER HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS SHIELDS ********
    if($attackerbeams > $targetshields)
    {                                  //****** ATTACKER BEAMS GT TARGET SHIELDS ******
      $attackerbeams=$attackerbeams-$targetshields;            //**** A LOOSES BEAMS EQ TO T SHIELDS ****
      $targetshields=0;                                        //**** T LOOSES ALL SHIELDS ****
    } else
    {                                  //****** ATTACKER BEAMS LE TARGET SHIELDS ******
      $targetshields=$targetshields-$attackerbeams;            //**** T LOOSES SHIELDS EQ TO A BEAMS ****
      $attackerbeams=0;                                        //**** A LOOSES ALL BEAMS ****
    }
  }
  if($targetbeams > 0)
  {                         //******** TARGET HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS SHIELDS ********
    if($targetbeams > $attackershields)
    {                                  //****** TARGET BEAMS GT ATTACKER SHIELDS ******
      $targetbeams=$targetbeams-$attackershields;              //**** T LOOSES BEAMS EQ TO A SHIELDS ****
      $attackershields=0;                                      //**** A LOOSES ALL SHIELDS ****
    } else
    {                                  //****** TARGET BEAMS LE ATTACKER SHIELDS ****** 
      $attackershields=$attackershields-$targetbeams;          //**** A LOOSES SHIELDS EQ TO T BEAMS ****
      $targetbeams=0;                                          //**** T LOOSES ALL BEAMS ****
    }
  }
  if($targetbeams > 0)
  {                        //******** TARGET HAS BEAMS LEFT - CONTINUE COMBAT - BEAMS VS ARMOR ******** 
    if($targetbeams > $attackerarmor)
    {                                 //****** TARGET BEAMS GT ATTACKER ARMOR ******
      $targetbeams=$targetbeams-$attackerarmor;                //**** T LOOSES BEAMS EQ TO A ARMOR ****
      $attackerarmor=0;                                        //**** A LOOSES ALL ARMOR (A DESTROYED) ****
    } else
    {                                 //****** TARGET BEAMS LE ATTACKER ARMOR ******
      $attackerarmor=$attackerarmor-$targetbeams;              //**** A LOOSES ARMOR EQ TO T BEAMS ****
      $targetbeams=0;                                          //**** T LOOSES ALL BEAMS ****
    } 
  }
  if($targetfighters > 0 && $attackertorpdamage > 0)
  {                        //******** ATTACKER FIRES TORPS - TARGET HAS FIGHTERS - TORPS VS FIGHTERS ********
    if($attackertorpdamage > $targetfighters)
    {                                 //****** ATTACKER FIRED TORPS GT TARGET FIGHTERS ******
      $lost=$targetfighters;
      $targetfighters=0;                                       //**** T LOOSES ALL FIGHTERS ****
      $attackertorpdamage=$attackertorpdamage-$lost;           //**** A LOOSES FIRED TORPS EQ TO T FIGHTERS ****
    } else
    {                                 //****** ATTACKER FIRED TORPS LE HALF TARGET FIGHTERS ******
      $targetfighters=$targetfighters-$attackertorpdamage;     //**** T LOOSES FIGHTERS EQ TO A TORPS FIRED ****
      $attackertorpdamage=0;                                   //**** A LOOSES ALL TORPS FIRED ****
    }
  }
  if($attackerfighters > 0 && $targettorpdmg > 0)
  {                        //******** TARGET FIRES TORPS - ATTACKER HAS FIGHTERS - TORPS VS FIGHTERS ********
    if($targettorpdmg > round($attackerfighters / 2))
    {                                 //****** TARGET FIRED TORPS GT HALF ATTACKER FIGHTERS ******
      $lost=$attackerfighters-(round($attackerfighters/2));
      $attackerfighters=$attackerfighters-$lost;               //**** A LOOSES HALF ALL FIGHTERS ****
      $targettorpdmg=$targettorpdmg-$lost;                     //**** T LOOSES FIRED TORPS EQ TO HALF A FIGHTERS ****
    } else
    {                                 //****** TARGET FIRED TORPS LE HALF ATTACKER FIGHTERS ******
      $attackerfighters=$attackerfighters-$targettorpdmg;      //**** A LOOSES FIGHTERS EQ TO T TORPS FIRED ****
      $targettorpdmg=0;                                        //**** T LOOSES ALL TORPS FIRED ****
    }
  }
  if($targettorpdmg > 0)
  {                        //******** TARGET FIRES TORPS - CONTINUE COMBAT - TORPS VS ARMOR ********
    if($targettorpdmg > $attackerarmor)
    {                                 //****** TARGET FIRED TORPS GT HALF ATTACKER ARMOR ******
      $targettorpdmg=$targettorpdmg-$attackerarmor;            //**** T LOOSES FIRED TORPS EQ TO A ARMOR ****
      $attackerarmor=0;                                        //**** A LOOSES ALL ARMOR (A DESTROYED) ****
    } else
    {                                 //****** TARGET FIRED TORPS LE HALF ATTACKER ARMOR ******
      $attackerarmor=$attackerarmor-$targettorpdmg;            //**** A LOOSES ARMOR EQ TO T TORPS FIRED ****
      $targettorpdmg=0;                                        //**** T LOOSES ALL TORPS FIRED ****
    } 
  }
  if($attackerfighters > 0 && $targetfighters > 0)
  {                        //******** ATTACKER HAS FIGHTERS - TARGET HAS FIGHTERS - FIGHTERS VS FIGHTERS ********
    if($attackerfighters > $targetfighters)
    {                                 //****** ATTACKER FIGHTERS GT TARGET FIGHTERS ******
      $temptargfighters=0;                                     //**** T WILL LOOSE ALL FIGHTERS ****
    } else
    {                                 //****** ATTACKER FIGHTERS LE TARGET FIGHTERS ******
      $temptargfighters=$targetfighters-$attackerfighters;     //**** T WILL LOOSE FIGHTERS EQ TO A FIGHTERS ****
    }
    if($targetfighters > $attackerfighters)
    {                                 //****** TARGET FIGHTERS GT ATTACKER FIGHTERS ******
      $tempplayfighters=0;                                     //**** A WILL LOOSE ALL FIGHTERS ****
    } else
    {                                 //****** TARGET FIGHTERS LE ATTACKER FIGHTERS ******
      $tempplayfighters=$attackerfighters-$targetfighters;     //**** A WILL LOOSE FIGHTERS EQ TO T FIGHTERS ****
    }     
    $attackerfighters=$tempplayfighters;
    $targetfighters=$temptargfighters;
  }
  if($targetfighters > 0)
  {                        //******** TARGET HAS FIGHTERS - CONTINUE COMBAT - FIGHTERS VS ARMOR ********
    if($targetfighters > $attackerarmor)
    {                                 //****** TARGET FIGHTERS GT ATTACKER ARMOR ******
      $attackerarmor=0;                                        //**** A LOOSES ALL ARMOR (A DESTROYED) ****
    } else
    {                                 //****** TARGET FIGHTERS LE ATTACKER ARMOR ******
      $attackerarmor=$attackerarmor-$targetfighters;           //**** A LOOSES ARMOR EQ TO T FIGHTERS ****
    }
  }

  // *********************************
  // **** FIX NEGATIVE VALUE VARS ****
  // *********************************
  if ($attackerfighters < 0) $attackerfighters = 0;
  if ($attackertorps    < 0) $attackertorps = 0;
  if ($attackershields  < 0) $attackershields = 0;
  if ($attackerbeams    < 0) $attackerbeams = 0;
  if ($attackerarmor    < 0) $attackerarmor = 0;
  if ($targetfighters   < 0) $targetfighters = 0;
  if ($targettorps      < 0) $targettorps = 0;
  if ($targetshields    < 0) $targetshields = 0;
  if ($targetbeams      < 0) $targetbeams = 0;

  // ******************************************
  // *** CHECK IF ATTACKER SHIP DESTROYED   ***
  // ******************************************
  if(!$attackerarmor>0)
  {
    playerlog($playerinfo[player_id], LOG_RAW, "Ship destroyed by planetary defenses on planet $planetinfo[name]");
    $furangeeisdead = 1;
// news
	$headline="Furangee Attacks ".$planetinfo[name]."!";
	$newstext="Furangee ".$playerinfo[character_name]." in the ship ".$shipinfo[ship_name]." led an attack today against ".$ownerinfo[character_name]."s planet ".$planetinfo[name]." but was brought down by heavy planetary defenses. ";
	if ($playerinfo[score] < $ownerinfo[score]) {
		$newstext = $newstext . $playerinfo[character_name]." was blinded by the huge riches stored on the planet.";
	} else {
		$newstext = $newstext . $playerinfo[character_name]." thought it would be easy money but underestimated the planet defenses.";
	}
	$player_id = $playerinfo[player_id];
	$news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'attack')");

    $free_ore = round($shipinfo[ship_ore]/2);
    $free_organics = round($shipinfo[ship_organics]/2);
    $free_goods = round($shipinfo[ship_goods]/2);
    $ship_value=$upgrade_cost*(round(mypw($upgrade_factor, $shipinfo[hull]))+round(mypw($upgrade_factor, $shipinfo[engines]))+round(mypw($upgrade_factor, $shipinfo[power]))+round(mypw($upgrade_factor, $shipinfo[computer]))+round(mypw($upgrade_factor, $shipinfo[sensors]))+round(mypw($upgrade_factor, $shipinfo[beams]))+round(mypw($upgrade_factor, $shipinfo[torp_launchers]))+round(mypw($upgrade_factor, $shipinfo[shields]))+round(mypw($upgrade_factor, $shipinfo[armor]))+round(mypw($upgrade_factor, $shipinfo[cloak])));
    $ship_salvage_rate=rand(10,20);
    $ship_salvage=$ship_value*$ship_salvage_rate/100;
    $fighters_lost = $planetinfo[fighters] - $targetfighters;

    db_kill_player($playerinfo[player_id],$playerinfo[currentship],$planetinfo[owner]);

    // *** LOG ATTACK TO PLANET OWNER ***
    playerlog($planetinfo[owner], LOG_PLANET_NOT_DEFEATED, "$planetinfo[name]|$planetinfo[sector_id]|Furangee $playerinfo[character_name]|".NUMBER($free_ore)."|".NUMBER($free_organics)."|".NUMBER($free_goods)."|".NUMBER($ship_salvage_rate)."|".NUMBER($ship_salvage));

    // *** UPDATE PLANET ***
    $db->Execute("UPDATE $dbtables[planets] SET energy=$planetinfo[energy],fighters=fighters-$fighters_lost, torps=torps-$targettorps, ore=ore+$free_ore, goods=goods+$free_goods, organics=organics+$free_organics, credits=credits+$ship_salvage WHERE planet_id=$planetinfo[planet_id]");
  
  }
  // **********************************************
  // *** MUST HAVE MADE IT PAST PLANET DEFENSES ***
  // **********************************************
  else
  {
    $armor_lost = $shipinfo[armour_pts] - $attackerarmor;
    $fighters_lost = $shipinfo[ship_fighters] - $attackerfighters;
    $target_fighters_lost = $planetinfo[fighters] - $targetfighters;
    playerlog($playerinfo[player_id], LOG_RAW, "Made it past defenses on planet $planetinfo[name]");

    // *** UPDATE ATTACKER ***
    $db->Execute ("UPDATE $dbtables[ships] SET energy=$shipinfo[ship_energy],fighters=fighters-$fighters_lost, torps=torps-$attackertorps, armour_pts=armour_pts-$armor_lost WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]");
    $shipinfo[ship_fighters] = $attackerfighters;
    $shipinfo[torps] = $attackertorps;
    $shipinfo[armour_pts] = $attackerarmor;


    // *** UPDATE PLANET ***
    $db->Execute ("UPDATE $dbtables[planets] SET energy=$planetinfo[energy], fighters=$targetfighters, torps=torps-$targettorps WHERE planet_id=$planetinfo[planet_id]");
    $planetinfo[fighters] = $targetfighters;
    $planetinfo[torps] = $targettorps;

    // *** NOW WE MUST ATTACK ALL SHIPS ON THE PLANET ONE BY ONE ***
	echo "Planet Info Bug tracker<br>";
	echo "Planet info planet ID = $planetinfo[planet_id]<br>";
    $resultps = $db->Execute("SELECT * FROM $dbtables[players] WHERE planet_id=$planetinfo[planet_id] AND on_planet='Y'");
    $shipsonplanet = $resultps->RecordCount();
    if ($shipsonplanet > 0)
    {
      while (!$resultps->EOF && $furangeeisdead < 1)
      {
        $onplanet = $resultps->fields;
        furangeetoship($onplanet[player_id]);
        $resultps->MoveNext();
      }
    }
    $resultps = $db->Execute("SELECT * FROM $dbtables[players] WHERE planet_id=$planetinfo[planet_id] AND on_planet='Y'");
    $shipsonplanet = $resultps->RecordCount();
    if ($shipsonplanet == 0 && $furangeeisdead < 1)
    {
      // *** MUST HAVE KILLED ALL SHIPS ON PLANET ***
      playerlog($playerinfo[player_id], LOG_RAW, "Defeated all ships on planet $planetinfo[name]");
      // *** LOG ATTACK TO PLANET OWNER ***
      playerlog($planetinfo[owner], LOG_PLANET_DEFEATED, "$planetinfo[name]|$planetinfo[sector_id]|Furangee $playerinfo[character_name]");
	  // news
	  $headline="Furangee Defeat Planet ".$planetinfo[name]."!";
	  $newstext="Furangee ".$playerinfo[character_name]." in the ship ".$shipinfo[ship_name]." defeated ".$ownerinfo[character_name]."s planet ".$planetinfo[name].". ";
		if ($playerinfo[score] < $ownerinfo[score]) {
			$newstext = $newstext . $playerinfo[character_name]." mentioned that the bigger they are, the easier the fall.";
		} else {
			$newstext = $newstext . $playerinfo[character_name]." took the weak out and stamped on them.";
		}
		$player_id = $playerinfo[player_id];
		$news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'attack')");

      // *** UPDATE PLANET ***
      $db->Execute("UPDATE $dbtables[planets] SET fighters=0, torps=0, base='N', owner=0, corp=0 WHERE planet_id=$planetinfo[planet_id]"); 
      calc_ownership($planetinfo[sector_id]);

    } else {
      // *** MUST HAVE DIED TRYING ***
      playerlog($playerinfo[player_id], LOG_RAW, "We were KILLED by ships defending planet $planetinfo[name]");
		// news
		$headline="Furangee burns up in attack!";
		$newstext="Furangee ".$playerinfo[character_name]." got intimate with deep space today when he tried to attack ".$ownerinfo[character_name]."s planet ".$planetinfo[name].". ";
		if ($playerinfo[score] < $ownerinfo[score]) {
			$newstext = $newstext . $playerinfo[character_name]." felt like his time had come and in a note left on the Intergalactic Bulletin Board he said that he wanted to go out in at least a modicum of style.";
		} else {
			$newstext = $newstext . $playerinfo[character_name]." was blinded by his own feelings of superiority.";
		}
		$player_id = $playerinfo[player_id];
		$news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'attack')");
      // *** LOG ATTACK TO PLANET OWNER ***
      playerlog($planetinfo[owner], LOG_PLANET_NOT_DEFEATED, "$planetinfo[name]|$planetinfo[sector_id]|Furangee $playerinfo[character_name]|0|0|0|0|0");

      // *** NO SALVAGE FOR PLANET BECAUSE WENT TO SHIP WHO WON **
    }

  }


  // *** END OF FURANGEE PLANET ATTACK CODE ***
  //$db->Execute("UNLOCK TABLES");

}