Merge lp:~widelands-dev/widelands/bug-1664145-miners into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8296
Proposed branch: lp:~widelands-dev/widelands/bug-1664145-miners
Merge into: lp:widelands
Diff against target: 87 lines (+37/-8)
3 files modified
src/logic/map_objects/tribes/warehouse.cc (+7/-7)
src/logic/map_objects/tribes/warehouse.h (+1/-1)
test/maps/plain.wmf/scripting/test_upgraded_workers.lua (+29/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1664145-miners
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+317710@code.launchpad.net

Commit message

Fixed a bug where higher-level workers wouldn't occupy lower-level workers' working position slots in productionsites. Added a test.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 1965. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/203049468.
Appveyor build 1800. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1664145_miners-1800.

Revision history for this message
toptopple (7010622-q-deactivatedaccount) wrote :

Tested today and appears to work correctly now. There was a tiny glitch in that 2 Master Miners (out of 7) remained at home despite new Miner posts requested; instead new Miners were created. We cannot say at this point where exactly this error lies, assuming it is an error. However, I would suggest that clearing out all Miners, Chief Miners and Master Miners should be target before new Miners are created from Pickaxes.

Revision history for this message
TiborB (tiborb95) wrote :

Gun, I can not see where in the code/diff you had changed anything..

Revision history for this message
GunChleoc (gunchleoc) wrote :

I marked up the line with the fix.

The tiny glitch is probably the result of a complex economy and a lot harder to track down. Can you reproduce it reliably? If so, we can add the info to the bug and keep the bug open.

Revision history for this message
TiborB (tiborb95) wrote :

Oh, I overlooked

As for the mentioned glitch - it is questionable if the fetching higher worker should be always preferred to creation of a new worker. I think mines right now are not able to switch higher worker for a spare lower worker to make the higher one available in case of need elsewhere.
But for now this should go as is

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

You make a good point about the glitch.

@bunnybot merge

Revision history for this message
toptopple (7010622-q-deactivatedaccount) wrote :

>I think mines right now are not able to switch higher worker for a spare lower worker to make the higher one available in case of need elsewhere.

Not a good point in my view! I think there should be still something to do for the players of the game to perform. What is certainly correct is that AI-players must be in the position to perform miner shifting (not the mines themselves!), but this request must be up already.

Revision history for this message
GunChleoc (gunchleoc) wrote :

We have 3 open bugs regarding workers in productionsites:

https://bugs.launchpad.net/widelands/+bug/1235928
https://bugs.launchpad.net/widelands/+bug/1299011
https://bugs.launchpad.net/widelands/+bug/1619981

None of them describe your point, so please feel free to open a new bug for this :)

Revision history for this message
TiborB (tiborb95) wrote :

I think current situation is not that bad, game will try:
a) fetch miner of the same level
b) create new one (applicable for lowest miner only, of course)
c) fetch higher miner if available

switching options b<->c would not be significant difference I believe. But I dont mind such change...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc 2017-02-12 09:10:57 +0000
+++ src/logic/map_objects/tribes/warehouse.cc 2017-02-18 23:38:55 +0000
@@ -742,17 +742,17 @@
742 * requirements.742 * requirements.
743 */743 */
744Quantity Warehouse::count_workers(const Game& /* game */,744Quantity Warehouse::count_workers(const Game& /* game */,
745 DescriptionIndex ware,745 DescriptionIndex worker_id,
746 const Requirements& req,746 const Requirements& req,
747 Match exact) {747 Match exact) {
748 Quantity sum = 0;748 Quantity sum = 0;
749749
750 do {750 do {
751 sum += supply_->stock_workers(ware);751 sum += supply_->stock_workers(worker_id);
752752
753 // NOTE: This code lies about the TrainingAttributes of non-instantiated workers.753 // NOTE: This code lies about the TrainingAttributes of non-instantiated workers.
754 if (incorporated_workers_.count(ware)) {754 if (incorporated_workers_.count(worker_id)) {
755 for (Worker* worker : incorporated_workers_[ware]) {755 for (Worker* worker : incorporated_workers_[worker_id]) {
756 if (!req.check(*worker)) {756 if (!req.check(*worker)) {
757 // This is one of the workers in our sum.757 // This is one of the workers in our sum.
758 // But he is too stupid for this job758 // But he is too stupid for this job
@@ -761,11 +761,11 @@
761 }761 }
762 }762 }
763 if (exact == Match::kCompatible) {763 if (exact == Match::kCompatible) {
764 ware = owner().tribe().get_worker_descr(ware)->becomes();764 worker_id = owner().tribe().get_worker_descr(worker_id)->becomes();
765 } else {765 } else {
766 ware = INVALID_INDEX;766 worker_id = INVALID_INDEX;
767 }767 }
768 } while (owner().tribe().has_ware(ware));768 } while (owner().tribe().has_worker(worker_id));
769769
770 return sum;770 return sum;
771}771}
772772
=== modified file 'src/logic/map_objects/tribes/warehouse.h'
--- src/logic/map_objects/tribes/warehouse.h 2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/tribes/warehouse.h 2017-02-18 23:38:55 +0000
@@ -198,7 +198,7 @@
198198
199 bool fetch_from_flag(Game&) override;199 bool fetch_from_flag(Game&) override;
200200
201 Quantity count_workers(const Game&, DescriptionIndex, const Requirements&, Match);201 Quantity count_workers(const Game&, DescriptionIndex worker, const Requirements&, Match);
202 Worker& launch_worker(Game&, DescriptionIndex worker, const Requirements&);202 Worker& launch_worker(Game&, DescriptionIndex worker, const Requirements&);
203203
204 // Adds the worker to the inventory. Takes ownership and might delete204 // Adds the worker to the inventory. Takes ownership and might delete
205205
=== added file 'test/maps/plain.wmf/scripting/test_upgraded_workers.lua'
--- test/maps/plain.wmf/scripting/test_upgraded_workers.lua 1970-01-01 00:00:00 +0000
+++ test/maps/plain.wmf/scripting/test_upgraded_workers.lua 2017-02-18 23:38:55 +0000
@@ -0,0 +1,29 @@
1run(function()
2 sleep(5000)
3
4 assert_equal(1, #p1:get_buildings("barbarians_headquarters"))
5
6 local hq = p1:get_buildings("barbarians_headquarters")[1]
7
8 hq:set_workers("barbarians_miner_chief", 5)
9 assert_equal(5, hq:get_workers("barbarians_miner_chief"))
10
11 -- This mine needs a miner, a chief miner and a master miner
12 p1:place_road(p1:place_flag(map:get_field(25,22)), "bl", "bl", "bl", "bl")
13 local mine = p1:place_building("barbarians_coalmine_deeper", wl.Game().map:get_field(24, 21), false, true)
14
15 sleep(1000)
16
17 -- 2 of the chief miners should have been requested by the mine now,
18 -- one of them acting as a basic miner
19 assert_equal(3, hq:get_workers("barbarians_miner_chief"))
20
21 hq:set_workers("barbarians_miner_master", 1)
22 sleep(1000)
23
24 -- The master miner has filled the remaining slot
25 assert_equal(0, hq:get_workers("barbarians_miner_master"))
26
27 print("# All Tests passed.")
28 wl.ui.MapView():close()
29end)

Subscribers

People subscribed via source and target branches

to status/vote changes: