<?
include("header.php");
// preset prices; getCosts adjusts them according to your barracks/land ratio and race bonus
$costs[armtrp] = $config[armtrp] * .45;
$costs[lndtrp] = $config[lndtrp] * .50;
$costs[flytrp] = $config[flytrp] * .55;
$costs[seatrp] = $config[seatrp] * .65;
$costs[food] = $config[food] * .45;
$config[armtrp] = $config[armtrp] * .45;
$config[lndtrp] = $config[lndtrp] * .50;
$config[flytrp] = $config[flytrp] * .55;
$config[seatrp] = $config[seatrp] * .65;
function getCosts ($type)
{
global $users, $urace, $costs, $canbuy, $config;
// when selling units, the bonus INCREASES the price, so you can get more for them
$costbonus = 1 + (1-$config[mktshop]) * ($users[barracks] / $users[land]) + $config[mktshop] * ($users[shops] / $users[land]);
if ($type == food) // food unaffected by cost bonuses
$costs[$type] = round($costs[$type]);
else
{
$costs[$type] = round($costs[$type] - (($users[barracks] / $users[land]) * $costs[$type]));
if ($costs[$type] < $config[$type] * .75)
$costs[$type] = $config[$type] * .75;
$costs[$type] = round($costs[$type] * $urace[mkt]);
}
}
function sellUnits ($type)
{
global $users, $uera, $sell, $costs, $config;
$amount = $sell[$type];
fixInputNum($amount);
$cost = $amount * $costs[$type];
if ($amount == 0)
return;
elseif ($amount < 0)
print "Cannot sell a negative amount of $uera[$type]!<br>\n";
elseif ($type != food && $amount > $users[$type])
print "You can't sell that many $uera[$type]!<br>\n";
elseif ($type == food && $amount > $users[$type])
print "You don't have that many $uera[$type]!<br>\n";
elseif ($type == armtrp && $amount > $users[$type])
print "You don't have that many $uera[$type]!<br>\n";
elseif ($type == flytrp && $amount > $users[$type])
print "You don't have that many $uera[$type]!<br>\n";
elseif ($type == lndtrp && $amount > $users[$type])
print "You don't have that many $uera[$type]!<br>\n";
elseif ($type == seatrp && $amount > $users[$type])
print "You don't have that many $uera[$type]!<br>\n";
else
{
$users[cash] += $cost;
$users["bmper"."$type"] = $users["bmper"."$type"] + ($amount/$users[$type])*10000;
$users[$type] -= $amount;
print commas($amount)." $uera[$type] sold for $".commas($cost)."<br>\n";
}
}
function printRow ($type)
{
global $users, $uera, $costs, $config;
?>
<tr><td><?=$uera[$type]?></td>
<td class="aright"><?=commas($users[$type])?></td>
<td class="aright"><?print commas($users[$type]);?></td>
<td class="aright">$<?=$costs[$type]?></td>
<td class="aright"><input type="text" name="sell[<?=$type?>]" size="8" value="0"></td>
<td class="acenter"><input type="checkbox" name="sell[<?=$type?>]" value="<?=$users[$type]?>"></td>
</tr>
<?
}
for ($i = 0; $i < sizeof($trplst); $i++)
getCosts($trplst[$i]);
if ($do_sell)
{
for ($i = 0; $i < sizeof($trplst); $i++)
sellUnits($trplst[$i]);
saveUserDataNet($users,"networth cash armtrp lndtrp flytrp seatrp food bmperseatrp bmperflytrp bmperlndtrp bmperarmtrp");
}
?>
Also see: <a href="<?=$config[main]?>?action=guide&section=military&era=<?=$users[era]?>">Promisance Guide: Military</a><br>
<form method="post" action="<?=$config[main]?>?action=pvtmarketsell">
<table class="inputtable">
<tr><td colspan="3"><a href="<?=$config[main]?>?action=pvtmarketbuy">Buy Goods</a></td>
<td colspan="3" class="aright"><a href="<?=$config[main]?>?action=pvtmarketsell">Sell Goods</a></td></tr>
<tr><th class="aleft">Unit</th>
<th class="aright">Owned</th>
<th class="aright">Can Sell</th>
<th class="aright">Price</th>
<th class="acenter">Sell</th>
<th class="acenter">Sell All</th>
</tr>
<?
for ($i = 0; $i < sizeof($trplst); $i++)
printRow($trplst[$i]);
?>
<tr><td colspan="7" class="acenter"><input type="submit" name="do_sell" value="Sell Goods"></td></tr>
</table>
</form>
<?
TheEnd("");
?>