← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1688655-suitability-mines into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1688655-suitability-mines into lp:widelands.

Commit message:
Fixed place_building_in_region to allow placing mines.
- Extended BuildingDescr::suitability to include mines.
- Changed return value to bool.
- Removed unused parameter 'req_suitability' from function place_building_in_region in infrastructure.lua.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1688655 in widelands: "lua func "place_building_in_region" not work for mines"
  https://bugs.launchpad.net/widelands/+bug/1688655

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1688655-suitability-mines/+merge/323716

Can be tested by hacking the Fortified Village starting condition like this:

=== modified file 'data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua'
--- data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua	2016-12-03 16:37:13 +0000
+++ data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua	2017-05-06 19:15:43 +0000
@@ -92,5 +92,8 @@
       place_building_in_region(plr, "barbarians_lime_kiln", sf:region(12), {
          inputs = { granite = 6, coal = 3 },
       })
+      place_building_in_region(plr, "barbarians_coalmine", sf:region(12), {
+         inputs = { ration = 3 },
+      })
    end
 }

-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1688655-suitability-mines into lp:widelands.
=== modified file 'data/scripting/infrastructure.lua'
--- data/scripting/infrastructure.lua	2016-11-01 14:54:20 +0000
+++ data/scripting/infrastructure.lua	2017-05-06 19:26:51 +0000
@@ -132,24 +132,19 @@
 --    :arg opts:  a table with prefill information (wares, soldiers, workers,
 --       see :func:`prefilled_buildings`) and the following options:
 --
---       req_suitability
---          The reguired suitability for this building. Default value is 1.
 --    :type opts: :class:`table`
 --
 --    :returns: the building created
-function place_building_in_region(
-   plr, building, fields, gargs
-)
+function place_building_in_region(plr, building, fields, gargs)
    local idx
    local f
    local args = gargs or {}
-   local req_suitability = args.req_suitability or 1
 
    while #fields > 0 do
       local idx = math.random(#fields)
       local f = fields[idx]
 
-      if plr:get_suitability(building, f) >= req_suitability then
+      if plr:get_suitability(building, f) then
          args[1] = building
          args[2] = f.x
          args[3] = f.y

=== 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-06 19:26:51 +0000
@@ -184,8 +184,10 @@
 	return b;
 }
 
-int32_t BuildingDescr::suitability(const Map&, const FCoords& fc) const {
-	return size_ <= (fc.field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK);
+bool BuildingDescr::suitability(const Map&, const FCoords& fc) const {
+	return mine_ ?
+		fc.field->nodecaps() & Widelands::BUILDCAPS_MINE :
+		size_ <= (fc.field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK);
 }
 
 /**

=== 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-06 19:26:51 +0000
@@ -155,7 +155,7 @@
 
 	WorkareaInfo workarea_info_;
 
-	virtual int32_t suitability(const Map&, const FCoords&) const;
+	bool suitability(const Map&, const FCoords&) const;
 	const BuildingHints& hints() const {
 		return hints_;
 	}

=== 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-06 19:26:51 +0000
@@ -785,17 +785,17 @@
 /* RST
    .. method:: get_suitability(building, field)
 
-      Returns the suitability that this building has for this field. This
-      is mainly useful in initialization where buildings must be placed
+      Returns whether this building type can be placed on this field. This
+      is mainly useful in initializations where buildings must be placed
       automatically.
 
-      :arg building: name of the building to check for
+      :arg building: name of the building description to check for
       :type building: :class:`string`
       :arg field: where the suitability should be checked
       :type field: :class:`wl.map.Field`
 
-      :returns: the suitability
-      :rtype: :class:`integer`
+      :returns: whether the field has a suitable building plot for this building type
+      :rtype: :class:`boolean`
 */
 // UNTESTED
 int LuaPlayer::get_suitability(lua_State* L) {
@@ -807,7 +807,7 @@
 	if (!tribes.building_exists(i))
 		report_error(L, "Unknown building type: <%s>", name);
 
-	lua_pushint32(L, tribes.get_building_descr(i)->suitability(
+	lua_pushboolean(L, tribes.get_building_descr(i)->suitability(
 	                    game.map(), (*get_user_class<LuaField>(L, 3))->fcoords(L)));
 	return 1;
 }


Follow ups