Skip to content

Commit 9c032e0

Browse files
committed
Scenario's default AI difficulty can now be changed via configuration. Default AI difficulty is now easy by default (was normal for scenarios and novice for random games). These changes affect new games only.
1 parent 3ba6ed6 commit 9c032e0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/freeciv/options.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,20 @@ def add_feature(self, label, key):
7272
def add_feature_bool(self, label_t, label_f, key):
7373
self.add(BoolOptionsButton(label_t, label_f, key))
7474

75+
def add_difficulty_button(self):
76+
def _callback(optionsPanel):
77+
change_difficulty(self.difficulty_button)
78+
79+
self.difficulty_button = ui.Button('Default difficulty for new games: ' + features.get('app.difficulty'), functools.partial(_callback, self))
80+
self.add(self.difficulty_button)
81+
7582
def show_options():
7683
options = OptionsPanel(marginleft=10)
7784
options.add(ui.Label(('Touch' if osutil.is_android else 'Click') + ' an option to change'))
7885
options.add_feature('Shutdown game after %d seconds of pause', 'app.shutdown')
7986
#options.add_feature_bool('New joystick', 'Old joystick', 'app.new_joystick')
8087
options.add(ui.Button('Change joystick', change_joystick))
88+
options.add_difficulty_button()
8189
options.add(ui.Button('Change ruleset for new games', change_ruleset))
8290
st = 'Full city label toggle button:'
8391
options.add_feature_bool(st + ' show', st + ' hide', 'app.full_label_toggle_button')
@@ -179,6 +187,20 @@ def set_ruleset(name):
179187

180188
ui.set_dialog(panel)
181189

190+
def change_difficulty(difficulty_button):
191+
def set_difficulty(name):
192+
features.set_perm('app.difficulty', name)
193+
difficulty_button.set_text('Default difficulty for new games: ' + name)
194+
ui.back()
195+
196+
difficulties = ['handicapped', 'novice', 'easy', 'normal', 'hard', 'cheating']
197+
panel = ui.LinearLayoutWidget()
198+
199+
for difficulty in difficulties:
200+
panel.add(ui.Button(difficulty, functools.partial(set_difficulty, difficulty)))
201+
202+
ui.set_dialog(panel)
203+
182204
def change_joystick():
183205
def set_type(name):
184206
features.set_perm('app.joystick', name)

lib/freeciv/save.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from monitor import get_save_dir
4040

4141
features.add_feature('app.ruleset', default='classic')
42+
features.add_feature('app.difficulty', default='easy')
4243

4344
# Using fork causes the "Failed to connect to game server" error that happens randomly
4445
# https://stackoverflow.com/questions/6078712/is-it-safe-to-fork-from-within-a-thread#6079669
@@ -132,7 +133,7 @@ def setup_ui(self):
132133
self.leader_name = 'Player'
133134
self.city_style = nation[1]
134135
self.leader_sex = 2
135-
self.difficulty = 'novice'
136+
self.difficulty = features.get('app.difficulty')
136137

137138
self.set_nation_settings()
138139
self.set_difficulty_settings()
@@ -324,6 +325,7 @@ def callback():
324325

325326
def load_game_now(port, username):
326327
client.client.chat('/take "%s"' % username)
328+
client.client.chat('/%s' % features.get('app.difficulty'))
327329
client.client.chat('/start')
328330
client.client.tick()
329331
ui.back(allow_override=False)

0 commit comments

Comments
 (0)