ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/map-grid-move-torus.ext
Revision: 1.5
Committed: Fri Dec 15 19:11:46 2006 UTC (17 years, 5 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -0 lines
State: FILE REMOVED
Log Message:
move .ext to server

File Contents

# User Rev Content
1 root 1.1 #! perl
2 root 1.4 #CONVERSION: NONE
3 root 1.1
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 root 1.2 my ($event, $who) = @_;
15 root 1.1
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 root 1.2 split /(?:\s+|=)/, $event->options,
21 root 1.1 };
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