| 1 | # -*- Perl -*- | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Game::EnergyLoop - a simple energy system | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Game::EnergyLoop; | ||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 6 | my ($enlos, $initiative, $arg) = @_; | |||||||||||||||||||||||||||
| 12 | 6 | my $min = ~0; | |||||||||||||||||||||||||||
| 13 | 6 | for my $ent (@$enlos) { | |||||||||||||||||||||||||||
| 14 | 9 | my $energy = $ent->enlo_energy; | |||||||||||||||||||||||||||
| 15 | 9 | ▶ | $min = $energy if $energy < $min; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 6 | ▶ | die "negative minimum energy $min" if $min < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 5 | my @active; | |||||||||||||||||||||||||||
| 19 | 5 | for my $ent (@$enlos) { | |||||||||||||||||||||||||||
| 20 | 8 | my $energy = $ent->enlo_energy; | |||||||||||||||||||||||||||
| 21 | 8 | $energy -= $min; | |||||||||||||||||||||||||||
| 22 | 8 | ▶ | push @active, $ent if $energy == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 8 | $ent->enlo_energy($energy); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 5 | ▶ | $initiative->( \@active ) if defined $initiative and @active > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $initiative and @active > 1
MC/DC100%2/2
defined $initiative and @active > 1
defined $initiative
@active > 1
Truth table100%3/3
A and B
A= defined $initiativeB= @active > 1
| |||||||||||||||||||||||||||||
| 26 | 5 | my @newbies; | |||||||||||||||||||||||||||
| 27 | 5 | for my $ent (@active) { | |||||||||||||||||||||||||||
| 28 | 5 | my ( $new_energy, $noobs ) = $ent->enlo_update( $min, $arg ); | |||||||||||||||||||||||||||
| 29 | 5 | ▶ | die "negative entity new_energy $new_energy" if $new_energy < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 4 | $ent->enlo_energy($new_energy); | |||||||||||||||||||||||||||
| 31 | 4 | ▶ | push @newbies, @$noobs if defined $noobs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 4 | push @$enlos, @newbies; | |||||||||||||||||||||||||||
| 34 | 4 | return $min; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # TODO may need a return flag to indicate whether game is blocked? but | ||||||||||||||||||||||||||||
| 38 | # if that's important the caller could set a flag in their world object | ||||||||||||||||||||||||||||
| 39 | # and check for that... | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | 1; | |||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||