Package horizons :: Package world :: Module island :: Class Island
[hide private]
[frames] | no frames]

Class Island

source code

           buildingowner.BuildingOwner --+
                                         |
util.changelistener.ChangeListener --+   |
                                     |   |
          util.worldobject.WorldObject --+
                                         |
                                        Island

The Island class represents an island. It contains a list of all things on the map
that belong to the island. This comprises ground tiles as well as buildings,
nature objects (which are buildings), and units.
All those objects also have a reference to the island, making it easy to determine to which island the instance belongs.
An Island instance is created during map creation, when all tiles are added to the map.
@param origin: Point instance - Position of the (0, 0) ground tile.
@param filename: file from which the island is loaded.

Each island holds some important attributes:
* grounds - All ground tiles that belong to the island are referenced here.
* grounds_map -  a dictionary that binds tuples of coordinates with a reference to the tile:
                  { (x, y): tileref, ...}
                                  This is important for pathfinding and quick tile fetching.
* position - a Rect that borders the island with the smallest possible area.
* buildings - a list of all Building instances that are present on the island.
* settlements - a list of all Settlement instances that are present on the island.
* path_nodes - a special dictionary used by the pather to save paths.

TUTORIAL:
Why do we use a separate __init() function, and do not use the __init__() function?
Simple: if we load the game, the class is not loaded as a new instance, so the __init__
function is not called. Rather, the load function is called, so everything that new
classes and loaded classes share to initialize goes into the __init() function.
This is the common way of doing this in Unknown Horizons, so better get used to it :)
NOTE: The components work a bit different, but this code here is mostly not component oriented.

To continue hacking, check out the __init() function now.

Instance Methods [hide private]
 
__init__(self, db, island_id, session, preview=False) source code
 
__init(self, db, island_id, preview)
Load the actual island from a file
source code
 
save(self, db) source code
 
get_coordinates(self)
Returns list of coordinates, that are on the island.
source code
 
get_tile(self, point)
Returns whether a tile is on island or not.
source code
 
get_tile_tuple(self, tup)
Overloaded get_tile, takes a tuple as argument
source code
 
get_tiles_tuple(self, tuples)
Same as get_tile, but takes a list of tuples.
source code
 
add_settlement(self, position, radius, player)
Adds a settlement to the island at the position x, y with radius as area of influence.
source code
 
add_existing_settlement(self, position, radius, settlement)
Same as add_settlement, but uses settlement from parameter.
source code
 
assign_settlement(self, position, radius, settlement)
Assigns the settlement property to tiles within the circle defined by position and radius.
source code
 
abandon_buildings(self, buildings_list)
Abandon all buildings in the list
source code
 
remove_settlement(self, building)
Removes the settlement property from tiles within the radius of the given building
source code
 
add_building(self, building, player, load=False)
Adds a building to the island at the position x, y with player as the owner.
source code
 
remove_building(self, building) source code
 
get_building_index(self, resource_id) source code
 
get_surrounding_tiles(self, where, radius=1, include_corners=True)
Returns tiles around point with specified radius.
source code
 
get_tiles_in_radius(self, location, radius, include_self)
Returns tiles in radius of location.
source code
 
__iter__(self) source code
 
check_wild_animal_population(self)
Creates a wild animal if they died out.
source code
 
_init_cache(self)
initializes the cache that knows when the last time the buildability of a rectangle may have changed on this island
source code
 
_register_change(self)
registers the possible buildability change of a rectangle on this island
source code
 
end(self) source code
    Inherited from buildingowner.BuildingOwner
 
get_building(self, point)
Returns the building at the point
source code
 
get_providers_in_range(self, radiusrect, res=None, reslist=None, player=None)
Returns all instances of provider within the specified shape.
source code
 
get_settlement(self, point)
Look for a settlement at a specific coordinate
source code
 
get_settlements(self, rect, player=None)
Returns the list of settlements for the coordinates describing a rect.
source code
    Inherited from util.worldobject.WorldObject
 
