Merge lp:~widelands-dev/widelands/economy_tutorial_fix into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7501
Proposed branch: lp:~widelands-dev/widelands/economy_tutorial_fix
Merge into: lp:widelands
Diff against target: 73 lines (+26/-1)
4 files modified
campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua (+1/-1)
src/scripting/lua_root.cc (+13/-0)
src/scripting/lua_root.h (+1/-0)
test/maps/plain.wmf/scripting/test_gamespeed.lua (+11/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/economy_tutorial_fix
Reviewer Review Type Date Requested Status
wl-zocker Approve
Review via email: mp+266519@code.launchpad.net

Description of the change

Economy tutorial: the building statistics window needs some time to build its contents.

To post a comment you must log in.
Revision history for this message
wl-zocker (wl-zocker) wrote :

This seems to work fine at speed 1.0, but if I increase the game speed, the window still has too little time to build up. Maybe using sleep(game_speed) helps? Also, you can remove sleep(500) three lines above. I think that was enough time to build up the old buildings statistics menu.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Good idea - done :)

Revision history for this message
wl-zocker (wl-zocker) wrote :

You also could have used wl.Game().desired_speed ... Or is there a difference?

Revision history for this message
GunChleoc (gunchleoc) wrote :

desired_speed sets the speed instead of just reading it.

Revision history for this message
wl-zocker (wl-zocker) wrote :
Revision history for this message
GunChleoc (gunchleoc) wrote :

I see. Now I'm wondering if we would have a use for the real speed as well though, because it makes a difference in multiplayer. Of course, for this branch, it doesn't matter.

Revision history for this message
wl-zocker (wl-zocker) wrote :

I tested your change and when using desired_speed, it works fine with speeds up to 50.

Regarding real_speed: I do not know if we want to introduce a new function that serves little purpose. Changing the speed in multiplayer scenarios might have strange effects (I guess desired_speed only works for player 1).

Revision history for this message
GunChleoc (gunchleoc) wrote :

real_speed is read-only, and it's the speed that the game is actually using. Desired speed is set by each user (read/write). In single player games, they are identical, but in multiplayer games, the real_speed is some form of arithmetic mean of the desired speeds of each player.

Revision history for this message
wl-zocker (wl-zocker) wrote :

I understand the difference between real and desired speed. I was just wondering whether we need more code (to maintain etc.). I'll approve the changes you made because the building statistics window is now always shown correctly. If you think it is necessary to keep the new function, then do so.

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

Merged. Thanks for the review :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua'
2--- campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2015-06-10 13:01:28 +0000
3+++ campaigns/tutorial04_economy.wmf/scripting/mission_thread.lua 2015-08-02 10:36:19 +0000
4@@ -20,9 +20,9 @@
5 sleep(2000)
6 local o = message_box_objective(plr, building_stat)
7 while not mv.windows.building_statistics do sleep(100) end
8- sleep(500)
9 o.done = true
10
11+ sleep(wl.Game().real_speed) -- The building statistics window needs some time to build up
12 o = message_box_objective(plr,explain_building_stat)
13 -- We cannot create several objectives with the same name. Therefore, we create o2 here once and change its visibility
14 local o2 = add_campaign_objective(reopen_building_stat_obj)
15
16=== modified file 'src/scripting/lua_root.cc'
17--- src/scripting/lua_root.cc 2015-01-31 16:03:59 +0000
18+++ src/scripting/lua_root.cc 2015-08-02 10:36:19 +0000
19@@ -83,6 +83,7 @@
20 {nullptr, nullptr},
21 };
22 const PropertyType<LuaGame> LuaGame::Properties[] = {
23+ PROP_RO(LuaGame, real_speed),
24 PROP_RO(LuaGame, time),
25 PROP_RW(LuaGame, desired_speed),
26 PROP_RW(LuaGame, allow_autosaving),
27@@ -107,6 +108,18 @@
28 */
29
30 /* RST
31+ .. attribute:: real_speed
32+
33+ (RO) The speed that the current game is running at in ms.
34+ For example, for game speed = 2x, this returns 2000.
35+*/
36+int LuaGame::get_real_speed(lua_State * L) {
37+ lua_pushinteger(L, get_game(L).game_controller()->real_speed());
38+ return 1;
39+}
40+
41+
42+/* RST
43 .. attribute:: time
44
45 (RO) The absolute time elapsed since the game was started in milliseconds.
46
47=== modified file 'src/scripting/lua_root.h'
48--- src/scripting/lua_root.h 2015-01-31 16:03:59 +0000
49+++ src/scripting/lua_root.h 2015-08-02 10:36:19 +0000
50@@ -48,6 +48,7 @@
51 /*
52 * Properties
53 */
54+ int get_real_speed(lua_State * L);
55 int get_time(lua_State *);
56 int get_desired_speed(lua_State *);
57 int set_desired_speed(lua_State *);
58
59=== added file 'test/maps/plain.wmf/scripting/test_gamespeed.lua'
60--- test/maps/plain.wmf/scripting/test_gamespeed.lua 1970-01-01 00:00:00 +0000
61+++ test/maps/plain.wmf/scripting/test_gamespeed.lua 2015-08-02 10:36:19 +0000
62@@ -0,0 +1,11 @@
63+run(function()
64+ sleep(1000)
65+
66+ game.desired_speed = 5000
67+ assert_equal(game.real_speed, 5000)
68+ assert_equal(game.desired_speed, 5000)
69+ assert_equal(game.real_speed, 5000)
70+
71+ print("# All Tests passed.")
72+ wl.ui.MapView():close()
73+end)

Subscribers

People subscribed via source and target branches

to status/vote changes: