Merge lp:~widelands-dev/widelands/bug-1721121-workers-invisible-wares into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8687
Proposed branch: lp:~widelands-dev/widelands/bug-1721121-workers-invisible-wares
Merge into: lp:widelands
Diff against target: 214 lines (+38/-64)
5 files modified
src/logic/map_objects/tribes/carrier.cc (+1/-23)
src/logic/map_objects/tribes/carrier.h (+0/-12)
src/logic/map_objects/tribes/worker.cc (+8/-0)
src/logic/map_objects/tribes/worker_descr.cc (+6/-15)
src/logic/map_objects/tribes/worker_descr.h (+23/-14)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1721121-workers-invisible-wares
Reviewer Review Type Date Requested Status
Notabilis diff, testing Approve
Review via email: mp+343272@code.launchpad.net

Commit message

Restored ware hotspot and animation to workers. Made some variables in WorkerDescr private and/or const.

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

Continuous integration builds have changed state:

Travis build 3376. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/366705865.
Appveyor build 3182. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1721121_workers_invisible_wares-3182.

Revision history for this message
Notabilis (notabilis27) wrote :

If I am not mistaken, this mostly just moves code around, right?
The lost wares are back and the code is looking good so in my opinion this can go in.
If you want to: two small nits regarding the documentation.

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

Thanks for the review - fixes applied :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map_objects/tribes/carrier.cc'
2--- src/logic/map_objects/tribes/carrier.cc 2018-04-07 16:59:00 +0000
3+++ src/logic/map_objects/tribes/carrier.cc 2018-05-05 09:26:43 +0000
4@@ -549,32 +549,10 @@
5 fw.signed_32(promised_pickup_to_);
6 }
7
8-void Carrier::draw_inner(const EditorGameBase& game,
9- const Vector2f& point_on_dst,
10- const float scale,
11- RenderTarget* dst) const {
12- assert(get_owner() != nullptr);
13- Worker::draw_inner(game, point_on_dst, scale, dst);
14-
15- if (WareInstance const* const carried_ware = get_carried_ware(game)) {
16- const RGBColor& player_color = get_owner()->get_playercolor();
17- const Vector2f hotspot = descr().get_ware_hotspot().cast<float>();
18- const Vector2f location(
19- point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);
20- dst->blit_animation(
21- location, scale, carried_ware->descr().get_animation("idle"), 0, player_color);
22- }
23-}
24-
25 CarrierDescr::CarrierDescr(const std::string& init_descname,
26 const LuaTable& table,
27 const EditorGameBase& egbase)
28- : WorkerDescr(init_descname, MapObjectType::CARRIER, table, egbase),
29- ware_hotspot_(Vector2i(0, 15)) {
30- if (table.has_key("ware_hotspot")) {
31- std::unique_ptr<LuaTable> items_table = table.get_table("ware_hotspot");
32- ware_hotspot_ = Vector2i(items_table->get_int(1), items_table->get_int(2));
33- }
34+ : WorkerDescr(init_descname, MapObjectType::CARRIER, table, egbase) {
35 }
36
37 /**
38
39=== modified file 'src/logic/map_objects/tribes/carrier.h'
40--- src/logic/map_objects/tribes/carrier.h 2018-04-07 16:59:00 +0000
41+++ src/logic/map_objects/tribes/carrier.h 2018-05-05 09:26:43 +0000
42@@ -33,16 +33,10 @@
43 ~CarrierDescr() override {
44 }
45
46- Vector2i get_ware_hotspot() const {
47- return ware_hotspot_;
48- }
49-
50 protected:
51 Bob& create_object() const override;
52
53 private:
54- Vector2i ware_hotspot_;
55-
56 DISALLOW_COPY_AND_ASSIGN(CarrierDescr);
57 };
58
59@@ -71,12 +65,6 @@
60
61 static Task const taskRoad;
62
63-protected:
64- void draw_inner(const EditorGameBase& game,
65- const Vector2f& point_on_dst,
66- const float scale,
67- RenderTarget* dst) const override;
68-
69 private:
70 void find_pending_ware(Game&);
71 int32_t find_closest_flag(Game&);
72
73=== modified file 'src/logic/map_objects/tribes/worker.cc'
74--- src/logic/map_objects/tribes/worker.cc 2018-04-07 16:59:00 +0000
75+++ src/logic/map_objects/tribes/worker.cc 2018-05-05 09:26:43 +0000
76@@ -2999,6 +2999,14 @@
77
78 dst->blit_animation(
79 point_on_dst, scale, get_current_anim(), game.get_gametime() - get_animstart(), player_color);
80+
81+ if (WareInstance const* const carried_ware = get_carried_ware(game)) {
82+ const Vector2f hotspot = descr().ware_hotspot().cast<float>();
83+ const Vector2f location(
84+ point_on_dst.x - hotspot.x * scale, point_on_dst.y - hotspot.y * scale);
85+ dst->blit_animation(
86+ location, scale, carried_ware->descr().get_animation("idle"), 0, player_color);
87+ }
88 }
89
90 /**
91
92=== modified file 'src/logic/map_objects/tribes/worker_descr.cc'
93--- src/logic/map_objects/tribes/worker_descr.cc 2018-04-07 16:59:00 +0000
94+++ src/logic/map_objects/tribes/worker_descr.cc 2018-05-05 09:26:43 +0000
95@@ -40,9 +40,12 @@
96 const LuaTable& table,
97 const EditorGameBase& egbase)
98 : BobDescr(init_descname, init_type, MapObjectDescr::OwnerType::kTribe, table),
99- buildable_(false),
100- needed_experience_(INVALID_INDEX),
101- becomes_(INVALID_INDEX),
102+ ware_hotspot_(table.has_key("ware_hotspot") ? Vector2i(table.get_table("ware_hotspot")->get_int(1), table.get_table("ware_hotspot")->get_int(2)) : Vector2i(0, 15)),
103+ default_target_quantity_(table.has_key("default_target_quantity") ? table.get_int("default_target_quantity") : std::numeric_limits<uint32_t>::max()),
104+ buildable_(table.has_key("buildcost")),
105+ // Read what the worker can become and the needed experience. If one of the keys is there, the other key must be there too. So, we cross the checks to trigger an exception if this is violated.
106+ becomes_(table.has_key("experience") ? egbase.tribes().safe_worker_index(table.get_string("becomes")) : INVALID_INDEX),
107+ needed_experience_(table.has_key("becomes") ? table.get_int("experience") : INVALID_INDEX),
108 egbase_(egbase) {
109 if (helptext_script().empty()) {
110 throw GameDataError("Worker %s has no helptext script", name().c_str());
111@@ -54,7 +57,6 @@
112 std::unique_ptr<LuaTable> items_table;
113
114 if (table.has_key("buildcost")) {
115- buildable_ = true;
116 const Tribes& tribes = egbase_.tribes();
117 items_table = table.get_table("buildcost");
118 for (const std::string& key : items_table->keys<std::string>()) {
119@@ -90,12 +92,6 @@
120 add_directional_animation(&walkload_anims_, "walkload");
121 }
122
123- // Read what the worker can become and the needed experience
124- if (table.has_key("becomes")) {
125- becomes_ = egbase_.tribes().safe_worker_index(table.get_string("becomes"));
126- needed_experience_ = table.get_int("experience");
127- }
128-
129 // Read programs
130 if (table.has_key("programs")) {
131 std::unique_ptr<LuaTable> programs_table = table.get_table("programs");
132@@ -114,11 +110,6 @@
133 }
134 }
135 }
136- if (table.has_key("default_target_quantity")) {
137- default_target_quantity_ = table.get_int("default_target_quantity");
138- } else {
139- default_target_quantity_ = std::numeric_limits<uint32_t>::max();
140- }
141 }
142
143 WorkerDescr::WorkerDescr(const std::string& init_descname,
144
145=== modified file 'src/logic/map_objects/tribes/worker_descr.h'
146--- src/logic/map_objects/tribes/worker_descr.h 2018-04-07 16:59:00 +0000
147+++ src/logic/map_objects/tribes/worker_descr.h 2018-05-05 09:26:43 +0000
148@@ -62,6 +62,10 @@
149 return buildcost_;
150 }
151
152+ const Vector2i& ware_hotspot() const {
153+ return ware_hotspot_;
154+ }
155+
156 /// How much of the worker type that an economy should store in warehouses.
157 /// The special value std::numeric_limits<uint32_t>::max() means that the
158 /// the target quantity of this ware type will never be checked and should
159@@ -82,9 +86,6 @@
160 default_target_quantity_ = 1;
161 }
162
163- const DirAnimations& get_walk_anims() const {
164- return walk_anims_;
165- }
166 const DirAnimations& get_right_walk_anims(bool const carries_ware) const {
167 return carries_ware ? walkload_anims_ : walk_anims_;
168 }
169@@ -116,26 +117,34 @@
170 }
171
172 protected:
173- Quantity default_target_quantity_;
174+ Programs programs_;
175+
176+private:
177+ const Vector2i ware_hotspot_;
178+
179 DirAnimations walk_anims_;
180 DirAnimations walkload_anims_;
181- bool buildable_;
182+
183+ Quantity default_target_quantity_;
184+ const bool buildable_;
185 Buildcost buildcost_;
186
187 /**
188+ * Type that this worker can become, i.e. level up to, or INVALID_INDEX if the worker cannot level up.
189+ */
190+ const DescriptionIndex becomes_;
191+
192+ /**
193 * Number of experience points required for leveling up,
194 * or INVALID_INDEX if the worker cannot level up.
195 */
196- int32_t needed_experience_;
197-
198- /**
199- * Type that this worker can become, i.e. level up to (or null).
200- */
201- DescriptionIndex becomes_;
202- Programs programs_;
203- std::set<DescriptionIndex> employers_; // Buildings where ths worker can work
204-private:
205+ const int32_t needed_experience_;
206+
207+ /// Buildings where this worker can work
208+ std::set<DescriptionIndex> employers_;
209+
210 const EditorGameBase& egbase_;
211+
212 DISALLOW_COPY_AND_ASSIGN(WorkerDescr);
213 };
214 }

Subscribers

People subscribed via source and target branches

to status/vote changes: