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
=== renamed file 'scripting/win_conditions/02_collectors.lua' => 'scripting/win_conditions/collectors.lua'
=== renamed file 'scripting/win_conditions/01_defeat_all.lua' => 'scripting/win_conditions/defeat_all.lua'
=== renamed file 'scripting/win_conditions/00_endless_game.lua' => 'scripting/win_conditions/endless_game.lua'
=== renamed file 'scripting/win_conditions/05_endless_game_fogless.lua' => 'scripting/win_conditions/endless_game_fogless.lua'
=== added file 'scripting/win_conditions/init.lua'
--- scripting/win_conditions/init.lua 1970-01-01 00:00:00 +0000
+++ scripting/win_conditions/init.lua 2015-02-06 16:48:18 +0000
@@ -0,0 +1,12 @@
1-- This config file sets the order of the starting conditions
2dirname = path.dirname(__file__)
3
4return {
5 dirname .. "collectors.lua",
6 dirname .. "wood_gnome.lua",
7 dirname .. "territorial_time.lua",
8 dirname .. "territorial_lord.lua",
9 dirname .. "defeat_all.lua",
10 dirname .. "endless_game.lua",
11 dirname .. "endless_game_fogless.lua",
12}
013
=== renamed file 'scripting/win_conditions/03_territorial_lord.lua' => 'scripting/win_conditions/territorial_lord.lua'
=== renamed file 'scripting/win_conditions/03_territorial_time.lua' => 'scripting/win_conditions/territorial_time.lua'
=== renamed file 'scripting/win_conditions/04_wood_gnome.lua' => 'scripting/win_conditions/wood_gnome.lua'
=== modified file 'src/logic/game_settings.h'
--- src/logic/game_settings.h 2014-09-20 09:37:47 +0000
+++ src/logic/game_settings.h 2015-02-06 16:48:18 +0000
@@ -20,11 +20,15 @@
20#ifndef WL_LOGIC_GAME_SETTINGS_H20#ifndef WL_LOGIC_GAME_SETTINGS_H
21#define WL_LOGIC_GAME_SETTINGS_H21#define WL_LOGIC_GAME_SETTINGS_H
2222
23#include <memory>
23#include <string>24#include <string>
24#include <vector>25#include <vector>
2526
27#include "io/filesystem/layered_filesystem.h"
26#include "logic/tribe_basic_info.h"28#include "logic/tribe_basic_info.h"
27#include "logic/widelands.h"29#include "logic/widelands.h"
30#include "scripting/lua_interface.h"
31#include "scripting/lua_table.h"
2832
29namespace Widelands {33namespace Widelands {
30enum class PlayerEndResult : uint8_t;34enum class PlayerEndResult : uint8_t;
@@ -82,7 +86,18 @@
82 scenario(false),86 scenario(false),
83 multiplayer(false),87 multiplayer(false),
84 savegame(false)88 savegame(false)
85 {}89 {
90 std::unique_ptr<LuaTable> win_conditions(
91 (new LuaInterface)->run_script("scripting/win_conditions/init.lua"));
92 for (const int key : win_conditions->keys<int>()) {
93 std::string filename = win_conditions->get_string(key);
94 if (g_fs->file_exists(filename)) {
95 win_condition_scripts.push_back(filename);
96 } else {
97 throw wexception("Win condition file \"%s\" does not exist", filename.c_str());
98 }
99 }
100 }
86101
87 /// Number of player position102 /// Number of player position
88 int16_t playernum;103 int16_t playernum;
@@ -95,6 +110,8 @@
95110
96 /// Lua file defining the win condition to use.111 /// Lua file defining the win condition to use.
97 std::string win_condition_script;112 std::string win_condition_script;
113 /// An ordered list of all win condition script files.
114 std::vector<std::string> win_condition_scripts;
98115
99 /// Is map a scenario116 /// Is map a scenario
100 bool scenario;117 bool scenario;
101118
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc 2015-01-31 16:03:59 +0000
+++ src/network/netclient.cc 2015-02-06 16:48:18 +0000
@@ -124,12 +124,8 @@
124 d->desiredspeed = 1000;124 d->desiredspeed = 1000;
125 file = nullptr;125 file = nullptr;
126126
127 // Temporarily register win condition scripts to get the default127 // Get the default win condition script
128 std::set<std::string> win_condition_scripts =128 d->settings.win_condition_script = d->settings.win_condition_scripts.front();
129 filter(g_fs->list_directory("scripting/win_conditions"),
130 [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
131 assert(win_condition_scripts.size());
132 d->settings.win_condition_script = *win_condition_scripts.begin();
133}129}
134130
135NetClient::~NetClient ()131NetClient::~NetClient ()
136132
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2015-01-31 16:03:59 +0000
+++ src/network/nethost.cc 2015-02-06 16:48:18 +0000
@@ -58,6 +58,7 @@
58#include "network/network_system.h"58#include "network/network_system.h"
59#include "profile/profile.h"59#include "profile/profile.h"
60#include "scripting/lua_interface.h"60#include "scripting/lua_interface.h"
61#include "scripting/lua_table.h"
61#include "ui_basic/progresswindow.h"62#include "ui_basic/progresswindow.h"
62#include "ui_fsmenu/launch_mpg.h"63#include "ui_fsmenu/launch_mpg.h"
63#include "wlapplication.h"64#include "wlapplication.h"
@@ -67,11 +68,8 @@
6768
6869
69struct HostGameSettingsProvider : public GameSettingsProvider {70struct HostGameSettingsProvider : public GameSettingsProvider {
70 HostGameSettingsProvider(NetHost * const _h) : h(_h), m_lua(nullptr), m_cur_wincondition(0) {}71 HostGameSettingsProvider(NetHost * const _h) : h(_h), m_cur_wincondition(0) {}
71 ~HostGameSettingsProvider() {72 ~HostGameSettingsProvider() {}
72 delete m_lua;
73 m_lua = nullptr;
74 }
7573
76 void set_scenario(bool is_scenario) override {h->set_scenario(is_scenario);}74 void set_scenario(bool is_scenario) override {h->set_scenario(is_scenario);}
7775
@@ -294,14 +292,8 @@
294 }292 }
295293
296 void next_win_condition() override {294 void next_win_condition() override {
297 if (m_win_condition_scripts.size() < 1) {295 if (m_win_condition_scripts.empty()) {
298 if (!m_lua)296 m_win_condition_scripts = h->settings().win_condition_scripts;
299 m_lua = new LuaInterface();
300 std::set<std::string> win_conditions =
301 filter(g_fs->list_directory("scripting/win_conditions"),
302 [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
303 m_win_condition_scripts.insert(
304 m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
305 m_cur_wincondition = -1;297 m_cur_wincondition = -1;
306 }298 }
307299
@@ -314,7 +306,6 @@
314306
315private:307private:
316 NetHost * h;308 NetHost * h;
317 LuaInterface * m_lua;
318 int16_t m_cur_wincondition;309 int16_t m_cur_wincondition;
319 std::vector<std::string> m_win_condition_scripts;310 std::vector<std::string> m_win_condition_scripts;
320};311};
321312
=== modified file 'src/ui_fsmenu/launch_spg.cc'
--- src/ui_fsmenu/launch_spg.cc 2015-01-31 16:03:59 +0000
+++ src/ui_fsmenu/launch_spg.cc 2015-02-06 16:48:18 +0000
@@ -25,6 +25,7 @@
2525
26#include "base/i18n.h"26#include "base/i18n.h"
27#include "base/warning.h"27#include "base/warning.h"
28#include "base/wexception.h"
28#include "graphic/graphic.h"29#include "graphic/graphic.h"
29#include "graphic/text_constants.h"30#include "graphic/text_constants.h"
30#include "helper.h"31#include "helper.h"
@@ -126,15 +127,8 @@
126 (boost::bind127 (boost::bind
127 (&FullscreenMenuLaunchSPG::start_clicked, boost::ref(*this)));128 (&FullscreenMenuLaunchSPG::start_clicked, boost::ref(*this)));
128129
129
130 m_lua = new LuaInterface();130 m_lua = new LuaInterface();
131 std::set<std::string> win_conditions =131 m_win_condition_scripts = m_settings->settings().win_condition_scripts;
132 filter(g_fs->list_directory("scripting/win_conditions"),
133 [](const std::string& fn) {return boost::ends_with(fn, ".lua");});
134
135 m_win_condition_scripts.insert(
136 m_win_condition_scripts.end(), win_conditions.begin(), win_conditions.end());
137
138 m_cur_wincondition = -1;132 m_cur_wincondition = -1;
139 win_condition_clicked();133 win_condition_clicked();
140134

Subscribers

People subscribed via source and target branches

to status/vote changes: