Skip to content

Instantly share code, notes, and snippets.

@pneftali
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pneftali/9470488 to your computer and use it in GitHub Desktop.
Save pneftali/9470488 to your computer and use it in GitHub Desktop.
EE new dr formula
/**
* @param $cnum country number
* @param $news combined att and def news of a country
* @src http://earthempires.com/forum/announcements/20140201-changeset-15-restart-aid-abbr-diminishing-returns-29694?t=1393414830
*/
function getDR( $cnum, $newsObj ) {
// For each hit within the past 72 hours, add 1/2^(T/H).
// where:
// T = hours have passed since the hit
// H = halflife; 20 average oversend; 18 if DH
$timeAgo = strtotime( "72 hours ago" );
$now = time();
$dr = 0;
$_bounced = 18;
// 10 Nuclear Missile
// 11 Chemical Missile
// 12 Cruise Missile
$no_dr_attack_type = array('10', '11', '12');
// 5 Guerilla Strike
// 6 Bombing Run
// 7 Artillery Barrage
$special_attack_type = array('5', '6', '7');
// iterate over the news;
// stop when over $timeAgo;
foreach ($newsObj as $key => $value) {
// we need to put this one here
// so each iteration, the half-life
// gets re-intialized to the default value
$_hl = 20;
if ($value['timestamp'] >= $timeAgo) {
$_t = number_format(($now-$value['timestamp'])/3600, 2);
if ($value['win']==='0') { // bounced
$_hl = $_bounced;
}
$_exp = $_t/$_hl;
$_mod = 1/pow(2, $_exp);
if ($cnum === $value['defender_num'] && !in_array($value['type'], $no_dr_attack_type)) {
// defends
// ignore failed special attacks
if ($value['win']==='0' && in_array($value['type'], $special_attack_type)) {
continue;
} else {
$dr = $dr + $_mod;
}
} else {
// attacks
if ($dr>0) {
$tmp = $dr - $_mod;
if ($tmp>0) {
$dr = $tmp;
} else {
$dr = 0;
}
}
}
} else {
break;
}
}
return number_format($dr,2);
}
@pneftali
Copy link
Author

Ignored failed special incoming attacks: gs, br, ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment