ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-grid-move-torus.ext
Revision: 1.3
Committed: Tue May 4 21:45:42 2010 UTC (14 years ago) by root
Branch: MAIN
CVS Tags: rel-3_1, rel-3_0, HEAD
Changes since 1.2: +0 -2 lines
Log Message:
*** empty log message ***

File Contents

# 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 <= cf::rndm) {
29 # horizontal
30
31 my $y = $y1 + cf::rndm $self->{height};
32
33 my @ass = map [grep $_->remove || 1, $who->map->at ($_, $y)], $x1 .. $x1 + $self->{width} - 1;
34
35 if (0.5 <= cf::rndm) {
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 + cf::rndm $self->{width};
47
48 my @ass = map [grep $_->remove || 1, $who->map->at ($x, $_)], $y1 .. $y1 + $self->{height} - 1;
49
50 if (0.5 <= cf::rndm) {
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