Location: PHPKode > projects > EliteSquadrons Promisance (TM) > esprom2_3_1/aid.php
<?
include("header.php");

function sendUnits ($type)
{
	global $users, $uera, $enemy, $eera, $send, $cansend, $mesg;
	fixInputNum($send[$type]);
	$amount = $send[$type];
	if ($amount == 0)
		return;
	elseif ($amount < 0)
		TheEnd("Cannot send a negative amount of $uera[$type]!");
	elseif ($amount > $users[$type])
		TheEnd("You don't have that many $uera[$type]!");
	elseif ($amount > $cansend[$type])
		TheEnd("Cannot send more than 20% of your $uera[$type]!");
	else
	{
		$amount1 = $amount * $config[aidtax];
		$amount = $amount - $amount1;

		$users[$type] -= $amount;
		$enemy[$type] += $amount;
		if ($type == seatrp)
			;
		elseif ($type == cash)
			$mesg .= "$".commas($amount)."<br>";
		else	$mesg .= commas($amount)." $eera[$type]<br>";
	}
}

function printRow ($type)
{
	global $users, $uera, $cansend, $convoy;
	?>
	<tr><td><?if ($type == cash) echo "Money"; else echo $uera[$type]?></td>
    <td class="aright"><?=commas($users[$type])?></td>
    <td class="aright"><?=commas($cansend[$type])?></td>
    <td class="aright"><input type="text" name="send[<?=$type?>]" size="8" value="0"></td></tr>
	<?
}

if ($users[turnsused] <= $config[protection])
	TheEnd("Cannot send aid while under protection!");
if ($users[aidcred] == 0)
	TheEnd("Cannot send any more foreign aid!");
if ($config[aid_ac] == 1) {
	if ($users[aidget] > 0)
		TheEnd("Cannot send aid because we got an aid package today!"); 
}

$convoy = floor($users[networth] / 55);

// Now you need at least 5% of your land filled with markets
// - zEro

$markets_need = floor($users[land] * .05);

for ($i = 0; $i < 4; $i++)
	$cansend[$trplst[$i]] = round($users[$trplst[$i]] * .20);
$cansend[cash] = round($users[cash] * .20);
$cansend[runes] = round($users[runes] * .20);
$cansend[food] = round($users[food] * .20);

