Revision: | 1.2 |
Committed: | Sun Sep 30 16:24:29 2007 UTC (16 years, 9 months ago) by root |
Branch: | MAIN |
CVS Tags: | rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_3, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, rel-2_52, rel-2_53, rel-2_32, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, rel-2_43, rel-2_42, rel-2_41 |
Changes since 1.1: | +1 -1 lines |
Log Message: | finally remove the old buggy plug-in cruft |
# | Content |
---|---|
1 | #! perl |
2 | #CONVERSION: NONE |
3 | |
4 | use List::Util; |
5 | |
6 | sub on_move { |
7 | my ($event, $who) = @_; |
8 | |
9 | my ($x1, $y1) = ($who->x, $who->y); |
10 | |
11 | # on first call (there is no initialiser callback), initialise |
12 | my $self = $who->{map_grid_move} ||= do { |
13 | my %opt = split /(?:\s+|=)/, $event->options; |
14 | |
15 | for my $ob ($who->inv) { |
16 | my $num = $opt{"num_" . $ob->name} || 1; |
17 | |
18 | for (1 .. $num) { |
19 | my $ob = $ob->clone (0); |
20 | |
21 | $who->map->insert ($ob, $x1 + rand $opt{width}, $y1 + rand $opt{height}); |
22 | |
23 | push @{ $opt{ob} }, $ob; |
24 | } |
25 | } |
26 | |
27 | \%opt |
28 | }; |
29 | |
30 | my ($x2, $y2) = ($x1 + $self->{width} - 1, $y1 + $self->{height} - 1); |
31 | |
32 | for my $ob (@{$self->{ob}}) { |
33 | my ($x, $y) = ($ob->x, $ob->y); |
34 | |
35 | if (0.5 <= rand) { |
36 | $x += 1 - int rand 3; |
37 | } else { |
38 | $y += 1 - int rand 3; |
39 | } |
40 | |
41 | $x = List::Util::max $x1, List::Util::min $x2, $x; |
42 | $y = List::Util::max $y1, List::Util::min $y2, $y; |
43 | |
44 | $ob->remove; |
45 | $ob->insert_ob_in_map_at ($ob->map, undef, cf::INS_ABOVE_FLOOR_ONLY, $x, $y); |
46 | } |
47 | |
48 | 1 |
49 | } |
50 | |
51 | |
52 |