no edit button.. awesome
username the user sname
modifiername the mods name
thechange a number
life a number
drawback a number
modifierid unique#
the table is used in a math function as to throw a curve ball into a formulas
I don't know if you have ever played http://en.wikipedia.org/wiki/Aerobiz but I am attempting to re-create some of the game via web.
this modifier table is really designed to add to the planes population and minus from the cash earned on the flight.
so... say the plane (based on your ticket price) is 60% full, if you have a modifier, lets say Beverages (+2% to plane population, but -1% to profit) i want to pull that into the formula used to total out what you made on that flight. if it doesn't exist, IE you don't have any modifiers, then I want to ignore it and calculate your profits without it.
don't laugh.... it's my first large project in php
only thing i really have left to do with this page is figure out how the hell to get this page to do every plane in my locker rather then just one plane....
//get the turn played value, have they played already?
$query0="SELECT myturn FROM turnbased WHERE username='$_SESSION[user_name]' ";
$result0=mysql_query($query0);
$turnplayed=mysql_result($result0,"turnplayed");
$idtag=2;
//if they have not played already, go ahead and play
if ($turnplayed > 0){
//Get users cash value
$query1="SELECT cash FROM authorize WHERE username='$_SESSION[user_name]' ";
$result1=mysql_query($query1);
$cash=mysql_result($result1,"cash");
//************************ getting the single item rather then the whole? how do i choose each one *******************
//Life of the mod
$query222="SELECT * FROM modifier WHERE username='$_SESSION[user_name]' ";
$result222=mysql_query($query222);
if (mysql_num_rows($result222) > 0) {
$query2="SELECT life FROM modifier WHERE username='$_SESSION[user_name]' ";
$result2=mysql_query($query2);
$life=mysql_result($result2,"life");
}
Else {
}
//get the plane from the flight
$query5="SELECT planes FROM locker WHERE planeid='$idtag' ";
$result5=mysql_query($query5);
$planetype=mysql_result($result5,"planetype");
//get the ticket price of the flight
$query6="SELECT ticketprice FROM locker WHERE planeid='$idtag' ";
$result6=mysql_query($query6);
$ticketprice=mysql_result($result6,"ticketprice");
//get the drawbacks of that plane type of the flight
$query7="SELECT fuel FROM planes WHERE planes='$planetype' ";
$result7=mysql_query($query7);
$fuelcost=mysql_result($result7,"fuelcost");
//*******************************************************************
$query8="SELECT org FROM locker WHERE planeid='$idtag' ";
$result8=mysql_query($query8);
$airport1=mysql_result($result8,"airport1");
$query9="SELECT dest FROM locker WHERE planeid='$idtag' ";
$result9=mysql_query($query9);
$airport2=mysql_result($result9,"airport2");
//----------------------------------------trying to get the avg ticket price in an array and calculate it
//$sql = "SELECT 'ticketprice' FROM locker WHERE org='$airport1' AND dest='$airport2' ";
//********************************************************************
function avgval($avg_vals) {
if ( is_array($avg_vals) && count($avg_vals) > 1 ) {
$return_vals = ( array_sum($avg_vals) / count($avg_vals) );
} elseif ( is_array($avg_vals) && count($avg_vals) == 1 ) {
$return_vals = current($avg_vals);
} else {
$return_vals = FALSE;
}
return $return_vals;
}
//*******************************************************************
//--------------------------------------------------------done fetching now time to write it-----------------------------
//this even a valid way to do this attempting to populate the averageticket price array with this function
$sql = "SELECT ticketprice FROM locker WHERE org='$airport1' AND dest='$airport2' ";
$result = mysql_query($sql);
$var = array();
while ($row = mysql_fetch_array($result)) {
$var[] = $row['ticketprice'];
}
$averageticketprice=round((avgval($var))); // outputs the avg ticket price
//modifier life, use it , and knock it down by 1
if (mysql_num_rows($result222) > 0) {
if ($life > 0){
$newlife=($life - 1);
mysql_query("UPDATE `modifier` SET life='$newlife' WHERE username='$_SESSION[user_name]' ");
//get the mod its self on the good side
$query3="SELECT thechange FROM modifier WHERE username='$_SESSION[user_name]' ";
$result3=mysql_query($query3);
$modthegood=mysql_result($result3,"modthegood");
//get the mod its self on the bad side
$query4="SELECT drawback FROM modifier WHERE username='$_SESSION[user_name]' ";
$result4=mysql_query($query4);
$modthebad=mysql_result($result4,"modthebad");
}
Else {
Echo "No Mods Apply,";
$modthgood="0";
$modthebad="0";
if ($life = 0){
Echo "Something isn't right";
}
else {
$query22="SELECT `modifierid` FROM modifier WHERE username='$_SESSION[user_name]' ";
$result22=mysql_query($query22);
$modbyebye=mysql_result($result22,"modbyebye");
mysql_query("UPDATE `modifier` SET username='trash99' WHERE modifierid='$modbyebye' ");
Echo "Expired mod removed,";
}
}
}
Else {
Echo "you have no mods";
}
//do the calculations and set the fun ******************************
$planepopulation=rand(40, 60);
if($ticketprice > $averageticketprice) //find out what percent the ticket price is off by, deduct % from the planes population - set that as $overpriced
{
$overpriced=rand(5, 15);
$newplanepop=($planepopulation-$overpriced);
}
else {
if($ticketprice < $averageticketprice) //find out what percent the ticket price is off by, fadd % to the planes population - set that as $underpriced
{
$underpriced=rand(5, 15);
$newplanepop=($planepopulation+$underpriced);
}
else {
if($ticketprice = $averageticketprice) //ticket price is the average ticket price - add % flat set that as $flatprice
{
$flatprice=rand(15, 20);
$newplanepop=($planepopulation+$flatprice);
}
else {
Echo "Can't get the ticket price! WTF!";
}
}
}
//would like to add some sorta stats to show what happened behind the scene so people can have an idea of what flights to adjust and whats doing ok
//good mod calc
$tmppercent2=100-$modthegood;
$equals2=($newplanepop / 100 * $tmppercent2);
$differ=$newplanepop - $equals2;
//using this for debugging
$whatismyplanepop=$newplanepop + $differ;
//-----
$totalsum=($newplanepop + $differ) * $ticketprice;
//bad modification calculator
$percent1 = $modthebad;
$total1 = $totalsum;
$tmppercent1=100-$percent1;
$equals1=($total1 / 100 * $tmppercent1);
//fuel calc
$percentfuel = $fuelcost;
$totalfuel = $totalsum;
$tmppercentfuel=100-$percentfuel;
$fuelcost2=($totalfuel / 100 * $tmppercentfuel);
// if statement in case the bad mod has no value
if ($$equals1 > 0) {
$totalvalue=($totalsum-$equals1)-$fuelcost2;
}
ELSE {
$totalvalue=$totalsum-$fuelcost2;
}
// get the cash
$cashadded=$cash+$totalvalue;
//update the bankroll
mysql_query("UPDATE `authorize` SET cash='$cashadded' WHERE username='$_SESSION[user_name]' ");
mysql_query("UPDATE `turnbased` SET myturn='0' WHERE username='$_SESSION[user_name]' ");
Echo "<P>Your Turn is completed<P>";
}
Else {
Echo "Your Turn has been played in this hour already";
}
?>