widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03268
Re: [Merge] lp:~widelands-dev/widelands/bug-1281823 into lp:widelands
Review: Needs Fixing
You missed some :). See inline comments.
Diff comments:
> === modified file 'src/editor/map_generator.cc'
> --- src/editor/map_generator.cc 2014-09-20 09:37:47 +0000
> +++ src/editor/map_generator.cc 2014-12-01 21:50:51 +0000
> @@ -138,7 +138,7 @@
> res_val /= 3;
> if (editor_change_resource_tool_callback(fc, map_, world, res_idx)) {
> fc.field->set_resources(res_idx, res_val);
> - fc.field->set_starting_res_amount(res_val);
> + fc.field->set_initial_res_amount(res_val);
> }
> };
>
>
> === modified file 'src/editor/tools/editor_decrease_resources_tool.cc'
> --- src/editor/tools/editor_decrease_resources_tool.cc 2014-09-20 09:37:47 +0000
> +++ src/editor/tools/editor_decrease_resources_tool.cc 2014-12-01 21:50:51 +0000
> @@ -66,10 +66,10 @@
> map.overlay_manager().remove_overlay(mr.location(), pic);
> if (!amount) {
> mr.location().field->set_resources(0, 0);
> - mr.location().field->set_starting_res_amount(0);
> + mr.location().field->set_initial_res_amount(0);
> } else {
> mr.location().field->set_resources(args.cur_res, amount);
> - mr.location().field->set_starting_res_amount(amount);
> + mr.location().field->set_initial_res_amount(amount);
> // set new overlay
> str = world.get_resource(args.cur_res)->get_editor_pic(amount);
> pic = g_gr->images().get(str);
>
> === modified file 'src/editor/tools/editor_increase_resources_tool.cc'
> --- src/editor/tools/editor_increase_resources_tool.cc 2014-09-20 09:37:47 +0000
> +++ src/editor/tools/editor_increase_resources_tool.cc 2014-12-01 21:50:51 +0000
> @@ -121,10 +121,10 @@
>
> if (!amount) {
> mr.location().field->set_resources(0, 0);
> - mr.location().field->set_starting_res_amount(0);
> + mr.location().field->set_initial_res_amount(0);
> } else {
> mr.location().field->set_resources(args.cur_res, amount);
> - mr.location().field->set_starting_res_amount(amount);
> + mr.location().field->set_initial_res_amount(amount);
> // set new overlay
> pic = g_gr->images().get
> (world.get_resource(args.cur_res)->get_editor_pic(amount));
>
> === modified file 'src/editor/tools/editor_set_resources_tool.cc'
> --- src/editor/tools/editor_set_resources_tool.cc 2014-09-20 09:37:47 +0000
> +++ src/editor/tools/editor_set_resources_tool.cc 2014-12-01 21:50:51 +0000
> @@ -63,10 +63,10 @@
>
> if (!amount) {
> mr.location().field->set_resources(0, 0);
> - mr.location().field->set_starting_res_amount(0);
> + mr.location().field->set_initial_res_amount(0);
> } else {
> mr.location().field->set_resources(args.cur_res, amount);
> - mr.location().field->set_starting_res_amount(amount);
> + mr.location().field->set_initial_res_amount(amount);
> // set new overlay
> pic =
> g_gr->images().get(world.get_resource(args.cur_res)->get_editor_pic(amount));
> @@ -107,10 +107,10 @@
>
> if (!amount) {
> mr.location().field->set_resources(0, 0);
> - mr.location().field->set_starting_res_amount(0);
> + mr.location().field->set_initial_res_amount(0);
> } else {
> mr.location().field->set_resources(*it, amount);
> - mr.location().field->set_starting_res_amount(amount);
> + mr.location().field->set_initial_res_amount(amount);
> // set new overlay
> pic = g_gr->images().get(world.get_resource(*it)->get_editor_pic(amount));
> overlay_manager.register_overlay(mr.location(), pic, 4);
>
> === modified file 'src/logic/field.h'
> --- src/logic/field.h 2014-09-14 11:31:58 +0000
> +++ src/logic/field.h 2014-12-01 21:50:51 +0000
> @@ -124,7 +124,7 @@
> OwnerInfoAndSelectionsType owner_info_and_selections;
>
> ResourceIndex m_resources; ///< Resource type on this field, if any
> - uint8_t m_starting_res_amount; ///< Initial amount of m_resources
> + uint8_t m_initial_res_amount; ///< Initial amount of m_resources
> uint8_t m_res_amount; ///< Current amount of m_resources
>
> Terrains terrains;
> @@ -214,11 +214,11 @@
> }
>
> // TODO(unknown): This should take uint8_t
> - void set_starting_res_amount(int32_t const amount) {
> - m_starting_res_amount = amount;
> + void set_initial_res_amount(int32_t const amount) {
> + m_initial_res_amount = amount;
> }
> // TODO(unknown): This should return uint8_t
> - int32_t get_starting_res_amount() const {return m_starting_res_amount;}
> + int32_t get_initial_res_amount() const {return m_initial_res_amount;}
>
> /// \note you must reset this field's + neighbor's brightness when you
> /// change the height. Map::change_height does this. This function is not
>
> === modified file 'src/logic/findnode.cc'
> --- src/logic/findnode.cc 2014-11-28 16:40:55 +0000
> +++ src/logic/findnode.cc 2014-12-01 21:50:51 +0000
> @@ -126,7 +126,7 @@
> if (m_resource != coord.field->get_resources()) {
> return false;
> }
> - if (coord.field->get_resources_amount() < coord.field->get_starting_res_amount()) {
> + if (coord.field->get_resources_amount() < coord.field->get_initial_res_amount()) {
> return true;
> }
> for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
> @@ -134,7 +134,7 @@
> if
> (m_resource == neighb.field->get_resources()
> &&
> - neighb.field->get_resources_amount() < neighb.field->get_starting_res_amount())
> + neighb.field->get_resources_amount() < neighb.field->get_initial_res_amount())
> {
> return true;
> }
>
> === modified file 'src/logic/map.cc'
> --- src/logic/map.cc 2014-10-29 06:41:10 +0000
> +++ src/logic/map.cc 2014-12-01 21:50:51 +0000
> @@ -272,10 +272,10 @@
>
> if (res == -1 || !amount) {
> f.field->set_resources(0, 0);
> - f.field->set_starting_res_amount(0);
> + f.field->set_initial_res_amount(0);
> } else {
> f.field->set_resources(res, amount);
> - f.field->set_starting_res_amount(amount);
> + f.field->set_initial_res_amount(amount);
> }
>
> }
>
> === modified file 'src/logic/production_program.cc'
> --- src/logic/production_program.cc 2014-11-22 11:21:12 +0000
> +++ src/logic/production_program.cc 2014-12-01 21:50:51 +0000
> @@ -1254,7 +1254,7 @@
> uint8_t fres = mr.location().field->get_resources();
> uint32_t amount = mr.location().field->get_resources_amount();
> uint32_t start_amount =
> - mr.location().field->get_starting_res_amount();
> + mr.location().field->get_initial_res_amount();
>
> if (fres != m_resource) {
> amount = 0;
>
> === modified file 'src/logic/worker.cc'
> --- src/logic/worker.cc 2014-11-30 18:49:38 +0000
> +++ src/logic/worker.cc 2014-12-01 21:50:51 +0000
> @@ -235,7 +235,7 @@
> do {
> uint8_t fres = mr.location().field->get_resources();
> uint32_t amount =
> - mr.location().field->get_starting_res_amount() -
> + mr.location().field->get_initial_res_amount() -
> mr.location().field->get_resources_amount ();
>
> // In the future, we might want to support amount = 0 for
> @@ -278,7 +278,7 @@
> continue;
>
> uint32_t amount =
> - mr.location().field->get_starting_res_amount() -
> + mr.location().field->get_initial_res_amount() -
> mr.location().field->get_resources_amount ();
>
> pick -= 8 * amount;
> @@ -288,7 +288,7 @@
> --amount;
>
> mr.location().field->set_resources
> - (res, mr.location().field->get_starting_res_amount() - amount);
> + (res, mr.location().field->get_initial_res_amount() - amount);
> break;
> }
> } while (mr.advance(map));
>
> === modified file 'src/map_io/map_resources_packet.cc'
> --- src/map_io/map_resources_packet.cc 2014-09-20 09:37:47 +0000
> +++ src/map_io/map_resources_packet.cc 2014-12-01 21:50:51 +0000
> @@ -86,7 +86,7 @@
> if (0xa < set_id)
> throw "Unknown resource in map file. It is not in world!\n";
> map[Coords(x, y)].set_resources(set_id, set_amount);
> - map[Coords(x, y)].set_starting_res_amount(set_start_amount);
> + map[Coords(x, y)].set_initial_res_amount(set_start_amount);
> }
> }
> } else
> @@ -133,7 +133,7 @@
> const Field & f = map[Coords(x, y)];
> int32_t res = f.get_resources ();
> int32_t const amount = f.get_resources_amount ();
> - int32_t const start_amount = f.get_starting_res_amount();
> + int32_t const start_amount = f.get_initial_res_amount();
> if (!amount)
> res = 0;
> fw.unsigned_8(res);
>
> === modified file 'src/map_io/s2map.cc'
> --- src/map_io/s2map.cc 2014-10-04 09:40:18 +0000
> +++ src/map_io/s2map.cc 2014-12-01 21:50:51 +0000
> @@ -645,7 +645,7 @@
> const int32_t real_amount = static_cast<int32_t>
> (2.86 * static_cast<float>(amount));
> f->set_resources(nres, real_amount);
> - f->set_starting_res_amount(real_amount);
> + f->set_initial_res_amount(real_amount);
> }
>
>
>
> === modified file 'src/scripting/lua_map.cc'
> --- src/scripting/lua_map.cc 2014-11-30 18:49:38 +0000
> +++ src/scripting/lua_map.cc 2014-12-01 21:50:51 +0000
> @@ -3502,6 +3502,7 @@
> PROP_RO(LuaField, viewpoint_y),
> PROP_RW(LuaField, resource),
> PROP_RW(LuaField, resource_amount),
> + PROP_RO(LuaField, starting_resource_amount),
> PROP_RO(LuaField, claimers),
> PROP_RO(LuaField, owner),
> {nullptr, nullptr, nullptr},
> @@ -3661,10 +3662,21 @@
> report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, max_amount);
>
> field->set_resources(res, amount);
> + field->set_initial_res_amount(amount);
>
> return 0;
> }
> -
> +/* RST
> + .. attribute:: starting_resource_amount
you missed this function and it's documentation
> +
> + (RO) Starting value of resource. It is set be resource_amount
> +
> + :see also: :attr:`resource`
> +*/
> +int LuaField::get_starting_resource_amount(lua_State * L) {
> + lua_pushuint32(L, fcoords(L).field->get_initial_res_amount());
> + return 1;
> +}
> /* RST
> .. attribute:: immovable
>
>
> === modified file 'src/scripting/lua_map.h'
> --- src/scripting/lua_map.h 2014-09-14 11:31:58 +0000
> +++ src/scripting/lua_map.h 2014-12-01 21:50:51 +0000
> @@ -942,6 +942,7 @@
> int set_resource(lua_State *);
> int get_resource_amount(lua_State *);
> int set_resource_amount(lua_State *);
> + int get_starting_resource_amount(lua_State *);
> int get_claimers(lua_State *);
> int get_owner(lua_State *);
>
>
> === modified file 'src/wui/game_debug_ui.cc'
> --- src/wui/game_debug_ui.cc 2014-11-30 18:49:38 +0000
> +++ src/wui/game_debug_ui.cc 2014-12-01 21:50:51 +0000
> @@ -360,7 +360,7 @@
> {
> Widelands::ResourceIndex ridx = m_coords.field->get_resources();
> int ramount = m_coords.field->get_resources_amount();
> - int startingAmount = m_coords.field->get_starting_res_amount();
> + int startingAmount = m_coords.field->get_initial_res_amount();
starting_amount. This is not java. Or rather initial_amount
>
> str += (boost::format("Resource: %s\n")
> % ibase().egbase().world().get_resource(ridx)->name().c_str()).str();
>
> === modified file 'test/maps/lua_testsuite.wmf/scripting/efield.lua'
> --- test/maps/lua_testsuite.wmf/scripting/efield.lua 2014-01-12 19:06:22 +0000
> +++ test/maps/lua_testsuite.wmf/scripting/efield.lua 2014-12-01 21:50:51 +0000
> @@ -11,5 +11,17 @@
> assert_equal(0, self.f.resource_amount)
> end
>
> +function field_resources_tests:test_starting_resource_in_editor()
> + -- making sure that (set_) resource_amount sets also starting resource
> + assert_equal("coal", self.f.resource)
> + self.f.resource_amount=10
> + assert_equal(self.f.starting_resource_amount, self.f.resource_amount)
> + assert_equal(10, self.f.starting_resource_amount)
> + self.f.resource_amount=20
> + assert_equal(self.f.starting_resource_amount, self.f.resource_amount)
> + assert_equal(20, self.f.starting_resource_amount)
> +end
> +
> +
>
>
>
--
https://code.launchpad.net/~widelands-dev/widelands/bug-1281823/+merge/242837
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1281823.
References