Package horizons :: Package world :: Class World
[hide private]
[frames] | no frames]

Class World

source code

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

The World class represents an Unknown Horizons map with all its units, grounds, buildings, etc.

It inherits from BuildingOwner, among other things, so it has building management capabilities.
There is always one big reference per building, which is stored in either the world, the island,
or the settlement.

The main components of the world are:
   * players - a list of all the session's players - Player instances
   * islands - a list of all the map's islands - Island instances
   * grounds - a list of all the map's groundtiles
   * ground_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.
   * island_map - a dictionary that binds tuples of coordinates with a reference to the island
   * ships - a list of all the ships ingame - horizons.world.units.ship.Ship instances
   * ship_map - same as ground_map, but for ships
   * session - reference to horizons.session.Session instance of the current game
   * trader - The world's ingame free trader player instance (can control multiple ships)
   * pirate - The world's ingame pirate player instance
   TUTORIAL: You should now check out the _init() function.

Instance Methods [hide private]
 
__init__(self, session) source code
 
end(self) source code
 
_init(self, savegame_db, force_player_id=None, disasters_enabled=True) source code
 
_load_combat(self, savegame_db) source code
 
_load_diplomacy(self, savegame_db) source code
 
_load_disasters(self, savegame_db) source code
 
load_raw_map(self, savegame_db, preview=False) source code
 
_load_players(self, savegame_db, force_player_id) source code
 
_init_water_bodies(self)
This function runs the flood fill algorithm on the water to make it easy to recognize different water bodies.
source code
 
_init_shallow_water_bodies(self)
This function runs the flood fill algorithm on the water and the coast to make it easy to recognise different water bodies for fishers.
source code
 
init_fish_indexer(self) source code
 
init_new_world(self, trader_enabled, pirate_enabled, natural_resource_multiplier)
This should be called if a new map is loaded (not a savegame, a fresh map).
source code
 
_add_nature_objects(self, natural_resource_multiplier) source code
 
set_forced_player(self, force_player_id) source code
 
get_random_possible_ground_unit_position(self)
Returns a random position upon an island.
source code
 
get_random_possible_ship_position(self)
Returns a random position in water that is not at the border of the world.
source code
 
get_random_possible_coastal_ship_position(self)
Returns a random position in water that is not at the border of the world but on the coast of an island.
source code
 
get_tiles_in_radius(self, position, radius, shuffle=False)
Returns all tiles in the radius around the point.
source code
 
get_points_in_radius(self, position, radius, shuffle=False)
Returns all points in the radius around the point.
source code
 
setup_player(self, id, name, color, clientid, local, is_ai, difficulty_level)
Sets up a new Player instance and adds her to the active world.
source code
 
get_tile(self, point)
Returns the ground at x, y.
source code
 
settlements(self)
Returns all settlements on world
source code
 
get_island(self, point)
Returns the island for that coordinate.
source code
 
get_island_tuple(self, tup)
Overloaded from above
source code
 
get_islands_in_radius(self, point, radius)
Returns all islands in a certain radius around a point.
source code
 
get_warehouses(self, position=None, radius=None, owner=None, include_tradeable=False)
Returns all warehouses on the map, optionally only those in range around the specified position.
source code
 
get_ships(self, position=None, radius=None)
Returns all ships on the map, optionally only those in range around the specified position.
source code
 
get_ground_units(self, position=None, radius=None)
@see get_ships
source code
 
get_buildings(self, position=None, radius=None)
@see get_ships
source code
 
get_all_buildings(self)
Yields all buildings independent of owner
source code
 
get_health_instances(self, position=None, radius=None)
Returns all instances that have health
source code
 
save(self, db)
Saves the current game to the specified db.
source code
 
get_checkup_hash(self)
Returns a collection of important game state values.
source code
 
toggle_owner_highlight(self) source code
 
toggle_translucency(self)
Make certain building types translucent
source code
 
toggle_health_for_all_health_instances(self) source code
    Inherited from buildingowner.BuildingOwner
 
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
 
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
 
remove_building(self, building) 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]
 
_recognize_water_bodies(cls, map_dict)
This function runs the flood fill algorithm on the water to make it easy to recognize different water bodies.
source code
    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")
Instance Variables [hide private]
  inited
TUTORIAL: To dig deeper, you should now continue to horizons/world/island.py, to check out how buildings and settlements are added to the map.
Method Details [hide private]

__init__(self, session)
(Constructor)

source code 
Parameters:
  • session (horizons.session.Session) - instance of session the world belongs to.
Overrides: util.changelistener.ChangeListener.__init__

end(self)

source code 
Overrides: util.changelistener.ChangeListener.end

_init(self, savegame_db, force_player_id=None, disasters_enabled=True)

source code 
Parameters:
  • savegame_db - Dbreader with loaded savegame database
  • force_player_id - the worldid of the selected human player or default if None (debug option)

init_new_world(self, trader_enabled, pirate_enabled, natural_resource_multiplier)

source code 

This should be called if a new map is loaded (not a savegame, a fresh
map). In other words, when it is loaded for the first time.

NOTE: commands for creating the world objects are executed directly,
      bypassing the manager.
      This is necessary because else the commands would be transmitted
      over the wire in network games.

@return: the coordinates of the players first ship

get_random_possible_ground_unit_position(self)

source code 

Returns a random position upon an island.

Returns:
Point

get_random_possible_ship_position(self)

source code 

Returns a random position in water that is not at the border of the world.

Returns:
Point

get_random_possible_coastal_ship_position(self)

source code 

Returns a random position in water that is not at the border of the world but on the coast of an island.

Returns:
Point

get_tiles_in_radius(self, position, radius, shuffle=False)

source code 

Returns all tiles in the radius around the point. This is a generator; make sure you use it appropriately.

Parameters:
  • position - Point instance @return List of tiles in radius.

get_points_in_radius(self, position, radius, shuffle=False)

source code 

Returns all points in the radius around the point. This is a generator; make sure you use it appropriately.

Parameters:
  • position - Point instance @return List of points in radius.

setup_player(self, id, name, color, clientid, local, is_ai, difficulty_level)

source code 

Sets up a new Player instance and adds her to the active world. Only used for new games. Loading old players is done in _init().

Parameters:
  • local - bool, whether the player is the one sitting on front of this machine.

get_tile(self, point)

source code 

Returns the ground at x, y.

Parameters:
  • point - coords as Point
Returns:
instance of Ground at x, y
Overrides: buildingowner.BuildingOwner.get_tile

settlements(self)

source code 

Returns all settlements on world

Decorators:
  • @property

get_island(self, point)

source code 

Returns the island for that coordinate. If none is found, returns None.

Parameters:
  • point - instance of Point

get_islands_in_radius(self, point, radius)

source code 

Returns all islands in a certain radius around a point. @return set of islands in radius

get_warehouses(self, position=None, radius=None, owner=None, include_tradeable=False)

source code 

Returns all warehouses on the map, optionally only those in range around the specified position.

Parameters:
  • position - Point or Rect instance.
  • radius - int radius to use.
  • owner - Player instance, list only warehouses belonging to this player. @param include_tradeable also list the warehouses the owner can trade with
Returns:
List of warehouses.

get_ships(self, position=None, radius=None)

source code 

Returns all ships on the map, optionally only those in range around the specified position.

Parameters:
  • position - Point or Rect instance.
  • radius - int radius to use.
Returns:
List of ships.

save(self, db)

source code 

Saves the current game to the specified db.

Parameters:
  • db - DbReader object of the db the game is saved to.
Overrides: util.worldobject.WorldObject.save

get_checkup_hash(self)

source code 

Returns a collection of important game state values. Used to check if two mp games have diverged. Not designed to be reliable.