__lt__(self, other) source code
 
load(self, db, worldid) source code
 
remove(self) source code
    Inherited from util.changelistener.ChangeListener
 
_changed(self)
Calls every listener when an object changed
source code
 
add_change_listener(self, listener, call_listener_now=False, no_duplicates=False) source code
 
add_remove_listener(self, listener, no_duplicates=False)
A listener that listens for removal of the object
source code
 
clear_change_listeners(self)
Removes all change listeners
source code
 
discard_change_listener(self, listener)
Remove listener if it's there
source code
 
discard_remove_listener(self, listener) source code
 
has_change_listener(self, listener) source code
 
has_remove_listener(self, listener) source code
 
remove_change_listener(self, listener) source code
 
remove_remove_listener(self, listener) source code
Class Methods [hide private]
    Inherited from util.worldobject.WorldObject
 
get_object_by_id(cls, id)
Returns the worldobject with id id Throws WorldObjectNotFound with the worldid as arg.
source code
 
get_objs(cls) source code
 
reset(cls) source code
Class Variables [hide private]
  log = logging.getLogger("world.island")
Method Details [hide private]

__init__(self, db, island_id, session, preview=False)
(Constructor)

source code 
Parameters:
  • db - db instance with island table
  • island_id - id of island in that table
  • session - reference to Session instance
  • preview - flag, map preview mode
Overrides: util.changelistener.ChangeListener.__init__

__init(self, db, island_id, preview)

source code 

Load the actual island from a file

Parameters:
  • preview - flag, map preview mode

save(self, db)

source code 
Overrides: util.worldobject.WorldObject.save

get_tile(self, point)

source code 

Returns whether a tile is on island or not.

Parameters:
  • point - Point contains position of the tile.
Returns:
tile instance if tile is on island, else None.
Overrides: buildingowner.BuildingOwner.get_tile

get_tiles_tuple(self, tuples)

source code 

Same as get_tile, but takes a list of tuples.

Parameters:
  • tuples - iterable of tuples
Returns:
iterable of map tiles

add_settlement(self, position, radius, player)

source code 

Adds a settlement to the island at the position x, y with radius as area of influence.

Parameters:
  • position - Rect describing the position of the new warehouse
  • radius - int radius of the area of influence.
  • player - int id of the player that owns the settlement

add_existing_settlement(self, position, radius, settlement)

source code 

Same as add_settlement, but uses settlement from parameter. May also be called for extension of an existing settlement by a new building (this is useful for loading, where every loaded building extends the radius of its settlement).

Parameters:
  • position - Rect
  • load - whether it has been called during load

assign_settlement(self, position, radius, settlement)

source code 

Assigns the settlement property to tiles within the circle defined by position and radius.

Parameters:
  • position - Rect
  • radius
  • settlement

abandon_buildings(self, buildings_list)

source code 

Abandon all buildings in the list

Parameters:
  • buildings_list - buildings to abandon

add_building(self, building, player, load=False)

source code 

Adds a building to the island at the position x, y with player as the owner.

Parameters:
  • building - Building class instance of the building that is to be added.
  • player - int id of the player that owns the settlement
  • load - boolean, whether it has been called during loading
Overrides: buildingowner.BuildingOwner.add_building

remove_building(self, building)

source code 
Overrides: buildingowner.BuildingOwner.remove_building

get_surrounding_tiles(self, where, radius=1, include_corners=True)

source code 

Returns tiles around point with specified radius.

Parameters:
  • where - instance of Point, or object with get_surrounding()

get_tiles_in_radius(self, location, radius, include_self)

source code 

Returns tiles in radius of location. This is a generator.

Parameters:
  • location - anything that supports get_radius_coordinates (usually Rect).
  • include_self - bool, whether to include the coordinates in location

end(self)

source code 
Overrides: util.changelistener.ChangeListener.end