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.3 by root, Fri Mar 17 02:40:09 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 =>
67 on_tick => sub {
63 my ($event) = @_; 68 my ($self) = @_;
64 69
65 my $who = $event->{who}; 70 if (my $queue = $self->{queue}) {
71 my $count = 4;
66 72
67 if (my $queue = $who->{queue}) { 73 while (@$queue) {
68 my $count = 4; 74 my $i = int rand @$queue;
75 my $ob = splice @$queue, $i, 1, ();
69 76
70 while (@$queue) { 77 next if $ob->{visible};
71 my $i = int rand @$queue;
72 my $ob = splice @$queue, $i, 1, ();
73 78
74 next if $ob->{visible}; 79 apply $ob
80 or next;
75 81
76 apply $ob 82 result $self, "success"
77 or next; 83 unless $self->{todo};
78 84
79 result $who, "success" 85 $count--
80 unless $who->{todo}; 86 or last;
87 }
88 } else {
89 my %arg = %{ $self->{options} = delete $self->{minesweeper} };
90 $self->{queue} = [];
81 91
82 $count-- 92 my $map = $self->{map} = [];
83 or last;
84 }
85 } else {
86 # generate minesweeper field
87 my %arg = split /(?:\s+|=)/, $event->{options};
88 93
89 $who->{options} = \%arg; 94 for my $x (0 .. $arg{width} - 1) {
90 $who->{queue} = []; 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 my $map = $who->{map} = []; 100 $ob->attach ("minesweeper_field");
101 $ob->insert_ob_in_map_at ($self->map, undef, cf::INS_ABOVE_FLOOR_ONLY,
102 $self->x + $x, $self->y + $y);
103 }
104 }
93 105
94 for my $x (0 .. $arg{width} - 1) { 106 # #tiles that need to be uncovered
95 for my $y (0 .. $arg{height} - 1) { 107 $self->{todo} = $arg{width} * $arg{height} - $arg{bombs};
96 my $ob = $map->[$x][$y] = cf::object::new "minesweeper-unknown";
97 $ob->set_name ("apply to try your luck or intelligence");
98 Scalar::Util::weaken ($ob->{meta} = $who);
99 108
100 my $ev = cf::object::new "event_apply"; 109 for (1 .. $arg{bombs}) {
101 $ev->set_title ("perl"); 110 my $x = int rand $arg{width};
102 $ev->set_slaying ("minesweeper"); 111 my $y = int rand $arg{height};
103 $ev->insert_in_ob ($ob); 112
104 113 redo if $map->[$x][$y]{bomb};
105 $ob->insert_ob_in_map_at ($who->map, undef, cf::INS_ABOVE_FLOOR_ONLY, 114
106 $who->x + $x, $who->y + $y); 115 $map->[$x][$y]{bomb} = 1;
107 } 116 }
108 } 117 }
109 118
110 # #tiles that need to be uncovered 119 cf::override;
111 $who->{todo} = $arg{width} * $arg{height} - $arg{bombs}; 120 },
121;
112 122
113 for (1 .. $arg{bombs}) { 123cf::register_attachment minesweeper_field =>
114 my $x = int rand $arg{width}; 124 on_apply => sub {
115 my $y = int rand $arg{height}; 125 my ($ob, $who) = @_;
116 126
117 redo if $map->[$x][$y]{bomb}; 127 $ob->{meta}{player} = $who->name;
128 push @{$ob->{meta}{queue}}, $ob;
118 129
119 $map->[$x][$y]{bomb} = 1; 130 cf::override 1;
120 }
121 } 131 },
122} 132;
123 133
124sub on_apply {
125 my ($event) = @_;
126
127 my $who = $event->{who};
128 my $activator = $event->{activator};
129
130 $who->{meta}{player} = $activator->name;
131 push @{$who->{meta}{queue}}, $who;
132}
133
134

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines