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.10 by root, Fri Aug 25 15:07:43 2006 UTC vs.
Revision 1.15 by root, Tue Dec 12 16:59:34 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines