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.7 by root, Fri Mar 31 22:47:19 2006 UTC vs.
Revision 1.14 by root, Fri Sep 8 16:22:14 2006 UTC

6 6
7sub result { 7sub result {
8 my ($ob, $status) = @_; 8 my ($ob, $status) = @_;
9 9
10 if (my $teleport = $ob->{options}{"teleport_$status"}) { 10 if (my $teleport = $ob->{options}{"teleport_$status"}) {
11 my ($x, $y) = split /,/, $teleport; 11 my ($x, $y, $damned) = split /,/, $teleport;
12 my $pl = cf::player::find $ob->{player};
12 13
13 (cf::player::find $ob->{player})->ob->transfer ($x, $y); 14 $pl->ob->transfer ($x, $y);
15 $pl->savebed ($pl->ob->map->path, $x, $y)
16 if $ob->{options}{"set_savebed_$status"};
14 } 17 }
15} 18}
16 19
17sub apply { 20sub apply {
18 my ($who) = @_; 21 my ($who) = @_;
25 my ($x, $y) = ($who->x - $meta->x, $who->y - $meta->y); 28 my ($x, $y) = ($who->x - $meta->x, $who->y - $meta->y);
26 29
27 $who->{visible} = 1; 30 $who->{visible} = 1;
28 31
29 if ($who->{bomb}) { 32 if ($who->{bomb}) {
30 result $meta, "failure"; 33 result $meta, "failure"
34 if $meta->{todo};
31 } else { 35 } else {
32 $meta->{todo}--; 36 $meta->{todo}--;
33 # if zero, finished 37 # if <= 0, finished
34 38
35 my @neigh; 39 my @neigh;
36 40
37 for my $y ($y - 1 .. $y + 1) { 41 for my $y ($y - 1 .. $y + 1) {
38 next if $y < 0 || $y > $#{$map->[0]}; 42 next if $y < 0 || $y > $#{$map->[0]};
57 } 61 }
58 62
59 1 63 1
60} 64}
61 65
62sub on_time { 66cf::register_attachment minesweeper =>
63 my ($event, $who) = @_; 67 on_tick => sub {
68 my ($self) = @_;
64 69
65 if (my $queue = $who->{queue}) { 70 if (my $queue = $self->{queue}) {
66 my $count = 4; 71 my $count = 4;
67 72
68 while (@$queue) { 73 while (@$queue) {
69 my $i = int rand @$queue; 74 my $i = int rand @$queue;
70 my $ob = splice @$queue, $i, 1, (); 75 my $ob = splice @$queue, $i, 1, ();
71 76
72 next if $ob->{visible}; 77 next if $ob->{visible};
73 78
74 apply $ob 79 apply $ob
75 or next; 80 or next;
76 81
77 result $who, "success" 82 result $self, "success"
78 unless $who->{todo}; 83 unless $self->{todo};
79 84
80 $count-- 85 $count--
81 or last; 86 or last;
82 } 87 }
83 } else { 88 } else {
84 # generate minesweeper field 89 my %arg = %{ $self->{options} = delete $self->{minesweeper} };
85 my %arg = split /(?:\s+|=)/, $event->options; 90 $self->{queue} = [];
86 91
87 $who->{options} = \%arg; 92 my $map = $self->{map} = [];
88 $who->{queue} = [];
89 93
90 my $map = $who->{map} = []; 94 for my $x (0 .. $arg{width} - 1) {
95 for my $y (0 .. $arg{height} - 1) {
96 my $ob = $map->[$x][$y] = cf::object::new "minesweeper-unknown";
97 $ob->name ("apply to try your luck or intelligence");
98 Scalar::Util::weaken ($ob->{meta} = $self);
91 99
92 for my $x (0 .. $arg{width} - 1) { 100 $ob->attach ("minesweeper_field");
93 for my $y (0 .. $arg{height} - 1) { 101 $ob->insert_ob_in_map_at ($self->map, undef, cf::INS_ABOVE_FLOOR_ONLY,
94 my $ob = $map->[$x][$y] = cf::object::new "minesweeper-unknown"; 102 $self->x + $x, $self->y + $y);
95 $ob->set_name ("apply to try your luck or intelligence"); 103 }
96 Scalar::Util::weaken ($ob->{meta} = $who); 104 }
97 105
98 my $ev = cf::object::new "event_apply"; 106 # #tiles that need to be uncovered
99 $ev->set_title ("perl"); 107 $self->{todo} = $arg{width} * $arg{height} - $arg{bombs};
100 $ev->set_slaying ("minesweeper"); 108
101 $ev->insert_in_ob ($ob); 109 for (1 .. $arg{bombs}) {
102 110 my $x = int rand $arg{width};
103 $ob->insert_ob_in_map_at ($who->map, undef, cf::INS_ABOVE_FLOOR_ONLY, 111 my $y = int rand $arg{height};
104 $who->x + $x, $who->y + $y); 112
113 redo if $map->[$x][$y]{bomb};
114
115 $map->[$x][$y]{bomb} = 1;
105 } 116 }
106 } 117 }
107 118
108 # #tiles that need to be uncovered 119 cf::override;
109 $who->{todo} = $arg{width} * $arg{height} - $arg{bombs}; 120 },
121;
110 122
111 for (1 .. $arg{bombs}) { 123cf::register_attachment minesweeper_field =>
112 my $x = int rand $arg{width}; 124 on_apply => sub {
113 my $y = int rand $arg{height}; 125 my ($ob, $who) = @_;
114 126
115 redo if $map->[$x][$y]{bomb}; 127 $ob->{meta}{player} = $who->name;
128 push @{$ob->{meta}{queue}}, $ob;
116 129
117 $map->[$x][$y]{bomb} = 1; 130 cf::override 1;
118 }
119 } 131 },
120} 132;
121 133
122sub on_apply {
123 my ($event, $ob, $who) = @_;
124
125 $ob->{meta}{player} = $who->name;
126 push @{$ob->{meta}{queue}}, $ob;
127
128 1
129}
130
131

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines