public void computeRange(int arc,boolean aptGunnery){
  double optimizer[]={0,0,0,0};
  Arrays.fill(range_damages,0);
  rd_bracket=long_range / 4;
  for (int range_walk=(entity instanceof Infantry ? 0 : 1); range_walk < long_range; range_walk++) {
    if (range_walk <= rd_bracket) {
      optimizer[RANGE_SHORT]+=damages[arc][range_walk];
      range_damages[RANGE_SHORT]+=damages[arc][range_walk];
    }
    if ((range_walk > rd_bracket) & (range_walk <= (2 * rd_bracket))) {
      optimizer[RANGE_MEDIUM]+=getModifiedDamage(arc,range_walk,-2,aptGunnery);
      range_damages[RANGE_MEDIUM]+=damages[arc][range_walk];
    }
    if ((range_walk > (2 * rd_bracket)) & (range_walk <= (3 * rd_bracket))) {
      optimizer[RANGE_LONG]+=getModifiedDamage(arc,range_walk,-4,aptGunnery);
      range_damages[RANGE_LONG]+=damages[arc][range_walk];
    }
    range_damages[RANGE_ALL]+=damages[arc][range_walk];
  }
  if (rd_bracket > 0) {
    range_damages[RANGE_SHORT]/=rd_bracket;
    optimizer[RANGE_SHORT]/=rd_bracket;
    range_damages[RANGE_MEDIUM]/=rd_bracket;
    optimizer[RANGE_MEDIUM]/=rd_bracket;
    range_damages[RANGE_LONG]/=rd_bracket;
    optimizer[RANGE_LONG]/=rd_bracket;
    range_damages[RANGE_ALL]/=(rd_bracket * 3);
  }
 else {
    range_damages[RANGE_SHORT]=damages[arc][0];
    optimizer[RANGE_SHORT]=damages[arc][0];
    range_damages[RANGE_MEDIUM]=damages[arc][0];
    optimizer[RANGE_MEDIUM]=damages[arc][0];
    range_damages[RANGE_LONG]=damages[arc][0];
    optimizer[RANGE_LONG]=damages[arc][0];
    range_damages[RANGE_ALL]=damages[arc][0];
  }
  int best_range=RANGE_ALL;
  for (range=RANGE_SHORT; range <= RANGE_LONG; range++) {
    if (optimizer[range] > optimizer[best_range]) {
      best_range=range;
    }
  }
  range=best_range;
}

public void computeRange ( int arc , boolean aptGunnery ) { double optimizer [ ] = { 0 , 0 , 0 , 0 } ; Arrays . fill ( range_damages , 0 ) ; rd_bracket = long_range / 4 ; for ( int range_walk = ( entity instanceof Infantry ? 0 : 1 ) ; range_walk < long_range ; range_walk ++ ) { if ( range_walk <= rd_bracket ) { optimizer [ RANGE_SHORT ] += damages [ arc ] [ range_walk ] ; range_damages [ RANGE_SHORT ] += damages [ arc ] [ range_walk ] ; } if ( ( range_walk > rd_bracket ) & ( range_walk <= ( 2 * rd_bracket ) ) ) { optimizer [ RANGE_MEDIUM ] += getModifiedDamage ( arc , range_walk , - 2 , aptGunnery ) ; range_damages [ RANGE_MEDIUM ] += damages [ arc ] [ range_walk ] ; } if ( ( range_walk > ( 2 * rd_bracket ) ) & ( range_walk <= ( 3 * rd_bracket ) ) ) { optimizer [ RANGE_LONG ] += getModifiedDamage ( arc , range_walk , - 4 , aptGunnery ) ; range_damages [ RANGE_LONG ] += damages [ arc ] [ range_walk ] ; } range_damages [ RANGE_ALL ] += damages [ arc ] [ range_walk ] ; } if ( rd_bracket > 0 ) { range_damages [ RANGE_SHORT ] /= rd_bracket ; optimizer [ RANGE_SHORT ] /= rd_bracket ; range_damages [ RANGE_MEDIUM ] /= rd_bracket ; optimizer [ RANGE_MEDIUM ] /= rd_bracket ; range_damages [ RANGE_LONG ] /= rd_bracket ; optimizer [ RANGE_LONG ] /= rd_bracket ; range_damages [ RANGE_ALL ] /= ( rd_bracket * 3 ) ; } else { range_damages [ RANGE_SHORT ] = damages [ arc ] [ 0 ] ; optimizer [ RANGE_SHORT ] = damages [ arc ] [ 0 ] ; range_damages [ RANGE_MEDIUM ] = damages [ arc ] [ 0 ] ; optimizer [ RANGE_MEDIUM ] = damages [ arc ] [ 0 ] ; range_damages [ RANGE_LONG ] = damages [ arc ] [ 0 ] ; optimizer [ RANGE_LONG ] = damages [ arc ] [ 0 ] ; range_damages [ RANGE_ALL ] = damages [ arc ] [ 0 ] ; } int best_range = RANGE_ALL ; for ( range = RANGE_SHORT ; range <= RANGE_LONG ; range ++ ) { if ( optimizer [ range ] > optimizer [ best_range ] ) { best_range = range ; } } range = best_range ; }
fills range damage values for short , medium , long , and all , plus sets the range bracket for the entity , which is 1 / 3 of long range or 1 / 4 extreme range . the arc argument follows compute . arc_xxx format .
