Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 326 lines (285 sloc) 12.385 kB
695bd53 did much...
spq authored
1 # ###################################################
c8e455c @nihathrael Changed 2010 -> 2011
nihathrael authored
2 # Copyright (C) 2011 The Unknown Horizons Team
844e05d * Renamed all accurances of OpenAnno to Unknown Horizons
nihathrael authored
3 # team@unknown-horizons.org
4 # This file is part of Unknown Horizons.
695bd53 did much...
spq authored
5 #
844e05d * Renamed all accurances of OpenAnno to Unknown Horizons
nihathrael authored
6 # Unknown Horizons is free software; you can redistribute it and/or modify
695bd53 did much...
spq authored
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
21
0249fda Implemented changeable limit for quicksaves
totycro authored
22 import os
faea683 supprt saving
spq authored
23 import os.path
8f620ee * Merged production_rework branch into trunk
nihathrael authored
24 import logging
4f84347 @totycro Save/load the rng state
totycro authored
25 import json
af6473a Fixed mem leak by making Settlement.buildings a weaklist
totycro authored
26
f4d073d Change reference to modules according
christoph authored
27 import horizons.main
b58be8a * Fixed some imports to be more direct.
nihathrael authored
28
4ecfdb9 @otinn clear the Builder cache
otinn authored
29 from horizons.ai.aiplayer import AIPlayer
bd954db Fixed release_mode decorator for most cases. Don't use it (for now) i…
totycro authored
30 from horizons.gui.ingamegui import IngameGui
2d9192d Created directory structure in horizons/gui
totycro authored
31 from horizons.gui.mousetools import SelectionTool
32 from horizons.gui.keylisteners import IngameKeyListener
33 from horizons.gui.mousetools import TearingTool
2b04d39 MFMP #1
manuel authored
34 from horizons.scheduler import Scheduler
35 from horizons.extscheduler import ExtScheduler
36 from horizons.view import View
2cf8d92 @totycro Made trader invincible also in loaded games
totycro authored
37 from horizons.gui import Gui
2b04d39 MFMP #1
manuel authored
38 from horizons.world import World
39 from horizons.entities import Entities
3ed5272 @otinn Introduce SavegameAccessor
otinn authored
40 from horizons.util import WorldObject, NamedObject, LivingObject, livingProperty, SavegameAccessor
66d0851 Introduces handling of singletons to get rid of global variables
totycro authored
41 from horizons.savegamemanager import SavegameManager
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
42 from horizons.scenario import ScenarioEventHandler
60ef134 missing import from merge
manuel authored
43 from horizons.constants import GAME_SPEED
695bd53 did much...
spq authored
44
449b1e2 * Readded a LivingObject class to ensure proper deletion of objects that
nihathrael authored
45 class Session(LivingObject):
c9eb3e1 * Began with an incode tutorial
nihathrael authored
46 """Session class represents the games main ingame view and controls cameras and map loading.
47
844e05d * Renamed all accurances of OpenAnno to Unknown Horizons
nihathrael authored
48 This is the most important class if you are going to hack on Unknown Horizons, it provides most of
8dcdbc2 Further reduction of usage of globals
totycro authored
49 the important ingame variables.
c9eb3e1 * Began with an incode tutorial
nihathrael authored
50 Here's a small list of commonly used attributes:
f4d073d Change reference to modules according
christoph authored
51 * manager - horizons.manager instance. Used to execute commands that need to be tick,
c9eb3e1 * Began with an incode tutorial
nihathrael authored
52 synchronized check the class for more information.
f4d073d Change reference to modules according
christoph authored
53 * scheduler - horizons.scheduler instance. Used to execute timed events that do not effect
46b6c39 * Updated a bunch of documentation and updated the incode tutorial, s…
nihathrael authored
54 network games but rather control the local simulation.
f4d073d Change reference to modules according
christoph authored
55 * view - horizons.view instance. Used to control the ingame camera.
56 * ingame_gui - horizons.gui.ingame_gui instance. Used to controll the ingame gui.
57 * cursor - horizons.gui.{navigation/cursor/selection/building}tool instance. Used to controll
c9eb3e1 * Began with an incode tutorial
nihathrael authored
58 mouse events, check the classes for more info.
59 * selected_instances - Set that holds the currently selected instances (building, units).
f4d073d Change reference to modules according
christoph authored
60 * world - horizons.world instance of the currently running horizons. Stores islands, players,
d010fa9 * Small fix for the scheduler
nihathrael authored
61 for later access.
c9eb3e1 * Began with an incode tutorial
nihathrael authored
62
63 TUTORIAL:
64 For further digging you should now be checking out the load() function.
65 """
53c86e2 living objects
spq authored
66 timer = livingProperty()
67 manager = livingProperty()
68 view = livingProperty()
69 ingame_gui = livingProperty()
70 keylistener = livingProperty()
71 cursor = livingProperty()
7bf1790 use living property for world, makes world usable while it is created.
spq authored
72 world = livingProperty()
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
73 scenario_eventhandler = livingProperty()
53c86e2 living objects
spq authored
74
8f620ee * Merged production_rework branch into trunk
nihathrael authored
75 log = logging.getLogger('session')
76
da1bd00 @squiddy Allow passing a seed to the RNG for all session types
squiddy authored
77 def __init__(self, gui, db, rng_seed=None):
5c8a184 * Removed livingObject class
nihathrael authored
78 super(Session, self).__init__()
2cf8d92 @totycro Made trader invincible also in loaded games
totycro authored
79 assert isinstance(gui, Gui)
2b04d39 MFMP #1
manuel authored
80 self.log.debug("Initing session")
4059a83 Getting rid of global function access #2
totycro authored
81 self.gui = gui # main gui, not ingame gui
c9f7c47 Got rid of horizons.main.gui global. References exist in session inst…
totycro authored
82 self.db = db # main db for game data (game.sqlite)
f17e70c Introduced savecounter (saves how often a game has been saved, access…
totycro authored
83 # this saves how often the current game has been saved
84 self.savecounter = 0
4ac1002 Fixed 2 minor issues
totycro authored
85 self.is_alive = True
53c86e2 living objects
spq authored
86
ab13efa phiker: Use weakrefs in WorldObject and reset at session start
phiker authored
87 WorldObject.reset()
6056273 @otinn Reset the list of used names for every game
otinn authored
88 NamedObject.reset()
4ecfdb9 @otinn clear the Builder cache
otinn authored
89 AIPlayer.clear_caches()
ab13efa phiker: Use weakrefs in WorldObject and reset at session start
phiker authored
90
b98e87a move layers and some other things to view
spq authored
91 #game
da1bd00 @squiddy Allow passing a seed to the RNG for all session types
squiddy authored
92 self.random = self.create_rng(rng_seed)
5c54b70 @totycro Only strech time in singleplayer games
totycro authored
93 self.timer = self.create_timer()
7cf6b07 Made Scheduler a singleton after a long and intense discussion and co…
totycro authored
94 Scheduler.create_instance(self.timer)
2b04d39 MFMP #1
manuel authored
95 self.manager = self.create_manager()
2c9012f @totycro Force cam refresh on camera move
totycro authored
96 self.view = View(self)
8dcdbc2 Further reduction of usage of globals
totycro authored
97 Entities.load(self.db)
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
98 self.scenario_eventhandler = ScenarioEventHandler(self) # dummy handler with no events
922eb87 @court-jus refs #811 : Campaigns
court-jus authored
99 self.campaign = {}
695bd53 did much...
spq authored
100
b98e87a move layers and some other things to view
spq authored
101 #GUI
c4291fc Made help and a few more labels translateable.
totycro authored
102 self.gui.session = self
c9f7c47 Got rid of horizons.main.gui global. References exist in session inst…
totycro authored
103 self.ingame_gui = IngameGui(self, self.gui)
84fc2f6 Fixed bug when building over a building with size > 1x1 (e.g. tent ruin)
totycro authored
104 self.keylistener = IngameKeyListener(self)
aea4bb6 @otinn added coordinates' tooltip (toggle by pressing h)
otinn authored
105 self.coordinates_tooltip = None
e46d902 Add a speed counter
greyghost authored
106 self.display_speed()
695bd53 did much...
spq authored
107
43db8c0 fix selecting
spq authored
108 self.selected_instances = set()
c9eb3e1 * Began with an incode tutorial
nihathrael authored
109 self.selection_groups = [set()] * 10 # List of sets that holds the player assigned unit groups.
e96f577 Small improvement for Savegamemanager
totycro authored
110
2b04d39 MFMP #1
manuel authored
111 def start(self):
1ae73aa @otinn fix spelling of 'actually' in comments
otinn authored
112 """Actually starts the game."""
2b04d39 MFMP #1
manuel authored
113 self.timer.activate()
114
115 def create_manager(self):
116 """Returns instance of command manager (currently MPManager or SPManager)"""
117 raise NotImplementedError
118
da1bd00 @squiddy Allow passing a seed to the RNG for all session types
squiddy authored
119 def create_rng(self, seed=None):
2b04d39 MFMP #1
manuel authored
120 """Returns a RNG (random number generator). Must support the python random.Random interface"""
121 raise NotImplementedError
ab13efa phiker: Use weakrefs in WorldObject and reset at session start
phiker authored
122
5c54b70 @totycro Only strech time in singleplayer games
totycro authored
123 def create_timer(self):
124 """Returns a Timer instance."""
125 raise NotImplementedError
126
449b1e2 * Readded a LivingObject class to ensure proper deletion of objects that
nihathrael authored
127 def end(self):
8f620ee * Merged production_rework branch into trunk
nihathrael authored
128 self.log.debug("Ending session")
4ac1002 Fixed 2 minor issues
totycro authored
129 self.is_alive = False
8f620ee * Merged production_rework branch into trunk
nihathrael authored
130
1131e0e Fixed some small issues
totycro authored
131 self.gui.session = None
8dcdbc2 Further reduction of usage of globals
totycro authored
132
f9114ac Fixed circular import and minor issues
totycro authored
133 Scheduler().rem_all_classinst_calls(self)
967816b Fixed 2 saving bugs
totycro authored
134 ExtScheduler().rem_all_classinst_calls(self)
e96f577 Small improvement for Savegamemanager
totycro authored
135
1f87a99 * Removed Settings class in favor of the new fife_settings module
nihathrael authored
136 if horizons.main.fife.get_fife_setting("PlaySounds"):
e641c91 Fix ticket #494.
greyghost authored
137 for emitter in horizons.main.fife.emitter['ambient'][:]:
d665e59 Fixed a bug, that occurs on session end, when sound is disabled
totycro authored
138 emitter.stop()
f4d073d Change reference to modules according
christoph authored
139 horizons.main.fife.emitter['ambient'].remove(emitter)
140 horizons.main.fife.emitter['effects'].stop()
141 horizons.main.fife.emitter['speech'].stop()
0e8e523 clean up deconstruction
spq authored
142 self.cursor = None
f9ee47c fixes #665
totycro authored
143 self.world = None
0e8e523 clean up deconstruction
spq authored
144 self.keylistener = None
145 self.ingame_gui = None
146 self.view = None
147 self.manager = None
2b04d39 MFMP #1
manuel authored
148 self.timer = None
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
149 self.scenario_eventhandler = None
9897ddd Use CreateUnit for creation and reproduction of wild animals
totycro authored
150 Scheduler.destroy_instance()
d6515e8 Don't handle entities as an instance, since it's static data from the…
totycro authored
151
28d65cf Fixed mem leak when ship is selected while quitting session
totycro authored
152 self.selected_instances = None
153 self.selection_groups = None
0249fda Implemented changeable limit for quicksaves
totycro authored
154
7124e82 Fix tearing tool bug when pressed 'x' twice..
greyghost authored
155 def destroy_tool(self):
156 """Initiate the destroy tool"""
dcd772c Several random minor changes
totycro authored
157 if not hasattr(self.cursor, 'tear_tool_active') or \
158 not self.cursor.tear_tool_active:
c9f7c47 Got rid of horizons.main.gui global. References exist in session inst…
totycro authored
159 self.cursor = TearingTool(self)
7124e82 Fix tearing tool bug when pressed 'x' twice..
greyghost authored
160 self.ingame_gui.hide_menu()
161
0249fda Implemented changeable limit for quicksaves
totycro authored
162 def autosave(self):
2b04d39 MFMP #1
manuel authored
163 raise NotImplementedError
0249fda Implemented changeable limit for quicksaves
totycro authored
164 def quicksave(self):
2b04d39 MFMP #1
manuel authored
165 raise NotImplementedError
4395b53 Implemented quickload (accessible via F9)
totycro authored
166 def quickload(self):
2b04d39 MFMP #1
manuel authored
167 raise NotImplementedError
2978207 @totycro Unified signature of save in Session and subclasses
totycro authored
168 def save(self, savegame=None):
2b04d39 MFMP #1
manuel authored
169 raise NotImplementedError
3f3ab3b recording demos works, playing not tested
spq authored
170
709006a @otinn distribute resource deposits better; add resource density option to t…
otinn authored
171 def load(self, savegame, players, trader_enabled, pirate_enabled, natural_resource_multiplier, is_scenario=False, campaign=None):
b163767 First steps towards loading, breaks everything for now
yonibear authored
172 """Loads a map.
173 @param savegame: path to the savegame database.
3911fe7 @otinn set up the players list correctly for multiplayer
otinn authored
174 @param players: iterable of dictionaries containing id, name, color, local, ai, and difficulty
46b6c39 * Updated a bunch of documentation and updated the incode tutorial, s…
nihathrael authored
175 @param is_scenario: Bool whether the loaded map is a scenario or not
b163767 First steps towards loading, breaks everything for now
yonibear authored
176 """
e675f8a Slight horizons.gui cleanup
totycro authored
177 if is_scenario:
46b6c39 * Updated a bunch of documentation and updated the incode tutorial, s…
nihathrael authored
178 # savegame is a yaml file, that contains reference to actual map file
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
179 self.scenario_eventhandler = ScenarioEventHandler(self, savegame)
2714b87 @totycro Added recommended number of players to all maps, display value at sin…
totycro authored
180 # scenario maps can be normal maps or scenario maps:
181 map_filename = self.scenario_eventhandler.get_map_file()
182 savegame = os.path.join(SavegameManager.scenario_maps_dir, map_filename)
183 if not os.path.exists(savegame):
184 savegame = os.path.join(SavegameManager.maps_dir, map_filename)
31be03b @squiddy Remove mutable default arguments
squiddy authored
185 self.campaign = {} if not campaign else campaign
e675f8a Slight horizons.gui cleanup
totycro authored
186
8f620ee * Merged production_rework branch into trunk
nihathrael authored
187 self.log.debug("Session: Loading from %s", savegame)
3ed5272 @otinn Introduce SavegameAccessor
otinn authored
188 savegame_db = SavegameAccessor(savegame) # Initialize new dbreader
4f84347 @totycro Save/load the rng state
totycro authored
189 savegame_data = SavegameManager.get_metadata(savegame)
190
191 # load how often the game has been saved (used to know the difference between
192 # a loaded and a new game)
193 self.savecounter = 0 if not 'savecounter' in savegame_data else savegame_data['savecounter']
194
195 if savegame_data.get('rng_state', None):
196 rng_state_list = json.loads( savegame_data['rng_state'] )
197 # json treats tuples as lists, but we need tuples here, so convert back
198 def rec_list_to_tuple(x):
199 if isinstance(x, list):
200 return tuple( rec_list_to_tuple(i) for i in x )
201 else:
202 return x
203 rng_state_tuple = rec_list_to_tuple(rng_state_list)
204 # changing the rng is safe for mp, as all players have to have the same map
205 self.random.setstate( rng_state_tuple )
7542775 Fixed player save/load (includes money)
totycro authored
206
8dcdbc2 Further reduction of usage of globals
totycro authored
207 self.world = World(self) # Load horizons.world module (check horizons/world/__init__.py)
208 self.world._init(savegame_db)
209 self.view.load(savegame_db) # load view
9a59187 * No more ships saved in the basemaps.
nihathrael authored
210 if not self.is_game_loaded():
2b04d39 MFMP #1
manuel authored
211 # NOTE: this must be sorted before iteration, cause there is no defined order for
212 # iterating a dict, and it must happen in the same order for mp games.
c5921ef @otinn load players in the order of their id
otinn authored
213 for i in sorted(players, lambda p1, p2: cmp(p1['id'], p2['id'])):
5a8a946 @otinn add support for difficulty settings
otinn authored
214 self.world.setup_player(i['id'], i['name'], i['color'], i['local'], i['ai'], i['difficulty'])
709006a @otinn distribute resource deposits better; add resource density option to t…
otinn authored
215 center = self.world.init_new_world(trader_enabled, pirate_enabled, natural_resource_multiplier)
9a59187 * No more ships saved in the basemaps.
nihathrael authored
216 self.view.center(center[0], center[1])
3220735 Added save/load support for scenario files
totycro authored
217 else:
5ba101a @mayanks43 Removes traces of campaign from the code (sets stage for a proper cam…
mayanks43 authored
218 # try to load scenario data
219 self.scenario_eventhandler.load(savegame_db)
2b04d39 MFMP #1
manuel authored
220 self.manager.load(savegame_db) # load the manager (there might me old scheduled ticks).
fa2a002 @otinn added a global fish indexer to make nearby fish lookup fast; made the…
otinn authored
221 self.world.init_fish_indexer() # now the fish should exist
8dcdbc2 Further reduction of usage of globals
totycro authored
222 self.ingame_gui.load(savegame_db) # load the old gui positions and stuff
e96f577 Small improvement for Savegamemanager
totycro authored
223
8dcdbc2 Further reduction of usage of globals
totycro authored
224 for instance_id in savegame_db("SELECT id FROM selected WHERE `group` IS NULL"): # Set old selected instance
a688130 Changed CamelCase-style method names to our style.
totycro authored
225 obj = WorldObject.get_object_by_id(instance_id[0])
e31d992 Implemented unit loading.
totycro authored
226 self.selected_instances.add(obj)
227 obj.select()
c9eb3e1 * Began with an incode tutorial
nihathrael authored
228 for group in xrange(len(self.selection_groups)): # load user defined unit groups
8dcdbc2 Further reduction of usage of globals
totycro authored
229 for instance_id in savegame_db("SELECT id FROM selected WHERE `group` = ?", group):
a688130 Changed CamelCase-style method names to our style.
totycro authored
230 self.selection_groups[group].add(WorldObject.get_object_by_id(instance_id[0]))
e96f577 Small improvement for Savegamemanager
totycro authored
231
017ed76 Added code for captains log
totycro authored
232 # cursor has to be inited last, else player interacts with a not inited world with it.
233 self.cursor = SelectionTool(self)
2c9012f @totycro Force cam refresh on camera move
totycro authored
234 # Set cursor correctly, menus might need to be opened.
803bb51 @mihaibivol fixed ground unit load and save
authored
235 # Open menus later, they may need unit data not yet inited
236 self.cursor.apply_select()
060de5f * Disabled autosave
nihathrael authored
237
8dcdbc2 Further reduction of usage of globals
totycro authored
238 assert hasattr(self.world, "player"), 'Error: there is no human player'
c9eb3e1 * Began with an incode tutorial
nihathrael authored
239 """
240 TUTORIAL:
241 From here on you should digg into the classes that are loaded above, especially the world class.
09b0056 Updated file paths from game/ to horizons/
totycro authored
242 (horizons/world/__init__.py). It's where the magic happens and all buildings and units are loaded.
c9eb3e1 * Began with an incode tutorial
nihathrael authored
243 """
b163767 First steps towards loading, breaks everything for now
yonibear authored
244
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
245 def speed_set(self, ticks, suggestion=False):
2b04d39 MFMP #1
manuel authored
246 """Set game speed to ticks ticks per second"""
247 raise NotImplementedError
e46d902 Add a speed counter
greyghost authored
248
249 def display_speed(self):
338bbe1 Fixed #421
totycro authored
250 text = u''
75d0ba8 @ChrisOelmueller * Disable buttons for further altering game speed in this direction w…
ChrisOelmueller authored
251 up_icon = self.ingame_gui.widgets['minimap'].findChild(name='speedUp')
252 down_icon = self.ingame_gui.widgets['minimap'].findChild(name='speedDown')
338bbe1 Fixed #421
totycro authored
253 tps = self.timer.ticks_per_second
254 if tps == 0: # pause
04aa027 @rudis Use 0x as pause indicator instead of II.
rudis authored
255 text = u'0x'
75d0ba8 @ChrisOelmueller * Disable buttons for further altering game speed in this direction w…
ChrisOelmueller authored
256 up_icon.set_inactive()
257 down_icon.set_inactive()
338bbe1 Fixed #421
totycro authored
258 else:
e441f9b @ChrisOelmueller * Do not display '1x' as game speed
ChrisOelmueller authored
259 if tps != GAME_SPEED.TICKS_PER_SECOND:
260 text = unicode("%1gx" % (tps * 1.0/GAME_SPEED.TICKS_PER_SECOND))
261 #%1g: displays 0.5x, but 2x instead of 2.0x
ab2318f @ChrisOelmueller * New game speed array [0.5x 1x 2x 3x 4x 6x 8x 11x]
ChrisOelmueller authored
262 index = GAME_SPEED.TICK_RATES.index(tps)
263 if index + 1 >= len(GAME_SPEED.TICK_RATES):
75d0ba8 @ChrisOelmueller * Disable buttons for further altering game speed in this direction w…
ChrisOelmueller authored
264 up_icon.set_inactive()
265 else:
266 up_icon.set_active()
ab2318f @ChrisOelmueller * New game speed array [0.5x 1x 2x 3x 4x 6x 8x 11x]
ChrisOelmueller authored
267 if index > 0:
268 down_icon.set_active()
269 else:
270 down_icon.set_inactive()
c4291fc Made help and a few more labels translateable.
totycro authored
271 self.ingame_gui.display_game_speed(text)
20ecf0e functions to change ticks per second
spq authored
272
75d0ba8 @ChrisOelmueller * Disable buttons for further altering game speed in this direction w…
ChrisOelmueller authored
273
20ecf0e functions to change ticks per second
spq authored
274 def speed_up(self):
c2053a0 @totycro Disable game speed modification buttons when game is in paused state
totycro authored
275 if self.speed_is_paused():
276 # TODO: sound feedback to signal that this is an invalid action
277 return
1f87a99 * Removed Settings class in favor of the new fife_settings module
nihathrael authored
278 if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
279 i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
280 if i + 1 < len(GAME_SPEED.TICK_RATES):
281 self.speed_set(GAME_SPEED.TICK_RATES[i + 1])
20ecf0e functions to change ticks per second
spq authored
282 else:
e5ee900 @nihathrael Fixed a small error when adjusting the game speed while game is pause…
nihathrael authored
283 self.speed_set(GAME_SPEED.TICK_RATES[0])
20ecf0e functions to change ticks per second
spq authored
284
285 def speed_down(self):
c2053a0 @totycro Disable game speed modification buttons when game is in paused state
totycro authored
286 if self.speed_is_paused():
287 # TODO: sound feedback to signal that this is an invalid action
288 return
1f87a99 * Removed Settings class in favor of the new fife_settings module
nihathrael authored
289 if self.timer.ticks_per_second in GAME_SPEED.TICK_RATES:
290 i = GAME_SPEED.TICK_RATES.index(self.timer.ticks_per_second)
20ecf0e functions to change ticks per second
spq authored
291 if i > 0:
cc73ebe Fixes #593, hopefully
nihathrael authored
292 self.speed_set(GAME_SPEED.TICK_RATES[i - 1])
20ecf0e functions to change ticks per second
spq authored
293 else:
1f87a99 * Removed Settings class in favor of the new fife_settings module
nihathrael authored
294 self.speed_set(GAME_SPEED.TICK_RATES[0])
20ecf0e functions to change ticks per second
spq authored
295
af9b8ef @totycro Introduced a "pause stack".
totycro authored
296 _pause_stack = 0 # this saves the level of pausing
297 # e.g. if two dialogs are displayed, that pause the game,
298 # unpause needs to be called twice to unpause the game. cf. #876
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
299 def speed_pause(self, suggestion=False):
8f620ee * Merged production_rework branch into trunk
nihathrael authored
300 self.log.debug("Session: Pausing")
af9b8ef @totycro Introduced a "pause stack".
totycro authored
301 self._pause_stack += 1
ab47d4f Fixed a mistake in my last commit
totycro authored
302 if not self.speed_is_paused():
8f0d094 Fixed loading
phiker authored
303 self.paused_ticks_per_second = self.timer.ticks_per_second
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
304 self.speed_set(0, suggestion)
8f0d094 Fixed loading
phiker authored
305
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
306 def speed_unpause(self, suggestion=False):
8f620ee * Merged production_rework branch into trunk
nihathrael authored
307 self.log.debug("Session: Unpausing")
ab47d4f Fixed a mistake in my last commit
totycro authored
308 if self.speed_is_paused():
af9b8ef @totycro Introduced a "pause stack".
totycro authored
309 self._pause_stack -= 1
310 if self._pause_stack == 0:
311 self.speed_set(self.paused_ticks_per_second)
8f0d094 Fixed loading
phiker authored
312
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
313 def speed_toggle_pause(self, suggestion=False):
ab47d4f Fixed a mistake in my last commit
totycro authored
314 if self.speed_is_paused():
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
315 self.speed_unpause(suggestion)
20ecf0e functions to change ticks per second
spq authored
316 else:
a814656 @nihathrael Added a suggestion parameter to the sessions speed_set function.
nihathrael authored
317 self.speed_pause(suggestion)
454164a Create random trees only on new game
totycro authored
318
ab47d4f Fixed a mistake in my last commit
totycro authored
319 def speed_is_paused(self):
320 return (self.timer.ticks_per_second == 0)
321
454164a Create random trees only on new game
totycro authored
322 def is_game_loaded(self):
323 """Checks if the current game is a new one, or a loaded one.
324 @return: True if game is loaded, else False
325 """
2714b87 @totycro Added recommended number of players to all maps, display value at sin…
totycro authored
326 return (self.savecounter > 0)
Something went wrong with that request. Please try again.