DeletedUser3866
Ar fi ideal sa avem ecuatiile fara sa le mai calculam noi
function simulate($att, $att_tech, $def, $def_tech, $others) {
global $cl_units;
global $config;
global $arr_basic_defense;
global $arr_wall_bonus;
global $cl_ramHarm;
global $cl_catapultHarm;
global $arr_builds_starts_by_one;
$attPoints_onlyFootTroops = 0;
$attPoints_onlyCav = 0;
$defPoints_footTroops = 0;
$defPoints_cav = 0;
foreach ($cl_units->get_array( 'dbname' ) as $name => $dbname) {
if ($cl_units->get_group( $dbname ) == 'cav') {
$attPoints_onlyFootTroops += $cl_units->get_att( $dbname, $att_tech[$dbname] ) * $att[$dbname];
} else {
if ($cl_units->get_group( $dbname ) == 'foot') {
$attPoints_onlyCav += $cl_units->get_att( $dbname, $att_tech[$dbname] ) * $att[$dbname];
}
}
$defPoints_footTroops += $cl_units->get_def( $dbname, $def_tech[$dbname] ) * $def[$dbname];
$defPoints_cav += $cl_units->get_defCav( $dbname, $def_tech[$dbname] ) * $def[$dbname];
}
if ($attPoints_onlyCav == '0') {
$attPoints_onlyCav = 1.0e-6;
}
if ($attPoints_onlyFootTroops == '0') {
$attPoints_onlyFootTroops = 1.0e-6;
}
if ($attPoints_onlyCav < $attPoints_onlyFootTroops) {
$off_factor = $attPoints_onlyFootTroops / $attPoints_onlyCav;
} else {
$off_factor = $attPoints_onlyCav / $attPoints_onlyFootTroops;
}
$offPoints = ( $attPoints_onlyFootTroops + $attPoints_onlyCav ) * ( ( 100 + $others['luck'] ) / 100 );
if ($config['moral_activ']) {
$offPoints *= $others['moral'] / 100;
}
if ($defPoints_cav < $defPoints_footTroops) {
if ($attPoints_onlyFootTroops < $attPoints_onlyCav) {
$defPoints = $defPoints_footTroops - ( $defPoints_footTroops - $defPoints_cav ) / $off_factor;
} else {
$defPoints = $defPoints_cav + ( $defPoints_footTroops - $defPoints_cav ) / $off_factor;
}
} else {
if ($attPoints_onlyFootTroops < $attPoints_onlyCav) {
$defPoints = $defPoints_footTroops + ( $defPoints_cav - $defPoints_footTroops ) / $off_factor;
} else {
$defPoints = $defPoints_cav - ( $defPoints_cav - $defPoints_footTroops ) / $off_factor;
}
}
$tmp_defPoints = $defPoints;
$defPoints += $config['reason_defense'] + $arr_basic_defense[$others['def_wall']];
$factor = ( $defPoints *= $arr_wall_bonus[$others['def_wall']] + 1 ) / $offPoints;
$att_lose = array( );
$def_lose = array( );
$others['att_color'] = '';
$others['def_color'] = '';
if (1 < $factor) {
$ram_factor = $offPoints / $defPoints;
} else {
$ram_factor = 1 - $factor;
}
$ram_att = $cl_units->get_att( 'unit_ram', $att_tech['unit_ram'] ) * $att['unit_ram'] * $ram_factor;
for ($stage = $others['def_wall']; 0 <= $stage; --$stage) {
while (( $ram_att -= $cl_ramHarm->get_buildDeff( $stage ) ) < 0) {
$others['new_wall'] = $stage;
$stage = -1;
break;
}
}
if (empty( $others['new_wall'] )) {
$others['new_wall'] = 0;
}
if (1 < $factor) {
$cata_factor = $offPoints / $defPoints;
} else {
$cata_factor = 1 - $factor;
}
if ($others['cata_building'] == 'wall') {
$others['def_building'] = $others['new_wall'];
}
if (in_array( 'unit_catapult', $cl_units->get_array( 'dbname' ) )) {
$cata_att = $cl_units->get_att( 'unit_catapult', $att_tech['unit_catapult'] ) * $att['unit_catapult'] * $cata_factor;
}
for ($stage = $others['def_building']; 0 <= $stage; --$stage) {
while (( $cata_att -= $cl_catapultHarm->get_buildDeff( $stage ) ) < 0) {
$others['new_building'] = $stage;
$stage = -1;
break;
}
}
if (empty( $others['new_building'] )) {
$others['new_building'] = 0;
}
if ($others['new_building'] == '0') {
if (in_array( $others['cata_building'], $arr_builds_starts_by_one )) {
$others['new_building'] = 1;
}
}
if ($def['unit_spy'] == '0') {
$def_lose['unit_spy'] = 0;
$att_lose['unit_spy'] = 0;
if (0 < $att['unit_spy']) {
$others['att_color'] = 'blue';
$others['def_color'] = 'blue';
}
} else {
if ($att['unit_spy'] != '0') {
$att_lose['unit_spy'] = floor( $def['unit_spy'] / $spy_factor = $att['unit_spy'] * pow( $config['factor_spy'], 2 ) / $def['unit_spy'] );
if ($att['unit_spy'] < $att_lose['unit_spy']) {
$att_lose['unit_spy'] = $att['unit_spy'];
}
if ($att_lose['unit_spy'] == '0') {
$others['att_color'] = 'blue';
$others['def_color'] = 'blue';
} else {
if ($att['unit_spy'] != $att_lose['unit_spy']) {
$others['att_color'] = 'yellow';
$others['def_color'] = 'blue';
} else {
$others['att_color'] = 'red';
$others['def_color'] = 'blue';
}
}
} else {
$att_lose['unit_spy'] = 0;
}
}
if (!( $others['def_wall'] != ['new_wall'])) {
if ($others['def_building'] != ['new_building']) {
if ($others['cata_building'] == 'wall') {
}
}
}
$old_wall = '';
if ($others['def_wall'] != ['new_wall']) {
$old_wall = $others['def_wall'];
$new_wall = $others['new_wall'];
}
if ($others['def_building'] != ['new_building']) {
if ($others['cata_building'] == 'wall') {
if (empty( $old_wall )) {
$old_wall = $others['def_buildung'];
$new_wall = $others['new_building'];
}
}
}
$new_walldeff = $tmp_defPoints + $config['reason_defense'] + $arr_basic_defense[$new_wall];
$new_walldeff *= $arr_wall_bonus[$new_wall] + 1;
$old_walldeff = $tmp_defPoints + $config['reason_defense'] + $arr_basic_defense[$old_wall];
$old_walldeff *= $arr_wall_bonus[$old_wall] + 1;
if ($new_walldeff == '0') {
$new_walldeff = '1';
}
if ($old_walldeff == '0') {
$old_walldeff = '1';
}
$factor = ( $defPoints -= ( $old_walldeff - $new_walldeff ) / 1.10000000000000008881784 ) / $offPoints;
$defPoints /= 1.03000000000000002664535;
if (1.01000000000000000888178 < $factor) {
$others['wins'] = 'def';
if ($others['att_color'] == 'blue') {
$others['att_color'] = 'blue';
} else {
if ($others['att_color'] == 'yellow') {
$others['att_color'] = 'yellow';
} else {
$others['att_color'] = 'red';
}
}
$factor = $offPoints / $defPoints;
foreach ($att as $unitname => $num) {
while ( != 'unit_spy') {
$att_lose[$unitname] = $num;
break;
}
}
$off_back = $offPoints * $factor;
$unit_num = 0;
foreach ($def as $unitname => $num) {
$unit_num += $num;
}
$lose_units_def = $off_back / $cutTrought_def = $defPoints / $unit_num;
$units_lose = false;
$units_die = 0;
foreach ($def as $unitname => $num) {
while ($num == '0') {
$def_lose[$unitname] = 0;
break;
}
$def_lose[$unitname] = round( $lose_units_def * ( 100 * $num / $unit_num ) / 100 );
if ($num < $def_lose[$unitname]) {
$def_lose[$unitname] = $num;
}
$units_die += $def_lose[$unitname];
while ($def_lose[$unitname] != '0') {
$units_lose = true;
break;
}
}
if ($units_lose) {
$others['def_color'] = 'yellow';
} else {
$others['def_color'] = 'green';
}
$def_units = 0;
foreach ($def as $num) {
$def_units += ;
}
if (!( 66 < 100 / $def_units * $units_die)) {
if (!( ( $units_die == 0 && $def_units == 0 ))) {
if ($att['unit_spy'] - $att_lose['unit_spy']) {
}
}
}
$others['see_def_units'] = ( true ? 1 : 0 );
} else {
$others['wins'] = 'att';
$others['def_color'] = 'red';
$others['see_def_units'] = 1;
$factor = $defPoints / $offPoints;
foreach ($def as $unitname => $num) {
$def_lose[] = $num;
}
$def_back = $defPoints * $factor;
$unit_num = 0;
foreach ($att as $unitname => $num) {
$unit_num += $num;
}
$lose_units_off = $def_back / $cutTrought_off = $offPoints / $unit_num;
$units_lose = false;
foreach ($att as $unitname => $num) {
while ( != 'unit_spy') {
while ($num == '0') {
$att_lose[$unitname] = 0;
break 2;
}
$att_lose[$unitname] = round( $lose_units_off * ( 100 * $num / $unit_num ) / 100 );
if ($num < $att_lose[$unitname]) {
$att_lose[$unitname] = $num;
}
while ($att_lose[$unitname] != '0') {
$units_lose = true;
break 2;
}
break;
}
}
if ($units_lose) {
$others['att_color'] = 'yellow';
} else {
if ($others['att_color'] == 'blue') {
if (0 < $offPoints) {
$others['att_color'] = 'green';
}
} else {
if ($others['att_color'] != 'blue') {
$others['att_color'] = 'green';
}
}
}
}
$att_lose_tmp = array( );
foreach ($att as $unitname => $num) {
$att_lose_tmp[] = $att_lose[$unitname];
}
$att_lose = $att_lose_tmp;
$def_lose_tmp = array( );
foreach ($def as $unitname => $num) {
$def_lose_tmp[] = $def_lose[$unitname];
}
return array( 'att' => $att, 'att_lose' => $att_lose, 'def' => $def, 'def_lose' => $def_lose = $def_lose_tmp, 'others' => $others );
}