if ($do_sendaid)
{
	if ($users[turns] < $urace[aidturns])
		TheEnd("Not enough turns!");
	if (!$dest)
		TheEnd("You must specify an empire!");
	if ($dest == $users[num])
		TheEnd("Cannot send aid to yourself!");
	if ($users[peasants] < $convoy)
		// We replaced the galleons with peasants
		TheEnd("You don't have enough $uera[peasants]!");
	if ($users[shops] < $markets_need)
		TheEnd("You don't have at least $markets_need $uera[shops]");
	fixInputNum($send[seatrp]);
//	if ($send[peasants] < $convoy)
//		TheEnd("You must send at least $convoy $uera[peasants]!");

	$enemy = loadUser($dest);
	$eera = loadEra($enemy[era]);

// Two new lines for the new code.

//	$bankuser = loadUser($config[banknum]);
//	$bank_era = loadEra($bankuser[era]);	
	if ($enemy[land] <= 0)
		TheEnd("Empire is dead! Cannot send aid!");
	if ($enemy[num] != $dest)
		TheEnd("No such empire!");
	if (($enemy[era] != $users[era]) && ($enemy[gate] <= $time) && ($users[gate] <= $time))
		TheEnd("Need to open a time portal first!");
	if ($enemy[disabled] >= 2)
		TheEnd("Cannot send aid to disabled empires!");
// Anti Cheating Protection
	if ($config[aid_ac] == 1) {
		if (($enemy[aidget] > 0) && ($enemy[aidget] < $config[maxaidget]))
			TheEnd("Cannot send more aid packages since $enemy[empire] (#$enemy[num]) has got $config[maxaidget] aid packages today!");
		if ($enemy[aidcred] < $config[maxaid])
			TheEnd("Cannot send aid to someone who has send aid in the last $config[aidhours]!");
	}
	if ($enemy[turnsused] <= $config[protection])
		TheEnd("Cannot send aid to someone under protection!");
	if ($enemy[vacation] > $config[vacationdelay])
		TheEnd("Cannot send aid to someone on vacation!");
	if ($enemy[networth] > ($users[networth] * $config[nonaid]))
			TheEnd("That empire is far too large to require your aid!");
//	if ($enemy[networth] < ($users[networth] * $config[nonaid]))
//			TheEnd("Cannot send aid, due to the empire being near the same size of your networth");

	$uclan = loadClan($users[clan]);
	if ($enemy[clan])
	{
		if (($uclan[war1] == $enemy[clan]) || ($uclan[war2] == $enemy[clan])|| ($uclan[war3] == $enemy[clan]))
			TheEnd("Your Generals laugh at the idea of sending aid to your enemies.");
		if (($users[clan] == $enemy[clan]) || ($uclan[ally1] == $enemy[clan]) || ($uclan[ally2] == $enemy[clan]) || ($uclan[ally3] == $enemy[clan]))
			$users[aidcred]++;	// unlimited aid to allies
	}


	sendUnits(seatrp);	// MUST do this first
	for ($i = 0; $i < 4; $i++)
		sendUnits($trplst[$i]);
	sendUnits(cash);
	sendUnits(runes);
	sendUnits(food);


	addNews(102,$users,$enemy,$send[seatrp],$send[armtrp],$send[lndtrp],$send[flytrp],$send[cash],$send[runes],$send[food],$send[aid]);
	$users[aidcred]--;
	$users[peasants] -= $convoy;
	saveUserDataNet($users,"networth armtrp lndtrp flytrp seatrp cash runes food aidcred peasants");
	saveUserDataNet($enemy,"networth armtrp lndtrp flytrp seatrp cash runes food aidget");

// Beta code

//	saveUserDataNet($bankuser,"networth cash armtrp lndtrp flytrp seatrp runes food iron");

	// New turns for aiding :)

	takeTurns($urace[aidturns],aid);
?>
<?=commas($send[seatrp])?> <?=$uera[seatrp]?> have departed with shipment to <b><?=$enemy[empire]?> (#<?=$enemy[num]?>)</b>
<hr>
<?
$convoy = floor($users[networth] / 55);

// Now you need at least 5% of your land filled with markets
// - zEro

$markets_need = floor($users[land] * .05);

	for ($i = 0; $i < 4; $i++)
		$cansend[$trplst[$i]] = round($users[$trplst[$i]] * .20);
	$cansend[cash] = round($users[cash] * .20);
	$cansend[runes] = round($users[runes] * .20);
	$cansend[food] = round($users[food] * .20);
}
?>

<? 

// Configuration so you can or can't aid.

if ($config[canaid] == 0)
	TheEnd("Cannot Aid in this game!");
		
?>

Sending aid requires <?=$urace[aidturns]?> turn<?=plural($urace[aidturns],"s","")?> and at least <?=commas($convoy)?> <?=$uera[peasants]?><br>
Due to our world general taxes, we need to pay a <? $test = $config[aidtax] * 100; print "$test";?>% aiding tax.<br>
And we need at least <?=$markets_need?> market<?=plural($markets_need,"s","")?>.<br>
We can send up to <?=$users[aidcred]?> shipment<?=plural($users[aidcred],"s","")?>.<br>
We can send an additional shipment every hour.<br><br>
<form method="post" action="<?=$config[main]?>?action=aid">
<table class="inputtable">
<tr><td colspan="3" class="aright">Send aid to which empire?</td>
    <td><input type="text" name="dest" size="6"></td></tr>
<tr><th class="aleft">Unit</th>
    <th class="aright">Owned</th>
    <th class="aright">Can Send</th>
    <th class="aright">Send</th></tr>
<?
for ($i = 0; $i < 4; $i++)
	printRow($trplst[$i]);
printRow(cash);
printRow(runes);
printRow(food);
?>
<tr><td colspan="4" class="acenter"><input type="submit" name="do_sendaid" value="Send Assistance"></td></tr>
</table>
</form>
<?
TheEnd("");
?>
Return current item: EliteSquadrons Promisance (TM)