widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #09917
[Merge] lp:~widelands-dev/widelands/bug-1675179-lua-hide-fields into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1675179-lua-hide-fields into lp:widelands.
Commit message:
Added option to Lua function player:hide_fields to mark them as unexplored.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1675179 in widelands: "missing/new lua functions"
https://bugs.launchpad.net/widelands/+bug/1675179
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1675179-lua-hide-fields/+merge/320981
New Lua function for the Barbarians 3 scenario.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1675179-lua-hide-fields into lp:widelands.
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc 2017-03-03 18:13:55 +0000
+++ src/logic/player.cc 2017-03-24 19:05:11 +0000
@@ -1024,9 +1024,10 @@
field.vision = fvision;
}
-void Player::unsee_node(MapIndex const i, Time const gametime, bool const forward) {
+/// If 'hide_completely', fields will be marked as unexplored. Else, player no longer sees what's currently going on.
+void Player::unsee_node(MapIndex const i, Time const gametime, const bool hide_completely, bool const forward) {
Field& field = fields_[i];
- if (field.vision <= 1) // Already does not see this
+ if ((!hide_completely && field.vision <= 1) || field.vision < 1) // Already does not see this
return;
// If this is not already a forwarded call, we should inform allied players
@@ -1035,13 +1036,18 @@
update_team_players();
if (!forward && !team_player_.empty()) {
for (uint8_t j = 0; j < team_player_.size(); ++j)
- team_player_[j]->unsee_node(i, gametime, true);
+ team_player_[j]->unsee_node(i, gametime, hide_completely, true);
}
- --field.vision;
- if (field.vision == 1)
+ if (hide_completely) {
+ field.vision = 0;
+ } else {
+ --field.vision;
+ assert(1 <= field.vision);
+ }
+ if (field.vision < 2) {
field.time_node_last_unseen = gametime;
- assert(1 <= field.vision);
+ }
}
/**
=== modified file 'src/logic/player.h'
--- src/logic/player.h 2017-01-25 18:55:59 +0000
+++ src/logic/player.h 2017-03-24 19:05:11 +0000
@@ -445,7 +445,7 @@
const bool forward = false);
/// Decrement this player's vision for a node.
- void unsee_node(const MapIndex, const Time, const bool forward = false);
+ void unsee_node(const MapIndex, const Time, const bool hide_completely = false, const bool forward = false);
/// Call see_node for each node in the area.
void see_area(const Area<FCoords>& area) {
=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc 2017-01-25 18:55:59 +0000
+++ src/scripting/lua_game.cc 2017-03-24 19:05:11 +0000
@@ -620,6 +620,9 @@
:arg fields: The fields to hide
:type fields: :class:`array` of :class:`wl.map.Fields`
+ :arg hide_completely: *Optional*. The fields will be marked as unexplored.
+ :type hide_completely: :class:`boolean`
+
:returns: :const:`nil`
*/
int LuaPlayer::hide_fields(lua_State* L) {
@@ -628,11 +631,12 @@
Map& m = egbase.map();
luaL_checktype(L, 2, LUA_TTABLE);
+ const bool hide_completely = !lua_isnone(L, 3) && luaL_checkboolean(L, 3);
lua_pushnil(L); /* first key */
while (lua_next(L, 2) != 0) {
- p.unsee_node(
- (*get_user_class<LuaField>(L, -1))->fcoords(L).field - &m[0], egbase.get_gametime());
+ p.unsee_node((*get_user_class<LuaField>(L, -1))->fcoords(L).field - &m[0],
+ egbase.get_gametime(), hide_completely);
lua_pop(L, 1);
}
=== modified file 'test/maps/lua_testsuite.wmf/scripting/gplayer.lua'
--- test/maps/lua_testsuite.wmf/scripting/gplayer.lua 2017-01-17 20:07:46 +0000
+++ test/maps/lua_testsuite.wmf/scripting/gplayer.lua 2017-03-24 19:05:11 +0000
@@ -59,6 +59,30 @@
assert_equal(true, player1:sees_field(self.f))
end
+-- This test must go last, because we change the state of player1:seen_field.
+function player_vision_tests:test_hide_completely()
+ player1.see_all = true
+ assert_equal(true, player1:sees_field(self.f))
+ player1.see_all = false
+ assert_equal(false, player1:sees_field(self.f))
+
+ player1:hide_fields(self.f:region(1), false)
+ game.desired_speed = 0;
+ assert_equal(false, player1:sees_field(self.f))
+ assert_equal(true, player1:seen_field(self.f))
+
+ player1.see_all = true
+ assert_equal(true, player1:sees_field(self.f))
+ player1.see_all = false
+ assert_equal(false, player1:sees_field(self.f))
+
+ player1:hide_fields(self.f:region(1), true)
+ game.desired_speed = 0;
+ assert_equal(false, player1:sees_field(self.f))
+ assert_equal(false, player1:seen_field(self.f))
+ player1:reveal_fields(self.f:region(1))
+end
+
-- =========================
-- Forbid & Allow buildings
Follow ups