Merge lp:~widelands-dev/widelands/bug-1408775 into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7385
Proposed branch: lp:~widelands-dev/widelands/bug-1408775
Merge into: lp:widelands
Diff against target: 170 lines (+39/-29)
5 files modified
scripting/win_conditions/init.lua (+12/-0)
src/logic/game_settings.h (+18/-1)
src/network/netclient.cc (+2/-6)
src/network/nethost.cc (+5/-14)
src/ui_fsmenu/launch_spg.cc (+2/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1408775
Reviewer Review Type Date Requested Status
SirVer Approve
GunChleoc Needs Resubmitting
Review via email: mp+248181@code.launchpad.net

Description of the change

Win conditions order is now determined by an init.lua file.

I kept the file names in case a change would break savegames.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

> I kept the file names in case a change would break savegames.

Should be save I think - win conditions are loaded on game start and then are part of the Lua state and are therefore persisted with the savegame. If the display logic in the menus is not trying to load the files nothing should. I'd say rename the files, but drop the numbers.

review: Needs Fixing
Revision history for this message
GunChleoc (gunchleoc) wrote :

I have some code duplication because of the circular dependency with lua_table.h

Shall we wait until you have figured out separating this?

Revision history for this message
SirVer (sirver) wrote :

> Shall we wait until you have figured out separating this?

Done. Merge request is here:
https://code.launchpad.net/~widelands-dev/widelands/split_lua_table

Revision history for this message
GunChleoc (gunchleoc) wrote :

Common code now resides in GameSettings.

review: Needs Resubmitting
Revision history for this message
SirVer (sirver) wrote :

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'scripting/win_conditions/02_collectors.lua' => 'scripting/win_conditions/collectors.lua'
2=== renamed file 'scripting/win_conditions/01_defeat_all.lua' => 'scripting/win_conditions/defeat_all.lua'
3=== renamed file 'scripting/win_conditions/00_endless_game.lua' => 'scripting/win_conditions/endless_game.lua'
4=== renamed file 'scripting/win_conditions/05_endless_game_fogless.lua' => 'scripting/win_conditions/endless_game_fogless.lua'
5=== added file 'scripting/win_conditions/init.lua'
6--- scripting/win_conditions/init.lua 1970-01-01 00:00:00 +0000
7+++ scripting/win_conditions/init.lua 2015-02-06 16:48:18 +0000
8@@ -0,0 +1,12 @@
9+-- This config file sets the order of the starting conditions
10+dirname = path.dirname(__file__)
11+
12+return {
13+ dirname .. "collectors.lua",
14+ dirname .. "wood_gnome.lua",
15+ dirname .. "territorial_time.lua",
16+ dirname .. "territorial_lord.lua",
17+ dirname .. "defeat_all.lua",
18+ dirname .. "endless_game.lua",
19+ dirname .. "endless_game_fogless.lua",
20+}
21
22=== renamed file 'scripting/win_conditions/03_territorial_lord.lua' => 'scripting/win_conditions/territorial_lord.lua'
23=== renamed file 'scripting/win_conditions/03_territorial_time.lua' => 'scripting/win_conditions/territorial_time.lua'
24=== renamed file 'scripting/win_conditions/04_wood_gnome.lua' => 'scripting/win_conditions/wood_gnome.lua'
25=== modified file 'src/logic/game_settings.h'
26--- src/logic/game_settings.h 2014-09-20 09:37:47 +0000
27+++ src/logic/game_settings.h 2015-02-06 16:48:18 +0000
28@@ -20,11 +20,15 @@
29 #ifndef WL_LOGIC_GAME_SETTINGS_H
30 #define WL_LOGIC_GAME_SETTINGS_H
31
32+#include <memory>
33 #include <string>
34 #include <vector>
35
36+#include "io/filesystem/layered_filesystem.h"
37 #include "logic/tribe_basic_info.h"
38 #include "logic/widelands.h"
39+#include "scripting/lua_interface.h"
40+#include "scripting/lua_table.h"
41
42 namespace Widelands {
43 enum class PlayerEndResult : uint8_t;
44@@ -82,7 +86,18 @@
45 scenario(false),
46 multiplayer(false),
47 savegame(false)
48- {}
49+ {
50+ std::unique_ptr<LuaTable> win_conditions(
51+ (new LuaInterface)->run_script("scripting/win_conditions/init.lua"));
52+ for (const int key : win_conditions->keys<int>()) {
53+ std::string filename = win_conditions->get_string(key);
54+ if (g_fs->file_exists(filename)) {
55+ win_condition_scripts.push_back(filename);
56+ } else {
57+ throw wexception("Win condition file \"%s\" does not exist", filename.c_str());
58+ }
59+ }
60+ }
61
62 /// Number of player position
63 int16_t playernum;
64@@ -95,6 +110,8 @@
65
66 /// Lua file defining the win condition to use.
67 std::string win_condition_script;
68+ /// An ordered list of all win condition script files.
69+ std::vector<std::string> win_condition_scripts;
70
71 /// Is map a scenario
72 bool scenario;
73
74=== modified file 'src/network/netclient.cc'
75--- src/network/netclient.cc 2015-01-31 16:03:59 +0000
76+++ src/network/netclient.cc 2015-02-06 16:48:18 +0000
77@@ -124,12 +124,8 @@
78 d->desiredspeed = 1000;
79 file = nullptr;
80
81- // Temporarily register win condition scripts to get the default
82- std::set<std::string> win_condition_scripts =
83- filter(g_fs->list_directory("scripting/win_conditions"),
84- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
85- assert(win_condition_scripts.size());
86- d->settings.win_condition_script = *win_condition_scripts.begin();
87+ // Get the default win condition script
88+ d->settings.win_condition_script = d->settings.win_condition_scripts.front();
89 }
90
91 NetClient::~NetClient ()
92
93=== modified file 'src/network/nethost.cc'
94--- src/network/nethost.cc 2015-01-31 16:03:59 +0000
95+++ src/network/nethost.cc 2015-02-06 16:48:18 +0000
96@@ -58,6 +58,7 @@
97 #include "network/network_system.h"
98 #include "profile/profile.h"
99 #include "scripting/lua_interface.h"
100+#include "scripting/lua_table.h"
101 #include "ui_basic/progresswindow.h"
102 #include "ui_fsmenu/launch_mpg.h"
103 #include "wlapplication.h"
104@@ -67,11 +68,8 @@
105
106
107 struct HostGameSettingsProvider : public GameSettingsProvider {
108- HostGameSettingsProvider(NetHost * const _h) : h(_h), m_lua(nullptr), m_cur_wincondition(0) {}
109- ~HostGameSettingsProvider() {
110- delete m_lua;
111- m_lua = nullptr;
112- }
113+ HostGameSettingsProvider(NetHost * const _h) : h(_h), m_cur_wincondition(0) {}
114+ ~HostGameSettingsProvider() {}
115
116 void set_scenario(bool is_scenario) override {h->set_scenario(is_scenario);}
117
118@@ -294,14 +292,8 @@
119 }
120
121 void next_win_condition() override {
122- if (m_win_condition_scripts.size() < 1) {
123- if (!m_lua)
124- m_lua = new LuaInterface();
125- std::set<std::string> win_conditions =
126- filter(g_fs->list_directory("scripting/win_conditions"),
127- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
128- m_win_condition_scripts.insert(
129- m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
130+ if (m_win_condition_scripts.empty()) {
131+ m_win_condition_scripts = h->settings().win_condition_scripts;
132 m_cur_wincondition = -1;
133 }
134
135@@ -314,7 +306,6 @@
136
137 private:
138 NetHost * h;
139- LuaInterface * m_lua;
140 int16_t m_cur_wincondition;
141 std::vector<std::string> m_win_condition_scripts;
142 };
143
144=== modified file 'src/ui_fsmenu/launch_spg.cc'
145--- src/ui_fsmenu/launch_spg.cc 2015-01-31 16:03:59 +0000
146+++ src/ui_fsmenu/launch_spg.cc 2015-02-06 16:48:18 +0000
147@@ -25,6 +25,7 @@
148
149 #include "base/i18n.h"
150 #include "base/warning.h"
151+#include "base/wexception.h"
152 #include "graphic/graphic.h"
153 #include "graphic/text_constants.h"
154 #include "helper.h"
155@@ -126,15 +127,8 @@
156 (boost::bind
157 (&FullscreenMenuLaunchSPG::start_clicked, boost::ref(*this)));
158
159-
160 m_lua = new LuaInterface();
161- std::set<std::string> win_conditions =
162- filter(g_fs->list_directory("scripting/win_conditions"),
163- [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
164-
165- m_win_condition_scripts.insert(
166- m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
167-
168+ m_win_condition_scripts = m_settings->settings().win_condition_scripts;
169 m_cur_wincondition = -1;
170 win_condition_clicked();
171

Subscribers

People subscribed via source and target branches

to status/vote changes: