widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07599
[Merge] lp:~widelands-dev/widelands/fix_tut1_destroy_quarries_2 into lp:widelands
Miroslav Remák has proposed merging lp:~widelands-dev/widelands/fix_tut1_destroy_quarries_2 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fix_tut1_destroy_quarries_2/+merge/294713
The 'destroy_quarries_message' message box which is displayed after a quarry sends an "Out of rocks" message mentions receiving multiple messages.
This merge request prevents triggering destroy_quarries_message immediately after the stones are taken away if the player had previously restored any archived message.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fix_tut1_destroy_quarries_2 into lp:widelands.
=== modified file 'data/campaigns/tutorial01_basic_control.wmf/scripting/mission_thread.lua'
--- data/campaigns/tutorial01_basic_control.wmf/scripting/mission_thread.lua 2016-05-14 07:52:43 +0000
+++ data/campaigns/tutorial01_basic_control.wmf/scripting/mission_thread.lua 2016-05-14 16:10:30 +0000
@@ -332,8 +332,18 @@
-- Remove all rocks
remove_all_rocks(first_quarry_field:region(6))
+ function count_quarry_messages(field)
+ local count = 0
+ for i, msg in ipairs(plr.messages) do
+ if (msg.field == first_quarry_field or msg.field == second_quarry_field) then
+ count = count + 1
+ end
+ end
+ return count
+ end
+
-- Wait for messages to arrive
- while #plr.inbox < 1 do sleep(300) end
+ while count_quarry_messages() < 2 do sleep(300) end
local o = message_box_objective(plr, destroy_quarries_message)
=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc 2016-03-14 19:56:14 +0000
+++ src/scripting/lua_game.cc 2016-05-14 16:10:30 +0000
@@ -108,6 +108,7 @@
PROP_RO(LuaPlayer, allowed_buildings),
PROP_RO(LuaPlayer, objectives),
PROP_RO(LuaPlayer, defeated),
+ PROP_RO(LuaPlayer, messages),
PROP_RO(LuaPlayer, inbox),
PROP_RW(LuaPlayer, team),
PROP_RO(LuaPlayer, tribe),
@@ -192,9 +193,29 @@
}
/* RST
+ .. attribute:: messages
+
+ (RO) An array of all the messages sent to the player. Note that you
+ can't add messages to this array, use :meth:`send_message` for that.
+*/
+int LuaPlayer::get_messages(lua_State * L) {
+ Player & p = get(L, get_egbase(L));
+
+ lua_newtable(L);
+ uint32_t cidx = 1;
+ for (const auto& temp_message : p.messages()) {
+ lua_pushuint32(L, cidx ++);
+ to_lua<LuaMessage>(L, new LuaMessage(player_number(), temp_message.first));
+ lua_rawset(L, -3);
+ }
+
+ return 1;
+}
+
+/* RST
.. attribute:: inbox
- (RO) An array of the message that are either read or new. Note that you
+ (RO) An array of the messages that are either read or new. Note that you
can't add messages to this array, use :meth:`send_message` for that.
*/
int LuaPlayer::get_inbox(lua_State * L) {
=== modified file 'src/scripting/lua_game.h'
--- src/scripting/lua_game.h 2016-04-03 08:01:49 +0000
+++ src/scripting/lua_game.h 2016-05-14 16:10:30 +0000
@@ -63,6 +63,7 @@
int get_allowed_buildings(lua_State * L);
int get_objectives(lua_State * L);
int get_defeated(lua_State * L);
+ int get_messages(lua_State * L);
int get_inbox(lua_State * L);
int get_team(lua_State * L);
int get_tribe(lua_State * L);
Follow ups