Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

big update

  • Loading branch information...
commit 8c44bb4e2a58dd3bc1d7ae8826bd78f1cbdcba5c 1 parent a566e25
unknown authored
Showing with 1,465 additions and 993 deletions.
  1. +3 −4 Admin/admin.php
  2. +0 −1  GameEngine/Account.php
  3. +32 −4 GameEngine/Admin/database.php
  4. +8 −1 GameEngine/Alliance.php
  5. +341 −80 GameEngine/Automation.php
  6. +755 −793 GameEngine/Battle.php
  7. +1 −1  GameEngine/Building.php
  8. +15 −9 GameEngine/Database/db_MYSQL.php
  9. +1 −1  GameEngine/Generator.php
  10. +6 −2 GameEngine/Ranking.php
  11. +1 −0  GameEngine/Session.php
  12. +7 −7 GameEngine/Technology.php
  13. +34 −28 Templates/Ajax/quest_core.tpl
  14. +57 −0 Templates/Alliance/alliance.tpl
  15. +1 −1  Templates/Alliance/overview.tpl
  16. +34 −0 Templates/Build/19_train.tpl
  17. +3 −1 Templates/Build/20.tpl
  18. +3 −3 Templates/Build/21.tpl
  19. +1 −1  Templates/Build/25_train.tpl
  20. +1 −1  Templates/Build/26_train.tpl
  21. +1 −1  Templates/Build/37_hero.tpl
  22. +2 −2 Templates/Message/write.tpl
  23. +15 −1 Templates/Notice/18.tpl
  24. +15 −1 Templates/Notice/18x.tpl
  25. +15 −1 Templates/Notice/19.tpl
  26. +15 −1 Templates/Notice/19x.tpl
  27. +15 −1 Templates/Notice/20.tpl
  28. +15 −1 Templates/Notice/20x.tpl
  29. +15 −1 Templates/Notice/21.tpl
  30. +15 −1 Templates/Notice/21x.tpl
  31. +4 −4 Templates/Notice/3x.tpl
  32. +1 −1  Templates/Plus/10.tpl
  33. +1 −1  Templates/Plus/11.tpl
  34. +1 −1  Templates/Plus/12.tpl
  35. +1 −1  Templates/Plus/9.tpl
  36. +1 −3 Templates/Profile/account.tpl
  37. +1 −1  Templates/Ranking/ww.tpl
  38. +0 −2  Templates/menu.tpl
  39. +2 −2 Templates/quest.tpl
  40. +2 −2 anmelden.php
  41. +1 −1  create_account.php
  42. +1 −1  dorf1.php
  43. BIN  gpack/travian_default/img/q/l4.jpg
  44. BIN  gpack/travian_default/img/q/l4g.jpg
  45. +2 −2 login.php
  46. +20 −22 medals.php
7 Admin/admin.php
View
@@ -93,7 +93,6 @@ function hideStuff(id) {
<a href="<?php echo HOMEPAGE; ?>">Server Homepage</a>
<a href="admin.php">Control Panel Home</a>
<a href="<?php echo SERVER; ?>dorf1.php">Return to the server</a>
- <a href="?p=update"><font color="Red"><b>Server Update</font></b></a>
<br />
<a href="?action=logout">Logout</a>
<br />
@@ -103,8 +102,8 @@ function hideStuff(id) {
<a href="?p=notregistered">Players Not Activated</a>
<br />
<a href="#"><b>Search</b></a>
- <a href="?p=search">General Search</a>
- <a href="?p=message">Search IGMs/Reports</a>
+ <a href="?p=search">Search Players/Alliances/Villages/E-mails/IPs/Deleted Players</a>
+ <a href="?p=message">Search Messages/Battle Reports</a>
<br />
<a href="#"><b>Ban</b></a>
<a href="?p=ban">Ban/Unban Players</a>
@@ -130,7 +129,7 @@ function hideStuff(id) {
<br />
<a href="#"><b>Natars</b></a>
<a href="?p=natarend">Add WW Villages</a>
- <a href="?p=natarbuildingplan">Add WW Building Plan Villages</a>
+ <a href="?p=natarbuildingplan">Add WW Buildingplan Villages</a>
<br />
<a href="#"><b>Admin:</b></a>
<a href="?p=admin_log"><font color="Red"><b>Admin Log</font></b></a>
1  GameEngine/Account.php
View
@@ -114,7 +114,6 @@ private function Signup() {
if($uid) {
setcookie("COOKUSR",$_POST['name'],time()+COOKIE_EXPIRE,COOKIE_PATH);
setcookie("COOKEMAIL",$_POST['email'],time()+COOKIE_EXPIRE,COOKIE_PATH);
-
$database->updateUserField($uid,"act","",1);
$database->updateUserField($uid,"invited",$_POST['invited'],1);
$this->generateBase($_POST['kid'],$uid,$_POST['name']);
36 GameEngine/Admin/database.php
View
@@ -52,6 +52,7 @@ function recountPopUser($uid){
for ($i = 0; $i <= count($villages)-1; $i++) {
$vid = $villages[$i]['wref'];
$this->recountPop($vid);
+ $this->recountCP($vid);
}
}
@@ -60,15 +61,30 @@ function recountPop($vid){
$fdata = $database->getResourceLevel($vid);
$popTot = 0;
for ($i = 1; $i <= 40; $i++) {
- $lvl = $fdata["f".$i];
- $building = $fdata["f".$i."t"];
- if($building){
+ $lvl = $fdata["f".$i];
+ $building = $fdata["f".$i."t"];
+ if($building){
$popTot += $this->buildingPOP($building,$lvl);
- }
+ }
}
$q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid";
mysql_query($q, $this->connection);
}
+
+ function recountCP($vid){
+ global $database;
+ $fdata = $database->getResourceLevel($vid);
+ $popTot = 0;
+ for ($i = 1; $i <= 40; $i++) {
+ $lvl = $fdata["f".$i];
+ $building = $fdata["f".$i."t"];
+ if($building){
+ $popTot += $this->buildingCP($building,$lvl);
+ }
+ }
+ $q = "UPDATE ".TB_PREFIX."vdata set cp = $popTot where wref = $vid";
+ mysql_query($q, $this->connection);
+ }
function buildingPOP($f,$lvl){
$name = "bid".$f;
@@ -80,6 +96,18 @@ function buildingPOP($f,$lvl){
}
return $popT;
}
+
+ function buildingCP($f,$lvl){
+ $name = "bid".$f;
+ global $$name;
+ $popT = 0;
+ $dataarray = $$name;
+
+ for ($i = 0; $i <= $lvl; $i++) {
+ $popT += $dataarray[$i]['cp'];
+ }
+ return $popT;
+ }
function getWref($x,$y) {
$q = "SELECT id FROM ".TB_PREFIX."wdata where x = $x and y = $y";
9 GameEngine/Alliance.php
View
@@ -108,7 +108,7 @@ public function procAlliForm($post) {
public function sendInvite($post) {
global $form, $database, $session;
if($session->access != BANNED){
- if(isset($post['a_name']) && $post['a_uid'] != ""){
+ if(isset($post['a_name']) or $post['a_uid'] == ""){
$UserData = $database->getUserArray($post['a_name'], 0);
if($this->userPermArray['opt4'] == 0) {
$form->addError("perm", NO_PERMISSION);
@@ -393,6 +393,13 @@ private function quitally($post) {
} elseif(md5($post['pw']) !== $session->userinfo['password']) {
$form->addError("pw2", PW_ERR);
} else {
+ if($database->isAllianceOwner($sessiom->uid)){
+ $newowner = $database->getAllMember2($session->alliance);
+ $newleader = $newowner['id'];
+ $q = "UPDATE " . TB_PREFIX . "alidata set leader = ".$newleader." where id = ".$session->alliance."";
+ $database->query($q);
+ $database->updateAlliPermissions($newleader, 1, 1, 1, 1, 1, 1, 1, 1, 1);
+ }
$database->updateUserField($session->uid, 'alliance', 0, 1);
$database->deleteAlliPermissions($session->uid);
// log the notice
421 GameEngine/Automation.php
View
@@ -1,7 +1,9 @@
<?php
-if (!isset($_SESSION)) {
- session_start();
-}
+# Developed By : Mr.php
+# you have no rights to change this !!
+# Fixed : Doubling Troops , Hero not dieing etc ..
+# Email : mr.php-majed@hotmail.com
+# Skype : mr.majed1005
class Automation {
@@ -101,6 +103,7 @@ function recountCP($vid){
global $database;
$fdata = $database->getResourceLevel($vid);
$popTot = 0;
+
for ($i = 1; $i <= 40; $i++) {
$lvl = $fdata["f".$i];
$building = $fdata["f".$i."t"];
@@ -109,7 +112,7 @@ function recountCP($vid){
}
}
- $q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid";
+ $q = "UPDATE ".TB_PREFIX."vdata set cp = $popTot where wref = $vid";
mysql_query($q);
return $popTot;
@@ -141,39 +144,77 @@ function buildingCP($f,$lvl){
}
public function Automation() {
+
$this->procClimbers();
+ $this->ClearUser();
$this->ClearInactive();
$this->oasisResoucesProduce();
$this->pruneResource();
$this->pruneOResource();
$this->checkWWAttacks();
- $this->culturePoints();
- $this->updateHero();
- $this->clearDeleting();
- $this->buildComplete();
+ if(!file_exists("GameEngine/Prevention/culturepoints.txt") or time()-filemtime("GameEngine/Prevention/culturepoints.txt")>10) {
+ $this->culturePoints();
+ }
+ if(!file_exists("GameEngine/Prevention/updatehero.txt") or time()-filemtime("GameEngine/Prevention/updatehero.txt")>50) {
+ $this->updateHero();
+ }
+ if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time()-filemtime("GameEngine/Prevention/cleardeleting.txt")>10) {
+ $this->clearDeleting();
+ }
+ if (! file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt") > 10)
+ {
+ $this->buildComplete();
+ }
$this->MasterBuilder();
- $this->demolitionComplete();
+ if (! file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt") > 10)
+ {
+ $this->demolitionComplete();
+ }
$this->updateStore();
$this->delTradeRoute();
$this->TradeRoute();
- $this->marketComplete();
- $this->researchComplete();
- $this->trainingComplete();
- $this->starvation();
- $this->celebrationComplete();
- $this->sendunitsComplete();
- $this->loyaltyRegeneration();
- $this->sendreinfunitsComplete();
- $this->returnunitsComplete();
- $this->sendSettlersComplete();
+ if(!file_exists("GameEngine/Prevention/market.txt") or time()-filemtime("GameEngine/Prevention/market.txt")>10) {
+ $this->marketComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/research.txt") or time()-filemtime("GameEngine/Prevention/research.txt")>10) {
+ $this->researchComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/training.txt") or time()-filemtime("GameEngine/Prevention/training.txt")>10) {
+ $this->trainingComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/starvation.txt") or time()-filemtime("GameEngine/Prevention/starvation.txt")>10) {
+ $this->starvation();
+ }
+ if(!file_exists("GameEngine/Prevention/celebration.txt") or time()-filemtime("GameEngine/Prevention/celebration.txt")>10) {
+ $this->celebrationComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/sendunits.txt") or time()-filemtime("GameEngine/Prevention/sendunits.txt")>10) {
+ $this->sendunitsComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/loyalty.txt") or time()-filemtime("GameEngine/Prevention/loyalty.txt")>50) {
+ $this->loyaltyRegeneration();
+ }
+ if(!file_exists("GameEngine/Prevention/sendreinfunits.txt") or time()-filemtime("GameEngine/Prevention/sendreinfunits.txt")>10) {
+ $this->sendreinfunitsComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/returnunits.txt") or time()-filemtime("GameEngine/Prevention/returnunits.txt")>51) {
+ $this->returnunitsComplete();
+ }
+ if(!file_exists("GameEngine/Prevention/settlers.txt") or time()-filemtime("GameEngine/Prevention/settlers.txt")>10) {
+ $this->sendSettlersComplete();
+ }
$this->updateGeneralAttack();
$this->checkInvitedPlayes();
+ $this->updateStore();
$this->CheckBan();
$this->regenerateOasisTroops();
$this->artefactOfTheFool();
}
private function loyaltyRegeneration() {
+ if(file_exists("GameEngine/Prevention/loyalty.txt")) {
+ unlink("GameEngine/Prevention/loyalty.txt");
+ }
global $database;
$array = array();
$q = "SELECT * FROM ".TB_PREFIX."vdata WHERE loyalty<>100";
@@ -209,6 +250,9 @@ private function loyaltyRegeneration() {
$database->query($q);
}
}
+ if(file_exists("GameEngine/Prevention/loyalty.txt")) {
+ unlink("GameEngine/Prevention/loyalty.txt");
+ }
}
private function getfieldDistance($coorx1, $coory1, $coorx2, $coory2) {
@@ -271,7 +315,12 @@ public function getTypeLevel($tid,$vid) {
}
private function clearDeleting() {
+ if(file_exists("GameEngine/Prevention/cleardeleting.txt")) {
+ unlink("GameEngine/Prevention/cleardeleting.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/cleardeleting.txt", 'w');
+ fclose($ourFileHandle);
$needDelete = $database->getNeedDelete();
if(count($needDelete) > 0) {
foreach($needDelete as $need) {
@@ -281,14 +330,12 @@ private function clearDeleting() {
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."bdata where wid = ".$village;
$database->query($q);
- $q = "DELETE FROM ".TB_PREFIX."enforcement where vref = ".$village;
+ $q = "DELETE FROM ".TB_PREFIX."enforcement where from = ".$village;
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."fdata where vref = ".$village;
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."market where vref = ".$village;
$database->query($q);
- $q = "DELETE FROM ".TB_PREFIX."movement where to = ".$village." or from = ".$village;
- $database->query($q);
$q = "DELETE FROM ".TB_PREFIX."odata where wref = ".$village;
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."research where vref = ".$village;
@@ -299,11 +346,56 @@ private function clearDeleting() {
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."units where vref =".$village;
$database->query($q);
- $q = "DELETE FROM ".TB_PREFIX."vdata where vref = ".$village;
+ $q = "DELETE FROM ".TB_PREFIX."vdata where wref = ".$village;
$database->query($q);
$q = "UPDATE ".TB_PREFIX."wdata set occupied = 0 where id = ".$village;
$database->query($q);
+ $getmovement = $database->getMovement(3,$village,1);
+ foreach($getmovement as $movedata) {
+ $time = time();
+ $time2 = $time - $movedata['starttime'];
+ $database->addMovement(4,$movedata['to'],$movedata['from'],$movedata['ref'],$time,$time+$time2);
+ $database->setMovementProc($movedata['moveid']);
+ }
+ $q = "DELETE FROM ".TB_PREFIX."movement where from = ".$village;
+ $database->query($q);
+ $getprisoners = $database->getPrisoners($village);
+ foreach($getprisoners as $pris) {
+ $troops = 0;
+ for($i=1;$i<12;$i++){
+ $troops += $pris['t'.$i];
+ }
+ $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0));
+ $database->deletePrisoners($pris['id']);
+ }
+ $getprisoners = $database->getPrisoners3($village);
+ foreach($getprisoners as $pris) {
+ $troops = 0;
+ for($i=1;$i<12;$i++){
+ $troops += $pris['t'.$i];
+ }
+ $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0));
+ $database->deletePrisoners($pris['id']);
+ }
+ $enforcement = $database->getEnforceVillage($village,0);
+ foreach($enforcement as $enforce) {
+ $time = time();
+ $fromcoor = $database->getCoor($enforce['vref']);
+ $tocoor = $database->getCoor($enforce['from']);
+ $targettribe = $database->getUserField($database->getVillageField($enforce['from'],"owner"),"tribe",0);
+ $time2 = $this->procDistanceTime($tocoor,$fromcoor,$targettribe,0);
+ $start = 10*($targettribe-1);
+ for($i=1;$i<11;$i++){
+ $unit = $start + $i;
+ $post['t'.$i] = $enforce['u'.$unit];
+ }
+ $post['t11'] = $enforce['hero'];
+ $reference = $database->addAttack($enforce['from'],$post['t1'],$post['t2'],$post['t3'],$post['t4'],$post['t5'],$post['t6'],$post['t7'],$post['t8'],$post['t9'],$post['t10'],$post['t11'],2,0,0,0,0);
+ $database->addMovement(4,$enforce['vref'],$enforce['from'],$reference,$time,$time+$time2);
+ }
}
+ $q = "DELETE FROM ".TB_PREFIX."hero where uid = ".$need['uid'];
+ $database->query($q);
$q = "DELETE FROM ".TB_PREFIX."mdata where target = ".$need['uid']." or owner = ".$need['uid'];
$database->query($q);
$q = "DELETE FROM ".TB_PREFIX."ndata where uid = ".$need['uid'];
@@ -312,8 +404,20 @@ private function clearDeleting() {
$database->query($q);
}
}
+ if(file_exists("GameEngine/Prevention/cleardeleting.txt")) {
+ unlink("GameEngine/Prevention/cleardeleting.txt");
+ }
}
-
+
+ private function ClearUser() {
+ global $database;
+ if(AUTO_DEL_INACTIVE) {
+ $time = time()+UN_ACT_TIME;
+ $q = "DELETE from ".TB_PREFIX."users where timestamp >= $time and act != ''";
+ $database->query($q);
+ }
+ }
+
private function ClearInactive() {
global $database;
if(TRACK_USR) {
@@ -470,6 +574,9 @@ private function pruneResource() {
}
private function culturePoints() {
+ if(file_exists("GameEngine/Prevention/culturepoints.txt")) {
+ unlink("GameEngine/Prevention/culturepoints.txt");
+ }
global $database,$session;
$time = time()-600; // 10minutes
$array = array();
@@ -485,9 +592,15 @@ private function culturePoints() {
$database->query($q);
}
}
- }
+ if(file_exists("GameEngine/Prevention/culturepoints.txt")) {
+ unlink("GameEngine/Prevention/culturepoints.txt");
+ }
+}
private function buildComplete() {
+ if(file_exists("GameEngine/Prevention/build.txt")) {
+ unlink("GameEngine/Prevention/build.txt");
+ }
global $database,$bid18,$bid10,$bid11,$bid38,$bid39;
$time = time();
$array = array();
@@ -584,6 +697,9 @@ private function buildComplete() {
$database->setVillageField($indi['wid'], 'starvupdate', $time);
}
}
+ if(file_exists("GameEngine/Prevention/build.txt")) {
+ unlink("GameEngine/Prevention/build.txt");
+ }
}
// by SlimShady95 aka Manuel Mannhardt < manuel_mannhardt@web.de >
@@ -782,7 +898,12 @@ private function TradeRoute() {
}
private function marketComplete() {
+ if(file_exists("GameEngine/Prevention/market.txt")) {
+ unlink("GameEngine/Prevention/market.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/market.txt", 'w');
+ fclose($ourFileHandle);
$time = time();
$q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."send where ".TB_PREFIX."movement.ref = ".TB_PREFIX."send.id and ".TB_PREFIX."movement.proc = 0 and sort_type = 0 and endtime < $time";
$dataarray = $database->query_return($q);
@@ -817,6 +938,9 @@ private function marketComplete() {
$this->sendResource2($data1['wood'],$data1['clay'],$data1['iron'],$data1['crop'],$data1['to'],$data1['from'],$targettribe1,$send);
}
}
+ if(file_exists("GameEngine/Prevention/market.txt")) {
+ unlink("GameEngine/Prevention/market.txt");
+ }
}
private function sendResource2($wtrans,$ctrans,$itrans,$crtrans,$from,$to,$tribe,$send) {
@@ -854,7 +978,12 @@ private function sendResource2($wtrans,$ctrans,$itrans,$crtrans,$from,$to,$tribe
}
private function sendunitsComplete() {
+ if(file_exists("GameEngine/Prevention/sendunits.txt")) {
+ unlink("GameEngine/Prevention/sendunits.txt");
+ }
global $bid23,$bid34,$database,$battle,$village,$technology,$logging,$generator;
+ $ourFileHandle = fopen("GameEngine/Prevention/sendunits.txt", 'w');
+ fclose($ourFileHandle);
$time = time();
$q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = '0' and ".TB_PREFIX."movement.sort_type = '3' and ".TB_PREFIX."attacks.attack_type != '2' and endtime < $time ORDER BY endtime ASC";
$dataarray = $database->query_return($q);
@@ -956,9 +1085,9 @@ private function sendunitsComplete() {
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catp = 0;
- $catapult = array(8,18,28,38,48);
- $ram = array(7,17,27,37,47);
- $chief = array(9,19,29,39,49);
+ $catapult = array(8,18,28,48);
+ $ram = array(7,17,27,47);
+ $chief = array(9,19,29,49);
$spys = array(4,14,23,44);
for($i=$start;$i<=$end;$i++) {
$y = $i-$u;
@@ -1112,8 +1241,6 @@ private function sendunitsComplete() {
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catp = 0;
- $rams = 0;
- $chiefs = 0;
$catapult = array(8,18,28,38,48);
$ram = array(7,17,27,37,47);
$chief = array(9,19,29,39,49);
@@ -1703,7 +1830,7 @@ private function sendunitsComplete() {
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
- if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0)
+ if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$_rand[$j]=$bdo['f'.$i];
@@ -1732,7 +1859,7 @@ private function sendunitsComplete() {
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
- if ($bdo['f'.$i] > 0)
+ if ($bdo['f'.$i] > 0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$list[$j]=$i;
$j++;
@@ -1773,7 +1900,8 @@ private function sendunitsComplete() {
$database->query($q);
}
$pop=$this->recountPop($data['to']);
- if($pop=='0')
+ $capital = $database->getVillage($data['to']);
+ if($pop=='0' && $capital['capital']=='0')
{
$village_destroyed = 1;
}
@@ -1827,7 +1955,7 @@ private function sendunitsComplete() {
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
- if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0)
+ if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$_rand[$j]=$bdo['f'.$i];
@@ -1856,7 +1984,7 @@ private function sendunitsComplete() {
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
- if ($bdo['f'.$i] > 0)
+ if ($bdo['f'.$i] > 0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$list[$j]=$i;
@@ -1951,7 +2079,7 @@ private function sendunitsComplete() {
for ($i=1;$i<=41;$i++)
{
if ($i==41) $i=99;
- if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0)
+ if ($bdo['f'.$i.'t']==$rand && $bdo['f'.$i]>0 && $rand != 31 && $rand != 32 && $rand != 33)
{
$j++;
$_rand[$j]=$bdo['f'.$i];
@@ -2380,7 +2508,7 @@ private function sendunitsComplete() {
$database->modifyAttack2($data['ref'],10,$prisoner['t10']);
$database->modifyAttack2($data['ref'],11,$prisoner['t11']);
$mytroops = $prisoner['t1']+$prisoner['t2']+$prisoner['t3']+$prisoner['t4']+$prisoner['t5']+$prisoner['t6']+$prisoner['t7']+$prisoner['t8']+$prisoner['t9']+$prisoner['t10']+$prisoner['t11'];
- $newtraps = (round($mytroops/3))*2;
+ $newtraps = round($mytroops/3);
$database->modifyUnit($data['to'],array("99"),array($newtraps),array(0));
$database->modifyUnit($data['to'],array("99o"),array($mytroops),array(0));
}else{
@@ -2464,7 +2592,7 @@ private function sendunitsComplete() {
}
}
}
- $data2 = $data2.','.$info_trap.',,';
+ $data2 = $data2.','.addslashes($info_trap).',,';
if($totalsend_alldef == 0){
$database->addNotice($to['owner'],$to['wref'],$targetally,7,''.addslashes($from['name']).' attacks '.addslashes($to['name']).'',$data2,$AttackArrivalTime);
}else if($totaldead_alldef == 0){
@@ -2582,6 +2710,40 @@ private function sendunitsComplete() {
}
$q = "DELETE FROM ".TB_PREFIX."movement where from = ".$data['to'];
$database->query($q);
+ $getprisoners = $database->getPrisoners($data['to']);
+ foreach($getprisoners as $pris) {
+ $troops = 0;
+ for($i=1;$i<12;$i++){
+ $troops += $pris['t'.$i];
+ }
+ $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0));
+ $database->deletePrisoners($pris['id']);
+ }
+ $getprisoners = $database->getPrisoners3($data['to']);
+ foreach($getprisoners as $pris) {
+ $troops = 0;
+ for($i=1;$i<12;$i++){
+ $troops += $pris['t'.$i];
+ }
+ $database->modifyUnit($pris['wref'],array("99o"),array($troops),array(0));
+ $database->deletePrisoners($pris['id']);
+ }
+ $enforcement = $database->getEnforceVillage($data['to'],0);
+ foreach($enforcement as $enforce) {
+ $time = time();
+ $fromcoor = $database->getCoor($enforce['vref']);
+ $tocoor = $database->getCoor($enforce['from']);
+ $targettribe = $database->getUserField($database->getVillageField($enforce['from'],"owner"),"tribe",0);
+ $time2 = $this->procDistanceTime($tocoor,$fromcoor,$targettribe,0);
+ $start = 10*($targettribe-1);
+ for($i=1;$i<11;$i++){
+ $unit = $start + $i;
+ $post['t'.$i] = $enforce['u'.$unit];
+ }
+ $post['t11'] = $enforce['hero'];
+ $reference = $database->addAttack($enforce['from'],$post['t1'],$post['t2'],$post['t3'],$post['t4'],$post['t5'],$post['t6'],$post['t7'],$post['t8'],$post['t9'],$post['t10'],$post['t11'],2,0,0,0,0);
+ $database->addMovement(4,$enforce['vref'],$enforce['from'],$reference,$time,$time+$time2);
+ }
}
}
}else{
@@ -2716,6 +2878,9 @@ private function sendunitsComplete() {
#################################################
}
+ if(file_exists("GameEngine/Prevention/sendunits.txt")) {
+ unlink("GameEngine/Prevention/sendunits.txt");
+ }
}
private function sendTroopsBack($post) {
@@ -2846,8 +3011,13 @@ private function sendTroopsBack($post) {
}
private function sendreinfunitsComplete() {
+ if(file_exists("GameEngine/Prevention/sendreinfunits.txt")) {
+ unlink("GameEngine/Prevention/sendreinfunits.txt");
+ }
global $bid23,$database,$battle;
$time = time();
+ $ourFileHandle = fopen("GameEngine/Prevention/sendreinfunits.txt", 'w');
+ fclose($ourFileHandle);
$q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = '0' and ".TB_PREFIX."movement.sort_type = '3' and ".TB_PREFIX."attacks.attack_type = '2' and endtime < $time";
$dataarray = $database->query_return($q);
foreach($dataarray as $data) {
@@ -2909,10 +3079,18 @@ private function sendreinfunitsComplete() {
$database->setMovementProc($data['moveid']);
}
}
+ if(file_exists("GameEngine/Prevention/sendreinfunits.txt")) {
+ unlink("GameEngine/Prevention/sendreinfunits.txt");
+ }
}
private function returnunitsComplete() {
+ if(file_exists("GameEngine/Prevention/returnunits.txt")) {
+ unlink("GameEngine/Prevention/returnunits.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/returnunits.txt", 'w');
+ fclose($ourFileHandle);
$time = time();
$q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = '0' and ".TB_PREFIX."movement.sort_type = '4' and endtime < $time";
$dataarray = $database->query_return($q);
@@ -2961,10 +3139,19 @@ private function returnunitsComplete() {
$database->modifyUnit($data['to'],array($tribe."0"),array(3),array(1));
$database->setMovementProc($data['moveid']);
}
+
+ if(file_exists("GameEngine/Prevention/returnunits.txt")) {
+ unlink("GameEngine/Prevention/returnunits.txt");
+ }
}
private function sendSettlersComplete() {
+ if(file_exists("GameEngine/Prevention/settlers.txt")) {
+ unlink("GameEngine/Prevention/settlers.txt");
+ }
global $database, $building;
+ $ourFileHandle = fopen("GameEngine/Prevention/settlers.txt", 'w');
+ fclose($ourFileHandle);
$time = time();
$q = "SELECT * FROM ".TB_PREFIX."movement where proc = 0 and sort_type = 5 and endtime < $time";
$dataarray = $database->query_return($q);
@@ -3005,10 +3192,18 @@ private function sendSettlersComplete() {
$database->setMovementProc($data['moveid']);
}
}
- }
+ if(file_exists("GameEngine/Prevention/settlers.txt")) {
+ unlink("GameEngine/Prevention/settlers.txt");
+ }
+ }
private function researchComplete() {
+ if(file_exists("GameEngine/Prevention/research.txt")) {
+ unlink("GameEngine/Prevention/research.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/research.txt", 'w');
+ fclose($ourFileHandle);
$time = time();
$q = "SELECT * FROM ".TB_PREFIX."research where timestamp < $time";
$dataarray = $database->query_return($q);
@@ -3027,6 +3222,9 @@ private function researchComplete() {
$q = "DELETE FROM ".TB_PREFIX."research where id = ".$data['id'];
$database->query($q);
}
+ if(file_exists("GameEngine/Prevention/research.txt")) {
+ unlink("GameEngine/Prevention/research.txt");
+ }
}
private function updateRes($bountywid,$uid) {
@@ -3137,8 +3335,9 @@ function getAllUnits($base) {
public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
global $database,$session,$village;
- if ($vid == 0) { $vid = $_SESSION['wid']; }
- $buildarray = $database->getResourceLevel($vid);
+ if($vid==0) { $vid=$village->wid; }
+ $buildarray = array();
+ if($vid!=0){ $buildarray = $database->getResourceLevel($vid); }
$upkeep = 0;
switch($type) {
case 0:
@@ -3209,9 +3408,9 @@ public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
}else{
$upkeep += $array['t11'] * 6;
}
- $artefact = count($database->getOwnUniqueArtefactInfo2($_SESSION['id_user'],4,3,0));
+ $artefact = count($database->getOwnUniqueArtefactInfo2($session->uid,4,3,0));
$artefact1 = count($database->getOwnUniqueArtefactInfo2($vid,4,1,1));
- $artefact2 = count($database->getOwnUniqueArtefactInfo2($_SESSION['id_user'],4,2,0));
+ $artefact2 = count($database->getOwnUniqueArtefactInfo2($session->uid,4,2,0));
if($artefact > 0){
$upkeep /= 2;
$upkeep = round($upkeep);
@@ -3223,7 +3422,7 @@ public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
$upkeep = round($upkeep);
$upkeep *= 3;
}
- $foolartefact = $database->getFoolArtefactInfo(4,$vid,$_SESSION['id_user']);
+ $foolartefact = $database->getFoolArtefactInfo(4,$vid,$session->uid);
if(count($foolartefact) > 0){
foreach($foolartefact as $arte){
if($arte['bad_effect'] == 1){
@@ -3414,8 +3613,13 @@ private function bountyGetCropProd() {
}
private function trainingComplete() {
+ if(file_exists("GameEngine/Prevention/training.txt")) {
+ unlink("GameEngine/Prevention/training.txt");
+ }
global $database;
$time = time();
+ $ourFileHandle = fopen("GameEngine/Prevention/training.txt", 'w');
+ fclose($ourFileHandle);
$trainlist = $database->getTrainingList();
if(count($trainlist) > 0){
foreach($trainlist as $train){
@@ -3452,6 +3656,9 @@ private function trainingComplete() {
}
}
}
+ if(file_exists("GameEngine/Prevention/training.txt")) {
+ unlink("GameEngine/Prevention/training.txt");
+ }
}
public function procDistanceTime($coor,$thiscoor,$ref,$mode) {
@@ -3546,7 +3753,13 @@ private function getsort_typeLevel($tid,$resarray) {
}
private function celebrationComplete() {
+ if(file_exists("GameEngine/Prevention/celebration.txt")) {
+ unlink("GameEngine/Prevention/celebration.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/celebration.txt", 'w');
+ fclose($ourFileHandle);
+
$varray = $database->getCel();
foreach($varray as $vil){
$id = $vil['wref'];
@@ -3556,10 +3769,19 @@ private function celebrationComplete() {
$database->clearCel($id);
$database->setCelCp($user,$cp);
}
+ if(file_exists("GameEngine/Prevention/celebration.txt")) {
+ unlink("GameEngine/Prevention/celebration.txt");
+ }
}
private function demolitionComplete() {
+ if(file_exists("GameEngine/Prevention/demolition.txt")) {
+ unlink("GameEngine/Prevention/demolition.txt");
+ }
global $building,$database;
+ $ourFileHandle = fopen("GameEngine/Prevention/demolition.txt", 'w');
+ fclose($ourFileHandle);
+
$varray = $database->getDemolition();
foreach($varray as $vil) {
if ($vil['timetofinish'] <= time()) {
@@ -3586,16 +3808,22 @@ private function demolitionComplete() {
$database->delDemolition($vil['vref']);
}
}
+ if(file_exists("GameEngine/Prevention/demolition.txt")) {
+ unlink("GameEngine/Prevention/demolition.txt");
+ }
}
private function updateHero() {
+ if(file_exists("GameEngine/Prevention/updatehero.txt")) {
+ unlink("GameEngine/Prevention/updatehero.txt");
+ }
global $database,$hero_levels;
$harray = $database->getHero();
if(!empty($harray)){
foreach($harray as $hdata){
if((time()-$hdata['lastupdate'])>=1){
if($hdata['health']<100 and $hdata['health']>0){
- $reg = $hdata['health']+$hdata['regeneration']*5*SPEED/86400*(time()-$hdata['lastupdate']);
+ $reg = $hdata['health']+$hdata['regeneration']*5*ceil(SPEED/10)/86400*(time()-$hdata['lastupdate']);
if($reg <= 100){
$database->modifyHero("health",$reg,$hdata['heroid']);
}else{
@@ -3619,45 +3847,58 @@ private function updateHero() {
}
}
}
- }
-
+ if(file_exists("GameEngine/Prevention/updatehero.txt")) {
+ unlink("GameEngine/Prevention/updatehero.txt");
+ }
+
+
+}
+
+ // by SlimShady95, aka Manuel Mannhardt < manuel_mannhardt@web.de > UPDATED FROM songeriux < haroldas.snei@gmail.com >
private function updateStore() {
global $bid10, $bid38, $bid11, $bid39;
-
- $result = mysql_query("SELECT * FROM `".TB_PREFIX."fdata` WHERE vref = '".$_SESSION['wid']."' LIMIT 1");
- $row = mysql_fetch_assoc($result);
- if ($row == null) { return; }
-
- $ress = $crop = 0;
-
- for ($i = 19; $i < 40; ++$i) {
- switch ($row['f' . $i . 't']) {
- case 10:
+
+ $result = mysql_query('SELECT * FROM `' . TB_PREFIX . 'fdata`');
+ while ($row = mysql_fetch_assoc($result))
+ {
+ $ress = $crop = 0;
+ for ($i = 19; $i < 40; ++$i)
+ {
+ if ($row['f' . $i . 't'] == 10)
+ {
$ress += $bid10[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER;
- break;
-
- case 11:
- $crop += $bid11[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER;
- break;
-
- case 38:
+ }
+
+ if ($row['f' . $i . 't'] == 38)
+ {
$ress += $bid38[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER;
- break;
-
- case 39:
+ }
+
+
+
+ if ($row['f' . $i . 't'] == 11)
+ {
+ $crop += $bid11[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER;
+ }
+
+ if ($row['f' . $i . 't'] == 39)
+ {
$crop += $bid39[$row['f' . $i]]['attri'] * STORAGE_MULTIPLIER;
- break;
+ }
}
+
+ if ($ress == 0)
+ {
+ $ress = 800 * STORAGE_MULTIPLIER;
+ }
+
+ if ($crop == 0)
+ {
+ $crop = 800 * STORAGE_MULTIPLIER;
+ }
+
+ mysql_query('UPDATE `' . TB_PREFIX . 'vdata` SET `maxstore` = ' . $ress . ', `maxcrop` = ' . $crop . ' WHERE `wref` = ' . $row['vref']) or die(mysql_error());
}
-
- if ($ress == 0) {
- $ress = 800 * STORAGE_MULTIPLIER;
- }
- if ($crop == 0) {
- $crop = 800 * STORAGE_MULTIPLIER;
- }
-
- mysql_query('UPDATE `' . TB_PREFIX . 'vdata` SET `maxstore` = ' . $ress . ', `maxcrop` = ' . $crop . ' WHERE `wref` = ' . $row['vref']) or die(mysql_error());
}
private function oasisResoucesProduce() {
@@ -3682,8 +3923,6 @@ private function checkInvitedPlayes() {
foreach($array as $user) {
$numusers = mysql_query("SELECT * FROM ".TB_PREFIX."users WHERE id = ".$user['invited']);
if(mysql_num_rows($numusers) > 0){
- $database->updateUserField($user['id'],"invited",0,1);
- }else{
$varray = count($database->getProfileVillages($user['id']));
if($varray > 1){
$usergold = $database->getUserField($user['invited'],"gold",0);
@@ -3764,7 +4003,12 @@ private function MasterBuilder() {
}
private function starvation() {
+ if(file_exists("GameEngine/Prevention/starvation.txt")) {
+ unlink("GameEngine/Prevention/starvation.txt");
+ }
global $database;
+ $ourFileHandle = fopen("GameEngine/Prevention/starvation.txt", 'w');
+ fclose($ourFileHandle);
$starvupkeep = array(
'1'=>1,
@@ -3918,9 +4162,16 @@ private function starvation() {
unset ($starv,$unitarrays,$enforcearray,$enforce,$starvarray);
}
+
+ if(file_exists("GameEngine/Prevention/starvation.txt")) {
+ unlink("GameEngine/Prevention/starvation.txt");
+ }
}
-
+
private function procClimbers() {
+ if(file_exists("GameEngine/Prevention/climbers.txt")) {
+ unlink("GameEngine/Prevention/climbers.txt");
+ }
global $database, $ranking;
$users = "SELECT * FROM " . TB_PREFIX . "users WHERE access < " . (INCLUDE_ADMIN ? "10" : "8") . "";
$array = $database->query_return($users);
@@ -3936,6 +4187,9 @@ private function procClimbers() {
}
foreach($array as $session){
$oldrank = $ranking->getUserRank($session['id']);
+ if($session['oldrank'] == 0){
+ $database->updateoldrank($session['id'], $oldrank);
+ }else{
if($week > 1){
if($session['oldrank'] > $oldrank) {
$totalpoints = $session['oldrank'] - $oldrank;
@@ -3954,6 +4208,7 @@ private function procClimbers() {
}
}
}
+ }
$alliance = $database->getARanking();
$ranking->procARankArray();
if(count($ranking->getRank()) > 0){
@@ -3963,6 +4218,9 @@ private function procClimbers() {
foreach($memberlist as $member) {
$oldrank += $database->getVSumField($member['id'],"pop");
}
+ if($ally['oldrank'] == 0){
+ $database->updateoldrankAlly($ally['id'], $oldrank);
+ }
if($ally['oldrank'] < $oldrank) {
$totalpoints = $oldrank - $ally['oldrank'];
$database->addclimberrankpopAlly($ally['id'], $totalpoints);
@@ -3975,6 +4233,9 @@ private function procClimbers() {
}
}
}
+ if(file_exists("GameEngine/Prevention/climbers.txt")) {
+ unlink("GameEngine/Prevention/climbers.txt");
+ }
}
private function checkBan() {
1,548 GameEngine/Battle.php
View
@@ -13,60 +13,58 @@
class Battle {
- public function procSim($post) {
- global $form;
- // Recivimos el formulario y procesamos
- if(isset($post['a1_v']) && (isset($post['a2_v1']) || isset($post['a2_v2']) || isset($post['a2_v3']) || isset($post['a2_v4']))) {
- $_POST['mytribe'] = $post['a1_v'];
- $target = array();
- if(isset($post['a2_v1'])) {
- array_push($target,1);
- }
- if(isset($post['a2_v2'])) {
- array_push($target,2);
- }
- if(isset($post['a2_v3'])) {
- array_push($target,3);
- }
- if(isset($post['a2_v4'])) {
- array_push($target,4);
- }
- if(isset($post['a2_v5'])) {
- array_push($target,5);
- }
- $_POST['target'] = $target;
- if(isset($post['a1_1'])) {
- $sum = $sum2 = 0;
- for($i=1;$i<=10;$i++) {
- $sum += $post['a1_'.$i];
+ public function procSim($post) {
+ global $form;
+ // Recivimos el formulario y procesamos
+ if(isset($post['a1_v']) && (isset($post['a2_v1']) || isset($post['a2_v2']) || isset($post['a2_v3']) || isset($post['a2_v4']))) {
+ $_POST['mytribe'] = $post['a1_v'];
+ $target = array();
+ if(isset($post['a2_v1'])) {
+ array_push($target,1);
+ }
+ if(isset($post['a2_v2'])) {
+ array_push($target,2);
+ }
+ if(isset($post['a2_v3'])) {
+ array_push($target,3);
+ }
+ if(isset($post['a2_v4'])) {
+ array_push($target,4);
+ }
+ if(isset($post['a2_v5'])) {
+ array_push($target,5);
}
- if($sum > 0) {
- if($post['palast'] == "") {
- $post['palast'] = 0;
- }
- if(isset($post['wall1']) && $post['wall1'] == "") {
- $post['wall1'] = 0;
- }
- if(isset($post['wall2']) && $post['wall2'] == "") {
- $post['wall2'] = 0;
- }
- if(isset($post['wall3']) && $post['wall3'] == "") {
- $post['wall3'] = 0;
- }
- if(isset($post['wall4']) && $post['wall4'] == "") {
- $post['wall4'] = 0;
- }
- if(isset($post['wall5']) && $post['wall5'] == "") {
- $post['wall5'] = 0;
- }
- $post['tribe'] = $target[0];
- $_POST['result'] = $this->simulate($post);
- $form->valuearray = $post;
+ $_POST['target'] = $target;
+ if(isset($post['a1_1'])) {
+ $sum = $sum2 = 0;
+ for($i=1;$i<=10;$i++) {
+ $sum += $post['a1_'.$i];
+ }
+ if($sum > 0) {
+ if($post['palast'] == "") {
+ $post['palast'] = 0;
+ }
+ if(isset($post['wall1']) && $post['wall1'] == "") {
+ $post['wall1'] = 0;
+ }
+ if(isset($post['wall2']) && $post['wall2'] == "") {
+ $post['wall2'] = 0;
+ }
+ if(isset($post['wall3']) && $post['wall3'] == "") {
+ $post['wall3'] = 0;
+ }if(isset($post['wall4']) && $post['wall4'] == "") {
+ $post['wall4'] = 0;
+ }if(isset($post['wall5']) && $post['wall5'] == "") {
+ $post['wall5'] = 0;
+ }
+ $post['tribe'] = $target[0];
+ $_POST['result'] = $this->simulate($post);
+ $form->valuearray = $post;
+ }
+ }
}
- }
}
- }
- private function getBattleHero($uid) {
+ private function getBattleHero($uid) {
global $database;
$heroarray = $database->getHero($uid);
$herodata = $GLOBALS["h".$heroarray[0]['unit']];
@@ -78,104 +76,103 @@ private function getBattleHero($uid) {
$h_db = 1 + 0.002 * $heroarray[0]['defencebonus'];
return array('heroid'=>$heroarray[0]['heroid'],'unit'=>$heroarray[0]['unit'],'atk'=>$h_atk,'di'=>$h_di,'dc'=>$h_dc,'ob'=>$h_ob,'db'=>$h_db,'health'=>$heroarray['health']);
- }
-
- private function simulate($post) {
- // Establecemos los arrays con las unidades del atacante y defensor
- $attacker = array('u1'=>0,'u2'=>0,'u3'=>0,'u4'=>0,'u5'=>0,'u6'=>0,'u7'=>0,'u8'=>0,'u9'=>0,'u10'=>0,'u11'=>0,'u12'=>0,'u13'=>0,'u14'=>0,'u15'=>0,'u16'=>0,'u17'=>0,'u18'=>0,'u19'=>0,'u20'=>0,'u21'=>0,'u22'=>0,'u23'=>0,'u24'=>0,'u25'=>0,'u26'=>0,'u27'=>0,'u28'=>0,'u29'=>0,'u30'=>0,'u31'=>0,'u32'=>0,'u33'=>0,'u34'=>0,'u35'=>0,'u36'=>0,'u37'=>0,'u38'=>0,'u39'=>0,'u40'=>0,'u41'=>0,'u42'=>0,'u43'=>0,'u44'=>0,'u45'=>0,'u46'=>0,'u47'=>0,'u48'=>0,'u49'=>0,'u50'=>0);
- $start = ($post['a1_v']-1)*10+1;
- $index = 1;
- for($i=$start;$i<=($start+9);$i++) {
- $attacker['u'.$i] = $post['a1_'.$index];
- if($index <=8) {
- ${att_ab.$index} = $post['f1_'.$index];
- }
- $index += 1;
- }
- $defender = array();
- for($i=1;$i<=50;$i++) {
- if(isset($post['a2_'.$i]) && $post['a2_'.$i] != "") {
- $defender['u'.$i] = $post['a2_'.$i];
- }
- else {
- $defender['u'.$i] = 0;
- }
}
- $deftribe = $post['tribe'];
- $wall = 0;
- switch($deftribe) {
- case 1:
- for($i=1;$i<=8;$i++) {
- ${def_ab.$i} = $post['f2_'.$i];
- }
- break;
- case 2:
- for($i=11;$i<=18;$i++) {
- ${def_ab.$i-10} = $post['f2_'.$i];
+
+ private function simulate($post) {
+ // Establecemos los arrays con las unidades del atacante y defensor
+ $attacker = array('u1'=>0,'u2'=>0,'u3'=>0,'u4'=>0,'u5'=>0,'u6'=>0,'u7'=>0,'u8'=>0,'u9'=>0,'u10'=>0,'u11'=>0,'u12'=>0,'u13'=>0,'u14'=>0,'u15'=>0,'u16'=>0,'u17'=>0,'u18'=>0,'u19'=>0,'u20'=>0,'u21'=>0,'u22'=>0,'u23'=>0,'u24'=>0,'u25'=>0,'u26'=>0,'u27'=>0,'u28'=>0,'u29'=>0,'u30'=>0,'u31'=>0,'u32'=>0,'u33'=>0,'u34'=>0,'u35'=>0,'u36'=>0,'u37'=>0,'u38'=>0,'u39'=>0,'u40'=>0,'u41'=>0,'u42'=>0,'u43'=>0,'u44'=>0,'u45'=>0,'u46'=>0,'u47'=>0,'u48'=>0,'u49'=>0,'u50'=>0);
+ $start = ($post['a1_v']-1)*10+1;
+ $index = 1;
+ for($i=$start;$i<=($start+9);$i++) {
+ $attacker['u'.$i] = $post['a1_'.$index];
+ if($index <=8) {
+ ${att_ab.$index} = $post['f1_'.$index];
+ }
+ $index += 1;
}
- break;
- case 3:
- for($i=21;$i<=28;$i++) {
- ${def_ab.$i-20} = $post['f2_'.$i];
+ $defender = array();
+ for($i=1;$i<=50;$i++) {
+ if(isset($post['a2_'.$i]) && $post['a2_'.$i] != "") {
+ $defender['u'.$i] = $post['a2_'.$i];
+ }
+ else {
+ $defender['u'.$i] = 0;
+ }
}
- break;
+ $deftribe = $post['tribe'];
+ $wall = 0;
+ switch($deftribe) {
+ case 1:
+ for($i=1;$i<=8;$i++) {
+ ${def_ab.$i} = $post['f2_'.$i];
+ }
+ break;
+ case 2:
+ for($i=11;$i<=18;$i++) {
+ ${def_ab.$i-10} = $post['f2_'.$i];
+ }
+ break;
+ case 3:
+ for($i=21;$i<=28;$i++) {
+ ${def_ab.$i-20} = $post['f2_'.$i];
+ }
+ break;
case 4:
- for($i=31;$i<=38;$i++) {
- ${def_ab.$i-30} = $post['f2_'.$i];
- }
- break;
+ for($i=31;$i<=38;$i++) {
+ ${def_ab.$i-30} = $post['f2_'.$i];
+ }
+ break;
case 5:
- for($i=41;$i<=48;$i++) {
- ${def_ab.$i-40} = $post['f2_'.$i];
+ for($i=41;$i<=48;$i++) {
+ ${def_ab.$i-40} = $post['f2_'.$i];
+ }
+ break;
+ }
+ if($post['kata'] == "") {
+ $post['kata'] = 0;
}
- break;
- }
- if($post['kata'] == "") {
- $post['kata'] = 0;
- }
- // check scout
+ // check scout
- $scout = 1;
- for($i=$start;$i<=($start+9);$i++) {
- if($i == 4 || $i == 14 || $i == 23 || $i == 44)
- {
- }
- else{
- if($attacker['u'.$i]>0) {
- $scout = 0;
- break;
+ $scout = 1;
+ for($i=$start;$i<=($start+9);$i++) {
+ if($i == 4 || $i == 14 || $i == 23 || $i == 44)
+ {}
+ else{
+ if($attacker['u'.$i]>0) {
+ $scout = 0;
+ break;
+ }
+ }
}
- }
- }
- if($post['wall1'] != 0){
- $walllevel = $post['wall1'];
- }elseif($post['wall2'] != 0){
- $walllevel = $post['wall2'];
- }elseif($post['wall3'] != 0){
- $walllevel = $post['wall3'];
- }elseif($post['wall4'] != 0){
- $walllevel = $post['wall4'];
- }elseif($post['wall5'] != 0){
- $walllevel = $post['wall5'];
- }else{
- $walllevel = 0;
- }
- if($walllevel > 20){
- $walllevel = 0;
+ if($post['wall1'] != 0){
+ $walllevel = $post['wall1'];
+ }elseif($post['wall2'] != 0){
+ $walllevel = $post['wall2'];
+ }elseif($post['wall3'] != 0){
+ $walllevel = $post['wall3'];
+ }elseif($post['wall4'] != 0){
+ $walllevel = $post['wall4'];
+ }elseif($post['wall5'] != 0){
+ $walllevel = $post['wall5'];
+ }else{
+ $walllevel = 0;
+ }
+ if($walllevel > 20){
+ $walllevel = 0;
+ }
+ $wall = $walllevel;
+ if(!$scout)
+ return $this->calculateBattle($attacker,$defender,$wall,$post['a1_v'],$deftribe,$post['palast'],$post['ew1'],$post['ew2'],$post['ktyp']+3,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$post['kata'],$post['stonemason'],$walllevel,0,0,0,0);
+ else
+ return $this->calculateBattle($attacker,$defender,$wall,$post['a1_v'],$deftribe,$post['palast'],$post['ew1'],$post['ew2'],1,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$post['kata'],$post['stonemason'],$walllevel,0,0,0,0);
}
- $wall = $walllevel;
- if(!$scout)
- return $this->calculateBattle($attacker,$defender,$wall,$post['a1_v'],$deftribe,$post['palast'],$post['ew1'],$post['ew2'],$post['ktyp']+3,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$post['kata'],$post['stonemason'],$walllevel,0,0,0,0);
- else
- return $this->calculateBattle($attacker,$defender,$wall,$post['a1_v'],$deftribe,$post['palast'],$post['ew1'],$post['ew2'],1,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$post['kata'],$post['stonemason'],$walllevel,0,0,0,0);
- }
- public function getTypeLevel($tid,$vid) {
+ public function getTypeLevel($tid,$vid) {
global $village,$database;
$keyholder = array();
- $resourcearray = $database->getResourceLevel($vid);
+ $resourcearray = $database->getResourceLevel($vid);
foreach(array_keys($resourcearray,$tid) as $key) {
if(strpos($key,'t')) {
@@ -192,7 +189,7 @@ public function getTypeLevel($tid,$vid) {
}
foreach ($temparray as $key => $val) {
if ($val == max($temparray))
- $target = $key;
+ $target = $key;
}
}
else {
@@ -218,135 +215,137 @@ public function getTypeLevel($tid,$vid) {
}
}
- //1 raid 0 normal
- function calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$residence,$attpop,$defpop,$type,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$tblevel,$stonemason,$walllevel,$AttackerID,$DefenderID,$AttackerWref,$DefenderWref) {
- global $bid34,$bid35,$database;
- // Define the array with the units
- $calvary = array(4,5,6,15,16,23,24,25,26,35,36,45,46);
- $catapult = array(8,18,28,38,48);
- $rams = array(7,17,27,37,47);
- $catp = $ram = 0;
- // Array to return the result of the calculation
- $result = array();
- $involve = 0;
- $winner = false;
- // 0 for all partial results
- $cap = $ap = $dp = $cdp = $rap = $rdp = 0;
+ //1 raid 0 normal
+ function calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$residence,$attpop,$defpop,$type,$def_ab1,$def_ab2,$def_ab3,$def_ab4,$def_ab5,$def_ab6,$def_ab7,$def_ab8,$att_ab1,$att_ab2,$att_ab3,$att_ab4,$att_ab5,$att_ab6,$att_ab7,$att_ab8,$tblevel,$stonemason,$walllevel,$AttackerID,$DefenderID,$AttackerWref,$DefenderWref) {
+ global $bid34,$bid35,$database;
+ // Definieer de array met de eenheden
+ $calvary = array(4,5,6,15,16,23,24,25,26,45,46);
+ $catapult = array(8,18,28,48);
+ $rams = array(7,17,27,47);
+ $catp = $ram = 0;
+ // Array om terug te keren met het resultaat van de berekening
+ $result = array();
+ $involve = 0;
+ $winner = false;
+ // bij 0 alle deelresultaten
+ $cap = $ap = $dp = $cdp = $rap = $rdp = 0;
//exit($type);
- $att_artefact = count($database->getOwnUniqueArtefactInfo2($AttackerID,3,3,0));
- $att_artefact1 = count($database->getOwnUniqueArtefactInfo2($AttackerWref,3,1,1));
- $att_artefact2 = count($database->getOwnUniqueArtefactInfo2($AttackerID,3,2,0));
- if($att_artefact > 0){
+ $att_artefact = count($database->getOwnUniqueArtefactInfo2($AttackerID,3,3,0));
+ $att_artefact1 = count($database->getOwnUniqueArtefactInfo2($AttackerWref,3,1,1));
+ $att_artefact2 = count($database->getOwnUniqueArtefactInfo2($AttackerID,3,2,0));
+ if($att_artefact > 0){
$attacker_artefact = 10;
- }else if($att_artefact1 > 0){
+ }else if($att_artefact1 > 0){
$attacker_artefact = 5;
- }else if($att_artefact2 > 0){
+ }else if($att_artefact2 > 0){
$attacker_artefact = 3;
- }else{
+ }else{
$attacker_artefact = 1;
- }
- $def_artefact = count($database->getOwnUniqueArtefactInfo2($DefenderID,3,3,0));
- $def_artefact1 = count($database->getOwnUniqueArtefactInfo2($DefenderWref,3,1,1));
- $def_artefact2 = count($database->getOwnUniqueArtefactInfo2($DefenderID,3,2,0));
- if($def_artefact > 0){
+ }
+ $def_artefact = count($database->getOwnUniqueArtefactInfo2($DefenderID,3,3,0));
+ $def_artefact1 = count($database->getOwnUniqueArtefactInfo2($DefenderWref,3,1,1));
+ $def_artefact2 = count($database->getOwnUniqueArtefactInfo2($DefenderID,3,2,0));
+ if($def_artefact > 0){
$defender_artefact = 10;
- }else if($att_artefact1 > 0){
+ }else if($att_artefact1 > 0){
$defender_artefact = 5;
- }else if($def_artefact2 > 0){
+ }else if($def_artefact2 > 0){
$defender_artefact = 3;
- }else{
+ }else{
$defender_artefact = 1;
- }
+ }
if($Attacker['uhero'] != 0)
{
//exit($AttackerID);
- $atkhero = $this->getBattleHero($AttackerID);
+ $atkhero = $this->getBattleHero($AttackerID);
}
if($Defender['hero'] != 0)
{
//exit($DefenderID);
- $defenderhero = $this->getBattleHero($DefenderID);
+ $defenderhero = $this->getBattleHero($DefenderID);
}
$DefendersAll = $database->getEnforceVillage($DefenderWref,0);
if(!empty($DefendersAll)){
- foreach($DefendersAll as $defenders) {
- $fromvillage = $defenders['from'];
- $reinfowner = $database->getVillageField($fromvillage,"owner");
- $defhero[$fromvillage] = $this->getBattleHero($reinfowner);
- }
+ foreach($DefendersAll as $defenders) {
+ $fromvillage = $defenders['from'];
+ $reinfowner = $database->getVillageField($fromvillage,"owner");
+ $defhero[$fromvillage] = $this->getBattleHero($reinfowner);
+ }
}
- // Calculate the total points of Attacker
+ // Berekenen het totaal aantal punten van Aanvaller
$start = ($att_tribe-1)*10+1;
$end = ($att_tribe*10);
if($att_tribe == 3){
- $abcount = 3;
+ $abcount = 3;
}else{
- $abcount = 4;
+ $abcount = 4;
}
+
+ if($type == 1)
+ {
+ for($i=$start;$i<=$end;$i++) {
+ global ${'u'.$i};
+ $j = $i-$start+1;
+ if($abcount <= 8 && ${att_ab.$abcount} > 0) {
+
+ $ap += (35 + ( 35 + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i] * $attacker_artefact;
+ $att_foolartefact = $database->getFoolArtefactInfo(3,$AttackerWref,$AttackerID);
+ if(count($att_foolartefact) > 0){
+ foreach($att_foolartefact as $arte){
+ if($arte['bad_effect'] == 1){
+ $ap *= $arte['effect2'];
+ }else{
+ $ap /= $arte['effect2'];
+ $ap = round($ap);
+ }
+ }
+ }
+ }
+ else {
+ $ap += ($Attacker['u'.$i] * $Attacker['u'.$i] * $Attacker['u'.$i])/3;
+ }
- if($type == 1)
- {
- for($i=$start;$i<=$end;$i++) {
- global ${'u'.$i};
- $j = $i-$start+1;
- if($abcount <= 8 && ${att_ab.$abcount} > 0) {
- $ap += (35 + ( 35 + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i] * $attacker_artefact;
- $att_foolartefact = $database->getFoolArtefactInfo(3,$AttackerWref,$AttackerID);
- if(count($att_foolartefact) > 0){
- foreach($att_foolartefact as $arte){
- if($arte['bad_effect'] == 1){
- $ap *= $arte['effect2'];
- }else{
- $ap /= $arte['effect2'];
- $ap = round($ap);
- }
- }
- }
- }
- else {
- $ap += ($Attacker['u'.$i] * $Attacker['u'.$i] * $Attacker['u'.$i])/3;
- }
- $units['Att_unit'][$i] = $Attacker['u'.$i];
- }
+ $units['Att_unit'][$i] = $Attacker['u'.$i];
+ }
if ($Attacker['uhero'] != 0){
- $ap += $atkhero['atk'] * 35;
- $ap = $ap * $atkhero['ob'];
+ $ap += $atkhero['atk'] * 35;
+ $ap = $ap * $atkhero['ob'];
}
- }
- else
- {
- $abcount = 1;
- for($i=$start;$i<=$end;$i++) {
- global ${'u'.$i};
- $j = $i-$start+1;
- if($abcount <= 8 && ${att_ab.$abcount} > 0) {
- if(in_array($i,$calvary)) {
- $cap += (${'u'.$i}['atk'] + (${'u'.$i}['atk'] + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i];
- }
- else {
- $ap += (${'u'.$i}['atk'] + (${'u'.$i}['atk'] + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i];
- }
- }
- else {
- if(in_array($i,$calvary)) {
- $cap += $Attacker['u'.$i]*${'u'.$i}['atk'];
- }
- else {
- $ap += $Attacker['u'.$i]*${'u'.$i}['atk'];
- }
}
+ else
+ {
+ $abcount = 1;
+ for($i=$start;$i<=$end;$i++) {
+ global ${'u'.$i};
+ $j = $i-$start+1;
+ if($abcount <= 8 && ${att_ab.$abcount} > 0) {
+ if(in_array($i,$calvary)) {
+ $cap += (${'u'.$i}['atk'] + (${'u'.$i}['atk'] + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i];
+ }
+ else {
+ $ap += (${'u'.$i}['atk'] + (${'u'.$i}['atk'] + 300 * ${'u'.$i}['pop'] / 7) * (pow(1.007, ${att_ab.$abcount}) - 1)) * $Attacker['u'.$i];
+ }
+ }
+ else {
+ if(in_array($i,$calvary)) {
+ $cap += $Attacker['u'.$i]*${'u'.$i}['atk'];
+ }
+ else {
+ $ap += $Attacker['u'.$i]*${'u'.$i}['atk'];
+ }
+ }
- $abcount +=1;
- // catapult attack
- if(in_array($i,$catapult)) {
- $catp += $Attacker['u'.$i];
- }
- // ram
+ $abcount +=1;
+ // Punten van de catavult van de aanvaller
+ if(in_array($i,$catapult)) {
+ $catp += $Attacker['u'.$i];
+ }
+ // Punten van de Rammen van de aanvaller
if(in_array($i,$rams))
{
$ram += $Attacker['u'.$i];
@@ -366,71 +365,76 @@ function calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$re
}
- //
- // Calculates the total points of the Defender
- //
+ //
+ // Berekent het totaal aantal punten van de Defender
+ //
$start = ($def_tribe-1)*10+1;
$end = ($def_tribe*10);
$abcount = 1;
- if($type == 1)
- {
- for($y=4;$y<=44;$y++) {
- if($y == 4 || $y == 14 || $y == 23 || $y == 44)
+ if($type == 1)
{
- global ${'u'.$y};
- if($y >= $start && $y <= ($end-2) && ${def_ab.$abcount} > 0) {
- $dp += (20 + (20 + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * (($Defender['u'.$y]*$Defender['u'.$y]*$Defender['u'.$y])/4) * $defender_artefact;
- $abcount +=1;
- $def_foolartefact = $database->getFoolArtefactInfo(3,$AttackerWref,$AttackerID);
- if(count($def_foolartefact) > 0){
- foreach($def_foolartefact as $arte){
- if($arte['bad_effect'] == 1){
+ for($y=4;$y<=44;$y++) {
+ if($y == 4 || $y == 14 || $y == 23)
+ {
+ global ${'u'.$y};
+ if($y >= $start && $y <= ($end-2) && ${def_ab.$abcount} > 0) {
+ $dp += (20 + (20 + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * (($Defender['u'.$y]*$Defender['u'.$y]*$Defender['u'.$y])/4) * $defender_artefact;
+ $abcount +=1;
+ $def_foolartefact = $database->getFoolArtefactInfo(3,$AttackerWref,$AttackerID);
+ if(count($def_foolartefact) > 0){
+ foreach($def_foolartefact as $arte){
+ if($arte['bad_effect'] == 1){
$dp *= $arte['effect2'];
- }else{
+ }else{
$dp /= $arte['effect2'];
$dp = round($dp);
- }
+ }
+ }
+ }
+ }
+ else {
+ $dp += ($Defender['u'.$y]*$Defender['u'.$y]*$Defender['u'.$y])/4;
+ }
+ $units['Def_unit'][$y] = $Defender['u'.$y];
+ if($units['Def_unit'][$y] > 0){
+ $detected = 1;
+ }
}
+ }
+ if($detected == 1){
+ if ($Defender['hero'] != 0){
+ $dp += $defenderhero['di'] * 35;
+ $dp = $dp * $defenderhero['db'];
}
- }
- else {
- $dp += ($Defender['u'.$y]*$Defender['u'.$y]*$Defender['u'.$y])/4;
- }
- $units['Def_unit'][$y] = $Defender['u'.$y];
- }
- }
- if ($Defender['hero'] != 0){
- $dp += $defenderhero['di'] * 35;
- $dp = $dp * $defenderhero['db'];
- }
- $DefendersAll = $database->getEnforceVillage($DefenderWref,0);
- if(!empty($DefendersAll)){
- foreach($DefendersAll as $defenders) {
- $fromvillage = $defenders['from'];
- $dp += $defhero[$fromvillage]['di'] * 35;
- $dp = $dp * $defhero[$fromvillage]['db'];
+ $DefendersAll = $database->getEnforceVillage($DefenderWref,0);
+ if(!empty($DefendersAll)){
+ foreach($DefendersAll as $defenders) {
+ $fromvillage = $defenders['from'];
+ $dp += $defhero[$fromvillage]['di'] * 35;
+ $dp = $dp * $defhero[$fromvillage]['db'];
+ }
+ }
+ }
}
- }
- }
- else
- {
- for($y=1;$y<=50;$y++) {
- global ${'u'.$y};
- if($y >= $start && $y <= ($end-2) && ${def_ab.$abcount} > 0) {
- $dp += (${'u'.$y}['di'] + (${'u'.$y}['di'] + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * $Defender['u'.$y];
- $cdp += (${'u'.$y}['dc'] + (${'u'.$y}['dc'] + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * $Defender['u'.$y];
- }
- else {
- $dp += $Defender['u'.$y]*${'u'.$y}['di'];
- $cdp += $Defender['u'.$y]*${'u'.$y}['dc'];
- }
- $involve += $Defender['u'.$y];
- $units['Def_unit'][$y] = $Defender['u'.$y];
- $abcount +=1;
- }
+ else
+ {
+ for($y=1;$y<=50;$y++) {
+ global ${'u'.$y};
+ if($y >= $start && $y <= ($end-2) && ${def_ab.$abcount} > 0) {
+ $dp += (${'u'.$y}['di'] + (${'u'.$y}['di'] + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * $Defender['u'.$y];
+ $cdp += (${'u'.$y}['dc'] + (${'u'.$y}['dc'] + 300 * ${'u'.$y}['pop'] / 7) * (pow(1.007, ${def_ab.$abcount}) - 1)) * $Defender['u'.$y];
+ }
+ else {
+ $dp += $Defender['u'.$y]*${'u'.$y}['di'];
+ $cdp += $Defender['u'.$y]*${'u'.$y}['dc'];
+ }
+ $involve += $Defender['u'.$y];
+ $units['Def_unit'][$y] = $Defender['u'.$y];
+ $abcount +=1;
+ }
if($Defender['hero'] != 0)
{
$units['Def_unit']['hero'] = $Defender['hero'];
@@ -441,160 +445,156 @@ function calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$re
}
$DefendersAll = $database->getEnforceVillage($DefenderWref,0);
if(!empty($DefendersAll)){
- foreach($DefendersAll as $defenders) {
- $fromvillage = $defenders['from'];
- $cdp += $defhero[$fromvillage]['dc'];
- $dp += $defhero[$fromvillage]['di'];
- $dp = $dp * $defhero[$fromvillage]['db'];
- $cdp = $cdp * $defhero[$fromvillage]['db'];
- }
+ foreach($DefendersAll as $defenders) {
+ $fromvillage = $defenders['from'];
+ $cdp += $defhero[$fromvillage]['dc'];
+ $dp += $defhero[$fromvillage]['di'];
+ $dp = $dp * $defhero[$fromvillage]['db'];
+ $cdp = $cdp * $defhero[$fromvillage]['db'];
}
- }
-
- //
- // Formula for calculating the bonus defense wall and Residence
- //
- if($def_wall > 0) {
- // Set the factor for calculating the "Wall" as the type of civilization
- // Factor = 1030 Roman wall
- // Factor = 1020 German wall
- // Factor = 1025 Gallic Wall
- $factor = ($def_tribe == 1)? 1.030 : (($def_tribe == 2)? 1.020 : 1.025);
- // Defense Infantry = Infantry * Wall (%)
- $dp *= pow($factor,$def_wall);
- // Defense Cavalry = Cavalry * Wall (%)
- $cdp *= pow($factor,$def_wall);
-
- // Calculation of the Basic defense bonus "Residence"
- $dp += ((2*(pow($residence,2)))*(pow($factor,$def_wall)));
- $cdp += ((2*(pow($residence,2)))*(pow($factor,$def_wall)));
- }
- else
- {
- // Calculation of the Basic defense bonus "Residence"
- $dp += (2*(pow($residence,2)));
- $cdp += (2*(pow($residence,2)));
- }
-
- //
- // Formula for calculating points attackers (Infantry & Cavalry)
- //
- if($AttackerWref != 0){
- $rap = ($ap+$cap)+(($ap+$cap)/100*$bid35[$this->getTypeLevel(35,$AttackerWref)]['attri']);
- }else{
- $rap = $ap+$cap;
- }
- //
- // Formula for calculating Defensive Points
- //
- if ($rap==0)
- $rdp = ($dp) + ($cdp) + 10;
- else
- $rdp = ($dp * ($ap/$rap)) + ($cdp * ($cap/$rap)) + 10;
- //
- // And the Winner is ....:
- //
- $result['Attack_points'] = $rap;
- $result['Defend_points'] = $rdp;
-
- $winner = ($rap > $rdp);
-
- $result['Winner'] = ($winner)? "attacker" : "defender";
-
- // Formula for calculating the Moral
- if($attpop > $defpop) {
- if ($rap < $rdp) {
- $moralbonus = min(1.5, pow($attpop / $defpop, (0.2*($rap/$rdp))));
}
- else {
- if($defpop==0){
- $moralbonus = min(1.5, pow($attpop, 0.2));
+ }
+
+ //
+ // Formule voor de berekening van de bonus verdedigingsmuur "en" Residence ";
+ //
+ if($def_wall > 0) {
+ // Stel de factor berekening voor de "Muur" als het type van de beschaving
+ // Factor = 1030 Romeinse muur
+ // Factor = 1020 Wall Germanen
+ // Factor = 1025 Wall Galliers
+ $factor = ($def_tribe == 1)? 1.030 : (($def_tribe == 2)? 1.020 : 1.025);
+ // Verdediging infantery = Infantery * Muur (%)
+ $dp *= pow($factor,$def_wall);
+ // Verdediging Cavelerie = Cavelerie * Muur (%)
+ $cdp *= pow($factor,$def_wall);
+
+ // Berekening van de Basic defence bonus "Residence"
+ $dp += ((2*(pow($residence,2)))*(pow($factor,$def_wall)));
+ $cdp += ((2*(pow($residence,2)))*(pow($factor,$def_wall)));
+ }
+ else
+ {
+ // Berekening van de Basic defence bonus "Residence"
+ $dp += (2*(pow($residence,2)));
+ $cdp += (2*(pow($residence,2)));
+ }
+
+ //
+ // Formule voor het berekenen van punten aanvallers (Infanterie & Cavalry)
+ //
+ if($AttackerWref != 0){
+ $rap = ($ap+$cap)+(($ap+$cap)/100*$bid35[$this->getTypeLevel(35,$AttackerWref)]['attri']);
}else{
- $moralbonus = min(1.5, pow($attpop / $defpop, 0.2));
+ $rap = $ap+$cap;
}
- }
- }
- else {
- $moralbonus = 1.0;
- }
+ //
+ // Formule voor de berekening van Defensive Punten
+ //
+ if ($rap==0)
+ $rdp = ($dp) + ($cdp) + 10;
+ else
+ $rdp = ($dp * ($ap/$rap)) + ($cdp * ($cap/$rap)) + 10;
+ //
+ // En de Winnaar is....:
+ //
+ $result['Attack_points'] = $rap;
+ $result['Defend_points'] = $rdp;
- if($involve >= 1000) {
- $Mfactor = round(2*(1.8592-pow($involve,0.015)),4);
- }
- else {
- $Mfactor = 1.5;
- }
- if ($Mfactor < 1.25778){
- $Mfactor=1.25778;
- }elseif ($Mfactor > 1.5){
- $Mfactor=1.5;
- }
- // Formula for calculating lost units
- // $type = 1 Raid, 0 Normal<