widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #10970
[Merge] lp:~widelands-dev/widelands/bug-986611-cppcheck-mopup into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-986611-cppcheck-mopup into lp:widelands.
Commit message:
Fixed diverse cppcheck warnings:
- Performance
- Made some constructors explicit.
- Added parentheses to logic in MapPlayersViewPacket.
- Fixed order of statements and a logic error in the AI.
- Fixed suspicious calculation warnings.
- Removed some unused variables.
- Removed most unused functions.
Requested reviews:
TiborB (tiborb95)
Widelands Developers (widelands-dev)
Related bugs:
Bug #986611 in widelands: "Issues reported by cppcheck"
https://bugs.launchpad.net/widelands/+bug/986611
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-986611-cppcheck-mopup/+merge/329280
This should make the report short enough so that we can look at the interesting issues.
Also caught 2 bugs in the AI.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-986611-cppcheck-mopup into lp:widelands.
=== modified file 'src/ai/ai_help_structs.cc'
--- src/ai/ai_help_structs.cc 2017-08-18 00:17:39 +0000
+++ src/ai/ai_help_structs.cc 2017-08-19 07:34:40 +0000
@@ -262,10 +262,6 @@
is_militarysite(false) {
}
-int32_t BuildableField::own_military_sites_nearby_() {
- return military_stationed + military_unstationed;
-}
-
MineableField::MineableField(const Widelands::FCoords& fc)
: coords(fc),
field_info_expiration(20000),
@@ -405,9 +401,7 @@
}
// FNeuron is basically a single uint32_t integer, and the AI can query every bit of that uint32_t
-FNeuron::FNeuron(uint32_t c, uint16_t i) {
- core = c;
- id = i;
+FNeuron::FNeuron(uint32_t c, uint16_t i) : core(c), id(i) {
}
// Returning a result depending on combinations of 5 bools
@@ -1294,14 +1288,6 @@
return pw;
}
-// This is casualities of player
-uint32_t PlayersStrengths::get_player_casualities(Widelands::PlayerNumber pn) {
- if (all_stats.count(pn) > 0) {
- return all_stats[pn].players_casualities;
- }
- return 0;
-}
-
// This is strength of player plus third of strength of other members of his team
uint32_t PlayersStrengths::get_modified_player_power(Widelands::PlayerNumber pn) {
uint32_t result = 0;
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2017-08-18 00:17:39 +0000
+++ src/ai/ai_help_structs.h 2017-08-19 07:34:40 +0000
@@ -302,8 +302,6 @@
struct BuildableField {
explicit BuildableField(const Widelands::FCoords& fc);
- int32_t own_military_sites_nearby_();
-
Widelands::FCoords coords;
uint32_t field_info_expiration;
@@ -833,7 +831,6 @@
uint32_t get_enemies_max_power();
uint32_t get_enemies_max_land();
uint32_t get_old_visible_enemies_power(uint32_t);
- uint32_t get_player_casualities(Widelands::PlayerNumber pn);
bool players_in_same_team(Widelands::PlayerNumber pl1, Widelands::PlayerNumber pl2);
bool strong_enough(Widelands::PlayerNumber pl);
void set_last_time_seen(uint32_t, Widelands::PlayerNumber);
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2017-08-18 00:17:39 +0000
+++ src/ai/defaultai.cc 2017-08-19 07:34:40 +0000
@@ -3643,7 +3643,7 @@
// The site is in process of emptying its input queues
// Do nothing when some wares are left, but do not wait more then 4 minutes
if (site.bo->construction_decision_time + 4 * 60 * 1000 > gametime &&
- set_inputs_to_zero(site) > 0) {
+ !set_inputs_to_zero(site)) {
return false;
}
assert(site.bo->cnt_upgrade_pending == 1);
@@ -4879,9 +4879,9 @@
if (tmp_score < 0) {
return BuildingNecessity::kNeededPending;
} else {
- return BuildingNecessity::kNeeded;
bo.primary_priority +=
tmp_score * std::abs(management_data.get_military_number_at(127) / 5);
+ return BuildingNecessity::kNeeded;
}
} else if (bo.max_needed_preciousness > 0) {
@@ -6020,14 +6020,6 @@
}
}
- std::string summary;
- for (const auto material : materials) {
- uint32_t stock = calculate_stocklevel(material);
- if (stock == 0) {
- summary = summary + game().tribes().get_ware_descr(material)->descname() + ", ";
- }
- }
-
if (false)
log(" %1d: %s Buildings count: Pr:%3u, Ml:%3u, Mi:%2u, Wh:%2u, Po:%u.\n", pn,
gamestring_with_leading_zeros(gametime), static_cast<uint32_t>(productionsites.size()),
@@ -6101,32 +6093,20 @@
why += ", less then 2 mines";
}
- if (false)
+ if (false) {
log("Prodsites in constr: %2d, mines in constr: %2d %s %s\n", numof_psites_in_constr,
mines_in_constr(),
(expansion_type.get_expansion_type() != ExpansionMode::kEconomy) ? "NEW BUILDING STOP" :
"",
why.c_str());
+ }
- if (false)
+ if (false) {
log("Least military score: %5d/%3d, msites in constr: %3d,"
"soldier st: %2d, strength: %3d\n",
persistent_data->least_military_score, persistent_data->ai_personality_mil_upper_limit,
msites_in_constr(), static_cast<int8_t>(soldier_status_),
player_statistics.get_modified_player_power(player_number()));
- std::string wpolicy;
- switch (wood_policy_) {
- case WoodPolicy::kDismantleRangers:
- wpolicy = "Dismantle rangers";
- break;
- case WoodPolicy::kAllowRangers:
- wpolicy = "Allow rangers";
- break;
- case WoodPolicy::kStopRangers:
- wpolicy = "Stop rangers";
- break;
- default:
- wpolicy = "unknown";
}
}
=== modified file 'src/ai/defaultai.h'
--- src/ai/defaultai.h 2017-08-14 18:31:43 +0000
+++ src/ai/defaultai.h 2017-08-19 07:34:40 +0000
@@ -259,7 +259,6 @@
bool check_enemy_sites(uint32_t);
void count_military_vacant_positions();
bool check_trainingsites(uint32_t);
- uint32_t barracks_count();
// return single number of strength of vector of soldiers
int32_t calculate_strength(const std::vector<Widelands::Soldier*>&);
// for militarysites (overloading the function)
=== modified file 'src/ai/defaultai_warfare.cc'
--- src/ai/defaultai_warfare.cc 2017-08-09 18:45:15 +0000
+++ src/ai/defaultai_warfare.cc 2017-08-19 07:34:40 +0000
@@ -879,16 +879,6 @@
return changed;
}
-uint32_t DefaultAI::barracks_count() {
- uint32_t count = 0;
- for (auto ps : productionsites) {
- if (ps.bo->is(BuildingAttribute::kBarracks)) {
- count += ps.bo->total_count();
- }
- }
- return count;
-}
-
// This calculates strength of vector of soldiers, f.e. soldiers in a building or
// ones ready to attack
int32_t DefaultAI::calculate_strength(const std::vector<Widelands::Soldier*>& soldiers) {
=== modified file 'src/chat/chat.h'
--- src/chat/chat.h 2017-08-16 04:31:56 +0000
+++ src/chat/chat.h 2017-08-19 07:34:40 +0000
@@ -32,7 +32,7 @@
struct ChatMessage {
CAN_BE_SENT_AS_NOTE(NoteId::ChatMessage)
- ChatMessage(const std::string& message) : msg(message) {
+ explicit ChatMessage(const std::string& message) : msg(message) {
}
// The (real-)time at which the message was received.
=== modified file 'src/economy/shippingitem.cc'
--- src/economy/shippingitem.cc 2017-01-25 18:55:59 +0000
+++ src/economy/shippingitem.cc 2017-08-19 07:34:40 +0000
@@ -129,19 +129,6 @@
destination_dock_ = dynamic_cast<PortDock*>(next);
}
-void ShippingItem::schedule_update(Game& game, int32_t delay) {
- WareInstance* ware;
- Worker* worker;
- get(game, &ware, &worker);
-
- if (ware) {
- ware->schedule_act(game, delay);
- }
- if (worker) {
- worker->send_signal(game, "wakeup");
- }
-}
-
/**
* Remove the underlying item directly. This is used when ships are removed.
*/
=== modified file 'src/economy/shippingitem.h'
--- src/economy/shippingitem.h 2017-08-09 17:53:24 +0000
+++ src/economy/shippingitem.h 2017-08-19 07:34:40 +0000
@@ -54,7 +54,6 @@
void set_economy(Game&, Economy* e);
PortDock* get_destination(Game&);
- void schedule_update(Game&, int32_t delay);
void remove(EditorGameBase&);
=== modified file 'src/economy/trackptr.h'
--- src/economy/trackptr.h 2017-06-24 08:47:46 +0000
+++ src/economy/trackptr.h 2017-08-19 07:34:40 +0000
@@ -157,12 +157,11 @@
derived from Trackable.
*/
template <class T> struct TrackPtr : BaseTrackPtr {
- TrackPtr() {
- }
+ TrackPtr() = default;
explicit TrackPtr(T* ptr) : BaseTrackPtr(ptr) {
}
- TrackPtr(const TrackPtr<T>& o) : BaseTrackPtr(o) {
+ explicit TrackPtr(const TrackPtr<T>& o) : BaseTrackPtr(o) {
}
TrackPtr& operator=(const TrackPtr<T>& o) {
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc 2017-01-25 18:55:59 +0000
+++ src/editor/map_generator.cc 2017-08-19 07:34:40 +0000
@@ -51,7 +51,7 @@
}
void MapGenerator::generate_bobs(std::unique_ptr<uint32_t[]> const* random_bobs,
- Coords const fc,
+ const Coords& fc,
RNG& rng,
MapGenAreaInfo::MapGenTerrainType const terrType) {
// Figure out which bob area is due here...
@@ -194,7 +194,7 @@
/// (map specific info).
///
/// \returns A map height value corresponding to elevation.
-uint8_t MapGenerator::make_node_elevation(double const elevation, Coords const c) {
+uint8_t MapGenerator::make_node_elevation(double const elevation, const Coords& c) {
int32_t const water_h = map_gen_info_->get_water_shallow_height();
int32_t const mount_h = map_gen_info_->get_mountain_foot_height();
int32_t const summit_h = map_gen_info_->get_summit_height();
=== modified file 'src/editor/map_generator.h'
--- src/editor/map_generator.h 2017-01-25 18:55:59 +0000
+++ src/editor/map_generator.h 2017-08-19 07:34:40 +0000
@@ -78,7 +78,7 @@
private:
void generate_bobs(std::unique_ptr<uint32_t[]> const* random_bobs,
- Coords,
+ const Coords&,
RNG&,
MapGenAreaInfo::MapGenTerrainType terrType);
@@ -88,7 +88,7 @@
uint32_t const* const random4,
const FCoords& fc);
- uint8_t make_node_elevation(double elevation, Coords);
+ uint8_t make_node_elevation(double elevation, const Coords&);
static uint32_t* generate_random_value_map(uint32_t w, uint32_t h, RNG& rng);
=== modified file 'src/editor/tools/set_port_space_tool.h'
--- src/editor/tools/set_port_space_tool.h 2017-08-13 18:02:53 +0000
+++ src/editor/tools/set_port_space_tool.h 2017-08-19 07:34:40 +0000
@@ -51,7 +51,7 @@
/// Sets a buildspace for ports.
class EditorSetPortSpaceTool : public EditorTool {
public:
- EditorSetPortSpaceTool(EditorUnsetPortSpaceTool&);
+ explicit EditorSetPortSpaceTool(EditorUnsetPortSpaceTool&);
int32_t handle_click_impl(const Widelands::World& world,
const Widelands::NodeAndTriangle<>& center,
=== modified file 'src/graphic/font.cc'
--- src/graphic/font.cc 2017-03-25 15:32:49 +0000
+++ src/graphic/font.cc 2017-08-19 07:34:40 +0000
@@ -122,13 +122,6 @@
}
/**
- * \return the number of pixels between lines in this font (from baseline to baseline).
- */
-uint32_t Font::lineskip() const {
- return computed_typical_maxy_ - computed_typical_miny_;
-}
-
-/**
* Return the font for the given name and size.
*
* \note Fonts are cached and need not be freed explicitly. \see shutdown
=== modified file 'src/graphic/font.h'
--- src/graphic/font.h 2017-03-25 15:32:49 +0000
+++ src/graphic/font.h 2017-08-19 07:34:40 +0000
@@ -50,7 +50,6 @@
uint32_t size() const;
uint32_t ascent() const;
uint32_t height() const;
- uint32_t lineskip() const;
TTF_Font* get_ttf_font() const {
return font_;
=== modified file 'src/graphic/font_handler.cc'
--- src/graphic/font_handler.cc 2017-05-14 04:38:39 +0000
+++ src/graphic/font_handler.cc 2017-08-19 07:34:40 +0000
@@ -118,18 +118,6 @@
d.reset(new Data);
}
-/*
- * Returns the height of the font, in pixels.
-*/
-uint32_t FontHandler::get_fontheight(const std::string& name, int32_t const size) {
- TTF_Font* const f = Font::get(name, size)->get_ttf_font();
- const int32_t fontheight = TTF_FontHeight(f);
- if (fontheight < 0)
- throw wexception("TTF_FontHeight returned a negative value, which does not have a "
- "known meaning.");
- return fontheight;
-}
-
/**
* Get a cache entry for the given text (without linebreaks!) rendered
* in the given style.
=== modified file 'src/graphic/font_handler.h'
--- src/graphic/font_handler.h 2017-02-23 19:38:51 +0000
+++ src/graphic/font_handler.h 2017-08-19 07:34:40 +0000
@@ -60,7 +60,6 @@
uint32_t& w,
uint32_t& h,
uint32_t wrap = std::numeric_limits<uint32_t>::max());
- uint32_t get_fontheight(const std::string& name, int32_t size);
// Delete the whole cache.
void flush();
=== modified file 'src/graphic/image_io.cc'
--- src/graphic/image_io.cc 2017-01-25 18:55:59 +0000
+++ src/graphic/image_io.cc 2017-08-19 07:34:40 +0000
@@ -77,7 +77,7 @@
SDL_Surface* sdlsurf = IMG_Load_RW(SDL_RWFromMem(fr.data(0), fr.get_size()), 1);
if (!sdlsurf) {
- throw ImageLoadingError(fname.c_str(), IMG_GetError());
+ throw ImageLoadingError(fname, IMG_GetError());
}
return sdlsurf;
}
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2017-08-16 13:23:15 +0000
+++ src/graphic/text/rt_render.cc 2017-08-19 07:34:40 +0000
@@ -259,9 +259,6 @@
UI::Align halign() const {
return halign_;
}
- void set_halign(UI::Align ghalign) {
- halign_ = ghalign;
- }
UI::Align valign() const {
return valign_;
}
=== modified file 'src/io/filesystem/disk_filesystem.cc'
--- src/io/filesystem/disk_filesystem.cc 2017-07-03 19:24:02 +0000
+++ src/io/filesystem/disk_filesystem.cc 2017-08-19 07:34:40 +0000
@@ -77,19 +77,6 @@
return true;
}
-/// returns true, if the file is writeable
-bool RealFSImpl::file_is_writeable(const std::string& path) {
- std::string fullname;
- fullname = canonicalize_name(path);
-
- // we call fopen with "a" == append to be sure nothing gets overwritten
- FILE* const f = fopen(fullname.c_str(), "a");
- if (!f)
- return false;
- fclose(f);
- return true;
-}
-
std::set<std::string> RealFSImpl::list_directory(const std::string& path) {
#ifdef _WIN32
std::string buf;
=== modified file 'src/io/filesystem/disk_filesystem.h'
--- src/io/filesystem/disk_filesystem.h 2017-06-24 08:47:46 +0000
+++ src/io/filesystem/disk_filesystem.h 2017-08-19 07:34:40 +0000
@@ -33,7 +33,6 @@
std::set<std::string> list_directory(const std::string& path) override;
bool is_writable() const override;
- bool file_is_writeable(const std::string& path);
bool file_exists(const std::string& path) override;
bool is_directory(const std::string& path) override;
void ensure_directory_exists(const std::string& fs_dirname) override;
=== modified file 'src/io/filesystem/layered_filesystem.cc'
--- src/io/filesystem/layered_filesystem.cc 2017-01-25 18:55:59 +0000
+++ src/io/filesystem/layered_filesystem.cc 2017-08-19 07:34:40 +0000
@@ -70,17 +70,6 @@
}
/**
- * Remove a filesystem from the stack
- * \param fs The filesystem to be removed
- */
-void LayeredFileSystem::remove_file_system(const FileSystem& fs) {
- if (filesystems_.back().get() != &fs)
- throw std::logic_error("LayeredFileSystem::remove_file_system: interspersed add/remove "
- "detected!");
- filesystems_.pop_back();
-}
-
-/**
* Find files in all sub-filesystems in the given path, with the given pattern.
* Store all found files in results.
*
=== modified file 'src/io/filesystem/layered_filesystem.h'
--- src/io/filesystem/layered_filesystem.h 2017-01-25 18:55:59 +0000
+++ src/io/filesystem/layered_filesystem.h 2017-08-19 07:34:40 +0000
@@ -56,8 +56,6 @@
// files). Take ownership of the given filesystem.
void set_home_file_system(FileSystem*);
- virtual void remove_file_system(const FileSystem&);
-
std::set<std::string> list_directory(const std::string& path) override;
/// Returns true if the filename is legal in all operating systems
=== modified file 'src/io/filewrite.cc'
--- src/io/filewrite.cc 2017-01-25 18:55:59 +0000
+++ src/io/filewrite.cc 2017-08-19 07:34:40 +0000
@@ -41,11 +41,6 @@
clear();
}
-void FileWrite::write_append(RealFSImpl& fs, char const* const filename) {
- fs.write(filename, data_, length_, true);
- clear();
-}
-
FileWrite::Pos FileWrite::get_pos() const {
return filepos_;
}
=== modified file 'src/io/filewrite.h'
--- src/io/filewrite.h 2017-01-25 18:55:59 +0000
+++ src/io/filewrite.h 2017-08-19 07:34:40 +0000
@@ -53,7 +53,7 @@
Pos operator++() {
return ++pos;
}
- Pos operator+=(Pos const other) {
+ Pos operator+=(const Pos& other) {
return pos += other.pos;
}
@@ -78,10 +78,6 @@
/// worry, it will be cleared by the destructor).
void write(FileSystem& fs, char const* const filename);
- /// Same as above, just that the data is appended to the file
- /// NOTE RealFSImpl is used by purpose - zip filesystems do not support appending
- void write_append(RealFSImpl& fs, char const* const filename);
-
/// Get the position that will be written to in the next write operation that
/// does not specify a position.
Pos get_pos() const;
=== modified file 'src/logic/cookie_priority_queue.h'
--- src/logic/cookie_priority_queue.h 2017-01-25 18:55:59 +0000
+++ src/logic/cookie_priority_queue.h 2017-08-19 07:34:40 +0000
@@ -224,7 +224,9 @@
swap(elt_cookie, parent_cookie);
}
- // selftest();
+#ifndef NDEBUG
+ selftest();
+#endif
}
template <typename _T, typename _Cw, typename _CA>
@@ -266,8 +268,9 @@
break;
}
-
- // selftest();
+#ifndef NDEBUG
+ selftest();
+#endif
}
template <typename _T, typename _Cw, typename _CA>
=== modified file 'src/logic/findimmovable.h'
--- src/logic/findimmovable.h 2017-06-24 08:47:46 +0000
+++ src/logic/findimmovable.h 2017-08-19 07:34:40 +0000
@@ -62,7 +62,7 @@
BaseCapsule* capsule;
public:
- FindImmovable(const FindImmovable& o) {
+ explicit FindImmovable(const FindImmovable& o) {
capsule = o.capsule;
capsule->addref();
}
=== modified file 'src/logic/findnode.h'
--- src/logic/findnode.h 2017-02-15 01:56:35 +0000
+++ src/logic/findnode.h 2017-08-19 07:34:40 +0000
@@ -53,7 +53,7 @@
int refcount;
};
template <typename T> struct Capsule : public BaseCapsule {
- Capsule(const T& init_op) : op(init_op) {
+ explicit Capsule(const T& init_op) : op(init_op) {
}
bool accept(const Map& map, const FCoords& coord) const override {
return op.accept(map, coord);
@@ -65,7 +65,7 @@
BaseCapsule* capsule;
public:
- FindNode(const FindNode& o) {
+ explicit FindNode(const FindNode& o) {
capsule = o.capsule;
capsule->addref();
}
@@ -91,7 +91,7 @@
};
struct FindNodeCaps {
- FindNodeCaps(uint8_t init_mincaps) : mincaps(init_mincaps) {
+ explicit FindNodeCaps(uint8_t init_mincaps) : mincaps(init_mincaps) {
}
bool accept(const Map&, const FCoords&) const;
@@ -132,7 +132,7 @@
sizePort, // can build a port on this field
};
- FindNodeSize(Size init_size) : size(init_size) {
+ explicit FindNodeSize(Size init_size) : size(init_size) {
}
bool accept(const Map&, const FCoords&) const;
@@ -145,7 +145,7 @@
struct FindNodeImmovableSize {
enum { sizeNone = 1 << 0, sizeSmall = 1 << 1, sizeMedium = 1 << 2, sizeBig = 1 << 3 };
- FindNodeImmovableSize(uint32_t init_sizes) : sizes(init_sizes) {
+ explicit FindNodeImmovableSize(uint32_t init_sizes) : sizes(init_sizes) {
}
bool accept(const Map&, const FCoords&) const;
@@ -156,7 +156,7 @@
/// Accepts a node if it has an immovable with a given attribute.
struct FindNodeImmovableAttribute {
- FindNodeImmovableAttribute(uint32_t attrib) : attribute(attrib) {
+ explicit FindNodeImmovableAttribute(uint32_t attrib) : attribute(attrib) {
}
bool accept(const Map&, const FCoords&) const;
@@ -167,7 +167,7 @@
/// Accepts a node if it has at least one of the given resource.
struct FindNodeResource {
- FindNodeResource(DescriptionIndex res) : resource(res) {
+ explicit FindNodeResource(DescriptionIndex res) : resource(res) {
}
bool accept(const Map&, const FCoords&) const;
@@ -179,7 +179,7 @@
/// Accepts a node if it has the given resource type and remaining capacity.
/// If 'br' == AnimalBreedable::kAnimalFull, only accepts the node if it is full
struct FindNodeResourceBreedable {
- FindNodeResourceBreedable(DescriptionIndex res, AnimalBreedable br = AnimalBreedable::kDefault)
+ explicit FindNodeResourceBreedable(DescriptionIndex res, AnimalBreedable br = AnimalBreedable::kDefault)
: resource(res), strictness(br) {
}
@@ -193,7 +193,7 @@
/// Accepts a node if it is a shore node in the sense that it is walkable
/// and has at least one neighbouring field that is swimmable
struct FindNodeShore {
- FindNodeShore(uint16_t f = 1) : min_fields(f) {
+ explicit FindNodeShore(uint16_t f = 1) : min_fields(f) {
}
bool accept(const Map&, const FCoords&) const;
=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
--- src/logic/map_objects/tribes/dismantlesite.cc 2017-04-23 12:11:19 +0000
+++ src/logic/map_objects/tribes/dismantlesite.cc 2017-08-19 07:34:40 +0000
@@ -67,7 +67,7 @@
DismantleSite::DismantleSite(const DismantleSiteDescr& gdescr,
EditorGameBase& egbase,
- Coords const c,
+ const Coords& c,
Player& plr,
bool loading,
Building::FormerBuildings& former_buildings)
=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
--- src/logic/map_objects/tribes/dismantlesite.h 2017-06-25 19:12:30 +0000
+++ src/logic/map_objects/tribes/dismantlesite.h 2017-08-19 07:34:40 +0000
@@ -68,7 +68,7 @@
explicit DismantleSite(const DismantleSiteDescr& descr);
explicit DismantleSite(const DismantleSiteDescr& descr,
EditorGameBase&,
- Coords const,
+ const Coords&,
Player&,
bool,
Building::FormerBuildings& former_buildings);
=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc 2017-07-01 15:36:36 +0000
+++ src/logic/map_objects/tribes/warehouse.cc 2017-08-19 07:34:40 +0000
@@ -1270,10 +1270,6 @@
next_worker_without_cost_spawn_[worker_types_without_cost_index] =
schedule_act(game, WORKER_WITHOUT_COST_SPAWN_INTERVAL);
}
-void Warehouse::disable_spawn(uint8_t const worker_types_without_cost_index) {
- assert(next_worker_without_cost_spawn_[worker_types_without_cost_index] != never());
- next_worker_without_cost_spawn_[worker_types_without_cost_index] = never();
-}
void Warehouse::PlannedWorkers::cleanup() {
while (!requests.empty()) {
=== modified file 'src/logic/map_objects/tribes/warehouse.h'
--- src/logic/map_objects/tribes/warehouse.h 2017-06-25 19:12:30 +0000
+++ src/logic/map_objects/tribes/warehouse.h 2017-08-19 07:34:40 +0000
@@ -195,7 +195,6 @@
std::vector<Quantity> calc_available_for_worker(Game&, DescriptionIndex index) const;
void enable_spawn(Game&, uint8_t worker_types_without_cost_index);
- void disable_spawn(uint8_t worker_types_without_cost_index);
void receive_ware(Game&, DescriptionIndex ware) override;
void receive_worker(Game&, Worker& worker) override;
=== modified file 'src/logic/map_revision.cc'
--- src/logic/map_revision.cc 2017-01-25 18:55:59 +0000
+++ src/logic/map_revision.cc 2017-08-19 07:34:40 +0000
@@ -23,8 +23,6 @@
namespace Widelands {
-MapVersion::MapVersion() : map_version_major(0), map_version_minor(0) {
- map_creator_version = build_id();
- map_version_timestamp = static_cast<uint32_t>(time(nullptr));
+MapVersion::MapVersion() : map_creator_version(build_id()), map_version_major(0), map_version_minor(0), map_version_timestamp(static_cast<uint32_t>(time(nullptr))) {
}
}
=== modified file 'src/logic/mapastar.h'
--- src/logic/mapastar.h 2017-06-24 08:47:46 +0000
+++ src/logic/mapastar.h 2017-08-19 07:34:40 +0000
@@ -158,7 +158,7 @@
// avoid bias by using different orders when pathfinding
static const int8_t order1[] = {WALK_NW, WALK_NE, WALK_E, WALK_SE, WALK_SW, WALK_W};
static const int8_t order2[] = {WALK_NW, WALK_W, WALK_SW, WALK_SE, WALK_E, WALK_NE};
- int8_t const* direction = (cur.x + cur.y) & 1 ? order1 : order2;
+ int8_t const* direction = ((cur.x + cur.y) & 1) ? order1 : order2;
// Check all the 6 neighbours
for (uint32_t i = 6; i; i--, direction++) {
=== modified file 'src/logic/mapdifferenceregion.cc'
--- src/logic/mapdifferenceregion.cc 2017-01-25 18:55:59 +0000
+++ src/logic/mapdifferenceregion.cc 2017-08-19 07:34:40 +0000
@@ -43,34 +43,4 @@
return false;
}
-template <> void MapDifferenceRegion<Area<FCoords>>::move_to_other_side(const Map& map) {
- assert(1 <= direction_);
- assert(direction_ <= 6);
- assert(passed_corner_);
- --direction_;
- if (!direction_)
- direction_ = 6;
- Area<FCoords>::RadiusType steps_left = area_.radius + 1;
- switch (direction_) {
-#define DIRECTION_CASE(dir, neighbour_function) \
- case dir: \
- for (; steps_left; --steps_left) \
- map.neighbour_function(area_, &area_); \
- break;
-
- DIRECTION_CASE(WALK_NW, get_tln);
- DIRECTION_CASE(WALK_NE, get_trn);
- DIRECTION_CASE(WALK_E, get_rn);
- DIRECTION_CASE(WALK_SE, get_brn);
- DIRECTION_CASE(WALK_SW, get_bln);
- DIRECTION_CASE(WALK_W, get_ln);
- default:
- NEVER_HERE();
- }
- --direction_;
- if (!direction_)
- direction_ = 6;
- remaining_in_edge_ = area_.radius;
- passed_corner_ = false;
-}
}
=== modified file 'src/logic/mapdifferenceregion.h'
--- src/logic/mapdifferenceregion.h 2017-01-25 18:55:59 +0000
+++ src/logic/mapdifferenceregion.h 2017-08-19 07:34:40 +0000
@@ -29,13 +29,6 @@
/// constructor takes a Direction parameter, which is the walking direction
/// when going from a to b.
///
-/// It first iterates over the set of nodes that are in A but not in B. When
-/// that iteration is completed (advance has returned false),
-/// move_to_other_side can be called to prepare the region for iterating over
-/// the set of nodes in B but not in A. (Because of symmetry, it is after that
-/// iteration again possible to call move_to_other_side to iterate over the
-/// nodes that are in A but not in B again, and so on.)
-///
/// \note The order in which nodes are returned is not guarantueed.
template <typename AreaType = Area<>> struct MapDifferenceRegion {
MapDifferenceRegion(const Map& map, AreaType area, Direction direction)
@@ -86,8 +79,6 @@
*/
bool advance(const Map& map);
- void move_to_other_side(const Map& map);
-
typename AreaType::RadiusType radius() const {
return area_.radius;
}
=== modified file 'src/logic/maphollowregion.cc'
--- src/logic/maphollowregion.cc 2017-01-25 18:55:59 +0000
+++ src/logic/maphollowregion.cc 2017-08-19 07:34:40 +0000
@@ -22,7 +22,7 @@
namespace Widelands {
template <>
-MapHollowRegion<Area<>>::MapHollowRegion(const Map& map, HollowArea<Area<>> const hollow_area)
+MapHollowRegion<Area<>>::MapHollowRegion(const Map& map, const HollowArea<Area<>>& hollow_area)
: hollow_area_(hollow_area),
phase_(Top),
delta_radius_(hollow_area.radius - hollow_area.hole_radius),
=== modified file 'src/logic/maphollowregion.h'
--- src/logic/maphollowregion.h 2017-01-25 18:55:59 +0000
+++ src/logic/maphollowregion.h 2017-08-19 07:34:40 +0000
@@ -32,7 +32,7 @@
* \note The order in which fields are returned is not guarantueed.
*/
template <typename AreaType = Area<>> struct MapHollowRegion {
- MapHollowRegion(const Map& map, const HollowArea<AreaType> hollow_area);
+ MapHollowRegion(const Map& map, const HollowArea<AreaType>& hollow_area);
const typename AreaType::CoordsType& location() const {
return hollow_area_;
=== modified file 'src/logic/path.cc'
--- src/logic/path.cc 2017-01-25 18:55:59 +0000
+++ src/logic/path.cc 2017-08-19 07:34:40 +0000
@@ -122,7 +122,7 @@
/// After which step does the node appear in this path?
/// \return -1 if node is not part of this path.
-int32_t CoordPath::get_index(Coords const c) const {
+int32_t CoordPath::get_index(const Coords& c) const {
for (uint32_t i = 0; i < coords_.size(); ++i)
if (coords_[i] == c)
return i;
=== modified file 'src/logic/path.h'
--- src/logic/path.h 2017-01-25 18:55:59 +0000
+++ src/logic/path.h 2017-08-19 07:34:40 +0000
@@ -112,7 +112,7 @@
return path_;
}
- int32_t get_index(Coords field) const;
+ int32_t get_index(const Coords& field) const;
void reverse();
void truncate(const std::vector<char>::size_type after);
=== modified file 'src/logic/widelands_geometry_io.cc'
--- src/logic/widelands_geometry_io.cc 2017-01-25 18:55:59 +0000
+++ src/logic/widelands_geometry_io.cc 2017-08-19 07:34:40 +0000
@@ -76,12 +76,6 @@
return result;
}
-Area<Coords, uint16_t> read_area_48(StreamRead* fr, const Extent& extent) {
- Coords const c = read_coords_32(fr, extent);
- uint16_t const r = fr->unsigned_16();
- return Area<Coords, uint16_t>(c, r);
-}
-
void write_direction_8(StreamWrite* wr, Direction const d) {
assert(0 < d);
assert(d <= 6);
@@ -100,9 +94,4 @@
wr->unsigned_16(c.y);
}
-void write_area_48(StreamWrite* wr, const Area<Coords, uint16_t>& area) {
- write_coords_32(wr, area);
- wr->unsigned_16(area.radius);
-}
-
} // namespace Widelands
=== modified file 'src/logic/widelands_geometry_io.h'
--- src/logic/widelands_geometry_io.h 2017-06-24 08:47:46 +0000
+++ src/logic/widelands_geometry_io.h 2017-08-19 07:34:40 +0000
@@ -94,8 +94,6 @@
/// invalidity, as defined by Coords::null.
Coords read_coords_32_allow_null(StreamRead* fr, const Extent& extent);
-Area<Coords, uint16_t> read_area_48(StreamRead* fr, const Extent& extent);
-
// Writes 'd' to 'wr'.
void write_direction_8(StreamWrite* wr, Direction d);
@@ -105,9 +103,6 @@
// Writes 'c' to 'wr'.
void write_coords_32(StreamWrite* wr, const Coords& c);
-// Writes 'area' to 'wr'.
-void write_area_48(StreamWrite* wr, const Area<Coords, uint16_t>& area);
-
} // namespace Widelands
#endif // end of include guard: WL_LOGIC_WIDELANDS_GEOMETRY_IO_H
=== modified file 'src/map_io/map_players_view_packet.cc'
--- src/map_io/map_players_view_packet.cc 2017-06-24 08:47:46 +0000
+++ src/map_io/map_players_view_packet.cc 2017-08-19 07:34:40 +0000
@@ -912,7 +912,7 @@
if
// the player does not see the D triangle now but has
// seen it
- (!bl_seen & !br_seen & (f_everseen | bl_everseen | br_everseen)) {
+ ((!bl_seen) & (!br_seen) & (f_everseen | bl_everseen | br_everseen)) {
terrains_file.unsigned_8(f_player_field.terrains.d);
MapObjectData mod;
mod.map_object_descr = f_player_field.map_object_descr[TCoords<>::D];
@@ -922,7 +922,7 @@
if
// the player does not see the R triangle now but has
// seen it
- (!br_seen & !r_seen & (f_everseen | br_everseen | r_everseen)) {
+ ((!br_seen) & (!r_seen) & (f_everseen | br_everseen | r_everseen)) {
terrains_file.unsigned_8(f_player_field.terrains.r);
MapObjectData mod;
mod.map_object_descr = f_player_field.map_object_descr[TCoords<>::R];
@@ -931,11 +931,11 @@
}
// edges
- if (!bl_seen && (f_everseen || bl_everseen))
+ if ((!bl_seen) && (f_everseen || bl_everseen))
roads_file.unsigned_8(f_player_field.road_sw());
- if (!br_seen && (f_everseen || br_everseen))
+ if ((!br_seen) && (f_everseen || br_everseen))
roads_file.unsigned_8(f_player_field.road_se());
- if (!r_seen && (f_everseen || r_everseen))
+ if ((!r_seen) && (f_everseen || r_everseen))
roads_file.unsigned_8(f_player_field.road_e());
}
=== modified file 'src/map_io/s2map.cc'
--- src/map_io/s2map.cc 2017-08-16 05:10:15 +0000
+++ src/map_io/s2map.cc 2017-08-19 07:34:40 +0000
@@ -56,7 +56,6 @@
int8_t uses_world; // 0 = green, 1 =black, 2 = winter
int8_t nplayers;
char author[26];
- char bulk[2290]; // unknown
} /* size 2352 */;
// TODO(unknown): the following bob types appear in S2 maps but are unknown
=== modified file 'src/network/gamehost.cc'
--- src/network/gamehost.cc 2017-08-17 06:19:40 +0000
+++ src/network/gamehost.cc 2017-08-19 07:34:40 +0000
@@ -950,7 +950,7 @@
std::string::size_type const space = cmdarray.find(' ');
if (space > cmdarray.size())
// only cmd
- cmd = cmdarray.substr(0);
+ cmd = cmdarray;
else {
cmd = cmdarray.substr(0, space);
std::string::size_type const space2 = cmdarray.find(' ', space + 1);
@@ -1750,7 +1750,7 @@
.str();
send_system_message_code("CLIENT_HUNG",
d->settings.users.at(d->clients.at(i).usernum).name,
- seconds.c_str());
+ seconds);
d->clients.at(i).lastdelta = deltanow;
}
}
@@ -1836,7 +1836,7 @@
speeds[1] = speeds[0] + 1000;
}
- d->networkspeed = speeds.size() % 2 ?
+ d->networkspeed = (speeds.size() % 2) ?
speeds.at(speeds.size() / 2) :
(speeds.at(speeds.size() / 2) + speeds.at((speeds.size() / 2) - 1)) / 2;
=== modified file 'src/profile/profile.cc'
--- src/profile/profile.cc 2017-08-18 00:17:39 +0000
+++ src/profile/profile.cc 2017-08-19 07:34:40 +0000
@@ -553,7 +553,7 @@
* If the section doesn't exist, an exception is thrown.
*/
Section& Profile::get_safe_section(const std::string& name) {
- if (Section* const s = get_section(name.c_str()))
+ if (Section* const s = get_section(name))
return *s;
else
throw wexception("in \"%s\" section [%s] not found", filename_.c_str(), name.c_str());
=== modified file 'src/scripting/lua_map.h'
--- src/scripting/lua_map.h 2017-06-25 19:12:30 +0000
+++ src/scripting/lua_map.h 2017-08-19 07:34:40 +0000
@@ -793,8 +793,7 @@
LuaMapObject() : ptr_(nullptr) {
}
- explicit LuaMapObject(Widelands::MapObject& mo) {
- ptr_ = &mo;
+ explicit LuaMapObject(Widelands::MapObject& mo) : ptr_(&mo) {
}
explicit LuaMapObject(lua_State* L) : ptr_(nullptr) {
report_error(L, "Cannot instantiate a '%s' directly!", className);
=== modified file 'src/ui_basic/checkbox.cc'
--- src/ui_basic/checkbox.cc 2017-08-16 04:31:56 +0000
+++ src/ui_basic/checkbox.cc 2017-08-19 07:34:40 +0000
@@ -157,7 +157,7 @@
dst.blitrect(
image_anchor, pic_graphics_,
- Recti(Vector2i(flags_ & Is_Checked ? kStateboxSize : 0, 0), kStateboxSize, kStateboxSize));
+ Recti(Vector2i((flags_ & Is_Checked) ? kStateboxSize : 0, 0), kStateboxSize, kStateboxSize));
if (flags_ & Is_Highlighted)
dst.draw_rect(
=== modified file 'src/ui_basic/listselect.cc'
--- src/ui_basic/listselect.cc 2017-06-15 16:34:58 +0000
+++ src/ui_basic/listselect.cc 2017-08-19 07:34:40 +0000
@@ -117,7 +117,6 @@
er->entry_ = entry;
er->pic = pic;
- er->use_clr = false;
er->name = name;
er->tooltip = tooltip_text;
int entry_height = lineheight_;
@@ -152,7 +151,6 @@
}
er->pic = pic;
- er->use_clr = false;
er->name = name;
er->tooltip = tooltip_text;
@@ -177,24 +175,6 @@
}
/**
- * Switch two entries
- */
-void BaseListselect::switch_entries(const uint32_t m, const uint32_t n) {
- assert(m < size());
- assert(n < size());
-
- std::swap(entry_records_[m], entry_records_[n]);
-
- if (selection_ == m) {
- selection_ = n;
- selected(n);
- } else if (selection_ == n) {
- selection_ = m;
- selected(m);
- }
-}
-
-/**
* Sort the listbox alphabetically. make sure that the current selection stays
* valid (though it might scroll out of visibility).
* start and end defines the beginning and the end of a subarea to
@@ -230,17 +210,6 @@
}
/**
- * Define a special color that will be used to display the item at the given
- * index.
- */
-void BaseListselect::set_entry_color(const uint32_t n, const RGBColor& col) {
- assert(n < entry_records_.size());
-
- entry_records_[n]->use_clr = true;
- entry_records_[n]->clr = col;
-}
-
-/**
* Change the currently selected entry
*
* Args: i the entry to select
@@ -279,14 +248,6 @@
}
/**
- * Remove the currently selected item. Requires an element to have been selected first.
- */
-void BaseListselect::remove_selected() {
- assert(selection_ != no_selection_index());
- remove(selection_);
-}
-
-/**
* \return The name of the currently selected entry. Requires an entry to have been selected.
*/
const std::string& BaseListselect::get_selected_name() const {
@@ -332,7 +293,7 @@
for (size_t i = 0; i < entry_records_.size(); ++i) {
const EntryRecord& er = *entry_records_[i];
std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(as_uifont(
- richtext_escape(er.name), UI_FONT_SIZE_SMALL, er.use_clr ? er.clr : UI_FONT_CLR_FG));
+ richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
int picw = max_pic_width_ ? max_pic_width_ + 10 : 0;
int difference = rendered_text->width() + picw + 8 - get_eff_w();
if (difference > 0) {
@@ -377,7 +338,7 @@
const EntryRecord& er = *entry_records_[idx];
std::shared_ptr<const UI::RenderedText> rendered_text = UI::g_fh1->render(as_uifont(
- richtext_escape(er.name), UI_FONT_SIZE_SMALL, er.use_clr ? er.clr : UI_FONT_CLR_FG));
+ richtext_escape(er.name), UI_FONT_SIZE_SMALL, UI_FONT_CLR_FG));
int lineheight = std::max(get_lineheight(), rendered_text->height());
=== modified file 'src/ui_basic/listselect.h'
--- src/ui_basic/listselect.h 2017-02-27 22:09:57 +0000
+++ src/ui_basic/listselect.h 2017-08-19 07:34:40 +0000
@@ -73,10 +73,6 @@
void remove(uint32_t);
void remove(const char* name);
- void switch_entries(uint32_t, uint32_t);
-
- void set_entry_color(uint32_t, const RGBColor&);
-
uint32_t size() const {
return entry_records_.size();
}
@@ -101,7 +97,6 @@
bool has_selection() const;
uint32_t get_selected() const;
- void remove_selected();
const std::string& get_selected_name() const;
const std::string& get_selected_tooltip() const;
@@ -136,8 +131,6 @@
struct EntryRecord {
uint32_t entry_;
- bool use_clr;
- RGBColor clr;
const Image* pic;
std::string name;
std::string tooltip;
=== modified file 'src/ui_basic/multilineeditbox.cc'
--- src/ui_basic/multilineeditbox.cc 2017-08-16 13:23:15 +0000
+++ src/ui_basic/multilineeditbox.cc 2017-08-19 07:34:40 +0000
@@ -149,19 +149,6 @@
changed();
}
-/**
- * Set the maximum number of bytes in the scrollbar text.
- *
- * This will shorten the currently stored text when necessary.
- */
-void MultilineEditbox::set_maximum_bytes(const uint32_t n) {
- while (n < d_->text.size())
- d_->erase_bytes(d_->prev_char(d_->text.size()), d_->text.size());
- d_->maxbytes = n;
-
- // do not need to update here, because erase() will
- // update when necessary
-}
/**
* Erase the given range of bytes, adjust the cursor position, and update.
=== modified file 'src/ui_basic/multilineeditbox.h'
--- src/ui_basic/multilineeditbox.h 2017-06-23 17:23:04 +0000
+++ src/ui_basic/multilineeditbox.h 2017-08-19 07:34:40 +0000
@@ -49,8 +49,6 @@
const std::string& get_text() const;
void set_text(const std::string&);
- void set_maximum_bytes(uint32_t n);
-
void focus(bool topcaller = true) override;
protected:
=== modified file 'src/ui_basic/table.h'
--- src/ui_basic/table.h 2017-06-25 21:56:53 +0000
+++ src/ui_basic/table.h 2017-08-19 07:34:40 +0000
@@ -255,11 +255,6 @@
assert(selection_ < entry_records_.size());
return *entry_records_.at(selection_);
}
- void remove_selected() {
- if (selection_ == no_selection_index())
- throw NoSelection();
- remove(selection_);
- }
void* get_selected() const {
return get_selected_record().entry();
}
=== modified file 'src/wui/general_statistics_menu.cc'
--- src/wui/general_statistics_menu.cc 2017-05-13 18:48:26 +0000
+++ src/wui/general_statistics_menu.cc 2017-08-19 07:34:40 +0000
@@ -213,13 +213,6 @@
}
}
-/**
- * called when the help button was clicked
- */
-// TODO(unknown): Implement help
-void GeneralStatisticsMenu::clicked_help() {
-}
-
/*
* Cb has been changed to this state
*/
=== modified file 'src/wui/general_statistics_menu.h'
--- src/wui/general_statistics_menu.h 2017-01-25 18:55:59 +0000
+++ src/wui/general_statistics_menu.h 2017-08-19 07:34:40 +0000
@@ -60,7 +60,6 @@
UI::Button* cbs_[kMaxPlayers];
uint32_t ndatasets_;
- void clicked_help();
void cb_changed_to(int32_t);
void radiogroup_changed(int32_t);
};
=== modified file 'src/wui/minimap.cc'
--- src/wui/minimap.cc 2017-05-14 04:38:39 +0000
+++ src/wui/minimap.cc 2017-08-19 07:34:40 +0000
@@ -205,7 +205,7 @@
}
void MiniMap::resize() {
- view_.set_zoom(*view_.minimap_layers_ & MiniMapLayer::Zoom2 ? 2 : 1);
+ view_.set_zoom((*view_.minimap_layers_ & MiniMapLayer::Zoom2) ? 2 : 1);
set_inner_size(view_.get_w(), view_.get_h() + number_of_button_rows() * but_h());
button_terrn.set_pos(Vector2i(but_w() * 0, view_.get_h() + but_h() * 0));
button_terrn.set_size(but_w(), but_h());
=== modified file 'src/wui/ware_statistics_menu.h'
--- src/wui/ware_statistics_menu.h 2017-05-01 18:30:33 +0000
+++ src/wui/ware_statistics_menu.h 2017-08-19 07:34:40 +0000
@@ -45,7 +45,6 @@
std::vector<uint8_t> color_map_; // Maps ware index to colors
std::vector<bool> active_colors_;
- void clicked_help();
void cb_changed_to(Widelands::DescriptionIndex, bool);
};
=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc 2017-05-25 12:30:40 +0000
+++ src/wui/waresdisplay.cc 2017-08-19 07:34:40 +0000
@@ -368,16 +368,6 @@
hidden_[ware] = true;
}
-void AbstractWaresDisplay::unhide_ware(Widelands::DescriptionIndex ware) {
- if (!hidden_[ware])
- return;
- hidden_[ware] = false;
-}
-
-bool AbstractWaresDisplay::ware_hidden(Widelands::DescriptionIndex ware) {
- return hidden_[ware];
-}
-
WaresDisplay::WaresDisplay(UI::Panel* const parent,
int32_t x,
int32_t y,
=== modified file 'src/wui/waresdisplay.h'
--- src/wui/waresdisplay.h 2017-01-25 18:55:59 +0000
+++ src/wui/waresdisplay.h 2017-08-19 07:34:40 +0000
@@ -66,8 +66,6 @@
// Wares may be hidden
void hide_ware(Widelands::DescriptionIndex);
- void unhide_ware(Widelands::DescriptionIndex);
- bool ware_hidden(Widelands::DescriptionIndex);
Widelands::DescriptionIndex ware_at_point(int32_t x, int32_t y) const;
Widelands::WareWorker get_type() const {