some bugs with json fixed
[aymargeddon/current.git] / src / FROGS / Map.pm
1 ##########################################################################
2 #
3 #   Copyright (c) 2003-2012 Aymargeddon Development Team
4 #
5 #   This file is part of "Last days of Aymargeddon" - a massive multi player
6 #   onine game of strategy      
7 #   
8 #        This program is free software: you can redistribute it and/or modify
9 #        it under the terms of the GNU Affero General Public License as
10 #        published by the Free Software Foundation, either version 3 of the
11 #        License, or (at your option) any later version.
12 #    
13 #        This program is distributed in the hope that it will be useful,
14 #        but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 #
17 #    See the GNU Affero General Public License for more details.
18 #    
19 #    You should have received a copy of the GNU Affero General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #    
22 ###########################################################################
23 #
24
25 #
26 # This file holds a baseclass for the topology of the game.
27 # All methods here are independent of a concrete topology. 
28 # but they require, that such dependent functions exists,
29 # so this base class did not work if there is no derived class.
30 #
31 # Derived classes have to implement the following functions
32 #
33 # grep() - return a list of all locations with true evaluation of sub
34 # neighbours() - returns a list of all neigbours of location
35 # distance() - returns the distance between two locations
36 #
37 # have a look at HexTorus.pm to see an example
38
39
40 package Map;
41
42 use strict;
43
44 # returns all locations
45 sub get_all{
46     my $self = shift;
47
48     return $self->grep(sub{1;});
49 }
50
51 # returns all locations with distance <= dist arround loc
52 sub distant_neighbours{
53     my ($self,$loc,$dist) = @_;
54
55     # for performance reason
56     # TODO: do this only, if neighbours() is avaiable in the derived class
57     return $self->neighbours($loc) if $dist == 1;
58
59     return $self->grep(sub{
60         my $loc2 = shift;
61         return $self->distance($loc,$loc2) <= $dist;});
62
63 }
64
65 1;
66
67