Changeset 432 for veekun/trunk

Show
Ignore:
Timestamp:
05/23/08 02:41:12 (8 months ago)
Author:
eevee
Message:

Changed breeding chain calculator to interpret its Pokemon input as a target rather than.. whatever it was before. (#309)
Also added some more detail on reading the results.

Location:
veekun/trunk
Files:
3 modified

Legend:

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

    r431 r432  
    270270    } 
    271271 
    272     if ($pokemon->breeding_code == 255) { 
    273         $s->{error_msg} = $pokemon->name . ' cannot breed.'; 
     272    my $basic_form = $pokemon->evo_chain->basic_form; 
     273    my @egg_forms  = $pokemon->evo_chain->egg_forms; 
     274 
     275    warn join "\n", map { $_->name } @egg_forms; 
     276    # N.B.: this assumes (correctly, as of DP) that every gendered Pokemon in 
     277    # a given chain has the same breeding code. 
     278    my $breedable_form = $pokemon->evo_chain->pokemon({ 
     279        'breeds.breed' => { '!=' => 15 }, 
     280    }, { 
     281        join           => 'breeds', 
     282    })->first; 
     283    if (not $breedable_form) { 
     284        $s->{error_msg} = 'Nothing in the ' . $basic_form->name 
     285                        . ' family can breed.'; 
    274286        return; 
    275287    } 
    276288 
    277289    my @unlearnable_moves; 
    278     for my $move (@moves) { 
    279         my $method = $pokemon->move_method_string($move, $version); 
    280         if (not $method) { 
    281             push @unlearnable_moves, $move; 
    282         } 
     290    MOVE: for my $move (@moves) { 
     291        for my $egg (@egg_forms) { 
     292            next MOVE if $egg->move_method_string($move, $version); 
     293        } 
     294 
     295        push @unlearnable_moves, $move; 
    283296    } 
    284297    if (@unlearnable_moves) { 
     
    287300            $move_names[-1] = 'or ' . $move_names[-1]; 
    288301        } 
    289         $s->{error_msg} = $pokemon->name . " cannot inherit " 
    290                         . join(', ', @move_names) . '.'; 
     302        $s->{error_msg} = 'No egg in the ' . $basic_form->name . ' family can' 
     303                        . ' inherit ' . join(', ', @move_names) . '.'; 
    291304        return; 
    292305    } 
     
    329342    # tree iteratively from there 
    330343    my %egg_groups_tree = ( 
    331         groups   => [ $pokemon->breeding_groups ], 
    332         pokemon  => [ $pokemon ], 
     344        groups   => [ $breedable_form->breeding_groups ], 
     345        pokemon  => [ @egg_forms ], 
    333346        children => [], 
    334347    ); 
  • veekun/trunk/lib/Vee/Schema/EvoChains.pm

    r406 r432  
    2323__PACKAGE__->has_many(pokemon => 'Vee::Schema::Pokemon', 'evo_chain_id'); 
    2424 
     25=head2 baby_form 
     26 
     27Returns the baby Pokemon in this chain, if any. 
     28 
     29=cut 
     30 
     31sub baby_form { 
     32    my ($self) = @_; 
     33 
     34    return $self->pokemon( \ 'FIND_IN_SET(flags, "baby")' )->single; 
     35} 
     36 
     37=head2 basic_form 
     38 
     39Returns the basic form of this Pokemon. 
     40 
     41=cut 
     42 
     43sub basic_form { 
     44    my ($self) = @_; 
     45 
     46    return $self->pokemon( 
     47        \ 'NOT FIND_IN_SET(flags, "baby")', 
     48    { 
     49        order_by => 'id ASC', 
     50    })->first; 
     51} 
     52 
     53=head2 egg_forms 
     54 
     55Returns any Pokemon that can result from a breeding in this chain. 
     56 
     57=cut 
     58 
     59sub egg_forms { 
     60    my ($self) = @_; 
     61    my @ret; 
     62 
     63    my $baby_form  = $self->baby_form; 
     64    if ($baby_form) { 
     65        push @ret, $baby_form; 
     66    } 
     67 
     68    my $basic_form = $self->basic_form; 
     69    if (not $baby_form 
     70        or $self->baby_item)  # e.g. Munchlax with incense 
     71    { 
     72        push @ret, $basic_form; 
     73    } 
     74 
     75    return @ret; 
     76} 
     77 
    2578=head1 SEE ALSO 
    2679 
  • veekun/trunk/templates/dex/utils/breeding_chains.tt

    r431 r432  
    1919[% END %] 
    2020 
    21 <p> This tree is arranged by combinations of egg groups.  Any Pok&eacute;mon from a set may be used; since they have the same egg groups, they are all equally valid partners for all the Pok&eacute;mon in the sets above and below them. </p> 
     21<p> The following table is arranged as a family tree, where the Pok&eacute;mon the furthest on the left are the children and the Pok&eacute;mon to the right are successive generations of <em>fathers</em>.  The mother must always be in the same chain/family as the egg, and so has been omitted. </p> 
     22<p> Egg group combinations are grouped together as individual sets.  Any Pok&eacute;mon from a set may be used; since they have the same egg groups, they are all equally valid parents for any of their possible children. </p> 
    2223 
    2324<table class="dex-table dex-pokemon" cellspacing="0">