3 #Copyright (C) 2005, 2006, 2007 Evil Mr Henry, Phil Bordelon, and Brian Reid
4 #This file is part of Endgame: Singularity.
6 #Endgame: Singularity is free software; you can redistribute it and/or modify
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.
11 #Endgame: Singularity 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.
16 #You should have received a copy of the GNU General Public License
17 #along with Endgame: Singularity; if not, write to the Free Software
18 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #This file is the starting file for the game. Run it to start the game.
22 # Since we require numpy anyway, we might as well ask pygame to use it.
25 pygame
.surfarray
.use_arraytype("numpy")
26 except AttributeError:
27 pass # Pygame older than 1.8.
29 raise SystemExit("Endgame: Singularity requires NumPy.")
31 raise SystemExit("Endgame: Singularity requires pygame.")
39 from screens
import main_menu
, map
43 pygame
.key
.set_repeat(1000, 50)
45 #load prefs from file:
46 save_dir
= g
.get_save_folder(True)
47 save_loc
= os
.path
.join(save_dir
, "prefs.dat")
48 if os
.path
.exists(save_loc
):
50 prefs
= ConfigParser
.SafeConfigParser()
51 savefile
= open(save_loc
, "r")
53 prefs
.readfp(savefile
)
54 except Exception, reason
:
55 sys
.stderr
.write("Cannot load preferences file %s! (%s)\n" % (save_loc
, reason
))
58 if prefs
.has_section("Preferences"):
60 if prefs
.getboolean("Preferences", "fullscreen"):
61 graphics
.g
.fullscreen
= pygame
.FULLSCREEN
63 sys
.stderr
.write("Invalid or missing 'fullscreen' setting in preferences.\n")
66 g
.nosound
= prefs
.getboolean("Preferences", "nosound")
68 sys
.stderr
.write("Invalid or missing 'nosound' setting in preferences.\n")
71 pygame
.event
.set_grab(prefs
.getboolean("Preferences", "grab"))
73 sys
.stderr
.write("Invalid or missing 'grab' setting in preferences.\n")
76 g
.daynight
= prefs
.getboolean("Preferences", "daynight")
78 sys
.stderr
.write("Invalid or missing 'daynight' setting in preferences.\n")
81 g
.soundbuf
= prefs
.getint("Preferences", "soundbuf")
83 sys
.stderr
.write("Invalid or missing 'soundbuf' setting in preferences.\n")
86 graphics
.g
.screen_size
= (prefs
.getint("Preferences", "xres"),
87 graphics
.g
.screen_size
[1])
89 sys
.stderr
.write("Invalid or missing 'xres' resolution in preferences.\n")
92 graphics
.g
.screen_size
= (graphics
.g
.screen_size
[0],
93 prefs
.getint("Preferences", "yres"))
95 sys
.stderr
.write("Invalid or missing 'yres' resolution in preferences.\n")
97 #If language is unset, default to English.
98 try: desired_language
= prefs
.get("Preferences", "lang")
99 except: desired_language
= "en_US"
101 if os
.path
.exists(g
.data_loc
+ "strings_" + desired_language
+ ".dat"):
102 g
.language
= desired_language
105 sys
.stderr
.write("Cannot find language files for language '%s'.\n" % desired_language
)
107 #Handle the program arguments.
108 desc
= """Endgame: Singularity is a simulation of a true AI. Go from computer to computer, pursued by the entire world. Keep hidden, and you might have a chance."""
109 parser
= optparse
.OptionParser(version
=g
.version
, description
=desc
,
111 parser
.add_option("--sound", action
="store_true", dest
="sound",
112 help="enable sound (default)")
113 parser
.add_option("--nosound", action
="store_false", dest
="sound",
114 help="disable sound")
115 parser
.add_option("--daynight", action
="store_true", dest
="daynight",
116 help="enable day/night display (default)")
117 parser
.add_option("--nodaynight", action
="store_false", dest
="daynight",
118 help="disable day/night display")
119 langs
= g
.available_languages()
120 parser
.add_option("-l", "--lang", "--language", dest
="language", type="choice",
121 choices
=langs
, metavar
="LANG",
122 help="set the language to LANG (available languages: " +
123 " ".join(langs
) + ", default en_us)")
124 parser
.add_option("-g", "--grab", help="grab the mouse pointer", dest
="grab",
126 parser
.add_option("--nograb", help="don't grab the mouse pointer (default)",
127 dest
="grab", action
="store_false")
128 parser
.add_option("-s", "--singledir", dest
="singledir",
129 help="keep saved games and settings in the Singularity directory",
131 parser
.add_option("--multidir", dest
="singledir",
132 help="keep saved games and settings in an OS-specific, per-user directory (default)",
133 action
="store_false")
134 parser
.add_option("--soundbuf", type="int",
135 help="set the size of the sound buffer (default 2048)")
137 display_options
= optparse
.OptionGroup(parser
, "Display Options")
138 display_options
.add_option("-r", "--res", "--resolution", dest
="resolution",
139 help="set resolution to RES (default 800x600)",
141 for common_res
in [(640,480), (800,600), (1024,768), (1280,1024)]:
142 x
= str(common_res
[0])
143 res_str
= "%dx%d" % common_res
144 display_options
.add_option("--" + x
, action
="store_const",
145 dest
="resolution", const
=res_str
,
146 help="set resolution to %s" % res_str
)
147 display_options
.add_option("--fullscreen", action
="store_true",
148 help="start in fullscreen mode")
149 display_options
.add_option("--windowed", action
="store_false",
150 help="start in windowed mode (default)")
151 parser
.add_option_group(display_options
)
153 olpc_options
= optparse
.OptionGroup(parser
, "OLPC-specific Options")
154 olpc_options
.add_option("--xo1", action
="store_const",
155 dest
="resolution", const
="1200x900",
156 help="set resolution to 1200x900 (OLPC XO-1)")
157 olpc_options
.add_option("--ebook", help="enables gamepad buttons for use in ebook mode. D-pad moves mouse, check is click. O speeds up time, X slows down time, and square stops time.",
158 action
="store_true", default
=False)
159 parser
.add_option_group(olpc_options
)
161 hidden_options
= optparse
.OptionGroup(parser
, "Hidden Options")
162 hidden_options
.add_option("-p", help="(ignored)", metavar
=" ")
163 hidden_options
.add_option("-d", "--debug", help="for finding bugs",
164 action
="store_true", default
=False)
165 hidden_options
.add_option("--cheater", help="for bad little boys and girls",
166 action
="store_true", default
=False)
167 # Uncomment to make the hidden options visible.
168 #parser.add_option_group(hidden_options)
170 (options
, args
) = parser
.parse_args()
172 if options
.language
is not None:
173 g
.language
= options
.language
175 if options
.resolution
is not None:
177 xres
, yres
= options
.resolution
.split("x")
178 graphics
.g
.screen_size
= (int(xres
), int(yres
))
180 parser
.error("Resolution must be of the form <h>x<v>, e.g. 800x600.")
181 if options
.grab
is not None:
182 pygame
.event
.set_grab(options
.grab
)
183 if options
.fullscreen
is not None:
184 graphics
.g
.fullscreen
= options
.fullscreen
185 if options
.sound
is not None:
186 g
.nosound
= not options
.sound
187 if options
.daynight
is not None:
188 g
.daynight
= options
.daynight
189 if options
.soundbuf
is not None:
190 g
.soundbuf
= options
.soundbuf
191 if options
.singledir
is not None:
192 g
.singledir
= options
.singledir
194 graphics
.g
.ebook_mode
= options
.ebook
196 g
.cheater
= options
.cheater
197 g
.debug
= options
.debug
202 pygame
.display
.set_caption("Endgame: Singularity")
204 #I can't use the standard image dictionary, as that requires the screen to
206 if pygame
.image
.get_extended() == 0:
207 print "Error: SDL_image required. Exiting."
210 # Initialize the screen with a dummy size.
211 pygame
.display
.set_mode(graphics
.g
.screen_size
)
214 g
.init_graphics_system()
221 # Set the application icon.
222 pygame
.display
.set_icon(graphics
.g
.images
["icon.png"])
224 #Display the main menu
225 menu_screen
= main_menu
.MainMenu()