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

Comparing deliantra/server/ext/minesweeper.ext (file contents):
Revision 1.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.8 by root, Wed Dec 16 21:36:20 2009 UTC

1#! perl 1#! perl # mandatory
2 2
3use Scalar::Util; 3use Scalar::Util;
4 4
5# minesweeper extension. dumb. 5# minesweeper extension. dumb.
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, $damned) = split /,/, $teleport; 11 my ($x, $y, $damned) = split /,/, $teleport;
12 my $pl = cf::player::find $ob->{player}; 12 my $pl = cf::player::find_active $ob->{player};
13 13
14 $pl->ob->transfer ($x, $y); 14 my $path = $pl->ob->map->path;
15
16 $pl->ob->goto ($path, $x, $y);
15 $pl->savebed ($pl->ob->map->path, $x, $y) 17 $pl->savebed ($path, $x, $y)
16 if $ob->{options}{"set_savebed_$status"}; 18 if $ob->{options}{"set_savebed_$status"};
17 } 19 }
18} 20}
19 21
20sub apply { 22sub apply {
60 } 62 }
61 63
62 1 64 1
63} 65}
64 66
65cf::register_attachment minesweeper => 67cf::object::attachment minesweeper =>
66 on_tick => sub { 68 on_tick => sub {
67 my ($self) = @_; 69 my ($self) = @_;
68 70
69 if (my $queue = $self->{queue}) { 71 if (my $queue = $self->{queue}) {
70 my $count = 4; 72 my $count = 4;
92 94
93 for my $x (0 .. $arg{width} - 1) { 95 for my $x (0 .. $arg{width} - 1) {
94 for my $y (0 .. $arg{height} - 1) { 96 for my $y (0 .. $arg{height} - 1) {
95 my $ob = $map->[$x][$y] = cf::object::new "minesweeper-unknown"; 97 my $ob = $map->[$x][$y] = cf::object::new "minesweeper-unknown";
96 $ob->name ("apply to try your luck or intelligence"); 98 $ob->name ("apply to try your luck or intelligence");
97 Scalar::Util::weaken ($ob->{meta} = $self); 99 cf::weaken ($ob->{meta} = $self);
98 100
99 $ob->attach ("minesweeper_field"); 101 $ob->attach ("minesweeper_field");
100 $ob->insert_ob_in_map_at ($self->map, undef, cf::INS_ABOVE_FLOOR_ONLY, 102 $ob->insert_ob_in_map_at ($self->map, undef, cf::INS_ABOVE_FLOOR_ONLY,
101 $self->x + $x, $self->y + $y); 103 $self->x + $x, $self->y + $y);
102 } 104 }
104 106
105 # #tiles that need to be uncovered 107 # #tiles that need to be uncovered
106 $self->{todo} = $arg{width} * $arg{height} - $arg{bombs}; 108 $self->{todo} = $arg{width} * $arg{height} - $arg{bombs};
107 109
108 for (1 .. $arg{bombs}) { 110 for (1 .. $arg{bombs}) {
109 my $x = int rand $arg{width}; 111 my $x = cf::rndm $arg{width};
110 my $y = int rand $arg{height}; 112 my $y = cf::rndm $arg{height};
111 113
112 redo if $map->[$x][$y]{bomb}; 114 redo if $map->[$x][$y]{bomb};
113 115
114 $map->[$x][$y]{bomb} = 1; 116 $map->[$x][$y]{bomb} = 1;
115 } 117 }
117 119
118 cf::override; 120 cf::override;
119 }, 121 },
120; 122;
121 123
122cf::register_attachment minesweeper_field => 124cf::object::attachment minesweeper_field =>
123 on_apply => sub { 125 on_apply => sub {
124 my ($ob, $who) = @_; 126 my ($ob, $who) = @_;
125 127
126 $ob->{meta}{player} = $who->name; 128 $ob->{meta}{player} = $who->name;
127 push @{$ob->{meta}{queue}}, $ob; 129 push @{$ob->{meta}{queue}}, $ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines