| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- Perl -*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Game::EnergyLoop - a simple energy system |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Game::EnergyLoop; |
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
7
|
2
|
|
|
2
|
|
588439
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
62
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
679
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub update { |
|
11
|
6
|
|
|
6
|
1
|
247297
|
my ($enlos, $initiative, $arg) = @_; |
|
12
|
6
|
|
|
|
|
13
|
my $min = ~0; |
|
13
|
6
|
|
|
|
|
17
|
for my $ent (@$enlos) { |
|
14
|
9
|
|
|
|
|
34
|
my $energy = $ent->enlo_energy; |
|
15
|
9
|
100
|
|
|
|
167
|
$min = $energy if $energy < $min; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
6
|
100
|
|
|
|
28
|
die "negative minimum energy $min" if $min < 0; |
|
18
|
5
|
|
|
|
|
12
|
my @active; |
|
19
|
5
|
|
|
|
|
10
|
for my $ent (@$enlos) { |
|
20
|
8
|
|
|
|
|
38
|
my $energy = $ent->enlo_energy; |
|
21
|
8
|
|
|
|
|
46
|
$energy -= $min; |
|
22
|
8
|
100
|
|
|
|
23
|
push @active, $ent if $energy == 0; |
|
23
|
8
|
|
|
|
|
20
|
$ent->enlo_energy($energy); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
5
|
100
|
100
|
|
|
41
|
$initiative->( \@active ) if defined $initiative and @active > 1; |
|
26
|
5
|
|
|
|
|
15
|
my @newbies; |
|
27
|
5
|
|
|
|
|
11
|
for my $ent (@active) { |
|
28
|
5
|
|
|
|
|
16
|
my ( $new_energy, $noobs ) = $ent->enlo_update( $min, $arg ); |
|
29
|
5
|
100
|
|
|
|
83
|
die "negative entity new_energy $new_energy" if $new_energy < 0; |
|
30
|
4
|
|
|
|
|
17
|
$ent->enlo_energy($new_energy); |
|
31
|
4
|
100
|
|
|
|
30
|
push @newbies, @$noobs if defined $noobs; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
4
|
|
|
|
|
9
|
push @$enlos, @newbies; |
|
34
|
4
|
|
|
|
|
12
|
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
|
|
|
|
|
|
|
1; |
|
42
|
|
|
|
|
|
|
__END__ |