Merge lp:~widelands-dev/widelands/bug-986611-cppcheck-uninitialized-variables into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8423
Proposed branch: lp:~widelands-dev/widelands/bug-986611-cppcheck-uninitialized-variables
Merge into: lp:widelands
Diff against target: 1837 lines (+238/-263)
71 files modified
src/ai/defaultai.cc (+2/-2)
src/ai/defaultai_warfare.cc (+4/-4)
src/base/i18n.cc (+1/-1)
src/base/md5.h (+2/-2)
src/chat/CMakeLists.txt (+1/-0)
src/chat/chat.h (+6/-2)
src/economy/shippingitem.h (+1/-1)
src/editor/ui_menus/categorized_item_selection_menu.h (+1/-1)
src/game_io/game_preload_packet.h (+6/-5)
src/graphic/gl/fields_to_draw.h (+2/-0)
src/graphic/graphic.h (+4/-4)
src/graphic/render_queue.h (+8/-10)
src/graphic/text/rt_render.cc (+2/-2)
src/graphic/texture_atlas.h (+1/-1)
src/io/filesystem/filesystem.cc (+0/-2)
src/io/filesystem/filesystem.h (+1/-1)
src/logic/field.h (+17/-17)
src/logic/game.cc (+4/-3)
src/logic/game.h (+2/-1)
src/logic/game_controller.h (+5/-4)
src/logic/game_settings.h (+2/-2)
src/logic/map_objects/map_object.cc (+1/-3)
src/logic/map_objects/tribes/battle.cc (+3/-1)
src/logic/map_objects/tribes/building.cc (+1/-1)
src/logic/map_objects/tribes/building.h (+0/-1)
src/logic/map_objects/tribes/militarysite.cc (+9/-17)
src/logic/map_objects/tribes/militarysite.h (+7/-7)
src/logic/map_objects/tribes/production_program.cc (+1/-1)
src/logic/map_objects/tribes/productionsite.cc (+1/-6)
src/logic/map_objects/tribes/ship.cc (+1/-4)
src/logic/map_objects/tribes/ship.h (+4/-4)
src/logic/map_objects/world/critter_program.h (+2/-2)
src/logic/map_objects/world/map_gen.cc (+19/-19)
src/logic/map_objects/world/map_gen.h (+7/-8)
src/logic/maptriangleregion.h (+8/-8)
src/logic/player.cc (+2/-4)
src/logic/player.h (+1/-1)
src/logic/playercommand.cc (+4/-6)
src/logic/playercommand.h (+6/-5)
src/logic/replay_game_controller.cc (+1/-1)
src/logic/save_handler.cc (+0/-1)
src/logic/single_player_game_controller.cc (+1/-1)
src/map_io/map_buildingdata_packet.cc (+8/-4)
src/map_io/map_elemental_packet.cc (+2/-1)
src/map_io/map_elemental_packet.h (+3/-1)
src/map_io/s2map.cc (+9/-9)
src/map_io/s2map.h (+4/-4)
src/network/gameclient.cc (+7/-10)
src/network/gamehost.cc (+5/-15)
src/network/internet_gaming.cc (+2/-4)
src/network/network.h (+1/-1)
src/scripting/lua_game.cc (+2/-2)
src/scripting/lua_game.h (+1/-2)
src/scripting/lua_map.cc (+1/-1)
src/scripting/lua_ui.cc (+1/-1)
src/sound/sound_handler.cc (+0/-1)
src/ui_basic/checkbox.cc (+1/-2)
src/ui_basic/multilineeditbox.cc (+4/-4)
src/ui_basic/slider.cc (+1/-0)
src/ui_basic/table.h (+9/-9)
src/ui_basic/window.cc (+1/-0)
src/ui_basic/window.h (+1/-1)
src/ui_fsmenu/loadgame.cc (+8/-6)
src/ui_fsmenu/loadgame.h (+1/-1)
src/wui/building_statistics_menu.cc (+1/-1)
src/wui/debugconsole.cc (+2/-4)
src/wui/field_overlay_manager.cc (+1/-1)
src/wui/game_message_menu.cc (+1/-1)
src/wui/mapdata.cc (+0/-2)
src/wui/soldierlist.cc (+9/-8)
src/wui/tribal_encyclopedia.cc (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-986611-cppcheck-uninitialized-variables
Reviewer Review Type Date Requested Status
SirVer Approve
GunChleoc Needs Resubmitting
Review via email: mp+326256@code.launchpad.net

Commit message

Initialize a bunch of uninitialized member variables, adding constructors where necessary. Turned some enums into enum classes. Removed empty string initializations.

Description of the change

I'm on a code cleanup rampage today... this one needs a bit of looking at to make sure that I initialized everything correctly.

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

Continuous integration builds have changed state:

Travis build 2356. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/246523458.
Appveyor build 2184. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_uninitialized_variables-2184.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2391. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/247860909.
Appveyor build 2219. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_uninitialized_variables-2219.

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks for your efforts on cleaning up the code!

Most of this branch looks good to me, although I have a a few comments. The first two points should probably be fixed, the other ones are not so important.

Note that I haven't tried compiling or testing, I only looked at the code.

Revision history for this message
Hans Joachim Desserud (hjd) wrote :

I only checked a couple of the build logs, but the Travis errors seems to be due to packages failing to install. Is there an easy way to retrigger builds?

I haven't looked into the details of the changes, but it is great to see the amount of issues reduced. This seems to be the last branch in review now that should have a large impact on the cppcheck report. I'll keep an eye out for when it is merged, and upload a new report :)

Revision history for this message
SirVer (sirver) :
review: Needs Fixing
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2391. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/247860909.
Appveyor build 2219. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_uninitialized_variables-2219.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Ready for the next round.

review: Needs Resubmitting
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2517. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/262810177.
Appveyor build 2341. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_uninitialized_variables-2341.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2518. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/262995097.
Appveyor build 2342. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_986611_cppcheck_uninitialized_variables-2342.

Revision history for this message
SirVer (sirver) wrote :

3 nits about initializing std::string = "", otherwise lgtm. I think this can go in once you have a look at the nits.

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

Well, it's just the same as initializing numbers to 0 - cppcheck is complaining, so I'm trying to get rid of that noise in the report.

The actual error message is:

src/game_io/game_preload_packet.h:38: (style) The struct 'GamePreloadPacket' does not have a constructor although it has private member variables. Member variables of builtin types are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.

I then proceeded to create a constructor, and you then advised to directly initialize the variables.

The only way to test if this will shut up cppcheck is to run the full report again.

Revision history for this message
SirVer (sirver) wrote :

> Well, it's just the same as initializing numbers to 0 - cppcheck is complaining, so I'm trying to get rid of that noise in the report.

That would be wrong though - plain old datatypes (POD) are not initialized in cpp, so numbers are indeed a random value if not properly initialized. std::string is a class, not a POD though so its constructor is always run. If cppcheck complains about this it would be wrong. I wonder if it is worthwhile to clutter the code with unnecessary (and for std::string even slightly decremental) changes to appease the tool.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I am currently running the report, which will probably take all day. I'll then run it again without the string init to see if it makes a difference.

I'll then revert any changes in this branch that won't fix the report.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have now gone through the code base and removed all empty string initializations. I also found a few more uninitialized variables in MapTriangleRegion.

If you agree with these changes, the branch will be ready.

review: Needs Resubmitting
Revision history for this message
SirVer (sirver) wrote :

lgtm.

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai.cc'
2--- src/ai/defaultai.cc 2017-08-01 12:03:03 +0000
3+++ src/ai/defaultai.cc 2017-08-16 05:11:06 +0000
4@@ -6015,7 +6015,7 @@
5 }
6 }
7
8- std::string summary = "";
9+ std::string summary;
10 for (const auto material : materials) {
11 uint32_t stock = calculate_stocklevel(material);
12 if (stock == 0) {
13@@ -6109,7 +6109,7 @@
14 persistent_data->least_military_score, persistent_data->ai_personality_mil_upper_limit,
15 msites_in_constr(), static_cast<int8_t>(soldier_status_),
16 player_statistics.get_modified_player_power(player_number()));
17- std::string wpolicy = "";
18+ std::string wpolicy;
19 switch (wood_policy_) {
20 case WoodPolicy::kDismantleRangers:
21 wpolicy = "Dismantle rangers";
22
23=== modified file 'src/ai/defaultai_warfare.cc'
24--- src/ai/defaultai_warfare.cc 2017-07-05 00:26:07 +0000
25+++ src/ai/defaultai_warfare.cc 2017-08-16 05:11:06 +0000
26@@ -845,8 +845,8 @@
27 game().send_player_change_soldier_capacity(*ms, -1);
28 changed = true;
29 }
30- if (ms->get_soldier_preference() == MilitarySite::kPrefersRookies) {
31- game().send_player_militarysite_set_soldier_preference(*ms, MilitarySite::kPrefersHeroes);
32+ if (ms->get_soldier_preference() == SoldierPreference::kRookies) {
33+ game().send_player_militarysite_set_soldier_preference(*ms, SoldierPreference::kHeroes);
34 changed = true;
35 }
36 } else if (should_be_dismantled && can_be_dismantled) {
37@@ -864,8 +864,8 @@
38 game().send_player_change_soldier_capacity(*ms, -1);
39 changed = true;
40 }
41- if (ms->get_soldier_preference() == MilitarySite::kPrefersHeroes) {
42- game().send_player_militarysite_set_soldier_preference(*ms, MilitarySite::kPrefersRookies);
43+ if (ms->get_soldier_preference() == SoldierPreference::kHeroes) {
44+ game().send_player_militarysite_set_soldier_preference(*ms, SoldierPreference::kRookies);
45 changed = true;
46 }
47 }
48
49=== modified file 'src/base/i18n.cc'
50--- src/base/i18n.cc 2017-06-24 11:18:12 +0000
51+++ src/base/i18n.cc 2017-08-16 05:11:06 +0000
52@@ -322,7 +322,7 @@
53 }
54
55 std::string localize_list(const std::vector<std::string>& items, ConcatenateWith listtype) {
56- std::string result = "";
57+ std::string result;
58 for (std::vector<std::string>::const_iterator it = items.begin(); it != items.end(); ++it) {
59 if (it == items.begin()) {
60 result = *it;
61
62=== modified file 'src/base/md5.h'
63--- src/base/md5.h 2017-01-25 18:55:59 +0000
64+++ src/base/md5.h 2017-08-16 05:11:06 +0000
65@@ -75,14 +75,14 @@
66 template <typename Base> class MD5Checksum : public Base {
67 public:
68 MD5Checksum() {
69- Reset();
70+ reset();
71 }
72 explicit MD5Checksum(const MD5Checksum& other)
73 : Base(), can_handle_data(other.can_handle_data), sum(other.sum), ctx(other.ctx) {
74 }
75
76 /// Reset the checksumming machinery to its initial state.
77- void Reset() {
78+ void reset() {
79 can_handle_data = 1;
80 ctx.A = 0x67452301;
81 ctx.B = 0xefcdab89;
82
83=== modified file 'src/chat/CMakeLists.txt'
84--- src/chat/CMakeLists.txt 2014-07-13 18:51:52 +0000
85+++ src/chat/CMakeLists.txt 2017-08-16 05:11:06 +0000
86@@ -3,5 +3,6 @@
87 chat.h
88 chat.cc
89 DEPENDS
90+ logic_constants
91 notifications
92 )
93
94=== modified file 'src/chat/chat.h'
95--- src/chat/chat.h 2017-01-25 18:55:59 +0000
96+++ src/chat/chat.h 2017-08-16 05:11:06 +0000
97@@ -24,6 +24,7 @@
98 #include <string>
99 #include <vector>
100
101+#include "logic/widelands.h"
102 #include "notifications/note_ids.h"
103 #include "notifications/notifications.h"
104
105@@ -31,12 +32,15 @@
106 struct ChatMessage {
107 CAN_BE_SENT_AS_NOTE(NoteId::ChatMessage)
108
109+ ChatMessage(const std::string& message) : msg(message) {
110+ }
111+
112 // The (real-)time at which the message was received.
113- time_t time;
114+ time_t time = std::time(nullptr);
115
116 // The playercolor. Used to colorize the senders name; negative numbers
117 // indicate system messages for which richtext is allowed.
118- int16_t playern;
119+ int16_t playern = Widelands::neutral();
120
121 // A string identifying the sender of the message.
122 // This string is empty for system-generated messages.
123
124=== modified file 'src/economy/shippingitem.h'
125--- src/economy/shippingitem.h 2017-06-24 08:47:46 +0000
126+++ src/economy/shippingitem.h 2017-08-16 05:11:06 +0000
127@@ -63,7 +63,7 @@
128 ShippingItem get(MapObjectLoader& mol);
129
130 private:
131- uint32_t serial_;
132+ uint32_t serial_ = 0U;
133 };
134
135 void save(EditorGameBase& egbase, MapObjectSaver& mos, FileWrite& fw);
136
137=== modified file 'src/editor/ui_menus/categorized_item_selection_menu.h'
138--- src/editor/ui_menus/categorized_item_selection_menu.h 2017-06-11 20:09:05 +0000
139+++ src/editor/ui_menus/categorized_item_selection_menu.h 2017-08-16 05:11:06 +0000
140@@ -175,7 +175,7 @@
141 template <typename DescriptionType, typename ToolType>
142 void CategorizedItemSelectionMenu<DescriptionType, ToolType>::update_label() {
143 current_selection_names_.set_size(tab_panel_.get_inner_w(), 20);
144- std::string buf = "";
145+ std::string buf;
146 constexpr int max_string_size = 100;
147 int j = tool_->get_nr_enabled();
148 for (int i = 0; j && buf.size() < max_string_size; ++i) {
149
150=== modified file 'src/game_io/game_preload_packet.h'
151--- src/game_io/game_preload_packet.h 2017-01-25 18:55:59 +0000
152+++ src/game_io/game_preload_packet.h 2017-08-16 05:11:06 +0000
153@@ -78,12 +78,13 @@
154 std::string mapname_;
155 std::string background_;
156 std::string win_condition_;
157- uint32_t gametime_;
158- uint8_t player_nr_; // The local player idx
159- uint8_t number_of_players_;
160+ // Initializing everything to make cppcheck happy.
161+ uint32_t gametime_ = 0U;
162+ uint8_t player_nr_ = 0U; // The local player idx
163+ uint8_t number_of_players_ = 0U;
164 std::string version_;
165- time_t savetimestamp_;
166- GameController::GameType gametype_;
167+ time_t savetimestamp_ = 0;
168+ GameController::GameType gametype_ = GameController::GameType::kUndefined;
169 };
170 }
171
172
173=== modified file 'src/graphic/gl/fields_to_draw.h'
174--- src/graphic/gl/fields_to_draw.h 2017-05-13 18:48:26 +0000
175+++ src/graphic/gl/fields_to_draw.h 2017-08-16 05:11:06 +0000
176@@ -78,6 +78,8 @@
177 };
178
179 FieldsToDraw() {
180+ // Initialize everything to make cppcheck happy.
181+ reset(0, 0, 0, 0);
182 }
183
184 // Resize this fields to draw for reuse.
185
186=== modified file 'src/graphic/graphic.h'
187--- src/graphic/graphic.h 2017-05-10 09:43:20 +0000
188+++ src/graphic/graphic.h 2017-08-16 05:11:06 +0000
189@@ -99,8 +99,8 @@
190 void resolution_changed();
191
192 // The height & width of the window should we be in window mode.
193- int window_mode_width_;
194- int window_mode_height_;
195+ int window_mode_width_ = 0;
196+ int window_mode_height_ = 0;
197
198 /// This is the main screen Surface.
199 /// A RenderTarget for this can be retrieved with get_render_target()
200@@ -109,11 +109,11 @@
201 /// This saves a copy of the screen SDL_Surface. This is needed for
202 /// opengl rendering as the SurfaceOpenGL does not use it. It allows
203 /// manipulation the screen context.
204- SDL_Window* sdl_window_;
205+ SDL_Window* sdl_window_ = nullptr;
206 SDL_GLContext gl_context_;
207
208 /// The maximum width or height a texture can have.
209- int max_texture_size_;
210+ int max_texture_size_ = kMinimumSizeForTextures;
211
212 /// A RenderTarget for screen_. This is initialized during init()
213 std::unique_ptr<RenderTarget> render_target_;
214
215=== modified file 'src/graphic/render_queue.h'
216--- src/graphic/render_queue.h 2017-01-25 18:55:59 +0000
217+++ src/graphic/render_queue.h 2017-08-16 05:11:06 +0000
218@@ -113,16 +113,14 @@
219 };
220
221 struct TerrainArguments {
222- TerrainArguments() {
223- }
224-
225- int gametime;
226- int renderbuffer_width;
227- int renderbuffer_height;
228- const DescriptionMaintainer<Widelands::TerrainDescription>* terrains;
229- FieldsToDraw* fields_to_draw;
230- float scale;
231- Rectf destination_rect;
232+ // Initialize everything to make cppcheck happy.
233+ int gametime = 0;
234+ int renderbuffer_width = 0;
235+ int renderbuffer_height = 0;
236+ const DescriptionMaintainer<Widelands::TerrainDescription>* terrains = nullptr;
237+ FieldsToDraw* fields_to_draw = nullptr;
238+ float scale = 1.f;
239+ Rectf destination_rect = Rectf(0.f, 0.f, 0.f, 0.f);
240 };
241
242 // The union of all possible program arguments represents an Item that is
243
244=== modified file 'src/graphic/text/rt_render.cc'
245--- src/graphic/text/rt_render.cc 2017-06-25 21:55:39 +0000
246+++ src/graphic/text/rt_render.cc 2017-08-16 05:11:06 +0000
247@@ -702,7 +702,6 @@
248 w_(w),
249 h_(h),
250 background_image_(nullptr),
251- filename_(""),
252 is_expanding_(expanding) {
253 check_size();
254 }
255@@ -779,6 +778,8 @@
256 explicit DivTagRenderNode(NodeStyle& ns)
257 : RenderNode(ns),
258 desired_width_(),
259+ w_(0),
260+ h_(0),
261 background_color_(0, 0, 0),
262 is_background_color_set_(false),
263 background_image_(nullptr) {
264@@ -1262,7 +1263,6 @@
265 const UI::FontSets& fontsets)
266 : TagHandler(tag, fc, ns, image_cache, init_renderer_style, fontsets),
267 background_image_(nullptr),
268- image_filename_(""),
269 space_(0) {
270 }
271
272
273=== modified file 'src/graphic/texture_atlas.h'
274--- src/graphic/texture_atlas.h 2017-06-24 08:47:46 +0000
275+++ src/graphic/texture_atlas.h 2017-08-16 05:11:06 +0000
276@@ -81,7 +81,7 @@
277
278 struct Block {
279 Block(int init_index, const Image* init_texture)
280- : index(init_index), texture(init_texture), done(false) {
281+ : index(init_index), texture(init_texture), node(nullptr), done(false) {
282 }
283
284 // The index in the order the blocks have been added.
285
286=== modified file 'src/io/filesystem/filesystem.cc'
287--- src/io/filesystem/filesystem.cc 2017-01-25 18:55:59 +0000
288+++ src/io/filesystem/filesystem.cc 2017-08-16 05:11:06 +0000
289@@ -60,8 +60,6 @@
290 #define PATH_MAX MAX_PATH
291 #endif
292
293-FileSystem::FileSystem() : root_("") {
294-}
295
296 /**
297 * \param path A file or directory name
298
299=== modified file 'src/io/filesystem/filesystem.h'
300--- src/io/filesystem/filesystem.h 2017-07-02 19:21:56 +0000
301+++ src/io/filesystem/filesystem.h 2017-08-16 05:11:06 +0000
302@@ -132,7 +132,7 @@
303
304 protected:
305 /// To get a filesystem, use the Create methods
306- FileSystem();
307+ FileSystem() = default;
308
309 /// How to address the fs' topmost component (e.g. "" on Unix, "D:" on win32)
310 /// \warning This is should \e not contain filesep!
311
312=== modified file 'src/logic/field.h'
313--- src/logic/field.h 2017-01-25 18:55:59 +0000
314+++ src/logic/field.h 2017-08-16 05:11:06 +0000
315@@ -231,24 +231,24 @@
316 Player_Number_Bitmask + Border_Bitmask;
317 static_assert(kMaxPlayers <= Player_Number_Bitmask, "Bitmask is too big.");
318
319- // Data Members
320+ // Data Members. Initialize everything to make cppcheck happy.
321 /** linked list, \sa Bob::linknext_ */
322- Bob* bobs;
323- BaseImmovable* immovable;
324-
325- uint8_t caps : 7;
326- uint8_t roads : 6;
327-
328- Height height;
329- int8_t brightness;
330-
331- OwnerInfoAndSelectionsType owner_info_and_selections;
332-
333- DescriptionIndex resources; ///< Resource type on this field, if any
334- ResourceAmount initial_res_amount; ///< Initial amount of resources
335- ResourceAmount res_amount; ///< Current amount of resources
336-
337- Terrains terrains;
338+ Bob* bobs = nullptr;
339+ BaseImmovable* immovable = nullptr;
340+
341+ uint8_t caps = 0U;
342+ uint8_t roads = 0U;
343+
344+ Height height = 0U;
345+ int8_t brightness = 0;
346+
347+ OwnerInfoAndSelectionsType owner_info_and_selections = Widelands::neutral();
348+
349+ DescriptionIndex resources = INVALID_INDEX; ///< Resource type on this field, if any
350+ ResourceAmount initial_res_amount = 0U; ///< Initial amount of resources
351+ ResourceAmount res_amount = 0U; ///< Current amount of resources
352+
353+ Terrains terrains = Terrains{INVALID_INDEX, INVALID_INDEX};
354 };
355 #pragma pack(pop)
356
357
358=== modified file 'src/logic/game.cc'
359--- src/logic/game.cc 2017-07-02 19:11:13 +0000
360+++ src/logic/game.cc 2017-08-16 05:11:06 +0000
361@@ -125,7 +125,8 @@
362 state_(gs_notrunning),
363 cmdqueue_(*this),
364 /** TRANSLATORS: Win condition for this game has not been set. */
365- win_condition_displayname_(_("Not set")) {
366+ win_condition_displayname_(_("Not set")),
367+ replay_(false) {
368 }
369
370 Game::~Game() {
371@@ -134,7 +135,7 @@
372 void Game::sync_reset() {
373 syncwrapper_.counter_ = 0;
374
375- synchash_.Reset();
376+ synchash_.reset();
377 log("[sync] Reset\n");
378 }
379
380@@ -666,7 +667,7 @@
381 }
382
383 void Game::send_player_militarysite_set_soldier_preference(Building& building,
384- uint8_t my_preference) {
385+ SoldierPreference my_preference) {
386 send_player_command(*new CmdMilitarySiteSetSoldierPreference(
387 get_gametime(), building.owner().player_number(), building, my_preference));
388 }
389
390=== modified file 'src/logic/game.h'
391--- src/logic/game.h 2017-06-23 17:23:04 +0000
392+++ src/logic/game.h 2017-08-16 05:11:06 +0000
393@@ -45,6 +45,7 @@
394 struct PlayerImmovable;
395 enum class IslandExploreDirection;
396 enum class ScoutingDirection;
397+enum class SoldierPreference : uint8_t;
398 struct Ship;
399 struct PlayerEndStatus;
400 class TrainingSite;
401@@ -183,7 +184,7 @@
402 void send_player_build_road(int32_t, Path&);
403 void send_player_flagaction(Flag&);
404 void send_player_start_stop_building(Building&);
405- void send_player_militarysite_set_soldier_preference(Building&, uint8_t preference);
406+ void send_player_militarysite_set_soldier_preference(Building&, SoldierPreference preference);
407 void send_player_start_or_cancel_expedition(Building&);
408
409 void send_player_enhance_building(Building&, DescriptionIndex);
410
411=== modified file 'src/logic/game_controller.h'
412--- src/logic/game_controller.h 2017-06-05 07:33:18 +0000
413+++ src/logic/game_controller.h 2017-08-16 05:11:06 +0000
414@@ -42,10 +42,11 @@
415 class GameController {
416 public:
417 enum class GameType : uint8_t {
418- SINGLEPLAYER = 1, // we don't want SINGLEPLAYER just because a value is empty
419- NETCLIENT,
420- NETHOST,
421- REPLAY
422+ kUndefined = 0,
423+ kSingleplayer,
424+ kNetClient,
425+ kNetHost,
426+ kReplay
427 };
428
429 virtual ~GameController() {
430
431=== modified file 'src/logic/game_settings.h'
432--- src/logic/game_settings.h 2017-06-05 07:33:18 +0000
433+++ src/logic/game_settings.h 2017-08-16 05:11:06 +0000
434@@ -58,12 +58,12 @@
435 }
436
437 UserSettings(Widelands::PlayerEndResult init_result, bool init_ready)
438- : position(0), name(""), result(init_result), win_condition_string(""), ready(init_ready) {
439+ : result(init_result), ready(init_ready) {
440 }
441 UserSettings() : UserSettings(Widelands::PlayerEndResult::kUndefined, false) {
442 }
443
444- uint8_t position;
445+ uint8_t position = 0;
446 std::string name;
447 Widelands::PlayerEndResult result;
448 std::string win_condition_string;
449
450=== modified file 'src/logic/map_objects/map_object.cc'
451--- src/logic/map_objects/map_object.cc 2017-08-09 19:25:04 +0000
452+++ src/logic/map_objects/map_object.cc 2017-08-16 05:11:06 +0000
453@@ -218,9 +218,7 @@
454 const std::string& init_descname)
455 : type_(init_type),
456 name_(init_name),
457- descname_(init_descname),
458- representative_image_filename_(""),
459- icon_filename_("") {
460+ descname_(init_descname) {
461 }
462 MapObjectDescr::MapObjectDescr(const MapObjectType init_type,
463 const std::string& init_name,
464
465=== modified file 'src/logic/map_objects/tribes/battle.cc'
466--- src/logic/map_objects/tribes/battle.cc 2017-06-02 08:14:40 +0000
467+++ src/logic/map_objects/tribes/battle.cc 2017-08-16 05:11:06 +0000
468@@ -57,9 +57,11 @@
469 : MapObject(&g_battle_descr),
470 first_(first_soldier),
471 second_(second_soldier),
472+ creationtime_(0),
473 readyflags_(0),
474 damage_(0),
475- first_strikes_(true) {
476+ first_strikes_(true),
477+ last_attack_hits_(false) {
478 assert(first_soldier->get_owner() != second_soldier->get_owner());
479 {
480 StreamWrite& ss = game.syncstream();
481
482=== modified file 'src/logic/map_objects/tribes/building.cc'
483--- src/logic/map_objects/tribes/building.cc 2017-07-05 19:21:57 +0000
484+++ src/logic/map_objects/tribes/building.cc 2017-08-16 05:11:06 +0000
485@@ -458,7 +458,7 @@
486 }
487
488 std::string Building::info_string(const InfoStringFormat& format) {
489- std::string result = "";
490+ std::string result;
491 switch (format) {
492 case InfoStringFormat::kCensus:
493 if (upcast(ConstructionSite const, constructionsite, this)) {
494
495=== modified file 'src/logic/map_objects/tribes/building.h'
496--- src/logic/map_objects/tribes/building.h 2017-06-26 15:09:21 +0000
497+++ src/logic/map_objects/tribes/building.h 2017-08-16 05:11:06 +0000
498@@ -357,7 +357,6 @@
499 // The player who has defeated this building.
500 PlayerNumber defeating_player_;
501
502- int32_t priority_; // base priority
503 std::map<DescriptionIndex, int32_t> ware_priorities_;
504
505 /// Whether we see our vision_range area based on workers in the building
506
507=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
508--- src/logic/map_objects/tribes/militarysite.cc 2017-06-24 20:22:19 +0000
509+++ src/logic/map_objects/tribes/militarysite.cc 2017-08-16 05:11:06 +0000
510@@ -343,7 +343,7 @@
511 didconquer_(false),
512 capacity_(ms_descr.get_max_number_of_soldiers()),
513 nexthealtime_(0),
514- soldier_preference_(ms_descr.prefers_heroes_at_start_ ? kPrefersHeroes : kPrefersRookies),
515+ soldier_preference_(ms_descr.prefers_heroes_at_start_ ? SoldierPreference::kHeroes : SoldierPreference::kRookies),
516 soldier_upgrade_try_(false),
517 doing_upgrade_request_(false) {
518 next_swap_soldiers_time_ = 0;
519@@ -470,7 +470,7 @@
520
521 Soldier* MilitarySite::find_least_suited_soldier() {
522 const std::vector<Soldier*> present = soldier_control_.present_soldiers();
523- const int32_t multiplier = kPrefersHeroes == soldier_preference_ ? -1 : 1;
524+ const int32_t multiplier = SoldierPreference::kHeroes == soldier_preference_ ? -1 : 1;
525 int worst_soldier_level = INT_MIN;
526 Soldier* worst_soldier = nullptr;
527 for (Soldier* sld : present) {
528@@ -509,9 +509,9 @@
529 if (nullptr != newguy && nullptr != kickoutCandidate) {
530 int32_t old_level = kickoutCandidate->get_level(TrainingAttribute::kTotal);
531 int32_t new_level = newguy->get_level(TrainingAttribute::kTotal);
532- if (kPrefersHeroes == soldier_preference_ && old_level >= new_level) {
533+ if (SoldierPreference::kHeroes == soldier_preference_ && old_level >= new_level) {
534 return false;
535- } else if (kPrefersRookies == soldier_preference_ && old_level <= new_level) {
536+ } else if (SoldierPreference::kRookies == soldier_preference_ && old_level <= new_level) {
537 return false;
538 }
539 }
540@@ -833,7 +833,7 @@
541
542 // feature request 1247384 in launchpad bugs: Conquered buildings tend to
543 // be in a hostile area; typically players want heroes there.
544- set_soldier_preference(kPrefersHeroes);
545+ set_soldier_preference(SoldierPreference::kHeroes);
546 }
547
548 /// Calculates whether the military presence is still kept and \returns true if.
549@@ -935,13 +935,6 @@
550 int32_t soldier_upgrade_required_min = soldier_upgrade_requirements_.get_min();
551 int32_t soldier_upgrade_required_max = soldier_upgrade_requirements_.get_max();
552
553- if (kPrefersHeroes != soldier_preference_ && kPrefersRookies != soldier_preference_) {
554- log(
555- "MilitarySite::swapSoldiers: error: Unknown player preference %d.\n", soldier_preference_);
556- soldier_upgrade_try_ = false;
557- return false;
558- }
559-
560 // Find the level of the soldier that is currently least-suited.
561 Soldier* worst_guy = find_least_suited_soldier();
562 if (worst_guy == nullptr) {
563@@ -953,7 +946,7 @@
564 // Micro-optimization: I assume that the majority of military sites have only level-zero
565 // soldiers and prefer rookies. Handle them separately.
566 soldier_upgrade_try_ = true;
567- if (kPrefersRookies == soldier_preference_) {
568+ if (SoldierPreference::kRookies == soldier_preference_) {
569 if (0 == wg_level) {
570 soldier_upgrade_try_ = false;
571 return false;
572@@ -961,8 +954,8 @@
573 }
574
575 // Now I actually build the new requirements.
576- int32_t reqmin = kPrefersHeroes == soldier_preference_ ? 1 + wg_level : 0;
577- int32_t reqmax = kPrefersHeroes == soldier_preference_ ? SHRT_MAX : wg_level - 1;
578+ int32_t reqmin = SoldierPreference::kHeroes == soldier_preference_ ? 1 + wg_level : 0;
579+ int32_t reqmax = SoldierPreference::kHeroes == soldier_preference_ ? SHRT_MAX : wg_level - 1;
580
581 bool maxchanged = reqmax != soldier_upgrade_required_max;
582 bool minchanged = reqmin != soldier_upgrade_required_min;
583@@ -981,8 +974,7 @@
584
585 // setters
586
587-void MilitarySite::set_soldier_preference(MilitarySite::SoldierPreference p) {
588- assert(kPrefersHeroes == p || kPrefersRookies == p);
589+void MilitarySite::set_soldier_preference(SoldierPreference p) {
590 soldier_preference_ = p;
591 next_swap_soldiers_time_ = 0;
592 }
593
594=== modified file 'src/logic/map_objects/tribes/militarysite.h'
595--- src/logic/map_objects/tribes/militarysite.h 2017-06-25 19:12:30 +0000
596+++ src/logic/map_objects/tribes/militarysite.h 2017-08-16 05:11:06 +0000
597@@ -34,6 +34,13 @@
598 class Soldier;
599 class World;
600
601+// I assume elsewhere, that enum SoldierPreference fits to uint8_t.
602+enum class SoldierPreference : uint8_t {
603+ kNotSet, // For savegame compatibility only.
604+ kRookies,
605+ kHeroes,
606+};
607+
608 class MilitarySiteDescr : public BuildingDescr {
609 public:
610 MilitarySiteDescr(const std::string& init_descname,
611@@ -73,13 +80,6 @@
612 MO_DESCR(MilitarySiteDescr)
613
614 public:
615- // I assume elsewhere, that enum SoldierPreference fits to uint8_t.
616- enum SoldierPreference : uint8_t {
617- kNoPreference,
618- kPrefersRookies,
619- kPrefersHeroes,
620- };
621-
622 explicit MilitarySite(const MilitarySiteDescr&);
623 virtual ~MilitarySite();
624
625
626=== modified file 'src/logic/map_objects/tribes/production_program.cc'
627--- src/logic/map_objects/tribes/production_program.cc 2017-06-24 20:22:19 +0000
628+++ src/logic/map_objects/tribes/production_program.cc 2017-08-16 05:11:06 +0000
629@@ -537,7 +537,7 @@
630 std::string condition_string =
631 i18n::localize_list(condition_list, i18n::ConcatenateWith::AND);
632
633- std::string result_string = "";
634+ std::string result_string;
635 if (result_ == Failed) {
636 /** TRANSLATORS: "Did not start working because the economy needs the ware ‘%s’" */
637 result_string = (boost::format(_("Did not start %1$s because %2$s")) %
638
639=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
640--- src/logic/map_objects/tribes/productionsite.cc 2017-06-23 16:16:28 +0000
641+++ src/logic/map_objects/tribes/productionsite.cc 2017-08-16 05:11:06 +0000
642@@ -65,10 +65,6 @@
643 const LuaTable& table,
644 const EditorGameBase& egbase)
645 : BuildingDescr(init_descname, init_type, table, egbase),
646- out_of_resource_title_(""),
647- out_of_resource_heading_(""),
648- out_of_resource_message_(""),
649- resource_not_needed_message_(""),
650 out_of_resource_productivity_threshold_(100) {
651 i18n::Textdomain td("tribes");
652 std::unique_ptr<LuaTable> items_table;
653@@ -241,8 +237,7 @@
654 last_stat_percent_(0),
655 crude_percent_(0),
656 is_stopped_(false),
657- default_anim_("idle"),
658- production_result_("") {
659+ default_anim_("idle") {
660 calc_statistics();
661 }
662
663
664=== modified file 'src/logic/map_objects/tribes/ship.cc'
665--- src/logic/map_objects/tribes/ship.cc 2017-08-09 19:25:04 +0000
666+++ src/logic/map_objects/tribes/ship.cc 2017-08-16 05:11:06 +0000
667@@ -967,7 +967,7 @@
668 Bob::draw(egbase, draw_text, field_on_dst, scale, dst);
669
670 // Show ship name and current activity
671- std::string statistics_string = "";
672+ std::string statistics_string;
673 if (draw_text & TextToDraw::kStatistics) {
674 switch (ship_state_) {
675 case (ShipStates::kTransport):
676@@ -1083,9 +1083,6 @@
677
678 constexpr uint8_t kCurrentPacketVersion = 6;
679
680-Ship::Loader::Loader() : lastdock_(0), destination_(0) {
681-}
682-
683 const Bob::Task* Ship::Loader::get_task(const std::string& name) {
684 if (name == "shipidle" || name == "ship")
685 return &taskShip;
686
687=== modified file 'src/logic/map_objects/tribes/ship.h'
688--- src/logic/map_objects/tribes/ship.h 2017-06-24 08:47:46 +0000
689+++ src/logic/map_objects/tribes/ship.h 2017-08-16 05:11:06 +0000
690@@ -295,7 +295,6 @@
691 // saving and loading
692 protected:
693 struct Loader : Bob::Loader {
694- Loader();
695
696 const Task* get_task(const std::string& name) override;
697
698@@ -304,9 +303,10 @@
699 void load_finish() override;
700
701 private:
702- uint32_t lastdock_;
703- uint32_t destination_;
704- ShipStates ship_state_;
705+ // Initialize everything to make cppcheck happy.
706+ uint32_t lastdock_ = 0U;
707+ uint32_t destination_ = 0U;
708+ ShipStates ship_state_ = ShipStates::kTransport;
709 std::string shipname_;
710 std::unique_ptr<Expedition> expedition_;
711 std::vector<ShippingItem::Loader> items_;
712
713=== modified file 'src/logic/map_objects/world/critter_program.h'
714--- src/logic/map_objects/world/critter_program.h 2017-06-24 08:47:46 +0000
715+++ src/logic/map_objects/world/critter_program.h 2017-08-16 05:11:06 +0000
716@@ -33,8 +33,8 @@
717 };
718
719 CritterExecuteActionFn function;
720- int32_t iparam1;
721- int32_t iparam2;
722+ int32_t iparam1 = 0;
723+ int32_t iparam2 = 0;
724 std::string sparam1;
725
726 std::vector<std::string> sparamv;
727
728=== modified file 'src/logic/map_objects/world/map_gen.cc'
729--- src/logic/map_objects/world/map_gen.cc 2017-01-25 18:55:59 +0000
730+++ src/logic/map_objects/world/map_gen.cc 2017-08-16 05:11:06 +0000
731@@ -36,8 +36,8 @@
732 }
733
734 const MapGenBobCategory*
735-MapGenLandResource::get_bob_category(MapGenAreaInfo::MapGenTerrainType terrType) const {
736- switch (terrType) {
737+MapGenLandResource::get_bob_category(MapGenAreaInfo::MapGenTerrainType terrain_type) const {
738+ switch (terrain_type) {
739 case MapGenAreaInfo::ttLandCoast:
740 return land_coast_bob_category_;
741 case MapGenAreaInfo::ttLandLand:
742@@ -59,20 +59,20 @@
743 NEVER_HERE();
744 }
745
746-MapGenLandResource::MapGenLandResource(const LuaTable& table, MapGenInfo& mapGenInfo) {
747+MapGenLandResource::MapGenLandResource(const LuaTable& table, MapGenInfo& map_gen_info) {
748 weight_ = get_uint(table, "weight");
749
750 immovable_density_ = static_cast<uint8_t>(get_uint(table, "immovable_density"));
751 critter_density_ = static_cast<uint8_t>(get_uint(table, "critter_density"));
752
753- const auto do_assign = [&table, &mapGenInfo](
754+ const auto do_assign = [&table, &map_gen_info](
755 const std::string& key, const MapGenBobCategory** our_pointer) {
756 const std::string value = table.get_string(key);
757 if (value.empty()) {
758 *our_pointer = nullptr;
759 return;
760 }
761- *our_pointer = mapGenInfo.get_bob_category(value);
762+ *our_pointer = map_gen_info.get_bob_category(value);
763 };
764
765 do_assign("land_coast_bobs", &land_coast_bob_category_);
766@@ -84,7 +84,7 @@
767
768 MapGenAreaInfo::MapGenAreaInfo(const LuaTable& table,
769 const World& world,
770- MapGenAreaType const areaType) {
771+ MapGenAreaType const area_type) {
772 weight_ = get_positive_int(table, "weight");
773
774 const auto read_terrains = [this, &table, &world](
775@@ -97,7 +97,7 @@
776 }
777 };
778
779- switch (areaType) {
780+ switch (area_type) {
781 case atWater:
782 read_terrains("ocean_terrains", &terrains1_);
783 read_terrains("shelf_terrains", &terrains2_);
784@@ -120,8 +120,8 @@
785 }
786 }
787
788-size_t MapGenAreaInfo::get_num_terrains(MapGenTerrainType const terrType) const {
789- switch (terrType) {
790+size_t MapGenAreaInfo::get_num_terrains(MapGenTerrainType const terrain_type) const {
791+ switch (terrain_type) {
792 case ttWaterOcean:
793 return terrains1_.size();
794 case ttWaterShelf:
795@@ -151,9 +151,9 @@
796 NEVER_HERE();
797 }
798
799-DescriptionIndex MapGenAreaInfo::get_terrain(MapGenTerrainType const terrType,
800+DescriptionIndex MapGenAreaInfo::get_terrain(MapGenTerrainType const terrain_type,
801 uint32_t const index) const {
802- switch (terrType) {
803+ switch (terrain_type) {
804 case ttWaterOcean:
805 return terrains1_[index];
806 case ttWaterShelf:
807@@ -217,8 +217,8 @@
808 return sum_bob_area_weights_;
809 }
810
811-size_t MapGenInfo::get_num_areas(MapGenAreaInfo::MapGenAreaType const areaType) const {
812- switch (areaType) {
813+size_t MapGenInfo::get_num_areas(MapGenAreaInfo::MapGenAreaType const area_type) const {
814+ switch (area_type) {
815 case MapGenAreaInfo::atWater:
816 return water_areas_.size();
817 case MapGenAreaInfo::atLand:
818@@ -231,9 +231,9 @@
819 NEVER_HERE();
820 }
821
822-const MapGenAreaInfo& MapGenInfo::get_area(MapGenAreaInfo::MapGenAreaType const areaType,
823+const MapGenAreaInfo& MapGenInfo::get_area(MapGenAreaInfo::MapGenAreaType const area_type,
824 uint32_t const index) const {
825- switch (areaType) {
826+ switch (area_type) {
827 case MapGenAreaInfo::atWater:
828 return water_areas_.at(index);
829 case MapGenAreaInfo::atLand:
830@@ -246,12 +246,12 @@
831 NEVER_HERE();
832 }
833
834-const MapGenBobCategory* MapGenInfo::get_bob_category(const std::string& bobCategory) const {
835- if (bob_categories_.find(bobCategory) == bob_categories_.end())
836- throw wexception("invalid MapGenBobCategory %s", bobCategory.c_str());
837+const MapGenBobCategory* MapGenInfo::get_bob_category(const std::string& bob_category) const {
838+ if (bob_categories_.find(bob_category) == bob_categories_.end())
839+ throw wexception("invalid MapGenBobCategory %s", bob_category.c_str());
840 // Ugly workaround because at is not defined for some systems
841 // and operator[] does not fare well with constants
842- return &bob_categories_.find(bobCategory)->second;
843+ return &bob_categories_.find(bob_category)->second;
844 }
845
846 MapGenInfo::MapGenInfo(const LuaTable& table, const World& world) {
847
848=== modified file 'src/logic/map_objects/world/map_gen.h'
849--- src/logic/map_objects/world/map_gen.h 2017-06-24 08:47:46 +0000
850+++ src/logic/map_objects/world/map_gen.h 2017-08-16 05:11:06 +0000
851@@ -55,10 +55,10 @@
852 ttMountainsSnow
853 };
854
855- MapGenAreaInfo(const LuaTable& table, const World& world, MapGenAreaType areaType);
856+ MapGenAreaInfo(const LuaTable& table, const World& world, MapGenAreaType area_type);
857
858 size_t get_num_terrains(MapGenTerrainType) const;
859- DescriptionIndex get_terrain(MapGenTerrainType terrType, uint32_t index) const;
860+ DescriptionIndex get_terrain(MapGenTerrainType terrain_type, uint32_t index) const;
861 uint32_t get_weight() const {
862 return weight_;
863 }
864@@ -69,7 +69,6 @@
865 std::vector<DescriptionIndex> terrains3_; // shallow, upper, snow
866
867 uint32_t weight_;
868- MapGenAreaType areaType_;
869 };
870
871 struct MapGenBobCategory {
872@@ -95,12 +94,12 @@
873 };
874
875 struct MapGenLandResource {
876- MapGenLandResource(const LuaTable& table, MapGenInfo& mapGenInfo);
877+ MapGenLandResource(const LuaTable& table, MapGenInfo& map_gen_info);
878
879 uint32_t get_weight() const {
880 return weight_;
881 }
882- const MapGenBobCategory* get_bob_category(MapGenAreaInfo::MapGenTerrainType terrType) const;
883+ const MapGenBobCategory* get_bob_category(MapGenAreaInfo::MapGenTerrainType terrain_type) const;
884
885 uint8_t get_immovable_density() const {
886 return immovable_density_;
887@@ -128,9 +127,9 @@
888 struct MapGenInfo {
889 MapGenInfo(const LuaTable& table, const World& world);
890
891- size_t get_num_areas(MapGenAreaInfo::MapGenAreaType areaType) const;
892- const MapGenAreaInfo& get_area(MapGenAreaInfo::MapGenAreaType areaType, uint32_t index) const;
893- const MapGenBobCategory* get_bob_category(const std::string& bobCategory) const;
894+ size_t get_num_areas(MapGenAreaInfo::MapGenAreaType area_type) const;
895+ const MapGenAreaInfo& get_area(MapGenAreaInfo::MapGenAreaType area_type, uint32_t index) const;
896+ const MapGenBobCategory* get_bob_category(const std::string& bob_category) const;
897
898 uint8_t get_water_ocean_height() const {
899 return ocean_height_;
900
901=== modified file 'src/logic/maptriangleregion.h'
902--- src/logic/maptriangleregion.h 2017-01-25 18:55:59 +0000
903+++ src/logic/maptriangleregion.h 2017-08-16 05:11:06 +0000
904@@ -103,9 +103,9 @@
905 private:
906 Area<TCoords<FCoords>> area_;
907 FCoords left_;
908- uint16_t rowwidth_;
909- uint16_t remaining_in_row_;
910- uint16_t remaining_rows_;
911+ uint16_t rowwidth_ = 0;
912+ uint16_t remaining_in_row_ = 0;
913+ uint16_t remaining_rows_ = 0;
914 };
915 template <typename CoordsType> struct MapTriangleRegion<TCoords<CoordsType>> {
916 MapTriangleRegion(const Map&, Area<TCoords<CoordsType>, uint16_t>);
917@@ -117,11 +117,11 @@
918 bool advance(const Map&);
919
920 private:
921- const bool radius_is_odd_;
922- enum { Top, Upper, Lower, Bottom } phase_;
923- uint16_t remaining_rows_in_upper_phase_;
924- uint16_t remaining_rows_in_lower_phase_;
925- uint16_t row_length_, remaining_in_row_;
926+ const bool radius_is_odd_ = false;
927+ enum { Top, Upper, Lower, Bottom } phase_ = Top;
928+ uint16_t remaining_rows_in_upper_phase_ = 0U;
929+ uint16_t remaining_rows_in_lower_phase_ = 0U;
930+ uint16_t row_length_, remaining_in_row_ = 0U;
931 CoordsType left_;
932 TCoords<CoordsType> location_;
933 };
934
935=== modified file 'src/logic/player.cc'
936--- src/logic/player.cc 2017-07-02 21:00:58 +0000
937+++ src/logic/player.cc 2017-08-16 05:11:06 +0000
938@@ -136,7 +136,6 @@
939 fields_(nullptr),
940 allowed_worker_types_(the_egbase.tribes().nrworkers(), true),
941 allowed_building_types_(the_egbase.tribes().nrbuildings(), true),
942- ai_(""),
943 current_produced_statistics_(the_egbase.tribes().nrwares()),
944 current_consumed_statistics_(the_egbase.tribes().nrwares()),
945 ware_productions_(the_egbase.tribes().nrwares()),
946@@ -653,11 +652,10 @@
947 }
948
949 void Player::military_site_set_soldier_preference(PlayerImmovable& imm,
950- uint8_t soldier_preference) {
951+ SoldierPreference soldier_preference) {
952 if (&imm.owner() == this)
953 if (upcast(MilitarySite, milsite, &imm))
954- milsite->set_soldier_preference(
955- static_cast<MilitarySite::SoldierPreference>(soldier_preference));
956+ milsite->set_soldier_preference(soldier_preference);
957 }
958
959 /*
960
961=== modified file 'src/logic/player.h'
962--- src/logic/player.h 2017-07-05 19:21:57 +0000
963+++ src/logic/player.h 2017-08-16 05:11:06 +0000
964@@ -507,7 +507,7 @@
965 void bulldoze(PlayerImmovable&, bool recurse = false);
966 void flagaction(Flag&);
967 void start_stop_building(PlayerImmovable&);
968- void military_site_set_soldier_preference(PlayerImmovable&, uint8_t soldier_preference);
969+ void military_site_set_soldier_preference(PlayerImmovable&, SoldierPreference soldier_preference);
970 void start_or_cancel_expedition(Warehouse&);
971 void enhance_building(Building*, DescriptionIndex index_of_new_building);
972 void dismantle_building(Building*);
973
974=== modified file 'src/logic/playercommand.cc'
975--- src/logic/playercommand.cc 2017-06-24 08:18:11 +0000
976+++ src/logic/playercommand.cc 2017-08-16 05:11:06 +0000
977@@ -29,8 +29,6 @@
978 #include "io/streamwrite.h"
979 #include "logic/game.h"
980 #include "logic/map_objects/map_object.h"
981-#include "logic/map_objects/tribes/militarysite.h"
982-#include "logic/map_objects/tribes/ship.h"
983 #include "logic/map_objects/tribes/soldier.h"
984 #include "logic/map_objects/tribes/tribe_descr.h"
985 #include "logic/player.h"
986@@ -506,14 +504,14 @@
987 CmdMilitarySiteSetSoldierPreference::CmdMilitarySiteSetSoldierPreference(StreamRead& des)
988 : PlayerCommand(0, des.unsigned_8()) {
989 serial = des.unsigned_32();
990- preference = des.unsigned_8();
991+ preference = static_cast<Widelands::SoldierPreference>(des.unsigned_8());
992 }
993
994 void CmdMilitarySiteSetSoldierPreference::serialize(StreamWrite& ser) {
995 ser.unsigned_8(PLCMD_MILITARYSITESETSOLDIERPREFERENCE);
996 ser.unsigned_8(sender());
997 ser.unsigned_32(serial);
998- ser.unsigned_8(preference);
999+ ser.unsigned_8(static_cast<uint8_t>(preference));
1000 }
1001
1002 void CmdMilitarySiteSetSoldierPreference::execute(Game& game) {
1003@@ -531,7 +529,7 @@
1004 // Write base classes
1005 PlayerCommand::write(fw, egbase, mos);
1006
1007- fw.unsigned_8(preference);
1008+ fw.unsigned_8(static_cast<uint8_t>(preference));
1009
1010 // Now serial.
1011 fw.unsigned_32(mos.get_object_file_index_or_zero(egbase.objects().get_object(serial)));
1012@@ -544,7 +542,7 @@
1013 const uint16_t packet_version = fr.unsigned_16();
1014 if (packet_version == kCurrentPacketVersionSoldierPreference) {
1015 PlayerCommand::read(fr, egbase, mol);
1016- preference = fr.unsigned_8();
1017+ preference = static_cast<Widelands::SoldierPreference>(fr.unsigned_8());
1018 serial = get_object_serial_or_zero<MilitarySite>(fr.unsigned_32(), mol);
1019 } else {
1020 throw UnhandledVersionError("CmdMilitarySiteSetSoldierPreference", packet_version,
1021
1022=== modified file 'src/logic/playercommand.h'
1023--- src/logic/playercommand.h 2017-07-02 19:11:13 +0000
1024+++ src/logic/playercommand.h 2017-08-16 05:11:06 +0000
1025@@ -24,6 +24,7 @@
1026
1027 #include "economy/flag.h"
1028 #include "logic/cmd_queue.h"
1029+#include "logic/map_objects/tribes/militarysite.h"
1030 #include "logic/map_objects/tribes/ship.h"
1031 #include "logic/map_objects/tribes/trainingsite.h"
1032 #include "logic/map_objects/tribes/warehouse.h"
1033@@ -218,12 +219,12 @@
1034 };
1035
1036 struct CmdMilitarySiteSetSoldierPreference : public PlayerCommand {
1037- CmdMilitarySiteSetSoldierPreference() : PlayerCommand(), serial(0) {
1038+ CmdMilitarySiteSetSoldierPreference() : PlayerCommand(), serial(0), preference(SoldierPreference::kRookies) {
1039 } // For savegame loading
1040 CmdMilitarySiteSetSoldierPreference(const uint32_t t,
1041 const PlayerNumber p,
1042 Building& b,
1043- uint8_t prefs)
1044+ SoldierPreference prefs)
1045 : PlayerCommand(t, p), serial(b.serial()), preference(prefs) {
1046 }
1047
1048@@ -241,7 +242,7 @@
1049
1050 private:
1051 Serial serial;
1052- uint8_t preference;
1053+ Widelands::SoldierPreference preference;
1054 };
1055 struct CmdStartOrCancelExpedition : public PlayerCommand {
1056 CmdStartOrCancelExpedition() : PlayerCommand() {
1057@@ -343,7 +344,7 @@
1058 };
1059
1060 struct CmdShipScoutDirection : public PlayerCommand {
1061- CmdShipScoutDirection() : PlayerCommand(), serial(0) {
1062+ CmdShipScoutDirection() : PlayerCommand(), serial(0), dir(WalkingDir::IDLE) {
1063 } // For savegame loading
1064 CmdShipScoutDirection(uint32_t const t, PlayerNumber const p, Serial s, WalkingDir direction)
1065 : PlayerCommand(t, p), serial(s), dir(direction) {
1066@@ -391,7 +392,7 @@
1067 };
1068
1069 struct CmdShipExploreIsland : public PlayerCommand {
1070- CmdShipExploreIsland() : PlayerCommand(), serial(0) {
1071+ CmdShipExploreIsland() : PlayerCommand(), serial(0), island_explore_direction(IslandExploreDirection::kNotSet) {
1072 } // For savegame loading
1073 CmdShipExploreIsland(uint32_t const t,
1074 PlayerNumber const p,
1075
1076=== modified file 'src/logic/replay_game_controller.cc'
1077--- src/logic/replay_game_controller.cc 2017-05-14 18:17:16 +0000
1078+++ src/logic/replay_game_controller.cc 2017-08-16 05:11:06 +0000
1079@@ -72,7 +72,7 @@
1080 }
1081
1082 GameController::GameType ReplayGameController::get_game_type() {
1083- return GameController::GameType::REPLAY;
1084+ return GameController::GameType::kReplay;
1085 }
1086
1087 uint32_t ReplayGameController::real_speed() {
1088
1089=== modified file 'src/logic/save_handler.cc'
1090--- src/logic/save_handler.cc 2017-08-09 19:25:04 +0000
1091+++ src/logic/save_handler.cc 2017-08-16 05:11:06 +0000
1092@@ -46,7 +46,6 @@
1093 allow_saving_(true),
1094 save_requested_(false),
1095 saving_next_tick_(false),
1096- save_filename_(""),
1097 autosave_filename_("wl_autosave"),
1098 fs_type_(FileSystem::ZIP),
1099 autosave_interval_in_ms_(kDefaultAutosaveInterval * 60 * 1000),
1100
1101=== modified file 'src/logic/single_player_game_controller.cc'
1102--- src/logic/single_player_game_controller.cc 2017-03-03 11:19:16 +0000
1103+++ src/logic/single_player_game_controller.cc 2017-08-16 05:11:06 +0000
1104@@ -84,7 +84,7 @@
1105 }
1106
1107 GameController::GameType SinglePlayerGameController::get_game_type() {
1108- return GameController::GameType::SINGLEPLAYER;
1109+ return GameController::GameType::kSingleplayer;
1110 }
1111
1112 uint32_t SinglePlayerGameController::real_speed() {
1113
1114=== modified file 'src/map_io/map_buildingdata_packet.cc'
1115--- src/map_io/map_buildingdata_packet.cc 2017-06-25 13:18:49 +0000
1116+++ src/map_io/map_buildingdata_packet.cc 2017-08-16 05:11:06 +0000
1117@@ -63,7 +63,7 @@
1118 constexpr uint16_t kCurrentPacketPFBuilding = 1;
1119 // Responsible for warehouses and expedition bootstraps
1120 constexpr uint16_t kCurrentPacketVersionWarehouse = 7;
1121-constexpr uint16_t kCurrentPacketVersionMilitarysite = 5;
1122+constexpr uint16_t kCurrentPacketVersionMilitarysite = 6;
1123 constexpr uint16_t kCurrentPacketVersionProductionsite = 6;
1124 constexpr uint16_t kCurrentPacketVersionTrainingsite = 5;
1125
1126@@ -464,7 +464,7 @@
1127 MapObjectLoader& mol) {
1128 try {
1129 uint16_t const packet_version = fr.unsigned_16();
1130- if (packet_version == kCurrentPacketVersionMilitarysite) {
1131+ if (packet_version >= 5 && packet_version <= kCurrentPacketVersionMilitarysite) {
1132 militarysite.normal_soldier_request_.reset();
1133
1134 if (fr.unsigned_8()) {
1135@@ -506,7 +506,11 @@
1136 militarysite.soldier_upgrade_requirements_ =
1137 RequireAttribute(TrainingAttribute::kTotal, reqmin, reqmax);
1138 militarysite.soldier_preference_ =
1139- static_cast<MilitarySite::SoldierPreference>(fr.unsigned_8());
1140+ static_cast<SoldierPreference>(fr.unsigned_8());
1141+ // TODO(GunChleoc): Savegame compatibility, remove kNotSet after Build 20.
1142+ if (militarysite.soldier_preference_ == SoldierPreference::kNotSet) {
1143+ militarysite.soldier_preference_ = SoldierPreference::kRookies;
1144+ }
1145 militarysite.next_swap_soldiers_time_ = fr.signed_32();
1146 militarysite.soldier_upgrade_try_ = 0 != fr.unsigned_8() ? true : false;
1147 militarysite.doing_upgrade_request_ = 0 != fr.unsigned_8() ? true : false;
1148@@ -1083,7 +1087,7 @@
1149 }
1150 fw.unsigned_16(militarysite.soldier_upgrade_requirements_.get_min());
1151 fw.unsigned_16(militarysite.soldier_upgrade_requirements_.get_max());
1152- fw.unsigned_8(militarysite.soldier_preference_);
1153+ fw.unsigned_8(static_cast<uint8_t>(militarysite.soldier_preference_));
1154 fw.signed_32(militarysite.next_swap_soldiers_time_);
1155 fw.unsigned_8(militarysite.soldier_upgrade_try_ ? 1 : 0);
1156 fw.unsigned_8(militarysite.doing_upgrade_request_ ? 1 : 0);
1157
1158=== modified file 'src/map_io/map_elemental_packet.cc'
1159--- src/map_io/map_elemental_packet.cc 2017-01-25 18:55:59 +0000
1160+++ src/map_io/map_elemental_packet.cc 2017-08-16 05:11:06 +0000
1161@@ -33,6 +33,7 @@
1162 constexpr int32_t kEightPlayersPacketVersion = 1;
1163 constexpr int32_t kSixteenPlayersPacketVersion = 2;
1164
1165+
1166 void MapElementalPacket::pre_read(FileSystem& fs, Map* map) {
1167 Profile prof;
1168 prof.read("elemental", nullptr, fs);
1169@@ -147,7 +148,7 @@
1170 prof.create_section((boost::format("teams%02d") % counter++).str().c_str());
1171 int lineup_counter = 0;
1172 for (Widelands::Map::SuggestedTeam team : lineup) {
1173- std::string section_contents = "";
1174+ std::string section_contents;
1175 for (std::vector<PlayerNumber>::const_iterator it = team.begin(); it != team.end(); ++it) {
1176 if (it == team.begin()) {
1177 section_contents = (boost::format("%d") % static_cast<unsigned int>(*it)).str();
1178
1179=== modified file 'src/map_io/map_elemental_packet.h'
1180--- src/map_io/map_elemental_packet.h 2017-01-25 18:55:59 +0000
1181+++ src/map_io/map_elemental_packet.h 2017-08-16 05:11:06 +0000
1182@@ -35,6 +35,8 @@
1183 * like number of players, map size, world name, magic bytes and so on
1184 */
1185 struct MapElementalPacket {
1186+ MapElementalPacket() = default;
1187+
1188 void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&);
1189 void write(FileSystem&, EditorGameBase&, MapObjectSaver&);
1190
1191@@ -54,7 +56,7 @@
1192
1193 private:
1194 std::string old_world_name_;
1195- uint32_t version_;
1196+ uint32_t version_ = 0;
1197 };
1198 }
1199
1200
1201=== modified file 'src/map_io/s2map.cc'
1202--- src/map_io/s2map.cc 2017-08-12 16:57:43 +0000
1203+++ src/map_io/s2map.cc 2017-08-16 05:11:06 +0000
1204@@ -212,11 +212,11 @@
1205
1206 std::string get_world_name(S2MapLoader::WorldType world) {
1207 switch (world) {
1208- case S2MapLoader::GREENLAND:
1209+ case S2MapLoader::WorldType::kGreenland:
1210 return "greenland";
1211- case S2MapLoader::BLACKLAND:
1212+ case S2MapLoader::WorldType::kBlackland:
1213 return "blackland";
1214- case S2MapLoader::WINTERLAND:
1215+ case S2MapLoader::WorldType::kWinterland:
1216 return "winterland";
1217 }
1218 NEVER_HERE();
1219@@ -244,18 +244,18 @@
1220 : world_legacy_lookup_table_(lookup_table),
1221 world_(world),
1222 table_{std::make_pair(
1223- S2MapLoader::GREENLAND,
1224+ S2MapLoader::WorldType::kGreenland,
1225 std::vector<std::string>{
1226 "summer_steppe", "summer_mountain1", "summer_snow", "summer_swamp",
1227 "summer_beach", "summer_water", "summer_meadow1", "summer_meadow2",
1228 "summer_meadow3", "summer_mountain2", "summer_mountain3", "summer_mountain4",
1229 "summer_steppe_barren", "summer_meadow4", "lava", "summer_mountain_meadow"}),
1230- std::make_pair(S2MapLoader::BLACKLAND,
1231+ std::make_pair(S2MapLoader::WorldType::kBlackland,
1232 std::vector<std::string>{
1233 "ashes", "mountain1", "lava-stone1", "lava-stone2", "strand", "water",
1234 "hardground1", "hardground2", "hardground3", "mountain2", "mountain3",
1235 "mountain4", "ashes2", "hardground4", "lava", "hardlava"}),
1236- std::make_pair(S2MapLoader::WINTERLAND,
1237+ std::make_pair(S2MapLoader::WorldType::kWinterland,
1238 std::vector<std::string>{
1239 "tundra", "mountain1", "ice_flows", "ice_flows2", "ice", "water",
1240 "tundra_taiga", "tundra2", "tundra3", "mountain2", "mountain3",
1241@@ -338,7 +338,7 @@
1242 } // namespace
1243
1244 S2MapLoader::S2MapLoader(const std::string& filename, Widelands::Map& M)
1245- : Widelands::MapLoader(filename, M), filename_(filename) {
1246+ : Widelands::MapLoader(filename, M), filename_(filename), worldtype_(WorldType::kGreenland) {
1247 }
1248
1249 /// Load the header. The map will then return valid information when
1250@@ -953,10 +953,10 @@
1251 break;
1252
1253 case BOB_CACTUS1:
1254- bobname = worldtype_ != S2MapLoader::WINTERLAND ? "cactus1" : "snowman";
1255+ bobname = worldtype_ != S2MapLoader::WorldType::kWinterland ? "cactus1" : "snowman";
1256 break;
1257 case BOB_CACTUS2:
1258- bobname = worldtype_ != S2MapLoader::WINTERLAND ? "cactus2" : "track";
1259+ bobname = worldtype_ != S2MapLoader::WorldType::kWinterland ? "cactus2" : "track";
1260 break;
1261
1262 case BOB_BUSH1:
1263
1264=== modified file 'src/map_io/s2map.h'
1265--- src/map_io/s2map.h 2017-01-25 18:55:59 +0000
1266+++ src/map_io/s2map.h 2017-08-16 05:11:06 +0000
1267@@ -28,10 +28,10 @@
1268 class FileRead;
1269
1270 struct S2MapLoader : public Widelands::MapLoader {
1271- enum WorldType {
1272- GREENLAND = 0,
1273- BLACKLAND = 1,
1274- WINTERLAND = 2,
1275+ enum class WorldType {
1276+ kGreenland = 0,
1277+ kBlackland = 1,
1278+ kWinterland = 2,
1279 };
1280
1281 S2MapLoader(const std::string& filename, Widelands::Map& M);
1282
1283=== modified file 'src/network/gameclient.cc'
1284--- src/network/gameclient.cc 2017-07-05 19:21:57 +0000
1285+++ src/network/gameclient.cc 2017-08-16 05:11:06 +0000
1286@@ -263,7 +263,7 @@
1287 }
1288
1289 GameController::GameType GameClient::get_game_type() {
1290- return GameController::GameType::NETCLIENT;
1291+ return GameController::GameType::kNetClient;
1292 }
1293
1294 void GameClient::report_result(uint8_t player_nr,
1295@@ -820,8 +820,7 @@
1296 }
1297
1298 case NETCMD_CHAT: {
1299- ChatMessage c;
1300- c.time = time(nullptr);
1301+ ChatMessage c("");
1302 c.playern = packet.signed_16();
1303 c.sender = packet.string();
1304 c.msg = packet.string();
1305@@ -833,13 +832,11 @@
1306 }
1307
1308 case NETCMD_SYSTEM_MESSAGE_CODE: {
1309- ChatMessage c;
1310- c.time = time(nullptr);
1311- std::string code = packet.string();
1312- std::string arg1 = packet.string();
1313- std::string arg2 = packet.string();
1314- std::string arg3 = packet.string();
1315- c.msg = NetworkGamingMessages::get_message(code, arg1, arg2, arg3);
1316+ const std::string code = packet.string();
1317+ const std::string arg1 = packet.string();
1318+ const std::string arg2 = packet.string();
1319+ const std::string arg3 = packet.string();
1320+ ChatMessage c(NetworkGamingMessages::get_message(code, arg1, arg2, arg3));
1321 c.playern = UserSettings::none(); // == System message
1322 // c.sender remains empty to indicate a system message
1323 d->chatmessages.push_back(c);
1324
1325=== modified file 'src/network/gamehost.cc'
1326--- src/network/gamehost.cc 2017-07-02 21:09:23 +0000
1327+++ src/network/gamehost.cc 2017-08-16 05:11:06 +0000
1328@@ -282,11 +282,9 @@
1329 }
1330
1331 void send(const std::string& msg) override {
1332- ChatMessage c;
1333- c.time = time(nullptr);
1334+ ChatMessage c(msg);
1335 c.playern = h->get_local_playerposition();
1336 c.sender = h->get_local_playername();
1337- c.msg = msg;
1338 if (c.msg.size() && *c.msg.begin() == '@') {
1339 // Personal message
1340 std::string::size_type const space = c.msg.find(' ');
1341@@ -855,12 +853,8 @@
1342
1343 // is host the sender?
1344 if (d->localplayername == msg.sender) {
1345- ChatMessage err;
1346- err.time = time(nullptr);
1347+ ChatMessage err(fail);
1348 err.playern = -2; // System message
1349- err.sender = "";
1350- err.msg = fail;
1351- err.recipient = "";
1352 d->chat.receive(err);
1353 return; // nothing left to do!
1354 }
1355@@ -986,9 +980,7 @@
1356 broadcast(s);
1357
1358 // Now add to our own chatbox
1359- ChatMessage msg;
1360- msg.time = time(nullptr);
1361- msg.msg = NetworkGamingMessages::get_message(code, a, b, c);
1362+ ChatMessage msg(NetworkGamingMessages::get_message(code, a, b, c));
1363 msg.playern = UserSettings::none(); // == System message
1364 // c.sender remains empty to indicate a system message
1365 d->chat.receive(msg);
1366@@ -999,7 +991,7 @@
1367 }
1368
1369 GameController::GameType GameHost::get_game_type() {
1370- return GameController::GameType::NETHOST;
1371+ return GameController::GameType::kNetHost;
1372 }
1373
1374 const GameSettings& GameHost::settings() {
1375@@ -2164,11 +2156,9 @@
1376 }
1377
1378 case NETCMD_CHAT: {
1379- ChatMessage c;
1380- c.time = time(nullptr);
1381+ ChatMessage c(r.string());
1382 c.playern = d->settings.users.at(client.usernum).position;
1383 c.sender = d->settings.users.at(client.usernum).name;
1384- c.msg = r.string();
1385 if (c.msg.size() && *c.msg.begin() == '@') {
1386 // Personal message
1387 std::string::size_type const space = c.msg.find(' ');
1388
1389=== modified file 'src/network/internet_gaming.cc'
1390--- src/network/internet_gaming.cc 2017-07-23 08:46:00 +0000
1391+++ src/network/internet_gaming.cc 2017-08-16 05:11:06 +0000
1392@@ -629,7 +629,7 @@
1393 // Client received an ERROR message - seems something went wrong
1394 std::string subcmd(packet.string());
1395 std::string reason(packet.string());
1396- std::string message = "";
1397+ std::string message;
1398
1399 if (subcmd == IGPCMD_CHAT) {
1400 // Something went wrong with the chat message the user sent.
1401@@ -873,16 +873,14 @@
1402 const std::string& to,
1403 bool system,
1404 const std::string& msg) {
1405- ChatMessage c;
1406+ ChatMessage c(msg);
1407 if (!system && from.empty()) {
1408 std::string unkown_string = (boost::format("<%s>") % _("unknown")).str();
1409 c.sender = unkown_string;
1410 } else {
1411 c.sender = from;
1412 }
1413- c.time = time(nullptr);
1414 c.playern = system ? -1 : to.size() ? 3 : 7;
1415- c.msg = msg;
1416 c.recipient = to;
1417
1418 receive(c);
1419
1420=== modified file 'src/network/network.h'
1421--- src/network/network.h 2017-07-02 21:09:23 +0000
1422+++ src/network/network.h 2017-08-16 05:11:06 +0000
1423@@ -172,7 +172,7 @@
1424 private:
1425 friend class Deserializer;
1426 std::vector<uint8_t> buffer;
1427- size_t index_;
1428+ size_t index_ = 0U;
1429 };
1430
1431 struct FilePart {
1432
1433=== modified file 'src/scripting/lua_game.cc'
1434--- src/scripting/lua_game.cc 2017-07-02 18:58:30 +0000
1435+++ src/scripting/lua_game.cc 2017-08-16 05:11:06 +0000
1436@@ -422,7 +422,7 @@
1437 int LuaPlayer::message_box(lua_State* L) {
1438 Game& game = get_game(L);
1439 // don't show message boxes in replays, cause they crash the game
1440- if (game.game_controller()->get_game_type() == GameController::GameType::REPLAY) {
1441+ if (game.game_controller()->get_game_type() == GameController::GameType::kReplay) {
1442 return 1;
1443 }
1444
1445@@ -1322,7 +1322,7 @@
1446 */
1447 // TODO(sirver): this should be a method of wl.Game(). Fix for b19.
1448 static int L_report_result(lua_State* L) {
1449- std::string info = "";
1450+ std::string info;
1451 if (lua_gettop(L) >= 3)
1452 info = luaL_checkstring(L, 3);
1453
1454
1455=== modified file 'src/scripting/lua_game.h'
1456--- src/scripting/lua_game.h 2017-06-24 08:47:46 +0000
1457+++ src/scripting/lua_game.h 2017-08-16 05:11:06 +0000
1458@@ -118,8 +118,7 @@
1459 }
1460
1461 explicit LuaObjective(const Widelands::Objective& n);
1462- LuaObjective() : name_("") {
1463- }
1464+ LuaObjective() = default;
1465 explicit LuaObjective(lua_State* L) {
1466 report_error(L, "Cannot instantiate a '%s' directly!", className);
1467 }
1468
1469=== modified file 'src/scripting/lua_map.cc'
1470--- src/scripting/lua_map.cc 2017-08-03 14:51:55 +0000
1471+++ src/scripting/lua_map.cc 2017-08-16 05:11:06 +0000
1472@@ -1206,7 +1206,7 @@
1473 :returns: The created immovable.
1474 */
1475 int LuaMap::place_immovable(lua_State* const L) {
1476- std::string from_where = "";
1477+ std::string from_where;
1478
1479 const std::string objname = luaL_checkstring(L, 2);
1480 LuaMaps::LuaField* c = *get_user_class<LuaMaps::LuaField>(L, 3);
1481
1482=== modified file 'src/scripting/lua_ui.cc'
1483--- src/scripting/lua_ui.cc 2017-05-13 11:25:24 +0000
1484+++ src/scripting/lua_ui.cc 2017-08-16 05:11:06 +0000
1485@@ -649,7 +649,7 @@
1486 int LuaMapView::scroll_to_map_pixel(lua_State* L) {
1487 Widelands::Game& game = get_game(L);
1488 // don't move view in replays
1489- if (game.game_controller()->get_game_type() == GameController::GameType::REPLAY) {
1490+ if (game.game_controller()->get_game_type() == GameController::GameType::kReplay) {
1491 return 0;
1492 }
1493
1494
1495=== modified file 'src/sound/sound_handler.cc'
1496--- src/sound/sound_handler.cc 2017-03-03 18:13:55 +0000
1497+++ src/sound/sound_handler.cc 2017-08-16 05:11:06 +0000
1498@@ -72,7 +72,6 @@
1499 music_volume_(MIX_MAX_VOLUME),
1500 fx_volume_(MIX_MAX_VOLUME),
1501 random_order_(true),
1502- current_songset_(""),
1503 fx_lock_(nullptr) {
1504 }
1505
1506
1507=== modified file 'src/ui_basic/checkbox.cc'
1508--- src/ui_basic/checkbox.cc 2017-06-23 16:16:28 +0000
1509+++ src/ui_basic/checkbox.cc 2017-08-16 05:11:06 +0000
1510@@ -45,8 +45,7 @@
1511 : Panel(parent, p.x, p.y, kStateboxSize, kStateboxSize, tooltip_text),
1512 flags_(Is_Enabled),
1513 pic_graphics_(pic),
1514- rendered_text_(nullptr),
1515- label_text_("") {
1516+ rendered_text_(nullptr) {
1517 uint16_t w = pic->width();
1518 uint16_t h = pic->height();
1519 set_desired_size(w, h);
1520
1521=== modified file 'src/ui_basic/multilineeditbox.cc'
1522--- src/ui_basic/multilineeditbox.cc 2017-06-23 17:23:04 +0000
1523+++ src/ui_basic/multilineeditbox.cc 2017-08-16 05:11:06 +0000
1524@@ -59,7 +59,7 @@
1525 WordWrap ww;
1526 /*@}*/
1527
1528- Data(MultilineEditbox&, const Image* button_background);
1529+ Data(MultilineEditbox&, const Image* init_background, const Image* button_background);
1530 void refresh_ww();
1531
1532 void update();
1533@@ -89,8 +89,7 @@
1534 const std::string& text,
1535 const Image* background,
1536 const Image* button_background)
1537- : Panel(parent, x, y, w, h), d_(new Data(*this, button_background)) {
1538- d_->background = background;
1539+ : Panel(parent, x, y, w, h), d_(new Data(*this, background, button_background)) {
1540 d_->lineheight = text_height();
1541 set_handle_mouse(true);
1542 set_can_focus(true);
1543@@ -100,8 +99,9 @@
1544 set_text(text);
1545 }
1546
1547-MultilineEditbox::Data::Data(MultilineEditbox& o, const Image* button_background)
1548+MultilineEditbox::Data::Data(MultilineEditbox& o, const Image* init_background, const Image* button_background)
1549 : scrollbar(&o, o.get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, o.get_h(), button_background),
1550+ background(init_background),
1551 cursor_pos(0),
1552 maxbytes(std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, 0xffff)),
1553 ww_valid(false),
1554
1555=== modified file 'src/ui_basic/slider.cc'
1556--- src/ui_basic/slider.cc 2017-07-02 19:21:56 +0000
1557+++ src/ui_basic/slider.cc 2017-08-16 05:11:06 +0000
1558@@ -66,6 +66,7 @@
1559 min_value_(min_value),
1560 max_value_(max_value),
1561 value_(value),
1562+ relative_move_(0),
1563 highlighted_(false),
1564 pressed_(false),
1565 enabled_(enabled),
1566
1567=== modified file 'src/ui_basic/table.h'
1568--- src/ui_basic/table.h 2017-06-24 08:47:46 +0000
1569+++ src/ui_basic/table.h 2017-08-16 05:11:06 +0000
1570@@ -156,6 +156,15 @@
1571 std::vector<Data> data_;
1572 };
1573
1574+ Table(Panel* parent,
1575+ int32_t x,
1576+ int32_t y,
1577+ uint32_t w,
1578+ uint32_t h,
1579+ const Image* button_background = g_gr->images().get("images/ui_basic/but3.png"),
1580+ TableRows rowtype = TableRows::kSingle);
1581+ ~Table();
1582+
1583 /**
1584 * Compare the two items at the given indices in the list.
1585 *
1586@@ -163,15 +172,6 @@
1587 */
1588 using CompareFn = boost::function<bool(uint32_t, uint32_t)>;
1589
1590- Table(Panel* parent,
1591- int32_t x,
1592- int32_t y,
1593- uint32_t w,
1594- uint32_t h,
1595- const Image* button_background = g_gr->images().get("images/ui_basic/but3.png"),
1596- TableRows rowtype = TableRows::kSingle);
1597- ~Table();
1598-
1599 boost::signals2::signal<void(uint32_t)> selected;
1600 boost::signals2::signal<void(uint32_t)> double_clicked;
1601
1602
1603=== modified file 'src/ui_basic/window.cc'
1604--- src/ui_basic/window.cc 2017-06-01 08:52:15 +0000
1605+++ src/ui_basic/window.cc 2017-08-16 05:11:06 +0000
1606@@ -78,6 +78,7 @@
1607 w + VT_B_PIXMAP_THICKNESS * 2,
1608 TP_B_PIXMAP_THICKNESS + h + BT_B_PIXMAP_THICKNESS),
1609 is_minimal_(false),
1610+ oldh_(TP_B_PIXMAP_THICKNESS + h + BT_B_PIXMAP_THICKNESS),
1611 dragging_(false),
1612 docked_left_(false),
1613 docked_right_(false),
1614
1615=== modified file 'src/ui_basic/window.h'
1616--- src/ui_basic/window.h 2017-01-25 18:55:59 +0000
1617+++ src/ui_basic/window.h 2017-08-16 05:11:06 +0000
1618@@ -104,7 +104,7 @@
1619
1620 private:
1621 bool is_minimal_;
1622- uint32_t oldh_; // if it is, this is the old height
1623+ uint32_t oldh_; // if it is minimized, this is the old height
1624 bool dragging_, docked_left_, docked_right_, docked_bottom_;
1625 int32_t drag_start_win_x_, drag_start_win_y_;
1626 int32_t drag_start_mouse_x_, drag_start_mouse_y_;
1627
1628=== modified file 'src/ui_fsmenu/loadgame.cc'
1629--- src/ui_fsmenu/loadgame.cc 2017-06-15 16:34:58 +0000
1630+++ src/ui_fsmenu/loadgame.cc 2017-08-16 05:11:06 +0000
1631@@ -531,10 +531,10 @@
1632
1633 if (!is_replay_) {
1634 if (settings_->settings().multiplayer) {
1635- if (gamedata.gametype == GameController::GameType::SINGLEPLAYER) {
1636+ if (gamedata.gametype == GameController::GameType::kSingleplayer) {
1637 continue;
1638 }
1639- } else if (gamedata.gametype > GameController::GameType::SINGLEPLAYER) {
1640+ } else if (gamedata.gametype > GameController::GameType::kSingleplayer) {
1641 continue;
1642 }
1643 }
1644@@ -601,14 +601,14 @@
1645 if (is_replay_ || settings_->settings().multiplayer) {
1646 std::string gametypestring;
1647 switch (gamedata.gametype) {
1648- case GameController::GameType::SINGLEPLAYER:
1649+ case GameController::GameType::kSingleplayer:
1650 /** TRANSLATORS: "Single Player" entry in the Game Mode table column. */
1651 /** TRANSLATORS: "Keep this to 6 letters maximum. */
1652 /** TRANSLATORS: A tooltip will explain the abbreviation. */
1653 /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
1654 gametypestring = _("SP");
1655 break;
1656- case GameController::GameType::NETHOST:
1657+ case GameController::GameType::kNetHost:
1658 /** TRANSLATORS: "Multiplayer Host" entry in the Game Mode table column. */
1659 /** TRANSLATORS: "Keep this to 2 letters maximum. */
1660 /** TRANSLATORS: A tooltip will explain the abbreviation. */
1661@@ -618,7 +618,7 @@
1662 (boost::format(_("H (%1%)")) % static_cast<unsigned int>(gamedata.nrplayers))
1663 .str();
1664 break;
1665- case GameController::GameType::NETCLIENT:
1666+ case GameController::GameType::kNetClient:
1667 /** TRANSLATORS: "Multiplayer" entry in the Game Mode table column. */
1668 /** TRANSLATORS: "Keep this to 2 letters maximum. */
1669 /** TRANSLATORS: A tooltip will explain the abbreviation. */
1670@@ -628,9 +628,11 @@
1671 (boost::format(_("MP (%1%)")) % static_cast<unsigned int>(gamedata.nrplayers))
1672 .str();
1673 break;
1674- case GameController::GameType::REPLAY:
1675+ case GameController::GameType::kReplay:
1676 gametypestring = "";
1677 break;
1678+ case GameController::GameType::kUndefined:
1679+ NEVER_HERE();
1680 }
1681 te.set_string(1, gametypestring);
1682 te.set_string(2, map_filename(gamedata.filename, gamedata.mapname));
1683
1684=== modified file 'src/ui_fsmenu/loadgame.h'
1685--- src/ui_fsmenu/loadgame.h 2017-01-26 09:28:40 +0000
1686+++ src/ui_fsmenu/loadgame.h 2017-08-16 05:11:06 +0000
1687@@ -65,7 +65,7 @@
1688 : gametime(0),
1689 nrplayers(0),
1690 savetimestamp(0),
1691- gametype(GameController::GameType::SINGLEPLAYER) {
1692+ gametype(GameController::GameType::kSingleplayer) {
1693 }
1694 };
1695
1696
1697=== modified file 'src/wui/building_statistics_menu.cc'
1698--- src/wui/building_statistics_menu.cc 2017-06-28 07:17:12 +0000
1699+++ src/wui/building_statistics_menu.cc 2017-08-16 05:11:06 +0000
1700@@ -676,7 +676,7 @@
1701 }
1702 }
1703
1704- std::string owned_text = "";
1705+ std::string owned_text;
1706 if (player.tribe().has_building(id) && (building.is_buildable() || building.is_enhanced())) {
1707 /** TRANSLATORS Buildings: owned / under construction */
1708 owned_text = (boost::format(_("%1%/%2%")) % nr_owned % nr_build).str();
1709
1710=== modified file 'src/wui/debugconsole.cc'
1711--- src/wui/debugconsole.cc 2017-01-25 18:55:59 +0000
1712+++ src/wui/debugconsole.cc 2017-08-16 05:11:06 +0000
1713@@ -25,6 +25,7 @@
1714
1715 #include "base/log.h"
1716 #include "chat/chat.h"
1717+#include "logic/widelands.h"
1718
1719 namespace DebugConsole {
1720
1721@@ -87,10 +88,7 @@
1722 }
1723
1724 void write(const std::string& msg) {
1725- ChatMessage cm;
1726-
1727- cm.time = time(nullptr);
1728- cm.msg = msg;
1729+ ChatMessage cm(msg);
1730 messages.push_back(cm);
1731
1732 log("*** %s\n", msg.c_str());
1733
1734=== modified file 'src/wui/field_overlay_manager.cc'
1735--- src/wui/field_overlay_manager.cc 2017-08-15 17:37:57 +0000
1736+++ src/wui/field_overlay_manager.cc 2017-08-16 05:11:06 +0000
1737@@ -26,7 +26,7 @@
1738 #include "graphic/graphic.h"
1739 #include "logic/field.h"
1740
1741-FieldOverlayManager::FieldOverlayManager() : current_overlay_id_(0) {
1742+FieldOverlayManager::FieldOverlayManager() : buildhelp_(false), current_overlay_id_(0) {
1743 OverlayInfo* buildhelp_info = buildhelp_infos_;
1744 const char* filenames[] = {"images/wui/overlays/set_flag.png", "images/wui/overlays/small.png",
1745 "images/wui/overlays/medium.png", "images/wui/overlays/big.png",
1746
1747=== modified file 'src/wui/game_message_menu.cc'
1748--- src/wui/game_message_menu.cc 2017-06-24 11:18:12 +0000
1749+++ src/wui/game_message_menu.cc 2017-08-16 05:11:06 +0000
1750@@ -613,7 +613,7 @@
1751 return;
1752 }
1753 archivebtn_->set_enabled(true);
1754- std::string button_tooltip = "";
1755+ std::string button_tooltip;
1756 size_t no_selections = list->selections().size();
1757 switch (mode) {
1758 case Archive:
1759
1760=== modified file 'src/wui/mapdata.cc'
1761--- src/wui/mapdata.cc 2017-01-25 18:55:59 +0000
1762+++ src/wui/mapdata.cc 2017-08-16 05:11:06 +0000
1763@@ -30,8 +30,6 @@
1764 name(init_localized_name),
1765 localized_name(init_localized_name),
1766 authors(init_author),
1767- description(""),
1768- hint(""),
1769 nrplayers(0),
1770 width(0),
1771 height(0),
1772
1773=== modified file 'src/wui/soldierlist.cc'
1774--- src/wui/soldierlist.cc 2017-08-09 19:25:04 +0000
1775+++ src/wui/soldierlist.cc 2017-08-16 05:11:06 +0000
1776@@ -144,6 +144,8 @@
1777 icon.row = row;
1778 icon.col = col;
1779 icon.pos = calc_pos(row, col);
1780+ icon.cache_health = 0;
1781+ icon.cache_level = 0;
1782 icons_.push_back(icon);
1783
1784 if (++col >= cols_) {
1785@@ -407,7 +409,7 @@
1786 }
1787
1788 soldier_preference_.set_state(0);
1789- if (ms->get_soldier_preference() == Widelands::MilitarySite::kPrefersHeroes) {
1790+ if (ms->get_soldier_preference() == Widelands::SoldierPreference::kHeroes) {
1791 soldier_preference_.set_state(1);
1792 }
1793 if (can_act) {
1794@@ -433,15 +435,14 @@
1795 }
1796 if (upcast(Widelands::MilitarySite, ms, &building_)) {
1797 switch (ms->get_soldier_preference()) {
1798- case Widelands::MilitarySite::kPrefersRookies:
1799+ case Widelands::SoldierPreference::kRookies:
1800+ FALLS_THROUGH;
1801+ case Widelands::SoldierPreference::kNotSet:
1802 soldier_preference_.set_state(0);
1803 break;
1804- case Widelands::MilitarySite::kPrefersHeroes:
1805+ case Widelands::SoldierPreference::kHeroes:
1806 soldier_preference_.set_state(1);
1807 break;
1808- case Widelands::MilitarySite::kNoPreference:
1809- soldier_preference_.set_state(-1);
1810- break;
1811 }
1812 }
1813 }
1814@@ -476,8 +477,8 @@
1815 assert(ms);
1816 #endif
1817 igbase_.game().send_player_militarysite_set_soldier_preference(
1818- building_, changed_to == 0 ? Widelands::MilitarySite::kPrefersRookies :
1819- Widelands::MilitarySite::kPrefersHeroes);
1820+ building_, changed_to == 0 ? Widelands::SoldierPreference::kRookies :
1821+ Widelands::SoldierPreference::kHeroes);
1822 }
1823
1824 UI::Panel*
1825
1826=== modified file 'src/wui/tribal_encyclopedia.cc'
1827--- src/wui/tribal_encyclopedia.cc 2017-01-25 18:55:59 +0000
1828+++ src/wui/tribal_encyclopedia.cc 2017-08-16 05:11:06 +0000
1829@@ -43,7 +43,7 @@
1830 std::unique_ptr<LuaCoroutine> cr(table->get_coroutine("func"));
1831 cr->push_arg(tribe.name());
1832 upcast(Widelands::Game, game, &parent.egbase());
1833- if (game->game_controller()->get_game_type() == GameController::GameType::SINGLEPLAYER) {
1834+ if (game->game_controller()->get_game_type() == GameController::GameType::kSingleplayer) {
1835 cr->push_arg("singleplayer");
1836 } else {
1837 cr->push_arg("multiplayer");

Subscribers

People subscribed via source and target branches

to status/vote changes: