Changeset 230

Show
Ignore:
Timestamp:
06/09/07 03:54:12 (3 years ago)
Author:
eevee
Message:

Fixed Hidden Power calculations and added them to the IV calculator on the off chance that the user narrows down all the IVs exactly.

Location:
veekun/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/Controller/Dex/Utils.pm

    r208 r230  
    330330            $nature_change[ $nature_updown->{down} ] = 0.9; 
    331331        } 
     332 
     333        my $all_exact = 1; 
    332334        for my $s (0 .. $#StatColumns) { 
    333335            my $stat = $StatColumns[$s]; 
     
    346348            $iv_ranges[$s]{min} = first_index { $_ } @{ $ivs[$s] }; 
    347349            $iv_ranges[$s]{max} =  last_index { $_ } @{ $ivs[$s] }; 
     350            $all_exact = 0 
     351                if $iv_ranges[$s]{min} != $iv_ranges[$s]{max} 
     352                or $iv_ranges[$s]{min} == -1; 
    348353 
    349354            # entire range of possible stats for this Pokemon 
     
    356361        $s->{possible_stats} = \@possible_stats; 
    357362 
     363        # TODO: improve this a bit since even at L100 you rarely get perfect results 
     364        if ($all_exact) { 
     365            $s->{hp_power} = ingame_hp_power( map { $_->{min} } @iv_ranges ); 
     366            $s->{hp_type}  = ingame_hp_type ( map { $_->{min} } @iv_ranges ); 
     367        } 
     368 
    358369        $s->{nature}         = $p->{nature}; 
    359370        $s->{pokemon}        = $pokemon; 
  • veekun/trunk/lib/Vee/Dex.pm

    r218 r230  
    198198our (@PokemonJohto, @PokemonHoenn, @PokemonSinnoh); 
    199199our (@MoveData, $DamagingMoveCount); 
    200 our (%TypeData, @TypeNames, %OldTypeOrder); 
     200our (%TypeData, @TypeNames, %OldTypeOrder, @NewTypeOrder); 
    201201our (@AbilityNames, @ItemNames); 
    202202our (@TMs, %MoveTMs); 
     
    227227    @TypeNames = sort keys %TypeData; 
    228228    %OldTypeOrder = map { $_->internalid + 1 => $_->name } values %TypeData;  # for Compat.pm 
     229    @NewTypeOrder = map { $_->name } sort { $a->id <=> $b->id } grep { $_->id >= 0 } values %TypeData; 
    229230 
    230231    @AbilityNames = $schema->resultset('Abilities')->search({ id => { '<', 200 } }, { order_by => 'id ASC', columns => ['name'] })->get_column('name')->all; 
     
    647648 
    648649# 31-base hidden power power 
    649 # stupidly complicated 
    650650sub ingame_hp_power { 
    651     my (%ivs) = @_; 
    652  
    653     my @ivs = @ivs{qw/ stat_hp stat_at stat_de stat_sp stat_sa stat_sd /}; 
     651    my (@ivs) = @_; 
     652 
     653    # speed is in the middle as far as the game is concerned 
     654    @ivs = @ivs[ 0, 1, 2, 5, 3, 4 ]; 
    654655 
    655656    my $sum = 0; 
     
    659660 
    660661    return int($sum * 40 / 63) + 30; 
     662} 
     663 
     664# 31-base hidden power type 
     665sub ingame_hp_type { 
     666    my (@ivs) = @_; 
     667 
     668    # speed is in the middle as far as the game is concerned 
     669    @ivs = @ivs[ 0, 1, 2, 5, 3, 4 ]; 
     670 
     671    my $sum = 0; 
     672    for my $i (0 .. 5) { 
     673        $sum += ($ivs[$i] & 0x01) << $i; 
     674    } 
     675 
     676    # +1 is to skip normal and make fighting (normally 1) be zero 
     677    return $NewTypeOrder[ int($sum * 15 / 63) + 1 ]; 
    661678} 
    662679 
  • veekun/trunk/templates/dex/utils/iv.tt

    r193 r230  
     1[% PROCESS 'dex/common.tt' %] 
     2 
    13<h1>Calculator</h1> 
    24<p>See below for instructions and hints.</p> 
     
    911    <dd>[% form.get_tag('level') %]</dd> 
    1012    <dt>Nature</dt> 
    11     <dd>[% form.get_tag('nature') %]</dd> 
     13    <dd> 
     14        [% form.get_tag('nature') %] 
     15[% IF form.submitted AND Natures.$nature %] 
     16        <p class="typemod-25">  +10%: [% StatNames.${ Natures.$nature.up   } %] </p> 
     17        <p class="typemod-400"> -10%: [% StatNames.${ Natures.$nature.down } %] </p> 
     18[% END %] 
     19    </dd> 
    1220</dl> 
    1321<table class="dex-table dex-statcalc" cellspacing="0"> 
     
    4250    <td class="stat">[% pokemon.${StatColumns.$s} %]</td> 
    4351    <td class="possible-stats[% nature_class %]">[% possible_stats.$s %]</td> 
    44     [%         IF iv_ranges.$s.min >= 0 %] 
     52[%         IF iv_ranges.$s.min >= 0 %] 
    4553    <td class="possible-ivs">[% iv_ranges.$s.min %][% IF iv_ranges.$s.min != iv_ranges.$s.max %] - [% iv_ranges.$s.max %][% END %]</td> 
    4654    <td class="iv-graph"><div class="iv-bar"> 
     
    5765[% END %] 
    5866</table> 
     67 
     68[% IF hp_power %] 
     69<p> <a href="[% dex_uri('moves', 'Hidden Power') %]">Hidden Power</a> for this Pok&eacute;mon will be [% type_name(hp_type) %] and have [% hp_power %] power. </p> 
     70[% END %] 
     71 
    5972<hr/> 
    60 <p> 
    61     <input type="submit" value="Calculate"/> 
    62     <input type="reset" value="Reset"/> 
    63 </p> 
     73 
     74<ul> 
     75    <li> <input type="submit" value="Calculate IVs"/> from stats and, optionally, effort </li> 
     76    <li> <input type="reset" value="Reset"/> form </li> 
     77</ul> 
    6478</form> 
    6579