line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::Homespring::Salmon; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = 0.02; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
118
|
|
6
|
4
|
|
|
4
|
|
23
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
4447
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $salmon_count = 0; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
187
|
|
|
187
|
0
|
233
|
my $class = shift; |
12
|
187
|
|
|
|
|
504
|
my $self = bless {}, $class; |
13
|
|
|
|
|
|
|
|
14
|
187
|
|
|
|
|
233
|
my $options = shift; |
15
|
187
|
|
|
|
|
463
|
$self->{interp} = $options->{interp}; |
16
|
187
|
|
100
|
|
|
680
|
$self->{value} = $options->{value} || 'homeless'; |
17
|
187
|
|
100
|
|
|
593
|
$self->{upstream} = $options->{upstream} || 0; |
18
|
187
|
|
100
|
|
|
706
|
$self->{mature} = $options->{mature} || 0; |
19
|
187
|
|
|
|
|
329
|
$self->{location} = $options->{location}; |
20
|
187
|
|
|
|
|
328
|
$self->{time_in_river} = 0; |
21
|
187
|
|
|
|
|
377
|
$self->{uid} = ++$salmon_count; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#print "Creating salmon : ".$self->debug()."\n"; |
24
|
|
|
|
|
|
|
|
25
|
187
|
|
|
|
|
626
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub move { |
29
|
338
|
|
|
338
|
0
|
418
|
my ($self) = @_; |
30
|
338
|
|
|
|
|
322
|
my ($node_to_pass, $river_target); |
31
|
|
|
|
|
|
|
|
32
|
338
|
100
|
|
|
|
618
|
if ($self->{upstream}){ |
33
|
90
|
|
|
|
|
133
|
$node_to_pass = $self->{location}->{up_node}; |
34
|
90
|
|
|
|
|
99
|
$river_target = undef; |
35
|
90
|
50
|
|
|
|
180
|
if ($node_to_pass){ |
36
|
90
|
|
|
|
|
94
|
my $count = scalar(@{$node_to_pass->{rivers_up}}); |
|
90
|
|
|
|
|
160
|
|
37
|
90
|
100
|
|
|
|
190
|
if ($count){ |
38
|
11
|
|
|
|
|
17
|
$river_target = @{$node_to_pass->{rivers_up}}[0]; |
|
11
|
|
|
|
|
22
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
}else{ |
42
|
248
|
|
|
|
|
621
|
$node_to_pass = $self->{location}->{down_node}; |
43
|
248
|
|
|
|
|
326
|
$river_target = $node_to_pass->{river_down}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
338
|
|
|
|
|
394
|
$self->{time_in_river}++; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## |
49
|
|
|
|
|
|
|
## see if we can pass the next node |
50
|
|
|
|
|
|
|
## |
51
|
|
|
|
|
|
|
|
52
|
338
|
|
|
|
|
459
|
my $node_name = $node_to_pass->{node_name}; |
53
|
|
|
|
|
|
|
|
54
|
338
|
100
|
100
|
|
|
838
|
return if (($node_to_pass->{node_name} eq 'shallows') && ($self->{mature}) && ($self->{time_in_river} == 1)); |
|
|
|
100
|
|
|
|
|
55
|
335
|
100
|
100
|
|
|
767
|
return if (($node_to_pass->{node_name} eq 'rapids') && (!$self->{mature}) && ($self->{time_in_river} == 1)); |
|
|
|
100
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
332
|
100
|
100
|
|
|
803
|
return if (($node_to_pass->{node_name} eq 'net') && ($self->{mature})); |
58
|
326
|
100
|
100
|
|
|
715
|
return if (($node_to_pass->{node_name} eq 'current') && (!$self->{mature})); |
59
|
|
|
|
|
|
|
|
60
|
323
|
100
|
100
|
|
|
806
|
if (($node_to_pass->{node_name} eq 'bear') && ($self->{mature})){ |
61
|
19
|
|
|
|
|
54
|
$self->kill(); |
62
|
19
|
|
|
|
|
87
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
304
|
100
|
100
|
|
|
651
|
if (($node_to_pass->{node_name} eq 'young bear') && ($self->{mature})){ |
66
|
4
|
100
|
|
|
|
21
|
if ($node_to_pass->every_other()){ |
67
|
2
|
|
|
|
|
6
|
$self->kill(); |
68
|
2
|
|
|
|
|
9
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
302
|
100
|
100
|
|
|
709
|
if (($node_to_pass->{node_name} eq 'bird') && (!$self->{mature})){ |
73
|
2
|
|
|
|
|
5
|
$self->kill(); |
74
|
2
|
|
|
|
|
9
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
300
|
100
|
100
|
|
|
771
|
if (($node_to_pass->{node_name} eq 'force field') && ($node_to_pass->{power})){ |
78
|
15
|
100
|
|
|
|
32
|
if ($self->{upstream}){ |
79
|
5
|
|
|
|
|
11
|
$self->spawn($node_to_pass); |
80
|
|
|
|
|
|
|
}else{ |
81
|
10
|
|
|
|
|
43
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
## |
86
|
|
|
|
|
|
|
## do we have a new river to swim into? |
87
|
|
|
|
|
|
|
## |
88
|
|
|
|
|
|
|
|
89
|
290
|
100
|
|
|
|
514
|
if (defined($river_target)){ |
90
|
|
|
|
|
|
|
|
91
|
147
|
|
|
|
|
313
|
$self->{location} = $river_target; |
92
|
147
|
|
|
|
|
652
|
$self->{time_in_river} = 0; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
}else{ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# if there's nowhere to go, |
97
|
|
|
|
|
|
|
# either spawn or print |
98
|
|
|
|
|
|
|
|
99
|
143
|
100
|
|
|
|
238
|
if ($self->{upstream}){ |
100
|
79
|
|
|
|
|
184
|
$self->spawn($node_to_pass); |
101
|
|
|
|
|
|
|
}else{ |
102
|
64
|
|
|
|
|
129
|
$self->output(); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub spawn { |
109
|
84
|
|
|
84
|
0
|
107
|
my ($self, $spring) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#print "spawning in river ".$self->{location}->{uid}." from node ".$spring->debug()."\n"; |
112
|
|
|
|
|
|
|
|
113
|
84
|
100
|
|
|
|
170
|
my $value = ($spring->{spring})?$spring->{node_name}:'nameless'; |
114
|
84
|
|
|
|
|
524
|
my $new_salmon = new Language::Homespring::Salmon({ |
115
|
|
|
|
|
|
|
'interp' => $self->{interp}, |
116
|
|
|
|
|
|
|
'value' => $value, |
117
|
|
|
|
|
|
|
'upstream' => 0, |
118
|
|
|
|
|
|
|
'mature' => 0, |
119
|
|
|
|
|
|
|
'location' => $self->{location}, |
120
|
|
|
|
|
|
|
}); |
121
|
84
|
|
|
|
|
194
|
push @{$self->{interp}->{new_salmon}}, $new_salmon; |
|
84
|
|
|
|
|
246
|
|
122
|
84
|
|
|
|
|
115
|
$self->{upstream} = 0; |
123
|
84
|
|
|
|
|
333
|
$self->{mature} = 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub output { |
127
|
64
|
|
|
64
|
0
|
76
|
my ($self) = @_; |
128
|
64
|
|
|
|
|
132
|
$self->{interp}->{output} .= $self->{value}; |
129
|
64
|
|
|
|
|
241
|
$self->kill(); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub kill { |
133
|
87
|
|
|
87
|
0
|
97
|
my ($self) = @_; |
134
|
87
|
|
|
|
|
119
|
$self->{value} = 'DEAD'; |
135
|
87
|
|
|
|
|
96
|
push @{$self->{interp}->{dead_salmon}}, $_; |
|
87
|
|
|
|
|
409
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub debug { |
139
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
140
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
return "salmon $self->{uid} in river ".$self->{location}->{uid}." (" |
|
|
0
|
|
|
|
|
|
142
|
|
|
|
|
|
|
.(($self->{mature})?'mature':'young') |
143
|
|
|
|
|
|
|
.") swimming " |
144
|
|
|
|
|
|
|
.(($self->{upstream})?'upsteam':'downstream') |
145
|
|
|
|
|
|
|
."\n"; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|