Revision: | 1.1 |
Committed: | Fri Dec 15 19:29:18 2006 UTC (17 years, 7 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_2, rel-2_3, rel-2_0, rel-2_1, 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 |
Log Message: | moved perl extensions into server codebase, where they belong |
# | Content |
---|---|
1 | #! perl |
2 | #CONVERSION: NONE |
3 | |
4 | use List::Util; |
5 | |
6 | sub set_stack { |
7 | my ($map, $x, $y, $as) = @_; |
8 | |
9 | $_->insert_ob_in_map_at ($map, $_, cf::INS_ON_TOP, $x, $y) |
10 | for @$as; |
11 | } |
12 | |
13 | sub on_move { |
14 | my ($event, $who) = @_; |
15 | |
16 | # on first call (there is no initialiser callback), initialise |
17 | my $self = $who->{map_grid_move} ||= { |
18 | x1 => $who->x, |
19 | y1 => $who->y, |
20 | split /(?:\s+|=)/, $event->options, |
21 | }; |
22 | |
23 | my ($x1, $y1) = ($self->{x1}, $self->{y1}); |
24 | |
25 | # this is horribly ugly code.. why can't there be a simple function to just move objects, |
26 | # instead of having 20+ of them that all crash in different ways. |
27 | |
28 | if (0.5 <= rand) { |
29 | # horizontal |
30 | |
31 | my $y = $y1 + int rand $self->{height}; |
32 | |
33 | my @ass = map [grep $_->remove || 1, $who->map->at ($_, $y)], $x1 .. $x1 + $self->{width} - 1; |
34 | |
35 | if (0.5 <= rand) { |
36 | my $as = pop @ass; unshift @ass, $as; |
37 | } else { |
38 | my $as = shift @ass; push @ass, $as; |
39 | } |
40 | |
41 | set_stack $who->map, $_, $y, $ass[$_ - $x1] for $x1 .. $x1 + $self->{width} - 1; |
42 | |
43 | } else { |
44 | # vertical |
45 | |
46 | my $x = $x1 + int rand $self->{width}; |
47 | |
48 | my @ass = map [grep $_->remove || 1, $who->map->at ($x, $_)], $y1 .. $y1 + $self->{height} - 1; |
49 | |
50 | if (0.5 <= rand) { |
51 | my $as = pop @ass; unshift @ass, $as; |
52 | } else { |
53 | my $as = shift @ass; push @ass, $as; |
54 | } |
55 | |
56 | set_stack $who->map, $x, $_, $ass[$_ - $y1] for $y1 .. $y1 + $self->{height} - 1; |
57 | |
58 | } |
59 | |
60 | 1 |
61 | } |
62 | |
63 | |
64 |