Fixed some catapult/ram bugs

Battle.php:
Fixed the blacksmith level formula for catapults and rams.

Automation.php:
+Catapults and rams now works better because of a new formula.

Note: this formula isn't 100% accurate with the real Travian formula, i can't find that formula anywhere, so i created an approximate formula.
This commit is contained in:
Pietro
2018-04-05 17:05:25 +02:00
committed by GitHub
parent 9fc3db754c
commit a1fbf9dcfc
2 changed files with 15 additions and 26 deletions
+13 -24
View File
@@ -1151,27 +1151,16 @@ class Automation {
else
// building/field was damaged, let's calculate the actual damage
{
//TODO: MUST TO BE FIX This part goes also below 0 if u have a lot of catapults
// TODO: this whole math seems incorrect, it needs a revision, and potentially a rewrite
$totallvl = round( sqrt( pow( ( $tblevel + 0.5 ), 2 ) - ( ( !$twoRowsCatapultSetup ? (float) $battlepart[4] : (float) $battlepart[4] / 2 ) * 8 ) ) );
// sometimes this goes above the actual level, so in that case we just reverse everything
// and take the buiding down so many levels
if ($totallvl > $tblevel) {
$totallvl = $tblevel - ($totallvl - $tblevel);
}
// don't allow this to go below 0
if ($totallvl < 0) {
$totallvl = 0;
}
$totallvl = round($tblevel-((pow(M_E, ($twoRowsCatapultSetup ? ($battlepart[4]/$battlepart[3])/2 : $battlepart[4]/$battlepart[3]))-1) * ($tblevel/2)));
// no damage to the building/field
if ( $tblevel == $totallvl ) {
if ($tblevel == $totallvl) {
$info_cata = " was not damaged.";
} else // building/field damaged, damage calculations to follow
}
else // building/field damaged, damage calculations to follow
{
// update $bdo, so we don't have to reselect later
$bdo[ 'f' . $catapultTarget ] = $totallvl;
$bdo['f' . $catapultTarget] = $totallvl;
if ($tblevel == 1 && $totallvl == 0) {
// building was actually destroyed - recalculate population and remove village itself, if needed
@@ -1181,16 +1170,16 @@ class Automation {
$info_cata = " damaged from level <b>" . $tblevel . "</b> to level <b>" . $totallvl . "</b>.";
}
$buildarray = $GLOBALS[ "bid" . $tbgid ];
$buildarray = $GLOBALS["bid" . $tbgid];
// (great) warehouse level was changed
if ( $tbgid == 10 || $tbgid == 38 ) {
$database->setMaxStoreForVillage( $data['to'], $buildarray[ $tblevel ]['attri'] );
if ($tbgid == 10 || $tbgid == 38) {
$database->setMaxStoreForVillage($data['to'], $buildarray[ $tblevel ]['attri']);
}
// (great) granary level was changed
if ( $tbgid == 11 || $tbgid == 39 ) {
$database->setMaxCropForVillage( $data['to'], $buildarray[ $tblevel ]['attri'] );
if ($tbgid == 11 || $tbgid == 39) {
$database->setMaxCropForVillage($data['to'], $buildarray[ $tblevel ]['attri']);
}
}
@@ -1203,10 +1192,10 @@ class Automation {
$bdo['f'.$catapultTarget."t"] = 0;
}
$database->setVillageLevel( $data['to'], $fieldsToSet, $fieldValuesToSet );
$database->setVillageLevel($data['to'], $fieldsToSet, $fieldValuesToSet);
// recalculate population and check if the village shouldn't be destroyed at this point
$pop = $this->recountPop( $data['to'], false );
$pop = $this->recountPop($data['to'], false);
if ($isoasis == 0) {
if($pop==0 && $can_destroy==1){
$village_destroyed = 1;
@@ -2295,7 +2284,7 @@ class Automation {
$info_ram = "".$ram_pic.",Wall was not damaged.";
}else{
$totallvl = round(sqrt(pow(($walllevel+0.5),2)-($battlepart[8]*8)));
$totallvl = round($walllevel-((pow(M_E, $battlepart[8]/$battlepart[7])-1) * ($walllevel/2)));
if($walllevel == $totallvl){
$info_ram = "".$ram_pic.",Wall was not damaged.";
}else{
+2 -2
View File
@@ -583,7 +583,7 @@ class Battle {
if($catp > 0 && $tblevel != 0) {
$wctp = pow(($rap/$rdp),1.5);
$wctp = ($wctp >= 1)? 1-0.5/$wctp : 0.5*$wctp;
$wctp *= $catp+($att_ab8/1.5);
$wctp *= $catp + (round(200 * pow(1.0205,$att_ab8))/200);
$artowner = $database->getVillageField( $DefenderWref, "owner" );
$bartefact = count($database->getOwnUniqueArtefactInfo2($artowner,1,3,0));
$bartefact1 = count($database->getOwnUniqueArtefactInfo2($DefenderWref,1,1,1));
@@ -626,7 +626,7 @@ class Battle {
if($ram > 0 && $walllevel != 0) {
$wctp = pow(($rap/$rdp),1.5);
$wctp = ($wctp >= 1)? 1-0.5/$wctp : 0.5*$wctp;
$wctp *= ($ram/2) + ($att_ab7/1.5);
$wctp *= ($ram/2) + (round(200 * pow(1.0205,$att_ab7))/200);
$artowner = $database->getVillageField( $DefenderWref, "owner" );
$bartefact = count($database->getOwnUniqueArtefactInfo2($artowner,1,3,0));
$bartefact1 = count($database->getOwnUniqueArtefactInfo2($DefenderWref,1,1,1));