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

Proposed by Jens Beyer
Status: Merged
Merged at revision: 7540
Proposed branch: lp:~widelands-dev/widelands/bug580923
Merge into: lp:widelands
Diff against target: 90 lines (+33/-19)
2 files modified
src/logic/warehouse.cc (+32/-18)
src/logic/warehouse.h (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug580923
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+273274@code.launchpad.net

Description of the change

Freely creating workers in special situations (cheating ^^) is gone.

For widelands game itself it should not make a big difference, as the carrier doesn't cost anything. The game still creates carriers once a second or so, even if not needed.

But when you apply a buildcost to the carrier, the automatic creation stops, and they are created only if necessary.

If there is no carrier, and no resources to create one, the economy stalls...

Please test thoroughly, I don't know if I have found all cases and circumstances to test.

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

It looks good to me. But what is the purpose of this change? Can you imagine that carriers will have any kind of buildcost in the future? If not, then such change is not needed.

Revision history for this message
Jens Beyer (qcumber-some) wrote :

Hi TiborB, thanks for looking into it.

For the reason of the change, please have a look at the related bug ( https://bugs.launchpad.net/widelands/+bug/580923 ), SirVer states it quite clearly, it is not a bug for Widelands (Game), but for Widelands (Engine), and there have been people (including myself) trying to alter the game by applying buildcost to the Carrier, which was undermining by this bug.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have tested it and LTGM :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/warehouse.cc'
2--- src/logic/warehouse.cc 2015-07-24 18:21:58 +0000
3+++ src/logic/warehouse.cc 2015-10-02 18:24:14 +0000
4@@ -788,11 +788,17 @@
5 {
6 WareIndex const carrierid = descr().tribe().safe_worker_index("carrier");
7
8- if (!m_supply->stock_workers(carrierid)) // XXX yep, let's cheat
9- insert_workers(carrierid, 1);
10-
11- launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag
12- (game);
13+ if (!m_supply->stock_workers(carrierid))
14+ {
15+ if (can_create_worker(game, carrierid))
16+ {
17+ create_worker(game, carrierid);
18+ }
19+ }
20+ if (m_supply->stock_workers(carrierid))
21+ {
22+ launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag(game);
23+ }
24
25 return true;
26 }
27@@ -930,29 +936,37 @@
28 // Create the ware
29 WareInstance & ware = *new WareInstance(ware_index, descr().tribe().get_ware_descr(ware_index));
30 ware.init(game);
31- do_launch_ware(game, ware);
32-
33- m_supply->remove_wares(ware_index, 1);
34-
35+ if (do_launch_ware(game, ware))
36+ {
37+ m_supply->remove_wares(ware_index, 1);
38+ }
39 return ware;
40 }
41
42
43 /// Get a carrier to actually move this ware out of the warehouse.
44-void Warehouse::do_launch_ware(Game & game, WareInstance & ware)
45+bool Warehouse::do_launch_ware(Game & game, WareInstance & ware)
46 {
47 // Create a carrier
48 WareIndex const carrierid = descr().tribe().worker_index("carrier");
49- const WorkerDescr & workerdescr = *descr().tribe().get_worker_descr(carrierid);
50-
51- Worker & worker = workerdescr.create(game, owner(), this, m_position);
52-
53- // Yup, this is cheating.
54+
55+ if (!m_supply->stock_workers(carrierid))
56+ {
57+ if (can_create_worker(game, carrierid))
58+ {
59+ create_worker(game, carrierid);
60+ }
61+ }
62 if (m_supply->stock_workers(carrierid))
63- m_supply->remove_workers(carrierid, 1);
64+ {
65+ Widelands::Worker & worker = launch_worker(game, carrierid, Requirements());
66+ // Setup the carrier
67+ worker.start_task_dropoff(game, ware);
68+ return true;
69+ }
70
71- // Setup the carrier
72- worker.start_task_dropoff(game, ware);
73+ //we did not launch the ware...
74+ return false;
75 }
76
77
78
79=== modified file 'src/logic/warehouse.h'
80--- src/logic/warehouse.h 2015-02-12 21:49:05 +0000
81+++ src/logic/warehouse.h 2015-10-02 18:24:14 +0000
82@@ -183,7 +183,7 @@
83 void incorporate_worker(EditorGameBase&, Worker* worker);
84
85 WareInstance & launch_ware(Game &, WareIndex);
86- void do_launch_ware(Game &, WareInstance &);
87+ bool do_launch_ware(Game &, WareInstance &);
88
89 // Adds the ware to our inventory. Takes ownership and might delete 'ware'.
90 void incorporate_ware(EditorGameBase&, WareInstance* ware);

Subscribers

People subscribed via source and target branches

to status/vote changes: