mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-12 07:36:07 +00:00
Distance calculation optimization and bug fixing
-Removed a lot of redundant code and put into a function +Fixed a bug that permitted to found a new village in already founded village +Fixed a bug that permitted to found in an oasis +Fixed a bug that permitted to hack the time you need to found a new village +Fixed a bug that permitted to found a new village to an inexistent one
This commit is contained in:
+26
-147
@@ -343,7 +343,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function clearDeleting() {
|
||||
global $autoprefix;
|
||||
global $autoprefix, $units;
|
||||
if(file_exists($autoprefix."GameEngine/Prevention/cleardeleting.txt")) {
|
||||
unlink($autoprefix."GameEngine/Prevention/cleardeleting.txt");
|
||||
}
|
||||
@@ -435,10 +435,9 @@ class Automation {
|
||||
|
||||
foreach($enforcement as $enforce) {
|
||||
$time = microtime(true);
|
||||
$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);
|
||||
$targetOwner = $database->getVillageField($enforce['from'], "owner");
|
||||
$targettribe = $database->getUserField($targetOwner, "tribe", 0);
|
||||
$time2 = $units->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $targetOwner, $targettribe, $enforce, 1);
|
||||
$start = 10*($targettribe-1);
|
||||
for($i=1;$i<11;$i++){
|
||||
$unit = $start + $i;
|
||||
@@ -942,7 +941,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function marketComplete() {
|
||||
global $database, $autoprefix;
|
||||
global $database, $autoprefix, $units;
|
||||
if(file_exists($autoprefix."GameEngine/Prevention/market.txt")) {
|
||||
unlink($autoprefix."GameEngine/Prevention/market.txt");
|
||||
}
|
||||
@@ -972,10 +971,8 @@ class Automation {
|
||||
$database->addNotice($from['owner'],$to['wref'],$ownally,$sort_type,''.addslashes($from['name']).' send resources to '.addslashes($to['name']).'',''.$from['owner'].','.$from['wref'].','.$data['wood'].','.$data['clay'].','.$data['iron'].','.$data['crop'].'',$data['endtime']);
|
||||
}
|
||||
$database->modifyResource($data['to'],$data['wood'],$data['clay'],$data['iron'],$data['crop'],1);
|
||||
$tocoor = $database->getCoor($data['from']);
|
||||
$fromcoor = $database->getCoor($data['to']);
|
||||
$targettribe = $userData_to["tribe"];
|
||||
$endtime = $this->procDistanceTime($tocoor,$fromcoor,$targettribe,0) + $data['endtime'];
|
||||
$endtime = $units->getWalkingTroopsTime($data['from'], $data['to'], 0, 0, [$targettribe], 0) + $data['endtime'];
|
||||
$database->addMovement(2,$data['to'],$data['from'],$data['merchant'],time(),$endtime,$data['send'],$data['wood'],$data['clay'],$data['iron'],$data['crop']);
|
||||
$database->setMovementProc($data['moveid']);
|
||||
}
|
||||
@@ -1006,7 +1003,7 @@ class Automation {
|
||||
}
|
||||
|
||||
private function sendResource2($wtrans, $ctrans, $itrans, $crtrans, $from, $to, $tribe, $send) {
|
||||
global $bid17,$bid28,$database,$generator,$logging;
|
||||
global $bid17, $bid28, $database, $units;
|
||||
|
||||
$availableWood = $database->getWoodAvailable($from);
|
||||
$availableClay = $database->getClayAvailable($from);
|
||||
@@ -1033,12 +1030,9 @@ class Automation {
|
||||
$resource = array($wtrans,$ctrans,$itrans,$crtrans);
|
||||
$reqMerc = ceil((array_sum($resource)-0.1)/$maxcarry2);
|
||||
|
||||
if($merchantAvail2 != 0 && $reqMerc <= $merchantAvail2) {
|
||||
$coor = $database->getCoor($to);
|
||||
$coor2 = $database->getCoor($from);
|
||||
|
||||
if($merchantAvail2 != 0 && $reqMerc <= $merchantAvail2) {
|
||||
if($database->getVillageState($to)) {
|
||||
$timetaken = $generator->procDistanceTime($coor,$coor2,$tribe,0);
|
||||
$timetaken = $units->getWalkingTroopsTime($from, $to, 0, 0, [$tribe], 0);
|
||||
$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
|
||||
if($res!=0){
|
||||
$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
|
||||
@@ -1587,7 +1581,7 @@ class Automation {
|
||||
//impossible to attack or scout NATAR Capital Village
|
||||
if ($NatarCapital)
|
||||
{
|
||||
for($i=1;$i<=11;$i++) ${'traped'.$i} = $data['t'.$i];
|
||||
for($i = 1; $i <= 11; $i++) ${'traped'.$i} = $data['t'.$i];
|
||||
}
|
||||
elseif(empty($scout))
|
||||
{
|
||||
@@ -1757,7 +1751,7 @@ class Automation {
|
||||
if (isset($battlepart['casualties_attacker']) && isset($battlepart['casualties_attacker'][$i]) && $battlepart['casualties_attacker'][$i] <= 0) {
|
||||
${'dead'.$i} = 0;
|
||||
} else if (isset($data['t'.$i]) && isset($battlepart['casualties_attacker']) && isset($battlepart['casualties_attacker'][$i]) && $battlepart['casualties_attacker'][$i] > $data['t'.$i]) {
|
||||
${'dead'.$i}=$data['t'.$i];
|
||||
${'dead'.$i} = $data['t'.$i];
|
||||
} else {
|
||||
${'dead'.$i} = (isset($battlepart['casualties_attacker']) && isset($battlepart['casualties_attacker'][$i]) ? $battlepart['casualties_attacker'][$i] : 0);
|
||||
}
|
||||
@@ -2178,48 +2172,20 @@ class Automation {
|
||||
}
|
||||
}
|
||||
|
||||
//work out time of return
|
||||
$start = ($owntribe-1)*10+1;
|
||||
$end = ($owntribe*10);
|
||||
|
||||
$unitspeeds = array(6,5,7,16,14,10,4,3,4,5,
|
||||
7,7,6,9,10,9,4,3,4,5,
|
||||
7,6,17,19,16,13,4,3,4,5,
|
||||
7,7,6,9,10,9,4,3,4,5,
|
||||
7,7,6,9,10,9,4,3,4,5);
|
||||
|
||||
$speeds = array();
|
||||
|
||||
//find slowest unit.
|
||||
for($i=1;$i<=10;$i++)
|
||||
{
|
||||
if ($data['t'.$i] > $battlepart['casualties_attacker'][$i]) {
|
||||
if($unitarray) { reset($unitarray); }
|
||||
$unitarray = $GLOBALS["u".(($owntribe-1)*10+$i)];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
}
|
||||
}
|
||||
if ($herosend_att>0){
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit');
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
}
|
||||
|
||||
// Data for when troops return.
|
||||
|
||||
//catapults look :D
|
||||
$info_cat = $info_chief = $info_ram = $info_hero = ",";
|
||||
//check to see if can destroy village
|
||||
if (count($varray) != 1 && $to['capital'] != 1 && !$database->villageHasArtefact($DefenderWref)) {
|
||||
$can_destroy=1;
|
||||
} else {
|
||||
$can_destroy=0;
|
||||
$can_destroy = 1;
|
||||
}
|
||||
else $can_destroy = 0;
|
||||
|
||||
if($isoasis == 0)
|
||||
{
|
||||
if ($type=='3')
|
||||
if ($type == 3)
|
||||
{
|
||||
if (($data['t7']-$traped7)>0){
|
||||
if (($data['t7'] - $traped7) > 0){
|
||||
$newLevel = $battle->CalculateNewBuildingLevel($battlepart['rams']['moral'], $battlepart['rams']['updown'], $walllevel, $battlepart['rams']['realAttackers'], $data['t7']);
|
||||
if (isset($empty)){
|
||||
$info_ram = "".$ram_pic.",There is no wall to destroy.";
|
||||
@@ -2241,11 +2207,8 @@ class Automation {
|
||||
|
||||
// village has been destroyed
|
||||
if ($pop <= 0) {
|
||||
if ($can_destroy==1) {
|
||||
$info_cat = "".$catp_pic.", Village already destroyed.";
|
||||
} else {
|
||||
$info_cat = "".$catp_pic.", Village can\'t be destroyed.";
|
||||
}
|
||||
if ($can_destroy == 1) $info_cat = "".$catp_pic.", Village already destroyed.";
|
||||
else $info_cat = "".$catp_pic.", Village can\'t be destroyed.";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2395,7 +2358,7 @@ class Automation {
|
||||
|
||||
//chiefing village
|
||||
//there are senators
|
||||
if(($data['t9']-$dead9-$traped9)>0 && $isoasis==0){
|
||||
if(($data['t9']- $dead9- $traped9) > 0 && $isoasis == 0){
|
||||
if ($type=='3') {
|
||||
|
||||
$palacelevel = $database->getResourceLevel($from['wref']);
|
||||
@@ -2601,7 +2564,7 @@ class Automation {
|
||||
$database->setVillageField($data['from'],$exp,$value);
|
||||
|
||||
//remove oasis related to village
|
||||
$units->returnTroops($data['to'],1);
|
||||
$units->returnTroops($data['to'], 1);
|
||||
$chiefing_village = 1;
|
||||
|
||||
//Remove trade routes related to village
|
||||
@@ -2791,33 +2754,9 @@ class Automation {
|
||||
$neutral = ($neutralarray[0]['alli1'] > 0 && $neutralarray[0]['alli2'] > 0 && $p_alliance > 0) && ($neutralarray[0]['alli1'] == $ownally || $neutralarray[0]['alli2'] == $ownally) && ($ownally != $p_alliance && $ownally && $p_alliance);
|
||||
|
||||
if($p_alliance == $ownally || $friend || $neutral){
|
||||
$p_tribe = $database->getUserField($p_owner,"tribe",0);
|
||||
$p_tribe = $database->getUserField($p_owner, "tribe", 0);
|
||||
|
||||
$p_eigen = $database->getCoor($prisoner['wref']);
|
||||
$p_from = array('x'=>$p_eigen['x'], 'y'=>$p_eigen['y']);
|
||||
$p_ander = $database->getCoor($prisoner['from']);
|
||||
$p_to = array('x'=>$p_ander['x'], 'y'=>$p_ander['y']);
|
||||
$p_tribe = $database->getUserField($p_owner,"tribe",0);
|
||||
|
||||
$p_speeds = array();
|
||||
|
||||
//find slowest unit.
|
||||
for($i = 1; $i <= 10; $i++){
|
||||
if ($prisoner['t'.$i]){
|
||||
if(!empty($prisoner['t'.$i]) && $prisoner['t'.$i] > 0){
|
||||
if($p_unitarray) { reset($p_unitarray); }
|
||||
$p_unitarray = $GLOBALS["u".(($p_tribe-1)*10+$i)];
|
||||
$p_speeds[] = $p_unitarray['speed'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($prisoner['t11'] > 0){
|
||||
$p_hero_unit = $database->getHeroField($p_owner, 'unit');
|
||||
$p_speeds[] = $GLOBALS['u'.$p_hero_unit]['speed'];
|
||||
}
|
||||
|
||||
$troopsTime = $this->procDistanceTime($p_to, $p_from, min($p_speeds), 1);
|
||||
$troopsTime = $units->getWalkingTroopsTime($prisoner['from'], $prisoner['wref'], $p_owner, $p_tribe, $prisoner, 1, 't');
|
||||
$p_time = $database->getArtifactsValueInfluence($p_owner, $prisoner['from'], 2, $troopsTime);
|
||||
|
||||
$p_reference = $database->addAttack($prisoner['from'],$prisoner['t1'],$prisoner['t2'],$prisoner['t3'],$prisoner['t4'],$prisoner['t5'],$prisoner['t6'],$prisoner['t7'],$prisoner['t8'],$prisoner['t9'],$prisoner['t10'],$prisoner['t11'],3,0,0,0,0,0,0,0,0,0,0,0);
|
||||
@@ -2880,7 +2819,9 @@ class Automation {
|
||||
// If the dead units not equal the ammount sent they will return and report
|
||||
if($totalsend_att - ($totaldead_att + (isset($totaltraped_att) ? $totaltraped_att : 0)) > 0)
|
||||
{
|
||||
$troopsTime = $this->procDistanceTime($from, $to, min($speeds), 1);
|
||||
$returningTroops = [];
|
||||
for($i = 1; $i <= 11; $i++) $returningTroops['t'.$i] = $data['t'.$i] - ${'traped'.$i} - ${'dead'.$i};
|
||||
$troopsTime = $units->getWalkingTroopsTime($from['wref'], $to['wref'], $from['owner'], $owntribe, $returningTroops, 1, 't');
|
||||
$endtime = $database->getArtifactsValueInfluence($from['owner'], $from['wref'], 2, $troopsTime);
|
||||
$endtime += $AttackArrivalTime;
|
||||
if($type == 1) {
|
||||
@@ -2960,25 +2901,8 @@ class Automation {
|
||||
$unitssend_att1 = ''.$data['t1'].','.$data['t2'].','.$data['t3'].','.$data['t4'].','.$data['t5'].','.$data['t6'].','.$data['t7'].','.$data['t8'].','.$data['t9'].','.$data['t10'].'';
|
||||
$herosend_att = $data['t11'];
|
||||
$unitssend_att= $unitssend_att1.','.$herosend_att;
|
||||
|
||||
$speeds = [];
|
||||
|
||||
//find slowest unit.
|
||||
//TODO: Needs to be made as a function
|
||||
for($i = 1; $i <= 10; $i++)
|
||||
{
|
||||
if ($data['t'.$i] > 0) {
|
||||
$unitarray = $GLOBALS["u".(($owntribe-1)*10+$i)];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($herosend_att > 0){
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit');
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
}
|
||||
|
||||
$troopsTime = $this->procDistanceTime($from, $to, min($speeds), 1);
|
||||
|
||||
$troopsTime = $units->getWalkingTroopsTime($from['wref'], $to['wref'], $from['owner'], $owntribe, $data, 1, 't');
|
||||
$endtime = $database->getArtifactsValueInfluence($from['owner'], $from['wref'], 2, $troopsTime);
|
||||
$endtime += $AttackArrivalTime;
|
||||
|
||||
@@ -4209,51 +4133,6 @@ class Automation {
|
||||
}
|
||||
}
|
||||
|
||||
public function procDistanceTime($coor,$thiscoor,$ref,$mode) {
|
||||
global $bid14,$database,$generator;
|
||||
$resarray = $database->getResourceLevel($generator->getBaseID($coor['x'],$coor['y']));
|
||||
$xdistance = ABS($thiscoor['x'] - $coor['x']);
|
||||
if($xdistance > WORLD_MAX) {
|
||||
$xdistance = (2*WORLD_MAX+1) - $xdistance;
|
||||
}
|
||||
$ydistance = ABS($thiscoor['y'] - $coor['y']);
|
||||
if($ydistance > WORLD_MAX) {
|
||||
$ydistance = (2*WORLD_MAX+1) - $ydistance;
|
||||
}
|
||||
$distance = SQRT(POW($xdistance,2)+POW($ydistance,2));
|
||||
if(!$mode) {
|
||||
if($ref == 1) {
|
||||
$speed = 16;
|
||||
}
|
||||
else if($ref == 2) {
|
||||
$speed = 12;
|
||||
}
|
||||
else if($ref == 3) {
|
||||
$speed = 24;
|
||||
}
|
||||
else if($ref == 300) {
|
||||
$speed = 5;
|
||||
}
|
||||
else {
|
||||
$speed = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$speed = $ref;
|
||||
if($this->getsort_typeLevel(14,$resarray) != 0 && $distance >= TS_THRESHOLD) {
|
||||
$speed = $speed * ($bid14[$this->getsort_typeLevel(14,$resarray)]['attri']/100) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($speed!=0){
|
||||
return round(($distance/$speed) * 3600 / INCREASE_SPEED);
|
||||
}else{
|
||||
return round($distance * 3600 / INCREASE_SPEED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getsort_typeLevel($tid,$resarray) {
|
||||
global $village;
|
||||
|
||||
|
||||
+13
-26
@@ -35,8 +35,8 @@ class MyGenerator {
|
||||
return substr($encode,0,$length);
|
||||
}
|
||||
|
||||
public function procDistanceTime($coor,$thiscoor,$ref,$mode) {
|
||||
global $bid28,$bid14,$building;
|
||||
public function procDistanceTime($coor, $thiscoor, $ref, $mode) {
|
||||
global $bid28, $bid14, $building;
|
||||
$xdistance = ABS($thiscoor['x'] - $coor['x']);
|
||||
if($xdistance > WORLD_MAX) {
|
||||
$xdistance = (2 * WORLD_MAX + 1) - $xdistance;
|
||||
@@ -46,34 +46,21 @@ class MyGenerator {
|
||||
$ydistance = (2 * WORLD_MAX + 1) - $ydistance;
|
||||
}
|
||||
$distance = SQRT(POW($xdistance,2)+POW($ydistance,2));
|
||||
if(!$mode) {
|
||||
if($ref == 1) {
|
||||
$speed = 16;
|
||||
}
|
||||
else if($ref == 2) {
|
||||
$speed = 12;
|
||||
}
|
||||
else if($ref == 3) {
|
||||
$speed = 24;
|
||||
}
|
||||
else if($ref == 300) {
|
||||
$speed = 5;
|
||||
}
|
||||
else {
|
||||
$speed = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(!$mode){
|
||||
if($ref == 1) $speed = 16;
|
||||
else if($ref == 2) $speed = 12;
|
||||
else if($ref == 3) $speed = 24;
|
||||
else if($ref == 300) $speed = 5;
|
||||
else $speed = 1;
|
||||
}else{
|
||||
$speed = $ref;
|
||||
if($building->getTypeLevel(14) != 0 && $distance >= TS_THRESHOLD) {
|
||||
$speed = $speed * ($bid14[$building->gettypeLevel(14)]['attri']/100) ;
|
||||
$speed *= ($bid14[$building->gettypeLevel(14)]['attri'] / 100) ;
|
||||
}
|
||||
}
|
||||
if($speed!=0){
|
||||
return round(($distance/$speed) * 3600 / INCREASE_SPEED);
|
||||
}else{
|
||||
return round($distance * 3600 / INCREASE_SPEED);
|
||||
}
|
||||
|
||||
if($speed != 0) return round(($distance / $speed) * 3600 / INCREASE_SPEED);
|
||||
else return round($distance * 3600 / INCREASE_SPEED);
|
||||
}
|
||||
|
||||
public function getTimeFormat($time) {
|
||||
|
||||
@@ -123,7 +123,7 @@ class Market
|
||||
$coor = $database->getCoor($id);
|
||||
if($database->getVillageState($id))
|
||||
{
|
||||
$timetaken = $generator->procDistanceTime($coor,$village->coor,$session->tribe,0);
|
||||
$timetaken = $generator->procDistanceTime($coor, $village->coor, $session->tribe, 0);
|
||||
$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
|
||||
if($res!=0)
|
||||
{
|
||||
@@ -308,7 +308,7 @@ class Market
|
||||
foreach($displayarray as $value)
|
||||
{
|
||||
$targetcoor = $database->getCoor($value['vref']);
|
||||
$duration = $generator->procDistanceTime($targetcoor,$village->coor,$session->tribe,0);
|
||||
$duration = $generator->procDistanceTime($targetcoor, $village->coor, $session->tribe, 0);
|
||||
if($duration <= ($value['maxtime'] * 3600) || $value['maxtime'] == 0)
|
||||
{
|
||||
$value['duration'] = $duration;
|
||||
|
||||
+108
-148
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Database\IDbConnection;
|
||||
|
||||
#################################################################################
|
||||
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
||||
## --------------------------------------------------------------------------- ##
|
||||
@@ -67,7 +69,7 @@ class Units {
|
||||
}
|
||||
|
||||
case "5":
|
||||
if (isset($post['a'])&& $post['a']== "new"){
|
||||
if (isset($post['a']) && $post['a']== "new"){
|
||||
$this->Settlers($post);
|
||||
}else{
|
||||
$post = $this->loadUnits($post);
|
||||
@@ -217,7 +219,7 @@ class Units {
|
||||
// another variable that will define the flag is raised and is being sent and the type of shipping
|
||||
$villageName = $database->getVillageField($id,'name');
|
||||
$speed= 300;
|
||||
$timetaken = $generator->procDistanceTime($coor,$village->coor,INCREASE_SPEED,1);
|
||||
$timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1);
|
||||
array_push($post, "$id", "$villageName", "$villageOwner","$timetaken");
|
||||
return $post;
|
||||
|
||||
@@ -232,7 +234,7 @@ class Units {
|
||||
} else if (isset($id)) {
|
||||
$villageName = $database->getOasisField($id,"name");
|
||||
$speed= 300;
|
||||
$timetaken = $generator->procDistanceTime($coor,$village->coor,INCREASE_SPEED,1);
|
||||
$timetaken = $generator->procDistanceTime($coor, $village->coor, INCREASE_SPEED, 1);
|
||||
array_push($post, "$id", "$villageName", "2","$timetaken");
|
||||
return $post;
|
||||
|
||||
@@ -241,7 +243,7 @@ class Units {
|
||||
|
||||
}
|
||||
|
||||
public function returnTroops($wref,$mode=0) {
|
||||
public function returnTroops($wref, $mode = 0) {
|
||||
global $database;
|
||||
if (!$mode) {
|
||||
$getenforce=$database->getEnforceVillage($wref,0);
|
||||
@@ -263,38 +265,9 @@ class Units {
|
||||
private function processReturnTroops($enforce) {
|
||||
global $database, $generator;
|
||||
$to = $database->getVillage($enforce['from']);
|
||||
$Gtribe = ($tribe = $database->getUserField($to['owner'], 'tribe',0)) == 1 ? "" : $tribe - 1;
|
||||
|
||||
$start = ($database->getUserField($to['owner'], 'tribe', 0) - 1) * 10 + 1;
|
||||
$end = ($database->getUserField($to['owner'] ,'tribe', 0) * 10);
|
||||
|
||||
$from = $database->getVillage($enforce['from']);
|
||||
$fromcoor = $database->getCoor($enforce['from']);
|
||||
$tocoor = $database->getCoor($enforce['vref']);
|
||||
$fromCor = ['x' => $tocoor['x'], 'y' => $tocoor['y']];
|
||||
$toCor = ['x' => $fromcoor['x'], 'y' => $fromcoor['y']];
|
||||
|
||||
$speeds = [];
|
||||
|
||||
//find slowest unit.
|
||||
for($i = $start; $i <= $end; $i++){
|
||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||
|
||||
if(intval($enforce['u'.$i]) > 0){
|
||||
if($unitarray) { reset($unitarray); }
|
||||
$unitarray = $GLOBALS["u".$i];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
}else{
|
||||
$enforce['u'.$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(intval($enforce['hero']) > 0){
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit');
|
||||
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
|
||||
}
|
||||
else $enforce['hero'] = 0;
|
||||
|
||||
$troopsTime = $generator->procDistanceTime($fromCor, $toCor, min($speeds), $enforce['from']);
|
||||
$troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $enforce, 1);
|
||||
$time = $database->getArtifactsValueInfluence($from['owner'], $enforce['from'], 2, $troopsTime);
|
||||
|
||||
$reference = $database->addAttack($enforce['from'], $enforce['u'.$start], $enforce['u'.($start + 1)], $enforce['u'.($start + 2)], $enforce['u'.($start + 3)], $enforce['u'.($start + 4)], $enforce['u'.($start + 5)], $enforce['u'.($start + 6)], $enforce['u'.($start + 7)], $enforce['u'.($start + 8)], $enforce['u'.($start + 9)], $enforce['hero'], 2, 0, 0, 0, 0);
|
||||
@@ -345,7 +318,7 @@ class Units {
|
||||
|
||||
$database->modifyUnit(
|
||||
$village->wid,
|
||||
array(
|
||||
[
|
||||
$u . "1",
|
||||
$u . "2",
|
||||
$u . "3",
|
||||
@@ -357,8 +330,8 @@ class Units {
|
||||
$u . "9",
|
||||
$u . $session->tribe . "0",
|
||||
"hero"
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
$data['u1'],
|
||||
$data['u2'],
|
||||
$data['u3'],
|
||||
@@ -370,37 +343,11 @@ class Units {
|
||||
$data['u9'],
|
||||
$data['u10'],
|
||||
$data['u11']
|
||||
),
|
||||
array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
);
|
||||
|
||||
$fromcoor = $database->getCoor( $village->wid );
|
||||
$from = ['x' => $fromcoor['x'], 'y' => $fromcoor['y']];
|
||||
$tocoor = $database->getCoor( $data['to_vid'] );
|
||||
$to = ['x' => $tocoor['x'], 'y' => $tocoor['y']];
|
||||
$speeds = [];
|
||||
|
||||
//find slowest unit.
|
||||
for ($i = 1; $i <= 10; $i ++) {
|
||||
if (isset( $data['u'.$i] ) ) {
|
||||
if (!empty($data['u'.$i]) && $data['u'.$i] > 0) {
|
||||
if ($unitarray) {
|
||||
reset($unitarray);
|
||||
}
|
||||
$unitarray = $GLOBALS["u".(($session->tribe - 1) * 10 + $i)];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($data['u11'])) {
|
||||
if (!empty($data['u11']) && $data['u11'] > 0) {
|
||||
$heroarray = $database->getHero( $session->uid);
|
||||
$herodata = $GLOBALS['u'.$heroarray[0]['unit']];
|
||||
$speeds[] = $herodata['speed'];
|
||||
}
|
||||
}
|
||||
|
||||
$troopsTime = $generator->procDistanceTime($from, $to, min($speeds), 1);
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
// Check if have WW owner have artefact Rivals great confusion or Artefact of the unique fool with that effect
|
||||
@@ -510,12 +457,12 @@ class Units {
|
||||
if ( isset( $post[ 't' . $i ] ) ) {
|
||||
if ( $i != 10 ) {
|
||||
if ( $post[ 't' . $i ] > $enforce[ 'u' . $Gtribe . $i ] ) {
|
||||
$form->addError( "error", "You can't send more units than you have" );
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $post[ 't' . $i ] < 0 ) {
|
||||
$form->addError( "error", "You can't send negative units." );
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -525,11 +472,11 @@ class Units {
|
||||
}
|
||||
if ( isset( $post['t11'] ) ) {
|
||||
if ( $post['t11'] > $enforce['hero'] ) {
|
||||
$form->addError( "error", "You can't send more units than you have" );
|
||||
$form->addError( "error", "You can't send back more units than you have" );
|
||||
}
|
||||
|
||||
if ( $post['t11'] < 0 ) {
|
||||
$form->addError( "error", "You can't send negative units." );
|
||||
$form->addError( "error", "You can't send back negative units." );
|
||||
}
|
||||
} else {
|
||||
$post['t11'] = '0';
|
||||
@@ -543,8 +490,9 @@ class Units {
|
||||
} else {
|
||||
|
||||
//change units
|
||||
$start = ( $database->getUserField( $to['owner'], 'tribe', 0 ) - 1 ) * 10 + 1;
|
||||
$end = ( $database->getUserField( $to['owner'], 'tribe', 0 ) * 10 );
|
||||
$tribe = $database->getUserField($to['owner'], 'tribe', 0);
|
||||
$start = ($tribe - 1 ) * 10 + 1;
|
||||
$end = $tribe * 10 ;
|
||||
|
||||
$units = [];
|
||||
$amounts = [];
|
||||
@@ -562,48 +510,15 @@ class Units {
|
||||
$amounts[] = $post['t11'];
|
||||
$modes[] = 0;
|
||||
|
||||
$database->modifyEnforce( $post['ckey'], $units, $amounts, $modes );
|
||||
$j ++;
|
||||
//get cord
|
||||
$from = $database->getVillage( $enforce['from'] );
|
||||
$fromcoor = $database->getCoor( $enforce['from'] );
|
||||
$tocoor = $database->getCoor( $enforce['vref'] );
|
||||
$fromCor = array( 'x' => $tocoor['x'], 'y' => $tocoor['y'] );
|
||||
$toCor = array( 'x' => $fromcoor['x'], 'y' => $fromcoor['y'] );
|
||||
|
||||
$speeds = array();
|
||||
|
||||
//find slowest unit.
|
||||
for ( $i = 1; $i <= 10; $i ++ ) {
|
||||
if ( isset( $post[ 't' . $i ] ) ) {
|
||||
if ( $post[ 't' . $i ] != '' && $post[ 't' . $i ] > 0 ) {
|
||||
if ( $unitarray ) {
|
||||
reset( $unitarray );
|
||||
}
|
||||
$unitarray = $GLOBALS[ "u" . ( ( $session->tribe - 1 ) * 10 + $i ) ];
|
||||
$speeds[] = $unitarray['speed'];
|
||||
} else {
|
||||
$post[ 't' . $i . '' ] = '0';
|
||||
}
|
||||
} else {
|
||||
$post[ 't' . $i . '' ] = '0';
|
||||
}
|
||||
}
|
||||
if ( isset( $post['t11'] ) ) {
|
||||
if ( $post['t11'] != '' && $post['t11'] > 0 ) {
|
||||
$hero_unit = $database->getHeroField($from['owner'], 'unit');
|
||||
$speeds[] = $GLOBALS[ 'u' . $hero_unit ]['speed'];
|
||||
}
|
||||
else $post['t11'] = 0;
|
||||
}
|
||||
else $post['t11'] = 0;
|
||||
|
||||
$troopsTime = $generator->procDistanceTime($fromCor, $toCor, min($speeds), 1);
|
||||
$database->modifyEnforce($post['ckey'], $units, $amounts, $modes);
|
||||
$j++;
|
||||
|
||||
$troopsTime = $this->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $tribe, $post, 1, 't');
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$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, $village->wid, $enforce['from'], $reference, time(), ( $time + time() ) );
|
||||
$technology->checkReinf( $post['ckey'], false );
|
||||
$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, $village->wid, $enforce['from'], $reference, time(), ($time + time()));
|
||||
$technology->checkReinf($post['ckey'], false );
|
||||
|
||||
header( "Location: build.php?id=39&refresh=1" );
|
||||
exit;
|
||||
@@ -626,48 +541,34 @@ class Units {
|
||||
|
||||
public function Settlers($post) {
|
||||
global $form, $database, $village, $session;
|
||||
//-- Prevent user from founding a new village if there are not enough settlers
|
||||
//-- fix by AL-Kateb
|
||||
$tempunits = $database->getUnit($village->coor['id']);
|
||||
$settler_key = "u" . $session->userinfo['tribe'] . "0";
|
||||
$settlers = (int)$tempunits[$settler_key];
|
||||
if($settlers < 3){
|
||||
header("location: dorf1.php");
|
||||
exit;
|
||||
}
|
||||
//--
|
||||
|
||||
if ( $session->access != BANNED ) {
|
||||
$mode = CP;
|
||||
$total = count( $database->getProfileVillages( $session->uid ) );
|
||||
$need_cps = ${'cp' . $mode}[ $total + 1 ];
|
||||
$cps = $session->cp;
|
||||
$rallypoint = $database->getResourceLevel( $village->wid );
|
||||
if ( $rallypoint['f39'] > 0 ) {
|
||||
if ( $cps >= $need_cps ) {
|
||||
$unit = ( $session->tribe * 10 );
|
||||
$database->modifyResource( $village->wid, 750, 750, 750, 750, 0 );
|
||||
$database->modifyUnit( $village->wid, array( $unit ), array( 3 ), array( 0 ) );
|
||||
$database->addMovement( 5, $village->wid, $post['s'], 0, time(), time() + $post['timestamp'] );
|
||||
header( "Location: build.php?id=39" );
|
||||
exit;
|
||||
if ($session->access != BANNED) {
|
||||
$mode = CP;
|
||||
$total = count($database->getProfileVillages($session->uid));
|
||||
$need_cps = ${'cp'.$mode}[$total + 1];
|
||||
$cps = $session->cp;
|
||||
$rallypoint = $database->getResourceLevel($village->wid);
|
||||
|
||||
if ( $form->returnErrors() > 0 ) {
|
||||
$_SESSION['errorarray'] = $form->getErrors();
|
||||
$_SESSION['valuearray'] = $_POST;
|
||||
header( "Location: a2b.php" );
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
header( "Location: build.php?id=39" );
|
||||
exit;
|
||||
//-- Prevent user from founding a new village if there are not enough settlers or the player put an invalid village ID or an already occupied one
|
||||
//-- fix by AL-Kateb - Semplified and additions by iopietro
|
||||
if ($rallypoint['f39'] > 0 && $village->unitarray['u'.$session->tribe.'0'] >= 3 && isset($post['s']) && ($newvillage = $database->getMInfo($post['s']))['id'] > 0 && $newvillage['occupied'] == 0 && $newvillage['oasistype'] == 0) {
|
||||
if ($cps >= $need_cps) {
|
||||
$troopsTime = $this->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
|
||||
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
|
||||
|
||||
$unit = ($session->tribe * 10);
|
||||
$database->modifyResource($village->wid, 750, 750, 750, 750, 0);
|
||||
$database->modifyUnit($village->wid, [$unit], [3], [0]);
|
||||
$database->addMovement(5, $village->wid, $post['s'], 0, time(), time() + $time);
|
||||
}
|
||||
header("Location: build.php?id=39");
|
||||
exit;
|
||||
} else {
|
||||
header( "Location: dorf1.php" );
|
||||
header("Location: dorf1.php");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
header( "Location: banned.php" );
|
||||
header("Location: banned.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -773,6 +674,65 @@ class Units {
|
||||
return $heroes;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get how much time troops spend to walk from a village to another
|
||||
*
|
||||
* @param int $from The start village ID
|
||||
* @param int $to The target village ID
|
||||
* @param int $owner The owner of the troops
|
||||
* @param int $tribe The tribe of the owner's troops
|
||||
* @param array $unitArray The array containing troops count if mode is 0, otherwise it'll contains the troop speed
|
||||
* @param int $mode How the time should be calculated
|
||||
* @return int Returns the time troops take to walk from a village to another
|
||||
*/
|
||||
|
||||
public function getWalkingTroopsTime($from, $to, $owner, $tribe, $unitArray, $mode, $unit = ""){
|
||||
global $generator, $database;
|
||||
|
||||
$fromCoor = $database->getCoor($from);
|
||||
$toCoor = $database->getCoor($to);
|
||||
$fromCor = ['x' => $fromCoor['x'], 'y' => $fromCoor['y']];
|
||||
$toCor = ['x' => $toCoor['x'], 'y' => $toCoor['y']];
|
||||
|
||||
if(!$mode) return $generator->procDistanceTime($fromCor, $toCor, $unitArray[0], $mode);
|
||||
|
||||
$start = ($tribe - 1) * 10 + 1;
|
||||
$end = $tribe * 10;
|
||||
|
||||
$speeds = [];
|
||||
|
||||
//Find slowest unit
|
||||
if(!empty($unit)){
|
||||
for($i = 1; $i <= 11; $i++){
|
||||
if(isset($unitArray[$unit.$i]) && $unitArray[$unit.$i] > 0) $unitArray[$i - 1] = $unitArray[$unit.$i];
|
||||
else $unitArray[$i - 1] = 0;
|
||||
}
|
||||
}else{
|
||||
for($i = $start; $i <= $end; $i++){
|
||||
if(isset($unitArray['u'.$i]) && $unitArray['u'.$i] > 0) $unitArray[$i - $start] = $unitArray['u'.$i];
|
||||
else $unitArray[$i - $start] = 0;
|
||||
}
|
||||
|
||||
if(isset($unitArray['hero']) && $unitArray['hero'] > 0){
|
||||
$unitArray[10] = $unitArray['hero'];
|
||||
}
|
||||
else $unitArray[10] = 0;
|
||||
}
|
||||
|
||||
for($i = 0; $i <= 9; $i++){
|
||||
if(isset($unitArray[$i]) && $unitArray[$i] > 0){
|
||||
$speeds[] = $GLOBALS['u'.($i + $start)]['speed'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($unitArray[10]) && $unitArray[10] > 0){
|
||||
$heroUnit = $database->getHeroField($owner, 'unit');
|
||||
$speeds[] = $GLOBALS['u'.$heroUnit]['speed'];
|
||||
}
|
||||
|
||||
return $generator->procDistanceTime($fromCor, $toCor, min($speeds), $mode);
|
||||
}
|
||||
};
|
||||
|
||||
$units = new Units;
|
||||
|
||||
Reference in New Issue
Block a user