1
|
|
|
#!/usr/bin/env python2 |
2
|
|
|
# |
3
|
|
|
# Copyright 2001 - 2017 Ludek Smid [http://www.ospace.net/] |
4
|
|
|
# |
5
|
|
|
# This file is part of Outer Space. |
6
|
|
|
# |
7
|
|
|
# Outer Space is free software; you can redistribute it and/or modify |
8
|
|
|
# it under the terms of the GNU General Public License as published by |
9
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
# (at your option) any later version. |
11
|
|
|
# |
12
|
|
|
# Outer Space is distributed in the hope that it will be useful, |
13
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
# GNU General Public License for more details. |
16
|
|
|
# |
17
|
|
|
# You should have received a copy of the GNU General Public License |
18
|
|
|
# along with Outer Space; if not, write to the Free Software |
19
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
20
|
|
|
# |
21
|
|
|
import argparse |
22
|
|
|
import atexit |
23
|
|
|
import logging as log |
24
|
|
|
import os |
25
|
|
|
import sys |
26
|
|
|
import time |
27
|
|
|
|
28
|
|
|
import common as c |
29
|
|
|
|
30
|
|
|
log.basicConfig(level=log.INFO, format='%(levelname)-7s: %(message)s') |
31
|
|
|
|
32
|
|
|
def slicer(slices): |
33
|
|
|
slices = int(slices) |
34
|
|
|
if 24 % slices: |
35
|
|
|
raise ArgumentError |
|
|
|
|
36
|
|
|
return 24 / slices |
37
|
|
|
|
38
|
|
|
# parse command line arguments |
39
|
|
|
parser = argparse.ArgumentParser() |
40
|
|
|
parser.add_argument("--configdir", dest = "configdir", default = None, |
41
|
|
|
type = str, metavar = "CONFIGDIR", help = ("Directory where server data are stored, " |
42
|
|
|
"by default it is temporary directory. If existing directory is specified, " |
43
|
|
|
"it won't recreate galaxies but continue with what is already available.")) |
44
|
|
|
parser.add_argument("--history", dest = "history", default = "./history", |
45
|
|
|
type = str, metavar = "PATH", help = "Directory where screenshots will be saved.") |
46
|
|
|
parser.add_argument("--days", dest = "days", default = 0, |
47
|
|
|
type = int, metavar = "N", help = "Process N days of the gameplay, default is 0.") |
48
|
|
|
parser.add_argument("--day-slices", dest = "turnSkip", default = slicer(4), |
49
|
|
|
type = slicer, metavar = "N", help = "Process N cycles per day, default is 4.") |
50
|
|
|
parser.add_argument("--galaxy-check", dest = "galaxy_check", default = None, nargs = 2, |
51
|
|
|
metavar = "GALAXY_TYPE NUMBER", help = ("Allows visual checking of galaxy generator " |
52
|
|
|
"settings by easily generating selected NUMBER of GALAXY_TYPE galaxies.")) |
53
|
|
|
args = parser.parse_args() |
54
|
|
|
|
55
|
|
|
c.initPaths(args.configdir) |
56
|
|
|
if not c.startServer(): |
57
|
|
|
sys.exit() |
58
|
|
|
atexit.register(c.killServer) |
59
|
|
|
if args.configdir is None: |
60
|
|
|
if not args.galaxy_check: |
61
|
|
|
# default set |
62
|
|
|
#c.createGalaxy("Circle1SP") |
63
|
|
|
#c.createGalaxy("Circle3SP") |
64
|
|
|
#c.createGalaxy("Circle2CP") |
65
|
|
|
c.createGalaxy("Circle3CP") |
66
|
|
|
#c.createGalaxy("Circle9P") |
67
|
|
|
#c.createGalaxy("Circle42P") |
68
|
|
|
else: |
69
|
|
|
galaxy_type, quantity = args.galaxy_check[0], int(args.galaxy_check[1]) |
70
|
|
|
for num in xrange(quantity): |
|
|
|
|
71
|
|
|
c.createGalaxy(galaxy_type, "{0}.{1}".format(galaxy_type, num + 1)) |
72
|
|
|
|
73
|
|
|
c.startServerTime() |
74
|
|
|
|
75
|
|
|
c.makeScreenshots(args.history) |
76
|
|
|
for day in xrange(args.days): |
77
|
|
|
start_time = time.time() |
78
|
|
|
for _slice in xrange(24 / args.turnSkip): |
79
|
|
|
c.doTurns(args.turnSkip, args.turnSkip, verbose=False) |
80
|
|
|
c.makeScreenshots(args.history) |
81
|
|
|
log.info("Day {0} rendered ({1}s).".format(day + 1, int(time.time() - start_time))) |
82
|
|
|
c.stopServer() |
83
|
|
|
|
84
|
|
|
|