← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1687100-reveal_fields into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1687100-reveal_fields into lp:widelands.

Commit message:
LuaPlayer::hide_fields no longer hides fields that the player's buildings see.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1687100 in widelands: "Lua: reveal_fields after hide_fields(fields, hide_completely) does not respect seen fields"
  https://bugs.launchpad.net/widelands/+bug/1687100

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1687100-reveal_fields/+merge/323721

This was actually a long-standing bug - the function wasn't doing what the documentation described in the first place.

Can be tested by hacking the seafaring tutorial:


=== modified file 'data/campaigns/tutorial03_seafaring.wmf/scripting/mission_thread.lua'
--- data/campaigns/tutorial03_seafaring.wmf/scripting/mission_thread.lua	2016-10-23 11:31:25 +0000
+++ data/campaigns/tutorial03_seafaring.wmf/scripting/mission_thread.lua	2017-05-07 07:51:04 +0000
@@ -5,6 +5,14 @@
 function introduction()
    additional_port_space.terr = "summer_water" -- disable the port space
    sleep(1000)
+
+plr:reveal_fields(wl.Game().map:get_field(41,43):region(60))
+plr:hide_fields(wl.Game().map:get_field(41,43):region(40),true)
+
+plr:hide_fields(wl.Game().map:get_field(43,52):region(20),true)
+plr:reveal_fields(wl.Game().map:get_field(43,52):region(20))
+sleep(600000)
+
    message_box_objective(plr, intro_south)
    sleep(300)
    message_box_objective(plr, intro_north)


-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1687100-reveal_fields into lp:widelands.
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc	2017-05-03 07:24:06 +0000
+++ src/logic/map_objects/tribes/building.cc	2017-05-07 08:07:03 +0000
@@ -713,6 +713,13 @@
 }
 
 /**
+ * Returns whether this building should see its vision range.
+ */
+bool Building::is_seeing() const {
+	return seeing_ || descr().type() == MapObjectType::WAREHOUSE;
+}
+
+/**
  * Send a message about this building to the owning player.
  *
  * It will have the building's coordinates, and display a picture of the

=== modified file 'src/logic/map_objects/tribes/building.h'
--- src/logic/map_objects/tribes/building.h	2017-04-23 12:11:19 +0000
+++ src/logic/map_objects/tribes/building.h	2017-05-07 08:07:03 +0000
@@ -235,6 +235,8 @@
 	}
 	PositionList get_positions(const EditorGameBase&) const override;
 
+	bool is_seeing() const;
+
 	std::string info_string(const InfoStringFormat& format);
 
 	// Return the overlay string that is displayed on the map view when enabled

=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc	2017-04-22 05:35:46 +0000
+++ src/scripting/lua_game.cc	2017-05-07 08:07:03 +0000
@@ -27,6 +27,7 @@
 #include "economy/flag.h"
 #include "logic/campaign_visibility.h"
 #include "logic/game_controller.h"
+#include "logic/map_objects/tribes/building.h"
 #include "logic/map_objects/tribes/tribe_descr.h"
 #include "logic/message.h"
 #include "logic/objective.h"
@@ -615,7 +616,7 @@
    .. method:: hide_fields(fields)
 
       Make these fields hidden for the current player if they are not
-      seen by a military building.
+      seen by a building.
 
       :arg fields: The fields to hide
       :type fields: :class:`array` of :class:`wl.map.Fields`
@@ -641,6 +642,19 @@
 		lua_pop(L, 1);
 	}
 
+	// Player should still see what the buildings see
+	for (const auto& building_index : p.tribe().buildings()) {
+		const std::vector<Player::BuildingStats>& stats_vector = p.get_building_statistics(building_index);
+		for (size_t i = 0; i < stats_vector.size(); ++i) {
+			const BaseImmovable* immovable = m[stats_vector[i].pos].get_immovable();
+			if (upcast(const Widelands::Building, building, immovable)) {
+				if (building->is_seeing()) {
+					p.see_area(Area<FCoords>(m.get_fcoords(building->get_position()), building->descr().vision_range()));
+				}
+			}
+		}
+	}
+
 	return 0;
 }
 


Follow ups