Merge lp:~widelands-dev/widelands/busy_roads_for_buildings into lp:widelands
- busy_roads_for_buildings
- Merge into trunk
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 7391 | ||||||||
Proposed branch: | lp:~widelands-dev/widelands/busy_roads_for_buildings | ||||||||
Merge into: | lp:widelands | ||||||||
Diff against target: |
1276 lines (+341/-140) 34 files modified
src/economy/flag.cc (+4/-2) src/economy/road.cc (+7/-7) src/graphic/game_renderer.cc (+7/-0) src/graphic/gl/fields_to_draw.h (+5/-1) src/graphic/gl/road_program.cc (+39/-51) src/graphic/gl/road_program.h (+6/-15) src/logic/CMakeLists.txt (+2/-0) src/logic/bob.h (+1/-1) src/logic/buildcost.h (+1/-1) src/logic/building.h (+1/-1) src/logic/editor_game_base.cc (+42/-12) src/logic/editor_game_base.h (+5/-3) src/logic/field.h (+2/-2) src/logic/immovable.h (+1/-1) src/logic/player.cc (+6/-6) src/logic/player.h (+4/-4) src/logic/production_program.h (+1/-1) src/logic/road_textures.cc (+38/-0) src/logic/road_textures.h (+45/-0) src/logic/roadtype.h (+8/-8) src/logic/tribe.cc (+50/-0) src/logic/tribe.h (+25/-2) src/logic/ware_descr.h (+1/-1) src/logic/warehouse.h (+1/-1) src/logic/worker_descr.h (+1/-1) src/map_io/map_players_view_packet.cc (+12/-12) src/scripting/lua_game.h (+1/-1) src/scripting/lua_map.cc (+3/-3) src/wui/encyclopedia_window.h (+1/-1) src/wui/interactive_base.cc (+1/-1) src/wui/waresdisplay.h (+1/-1) tribes/atlanteans/conf (+6/-0) tribes/barbarians/conf (+5/-0) tribes/empire/conf (+8/-0) |
||||||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/busy_roads_for_buildings | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+249013@code.launchpad.net |
Commit message
Description of the change
- Implement drawing of per-tribe roads and textures. Each tribe can have multiple normal or busy roads and they will be used at random when roads are drawn.
- Small buildings will now use normal roads for the road towards them, all others use busy roads.
SirVer (sirver) wrote : | # |
GunChleoc (gunchleoc) wrote : | # |
LGTM. We had discussed different road textures for different terrains though rather than using them at random. Maybe something for another branch?
SirVer (sirver) wrote : | # |
> LGTM. We had discussed different road textures for different terrains though rather than using them at random. Maybe something for another branch?
thanks for the review! I know that this has been discussed too, but it is distinct from the feature I added here. I hope that with this merge request, the repetition of roads can be reduced a bit to not look too dull.
About the roads per texture suggestion: I think it is viable to look into that, but I'd prefer to see some mocks before jumping at an implementation. I could imagine that it might get too noisy and with the current road system, pretty distinct (i.e. non uniform color) roads can be made that I hope are rather visible on all terrains.
kaputtnik (franku) wrote : | # |
If i add more than one normal road to each tribe, could i use this branch again for upload? Or must i create a new branch from trunk?
kaputtnik (franku) wrote : | # |
Forgotton: I want to store the related gimp-xcf files also somewhere in the project. I think widelands-media is the correct place for that... but its quity messy and i don't know where to put such files.
Chuck Wilder (chuckw20) wrote : | # |
The Widelands media branch is truly the place where the xcf files should be
stored.
If you wish, attach them to a reply here and I will be happy to push them
to the media branch. It is a huge trunk owing to all of the graphics files
and it takes a long time to checkout a branch.
On Tue, Feb 10, 2015 at 9:33 AM, kaputtnik <email address hidden> wrote:
> Forgotton: I want to store the related gimp-xcf files also somewhere in
> the project. I think widelands-media is the correct place for that... but
> its quity messy and i don't know where to put such files.
> --
>
> https:/
> You are subscribed to branch lp:widelands.
>
kaputtnik (franku) wrote : | # |
Thanks chuck,
the zip file contains xcf-files for each tribe plus one with testpatterns. If you find the testpatterns are useless, throw it away.
Because it isn't possible to make an attachment here, i provide a link to it:
http://
Chuck Wilder (chuckw20) wrote : | # |
I've got the zip file. The xcf's will be added to the media trunk with my
next push. Thanks!
On Wed, Feb 11, 2015 at 3:27 AM, kaputtnik <email address hidden> wrote:
> Thanks chuck,
>
> the zip file contains xcf-files for each tribe plus one with testpatterns.
> If you find the testpatterns are useless, throw it away.
>
> Because it isn't possible to make an attachment here, i provide a link to
> it:
>
> http://
> --
>
> https:/
> You are subscribed to branch lp:widelands.
>
SirVer (sirver) wrote : | # |
> If i add more than one normal road to each tribe, could i use this branch again for upload? Or must i create a new branch from trunk?
Making a new branch is usually the cleaner way of action. If that is inconvenient you can also reuse this one.
Preview Diff
1 | === modified file 'src/economy/flag.cc' |
2 | --- src/economy/flag.cc 2014-11-30 18:49:38 +0000 |
3 | +++ src/economy/flag.cc 2015-02-09 05:57:46 +0000 |
4 | @@ -203,7 +203,9 @@ |
5 | |
6 | const Map & map = egbase.map(); |
7 | egbase.set_road |
8 | - (map.get_fcoords(map.tl_n(m_position)), Road_SouthEast, Road_Normal); |
9 | + (map.get_fcoords(map.tl_n(m_position)), |
10 | + RoadType::kSouthEast, |
11 | + m_building->get_size() == BaseImmovable::SMALL? RoadType::kNormal : RoadType::kBusy); |
12 | |
13 | building.set_economy(get_economy()); |
14 | } |
15 | @@ -219,7 +221,7 @@ |
16 | |
17 | const Map & map = egbase.map(); |
18 | egbase.set_road |
19 | - (map.get_fcoords(map.tl_n(m_position)), Road_SouthEast, Road_None); |
20 | + (map.get_fcoords(map.tl_n(m_position)), RoadType::kSouthEast, RoadType::kNone); |
21 | |
22 | m_building = nullptr; |
23 | } |
24 | |
25 | === modified file 'src/economy/road.cc' |
26 | --- src/economy/road.cc 2014-11-30 18:49:38 +0000 |
27 | +++ src/economy/road.cc 2015-02-09 05:57:46 +0000 |
28 | @@ -99,7 +99,7 @@ |
29 | Player & owner = start.owner(); |
30 | Road & road = *new Road(); |
31 | road.set_owner(&owner); |
32 | - road.m_type = Road_Normal; |
33 | + road.m_type = RoadType::kNormal; |
34 | road.m_flags[FlagStart] = &start; |
35 | road.m_flags[FlagEnd] = &end; |
36 | // m_flagidx is set when attach_road() is called, i.e. in init() |
37 | @@ -224,7 +224,7 @@ |
38 | Direction const rdir = 2 * (dir - WALK_E); |
39 | |
40 | if (rdir <= 4) |
41 | - egbase.set_road(curf, rdir, Road_None); |
42 | + egbase.set_road(curf, rdir, RoadType::kNone); |
43 | } |
44 | |
45 | // mark the road that leads away from this field |
46 | @@ -233,7 +233,7 @@ |
47 | Direction const rdir = 2 * (dir - WALK_E); |
48 | |
49 | if (rdir <= 4) |
50 | - egbase.set_road(curf, rdir, Road_None); |
51 | + egbase.set_road(curf, rdir, RoadType::kNone); |
52 | |
53 | map.get_neighbour(curf, dir, &curf); |
54 | } |
55 | @@ -293,7 +293,7 @@ |
56 | } else if |
57 | (!slot.carrier_request && |
58 | (slot.carrier_type == 1 || |
59 | - m_type == Road_Busy)) { |
60 | + m_type == RoadType::kBusy)) { |
61 | _request_carrier(slot); |
62 | } |
63 | } |
64 | @@ -584,7 +584,7 @@ |
65 | (!slot.carrier.get(game) && |
66 | !slot.carrier_request && |
67 | (slot.carrier_type == 1 || |
68 | - m_type == Road_Busy)) { |
69 | + m_type == RoadType::kBusy)) { |
70 | _request_carrier(slot); |
71 | } |
72 | } |
73 | @@ -632,7 +632,7 @@ |
74 | // ie: cancelling current task |
75 | m_carrier_slots[1].carrier = nullptr; |
76 | m_carrier_slots[1].carrier_request = nullptr; |
77 | - m_type = Road_Normal; |
78 | + m_type = RoadType::kNormal; |
79 | _mark_map(game); |
80 | } |
81 | } |
82 | @@ -648,7 +648,7 @@ |
83 | if (100 < tdelta) { |
84 | m_busyness_last_update = gametime; |
85 | if (500 < (m_busyness += 10)) { |
86 | - m_type = Road_Busy; |
87 | + m_type = RoadType::kBusy; |
88 | _mark_map(game); |
89 | for (CarrierSlot& slot : m_carrier_slots) { |
90 | if |
91 | |
92 | === modified file 'src/graphic/game_renderer.cc' |
93 | --- src/graphic/game_renderer.cc 2014-11-28 08:13:14 +0000 |
94 | +++ src/graphic/game_renderer.cc 2015-02-09 05:57:46 +0000 |
95 | @@ -209,6 +209,13 @@ |
96 | |
97 | f.brightness = field_brightness(fcoords, gametime, map, player); |
98 | |
99 | + PlayerNumber owner_number = fcoords.field->get_owned_by(); |
100 | + if (owner_number > 0) { |
101 | + f.road_textures = &egbase.player(owner_number).tribe().road_textures(); |
102 | + } else { |
103 | + f.road_textures = nullptr; |
104 | + } |
105 | + |
106 | f.roads = field_roads(fcoords, map, player); |
107 | } |
108 | } |
109 | |
110 | === modified file 'src/graphic/gl/fields_to_draw.h' |
111 | --- src/graphic/gl/fields_to_draw.h 2014-11-08 18:06:17 +0000 |
112 | +++ src/graphic/gl/fields_to_draw.h 2015-02-09 05:57:46 +0000 |
113 | @@ -20,11 +20,14 @@ |
114 | #ifndef WL_GRAPHIC_GL_FIELDS_TO_DRAW_H |
115 | #define WL_GRAPHIC_GL_FIELDS_TO_DRAW_H |
116 | |
117 | +#include <cstddef> |
118 | +#include <string> |
119 | #include <vector> |
120 | -#include <cstddef> |
121 | |
122 | #include <stdint.h> |
123 | |
124 | +#include "logic/road_textures.h" |
125 | + |
126 | // Helper struct that contains the data needed for drawing all fields. All |
127 | // methods are inlined for performance reasons. |
128 | class FieldsToDraw { |
129 | @@ -37,6 +40,7 @@ |
130 | float brightness; // brightness of the pixel |
131 | uint8_t ter_r, ter_d; // Texture index of the right and down triangle. |
132 | uint8_t roads; // Bitmask of roads to render, see logic/roadtype.h. |
133 | + const RoadTextures* road_textures; // Road Textures to use for drawing. |
134 | }; |
135 | |
136 | FieldsToDraw(int minfx, int maxfx, int minfy, int maxfy) |
137 | |
138 | === modified file 'src/graphic/gl/road_program.cc' |
139 | --- src/graphic/gl/road_program.cc 2015-01-20 18:54:50 +0000 |
140 | +++ src/graphic/gl/road_program.cc 2015-02-09 05:57:46 +0000 |
141 | @@ -19,6 +19,7 @@ |
142 | |
143 | #include "graphic/gl/road_program.h" |
144 | |
145 | +#include <cassert> |
146 | #include <cmath> |
147 | |
148 | #include "base/log.h" |
149 | @@ -37,17 +38,14 @@ |
150 | // Attributes. |
151 | attribute vec2 attr_position; |
152 | attribute vec2 attr_texture_position; |
153 | -attribute float attr_texture_mix; |
154 | attribute float attr_brightness; |
155 | |
156 | // Outputs. |
157 | varying vec2 out_texture_position; |
158 | -varying float out_texture_mix; |
159 | varying float out_brightness; |
160 | |
161 | void main() { |
162 | out_texture_position = attr_texture_position; |
163 | - out_texture_mix = attr_texture_mix; |
164 | out_brightness = attr_brightness; |
165 | gl_Position = vec4(attr_position, 0., 1.); |
166 | } |
167 | @@ -58,16 +56,12 @@ |
168 | |
169 | // Inputs. |
170 | varying vec2 out_texture_position; |
171 | -varying float out_texture_mix; |
172 | varying float out_brightness; |
173 | |
174 | -uniform sampler2D u_normal_road_texture; |
175 | -uniform sampler2D u_busy_road_texture; |
176 | +uniform sampler2D u_texture; |
177 | |
178 | void main() { |
179 | - vec4 normal_road_color = texture2D(u_normal_road_texture, out_texture_position); |
180 | - vec4 busy_road_color = texture2D(u_busy_road_texture, out_texture_position); |
181 | - vec4 color = mix(normal_road_color, busy_road_color, out_texture_mix); |
182 | + vec4 color = texture2D(u_texture, out_texture_position); |
183 | color.rgb *= out_brightness; |
184 | gl_FragColor = color; |
185 | } |
186 | @@ -81,14 +75,9 @@ |
187 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); |
188 | attr_texture_position_ = |
189 | glGetAttribLocation(gl_program_.object(), "attr_texture_position"); |
190 | - attr_texture_mix_ = glGetAttribLocation(gl_program_.object(), "attr_texture_mix"); |
191 | attr_brightness_ = glGetAttribLocation(gl_program_.object(), "attr_brightness"); |
192 | |
193 | - u_normal_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_normal_road_texture"); |
194 | - u_busy_road_texture_ = glGetUniformLocation(gl_program_.object(), "u_busy_road_texture"); |
195 | - |
196 | - normal_road_texture_ = load_image("world/pics/roadt_normal.png"); |
197 | - busy_road_texture_ = load_image("world/pics/roadt_busy.png"); |
198 | + u_texture_ = glGetUniformLocation(gl_program_.object(), "u_texture"); |
199 | } |
200 | |
201 | RoadProgram::~RoadProgram() { |
202 | @@ -97,16 +86,15 @@ |
203 | void RoadProgram::add_road(const Surface& surface, |
204 | const FieldsToDraw::Field& start, |
205 | const FieldsToDraw::Field& end, |
206 | - const Widelands::RoadType road_type) { |
207 | + const Widelands::RoadType road_type, |
208 | + const Direction direction, |
209 | + int* gl_texture) { |
210 | // The thickness of the road in pixels on screen. |
211 | static constexpr float kRoadThicknessInPixels = 5.; |
212 | |
213 | // The overshot of the road in either direction in percent. |
214 | static constexpr float kRoadElongationInPercent = .1; |
215 | |
216 | - // A tiny value we use instead 0, to make sure that we always sample inside of the texture. |
217 | - constexpr float kEpsilon = 1e-6; |
218 | - |
219 | const float delta_x = end.pixel_x - start.pixel_x; |
220 | const float delta_y = end.pixel_y - start.pixel_y; |
221 | const float vector_length = std::hypot(delta_x, delta_y); |
222 | @@ -119,35 +107,43 @@ |
223 | const float road_thickness_x = (-delta_y / vector_length) * kRoadThicknessInPixels; |
224 | const float road_thickness_y = (delta_x / vector_length) * kRoadThicknessInPixels; |
225 | |
226 | - const float texture_mix = road_type == Widelands::Road_Normal ? 0. : 1.; |
227 | + const Texture& texture = |
228 | + road_type == Widelands::RoadType::kNormal ? |
229 | + start.road_textures->get_normal_texture(start.fx, start.fy, direction) : |
230 | + start.road_textures->get_busy_texture(start.fx, start.fy, direction); |
231 | + if (*gl_texture == -1) { |
232 | + *gl_texture = texture.get_gl_texture(); |
233 | + } |
234 | + // We assume that all road textures are in the same OpenGL texture, i.e. in |
235 | + // one texture atlas. |
236 | + assert(*gl_texture == texture.get_gl_texture()); |
237 | + |
238 | + const auto& texture_rect = texture.texture_coordinates(); |
239 | |
240 | vertices_.emplace_back(PerVertexData{ |
241 | start.pixel_x - road_overshoot_x + road_thickness_x, |
242 | start.pixel_y - road_overshoot_y + road_thickness_y, |
243 | - kEpsilon, |
244 | - kEpsilon, |
245 | + texture_rect.x, |
246 | + texture_rect.y, |
247 | start.brightness, |
248 | - texture_mix, |
249 | }); |
250 | surface.pixel_to_gl(&vertices_.back().gl_x, &vertices_.back().gl_y); |
251 | |
252 | vertices_.emplace_back(PerVertexData{ |
253 | start.pixel_x - road_overshoot_x - road_thickness_x, |
254 | start.pixel_y - road_overshoot_y - road_thickness_y, |
255 | - kEpsilon, |
256 | - 1.f - kEpsilon, |
257 | + texture_rect.x, |
258 | + texture_rect.y + texture_rect.h, |
259 | start.brightness, |
260 | - texture_mix, |
261 | }); |
262 | surface.pixel_to_gl(&vertices_.back().gl_x, &vertices_.back().gl_y); |
263 | |
264 | vertices_.emplace_back(PerVertexData{ |
265 | end.pixel_x + road_overshoot_x + road_thickness_x, |
266 | end.pixel_y + road_overshoot_y + road_thickness_y, |
267 | - 1.f - kEpsilon, |
268 | - kEpsilon, |
269 | + texture_rect.x + texture_rect.w, |
270 | + texture_rect.y, |
271 | end.brightness, |
272 | - texture_mix, |
273 | }); |
274 | surface.pixel_to_gl(&vertices_.back().gl_x, &vertices_.back().gl_y); |
275 | |
276 | @@ -161,10 +157,9 @@ |
277 | vertices_.emplace_back(PerVertexData{ |
278 | end.pixel_x + road_overshoot_x - road_thickness_x, |
279 | end.pixel_y + road_overshoot_y - road_thickness_y, |
280 | - 1.f - kEpsilon, |
281 | - 1.f - kEpsilon, |
282 | + texture_rect.x + texture_rect.w, |
283 | + texture_rect.y + texture_rect.h, |
284 | end.brightness, |
285 | - texture_mix, |
286 | }); |
287 | surface.pixel_to_gl(&vertices_.back().gl_x, &vertices_.back().gl_y); |
288 | } |
289 | @@ -172,6 +167,7 @@ |
290 | void RoadProgram::draw(const Surface& surface, const FieldsToDraw& fields_to_draw) { |
291 | vertices_.clear(); |
292 | |
293 | + int gl_texture = -1; |
294 | for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) { |
295 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); |
296 | |
297 | @@ -179,9 +175,9 @@ |
298 | const int rn_index = fields_to_draw.calculate_index(field.fx + 1, field.fy); |
299 | if (rn_index != -1) { |
300 | const Widelands::RoadType road = |
301 | - static_cast<Widelands::RoadType>(field.roads & Widelands::Road_Mask); |
302 | - if (road != Widelands::Road_None) { |
303 | - add_road(surface, field, fields_to_draw.at(rn_index), road); |
304 | + static_cast<Widelands::RoadType>(field.roads & Widelands::RoadType::kMask); |
305 | + if (road != Widelands::RoadType::kNone) { |
306 | + add_road(surface, field, fields_to_draw.at(rn_index), road, kEast, &gl_texture); |
307 | } |
308 | } |
309 | |
310 | @@ -189,9 +185,9 @@ |
311 | const int brn_index = fields_to_draw.calculate_index(field.fx + (field.fy & 1), field.fy + 1); |
312 | if (brn_index != -1) { |
313 | const Widelands::RoadType road = |
314 | - static_cast<Widelands::RoadType>((field.roads >> 2) & Widelands::Road_Mask); |
315 | - if (road != Widelands::Road_None) { |
316 | - add_road(surface, field, fields_to_draw.at(brn_index), road); |
317 | + static_cast<Widelands::RoadType>((field.roads >> 2) & Widelands::RoadType::kMask); |
318 | + if (road != Widelands::RoadType::kNone) { |
319 | + add_road(surface, field, fields_to_draw.at(brn_index), road, kSouthEast, &gl_texture); |
320 | } |
321 | } |
322 | |
323 | @@ -200,9 +196,9 @@ |
324 | fields_to_draw.calculate_index(field.fx + (field.fy & 1) - 1, field.fy + 1); |
325 | if (bln_index != -1) { |
326 | const Widelands::RoadType road = |
327 | - static_cast<Widelands::RoadType>((field.roads >> 4) & Widelands::Road_Mask); |
328 | - if (road != Widelands::Road_None) { |
329 | - add_road(surface, field, fields_to_draw.at(bln_index), road); |
330 | + static_cast<Widelands::RoadType>((field.roads >> 4) & Widelands::RoadType::kMask); |
331 | + if (road != Widelands::RoadType::kNone) { |
332 | + add_road(surface, field, fields_to_draw.at(bln_index), road, kSouthWest, &gl_texture); |
333 | } |
334 | } |
335 | } |
336 | @@ -212,7 +208,6 @@ |
337 | glEnableVertexAttribArray(attr_position_); |
338 | glEnableVertexAttribArray(attr_texture_position_); |
339 | glEnableVertexAttribArray(attr_brightness_); |
340 | - glEnableVertexAttribArray(attr_texture_mix_); |
341 | |
342 | glBindBuffer(GL_ARRAY_BUFFER, gl_array_buffer_.object()); |
343 | glBufferData( |
344 | @@ -229,25 +224,18 @@ |
345 | set_attrib_pointer(attr_position_, 2, offsetof(PerVertexData, gl_x)); |
346 | set_attrib_pointer(attr_texture_position_, 2, offsetof(PerVertexData, texture_x)); |
347 | set_attrib_pointer(attr_brightness_, 1, offsetof(PerVertexData, brightness)); |
348 | - set_attrib_pointer(attr_texture_mix_, 1, offsetof(PerVertexData, texture_mix)); |
349 | |
350 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
351 | |
352 | // Bind the textures. |
353 | glActiveTexture(GL_TEXTURE0); |
354 | - glBindTexture(GL_TEXTURE_2D, normal_road_texture_->get_gl_texture()); |
355 | - glUniform1i(u_normal_road_texture_, 0); |
356 | + glBindTexture(GL_TEXTURE_2D, gl_texture); |
357 | |
358 | - glActiveTexture(GL_TEXTURE1); |
359 | - glBindTexture(GL_TEXTURE_2D, busy_road_texture_->get_gl_texture()); |
360 | - glUniform1i(u_busy_road_texture_, 1); |
361 | + glUniform1i(u_texture_, 0); |
362 | |
363 | glDrawArrays(GL_TRIANGLES, 0, vertices_.size()); |
364 | |
365 | glDisableVertexAttribArray(attr_position_); |
366 | glDisableVertexAttribArray(attr_texture_position_); |
367 | glDisableVertexAttribArray(attr_brightness_); |
368 | - glDisableVertexAttribArray(attr_texture_mix_); |
369 | - |
370 | - glActiveTexture(GL_TEXTURE0); |
371 | } |
372 | |
373 | === modified file 'src/graphic/gl/road_program.h' |
374 | --- src/graphic/gl/road_program.h 2014-11-24 07:10:03 +0000 |
375 | +++ src/graphic/gl/road_program.h 2015-02-09 05:57:46 +0000 |
376 | @@ -48,21 +48,18 @@ |
377 | float texture_x; |
378 | float texture_y; |
379 | float brightness; |
380 | - |
381 | - // This is a hack: we want to draw busy and normal roads in the same |
382 | - // run, but since samplers (apparently?) cannot be passed through |
383 | - // attribute arrays, we instead sample twice (busy and normal) and mix |
384 | - // them together with 'texture_mix' which is either 1 or 0. |
385 | - float texture_mix; |
386 | }; |
387 | - static_assert(sizeof(PerVertexData) == 24, "Wrong padding."); |
388 | + static_assert(sizeof(PerVertexData) == 20, "Wrong padding."); |
389 | |
390 | // Adds a road from 'start' to 'end' to be rendered in this frame using the |
391 | // correct texture for 'road_type'. |
392 | + enum Direction {kEast, kSouthEast, kSouthWest}; |
393 | void add_road(const Surface& surface, |
394 | const FieldsToDraw::Field& start, |
395 | const FieldsToDraw::Field& end, |
396 | - const Widelands::RoadType road_type); |
397 | + const Widelands::RoadType road_type, |
398 | + const Direction direction, |
399 | + int* gl_texture); |
400 | |
401 | // The buffer that will contain 'vertices_' for rendering. |
402 | Gl::Buffer gl_array_buffer_; |
403 | @@ -74,19 +71,13 @@ |
404 | GLint attr_position_; |
405 | GLint attr_texture_position_; |
406 | GLint attr_brightness_; |
407 | - GLint attr_texture_mix_; |
408 | |
409 | // Uniforms. |
410 | - GLint u_normal_road_texture_; |
411 | - GLint u_busy_road_texture_; |
412 | + GLint u_texture_; |
413 | |
414 | // All vertices that get rendered this frame. |
415 | std::vector<PerVertexData> vertices_; |
416 | |
417 | - // The road textures. |
418 | - std::unique_ptr<Texture> normal_road_texture_; |
419 | - std::unique_ptr<Texture> busy_road_texture_; |
420 | - |
421 | DISALLOW_COPY_AND_ASSIGN(RoadProgram); |
422 | }; |
423 | |
424 | |
425 | === modified file 'src/logic/CMakeLists.txt' |
426 | --- src/logic/CMakeLists.txt 2015-01-31 16:03:59 +0000 |
427 | +++ src/logic/CMakeLists.txt 2015-02-09 05:57:46 +0000 |
428 | @@ -167,6 +167,8 @@ |
429 | replay.h |
430 | requirements.cc |
431 | requirements.h |
432 | + road_textures.cc |
433 | + road_textures.h |
434 | roadtype.h |
435 | save_handler.cc |
436 | save_handler.h |
437 | |
438 | === modified file 'src/logic/bob.h' |
439 | --- src/logic/bob.h 2014-09-19 12:54:54 +0000 |
440 | +++ src/logic/bob.h 2015-02-09 05:57:46 +0000 |
441 | @@ -35,7 +35,7 @@ |
442 | class Map; |
443 | struct Route; |
444 | struct Transfer; |
445 | -struct TribeDescr; |
446 | +class TribeDescr; |
447 | |
448 | |
449 | /** |
450 | |
451 | === modified file 'src/logic/buildcost.h' |
452 | --- src/logic/buildcost.h 2014-09-10 10:18:46 +0000 |
453 | +++ src/logic/buildcost.h 2015-02-09 05:57:46 +0000 |
454 | @@ -30,7 +30,7 @@ |
455 | |
456 | namespace Widelands { |
457 | |
458 | -struct TribeDescr; |
459 | +class TribeDescr; |
460 | |
461 | struct Buildcost : std::map<WareIndex, uint8_t> { |
462 | void parse(const TribeDescr & tribe, Section & buildcost_s); |
463 | |
464 | === modified file 'src/logic/building.h' |
465 | --- src/logic/building.h 2014-09-29 12:37:07 +0000 |
466 | +++ src/logic/building.h 2015-02-09 05:57:46 +0000 |
467 | @@ -47,7 +47,7 @@ |
468 | |
469 | struct Flag; |
470 | struct Message; |
471 | -struct TribeDescr; |
472 | +class TribeDescr; |
473 | class WaresQueue; |
474 | |
475 | class Building; |
476 | |
477 | === modified file 'src/logic/editor_game_base.cc' |
478 | --- src/logic/editor_game_base.cc 2015-01-31 16:03:59 +0000 |
479 | +++ src/logic/editor_game_base.cc 2015-02-09 05:57:46 +0000 |
480 | @@ -32,6 +32,9 @@ |
481 | #include "graphic/color.h" |
482 | #include "graphic/font_handler.h" |
483 | #include "graphic/graphic.h" |
484 | +#include "graphic/image_io.h" |
485 | +#include "graphic/texture_atlas.h" |
486 | +#include "io/filesystem/layered_filesystem.h" |
487 | #include "logic/battle.h" |
488 | #include "logic/building.h" |
489 | #include "logic/constants.h" |
490 | @@ -282,7 +285,34 @@ |
491 | tribe_descr->load_graphics(); |
492 | } |
493 | |
494 | - // TODO(unknown): load player graphics? (maybe) |
495 | + // Construct and hold on to the texture atlas that contains all road images. |
496 | + TextureAtlas ta; |
497 | + |
498 | + // These will be deleted at the end of the method. |
499 | + std::vector<std::unique_ptr<Texture>> individual_textures_; |
500 | + for (auto* tribe : tribes_) { |
501 | + for (const std::string& texture_path : tribe->normal_road_paths()) { |
502 | + individual_textures_.emplace_back(load_image(texture_path, g_fs)); |
503 | + ta.add(*individual_textures_.back()); |
504 | + } |
505 | + for (const std::string& texture_path : tribe->busy_road_paths()) { |
506 | + individual_textures_.emplace_back(load_image(texture_path, g_fs)); |
507 | + ta.add(*individual_textures_.back()); |
508 | + } |
509 | + } |
510 | + |
511 | + std::vector<std::unique_ptr<Texture>> textures; |
512 | + road_texture_ = ta.pack(&textures); |
513 | + |
514 | + size_t next_texture_to_move = 0; |
515 | + for (auto* tribe : tribes_) { |
516 | + for (size_t i = 0; i < tribe->normal_road_paths().size(); ++i) { |
517 | + tribe->add_normal_road_texture(std::move(textures.at(next_texture_to_move++))); |
518 | + } |
519 | + for (size_t i = 0; i < tribe->busy_road_paths().size(); ++i) { |
520 | + tribe->add_busy_road_texture(std::move(textures.at(next_texture_to_move++))); |
521 | + } |
522 | + } |
523 | } |
524 | |
525 | /** |
526 | @@ -516,12 +546,12 @@ |
527 | assert(&first_field <= f.field); |
528 | assert (f.field < &first_field + m.max_index()); |
529 | assert |
530 | - (direction == Road_SouthWest || |
531 | - direction == Road_SouthEast || |
532 | - direction == Road_East); |
533 | + (direction == RoadType::kSouthWest || |
534 | + direction == RoadType::kSouthEast || |
535 | + direction == RoadType::kEast); |
536 | assert |
537 | - (roadtype == Road_None || roadtype == Road_Normal || |
538 | - roadtype == Road_Busy || roadtype == Road_Water); |
539 | + (roadtype == RoadType::kNone || roadtype == RoadType::kNormal || |
540 | + roadtype == RoadType::kBusy || roadtype == RoadType::kWater); |
541 | |
542 | if (f.field->get_road(direction) == roadtype) |
543 | return; |
544 | @@ -530,17 +560,17 @@ |
545 | FCoords neighbour; |
546 | uint8_t mask = 0; |
547 | switch (direction) { |
548 | - case Road_SouthWest: |
549 | + case RoadType::kSouthWest: |
550 | neighbour = m.bl_n(f); |
551 | - mask = Road_Mask << Road_SouthWest; |
552 | + mask = RoadType::kMask << RoadType::kSouthWest; |
553 | break; |
554 | - case Road_SouthEast: |
555 | + case RoadType::kSouthEast: |
556 | neighbour = m.br_n(f); |
557 | - mask = Road_Mask << Road_SouthEast; |
558 | + mask = RoadType::kMask << RoadType::kSouthEast; |
559 | break; |
560 | - case Road_East: |
561 | + case RoadType::kEast: |
562 | neighbour = m. r_n(f); |
563 | - mask = Road_Mask << Road_East; |
564 | + mask = RoadType::kMask << RoadType::kEast; |
565 | break; |
566 | default: |
567 | assert(false); |
568 | |
569 | === modified file 'src/logic/editor_game_base.h' |
570 | --- src/logic/editor_game_base.h 2015-01-31 16:03:59 +0000 |
571 | +++ src/logic/editor_game_base.h 2015-02-09 05:57:46 +0000 |
572 | @@ -26,6 +26,7 @@ |
573 | #include <vector> |
574 | |
575 | #include "base/macros.h" |
576 | +#include "graphic/texture.h" |
577 | #include "logic/bob.h" |
578 | #include "logic/building.h" |
579 | #include "logic/map.h" |
580 | @@ -49,7 +50,7 @@ |
581 | struct ObjectManager; |
582 | class Player; |
583 | struct PlayerImmovable; |
584 | -struct TribeDescr; |
585 | +class TribeDescr; |
586 | struct Flag; |
587 | struct AttackController; |
588 | |
589 | @@ -262,9 +263,10 @@ |
590 | uint32_t lasttrackserial_; |
591 | std::map<uint32_t, void*> trackpointers_; |
592 | |
593 | + std::unique_ptr<Texture> road_texture_; |
594 | |
595 | - DISALLOW_COPY_AND_ASSIGN(EditorGameBase); |
596 | - }; |
597 | + DISALLOW_COPY_AND_ASSIGN(EditorGameBase); |
598 | +}; |
599 | |
600 | #define iterate_players_existing(p, nr_players, egbase, player) \ |
601 | iterate_player_numbers( \ |
602 | |
603 | === modified file 'src/logic/field.h' |
604 | --- src/logic/field.h 2014-12-01 21:47:22 +0000 |
605 | +++ src/logic/field.h 2015-02-09 05:57:46 +0000 |
606 | @@ -198,10 +198,10 @@ |
607 | |
608 | int32_t get_roads() const {return roads;} |
609 | int32_t get_road(int32_t const dir) const { |
610 | - return (roads >> dir) & Road_Mask; |
611 | + return (roads >> dir) & RoadType::kMask; |
612 | } |
613 | void set_road(int32_t const dir, int32_t const type) { |
614 | - roads &= ~(Road_Mask << dir); |
615 | + roads &= ~(RoadType::kMask << dir); |
616 | roads |= type << dir; |
617 | } |
618 | |
619 | |
620 | === modified file 'src/logic/immovable.h' |
621 | --- src/logic/immovable.h 2014-09-14 11:31:58 +0000 |
622 | +++ src/logic/immovable.h 2015-02-09 05:57:46 +0000 |
623 | @@ -44,7 +44,7 @@ |
624 | class World; |
625 | struct Flag; |
626 | struct PlayerImmovable; |
627 | -struct TribeDescr; |
628 | +class TribeDescr; |
629 | |
630 | struct NoteImmovable { |
631 | CAN_BE_SEND_AS_NOTE(NoteId::Immovable) |
632 | |
633 | === modified file 'src/logic/player.cc' |
634 | --- src/logic/player.cc 2015-01-31 16:03:59 +0000 |
635 | +++ src/logic/player.cc 2015-02-09 05:57:46 +0000 |
636 | @@ -1054,8 +1054,8 @@ |
637 | Field & tr_field = m_fields[tr.field - &first_map_field]; |
638 | if (tr_field.vision <= 1) { |
639 | tr_field.terrains.d = tr.field->terrain_d(); |
640 | - tr_field.roads &= ~(Road_Mask << Road_SouthWest); |
641 | - tr_field.roads |= Road_Mask << Road_SouthWest & tr.field->get_roads(); |
642 | + tr_field.roads &= ~(RoadType::kMask << RoadType::kSouthWest); |
643 | + tr_field.roads |= RoadType::kMask << RoadType::kSouthWest & tr.field->get_roads(); |
644 | } |
645 | } |
646 | { // discover both triangles and the SE edge of the top left neighbour |
647 | @@ -1063,8 +1063,8 @@ |
648 | Field & tl_field = m_fields[tl.field - &first_map_field]; |
649 | if (tl_field.vision <= 1) { |
650 | tl_field.terrains = tl.field->get_terrains(); |
651 | - tl_field.roads &= ~(Road_Mask << Road_SouthEast); |
652 | - tl_field.roads |= Road_Mask << Road_SouthEast & tl.field->get_roads(); |
653 | + tl_field.roads &= ~(RoadType::kMask << RoadType::kSouthEast); |
654 | + tl_field.roads |= RoadType::kMask << RoadType::kSouthEast & tl.field->get_roads(); |
655 | } |
656 | } |
657 | { // discover the R triangle and the E edge of the left neighbour |
658 | @@ -1072,8 +1072,8 @@ |
659 | Field & l_field = m_fields[l.field - &first_map_field]; |
660 | if (l_field.vision <= 1) { |
661 | l_field.terrains.r = l.field->terrain_r(); |
662 | - l_field.roads &= ~(Road_Mask << Road_East); |
663 | - l_field.roads |= Road_Mask << Road_East & l.field->get_roads(); |
664 | + l_field.roads &= ~(RoadType::kMask << RoadType::kEast); |
665 | + l_field.roads |= RoadType::kMask << RoadType::kEast & l.field->get_roads(); |
666 | } |
667 | } |
668 | } |
669 | |
670 | === modified file 'src/logic/player.h' |
671 | --- src/logic/player.h 2014-12-28 16:45:37 +0000 |
672 | +++ src/logic/player.h 2015-02-09 05:57:46 +0000 |
673 | @@ -42,7 +42,7 @@ |
674 | class Soldier; |
675 | class TrainingSite; |
676 | struct Flag; |
677 | -struct TribeDescr; |
678 | +class TribeDescr; |
679 | struct Road; |
680 | struct AttackController; |
681 | |
682 | @@ -246,14 +246,14 @@ |
683 | /// east, as far as this player knows. |
684 | /// Only valid when this player has seen this node or the node to the |
685 | /// east. |
686 | - uint8_t road_e() const {return roads & Road_Mask;} |
687 | + uint8_t road_e() const {return roads & RoadType::kMask;} |
688 | |
689 | /// Whether there is a road between this node and the node to the |
690 | /// southeast, as far as this player knows. |
691 | /// Only valid when this player has seen this node or the node to the |
692 | /// southeast. |
693 | uint8_t road_se() const { |
694 | - return roads >> Road_SouthEast & Road_Mask; |
695 | + return roads >> RoadType::kSouthEast & RoadType::kMask; |
696 | } |
697 | |
698 | /// Whether there is a road between this node and the node to the |
699 | @@ -261,7 +261,7 @@ |
700 | /// Only valid when this player has seen this node or the node to the |
701 | /// southwest. |
702 | uint8_t road_sw() const { |
703 | - return roads >> Road_SouthWest & Road_Mask; |
704 | + return roads >> RoadType::kSouthWest & RoadType::kMask; |
705 | } |
706 | |
707 | /** |
708 | |
709 | === modified file 'src/logic/production_program.h' |
710 | --- src/logic/production_program.h 2014-11-28 16:40:55 +0000 |
711 | +++ src/logic/production_program.h 2015-02-09 05:57:46 +0000 |
712 | @@ -43,7 +43,7 @@ |
713 | struct ImmovableDescr; |
714 | struct ProductionSiteDescr; |
715 | class ProductionSite; |
716 | -struct TribeDescr; |
717 | +class TribeDescr; |
718 | class Worker; |
719 | class World; |
720 | |
721 | |
722 | === added file 'src/logic/road_textures.cc' |
723 | --- src/logic/road_textures.cc 1970-01-01 00:00:00 +0000 |
724 | +++ src/logic/road_textures.cc 2015-02-09 05:57:46 +0000 |
725 | @@ -0,0 +1,38 @@ |
726 | +/* |
727 | + * Copyright (C) 2006-2015 by the Widelands Development Team |
728 | + * |
729 | + * This program is free software; you can redistribute it and/or |
730 | + * modify it under the terms of the GNU General Public License |
731 | + * as published by the Free Software Foundation; either version 2 |
732 | + * of the License, or (at your option) any later version. |
733 | + * |
734 | + * This program is distributed in the hope that it will be useful, |
735 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
736 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
737 | + * GNU General Public License for more details. |
738 | + * |
739 | + * You should have received a copy of the GNU General Public License |
740 | + * along with this program; if not, write to the Free Software |
741 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
742 | + * |
743 | + */ |
744 | + |
745 | +#include "logic/road_textures.h" |
746 | + |
747 | +#include <memory> |
748 | + |
749 | +const Texture& RoadTextures::get_normal_texture(int x, int y, int direction) const { |
750 | + return *normal_textures_.at((x + y + direction) % normal_textures_.size()); |
751 | +} |
752 | + |
753 | +const Texture& RoadTextures::get_busy_texture(int x, int y, int direction) const { |
754 | + return *busy_textures_.at((x + y + direction) % busy_textures_.size()); |
755 | +} |
756 | + |
757 | +void RoadTextures::add_normal_road_texture(std::unique_ptr<Texture> texture) { |
758 | + normal_textures_.emplace_back(std::move(texture)); |
759 | +} |
760 | + |
761 | +void RoadTextures::add_busy_road_texture(std::unique_ptr<Texture> texture) { |
762 | + busy_textures_.emplace_back(std::move(texture)); |
763 | +} |
764 | |
765 | === added file 'src/logic/road_textures.h' |
766 | --- src/logic/road_textures.h 1970-01-01 00:00:00 +0000 |
767 | +++ src/logic/road_textures.h 2015-02-09 05:57:46 +0000 |
768 | @@ -0,0 +1,45 @@ |
769 | +/* |
770 | + * Copyright (C) 2006-2015 by the Widelands Development Team |
771 | + * |
772 | + * This program is free software; you can redistribute it and/or |
773 | + * modify it under the terms of the GNU General Public License |
774 | + * as published by the Free Software Foundation; either version 2 |
775 | + * of the License, or (at your option) any later version. |
776 | + * |
777 | + * This program is distributed in the hope that it will be useful, |
778 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
779 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
780 | + * GNU General Public License for more details. |
781 | + * |
782 | + * You should have received a copy of the GNU General Public License |
783 | + * along with this program; if not, write to the Free Software |
784 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
785 | + * |
786 | + */ |
787 | + |
788 | +#ifndef WL_LOGIC_ROAD_TEXTURES_H |
789 | +#define WL_LOGIC_ROAD_TEXTURES_H |
790 | + |
791 | +#include <memory> |
792 | +#include <vector> |
793 | + |
794 | +#include "graphic/texture.h" |
795 | + |
796 | +// Simple container to give access of the road textures of a tribe. |
797 | +class RoadTextures { |
798 | +public: |
799 | + // Returns the road texture that should be used for the Cooordinate x, y and |
800 | + // the road going into direction 'direction' (which can be any number). |
801 | + const Texture& get_normal_texture(int x, int y, int direction) const; |
802 | + const Texture& get_busy_texture(int x, int y, int direction) const; |
803 | + |
804 | + // Adds a new road texture. |
805 | + void add_normal_road_texture(std::unique_ptr<Texture> texture); |
806 | + void add_busy_road_texture(std::unique_ptr<Texture> texture); |
807 | + |
808 | +private: |
809 | + std::vector<std::unique_ptr<Texture>> normal_textures_; |
810 | + std::vector<std::unique_ptr<Texture>> busy_textures_; |
811 | +}; |
812 | + |
813 | +#endif // end of include guard: WL_LOGIC_ROAD_TEXTURES_H |
814 | |
815 | === modified file 'src/logic/roadtype.h' |
816 | --- src/logic/roadtype.h 2014-11-01 20:40:39 +0000 |
817 | +++ src/logic/roadtype.h 2015-02-09 05:57:46 +0000 |
818 | @@ -30,15 +30,15 @@ |
819 | // the drawing code to keep around what kind of road it should draw. I guess |
820 | // that is the reason why it was combined in the first place. Still it is ugly. |
821 | enum RoadType { |
822 | - Road_None = 0, |
823 | - Road_Normal = 1, |
824 | - Road_Busy = 2, |
825 | - Road_Water = 3, |
826 | - Road_Mask = 3, |
827 | + kNone = 0, |
828 | + kNormal = 1, |
829 | + kBusy = 2, |
830 | + kWater = 3, |
831 | + kMask = 3, |
832 | |
833 | - Road_East = 0, // shift values |
834 | - Road_SouthEast = 2, |
835 | - Road_SouthWest = 4, |
836 | + kEast = 0, // shift values |
837 | + kSouthEast = 2, |
838 | + kSouthWest = 4, |
839 | }; |
840 | |
841 | } |
842 | |
843 | === modified file 'src/logic/tribe.cc' |
844 | --- src/logic/tribe.cc 2015-01-31 16:03:59 +0000 |
845 | +++ src/logic/tribe.cc 2015-02-09 05:57:46 +0000 |
846 | @@ -28,10 +28,12 @@ |
847 | |
848 | #include "base/i18n.h" |
849 | #include "base/macros.h" |
850 | +#include "base/wexception.h" |
851 | #include "graphic/graphic.h" |
852 | #include "helper.h" |
853 | #include "io/fileread.h" |
854 | #include "io/filesystem/disk_filesystem.h" |
855 | +#include "io/filesystem/filesystem.h" |
856 | #include "io/filesystem/layered_filesystem.h" |
857 | #include "logic/carrier.h" |
858 | #include "logic/constructionsite.h" |
859 | @@ -235,6 +237,33 @@ |
860 | PARSE_ORDER_INFORMATION(worker); |
861 | } |
862 | |
863 | + { |
864 | + Section road_s = root_conf.get_safe_section("roads"); |
865 | + const auto load_roads = [&road_s, this]( |
866 | + const std::string& prefix, std::vector<std::string>* images) { |
867 | + for (int i = 0; i < 99; ++i) { |
868 | + const char* img = |
869 | + road_s.get_string((boost::format("%s_%02i") % prefix % i).str().c_str(), nullptr); |
870 | + if (img == nullptr) { |
871 | + break; |
872 | + } |
873 | + if (!g_fs->file_exists(img)) { |
874 | + throw new GameDataError("File %s for roadtype %s in tribe %s does not exist", |
875 | + img, |
876 | + prefix.c_str(), |
877 | + m_name.c_str()); |
878 | + } |
879 | + images->emplace_back(img); |
880 | + } |
881 | + if (images->empty()) { |
882 | + throw new GameDataError( |
883 | + "No %s roads defined in tribe %s.", prefix.c_str(), m_name.c_str()); |
884 | + } |
885 | + }; |
886 | + load_roads("normal", &m_normal_road_paths); |
887 | + load_roads("busy", &m_busy_road_paths); |
888 | + } |
889 | + |
890 | m_frontier_animation_id = |
891 | g_gr->animations().load(path, root_conf.get_safe_section("frontier")); |
892 | m_flag_animation_id = |
893 | @@ -292,6 +321,27 @@ |
894 | m_buildings.get(i)->load_graphics(); |
895 | } |
896 | |
897 | +const std::vector<std::string>& TribeDescr::normal_road_paths() const { |
898 | + return m_normal_road_paths; |
899 | +} |
900 | + |
901 | +const std::vector<std::string>& TribeDescr::busy_road_paths() const { |
902 | + return m_busy_road_paths; |
903 | +} |
904 | + |
905 | + |
906 | +void TribeDescr::add_normal_road_texture(std::unique_ptr<Texture> texture) { |
907 | + m_road_textures.add_normal_road_texture(std::move(texture)); |
908 | +} |
909 | + |
910 | +void TribeDescr::add_busy_road_texture(std::unique_ptr<Texture> texture) { |
911 | + m_road_textures.add_busy_road_texture(std::move(texture)); |
912 | +} |
913 | + |
914 | +const RoadTextures& TribeDescr::road_textures() const { |
915 | + return m_road_textures; |
916 | +} |
917 | + |
918 | |
919 | /* |
920 | * does this tribe exist? |
921 | |
922 | === modified file 'src/logic/tribe.h' |
923 | --- src/logic/tribe.h 2014-09-14 11:31:58 +0000 |
924 | +++ src/logic/tribe.h 2015-02-09 05:57:46 +0000 |
925 | @@ -21,14 +21,18 @@ |
926 | #define WL_LOGIC_TRIBE_H |
927 | |
928 | #include <map> |
929 | +#include <memory> |
930 | #include <vector> |
931 | |
932 | #include "base/macros.h" |
933 | #include "graphic/animation.h" |
934 | +#include "graphic/texture.h" |
935 | #include "logic/bob.h" |
936 | #include "logic/building.h" |
937 | #include "logic/description_maintainer.h" |
938 | #include "logic/immovable.h" |
939 | +#include "logic/road_textures.h" |
940 | +#include "logic/roadtype.h" |
941 | #include "logic/tribe_basic_info.h" |
942 | #include "logic/ware_descr.h" |
943 | #include "logic/worker.h" |
944 | @@ -52,7 +56,8 @@ |
945 | buildings it can build and the associated graphics. |
946 | Two players can choose the same tribe. |
947 | */ |
948 | -struct TribeDescr { |
949 | +class TribeDescr { |
950 | +public: |
951 | TribeDescr(const std::string & name, EditorGameBase &); |
952 | |
953 | // Static function to check for tribes. |
954 | @@ -62,7 +67,20 @@ |
955 | static std::vector<TribeBasicInfo> get_all_tribe_infos(); |
956 | |
957 | |
958 | - const std::string & name() const {return m_name;} |
959 | + const std::string& name() const {return m_name;} |
960 | + |
961 | + // A vector of all texture images that can be used for drawing a |
962 | + // (normal|busy) road. The images are guaranteed to exist. |
963 | + const std::vector<std::string>& normal_road_paths() const; |
964 | + const std::vector<std::string>& busy_road_paths() const; |
965 | + |
966 | + // Add the corresponding texture (which probably resides in a |
967 | + // texture atlas) for roads. |
968 | + void add_normal_road_texture(std::unique_ptr<Texture> texture); |
969 | + void add_busy_road_texture(std::unique_ptr<Texture> texture); |
970 | + |
971 | + // The road textures used for drawing roads. |
972 | + const RoadTextures& road_textures() const; |
973 | |
974 | WareIndex get_nrworkers() const {return m_workers.get_nitems();} |
975 | WorkerDescr const * get_worker_descr(const WareIndex& index) const { |
976 | @@ -174,6 +192,11 @@ |
977 | |
978 | private: |
979 | const std::string m_name; |
980 | + |
981 | + std::vector<std::string> m_normal_road_paths; |
982 | + std::vector<std::string> m_busy_road_paths; |
983 | + RoadTextures m_road_textures; |
984 | + |
985 | uint32_t m_frontier_animation_id; |
986 | uint32_t m_flag_animation_id; |
987 | uint32_t m_bob_vision_range; |
988 | |
989 | === modified file 'src/logic/ware_descr.h' |
990 | --- src/logic/ware_descr.h 2014-09-10 08:55:04 +0000 |
991 | +++ src/logic/ware_descr.h 2015-02-09 05:57:46 +0000 |
992 | @@ -39,7 +39,7 @@ |
993 | |
994 | namespace Widelands { |
995 | |
996 | -struct TribeDescr; |
997 | +class TribeDescr; |
998 | |
999 | /** |
1000 | * Wares can be stored in warehouses. They can be transferred across an |
1001 | |
1002 | === modified file 'src/logic/warehouse.h' |
1003 | --- src/logic/warehouse.h 2014-09-19 12:54:54 +0000 |
1004 | +++ src/logic/warehouse.h 2015-02-09 05:57:46 +0000 |
1005 | @@ -38,7 +38,7 @@ |
1006 | class Request; |
1007 | struct Requirements; |
1008 | class Soldier; |
1009 | -struct TribeDescr; |
1010 | +class TribeDescr; |
1011 | class WareInstance; |
1012 | struct WareList; |
1013 | |
1014 | |
1015 | === modified file 'src/logic/worker_descr.h' |
1016 | --- src/logic/worker_descr.h 2014-09-19 12:54:54 +0000 |
1017 | +++ src/logic/worker_descr.h 2015-02-09 05:57:46 +0000 |
1018 | @@ -37,7 +37,7 @@ |
1019 | |
1020 | class WorkerDescr : public BobDescr |
1021 | { |
1022 | - friend struct TribeDescr; |
1023 | + friend class TribeDescr; |
1024 | friend class Warehouse; |
1025 | friend struct WorkerProgram; |
1026 | |
1027 | |
1028 | === modified file 'src/map_io/map_players_view_packet.cc' |
1029 | --- src/map_io/map_players_view_packet.cc 2014-10-27 10:14:10 +0000 |
1030 | +++ src/map_io/map_players_view_packet.cc 2015-02-09 05:57:46 +0000 |
1031 | @@ -485,11 +485,11 @@ |
1032 | { // edges |
1033 | uint8_t mask = 0; |
1034 | if (f_vision | bl_vision) |
1035 | - mask = Road_Mask << Road_SouthWest; |
1036 | + mask = RoadType::kMask << RoadType::kSouthWest; |
1037 | if (f_vision | br_vision) |
1038 | - mask |= Road_Mask << Road_SouthEast; |
1039 | + mask |= RoadType::kMask << RoadType::kSouthEast; |
1040 | if (f_vision | r_vision) |
1041 | - mask |= Road_Mask << Road_East; |
1042 | + mask |= RoadType::kMask << RoadType::kEast; |
1043 | f_player_field.roads = f.field->get_roads() & mask; |
1044 | } |
1045 | |
1046 | @@ -816,17 +816,17 @@ |
1047 | { // edges |
1048 | uint8_t mask = 0; |
1049 | if (f_seen | bl_seen) { |
1050 | - mask = Road_Mask << Road_SouthWest; |
1051 | + mask = RoadType::kMask << RoadType::kSouthWest; |
1052 | } else if (f_everseen | bl_everseen) { |
1053 | // The player has seen the SouthWest edge but does not see |
1054 | // it now. Load his information about this edge from file. |
1055 | if (road_file_version < 2) { |
1056 | - try {roads = legacy_road_bitbuffer.get() << Road_SouthWest;} |
1057 | + try {roads = legacy_road_bitbuffer.get() << RoadType::kSouthWest;} |
1058 | catch (const FileRead::FileBoundaryExceeded &) { |
1059 | throw GameDataError |
1060 | ("MapPlayersViewPacket::read: player %u: in " |
1061 | "\"%s\": node (%i, %i): unexpected end of file while " |
1062 | - "reading Road_SouthWest", |
1063 | + "reading RoadType::kSouthWest", |
1064 | plnum, roads_filename, f.x, f.y); |
1065 | } |
1066 | } else { |
1067 | @@ -834,17 +834,17 @@ |
1068 | } |
1069 | } |
1070 | if (f_seen | br_seen) { |
1071 | - mask |= Road_Mask << Road_SouthEast; |
1072 | + mask |= RoadType::kMask << RoadType::kSouthEast; |
1073 | } else if (f_everseen | br_everseen) { |
1074 | // The player has seen the SouthEast edge but does not see |
1075 | // it now. Load his information about this edge from file. |
1076 | if (road_file_version < 2) { |
1077 | - try {roads |= legacy_road_bitbuffer.get() << Road_SouthEast;} |
1078 | + try {roads |= legacy_road_bitbuffer.get() << RoadType::kSouthEast;} |
1079 | catch (const FileRead::FileBoundaryExceeded &) { |
1080 | throw GameDataError |
1081 | ("MapPlayersViewPacket::read: player %u: in " |
1082 | "\"%s\": node (%i, %i): unexpected end of file while " |
1083 | - "reading Road_SouthEast", |
1084 | + "reading RoadType::kSouthEast", |
1085 | plnum, roads_filename, f.x, f.y); |
1086 | } |
1087 | } else { |
1088 | @@ -852,17 +852,17 @@ |
1089 | } |
1090 | } |
1091 | if (f_seen | r_seen) { |
1092 | - mask |= Road_Mask << Road_East; |
1093 | + mask |= RoadType::kMask << RoadType::kEast; |
1094 | } else if (f_everseen | r_everseen) { |
1095 | // The player has seen the East edge but does not see |
1096 | // it now. Load his information about this edge from file. |
1097 | if (road_file_version < 2) { |
1098 | - try {roads |= legacy_road_bitbuffer.get() << Road_East;} |
1099 | + try {roads |= legacy_road_bitbuffer.get() << RoadType::kEast;} |
1100 | catch (const FileRead::FileBoundaryExceeded &) { |
1101 | throw GameDataError |
1102 | ("MapPlayersViewPacket::read: player %u: in " |
1103 | "\"%s\": node (%i, %i): unexpected end of file while " |
1104 | - "reading Road_East", |
1105 | + "reading RoadType::kEast", |
1106 | plnum, roads_filename, f.x, f.y); |
1107 | } |
1108 | } else { |
1109 | |
1110 | === modified file 'src/scripting/lua_game.h' |
1111 | --- src/scripting/lua_game.h 2015-01-31 16:03:59 +0000 |
1112 | +++ src/scripting/lua_game.h 2015-02-09 05:57:46 +0000 |
1113 | @@ -27,7 +27,7 @@ |
1114 | #include "scripting/luna.h" |
1115 | |
1116 | namespace Widelands { |
1117 | - struct TribeDescr; |
1118 | + class TribeDescr; |
1119 | class Objective; |
1120 | struct Message; |
1121 | } |
1122 | |
1123 | === modified file 'src/scripting/lua_map.cc' |
1124 | --- src/scripting/lua_map.cc 2015-01-31 16:03:59 +0000 |
1125 | +++ src/scripting/lua_map.cc 2015-02-09 05:57:46 +0000 |
1126 | @@ -220,7 +220,7 @@ |
1127 | WorkersMap valid_workers; |
1128 | valid_workers.insert(WorkerAmount(r.owner().tribe().worker_index("carrier"), 1)); |
1129 | |
1130 | - if (r.get_roadtype() == Road_Busy) |
1131 | + if (r.get_roadtype() == RoadType::kBusy) |
1132 | valid_workers.insert(WorkerAmount(r.owner().tribe().carrier2(), 1)); |
1133 | |
1134 | return valid_workers; |
1135 | @@ -2531,9 +2531,9 @@ |
1136 | */ |
1137 | int LuaRoad::get_road_type(lua_State * L) { |
1138 | switch (get(L, get_egbase(L))->get_roadtype()) { |
1139 | - case Road_Normal: |
1140 | + case RoadType::kNormal: |
1141 | lua_pushstring(L, "normal"); break; |
1142 | - case Road_Busy: |
1143 | + case RoadType::kBusy: |
1144 | lua_pushstring(L, "busy"); break; |
1145 | default: |
1146 | report_error(L, "Unknown Roadtype! This is a bug in widelands!"); |
1147 | |
1148 | === modified file 'src/wui/encyclopedia_window.h' |
1149 | --- src/wui/encyclopedia_window.h 2014-09-20 09:37:47 +0000 |
1150 | +++ src/wui/encyclopedia_window.h 2015-02-09 05:57:46 +0000 |
1151 | @@ -29,7 +29,7 @@ |
1152 | |
1153 | namespace Widelands { |
1154 | struct WareDescr; |
1155 | -struct TribeDescr; |
1156 | +class TribeDescr; |
1157 | } |
1158 | |
1159 | class InteractivePlayer; |
1160 | |
1161 | === modified file 'src/wui/interactive_base.cc' |
1162 | --- src/wui/interactive_base.cc 2015-01-31 16:03:59 +0000 |
1163 | +++ src/wui/interactive_base.cc 2015-02-09 05:57:46 +0000 |
1164 | @@ -767,7 +767,7 @@ |
1165 | int32_t const shift = 2 * (dir - Widelands::WALK_E); |
1166 | |
1167 | uint8_t set_to = overlay_manager.get_road_overlay(c); |
1168 | - set_to |= Widelands::Road_Normal << shift; |
1169 | + set_to |= Widelands::RoadType::kNormal << shift; |
1170 | overlay_manager.register_road_overlay(c, set_to, m_jobid); |
1171 | } |
1172 | |
1173 | |
1174 | === modified file 'src/wui/waresdisplay.h' |
1175 | --- src/wui/waresdisplay.h 2014-09-14 11:31:58 +0000 |
1176 | +++ src/wui/waresdisplay.h 2015-02-09 05:57:46 +0000 |
1177 | @@ -32,7 +32,7 @@ |
1178 | namespace UI {struct Textarea;} |
1179 | |
1180 | namespace Widelands { |
1181 | -struct TribeDescr; |
1182 | +class TribeDescr; |
1183 | struct WareList; |
1184 | } |
1185 | |
1186 | |
1187 | === modified file 'tribes/atlanteans/conf' |
1188 | --- tribes/atlanteans/conf 2014-08-26 17:25:00 +0000 |
1189 | +++ tribes/atlanteans/conf 2015-02-09 05:57:46 +0000 |
1190 | @@ -8,12 +8,18 @@ |
1191 | uiposition=100 |
1192 | carrier2=horse |
1193 | icon=pics/icon.png |
1194 | + |
1195 | # Wares and workers positions in wares window. Columns are separated by ;, |
1196 | # Entries in the columns separated by , |
1197 | wares_order=stone, log, planks, spideryarn, spidercloth; fish, smoked_fish, meat, smoked_meat, water, corn, cornflour, blackroot, blackrootflour, bread; quartz, diamond, coal, ironore, iron, goldore, gold; pick, saw, shovel, hammer, milking_tongs, fishing_net, bucket, hunting_bow, hook_pole, scythe, bread_paddle, fire_tongs; light_trident, long_trident, steel_trident, double_trident, heavy_double_trident,steel_shield, advanced_shield, tabard, goldyarn, golden_tabard |
1198 | |
1199 | workers_order=carrier, horse, horsebreeder; stonecutter, woodcutter, sawyer, forester, builder, spiderbreeder, weaver, shipwright; fisher, fish_breeder, hunter, smoker, farmer, blackroot_farmer, miller, baker; geologist, miner, charcoal_burner, smelter; toolsmith; soldier, trainer, weaponsmith, armorsmith, scout |
1200 | |
1201 | +# Image file paths for this tribe's road textures |
1202 | +[roads] |
1203 | +busy_00=tribes/atlanteans/pics/roadt_busy.png |
1204 | +normal_00=tribes/atlanteans/pics/roadt_normal.png |
1205 | + |
1206 | # Some blue fires would be fine, but just an idea |
1207 | [frontier] |
1208 | pics=pics/frontier_??.png |
1209 | |
1210 | === added file 'tribes/atlanteans/pics/roadt_busy.png' |
1211 | Binary files tribes/atlanteans/pics/roadt_busy.png 1970-01-01 00:00:00 +0000 and tribes/atlanteans/pics/roadt_busy.png 2015-02-09 05:57:46 +0000 differ |
1212 | === added file 'tribes/atlanteans/pics/roadt_normal.png' |
1213 | Binary files tribes/atlanteans/pics/roadt_normal.png 1970-01-01 00:00:00 +0000 and tribes/atlanteans/pics/roadt_normal.png 2015-02-09 05:57:46 +0000 differ |
1214 | === modified file 'tribes/barbarians/conf' |
1215 | --- tribes/barbarians/conf 2014-08-26 17:25:00 +0000 |
1216 | +++ tribes/barbarians/conf 2015-02-09 05:57:46 +0000 |
1217 | @@ -8,12 +8,17 @@ |
1218 | uiposition=10 |
1219 | carrier2=ox |
1220 | icon=pics/icon.png |
1221 | + |
1222 | # Wares and workers positions in wares window. Columns are separated by ;, |
1223 | # Entries in the columns separated by , |
1224 | wares_order= raw_stone,log, blackwood, grout, thatchreed, cloth; fish, meat, water, wheat, pittabread, beer, strongbeer, ration, snack, meal; coal, ironore, iron, goldore, gold; pick, felling_ax, shovel, hammer, fishing_rod, hunting_spear, scythe, bread_paddle, kitchen_tools, fire_tongs; ax, sharpax, broadax, bronzeax, battleax, warriorsax, helm , mask , warhelm |
1225 | |
1226 | workers_order=carrier, ox, cattlebreeder; stonemason, lumberjack, ranger, builder, lime-burner, gardener, weaver, shipwright; fisher , hunter , gamekeeper, farmer, baker, brewer, master-brewer, innkeeper; geologist,miner, chief-miner, master-miner, charcoal_burner, smelter; blacksmith, master-blacksmith; soldier, trainer, helmsmith, scout |
1227 | |
1228 | +# Image file paths for this tribe's road textures |
1229 | +[roads] |
1230 | +busy_00=tribes/barbarians/pics/roadt_busy.png |
1231 | +normal_00=tribes/barbarians/pics/roadt_normal.png |
1232 | |
1233 | [frontier] |
1234 | pics=pics/frontier_??.png |
1235 | |
1236 | === added file 'tribes/barbarians/pics/roadt_busy.png' |
1237 | Binary files tribes/barbarians/pics/roadt_busy.png 1970-01-01 00:00:00 +0000 and tribes/barbarians/pics/roadt_busy.png 2015-02-09 05:57:46 +0000 differ |
1238 | === added file 'tribes/barbarians/pics/roadt_normal.png' |
1239 | Binary files tribes/barbarians/pics/roadt_normal.png 1970-01-01 00:00:00 +0000 and tribes/barbarians/pics/roadt_normal.png 2015-02-09 05:57:46 +0000 differ |
1240 | === modified file 'tribes/empire/conf' |
1241 | --- tribes/empire/conf 2014-08-26 17:25:00 +0000 |
1242 | +++ tribes/empire/conf 2015-02-09 05:57:46 +0000 |
1243 | @@ -8,12 +8,20 @@ |
1244 | uiposition=20 |
1245 | carrier2=donkey |
1246 | icon=pics/icon.png |
1247 | + |
1248 | # Wares and workers positions in wares window. Columns are separated by ;, |
1249 | # Entries in the columns separated by , |
1250 | wares_order=stone, log, wood, wool,cloth; fish,meat, water, wheat, flour, bread, beer, grape, wine, ration, meal; marble, marblecolumn, coal, ironore, iron, goldore, gold; pick, ax, saw, shovel, hammer, fishing_rod, hunting_spear, scythe, bread_paddle, basket, kitchen_tools, fire_tongs; wood_lance, lance, advanced_lance, heavy_lance, war_lance, helm, armor, chain_armor, plate_armor |
1251 | |
1252 | workers_order=carrier, donkey, donkeybreeder; stonemason, carpenter, lumberjack, forester, builder, shepherd, weaver, shipwright; fisher, hunter, farmer, miller, baker, brewer, pig-breeder, vinefarmer, innkeeper; geologist, miner, master-miner, charcoal_burner, smelter; toolsmith; soldier, trainer, weaponsmith, armorsmith, scout |
1253 | |
1254 | +# Image file paths for this tribe's road textures |
1255 | +[roads] |
1256 | +busy_00=tribes/empire/pics/roadt_busy.png |
1257 | +normal_00=tribes/empire/pics/roadt_normal_00.png |
1258 | +normal_01=tribes/empire/pics/roadt_normal_01.png |
1259 | +normal_02=tribes/empire/pics/roadt_normal_02.png |
1260 | + |
1261 | # No idea for the frontier. Maybe some javelins? |
1262 | [frontier] |
1263 | pics=pics/frontier_??.png |
1264 | |
1265 | === added file 'tribes/empire/pics/roadt_busy.png' |
1266 | Binary files tribes/empire/pics/roadt_busy.png 1970-01-01 00:00:00 +0000 and tribes/empire/pics/roadt_busy.png 2015-02-09 05:57:46 +0000 differ |
1267 | === added file 'tribes/empire/pics/roadt_normal_00.png' |
1268 | Binary files tribes/empire/pics/roadt_normal_00.png 1970-01-01 00:00:00 +0000 and tribes/empire/pics/roadt_normal_00.png 2015-02-09 05:57:46 +0000 differ |
1269 | === added file 'tribes/empire/pics/roadt_normal_01.png' |
1270 | Binary files tribes/empire/pics/roadt_normal_01.png 1970-01-01 00:00:00 +0000 and tribes/empire/pics/roadt_normal_01.png 2015-02-09 05:57:46 +0000 differ |
1271 | === added file 'tribes/empire/pics/roadt_normal_02.png' |
1272 | Binary files tribes/empire/pics/roadt_normal_02.png 1970-01-01 00:00:00 +0000 and tribes/empire/pics/roadt_normal_02.png 2015-02-09 05:57:46 +0000 differ |
1273 | === removed file 'world/pics/roadt_busy.png' |
1274 | Binary files world/pics/roadt_busy.png 2014-04-26 10:53:52 +0000 and world/pics/roadt_busy.png 1970-01-01 00:00:00 +0000 differ |
1275 | === removed file 'world/pics/roadt_normal.png' |
1276 | Binary files world/pics/roadt_normal.png 2015-01-13 20:54:09 +0000 and world/pics/roadt_normal.png 1970-01-01 00:00:00 +0000 differ |
When testing, make sure to use the empire since it is the only tribe that already has more than one road graphic.