ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-grid-move-torus.ext
Revision: 1.2
Committed: Thu Apr 22 12:50:24 2010 UTC (14 years, 1 month ago) by root
Branch: MAIN
Changes since 1.1: +5 -5 lines
Log Message:
update to use newer cf::rndm and AE::Now

File Contents

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