ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/maps/perl/map-grid-move-torus.ext
Revision: 1.1
Committed: Fri Feb 10 07:37:13 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

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