Browse Source

add troop file arg

Bastien Sevajol 6 years ago
parent
commit
23565baeb3
1 changed files with 24 additions and 0 deletions
  1. 24 0
      run.py

+ 24 - 0
run.py View File

1
 # coding: utf-8
1
 # coding: utf-8
2
 import argparse
2
 import argparse
3
 import logging
3
 import logging
4
+import sys
4
 from random import seed
5
 from random import seed
5
 
6
 
6
 from synergine2.log import get_default_logger
7
 from synergine2.log import get_default_logger
20
     map_dir_path: str,
21
     map_dir_path: str,
21
     seed_value: int=None,
22
     seed_value: int=None,
22
     state_file_path: str=None,
23
     state_file_path: str=None,
24
+    troops_file_path: str=None,
23
     state_save_dir: str='.',
25
     state_save_dir: str='.',
24
     placement_mode: bool = False,
26
     placement_mode: bool = False,
25
 ):
27
 ):
28
+    assert not (state_file_path and troops_file_path),\
29
+        'Do not provide troops file when state file given'
30
+
26
     if seed_value is not None:
31
     if seed_value is not None:
27
         seed(seed_value)
32
         seed(seed_value)
28
 
33
 
49
         state = state_loader.get_state(state_file_path)
54
         state = state_loader.get_state(state_file_path)
50
         subjects.extend(state.subjects)
55
         subjects.extend(state.subjects)
51
 
56
 
57
+    elif troops_file_path:
58
+        troop_loader_builder = TroopConstructorBuilder(config, simulation)
59
+        troop_loader = troop_loader_builder.get_troop_loader()
60
+        troops = troop_loader.get_troops(troops_file_path)
61
+        subjects.extend(troops.subjects)
62
+
52
     simulation.subjects = subjects
63
     simulation.subjects = subjects
53
 
64
 
54
     core = Core(
65
     core = Core(
76
     )
87
     )
77
     parser.add_argument('map_dir_path', help='map directory path')
88
     parser.add_argument('map_dir_path', help='map directory path')
78
     parser.add_argument('--seed', dest='seed', default=None)
89
     parser.add_argument('--seed', dest='seed', default=None)
90
+    parser.add_argument('--troops', dest='troops', default=None)
79
     parser.add_argument('--state', dest='state', default=None)
91
     parser.add_argument('--state', dest='state', default=None)
80
     parser.add_argument(
92
     parser.add_argument(
81
         '--state-save-dir',
93
         '--state-save-dir',
90
 
102
 
91
     args = parser.parse_args()
103
     args = parser.parse_args()
92
 
104
 
105
+    if args.troops and args.state:
106
+        print(
107
+            'Cannot load state "{}" because you provide troops file "{}". '
108
+            'You must provide only one of them.'.format(
109
+                args.state,
110
+                args.troops,
111
+            ),
112
+            file=sys.stderr,
113
+        )
114
+        exit(1)
115
+
93
     main(
116
     main(
94
         args.map_dir_path,
117
         args.map_dir_path,
95
         seed_value=args.seed,
118
         seed_value=args.seed,
96
         state_file_path=args.state,
119
         state_file_path=args.state,
120
+        troops_file_path=args.troops,
97
         state_save_dir=args.state_save_dir,
121
         state_save_dir=args.state_save_dir,
98
         placement_mode=args.placement,
122
         placement_mode=args.placement,
99
     )
123
     )