ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/minesweeper.ext
(Generate patch)

Comparing deliantra/maps/perl/minesweeper.ext (file contents):
Revision 1.4 by elmex, Fri Mar 24 23:29:18 2006 UTC vs.
Revision 1.10 by root, Fri Aug 25 15:07:43 2006 UTC

1#! perl 1#! perl
2#CONVERSION: NONE
2 3
3use Scalar::Util; 4use Scalar::Util;
4 5
5# minesweeper extension. dumb. 6# minesweeper extension. dumb.
6 7
7sub result { 8sub result {
8 my ($ob, $status) = @_; 9 my ($ob, $status) = @_;
9 10
10 if (my $teleport = $ob->{options}{"teleport_$status"}) { 11 if (my $teleport = $ob->{options}{"teleport_$status"}) {
11 my ($x, $y) = split /,/, $teleport; 12 my ($x, $y, $damned) = split /,/, $teleport;
13 my $pl = cf::player::find $ob->{player};
12 14
13 (cf::player::find $ob->{player})->ob->transfer ($x, $y); 15 $pl->ob->transfer ($x, $y);
16 $pl->set_savebed ($pl->ob->map->path, $x, $y)
17 if $ob->{options}{"set_savebed_$status"};
14 } 18 }
15} 19}
16 20
17sub apply { 21sub apply {
18 my ($who) = @_; 22 my ($who) = @_;
25 my ($x, $y) = ($who->x - $meta->x, $who->y - $meta->y); 29 my ($x, $y) = ($who->x - $meta->x, $who->y - $meta->y);
26 30
27 $who->{visible} = 1; 31 $who->{visible} = 1;
28 32
29 if ($who->{bomb}) { 33 if ($who->{bomb}) {
30 result $meta, "failure"; 34 result $meta, "failure"
35 if $meta->{todo};
31 } else { 36 } else {
32 $meta->{todo}--; 37 $meta->{todo}--;
33 # if zero, finished 38 # if <= 0, finished
34 39
35 my @neigh; 40 my @neigh;
36 41
37 for my $y ($y - 1 .. $y + 1) { 42 for my $y ($y - 1 .. $y + 1) {
38 next if $y < 0 || $y > $#{$map->[0]}; 43 next if $y < 0 || $y > $#{$map->[0]};
58 63
59 1 64 1
60} 65}
61 66
62sub on_time { 67sub on_time {
63 my ($event) = @_; 68 my ($event, $who) = @_;
64
65 my $who = $event->{who};
66 69
67 if (my $queue = $who->{queue}) { 70 if (my $queue = $who->{queue}) {
68 my $count = 4; 71 my $count = 4;
69 72
70 while (@$queue) { 73 while (@$queue) {
82 $count-- 85 $count--
83 or last; 86 or last;
84 } 87 }
85 } else { 88 } else {
86 # generate minesweeper field 89 # generate minesweeper field
87 my %arg = split /(?:\s+|=)/, $event->{options}; 90 my %arg = split /(?:\s+|=)/, $event->options;
88 91
89 $who->{options} = \%arg; 92 $who->{options} = \%arg;
90 $who->{queue} = []; 93 $who->{queue} = [];
91 94
92 my $map = $who->{map} = []; 95 my $map = $who->{map} = [];
117 redo if $map->[$x][$y]{bomb}; 120 redo if $map->[$x][$y]{bomb};
118 121
119 $map->[$x][$y]{bomb} = 1; 122 $map->[$x][$y]{bomb} = 1;
120 } 123 }
121 } 124 }
122 0
123} 125}
124 126
125sub on_apply { 127sub on_apply {
126 my ($event) = @_; 128 my ($event, $ob, $who) = @_;
127 129
128 my $who = $event->{who}; 130 $ob->{meta}{player} = $who->name;
129 my $activator = $event->{activator}; 131 push @{$ob->{meta}{queue}}, $ob;
130 132
131 $who->{meta}{player} = $activator->name;
132 push @{$who->{meta}{queue}}, $who;
133 0 133 1
134} 134}
135 135
136 136

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines