echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_engines</TD><TD align=center>$l_level $shipinfo[engines]</TD><TD align=center>Max $l_level $shipinfo[maxengines]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_power</TD><TD align=center>$l_level $shipinfo[power]</TD><TD align=center>Max $l_level $shipinfo[maxpower]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_computer</TD><TD align=center>$l_level $shipinfo[computer]</TD><TD align=center>Max $l_level $shipinfo[maxcomputer]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_sensors</TD><TD align=center>$l_level $shipinfo[sensors]</TD><TD align=center>Max $l_level $shipinfo[maxsensors]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_armour</TD><TD align=center>$l_level $shipinfo[armour]</TD><TD align=center>Max $l_level $shipinfo[maxarmour]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_shields</TD><TD align=center>$l_level $shipinfo[shields]</TD><TD align=center>Max $l_level $shipinfo[maxshields]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_beams</TD><TD align=center>$l_level $shipinfo[beams]</TD><TD align=center>Max $l_level $shipinfo[maxbeams]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_torp_launch</TD><TD align=center>$l_level $shipinfo[torp_launchers]</TD><TD align=center>Max $l_level $shipinfo[maxtorp_launchers]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_cloak</TD><TD align=center>$l_level $shipinfo[cloak]</TD><TD align=center>Max $l_level $shipinfo[maxcloak]</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD><i>$l_shipavg</i></TD><TD align=center>$l_level " . NUMBER($shipavg, 2) . "</TD><td></td></TR>"; echo "</TABLE><P>"; //echo "</TD><TD VALIGN=TOP>"; echo "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 WIDTH=\"100%\">"; $holds_used = $shipinfo[ship_ore] + $shipinfo[ship_organics] + $shipinfo[ship_goods] + $shipinfo[ship_colonists]; $holds_max = NUM_HOLDS($shipinfo[hull]); echo "<TR BGCOLOR=\"$color_header\"><TD><B>$l_holds</B></TD><TD ALIGN=RIGHT><B>" . NUMBER($holds_used) . " / " . NUMBER($holds_max) . "</B></TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_ore</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[ship_ore]) . "</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_organics</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[ship_organics]) . "</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_goods</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[ship_goods]) . "</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_colonists</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[ship_colonists]) . "</TD></TR>"; //echo "<TR><TD> </TD></TR>"; echo "</TABLE><P>"; echo "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 WIDTH=\"100%\">"; $armour_pts_max = NUM_ARMOUR($shipinfo[armour]); $ship_fighters_max = NUM_FIGHTERS($shipinfo[computer]); $torps_max = NUM_TORPEDOES($shipinfo[torp_launchers]); echo "<TR BGCOLOR=\"$color_header\"><TD COLSPAN=2 align=center><B>$l_arm_weap</B></TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_armourpts</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[armour_pts]) . " / " . NUMBER($armour_pts_max) . "</TD></TR>"; echo "<TR BGCOLOR=\"$color_line2\"><TD>$l_fighters</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[ship_fighters]) . " / " . NUMBER($ship_fighters_max) . "</TD></TR>"; echo "<TR BGCOLOR=\"$color_line1\"><TD>$l_torps</TD><TD ALIGN=RIGHT>" . NUMBER($shipinfo[torps]) . " / " . NUMBER($torps_max) . "</TD></TR>";
TEXT_GOTOMAIN(); die; } } } $genesis_free = $max_genesis - $playerinfo['dev_genesis']; $beacon_free = $max_beacons - $playerinfo['dev_beacon']; $emerwarp_free = $max_emerwarp - $playerinfo['dev_emerwarp']; $warpedit_free = $max_warpedit - $playerinfo['dev_warpedit']; $fighter_max = NUM_FIGHTERS($playerinfo['computer']); $fighter_free = $fighter_max - $playerinfo['ship_fighters']; $torpedo_max = NUM_TORPEDOES($playerinfo['torp_launchers']); $torpedo_free = $torpedo_max - $playerinfo['torps']; $armor_max = NUM_ARMOR($playerinfo['armor']); $armor_free = $armor_max - $playerinfo['armor_pts']; $colonist_max = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods']; if ($colonist_max < 0) { $colonist_max = 0; } $colonist_free = $colonist_max - $playerinfo['ship_colonists']; TEXT_JAVASCRIPT_BEGIN(); echo "function MakeMax(name, val)\n"; echo "{\n"; echo " if (document.forms[0].elements[name].value != val)\n"; echo " {\n"; echo " if (val != 0)\n"; echo " {\n"; echo " document.forms[0].elements[name].value = val;\n"; echo " }\n"; echo " }\n"; echo "}\n";
$news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'bounty')"); echo $l_port_bountypaid; die(); } } } } $emerwarp_free = $max_emerwarp - $shipinfo[dev_emerwarp]; $fighter_max = NUM_FIGHTERS($shipinfo[computer]); $fighter_free = $fighter_max - $shipinfo[ship_fighters]; $torpedo_max = NUM_TORPEDOES($shipinfo[torp_launchers]); $torpedo_free = $torpedo_max - $shipinfo[torps]; $armour_max = NUM_ARMOUR($shipinfo[armour]); $armour_free = $armour_max - $shipinfo[armour_pts]; $colonist_max = NUM_HOLDS($shipinfo[hull]) - $shipinfo[ship_ore] - $shipinfo[ship_organics] - $shipinfo[ship_goods]; $colonist_free = $colonist_max - $shipinfo[ship_colonists]; /* TEXT_JAVASCRIPT_BEGIN(); echo "function MakeMax(name, val)\n"; echo "{\n"; echo " if (document.forms[0].elements[name].value != val)\n"; echo " {\n"; echo " if (val != 0)\n"; echo " {\n"; echo " document.forms[0].elements[name].value = val;\n"; echo " }\n"; echo " }\n"; echo "}\n";
$headline="Failed ship attack!"; $newstext=$playerinfo[character_name]." in the ship ".$shipinfo[ship_name]." attacked ".$targetinfo[character_name]."'s ship but was overcome by ".$targetinfo[character_name]."'s defenses and was vapourized."; $player_id = $playerinfo[player_id]; $newstext=addslashes($newstext); $news = $db->Execute("INSERT INTO $dbtables[news] (headline, newstext, user_id, date, news_type) VALUES ('$headline','$newstext','$player_id',NOW(), 'attack')"); db_kill_player($playerinfo[player_id],$playerinfo[currentship],$targetinfo[player_id]); collect_bounty($targetinfo[player_id],$playerinfo[player_id]); // news player died due to no escape pod } if($targetarmour > 0) { // news opponent won when other player attacked $free_ore = floor($shipinfo[ship_ore]/2); $free_organics = floor($shipinfo[ship_organics]/2); $free_goods = floor($shipinfo[ship_goods]/2); $free_holds = NUM_HOLDS($targetshipinfo[hull]) - $targetshipinfo[ship_ore] - $targetshipinfo[ship_organics] - $targetshipinfo[ship_goods] - $targetshipinfo[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)
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"); }
echo "{$l_planet_none}<br>"; TEXT_GOTOMAIN(); include "footer.php"; die; } $trade_ore = round(abs($trade_ore)); $trade_organics = round(abs($trade_organics)); $trade_goods = round(abs($trade_goods)); $trade_energy = round(abs($trade_energy)); $ore_price = $ore_price + $ore_delta / 4; $organics_price = $organics_price + $organics_delta / 4; $goods_price = $goods_price + $goods_delta / 4; $energy_price = $energy_price + $energy_delta / 4; if ($planetinfo['sells'] == 'Y') { $cargo_exchanged = $trade_ore + $trade_organics + $trade_goods; $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists']; $free_power = NUM_ENERGY($playerinfo['power']) - $playerinfo['ship_energy']; $total_cost = $trade_ore * $ore_price + $trade_organics * $organics_price + $trade_goods * $goods_price + $trade_energy * $energy_price; if ($free_holds < $cargo_exchanged) { echo "{$l_notenough_cargo} <a href=planet.php?planet_id={$planet_id}>{$l_clickme}</a> {$l_toplanetmenu}<br><br>"; } elseif ($trade_energy > $free_power) { echo "{$l_notenough_power} <a href=planet.php?planet_id={$planet_id}>{$l_clickme}</a> {$l_toplanetmenu}<br><br>"; } elseif ($playerinfo['turns'] < 1) { echo "{$l_notenough_turns}<br><br>"; } elseif ($playerinfo['credits'] < $total_cost) { echo "{$l_notenough_credits}<br><br>"; } elseif ($trade_organics > $planetinfo['organics']) { echo "{$l_exceed_organics} "; } elseif ($trade_ore > $planetinfo['ore']) { echo "{$l_exceed_ore} "; } elseif ($trade_goods > $planetinfo['goods']) {
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 traderoute_engage($j) { global $playerinfo, $color_line1, $color_line2, $color_header; global $engage, $dist, $servertimezone; global $color_line2; global $color_line1; global $traderoutes; global $fighter_price; global $torpedo_price; global $colonist_price; global $colonist_limit; global $inventory_factor; global $ore_price; global $ore_delta; global $ore_limit; global $organics_price; global $organics_delta; global $organics_limit; global $goods_price; global $goods_delta; global $goods_limit; global $energy_price; global $energy_delta; global $energy_limit; global $mine_hullsize; global $l_tdr_turnsused, $l_tdr_turnsleft, $l_tdr_credits, $l_tdr_profit, $l_tdr_cost, $l_tdr_totalprofit, $l_tdr_totalcost; global $l_tdr_planetisovercrowded, $l_tdr_engageagain, $l_tdr_onlyonewaytdr, $l_tdr_engagenonexist, $l_tdr_notowntdr; global $l_tdr_invalidspoint, $l_tdr_inittdr, $l_tdr_invalidsrc, $l_tdr_inittdrsector, $l_tdr_organics, $l_tdr_energy, $l_tdr_loaded; global $l_tdr_nothingtoload, $l_tdr_scooped, $l_tdr_dumped, $l_tdr_portisempty, $l_tdr_portisfull, $l_tdr_ore, $l_tdr_sold; global $l_tdr_goods, $l_tdr_notyourplanet, $l_tdr_invalidssector, $l_tdr_invaliddport, $l_tdr_invaliddplanet; global $l_tdr_invaliddsector, $l_tdr_nowlink1, $l_tdr_nowlink2, $l_tdr_moreturnsneeded, $l_tdr_hostdef; global $l_tdr_globalsetbuynothing, $l_tdr_nosrcporttrade, $l_tdr_tradesrcportoutsider, $l_tdr_res, $l_tdr_torps; global $l_tdr_nodestporttrade, $l_tdr_tradedestportoutsider, $l_tdr_portin, $l_tdr_planet, $l_tdr_bought, $l_tdr_colonists; global $l_tdr_fighters, $l_tdr_nothingtotrade, $l_here, $l_tdr_five, $l_tdr_ten, $l_tdr_fifty; global $l_tdr_nothingtodump; global $db; global $db_logging; global $portfull; foreach ($traderoutes as $testroute) { if ($testroute['traderoute_id'] == $engage) { $traderoute = $testroute; } } if (!isset($traderoute)) { traderoute_die($l_tdr_engagenonexist); } if ($traderoute['owner'] != $playerinfo['ship_id']) { traderoute_die($l_tdr_notowntdr); } // Source Check if ($traderoute['source_type'] == 'P') { // Retrieve port info here, we'll need it later anyway $result = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id=?;", array($traderoute['source_id'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); // $result = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=$traderoute[source_id] AND (owner = $playerinfo[ship_id] OR (corp <> 0 AND corp = $playerinfo[team]));"); if (!$result || $result->EOF) { traderoute_die($l_tdr_invalidspoint); } $source = $result->fields; if ($traderoute['source_id'] != $playerinfo['sector']) { $l_tdr_inittdr = str_replace("[tdr_source_id]", $traderoute['source_id'], $l_tdr_inittdr); traderoute_die($l_tdr_inittdr); } } elseif ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { // $result = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=$traderoute[source_id]"); $result = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=? AND (owner = ? OR (corp <> 0 AND corp = ?));", array($traderoute['source_id'], $playerinfo['ship_id'], $playerinfo['team'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); if (!$result || $result->EOF) { traderoute_die($l_tdr_invalidsrc); } $source = $result->fields; if ($source['sector_id'] != $playerinfo['sector']) { // Check for valid Owned Source Planet // $l_tdr_inittdrsector = str_replace("[tdr_source_sector_id]", $source['sector_id'], $l_tdr_inittdrsector); // traderoute_die ($l_tdr_inittdrsector); traderoute_die("You must be in starting sector before you initiate a trade route!"); } if ($traderoute['source_type'] == 'L') { if ($source['owner'] != $playerinfo['ship_id']) { // $l_tdr_notyourplanet = str_replace("[tdr_source_name]", $source[name], $l_tdr_notyourplanet); // $l_tdr_notyourplanet = str_replace("[tdr_source_sector_id]", $source[sector_id], $l_tdr_notyourplanet); // traderoute_die ($l_tdr_notyourplanet); traderoute_die($l_tdr_invalidsrc); } } elseif ($traderoute['source_type'] == 'C') { if ($source['corp'] != $playerinfo['team']) { // $l_tdr_notyourplanet = str_replace("[tdr_source_name]", $source[name], $l_tdr_notyourplanet); // $l_tdr_notyourplanet = str_replace("[tdr_source_sector_id]", $source[sector_id], $l_tdr_notyourplanet); // $not_corp_planet = "$source[name] in $source[sector_id] not a Copporate Planet"; // traderoute_die ($not_corp_planet); traderoute_die($l_tdr_invalidsrc); } } // Store starting port info, we'll need it later $result = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id=?;", array($source['sector_id'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); if (!$result || $result->EOF) { traderoute_die($l_tdr_invalidssector); } $sourceport = $result->fields; } // Destination Check if ($traderoute['dest_type'] == 'P') { $result = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id=?;", array($traderoute['dest_id'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); if (!$result || $result->EOF) { traderoute_die($l_tdr_invaliddport); } $dest = $result->fields; } elseif ($traderoute['dest_type'] == 'L' || $traderoute['dest_type'] == 'C') { // Check for valid Owned Source Planet // This now only returns Planets that the player owns or planets that belong to the team and set as corp planets.. // $result = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=$traderoute[dest_id]"); $result = $db->Execute("SELECT * FROM {$db->prefix}planets WHERE planet_id=? AND (owner = ? OR (corp <> 0 AND corp = ?));", array($traderoute['dest_id'], $playerinfo['ship_id'], $playerinfo['team'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); if (!$result || $result->EOF) { traderoute_die($l_tdr_invaliddplanet); } $dest = $result->fields; if ($traderoute['dest_type'] == 'L') { if ($dest['owner'] != $playerinfo['ship_id']) { $l_tdr_notyourplanet = str_replace("[tdr_source_name]", $dest['name'], $l_tdr_notyourplanet); $l_tdr_notyourplanet = str_replace("[tdr_source_sector_id]", $dest['sector_id'], $l_tdr_notyourplanet); traderoute_die($l_tdr_notyourplanet); } } elseif ($traderoute['dest_type'] == 'C') { if ($dest['corp'] != $playerinfo['team']) { $l_tdr_notyourplanet = str_replace("[tdr_source_name]", $dest['name'], $l_tdr_notyourplanet); $l_tdr_notyourplanet = str_replace("[tdr_source_sector_id]", $dest['sector_id'], $l_tdr_notyourplanet); traderoute_die($l_tdr_notyourplanet); } } $result = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id=?;", array($dest['sector_id'])); db_op_result($db, $result, __LINE__, __FILE__, $db_logging); if (!$result || $result->EOF) { traderoute_die($l_tdr_invaliddsector); } $destport = $result->fields; } if (!isset($sourceport)) { $sourceport = $source; } if (!isset($destport)) { $destport = $dest; } // Warp or RealSpace and generate distance if ($traderoute['move_type'] == 'W') { $query = $db->Execute("SELECT link_id FROM {$db->prefix}links WHERE link_start=? AND link_dest=?;", array($source['sector_id'], $dest['sector_id'])); db_op_result($db, $query, __LINE__, __FILE__, $db_logging); if ($query->EOF) { $l_tdr_nowlink1 = str_replace("[tdr_src_sector_id]", $source['sector_id'], $l_tdr_nowlink1); $l_tdr_nowlink1 = str_replace("[tdr_dest_sector_id]", $dest['sector_id'], $l_tdr_nowlink1); traderoute_die($l_tdr_nowlink1); } if ($traderoute['circuit'] == '2') { $query = $db->Execute("SELECT link_id FROM {$db->prefix}links WHERE link_start=? AND link_dest=?;", array($dest['sector_id'], $source['sector_id'])); db_op_result($db, $query, __LINE__, __FILE__, $db_logging); if ($query->EOF) { $l_tdr_nowlink2 = str_replace("[tdr_src_sector_id]", $source['sector_id'], $l_tdr_nowlink2); $l_tdr_nowlink2 = str_replace("[tdr_dest_sector_id]", $dest['sector_id'], $l_tdr_nowlink2); traderoute_die($l_tdr_nowlink2); } $dist['triptime'] = 4; } else { $dist['triptime'] = 2; } $dist['scooped'] = 0; $dist['scooped1'] = 0; $dist['scooped2'] = 0; } else { $dist = traderoute_distance('P', 'P', $sourceport, $destport, $traderoute['circuit']); } // Check if player has enough turns if ($playerinfo['turns'] < $dist['triptime']) { $l_tdr_moreturnsneeded = str_replace("[tdr_dist_triptime]", $dist['triptime'], $l_tdr_moreturnsneeded); $l_tdr_moreturnsneeded = str_replace("[tdr_playerinfo_turns]", $playerinfo['turns'], $l_tdr_moreturnsneeded); traderoute_die($l_tdr_moreturnsneeded); } // Sector Defense Check $hostile = 0; $result99 = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id = ? AND ship_id <> ?;", array($source['sector_id'], $playerinfo['ship_id'])); db_op_result($db, $result99, __LINE__, __FILE__, $db_logging); if (!$result99->EOF) { $fighters_owner = $result99->fields; $nsresult = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?;", array($fighters_owner['ship_id'])); db_op_result($db, $nsresult, __LINE__, __FILE__, $db_logging); $nsfighters = $nsresult->fields; if ($nsfighters['team'] != $playerinfo['team'] || $playerinfo['team'] == 0) { $hostile = 1; } } $result98 = $db->Execute("SELECT * FROM {$db->prefix}sector_defence WHERE sector_id = ? AND ship_id <> ?;", array($dest['sector_id'], $playerinfo['ship_id'])); db_op_result($db, $result98, __LINE__, __FILE__, $db_logging); if (!$result98->EOF) { $fighters_owner = $result98->fields; $nsresult = $db->Execute("SELECT * FROM {$db->prefix}ships WHERE ship_id=?;", array($fighters_owner['ship_id'])); db_op_result($db, $nsresult, __LINE__, __FILE__, $db_logging); $nsfighters = $nsresult->fields; if ($nsfighters['team'] != $playerinfo['team'] || $playerinfo['team'] == 0) { $hostile = 1; } } if ($hostile > 0 && $playerinfo['hull'] > $mine_hullsize) { traderoute_die($l_tdr_hostdef); } // Special Port Nothing to do if ($traderoute['source_type'] == 'P' && $source['port_type'] == 'special' && $playerinfo['trade_colonists'] == 'N' && $playerinfo['trade_fighters'] == 'N' && $playerinfo['trade_torps'] == 'N') { traderoute_die($l_tdr_globalsetbuynothing); } // Check if zone allows trading SRC if ($traderoute['source_type'] == 'P') { $res = $db->Execute("SELECT * FROM {$db->prefix}zones,{$db->prefix}universe WHERE {$db->prefix}universe.sector_id=? AND {$db->prefix}zones.zone_id={$db->prefix}universe.zone_id;", array($traderoute['source_id'])); db_op_result($db, $res, __LINE__, __FILE__, $db_logging); $zoneinfo = $res->fields; if ($zoneinfo['allow_trade'] == 'N') { traderoute_die($l_tdr_nosrcporttrade); } elseif ($zoneinfo['allow_trade'] == 'L') { if ($zoneinfo['corp_zone'] == 'N') { $res = $db->Execute("SELECT team FROM {$db->prefix}ships WHERE ship_id=?;", array($zoneinfo['owner'])); db_op_result($db, $res, __LINE__, __FILE__, $db_logging); $ownerinfo = $res->fields; if ($playerinfo['ship_id'] != $zoneinfo['owner'] && $playerinfo['team'] == 0 || $playerinfo['team'] != $ownerinfo['team']) { traderoute_die($l_tdr_tradesrcportoutsider); } } else { if ($playerinfo['team'] != $zoneinfo['owner']) { traderoute_die($l_tdr_tradesrcportoutsider); } } } } // Check if zone allows trading DEST if ($traderoute['dest_type'] == 'P') { $res = $db->Execute("SELECT * FROM {$db->prefix}zones,{$db->prefix}universe WHERE {$db->prefix}universe.sector_id=? AND {$db->prefix}zones.zone_id={$db->prefix}universe.zone_id;", array($traderoute['dest_id'])); db_op_result($db, $res, __LINE__, __FILE__, $db_logging); $zoneinfo = $res->fields; if ($zoneinfo['allow_trade'] == 'N') { traderoute_die($l_tdr_nodestporttrade); } elseif ($zoneinfo['allow_trade'] == 'L') { if ($zoneinfo['corp_zone'] == 'N') { $res = $db->Execute("SELECT team FROM {$db->prefix}ships WHERE ship_id=?;", array($zoneinfo['owner'])); db_op_result($db, $res, __LINE__, __FILE__, $db_logging); $ownerinfo = $res->fields; if ($playerinfo['ship_id'] != $zoneinfo['owner'] && $playerinfo['team'] == 0 || $playerinfo['team'] != $ownerinfo['team']) { traderoute_die($l_tdr_tradedestportoutsider); } } else { if ($playerinfo['team'] != $zoneinfo['owner']) { traderoute_die($l_tdr_tradedestportoutsider); } } } } traderoute_results_table_top(); // Determine if Source is Planet or Port if ($traderoute['source_type'] == 'P') { echo "{$l_tdr_portin} {$source['sector_id']}"; } elseif ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { echo "{$l_tdr_planet} {$source['name']} in {$sourceport['sector_id']}"; } traderoute_results_source(); // Determine if Destination is Planet or Port if ($traderoute['dest_type'] == 'P') { echo "{$l_tdr_portin} {$dest['sector_id']}"; } elseif ($traderoute['dest_type'] == 'L' || $traderoute['dest_type'] == 'C') { echo "{$l_tdr_planet} {$dest['name']} in {$destport['sector_id']}"; } traderoute_results_destination(); $sourcecost = 0; // Source is Port if ($traderoute['source_type'] == 'P') { // Special Port Section (begin) if ($source['port_type'] == 'special') { $ore_buy = 0; $goods_buy = 0; $organics_buy = 0; $energy_buy = 0; $total_credits = $playerinfo['credits']; if ($playerinfo['trade_colonists'] == 'Y') { $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists']; $colonists_buy = $free_holds; if ($playerinfo['credits'] < $colonist_price * $colonists_buy) { $colonists_buy = $playerinfo['credits'] / $colonist_price; } if ($colonists_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($colonists_buy) . " {$l_tdr_colonists}<br>"; } $sourcecost -= $colonists_buy * $colonist_price; $total_credits -= $colonists_buy * $colonist_price; } else { $colonists_buy = 0; } if ($playerinfo['trade_fighters'] == 'Y') { $free_fighters = NUM_FIGHTERS($playerinfo['computer']) - $playerinfo['ship_fighters']; $fighters_buy = $free_fighters; if ($total_credits < $fighters_buy * $fighter_price) { $fighters_buy = $total_credits / $fighter_price; } if ($fighters_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($fighters_buy) . " {$l_tdr_fighters}<br>"; } $sourcecost -= $fighters_buy * $fighter_price; $total_credits -= $fighters_buy * $fighter_price; } else { $fighters_buy = 0; } if ($playerinfo['trade_torps'] == 'Y') { $free_torps = NUM_FIGHTERS($playerinfo['torp_launchers']) - $playerinfo['torps']; $torps_buy = $free_torps; if ($total_credits < $torps_buy * $torpedo_price) { $torps_buy = $total_credits / $torpedo_price; } if ($torps_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($torps_buy) . " {$l_tdr_torps}<br>"; } $sourcecost -= $torps_buy * $torpedo_price; } else { $torps_buy = 0; } if ($torps_buy == 0 && $colonists_buy == 0 && $fighters_buy == 0) { echo "{$l_tdr_nothingtotrade}<br>"; } if ($traderoute['circuit'] == '1') { $resb = $db->Execute("UPDATE {$db->prefix}ships SET ship_colonists=ship_colonists+?, ship_fighters=ship_fighters+?,torps=torps+?, ship_energy=ship_energy+? WHERE ship_id=?;", array($colonists_buy, $fighters_buy, $torps_buy, $dist['scooped1'], $playerinfo['ship_id'])); db_op_result($db, $resb, __LINE__, __FILE__, $db_logging); } } else { // Sells commodities // Added below initializations, for traderoute bug $ore_buy = 0; $goods_buy = 0; $organics_buy = 0; $energy_buy = 0; if ($source['port_type'] != 'ore') { $ore_price1 = $ore_price + $ore_delta * $source['port_ore'] / $ore_limit * $inventory_factor; if ($source['port_ore'] - $playerinfo['ship_ore'] < 0) { $ore_buy = $source['port_ore']; $portfull = 1; } else { $ore_buy = $playerinfo['ship_ore']; } $sourcecost += $ore_buy * $ore_price1; if ($ore_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($ore_buy) . " {$l_tdr_ore} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($ore_buy) . " {$l_tdr_ore}<br>"; } } $playerinfo['ship_ore'] -= $ore_buy; } $portfull = 0; if ($source['port_type'] != 'goods') { $goods_price1 = $goods_price + $goods_delta * $source['port_goods'] / $goods_limit * $inventory_factor; if ($source['port_goods'] - $playerinfo['ship_goods'] < 0) { $goods_buy = $source['port_goods']; $portfull = 1; } else { $goods_buy = $playerinfo['ship_goods']; } $sourcecost += $goods_buy * $goods_price1; if ($goods_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($goods_buy) . " {$l_tdr_goods} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($goods_buy) . " {$l_tdr_goods}<br>"; } } $playerinfo['ship_goods'] -= $goods_buy; } $portfull = 0; if ($source['port_type'] != 'organics') { $organics_price1 = $organics_price + $organics_delta * $source['port_organics'] / $organics_limit * $inventory_factor; if ($source['port_organics'] - $playerinfo['ship_organics'] < 0) { $organics_buy = $source['port_organics']; $portfull = 1; } else { $organics_buy = $playerinfo['ship_organics']; } $sourcecost += $organics_buy * $organics_price1; if ($organics_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($organics_buy) . " {$l_tdr_organics} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($organics_buy) . " {$l_tdr_organics}<br>"; } } $playerinfo['ship_organics'] -= $organics_buy; } $portfull = 0; if ($source['port_type'] != 'energy' && $playerinfo['trade_energy'] == 'Y') { $energy_price1 = $energy_price + $energy_delta * $source['port_energy'] / $energy_limit * $inventory_factor; if ($source['port_energy'] - $playerinfo['ship_energy'] < 0) { $energy_buy = $source['port_energy']; $portfull = 1; } else { $energy_buy = $playerinfo['ship_energy']; } $sourcecost += $energy_buy * $energy_price1; if ($energy_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($energy_buy) . " {$l_tdr_energy} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($energy_buy) . " {$l_tdr_energy}<br>"; } } $playerinfo['ship_energy'] -= $energy_buy; } $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists']; // Time to buy if ($source['port_type'] == 'ore') { $ore_price1 = $ore_price - $ore_delta * $source['port_ore'] / $ore_limit * $inventory_factor; $ore_buy = $free_holds; if ($playerinfo['credits'] + $sourcecost < $ore_buy * $ore_price1) { $ore_buy = ($playerinfo['credits'] + $sourcecost) / $ore_price1; } if ($source['port_ore'] < $ore_buy) { $ore_buy = $source['port_ore']; if ($source['port_ore'] == 0) { echo "{$l_tdr_bought} " . NUMBER($ore_buy) . " {$l_tdr_ore} ({$l_tdr_portisempty})<br>"; } } if ($ore_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($ore_buy) . " {$l_tdr_ore}<br>"; } $playerinfo['ship_ore'] += $ore_buy; $sourcecost -= $ore_buy * $ore_price1; $resc = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $source['sector_id'])); db_op_result($db, $resc, __LINE__, __FILE__, $db_logging); } if ($source['port_type'] == 'goods') { $goods_price1 = $goods_price - $goods_delta * $source['port_goods'] / $goods_limit * $inventory_factor; $goods_buy = $free_holds; if ($playerinfo['credits'] + $sourcecost < $goods_buy * $goods_price1) { $goods_buy = ($playerinfo['credits'] + $sourcecost) / $goods_price1; } if ($source['port_goods'] < $goods_buy) { $goods_buy = $source['port_goods']; if ($source['port_goods'] == 0) { echo "{$l_tdr_bought} " . NUMBER($goods_buy) . " {$l_tdr_goods} ({$l_tdr_portisempty})<br>"; } } if ($goods_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($goods_buy) . " {$l_tdr_goods}<br>"; } $playerinfo['ship_goods'] += $goods_buy; $sourcecost -= $goods_buy * $goods_price1; $resd = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $source['sector_id'])); db_op_result($db, $resd, __LINE__, __FILE__, $db_logging); } if ($source['port_type'] == 'organics') { $organics_price1 = $organics_price - $organics_delta * $source['port_organics'] / $organics_limit * $inventory_factor; $organics_buy = $free_holds; if ($playerinfo['credits'] + $sourcecost < $organics_buy * $organics_price1) { $organics_buy = ($playerinfo['credits'] + $sourcecost) / $organics_price1; } if ($source['port_organics'] < $organics_buy) { $organics_buy = $source['port_organics']; if ($source['port_organics'] == 0) { echo "{$l_tdr_bought} " . NUMBER($organics_buy) . " {$l_tdr_organics} ({$l_tdr_portisempty})<br>"; } } if ($organics_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($organics_buy) . " {$l_tdr_organics}<br>"; } $playerinfo['ship_organics'] += $organics_buy; $sourcecost -= $organics_buy * $organics_price1; $rese = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $source['sector_id'])); db_op_result($db, $rese, __LINE__, __FILE__, $db_logging); } if ($source['port_type'] == 'energy') { $energy_price1 = $energy_price - $energy_delta * $source['port_energy'] / $energy_limit * $inventory_factor; $energy_buy = NUM_ENERGY($playerinfo['power']) - $playerinfo['ship_energy'] - $dist['scooped1']; if ($playerinfo['credits'] + $sourcecost < $energy_buy * $energy_price1) { $energy_buy = ($playerinfo['credits'] + $sourcecost) / $energy_price1; } if ($source['port_energy'] < $energy_buy) { $energy_buy = $source['port_energy']; if ($source['port_energy'] == 0) { echo "{$l_tdr_bought} " . NUMBER($energy_buy) . " {$l_tdr_energy} ({$l_tdr_portisempty})<br>"; } } if ($energy_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($energy_buy) . " {$l_tdr_energy}<br>"; } $playerinfo['ship_energy'] += $energy_buy; $sourcecost -= $energy_buy * $energy_price1; $resf = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $source['sector_id'])); db_op_result($db, $resf, __LINE__, __FILE__, $db_logging); } if ($dist['scooped1'] > 0) { $playerinfo['ship_energy'] += $dist['scooped1']; if ($playerinfo['ship_energy'] > NUM_ENERGY($playerinfo['power'])) { $playerinfo['ship_energy'] = NUM_ENERGY($playerinfo['power']); } } if ($ore_buy == 0 && $goods_buy == 0 && $energy_buy == 0 && $organics_buy == 0) { echo "{$l_tdr_nothingtotrade}<br>"; } if ($traderoute['circuit'] == '1') { $resf = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=?, ship_goods=?, ship_organics=?, ship_energy=? WHERE ship_id=?;", array($playerinfo['ship_ore'], $playerinfo['ship_goods'], $playerinfo['ship_organics'], $playerinfo['ship_energy'], $playerinfo['ship_id'])); db_op_result($db, $resf, __LINE__, __FILE__, $db_logging); } } } elseif ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists']; if ($traderoute['dest_type'] == 'P') { // Pick stuff up to sell at port if ($playerinfo['ship_id'] == $source['owner'] || $playerinfo['team'] == $source['corp']) { if ($source['goods'] > 0 && $free_holds > 0 && $dest['port_type'] != 'goods') { if ($source['goods'] > $free_holds) { $goods_buy = $free_holds; } else { $goods_buy = $source['goods']; } $free_holds -= $goods_buy; $playerinfo['ship_goods'] += $goods_buy; echo "{$l_tdr_loaded} " . NUMBER($goods_buy) . " {$l_tdr_goods}<br>"; } else { $goods_buy = 0; } if ($source['ore'] > 0 && $free_holds > 0 && $dest['port_type'] != 'ore') { if ($source['ore'] > $free_holds) { $ore_buy = $free_holds; } else { $ore_buy = $source['ore']; } $free_holds -= $ore_buy; $playerinfo['ship_ore'] += $ore_buy; echo "{$l_tdr_loaded} " . NUMBER($ore_buy) . " {$l_tdr_ore}<br>"; } else { $ore_buy = 0; } if ($source['organics'] > 0 && $free_holds > 0 && $dest['port_type'] != 'organics') { if ($source['organics'] > $free_holds) { $organics_buy = $free_holds; } else { $organics_buy = $source['organics']; } $free_holds -= $organics_buy; $playerinfo['ship_organics'] += $organics_buy; echo "{$l_tdr_loaded} " . NUMBER($organics_buy) . " {$l_tdr_organics}<br>"; } else { $organics_buy = 0; } if ($ore_buy == 0 && $goods_buy == 0 && $organics_buy == 0) { echo "{$l_tdr_nothingtoload}<br>"; } if ($traderoute['circuit'] == '1') { $resg = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=?, ship_goods=?, ship_organics=? WHERE ship_id=?;", array($playerinfo['ship_ore'], $playerinfo['ship_goods'], $playerinfo['ship_organics'], $playerinfo['ship_id'])); db_op_result($db, $resg, __LINE__, __FILE__, $db_logging); } } else { } $resh = $db->Execute("UPDATE {$db->prefix}planets SET ore=ore-?, goods=goods-?, organics=organics-? WHERE planet_id=?;", array($ore_buy, $goods_buy, $organics_buy, $source['planet_id'])); db_op_result($db, $resh, __LINE__, __FILE__, $db_logging); } elseif ($traderoute['dest_type'] == 'L' || $traderoute['dest_type'] == 'C') { if ($source['colonists'] > 0 && $free_holds > 0 && $playerinfo['trade_colonists'] == 'Y') { if ($source['colonists'] > $free_holds) { $colonists_buy = $free_holds; } else { $colonists_buy = $source['colonists']; } $free_holds -= $colonists_buy; $playerinfo['ship_colonists'] += $colonists_buy; echo "{$l_tdr_loaded} " . NUMBER($colonists_buy) . " {$l_tdr_colonists}<br>"; } else { $colonists_buy = 0; } $free_torps = NUM_TORPEDOES($playerinfo['torp_launchers']) - $playerinfo['torps']; if ($source['torps'] > 0 && $free_torps > 0 && $playerinfo['trade_torps'] == 'Y') { if ($source['torps'] > $free_torps) { $torps_buy = $free_torps; } else { $torps_buy = $source['torps']; } $free_torps -= $torps_buy; $playerinfo['torps'] += $torps_buy; echo "{$l_tdr_loaded} " . NUMBER($torps_buy) . " {$l_tdr_torps}<br>"; } else { $torps_buy = 0; } $free_fighters = NUM_FIGHTERS($playerinfo['computer']) - $playerinfo['ship_fighters']; if ($source['fighters'] > 0 && $free_fighters > 0 && $playerinfo['trade_fighters'] == 'Y') { if ($source['fighters'] > $free_fighters) { $fighters_buy = $free_fighters; } else { $fighters_buy = $source['fighters']; } $free_fighters -= $fighters_buy; $playerinfo['ship_fighters'] += $fighters_buy; echo "{$l_tdr_loaded} " . NUMBER($fighters_buy) . " {$l_tdr_fighters}<br>"; } else { $fighters_buy = 0; } if ($fighters_buy == 0 && $torps_buy == 0 && $colonists_buy == 0) { echo "{$l_tdr_nothingtoload}<br>"; } if ($traderoute['circuit'] == '1') { $resi = $db->Execute("UPDATE {$db->prefix}ships SET torps=?, ship_fighters=?, ship_colonists=? WHERE ship_id=?;", array($playerinfo['torps'], $playerinfo['ship_fighters'], $playerinfo['ship_colonists'], $playerinfo['ship_id'])); db_op_result($db, $resi, __LINE__, __FILE__, $db_logging); } $resj = $db->Execute("UPDATE {$db->prefix}planets SET colonists=colonists-?, torps=torps-?, fighters=fighters-? WHERE planet_id=?;", array($colonists_buy, $torps_buy, $fighters_buy, $source['planet_id'])); db_op_result($db, $resj, __LINE__, __FILE__, $db_logging); } } if ($dist['scooped1'] != 0) { echo "{$l_tdr_scooped} " . NUMBER($dist['scooped1']) . " {$l_tdr_energy}<br>"; } traderoute_results_close_cell(); if ($traderoute['circuit'] == '2') { $playerinfo['credits'] += $sourcecost; $destcost = 0; if ($traderoute['dest_type'] == 'P') { // Added the below for traderoute bug $ore_buy = 0; $goods_buy = 0; $organics_buy = 0; $energy_buy = 0; // Sells commodities $portfull = 0; if ($dest['port_type'] != 'ore') { $ore_price1 = $ore_price + $ore_delta * $dest['port_ore'] / $ore_limit * $inventory_factor; if ($dest['port_ore'] - $playerinfo['ship_ore'] < 0) { $ore_buy = $dest['port_ore']; $portfull = 1; } else { $ore_buy = $playerinfo['ship_ore']; } $destcost += $ore_buy * $ore_price1; if ($ore_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($ore_buy) . " {$l_tdr_ore} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($ore_buy) . " {$l_tdr_ore}<br>"; } } $playerinfo['ship_ore'] -= $ore_buy; } $portfull = 0; if ($dest['port_type'] != 'goods') { $goods_price1 = $goods_price + $goods_delta * $dest['port_goods'] / $goods_limit * $inventory_factor; if ($dest['port_goods'] - $playerinfo['ship_goods'] < 0) { $goods_buy = $dest['port_goods']; $portfull = 1; } else { $goods_buy = $playerinfo['ship_goods']; } $destcost += $goods_buy * $goods_price1; if ($goods_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($goods_buy) . " {$l_tdr_goods} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($goods_buy) . " {$l_tdr_goods}<br>"; } } $playerinfo['ship_goods'] -= $goods_buy; } $portfull = 0; if ($dest['port_type'] != 'organics') { $organics_price1 = $organics_price + $organics_delta * $dest['port_organics'] / $organics_limit * $inventory_factor; if ($dest['port_organics'] - $playerinfo['ship_organics'] < 0) { $organics_buy = $dest['port_organics']; $portfull = 1; } else { $organics_buy = $playerinfo['ship_organics']; } $destcost += $organics_buy * $organics_price1; if ($organics_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($organics_buy) . " {$l_tdr_organics} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($organics_buy) . " {$l_tdr_organics}<br>"; } } $playerinfo['ship_organics'] -= $organics_buy; } $portfull = 0; if ($dest['port_type'] != 'energy' && $playerinfo['trade_energy'] == 'Y') { $energy_price1 = $energy_price + $energy_delta * $dest['port_energy'] / $energy_limit * $inventory_factor; if ($dest['port_energy'] - $playerinfo['ship_energy'] < 0) { $energy_buy = $dest['port_energy']; $portfull = 1; } else { $energy_buy = $playerinfo['ship_energy']; } $destcost += $energy_buy * $energy_price1; if ($energy_buy != 0) { if ($portfull == 1) { echo "{$l_tdr_sold} " . NUMBER($energy_buy) . " {$l_tdr_energy} ({$l_tdr_portisfull})<br>"; } else { echo "{$l_tdr_sold} " . NUMBER($energy_buy) . " {$l_tdr_energy}<br>"; } } $playerinfo['ship_energy'] -= $energy_buy; } else { $energy_buy = 0; } $free_holds = NUM_HOLDS($playerinfo['hull']) - $playerinfo['ship_ore'] - $playerinfo['ship_organics'] - $playerinfo['ship_goods'] - $playerinfo['ship_colonists']; // Time to buy if ($dest['port_type'] == 'ore') { $ore_price1 = $ore_price - $ore_delta * $dest['port_ore'] / $ore_limit * $inventory_factor; if ($traderoute['source_type'] == 'L') { $ore_buy = 0; } else { $ore_buy = $free_holds; if ($playerinfo['credits'] + $destcost < $ore_buy * $ore_price1) { $ore_buy = ($playerinfo['credits'] + $destcost) / $ore_price1; } if ($dest['port_ore'] < $ore_buy) { $ore_buy = $dest['port_ore']; if ($dest['port_ore'] == 0) { echo "{$l_tdr_bought} " . NUMBER($ore_buy) . " {$l_tdr_ore} ({$l_tdr_portisempty})<br>"; } } if ($ore_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($ore_buy) . " {$l_tdr_ore}<br>"; } $playerinfo['ship_ore'] += $ore_buy; $destcost -= $ore_buy * $ore_price1; } $resk = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $dest['sector_id'])); db_op_result($db, $resk, __LINE__, __FILE__, $db_logging); } if ($dest['port_type'] == 'goods') { $goods_price1 = $goods_price - $goods_delta * $dest['port_goods'] / $goods_limit * $inventory_factor; if ($traderoute['source_type'] == 'L') { $goods_buy = 0; } else { $goods_buy = $free_holds; if ($playerinfo['credits'] + $destcost < $goods_buy * $goods_price1) { $goods_buy = ($playerinfo['credits'] + $destcost) / $goods_price1; } if ($dest['port_goods'] < $goods_buy) { $goods_buy = $dest['port_goods']; if ($dest['port_goods'] == 0) { echo "{$l_tdr_bought} " . NUMBER($goods_buy) . " {$l_tdr_goods} ({$l_tdr_portisempty})<br>"; } } if ($goods_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($goods_buy) . " {$l_tdr_goods}<br>"; } $playerinfo['ship_goods'] += $goods_buy; $destcost -= $goods_buy * $goods_price1; } $resl = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $dest['sector_id'])); db_op_result($db, $resl, __LINE__, __FILE__, $db_logging); } if ($dest['port_type'] == 'organics') { $organics_price1 = $organics_price - $organics_delta * $dest['port_organics'] / $organics_limit * $inventory_factor; if ($traderoute['source_type'] == 'L') { $organics_buy = 0; } else { $organics_buy = $free_holds; if ($playerinfo['credits'] + $destcost < $organics_buy * $organics_price1) { $organics_buy = ($playerinfo['credits'] + $destcost) / $organics_price1; } if ($dest['port_organics'] < $organics_buy) { $organics_buy = $dest['port_organics']; if ($dest['port_organics'] == 0) { echo "{$l_tdr_bought} " . NUMBER($organics_buy) . " {$l_tdr_organics} ({$l_tdr_portisempty})<br>"; } } if ($organics_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($organics_buy) . " {$l_tdr_organics}<br>"; } $playerinfo['ship_organics'] += $organics_buy; $destcost -= $organics_buy * $organics_price1; } $resm = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $dest['sector_id'])); db_op_result($db, $resm, __LINE__, __FILE__, $db_logging); } if ($dest['port_type'] == 'energy') { $energy_price1 = $energy_price - $energy_delta * $dest['port_energy'] / $energy_limit * $inventory_factor; if ($traderoute['source_type'] == 'L') { $energy_buy = 0; } else { $energy_buy = NUM_ENERGY($playerinfo['power']) - $playerinfo['ship_energy'] - $dist['scooped1']; if ($playerinfo['credits'] + $destcost < $energy_buy * $energy_price1) { $energy_buy = ($playerinfo['credits'] + $destcost) / $energy_price1; } if ($dest['port_energy'] < $energy_buy) { $energy_buy = $dest['port_energy']; if ($dest['port_energy'] == 0) { echo "{$l_tdr_bought} " . NUMBER($energy_buy) . " {$l_tdr_energy} ({$l_tdr_portisempty})<br>"; } } if ($energy_buy != 0) { echo "{$l_tdr_bought} " . NUMBER($energy_buy) . " {$l_tdr_energy}<br>"; } $playerinfo['ship_energy'] += $energy_buy; $destcost -= $energy_buy * $energy_price1; } if ($ore_buy == 0 && $goods_buy == 0 && $energy_buy == 0 && $organics_buy == 0) { echo "{$l_tdr_nothingtotrade}<br>"; } $resn = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-?, port_energy=port_energy-?, port_goods=port_goods-?, port_organics=port_organics-? WHERE sector_id=?;", array($ore_buy, $energy_buy, $goods_buy, $organics_buy, $dest['sector_id'])); db_op_result($db, $resn, __LINE__, __FILE__, $db_logging); } if ($dist['scooped2'] > 0) { $playerinfo['ship_energy'] += $dist['scooped2']; if ($playerinfo['ship_energy'] > NUM_ENERGY($playerinfo['power'])) { $playerinfo['ship_energy'] = NUM_ENERGY($playerinfo['power']); } } $reso = $db->Execute("UPDATE {$db->prefix}ships SET ship_ore=?, ship_goods=?, ship_organics=?, ship_energy=? WHERE ship_id=?;", array($playerinfo['ship_ore'], $playerinfo['ship_goods'], $playerinfo['ship_organics'], $playerinfo['ship_energy'], $playerinfo['ship_id'])); db_op_result($db, $reso, __LINE__, __FILE__, $db_logging); } else { if ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { $colonists_buy = 0; $fighters_buy = 0; $torps_buy = 0; } $setcol = 0; if ($playerinfo['trade_colonists'] == 'Y') { $colonists_buy += $playerinfo['ship_colonists']; $col_dump = $playerinfo['ship_colonists']; if ($dest['colonists'] + $colonists_buy >= $colonist_limit) { $exceeding = $dest['colonists'] + $colonists_buy - $colonist_limit; $col_dump = $exceeding; $setcol = 1; $colonists_buy -= $exceeding; if ($colonists_buy < 0) { $colonists_buy = 0; } } } else { $col_dump = 0; } if ($colonists_buy != 0) { if ($setcol == 1) { echo "{$l_tdr_dumped} " . NUMBER($colonists_buy) . " {$l_tdr_colonists} ({$l_tdr_planetisovercrowded})<br>"; } else { echo "{$l_tdr_dumped} " . NUMBER($colonists_buy) . " {$l_tdr_colonists}<br>"; } } if ($playerinfo['trade_fighters'] == 'Y') { $fighters_buy += $playerinfo['ship_fighters']; $fight_dump = $playerinfo['ship_fighters']; } else { $fight_dump = 0; } if ($fighters_buy != 0) { echo "{$l_tdr_dumped} " . NUMBER($fighters_buy) . " {$l_tdr_fighters}<br>"; } if ($playerinfo['trade_torps'] == 'Y') { $torps_buy += $playerinfo['torps']; $torps_dump = $playerinfo['torps']; } else { $torps_dump = 0; } if ($torps_buy != 0) { echo "{$l_tdr_dumped} " . NUMBER($torps_buy) . " {$l_tdr_torps}<br>"; } if ($torps_buy == 0 && $fighters_buy == 0 && $colonists_buy == 0) { echo "{$l_tdr_nothingtodump}<br>"; } if ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { if ($playerinfo['trade_colonists'] == 'Y') { if ($setcol != 1) { $col_dump = 0; } } else { $col_dump = $playerinfo['ship_colonists']; } if ($playerinfo['trade_fighters'] == 'Y') { $fight_dump = 0; } else { $fight_dump = $playerinfo['ship_fighters']; } if ($playerinfo['trade_torps'] == 'Y') { $torps_dump = 0; } else { $torps_dump = $playerinfo['torps']; } } $resp = $db->Execute("UPDATE {$db->prefix}planets SET colonists=colonists+?, fighters=fighters+?, torps=torps+? WHERE planet_id=?;", array($colonists_buy, $fighters_buy, $torps_buy, $traderoute['dest_id'])); db_op_result($db, $resp, __LINE__, __FILE__, $db_logging); if ($traderoute['source_type'] == 'L' || $traderoute['source_type'] == 'C') { $resq = $db->Execute("UPDATE {$db->prefix}ships SET ship_colonists=?, ship_fighters=?, torps=?, ship_energy=ship_energy+? WHERE ship_id=?;", array($col_dump, $fight_dump, $torps_dump, $dist['scooped'], $playerinfo['ship_id'])); db_op_result($db, $resq, __LINE__, __FILE__, $db_logging); } else { if ($setcol == 1) { $resr = $db->Execute("UPDATE {$db->prefix}ships SET ship_colonists=?, ship_fighters=ship_fighters-?, torps=torps-?, ship_energy=ship_energy+? WHERE ship_id=?;", array($col_dump, $fight_dump, $torps_dump, $dist['scooped'], $playerinfo['ship_id'])); db_op_result($db, $resr, __LINE__, __FILE__, $db_logging); } else { $ress = $db->Execute("UPDATE {$db->prefix}ships SET ship_colonists=ship_colonists-?, ship_fighters=ship_fighters-?, torps=torps-?, ship_energy=ship_energy+? WHERE ship_id=?;", array($col_dump, $fight_dump, $torps_dump, $dist['scooped'], $playerinfo['ship_id'])); db_op_result($db, $ress, __LINE__, __FILE__, $db_logging); } } } if ($dist['scooped2'] != 0) { echo "{$l_tdr_scooped} " . NUMBER($dist['scooped1']) . " {$l_tdr_energy}<br>"; } } else { echo $l_tdr_onlyonewaytdr; $destcost = 0; } traderoute_results_show_cost(); if ($sourcecost > 0) { echo "{$l_tdr_profit} : " . NUMBER(abs($sourcecost)); } else { echo "{$l_tdr_cost} : " . NUMBER(abs($sourcecost)); } traderoute_results_close_cost(); if ($destcost > 0) { echo "{$l_tdr_profit} : " . NUMBER(abs($destcost)); } else { echo "{$l_tdr_cost} : " . NUMBER(abs($destcost)); } traderoute_results_close_table(); $total_profit = $sourcecost + $destcost; traderoute_results_display_totals($total_profit); if ($traderoute['circuit'] == '1') { $newsec = $destport['sector_id']; } else { $newsec = $sourceport['sector_id']; } $rest = $db->Execute("UPDATE {$db->prefix}ships SET turns=turns-?, credits=credits+?, turns_used=turns_used+?, sector=? WHERE ship_id=?;", array($dist['triptime'], $total_profit, $dist['triptime'], $newsec, $playerinfo['ship_id'])); db_op_result($db, $rest, __LINE__, __FILE__, $db_logging); $playerinfo['credits'] += $total_profit - $sourcecost; $playerinfo['turns'] -= $dist['triptime']; $tdr_display_creds = NUMBER($playerinfo['credits']); traderoute_results_display_summary($tdr_display_creds); // echo $j." -- "; if ($traderoute['circuit'] == 2) { $l_tdr_engageagain = str_replace("[here]", "<a href=\"traderoute.php?engage=[tdr_engage]\">" . $l_here . "</a>", $l_tdr_engageagain); $l_tdr_engageagain = str_replace("[five]", "<a href=\"traderoute.php?engage=[tdr_engage]&tr_repeat=5\">" . $l_tdr_five . "</a>", $l_tdr_engageagain); $l_tdr_engageagain = str_replace("[ten]", "<a href=\"traderoute.php?engage=[tdr_engage]&tr_repeat=10\">" . $l_tdr_ten . "</a>", $l_tdr_engageagain); $l_tdr_engageagain = str_replace("[fifty]", "<a href=\"traderoute.php?engage=[tdr_engage]&tr_repeat=50\">" . $l_tdr_fifty . "</a>", $l_tdr_engageagain); $l_tdr_engageagain = str_replace("[tdr_engage]", $engage, $l_tdr_engageagain); if ($j == 1) { echo $l_tdr_engageagain . "\n"; traderoute_results_show_repeat(); } } if ($j == 1) { traderoute_die(""); } }
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 xenobetrade() { // // SETUP GENERAL VARIABLES // global $playerinfo; global $inventory_factor; global $ore_price; global $ore_delta; global $ore_limit; global $goods_price; global $goods_delta; global $goods_limit; global $organics_price; global $organics_delta; global $organics_limit; global $xenobeisdead; global $db, $db_logging; // We need to get rid of this.. the bug causing it needs to be identified and squashed. In the meantime, we want functional xen's. :) $ore_price = 11; $organics_price = 5; $goods_price = 15; // OBTAIN SECTOR INFORMATION $sectres = $db->Execute("SELECT * FROM {$db->prefix}universe WHERE sector_id='{$playerinfo['sector']}'"); db_op_result($db, $sectres, __LINE__, __FILE__, $db_logging); $sectorinfo = $sectres->fields; // OBTAIN ZONE INFORMATION $zoneres = $db->Execute("SELECT zone_id,allow_attack,allow_trade FROM {$db->prefix}zones WHERE zone_id='{$sectorinfo['zone_id']}'"); db_op_result($db, $zoneres, __LINE__, __FILE__, $db_logging); $zonerow = $zoneres->fields; // Debug info //playerlog ($db, $playerinfo[ship_id], LOG_RAW, "PORT $sectorinfo[port_type] ALLOW_TRADE $zonerow[allow_trade] PORE $sectorinfo[port_ore] PORG $sectorinfo[port_organics] PGOO $sectorinfo[port_goods] ORE $playerinfo[ship_ore] ORG $playerinfo[ship_organics] GOO $playerinfo[ship_goods] CREDITS $playerinfo[credits] "); // // MAKE SURE WE CAN TRADE HERE // if ($zonerow[allow_trade] == "N") { return; } // // CHECK FOR A PORT WE CAN USE // if ($sectorinfo[port_type] == "none") { return; } // Xenobe DO NOT TRADE AT ENERGY PORTS SINCE THEY REGEN ENERGY if ($sectorinfo[port_type] == "energy") { return; } // // CHECK FOR NEG CREDIT/CARGO // if ($playerinfo[ship_ore] < 0) { $playerinfo[ship_ore] = $shipore = 0; } if ($playerinfo[ship_organics] < 0) { $playerinfo[ship_organics] = $shiporganics = 0; } if ($playerinfo[ship_goods] < 0) { $playerinfo[ship_goods] = $shipgoods = 0; } if ($playerinfo[credits] < 0) { $playerinfo[credits] = $shipcredits = 0; } if ($sectorinfo[port_ore] <= 0) { return; } if ($sectorinfo[port_organics] <= 0) { return; } if ($sectorinfo[port_goods] <= 0) { return; } // // CHECK Xenobe CREDIT/CARGO // if ($playerinfo[ship_ore] > 0) { $shipore = $playerinfo[ship_ore]; } if ($playerinfo[ship_organics] > 0) { $shiporganics = $playerinfo[ship_organics]; } if ($playerinfo[ship_goods] > 0) { $shipgoods = $playerinfo[ship_goods]; } if ($playerinfo[credits] > 0) { $shipcredits = $playerinfo[credits]; } // MAKE SURE WE HAVE CARGO OR CREDITS if (!$playerinfo[credits] > 0 && !$playerinfo[ship_ore] > 0 && !$playerinfo[ship_goods] > 0 && !$playerinfo[ship_organics] > 0) { return; } // // MAKE SURE CARGOS COMPATABLE // if ($sectorinfo[port_type] == "ore" && $shipore > 0) { return; } if ($sectorinfo[port_type] == "organics" && $shiporganics > 0) { return; } if ($sectorinfo[port_type] == "goods" && $shipgoods > 0) { return; } // // LETS TRADE SOME CARGO * // if ($sectorinfo[port_type] == "ore") { // SET THE PRICES $ore_price = $ore_price - $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $organics_price = $organics_price + $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; $goods_price = $goods_price + $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; // SET CARGO BUY/SELL $amount_organics = $playerinfo[ship_organics]; $amount_goods = $playerinfo[ship_goods]; // SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT $amount_ore = NUM_HOLDS($playerinfo[hull]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL $amount_ore = min($amount_ore, $sectorinfo[port_ore]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY $amount_ore = min($amount_ore, floor(($playerinfo[credits] + $amount_organics * $organics_price + $amount_goods * $goods_price) / $ore_price)); // BUY/SELL CARGO $total_cost = round($amount_ore * $ore_price - ($amount_organics * $organics_price + $amount_goods * $goods_price)); $newcredits = max(0, $playerinfo[credits] - $total_cost); $newore = $playerinfo[ship_ore] + $amount_ore; $neworganics = max(0, $playerinfo[ship_organics] - $amount_organics); $newgoods = max(0, $playerinfo[ship_goods] - $amount_goods); $trade_result = $db->Execute("UPDATE {$db->prefix}ships SET rating=rating+1, credits={$newcredits}, ship_ore={$newore}, ship_organics={$neworganics}, ship_goods={$newgoods} WHERE ship_id={$playerinfo['ship_id']}"); db_op_result($db, $trade_result, __LINE__, __FILE__, $db_logging); $trade_result2 = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore-{$amount_ore}, port_organics=port_organics+{$amount_organics}, port_goods=port_goods+{$amount_goods} WHERE sector_id={$sectorinfo['sector_id']}"); db_op_result($db, $trade_result2, __LINE__, __FILE__, $db_logging); playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe Trade Results: Sold {$amount_organics} Organics Sold {$amount_goods} Goods Bought {$amount_ore} Ore Cost {$total_cost}"); } if ($sectorinfo[port_type] == "organics") { // SET THE PRICES $organics_price = $organics_price - $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; $ore_price = $ore_price + $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $goods_price = $goods_price + $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; // // SET CARGO BUY/SELL // $amount_ore = $playerinfo[ship_ore]; $amount_goods = $playerinfo[ship_goods]; // SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT $amount_organics = NUM_HOLDS($playerinfo[hull]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL $amount_organics = min($amount_organics, $sectorinfo[port_organics]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY $amount_organics = min($amount_organics, floor(($playerinfo[credits] + $amount_ore * $ore_price + $amount_goods * $goods_price) / $organics_price)); // // BUY/SELL CARGO // $total_cost = round($amount_organics * $organics_price - ($amount_ore * $ore_price + $amount_goods * $goods_price)); $newcredits = max(0, $playerinfo[credits] - $total_cost); $newore = max(0, $playerinfo[ship_ore] - $amount_ore); $neworganics = $playerinfo[ship_organics] + $amount_organics; $newgoods = max(0, $playerinfo[ship_goods] - $amount_goods); $trade_result = $db->Execute("UPDATE {$db->prefix}ships SET rating=rating+1, credits={$newcredits}, ship_ore={$newore}, ship_organics={$neworganics}, ship_goods={$newgoods} WHERE ship_id={$playerinfo['ship_id']}"); db_op_result($db, $trade_result, __LINE__, __FILE__, $db_logging); $trade_result2 = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore+{$amount_ore}, port_organics=port_organics-{$amount_organics}, port_goods=port_goods+{$amount_goods} WHERE sector_id={$sectorinfo['sector_id']}"); db_op_result($db, $trade_result2, __LINE__, __FILE__, $db_logging); playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe Trade Results: Sold {$amount_goods} Goods Sold {$amount_ore} Ore Bought {$amount_organics} Organics Cost {$total_cost}"); } if ($sectorinfo[port_type] == "goods") { // // SET THE PRICES // $goods_price = $goods_price - $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; $ore_price = $ore_price + $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $organics_price = $organics_price + $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; // // SET CARGO BUY/SELL // $amount_ore = $playerinfo[ship_ore]; $amount_organics = $playerinfo[ship_organics]; // SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT $amount_goods = NUM_HOLDS($playerinfo[hull]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL $amount_goods = min($amount_goods, $sectorinfo[port_goods]); // WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY $amount_goods = min($amount_goods, floor(($playerinfo[credits] + $amount_ore * $ore_price + $amount_organics * $organics_price) / $goods_price)); // // BUY/SELL CARGO // $total_cost = round($amount_goods * $goods_price - ($amount_organics * $organics_price + $amount_ore * $ore_price)); $newcredits = max(0, $playerinfo[credits] - $total_cost); $newore = max(0, $playerinfo[ship_ore] - $amount_ore); $neworganics = max(0, $playerinfo[ship_organics] - $amount_organics); $newgoods = $playerinfo[ship_goods] + $amount_goods; $trade_result = $db->Execute("UPDATE {$db->prefix}ships SET rating=rating+1, credits={$newcredits}, ship_ore={$newore}, ship_organics={$neworganics}, ship_goods={$newgoods} WHERE ship_id={$playerinfo['ship_id']}"); db_op_result($db, $trade_result, __LINE__, __FILE__, $db_logging); $trade_result2 = $db->Execute("UPDATE {$db->prefix}universe SET port_ore=port_ore+{$amount_ore}, port_organics=port_organics+{$amount_organics}, port_goods=port_goods-{$amount_goods} WHERE sector_id={$sectorinfo['sector_id']}"); db_op_result($db, $trade_result2, __LINE__, __FILE__, $db_logging); playerlog($db, $playerinfo[ship_id], LOG_RAW, "Xenobe Trade Results: Sold {$amount_ore} Ore Sold {$amount_organics} Organics Bought {$amount_goods} Goods Cost {$total_cost}"); } }
} elseif ($ship_component_level < 40) { $shiplevel = 3; } else { $shiplevel = 4; } return $shiplevel; } function percent($num_amount, $num_total) { $count1 = $num_amount / $num_total; $count2 = $count1 * 100; $count = number_format($count2, 0); return $count; } $holds_used = $playerinfo['ship_ore'] + $playerinfo['ship_organics'] + $playerinfo['ship_goods'] + $playerinfo['ship_colonists']; $holds_max = NUM_HOLDS($playerinfo['hull']); $armor_pts_max = NUM_ARMOR($playerinfo['armor']); $ship_fighters_max = NUM_FIGHTERS($playerinfo['computer']); $torps_max = NUM_TORPEDOES($playerinfo['torp_launchers']); $energy_max = NUM_ENERGY($playerinfo['power']); $escape_pod = $playerinfo['dev_escapepod'] == 'Y' ? $l_yes : $l_no; $fuel_scoop = $playerinfo['dev_fuelscoop'] == 'Y' ? $l_yes : $l_no; $lssd = $playerinfo['dev_lssd'] == 'Y' ? $l_yes : $l_no; if ($playerinfo['dev_escapepod'] == 'N') { $escape_pod_warning = '<span class="ship-component-warning-span">CRITICAL COMPONENT NOT INSTALLED</span>'; } if ($playerinfo['dev_minedeflector'] == '0') { $mine_deflector_warning = '<span class="ship-component-warning-span">WARNING YOU HAVE NO MINEDEFLECTORS</span>'; } if ($playerinfo['dev_emerwarp'] == '0') { $emergancy_warp_warning = '<span class="ship-component-warning-span">WARNING NO EMERGENCY WARPS INSTALLED</span>';
} $trade_ore = TRADE($ore_price, $ore_delta, $sectorinfo[port_ore], $ore_limit, $inventory_factor, "ore", $trade_ore); $trade_organics = TRADE($organics_price, $organics_delta, $sectorinfo[port_organics], $organics_limit, $inventory_factor, "organics", $trade_organics ); $trade_goods = TRADE($goods_price, $goods_delta, $sectorinfo[port_goods], $goods_limit, $inventory_factor, "goods", $trade_goods); $trade_energy = TRADE($energy_price, $energy_delta, $sectorinfo[port_energy], $energy_limit, $inventory_factor, "energy", $trade_energy); $ore_price = $price_array['ore']; $organics_price = $price_array['organics']; $goods_price = $price_array['goods']; $energy_price = $price_array['energy']; $cargo_exchanged = $trade_ore + $trade_organics + $trade_goods; $free_holds = NUM_HOLDS($shipinfo[hull]) - $shipinfo[ship_ore] - $shipinfo[ship_organics] - $shipinfo[ship_goods] - $shipinfo[ship_colonists]; $free_power = NUM_ENERGY($shipinfo[power]) - $shipinfo[ship_energy]; $total_cost = $trade_ore * $ore_price + $trade_organics * $organics_price + $trade_goods * $goods_price + $trade_energy * $energy_price; /* debug info echo "$trade_ore * $ore_price + $trade_organics * $organics_price + $trade_goods * $goods_price + $trade_energy * $energy_price = $total_cost"; */ if($free_holds < $cargo_exchanged) { echo "$l_notenough_cargo $l_returnto_port<BR><BR>"; } elseif($trade_energy > $free_power) {
function furangeetrade() { // ********************************* // *** SETUP GENERAL VARIABLES **** // ********************************* global $playerinfo; global $shipinfo; global $inventory_factor; global $ore_price; global $ore_delta; global $ore_limit; global $goods_price; global $goods_delta; global $goods_limit; global $organics_price; global $organics_delta; global $organics_limit; global $furangeeisdead; global $db, $dbtables; //echo "Name: $playerinfo[character_name] Credits: $playerinfo[credits] Ore:$shipinfo[ship_ore] Goods:$shipinfo[ship_goods] Organics:$shipinfo[ship_organics]<br>"; //echo "<pre>"; //print_r($shipinfo); //echo "</pre>"; // ************************************* // *** OBTAIN PREFERANCE INFORMATION *** // ************************************* $furanres = $db->Execute ("SELECT * FROM $dbtables[furangee] WHERE furangee_id='$playerinfo[email]'"); $furangeeinfo = $furanres->fields; $prefer = $furangeeinfo[prefer]; //echo "Furangee likes $prefer<br>"; $prefer2 = "ship_".$prefer; $prefer3 = $prefer."_price"; // ********************************* // *** OBTAIN SECTOR INFORMATION *** // ********************************* $sectres = $db->Execute ("SELECT * FROM $dbtables[universe] WHERE sector_id='$playerinfo[sector]'"); $sectorinfo = $sectres->fields; // ********************************* // *** OBTAIN PLANET INFORMATION *** // ********************************* // Select the planet with the most of what I want //echo "I am in sector $playerinfo[sector]<br>"; $planres = $db->Execute ("SELECT * FROM $dbtables[planets] WHERE sector_id='$playerinfo[sector]' AND sells='Y' AND $prefer>0 ORDER BY $prefer ASC LIMIT 1"); // See if there are any planets to trade with and I don't have what I want already $planet_traded = false; while (($prefer != "none") && (!$planres->EOF) && $playerinfo[$prefer2] == 0) { //echo "There is a planet to trade with here!<br>"; $planet_traded = true; $planetinfo = $planres->fields; // Find out prices for the commodities //echo "DEBUG: SELECT $prefer3 AS price FROM $dbtables[players] WHERE player_id=$planetinfo[owner] LIMIT 1<br>"; $sellres = $db->Execute("SELECT $prefer3 AS price FROM $dbtables[players] WHERE player_id=$planetinfo[owner] LIMIT 1"); $sellinfo = $sellres->fields; //echo "The seller has the following price for $prefer: $sellinfo[price]<br>"; $quantity = 0; if ($sellinfo[price]>=0.1) { // Find out how much I can afford, what's available and what I can carry $quantity = min(floor($playerinfo[credits]/$sellinfo[price]),$planetinfo[$prefer],NUM_HOLDS($shipinfo[hull])); } //echo "I can buy $quantity of $prefer<br>"; // Check to see if I can afford to buy anything if ($quantity==0) { $planet_traded = false; } else { // The planet has some of what I want //echo "My holds have ore $shipinfo[ship_ore], goods $shipinfo[ship_goods], organics $shipinfo[ship_organics]<br>"; // Find out what I need to dump to make room, dump it and load up $amount_ore = 0; $amount_goods = 0; $amount_organics = 0; $dump_value = rand(1,10); if ($prefer == "ore") { if ($shipinfo[ship_goods] > $quantity) { // We have more goods than what I want. Just drop off the some of goods on the planet and dump the rest in space $shipinfo[ship_goods] -= $quantity; $planetinfo[goods] += $quantity/$dump_value; $amount_goods = $quantity/$dump_value; } else { // I need to drop off more than just the goods // Drop off all the goods $planetinfo[goods] += $shipinfo[ship_goods]; $quantityleft = $quantity - $shipinfo[ship_goods]; $amount_goods = $shipinfo[ship_goods]; $shipinfo[ship_goods] = 0; if ($shipinfo[ship_organics] > $quantityleft) { // We have enough orgs to cover what needs to be dropped off $shipinfo[ship_organics] -= $quantityleft; $planetinfo[organics] += $quantityleft/$dump_value; $amount_organics = $quantityleft/$dump_value; } else { // All the organics need to go too $planetinfo[organics] += $shipinfo[ship_organics]/$dump_value; $amount_organics = $shipinfo[ship_organics]/$dump_value; $shipinfo[ship_organics] = 0; // Anything left after this must be just remainder I hope } } } else if ($prefer == "organics") { if ($shipinfo[ship_goods] > $quantity) { // We have more goods than what I want. Just drop off the same number of goods on the planet $shipinfo[ship_goods] -= $quantity; $planetinfo[goods] += $quantity/$dump_value; $amount_goods = $quantity/$dump_value; } else { // I need to drop off more than just the goods // Drop off all the goods $planetinfo[goods] += $shipinfo[ship_goods]/$dump_value; $quantityleft = $quantity - $shipinfo[ship_goods]; $amount_goods = $shipinfo[ship_goods]/$dump_value; $shipinfo[ship_goods] = 0; if ($shipinfo[ship_ore] > $quantityleft) { // We have enough ore to cover what needs to be dropped off $shipinfo[ship_ore] -= $quantityleft; $planetinfo[ore] += $quantityleft/$dump_value; $amount_ore = $quantityleft/$dump_value; } else { // All the ore need to go too $planetinfo[ore] += $shipinfo[ship_ore]/$dump_value; $amount_ore = $shipinfo[ship_ore]/$dump_value; $shipinfo[ship_ore] = 0; // Anything left after this must be just remainder I hope } } } else if ($prefer == "goods") { if ($shipinfo[ship_ore] > $quantity) { // We have more ore than what I want. Just drop off the same number of ore on the planet $shipinfo[ship_ore] -= $quantity; $planetinfo[ore] += $quantity/$dump_value; $amount_ore = $quantity/$dump_value; } else { // I need to drop off more than just the ore // Drop off all the ore $planetinfo[ore] += $shipinfo[ship_ore]/$dump_value; $quantityleft = $quantity - $shipinfo[ship_ore]; $amount_ore = $shipinfo[ship_ore]/$dump_value; $shipinfo[ship_ore] = 0; if ($shipinfo[ship_organics] > $quantityleft) { // We have enough orgs to cover what needs to be dropped off $shipinfo[ship_organics] -= $quantityleft; $planetinfo[organics] += $quantityleft/$dump_value; $amount_organics = $quantityleft/$dump_value; } else { // All the organics need to go too $planetinfo[organics] += $shipinfo[ship_organics]/$dump_value; $amount_organics = $shipinfo[ship_organics]/$dump_value; $shipinfo[ship_organics] = 0; // Anything left after this must be just remainder I hope } } } // Move the wanted items to the ship and deduct from the planet $planetinfo[$prefer] -= $quantity; $shipinfo[$prefer2] += $quantity; //echo "I bought $prefer from $planetinfo[name] and now my holds have ore $shipinfo[ship_ore], goods $shipinfo[ship_goods], organics $shipinfo[ship_organics]<br>"; //echo "I transfered $amount_ore ore, $amount_goods goods and $amount_organics organics.<br>"; // Buy that amount and put it on the ship //echo "I have $playerinfo[credits] credits<br>"; $playerinfo[credits]-= ($sellinfo[price]*$quantity); //echo "I now have $playerinfo[credits] credits<br>"; // Update the database tables // playerlog($playerinfo[player_id], LOG_FURANGEE_TRADE, "Furangee Traded At Planet: $planetinfo[name] and bought $quantity of $prefer and transfered $amount_ore ore, $amount_goods goods and $amount_organics organics."); // The rating of the furangee increases when he trades, I guess to make it bad to kill him $trade_result = $db->Execute("UPDATE $dbtables[players] SET rating=rating+1, credits=credits-($sellinfo[price]*$quantity) WHERE player_id=$playerinfo[player_id]"); $trade_result = $db->Execute("UPDATE $dbtables[ships] SET ship_ore=$shipinfo[ship_ore], ship_organics=$shipinfo[ship_organics], ship_goods=$shipinfo[ship_goods] WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]"); $trade_result2 = $db->Execute("UPDATE $dbtables[planets] SET ore=$planetinfo[ore], organics=$planetinfo[organics], goods=$planetinfo[goods], credits=credits+($sellinfo[price]*$quantity) WHERE planet_id=$planetinfo[planet_id]"); $message = "Furangee $playerinfo[character_name] bought ".NUMBER($quantity)." of $prefer from your planet $planetinfo[name] in sector $planetinfo[sector_id]. You made ".NUMBER(($sellinfo[price]*$quantity))." credits!"; if ($amount_ore > 0 | $amount_goods > 0 | $amount_organics > 0) { $message = $message." Furangee $playerinfo[character_name] also dumped"; if ($amount_ore > 0) { $message = $message." ".NUMBER($amount_ore)." ore"; } if ($amount_goods > 0) { if ($amount_ore > 0) $message = $message.","; $message = $message." ".NUMBER($amount_goods)." goods"; } if ($amount_organics > 0) { if ($amount_ore > 0 | $amount_goods > 0) $message = $message." and"; $message = $message." ".NUMBER($amount_organics)." organics"; } $message = $message." on the planet."; } playerlog($planetinfo[owner], LOG_FURANGEE_TRADE, $message); } $planres->MoveNext(); } if ($planet_traded) { //echo "I traded at a planet so I've finished<br>"; return; } else { //echo "I did not trade at a planet so I continue.<br>"; } // ********************************* // **** OBTAIN ZONE INFORMATION **** // ********************************* $zoneres = $db->Execute ("SELECT zone_id,allow_attack,allow_trade FROM $dbtables[zones] WHERE zone_id='$sectorinfo[zone_id]'"); $zonerow = $zoneres->fields; // Debug info //playerlog($playerinfo[player_id], LOG_RAW, "PORT $sectorinfo[port_type] ALLOW_TRADE $zonerow[allow_trade] PORE $sectorinfo[port_ore] PORG $sectorinfo[port_organics] PGOO $sectorinfo[port_goods] ORE $shipinfo[ship_ore] ORG $shipinfo[ship_organics] GOO $shipinfo[ship_goods] CREDITS $playerinfo[credits] "); // ********************************* // ** MAKE SURE WE CAN TRADE HERE ** // ********************************* //echo "Check if trade ok<br>"; if ($zonerow[allow_trade]=="N") return; // ********************************* // ** CHECK FOR A PORT WE CAN USE ** // ********************************* //echo "Check if port ok<br>"; if($sectorinfo[port_type] == "none") return; // *** FURANGEE DO NOT TRADE AT SPECIAL PORTS *** if($sectorinfo[port_type] == "special") return; // *** FURANGEE DO NOT TRADE AT ENERGY PORTS SINCE THEY REGEN ENERGY *** if($sectorinfo[port_type] == "energy") return; //echo "port ok. check for neg credit or cargo<br>"; // ********************************* // ** CHECK FOR NEG CREDIT/CARGO *** // ********************************* if($shipinfo[ship_ore] <= 0) $shipinfo[ship_ore]=$shipore=0; if($shipinfo[ship_organics] <= 0) $shipinfo[ship_organics]=$shiporganics=0; if($shipinfo[ship_goods] <= 0) $shipinfo[ship_goods]=$shipgoods=0; if($playerinfo[credits] <= 0) $playerinfo[credits]=$shipcredits=0; if($sectorinfo[port_ore] <= 0) return; if($sectorinfo[port_organics] <= 0) return; if($sectorinfo[port_goods] <= 0) return; //echo "check furangee credit cargo<br>"; // ********************************* // ** CHECK FURANGEE CREDIT/CARGO ** // ********************************* if($shipinfo[ship_ore]>0) $shipore=$shipinfo[ship_ore]; if($shipinfo[ship_organics]>0) $shiporganics=$shipinfo[ship_organics]; if($shipinfo[ship_goods]>0) $shipgoods=$shipinfo[ship_goods]; if($playerinfo[credits]>0) $shipcredits=$playerinfo[credits]; // *** MAKE SURE WE HAVE CARGO OR CREDITS ** //echo "Make sure we have cargo or credits<br>"; if(!$playerinfo[credits]>0 && !$shipinfo[ship_ore]>0 && !$shipinfo[ship_goods]>0 && !$shipinfo[ship_organics]>0) return; // ************************************** // ** MAKE SURE WE HAVE CARGO TO TRADE ** // ************************************** //echo "Make sure we have cargo to trade<br>"; /* if($sectorinfo[port_type]=="ore" && $shiporganics==0 && $shipgoods==0) return; if($sectorinfo[port_type]=="organics" && $shipore==0 && $shipgoods==0) return; if($sectorinfo[port_type]=="goods" && $shipore==0 && $shiporganics==0) return; */ // ********************************* // ***** LETS TRADE SOME CARGO ***** // ********************************* //echo "Let's trade<br>"; if($sectorinfo[port_type]=="ore") // ********************* // ***** PORT ORE ****** // ********************* { // ************************ // **** SET THE PRICES **** // ************************ $ore_price1 = $ore_price - $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $organics_price1 = $organics_price + $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; $goods_price1 = $goods_price + $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; // ************************ // ** SET CARGO BUY/SELL ** // ************************ $amount_organics = $shipinfo[ship_organics]; $amount_goods = $shipinfo[ship_goods]; // *** SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT *** $amount_ore = NUM_HOLDS($shipinfo[hull]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL *** $amount_ore = min($amount_ore, $sectorinfo[port_ore]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY *** $amount_ore = min($amount_ore, floor(($playerinfo[credits] + $amount_organics * $organics_price1 + $amount_goods * $goods_price1) / $ore_price1)); // ************************ // **** BUY/SELL CARGO **** // ************************ $total_cost = round(($amount_ore * $ore_price1) - ($amount_organics * $organics_price1 + $amount_goods * $goods_price1)); $newcredits = max(0,$playerinfo[credits]-$total_cost); $newore = $shipinfo[ship_ore]+$amount_ore; $neworganics = max(0,$shipinfo[ship_organics]-$amount_organics); $newgoods = max(0,$shipinfo[ship_goods]-$amount_goods); if ($newore < 0 || $neworganics < 0 || $newgoods < 0) { playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Negative ERROR: Port $sectorinfo[port_type] ORE player $newore port $sectorinfo[port_ore] price $ore_price1 delta $ore_delta ORG player $neworganics port $sectorinfo[port_organics] price $organics_price1 delta $organics_delta GOOD player $newgoods port $sectorinfo[port_goods] price $goods_price1 delta $goods_delta"); } $trade_result = $db->Execute("UPDATE $dbtables[players] SET rating=rating+1, credits=$newcredits WHERE player_id=$playerinfo[player_id]"); $trade_result = $db->Execute("UPDATE $dbtables[ships] SET ship_ore=$newore, ship_organics=$neworganics, ship_goods=$newgoods WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]"); $trade_result2 = $db->Execute("UPDATE $dbtables[universe] SET port_ore=port_ore-$amount_ore, port_organics=port_organics+$amount_organics, port_goods=port_goods+$amount_goods WHERE sector_id=$sectorinfo[sector_id]"); //playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Results: Sold $amount_organics Organics Sold $amount_goods Goods Bought $amount_ore Ore Cost $total_cost"); } if($sectorinfo[port_type]=="organics") // ********************* // *** PORT ORGANICS *** // ********************* { // ************************ // **** SET THE PRICES **** // ************************ $organics_price1 = $organics_price - $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; $ore_price1 = $ore_price + $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $goods_price1 = $goods_price + $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; // ************************ // ** SET CARGO BUY/SELL ** // ************************ $amount_ore = $shipinfo[ship_ore]; $amount_goods = $shipinfo[ship_goods]; // *** SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT *** $amount_organics = NUM_HOLDS($shipinfo[hull]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL *** $amount_organics = min($amount_organics, $sectorinfo[port_organics]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY *** $amount_organics = min($amount_organics, floor(($playerinfo[credits] + $amount_ore * $ore_price1 + $amount_goods * $goods_price1) / $organics_price1)); // ************************ // **** BUY/SELL CARGO **** // ************************ $total_cost = round(($amount_organics * $organics_price1) - ($amount_ore * $ore_price1 + $amount_goods * $goods_price1)); $newcredits = max(0,$playerinfo[credits]-$total_cost); $newore = max(0,$shipinfo[ship_ore]-$amount_ore); $neworganics = $shipinfo[ship_organics]+$amount_organics; $newgoods = max(0,$shipinfo[ship_goods]-$amount_goods); if ($newore < 0 || $neworganics < 0 || $newgoods < 0) { playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Negative ERROR: Port $sectorinfo[port_type] ORE player $newore port $sectorinfo[port_ore] price $ore_price1 delta $ore_delta ORG player $neworganics port $sectorinfo[port_organics] price $organics_price1 delta $organics_delta GOOD player $newgoods port $sectorinfo[port_goods] price $goods_price1 delta $goods_delta"); } $trace_result = $db->Execute("UPDATE $dbtables[players] SET rating=rating+1, credits=$newcredits WHERE player_id=$playerinfo[player_id]"); $trade_result = $db->Execute("UPDATE $dbtables[ships] SET ship_ore=$newore, ship_organics=$neworganics, ship_goods=$newgoods WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]"); $trade_result2 = $db->Execute("UPDATE $dbtables[universe] SET port_ore=port_ore+$amount_ore, port_organics=port_organics-$amount_organics, port_goods=port_goods+$amount_goods where sector_id=$sectorinfo[sector_id]"); //playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Results: Sold $amount_goods Goods Sold $amount_ore Ore Bought $amount_organics Organics Cost $total_cost"); } if($sectorinfo[port_type]=="goods") // ********************* // **** PORT GOODS ***** // ********************* { // ************************ // **** SET THE PRICES **** // ************************ $goods_price1 = $goods_price - $goods_delta * $sectorinfo[port_goods] / $goods_limit * $inventory_factor; $ore_price1 = $ore_price + $ore_delta * $sectorinfo[port_ore] / $ore_limit * $inventory_factor; $organics_price1 = $organics_price + $organics_delta * $sectorinfo[port_organics] / $organics_limit * $inventory_factor; // ************************ // ** SET CARGO BUY/SELL ** // ************************ $amount_ore = $shipinfo[ship_ore]; $amount_organics = $shipinfo[ship_organics]; // *** SINCE WE SELL ALL OTHER HOLDS WE SET AMOUNT TO BE OUR TOTAL HOLD LIMIT *** $amount_goods = NUM_HOLDS($shipinfo[hull]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEED WHAT THE PORT HAS TO SELL *** $amount_goods = min($amount_goods, $sectorinfo[port_goods]); // *** WE ADJUST THIS TO MAKE SURE IT DOES NOT EXCEES WHAT WE CAN AFFORD TO BUY *** $amount_goods = min($amount_goods, floor(($playerinfo[credits] + $amount_ore * $ore_price1 + $amount_organics * $organics_price1) / $goods_price1)); // ************************ // **** BUY/SELL CARGO **** // ************************ $total_cost = round(($amount_goods * $goods_price1) - ($amount_organics * $organics_price1 + $amount_ore * $ore_price1)); //echo "Total cost at goods port was $total_cost<br>"; $newcredits = max(0,$playerinfo[credits]-$total_cost); //echo "New credits = $newcredits<br>"; $newore = max(0,$shipinfo[ship_ore]-$amount_ore); $neworganics = max(0,$shipinfo[ship_organics]-$amount_organics); $newgoods = $shipinfo[ship_goods]+$amount_goods; if ($newore < 0 || $neworganics < 0 || $newgoods < 0) { playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Negative ERROR: Port $sectorinfo[port_type] ORE player $newore port $sectorinfo[port_ore] price $ore_price1 delta $ore_delta ORG player $neworganics port $sectorinfo[port_organics] price $organics_price1 delta $organics_delta GOOD player $newgoods port $sectorinfo[port_goods] price $goods_price1 delta $goods_delta"); } $trade_result = $db->Execute("UPDATE $dbtables[players] SET rating=rating+1, credits=$newcredits WHERE player_id=$playerinfo[player_id]"); $trade_result = $db->Execute("UPDATE $dbtables[ships] SET ship_ore=$newore, ship_organics=$neworganics, ship_goods=$newgoods WHERE player_id=$playerinfo[player_id] AND ship_id=$playerinfo[currentship]"); $trade_result2 = $db->Execute("UPDATE $dbtables[universe] SET port_ore=port_ore+$amount_ore, port_organics=port_organics+$amount_organics, port_goods=port_goods-$amount_goods where sector_id=$sectorinfo[sector_id]"); //playerlog($playerinfo[player_id], LOG_RAW, "Furangee Trade Results: Sold $amount_ore Ore Sold $amount_organics Organics Bought $amount_goods Goods Cost $total_cost"); } }