Merge lp:~widelands-dev/widelands/warehouse_worker into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7619
Proposed branch: lp:~widelands-dev/widelands/warehouse_worker
Merge into: lp:widelands
Diff against target: 81 lines (+15/-15)
2 files modified
src/logic/warehouse.cc (+14/-14)
src/logic/warehouse.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/warehouse_worker
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+277221@code.launchpad.net

Description of the change

Fixed bug in warehouse where check was done for ware instead of worker.

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

I just opened the bug bug-1515161 - this is probably the same issue ...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Yes, that's the one.

Revision history for this message
TiborB (tiborb95) wrote :

It seems that crash is gone, I left small question in diff

Revision history for this message
GunChleoc (gunchleoc) wrote :

Answered :)

Revision history for this message
TiborB (tiborb95) wrote :

good then, go ahead, this really needs fixing fast

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/logic/warehouse.cc'
--- src/logic/warehouse.cc 2015-10-18 15:42:01 +0000
+++ src/logic/warehouse.cc 2015-11-11 09:47:46 +0000
@@ -858,19 +858,19 @@
858/// Start a worker of a given type. The worker will858/// Start a worker of a given type. The worker will
859/// be assigned a job by the caller.859/// be assigned a job by the caller.
860Worker & Warehouse::launch_worker860Worker & Warehouse::launch_worker
861 (Game & game, WareIndex ware, const Requirements & req)861 (Game & game, WareIndex worker_id, const Requirements & req)
862{862{
863 do {863 do {
864 if (m_supply->stock_workers(ware)) {864 if (m_supply->stock_workers(worker_id)) {
865 uint32_t unincorporated = m_supply->stock_workers(ware);865 uint32_t unincorporated = m_supply->stock_workers(worker_id);
866866
867 // look if we got one of those in stock867 // look if we got one of those in stock
868 if (m_incorporated_workers.count(ware)) {868 if (m_incorporated_workers.count(worker_id)) {
869 // On cleanup, it could be that the worker was deleted under869 // On cleanup, it could be that the worker was deleted under
870 // us, so we erase the pointer we had to it and create a new870 // us, so we erase the pointer we had to it and create a new
871 // one.871 // one.
872 remove_no_longer_existing_workers(game, &m_incorporated_workers[ware]);872 remove_no_longer_existing_workers(game, &m_incorporated_workers[worker_id]);
873 WorkerList& incorporated_workers = m_incorporated_workers[ware];873 WorkerList& incorporated_workers = m_incorporated_workers[worker_id];
874874
875 for (std::vector<Worker *>::iterator worker_iter = incorporated_workers.begin();875 for (std::vector<Worker *>::iterator worker_iter = incorporated_workers.begin();
876 worker_iter != incorporated_workers.end(); ++worker_iter)876 worker_iter != incorporated_workers.end(); ++worker_iter)
@@ -883,30 +883,30 @@
883 worker->set_location(this); // back in a economy883 worker->set_location(this); // back in a economy
884 incorporated_workers.erase(worker_iter);884 incorporated_workers.erase(worker_iter);
885885
886 m_supply->remove_workers(ware, 1);886 m_supply->remove_workers(worker_id, 1);
887 return *worker;887 return *worker;
888 }888 }
889 }889 }
890 }890 }
891891
892 assert(unincorporated <= m_supply->stock_workers(ware));892 assert(unincorporated <= m_supply->stock_workers(worker_id));
893893
894 if (unincorporated) {894 if (unincorporated) {
895 // Create a new one895 // Create a new one
896 // NOTE: This code lies about the TrainingAttributes of the new worker896 // NOTE: This code lies about the TrainingAttributes of the new worker
897 m_supply->remove_workers(ware, 1);897 m_supply->remove_workers(worker_id, 1);
898 const WorkerDescr & workerdescr = *game.tribes().get_worker_descr(ware);898 const WorkerDescr & workerdescr = *game.tribes().get_worker_descr(worker_id);
899 return workerdescr.create(game, owner(), this, m_position);899 return workerdescr.create(game, owner(), this, m_position);
900 }900 }
901 }901 }
902902
903 if (can_create_worker(game, ware)) {903 if (can_create_worker(game, worker_id)) {
904 // don't want to use an upgraded worker, so create new one.904 // don't want to use an upgraded worker, so create new one.
905 create_worker(game, ware);905 create_worker(game, worker_id);
906 } else {906 } else {
907 ware = game.tribes().get_worker_descr(ware)->becomes();907 worker_id = game.tribes().get_worker_descr(worker_id)->becomes();
908 }908 }
909 } while (owner().tribe().has_ware(ware));909 } while (owner().tribe().has_worker(worker_id));
910910
911 throw wexception911 throw wexception
912 ("Warehouse::launch_worker: worker does not actually exist");912 ("Warehouse::launch_worker: worker does not actually exist");
913913
=== modified file 'src/logic/warehouse.h'
--- src/logic/warehouse.h 2015-11-01 10:11:56 +0000
+++ src/logic/warehouse.h 2015-11-11 09:47:46 +0000
@@ -173,7 +173,7 @@
173 bool fetch_from_flag(Game &) override;173 bool fetch_from_flag(Game &) override;
174174
175 uint32_t count_workers(const Game &, WareIndex, const Requirements &);175 uint32_t count_workers(const Game &, WareIndex, const Requirements &);
176 Worker & launch_worker(Game &, WareIndex, const Requirements &);176 Worker & launch_worker(Game &, WareIndex worker, const Requirements &);
177177
178 // Adds the worker to the inventory. Takes ownership and might delete178 // Adds the worker to the inventory. Takes ownership and might delete
179 // 'worker'.179 // 'worker'.

Subscribers

People subscribed via source and target branches

to status/vote changes: