Package horizons :: Module session :: Class Session
[hide private]
[frames] | no frames]

Class Session

source code --+

The Session class represents the game's main ingame view and controls cameras and map loading.
It is alive as long as a game is running.
Many objects require a reference to this, which makes it a pseudo-global, from which we would
like to move away in the long term. This is where we hope the components come into play, which
you will encounter later.

This is the most important class if you are going to hack on Unknown Horizons; it provides most of
the important ingame variables.
Here's a small list of commonly used attributes:

* world - instance of the currently running horizons. Stores players and islands,
        which store settlements, which store buildings, which have productions and collectors.
        Therefore, world deserves its name -- it contains the whole game state.
* scheduler - horizons.scheduler instance. Used to execute timed events. Master of time in UH.
* manager - horizons.manager instance. Used to execute commands (used to apply user interactions).
        There is a singleplayer and a multiplayer version. Our mp system works by the mp-manager not
        executing the commands directly, but sending them to all players, where they will be executed
        at the same tick.
* view - horizons.view instance. Used to control the ingame camera.
* ingame_gui - horizons.gui.ingame_gui instance. Used to control the ingame gui framework.
        (This is different from gui, which is the main menu and general session-independent gui)
* selected_instances - Set that holds the currently selected instances (building, units).

For further digging you should now be checking out the load() function.

Instance Methods [hide private]
__init__(self, db, rng_seed=None, ingame_gui_class=IngameGui) source code
Actually starts the game.
source code
(Re-)Set up autosave.
source code
_on_setting_changed(self, message) source code
Returns instance of command manager (currently MPManager or SPManager)
source code
create_rng(self, seed=None)
Returns a RNG (random number generator).
source code
Returns a Timer instance.
source code
Put all the code the object needs to end safely here.
source code
quit(self) source code
autosave(self) source code
quicksave(self) source code
quickload(self) source code
save(self, savegame=None) source code
load(self, options)
Loads a map.
source code
speed_set(self, ticks, suggestion=False)
Set game speed to ticks ticks per second
source code
speed_up(self) source code
speed_down(self) source code
speed_pause(self, suggestion=False) source code
speed_unpause(self, suggestion=False) source code
speed_toggle_pause(self, suggestion=False) source code
speed_is_paused(self) source code
Checks if the current game is a new one, or a loaded one.
source code
remove_selected(self) source code
_do_save(self, savegame)
Actual save code.
source code
Class Methods [hide private]
Clear all data caches in global namespace related to a session
source code
Class Variables [hide private]
  timer = livingProperty()
  manager = livingProperty()
  view = livingProperty()
  ingame_gui = livingProperty()
  scenario_eventhandler = livingProperty()
  log = logging.getLogger('session')
  _pause_stack = 0
Method Details [hide private]


source code 

(Re-)Set up autosave. Called if autosave interval has been changed.

create_rng(self, seed=None)

source code 

Returns a RNG (random number generator). Must support the python random.Random interface


source code 

Put all the code the object needs to end safely here. Make sure it always contains the super(YOUROBJECT, self).end() call, to ensure all parentobjects are deinited correctly.

(inherited documentation)

load(self, options)

source code 

Loads a map. Key method for starting a game.


source code 

Checks if the current game is a new one, or a loaded one.

True if game is loaded, else False

_do_save(self, savegame)

source code 

Actual save code.

  • savegame - absolute path