1 ##########################################################################
3 # Copyright (c) 2003-2012 Aymargeddon Development Team
5 # This file is part of "Last days of Aymargeddon" - a massive multi player
6 # onine game of strategy
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.
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.
17 # See the GNU Affero General Public License for more details.
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/>.
22 ###########################################################################
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.
31 # Derived classes have to implement the following functions
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
37 # have a look at HexTorus.pm to see an example
44 # returns all locations
48 return $self->grep(sub{1;});
51 # returns all locations with distance <= dist arround loc
52 sub distant_neighbours{
53 my ($self,$loc,$dist) = @_;
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;
59 return $self->grep(sub{
61 return $self->distance($loc,$loc2) <= $dist;});